Problem 434
Sum of R(m,n) for 1<=m,n<=100: connected braced grids mod 1000000033.
View problem on Project Euler
Performance comparison
| Metric | Our solution | Best known |
| Time complexity | O(n^3) | O(n log log n) |
| Space complexity | O(n) | O(n) |
| Approach | Flow solution | Sieve or enumeration |
| Verdict | Suboptimal |
Flow source
# Project Euler 434
# Sum of R(m,n) for 1<=m,n<=100: connected braced grids mod 1000000033.
extern {
function calloc(n: i64, size: i64) -> ptr<void>
function free(p: ptr<void>) -> void
}
function main() -> i32 {
let N: i32 = 100
let MOD: i64 = 1000000033
let pow2: ptr<i64> = calloc((N * N + 1) as i64, 8)
let binom: ptr<i64> = calloc(((N + 1) * (N + 1)) as i64, 8)
let R: ptr<i64> = calloc(((N + 1) * (N + 1)) as i64, 8)
if pow2 == null || binom == null || R == null { return 1 }
pow2[0] = 1
let mut k: i32 = 1
while k <= N * N {
pow2[k] = (pow2[k - 1] * 2) % MOD
k = k + 1
}
let mut n: i32 = 0
while n <= N {
binom[n * (N + 1) + 0] = 1
binom[n * (N + 1) + n] = 1
let mut j: i32 = 1
while j < n {
binom[n * (N + 1) + j] = (binom[(n - 1) * (N + 1) + (j - 1)] + binom[(n - 1) * (N + 1) + j]) % MOD
j = j + 1
}
n = n + 1
}
R[1 * (N + 1) + 0] = 1
let mut m: i32 = 1
while m <= N {
if m == 1 {
R[m * (N + 1) + 0] = 1
} else {
R[m * (N + 1) + 0] = 0
}
let mut nn: i32 = 1
while nn <= N {
let total: i64 = pow2[m * nn]
let mut sub: i64 = 0
let mut i: i32 = 1
while i <= m {
let combA: i64 = binom[(m - 1) * (N + 1) + (i - 1)]
if combA != 0 {
let mut j: i32 = 0
while j <= nn {
if !(i == m && j == nn) {
let rij: i64 = R[i * (N + 1) + j]
if rij != 0 {
let mut term: i64 = (combA * binom[nn * (N + 1) + j]) % MOD
term = (term * rij) % MOD
term = (term * pow2[(m - i) * (nn - j)]) % MOD
sub = (sub + term) % MOD
}
}
j = j + 1
}
}
i = i + 1
}
let mut val: i64 = (total - sub) % MOD
if val < 0 { val = val + MOD }
R[m * (N + 1) + nn] = val
nn = nn + 1
}
m = m + 1
}
let mut ans: i64 = 0
m = 1
while m <= N {
let mut nn: i32 = 1
while nn <= N {
ans = (ans + R[m * (N + 1) + nn]) % MOD
nn = nn + 1
}
m = m + 1
}
printf("%lld\n", ans)
free(R)
free(binom)
free(pow2)
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; }
int32_t main(void);
int32_t main(void) {
int32_t N = 100;
int64_t MOD = 1000000033;
int64_t* pow2 = (int64_t*)(calloc(((int64_t)(((N * N) + 1))), 8));
int64_t* binom = (int64_t*)(calloc(((int64_t)(((N + 1) * (N + 1)))), 8));
int64_t* R = (int64_t*)(calloc(((int64_t)(((N + 1) * (N + 1)))), 8));
if (((pow2 == NULL || binom == NULL) || R == NULL)) {
return 1;
}
pow2[0] = 1;
int32_t k = 1;
while (k <= (N * N)) {
pow2[k] = FLOW_CHECKED_MOD(((pow2[(k - 1)] * 2)), (MOD));
k = (k + 1);
}
int32_t n = 0;
while (n <= N) {
binom[((n * (N + 1)) + 0)] = 1;
binom[((n * (N + 1)) + n)] = 1;
int32_t j = 1;
while (j < n) {
binom[((n * (N + 1)) + j)] = FLOW_CHECKED_MOD(((binom[(((n - 1) * (N + 1)) + (j - 1))] + binom[(((n - 1) * (N + 1)) + j)])), (MOD));
j = (j + 1);
}
n = (n + 1);
}
R[((1 * (N + 1)) + 0)] = 1;
int32_t m = 1;
while (m <= N) {
if (m == 1) {
R[((m * (N + 1)) + 0)] = 1;
} else {
R[((m * (N + 1)) + 0)] = 0;
}
int32_t nn = 1;
while (nn <= N) {
int64_t total = pow2[(m * nn)];
int64_t sub = 0;
int32_t i = 1;
while (i <= m) {
int64_t combA = binom[(((m - 1) * (N + 1)) + (i - 1))];
if (combA != 0) {
int32_t j = 0;
while (j <= nn) {
if ((!((i == m && j == nn)))) {
int64_t rij = R[((i * (N + 1)) + j)];
if (rij != 0) {
int64_t term = FLOW_CHECKED_MOD(((combA * binom[((nn * (N + 1)) + j)])), (MOD));
term = FLOW_CHECKED_MOD(((term * rij)), (MOD));
term = FLOW_CHECKED_MOD(((term * pow2[((m - i) * (nn - j))])), (MOD));
sub = FLOW_CHECKED_MOD(((sub + term)), (MOD));
}
}
j = (j + 1);
}
}
i = (i + 1);
}
int64_t val = FLOW_CHECKED_MOD(((total - sub)), (MOD));
if (val < 0) {
val = (val + MOD);
}
R[((m * (N + 1)) + nn)] = val;
nn = (nn + 1);
}
m = (m + 1);
}
int64_t ans = 0;
m = 1;
while (m <= N) {
int32_t nn = 1;
while (nn <= N) {
ans = FLOW_CHECKED_MOD(((ans + R[((m * (N + 1)) + nn)])), (MOD));
nn = (nn + 1);
}
m = (m + 1);
}
printf("%lld\n", ans);
free(R);
free(binom);
free(pow2);
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 @main() -> i32 {
%0 = arith.constant 100 : i32
%1 = arith.constant 1000000033 : i32
%2 = arith.extsi %1 : i32 to i64
%4 = arith.muli %0, %0 : i32
%5 = arith.constant 1 : i32
%6 = arith.addi %4, %5 : i32
%7 = arith.extsi %6 : i32 to i64
%8 = arith.constant 8 : i32
%9 = arith.extsi %8 : i32 to i64
%3 = func.call @calloc(%7, %9) : (i64, i64) -> !llvm.ptr
%11 = arith.constant 1 : i32
%12 = arith.addi %0, %11 : i32
%13 = arith.constant 1 : i32
%14 = arith.addi %0, %13 : i32
%15 = arith.muli %12, %14 : i32
%16 = arith.extsi %15 : i32 to i64
%17 = arith.constant 8 : i32
%18 = arith.extsi %17 : i32 to i64
%10 = func.call @calloc(%16, %18) : (i64, i64) -> !llvm.ptr
%20 = arith.constant 1 : i32
%21 = arith.addi %0, %20 : i32
%22 = arith.constant 1 : i32
%23 = arith.addi %0, %22 : i32
%24 = arith.muli %21, %23 : i32
%25 = arith.extsi %24 : i32 to i64
%26 = arith.constant 8 : i32
%27 = arith.extsi %26 : i32 to i64
%19 = func.call @calloc(%25, %27) : (i64, i64) -> !llvm.ptr
%28 = llvm.mlir.zero : !llvm.ptr
%29 = llvm.icmp "eq" %3, %28 : !llvm.ptr
%30 = scf.if %29 -> (i1) {
%31 = arith.constant true
scf.yield %31 : i1
} else {
%32 = llvm.mlir.zero : !llvm.ptr
%33 = llvm.icmp "eq" %10, %32 : !llvm.ptr
scf.yield %33 : i1
}
%34 = scf.if %30 -> (i1) {
%35 = arith.constant true
scf.yield %35 : i1
} else {
%36 = llvm.mlir.zero : !llvm.ptr
%37 = llvm.icmp "eq" %19, %36 : !llvm.ptr
scf.yield %37 : i1
}
cf.cond_br %34, ^bb0, ^bb1
^bb0:
%38 = arith.constant 1 : i32
func.return %38 : i32
^bb1:
cf.br ^bb2
^bb2:
%39 = arith.constant 1 : i32
%40 = arith.constant 0 : i32
%41 = arith.extsi %39 : i32 to i64
%42 = arith.extsi %40 : i32 to i64
%43 = llvm.getelementptr %3[%42] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %41, %43 : i64, !llvm.ptr
%44 = arith.constant 1 : i32
%45 = llvm.mlir.constant(1 : i64) : i64
%46 = llvm.alloca %45 x i32 : (i64) -> !llvm.ptr
llvm.store %44, %46 : i32, !llvm.ptr
cf.br ^bb3
^bb3:
%47 = llvm.load %46 : !llvm.ptr -> i32
%48 = arith.muli %0, %0 : i32
%49 = arith.cmpi sle, %47, %48 : i32
cf.cond_br %49, ^bb4, ^bb5
^bb4:
%51 = llvm.load %46 : !llvm.ptr -> i32
%52 = arith.constant 1 : i32
%53 = arith.subi %51, %52 : i32
%54 = arith.extsi %53 : i32 to i64
%55 = llvm.getelementptr %3[%54] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%50 = llvm.load %55 : !llvm.ptr -> i64
%56 = arith.constant 2 : i32
%58 = arith.extsi %56 : i32 to i64
%57 = arith.muli %50, %58 : i64
%59 = arith.remsi %57, %2 : i64
%60 = llvm.load %46 : !llvm.ptr -> i32
%61 = arith.extsi %60 : i32 to i64
%62 = llvm.getelementptr %3[%61] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %59, %62 : i64, !llvm.ptr
%63 = llvm.load %46 : !llvm.ptr -> i32
%64 = arith.constant 1 : i32
%65 = arith.addi %63, %64 : i32
llvm.store %65, %46 : i32, !llvm.ptr
cf.br ^bb3
^bb5:
%66 = arith.constant 0 : i32
%67 = llvm.mlir.constant(1 : i64) : i64
%68 = llvm.alloca %67 x i32 : (i64) -> !llvm.ptr
llvm.store %66, %68 : i32, !llvm.ptr
cf.br ^bb6
^bb6:
%69 = llvm.load %68 : !llvm.ptr -> i32
%70 = arith.cmpi sle, %69, %0 : i32
cf.cond_br %70, ^bb7, ^bb8
^bb7:
%71 = arith.constant 1 : i32
%72 = llvm.load %68 : !llvm.ptr -> i32
%73 = arith.constant 1 : i32
%74 = arith.addi %0, %73 : i32
%75 = arith.muli %72, %74 : i32
%76 = arith.constant 0 : i32
%77 = arith.addi %75, %76 : i32
%78 = arith.extsi %71 : i32 to i64
%79 = arith.extsi %77 : i32 to i64
%80 = llvm.getelementptr %10[%79] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %78, %80 : i64, !llvm.ptr
%81 = arith.constant 1 : i32
%82 = llvm.load %68 : !llvm.ptr -> i32
%83 = arith.constant 1 : i32
%84 = arith.addi %0, %83 : i32
%85 = arith.muli %82, %84 : i32
%86 = llvm.load %68 : !llvm.ptr -> i32
%87 = arith.addi %85, %86 : i32
%88 = arith.extsi %81 : i32 to i64
%89 = arith.extsi %87 : i32 to i64
%90 = llvm.getelementptr %10[%89] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %88, %90 : i64, !llvm.ptr
%91 = arith.constant 1 : i32
%92 = llvm.mlir.constant(1 : i64) : i64
%93 = llvm.alloca %92 x i32 : (i64) -> !llvm.ptr
llvm.store %91, %93 : i32, !llvm.ptr
cf.br ^bb9
^bb9:
%94 = llvm.load %93 : !llvm.ptr -> i32
%95 = llvm.load %68 : !llvm.ptr -> i32
%96 = arith.cmpi slt, %94, %95 : i32
cf.cond_br %96, ^bb10, ^bb11
^bb10:
%98 = llvm.load %68 : !llvm.ptr -> i32
%99 = arith.constant 1 : i32
%100 = arith.subi %98, %99 : i32
%101 = arith.constant 1 : i32
%102 = arith.addi %0, %101 : i32
%103 = arith.muli %100, %102 : i32
%104 = llvm.load %93 : !llvm.ptr -> i32
%105 = arith.constant 1 : i32
%106 = arith.subi %104, %105 : i32
%107 = arith.addi %103, %106 : i32
%108 = arith.extsi %107 : i32 to i64
%109 = llvm.getelementptr %10[%108] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%97 = llvm.load %109 : !llvm.ptr -> i64
%111 = llvm.load %68 : !llvm.ptr -> i32
%112 = arith.constant 1 : i32
%113 = arith.subi %111, %112 : i32
%114 = arith.constant 1 : i32
%115 = arith.addi %0, %114 : i32
%116 = arith.muli %113, %115 : i32
%117 = llvm.load %93 : !llvm.ptr -> i32
%118 = arith.addi %116, %117 : i32
%119 = arith.extsi %118 : i32 to i64
%120 = llvm.getelementptr %10[%119] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%110 = llvm.load %120 : !llvm.ptr -> i64
%121 = arith.addi %97, %110 : i64
%122 = arith.remsi %121, %2 : i64
%123 = llvm.load %68 : !llvm.ptr -> i32
%124 = arith.constant 1 : i32
%125 = arith.addi %0, %124 : i32
%126 = arith.muli %123, %125 : i32
%127 = llvm.load %93 : !llvm.ptr -> i32
%128 = arith.addi %126, %127 : i32
%129 = arith.extsi %128 : i32 to i64
%130 = llvm.getelementptr %10[%129] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %122, %130 : i64, !llvm.ptr
%131 = llvm.load %93 : !llvm.ptr -> i32
%132 = arith.constant 1 : i32
%133 = arith.addi %131, %132 : i32
llvm.store %133, %93 : i32, !llvm.ptr
cf.br ^bb9
^bb11:
%134 = llvm.load %68 : !llvm.ptr -> i32
%135 = arith.constant 1 : i32
%136 = arith.addi %134, %135 : i32
llvm.store %136, %68 : i32, !llvm.ptr
cf.br ^bb6
^bb8:
%137 = arith.constant 1 : i32
%138 = arith.constant 1 : i32
%139 = arith.constant 1 : i32
%140 = arith.addi %0, %139 : i32
%141 = arith.muli %138, %140 : i32
%142 = arith.constant 0 : i32
%143 = arith.addi %141, %142 : i32
%144 = arith.extsi %137 : i32 to i64
%145 = arith.extsi %143 : i32 to i64
%146 = llvm.getelementptr %19[%145] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %144, %146 : i64, !llvm.ptr
%147 = arith.constant 1 : i32
%148 = llvm.mlir.constant(1 : i64) : i64
%149 = llvm.alloca %148 x i32 : (i64) -> !llvm.ptr
llvm.store %147, %149 : i32, !llvm.ptr
cf.br ^bb12
^bb12:
%150 = llvm.load %149 : !llvm.ptr -> i32
%151 = arith.cmpi sle, %150, %0 : i32
cf.cond_br %151, ^bb13, ^bb14
^bb13:
%152 = llvm.load %149 : !llvm.ptr -> i32
%153 = arith.constant 1 : i32
%154 = arith.cmpi eq, %152, %153 : i32
cf.cond_br %154, ^bb15, ^bb16
^bb15:
%155 = arith.constant 1 : i32
%156 = llvm.load %149 : !llvm.ptr -> i32
%157 = arith.constant 1 : i32
%158 = arith.addi %0, %157 : i32
%159 = arith.muli %156, %158 : i32
%160 = arith.constant 0 : i32
%161 = arith.addi %159, %160 : i32
%162 = arith.extsi %155 : i32 to i64
%163 = arith.extsi %161 : i32 to i64
%164 = llvm.getelementptr %19[%163] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %162, %164 : i64, !llvm.ptr
cf.br ^bb17
^bb16:
%165 = arith.constant 0 : i32
%166 = llvm.load %149 : !llvm.ptr -> i32
%167 = arith.constant 1 : i32
%168 = arith.addi %0, %167 : i32
%169 = arith.muli %166, %168 : i32
%170 = arith.constant 0 : i32
%171 = arith.addi %169, %170 : i32
%172 = arith.extsi %165 : i32 to i64
%173 = arith.extsi %171 : i32 to i64
%174 = llvm.getelementptr %19[%173] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %172, %174 : i64, !llvm.ptr
cf.br ^bb17
^bb17:
%175 = arith.constant 1 : i32
%176 = llvm.mlir.constant(1 : i64) : i64
%177 = llvm.alloca %176 x i32 : (i64) -> !llvm.ptr
llvm.store %175, %177 : i32, !llvm.ptr
cf.br ^bb18
^bb18:
%178 = llvm.load %177 : !llvm.ptr -> i32
%179 = arith.cmpi sle, %178, %0 : i32
cf.cond_br %179, ^bb19, ^bb20
^bb19:
%181 = llvm.load %149 : !llvm.ptr -> i32
%182 = llvm.load %177 : !llvm.ptr -> i32
%183 = arith.muli %181, %182 : i32
%184 = arith.extsi %183 : i32 to i64
%185 = llvm.getelementptr %3[%184] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%180 = llvm.load %185 : !llvm.ptr -> i64
%186 = arith.constant 0 : i32
%187 = arith.extsi %186 : i32 to i64
%188 = llvm.mlir.constant(1 : i64) : i64
%189 = llvm.alloca %188 x i64 : (i64) -> !llvm.ptr
llvm.store %187, %189 : i64, !llvm.ptr
%190 = arith.constant 1 : i32
%191 = llvm.mlir.constant(1 : i64) : i64
%192 = llvm.alloca %191 x i32 : (i64) -> !llvm.ptr
llvm.store %190, %192 : i32, !llvm.ptr
cf.br ^bb21
^bb21:
%193 = llvm.load %192 : !llvm.ptr -> i32
%194 = llvm.load %149 : !llvm.ptr -> i32
%195 = arith.cmpi sle, %193, %194 : i32
cf.cond_br %195, ^bb22, ^bb23
^bb22:
%197 = llvm.load %149 : !llvm.ptr -> i32
%198 = arith.constant 1 : i32
%199 = arith.subi %197, %198 : i32
%200 = arith.constant 1 : i32
%201 = arith.addi %0, %200 : i32
%202 = arith.muli %199, %201 : i32
%203 = llvm.load %192 : !llvm.ptr -> i32
%204 = arith.constant 1 : i32
%205 = arith.subi %203, %204 : i32
%206 = arith.addi %202, %205 : i32
%207 = arith.extsi %206 : i32 to i64
%208 = llvm.getelementptr %10[%207] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%196 = llvm.load %208 : !llvm.ptr -> i64
%209 = arith.constant 0 : i32
%211 = arith.extsi %209 : i32 to i64
%210 = arith.cmpi ne, %196, %211 : i64
cf.cond_br %210, ^bb24, ^bb25
^bb24:
%212 = arith.constant 0 : i32
%213 = llvm.mlir.constant(1 : i64) : i64
%214 = llvm.alloca %213 x i32 : (i64) -> !llvm.ptr
llvm.store %212, %214 : i32, !llvm.ptr
cf.br ^bb27
^bb27:
%215 = llvm.load %214 : !llvm.ptr -> i32
%216 = llvm.load %177 : !llvm.ptr -> i32
%217 = arith.cmpi sle, %215, %216 : i32
cf.cond_br %217, ^bb28, ^bb29
^bb28:
%218 = llvm.load %192 : !llvm.ptr -> i32
%219 = llvm.load %149 : !llvm.ptr -> i32
%220 = arith.cmpi eq, %218, %219 : i32
%221 = scf.if %220 -> (i1) {
%222 = llvm.load %214 : !llvm.ptr -> i32
%223 = llvm.load %177 : !llvm.ptr -> i32
%224 = arith.cmpi eq, %222, %223 : i32
scf.yield %224 : i1
} else {
%225 = arith.constant false
scf.yield %225 : i1
}
%227 = arith.constant 1 : i1
%226 = arith.xori %221, %227 : i1
cf.cond_br %226, ^bb30, ^bb31
^bb30:
%230 = llvm.load %192 : !llvm.ptr -> i32
%231 = arith.constant 1 : i32
%232 = arith.addi %0, %231 : i32
%233 = arith.muli %230, %232 : i32
%234 = llvm.load %214 : !llvm.ptr -> i32
%235 = arith.addi %233, %234 : i32
%236 = arith.extsi %235 : i32 to i64
%237 = llvm.getelementptr %19[%236] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%229 = llvm.load %237 : !llvm.ptr -> i64
%238 = arith.constant 0 : i32
%240 = arith.extsi %238 : i32 to i64
%239 = arith.cmpi ne, %229, %240 : i64
cf.cond_br %239, ^bb33, ^bb34
^bb33:
%242 = llvm.load %177 : !llvm.ptr -> i32
%243 = arith.constant 1 : i32
%244 = arith.addi %0, %243 : i32
%245 = arith.muli %242, %244 : i32
%246 = llvm.load %214 : !llvm.ptr -> i32
%247 = arith.addi %245, %246 : i32
%248 = arith.extsi %247 : i32 to i64
%249 = llvm.getelementptr %10[%248] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%241 = llvm.load %249 : !llvm.ptr -> i64
%250 = arith.muli %196, %241 : i64
%251 = arith.remsi %250, %2 : i64
%252 = llvm.mlir.constant(1 : i64) : i64
%253 = llvm.alloca %252 x i64 : (i64) -> !llvm.ptr
llvm.store %251, %253 : i64, !llvm.ptr
%254 = llvm.load %253 : !llvm.ptr -> i64
%255 = arith.muli %254, %229 : i64
%256 = arith.remsi %255, %2 : i64
llvm.store %256, %253 : i64, !llvm.ptr
%257 = llvm.load %253 : !llvm.ptr -> i64
%259 = llvm.load %149 : !llvm.ptr -> i32
%260 = llvm.load %192 : !llvm.ptr -> i32
%261 = arith.subi %259, %260 : i32
%262 = llvm.load %177 : !llvm.ptr -> i32
%263 = llvm.load %214 : !llvm.ptr -> i32
%264 = arith.subi %262, %263 : i32
%265 = arith.muli %261, %264 : i32
%266 = arith.extsi %265 : i32 to i64
%267 = llvm.getelementptr %3[%266] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%258 = llvm.load %267 : !llvm.ptr -> i64
%268 = arith.muli %257, %258 : i64
%269 = arith.remsi %268, %2 : i64
llvm.store %269, %253 : i64, !llvm.ptr
%270 = llvm.load %189 : !llvm.ptr -> i64
%271 = llvm.load %253 : !llvm.ptr -> i64
%272 = arith.addi %270, %271 : i64
%273 = arith.remsi %272, %2 : i64
llvm.store %273, %189 : i64, !llvm.ptr
cf.br ^bb35
^bb34:
cf.br ^bb35
^bb35:
cf.br ^bb32
^bb31:
cf.br ^bb32
^bb32:
%274 = llvm.load %214 : !llvm.ptr -> i32
%275 = arith.constant 1 : i32
%276 = arith.addi %274, %275 : i32
llvm.store %276, %214 : i32, !llvm.ptr
cf.br ^bb27
^bb29:
cf.br ^bb26
^bb25:
cf.br ^bb26
^bb26:
%277 = llvm.load %192 : !llvm.ptr -> i32
%278 = arith.constant 1 : i32
%279 = arith.addi %277, %278 : i32
llvm.store %279, %192 : i32, !llvm.ptr
cf.br ^bb21
^bb23:
%280 = llvm.load %189 : !llvm.ptr -> i64
%281 = arith.subi %180, %280 : i64
%282 = arith.remsi %281, %2 : i64
%283 = llvm.mlir.constant(1 : i64) : i64
%284 = llvm.alloca %283 x i64 : (i64) -> !llvm.ptr
llvm.store %282, %284 : i64, !llvm.ptr
%285 = llvm.load %284 : !llvm.ptr -> i64
%286 = arith.constant 0 : i32
%288 = arith.extsi %286 : i32 to i64
%287 = arith.cmpi slt, %285, %288 : i64
cf.cond_br %287, ^bb36, ^bb37
^bb36:
%289 = llvm.load %284 : !llvm.ptr -> i64
%290 = arith.addi %289, %2 : i64
llvm.store %290, %284 : i64, !llvm.ptr
cf.br ^bb38
^bb37:
cf.br ^bb38
^bb38:
%291 = llvm.load %284 : !llvm.ptr -> i64
%292 = llvm.load %149 : !llvm.ptr -> i32
%293 = arith.constant 1 : i32
%294 = arith.addi %0, %293 : i32
%295 = arith.muli %292, %294 : i32
%296 = llvm.load %177 : !llvm.ptr -> i32
%297 = arith.addi %295, %296 : i32
%298 = arith.extsi %297 : i32 to i64
%299 = llvm.getelementptr %19[%298] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %291, %299 : i64, !llvm.ptr
%300 = llvm.load %177 : !llvm.ptr -> i32
%301 = arith.constant 1 : i32
%302 = arith.addi %300, %301 : i32
llvm.store %302, %177 : i32, !llvm.ptr
cf.br ^bb18
^bb20:
%303 = llvm.load %149 : !llvm.ptr -> i32
%304 = arith.constant 1 : i32
%305 = arith.addi %303, %304 : i32
llvm.store %305, %149 : i32, !llvm.ptr
cf.br ^bb12
^bb14:
%306 = arith.constant 0 : i32
%307 = arith.extsi %306 : i32 to i64
%308 = llvm.mlir.constant(1 : i64) : i64
%309 = llvm.alloca %308 x i64 : (i64) -> !llvm.ptr
llvm.store %307, %309 : i64, !llvm.ptr
%310 = arith.constant 1 : i32
llvm.store %310, %149 : i32, !llvm.ptr
cf.br ^bb39
^bb39:
%311 = llvm.load %149 : !llvm.ptr -> i32
%312 = arith.cmpi sle, %311, %0 : i32
cf.cond_br %312, ^bb40, ^bb41
^bb40:
%313 = arith.constant 1 : i32
%314 = llvm.mlir.constant(1 : i64) : i64
%315 = llvm.alloca %314 x i32 : (i64) -> !llvm.ptr
llvm.store %313, %315 : i32, !llvm.ptr
cf.br ^bb42
^bb42:
%316 = llvm.load %315 : !llvm.ptr -> i32
%317 = arith.cmpi sle, %316, %0 : i32
cf.cond_br %317, ^bb43, ^bb44
^bb43:
%318 = llvm.load %309 : !llvm.ptr -> i64
%320 = llvm.load %149 : !llvm.ptr -> i32
%321 = arith.constant 1 : i32
%322 = arith.addi %0, %321 : i32
%323 = arith.muli %320, %322 : i32
%324 = llvm.load %315 : !llvm.ptr -> i32
%325 = arith.addi %323, %324 : i32
%326 = arith.extsi %325 : i32 to i64
%327 = llvm.getelementptr %19[%326] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%319 = llvm.load %327 : !llvm.ptr -> i64
%328 = arith.addi %318, %319 : i64
%329 = arith.remsi %328, %2 : i64
llvm.store %329, %309 : i64, !llvm.ptr
%330 = llvm.load %315 : !llvm.ptr -> i32
%331 = arith.constant 1 : i32
%332 = arith.addi %330, %331 : i32
llvm.store %332, %315 : i32, !llvm.ptr
cf.br ^bb42
^bb44:
%333 = llvm.load %149 : !llvm.ptr -> i32
%334 = arith.constant 1 : i32
%335 = arith.addi %333, %334 : i32
llvm.store %335, %149 : i32, !llvm.ptr
cf.br ^bb39
^bb41:
%336 = llvm.mlir.addressof @str_0 : !llvm.ptr
%337 = llvm.load %309 : !llvm.ptr -> i64
%338 = llvm.call @printf(%336, %337) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
func.call @free(%19) : (!llvm.ptr) -> ()
func.call @free(%10) : (!llvm.ptr) -> ()
func.call @free(%3) : (!llvm.ptr) -> ()
%342 = arith.constant 0 : i32
func.return %342 : i32
}
}