Problem 209
Circular Logic: count truth assignments via cycle Lucas numbers.
View problem on Project Euler
Performance comparison
| Metric | Our solution | Best known |
| Time complexity | O(n^2) | O(n) |
| Space complexity | O(n^2) | O(n) |
| Approach | Flow solution | Cycle decomposition |
| Verdict | Suboptimal |
Flow source
# Project Euler 209
# Circular Logic: count truth assignments via cycle Lucas numbers.
extern {
function calloc(n: i64, size: i64) -> ptr<void>
function free(p: ptr<void>) -> void
}
function main() -> i32 {
let N: i32 = 64
let conn: ptr<i32> = calloc(N as i64, 4)
let used: ptr<i8> = calloc(N as i64, 1)
let lucas: ptr<i64> = calloc(N as i64 + 1, 8)
if conn == null || used == null || lucas == null { return 1 }
let mut from_state: i32 = 0
while from_state < N {
let mut left: ptr<i32> = calloc(6, 4)
let mut i: i32 = 0
while i < 6 {
left[i] = (from_state >> i) & 1
i = i + 1
}
let mut right0: i32 = left[1]
let mut right1: i32 = left[2]
let mut right2: i32 = left[3]
let mut right3: i32 = left[4]
let mut right4: i32 = left[5]
let mut right5: i32 = left[0] ^ (left[1] & left[2])
let mut to_state: i32 = 0
to_state = to_state | (right0 << 0)
to_state = to_state | (right1 << 1)
to_state = to_state | (right2 << 2)
to_state = to_state | (right3 << 3)
to_state = to_state | (right4 << 4)
to_state = to_state | (right5 << 5)
conn[from_state] = to_state
free(left)
from_state = from_state + 1
}
lucas[0] = 2
lucas[1] = 1
let mut i: i32 = 2
while i <= N {
lucas[i] = lucas[i - 2] + lucas[i - 1]
i = i + 1
}
let mut result: i64 = 1
let mut all_used: bool = false
while !all_used {
let mut start: i32 = 0
while start < N && used[start] == 1 {
start = start + 1
}
if start >= N {
all_used = true
continue
}
let mut current: i32 = start
let mut cycle_len: i32 = 0
while true {
used[current] = 1
cycle_len = cycle_len + 1
current = conn[current]
if current == start { break }
}
result = result * lucas[cycle_len]
}
printf("%lld\n", result)
free(conn); free(used); free(lucas)
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 = 64;
int32_t* conn = (int32_t*)(calloc(((int64_t)(N)), 4));
int8_t* used = (int8_t*)(calloc(((int64_t)(N)), 1));
int64_t* lucas = (int64_t*)(calloc((((int64_t)(N)) + 1), 8));
if (((conn == NULL || used == NULL) || lucas == NULL)) {
return 1;
}
int32_t from_state = 0;
while (from_state < N) {
int32_t* left = (int32_t*)(calloc(6, 4));
int32_t i = 0;
while (i < 6) {
left[i] = (FLOW_CHECKED_SHR((from_state), (i)) & 1);
i = (i + 1);
}
int32_t right0 = left[1];
int32_t right1 = left[2];
int32_t right2 = left[3];
int32_t right3 = left[4];
int32_t right4 = left[5];
int32_t right5 = (left[0] ^ (left[1] & left[2]));
int32_t to_state = 0;
to_state = (to_state | FLOW_CHECKED_SHL((right0), (0)));
to_state = (to_state | FLOW_CHECKED_SHL((right1), (1)));
to_state = (to_state | FLOW_CHECKED_SHL((right2), (2)));
to_state = (to_state | FLOW_CHECKED_SHL((right3), (3)));
to_state = (to_state | FLOW_CHECKED_SHL((right4), (4)));
to_state = (to_state | FLOW_CHECKED_SHL((right5), (5)));
conn[from_state] = to_state;
free(left);
from_state = (from_state + 1);
}
lucas[0] = 2;
lucas[1] = 1;
int32_t i = 2;
while (i <= N) {
lucas[i] = (lucas[(i - 2)] + lucas[(i - 1)]);
i = (i + 1);
}
int64_t result = 1;
bool all_used = 0;
while ((!(all_used))) {
int32_t start = 0;
while ((start < N && used[start] == 1)) {
start = (start + 1);
}
if (start >= N) {
all_used = 1;
continue;
}
int32_t current = start;
int32_t cycle_len = 0;
while (1) {
used[current] = 1;
cycle_len = (cycle_len + 1);
current = conn[current];
if (current == start) {
break;
}
}
result = (result * lucas[cycle_len]);
}
printf("%lld\n", result);
free(conn);
free(used);
free(lucas);
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 64 : i32
%2 = arith.extsi %0 : i32 to i64
%3 = arith.constant 4 : i32
%4 = arith.extsi %3 : i32 to i64
%1 = func.call @calloc(%2, %4) : (i64, i64) -> !llvm.ptr
%6 = arith.extsi %0 : i32 to i64
%7 = arith.constant 1 : i32
%8 = arith.extsi %7 : i32 to i64
%5 = func.call @calloc(%6, %8) : (i64, i64) -> !llvm.ptr
%10 = arith.extsi %0 : i32 to i64
%11 = arith.constant 1 : i32
%13 = arith.extsi %11 : i32 to i64
%12 = arith.addi %10, %13 : i64
%14 = arith.constant 8 : i32
%15 = arith.extsi %14 : i32 to i64
%9 = func.call @calloc(%12, %15) : (i64, i64) -> !llvm.ptr
%16 = llvm.mlir.zero : !llvm.ptr
%17 = llvm.icmp "eq" %1, %16 : !llvm.ptr
%18 = scf.if %17 -> (i1) {
%19 = arith.constant true
scf.yield %19 : i1
} else {
%20 = llvm.mlir.zero : !llvm.ptr
%21 = llvm.icmp "eq" %5, %20 : !llvm.ptr
scf.yield %21 : i1
}
%22 = scf.if %18 -> (i1) {
%23 = arith.constant true
scf.yield %23 : i1
} else {
%24 = llvm.mlir.zero : !llvm.ptr
%25 = llvm.icmp "eq" %9, %24 : !llvm.ptr
scf.yield %25 : i1
}
cf.cond_br %22, ^bb0, ^bb1
^bb0:
%26 = arith.constant 1 : i32
func.return %26 : i32
^bb1:
cf.br ^bb2
^bb2:
%27 = arith.constant 0 : i32
%28 = llvm.mlir.constant(1 : i64) : i64
%29 = llvm.alloca %28 x i32 : (i64) -> !llvm.ptr
llvm.store %27, %29 : i32, !llvm.ptr
cf.br ^bb3
^bb3:
%30 = llvm.load %29 : !llvm.ptr -> i32
%31 = arith.cmpi slt, %30, %0 : i32
cf.cond_br %31, ^bb4, ^bb5
^bb4:
%33 = arith.constant 6 : i32
%34 = arith.constant 4 : i32
%35 = arith.extsi %33 : i32 to i64
%36 = arith.extsi %34 : i32 to i64
%32 = func.call @calloc(%35, %36) : (i64, i64) -> !llvm.ptr
%37 = llvm.mlir.constant(1 : i64) : i64
%38 = llvm.alloca %37 x !llvm.ptr : (i64) -> !llvm.ptr
llvm.store %32, %38 : !llvm.ptr, !llvm.ptr
%39 = arith.constant 0 : i32
%40 = llvm.mlir.constant(1 : i64) : i64
%41 = llvm.alloca %40 x i32 : (i64) -> !llvm.ptr
llvm.store %39, %41 : i32, !llvm.ptr
cf.br ^bb6
^bb6:
%42 = llvm.load %41 : !llvm.ptr -> i32
%43 = arith.constant 6 : i32
%44 = arith.cmpi slt, %42, %43 : i32
cf.cond_br %44, ^bb7, ^bb8
^bb7:
%45 = llvm.load %29 : !llvm.ptr -> i32
%46 = llvm.load %41 : !llvm.ptr -> i32
%47 = arith.shrsi %45, %46 : i32
%48 = arith.constant 1 : i32
%49 = arith.andi %47, %48 : i32
%50 = llvm.load %38 : !llvm.ptr -> !llvm.ptr
%51 = llvm.load %41 : !llvm.ptr -> i32
%52 = arith.extsi %51 : i32 to i64
%53 = llvm.getelementptr %50[%52] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %49, %53 : i32, !llvm.ptr
%54 = llvm.load %41 : !llvm.ptr -> i32
%55 = arith.constant 1 : i32
%56 = arith.addi %54, %55 : i32
llvm.store %56, %41 : i32, !llvm.ptr
cf.br ^bb6
^bb8:
%58 = llvm.load %38 : !llvm.ptr -> !llvm.ptr
%59 = arith.constant 1 : i32
%60 = arith.extsi %59 : i32 to i64
%61 = llvm.getelementptr %58[%60] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%57 = llvm.load %61 : !llvm.ptr -> i32
%62 = llvm.mlir.constant(1 : i64) : i64
%63 = llvm.alloca %62 x i32 : (i64) -> !llvm.ptr
llvm.store %57, %63 : i32, !llvm.ptr
%65 = llvm.load %38 : !llvm.ptr -> !llvm.ptr
%66 = arith.constant 2 : i32
%67 = arith.extsi %66 : i32 to i64
%68 = llvm.getelementptr %65[%67] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%64 = llvm.load %68 : !llvm.ptr -> i32
%69 = llvm.mlir.constant(1 : i64) : i64
%70 = llvm.alloca %69 x i32 : (i64) -> !llvm.ptr
llvm.store %64, %70 : i32, !llvm.ptr
%72 = llvm.load %38 : !llvm.ptr -> !llvm.ptr
%73 = arith.constant 3 : i32
%74 = arith.extsi %73 : i32 to i64
%75 = llvm.getelementptr %72[%74] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%71 = llvm.load %75 : !llvm.ptr -> i32
%76 = llvm.mlir.constant(1 : i64) : i64
%77 = llvm.alloca %76 x i32 : (i64) -> !llvm.ptr
llvm.store %71, %77 : i32, !llvm.ptr
%79 = llvm.load %38 : !llvm.ptr -> !llvm.ptr
%80 = arith.constant 4 : i32
%81 = arith.extsi %80 : i32 to i64
%82 = llvm.getelementptr %79[%81] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%78 = llvm.load %82 : !llvm.ptr -> i32
%83 = llvm.mlir.constant(1 : i64) : i64
%84 = llvm.alloca %83 x i32 : (i64) -> !llvm.ptr
llvm.store %78, %84 : i32, !llvm.ptr
%86 = llvm.load %38 : !llvm.ptr -> !llvm.ptr
%87 = arith.constant 5 : i32
%88 = arith.extsi %87 : i32 to i64
%89 = llvm.getelementptr %86[%88] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%85 = llvm.load %89 : !llvm.ptr -> i32
%90 = llvm.mlir.constant(1 : i64) : i64
%91 = llvm.alloca %90 x i32 : (i64) -> !llvm.ptr
llvm.store %85, %91 : i32, !llvm.ptr
%93 = llvm.load %38 : !llvm.ptr -> !llvm.ptr
%94 = arith.constant 0 : i32
%95 = arith.extsi %94 : i32 to i64
%96 = llvm.getelementptr %93[%95] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%92 = llvm.load %96 : !llvm.ptr -> i32
%98 = llvm.load %38 : !llvm.ptr -> !llvm.ptr
%99 = arith.constant 1 : i32
%100 = arith.extsi %99 : i32 to i64
%101 = llvm.getelementptr %98[%100] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%97 = llvm.load %101 : !llvm.ptr -> i32
%103 = llvm.load %38 : !llvm.ptr -> !llvm.ptr
%104 = arith.constant 2 : i32
%105 = arith.extsi %104 : i32 to i64
%106 = llvm.getelementptr %103[%105] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%102 = llvm.load %106 : !llvm.ptr -> i32
%107 = arith.andi %97, %102 : i32
%108 = arith.xori %92, %107 : i32
%109 = llvm.mlir.constant(1 : i64) : i64
%110 = llvm.alloca %109 x i32 : (i64) -> !llvm.ptr
llvm.store %108, %110 : i32, !llvm.ptr
%111 = arith.constant 0 : i32
%112 = llvm.mlir.constant(1 : i64) : i64
%113 = llvm.alloca %112 x i32 : (i64) -> !llvm.ptr
llvm.store %111, %113 : i32, !llvm.ptr
%114 = llvm.load %113 : !llvm.ptr -> i32
%115 = llvm.load %63 : !llvm.ptr -> i32
%116 = arith.constant 0 : i32
%117 = arith.shli %115, %116 : i32
%118 = arith.ori %114, %117 : i32
llvm.store %118, %113 : i32, !llvm.ptr
%119 = llvm.load %113 : !llvm.ptr -> i32
%120 = llvm.load %70 : !llvm.ptr -> i32
%121 = arith.constant 1 : i32
%122 = arith.shli %120, %121 : i32
%123 = arith.ori %119, %122 : i32
llvm.store %123, %113 : i32, !llvm.ptr
%124 = llvm.load %113 : !llvm.ptr -> i32
%125 = llvm.load %77 : !llvm.ptr -> i32
%126 = arith.constant 2 : i32
%127 = arith.shli %125, %126 : i32
%128 = arith.ori %124, %127 : i32
llvm.store %128, %113 : i32, !llvm.ptr
%129 = llvm.load %113 : !llvm.ptr -> i32
%130 = llvm.load %84 : !llvm.ptr -> i32
%131 = arith.constant 3 : i32
%132 = arith.shli %130, %131 : i32
%133 = arith.ori %129, %132 : i32
llvm.store %133, %113 : i32, !llvm.ptr
%134 = llvm.load %113 : !llvm.ptr -> i32
%135 = llvm.load %91 : !llvm.ptr -> i32
%136 = arith.constant 4 : i32
%137 = arith.shli %135, %136 : i32
%138 = arith.ori %134, %137 : i32
llvm.store %138, %113 : i32, !llvm.ptr
%139 = llvm.load %113 : !llvm.ptr -> i32
%140 = llvm.load %110 : !llvm.ptr -> i32
%141 = arith.constant 5 : i32
%142 = arith.shli %140, %141 : i32
%143 = arith.ori %139, %142 : i32
llvm.store %143, %113 : i32, !llvm.ptr
%144 = llvm.load %113 : !llvm.ptr -> i32
%145 = llvm.load %29 : !llvm.ptr -> i32
%146 = arith.extsi %145 : i32 to i64
%147 = llvm.getelementptr %1[%146] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %144, %147 : i32, !llvm.ptr
%149 = llvm.load %38 : !llvm.ptr -> !llvm.ptr
func.call @free(%149) : (!llvm.ptr) -> ()
%150 = llvm.load %29 : !llvm.ptr -> i32
%151 = arith.constant 1 : i32
%152 = arith.addi %150, %151 : i32
llvm.store %152, %29 : i32, !llvm.ptr
cf.br ^bb3
^bb5:
%153 = arith.constant 2 : i32
%154 = arith.constant 0 : i32
%155 = arith.extsi %153 : i32 to i64
%156 = arith.extsi %154 : i32 to i64
%157 = llvm.getelementptr %9[%156] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %155, %157 : i64, !llvm.ptr
%158 = arith.constant 1 : i32
%159 = arith.constant 1 : i32
%160 = arith.extsi %158 : i32 to i64
%161 = arith.extsi %159 : i32 to i64
%162 = llvm.getelementptr %9[%161] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %160, %162 : i64, !llvm.ptr
%163 = arith.constant 2 : i32
%164 = llvm.mlir.constant(1 : i64) : i64
%165 = llvm.alloca %164 x i32 : (i64) -> !llvm.ptr
llvm.store %163, %165 : i32, !llvm.ptr
cf.br ^bb9
^bb9:
%166 = llvm.load %165 : !llvm.ptr -> i32
%167 = arith.cmpi sle, %166, %0 : i32
cf.cond_br %167, ^bb10, ^bb11
^bb10:
%169 = llvm.load %165 : !llvm.ptr -> i32
%170 = arith.constant 2 : i32
%171 = arith.subi %169, %170 : i32
%172 = arith.extsi %171 : i32 to i64
%173 = llvm.getelementptr %9[%172] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%168 = llvm.load %173 : !llvm.ptr -> i64
%175 = llvm.load %165 : !llvm.ptr -> i32
%176 = arith.constant 1 : i32
%177 = arith.subi %175, %176 : i32
%178 = arith.extsi %177 : i32 to i64
%179 = llvm.getelementptr %9[%178] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%174 = llvm.load %179 : !llvm.ptr -> i64
%180 = arith.addi %168, %174 : i64
%181 = llvm.load %165 : !llvm.ptr -> i32
%182 = arith.extsi %181 : i32 to i64
%183 = llvm.getelementptr %9[%182] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %180, %183 : i64, !llvm.ptr
%184 = llvm.load %165 : !llvm.ptr -> i32
%185 = arith.constant 1 : i32
%186 = arith.addi %184, %185 : i32
llvm.store %186, %165 : i32, !llvm.ptr
cf.br ^bb9
^bb11:
%187 = arith.constant 1 : i32
%188 = arith.extsi %187 : i32 to i64
%189 = llvm.mlir.constant(1 : i64) : i64
%190 = llvm.alloca %189 x i64 : (i64) -> !llvm.ptr
llvm.store %188, %190 : i64, !llvm.ptr
%191 = arith.constant 0 : i1
%192 = llvm.mlir.constant(1 : i64) : i64
%193 = llvm.alloca %192 x i1 : (i64) -> !llvm.ptr
llvm.store %191, %193 : i1, !llvm.ptr
cf.br ^bb12
^bb12:
%194 = llvm.load %193 : !llvm.ptr -> i1
%196 = arith.constant 1 : i1
%195 = arith.xori %194, %196 : i1
cf.cond_br %195, ^bb13, ^bb14
^bb13:
%198 = arith.constant 0 : i32
%199 = llvm.mlir.constant(1 : i64) : i64
%200 = llvm.alloca %199 x i32 : (i64) -> !llvm.ptr
llvm.store %198, %200 : i32, !llvm.ptr
cf.br ^bb15
^bb15:
%201 = llvm.load %200 : !llvm.ptr -> i32
%202 = arith.cmpi slt, %201, %0 : i32
%203 = scf.if %202 -> (i1) {
%205 = llvm.load %200 : !llvm.ptr -> i32
%206 = arith.extsi %205 : i32 to i64
%207 = llvm.getelementptr %5[%206] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%204 = llvm.load %207 : !llvm.ptr -> i8
%208 = arith.constant 1 : i32
%210 = arith.extsi %204 : i8 to i32
%209 = arith.cmpi eq, %210, %208 : i32
scf.yield %209 : i1
} else {
%211 = arith.constant false
scf.yield %211 : i1
}
cf.cond_br %203, ^bb16, ^bb17
^bb16:
%212 = llvm.load %200 : !llvm.ptr -> i32
%213 = arith.constant 1 : i32
%214 = arith.addi %212, %213 : i32
llvm.store %214, %200 : i32, !llvm.ptr
cf.br ^bb15
^bb17:
%215 = llvm.load %200 : !llvm.ptr -> i32
%216 = arith.cmpi sge, %215, %0 : i32
cf.cond_br %216, ^bb18, ^bb19
^bb18:
%217 = arith.constant 1 : i1
llvm.store %217, %193 : i1, !llvm.ptr
cf.br ^bb12
^bb19:
cf.br ^bb20
^bb20:
%218 = llvm.load %200 : !llvm.ptr -> i32
%219 = llvm.mlir.constant(1 : i64) : i64
%220 = llvm.alloca %219 x i32 : (i64) -> !llvm.ptr
llvm.store %218, %220 : i32, !llvm.ptr
%221 = arith.constant 0 : i32
%222 = llvm.mlir.constant(1 : i64) : i64
%223 = llvm.alloca %222 x i32 : (i64) -> !llvm.ptr
llvm.store %221, %223 : i32, !llvm.ptr
cf.br ^bb21
^bb21:
%224 = arith.constant 1 : i1
cf.cond_br %224, ^bb22, ^bb23
^bb22:
%225 = arith.constant 1 : i32
%226 = llvm.load %220 : !llvm.ptr -> i32
%227 = arith.trunci %225 : i32 to i8
%228 = arith.extsi %226 : i32 to i64
%229 = llvm.getelementptr %5[%228] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %227, %229 : i8, !llvm.ptr
%230 = llvm.load %223 : !llvm.ptr -> i32
%231 = arith.constant 1 : i32
%232 = arith.addi %230, %231 : i32
llvm.store %232, %223 : i32, !llvm.ptr
%234 = llvm.load %220 : !llvm.ptr -> i32
%235 = arith.extsi %234 : i32 to i64
%236 = llvm.getelementptr %1[%235] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%233 = llvm.load %236 : !llvm.ptr -> i32
llvm.store %233, %220 : i32, !llvm.ptr
%237 = llvm.load %220 : !llvm.ptr -> i32
%238 = llvm.load %200 : !llvm.ptr -> i32
%239 = arith.cmpi eq, %237, %238 : i32
cf.cond_br %239, ^bb24, ^bb25
^bb24:
cf.br ^bb23
^bb25:
cf.br ^bb26
^bb26:
cf.br ^bb21
^bb23:
%240 = llvm.load %190 : !llvm.ptr -> i64
%242 = llvm.load %223 : !llvm.ptr -> i32
%243 = arith.extsi %242 : i32 to i64
%244 = llvm.getelementptr %9[%243] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%241 = llvm.load %244 : !llvm.ptr -> i64
%245 = arith.muli %240, %241 : i64
llvm.store %245, %190 : i64, !llvm.ptr
cf.br ^bb12
^bb14:
%246 = llvm.mlir.addressof @str_0 : !llvm.ptr
%247 = llvm.load %190 : !llvm.ptr -> i64
%248 = llvm.call @printf(%246, %247) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
func.call @free(%1) : (!llvm.ptr) -> ()
func.call @free(%5) : (!llvm.ptr) -> ()
func.call @free(%9) : (!llvm.ptr) -> ()
%252 = arith.constant 0 : i32
func.return %252 : i32
}
}