← All problems
Problem 675
2^omega(n): sum of S(i!) for i=2..10^7, where S(n) = prod_{p^e || n} (2e+1), mod 1e9+87.
View problem on Project Euler
Performance comparison
Metric Our solution Best known
Time complexity O(n^3)O(n log log n)
Space complexity O(n^2)O(n)
Approach Flow solution Sieve or enumeration
Verdict Suboptimal
Flow source
# Project Euler 675
# 2^omega(n): sum of S(i!) for i=2..10^7, where S(n) = prod_{p^e || n} (2e+1), mod 1e9+87.
extern {
function calloc(n: i64, size: i64) -> ptr<void>
function free(p: ptr<void>) -> void
}
const MOD: i64 = 1000000087
function mod_pow(base0: i64, exp0: i64, mod: i64) -> i64 {
let mut r: i64 = 1
let mut b: i64 = base0 % mod
let mut e: i64 = exp0
while e > 0 {
if (e & 1) == 1 {
let t: i128 = (r as i128) * (b as i128) % (mod as i128)
r = t as i64
}
let t2: i128 = (b as i128) * (b as i128) % (mod as i128)
b = t2 as i64
e = e / 2
}
return r
}
function main() -> i32 {
let N: i64 = 10000000
# Smallest prime factor sieve
let spf: ptr<i64> = calloc(N + 1, 8)
let primes: ptr<i64> = calloc(N / 5 + 100, 8)
let mut npc: i64 = 0
if spf == null || primes == null { return 1 }
for x in 2..(N + 1) {
if spf[x] == 0 {
spf[x] = x
primes[npc] = x
npc = npc + 1
}
let spfx: i64 = spf[x]
for j in 0..npc {
let p: i64 = primes[j]
let y: i64 = p * x
if y > N { break }
spf[y] = p
if p == spfx { break }
}
}
# Compute v_2(N!) to size the inverse table
let mut v2_fact: i64 = 0
let mut power: i64 = 2
while power <= N {
v2_fact = v2_fact + N / power
power = power * 2
}
# Inverse table up to 2*v2_fact + 1
let inv_limit: i64 = 2 * v2_fact + 1
let inv: ptr<i64> = calloc(inv_limit + 1, 8)
if inv == null { return 1 }
inv[1] = 1
for x in 2..(inv_limit + 1) {
inv[x] = (MOD - (MOD / x) * inv[MOD % x] % MOD) % MOD
}
# Exponents of each prime in the running factorial
let exps: ptr<i64> = calloc(N + 1, 8)
if exps == null { return 1 }
let mut running: i64 = 1
let mut total: i64 = 0
for i in 2..(N + 1) {
let mut x: i64 = i
while x > 1 {
let p: i64 = spf[x]
let mut count: i64 = 0
while x % p == 0 {
x = x / p
count = count + 1
}
let old_exp: i64 = exps[p]
let new_exp: i64 = old_exp + count
let old_factor: i64 = 2 * old_exp + 1
let new_factor: i64 = 2 * new_exp + 1
let t1: i128 = (running as i128) * (new_factor as i128) % (MOD as i128)
let t2: i128 = (t1 * (inv[old_factor] as i128)) % (MOD as i128)
running = t2 as i64
exps[p] = new_exp
}
total = (total + running) % MOD
}
printf("%lld\n", total)
free(exps)
free(inv)
free(primes)
free(spf)
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 mod_pow_i64_i64_i64(int64_t base0, int64_t exp0, int64_t mod);
int32_t main(void);
static const int64_t MOD = 1000000087;
int64_t mod_pow_i64_i64_i64(int64_t base0, int64_t exp0, int64_t mod) {
int64_t r = 1;
int64_t b = FLOW_CHECKED_MOD((base0), (mod));
int64_t e = exp0;
while (e > 0) {
if ((e & 1) == 1) {
__int128 t = FLOW_CHECKED_MOD(((((__int128)(r)) * ((__int128)(b)))), (((__int128)(mod))));
r = ((int64_t)(t));
}
__int128 t2 = FLOW_CHECKED_MOD(((((__int128)(b)) * ((__int128)(b)))), (((__int128)(mod))));
b = ((int64_t)(t2));
e = FLOW_CHECKED_DIV((e), (2));
}
return r;
}
int32_t main(void) {
int64_t N = 10000000;
int64_t* spf = (int64_t*)(calloc((N + 1), 8));
int64_t* primes = (int64_t*)(calloc((FLOW_CHECKED_DIV((N), (5)) + 100), 8));
int64_t npc = 0;
if ((spf == NULL || primes == NULL)) {
return 1;
}
int32_t __flow_step_1 = 1;
for (int32_t x = 2; (2 <= (N + 1)) ? x < (N + 1) : x > (N + 1); x += (2 <= (N + 1)) ? 1 : -1) {
if (spf[x] == 0) {
spf[x] = x;
primes[npc] = x;
npc = (npc + 1);
}
int64_t spfx = spf[x];
int32_t __flow_step_2 = 1;
for (int32_t j = 0; (0 <= npc) ? j < npc : j > npc; j += (0 <= npc) ? 1 : -1) {
int64_t p = primes[j];
int64_t y = (p * x);
if (y > N) {
break;
}
spf[y] = p;
if (p == spfx) {
break;
}
}
}
int64_t v2_fact = 0;
int64_t power = 2;
while (power <= N) {
v2_fact = (v2_fact + FLOW_CHECKED_DIV((N), (power)));
power = (power * 2);
}
int64_t inv_limit = ((2 * v2_fact) + 1);
int64_t* inv = (int64_t*)(calloc((inv_limit + 1), 8));
if (inv == NULL) {
return 1;
}
inv[1] = 1;
int32_t __flow_step_3 = 1;
for (int32_t x = 2; (2 <= (inv_limit + 1)) ? x < (inv_limit + 1) : x > (inv_limit + 1); x += (2 <= (inv_limit + 1)) ? 1 : -1) {
inv[x] = FLOW_CHECKED_MOD(((MOD - FLOW_CHECKED_MOD(((FLOW_CHECKED_DIV((MOD), (x)) * inv[FLOW_CHECKED_MOD((MOD), (x))])), (MOD)))), (MOD));
}
int64_t* exps = (int64_t*)(calloc((N + 1), 8));
if (exps == NULL) {
return 1;
}
int64_t running = 1;
int64_t total = 0;
int32_t __flow_step_4 = 1;
for (int32_t i = 2; (2 <= (N + 1)) ? i < (N + 1) : i > (N + 1); i += (2 <= (N + 1)) ? 1 : -1) {
int64_t x = i;
while (x > 1) {
int64_t p = spf[x];
int64_t count = 0;
while (FLOW_CHECKED_MOD((x), (p)) == 0) {
x = FLOW_CHECKED_DIV((x), (p));
count = (count + 1);
}
int64_t old_exp = exps[p];
int64_t new_exp = (old_exp + count);
int64_t old_factor = ((2 * old_exp) + 1);
int64_t new_factor = ((2 * new_exp) + 1);
__int128 t1 = FLOW_CHECKED_MOD(((((__int128)(running)) * ((__int128)(new_factor)))), (((__int128)(MOD))));
__int128 t2 = FLOW_CHECKED_MOD(((t1 * ((__int128)(inv[old_factor])))), (((__int128)(MOD))));
running = ((int64_t)(t2));
exps[p] = new_exp;
}
total = FLOW_CHECKED_MOD(((total + running)), (MOD));
}
printf("%lld\n", total);
free(exps);
free(inv);
free(primes);
free(spf);
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) -> ()
// Constant: MOD
llvm.mlir.global internal constant @MOD(1000000087 : i64) : i64
func.func @mod_pow(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
%0 = arith.constant 1 : 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 = arith.remsi %arg0, %arg2 : i64
%5 = llvm.mlir.constant(1 : i64) : i64
%6 = llvm.alloca %5 x i64 : (i64) -> !llvm.ptr
llvm.store %4, %6 : i64, !llvm.ptr
%7 = llvm.mlir.constant(1 : i64) : i64
%8 = llvm.alloca %7 x i64 : (i64) -> !llvm.ptr
llvm.store %arg1, %8 : i64, !llvm.ptr
cf.br ^bb0
^bb0:
%9 = llvm.load %8 : !llvm.ptr -> i64
%10 = arith.constant 0 : i32
%12 = arith.extsi %10 : i32 to i64
%11 = arith.cmpi sgt, %9, %12 : i64
cf.cond_br %11, ^bb1, ^bb2
^bb1:
%13 = llvm.load %8 : !llvm.ptr -> i64
%14 = arith.constant 1 : i32
%16 = arith.extsi %14 : i32 to i64
%15 = arith.andi %13, %16 : i64
%17 = arith.constant 1 : i32
%19 = arith.extsi %17 : i32 to i64
%18 = arith.cmpi eq, %15, %19 : i64
cf.cond_br %18, ^bb3, ^bb4
^bb3:
%20 = llvm.load %3 : !llvm.ptr -> i64
%21 = arith.extsi %20 : i64 to i128
%22 = llvm.load %6 : !llvm.ptr -> i64
%23 = arith.extsi %22 : i64 to i128
%25 = arith.trunci %21 : i128 to i64
%26 = arith.trunci %23 : i128 to i64
%24 = arith.muli %25, %26 : i64
%27 = arith.extsi %arg2 : i64 to i128
%29 = arith.trunci %27 : i128 to i64
%28 = arith.remsi %24, %29 : i64
%30 = arith.extsi %28 : i64 to i128
%31 = arith.trunci %30 : i128 to i64
llvm.store %31, %3 : i64, !llvm.ptr
cf.br ^bb5
^bb4:
cf.br ^bb5
^bb5:
%32 = llvm.load %6 : !llvm.ptr -> i64
%33 = arith.extsi %32 : i64 to i128
%34 = llvm.load %6 : !llvm.ptr -> i64
%35 = arith.extsi %34 : i64 to i128
%37 = arith.trunci %33 : i128 to i64
%38 = arith.trunci %35 : i128 to i64
%36 = arith.muli %37, %38 : i64
%39 = arith.extsi %arg2 : i64 to i128
%41 = arith.trunci %39 : i128 to i64
%40 = arith.remsi %36, %41 : i64
%42 = arith.extsi %40 : i64 to i128
%43 = arith.trunci %42 : i128 to i64
llvm.store %43, %6 : i64, !llvm.ptr
%44 = llvm.load %8 : !llvm.ptr -> i64
%45 = arith.constant 2 : i32
%47 = arith.extsi %45 : i32 to i64
%46 = arith.divsi %44, %47 : i64
llvm.store %46, %8 : i64, !llvm.ptr
cf.br ^bb0
^bb2:
%48 = llvm.load %3 : !llvm.ptr -> i64
func.return %48 : i64
}
func.func @main() -> i32 {
%49 = arith.constant 10000000 : i32
%50 = arith.extsi %49 : i32 to i64
%52 = arith.constant 1 : i32
%54 = arith.extsi %52 : i32 to i64
%53 = arith.addi %50, %54 : i64
%55 = arith.constant 8 : i32
%56 = arith.extsi %55 : i32 to i64
%51 = func.call @calloc(%53, %56) : (i64, i64) -> !llvm.ptr
%58 = arith.constant 5 : i32
%60 = arith.extsi %58 : i32 to i64
%59 = arith.divsi %50, %60 : i64
%61 = arith.constant 100 : i32
%63 = arith.extsi %61 : i32 to i64
%62 = arith.addi %59, %63 : i64
%64 = arith.constant 8 : i32
%65 = arith.extsi %64 : i32 to i64
%57 = func.call @calloc(%62, %65) : (i64, i64) -> !llvm.ptr
%66 = arith.constant 0 : i32
%67 = arith.extsi %66 : i32 to i64
%68 = llvm.mlir.constant(1 : i64) : i64
%69 = llvm.alloca %68 x i64 : (i64) -> !llvm.ptr
llvm.store %67, %69 : i64, !llvm.ptr
%70 = llvm.mlir.zero : !llvm.ptr
%71 = llvm.icmp "eq" %51, %70 : !llvm.ptr
%72 = scf.if %71 -> (i1) {
%73 = arith.constant true
scf.yield %73 : i1
} else {
%74 = llvm.mlir.zero : !llvm.ptr
%75 = llvm.icmp "eq" %57, %74 : !llvm.ptr
scf.yield %75 : i1
}
cf.cond_br %72, ^bb6, ^bb7
^bb6:
%76 = arith.constant 1 : i32
func.return %76 : i32
^bb7:
cf.br ^bb8
^bb8:
%77 = arith.constant 2 : i32
%78 = arith.constant 1 : i32
%80 = arith.extsi %78 : i32 to i64
%79 = arith.addi %50, %80 : i64
%81 = arith.index_cast %77 : i32 to index
%82 = arith.index_cast %79 : i32 to index
%84 = arith.constant 1 : index
%85 = arith.constant -1 : index
%86 = arith.cmpi sle, %81, %82 : index
%83 = arith.select %86, %84, %85 : index
cf.br ^bb9(%81 : index)
^bb9(%87: index):
%88 = arith.cmpi slt, %87, %82 : index
%89 = arith.cmpi sgt, %87, %82 : index
%90 = arith.select %86, %88, %89 : i1
cf.cond_br %90, ^bb10(%87 : index), ^bb11(%87 : index)
^bb10(%91: index):
%93 = arith.index_cast %91 : index to i64
%94 = llvm.getelementptr %51[%93] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%92 = llvm.load %94 : !llvm.ptr -> i64
%95 = arith.constant 0 : i32
%97 = arith.extsi %95 : i32 to i64
%96 = arith.cmpi eq, %92, %97 : i64
cf.cond_br %96, ^bb12, ^bb13
^bb12:
%98 = arith.index_cast %91 : index to i64
%99 = arith.index_cast %91 : index to i64
%100 = llvm.getelementptr %51[%99] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %98, %100 : i64, !llvm.ptr
%101 = llvm.load %69 : !llvm.ptr -> i64
%102 = arith.index_cast %91 : index to i64
%103 = llvm.getelementptr %57[%101] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %102, %103 : i64, !llvm.ptr
%104 = llvm.load %69 : !llvm.ptr -> i64
%105 = arith.constant 1 : i32
%107 = arith.extsi %105 : i32 to i64
%106 = arith.addi %104, %107 : i64
llvm.store %106, %69 : i64, !llvm.ptr
cf.br ^bb14
^bb13:
cf.br ^bb14
^bb14:
%109 = arith.index_cast %91 : index to i64
%110 = llvm.getelementptr %51[%109] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%108 = llvm.load %110 : !llvm.ptr -> i64
%111 = arith.constant 0 : i32
%112 = llvm.load %69 : !llvm.ptr -> i64
%113 = arith.index_cast %111 : i32 to index
%114 = arith.index_cast %112 : i32 to index
%116 = arith.constant 1 : index
%117 = arith.constant -1 : index
%118 = arith.cmpi sle, %113, %114 : index
%115 = arith.select %118, %116, %117 : index
cf.br ^bb15(%113 : index)
^bb15(%119: index):
%120 = arith.cmpi slt, %119, %114 : index
%121 = arith.cmpi sgt, %119, %114 : index
%122 = arith.select %118, %120, %121 : i1
cf.cond_br %122, ^bb16(%119 : index), ^bb17(%119 : index)
^bb16(%123: index):
%125 = arith.index_cast %123 : index to i64
%126 = llvm.getelementptr %57[%125] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%124 = llvm.load %126 : !llvm.ptr -> i64
%128 = arith.trunci %124 : i64 to i32
%129 = arith.index_cast %91 : index to i32
%127 = arith.muli %128, %129 : i32
%130 = arith.extsi %127 : i32 to i64
%131 = arith.cmpi sgt, %130, %50 : i64
cf.cond_br %131, ^bb18, ^bb19
^bb18:
cf.br ^bb17(%123 : index)
^bb19:
cf.br ^bb20
^bb20:
%132 = llvm.getelementptr %51[%130] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %124, %132 : i64, !llvm.ptr
%133 = arith.cmpi eq, %124, %108 : i64
cf.cond_br %133, ^bb21, ^bb22
^bb21:
cf.br ^bb17(%123 : index)
^bb22:
cf.br ^bb23
^bb23:
%134 = arith.addi %123, %115 : index
cf.br ^bb15(%134 : index)
^bb17(%135: index):
%136 = arith.addi %91, %83 : index
cf.br ^bb9(%136 : index)
^bb11(%137: index):
%138 = arith.constant 0 : i32
%139 = arith.extsi %138 : i32 to i64
%140 = llvm.mlir.constant(1 : i64) : i64
%141 = llvm.alloca %140 x i64 : (i64) -> !llvm.ptr
llvm.store %139, %141 : i64, !llvm.ptr
%142 = arith.constant 2 : i32
%143 = arith.extsi %142 : i32 to i64
%144 = llvm.mlir.constant(1 : i64) : i64
%145 = llvm.alloca %144 x i64 : (i64) -> !llvm.ptr
llvm.store %143, %145 : i64, !llvm.ptr
cf.br ^bb24
^bb24:
%146 = llvm.load %145 : !llvm.ptr -> i64
%147 = arith.cmpi sle, %146, %50 : i64
cf.cond_br %147, ^bb25, ^bb26
^bb25:
%148 = llvm.load %141 : !llvm.ptr -> i64
%149 = llvm.load %145 : !llvm.ptr -> i64
%150 = arith.divsi %50, %149 : i64
%151 = arith.addi %148, %150 : i64
llvm.store %151, %141 : i64, !llvm.ptr
%152 = llvm.load %145 : !llvm.ptr -> i64
%153 = arith.constant 2 : i32
%155 = arith.extsi %153 : i32 to i64
%154 = arith.muli %152, %155 : i64
llvm.store %154, %145 : i64, !llvm.ptr
cf.br ^bb24
^bb26:
%156 = arith.constant 2 : i32
%157 = llvm.load %141 : !llvm.ptr -> i64
%159 = arith.extsi %156 : i32 to i64
%158 = arith.muli %159, %157 : i64
%160 = arith.constant 1 : i32
%162 = arith.extsi %160 : i32 to i64
%161 = arith.addi %158, %162 : i64
%164 = arith.constant 1 : i32
%166 = arith.extsi %164 : i32 to i64
%165 = arith.addi %161, %166 : i64
%167 = arith.constant 8 : i32
%168 = arith.extsi %167 : i32 to i64
%163 = func.call @calloc(%165, %168) : (i64, i64) -> !llvm.ptr
%169 = llvm.mlir.zero : !llvm.ptr
%170 = llvm.icmp "eq" %163, %169 : !llvm.ptr
cf.cond_br %170, ^bb27, ^bb28
^bb27:
%171 = arith.constant 1 : i32
func.return %171 : i32
^bb28:
cf.br ^bb29
^bb29:
%172 = arith.constant 1 : i32
%173 = arith.constant 1 : i32
%174 = arith.extsi %172 : i32 to i64
%175 = arith.extsi %173 : i32 to i64
%176 = llvm.getelementptr %163[%175] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %174, %176 : i64, !llvm.ptr
%177 = arith.constant 2 : i32
%178 = arith.constant 1 : i32
%180 = arith.extsi %178 : i32 to i64
%179 = arith.addi %161, %180 : i64
%181 = arith.index_cast %177 : i32 to index
%182 = arith.index_cast %179 : i32 to index
%184 = arith.constant 1 : index
%185 = arith.constant -1 : index
%186 = arith.cmpi sle, %181, %182 : index
%183 = arith.select %186, %184, %185 : index
cf.br ^bb30(%181 : index)
^bb30(%187: index):
%188 = arith.cmpi slt, %187, %182 : index
%189 = arith.cmpi sgt, %187, %182 : index
%190 = arith.select %186, %188, %189 : i1
cf.cond_br %190, ^bb31(%187 : index), ^bb32(%187 : index)
^bb31(%191: index):
%192 = llvm.mlir.addressof @MOD : !llvm.ptr
%193 = llvm.load %192 : !llvm.ptr -> i64
%194 = llvm.mlir.addressof @MOD : !llvm.ptr
%195 = llvm.load %194 : !llvm.ptr -> i64
%197 = arith.trunci %195 : i64 to i32
%198 = arith.index_cast %191 : index to i32
%196 = arith.divsi %197, %198 : i32
%200 = llvm.mlir.addressof @MOD : !llvm.ptr
%201 = llvm.load %200 : !llvm.ptr -> i64
%203 = arith.trunci %201 : i64 to i32
%204 = arith.index_cast %191 : index to i32
%202 = arith.remsi %203, %204 : i32
%205 = arith.extsi %202 : i32 to i64
%206 = llvm.getelementptr %163[%205] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%199 = llvm.load %206 : !llvm.ptr -> i64
%208 = arith.extsi %196 : i32 to i64
%207 = arith.muli %208, %199 : i64
%209 = llvm.mlir.addressof @MOD : !llvm.ptr
%210 = llvm.load %209 : !llvm.ptr -> i64
%211 = arith.remsi %207, %210 : i64
%212 = arith.subi %193, %211 : i64
%213 = llvm.mlir.addressof @MOD : !llvm.ptr
%214 = llvm.load %213 : !llvm.ptr -> i64
%215 = arith.remsi %212, %214 : i64
%216 = arith.index_cast %191 : index to i64
%217 = llvm.getelementptr %163[%216] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %215, %217 : i64, !llvm.ptr
%218 = arith.addi %191, %183 : index
cf.br ^bb30(%218 : index)
^bb32(%219: index):
%221 = arith.constant 1 : i32
%223 = arith.extsi %221 : i32 to i64
%222 = arith.addi %50, %223 : i64
%224 = arith.constant 8 : i32
%225 = arith.extsi %224 : i32 to i64
%220 = func.call @calloc(%222, %225) : (i64, i64) -> !llvm.ptr
%226 = llvm.mlir.zero : !llvm.ptr
%227 = llvm.icmp "eq" %220, %226 : !llvm.ptr
cf.cond_br %227, ^bb33, ^bb34
^bb33:
%228 = arith.constant 1 : i32
func.return %228 : i32
^bb34:
cf.br ^bb35
^bb35:
%229 = arith.constant 1 : i32
%230 = arith.extsi %229 : i32 to i64
%231 = llvm.mlir.constant(1 : i64) : i64
%232 = llvm.alloca %231 x i64 : (i64) -> !llvm.ptr
llvm.store %230, %232 : i64, !llvm.ptr
%233 = arith.constant 0 : i32
%234 = arith.extsi %233 : i32 to i64
%235 = llvm.mlir.constant(1 : i64) : i64
%236 = llvm.alloca %235 x i64 : (i64) -> !llvm.ptr
llvm.store %234, %236 : i64, !llvm.ptr
%237 = arith.constant 2 : i32
%238 = arith.constant 1 : i32
%240 = arith.extsi %238 : i32 to i64
%239 = arith.addi %50, %240 : i64
%241 = arith.index_cast %237 : i32 to index
%242 = arith.index_cast %239 : i32 to index
%244 = arith.constant 1 : index
%245 = arith.constant -1 : index
%246 = arith.cmpi sle, %241, %242 : index
%243 = arith.select %246, %244, %245 : index
cf.br ^bb36(%241 : index)
^bb36(%247: index):
%248 = arith.cmpi slt, %247, %242 : index
%249 = arith.cmpi sgt, %247, %242 : index
%250 = arith.select %246, %248, %249 : i1
cf.cond_br %250, ^bb37(%247 : index), ^bb38(%247 : index)
^bb37(%251: index):
%252 = arith.index_cast %251 : index to i64
%253 = llvm.mlir.constant(1 : i64) : i64
%254 = llvm.alloca %253 x i64 : (i64) -> !llvm.ptr
llvm.store %252, %254 : i64, !llvm.ptr
cf.br ^bb39
^bb39:
%255 = llvm.load %254 : !llvm.ptr -> i64
%256 = arith.constant 1 : i32
%258 = arith.extsi %256 : i32 to i64
%257 = arith.cmpi sgt, %255, %258 : i64
cf.cond_br %257, ^bb40, ^bb41
^bb40:
%260 = llvm.load %254 : !llvm.ptr -> i64
%261 = llvm.getelementptr %51[%260] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%259 = llvm.load %261 : !llvm.ptr -> i64
%262 = arith.constant 0 : i32
%263 = arith.extsi %262 : i32 to i64
%264 = llvm.mlir.constant(1 : i64) : i64
%265 = llvm.alloca %264 x i64 : (i64) -> !llvm.ptr
llvm.store %263, %265 : i64, !llvm.ptr
cf.br ^bb42
^bb42:
%266 = llvm.load %254 : !llvm.ptr -> i64
%267 = arith.remsi %266, %259 : i64
%268 = arith.constant 0 : i32
%270 = arith.extsi %268 : i32 to i64
%269 = arith.cmpi eq, %267, %270 : i64
cf.cond_br %269, ^bb43, ^bb44
^bb43:
%271 = llvm.load %254 : !llvm.ptr -> i64
%272 = arith.divsi %271, %259 : i64
llvm.store %272, %254 : i64, !llvm.ptr
%273 = llvm.load %265 : !llvm.ptr -> i64
%274 = arith.constant 1 : i32
%276 = arith.extsi %274 : i32 to i64
%275 = arith.addi %273, %276 : i64
llvm.store %275, %265 : i64, !llvm.ptr
cf.br ^bb42
^bb44:
%278 = llvm.getelementptr %220[%259] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%277 = llvm.load %278 : !llvm.ptr -> i64
%279 = llvm.load %265 : !llvm.ptr -> i64
%280 = arith.addi %277, %279 : i64
%281 = arith.constant 2 : i32
%283 = arith.extsi %281 : i32 to i64
%282 = arith.muli %283, %277 : i64
%284 = arith.constant 1 : i32
%286 = arith.extsi %284 : i32 to i64
%285 = arith.addi %282, %286 : i64
%287 = arith.constant 2 : i32
%289 = arith.extsi %287 : i32 to i64
%288 = arith.muli %289, %280 : i64
%290 = arith.constant 1 : i32
%292 = arith.extsi %290 : i32 to i64
%291 = arith.addi %288, %292 : i64
%293 = llvm.load %232 : !llvm.ptr -> i64
%294 = arith.extsi %293 : i64 to i128
%295 = arith.extsi %291 : i64 to i128
%297 = arith.trunci %294 : i128 to i64
%298 = arith.trunci %295 : i128 to i64
%296 = arith.muli %297, %298 : i64
%299 = llvm.mlir.addressof @MOD : !llvm.ptr
%300 = llvm.load %299 : !llvm.ptr -> i64
%301 = arith.extsi %300 : i64 to i128
%303 = arith.trunci %301 : i128 to i64
%302 = arith.remsi %296, %303 : i64
%304 = arith.extsi %302 : i64 to i128
%306 = llvm.getelementptr %163[%285] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%305 = llvm.load %306 : !llvm.ptr -> i64
%307 = arith.extsi %305 : i64 to i128
%309 = arith.trunci %304 : i128 to i64
%310 = arith.trunci %307 : i128 to i64
%308 = arith.muli %309, %310 : i64
%311 = llvm.mlir.addressof @MOD : !llvm.ptr
%312 = llvm.load %311 : !llvm.ptr -> i64
%313 = arith.extsi %312 : i64 to i128
%315 = arith.trunci %313 : i128 to i64
%314 = arith.remsi %308, %315 : i64
%316 = arith.extsi %314 : i64 to i128
%317 = arith.trunci %316 : i128 to i64
llvm.store %317, %232 : i64, !llvm.ptr
%318 = llvm.getelementptr %220[%259] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %280, %318 : i64, !llvm.ptr
cf.br ^bb39
^bb41:
%319 = llvm.load %236 : !llvm.ptr -> i64
%320 = llvm.load %232 : !llvm.ptr -> i64
%321 = arith.addi %319, %320 : i64
%322 = llvm.mlir.addressof @MOD : !llvm.ptr
%323 = llvm.load %322 : !llvm.ptr -> i64
%324 = arith.remsi %321, %323 : i64
llvm.store %324, %236 : i64, !llvm.ptr
%325 = arith.addi %251, %243 : index
cf.br ^bb36(%325 : index)
^bb38(%326: index):
%327 = llvm.mlir.addressof @str_0 : !llvm.ptr
%328 = llvm.load %236 : !llvm.ptr -> i64
%329 = llvm.call @printf(%327, %328) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
func.call @free(%220) : (!llvm.ptr) -> ()
func.call @free(%163) : (!llvm.ptr) -> ()
func.call @free(%57) : (!llvm.ptr) -> ()
func.call @free(%51) : (!llvm.ptr) -> ()
%334 = arith.constant 0 : i32
func.return %334 : i32
}
}