← All problems
Problem 320
Sum_{i=10..10^6} N(i) mod 10^18 where N(i)! has ≥ 1234567890 trailing zeros in base i.
View problem on Project Euler
Performance comparison
Metric Our solution Best known
Time complexity O(n^3)?
Space complexity O(n)?
Approach Flow solution Not curated
Verdict Unknown
Flow source
# Project Euler 320
# Sum_{i=10..10^6} N(i) mod 10^18 where N(i)! has ≥ 1234567890 trailing zeros in base i.
extern {
function calloc(n: i64, size: i64) -> ptr<void>
function free(p: ptr<void>) -> void
}
function fact_val(n0: i64, p: i64) -> i64 {
let mut total: i64 = 0
let mut n: i64 = n0
while n > 0 {
n = n / p
total = total + n
}
return total
}
function inv_fact_val(p: i64, target: i64, lower: i64) -> i64 {
if fact_val(lower, p) >= target { return lower }
let mut lo: i64 = lower
let mut step: i64 = p
let mut hi: i64 = lo + step
while fact_val(hi, p) < target {
lo = hi
step = step * 2
hi = hi + step
}
while hi - lo > 1 {
let mid: i64 = (lo + hi) / 2
if fact_val(mid, p) >= target {
hi = mid
} else {
lo = mid
}
}
return hi
}
function main() -> i32 {
let limit: i64 = 1000000
let K: i64 = 1234567890
let MOD: i64 = 1000000000000000000
let spf: ptr<i32> = calloc(limit + 1, 4)
let targets: ptr<i64> = calloc(limit + 1, 8)
let witnesses: ptr<i64> = calloc(limit + 1, 8)
if spf == null || targets == null || witnesses == null { return 1 }
let mut i: i64 = 2
while i <= limit {
if spf[i] == 0 {
spf[i] = i as i32
if i * i <= limit {
let mut j: i64 = i * i
while j <= limit {
if spf[j] == 0 { spf[j] = i as i32 }
j = j + i
}
}
}
i = i + 1
}
let mut current: i64 = 0
let mut total: i64 = 0
i = 2
while i <= limit {
let mut n: i64 = i
while n > 1 {
let p: i64 = spf[n] as i64
let mut exponent: i64 = 0
while n % p == 0 {
n = n / p
exponent = exponent + 1
}
let target: i64 = targets[p] + K * exponent
targets[p] = target
if fact_val(current, p) >= target { continue }
let mut lower: i64 = target * (p - 1)
if witnesses[p] > lower { lower = witnesses[p] }
let witness: i64 = inv_fact_val(p, target, lower)
witnesses[p] = witness
if witness > current { current = witness }
}
if i >= 10 {
total = (total + current) % MOD
}
i = i + 1
}
printf("%lld\n", total)
free(spf); free(targets); free(witnesses)
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 fact_val_i64_i64(int64_t n0, int64_t p);
int64_t inv_fact_val_i64_i64_i64(int64_t p, int64_t target, int64_t lower);
int32_t main(void);
int64_t fact_val_i64_i64(int64_t n0, int64_t p) {
int64_t total = 0;
int64_t n = n0;
while (n > 0) {
n = FLOW_CHECKED_DIV((n), (p));
total = (total + n);
}
return total;
}
int64_t inv_fact_val_i64_i64_i64(int64_t p, int64_t target, int64_t lower) {
if (fact_val_i64_i64(lower, p) >= target) {
return lower;
}
int64_t lo = lower;
int64_t step = p;
int64_t hi = (lo + step);
while (fact_val_i64_i64(hi, p) < target) {
lo = hi;
step = (step * 2);
hi = (hi + step);
}
while ((hi - lo) > 1) {
int64_t mid = FLOW_CHECKED_DIV(((lo + hi)), (2));
if (fact_val_i64_i64(mid, p) >= target) {
hi = mid;
} else {
lo = mid;
}
}
return hi;
}
int32_t main(void) {
int64_t limit = 1000000;
int64_t K = 1234567890;
int64_t MOD = 1000000000000000000;
int32_t* spf = (int32_t*)(calloc((limit + 1), 4));
int64_t* targets = (int64_t*)(calloc((limit + 1), 8));
int64_t* witnesses = (int64_t*)(calloc((limit + 1), 8));
if (((spf == NULL || targets == NULL) || witnesses == NULL)) {
return 1;
}
int64_t i = 2;
while (i <= limit) {
if (spf[i] == 0) {
spf[i] = ((int32_t)(i));
if ((i * i) <= limit) {
int64_t j = (i * i);
while (j <= limit) {
if (spf[j] == 0) {
spf[j] = ((int32_t)(i));
}
j = (j + i);
}
}
}
i = (i + 1);
}
int64_t current = 0;
int64_t total = 0;
i = 2;
while (i <= limit) {
int64_t n = i;
while (n > 1) {
int64_t p = ((int64_t)(spf[n]));
int64_t exponent = 0;
while (FLOW_CHECKED_MOD((n), (p)) == 0) {
n = FLOW_CHECKED_DIV((n), (p));
exponent = (exponent + 1);
}
int64_t target = (targets[p] + (K * exponent));
targets[p] = target;
if (fact_val_i64_i64(current, p) >= target) {
continue;
}
int64_t lower = (target * (p - 1));
if (witnesses[p] > lower) {
lower = witnesses[p];
}
int64_t witness = inv_fact_val_i64_i64_i64(p, target, lower);
witnesses[p] = witness;
if (witness > current) {
current = witness;
}
}
if (i >= 10) {
total = FLOW_CHECKED_MOD(((total + current)), (MOD));
}
i = (i + 1);
}
printf("%lld\n", total);
free(spf);
free(targets);
free(witnesses);
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 @fact_val(%arg0: i64, %arg1: i64) -> i64 {
%0 = arith.constant 0 : i32
%1 = arith.extsi %0 : i32 to i64
%2 = llvm.mlir.constant(1 : i64) : i64
%3 = llvm.alloca %2 x i64 : (i64) -> !llvm.ptr
llvm.store %1, %3 : i64, !llvm.ptr
%4 = llvm.mlir.constant(1 : i64) : i64
%5 = llvm.alloca %4 x i64 : (i64) -> !llvm.ptr
llvm.store %arg0, %5 : i64, !llvm.ptr
cf.br ^bb0
^bb0:
%6 = llvm.load %5 : !llvm.ptr -> i64
%7 = arith.constant 0 : i32
%9 = arith.extsi %7 : i32 to i64
%8 = arith.cmpi sgt, %6, %9 : i64
cf.cond_br %8, ^bb1, ^bb2
^bb1:
%10 = llvm.load %5 : !llvm.ptr -> i64
%11 = arith.divsi %10, %arg1 : i64
llvm.store %11, %5 : i64, !llvm.ptr
%12 = llvm.load %3 : !llvm.ptr -> i64
%13 = llvm.load %5 : !llvm.ptr -> i64
%14 = arith.addi %12, %13 : i64
llvm.store %14, %3 : i64, !llvm.ptr
cf.br ^bb0
^bb2:
%15 = llvm.load %3 : !llvm.ptr -> i64
func.return %15 : i64
}
func.func @inv_fact_val(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
%16 = func.call @fact_val(%arg2, %arg0) : (i64, i64) -> i64
%17 = arith.cmpi sge, %16, %arg1 : i64
cf.cond_br %17, ^bb3, ^bb4
^bb3:
func.return %arg2 : i64
^bb4:
cf.br ^bb5
^bb5:
%18 = llvm.mlir.constant(1 : i64) : i64
%19 = llvm.alloca %18 x i64 : (i64) -> !llvm.ptr
llvm.store %arg2, %19 : i64, !llvm.ptr
%20 = llvm.mlir.constant(1 : i64) : i64
%21 = llvm.alloca %20 x i64 : (i64) -> !llvm.ptr
llvm.store %arg0, %21 : i64, !llvm.ptr
%22 = llvm.load %19 : !llvm.ptr -> i64
%23 = llvm.load %21 : !llvm.ptr -> i64
%24 = arith.addi %22, %23 : i64
%25 = llvm.mlir.constant(1 : i64) : i64
%26 = llvm.alloca %25 x i64 : (i64) -> !llvm.ptr
llvm.store %24, %26 : i64, !llvm.ptr
cf.br ^bb6
^bb6:
%28 = llvm.load %26 : !llvm.ptr -> i64
%27 = func.call @fact_val(%28, %arg0) : (i64, i64) -> i64
%29 = arith.cmpi slt, %27, %arg1 : i64
cf.cond_br %29, ^bb7, ^bb8
^bb7:
%30 = llvm.load %26 : !llvm.ptr -> i64
llvm.store %30, %19 : i64, !llvm.ptr
%31 = llvm.load %21 : !llvm.ptr -> i64
%32 = arith.constant 2 : i32
%34 = arith.extsi %32 : i32 to i64
%33 = arith.muli %31, %34 : i64
llvm.store %33, %21 : i64, !llvm.ptr
%35 = llvm.load %26 : !llvm.ptr -> i64
%36 = llvm.load %21 : !llvm.ptr -> i64
%37 = arith.addi %35, %36 : i64
llvm.store %37, %26 : i64, !llvm.ptr
cf.br ^bb6
^bb8:
cf.br ^bb9
^bb9:
%38 = llvm.load %26 : !llvm.ptr -> i64
%39 = llvm.load %19 : !llvm.ptr -> i64
%40 = arith.subi %38, %39 : i64
%41 = arith.constant 1 : i32
%43 = arith.extsi %41 : i32 to i64
%42 = arith.cmpi sgt, %40, %43 : i64
cf.cond_br %42, ^bb10, ^bb11
^bb10:
%44 = llvm.load %19 : !llvm.ptr -> i64
%45 = llvm.load %26 : !llvm.ptr -> i64
%46 = arith.addi %44, %45 : i64
%47 = arith.constant 2 : i32
%49 = arith.extsi %47 : i32 to i64
%48 = arith.divsi %46, %49 : i64
%50 = func.call @fact_val(%48, %arg0) : (i64, i64) -> i64
%51 = arith.cmpi sge, %50, %arg1 : i64
cf.cond_br %51, ^bb12, ^bb13
^bb12:
llvm.store %48, %26 : i64, !llvm.ptr
cf.br ^bb14
^bb13:
llvm.store %48, %19 : i64, !llvm.ptr
cf.br ^bb14
^bb14:
cf.br ^bb9
^bb11:
%52 = llvm.load %26 : !llvm.ptr -> i64
func.return %52 : i64
}
func.func @main() -> i32 {
%53 = arith.constant 1000000 : i32
%54 = arith.extsi %53 : i32 to i64
%55 = arith.constant 1234567890 : i32
%56 = arith.extsi %55 : i32 to i64
%57 = arith.constant 999999995705032704 : i32
%58 = arith.extsi %57 : i32 to i64
%60 = arith.constant 1 : i32
%62 = arith.extsi %60 : i32 to i64
%61 = arith.addi %54, %62 : i64
%63 = arith.constant 4 : i32
%64 = arith.extsi %63 : i32 to i64
%59 = func.call @calloc(%61, %64) : (i64, i64) -> !llvm.ptr
%66 = arith.constant 1 : i32
%68 = arith.extsi %66 : i32 to i64
%67 = arith.addi %54, %68 : i64
%69 = arith.constant 8 : i32
%70 = arith.extsi %69 : i32 to i64
%65 = func.call @calloc(%67, %70) : (i64, i64) -> !llvm.ptr
%72 = arith.constant 1 : i32
%74 = arith.extsi %72 : i32 to i64
%73 = arith.addi %54, %74 : i64
%75 = arith.constant 8 : i32
%76 = arith.extsi %75 : i32 to i64
%71 = func.call @calloc(%73, %76) : (i64, i64) -> !llvm.ptr
%77 = llvm.mlir.zero : !llvm.ptr
%78 = llvm.icmp "eq" %59, %77 : !llvm.ptr
%79 = scf.if %78 -> (i1) {
%80 = arith.constant true
scf.yield %80 : i1
} else {
%81 = llvm.mlir.zero : !llvm.ptr
%82 = llvm.icmp "eq" %65, %81 : !llvm.ptr
scf.yield %82 : i1
}
%83 = scf.if %79 -> (i1) {
%84 = arith.constant true
scf.yield %84 : i1
} else {
%85 = llvm.mlir.zero : !llvm.ptr
%86 = llvm.icmp "eq" %71, %85 : !llvm.ptr
scf.yield %86 : i1
}
cf.cond_br %83, ^bb15, ^bb16
^bb15:
%87 = arith.constant 1 : i32
func.return %87 : i32
^bb16:
cf.br ^bb17
^bb17:
%88 = arith.constant 2 : i32
%89 = arith.extsi %88 : i32 to i64
%90 = llvm.mlir.constant(1 : i64) : i64
%91 = llvm.alloca %90 x i64 : (i64) -> !llvm.ptr
llvm.store %89, %91 : i64, !llvm.ptr
cf.br ^bb18
^bb18:
%92 = llvm.load %91 : !llvm.ptr -> i64
%93 = arith.cmpi sle, %92, %54 : i64
cf.cond_br %93, ^bb19, ^bb20
^bb19:
%95 = llvm.load %91 : !llvm.ptr -> i64
%96 = llvm.getelementptr %59[%95] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%94 = llvm.load %96 : !llvm.ptr -> i32
%97 = arith.constant 0 : i32
%98 = arith.cmpi eq, %94, %97 : i32
cf.cond_br %98, ^bb21, ^bb22
^bb21:
%99 = llvm.load %91 : !llvm.ptr -> i64
%100 = arith.trunci %99 : i64 to i32
%101 = llvm.load %91 : !llvm.ptr -> i64
%102 = llvm.getelementptr %59[%101] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %100, %102 : i32, !llvm.ptr
%103 = llvm.load %91 : !llvm.ptr -> i64
%104 = llvm.load %91 : !llvm.ptr -> i64
%105 = arith.muli %103, %104 : i64
%106 = arith.cmpi sle, %105, %54 : i64
cf.cond_br %106, ^bb24, ^bb25
^bb24:
%107 = llvm.load %91 : !llvm.ptr -> i64
%108 = llvm.load %91 : !llvm.ptr -> i64
%109 = arith.muli %107, %108 : i64
%110 = llvm.mlir.constant(1 : i64) : i64
%111 = llvm.alloca %110 x i64 : (i64) -> !llvm.ptr
llvm.store %109, %111 : i64, !llvm.ptr
cf.br ^bb27
^bb27:
%112 = llvm.load %111 : !llvm.ptr -> i64
%113 = arith.cmpi sle, %112, %54 : i64
cf.cond_br %113, ^bb28, ^bb29
^bb28:
%115 = llvm.load %111 : !llvm.ptr -> i64
%116 = llvm.getelementptr %59[%115] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%114 = llvm.load %116 : !llvm.ptr -> i32
%117 = arith.constant 0 : i32
%118 = arith.cmpi eq, %114, %117 : i32
cf.cond_br %118, ^bb30, ^bb31
^bb30:
%119 = llvm.load %91 : !llvm.ptr -> i64
%120 = arith.trunci %119 : i64 to i32
%121 = llvm.load %111 : !llvm.ptr -> i64
%122 = llvm.getelementptr %59[%121] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %120, %122 : i32, !llvm.ptr
cf.br ^bb32
^bb31:
cf.br ^bb32
^bb32:
%123 = llvm.load %111 : !llvm.ptr -> i64
%124 = llvm.load %91 : !llvm.ptr -> i64
%125 = arith.addi %123, %124 : i64
llvm.store %125, %111 : i64, !llvm.ptr
cf.br ^bb27
^bb29:
cf.br ^bb26
^bb25:
cf.br ^bb26
^bb26:
cf.br ^bb23
^bb22:
cf.br ^bb23
^bb23:
%126 = llvm.load %91 : !llvm.ptr -> i64
%127 = arith.constant 1 : i32
%129 = arith.extsi %127 : i32 to i64
%128 = arith.addi %126, %129 : i64
llvm.store %128, %91 : i64, !llvm.ptr
cf.br ^bb18
^bb20:
%130 = arith.constant 0 : i32
%131 = arith.extsi %130 : i32 to i64
%132 = llvm.mlir.constant(1 : i64) : i64
%133 = llvm.alloca %132 x i64 : (i64) -> !llvm.ptr
llvm.store %131, %133 : i64, !llvm.ptr
%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
%138 = arith.constant 2 : i32
%139 = arith.extsi %138 : i32 to i64
llvm.store %139, %91 : i64, !llvm.ptr
cf.br ^bb33
^bb33:
%140 = llvm.load %91 : !llvm.ptr -> i64
%141 = arith.cmpi sle, %140, %54 : i64
cf.cond_br %141, ^bb34, ^bb35
^bb34:
%142 = llvm.load %91 : !llvm.ptr -> i64
%143 = llvm.mlir.constant(1 : i64) : i64
%144 = llvm.alloca %143 x i64 : (i64) -> !llvm.ptr
llvm.store %142, %144 : i64, !llvm.ptr
cf.br ^bb36
^bb36:
%145 = llvm.load %144 : !llvm.ptr -> i64
%146 = arith.constant 1 : i32
%148 = arith.extsi %146 : i32 to i64
%147 = arith.cmpi sgt, %145, %148 : i64
cf.cond_br %147, ^bb37, ^bb38
^bb37:
%150 = llvm.load %144 : !llvm.ptr -> i64
%151 = llvm.getelementptr %59[%150] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%149 = llvm.load %151 : !llvm.ptr -> i32
%152 = arith.extsi %149 : i32 to i64
%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 ^bb39
^bb39:
%157 = llvm.load %144 : !llvm.ptr -> i64
%158 = arith.remsi %157, %152 : i64
%159 = arith.constant 0 : i32
%161 = arith.extsi %159 : i32 to i64
%160 = arith.cmpi eq, %158, %161 : i64
cf.cond_br %160, ^bb40, ^bb41
^bb40:
%162 = llvm.load %144 : !llvm.ptr -> i64
%163 = arith.divsi %162, %152 : i64
llvm.store %163, %144 : i64, !llvm.ptr
%164 = llvm.load %156 : !llvm.ptr -> i64
%165 = arith.constant 1 : i32
%167 = arith.extsi %165 : i32 to i64
%166 = arith.addi %164, %167 : i64
llvm.store %166, %156 : i64, !llvm.ptr
cf.br ^bb39
^bb41:
%169 = llvm.getelementptr %65[%152] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%168 = llvm.load %169 : !llvm.ptr -> i64
%170 = llvm.load %156 : !llvm.ptr -> i64
%171 = arith.muli %56, %170 : i64
%172 = arith.addi %168, %171 : i64
%173 = llvm.getelementptr %65[%152] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %172, %173 : i64, !llvm.ptr
%175 = llvm.load %133 : !llvm.ptr -> i64
%174 = func.call @fact_val(%175, %152) : (i64, i64) -> i64
%176 = arith.cmpi sge, %174, %172 : i64
cf.cond_br %176, ^bb42, ^bb43
^bb42:
cf.br ^bb36
^bb43:
cf.br ^bb44
^bb44:
%177 = arith.constant 1 : i32
%179 = arith.extsi %177 : i32 to i64
%178 = arith.subi %152, %179 : i64
%180 = arith.muli %172, %178 : i64
%181 = llvm.mlir.constant(1 : i64) : i64
%182 = llvm.alloca %181 x i64 : (i64) -> !llvm.ptr
llvm.store %180, %182 : i64, !llvm.ptr
%184 = llvm.getelementptr %71[%152] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%183 = llvm.load %184 : !llvm.ptr -> i64
%185 = llvm.load %182 : !llvm.ptr -> i64
%186 = arith.cmpi sgt, %183, %185 : i64
cf.cond_br %186, ^bb45, ^bb46
^bb45:
%188 = llvm.getelementptr %71[%152] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%187 = llvm.load %188 : !llvm.ptr -> i64
llvm.store %187, %182 : i64, !llvm.ptr
cf.br ^bb47
^bb46:
cf.br ^bb47
^bb47:
%190 = llvm.load %182 : !llvm.ptr -> i64
%189 = func.call @inv_fact_val(%152, %172, %190) : (i64, i64, i64) -> i64
%191 = llvm.getelementptr %71[%152] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %189, %191 : i64, !llvm.ptr
%192 = llvm.load %133 : !llvm.ptr -> i64
%193 = arith.cmpi sgt, %189, %192 : i64
cf.cond_br %193, ^bb48, ^bb49
^bb48:
llvm.store %189, %133 : i64, !llvm.ptr
cf.br ^bb50
^bb49:
cf.br ^bb50
^bb50:
cf.br ^bb36
^bb38:
%194 = llvm.load %91 : !llvm.ptr -> i64
%195 = arith.constant 10 : i32
%197 = arith.extsi %195 : i32 to i64
%196 = arith.cmpi sge, %194, %197 : i64
cf.cond_br %196, ^bb51, ^bb52
^bb51:
%198 = llvm.load %137 : !llvm.ptr -> i64
%199 = llvm.load %133 : !llvm.ptr -> i64
%200 = arith.addi %198, %199 : i64
%201 = arith.remsi %200, %58 : i64
llvm.store %201, %137 : i64, !llvm.ptr
cf.br ^bb53
^bb52:
cf.br ^bb53
^bb53:
%202 = llvm.load %91 : !llvm.ptr -> i64
%203 = arith.constant 1 : i32
%205 = arith.extsi %203 : i32 to i64
%204 = arith.addi %202, %205 : i64
llvm.store %204, %91 : i64, !llvm.ptr
cf.br ^bb33
^bb35:
%206 = llvm.mlir.addressof @str_0 : !llvm.ptr
%207 = llvm.load %137 : !llvm.ptr -> i64
%208 = llvm.call @printf(%206, %207) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
func.call @free(%59) : (!llvm.ptr) -> ()
func.call @free(%65) : (!llvm.ptr) -> ()
func.call @free(%71) : (!llvm.ptr) -> ()
%212 = arith.constant 0 : i32
func.return %212 : i32
}
}