Problem 535
Fractal Sequence — last 9 digits of T(10^18).
View problem on Project Euler
Performance comparison
| Metric | Our solution | Best known |
| Time complexity | O(n) | O(n) |
| Space complexity | O(n^2) | O(n) |
| Approach | Flow solution | Big-integer arithmetic |
| Verdict | Optimal |
Flow source
# Project Euler 535
# Fractal Sequence — last 9 digits of T(10^18).
import euler.nt { isqrt }
extern {
function calloc(n: i64, size: i64) -> ptr<void>
function free(p: ptr<void>) -> void
}
const MOD: i64 = 1000000000
const CAP: i64 = 8388608
function sum_1_to_m_mod(m: i64) -> i64 {
if m <= 0 { return 0 }
let a: i64 = m % (2 * MOD)
let b: i64 = (m + 1) % (2 * MOD)
return (a * b / 2) % MOD
}
function sum_floor_sqrt128(m: i64) -> i128 {
if m <= 0 { return 0 }
let t: i64 = isqrt(m)
let full: i64 = t - 1
if full <= 0 { return (t as i128) * ((m - t * t + 1) as i128) }
let s2: i128 = (full as i128) * ((full + 1) as i128) * ((2 * full + 1) as i128) / 6
let s1: i128 = (full as i128) * ((full + 1) as i128) / 2
let total: i128 = 2 * s2 + s1 + (t as i128) * ((m - t * t + 1) as i128)
return total
}
function hslot(key: i64, keys: ptr<i64>, used: ptr<i8>) -> i64 {
let mut h: i64 = (key * 1140071481932319845) >> 41
h = h & (CAP - 1)
while used[h] == 1 && keys[h] != key {
h = (h + 1) & (CAP - 1)
}
return h
}
function G(n: i64, gk: ptr<i64>, gv: ptr<i128>, gu: ptr<i8>,
pk: ptr<i64>, pv: ptr<i64>, pu: ptr<i8>) -> i128
function phi(n: i64, gk: ptr<i64>, gv: ptr<i128>, gu: ptr<i8>,
pk: ptr<i64>, pv: ptr<i64>, pu: ptr<i8>) -> i64 {
if n <= 1 { return 0 }
let s: i64 = hslot(n, pk, pu)
if pu[s] == 1 { return pv[s] }
let mut lo: i64 = 0
let mut hi: i64 = n
while lo + 1 < hi {
let mid: i64 = (lo + hi) / 2
let gmid: i128 = G(mid, gk, gv, gu, pk, pv, pu)
if gmid > (n as i128) - (mid as i128) {
hi = mid
} else {
lo = mid
}
}
pu[s] = 1
pk[s] = n
pv[s] = lo
return lo
}
function G(n: i64, gk: ptr<i64>, gv: ptr<i128>, gu: ptr<i8>,
pk: ptr<i64>, pv: ptr<i64>, pu: ptr<i8>) -> i128 {
if n == 0 { return 0 }
let s: i64 = hslot(n, gk, gu)
if gu[s] == 1 { return gv[s] }
let r: i64 = phi(n, gk, gv, gu, pk, pv, pu)
let val: i128 = G(r, gk, gv, gu, pk, pv, pu) + sum_floor_sqrt128(n - r)
gu[s] = 1
gk[s] = n
gv[s] = val
return val
}
function main() -> i32 {
let gk: ptr<i64> = calloc(CAP, 8)
let gv: ptr<i128> = calloc(CAP, 16)
let gu: ptr<i8> = calloc(CAP, 1)
let pk: ptr<i64> = calloc(CAP, 8)
let pv: ptr<i64> = calloc(CAP, 8)
let pu: ptr<i8> = calloc(CAP, 1)
if gk == null || gv == null || gu == null || pk == null || pv == null || pu == null {
return 1
}
let mut total: i64 = 0
let mut n: i64 = 1000000000000000000
while n > 0 {
let r: i64 = phi(n, gk, gv, gu, pk, pv, pu)
total = (total + sum_1_to_m_mod(n - r)) % MOD
n = r
}
printf("%lld\n", total)
free(gk); free(gv); free(gu); free(pk); free(pv); free(pu)
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 gcd_i64_i64(int64_t a0, int64_t b0);
int64_t lcm_i64_i64(int64_t a, int64_t b);
int64_t isqrt_i64(int64_t n);
int64_t mulmod_i64_i64_i64(int64_t a0, int64_t b0, int64_t mod);
int64_t mod_pow_i64_i64_i64(int64_t base, int64_t exp, int64_t mod);
bool is_prime_i64(int64_t n);
int64_t sum_1_to_m_mod_i64(int64_t m);
__int128 sum_floor_sqrt128_i64(int64_t m);
int64_t hslot_i64_ptr_i64_ptr_i8(int64_t key, int64_t* keys, int8_t* used);
__int128 G_i64_ptr_i64_ptr_i128_ptr_i8_ptr_i64_ptr_i64_ptr_i8(int64_t n, int64_t* gk, __int128* gv, int8_t* gu, int64_t* pk, int64_t* pv, int8_t* pu);
int64_t phi_i64_ptr_i64_ptr_i128_ptr_i8_ptr_i64_ptr_i64_ptr_i8(int64_t n, int64_t* gk, __int128* gv, int8_t* gu, int64_t* pk, int64_t* pv, int8_t* pu);
__int128 G_i64_ptr_i64_ptr_i128_ptr_i8_ptr_i64_ptr_i64_ptr_i8(int64_t n, int64_t* gk, __int128* gv, int8_t* gu, int64_t* pk, int64_t* pv, int8_t* pu);
int32_t main(void);
static const int64_t MOD = 1000000000;
static const int64_t CAP = 8388608;
int64_t gcd_i64_i64(int64_t a0, int64_t b0) {
int64_t a = a0;
int64_t b = b0;
while (b != 0) {
int64_t t = FLOW_CHECKED_MOD((a), (b));
a = b;
b = t;
}
return a;
}
int64_t lcm_i64_i64(int64_t a, int64_t b) {
if ((a == 0 || b == 0)) {
return 0;
}
return (FLOW_CHECKED_DIV((a), (gcd_i64_i64(a, b))) * b);
}
int64_t isqrt_i64(int64_t n) {
if (n < 2) {
return n;
}
int64_t x = n;
int64_t y = FLOW_CHECKED_DIV(((x + 1)), (2));
while (y < x) {
x = y;
y = FLOW_CHECKED_DIV(((x + FLOW_CHECKED_DIV((n), (x)))), (2));
}
return x;
}
int64_t mulmod_i64_i64_i64(int64_t a0, int64_t b0, int64_t mod) {
int64_t a = FLOW_CHECKED_MOD((a0), (mod));
int64_t b = FLOW_CHECKED_MOD((b0), (mod));
int64_t result = 0;
while (b > 0) {
if (FLOW_CHECKED_MOD((b), (2)) == 1) {
result = FLOW_CHECKED_MOD(((result + a)), (mod));
}
a = FLOW_CHECKED_MOD(((a * 2)), (mod));
b = FLOW_CHECKED_DIV((b), (2));
}
return result;
}
int64_t mod_pow_i64_i64_i64(int64_t base, int64_t exp, int64_t mod) {
if (mod == 1) {
return 0;
}
int64_t result = 1;
int64_t b = FLOW_CHECKED_MOD((base), (mod));
int64_t e = exp;
while (e > 0) {
if (FLOW_CHECKED_MOD((e), (2)) == 1) {
result = mulmod_i64_i64_i64(result, b, mod);
}
b = mulmod_i64_i64_i64(b, b, mod);
e = FLOW_CHECKED_DIV((e), (2));
}
return result;
}
bool is_prime_i64(int64_t n) {
if (n < 2) {
return 0;
}
if (n < 4) {
return 1;
}
if ((FLOW_CHECKED_MOD((n), (2)) == 0 || FLOW_CHECKED_MOD((n), (3)) == 0)) {
return 0;
}
int64_t i = 5;
while ((i * i) <= n) {
if ((FLOW_CHECKED_MOD((n), (i)) == 0 || FLOW_CHECKED_MOD((n), ((i + 2))) == 0)) {
return 0;
}
i = (i + 6);
}
return 1;
}
int64_t sum_1_to_m_mod_i64(int64_t m) {
if (m <= 0) {
return 0;
}
int64_t a = FLOW_CHECKED_MOD((m), ((2 * MOD)));
int64_t b = FLOW_CHECKED_MOD(((m + 1)), ((2 * MOD)));
return FLOW_CHECKED_MOD((FLOW_CHECKED_DIV(((a * b)), (2))), (MOD));
}
__int128 sum_floor_sqrt128_i64(int64_t m) {
if (m <= 0) {
return 0;
}
int64_t t = isqrt_i64(m);
int64_t full = (t - 1);
if (full <= 0) {
return (((__int128)(t)) * ((__int128)(((m - (t * t)) + 1))));
}
__int128 s2 = FLOW_CHECKED_DIV((((((__int128)(full)) * ((__int128)((full + 1)))) * ((__int128)(((2 * full) + 1))))), (6));
__int128 s1 = FLOW_CHECKED_DIV(((((__int128)(full)) * ((__int128)((full + 1))))), (2));
__int128 total = (((2 * s2) + s1) + (((__int128)(t)) * ((__int128)(((m - (t * t)) + 1)))));
return total;
}
int64_t hslot_i64_ptr_i64_ptr_i8(int64_t key, int64_t* keys, int8_t* used) {
int64_t h = FLOW_CHECKED_SHR(((key * 1140071481932319845)), (41));
h = (h & (CAP - 1));
while ((used[h] == 1 && keys[h] != key)) {
h = ((h + 1) & (CAP - 1));
}
return h;
}
int64_t phi_i64_ptr_i64_ptr_i128_ptr_i8_ptr_i64_ptr_i64_ptr_i8(int64_t n, int64_t* gk, __int128* gv, int8_t* gu, int64_t* pk, int64_t* pv, int8_t* pu) {
if (n <= 1) {
return 0;
}
int64_t s = hslot_i64_ptr_i64_ptr_i8(n, pk, pu);
if (pu[s] == 1) {
return pv[s];
}
int64_t lo = 0;
int64_t hi = n;
while ((lo + 1) < hi) {
int64_t mid = FLOW_CHECKED_DIV(((lo + hi)), (2));
__int128 gmid = G_i64_ptr_i64_ptr_i128_ptr_i8_ptr_i64_ptr_i64_ptr_i8(mid, gk, gv, gu, pk, pv, pu);
if (gmid > (((__int128)(n)) - ((__int128)(mid)))) {
hi = mid;
} else {
lo = mid;
}
}
pu[s] = 1;
pk[s] = n;
pv[s] = lo;
return lo;
}
__int128 G_i64_ptr_i64_ptr_i128_ptr_i8_ptr_i64_ptr_i64_ptr_i8(int64_t n, int64_t* gk, __int128* gv, int8_t* gu, int64_t* pk, int64_t* pv, int8_t* pu) {
if (n == 0) {
return 0;
}
int64_t s = hslot_i64_ptr_i64_ptr_i8(n, gk, gu);
if (gu[s] == 1) {
return gv[s];
}
int64_t r = phi_i64_ptr_i64_ptr_i128_ptr_i8_ptr_i64_ptr_i64_ptr_i8(n, gk, gv, gu, pk, pv, pu);
__int128 val = (G_i64_ptr_i64_ptr_i128_ptr_i8_ptr_i64_ptr_i64_ptr_i8(r, gk, gv, gu, pk, pv, pu) + sum_floor_sqrt128_i64((n - r)));
gu[s] = 1;
gk[s] = n;
gv[s] = val;
return val;
}
int32_t main(void) {
int64_t* gk = (int64_t*)(calloc(CAP, 8));
__int128* gv = (__int128*)(calloc(CAP, 16));
int8_t* gu = (int8_t*)(calloc(CAP, 1));
int64_t* pk = (int64_t*)(calloc(CAP, 8));
int64_t* pv = (int64_t*)(calloc(CAP, 8));
int8_t* pu = (int8_t*)(calloc(CAP, 1));
if ((((((gk == NULL || gv == NULL) || gu == NULL) || pk == NULL) || pv == NULL) || pu == NULL)) {
return 1;
}
int64_t total = 0;
int64_t n = 1000000000000000000;
while (n > 0) {
int64_t r = phi_i64_ptr_i64_ptr_i128_ptr_i8_ptr_i64_ptr_i64_ptr_i8(n, gk, gv, gu, pk, pv, pu);
total = FLOW_CHECKED_MOD(((total + sum_1_to_m_mod_i64((n - r)))), (MOD));
n = r;
}
printf("%lld\n", total);
free(gk);
free(gv);
free(gu);
free(pk);
free(pv);
free(pu);
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 @gcd(%arg0: i64, %arg1: i64) -> i64 {
%0 = llvm.mlir.constant(1 : i64) : i64
%1 = llvm.alloca %0 x i64 : (i64) -> !llvm.ptr
llvm.store %arg0, %1 : i64, !llvm.ptr
%2 = llvm.mlir.constant(1 : i64) : i64
%3 = llvm.alloca %2 x i64 : (i64) -> !llvm.ptr
llvm.store %arg1, %3 : i64, !llvm.ptr
cf.br ^bb0
^bb0:
%4 = llvm.load %3 : !llvm.ptr -> i64
%5 = arith.constant 0 : i32
%7 = arith.extsi %5 : i32 to i64
%6 = arith.cmpi ne, %4, %7 : i64
cf.cond_br %6, ^bb1, ^bb2
^bb1:
%8 = llvm.load %1 : !llvm.ptr -> i64
%9 = llvm.load %3 : !llvm.ptr -> i64
%10 = arith.remsi %8, %9 : i64
%11 = llvm.load %3 : !llvm.ptr -> i64
llvm.store %11, %1 : i64, !llvm.ptr
llvm.store %10, %3 : i64, !llvm.ptr
cf.br ^bb0
^bb2:
%12 = llvm.load %1 : !llvm.ptr -> i64
func.return %12 : i64
}
func.func @lcm(%arg0: i64, %arg1: i64) -> i64 {
%13 = arith.constant 0 : i32
%15 = arith.extsi %13 : i32 to i64
%14 = arith.cmpi eq, %arg0, %15 : i64
%16 = scf.if %14 -> (i1) {
%17 = arith.constant true
scf.yield %17 : i1
} else {
%18 = arith.constant 0 : i32
%20 = arith.extsi %18 : i32 to i64
%19 = arith.cmpi eq, %arg1, %20 : i64
scf.yield %19 : i1
}
cf.cond_br %16, ^bb3, ^bb4
^bb3:
%21 = arith.constant 0 : i32
%22 = arith.extsi %21 : i32 to i64
func.return %22 : i64
^bb4:
cf.br ^bb5
^bb5:
%23 = func.call @gcd(%arg0, %arg1) : (i64, i64) -> i64
%24 = arith.divsi %arg0, %23 : i64
%25 = arith.muli %24, %arg1 : i64
func.return %25 : i64
}
func.func @isqrt(%arg0: i64) -> i64 {
%26 = arith.constant 2 : i32
%28 = arith.extsi %26 : i32 to i64
%27 = arith.cmpi slt, %arg0, %28 : i64
cf.cond_br %27, ^bb6, ^bb7
^bb6:
func.return %arg0 : i64
^bb7:
cf.br ^bb8
^bb8:
%29 = llvm.mlir.constant(1 : i64) : i64
%30 = llvm.alloca %29 x i64 : (i64) -> !llvm.ptr
llvm.store %arg0, %30 : i64, !llvm.ptr
%31 = llvm.load %30 : !llvm.ptr -> i64
%32 = arith.constant 1 : i32
%34 = arith.extsi %32 : i32 to i64
%33 = arith.addi %31, %34 : i64
%35 = arith.constant 2 : i32
%37 = arith.extsi %35 : i32 to i64
%36 = arith.divsi %33, %37 : i64
%38 = llvm.mlir.constant(1 : i64) : i64
%39 = llvm.alloca %38 x i64 : (i64) -> !llvm.ptr
llvm.store %36, %39 : i64, !llvm.ptr
cf.br ^bb9
^bb9:
%40 = llvm.load %39 : !llvm.ptr -> i64
%41 = llvm.load %30 : !llvm.ptr -> i64
%42 = arith.cmpi slt, %40, %41 : i64
cf.cond_br %42, ^bb10, ^bb11
^bb10:
%43 = llvm.load %39 : !llvm.ptr -> i64
llvm.store %43, %30 : i64, !llvm.ptr
%44 = llvm.load %30 : !llvm.ptr -> i64
%45 = llvm.load %30 : !llvm.ptr -> i64
%46 = arith.divsi %arg0, %45 : i64
%47 = arith.addi %44, %46 : i64
%48 = arith.constant 2 : i32
%50 = arith.extsi %48 : i32 to i64
%49 = arith.divsi %47, %50 : i64
llvm.store %49, %39 : i64, !llvm.ptr
cf.br ^bb9
^bb11:
%51 = llvm.load %30 : !llvm.ptr -> i64
func.return %51 : i64
}
func.func @mulmod(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
%52 = arith.remsi %arg0, %arg2 : i64
%53 = llvm.mlir.constant(1 : i64) : i64
%54 = llvm.alloca %53 x i64 : (i64) -> !llvm.ptr
llvm.store %52, %54 : i64, !llvm.ptr
%55 = arith.remsi %arg1, %arg2 : i64
%56 = llvm.mlir.constant(1 : i64) : i64
%57 = llvm.alloca %56 x i64 : (i64) -> !llvm.ptr
llvm.store %55, %57 : i64, !llvm.ptr
%58 = arith.constant 0 : i32
%59 = arith.extsi %58 : i32 to i64
%60 = llvm.mlir.constant(1 : i64) : i64
%61 = llvm.alloca %60 x i64 : (i64) -> !llvm.ptr
llvm.store %59, %61 : i64, !llvm.ptr
cf.br ^bb12
^bb12:
%62 = llvm.load %57 : !llvm.ptr -> i64
%63 = arith.constant 0 : i32
%65 = arith.extsi %63 : i32 to i64
%64 = arith.cmpi sgt, %62, %65 : i64
cf.cond_br %64, ^bb13, ^bb14
^bb13:
%66 = llvm.load %57 : !llvm.ptr -> i64
%67 = arith.constant 2 : i32
%69 = arith.extsi %67 : i32 to i64
%68 = arith.remsi %66, %69 : i64
%70 = arith.constant 1 : i32
%72 = arith.extsi %70 : i32 to i64
%71 = arith.cmpi eq, %68, %72 : i64
cf.cond_br %71, ^bb15, ^bb16
^bb15:
%73 = llvm.load %61 : !llvm.ptr -> i64
%74 = llvm.load %54 : !llvm.ptr -> i64
%75 = arith.addi %73, %74 : i64
%76 = arith.remsi %75, %arg2 : i64
llvm.store %76, %61 : i64, !llvm.ptr
cf.br ^bb17
^bb16:
cf.br ^bb17
^bb17:
%77 = llvm.load %54 : !llvm.ptr -> i64
%78 = arith.constant 2 : i32
%80 = arith.extsi %78 : i32 to i64
%79 = arith.muli %77, %80 : i64
%81 = arith.remsi %79, %arg2 : i64
llvm.store %81, %54 : i64, !llvm.ptr
%82 = llvm.load %57 : !llvm.ptr -> i64
%83 = arith.constant 2 : i32
%85 = arith.extsi %83 : i32 to i64
%84 = arith.divsi %82, %85 : i64
llvm.store %84, %57 : i64, !llvm.ptr
cf.br ^bb12
^bb14:
%86 = llvm.load %61 : !llvm.ptr -> i64
func.return %86 : i64
}
func.func @mod_pow(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
%87 = arith.constant 1 : i32
%89 = arith.extsi %87 : i32 to i64
%88 = arith.cmpi eq, %arg2, %89 : i64
cf.cond_br %88, ^bb18, ^bb19
^bb18:
%90 = arith.constant 0 : i32
%91 = arith.extsi %90 : i32 to i64
func.return %91 : i64
^bb19:
cf.br ^bb20
^bb20:
%92 = arith.constant 1 : i32
%93 = arith.extsi %92 : i32 to i64
%94 = llvm.mlir.constant(1 : i64) : i64
%95 = llvm.alloca %94 x i64 : (i64) -> !llvm.ptr
llvm.store %93, %95 : i64, !llvm.ptr
%96 = arith.remsi %arg0, %arg2 : i64
%97 = llvm.mlir.constant(1 : i64) : i64
%98 = llvm.alloca %97 x i64 : (i64) -> !llvm.ptr
llvm.store %96, %98 : i64, !llvm.ptr
%99 = llvm.mlir.constant(1 : i64) : i64
%100 = llvm.alloca %99 x i64 : (i64) -> !llvm.ptr
llvm.store %arg1, %100 : i64, !llvm.ptr
cf.br ^bb21
^bb21:
%101 = llvm.load %100 : !llvm.ptr -> i64
%102 = arith.constant 0 : i32
%104 = arith.extsi %102 : i32 to i64
%103 = arith.cmpi sgt, %101, %104 : i64
cf.cond_br %103, ^bb22, ^bb23
^bb22:
%105 = llvm.load %100 : !llvm.ptr -> i64
%106 = arith.constant 2 : i32
%108 = arith.extsi %106 : i32 to i64
%107 = arith.remsi %105, %108 : i64
%109 = arith.constant 1 : i32
%111 = arith.extsi %109 : i32 to i64
%110 = arith.cmpi eq, %107, %111 : i64
cf.cond_br %110, ^bb24, ^bb25
^bb24:
%113 = llvm.load %95 : !llvm.ptr -> i64
%114 = llvm.load %98 : !llvm.ptr -> i64
%112 = func.call @mulmod(%113, %114, %arg2) : (i64, i64, i64) -> i64
llvm.store %112, %95 : i64, !llvm.ptr
cf.br ^bb26
^bb25:
cf.br ^bb26
^bb26:
%116 = llvm.load %98 : !llvm.ptr -> i64
%117 = llvm.load %98 : !llvm.ptr -> i64
%115 = func.call @mulmod(%116, %117, %arg2) : (i64, i64, i64) -> i64
llvm.store %115, %98 : i64, !llvm.ptr
%118 = llvm.load %100 : !llvm.ptr -> i64
%119 = arith.constant 2 : i32
%121 = arith.extsi %119 : i32 to i64
%120 = arith.divsi %118, %121 : i64
llvm.store %120, %100 : i64, !llvm.ptr
cf.br ^bb21
^bb23:
%122 = llvm.load %95 : !llvm.ptr -> i64
func.return %122 : i64
}
func.func @is_prime(%arg0: i64) -> i1 {
%123 = arith.constant 2 : i32
%125 = arith.extsi %123 : i32 to i64
%124 = arith.cmpi slt, %arg0, %125 : i64
cf.cond_br %124, ^bb27, ^bb28
^bb27:
%126 = arith.constant 0 : i1
func.return %126 : i1
^bb28:
cf.br ^bb29
^bb29:
%127 = arith.constant 4 : i32
%129 = arith.extsi %127 : i32 to i64
%128 = arith.cmpi slt, %arg0, %129 : i64
cf.cond_br %128, ^bb30, ^bb31
^bb30:
%130 = arith.constant 1 : i1
func.return %130 : i1
^bb31:
cf.br ^bb32
^bb32:
%131 = arith.constant 2 : i32
%133 = arith.extsi %131 : i32 to i64
%132 = arith.remsi %arg0, %133 : i64
%134 = arith.constant 0 : i32
%136 = arith.extsi %134 : i32 to i64
%135 = arith.cmpi eq, %132, %136 : i64
%137 = scf.if %135 -> (i1) {
%138 = arith.constant true
scf.yield %138 : i1
} else {
%139 = arith.constant 3 : i32
%141 = arith.extsi %139 : i32 to i64
%140 = arith.remsi %arg0, %141 : i64
%142 = arith.constant 0 : i32
%144 = arith.extsi %142 : i32 to i64
%143 = arith.cmpi eq, %140, %144 : i64
scf.yield %143 : i1
}
cf.cond_br %137, ^bb33, ^bb34
^bb33:
%145 = arith.constant 0 : i1
func.return %145 : i1
^bb34:
cf.br ^bb35
^bb35:
%146 = arith.constant 5 : 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
cf.br ^bb36
^bb36:
%150 = llvm.load %149 : !llvm.ptr -> i64
%151 = llvm.load %149 : !llvm.ptr -> i64
%152 = arith.muli %150, %151 : i64
%153 = arith.cmpi sle, %152, %arg0 : i64
cf.cond_br %153, ^bb37, ^bb38
^bb37:
%154 = llvm.load %149 : !llvm.ptr -> i64
%155 = arith.remsi %arg0, %154 : i64
%156 = arith.constant 0 : i32
%158 = arith.extsi %156 : i32 to i64
%157 = arith.cmpi eq, %155, %158 : i64
%159 = scf.if %157 -> (i1) {
%160 = arith.constant true
scf.yield %160 : i1
} else {
%161 = llvm.load %149 : !llvm.ptr -> i64
%162 = arith.constant 2 : i32
%164 = arith.extsi %162 : i32 to i64
%163 = arith.addi %161, %164 : i64
%165 = arith.remsi %arg0, %163 : i64
%166 = arith.constant 0 : i32
%168 = arith.extsi %166 : i32 to i64
%167 = arith.cmpi eq, %165, %168 : i64
scf.yield %167 : i1
}
cf.cond_br %159, ^bb39, ^bb40
^bb39:
%169 = arith.constant 0 : i1
func.return %169 : i1
^bb40:
cf.br ^bb41
^bb41:
%170 = llvm.load %149 : !llvm.ptr -> i64
%171 = arith.constant 6 : i32
%173 = arith.extsi %171 : i32 to i64
%172 = arith.addi %170, %173 : i64
llvm.store %172, %149 : i64, !llvm.ptr
cf.br ^bb36
^bb38:
%174 = arith.constant 1 : i1
func.return %174 : i1
}
func.func private @calloc(i64, i64) -> !llvm.ptr
func.func private @free(!llvm.ptr) -> ()
// Constant: MOD
llvm.mlir.global internal constant @MOD(1000000000 : i64) : i64
// Constant: CAP
llvm.mlir.global internal constant @CAP(8388608 : i64) : i64
func.func @sum_1_to_m_mod(%arg0: i64) -> i64 {
%175 = arith.constant 0 : i32
%177 = arith.extsi %175 : i32 to i64
%176 = arith.cmpi sle, %arg0, %177 : i64
cf.cond_br %176, ^bb42, ^bb43
^bb42:
%178 = arith.constant 0 : i32
%179 = arith.extsi %178 : i32 to i64
func.return %179 : i64
^bb43:
cf.br ^bb44
^bb44:
%180 = arith.constant 2 : i32
%181 = llvm.mlir.addressof @MOD : !llvm.ptr
%182 = llvm.load %181 : !llvm.ptr -> i64
%184 = arith.extsi %180 : i32 to i64
%183 = arith.muli %184, %182 : i64
%185 = arith.remsi %arg0, %183 : i64
%186 = arith.constant 1 : i32
%188 = arith.extsi %186 : i32 to i64
%187 = arith.addi %arg0, %188 : i64
%189 = arith.constant 2 : i32
%190 = llvm.mlir.addressof @MOD : !llvm.ptr
%191 = llvm.load %190 : !llvm.ptr -> i64
%193 = arith.extsi %189 : i32 to i64
%192 = arith.muli %193, %191 : i64
%194 = arith.remsi %187, %192 : i64
%195 = arith.muli %185, %194 : i64
%196 = arith.constant 2 : i32
%198 = arith.extsi %196 : i32 to i64
%197 = arith.divsi %195, %198 : i64
%199 = llvm.mlir.addressof @MOD : !llvm.ptr
%200 = llvm.load %199 : !llvm.ptr -> i64
%201 = arith.remsi %197, %200 : i64
func.return %201 : i64
}
func.func @sum_floor_sqrt128(%arg0: i64) -> i128 {
%202 = arith.constant 0 : i32
%204 = arith.extsi %202 : i32 to i64
%203 = arith.cmpi sle, %arg0, %204 : i64
cf.cond_br %203, ^bb45, ^bb46
^bb45:
%205 = arith.constant 0 : i32
%206 = arith.extsi %205 : i32 to i128
func.return %206 : i128
^bb46:
cf.br ^bb47
^bb47:
%207 = func.call @isqrt(%arg0) : (i64) -> i64
%208 = arith.constant 1 : i32
%210 = arith.extsi %208 : i32 to i64
%209 = arith.subi %207, %210 : i64
%211 = arith.constant 0 : i32
%213 = arith.extsi %211 : i32 to i64
%212 = arith.cmpi sle, %209, %213 : i64
cf.cond_br %212, ^bb48, ^bb49
^bb48:
%214 = arith.extsi %207 : i64 to i128
%215 = arith.muli %207, %207 : i64
%216 = arith.subi %arg0, %215 : i64
%217 = arith.constant 1 : i32
%219 = arith.extsi %217 : i32 to i64
%218 = arith.addi %216, %219 : i64
%220 = arith.extsi %218 : i64 to i128
%222 = arith.trunci %214 : i128 to i64
%223 = arith.trunci %220 : i128 to i64
%221 = arith.muli %222, %223 : i64
%224 = arith.extsi %221 : i64 to i128
func.return %224 : i128
^bb49:
cf.br ^bb50
^bb50:
%225 = arith.extsi %209 : i64 to i128
%226 = arith.constant 1 : i32
%228 = arith.extsi %226 : i32 to i64
%227 = arith.addi %209, %228 : i64
%229 = arith.extsi %227 : i64 to i128
%231 = arith.trunci %225 : i128 to i64
%232 = arith.trunci %229 : i128 to i64
%230 = arith.muli %231, %232 : i64
%233 = arith.constant 2 : i32
%235 = arith.extsi %233 : i32 to i64
%234 = arith.muli %235, %209 : i64
%236 = arith.constant 1 : i32
%238 = arith.extsi %236 : i32 to i64
%237 = arith.addi %234, %238 : i64
%239 = arith.extsi %237 : i64 to i128
%241 = arith.trunci %239 : i128 to i64
%240 = arith.muli %230, %241 : i64
%242 = arith.constant 6 : i32
%244 = arith.extsi %242 : i32 to i64
%243 = arith.divsi %240, %244 : i64
%245 = arith.extsi %243 : i64 to i128
%246 = arith.extsi %209 : i64 to i128
%247 = arith.constant 1 : i32
%249 = arith.extsi %247 : i32 to i64
%248 = arith.addi %209, %249 : i64
%250 = arith.extsi %248 : i64 to i128
%252 = arith.trunci %246 : i128 to i64
%253 = arith.trunci %250 : i128 to i64
%251 = arith.muli %252, %253 : i64
%254 = arith.constant 2 : i32
%256 = arith.extsi %254 : i32 to i64
%255 = arith.divsi %251, %256 : i64
%257 = arith.extsi %255 : i64 to i128
%258 = arith.constant 2 : i32
%260 = arith.extsi %258 : i32 to i64
%261 = arith.trunci %245 : i128 to i64
%259 = arith.muli %260, %261 : i64
%263 = arith.trunci %257 : i128 to i64
%262 = arith.addi %259, %263 : i64
%264 = arith.extsi %207 : i64 to i128
%265 = arith.muli %207, %207 : i64
%266 = arith.subi %arg0, %265 : i64
%267 = arith.constant 1 : i32
%269 = arith.extsi %267 : i32 to i64
%268 = arith.addi %266, %269 : i64
%270 = arith.extsi %268 : i64 to i128
%272 = arith.trunci %264 : i128 to i64
%273 = arith.trunci %270 : i128 to i64
%271 = arith.muli %272, %273 : i64
%274 = arith.addi %262, %271 : i64
%275 = arith.extsi %274 : i64 to i128
func.return %275 : i128
}
func.func @hslot(%arg0: i64, %arg1: !llvm.ptr, %arg2: !llvm.ptr) -> i64 {
%276 = arith.constant 1140071477637352549 : i32
%278 = arith.extsi %276 : i32 to i64
%277 = arith.muli %arg0, %278 : i64
%279 = arith.constant 41 : i32
%281 = arith.extsi %279 : i32 to i64
%280 = arith.shrsi %277, %281 : i64
%282 = llvm.mlir.constant(1 : i64) : i64
%283 = llvm.alloca %282 x i64 : (i64) -> !llvm.ptr
llvm.store %280, %283 : i64, !llvm.ptr
%284 = llvm.load %283 : !llvm.ptr -> i64
%285 = llvm.mlir.addressof @CAP : !llvm.ptr
%286 = llvm.load %285 : !llvm.ptr -> i64
%287 = arith.constant 1 : i32
%289 = arith.extsi %287 : i32 to i64
%288 = arith.subi %286, %289 : i64
%290 = arith.andi %284, %288 : i64
llvm.store %290, %283 : i64, !llvm.ptr
cf.br ^bb51
^bb51:
%292 = llvm.load %283 : !llvm.ptr -> i64
%293 = llvm.getelementptr %arg2[%292] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%291 = llvm.load %293 : !llvm.ptr -> i8
%294 = arith.constant 1 : i32
%296 = arith.extsi %291 : i8 to i32
%295 = arith.cmpi eq, %296, %294 : i32
%297 = scf.if %295 -> (i1) {
%299 = llvm.load %283 : !llvm.ptr -> i64
%300 = llvm.getelementptr %arg1[%299] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%298 = llvm.load %300 : !llvm.ptr -> i64
%301 = arith.cmpi ne, %298, %arg0 : i64
scf.yield %301 : i1
} else {
%302 = arith.constant false
scf.yield %302 : i1
}
cf.cond_br %297, ^bb52, ^bb53
^bb52:
%303 = llvm.load %283 : !llvm.ptr -> i64
%304 = arith.constant 1 : i32
%306 = arith.extsi %304 : i32 to i64
%305 = arith.addi %303, %306 : i64
%307 = llvm.mlir.addressof @CAP : !llvm.ptr
%308 = llvm.load %307 : !llvm.ptr -> i64
%309 = arith.constant 1 : i32
%311 = arith.extsi %309 : i32 to i64
%310 = arith.subi %308, %311 : i64
%312 = arith.andi %305, %310 : i64
llvm.store %312, %283 : i64, !llvm.ptr
cf.br ^bb51
^bb53:
%313 = llvm.load %283 : !llvm.ptr -> i64
func.return %313 : i64
}
func.func @G(%arg0: i64, %arg1: !llvm.ptr, %arg2: !llvm.ptr, %arg3: !llvm.ptr, %arg4: !llvm.ptr, %arg5: !llvm.ptr, %arg6: !llvm.ptr) -> i128 {
}
func.func @phi(%arg0: i64, %arg1: !llvm.ptr, %arg2: !llvm.ptr, %arg3: !llvm.ptr, %arg4: !llvm.ptr, %arg5: !llvm.ptr, %arg6: !llvm.ptr) -> i64 {
%314 = arith.constant 1 : i32
%316 = arith.extsi %314 : i32 to i64
%315 = arith.cmpi sle, %arg0, %316 : i64
cf.cond_br %315, ^bb54, ^bb55
^bb54:
%317 = arith.constant 0 : i32
%318 = arith.extsi %317 : i32 to i64
func.return %318 : i64
^bb55:
cf.br ^bb56
^bb56:
%319 = func.call @hslot(%arg0, %arg4, %arg6) : (i64, !llvm.ptr, !llvm.ptr) -> i64
%321 = llvm.getelementptr %arg6[%319] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%320 = llvm.load %321 : !llvm.ptr -> i8
%322 = arith.constant 1 : i32
%324 = arith.extsi %320 : i8 to i32
%323 = arith.cmpi eq, %324, %322 : i32
cf.cond_br %323, ^bb57, ^bb58
^bb57:
%326 = llvm.getelementptr %arg5[%319] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%325 = llvm.load %326 : !llvm.ptr -> i64
func.return %325 : i64
^bb58:
cf.br ^bb59
^bb59:
%327 = arith.constant 0 : i32
%328 = arith.extsi %327 : i32 to i64
%329 = llvm.mlir.constant(1 : i64) : i64
%330 = llvm.alloca %329 x i64 : (i64) -> !llvm.ptr
llvm.store %328, %330 : i64, !llvm.ptr
%331 = llvm.mlir.constant(1 : i64) : i64
%332 = llvm.alloca %331 x i64 : (i64) -> !llvm.ptr
llvm.store %arg0, %332 : i64, !llvm.ptr
cf.br ^bb60
^bb60:
%333 = llvm.load %330 : !llvm.ptr -> i64
%334 = arith.constant 1 : i32
%336 = arith.extsi %334 : i32 to i64
%335 = arith.addi %333, %336 : i64
%337 = llvm.load %332 : !llvm.ptr -> i64
%338 = arith.cmpi slt, %335, %337 : i64
cf.cond_br %338, ^bb61, ^bb62
^bb61:
%339 = llvm.load %330 : !llvm.ptr -> i64
%340 = llvm.load %332 : !llvm.ptr -> i64
%341 = arith.addi %339, %340 : i64
%342 = arith.constant 2 : i32
%344 = arith.extsi %342 : i32 to i64
%343 = arith.divsi %341, %344 : i64
%345 = func.call @G(%343, %arg1, %arg2, %arg3, %arg4, %arg5, %arg6) : (i64, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr) -> i128
%346 = arith.extsi %arg0 : i64 to i128
%347 = arith.extsi %343 : i64 to i128
%349 = arith.trunci %346 : i128 to i64
%350 = arith.trunci %347 : i128 to i64
%348 = arith.subi %349, %350 : i64
%352 = arith.trunci %345 : i128 to i64
%351 = arith.cmpi sgt, %352, %348 : i64
cf.cond_br %351, ^bb63, ^bb64
^bb63:
llvm.store %343, %332 : i64, !llvm.ptr
cf.br ^bb65
^bb64:
llvm.store %343, %330 : i64, !llvm.ptr
cf.br ^bb65
^bb65:
cf.br ^bb60
^bb62:
%353 = arith.constant 1 : i32
%354 = arith.trunci %353 : i32 to i8
%355 = llvm.getelementptr %arg6[%319] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %354, %355 : i8, !llvm.ptr
%356 = llvm.getelementptr %arg4[%319] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %arg0, %356 : i64, !llvm.ptr
%357 = llvm.load %330 : !llvm.ptr -> i64
%358 = llvm.getelementptr %arg5[%319] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %357, %358 : i64, !llvm.ptr
%359 = llvm.load %330 : !llvm.ptr -> i64
func.return %359 : i64
}
func.func @G(%arg0: i64, %arg1: !llvm.ptr, %arg2: !llvm.ptr, %arg3: !llvm.ptr, %arg4: !llvm.ptr, %arg5: !llvm.ptr, %arg6: !llvm.ptr) -> i128 {
%360 = arith.constant 0 : i32
%362 = arith.extsi %360 : i32 to i64
%361 = arith.cmpi eq, %arg0, %362 : i64
cf.cond_br %361, ^bb66, ^bb67
^bb66:
%363 = arith.constant 0 : i32
%364 = arith.extsi %363 : i32 to i128
func.return %364 : i128
^bb67:
cf.br ^bb68
^bb68:
%365 = func.call @hslot(%arg0, %arg1, %arg3) : (i64, !llvm.ptr, !llvm.ptr) -> i64
%367 = llvm.getelementptr %arg3[%365] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%366 = llvm.load %367 : !llvm.ptr -> i8
%368 = arith.constant 1 : i32
%370 = arith.extsi %366 : i8 to i32
%369 = arith.cmpi eq, %370, %368 : i32
cf.cond_br %369, ^bb69, ^bb70
^bb69:
%372 = llvm.getelementptr %arg2[%365] : (!llvm.ptr, i64) -> !llvm.ptr, i128
%371 = llvm.load %372 : !llvm.ptr -> i128
func.return %371 : i128
^bb70:
cf.br ^bb71
^bb71:
%373 = func.call @phi(%arg0, %arg1, %arg2, %arg3, %arg4, %arg5, %arg6) : (i64, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr) -> i64
%374 = func.call @G(%373, %arg1, %arg2, %arg3, %arg4, %arg5, %arg6) : (i64, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr) -> i128
%376 = arith.subi %arg0, %373 : i64
%375 = func.call @sum_floor_sqrt128(%376) : (i64) -> i128
%378 = arith.trunci %374 : i128 to i64
%379 = arith.trunci %375 : i128 to i64
%377 = arith.addi %378, %379 : i64
%380 = arith.extsi %377 : i64 to i128
%381 = arith.constant 1 : i32
%382 = arith.trunci %381 : i32 to i8
%383 = llvm.getelementptr %arg3[%365] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %382, %383 : i8, !llvm.ptr
%384 = llvm.getelementptr %arg1[%365] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %arg0, %384 : i64, !llvm.ptr
%385 = llvm.getelementptr %arg2[%365] : (!llvm.ptr, i64) -> !llvm.ptr, i128
llvm.store %380, %385 : i128, !llvm.ptr
func.return %380 : i128
}
func.func @main() -> i32 {
%387 = llvm.mlir.addressof @CAP : !llvm.ptr
%388 = llvm.load %387 : !llvm.ptr -> i64
%389 = arith.constant 8 : i32
%390 = arith.extsi %389 : i32 to i64
%386 = func.call @calloc(%388, %390) : (i64, i64) -> !llvm.ptr
%392 = llvm.mlir.addressof @CAP : !llvm.ptr
%393 = llvm.load %392 : !llvm.ptr -> i64
%394 = arith.constant 16 : i32
%395 = arith.extsi %394 : i32 to i64
%391 = func.call @calloc(%393, %395) : (i64, i64) -> !llvm.ptr
%397 = llvm.mlir.addressof @CAP : !llvm.ptr
%398 = llvm.load %397 : !llvm.ptr -> i64
%399 = arith.constant 1 : i32
%400 = arith.extsi %399 : i32 to i64
%396 = func.call @calloc(%398, %400) : (i64, i64) -> !llvm.ptr
%402 = llvm.mlir.addressof @CAP : !llvm.ptr
%403 = llvm.load %402 : !llvm.ptr -> i64
%404 = arith.constant 8 : i32
%405 = arith.extsi %404 : i32 to i64
%401 = func.call @calloc(%403, %405) : (i64, i64) -> !llvm.ptr
%407 = llvm.mlir.addressof @CAP : !llvm.ptr
%408 = llvm.load %407 : !llvm.ptr -> i64
%409 = arith.constant 8 : i32
%410 = arith.extsi %409 : i32 to i64
%406 = func.call @calloc(%408, %410) : (i64, i64) -> !llvm.ptr
%412 = llvm.mlir.addressof @CAP : !llvm.ptr
%413 = llvm.load %412 : !llvm.ptr -> i64
%414 = arith.constant 1 : i32
%415 = arith.extsi %414 : i32 to i64
%411 = func.call @calloc(%413, %415) : (i64, i64) -> !llvm.ptr
%416 = llvm.mlir.zero : !llvm.ptr
%417 = llvm.icmp "eq" %386, %416 : !llvm.ptr
%418 = scf.if %417 -> (i1) {
%419 = arith.constant true
scf.yield %419 : i1
} else {
%420 = llvm.mlir.zero : !llvm.ptr
%421 = llvm.icmp "eq" %391, %420 : !llvm.ptr
scf.yield %421 : i1
}
%422 = scf.if %418 -> (i1) {
%423 = arith.constant true
scf.yield %423 : i1
} else {
%424 = llvm.mlir.zero : !llvm.ptr
%425 = llvm.icmp "eq" %396, %424 : !llvm.ptr
scf.yield %425 : i1
}
%426 = scf.if %422 -> (i1) {
%427 = arith.constant true
scf.yield %427 : i1
} else {
%428 = llvm.mlir.zero : !llvm.ptr
%429 = llvm.icmp "eq" %401, %428 : !llvm.ptr
scf.yield %429 : i1
}
%430 = scf.if %426 -> (i1) {
%431 = arith.constant true
scf.yield %431 : i1
} else {
%432 = llvm.mlir.zero : !llvm.ptr
%433 = llvm.icmp "eq" %406, %432 : !llvm.ptr
scf.yield %433 : i1
}
%434 = scf.if %430 -> (i1) {
%435 = arith.constant true
scf.yield %435 : i1
} else {
%436 = llvm.mlir.zero : !llvm.ptr
%437 = llvm.icmp "eq" %411, %436 : !llvm.ptr
scf.yield %437 : i1
}
cf.cond_br %434, ^bb72, ^bb73
^bb72:
%438 = arith.constant 1 : i32
func.return %438 : i32
^bb73:
cf.br ^bb74
^bb74:
%439 = arith.constant 0 : i32
%440 = arith.extsi %439 : i32 to i64
%441 = llvm.mlir.constant(1 : i64) : i64
%442 = llvm.alloca %441 x i64 : (i64) -> !llvm.ptr
llvm.store %440, %442 : i64, !llvm.ptr
%443 = arith.constant 999999995705032704 : i32
%444 = arith.extsi %443 : i32 to i64
%445 = llvm.mlir.constant(1 : i64) : i64
%446 = llvm.alloca %445 x i64 : (i64) -> !llvm.ptr
llvm.store %444, %446 : i64, !llvm.ptr
cf.br ^bb75
^bb75:
%447 = llvm.load %446 : !llvm.ptr -> i64
%448 = arith.constant 0 : i32
%450 = arith.extsi %448 : i32 to i64
%449 = arith.cmpi sgt, %447, %450 : i64
cf.cond_br %449, ^bb76, ^bb77
^bb76:
%452 = llvm.load %446 : !llvm.ptr -> i64
%451 = func.call @phi(%452, %386, %391, %396, %401, %406, %411) : (i64, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr) -> i64
%453 = llvm.load %442 : !llvm.ptr -> i64
%455 = llvm.load %446 : !llvm.ptr -> i64
%456 = arith.subi %455, %451 : i64
%454 = func.call @sum_1_to_m_mod(%456) : (i64) -> i64
%457 = arith.addi %453, %454 : i64
%458 = llvm.mlir.addressof @MOD : !llvm.ptr
%459 = llvm.load %458 : !llvm.ptr -> i64
%460 = arith.remsi %457, %459 : i64
llvm.store %460, %442 : i64, !llvm.ptr
llvm.store %451, %446 : i64, !llvm.ptr
cf.br ^bb75
^bb77:
%461 = llvm.mlir.addressof @str_0 : !llvm.ptr
%462 = llvm.load %442 : !llvm.ptr -> i64
%463 = llvm.call @printf(%461, %462) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
func.call @free(%386) : (!llvm.ptr) -> ()
func.call @free(%391) : (!llvm.ptr) -> ()
func.call @free(%396) : (!llvm.ptr) -> ()
func.call @free(%401) : (!llvm.ptr) -> ()
func.call @free(%406) : (!llvm.ptr) -> ()
func.call @free(%411) : (!llvm.ptr) -> ()
%470 = arith.constant 0 : i32
func.return %470 : i32
}
}