← All problems
Problem 223
Almost right-angled triangles I: a^2+b^2=c^2+1, perimeter <= 25e6.
View problem on Project Euler
Performance comparison
Metric Our solution Best known
Time complexity O(n)O(n^2)
Space complexity O(n)O(n^2)
Approach Flow solution Bottom-up DP
Verdict Optimal
Flow source
# Project Euler 223
# Almost right-angled triangles I: a^2+b^2=c^2+1, perimeter <= 25e6.
extern {
function calloc(n: i64, size: i64) -> ptr<void>
function free(p: ptr<void>) -> void
}
function main() -> i32 {
let LIM: i64 = 25000000
let CAP: i64 = 20000000
let sa: ptr<i32> = calloc(CAP, 4)
let sb: ptr<i32> = calloc(CAP, 4)
let sc: ptr<i32> = calloc(CAP, 4)
if sa == null || sb == null || sc == null { return 1 }
let mut sp: i64 = 0
sa[0] = 1; sb[0] = 1; sc[0] = 1; sp = 1
sa[1] = 1; sb[1] = 2; sc[1] = 2; sp = 2
let mut count: i64 = 0
while sp > 0 {
sp = sp - 1
let a: i64 = sa[sp] as i64
let b: i64 = sb[sp] as i64
let c: i64 = sc[sp] as i64
if a + b + c > LIM { continue }
count = count + 1
# A
let mut x: i64 = a - 2 * b + 2 * c
let mut y: i64 = 2 * a - b + 2 * c
let z: i64 = 2 * a - 2 * b + 3 * c
if x > y { let t: i64 = x; x = y; y = t }
if x + y + z <= LIM {
sa[sp] = x as i32; sb[sp] = y as i32; sc[sp] = z as i32; sp = sp + 1
}
# B
x = a + 2 * b + 2 * c
y = 2 * a + b + 2 * c
let z2: i64 = 2 * a + 2 * b + 3 * c
if x > y { let t2: i64 = x; x = y; y = t2 }
if x + y + z2 <= LIM {
sa[sp] = x as i32; sb[sp] = y as i32; sc[sp] = z2 as i32; sp = sp + 1
}
# C
if a != b {
x = 0 - a + 2 * b + 2 * c
y = 0 - 2 * a + b + 2 * c
let z3: i64 = 0 - 2 * a + 2 * b + 3 * c
if x > y { let t3: i64 = x; x = y; y = t3 }
if x + y + z3 <= LIM {
sa[sp] = x as i32; sb[sp] = y as i32; sc[sp] = z3 as i32; sp = sp + 1
}
}
}
printf("%lld\n", count)
free(sa); free(sb); free(sc)
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) {
int64_t LIM = 25000000;
int64_t CAP = 20000000;
int32_t* sa = (int32_t*)(calloc(CAP, 4));
int32_t* sb = (int32_t*)(calloc(CAP, 4));
int32_t* sc = (int32_t*)(calloc(CAP, 4));
if (((sa == NULL || sb == NULL) || sc == NULL)) {
return 1;
}
int64_t sp = 0;
sa[0] = 1;
sb[0] = 1;
sc[0] = 1;
sp = 1;
sa[1] = 1;
sb[1] = 2;
sc[1] = 2;
sp = 2;
int64_t count = 0;
while (sp > 0) {
sp = (sp - 1);
int64_t a = ((int64_t)(sa[sp]));
int64_t b = ((int64_t)(sb[sp]));
int64_t c = ((int64_t)(sc[sp]));
if (((a + b) + c) > LIM) {
continue;
}
count = (count + 1);
int64_t x = ((a - (2 * b)) + (2 * c));
int64_t y = (((2 * a) - b) + (2 * c));
int64_t z = (((2 * a) - (2 * b)) + (3 * c));
if (x > y) {
int64_t t = x;
x = y;
y = t;
}
if (((x + y) + z) <= LIM) {
sa[sp] = ((int32_t)(x));
sb[sp] = ((int32_t)(y));
sc[sp] = ((int32_t)(z));
sp = (sp + 1);
}
x = ((a + (2 * b)) + (2 * c));
y = (((2 * a) + b) + (2 * c));
int64_t z2 = (((2 * a) + (2 * b)) + (3 * c));
if (x > y) {
int64_t t2 = x;
x = y;
y = t2;
}
if (((x + y) + z2) <= LIM) {
sa[sp] = ((int32_t)(x));
sb[sp] = ((int32_t)(y));
sc[sp] = ((int32_t)(z2));
sp = (sp + 1);
}
if (a != b) {
x = (((0 - a) + (2 * b)) + (2 * c));
y = (((0 - (2 * a)) + b) + (2 * c));
int64_t z3 = (((0 - (2 * a)) + (2 * b)) + (3 * c));
if (x > y) {
int64_t t3 = x;
x = y;
y = t3;
}
if (((x + y) + z3) <= LIM) {
sa[sp] = ((int32_t)(x));
sb[sp] = ((int32_t)(y));
sc[sp] = ((int32_t)(z3));
sp = (sp + 1);
}
}
}
printf("%lld\n", count);
free(sa);
free(sb);
free(sc);
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 25000000 : i32
%1 = arith.extsi %0 : i32 to i64
%2 = arith.constant 20000000 : i32
%3 = arith.extsi %2 : i32 to i64
%5 = arith.constant 4 : i32
%6 = arith.extsi %5 : i32 to i64
%4 = func.call @calloc(%3, %6) : (i64, i64) -> !llvm.ptr
%8 = arith.constant 4 : i32
%9 = arith.extsi %8 : i32 to i64
%7 = func.call @calloc(%3, %9) : (i64, i64) -> !llvm.ptr
%11 = arith.constant 4 : i32
%12 = arith.extsi %11 : i32 to i64
%10 = func.call @calloc(%3, %12) : (i64, i64) -> !llvm.ptr
%13 = llvm.mlir.zero : !llvm.ptr
%14 = llvm.icmp "eq" %4, %13 : !llvm.ptr
%15 = scf.if %14 -> (i1) {
%16 = arith.constant true
scf.yield %16 : i1
} else {
%17 = llvm.mlir.zero : !llvm.ptr
%18 = llvm.icmp "eq" %7, %17 : !llvm.ptr
scf.yield %18 : i1
}
%19 = scf.if %15 -> (i1) {
%20 = arith.constant true
scf.yield %20 : i1
} else {
%21 = llvm.mlir.zero : !llvm.ptr
%22 = llvm.icmp "eq" %10, %21 : !llvm.ptr
scf.yield %22 : i1
}
cf.cond_br %19, ^bb0, ^bb1
^bb0:
%23 = arith.constant 1 : i32
func.return %23 : i32
^bb1:
cf.br ^bb2
^bb2:
%24 = arith.constant 0 : i32
%25 = arith.extsi %24 : i32 to i64
%26 = llvm.mlir.constant(1 : i64) : i64
%27 = llvm.alloca %26 x i64 : (i64) -> !llvm.ptr
llvm.store %25, %27 : i64, !llvm.ptr
%28 = arith.constant 1 : i32
%29 = arith.constant 0 : i32
%30 = arith.extsi %29 : i32 to i64
%31 = llvm.getelementptr %4[%30] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %28, %31 : i32, !llvm.ptr
%32 = arith.constant 1 : i32
%33 = arith.constant 0 : i32
%34 = arith.extsi %33 : i32 to i64
%35 = llvm.getelementptr %7[%34] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %32, %35 : i32, !llvm.ptr
%36 = arith.constant 1 : i32
%37 = arith.constant 0 : i32
%38 = arith.extsi %37 : i32 to i64
%39 = llvm.getelementptr %10[%38] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %36, %39 : i32, !llvm.ptr
%40 = arith.constant 1 : i32
%41 = arith.extsi %40 : i32 to i64
llvm.store %41, %27 : i64, !llvm.ptr
%42 = arith.constant 1 : i32
%43 = arith.constant 1 : i32
%44 = arith.extsi %43 : i32 to i64
%45 = llvm.getelementptr %4[%44] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %42, %45 : i32, !llvm.ptr
%46 = arith.constant 2 : i32
%47 = arith.constant 1 : i32
%48 = arith.extsi %47 : i32 to i64
%49 = llvm.getelementptr %7[%48] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %46, %49 : i32, !llvm.ptr
%50 = arith.constant 2 : i32
%51 = arith.constant 1 : i32
%52 = arith.extsi %51 : i32 to i64
%53 = llvm.getelementptr %10[%52] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %50, %53 : i32, !llvm.ptr
%54 = arith.constant 2 : i32
%55 = arith.extsi %54 : i32 to i64
llvm.store %55, %27 : i64, !llvm.ptr
%56 = arith.constant 0 : i32
%57 = arith.extsi %56 : i32 to i64
%58 = llvm.mlir.constant(1 : i64) : i64
%59 = llvm.alloca %58 x i64 : (i64) -> !llvm.ptr
llvm.store %57, %59 : i64, !llvm.ptr
cf.br ^bb3
^bb3:
%60 = llvm.load %27 : !llvm.ptr -> i64
%61 = arith.constant 0 : i32
%63 = arith.extsi %61 : i32 to i64
%62 = arith.cmpi sgt, %60, %63 : i64
cf.cond_br %62, ^bb4, ^bb5
^bb4:
%64 = llvm.load %27 : !llvm.ptr -> i64
%65 = arith.constant 1 : i32
%67 = arith.extsi %65 : i32 to i64
%66 = arith.subi %64, %67 : i64
llvm.store %66, %27 : i64, !llvm.ptr
%69 = llvm.load %27 : !llvm.ptr -> i64
%70 = llvm.getelementptr %4[%69] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%68 = llvm.load %70 : !llvm.ptr -> i32
%71 = arith.extsi %68 : i32 to i64
%73 = llvm.load %27 : !llvm.ptr -> i64
%74 = llvm.getelementptr %7[%73] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%72 = llvm.load %74 : !llvm.ptr -> i32
%75 = arith.extsi %72 : i32 to i64
%77 = llvm.load %27 : !llvm.ptr -> i64
%78 = llvm.getelementptr %10[%77] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%76 = llvm.load %78 : !llvm.ptr -> i32
%79 = arith.extsi %76 : i32 to i64
%80 = arith.addi %71, %75 : i64
%81 = arith.addi %80, %79 : i64
%82 = arith.cmpi sgt, %81, %1 : i64
cf.cond_br %82, ^bb6, ^bb7
^bb6:
cf.br ^bb3
^bb7:
cf.br ^bb8
^bb8:
%83 = llvm.load %59 : !llvm.ptr -> i64
%84 = arith.constant 1 : i32
%86 = arith.extsi %84 : i32 to i64
%85 = arith.addi %83, %86 : i64
llvm.store %85, %59 : i64, !llvm.ptr
%87 = arith.constant 2 : i32
%89 = arith.extsi %87 : i32 to i64
%88 = arith.muli %89, %75 : i64
%90 = arith.subi %71, %88 : i64
%91 = arith.constant 2 : i32
%93 = arith.extsi %91 : i32 to i64
%92 = arith.muli %93, %79 : i64
%94 = arith.addi %90, %92 : i64
%95 = llvm.mlir.constant(1 : i64) : i64
%96 = llvm.alloca %95 x i64 : (i64) -> !llvm.ptr
llvm.store %94, %96 : i64, !llvm.ptr
%97 = arith.constant 2 : i32
%99 = arith.extsi %97 : i32 to i64
%98 = arith.muli %99, %71 : i64
%100 = arith.subi %98, %75 : i64
%101 = arith.constant 2 : i32
%103 = arith.extsi %101 : i32 to i64
%102 = arith.muli %103, %79 : i64
%104 = arith.addi %100, %102 : i64
%105 = llvm.mlir.constant(1 : i64) : i64
%106 = llvm.alloca %105 x i64 : (i64) -> !llvm.ptr
llvm.store %104, %106 : i64, !llvm.ptr
%107 = arith.constant 2 : i32
%109 = arith.extsi %107 : i32 to i64
%108 = arith.muli %109, %71 : i64
%110 = arith.constant 2 : i32
%112 = arith.extsi %110 : i32 to i64
%111 = arith.muli %112, %75 : i64
%113 = arith.subi %108, %111 : i64
%114 = arith.constant 3 : i32
%116 = arith.extsi %114 : i32 to i64
%115 = arith.muli %116, %79 : i64
%117 = arith.addi %113, %115 : i64
%118 = llvm.load %96 : !llvm.ptr -> i64
%119 = llvm.load %106 : !llvm.ptr -> i64
%120 = arith.cmpi sgt, %118, %119 : i64
cf.cond_br %120, ^bb9, ^bb10
^bb9:
%121 = llvm.load %96 : !llvm.ptr -> i64
%122 = llvm.load %106 : !llvm.ptr -> i64
llvm.store %122, %96 : i64, !llvm.ptr
llvm.store %121, %106 : i64, !llvm.ptr
cf.br ^bb11
^bb10:
cf.br ^bb11
^bb11:
%123 = llvm.load %96 : !llvm.ptr -> i64
%124 = llvm.load %106 : !llvm.ptr -> i64
%125 = arith.addi %123, %124 : i64
%126 = arith.addi %125, %117 : i64
%127 = arith.cmpi sle, %126, %1 : i64
cf.cond_br %127, ^bb12, ^bb13
^bb12:
%128 = llvm.load %96 : !llvm.ptr -> i64
%129 = arith.trunci %128 : i64 to i32
%130 = llvm.load %27 : !llvm.ptr -> i64
%131 = llvm.getelementptr %4[%130] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %129, %131 : i32, !llvm.ptr
%132 = llvm.load %106 : !llvm.ptr -> i64
%133 = arith.trunci %132 : i64 to i32
%134 = llvm.load %27 : !llvm.ptr -> i64
%135 = llvm.getelementptr %7[%134] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %133, %135 : i32, !llvm.ptr
%136 = arith.trunci %117 : i64 to i32
%137 = llvm.load %27 : !llvm.ptr -> i64
%138 = llvm.getelementptr %10[%137] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %136, %138 : i32, !llvm.ptr
%139 = llvm.load %27 : !llvm.ptr -> i64
%140 = arith.constant 1 : i32
%142 = arith.extsi %140 : i32 to i64
%141 = arith.addi %139, %142 : i64
llvm.store %141, %27 : i64, !llvm.ptr
cf.br ^bb14
^bb13:
cf.br ^bb14
^bb14:
%143 = arith.constant 2 : i32
%145 = arith.extsi %143 : i32 to i64
%144 = arith.muli %145, %75 : i64
%146 = arith.addi %71, %144 : i64
%147 = arith.constant 2 : i32
%149 = arith.extsi %147 : i32 to i64
%148 = arith.muli %149, %79 : i64
%150 = arith.addi %146, %148 : i64
llvm.store %150, %96 : i64, !llvm.ptr
%151 = arith.constant 2 : i32
%153 = arith.extsi %151 : i32 to i64
%152 = arith.muli %153, %71 : i64
%154 = arith.addi %152, %75 : i64
%155 = arith.constant 2 : i32
%157 = arith.extsi %155 : i32 to i64
%156 = arith.muli %157, %79 : i64
%158 = arith.addi %154, %156 : i64
llvm.store %158, %106 : i64, !llvm.ptr
%159 = arith.constant 2 : i32
%161 = arith.extsi %159 : i32 to i64
%160 = arith.muli %161, %71 : i64
%162 = arith.constant 2 : i32
%164 = arith.extsi %162 : i32 to i64
%163 = arith.muli %164, %75 : i64
%165 = arith.addi %160, %163 : i64
%166 = arith.constant 3 : i32
%168 = arith.extsi %166 : i32 to i64
%167 = arith.muli %168, %79 : i64
%169 = arith.addi %165, %167 : i64
%170 = llvm.load %96 : !llvm.ptr -> i64
%171 = llvm.load %106 : !llvm.ptr -> i64
%172 = arith.cmpi sgt, %170, %171 : i64
cf.cond_br %172, ^bb15, ^bb16
^bb15:
%173 = llvm.load %96 : !llvm.ptr -> i64
%174 = llvm.load %106 : !llvm.ptr -> i64
llvm.store %174, %96 : i64, !llvm.ptr
llvm.store %173, %106 : i64, !llvm.ptr
cf.br ^bb17
^bb16:
cf.br ^bb17
^bb17:
%175 = llvm.load %96 : !llvm.ptr -> i64
%176 = llvm.load %106 : !llvm.ptr -> i64
%177 = arith.addi %175, %176 : i64
%178 = arith.addi %177, %169 : i64
%179 = arith.cmpi sle, %178, %1 : i64
cf.cond_br %179, ^bb18, ^bb19
^bb18:
%180 = llvm.load %96 : !llvm.ptr -> i64
%181 = arith.trunci %180 : i64 to i32
%182 = llvm.load %27 : !llvm.ptr -> i64
%183 = llvm.getelementptr %4[%182] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %181, %183 : i32, !llvm.ptr
%184 = llvm.load %106 : !llvm.ptr -> i64
%185 = arith.trunci %184 : i64 to i32
%186 = llvm.load %27 : !llvm.ptr -> i64
%187 = llvm.getelementptr %7[%186] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %185, %187 : i32, !llvm.ptr
%188 = arith.trunci %169 : i64 to i32
%189 = llvm.load %27 : !llvm.ptr -> i64
%190 = llvm.getelementptr %10[%189] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %188, %190 : i32, !llvm.ptr
%191 = llvm.load %27 : !llvm.ptr -> i64
%192 = arith.constant 1 : i32
%194 = arith.extsi %192 : i32 to i64
%193 = arith.addi %191, %194 : i64
llvm.store %193, %27 : i64, !llvm.ptr
cf.br ^bb20
^bb19:
cf.br ^bb20
^bb20:
%195 = arith.cmpi ne, %71, %75 : i64
cf.cond_br %195, ^bb21, ^bb22
^bb21:
%196 = arith.constant 0 : i32
%198 = arith.extsi %196 : i32 to i64
%197 = arith.subi %198, %71 : i64
%199 = arith.constant 2 : i32
%201 = arith.extsi %199 : i32 to i64
%200 = arith.muli %201, %75 : i64
%202 = arith.addi %197, %200 : i64
%203 = arith.constant 2 : i32
%205 = arith.extsi %203 : i32 to i64
%204 = arith.muli %205, %79 : i64
%206 = arith.addi %202, %204 : i64
llvm.store %206, %96 : i64, !llvm.ptr
%207 = arith.constant 0 : i32
%208 = arith.constant 2 : i32
%210 = arith.extsi %208 : i32 to i64
%209 = arith.muli %210, %71 : i64
%212 = arith.extsi %207 : i32 to i64
%211 = arith.subi %212, %209 : i64
%213 = arith.addi %211, %75 : i64
%214 = arith.constant 2 : i32
%216 = arith.extsi %214 : i32 to i64
%215 = arith.muli %216, %79 : i64
%217 = arith.addi %213, %215 : i64
llvm.store %217, %106 : i64, !llvm.ptr
%218 = arith.constant 0 : i32
%219 = arith.constant 2 : i32
%221 = arith.extsi %219 : i32 to i64
%220 = arith.muli %221, %71 : i64
%223 = arith.extsi %218 : i32 to i64
%222 = arith.subi %223, %220 : i64
%224 = arith.constant 2 : i32
%226 = arith.extsi %224 : i32 to i64
%225 = arith.muli %226, %75 : i64
%227 = arith.addi %222, %225 : i64
%228 = arith.constant 3 : i32
%230 = arith.extsi %228 : i32 to i64
%229 = arith.muli %230, %79 : i64
%231 = arith.addi %227, %229 : i64
%232 = llvm.load %96 : !llvm.ptr -> i64
%233 = llvm.load %106 : !llvm.ptr -> i64
%234 = arith.cmpi sgt, %232, %233 : i64
cf.cond_br %234, ^bb24, ^bb25
^bb24:
%235 = llvm.load %96 : !llvm.ptr -> i64
%236 = llvm.load %106 : !llvm.ptr -> i64
llvm.store %236, %96 : i64, !llvm.ptr
llvm.store %235, %106 : i64, !llvm.ptr
cf.br ^bb26
^bb25:
cf.br ^bb26
^bb26:
%237 = llvm.load %96 : !llvm.ptr -> i64
%238 = llvm.load %106 : !llvm.ptr -> i64
%239 = arith.addi %237, %238 : i64
%240 = arith.addi %239, %231 : i64
%241 = arith.cmpi sle, %240, %1 : i64
cf.cond_br %241, ^bb27, ^bb28
^bb27:
%242 = llvm.load %96 : !llvm.ptr -> i64
%243 = arith.trunci %242 : i64 to i32
%244 = llvm.load %27 : !llvm.ptr -> i64
%245 = llvm.getelementptr %4[%244] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %243, %245 : i32, !llvm.ptr
%246 = llvm.load %106 : !llvm.ptr -> i64
%247 = arith.trunci %246 : i64 to i32
%248 = llvm.load %27 : !llvm.ptr -> i64
%249 = llvm.getelementptr %7[%248] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %247, %249 : i32, !llvm.ptr
%250 = arith.trunci %231 : i64 to i32
%251 = llvm.load %27 : !llvm.ptr -> i64
%252 = llvm.getelementptr %10[%251] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %250, %252 : i32, !llvm.ptr
%253 = llvm.load %27 : !llvm.ptr -> i64
%254 = arith.constant 1 : i32
%256 = arith.extsi %254 : i32 to i64
%255 = arith.addi %253, %256 : i64
llvm.store %255, %27 : i64, !llvm.ptr
cf.br ^bb29
^bb28:
cf.br ^bb29
^bb29:
cf.br ^bb23
^bb22:
cf.br ^bb23
^bb23:
cf.br ^bb3
^bb5:
%257 = llvm.mlir.addressof @str_0 : !llvm.ptr
%258 = llvm.load %59 : !llvm.ptr -> i64
%259 = llvm.call @printf(%257, %258) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
func.call @free(%4) : (!llvm.ptr) -> ()
func.call @free(%7) : (!llvm.ptr) -> ()
func.call @free(%10) : (!llvm.ptr) -> ()
%263 = arith.constant 0 : i32
func.return %263 : i32
}
}