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