← All problems
Problem 760
g(m,n) = (m xor n) + (m or n) + (m and n) = 2*(m|n). G(N) = sum_{n=0..N} sum_{k=0..n} g(k, n-k) = 2 * sum of (a|b) over a+b<=N. Digit DP over binary sum a+b enforcing S<=N with optional fixed bit forced to 0.
View problem on Project Euler
Performance comparison
Metric Our solution Best known
Time complexity O(n)O(n * d * s)
Space complexity O(1)O(d * s)
Approach Flow solution Digit DP
Verdict Unknown
Flow source
# Project Euler 760: Sum over Bitwise Operators
# g(m,n) = (m xor n) + (m or n) + (m and n) = 2*(m|n).
# G(N) = sum_{n=0..N} sum_{k=0..n} g(k, n-k) = 2 * sum of (a|b) over a+b<=N.
# Digit DP over binary sum a+b enforcing S<=N with optional fixed bit forced to 0.
const MOD: i64 = 1000000007
function count_pairs_sum_leq(N: i64, fixed_bit: i32) -> i64 {
if N < 0 { return 0 }
let mut bits: i32 = 1
let mut t: i64 = N
while t > 1 {
t = t >> 1
bits = bits + 1
}
# dp[carry_next][less] - use flat arrays
let dp: ptr<i64> = calloc(4, 8)
let ndp: ptr<i64> = calloc(4, 8)
dp[0] = 1
let mut pos: i32 = bits - 1
while pos >= 0 {
let nbit: i32 = ((N >> pos) & 1) as i32
# Clear ndp
ndp[0] = 0
ndp[1] = 0
ndp[2] = 0
ndp[3] = 0
let mut carry_next: i32 = 0
while carry_next < 2 {
let mut less: i32 = 0
while less < 2 {
let ways: i64 = dp[carry_next * 2 + less]
if ways != 0 {
let mut carry_cur: i32 = 0
while carry_cur < 2 {
let mut a_bit: i32 = 0
while a_bit < 2 {
let mut b_bit: i32 = 0
while b_bit < 2 {
if fixed_bit >= 0 && pos == fixed_bit && (a_bit | b_bit) != 0 {
b_bit = b_bit + 1
continue
}
let total: i32 = a_bit + b_bit + carry_cur
if (total >> 1) != carry_next {
b_bit = b_bit + 1
continue
}
let s_bit: i32 = total & 1
if less == 0 && s_bit > nbit {
b_bit = b_bit + 1
continue
}
let new_less: i32 = less | (if s_bit < nbit { 1 } else { 0 })
let idx: i32 = carry_cur * 2 + new_less
ndp[idx] = (ndp[idx] + ways) % MOD
b_bit = b_bit + 1
}
a_bit = a_bit + 1
}
carry_cur = carry_cur + 1
}
}
less = less + 1
}
carry_next = carry_next + 1
}
# Copy ndp to dp
dp[0] = ndp[0]
dp[1] = ndp[1]
dp[2] = ndp[2]
dp[3] = ndp[3]
pos = pos - 1
}
let result: i64 = (dp[0] + dp[1]) % MOD
free(dp)
free(ndp)
return result
}
extern {
function calloc(n: i64, size: i64) -> ptr<void>
function free(p: ptr<void>) -> void
}
function main() -> i32 {
let N: i64 = 1000000000000000000
let inv2: i64 = (MOD + 1) / 2
let total_pairs: i64 = ((N + 1) % MOD) * ((N + 2) % MOD) % MOD
let total_pairs2: i64 = total_pairs * inv2 % MOD
let mut bits: i32 = 1
let mut t: i64 = N
while t > 1 {
t = t >> 1
bits = bits + 1
}
let mut pow2: i64 = 1
let mut sum_or: i64 = 0
let mut i: i32 = 0
while i < bits {
let both_zero: i64 = count_pairs_sum_leq(N, i)
let mut bit_is_one: i64 = (total_pairs2 - both_zero) % MOD
if bit_is_one < 0 { bit_is_one = bit_is_one + MOD }
sum_or = (sum_or + pow2 * bit_is_one) % MOD
pow2 = (pow2 * 2) % MOD
i = i + 1
}
printf("%lld\n", (2 * sum_or) % MOD)
return 0
}
Generated C
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* Flow runtime helpers */
typedef struct flow_temp_node { struct flow_temp_node* next; } flow_temp_node;
static flow_temp_node* flow_temp_head = NULL;
static int flow_temp_atexit_set = 0;
__attribute__((unused)) static void flow_temp_free_all(void) {
while (flow_temp_head) {
flow_temp_node* n = flow_temp_head;
flow_temp_head = n->next;
free(n);
}
}
__attribute__((unused)) static void* flow_temp_alloc(size_t nbytes) {
flow_temp_node* node = (flow_temp_node*)malloc(sizeof(flow_temp_node) + nbytes);
if (!node) return NULL;
node->next = flow_temp_head;
flow_temp_head = node;
if (!flow_temp_atexit_set) {
flow_temp_atexit_set = 1;
atexit(flow_temp_free_all);
}
return (void*)(node + 1);
}
#ifndef FLOW_DIAG
#define FLOW_DIAG(msg) fprintf(stderr, "%s", (msg))
#endif
#ifndef FLOW_LOG
#define FLOW_LOG(fmt, ...) printf(fmt, __VA_ARGS__)
#endif
#ifndef FLOW_LOG_EMPTY
#define FLOW_LOG_EMPTY(fmt) printf(fmt)
#endif
static char* flow_strcat(const char* a, const char* b) {
size_t la = strlen(a ? a : ""), lb = strlen(b ? b : "");
char* r = (char*)flow_temp_alloc(la + lb + 1);
if (!r) return NULL;
if (la) memcpy(r, a, la);
if (lb) memcpy(r + la, b, lb);
r[la + lb] = '\0';
return r;
}
#define __flow_in_arr(arr, val) __extension__ ({ \
int _found = 0; \
size_t _n = sizeof(arr)/sizeof((arr)[0]); \
for (size_t _i = 0; _i < _n; _i++) { \
if ((arr)[_i] == (val)) { _found = 1; break; } \
} _found; })
/* Unified fault handler (MISRA #279) — override with -DFLOW_FAULT_HANDLER=fn */
#ifndef FLOW_FAULT_HANDLER
__attribute__((unused)) static inline void flow_fault_handler(const char* msg) {
fprintf(stderr, "flow: %s\n", msg ? msg : "fault");
abort();
#if defined(__GNUC__) || defined(__clang__)
__builtin_unreachable();
#endif
}
#else
#define flow_fault_handler FLOW_FAULT_HANDLER
#endif
#define flow_div_by_zero_handler() flow_fault_handler("division by zero")
#define flow_shift_ub_handler() flow_fault_handler("invalid shift (amount out of range or left-shift of negative)")
#ifndef FLOW_CHECKED_DIV
#define FLOW_CHECKED_DIV(L, R) (((R) != 0) ? ((L) / (R)) : (flow_div_by_zero_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_MOD
#define FLOW_CHECKED_MOD(L, R) (((R) != 0) ? ((L) % (R)) : (flow_div_by_zero_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_SHL
#define FLOW_CHECKED_SHL(L, R) ((((R) >= 0) && ((unsigned long long)(R) < (sizeof(L) * 8ull)) && ((L) >= 0)) ? ((L) << (R)) : (flow_shift_ub_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_SHR
#define FLOW_CHECKED_SHR(L, R) ((((R) >= 0) && ((unsigned long long)(R) < (sizeof(L) * 8ull))) ? ((L) >> (R)) : (flow_shift_ub_handler(), (L) * 0))
#endif
#include <math.h>
void* _ui_state = NULL;
static inline float i32_to_f32(int32_t v) { return (float)v; }
/* Host stub for @gpu kernels (device codegen replaces this). */
static inline int32_t gpu_thread_id(void) { return 0; }
int64_t count_pairs_sum_leq_i64_i32(int64_t N, int32_t fixed_bit);
int32_t main(void);
static const int64_t MOD = 1000000007;
int64_t count_pairs_sum_leq_i64_i32(int64_t N, int32_t fixed_bit) {
if (N < 0) {
return 0;
}
int32_t bits = 1;
int64_t t = N;
while (t > 1) {
t = FLOW_CHECKED_SHR((t), (1));
bits = (bits + 1);
}
int64_t* dp = (int64_t*)(calloc(4, 8));
int64_t* ndp = (int64_t*)(calloc(4, 8));
dp[0] = 1;
int32_t pos = (bits - 1);
while (pos >= 0) {
int32_t nbit = ((int32_t)((FLOW_CHECKED_SHR((N), (pos)) & 1)));
ndp[0] = 0;
ndp[1] = 0;
ndp[2] = 0;
ndp[3] = 0;
int32_t carry_next = 0;
while (carry_next < 2) {
int32_t less = 0;
while (less < 2) {
int64_t ways = dp[((carry_next * 2) + less)];
if (ways != 0) {
int32_t carry_cur = 0;
while (carry_cur < 2) {
int32_t a_bit = 0;
while (a_bit < 2) {
int32_t b_bit = 0;
while (b_bit < 2) {
if (((fixed_bit >= 0 && pos == fixed_bit) && (a_bit | b_bit) != 0)) {
b_bit = (b_bit + 1);
continue;
}
int32_t total = ((a_bit + b_bit) + carry_cur);
if (FLOW_CHECKED_SHR((total), (1)) != carry_next) {
b_bit = (b_bit + 1);
continue;
}
int32_t s_bit = (total & 1);
if ((less == 0 && s_bit > nbit)) {
b_bit = (b_bit + 1);
continue;
}
int32_t new_less = (less | ((s_bit < nbit) ? (1) : (0)));
int32_t idx = ((carry_cur * 2) + new_less);
ndp[idx] = FLOW_CHECKED_MOD(((ndp[idx] + ways)), (MOD));
b_bit = (b_bit + 1);
}
a_bit = (a_bit + 1);
}
carry_cur = (carry_cur + 1);
}
}
less = (less + 1);
}
carry_next = (carry_next + 1);
}
dp[0] = ndp[0];
dp[1] = ndp[1];
dp[2] = ndp[2];
dp[3] = ndp[3];
pos = (pos - 1);
}
int64_t result = FLOW_CHECKED_MOD(((dp[0] + dp[1])), (MOD));
free(dp);
free(ndp);
return result;
}
int32_t main(void) {
int64_t N = 1000000000000000000;
int64_t inv2 = FLOW_CHECKED_DIV(((MOD + 1)), (2));
int64_t total_pairs = FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD(((N + 1)), (MOD)) * FLOW_CHECKED_MOD(((N + 2)), (MOD)))), (MOD));
int64_t total_pairs2 = FLOW_CHECKED_MOD(((total_pairs * inv2)), (MOD));
int32_t bits = 1;
int64_t t = N;
while (t > 1) {
t = FLOW_CHECKED_SHR((t), (1));
bits = (bits + 1);
}
int64_t pow2 = 1;
int64_t sum_or = 0;
int32_t i = 0;
while (i < bits) {
int64_t both_zero = count_pairs_sum_leq_i64_i32(N, i);
int64_t bit_is_one = FLOW_CHECKED_MOD(((total_pairs2 - both_zero)), (MOD));
if (bit_is_one < 0) {
bit_is_one = (bit_is_one + MOD);
}
sum_or = FLOW_CHECKED_MOD(((sum_or + (pow2 * bit_is_one))), (MOD));
pow2 = FLOW_CHECKED_MOD(((pow2 * 2)), (MOD));
i = (i + 1);
}
printf("%lld\n", FLOW_CHECKED_MOD(((2 * sum_or)), (MOD)));
return 0;
}
Generated MLIR
module {
llvm.func @printf(!llvm.ptr, ...) -> i32
llvm.mlir.global internal constant @str_0("%lld\n\00") {addr_space = 0 : i32} : !llvm.array<6 x i8>
// Constant: MOD
llvm.mlir.global internal constant @MOD(1000000007 : i64) : i64
func.func @count_pairs_sum_leq(%arg0: i64, %arg1: i32) -> i64 {
%0 = arith.constant 0 : i32
%2 = arith.extsi %0 : i32 to i64
%1 = arith.cmpi slt, %arg0, %2 : i64
cf.cond_br %1, ^bb0, ^bb1
^bb0:
%3 = arith.constant 0 : i32
%4 = arith.extsi %3 : i32 to i64
func.return %4 : i64
^bb1:
cf.br ^bb2
^bb2:
%5 = arith.constant 1 : i32
%6 = llvm.mlir.constant(1 : i64) : i64
%7 = llvm.alloca %6 x i32 : (i64) -> !llvm.ptr
llvm.store %5, %7 : i32, !llvm.ptr
%8 = llvm.mlir.constant(1 : i64) : i64
%9 = llvm.alloca %8 x i64 : (i64) -> !llvm.ptr
llvm.store %arg0, %9 : i64, !llvm.ptr
cf.br ^bb3
^bb3:
%10 = llvm.load %9 : !llvm.ptr -> i64
%11 = arith.constant 1 : i32
%13 = arith.extsi %11 : i32 to i64
%12 = arith.cmpi sgt, %10, %13 : i64
cf.cond_br %12, ^bb4, ^bb5
^bb4:
%14 = llvm.load %9 : !llvm.ptr -> i64
%15 = arith.constant 1 : i32
%17 = arith.extsi %15 : i32 to i64
%16 = arith.shrsi %14, %17 : i64
llvm.store %16, %9 : i64, !llvm.ptr
%18 = llvm.load %7 : !llvm.ptr -> i32
%19 = arith.constant 1 : i32
%20 = arith.addi %18, %19 : i32
llvm.store %20, %7 : i32, !llvm.ptr
cf.br ^bb3
^bb5:
%22 = arith.constant 4 : i32
%23 = arith.constant 8 : i32
%24 = arith.extsi %22 : i32 to i64
%25 = arith.extsi %23 : i32 to i64
%21 = func.call @calloc(%24, %25) : (i64, i64) -> !llvm.ptr
%27 = arith.constant 4 : i32
%28 = arith.constant 8 : i32
%29 = arith.extsi %27 : i32 to i64
%30 = arith.extsi %28 : i32 to i64
%26 = func.call @calloc(%29, %30) : (i64, i64) -> !llvm.ptr
%31 = arith.constant 1 : i32
%32 = arith.constant 0 : i32
%33 = arith.extsi %31 : i32 to i64
%34 = arith.extsi %32 : i32 to i64
%35 = llvm.getelementptr %21[%34] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %33, %35 : i64, !llvm.ptr
%36 = llvm.load %7 : !llvm.ptr -> i32
%37 = arith.constant 1 : i32
%38 = arith.subi %36, %37 : i32
%39 = llvm.mlir.constant(1 : i64) : i64
%40 = llvm.alloca %39 x i32 : (i64) -> !llvm.ptr
llvm.store %38, %40 : i32, !llvm.ptr
cf.br ^bb6
^bb6:
%41 = llvm.load %40 : !llvm.ptr -> i32
%42 = arith.constant 0 : i32
%43 = arith.cmpi sge, %41, %42 : i32
cf.cond_br %43, ^bb7, ^bb8
^bb7:
%44 = llvm.load %40 : !llvm.ptr -> i32
%46 = arith.extsi %44 : i32 to i64
%45 = arith.shrsi %arg0, %46 : i64
%47 = arith.constant 1 : i32
%49 = arith.extsi %47 : i32 to i64
%48 = arith.andi %45, %49 : i64
%50 = arith.trunci %48 : i64 to i32
%51 = arith.constant 0 : i32
%52 = arith.constant 0 : i32
%53 = arith.extsi %51 : i32 to i64
%54 = arith.extsi %52 : i32 to i64
%55 = llvm.getelementptr %26[%54] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %53, %55 : i64, !llvm.ptr
%56 = arith.constant 0 : i32
%57 = arith.constant 1 : i32
%58 = arith.extsi %56 : i32 to i64
%59 = arith.extsi %57 : i32 to i64
%60 = llvm.getelementptr %26[%59] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %58, %60 : i64, !llvm.ptr
%61 = arith.constant 0 : i32
%62 = arith.constant 2 : i32
%63 = arith.extsi %61 : i32 to i64
%64 = arith.extsi %62 : i32 to i64
%65 = llvm.getelementptr %26[%64] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %63, %65 : i64, !llvm.ptr
%66 = arith.constant 0 : i32
%67 = arith.constant 3 : i32
%68 = arith.extsi %66 : i32 to i64
%69 = arith.extsi %67 : i32 to i64
%70 = llvm.getelementptr %26[%69] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %68, %70 : i64, !llvm.ptr
%71 = arith.constant 0 : i32
%72 = llvm.mlir.constant(1 : i64) : i64
%73 = llvm.alloca %72 x i32 : (i64) -> !llvm.ptr
llvm.store %71, %73 : i32, !llvm.ptr
cf.br ^bb9
^bb9:
%74 = llvm.load %73 : !llvm.ptr -> i32
%75 = arith.constant 2 : i32
%76 = arith.cmpi slt, %74, %75 : i32
cf.cond_br %76, ^bb10, ^bb11
^bb10:
%77 = arith.constant 0 : i32
%78 = llvm.mlir.constant(1 : i64) : i64
%79 = llvm.alloca %78 x i32 : (i64) -> !llvm.ptr
llvm.store %77, %79 : i32, !llvm.ptr
cf.br ^bb12
^bb12:
%80 = llvm.load %79 : !llvm.ptr -> i32
%81 = arith.constant 2 : i32
%82 = arith.cmpi slt, %80, %81 : i32
cf.cond_br %82, ^bb13, ^bb14
^bb13:
%84 = llvm.load %73 : !llvm.ptr -> i32
%85 = arith.constant 2 : i32
%86 = arith.muli %84, %85 : i32
%87 = llvm.load %79 : !llvm.ptr -> i32
%88 = arith.addi %86, %87 : i32
%89 = arith.extsi %88 : i32 to i64
%90 = llvm.getelementptr %21[%89] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%83 = llvm.load %90 : !llvm.ptr -> i64
%91 = arith.constant 0 : i32
%93 = arith.extsi %91 : i32 to i64
%92 = arith.cmpi ne, %83, %93 : i64
cf.cond_br %92, ^bb15, ^bb16
^bb15:
%94 = arith.constant 0 : i32
%95 = llvm.mlir.constant(1 : i64) : i64
%96 = llvm.alloca %95 x i32 : (i64) -> !llvm.ptr
llvm.store %94, %96 : i32, !llvm.ptr
cf.br ^bb18
^bb18:
%97 = llvm.load %96 : !llvm.ptr -> i32
%98 = arith.constant 2 : i32
%99 = arith.cmpi slt, %97, %98 : i32
cf.cond_br %99, ^bb19, ^bb20
^bb19:
%100 = arith.constant 0 : i32
%101 = llvm.mlir.constant(1 : i64) : i64
%102 = llvm.alloca %101 x i32 : (i64) -> !llvm.ptr
llvm.store %100, %102 : i32, !llvm.ptr
cf.br ^bb21
^bb21:
%103 = llvm.load %102 : !llvm.ptr -> i32
%104 = arith.constant 2 : i32
%105 = arith.cmpi slt, %103, %104 : i32
cf.cond_br %105, ^bb22, ^bb23
^bb22:
%106 = arith.constant 0 : i32
%107 = llvm.mlir.constant(1 : i64) : i64
%108 = llvm.alloca %107 x i32 : (i64) -> !llvm.ptr
llvm.store %106, %108 : i32, !llvm.ptr
cf.br ^bb24
^bb24:
%109 = llvm.load %108 : !llvm.ptr -> i32
%110 = arith.constant 2 : i32
%111 = arith.cmpi slt, %109, %110 : i32
cf.cond_br %111, ^bb25, ^bb26
^bb25:
%112 = arith.constant 0 : i32
%113 = arith.cmpi sge, %arg1, %112 : i32
%114 = scf.if %113 -> (i1) {
%115 = llvm.load %40 : !llvm.ptr -> i32
%116 = arith.cmpi eq, %115, %arg1 : i32
scf.yield %116 : i1
} else {
%117 = arith.constant false
scf.yield %117 : i1
}
%118 = scf.if %114 -> (i1) {
%119 = llvm.load %102 : !llvm.ptr -> i32
%120 = llvm.load %108 : !llvm.ptr -> i32
%121 = arith.ori %119, %120 : i32
%122 = arith.constant 0 : i32
%123 = arith.cmpi ne, %121, %122 : i32
scf.yield %123 : i1
} else {
%124 = arith.constant false
scf.yield %124 : i1
}
cf.cond_br %118, ^bb27, ^bb28
^bb27:
%125 = llvm.load %108 : !llvm.ptr -> i32
%126 = arith.constant 1 : i32
%127 = arith.addi %125, %126 : i32
llvm.store %127, %108 : i32, !llvm.ptr
cf.br ^bb24
^bb28:
cf.br ^bb29
^bb29:
%128 = llvm.load %102 : !llvm.ptr -> i32
%129 = llvm.load %108 : !llvm.ptr -> i32
%130 = arith.addi %128, %129 : i32
%131 = llvm.load %96 : !llvm.ptr -> i32
%132 = arith.addi %130, %131 : i32
%133 = arith.constant 1 : i32
%134 = arith.shrsi %132, %133 : i32
%135 = llvm.load %73 : !llvm.ptr -> i32
%136 = arith.cmpi ne, %134, %135 : i32
cf.cond_br %136, ^bb30, ^bb31
^bb30:
%137 = llvm.load %108 : !llvm.ptr -> i32
%138 = arith.constant 1 : i32
%139 = arith.addi %137, %138 : i32
llvm.store %139, %108 : i32, !llvm.ptr
cf.br ^bb24
^bb31:
cf.br ^bb32
^bb32:
%140 = arith.constant 1 : i32
%141 = arith.andi %132, %140 : i32
%142 = llvm.load %79 : !llvm.ptr -> i32
%143 = arith.constant 0 : i32
%144 = arith.cmpi eq, %142, %143 : i32
%145 = scf.if %144 -> (i1) {
%146 = arith.cmpi sgt, %141, %50 : i32
scf.yield %146 : i1
} else {
%147 = arith.constant false
scf.yield %147 : i1
}
cf.cond_br %145, ^bb33, ^bb34
^bb33:
%148 = llvm.load %108 : !llvm.ptr -> i32
%149 = arith.constant 1 : i32
%150 = arith.addi %148, %149 : i32
llvm.store %150, %108 : i32, !llvm.ptr
cf.br ^bb24
^bb34:
cf.br ^bb35
^bb35:
%151 = llvm.load %79 : !llvm.ptr -> i32
%152 = arith.cmpi slt, %141, %50 : i32
%153 = scf.if %152 -> (i32) {
%154 = arith.constant 1 : i32
scf.yield %154 : i32
} else {
%155 = arith.constant 0 : i32
scf.yield %155 : i32
}
%156 = arith.ori %151, %153 : i32
%157 = llvm.load %96 : !llvm.ptr -> i32
%158 = arith.constant 2 : i32
%159 = arith.muli %157, %158 : i32
%160 = arith.addi %159, %156 : i32
%162 = arith.extsi %160 : i32 to i64
%163 = llvm.getelementptr %26[%162] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%161 = llvm.load %163 : !llvm.ptr -> i64
%164 = arith.addi %161, %83 : i64
%165 = llvm.mlir.addressof @MOD : !llvm.ptr
%166 = llvm.load %165 : !llvm.ptr -> i64
%167 = arith.remsi %164, %166 : i64
%168 = arith.extsi %160 : i32 to i64
%169 = llvm.getelementptr %26[%168] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %167, %169 : i64, !llvm.ptr
%170 = llvm.load %108 : !llvm.ptr -> i32
%171 = arith.constant 1 : i32
%172 = arith.addi %170, %171 : i32
llvm.store %172, %108 : i32, !llvm.ptr
cf.br ^bb24
^bb26:
%173 = llvm.load %102 : !llvm.ptr -> i32
%174 = arith.constant 1 : i32
%175 = arith.addi %173, %174 : i32
llvm.store %175, %102 : i32, !llvm.ptr
cf.br ^bb21
^bb23:
%176 = llvm.load %96 : !llvm.ptr -> i32
%177 = arith.constant 1 : i32
%178 = arith.addi %176, %177 : i32
llvm.store %178, %96 : i32, !llvm.ptr
cf.br ^bb18
^bb20:
cf.br ^bb17
^bb16:
cf.br ^bb17
^bb17:
%179 = llvm.load %79 : !llvm.ptr -> i32
%180 = arith.constant 1 : i32
%181 = arith.addi %179, %180 : i32
llvm.store %181, %79 : i32, !llvm.ptr
cf.br ^bb12
^bb14:
%182 = llvm.load %73 : !llvm.ptr -> i32
%183 = arith.constant 1 : i32
%184 = arith.addi %182, %183 : i32
llvm.store %184, %73 : i32, !llvm.ptr
cf.br ^bb9
^bb11:
%186 = arith.constant 0 : i32
%187 = arith.extsi %186 : i32 to i64
%188 = llvm.getelementptr %26[%187] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%185 = llvm.load %188 : !llvm.ptr -> i64
%189 = arith.constant 0 : i32
%190 = arith.extsi %189 : i32 to i64
%191 = llvm.getelementptr %21[%190] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %185, %191 : i64, !llvm.ptr
%193 = arith.constant 1 : i32
%194 = arith.extsi %193 : i32 to i64
%195 = llvm.getelementptr %26[%194] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%192 = llvm.load %195 : !llvm.ptr -> i64
%196 = arith.constant 1 : i32
%197 = arith.extsi %196 : i32 to i64
%198 = llvm.getelementptr %21[%197] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %192, %198 : i64, !llvm.ptr
%200 = arith.constant 2 : i32
%201 = arith.extsi %200 : i32 to i64
%202 = llvm.getelementptr %26[%201] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%199 = llvm.load %202 : !llvm.ptr -> i64
%203 = arith.constant 2 : i32
%204 = arith.extsi %203 : i32 to i64
%205 = llvm.getelementptr %21[%204] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %199, %205 : i64, !llvm.ptr
%207 = arith.constant 3 : i32
%208 = arith.extsi %207 : i32 to i64
%209 = llvm.getelementptr %26[%208] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%206 = llvm.load %209 : !llvm.ptr -> i64
%210 = arith.constant 3 : i32
%211 = arith.extsi %210 : i32 to i64
%212 = llvm.getelementptr %21[%211] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %206, %212 : i64, !llvm.ptr
%213 = llvm.load %40 : !llvm.ptr -> i32
%214 = arith.constant 1 : i32
%215 = arith.subi %213, %214 : i32
llvm.store %215, %40 : i32, !llvm.ptr
cf.br ^bb6
^bb8:
%217 = arith.constant 0 : i32
%218 = arith.extsi %217 : i32 to i64
%219 = llvm.getelementptr %21[%218] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%216 = llvm.load %219 : !llvm.ptr -> i64
%221 = arith.constant 1 : i32
%222 = arith.extsi %221 : i32 to i64
%223 = llvm.getelementptr %21[%222] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%220 = llvm.load %223 : !llvm.ptr -> i64
%224 = arith.addi %216, %220 : i64
%225 = llvm.mlir.addressof @MOD : !llvm.ptr
%226 = llvm.load %225 : !llvm.ptr -> i64
%227 = arith.remsi %224, %226 : i64
func.call @free(%21) : (!llvm.ptr) -> ()
func.call @free(%26) : (!llvm.ptr) -> ()
func.return %227 : i64
}
func.func private @calloc(i64, i64) -> !llvm.ptr
func.func private @free(!llvm.ptr) -> ()
func.func @main() -> i32 {
%230 = arith.constant 999999995705032704 : i32
%231 = arith.extsi %230 : i32 to i64
%232 = llvm.mlir.addressof @MOD : !llvm.ptr
%233 = llvm.load %232 : !llvm.ptr -> i64
%234 = arith.constant 1 : i32
%236 = arith.extsi %234 : i32 to i64
%235 = arith.addi %233, %236 : i64
%237 = arith.constant 2 : i32
%239 = arith.extsi %237 : i32 to i64
%238 = arith.divsi %235, %239 : i64
%240 = arith.constant 1 : i32
%242 = arith.extsi %240 : i32 to i64
%241 = arith.addi %231, %242 : i64
%243 = llvm.mlir.addressof @MOD : !llvm.ptr
%244 = llvm.load %243 : !llvm.ptr -> i64
%245 = arith.remsi %241, %244 : i64
%246 = arith.constant 2 : i32
%248 = arith.extsi %246 : i32 to i64
%247 = arith.addi %231, %248 : i64
%249 = llvm.mlir.addressof @MOD : !llvm.ptr
%250 = llvm.load %249 : !llvm.ptr -> i64
%251 = arith.remsi %247, %250 : i64
%252 = arith.muli %245, %251 : i64
%253 = llvm.mlir.addressof @MOD : !llvm.ptr
%254 = llvm.load %253 : !llvm.ptr -> i64
%255 = arith.remsi %252, %254 : i64
%256 = arith.muli %255, %238 : i64
%257 = llvm.mlir.addressof @MOD : !llvm.ptr
%258 = llvm.load %257 : !llvm.ptr -> i64
%259 = arith.remsi %256, %258 : i64
%260 = arith.constant 1 : i32
%261 = llvm.mlir.constant(1 : i64) : i64
%262 = llvm.alloca %261 x i32 : (i64) -> !llvm.ptr
llvm.store %260, %262 : i32, !llvm.ptr
%263 = llvm.mlir.constant(1 : i64) : i64
%264 = llvm.alloca %263 x i64 : (i64) -> !llvm.ptr
llvm.store %231, %264 : i64, !llvm.ptr
cf.br ^bb36
^bb36:
%265 = llvm.load %264 : !llvm.ptr -> i64
%266 = arith.constant 1 : i32
%268 = arith.extsi %266 : i32 to i64
%267 = arith.cmpi sgt, %265, %268 : i64
cf.cond_br %267, ^bb37, ^bb38
^bb37:
%269 = llvm.load %264 : !llvm.ptr -> i64
%270 = arith.constant 1 : i32
%272 = arith.extsi %270 : i32 to i64
%271 = arith.shrsi %269, %272 : i64
llvm.store %271, %264 : i64, !llvm.ptr
%273 = llvm.load %262 : !llvm.ptr -> i32
%274 = arith.constant 1 : i32
%275 = arith.addi %273, %274 : i32
llvm.store %275, %262 : i32, !llvm.ptr
cf.br ^bb36
^bb38:
%276 = arith.constant 1 : i32
%277 = arith.extsi %276 : i32 to i64
%278 = llvm.mlir.constant(1 : i64) : i64
%279 = llvm.alloca %278 x i64 : (i64) -> !llvm.ptr
llvm.store %277, %279 : i64, !llvm.ptr
%280 = arith.constant 0 : i32
%281 = arith.extsi %280 : i32 to i64
%282 = llvm.mlir.constant(1 : i64) : i64
%283 = llvm.alloca %282 x i64 : (i64) -> !llvm.ptr
llvm.store %281, %283 : i64, !llvm.ptr
%284 = arith.constant 0 : i32
%285 = llvm.mlir.constant(1 : i64) : i64
%286 = llvm.alloca %285 x i32 : (i64) -> !llvm.ptr
llvm.store %284, %286 : i32, !llvm.ptr
cf.br ^bb39
^bb39:
%287 = llvm.load %286 : !llvm.ptr -> i32
%288 = llvm.load %262 : !llvm.ptr -> i32
%289 = arith.cmpi slt, %287, %288 : i32
cf.cond_br %289, ^bb40, ^bb41
^bb40:
%291 = llvm.load %286 : !llvm.ptr -> i32
%290 = func.call @count_pairs_sum_leq(%231, %291) : (i64, i32) -> i64
%292 = arith.subi %259, %290 : i64
%293 = llvm.mlir.addressof @MOD : !llvm.ptr
%294 = llvm.load %293 : !llvm.ptr -> i64
%295 = arith.remsi %292, %294 : i64
%296 = llvm.mlir.constant(1 : i64) : i64
%297 = llvm.alloca %296 x i64 : (i64) -> !llvm.ptr
llvm.store %295, %297 : i64, !llvm.ptr
%298 = llvm.load %297 : !llvm.ptr -> i64
%299 = arith.constant 0 : i32
%301 = arith.extsi %299 : i32 to i64
%300 = arith.cmpi slt, %298, %301 : i64
cf.cond_br %300, ^bb42, ^bb43
^bb42:
%302 = llvm.load %297 : !llvm.ptr -> i64
%303 = llvm.mlir.addressof @MOD : !llvm.ptr
%304 = llvm.load %303 : !llvm.ptr -> i64
%305 = arith.addi %302, %304 : i64
llvm.store %305, %297 : i64, !llvm.ptr
cf.br ^bb44
^bb43:
cf.br ^bb44
^bb44:
%306 = llvm.load %283 : !llvm.ptr -> i64
%307 = llvm.load %279 : !llvm.ptr -> i64
%308 = llvm.load %297 : !llvm.ptr -> i64
%309 = arith.muli %307, %308 : i64
%310 = arith.addi %306, %309 : i64
%311 = llvm.mlir.addressof @MOD : !llvm.ptr
%312 = llvm.load %311 : !llvm.ptr -> i64
%313 = arith.remsi %310, %312 : i64
llvm.store %313, %283 : i64, !llvm.ptr
%314 = llvm.load %279 : !llvm.ptr -> i64
%315 = arith.constant 2 : i32
%317 = arith.extsi %315 : i32 to i64
%316 = arith.muli %314, %317 : i64
%318 = llvm.mlir.addressof @MOD : !llvm.ptr
%319 = llvm.load %318 : !llvm.ptr -> i64
%320 = arith.remsi %316, %319 : i64
llvm.store %320, %279 : i64, !llvm.ptr
%321 = llvm.load %286 : !llvm.ptr -> i32
%322 = arith.constant 1 : i32
%323 = arith.addi %321, %322 : i32
llvm.store %323, %286 : i32, !llvm.ptr
cf.br ^bb39
^bb41:
%324 = llvm.mlir.addressof @str_0 : !llvm.ptr
%325 = arith.constant 2 : i32
%326 = llvm.load %283 : !llvm.ptr -> i64
%328 = arith.extsi %325 : i32 to i64
%327 = arith.muli %328, %326 : i64
%329 = llvm.mlir.addressof @MOD : !llvm.ptr
%330 = llvm.load %329 : !llvm.ptr -> i64
%331 = arith.remsi %327, %330 : i64
%332 = llvm.call @printf(%324, %331) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
%333 = arith.constant 0 : i32
func.return %333 : i32
}
}