← All problems
Problem 201
Sum of uniquely-occurring 50-element subset sums of {1^2..100^2}.
View problem on Project Euler
Performance comparison
Metric Our solution Best known
Time complexity O(n^2)O(n * sum)
Space complexity O(n)O(sum)
Approach Flow solution Subset sum DP
Verdict Unknown
Flow source
# Project Euler 201
# Sum of uniquely-occurring 50-element subset sums of {1^2..100^2}.
extern {
function calloc(n: i64, size: i64) -> ptr<void>
function free(p: ptr<void>) -> void
}
function main() -> i32 {
let N: i32 = 100
let K: i32 = 50
let mut max_sum: i64 = 0
let mut i: i32 = N - K + 1
while i <= N {
max_sum = max_sum + (i as i64) * (i as i64)
i = i + 1
}
let SZ: i64 = max_sum + 1
# state[size][sum] capped at 2
let state: ptr<i8> = calloc((K as i64 + 1) * SZ, 1)
let low: ptr<i64> = calloc(K as i64 + 1, 8)
let high: ptr<i64> = calloc(K as i64 + 1, 8)
if state == null || low == null || high == null { return 1 }
let MISSING: i64 = max_sum + 1
i = 0
while i <= K {
low[i] = MISSING
high[i] = 0 - 1
i = i + 1
}
state[0] = 1
low[0] = 0
high[0] = 0
let mut used: i32 = 0
let mut sq_i: i32 = 1
while sq_i <= N {
let square: i64 = (sq_i as i64) * (sq_i as i64)
let upper: i32 = used + 1
let mut size: i32 = upper
if size > K { size = K }
while size > 0 {
let lo: i64 = low[size - 1]
if lo != MISSING {
let hi: i64 = high[size - 1]
let mut sub: i64 = hi
while sub >= lo {
let ways: i32 = state[((size - 1) as i64) * SZ + sub] as i32
if ways != 0 {
let ns: i64 = sub + square
let mut nw: i32 = (state[(size as i64) * SZ + ns] as i32) + ways
if nw >= 2 { nw = 2 }
state[(size as i64) * SZ + ns] = nw as i8
}
sub = sub - 1
}
let nlo: i64 = lo + square
let nhi: i64 = hi + square
if nlo < low[size] { low[size] = nlo }
if nhi > high[size] { high[size] = nhi }
}
size = size - 1
}
used = used + 1
sq_i = sq_i + 1
}
let mut total: i64 = 0
let mut s: i64 = low[K]
while s <= high[K] {
if state[(K as i64) * SZ + s] == 1 {
total = total + s
}
s = s + 1
}
printf("%lld\n", total)
free(state); free(low); free(high)
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;
int32_t K = 50;
int64_t max_sum = 0;
int32_t i = ((N - K) + 1);
while (i <= N) {
max_sum = (max_sum + (((int64_t)(i)) * ((int64_t)(i))));
i = (i + 1);
}
int64_t SZ = (max_sum + 1);
int8_t* state = (int8_t*)(calloc(((((int64_t)(K)) + 1) * SZ), 1));
int64_t* low = (int64_t*)(calloc((((int64_t)(K)) + 1), 8));
int64_t* high = (int64_t*)(calloc((((int64_t)(K)) + 1), 8));
if (((state == NULL || low == NULL) || high == NULL)) {
return 1;
}
int64_t MISSING = (max_sum + 1);
i = 0;
while (i <= K) {
low[i] = MISSING;
high[i] = (0 - 1);
i = (i + 1);
}
state[0] = 1;
low[0] = 0;
high[0] = 0;
int32_t used = 0;
int32_t sq_i = 1;
while (sq_i <= N) {
int64_t square = (((int64_t)(sq_i)) * ((int64_t)(sq_i)));
int32_t upper = (used + 1);
int32_t size = upper;
if (size > K) {
size = K;
}
while (size > 0) {
int64_t lo = low[(size - 1)];
if (lo != MISSING) {
int64_t hi = high[(size - 1)];
int64_t sub = hi;
while (sub >= lo) {
int32_t ways = ((int32_t)(state[((((int64_t)((size - 1))) * SZ) + sub)]));
if (ways != 0) {
int64_t ns = (sub + square);
int32_t nw = (((int32_t)(state[((((int64_t)(size)) * SZ) + ns)])) + ways);
if (nw >= 2) {
nw = 2;
}
state[((((int64_t)(size)) * SZ) + ns)] = ((int8_t)(nw));
}
sub = (sub - 1);
}
int64_t nlo = (lo + square);
int64_t nhi = (hi + square);
if (nlo < low[size]) {
low[size] = nlo;
}
if (nhi > high[size]) {
high[size] = nhi;
}
}
size = (size - 1);
}
used = (used + 1);
sq_i = (sq_i + 1);
}
int64_t total = 0;
int64_t s = low[K];
while (s <= high[K]) {
if (state[((((int64_t)(K)) * SZ) + s)] == 1) {
total = (total + s);
}
s = (s + 1);
}
printf("%lld\n", total);
free(state);
free(low);
free(high);
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 50 : i32
%2 = arith.constant 0 : i32
%3 = arith.extsi %2 : i32 to i64
%4 = llvm.mlir.constant(1 : i64) : i64
%5 = llvm.alloca %4 x i64 : (i64) -> !llvm.ptr
llvm.store %3, %5 : i64, !llvm.ptr
%6 = arith.subi %0, %1 : i32
%7 = arith.constant 1 : i32
%8 = arith.addi %6, %7 : i32
%9 = llvm.mlir.constant(1 : i64) : i64
%10 = llvm.alloca %9 x i32 : (i64) -> !llvm.ptr
llvm.store %8, %10 : i32, !llvm.ptr
cf.br ^bb0
^bb0:
%11 = llvm.load %10 : !llvm.ptr -> i32
%12 = arith.cmpi sle, %11, %0 : i32
cf.cond_br %12, ^bb1, ^bb2
^bb1:
%13 = llvm.load %5 : !llvm.ptr -> i64
%14 = llvm.load %10 : !llvm.ptr -> i32
%15 = arith.extsi %14 : i32 to i64
%16 = llvm.load %10 : !llvm.ptr -> i32
%17 = arith.extsi %16 : i32 to i64
%18 = arith.muli %15, %17 : i64
%19 = arith.addi %13, %18 : i64
llvm.store %19, %5 : i64, !llvm.ptr
%20 = llvm.load %10 : !llvm.ptr -> i32
%21 = arith.constant 1 : i32
%22 = arith.addi %20, %21 : i32
llvm.store %22, %10 : i32, !llvm.ptr
cf.br ^bb0
^bb2:
%23 = llvm.load %5 : !llvm.ptr -> i64
%24 = arith.constant 1 : i32
%26 = arith.extsi %24 : i32 to i64
%25 = arith.addi %23, %26 : i64
%28 = arith.extsi %1 : i32 to i64
%29 = arith.constant 1 : i32
%31 = arith.extsi %29 : i32 to i64
%30 = arith.addi %28, %31 : i64
%32 = arith.muli %30, %25 : i64
%33 = arith.constant 1 : i32
%34 = arith.extsi %33 : i32 to i64
%27 = func.call @calloc(%32, %34) : (i64, i64) -> !llvm.ptr
%36 = arith.extsi %1 : i32 to i64
%37 = arith.constant 1 : i32
%39 = arith.extsi %37 : i32 to i64
%38 = arith.addi %36, %39 : i64
%40 = arith.constant 8 : i32
%41 = arith.extsi %40 : i32 to i64
%35 = func.call @calloc(%38, %41) : (i64, i64) -> !llvm.ptr
%43 = arith.extsi %1 : i32 to i64
%44 = arith.constant 1 : i32
%46 = arith.extsi %44 : i32 to i64
%45 = arith.addi %43, %46 : i64
%47 = arith.constant 8 : i32
%48 = arith.extsi %47 : i32 to i64
%42 = func.call @calloc(%45, %48) : (i64, i64) -> !llvm.ptr
%49 = llvm.mlir.zero : !llvm.ptr
%50 = llvm.icmp "eq" %27, %49 : !llvm.ptr
%51 = scf.if %50 -> (i1) {
%52 = arith.constant true
scf.yield %52 : i1
} else {
%53 = llvm.mlir.zero : !llvm.ptr
%54 = llvm.icmp "eq" %35, %53 : !llvm.ptr
scf.yield %54 : i1
}
%55 = scf.if %51 -> (i1) {
%56 = arith.constant true
scf.yield %56 : i1
} else {
%57 = llvm.mlir.zero : !llvm.ptr
%58 = llvm.icmp "eq" %42, %57 : !llvm.ptr
scf.yield %58 : i1
}
cf.cond_br %55, ^bb3, ^bb4
^bb3:
%59 = arith.constant 1 : i32
func.return %59 : i32
^bb4:
cf.br ^bb5
^bb5:
%60 = llvm.load %5 : !llvm.ptr -> i64
%61 = arith.constant 1 : i32
%63 = arith.extsi %61 : i32 to i64
%62 = arith.addi %60, %63 : i64
%64 = arith.constant 0 : i32
llvm.store %64, %10 : i32, !llvm.ptr
cf.br ^bb6
^bb6:
%65 = llvm.load %10 : !llvm.ptr -> i32
%66 = arith.cmpi sle, %65, %1 : i32
cf.cond_br %66, ^bb7, ^bb8
^bb7:
%67 = llvm.load %10 : !llvm.ptr -> i32
%68 = arith.extsi %67 : i32 to i64
%69 = llvm.getelementptr %35[%68] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %62, %69 : i64, !llvm.ptr
%70 = arith.constant 0 : i32
%71 = arith.constant 1 : i32
%72 = arith.subi %70, %71 : i32
%73 = llvm.load %10 : !llvm.ptr -> i32
%74 = arith.extsi %72 : i32 to i64
%75 = arith.extsi %73 : i32 to i64
%76 = llvm.getelementptr %42[%75] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %74, %76 : i64, !llvm.ptr
%77 = llvm.load %10 : !llvm.ptr -> i32
%78 = arith.constant 1 : i32
%79 = arith.addi %77, %78 : i32
llvm.store %79, %10 : i32, !llvm.ptr
cf.br ^bb6
^bb8:
%80 = arith.constant 1 : i32
%81 = arith.constant 0 : i32
%82 = arith.trunci %80 : i32 to i8
%83 = arith.extsi %81 : i32 to i64
%84 = llvm.getelementptr %27[%83] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %82, %84 : i8, !llvm.ptr
%85 = arith.constant 0 : i32
%86 = arith.constant 0 : i32
%87 = arith.extsi %85 : i32 to i64
%88 = arith.extsi %86 : i32 to i64
%89 = llvm.getelementptr %35[%88] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %87, %89 : i64, !llvm.ptr
%90 = arith.constant 0 : i32
%91 = arith.constant 0 : i32
%92 = arith.extsi %90 : i32 to i64
%93 = arith.extsi %91 : i32 to i64
%94 = llvm.getelementptr %42[%93] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %92, %94 : i64, !llvm.ptr
%95 = arith.constant 0 : i32
%96 = llvm.mlir.constant(1 : i64) : i64
%97 = llvm.alloca %96 x i32 : (i64) -> !llvm.ptr
llvm.store %95, %97 : i32, !llvm.ptr
%98 = arith.constant 1 : i32
%99 = llvm.mlir.constant(1 : i64) : i64
%100 = llvm.alloca %99 x i32 : (i64) -> !llvm.ptr
llvm.store %98, %100 : i32, !llvm.ptr
cf.br ^bb9
^bb9:
%101 = llvm.load %100 : !llvm.ptr -> i32
%102 = arith.cmpi sle, %101, %0 : i32
cf.cond_br %102, ^bb10, ^bb11
^bb10:
%103 = llvm.load %100 : !llvm.ptr -> i32
%104 = arith.extsi %103 : i32 to i64
%105 = llvm.load %100 : !llvm.ptr -> i32
%106 = arith.extsi %105 : i32 to i64
%107 = arith.muli %104, %106 : i64
%108 = llvm.load %97 : !llvm.ptr -> i32
%109 = arith.constant 1 : i32
%110 = arith.addi %108, %109 : i32
%111 = llvm.mlir.constant(1 : i64) : i64
%112 = llvm.alloca %111 x i32 : (i64) -> !llvm.ptr
llvm.store %110, %112 : i32, !llvm.ptr
%113 = llvm.load %112 : !llvm.ptr -> i32
%114 = arith.cmpi sgt, %113, %1 : i32
cf.cond_br %114, ^bb12, ^bb13
^bb12:
llvm.store %1, %112 : i32, !llvm.ptr
cf.br ^bb14
^bb13:
cf.br ^bb14
^bb14:
cf.br ^bb15
^bb15:
%115 = llvm.load %112 : !llvm.ptr -> i32
%116 = arith.constant 0 : i32
%117 = arith.cmpi sgt, %115, %116 : i32
cf.cond_br %117, ^bb16, ^bb17
^bb16:
%119 = llvm.load %112 : !llvm.ptr -> i32
%120 = arith.constant 1 : i32
%121 = arith.subi %119, %120 : i32
%122 = arith.extsi %121 : i32 to i64
%123 = llvm.getelementptr %35[%122] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%118 = llvm.load %123 : !llvm.ptr -> i64
%124 = arith.cmpi ne, %118, %62 : i64
cf.cond_br %124, ^bb18, ^bb19
^bb18:
%126 = llvm.load %112 : !llvm.ptr -> i32
%127 = arith.constant 1 : i32
%128 = arith.subi %126, %127 : i32
%129 = arith.extsi %128 : i32 to i64
%130 = llvm.getelementptr %42[%129] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%125 = llvm.load %130 : !llvm.ptr -> i64
%131 = llvm.mlir.constant(1 : i64) : i64
%132 = llvm.alloca %131 x i64 : (i64) -> !llvm.ptr
llvm.store %125, %132 : i64, !llvm.ptr
cf.br ^bb21
^bb21:
%133 = llvm.load %132 : !llvm.ptr -> i64
%134 = arith.cmpi sge, %133, %118 : i64
cf.cond_br %134, ^bb22, ^bb23
^bb22:
%136 = llvm.load %112 : !llvm.ptr -> i32
%137 = arith.constant 1 : i32
%138 = arith.subi %136, %137 : i32
%139 = arith.extsi %138 : i32 to i64
%140 = arith.muli %139, %25 : i64
%141 = llvm.load %132 : !llvm.ptr -> i64
%142 = arith.addi %140, %141 : i64
%143 = llvm.getelementptr %27[%142] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%135 = llvm.load %143 : !llvm.ptr -> i8
%144 = arith.extsi %135 : i8 to i32
%145 = arith.constant 0 : i32
%146 = arith.cmpi ne, %144, %145 : i32
cf.cond_br %146, ^bb24, ^bb25
^bb24:
%147 = llvm.load %132 : !llvm.ptr -> i64
%148 = arith.addi %147, %107 : i64
%150 = llvm.load %112 : !llvm.ptr -> i32
%151 = arith.extsi %150 : i32 to i64
%152 = arith.muli %151, %25 : i64
%153 = arith.addi %152, %148 : i64
%154 = llvm.getelementptr %27[%153] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%149 = llvm.load %154 : !llvm.ptr -> i8
%155 = arith.extsi %149 : i8 to i32
%156 = arith.addi %155, %144 : i32
%157 = llvm.mlir.constant(1 : i64) : i64
%158 = llvm.alloca %157 x i32 : (i64) -> !llvm.ptr
llvm.store %156, %158 : i32, !llvm.ptr
%159 = llvm.load %158 : !llvm.ptr -> i32
%160 = arith.constant 2 : i32
%161 = arith.cmpi sge, %159, %160 : i32
cf.cond_br %161, ^bb27, ^bb28
^bb27:
%162 = arith.constant 2 : i32
llvm.store %162, %158 : i32, !llvm.ptr
cf.br ^bb29
^bb28:
cf.br ^bb29
^bb29:
%163 = llvm.load %158 : !llvm.ptr -> i32
%164 = arith.trunci %163 : i32 to i8
%165 = llvm.load %112 : !llvm.ptr -> i32
%166 = arith.extsi %165 : i32 to i64
%167 = arith.muli %166, %25 : i64
%168 = arith.addi %167, %148 : i64
%169 = llvm.getelementptr %27[%168] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %164, %169 : i8, !llvm.ptr
cf.br ^bb26
^bb25:
cf.br ^bb26
^bb26:
%170 = llvm.load %132 : !llvm.ptr -> i64
%171 = arith.constant 1 : i32
%173 = arith.extsi %171 : i32 to i64
%172 = arith.subi %170, %173 : i64
llvm.store %172, %132 : i64, !llvm.ptr
cf.br ^bb21
^bb23:
%174 = arith.addi %118, %107 : i64
%175 = arith.addi %125, %107 : i64
%177 = llvm.load %112 : !llvm.ptr -> i32
%178 = arith.extsi %177 : i32 to i64
%179 = llvm.getelementptr %35[%178] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%176 = llvm.load %179 : !llvm.ptr -> i64
%180 = arith.cmpi slt, %174, %176 : i64
cf.cond_br %180, ^bb30, ^bb31
^bb30:
%181 = llvm.load %112 : !llvm.ptr -> i32
%182 = arith.extsi %181 : i32 to i64
%183 = llvm.getelementptr %35[%182] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %174, %183 : i64, !llvm.ptr
cf.br ^bb32
^bb31:
cf.br ^bb32
^bb32:
%185 = llvm.load %112 : !llvm.ptr -> i32
%186 = arith.extsi %185 : i32 to i64
%187 = llvm.getelementptr %42[%186] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%184 = llvm.load %187 : !llvm.ptr -> i64
%188 = arith.cmpi sgt, %175, %184 : i64
cf.cond_br %188, ^bb33, ^bb34
^bb33:
%189 = llvm.load %112 : !llvm.ptr -> i32
%190 = arith.extsi %189 : i32 to i64
%191 = llvm.getelementptr %42[%190] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %175, %191 : i64, !llvm.ptr
cf.br ^bb35
^bb34:
cf.br ^bb35
^bb35:
cf.br ^bb20
^bb19:
cf.br ^bb20
^bb20:
%192 = llvm.load %112 : !llvm.ptr -> i32
%193 = arith.constant 1 : i32
%194 = arith.subi %192, %193 : i32
llvm.store %194, %112 : i32, !llvm.ptr
cf.br ^bb15
^bb17:
%195 = llvm.load %97 : !llvm.ptr -> i32
%196 = arith.constant 1 : i32
%197 = arith.addi %195, %196 : i32
llvm.store %197, %97 : i32, !llvm.ptr
%198 = llvm.load %100 : !llvm.ptr -> i32
%199 = arith.constant 1 : i32
%200 = arith.addi %198, %199 : i32
llvm.store %200, %100 : i32, !llvm.ptr
cf.br ^bb9
^bb11:
%201 = arith.constant 0 : i32
%202 = arith.extsi %201 : i32 to i64
%203 = llvm.mlir.constant(1 : i64) : i64
%204 = llvm.alloca %203 x i64 : (i64) -> !llvm.ptr
llvm.store %202, %204 : i64, !llvm.ptr
%206 = arith.extsi %1 : i32 to i64
%207 = llvm.getelementptr %35[%206] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%205 = llvm.load %207 : !llvm.ptr -> i64
%208 = llvm.mlir.constant(1 : i64) : i64
%209 = llvm.alloca %208 x i64 : (i64) -> !llvm.ptr
llvm.store %205, %209 : i64, !llvm.ptr
cf.br ^bb36
^bb36:
%210 = llvm.load %209 : !llvm.ptr -> i64
%212 = arith.extsi %1 : i32 to i64
%213 = llvm.getelementptr %42[%212] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%211 = llvm.load %213 : !llvm.ptr -> i64
%214 = arith.cmpi sle, %210, %211 : i64
cf.cond_br %214, ^bb37, ^bb38
^bb37:
%216 = arith.extsi %1 : i32 to i64
%217 = arith.muli %216, %25 : i64
%218 = llvm.load %209 : !llvm.ptr -> i64
%219 = arith.addi %217, %218 : i64
%220 = llvm.getelementptr %27[%219] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%215 = llvm.load %220 : !llvm.ptr -> i8
%221 = arith.constant 1 : i32
%223 = arith.extsi %215 : i8 to i32
%222 = arith.cmpi eq, %223, %221 : i32
cf.cond_br %222, ^bb39, ^bb40
^bb39:
%224 = llvm.load %204 : !llvm.ptr -> i64
%225 = llvm.load %209 : !llvm.ptr -> i64
%226 = arith.addi %224, %225 : i64
llvm.store %226, %204 : i64, !llvm.ptr
cf.br ^bb41
^bb40:
cf.br ^bb41
^bb41:
%227 = llvm.load %209 : !llvm.ptr -> i64
%228 = arith.constant 1 : i32
%230 = arith.extsi %228 : i32 to i64
%229 = arith.addi %227, %230 : i64
llvm.store %229, %209 : i64, !llvm.ptr
cf.br ^bb36
^bb38:
%231 = llvm.mlir.addressof @str_0 : !llvm.ptr
%232 = llvm.load %204 : !llvm.ptr -> i64
%233 = llvm.call @printf(%231, %232) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
func.call @free(%27) : (!llvm.ptr) -> ()
func.call @free(%35) : (!llvm.ptr) -> ()
func.call @free(%42) : (!llvm.ptr) -> ()
%237 = arith.constant 0 : i32
func.return %237 : i32
}
}