Problem 940
Two-Dimensional Recurrence — matrix powering; S(50) mod 1123581313.
View problem on Project Euler
Performance comparison
| Metric | Our solution | Best known |
| Time complexity | O(n^2) | O(log n) |
| Space complexity | O(n^2) | O(n^2) |
| Approach | Flow solution | Matrix exponentiation |
| Verdict | Suboptimal |
Flow source
# Project Euler 940
# Two-Dimensional Recurrence — matrix powering; S(50) mod 1123581313.
extern {
function calloc(n: i64, size: i64) -> ptr<void>
function free(p: ptr<void>) -> void
}
const MOD: i64 = 1123581313
function mmul(A: ptr<i64>, B: ptr<i64>, R: ptr<i64>) -> void {
R[0] = (A[0] * B[0] + A[1] * B[2]) % MOD
R[1] = (A[0] * B[1] + A[1] * B[3]) % MOD
R[2] = (A[2] * B[0] + A[3] * B[2]) % MOD
R[3] = (A[2] * B[1] + A[3] * B[3]) % MOD
}
function mpow(base: ptr<i64>, exp: i64, out: ptr<i64>) -> void {
out[0] = 1
out[1] = 0
out[2] = 0
out[3] = 1
let tmp: ptr<i64> = calloc(4, 8)
let cur: ptr<i64> = calloc(4, 8)
cur[0] = base[0]
cur[1] = base[1]
cur[2] = base[2]
cur[3] = base[3]
let mut e: i64 = exp
while e > 0 {
if (e & 1) == 1 {
mmul(out, cur, tmp)
out[0] = tmp[0]
out[1] = tmp[1]
out[2] = tmp[2]
out[3] = tmp[3]
}
mmul(cur, cur, tmp)
cur[0] = tmp[0]
cur[1] = tmp[1]
cur[2] = tmp[2]
cur[3] = tmp[3]
e = e / 2
}
free(tmp)
free(cur)
}
function find_idx(vals: ptr<i64>, n: i64, key: i64) -> i64 {
let mut i: i64 = 0
while i < n {
if vals[i] == key { return i }
i = i + 1
}
return -1
}
function S(k: i64) -> i64 {
let fib: ptr<i64> = calloc(k + 1, 8)
fib[0] = 0
fib[1] = 1
let mut i: i64 = 2
while i <= k {
fib[i] = fib[i - 1] + fib[i - 2]
i = i + 1
}
let idx_vals: ptr<i64> = calloc(k, 8)
let mut nv: i64 = 0
let mut t: i64 = 2
while t <= k {
idx_vals[nv] = fib[t]
nv = nv + 1
t = t + 1
}
# unique sorted
let uniq: ptr<i64> = calloc(nv, 8)
let mut nu: i64 = 0
let mut a: i64 = 0
while a < nv {
let v: i64 = idx_vals[a]
if find_idx(uniq, nu, v) < 0 {
uniq[nu] = v
nu = nu + 1
}
a = a + 1
}
let MAT_M: ptr<i64> = calloc(4, 8)
MAT_M[0] = 1
MAT_M[1] = 1
MAT_M[2] = 3
MAT_M[3] = 2
let MAT_N: ptr<i64> = calloc(4, 8)
MAT_N[0] = MOD - 1
MAT_N[1] = 1
MAT_N[2] = 1
MAT_N[3] = 2
# Store matrices flat: nu * 4
let powM: ptr<i64> = calloc(nu * 4, 8)
let powN: ptr<i64> = calloc(nu * 4, 8)
let mut u: i64 = 0
while u < nu {
let outm: ptr<i64> = calloc(4, 8)
let outn: ptr<i64> = calloc(4, 8)
mpow(MAT_M, uniq[u], outm)
mpow(MAT_N, uniq[u], outn)
powM[u * 4 + 0] = outm[0]
powM[u * 4 + 1] = outm[1]
powM[u * 4 + 2] = outm[2]
powM[u * 4 + 3] = outm[3]
powN[u * 4 + 0] = outn[0]
powN[u * 4 + 1] = outn[1]
powN[u * 4 + 2] = outn[2]
powN[u * 4 + 3] = outn[3]
free(outm)
free(outn)
u = u + 1
}
let mut total: i64 = 0
let mut mi: i64 = 0
while mi < nv {
let m: i64 = idx_vals[mi]
let im: i64 = find_idx(uniq, nu, m)
let p0: i64 = (powM[im * 4 + 0] * 0 + powM[im * 4 + 1] * 1) % MOD
let p1: i64 = (powM[im * 4 + 2] * 0 + powM[im * 4 + 3] * 1) % MOD
let q0: i64 = (p0 + p1) % MOD
let mut ni: i64 = 0
while ni < nv {
let n: i64 = idx_vals[ni]
let inn: i64 = find_idx(uniq, nu, n)
let a_mn: i64 = (powN[inn * 4 + 0] * p0 + powN[inn * 4 + 1] * q0) % MOD
total = (total + a_mn) % MOD
ni = ni + 1
}
mi = mi + 1
}
free(powM)
free(powN)
free(MAT_M)
free(MAT_N)
free(uniq)
free(idx_vals)
free(fib)
return total
}
function main() -> i32 {
printf("%lld\n", S(50))
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 mmul_ptr_i64_ptr_i64_ptr_i64(int64_t* A, int64_t* B, int64_t* R);
void mpow_ptr_i64_i64_ptr_i64(int64_t* base, int64_t exp, int64_t* out);
int64_t find_idx_ptr_i64_i64_i64(int64_t* vals, int64_t n, int64_t key);
int64_t S_i64(int64_t k);
int32_t main(void);
static const int64_t MOD = 1123581313;
void mmul_ptr_i64_ptr_i64_ptr_i64(int64_t* A, int64_t* B, int64_t* R) {
R[0] = FLOW_CHECKED_MOD((((A[0] * B[0]) + (A[1] * B[2]))), (MOD));
R[1] = FLOW_CHECKED_MOD((((A[0] * B[1]) + (A[1] * B[3]))), (MOD));
R[2] = FLOW_CHECKED_MOD((((A[2] * B[0]) + (A[3] * B[2]))), (MOD));
R[3] = FLOW_CHECKED_MOD((((A[2] * B[1]) + (A[3] * B[3]))), (MOD));
}
void mpow_ptr_i64_i64_ptr_i64(int64_t* base, int64_t exp, int64_t* out) {
out[0] = 1;
out[1] = 0;
out[2] = 0;
out[3] = 1;
int64_t* tmp = (int64_t*)(calloc(4, 8));
int64_t* cur = (int64_t*)(calloc(4, 8));
cur[0] = base[0];
cur[1] = base[1];
cur[2] = base[2];
cur[3] = base[3];
int64_t e = exp;
while (e > 0) {
if ((e & 1) == 1) {
mmul_ptr_i64_ptr_i64_ptr_i64(out, cur, tmp);
out[0] = tmp[0];
out[1] = tmp[1];
out[2] = tmp[2];
out[3] = tmp[3];
}
mmul_ptr_i64_ptr_i64_ptr_i64(cur, cur, tmp);
cur[0] = tmp[0];
cur[1] = tmp[1];
cur[2] = tmp[2];
cur[3] = tmp[3];
e = FLOW_CHECKED_DIV((e), (2));
}
free(tmp);
free(cur);
}
int64_t find_idx_ptr_i64_i64_i64(int64_t* vals, int64_t n, int64_t key) {
int64_t i = 0;
while (i < n) {
if (vals[i] == key) {
return i;
}
i = (i + 1);
}
return (-1);
}
int64_t S_i64(int64_t k) {
int64_t* fib = (int64_t*)(calloc((k + 1), 8));
fib[0] = 0;
fib[1] = 1;
int64_t i = 2;
while (i <= k) {
fib[i] = (fib[(i - 1)] + fib[(i - 2)]);
i = (i + 1);
}
int64_t* idx_vals = (int64_t*)(calloc(k, 8));
int64_t nv = 0;
int64_t t = 2;
while (t <= k) {
idx_vals[nv] = fib[t];
nv = (nv + 1);
t = (t + 1);
}
int64_t* uniq = (int64_t*)(calloc(nv, 8));
int64_t nu = 0;
int64_t a = 0;
while (a < nv) {
int64_t v = idx_vals[a];
if (find_idx_ptr_i64_i64_i64(uniq, nu, v) < 0) {
uniq[nu] = v;
nu = (nu + 1);
}
a = (a + 1);
}
int64_t* MAT_M = (int64_t*)(calloc(4, 8));
MAT_M[0] = 1;
MAT_M[1] = 1;
MAT_M[2] = 3;
MAT_M[3] = 2;
int64_t* MAT_N = (int64_t*)(calloc(4, 8));
MAT_N[0] = (MOD - 1);
MAT_N[1] = 1;
MAT_N[2] = 1;
MAT_N[3] = 2;
int64_t* powM = (int64_t*)(calloc((nu * 4), 8));
int64_t* powN = (int64_t*)(calloc((nu * 4), 8));
int64_t u = 0;
while (u < nu) {
int64_t* outm = (int64_t*)(calloc(4, 8));
int64_t* outn = (int64_t*)(calloc(4, 8));
mpow_ptr_i64_i64_ptr_i64(MAT_M, uniq[u], outm);
mpow_ptr_i64_i64_ptr_i64(MAT_N, uniq[u], outn);
powM[((u * 4) + 0)] = outm[0];
powM[((u * 4) + 1)] = outm[1];
powM[((u * 4) + 2)] = outm[2];
powM[((u * 4) + 3)] = outm[3];
powN[((u * 4) + 0)] = outn[0];
powN[((u * 4) + 1)] = outn[1];
powN[((u * 4) + 2)] = outn[2];
powN[((u * 4) + 3)] = outn[3];
free(outm);
free(outn);
u = (u + 1);
}
int64_t total = 0;
int64_t mi = 0;
while (mi < nv) {
int64_t m = idx_vals[mi];
int64_t im = find_idx_ptr_i64_i64_i64(uniq, nu, m);
int64_t p0 = FLOW_CHECKED_MOD((((powM[((im * 4) + 0)] * 0) + (powM[((im * 4) + 1)] * 1))), (MOD));
int64_t p1 = FLOW_CHECKED_MOD((((powM[((im * 4) + 2)] * 0) + (powM[((im * 4) + 3)] * 1))), (MOD));
int64_t q0 = FLOW_CHECKED_MOD(((p0 + p1)), (MOD));
int64_t ni = 0;
while (ni < nv) {
int64_t n = idx_vals[ni];
int64_t inn = find_idx_ptr_i64_i64_i64(uniq, nu, n);
int64_t a_mn = FLOW_CHECKED_MOD((((powN[((inn * 4) + 0)] * p0) + (powN[((inn * 4) + 1)] * q0))), (MOD));
total = FLOW_CHECKED_MOD(((total + a_mn)), (MOD));
ni = (ni + 1);
}
mi = (mi + 1);
}
free(powM);
free(powN);
free(MAT_M);
free(MAT_N);
free(uniq);
free(idx_vals);
free(fib);
return total;
}
int32_t main(void) {
printf("%lld\n", S_i64(50));
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) -> ()
// Constant: MOD
llvm.mlir.global internal constant @MOD(1123581313 : i64) : i64
func.func @mmul(%arg0: !llvm.ptr, %arg1: !llvm.ptr, %arg2: !llvm.ptr) -> () {
%1 = arith.constant 0 : i32
%2 = arith.extsi %1 : i32 to i64
%3 = llvm.getelementptr %arg0[%2] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%0 = llvm.load %3 : !llvm.ptr -> i64
%5 = arith.constant 0 : i32
%6 = arith.extsi %5 : i32 to i64
%7 = llvm.getelementptr %arg1[%6] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%4 = llvm.load %7 : !llvm.ptr -> i64
%8 = arith.muli %0, %4 : i64
%10 = arith.constant 1 : i32
%11 = arith.extsi %10 : i32 to i64
%12 = llvm.getelementptr %arg0[%11] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%9 = llvm.load %12 : !llvm.ptr -> i64
%14 = arith.constant 2 : i32
%15 = arith.extsi %14 : i32 to i64
%16 = llvm.getelementptr %arg1[%15] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%13 = llvm.load %16 : !llvm.ptr -> i64
%17 = arith.muli %9, %13 : i64
%18 = arith.addi %8, %17 : i64
%19 = llvm.mlir.addressof @MOD : !llvm.ptr
%20 = llvm.load %19 : !llvm.ptr -> i64
%21 = arith.remsi %18, %20 : i64
%22 = arith.constant 0 : i32
%23 = arith.extsi %22 : i32 to i64
%24 = llvm.getelementptr %arg2[%23] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %21, %24 : i64, !llvm.ptr
%26 = arith.constant 0 : i32
%27 = arith.extsi %26 : i32 to i64
%28 = llvm.getelementptr %arg0[%27] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%25 = llvm.load %28 : !llvm.ptr -> i64
%30 = arith.constant 1 : i32
%31 = arith.extsi %30 : i32 to i64
%32 = llvm.getelementptr %arg1[%31] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%29 = llvm.load %32 : !llvm.ptr -> i64
%33 = arith.muli %25, %29 : i64
%35 = arith.constant 1 : i32
%36 = arith.extsi %35 : i32 to i64
%37 = llvm.getelementptr %arg0[%36] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%34 = llvm.load %37 : !llvm.ptr -> i64
%39 = arith.constant 3 : i32
%40 = arith.extsi %39 : i32 to i64
%41 = llvm.getelementptr %arg1[%40] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%38 = llvm.load %41 : !llvm.ptr -> i64
%42 = arith.muli %34, %38 : i64
%43 = arith.addi %33, %42 : i64
%44 = llvm.mlir.addressof @MOD : !llvm.ptr
%45 = llvm.load %44 : !llvm.ptr -> i64
%46 = arith.remsi %43, %45 : i64
%47 = arith.constant 1 : i32
%48 = arith.extsi %47 : i32 to i64
%49 = llvm.getelementptr %arg2[%48] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %46, %49 : i64, !llvm.ptr
%51 = arith.constant 2 : i32
%52 = arith.extsi %51 : i32 to i64
%53 = llvm.getelementptr %arg0[%52] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%50 = llvm.load %53 : !llvm.ptr -> i64
%55 = arith.constant 0 : i32
%56 = arith.extsi %55 : i32 to i64
%57 = llvm.getelementptr %arg1[%56] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%54 = llvm.load %57 : !llvm.ptr -> i64
%58 = arith.muli %50, %54 : i64
%60 = arith.constant 3 : i32
%61 = arith.extsi %60 : i32 to i64
%62 = llvm.getelementptr %arg0[%61] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%59 = llvm.load %62 : !llvm.ptr -> i64
%64 = arith.constant 2 : i32
%65 = arith.extsi %64 : i32 to i64
%66 = llvm.getelementptr %arg1[%65] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%63 = llvm.load %66 : !llvm.ptr -> i64
%67 = arith.muli %59, %63 : i64
%68 = arith.addi %58, %67 : i64
%69 = llvm.mlir.addressof @MOD : !llvm.ptr
%70 = llvm.load %69 : !llvm.ptr -> i64
%71 = arith.remsi %68, %70 : i64
%72 = arith.constant 2 : i32
%73 = arith.extsi %72 : i32 to i64
%74 = llvm.getelementptr %arg2[%73] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %71, %74 : i64, !llvm.ptr
%76 = arith.constant 2 : i32
%77 = arith.extsi %76 : i32 to i64
%78 = llvm.getelementptr %arg0[%77] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%75 = llvm.load %78 : !llvm.ptr -> i64
%80 = arith.constant 1 : i32
%81 = arith.extsi %80 : i32 to i64
%82 = llvm.getelementptr %arg1[%81] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%79 = llvm.load %82 : !llvm.ptr -> i64
%83 = arith.muli %75, %79 : i64
%85 = arith.constant 3 : i32
%86 = arith.extsi %85 : i32 to i64
%87 = llvm.getelementptr %arg0[%86] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%84 = llvm.load %87 : !llvm.ptr -> i64
%89 = arith.constant 3 : i32
%90 = arith.extsi %89 : i32 to i64
%91 = llvm.getelementptr %arg1[%90] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%88 = llvm.load %91 : !llvm.ptr -> i64
%92 = arith.muli %84, %88 : i64
%93 = arith.addi %83, %92 : i64
%94 = llvm.mlir.addressof @MOD : !llvm.ptr
%95 = llvm.load %94 : !llvm.ptr -> i64
%96 = arith.remsi %93, %95 : i64
%97 = arith.constant 3 : i32
%98 = arith.extsi %97 : i32 to i64
%99 = llvm.getelementptr %arg2[%98] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %96, %99 : i64, !llvm.ptr
func.return
}
func.func @mpow(%arg0: !llvm.ptr, %arg1: i64, %arg2: !llvm.ptr) -> () {
%100 = arith.constant 1 : i32
%101 = arith.constant 0 : i32
%102 = arith.extsi %100 : i32 to i64
%103 = arith.extsi %101 : i32 to i64
%104 = llvm.getelementptr %arg2[%103] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %102, %104 : i64, !llvm.ptr
%105 = arith.constant 0 : i32
%106 = arith.constant 1 : i32
%107 = arith.extsi %105 : i32 to i64
%108 = arith.extsi %106 : i32 to i64
%109 = llvm.getelementptr %arg2[%108] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %107, %109 : i64, !llvm.ptr
%110 = arith.constant 0 : i32
%111 = arith.constant 2 : i32
%112 = arith.extsi %110 : i32 to i64
%113 = arith.extsi %111 : i32 to i64
%114 = llvm.getelementptr %arg2[%113] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %112, %114 : i64, !llvm.ptr
%115 = arith.constant 1 : i32
%116 = arith.constant 3 : i32
%117 = arith.extsi %115 : i32 to i64
%118 = arith.extsi %116 : i32 to i64
%119 = llvm.getelementptr %arg2[%118] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %117, %119 : i64, !llvm.ptr
%121 = arith.constant 4 : i32
%122 = arith.constant 8 : i32
%123 = arith.extsi %121 : i32 to i64
%124 = arith.extsi %122 : i32 to i64
%120 = func.call @calloc(%123, %124) : (i64, i64) -> !llvm.ptr
%126 = arith.constant 4 : i32
%127 = arith.constant 8 : i32
%128 = arith.extsi %126 : i32 to i64
%129 = arith.extsi %127 : i32 to i64
%125 = func.call @calloc(%128, %129) : (i64, i64) -> !llvm.ptr
%131 = arith.constant 0 : i32
%132 = arith.extsi %131 : i32 to i64
%133 = llvm.getelementptr %arg0[%132] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%130 = llvm.load %133 : !llvm.ptr -> i64
%134 = arith.constant 0 : i32
%135 = arith.extsi %134 : i32 to i64
%136 = llvm.getelementptr %125[%135] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %130, %136 : i64, !llvm.ptr
%138 = arith.constant 1 : i32
%139 = arith.extsi %138 : i32 to i64
%140 = llvm.getelementptr %arg0[%139] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%137 = llvm.load %140 : !llvm.ptr -> i64
%141 = arith.constant 1 : i32
%142 = arith.extsi %141 : i32 to i64
%143 = llvm.getelementptr %125[%142] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %137, %143 : i64, !llvm.ptr
%145 = arith.constant 2 : i32
%146 = arith.extsi %145 : i32 to i64
%147 = llvm.getelementptr %arg0[%146] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%144 = llvm.load %147 : !llvm.ptr -> i64
%148 = arith.constant 2 : i32
%149 = arith.extsi %148 : i32 to i64
%150 = llvm.getelementptr %125[%149] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %144, %150 : i64, !llvm.ptr
%152 = arith.constant 3 : i32
%153 = arith.extsi %152 : i32 to i64
%154 = llvm.getelementptr %arg0[%153] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%151 = llvm.load %154 : !llvm.ptr -> i64
%155 = arith.constant 3 : i32
%156 = arith.extsi %155 : i32 to i64
%157 = llvm.getelementptr %125[%156] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %151, %157 : i64, !llvm.ptr
%158 = llvm.mlir.constant(1 : i64) : i64
%159 = llvm.alloca %158 x i64 : (i64) -> !llvm.ptr
llvm.store %arg1, %159 : i64, !llvm.ptr
cf.br ^bb0
^bb0:
%160 = llvm.load %159 : !llvm.ptr -> i64
%161 = arith.constant 0 : i32
%163 = arith.extsi %161 : i32 to i64
%162 = arith.cmpi sgt, %160, %163 : i64
cf.cond_br %162, ^bb1, ^bb2
^bb1:
%164 = llvm.load %159 : !llvm.ptr -> i64
%165 = arith.constant 1 : i32
%167 = arith.extsi %165 : i32 to i64
%166 = arith.andi %164, %167 : i64
%168 = arith.constant 1 : i32
%170 = arith.extsi %168 : i32 to i64
%169 = arith.cmpi eq, %166, %170 : i64
cf.cond_br %169, ^bb3, ^bb4
^bb3:
func.call @mmul(%arg2, %125, %120) : (!llvm.ptr, !llvm.ptr, !llvm.ptr) -> ()
%173 = arith.constant 0 : i32
%174 = arith.extsi %173 : i32 to i64
%175 = llvm.getelementptr %120[%174] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%172 = llvm.load %175 : !llvm.ptr -> i64
%176 = arith.constant 0 : i32
%177 = arith.extsi %176 : i32 to i64
%178 = llvm.getelementptr %arg2[%177] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %172, %178 : i64, !llvm.ptr
%180 = arith.constant 1 : i32
%181 = arith.extsi %180 : i32 to i64
%182 = llvm.getelementptr %120[%181] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%179 = llvm.load %182 : !llvm.ptr -> i64
%183 = arith.constant 1 : i32
%184 = arith.extsi %183 : i32 to i64
%185 = llvm.getelementptr %arg2[%184] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %179, %185 : i64, !llvm.ptr
%187 = arith.constant 2 : i32
%188 = arith.extsi %187 : i32 to i64
%189 = llvm.getelementptr %120[%188] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%186 = llvm.load %189 : !llvm.ptr -> i64
%190 = arith.constant 2 : i32
%191 = arith.extsi %190 : i32 to i64
%192 = llvm.getelementptr %arg2[%191] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %186, %192 : i64, !llvm.ptr
%194 = arith.constant 3 : i32
%195 = arith.extsi %194 : i32 to i64
%196 = llvm.getelementptr %120[%195] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%193 = llvm.load %196 : !llvm.ptr -> i64
%197 = arith.constant 3 : i32
%198 = arith.extsi %197 : i32 to i64
%199 = llvm.getelementptr %arg2[%198] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %193, %199 : i64, !llvm.ptr
cf.br ^bb5
^bb4:
cf.br ^bb5
^bb5:
func.call @mmul(%125, %125, %120) : (!llvm.ptr, !llvm.ptr, !llvm.ptr) -> ()
%202 = arith.constant 0 : i32
%203 = arith.extsi %202 : i32 to i64
%204 = llvm.getelementptr %120[%203] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%201 = llvm.load %204 : !llvm.ptr -> i64
%205 = arith.constant 0 : i32
%206 = arith.extsi %205 : i32 to i64
%207 = llvm.getelementptr %125[%206] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %201, %207 : i64, !llvm.ptr
%209 = arith.constant 1 : i32
%210 = arith.extsi %209 : i32 to i64
%211 = llvm.getelementptr %120[%210] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%208 = llvm.load %211 : !llvm.ptr -> i64
%212 = arith.constant 1 : i32
%213 = arith.extsi %212 : i32 to i64
%214 = llvm.getelementptr %125[%213] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %208, %214 : i64, !llvm.ptr
%216 = arith.constant 2 : i32
%217 = arith.extsi %216 : i32 to i64
%218 = llvm.getelementptr %120[%217] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%215 = llvm.load %218 : !llvm.ptr -> i64
%219 = arith.constant 2 : i32
%220 = arith.extsi %219 : i32 to i64
%221 = llvm.getelementptr %125[%220] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %215, %221 : i64, !llvm.ptr
%223 = arith.constant 3 : i32
%224 = arith.extsi %223 : i32 to i64
%225 = llvm.getelementptr %120[%224] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%222 = llvm.load %225 : !llvm.ptr -> i64
%226 = arith.constant 3 : i32
%227 = arith.extsi %226 : i32 to i64
%228 = llvm.getelementptr %125[%227] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %222, %228 : i64, !llvm.ptr
%229 = llvm.load %159 : !llvm.ptr -> i64
%230 = arith.constant 2 : i32
%232 = arith.extsi %230 : i32 to i64
%231 = arith.divsi %229, %232 : i64
llvm.store %231, %159 : i64, !llvm.ptr
cf.br ^bb0
^bb2:
func.call @free(%120) : (!llvm.ptr) -> ()
func.call @free(%125) : (!llvm.ptr) -> ()
func.return
}
func.func @find_idx(%arg0: !llvm.ptr, %arg1: i64, %arg2: i64) -> i64 {
%235 = arith.constant 0 : i32
%236 = arith.extsi %235 : i32 to i64
%237 = llvm.mlir.constant(1 : i64) : i64
%238 = llvm.alloca %237 x i64 : (i64) -> !llvm.ptr
llvm.store %236, %238 : i64, !llvm.ptr
cf.br ^bb6
^bb6:
%239 = llvm.load %238 : !llvm.ptr -> i64
%240 = arith.cmpi slt, %239, %arg1 : i64
cf.cond_br %240, ^bb7, ^bb8
^bb7:
%242 = llvm.load %238 : !llvm.ptr -> i64
%243 = llvm.getelementptr %arg0[%242] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%241 = llvm.load %243 : !llvm.ptr -> i64
%244 = arith.cmpi eq, %241, %arg2 : i64
cf.cond_br %244, ^bb9, ^bb10
^bb9:
%245 = llvm.load %238 : !llvm.ptr -> i64
func.return %245 : i64
^bb10:
cf.br ^bb11
^bb11:
%246 = llvm.load %238 : !llvm.ptr -> i64
%247 = arith.constant 1 : i32
%249 = arith.extsi %247 : i32 to i64
%248 = arith.addi %246, %249 : i64
llvm.store %248, %238 : i64, !llvm.ptr
cf.br ^bb6
^bb8:
%250 = arith.constant 1 : i32
%252 = arith.constant 0 : i32
%251 = arith.subi %252, %250 : i32
%253 = arith.extsi %251 : i32 to i64
func.return %253 : i64
}
func.func @S(%arg0: i64) -> i64 {
%255 = arith.constant 1 : i32
%257 = arith.extsi %255 : i32 to i64
%256 = arith.addi %arg0, %257 : i64
%258 = arith.constant 8 : i32
%259 = arith.extsi %258 : i32 to i64
%254 = func.call @calloc(%256, %259) : (i64, i64) -> !llvm.ptr
%260 = arith.constant 0 : i32
%261 = arith.constant 0 : i32
%262 = arith.extsi %260 : i32 to i64
%263 = arith.extsi %261 : i32 to i64
%264 = llvm.getelementptr %254[%263] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %262, %264 : i64, !llvm.ptr
%265 = arith.constant 1 : i32
%266 = arith.constant 1 : i32
%267 = arith.extsi %265 : i32 to i64
%268 = arith.extsi %266 : i32 to i64
%269 = llvm.getelementptr %254[%268] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %267, %269 : i64, !llvm.ptr
%270 = arith.constant 2 : i32
%271 = arith.extsi %270 : i32 to i64
%272 = llvm.mlir.constant(1 : i64) : i64
%273 = llvm.alloca %272 x i64 : (i64) -> !llvm.ptr
llvm.store %271, %273 : i64, !llvm.ptr
cf.br ^bb12
^bb12:
%274 = llvm.load %273 : !llvm.ptr -> i64
%275 = arith.cmpi sle, %274, %arg0 : i64
cf.cond_br %275, ^bb13, ^bb14
^bb13:
%277 = llvm.load %273 : !llvm.ptr -> i64
%278 = arith.constant 1 : i32
%280 = arith.extsi %278 : i32 to i64
%279 = arith.subi %277, %280 : i64
%281 = llvm.getelementptr %254[%279] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%276 = llvm.load %281 : !llvm.ptr -> i64
%283 = llvm.load %273 : !llvm.ptr -> i64
%284 = arith.constant 2 : i32
%286 = arith.extsi %284 : i32 to i64
%285 = arith.subi %283, %286 : i64
%287 = llvm.getelementptr %254[%285] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%282 = llvm.load %287 : !llvm.ptr -> i64
%288 = arith.addi %276, %282 : i64
%289 = llvm.load %273 : !llvm.ptr -> i64
%290 = llvm.getelementptr %254[%289] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %288, %290 : i64, !llvm.ptr
%291 = llvm.load %273 : !llvm.ptr -> i64
%292 = arith.constant 1 : i32
%294 = arith.extsi %292 : i32 to i64
%293 = arith.addi %291, %294 : i64
llvm.store %293, %273 : i64, !llvm.ptr
cf.br ^bb12
^bb14:
%296 = arith.constant 8 : i32
%297 = arith.extsi %296 : i32 to i64
%295 = func.call @calloc(%arg0, %297) : (i64, i64) -> !llvm.ptr
%298 = arith.constant 0 : i32
%299 = arith.extsi %298 : i32 to i64
%300 = llvm.mlir.constant(1 : i64) : i64
%301 = llvm.alloca %300 x i64 : (i64) -> !llvm.ptr
llvm.store %299, %301 : i64, !llvm.ptr
%302 = arith.constant 2 : i32
%303 = arith.extsi %302 : i32 to i64
%304 = llvm.mlir.constant(1 : i64) : i64
%305 = llvm.alloca %304 x i64 : (i64) -> !llvm.ptr
llvm.store %303, %305 : i64, !llvm.ptr
cf.br ^bb15
^bb15:
%306 = llvm.load %305 : !llvm.ptr -> i64
%307 = arith.cmpi sle, %306, %arg0 : i64
cf.cond_br %307, ^bb16, ^bb17
^bb16:
%309 = llvm.load %305 : !llvm.ptr -> i64
%310 = llvm.getelementptr %254[%309] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%308 = llvm.load %310 : !llvm.ptr -> i64
%311 = llvm.load %301 : !llvm.ptr -> i64
%312 = llvm.getelementptr %295[%311] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %308, %312 : i64, !llvm.ptr
%313 = llvm.load %301 : !llvm.ptr -> i64
%314 = arith.constant 1 : i32
%316 = arith.extsi %314 : i32 to i64
%315 = arith.addi %313, %316 : i64
llvm.store %315, %301 : i64, !llvm.ptr
%317 = llvm.load %305 : !llvm.ptr -> i64
%318 = arith.constant 1 : i32
%320 = arith.extsi %318 : i32 to i64
%319 = arith.addi %317, %320 : i64
llvm.store %319, %305 : i64, !llvm.ptr
cf.br ^bb15
^bb17:
%322 = llvm.load %301 : !llvm.ptr -> i64
%323 = arith.constant 8 : i32
%324 = arith.extsi %323 : i32 to i64
%321 = func.call @calloc(%322, %324) : (i64, i64) -> !llvm.ptr
%325 = arith.constant 0 : i32
%326 = arith.extsi %325 : i32 to i64
%327 = llvm.mlir.constant(1 : i64) : i64
%328 = llvm.alloca %327 x i64 : (i64) -> !llvm.ptr
llvm.store %326, %328 : i64, !llvm.ptr
%329 = arith.constant 0 : i32
%330 = arith.extsi %329 : i32 to i64
%331 = llvm.mlir.constant(1 : i64) : i64
%332 = llvm.alloca %331 x i64 : (i64) -> !llvm.ptr
llvm.store %330, %332 : i64, !llvm.ptr
cf.br ^bb18
^bb18:
%333 = llvm.load %332 : !llvm.ptr -> i64
%334 = llvm.load %301 : !llvm.ptr -> i64
%335 = arith.cmpi slt, %333, %334 : i64
cf.cond_br %335, ^bb19, ^bb20
^bb19:
%337 = llvm.load %332 : !llvm.ptr -> i64
%338 = llvm.getelementptr %295[%337] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%336 = llvm.load %338 : !llvm.ptr -> i64
%340 = llvm.load %328 : !llvm.ptr -> i64
%339 = func.call @find_idx(%321, %340, %336) : (!llvm.ptr, i64, i64) -> i64
%341 = arith.constant 0 : i32
%343 = arith.extsi %341 : i32 to i64
%342 = arith.cmpi slt, %339, %343 : i64
cf.cond_br %342, ^bb21, ^bb22
^bb21:
%344 = llvm.load %328 : !llvm.ptr -> i64
%345 = llvm.getelementptr %321[%344] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %336, %345 : i64, !llvm.ptr
%346 = llvm.load %328 : !llvm.ptr -> i64
%347 = arith.constant 1 : i32
%349 = arith.extsi %347 : i32 to i64
%348 = arith.addi %346, %349 : i64
llvm.store %348, %328 : i64, !llvm.ptr
cf.br ^bb23
^bb22:
cf.br ^bb23
^bb23:
%350 = llvm.load %332 : !llvm.ptr -> i64
%351 = arith.constant 1 : i32
%353 = arith.extsi %351 : i32 to i64
%352 = arith.addi %350, %353 : i64
llvm.store %352, %332 : i64, !llvm.ptr
cf.br ^bb18
^bb20:
%355 = arith.constant 4 : i32
%356 = arith.constant 8 : i32
%357 = arith.extsi %355 : i32 to i64
%358 = arith.extsi %356 : i32 to i64
%354 = func.call @calloc(%357, %358) : (i64, i64) -> !llvm.ptr
%359 = arith.constant 1 : i32
%360 = arith.constant 0 : i32
%361 = arith.extsi %359 : i32 to i64
%362 = arith.extsi %360 : i32 to i64
%363 = llvm.getelementptr %354[%362] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %361, %363 : i64, !llvm.ptr
%364 = arith.constant 1 : i32
%365 = arith.constant 1 : i32
%366 = arith.extsi %364 : i32 to i64
%367 = arith.extsi %365 : i32 to i64
%368 = llvm.getelementptr %354[%367] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %366, %368 : i64, !llvm.ptr
%369 = arith.constant 3 : i32
%370 = arith.constant 2 : i32
%371 = arith.extsi %369 : i32 to i64
%372 = arith.extsi %370 : i32 to i64
%373 = llvm.getelementptr %354[%372] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %371, %373 : i64, !llvm.ptr
%374 = arith.constant 2 : i32
%375 = arith.constant 3 : i32
%376 = arith.extsi %374 : i32 to i64
%377 = arith.extsi %375 : i32 to i64
%378 = llvm.getelementptr %354[%377] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %376, %378 : i64, !llvm.ptr
%380 = arith.constant 4 : i32
%381 = arith.constant 8 : i32
%382 = arith.extsi %380 : i32 to i64
%383 = arith.extsi %381 : i32 to i64
%379 = func.call @calloc(%382, %383) : (i64, i64) -> !llvm.ptr
%384 = llvm.mlir.addressof @MOD : !llvm.ptr
%385 = llvm.load %384 : !llvm.ptr -> i64
%386 = arith.constant 1 : i32
%388 = arith.extsi %386 : i32 to i64
%387 = arith.subi %385, %388 : i64
%389 = arith.constant 0 : i32
%390 = arith.extsi %389 : i32 to i64
%391 = llvm.getelementptr %379[%390] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %387, %391 : i64, !llvm.ptr
%392 = arith.constant 1 : i32
%393 = arith.constant 1 : i32
%394 = arith.extsi %392 : i32 to i64
%395 = arith.extsi %393 : i32 to i64
%396 = llvm.getelementptr %379[%395] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %394, %396 : i64, !llvm.ptr
%397 = arith.constant 1 : i32
%398 = arith.constant 2 : i32
%399 = arith.extsi %397 : i32 to i64
%400 = arith.extsi %398 : i32 to i64
%401 = llvm.getelementptr %379[%400] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %399, %401 : i64, !llvm.ptr
%402 = arith.constant 2 : i32
%403 = arith.constant 3 : i32
%404 = arith.extsi %402 : i32 to i64
%405 = arith.extsi %403 : i32 to i64
%406 = llvm.getelementptr %379[%405] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %404, %406 : i64, !llvm.ptr
%408 = llvm.load %328 : !llvm.ptr -> i64
%409 = arith.constant 4 : i32
%411 = arith.extsi %409 : i32 to i64
%410 = arith.muli %408, %411 : i64
%412 = arith.constant 8 : i32
%413 = arith.extsi %412 : i32 to i64
%407 = func.call @calloc(%410, %413) : (i64, i64) -> !llvm.ptr
%415 = llvm.load %328 : !llvm.ptr -> i64
%416 = arith.constant 4 : i32
%418 = arith.extsi %416 : i32 to i64
%417 = arith.muli %415, %418 : i64
%419 = arith.constant 8 : i32
%420 = arith.extsi %419 : i32 to i64
%414 = func.call @calloc(%417, %420) : (i64, i64) -> !llvm.ptr
%421 = arith.constant 0 : i32
%422 = arith.extsi %421 : i32 to i64
%423 = llvm.mlir.constant(1 : i64) : i64
%424 = llvm.alloca %423 x i64 : (i64) -> !llvm.ptr
llvm.store %422, %424 : i64, !llvm.ptr
cf.br ^bb24
^bb24:
%425 = llvm.load %424 : !llvm.ptr -> i64
%426 = llvm.load %328 : !llvm.ptr -> i64
%427 = arith.cmpi slt, %425, %426 : i64
cf.cond_br %427, ^bb25, ^bb26
^bb25:
%429 = arith.constant 4 : i32
%430 = arith.constant 8 : i32
%431 = arith.extsi %429 : i32 to i64
%432 = arith.extsi %430 : i32 to i64
%428 = func.call @calloc(%431, %432) : (i64, i64) -> !llvm.ptr
%434 = arith.constant 4 : i32
%435 = arith.constant 8 : i32
%436 = arith.extsi %434 : i32 to i64
%437 = arith.extsi %435 : i32 to i64
%433 = func.call @calloc(%436, %437) : (i64, i64) -> !llvm.ptr
%440 = llvm.load %424 : !llvm.ptr -> i64
%441 = llvm.getelementptr %321[%440] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%439 = llvm.load %441 : !llvm.ptr -> i64
func.call @mpow(%354, %439, %428) : (!llvm.ptr, i64, !llvm.ptr) -> ()
%444 = llvm.load %424 : !llvm.ptr -> i64
%445 = llvm.getelementptr %321[%444] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%443 = llvm.load %445 : !llvm.ptr -> i64
func.call @mpow(%379, %443, %433) : (!llvm.ptr, i64, !llvm.ptr) -> ()
%447 = arith.constant 0 : i32
%448 = arith.extsi %447 : i32 to i64
%449 = llvm.getelementptr %428[%448] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%446 = llvm.load %449 : !llvm.ptr -> i64
%450 = llvm.load %424 : !llvm.ptr -> i64
%451 = arith.constant 4 : i32
%453 = arith.extsi %451 : i32 to i64
%452 = arith.muli %450, %453 : i64
%454 = arith.constant 0 : i32
%456 = arith.extsi %454 : i32 to i64
%455 = arith.addi %452, %456 : i64
%457 = llvm.getelementptr %407[%455] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %446, %457 : i64, !llvm.ptr
%459 = arith.constant 1 : i32
%460 = arith.extsi %459 : i32 to i64
%461 = llvm.getelementptr %428[%460] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%458 = llvm.load %461 : !llvm.ptr -> i64
%462 = llvm.load %424 : !llvm.ptr -> i64
%463 = arith.constant 4 : i32
%465 = arith.extsi %463 : i32 to i64
%464 = arith.muli %462, %465 : i64
%466 = arith.constant 1 : i32
%468 = arith.extsi %466 : i32 to i64
%467 = arith.addi %464, %468 : i64
%469 = llvm.getelementptr %407[%467] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %458, %469 : i64, !llvm.ptr
%471 = arith.constant 2 : i32
%472 = arith.extsi %471 : i32 to i64
%473 = llvm.getelementptr %428[%472] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%470 = llvm.load %473 : !llvm.ptr -> i64
%474 = llvm.load %424 : !llvm.ptr -> i64
%475 = arith.constant 4 : i32
%477 = arith.extsi %475 : i32 to i64
%476 = arith.muli %474, %477 : i64
%478 = arith.constant 2 : i32
%480 = arith.extsi %478 : i32 to i64
%479 = arith.addi %476, %480 : i64
%481 = llvm.getelementptr %407[%479] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %470, %481 : i64, !llvm.ptr
%483 = arith.constant 3 : i32
%484 = arith.extsi %483 : i32 to i64
%485 = llvm.getelementptr %428[%484] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%482 = llvm.load %485 : !llvm.ptr -> i64
%486 = llvm.load %424 : !llvm.ptr -> i64
%487 = arith.constant 4 : i32
%489 = arith.extsi %487 : i32 to i64
%488 = arith.muli %486, %489 : i64
%490 = arith.constant 3 : i32
%492 = arith.extsi %490 : i32 to i64
%491 = arith.addi %488, %492 : i64
%493 = llvm.getelementptr %407[%491] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %482, %493 : i64, !llvm.ptr
%495 = arith.constant 0 : i32
%496 = arith.extsi %495 : i32 to i64
%497 = llvm.getelementptr %433[%496] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%494 = llvm.load %497 : !llvm.ptr -> i64
%498 = llvm.load %424 : !llvm.ptr -> i64
%499 = arith.constant 4 : i32
%501 = arith.extsi %499 : i32 to i64
%500 = arith.muli %498, %501 : i64
%502 = arith.constant 0 : i32
%504 = arith.extsi %502 : i32 to i64
%503 = arith.addi %500, %504 : i64
%505 = llvm.getelementptr %414[%503] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %494, %505 : i64, !llvm.ptr
%507 = arith.constant 1 : i32
%508 = arith.extsi %507 : i32 to i64
%509 = llvm.getelementptr %433[%508] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%506 = llvm.load %509 : !llvm.ptr -> i64
%510 = llvm.load %424 : !llvm.ptr -> i64
%511 = arith.constant 4 : i32
%513 = arith.extsi %511 : i32 to i64
%512 = arith.muli %510, %513 : i64
%514 = arith.constant 1 : i32
%516 = arith.extsi %514 : i32 to i64
%515 = arith.addi %512, %516 : i64
%517 = llvm.getelementptr %414[%515] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %506, %517 : i64, !llvm.ptr
%519 = arith.constant 2 : i32
%520 = arith.extsi %519 : i32 to i64
%521 = llvm.getelementptr %433[%520] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%518 = llvm.load %521 : !llvm.ptr -> i64
%522 = llvm.load %424 : !llvm.ptr -> i64
%523 = arith.constant 4 : i32
%525 = arith.extsi %523 : i32 to i64
%524 = arith.muli %522, %525 : i64
%526 = arith.constant 2 : i32
%528 = arith.extsi %526 : i32 to i64
%527 = arith.addi %524, %528 : i64
%529 = llvm.getelementptr %414[%527] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %518, %529 : i64, !llvm.ptr
%531 = arith.constant 3 : i32
%532 = arith.extsi %531 : i32 to i64
%533 = llvm.getelementptr %433[%532] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%530 = llvm.load %533 : !llvm.ptr -> i64
%534 = llvm.load %424 : !llvm.ptr -> i64
%535 = arith.constant 4 : i32
%537 = arith.extsi %535 : i32 to i64
%536 = arith.muli %534, %537 : i64
%538 = arith.constant 3 : i32
%540 = arith.extsi %538 : i32 to i64
%539 = arith.addi %536, %540 : i64
%541 = llvm.getelementptr %414[%539] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %530, %541 : i64, !llvm.ptr
func.call @free(%428) : (!llvm.ptr) -> ()
func.call @free(%433) : (!llvm.ptr) -> ()
%544 = llvm.load %424 : !llvm.ptr -> i64
%545 = arith.constant 1 : i32
%547 = arith.extsi %545 : i32 to i64
%546 = arith.addi %544, %547 : i64
llvm.store %546, %424 : i64, !llvm.ptr
cf.br ^bb24
^bb26:
%548 = arith.constant 0 : i32
%549 = arith.extsi %548 : i32 to i64
%550 = llvm.mlir.constant(1 : i64) : i64
%551 = llvm.alloca %550 x i64 : (i64) -> !llvm.ptr
llvm.store %549, %551 : i64, !llvm.ptr
%552 = arith.constant 0 : i32
%553 = arith.extsi %552 : i32 to i64
%554 = llvm.mlir.constant(1 : i64) : i64
%555 = llvm.alloca %554 x i64 : (i64) -> !llvm.ptr
llvm.store %553, %555 : i64, !llvm.ptr
cf.br ^bb27
^bb27:
%556 = llvm.load %555 : !llvm.ptr -> i64
%557 = llvm.load %301 : !llvm.ptr -> i64
%558 = arith.cmpi slt, %556, %557 : i64
cf.cond_br %558, ^bb28, ^bb29
^bb28:
%560 = llvm.load %555 : !llvm.ptr -> i64
%561 = llvm.getelementptr %295[%560] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%559 = llvm.load %561 : !llvm.ptr -> i64
%563 = llvm.load %328 : !llvm.ptr -> i64
%562 = func.call @find_idx(%321, %563, %559) : (!llvm.ptr, i64, i64) -> i64
%565 = arith.constant 4 : i32
%567 = arith.extsi %565 : i32 to i64
%566 = arith.muli %562, %567 : i64
%568 = arith.constant 0 : i32
%570 = arith.extsi %568 : i32 to i64
%569 = arith.addi %566, %570 : i64
%571 = llvm.getelementptr %407[%569] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%564 = llvm.load %571 : !llvm.ptr -> i64
%572 = arith.constant 0 : i32
%574 = arith.extsi %572 : i32 to i64
%573 = arith.muli %564, %574 : i64
%576 = arith.constant 4 : i32
%578 = arith.extsi %576 : i32 to i64
%577 = arith.muli %562, %578 : i64
%579 = arith.constant 1 : i32
%581 = arith.extsi %579 : i32 to i64
%580 = arith.addi %577, %581 : i64
%582 = llvm.getelementptr %407[%580] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%575 = llvm.load %582 : !llvm.ptr -> i64
%583 = arith.constant 1 : i32
%585 = arith.extsi %583 : i32 to i64
%584 = arith.muli %575, %585 : i64
%586 = arith.addi %573, %584 : i64
%587 = llvm.mlir.addressof @MOD : !llvm.ptr
%588 = llvm.load %587 : !llvm.ptr -> i64
%589 = arith.remsi %586, %588 : i64
%591 = arith.constant 4 : i32
%593 = arith.extsi %591 : i32 to i64
%592 = arith.muli %562, %593 : i64
%594 = arith.constant 2 : i32
%596 = arith.extsi %594 : i32 to i64
%595 = arith.addi %592, %596 : i64
%597 = llvm.getelementptr %407[%595] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%590 = llvm.load %597 : !llvm.ptr -> i64
%598 = arith.constant 0 : i32
%600 = arith.extsi %598 : i32 to i64
%599 = arith.muli %590, %600 : i64
%602 = arith.constant 4 : i32
%604 = arith.extsi %602 : i32 to i64
%603 = arith.muli %562, %604 : i64
%605 = arith.constant 3 : i32
%607 = arith.extsi %605 : i32 to i64
%606 = arith.addi %603, %607 : i64
%608 = llvm.getelementptr %407[%606] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%601 = llvm.load %608 : !llvm.ptr -> i64
%609 = arith.constant 1 : i32
%611 = arith.extsi %609 : i32 to i64
%610 = arith.muli %601, %611 : i64
%612 = arith.addi %599, %610 : i64
%613 = llvm.mlir.addressof @MOD : !llvm.ptr
%614 = llvm.load %613 : !llvm.ptr -> i64
%615 = arith.remsi %612, %614 : i64
%616 = arith.addi %589, %615 : i64
%617 = llvm.mlir.addressof @MOD : !llvm.ptr
%618 = llvm.load %617 : !llvm.ptr -> i64
%619 = arith.remsi %616, %618 : i64
%620 = arith.constant 0 : i32
%621 = arith.extsi %620 : i32 to i64
%622 = llvm.mlir.constant(1 : i64) : i64
%623 = llvm.alloca %622 x i64 : (i64) -> !llvm.ptr
llvm.store %621, %623 : i64, !llvm.ptr
cf.br ^bb30
^bb30:
%624 = llvm.load %623 : !llvm.ptr -> i64
%625 = llvm.load %301 : !llvm.ptr -> i64
%626 = arith.cmpi slt, %624, %625 : i64
cf.cond_br %626, ^bb31, ^bb32
^bb31:
%628 = llvm.load %623 : !llvm.ptr -> i64
%629 = llvm.getelementptr %295[%628] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%627 = llvm.load %629 : !llvm.ptr -> i64
%631 = llvm.load %328 : !llvm.ptr -> i64
%630 = func.call @find_idx(%321, %631, %627) : (!llvm.ptr, i64, i64) -> i64
%633 = arith.constant 4 : i32
%635 = arith.extsi %633 : i32 to i64
%634 = arith.muli %630, %635 : i64
%636 = arith.constant 0 : i32
%638 = arith.extsi %636 : i32 to i64
%637 = arith.addi %634, %638 : i64
%639 = llvm.getelementptr %414[%637] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%632 = llvm.load %639 : !llvm.ptr -> i64
%640 = arith.muli %632, %589 : i64
%642 = arith.constant 4 : i32
%644 = arith.extsi %642 : i32 to i64
%643 = arith.muli %630, %644 : i64
%645 = arith.constant 1 : i32
%647 = arith.extsi %645 : i32 to i64
%646 = arith.addi %643, %647 : i64
%648 = llvm.getelementptr %414[%646] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%641 = llvm.load %648 : !llvm.ptr -> i64
%649 = arith.muli %641, %619 : i64
%650 = arith.addi %640, %649 : i64
%651 = llvm.mlir.addressof @MOD : !llvm.ptr
%652 = llvm.load %651 : !llvm.ptr -> i64
%653 = arith.remsi %650, %652 : i64
%654 = llvm.load %551 : !llvm.ptr -> i64
%655 = arith.addi %654, %653 : i64
%656 = llvm.mlir.addressof @MOD : !llvm.ptr
%657 = llvm.load %656 : !llvm.ptr -> i64
%658 = arith.remsi %655, %657 : i64
llvm.store %658, %551 : i64, !llvm.ptr
%659 = llvm.load %623 : !llvm.ptr -> i64
%660 = arith.constant 1 : i32
%662 = arith.extsi %660 : i32 to i64
%661 = arith.addi %659, %662 : i64
llvm.store %661, %623 : i64, !llvm.ptr
cf.br ^bb30
^bb32:
%663 = llvm.load %555 : !llvm.ptr -> i64
%664 = arith.constant 1 : i32
%666 = arith.extsi %664 : i32 to i64
%665 = arith.addi %663, %666 : i64
llvm.store %665, %555 : i64, !llvm.ptr
cf.br ^bb27
^bb29:
func.call @free(%407) : (!llvm.ptr) -> ()
func.call @free(%414) : (!llvm.ptr) -> ()
func.call @free(%354) : (!llvm.ptr) -> ()
func.call @free(%379) : (!llvm.ptr) -> ()
func.call @free(%321) : (!llvm.ptr) -> ()
func.call @free(%295) : (!llvm.ptr) -> ()
func.call @free(%254) : (!llvm.ptr) -> ()
%674 = llvm.load %551 : !llvm.ptr -> i64
func.return %674 : i64
}
func.func @main() -> i32 {
%675 = llvm.mlir.addressof @str_0 : !llvm.ptr
%677 = arith.constant 50 : i32
%678 = arith.extsi %677 : i32 to i64
%676 = func.call @S(%678) : (i64) -> i64
%679 = llvm.call @printf(%675, %676) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
%680 = arith.constant 0 : i32
func.return %680 : i32
}
}