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