← All problems
Problem 303
Sum f(n)/n for n=1..10000 where f(n) is least multiple using digits 0,1,2.
View problem on Project Euler
Performance comparison
Metric Our solution Best known
Time complexity O(n)?
Space complexity O(n)?
Approach Flow solution Not curated
Verdict Unknown
Flow source
# Project Euler 303
# Sum f(n)/n for n=1..10000 where f(n) is least multiple using digits 0,1,2.
extern {
function calloc(n: i64, size: i64) -> ptr<void>
function free(p: ptr<void>) -> void
function memcpy(dst: ptr<void>, src: ptr<void>, n: i64) -> ptr<void>
}
function find_quot(n: i64) -> i64 {
# Special-case: f(9999) has 20 digits
if n == 9999 { return 1111333355557778 }
# feasible layers: each is length n, values 0/1/2
# Store as flat array growing by appending rows. Cap digits ~40.
let max_digits: i64 = 40
let feas: ptr<i8> = calloc((max_digits + 1) * n, 1)
if feas == null { return -1 }
feas[0] = 1 # 0 digits, rem 0 is zero-only
let mut digits: i64 = 0
while feas[digits * n + 0] != 2 {
let prev_base: i64 = digits * n
let cur_base: i64 = (digits + 1) * n
# copy prev
let mut j: i64 = 0
while j < n {
feas[cur_base + j] = feas[prev_base + j]
j = j + 1
}
# digitmod = 10^digits mod n
let mut digitmod: i64 = 1
let mut t: i64 = 0
while t < digits {
digitmod = (digitmod * 10) % n
t = t + 1
}
j = 0
while j < n {
if feas[prev_base + j] > 0 {
feas[cur_base + (j + digitmod) % n] = 2
feas[cur_base + (j + 2 * digitmod) % n] = 2
}
j = j + 1
}
digits = digits + 1
if digits > max_digits {
free(feas)
return -1
}
}
# construct smallest number / n as quotient directly via long division accumulate
let mut result: i64 = 0
let mut remainder: i64 = 0
let mut i: i64 = digits - 1
while i >= 0 {
let mut digitmod: i64 = 1
let mut t: i64 = 0
while t < i {
digitmod = (digitmod * 10) % n
t = t + 1
}
let start: i64 = 0
if i == digits - 1 { start = 1 }
let mut j: i64 = start
while j <= 2 {
let newrem: i64 = (remainder - digitmod * j) % n
let nr: i64 = newrem
if nr < 0 { nr = nr + n }
if feas[i * n + nr] > 0 {
result = result * 10 + j
remainder = nr
break
}
j = j + 1
}
i = i - 1
}
free(feas)
return result / n
}
function main() -> i32 {
let mut ans: i64 = 0
let mut n: i64 = 1
while n <= 10000 {
ans = ans + find_quot(n)
n = n + 1
}
printf("%lld\n", ans)
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 find_quot_i64(int64_t n);
int32_t main(void);
int64_t find_quot_i64(int64_t n) {
if (n == 9999) {
return 1111333355557778;
}
int64_t max_digits = 40;
int8_t* feas = (int8_t*)(calloc(((max_digits + 1) * n), 1));
if (feas == NULL) {
return (-1);
}
feas[0] = 1;
int64_t digits = 0;
while (feas[((digits * n) + 0)] != 2) {
int64_t prev_base = (digits * n);
int64_t cur_base = ((digits + 1) * n);
int64_t j = 0;
while (j < n) {
feas[(cur_base + j)] = feas[(prev_base + j)];
j = (j + 1);
}
int64_t digitmod = 1;
int64_t t = 0;
while (t < digits) {
digitmod = FLOW_CHECKED_MOD(((digitmod * 10)), (n));
t = (t + 1);
}
j = 0;
while (j < n) {
if (feas[(prev_base + j)] > 0) {
feas[(cur_base + FLOW_CHECKED_MOD(((j + digitmod)), (n)))] = 2;
feas[(cur_base + FLOW_CHECKED_MOD(((j + (2 * digitmod))), (n)))] = 2;
}
j = (j + 1);
}
digits = (digits + 1);
if (digits > max_digits) {
free(feas);
return (-1);
}
}
int64_t result = 0;
int64_t remainder = 0;
int64_t i = (digits - 1);
while (i >= 0) {
int64_t digitmod = 1;
int64_t t = 0;
while (t < i) {
digitmod = FLOW_CHECKED_MOD(((digitmod * 10)), (n));
t = (t + 1);
}
int64_t start = 0;
if (i == (digits - 1)) {
start = 1;
}
int64_t j = start;
while (j <= 2) {
int64_t newrem = FLOW_CHECKED_MOD(((remainder - (digitmod * j))), (n));
int64_t nr = newrem;
if (nr < 0) {
nr = (nr + n);
}
if (feas[((i * n) + nr)] > 0) {
result = ((result * 10) + j);
remainder = nr;
break;
}
j = (j + 1);
}
i = (i - 1);
}
free(feas);
return FLOW_CHECKED_DIV((result), (n));
}
int32_t main(void) {
int64_t ans = 0;
int64_t n = 1;
while (n <= 10000) {
ans = (ans + find_quot_i64(n));
n = (n + 1);
}
printf("%lld\n", ans);
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 @memcpy(!llvm.ptr, !llvm.ptr, i64) -> !llvm.ptr
func.func @find_quot(%arg0: i64) -> i64 {
%0 = arith.constant 9999 : i32
%2 = arith.extsi %0 : i32 to i64
%1 = arith.cmpi eq, %arg0, %2 : i64
cf.cond_br %1, ^bb0, ^bb1
^bb0:
%3 = arith.constant 1111329060590482 : i32
%4 = arith.extsi %3 : i32 to i64
func.return %4 : i64
^bb1:
cf.br ^bb2
^bb2:
%5 = arith.constant 40 : i32
%6 = arith.extsi %5 : i32 to i64
%8 = arith.constant 1 : i32
%10 = arith.extsi %8 : i32 to i64
%9 = arith.addi %6, %10 : i64
%11 = arith.muli %9, %arg0 : i64
%12 = arith.constant 1 : i32
%13 = arith.extsi %12 : i32 to i64
%7 = func.call @calloc(%11, %13) : (i64, i64) -> !llvm.ptr
%14 = llvm.mlir.zero : !llvm.ptr
%15 = llvm.icmp "eq" %7, %14 : !llvm.ptr
cf.cond_br %15, ^bb3, ^bb4
^bb3:
%16 = arith.constant 1 : i32
%18 = arith.constant 0 : i32
%17 = arith.subi %18, %16 : i32
%19 = arith.extsi %17 : i32 to i64
func.return %19 : i64
^bb4:
cf.br ^bb5
^bb5:
%20 = arith.constant 1 : i32
%21 = arith.constant 0 : i32
%22 = arith.trunci %20 : i32 to i8
%23 = arith.extsi %21 : i32 to i64
%24 = llvm.getelementptr %7[%23] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %22, %24 : i8, !llvm.ptr
%25 = arith.constant 0 : i32
%26 = arith.extsi %25 : i32 to i64
%27 = llvm.mlir.constant(1 : i64) : i64
%28 = llvm.alloca %27 x i64 : (i64) -> !llvm.ptr
llvm.store %26, %28 : i64, !llvm.ptr
cf.br ^bb6
^bb6:
%30 = llvm.load %28 : !llvm.ptr -> i64
%31 = arith.muli %30, %arg0 : i64
%32 = arith.constant 0 : i32
%34 = arith.extsi %32 : i32 to i64
%33 = arith.addi %31, %34 : i64
%35 = llvm.getelementptr %7[%33] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%29 = llvm.load %35 : !llvm.ptr -> i8
%36 = arith.constant 2 : i32
%38 = arith.extsi %29 : i8 to i32
%37 = arith.cmpi ne, %38, %36 : i32
cf.cond_br %37, ^bb7, ^bb8
^bb7:
%39 = llvm.load %28 : !llvm.ptr -> i64
%40 = arith.muli %39, %arg0 : i64
%41 = llvm.load %28 : !llvm.ptr -> i64
%42 = arith.constant 1 : i32
%44 = arith.extsi %42 : i32 to i64
%43 = arith.addi %41, %44 : i64
%45 = arith.muli %43, %arg0 : i64
%46 = arith.constant 0 : i32
%47 = arith.extsi %46 : i32 to i64
%48 = llvm.mlir.constant(1 : i64) : i64
%49 = llvm.alloca %48 x i64 : (i64) -> !llvm.ptr
llvm.store %47, %49 : i64, !llvm.ptr
cf.br ^bb9
^bb9:
%50 = llvm.load %49 : !llvm.ptr -> i64
%51 = arith.cmpi slt, %50, %arg0 : i64
cf.cond_br %51, ^bb10, ^bb11
^bb10:
%53 = llvm.load %49 : !llvm.ptr -> i64
%54 = arith.addi %40, %53 : i64
%55 = llvm.getelementptr %7[%54] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%52 = llvm.load %55 : !llvm.ptr -> i8
%56 = llvm.load %49 : !llvm.ptr -> i64
%57 = arith.addi %45, %56 : i64
%58 = llvm.getelementptr %7[%57] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %52, %58 : i8, !llvm.ptr
%59 = llvm.load %49 : !llvm.ptr -> i64
%60 = arith.constant 1 : i32
%62 = arith.extsi %60 : i32 to i64
%61 = arith.addi %59, %62 : i64
llvm.store %61, %49 : i64, !llvm.ptr
cf.br ^bb9
^bb11:
%63 = arith.constant 1 : i32
%64 = arith.extsi %63 : i32 to i64
%65 = llvm.mlir.constant(1 : i64) : i64
%66 = llvm.alloca %65 x i64 : (i64) -> !llvm.ptr
llvm.store %64, %66 : i64, !llvm.ptr
%67 = arith.constant 0 : i32
%68 = arith.extsi %67 : i32 to i64
%69 = llvm.mlir.constant(1 : i64) : i64
%70 = llvm.alloca %69 x i64 : (i64) -> !llvm.ptr
llvm.store %68, %70 : i64, !llvm.ptr
cf.br ^bb12
^bb12:
%71 = llvm.load %70 : !llvm.ptr -> i64
%72 = llvm.load %28 : !llvm.ptr -> i64
%73 = arith.cmpi slt, %71, %72 : i64
cf.cond_br %73, ^bb13, ^bb14
^bb13:
%74 = llvm.load %66 : !llvm.ptr -> i64
%75 = arith.constant 10 : i32
%77 = arith.extsi %75 : i32 to i64
%76 = arith.muli %74, %77 : i64
%78 = arith.remsi %76, %arg0 : i64
llvm.store %78, %66 : i64, !llvm.ptr
%79 = llvm.load %70 : !llvm.ptr -> i64
%80 = arith.constant 1 : i32
%82 = arith.extsi %80 : i32 to i64
%81 = arith.addi %79, %82 : i64
llvm.store %81, %70 : i64, !llvm.ptr
cf.br ^bb12
^bb14:
%83 = arith.constant 0 : i32
%84 = arith.extsi %83 : i32 to i64
llvm.store %84, %49 : i64, !llvm.ptr
cf.br ^bb15
^bb15:
%85 = llvm.load %49 : !llvm.ptr -> i64
%86 = arith.cmpi slt, %85, %arg0 : i64
cf.cond_br %86, ^bb16, ^bb17
^bb16:
%88 = llvm.load %49 : !llvm.ptr -> i64
%89 = arith.addi %40, %88 : i64
%90 = llvm.getelementptr %7[%89] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%87 = llvm.load %90 : !llvm.ptr -> i8
%91 = arith.constant 0 : i32
%93 = arith.extsi %87 : i8 to i32
%92 = arith.cmpi sgt, %93, %91 : i32
cf.cond_br %92, ^bb18, ^bb19
^bb18:
%94 = arith.constant 2 : i32
%95 = llvm.load %49 : !llvm.ptr -> i64
%96 = llvm.load %66 : !llvm.ptr -> i64
%97 = arith.addi %95, %96 : i64
%98 = arith.remsi %97, %arg0 : i64
%99 = arith.addi %45, %98 : i64
%100 = arith.trunci %94 : i32 to i8
%101 = llvm.getelementptr %7[%99] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %100, %101 : i8, !llvm.ptr
%102 = arith.constant 2 : i32
%103 = llvm.load %49 : !llvm.ptr -> i64
%104 = arith.constant 2 : i32
%105 = llvm.load %66 : !llvm.ptr -> i64
%107 = arith.extsi %104 : i32 to i64
%106 = arith.muli %107, %105 : i64
%108 = arith.addi %103, %106 : i64
%109 = arith.remsi %108, %arg0 : i64
%110 = arith.addi %45, %109 : i64
%111 = arith.trunci %102 : i32 to i8
%112 = llvm.getelementptr %7[%110] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %111, %112 : i8, !llvm.ptr
cf.br ^bb20
^bb19:
cf.br ^bb20
^bb20:
%113 = llvm.load %49 : !llvm.ptr -> i64
%114 = arith.constant 1 : i32
%116 = arith.extsi %114 : i32 to i64
%115 = arith.addi %113, %116 : i64
llvm.store %115, %49 : i64, !llvm.ptr
cf.br ^bb15
^bb17:
%117 = llvm.load %28 : !llvm.ptr -> i64
%118 = arith.constant 1 : i32
%120 = arith.extsi %118 : i32 to i64
%119 = arith.addi %117, %120 : i64
llvm.store %119, %28 : i64, !llvm.ptr
%121 = llvm.load %28 : !llvm.ptr -> i64
%122 = arith.cmpi sgt, %121, %6 : i64
cf.cond_br %122, ^bb21, ^bb22
^bb21:
func.call @free(%7) : (!llvm.ptr) -> ()
%124 = arith.constant 1 : i32
%126 = arith.constant 0 : i32
%125 = arith.subi %126, %124 : i32
%127 = arith.extsi %125 : i32 to i64
func.return %127 : i64
^bb22:
cf.br ^bb23
^bb23:
cf.br ^bb6
^bb8:
%128 = arith.constant 0 : i32
%129 = arith.extsi %128 : i32 to i64
%130 = llvm.mlir.constant(1 : i64) : i64
%131 = llvm.alloca %130 x i64 : (i64) -> !llvm.ptr
llvm.store %129, %131 : i64, !llvm.ptr
%132 = arith.constant 0 : i32
%133 = arith.extsi %132 : i32 to i64
%134 = llvm.mlir.constant(1 : i64) : i64
%135 = llvm.alloca %134 x i64 : (i64) -> !llvm.ptr
llvm.store %133, %135 : i64, !llvm.ptr
%136 = llvm.load %28 : !llvm.ptr -> i64
%137 = arith.constant 1 : i32
%139 = arith.extsi %137 : i32 to i64
%138 = arith.subi %136, %139 : i64
%140 = llvm.mlir.constant(1 : i64) : i64
%141 = llvm.alloca %140 x i64 : (i64) -> !llvm.ptr
llvm.store %138, %141 : i64, !llvm.ptr
cf.br ^bb24
^bb24:
%142 = llvm.load %141 : !llvm.ptr -> i64
%143 = arith.constant 0 : i32
%145 = arith.extsi %143 : i32 to i64
%144 = arith.cmpi sge, %142, %145 : i64
cf.cond_br %144, ^bb25, ^bb26
^bb25:
%146 = arith.constant 1 : i32
%147 = arith.extsi %146 : i32 to i64
%148 = llvm.mlir.constant(1 : i64) : i64
%149 = llvm.alloca %148 x i64 : (i64) -> !llvm.ptr
llvm.store %147, %149 : i64, !llvm.ptr
%150 = arith.constant 0 : i32
%151 = arith.extsi %150 : i32 to i64
%152 = llvm.mlir.constant(1 : i64) : i64
%153 = llvm.alloca %152 x i64 : (i64) -> !llvm.ptr
llvm.store %151, %153 : i64, !llvm.ptr
cf.br ^bb27
^bb27:
%154 = llvm.load %153 : !llvm.ptr -> i64
%155 = llvm.load %141 : !llvm.ptr -> i64
%156 = arith.cmpi slt, %154, %155 : i64
cf.cond_br %156, ^bb28, ^bb29
^bb28:
%157 = llvm.load %149 : !llvm.ptr -> i64
%158 = arith.constant 10 : i32
%160 = arith.extsi %158 : i32 to i64
%159 = arith.muli %157, %160 : i64
%161 = arith.remsi %159, %arg0 : i64
llvm.store %161, %149 : i64, !llvm.ptr
%162 = llvm.load %153 : !llvm.ptr -> i64
%163 = arith.constant 1 : i32
%165 = arith.extsi %163 : i32 to i64
%164 = arith.addi %162, %165 : i64
llvm.store %164, %153 : i64, !llvm.ptr
cf.br ^bb27
^bb29:
%166 = arith.constant 0 : i32
%167 = arith.extsi %166 : i32 to i64
%168 = llvm.load %141 : !llvm.ptr -> i64
%169 = llvm.load %28 : !llvm.ptr -> i64
%170 = arith.constant 1 : i32
%172 = arith.extsi %170 : i32 to i64
%171 = arith.subi %169, %172 : i64
%173 = arith.cmpi eq, %168, %171 : i64
%174 = scf.if %173 -> (i64) {
%175 = arith.constant 1 : i32
%176 = arith.extsi %175 : i32 to i64
scf.yield %176 : i64
} else {
scf.yield %167 : i64
}
%177 = llvm.mlir.constant(1 : i64) : i64
%178 = llvm.alloca %177 x i64 : (i64) -> !llvm.ptr
llvm.store %174, %178 : i64, !llvm.ptr
cf.br ^bb30
^bb30:
%179 = llvm.load %178 : !llvm.ptr -> i64
%180 = arith.constant 2 : i32
%182 = arith.extsi %180 : i32 to i64
%181 = arith.cmpi sle, %179, %182 : i64
cf.cond_br %181, ^bb31, ^bb32
^bb31:
%183 = llvm.load %135 : !llvm.ptr -> i64
%184 = llvm.load %149 : !llvm.ptr -> i64
%185 = llvm.load %178 : !llvm.ptr -> i64
%186 = arith.muli %184, %185 : i64
%187 = arith.subi %183, %186 : i64
%188 = arith.remsi %187, %arg0 : i64
%189 = arith.constant 0 : i32
%191 = arith.extsi %189 : i32 to i64
%190 = arith.cmpi slt, %188, %191 : i64
%192 = scf.if %190 -> (i64) {
%193 = arith.addi %188, %arg0 : i64
scf.yield %193 : i64
} else {
scf.yield %188 : i64
}
%195 = llvm.load %141 : !llvm.ptr -> i64
%196 = arith.muli %195, %arg0 : i64
%197 = arith.addi %196, %192 : i64
%198 = llvm.getelementptr %7[%197] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%194 = llvm.load %198 : !llvm.ptr -> i8
%199 = arith.constant 0 : i32
%201 = arith.extsi %194 : i8 to i32
%200 = arith.cmpi sgt, %201, %199 : i32
cf.cond_br %200, ^bb33, ^bb34
^bb33:
%202 = llvm.load %131 : !llvm.ptr -> i64
%203 = arith.constant 10 : i32
%205 = arith.extsi %203 : i32 to i64
%204 = arith.muli %202, %205 : i64
%206 = llvm.load %178 : !llvm.ptr -> i64
%207 = arith.addi %204, %206 : i64
llvm.store %207, %131 : i64, !llvm.ptr
llvm.store %192, %135 : i64, !llvm.ptr
cf.br ^bb32
^bb34:
cf.br ^bb35
^bb35:
%208 = llvm.load %178 : !llvm.ptr -> i64
%209 = arith.constant 1 : i32
%211 = arith.extsi %209 : i32 to i64
%210 = arith.addi %208, %211 : i64
llvm.store %210, %178 : i64, !llvm.ptr
cf.br ^bb30
^bb32:
%212 = llvm.load %141 : !llvm.ptr -> i64
%213 = arith.constant 1 : i32
%215 = arith.extsi %213 : i32 to i64
%214 = arith.subi %212, %215 : i64
llvm.store %214, %141 : i64, !llvm.ptr
cf.br ^bb24
^bb26:
func.call @free(%7) : (!llvm.ptr) -> ()
%217 = llvm.load %131 : !llvm.ptr -> i64
%218 = arith.divsi %217, %arg0 : i64
func.return %218 : i64
}
func.func @main() -> i32 {
%219 = arith.constant 0 : i32
%220 = arith.extsi %219 : i32 to i64
%221 = llvm.mlir.constant(1 : i64) : i64
%222 = llvm.alloca %221 x i64 : (i64) -> !llvm.ptr
llvm.store %220, %222 : i64, !llvm.ptr
%223 = arith.constant 1 : i32
%224 = arith.extsi %223 : i32 to i64
%225 = llvm.mlir.constant(1 : i64) : i64
%226 = llvm.alloca %225 x i64 : (i64) -> !llvm.ptr
llvm.store %224, %226 : i64, !llvm.ptr
cf.br ^bb36
^bb36:
%227 = llvm.load %226 : !llvm.ptr -> i64
%228 = arith.constant 10000 : i32
%230 = arith.extsi %228 : i32 to i64
%229 = arith.cmpi sle, %227, %230 : i64
cf.cond_br %229, ^bb37, ^bb38
^bb37:
%231 = llvm.load %222 : !llvm.ptr -> i64
%233 = llvm.load %226 : !llvm.ptr -> i64
%232 = func.call @find_quot(%233) : (i64) -> i64
%234 = arith.addi %231, %232 : i64
llvm.store %234, %222 : i64, !llvm.ptr
%235 = llvm.load %226 : !llvm.ptr -> i64
%236 = arith.constant 1 : i32
%238 = arith.extsi %236 : i32 to i64
%237 = arith.addi %235, %238 : i64
llvm.store %237, %226 : i64, !llvm.ptr
cf.br ^bb36
^bb38:
%239 = llvm.mlir.addressof @str_0 : !llvm.ptr
%240 = llvm.load %222 : !llvm.ptr -> i64
%241 = llvm.call @printf(%239, %240) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
%242 = arith.constant 0 : i32
func.return %242 : i32
}
}