← All problems
Problem 440
S(2000) mod 987898789 for gcd of tiling counts T(c^a), T(c^b).
View problem on Project Euler
Performance comparison
Metric Our solution Best known
Time complexity O(n^2)O(n * s)
Space complexity O(n^2)O(s)
Approach Flow solution Tiling DP with state
Verdict Unknown
Flow source
# Project Euler 440
# S(2000) mod 987898789 for gcd of tiling counts T(c^a), T(c^b).
extern {
function calloc(n: i64, size: i64) -> ptr<void>
function free(p: ptr<void>) -> void
}
function mul_pair(a0: i64, a1: i64, b0: i64, b1: i64, mod: i64, P: i64, o0: ptr<i64>, o1: ptr<i64>) -> void {
let t: i64 = (b1 - P * b0) % mod
if t < 0 { t = t + mod }
o0[0] = (a1 * b0 + a0 * t) % mod
o1[0] = (a1 * b1 + a0 * b0) % mod
}
function sq_pair(a0: i64, a1: i64, mod: i64, P: i64, o0: ptr<i64>, o1: ptr<i64>) -> void {
let v: i64 = (2 * a1 - P * a0) % mod
if v < 0 { v = v + mod }
o0[0] = (a0 * v) % mod
o1[0] = (a1 * a1 + a0 * a0) % mod
}
function main() -> i32 {
let MOD: i64 = 987898789
let P: i64 = 10
let L: i64 = 2000
let mu: ptr<i8> = calloc(L + 1, 1)
let is_comp: ptr<i8> = calloc(L + 1, 1)
let primes: ptr<i32> = calloc(L, 4)
if mu == null { return 1 }
mu[1] = 1
let mut pc: i64 = 0
let mut i: i64 = 2
while i <= L {
if is_comp[i] == 0 {
primes[pc] = i as i32
pc = pc + 1
mu[i] = -1
}
let mut j: i64 = 0
while j < pc {
let p: i64 = primes[j] as i64
let ip: i64 = i * p
if ip > L { break }
is_comp[ip] = 1
if i % p == 0 { mu[ip] = 0; break }
mu[ip] = (0 - (mu[i] as i64)) as i8
j = j + 1
}
i = i + 1
}
let f: ptr<i64> = calloc(L + 1, 8)
let mut n: i64 = 1
while n <= L {
let mut s: i64 = 0
let mut d: i64 = 1
while d <= n {
let md: i64 = mu[d] as i64
if md != 0 {
let t: i64 = (n / d + 1) / 2
s = s + md * t * t
}
d = d + 2
}
f[n] = s
n = n + 1
}
let Ncnt: ptr<i64> = calloc(L + 1, 8)
let mut sumN: i64 = 0
let mut g: i64 = 1
while g <= L {
Ncnt[g] = f[L / g]
sumN = sumN + Ncnt[g]
g = g + 1
}
let rest: i64 = L * L - sumN
let U: ptr<i64> = calloc(L + 2, 8)
U[0] = 0
U[1] = 1
i = 2
while i <= L + 1 {
U[i] = (P * U[i - 1] + U[i - 2]) % MOD
i = i + 1
}
let bits: ptr<i8> = calloc(64, 1)
let o0: i64 = 0
let o1: i64 = 0
let mut total: i64 = 0
let mut c: i64 = 1
while c <= L {
let mut nbits: i64 = 0
let mut x: i64 = c
while x > 0 {
bits[nbits] = (x & 1) as i8
x = x >> 1
nbits = nbits + 1
}
let mut pair0: i64 = U[c]
let mut pair1: i64 = U[c + 1]
let mut small: i64 = 1
if (c & 1) == 1 { small = U[2] }
let mut contrib: i64 = (rest % MOD) * small % MOD
g = 1
while g <= L {
contrib = (contrib + (Ncnt[g] % MOD) * pair1) % MOD
# pow_pair_by_bits
let mut r0: i64 = 0
let mut r1: i64 = 1
let mut b0: i64 = pair0
let mut b1: i64 = pair1
let mut bi: i64 = 0
while bi < nbits {
if bits[bi] != 0 {
mul_pair(r0, r1, b0, b1, MOD, P, &o0, &o1)
r0 = o0
r1 = o1
}
if bi != nbits - 1 {
sq_pair(b0, b1, MOD, P, &o0, &o1)
b0 = o0
b1 = o1
}
bi = bi + 1
}
pair0 = r0
pair1 = r1
g = g + 1
}
total = (total + contrib) % MOD
c = c + 1
}
printf("%lld\n", total)
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; }
void mul_pair_i64_i64_i64_i64_i64_i64_ptr_i64_ptr_i64(int64_t a0, int64_t a1, int64_t b0, int64_t b1, int64_t mod, int64_t P, int64_t* o0, int64_t* o1);
void sq_pair_i64_i64_i64_i64_ptr_i64_ptr_i64(int64_t a0, int64_t a1, int64_t mod, int64_t P, int64_t* o0, int64_t* o1);
int32_t main(void);
void mul_pair_i64_i64_i64_i64_i64_i64_ptr_i64_ptr_i64(int64_t a0, int64_t a1, int64_t b0, int64_t b1, int64_t mod, int64_t P, int64_t* o0, int64_t* o1) {
int64_t t = FLOW_CHECKED_MOD(((b1 - (P * b0))), (mod));
if (t < 0) {
t = (t + mod);
}
o0[0] = FLOW_CHECKED_MOD((((a1 * b0) + (a0 * t))), (mod));
o1[0] = FLOW_CHECKED_MOD((((a1 * b1) + (a0 * b0))), (mod));
}
void sq_pair_i64_i64_i64_i64_ptr_i64_ptr_i64(int64_t a0, int64_t a1, int64_t mod, int64_t P, int64_t* o0, int64_t* o1) {
int64_t v = FLOW_CHECKED_MOD((((2 * a1) - (P * a0))), (mod));
if (v < 0) {
v = (v + mod);
}
o0[0] = FLOW_CHECKED_MOD(((a0 * v)), (mod));
o1[0] = FLOW_CHECKED_MOD((((a1 * a1) + (a0 * a0))), (mod));
}
int32_t main(void) {
int64_t MOD = 987898789;
int64_t P = 10;
int64_t L = 2000;
int8_t* mu = (int8_t*)(calloc((L + 1), 1));
int8_t* is_comp = (int8_t*)(calloc((L + 1), 1));
int32_t* primes = (int32_t*)(calloc(L, 4));
if (mu == NULL) {
return 1;
}
mu[1] = 1;
int64_t pc = 0;
int64_t i = 2;
while (i <= L) {
if (is_comp[i] == 0) {
primes[pc] = ((int32_t)(i));
pc = (pc + 1);
mu[i] = (-1);
}
int64_t j = 0;
while (j < pc) {
int64_t p = ((int64_t)(primes[j]));
int64_t ip = (i * p);
if (ip > L) {
break;
}
is_comp[ip] = 1;
if (FLOW_CHECKED_MOD((i), (p)) == 0) {
mu[ip] = 0;
break;
}
mu[ip] = ((int8_t)((0 - ((int64_t)(mu[i])))));
j = (j + 1);
}
i = (i + 1);
}
int64_t* f = (int64_t*)(calloc((L + 1), 8));
int64_t n = 1;
while (n <= L) {
int64_t s = 0;
int64_t d = 1;
while (d <= n) {
int64_t md = ((int64_t)(mu[d]));
if (md != 0) {
int64_t t = FLOW_CHECKED_DIV(((FLOW_CHECKED_DIV((n), (d)) + 1)), (2));
s = (s + ((md * t) * t));
}
d = (d + 2);
}
f[n] = s;
n = (n + 1);
}
int64_t* Ncnt = (int64_t*)(calloc((L + 1), 8));
int64_t sumN = 0;
int64_t g = 1;
while (g <= L) {
Ncnt[g] = f[FLOW_CHECKED_DIV((L), (g))];
sumN = (sumN + Ncnt[g]);
g = (g + 1);
}
int64_t rest = ((L * L) - sumN);
int64_t* U = (int64_t*)(calloc((L + 2), 8));
U[0] = 0;
U[1] = 1;
i = 2;
while (i <= (L + 1)) {
U[i] = FLOW_CHECKED_MOD((((P * U[(i - 1)]) + U[(i - 2)])), (MOD));
i = (i + 1);
}
int8_t* bits = (int8_t*)(calloc(64, 1));
int64_t o0 = 0;
int64_t o1 = 0;
int64_t total = 0;
int64_t c = 1;
while (c <= L) {
int64_t nbits = 0;
int64_t x = c;
while (x > 0) {
bits[nbits] = ((int8_t)((x & 1)));
x = FLOW_CHECKED_SHR((x), (1));
nbits = (nbits + 1);
}
int64_t pair0 = U[c];
int64_t pair1 = U[(c + 1)];
int64_t small = 1;
if ((c & 1) == 1) {
small = U[2];
}
int64_t contrib = FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD((rest), (MOD)) * small)), (MOD));
g = 1;
while (g <= L) {
contrib = FLOW_CHECKED_MOD(((contrib + (FLOW_CHECKED_MOD((Ncnt[g]), (MOD)) * pair1))), (MOD));
int64_t r0 = 0;
int64_t r1 = 1;
int64_t b0 = pair0;
int64_t b1 = pair1;
int64_t bi = 0;
while (bi < nbits) {
if (bits[bi] != 0) {
mul_pair_i64_i64_i64_i64_i64_i64_ptr_i64_ptr_i64(r0, r1, b0, b1, MOD, P, (&(o0)), (&(o1)));
r0 = o0;
r1 = o1;
}
if (bi != (nbits - 1)) {
sq_pair_i64_i64_i64_i64_ptr_i64_ptr_i64(b0, b1, MOD, P, (&(o0)), (&(o1)));
b0 = o0;
b1 = o1;
}
bi = (bi + 1);
}
pair0 = r0;
pair1 = r1;
g = (g + 1);
}
total = FLOW_CHECKED_MOD(((total + contrib)), (MOD));
c = (c + 1);
}
printf("%lld\n", total);
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>
func.func private @calloc(i64, i64) -> !llvm.ptr
func.func private @free(!llvm.ptr) -> ()
func.func @mul_pair(%arg0: i64, %arg1: i64, %arg2: i64, %arg3: i64, %arg4: i64, %arg5: i64, %arg6: !llvm.ptr, %arg7: !llvm.ptr) -> () {
%0 = arith.muli %arg5, %arg2 : i64
%1 = arith.subi %arg3, %0 : i64
%2 = arith.remsi %1, %arg4 : i64
%3 = arith.constant 0 : i32
%5 = arith.extsi %3 : i32 to i64
%4 = arith.cmpi slt, %2, %5 : i64
%6 = scf.if %4 -> (i64) {
%7 = arith.addi %2, %arg4 : i64
scf.yield %7 : i64
} else {
scf.yield %2 : i64
}
%8 = arith.muli %arg1, %arg2 : i64
%9 = arith.muli %arg0, %6 : i64
%10 = arith.addi %8, %9 : i64
%11 = arith.remsi %10, %arg4 : i64
%12 = arith.constant 0 : i32
%13 = arith.extsi %12 : i32 to i64
%14 = llvm.getelementptr %arg6[%13] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %11, %14 : i64, !llvm.ptr
%15 = arith.muli %arg1, %arg3 : i64
%16 = arith.muli %arg0, %arg2 : i64
%17 = arith.addi %15, %16 : i64
%18 = arith.remsi %17, %arg4 : i64
%19 = arith.constant 0 : i32
%20 = arith.extsi %19 : i32 to i64
%21 = llvm.getelementptr %arg7[%20] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %18, %21 : i64, !llvm.ptr
func.return
}
func.func @sq_pair(%arg0: i64, %arg1: i64, %arg2: i64, %arg3: i64, %arg4: !llvm.ptr, %arg5: !llvm.ptr) -> () {
%22 = arith.constant 2 : i32
%24 = arith.extsi %22 : i32 to i64
%23 = arith.muli %24, %arg1 : i64
%25 = arith.muli %arg3, %arg0 : i64
%26 = arith.subi %23, %25 : i64
%27 = arith.remsi %26, %arg2 : i64
%28 = arith.constant 0 : i32
%30 = arith.extsi %28 : i32 to i64
%29 = arith.cmpi slt, %27, %30 : i64
%31 = scf.if %29 -> (i64) {
%32 = arith.addi %27, %arg2 : i64
scf.yield %32 : i64
} else {
scf.yield %27 : i64
}
%33 = arith.muli %arg0, %31 : i64
%34 = arith.remsi %33, %arg2 : i64
%35 = arith.constant 0 : i32
%36 = arith.extsi %35 : i32 to i64
%37 = llvm.getelementptr %arg4[%36] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %34, %37 : i64, !llvm.ptr
%38 = arith.muli %arg1, %arg1 : i64
%39 = arith.muli %arg0, %arg0 : i64
%40 = arith.addi %38, %39 : i64
%41 = arith.remsi %40, %arg2 : i64
%42 = arith.constant 0 : i32
%43 = arith.extsi %42 : i32 to i64
%44 = llvm.getelementptr %arg5[%43] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %41, %44 : i64, !llvm.ptr
func.return
}
func.func @main() -> i32 {
%45 = arith.constant 987898789 : i32
%46 = arith.extsi %45 : i32 to i64
%47 = arith.constant 10 : i32
%48 = arith.extsi %47 : i32 to i64
%49 = arith.constant 2000 : i32
%50 = arith.extsi %49 : i32 to i64
%52 = arith.constant 1 : i32
%54 = arith.extsi %52 : i32 to i64
%53 = arith.addi %50, %54 : i64
%55 = arith.constant 1 : i32
%56 = arith.extsi %55 : i32 to i64
%51 = func.call @calloc(%53, %56) : (i64, i64) -> !llvm.ptr
%58 = arith.constant 1 : i32
%60 = arith.extsi %58 : i32 to i64
%59 = arith.addi %50, %60 : i64
%61 = arith.constant 1 : i32
%62 = arith.extsi %61 : i32 to i64
%57 = func.call @calloc(%59, %62) : (i64, i64) -> !llvm.ptr
%64 = arith.constant 4 : i32
%65 = arith.extsi %64 : i32 to i64
%63 = func.call @calloc(%50, %65) : (i64, i64) -> !llvm.ptr
%66 = llvm.mlir.zero : !llvm.ptr
%67 = llvm.icmp "eq" %51, %66 : !llvm.ptr
cf.cond_br %67, ^bb0, ^bb1
^bb0:
%68 = arith.constant 1 : i32
func.return %68 : i32
^bb1:
cf.br ^bb2
^bb2:
%69 = arith.constant 1 : i32
%70 = arith.constant 1 : i32
%71 = arith.trunci %69 : i32 to i8
%72 = arith.extsi %70 : i32 to i64
%73 = llvm.getelementptr %51[%72] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %71, %73 : i8, !llvm.ptr
%74 = arith.constant 0 : i32
%75 = arith.extsi %74 : i32 to i64
%76 = llvm.mlir.constant(1 : i64) : i64
%77 = llvm.alloca %76 x i64 : (i64) -> !llvm.ptr
llvm.store %75, %77 : i64, !llvm.ptr
%78 = arith.constant 2 : i32
%79 = arith.extsi %78 : i32 to i64
%80 = llvm.mlir.constant(1 : i64) : i64
%81 = llvm.alloca %80 x i64 : (i64) -> !llvm.ptr
llvm.store %79, %81 : i64, !llvm.ptr
cf.br ^bb3
^bb3:
%82 = llvm.load %81 : !llvm.ptr -> i64
%83 = arith.cmpi sle, %82, %50 : i64
cf.cond_br %83, ^bb4, ^bb5
^bb4:
%85 = llvm.load %81 : !llvm.ptr -> i64
%86 = llvm.getelementptr %57[%85] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%84 = llvm.load %86 : !llvm.ptr -> i8
%87 = arith.constant 0 : i32
%89 = arith.extsi %84 : i8 to i32
%88 = arith.cmpi eq, %89, %87 : i32
cf.cond_br %88, ^bb6, ^bb7
^bb6:
%90 = llvm.load %81 : !llvm.ptr -> i64
%91 = arith.trunci %90 : i64 to i32
%92 = llvm.load %77 : !llvm.ptr -> i64
%93 = llvm.getelementptr %63[%92] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %91, %93 : i32, !llvm.ptr
%94 = llvm.load %77 : !llvm.ptr -> i64
%95 = arith.constant 1 : i32
%97 = arith.extsi %95 : i32 to i64
%96 = arith.addi %94, %97 : i64
llvm.store %96, %77 : i64, !llvm.ptr
%98 = arith.constant 1 : i32
%100 = arith.constant 0 : i32
%99 = arith.subi %100, %98 : i32
%101 = llvm.load %81 : !llvm.ptr -> i64
%102 = arith.trunci %99 : i32 to i8
%103 = llvm.getelementptr %51[%101] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %102, %103 : i8, !llvm.ptr
cf.br ^bb8
^bb7:
cf.br ^bb8
^bb8:
%104 = arith.constant 0 : i32
%105 = arith.extsi %104 : i32 to i64
%106 = llvm.mlir.constant(1 : i64) : i64
%107 = llvm.alloca %106 x i64 : (i64) -> !llvm.ptr
llvm.store %105, %107 : i64, !llvm.ptr
cf.br ^bb9
^bb9:
%108 = llvm.load %107 : !llvm.ptr -> i64
%109 = llvm.load %77 : !llvm.ptr -> i64
%110 = arith.cmpi slt, %108, %109 : i64
cf.cond_br %110, ^bb10, ^bb11
^bb10:
%112 = llvm.load %107 : !llvm.ptr -> i64
%113 = llvm.getelementptr %63[%112] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%111 = llvm.load %113 : !llvm.ptr -> i32
%114 = arith.extsi %111 : i32 to i64
%115 = llvm.load %81 : !llvm.ptr -> i64
%116 = arith.muli %115, %114 : i64
%117 = arith.cmpi sgt, %116, %50 : i64
cf.cond_br %117, ^bb12, ^bb13
^bb12:
cf.br ^bb11
^bb13:
cf.br ^bb14
^bb14:
%118 = arith.constant 1 : i32
%119 = arith.trunci %118 : i32 to i8
%120 = llvm.getelementptr %57[%116] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %119, %120 : i8, !llvm.ptr
%121 = llvm.load %81 : !llvm.ptr -> i64
%122 = arith.remsi %121, %114 : i64
%123 = arith.constant 0 : i32
%125 = arith.extsi %123 : i32 to i64
%124 = arith.cmpi eq, %122, %125 : i64
cf.cond_br %124, ^bb15, ^bb16
^bb15:
%126 = arith.constant 0 : i32
%127 = arith.trunci %126 : i32 to i8
%128 = llvm.getelementptr %51[%116] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %127, %128 : i8, !llvm.ptr
cf.br ^bb11
^bb16:
cf.br ^bb17
^bb17:
%129 = arith.constant 0 : i32
%131 = llvm.load %81 : !llvm.ptr -> i64
%132 = llvm.getelementptr %51[%131] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%130 = llvm.load %132 : !llvm.ptr -> i8
%133 = arith.extsi %130 : i8 to i64
%135 = arith.extsi %129 : i32 to i64
%134 = arith.subi %135, %133 : i64
%136 = arith.trunci %134 : i64 to i8
%137 = llvm.getelementptr %51[%116] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %136, %137 : i8, !llvm.ptr
%138 = llvm.load %107 : !llvm.ptr -> i64
%139 = arith.constant 1 : i32
%141 = arith.extsi %139 : i32 to i64
%140 = arith.addi %138, %141 : i64
llvm.store %140, %107 : i64, !llvm.ptr
cf.br ^bb9
^bb11:
%142 = llvm.load %81 : !llvm.ptr -> i64
%143 = arith.constant 1 : i32
%145 = arith.extsi %143 : i32 to i64
%144 = arith.addi %142, %145 : i64
llvm.store %144, %81 : i64, !llvm.ptr
cf.br ^bb3
^bb5:
%147 = arith.constant 1 : i32
%149 = arith.extsi %147 : i32 to i64
%148 = arith.addi %50, %149 : i64
%150 = arith.constant 8 : i32
%151 = arith.extsi %150 : i32 to i64
%146 = func.call @calloc(%148, %151) : (i64, i64) -> !llvm.ptr
%152 = arith.constant 1 : i32
%153 = arith.extsi %152 : i32 to i64
%154 = llvm.mlir.constant(1 : i64) : i64
%155 = llvm.alloca %154 x i64 : (i64) -> !llvm.ptr
llvm.store %153, %155 : i64, !llvm.ptr
cf.br ^bb18
^bb18:
%156 = llvm.load %155 : !llvm.ptr -> i64
%157 = arith.cmpi sle, %156, %50 : i64
cf.cond_br %157, ^bb19, ^bb20
^bb19:
%158 = arith.constant 0 : i32
%159 = arith.extsi %158 : i32 to i64
%160 = llvm.mlir.constant(1 : i64) : i64
%161 = llvm.alloca %160 x i64 : (i64) -> !llvm.ptr
llvm.store %159, %161 : i64, !llvm.ptr
%162 = arith.constant 1 : i32
%163 = arith.extsi %162 : i32 to i64
%164 = llvm.mlir.constant(1 : i64) : i64
%165 = llvm.alloca %164 x i64 : (i64) -> !llvm.ptr
llvm.store %163, %165 : i64, !llvm.ptr
cf.br ^bb21
^bb21:
%166 = llvm.load %165 : !llvm.ptr -> i64
%167 = llvm.load %155 : !llvm.ptr -> i64
%168 = arith.cmpi sle, %166, %167 : i64
cf.cond_br %168, ^bb22, ^bb23
^bb22:
%170 = llvm.load %165 : !llvm.ptr -> i64
%171 = llvm.getelementptr %51[%170] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%169 = llvm.load %171 : !llvm.ptr -> i8
%172 = arith.extsi %169 : i8 to i64
%173 = arith.constant 0 : i32
%175 = arith.extsi %173 : i32 to i64
%174 = arith.cmpi ne, %172, %175 : i64
cf.cond_br %174, ^bb24, ^bb25
^bb24:
%176 = llvm.load %155 : !llvm.ptr -> i64
%177 = llvm.load %165 : !llvm.ptr -> i64
%178 = arith.divsi %176, %177 : i64
%179 = arith.constant 1 : i32
%181 = arith.extsi %179 : i32 to i64
%180 = arith.addi %178, %181 : i64
%182 = arith.constant 2 : i32
%184 = arith.extsi %182 : i32 to i64
%183 = arith.divsi %180, %184 : i64
%185 = llvm.load %161 : !llvm.ptr -> i64
%186 = arith.muli %172, %183 : i64
%187 = arith.muli %186, %183 : i64
%188 = arith.addi %185, %187 : i64
llvm.store %188, %161 : i64, !llvm.ptr
cf.br ^bb26
^bb25:
cf.br ^bb26
^bb26:
%189 = llvm.load %165 : !llvm.ptr -> i64
%190 = arith.constant 2 : i32
%192 = arith.extsi %190 : i32 to i64
%191 = arith.addi %189, %192 : i64
llvm.store %191, %165 : i64, !llvm.ptr
cf.br ^bb21
^bb23:
%193 = llvm.load %161 : !llvm.ptr -> i64
%194 = llvm.load %155 : !llvm.ptr -> i64
%195 = llvm.getelementptr %146[%194] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %193, %195 : i64, !llvm.ptr
%196 = llvm.load %155 : !llvm.ptr -> i64
%197 = arith.constant 1 : i32
%199 = arith.extsi %197 : i32 to i64
%198 = arith.addi %196, %199 : i64
llvm.store %198, %155 : i64, !llvm.ptr
cf.br ^bb18
^bb20:
%201 = arith.constant 1 : i32
%203 = arith.extsi %201 : i32 to i64
%202 = arith.addi %50, %203 : i64
%204 = arith.constant 8 : i32
%205 = arith.extsi %204 : i32 to i64
%200 = func.call @calloc(%202, %205) : (i64, i64) -> !llvm.ptr
%206 = arith.constant 0 : i32
%207 = arith.extsi %206 : i32 to i64
%208 = llvm.mlir.constant(1 : i64) : i64
%209 = llvm.alloca %208 x i64 : (i64) -> !llvm.ptr
llvm.store %207, %209 : i64, !llvm.ptr
%210 = arith.constant 1 : i32
%211 = arith.extsi %210 : i32 to i64
%212 = llvm.mlir.constant(1 : i64) : i64
%213 = llvm.alloca %212 x i64 : (i64) -> !llvm.ptr
llvm.store %211, %213 : i64, !llvm.ptr
cf.br ^bb27
^bb27:
%214 = llvm.load %213 : !llvm.ptr -> i64
%215 = arith.cmpi sle, %214, %50 : i64
cf.cond_br %215, ^bb28, ^bb29
^bb28:
%217 = llvm.load %213 : !llvm.ptr -> i64
%218 = arith.divsi %50, %217 : i64
%219 = llvm.getelementptr %146[%218] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%216 = llvm.load %219 : !llvm.ptr -> i64
%220 = llvm.load %213 : !llvm.ptr -> i64
%221 = llvm.getelementptr %200[%220] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %216, %221 : i64, !llvm.ptr
%222 = llvm.load %209 : !llvm.ptr -> i64
%224 = llvm.load %213 : !llvm.ptr -> i64
%225 = llvm.getelementptr %200[%224] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%223 = llvm.load %225 : !llvm.ptr -> i64
%226 = arith.addi %222, %223 : i64
llvm.store %226, %209 : i64, !llvm.ptr
%227 = llvm.load %213 : !llvm.ptr -> i64
%228 = arith.constant 1 : i32
%230 = arith.extsi %228 : i32 to i64
%229 = arith.addi %227, %230 : i64
llvm.store %229, %213 : i64, !llvm.ptr
cf.br ^bb27
^bb29:
%231 = arith.muli %50, %50 : i64
%232 = llvm.load %209 : !llvm.ptr -> i64
%233 = arith.subi %231, %232 : i64
%235 = arith.constant 2 : i32
%237 = arith.extsi %235 : i32 to i64
%236 = arith.addi %50, %237 : i64
%238 = arith.constant 8 : i32
%239 = arith.extsi %238 : i32 to i64
%234 = func.call @calloc(%236, %239) : (i64, i64) -> !llvm.ptr
%240 = arith.constant 0 : i32
%241 = arith.constant 0 : i32
%242 = arith.extsi %240 : i32 to i64
%243 = arith.extsi %241 : i32 to i64
%244 = llvm.getelementptr %234[%243] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %242, %244 : i64, !llvm.ptr
%245 = arith.constant 1 : i32
%246 = arith.constant 1 : i32
%247 = arith.extsi %245 : i32 to i64
%248 = arith.extsi %246 : i32 to i64
%249 = llvm.getelementptr %234[%248] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %247, %249 : i64, !llvm.ptr
%250 = arith.constant 2 : i32
%251 = arith.extsi %250 : i32 to i64
llvm.store %251, %81 : i64, !llvm.ptr
cf.br ^bb30
^bb30:
%252 = llvm.load %81 : !llvm.ptr -> i64
%253 = arith.constant 1 : i32
%255 = arith.extsi %253 : i32 to i64
%254 = arith.addi %50, %255 : i64
%256 = arith.cmpi sle, %252, %254 : i64
cf.cond_br %256, ^bb31, ^bb32
^bb31:
%258 = llvm.load %81 : !llvm.ptr -> i64
%259 = arith.constant 1 : i32
%261 = arith.extsi %259 : i32 to i64
%260 = arith.subi %258, %261 : i64
%262 = llvm.getelementptr %234[%260] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%257 = llvm.load %262 : !llvm.ptr -> i64
%263 = arith.muli %48, %257 : i64
%265 = llvm.load %81 : !llvm.ptr -> i64
%266 = arith.constant 2 : i32
%268 = arith.extsi %266 : i32 to i64
%267 = arith.subi %265, %268 : i64
%269 = llvm.getelementptr %234[%267] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%264 = llvm.load %269 : !llvm.ptr -> i64
%270 = arith.addi %263, %264 : i64
%271 = arith.remsi %270, %46 : i64
%272 = llvm.load %81 : !llvm.ptr -> i64
%273 = llvm.getelementptr %234[%272] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %271, %273 : i64, !llvm.ptr
%274 = llvm.load %81 : !llvm.ptr -> i64
%275 = arith.constant 1 : i32
%277 = arith.extsi %275 : i32 to i64
%276 = arith.addi %274, %277 : i64
llvm.store %276, %81 : i64, !llvm.ptr
cf.br ^bb30
^bb32:
%279 = arith.constant 64 : i32
%280 = arith.constant 1 : i32
%281 = arith.extsi %279 : i32 to i64
%282 = arith.extsi %280 : i32 to i64
%278 = func.call @calloc(%281, %282) : (i64, i64) -> !llvm.ptr
%283 = arith.constant 0 : i32
%284 = arith.extsi %283 : i32 to i64
%285 = arith.constant 0 : i32
%286 = arith.extsi %285 : i32 to i64
%287 = arith.constant 0 : i32
%288 = arith.extsi %287 : i32 to i64
%289 = llvm.mlir.constant(1 : i64) : i64
%290 = llvm.alloca %289 x i64 : (i64) -> !llvm.ptr
llvm.store %288, %290 : i64, !llvm.ptr
%291 = arith.constant 1 : i32
%292 = arith.extsi %291 : i32 to i64
%293 = llvm.mlir.constant(1 : i64) : i64
%294 = llvm.alloca %293 x i64 : (i64) -> !llvm.ptr
llvm.store %292, %294 : i64, !llvm.ptr
cf.br ^bb33
^bb33:
%295 = llvm.load %294 : !llvm.ptr -> i64
%296 = arith.cmpi sle, %295, %50 : i64
cf.cond_br %296, ^bb34, ^bb35
^bb34:
%297 = arith.constant 0 : i32
%298 = arith.extsi %297 : i32 to i64
%299 = llvm.mlir.constant(1 : i64) : i64
%300 = llvm.alloca %299 x i64 : (i64) -> !llvm.ptr
llvm.store %298, %300 : i64, !llvm.ptr
%301 = llvm.load %294 : !llvm.ptr -> i64
%302 = llvm.mlir.constant(1 : i64) : i64
%303 = llvm.alloca %302 x i64 : (i64) -> !llvm.ptr
llvm.store %301, %303 : i64, !llvm.ptr
cf.br ^bb36
^bb36:
%304 = llvm.load %303 : !llvm.ptr -> i64
%305 = arith.constant 0 : i32
%307 = arith.extsi %305 : i32 to i64
%306 = arith.cmpi sgt, %304, %307 : i64
cf.cond_br %306, ^bb37, ^bb38
^bb37:
%308 = llvm.load %303 : !llvm.ptr -> i64
%309 = arith.constant 1 : i32
%311 = arith.extsi %309 : i32 to i64
%310 = arith.andi %308, %311 : i64
%312 = arith.trunci %310 : i64 to i8
%313 = llvm.load %300 : !llvm.ptr -> i64
%314 = llvm.getelementptr %278[%313] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %312, %314 : i8, !llvm.ptr
%315 = llvm.load %303 : !llvm.ptr -> i64
%316 = arith.constant 1 : i32
%318 = arith.extsi %316 : i32 to i64
%317 = arith.shrsi %315, %318 : i64
llvm.store %317, %303 : i64, !llvm.ptr
%319 = llvm.load %300 : !llvm.ptr -> i64
%320 = arith.constant 1 : i32
%322 = arith.extsi %320 : i32 to i64
%321 = arith.addi %319, %322 : i64
llvm.store %321, %300 : i64, !llvm.ptr
cf.br ^bb36
^bb38:
%324 = llvm.load %294 : !llvm.ptr -> i64
%325 = llvm.getelementptr %234[%324] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%323 = llvm.load %325 : !llvm.ptr -> i64
%326 = llvm.mlir.constant(1 : i64) : i64
%327 = llvm.alloca %326 x i64 : (i64) -> !llvm.ptr
llvm.store %323, %327 : i64, !llvm.ptr
%329 = llvm.load %294 : !llvm.ptr -> i64
%330 = arith.constant 1 : i32
%332 = arith.extsi %330 : i32 to i64
%331 = arith.addi %329, %332 : i64
%333 = llvm.getelementptr %234[%331] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%328 = llvm.load %333 : !llvm.ptr -> i64
%334 = llvm.mlir.constant(1 : i64) : i64
%335 = llvm.alloca %334 x i64 : (i64) -> !llvm.ptr
llvm.store %328, %335 : i64, !llvm.ptr
%336 = arith.constant 1 : i32
%337 = arith.extsi %336 : i32 to i64
%338 = llvm.mlir.constant(1 : i64) : i64
%339 = llvm.alloca %338 x i64 : (i64) -> !llvm.ptr
llvm.store %337, %339 : i64, !llvm.ptr
%340 = llvm.load %294 : !llvm.ptr -> i64
%341 = arith.constant 1 : i32
%343 = arith.extsi %341 : i32 to i64
%342 = arith.andi %340, %343 : i64
%344 = arith.constant 1 : i32
%346 = arith.extsi %344 : i32 to i64
%345 = arith.cmpi eq, %342, %346 : i64
cf.cond_br %345, ^bb39, ^bb40
^bb39:
%348 = arith.constant 2 : i32
%349 = arith.extsi %348 : i32 to i64
%350 = llvm.getelementptr %234[%349] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%347 = llvm.load %350 : !llvm.ptr -> i64
llvm.store %347, %339 : i64, !llvm.ptr
cf.br ^bb41
^bb40:
cf.br ^bb41
^bb41:
%351 = arith.remsi %233, %46 : i64
%352 = llvm.load %339 : !llvm.ptr -> i64
%353 = arith.muli %351, %352 : i64
%354 = arith.remsi %353, %46 : i64
%355 = llvm.mlir.constant(1 : i64) : i64
%356 = llvm.alloca %355 x i64 : (i64) -> !llvm.ptr
llvm.store %354, %356 : i64, !llvm.ptr
%357 = arith.constant 1 : i32
%358 = arith.extsi %357 : i32 to i64
llvm.store %358, %213 : i64, !llvm.ptr
cf.br ^bb42
^bb42:
%359 = llvm.load %213 : !llvm.ptr -> i64
%360 = arith.cmpi sle, %359, %50 : i64
cf.cond_br %360, ^bb43, ^bb44
^bb43:
%361 = llvm.load %356 : !llvm.ptr -> i64
%363 = llvm.load %213 : !llvm.ptr -> i64
%364 = llvm.getelementptr %200[%363] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%362 = llvm.load %364 : !llvm.ptr -> i64
%365 = arith.remsi %362, %46 : i64
%366 = llvm.load %335 : !llvm.ptr -> i64
%367 = arith.muli %365, %366 : i64
%368 = arith.addi %361, %367 : i64
%369 = arith.remsi %368, %46 : i64
llvm.store %369, %356 : i64, !llvm.ptr
%370 = arith.constant 0 : i32
%371 = arith.extsi %370 : i32 to i64
%372 = llvm.mlir.constant(1 : i64) : i64
%373 = llvm.alloca %372 x i64 : (i64) -> !llvm.ptr
llvm.store %371, %373 : i64, !llvm.ptr
%374 = arith.constant 1 : i32
%375 = arith.extsi %374 : i32 to i64
%376 = llvm.mlir.constant(1 : i64) : i64
%377 = llvm.alloca %376 x i64 : (i64) -> !llvm.ptr
llvm.store %375, %377 : i64, !llvm.ptr
%378 = llvm.load %327 : !llvm.ptr -> i64
%379 = llvm.mlir.constant(1 : i64) : i64
%380 = llvm.alloca %379 x i64 : (i64) -> !llvm.ptr
llvm.store %378, %380 : i64, !llvm.ptr
%381 = llvm.load %335 : !llvm.ptr -> i64
%382 = llvm.mlir.constant(1 : i64) : i64
%383 = llvm.alloca %382 x i64 : (i64) -> !llvm.ptr
llvm.store %381, %383 : i64, !llvm.ptr
%384 = arith.constant 0 : i32
%385 = arith.extsi %384 : i32 to i64
%386 = llvm.mlir.constant(1 : i64) : i64
%387 = llvm.alloca %386 x i64 : (i64) -> !llvm.ptr
llvm.store %385, %387 : i64, !llvm.ptr
cf.br ^bb45
^bb45:
%388 = llvm.load %387 : !llvm.ptr -> i64
%389 = llvm.load %300 : !llvm.ptr -> i64
%390 = arith.cmpi slt, %388, %389 : i64
cf.cond_br %390, ^bb46, ^bb47
^bb46:
%392 = llvm.load %387 : !llvm.ptr -> i64
%393 = llvm.getelementptr %278[%392] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%391 = llvm.load %393 : !llvm.ptr -> i8
%394 = arith.constant 0 : i32
%396 = arith.extsi %391 : i8 to i32
%395 = arith.cmpi ne, %396, %394 : i32
cf.cond_br %395, ^bb48, ^bb49
^bb48:
%398 = llvm.load %373 : !llvm.ptr -> i64
%399 = llvm.load %377 : !llvm.ptr -> i64
%400 = llvm.load %380 : !llvm.ptr -> i64
%401 = llvm.load %383 : !llvm.ptr -> i64
%402 = llvm.mlir.constant(1 : i64) : i64
%403 = llvm.alloca %402 x i64 : (i64) -> !llvm.ptr
llvm.store %284, %403 : i64, !llvm.ptr
%404 = llvm.mlir.constant(1 : i64) : i64
%405 = llvm.alloca %404 x i64 : (i64) -> !llvm.ptr
llvm.store %286, %405 : i64, !llvm.ptr
func.call @mul_pair(%398, %399, %400, %401, %46, %48, %403, %405) : (i64, i64, i64, i64, i64, i64, !llvm.ptr, !llvm.ptr) -> ()
%406 = llvm.load %403 : !llvm.ptr -> i64
llvm.store %406, %373 : i64, !llvm.ptr
%407 = llvm.load %405 : !llvm.ptr -> i64
llvm.store %407, %377 : i64, !llvm.ptr
cf.br ^bb50
^bb49:
cf.br ^bb50
^bb50:
%408 = llvm.load %387 : !llvm.ptr -> i64
%409 = llvm.load %300 : !llvm.ptr -> i64
%410 = arith.constant 1 : i32
%412 = arith.extsi %410 : i32 to i64
%411 = arith.subi %409, %412 : i64
%413 = arith.cmpi ne, %408, %411 : i64
cf.cond_br %413, ^bb51, ^bb52
^bb51:
%415 = llvm.load %380 : !llvm.ptr -> i64
%416 = llvm.load %383 : !llvm.ptr -> i64
func.call @sq_pair(%415, %416, %46, %48, %403, %405) : (i64, i64, i64, i64, !llvm.ptr, !llvm.ptr) -> ()
%417 = llvm.load %403 : !llvm.ptr -> i64
llvm.store %417, %380 : i64, !llvm.ptr
%418 = llvm.load %405 : !llvm.ptr -> i64
llvm.store %418, %383 : i64, !llvm.ptr
cf.br ^bb53
^bb52:
cf.br ^bb53
^bb53:
%419 = llvm.load %387 : !llvm.ptr -> i64
%420 = arith.constant 1 : i32
%422 = arith.extsi %420 : i32 to i64
%421 = arith.addi %419, %422 : i64
llvm.store %421, %387 : i64, !llvm.ptr
cf.br ^bb45
^bb47:
%423 = llvm.load %373 : !llvm.ptr -> i64
llvm.store %423, %327 : i64, !llvm.ptr
%424 = llvm.load %377 : !llvm.ptr -> i64
llvm.store %424, %335 : i64, !llvm.ptr
%425 = llvm.load %213 : !llvm.ptr -> i64
%426 = arith.constant 1 : i32
%428 = arith.extsi %426 : i32 to i64
%427 = arith.addi %425, %428 : i64
llvm.store %427, %213 : i64, !llvm.ptr
cf.br ^bb42
^bb44:
%429 = llvm.load %290 : !llvm.ptr -> i64
%430 = llvm.load %356 : !llvm.ptr -> i64
%431 = arith.addi %429, %430 : i64
%432 = arith.remsi %431, %46 : i64
llvm.store %432, %290 : i64, !llvm.ptr
%433 = llvm.load %294 : !llvm.ptr -> i64
%434 = arith.constant 1 : i32
%436 = arith.extsi %434 : i32 to i64
%435 = arith.addi %433, %436 : i64
llvm.store %435, %294 : i64, !llvm.ptr
cf.br ^bb33
^bb35:
%437 = llvm.mlir.addressof @str_0 : !llvm.ptr
%438 = llvm.load %290 : !llvm.ptr -> i64
%439 = llvm.call @printf(%437, %438) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
%440 = arith.constant 0 : i32
func.return %440 : i32
}
}