← All problems
Problem 543
Prime-Sum Numbers: sum S(F_r) for r=3..44 using Lehmer prime counting.
View problem on Project Euler
Performance comparison
Metric Our solution Best known
Time complexity O(n)?
Space complexity O(n^2)?
Approach Flow solution Not curated
Verdict Unknown
Flow source
# Project Euler 543
# Prime-Sum Numbers: sum S(F_r) for r=3..44 using Lehmer prime counting.
import euler.nt { isqrt }
extern {
function calloc(n: i64, size: i64) -> ptr<void>
function free(p: ptr<void>) -> void
function malloc(n: i64) -> ptr<void>
}
const CACHE_SIZE: i64 = 1048576
struct CacheEntry {
key: i64
val: i64
}
let mut g_primes: ptr<i64> = null as ptr<i64>
let mut g_pi_arr: ptr<i64> = null as ptr<i64>
let mut g_limit: i64 = 0
let mut g_phi_cache: ptr<CacheEntry> = null as ptr<CacheEntry>
let mut g_pi_cache: ptr<CacheEntry> = null as ptr<CacheEntry>
function cache_get(c: ptr<CacheEntry>, key: i64) -> i64 {
let prod: i128 = (key as i128) * (2654435761 as i128)
let mut h: i64 = (prod & ((CACHE_SIZE - 1) as i128)) as i64
while c[h].key != 0 {
if c[h].key == key { return c[h].val }
h = (h + 1) & (CACHE_SIZE - 1)
}
return -1
}
function cache_set(c: ptr<CacheEntry>, key: i64, val: i64) -> void {
let prod: i128 = (key as i128) * (2654435761 as i128)
let mut h: i64 = (prod & ((CACHE_SIZE - 1) as i128)) as i64
while c[h].key != 0 {
if c[h].key == key { c[h].val = val; return }
h = (h + 1) & (CACHE_SIZE - 1)
}
c[h].key = key
c[h].val = val
}
function icbrt(n: i64) -> i64 {
if n <= 0 { return 0 }
let mut lo: i64 = 1
let mut hi: i64 = 2
while hi * hi * hi <= n {
hi = hi * 2
}
while lo < hi {
let mid: i64 = (lo + hi + 1) / 2
if mid * mid * mid <= n {
lo = mid
} else {
hi = mid - 1
}
}
return lo
}
function phi(x: i64, a: i64) -> i64 {
if a == 0 { return x }
if a == 1 { return x - x / 2 }
let key: i64 = x * 100 + a
let cached: i64 = cache_get(g_phi_cache, key)
if cached >= 0 { return cached }
let r: i64 = phi(x, a - 1) - phi(x / g_primes[a - 1], a - 1)
cache_set(g_phi_cache, key, r)
return r
}
function pi_lehmer(x: i64) -> i64 {
if x <= g_limit { return g_pi_arr[x] }
let cached: i64 = cache_get(g_pi_cache, x)
if cached >= 0 { return cached }
let a: i64 = x |> isqrt |> isqrt |> pi_lehmer
let b: i64 = x |> isqrt |> pi_lehmer
let c: i64 = x |> icbrt |> pi_lehmer
let mut result: i64 = phi(x, a) + ((b + a - 2) * (b - a + 1)) / 2
let mut i: i64 = a + 1
while i <= b {
let w: i64 = x / g_primes[i - 1]
result = result - pi_lehmer(w)
if i <= c {
let bi: i64 = pi_lehmer(isqrt(w))
let mut j: i64 = i
while j <= bi {
result = result - (pi_lehmer(w / g_primes[j - 1]) - j + 1)
j = j + 1
}
}
i = i + 1
}
cache_set(g_pi_cache, x, result)
return result
}
function primePi(x: i64) -> i64 {
if x < 2 { return 0 }
g_limit = isqrt(x) + 10
let is_comp: ptr<i8> = calloc(g_limit + 1, 1)
let mut i: i64 = 2
while i * i <= g_limit {
if is_comp[i] == 0 {
let mut j: i64 = i * i
while j <= g_limit {
is_comp[j] = 1
j = j + i
}
}
i = i + 1
}
let mut np: i64 = 0
i = 2
while i <= g_limit {
if is_comp[i] == 0 { np = np + 1 }
i = i + 1
}
g_primes = malloc(np * 8)
let mut idx: i64 = 0
i = 2
while i <= g_limit {
if is_comp[i] == 0 {
g_primes[idx] = i
idx = idx + 1
}
i = i + 1
}
free(is_comp)
g_pi_arr = calloc(g_limit + 1, 8)
let mut cnt: i64 = 0
let mut pidx: i64 = 0
i = 0
while i <= g_limit {
while pidx < np && g_primes[pidx] <= i {
cnt = cnt + 1
pidx = pidx + 1
}
g_pi_arr[i] = cnt
i = i + 1
}
g_phi_cache = calloc(CACHE_SIZE, 16)
g_pi_cache = calloc(CACHE_SIZE, 16)
let result: i64 = pi_lehmer(x)
free(g_primes)
free(g_pi_arr)
free(g_phi_cache)
free(g_pi_cache)
return result
}
function fibonacci(n: i64) -> i64 {
let mut a: i64 = 0
let mut b: i64 = 1
let mut i: i64 = 0
while i < n {
let c: i64 = a + b
a = b
b = c
i = i + 1
}
return a
}
function S(n: i64) -> i64 {
let mut res: i64 = 0
res = res + primePi(n)
if n >= 4 {
res = res + n / 2 - 1
res = res + primePi(n - 2) - 1
}
if n >= 6 {
let half: i64 = n / 2
res = res + (half - 2) * (n + 1) - (half + 1) * half + 6
}
return res
}
function main() -> i32 {
let mut total: i64 = 0
let mut k: i64 = 3
while k <= 44 {
let fib: i64 = fibonacci(k)
total = total + S(fib)
k = k + 1
}
printf("%lld\n", total)
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; }
typedef struct CacheEntry CacheEntry;
struct CacheEntry {
int64_t key;
int64_t val;
};
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 cache_get_ptr_CacheEntry_i64(CacheEntry* c, int64_t key);
void cache_set_ptr_CacheEntry_i64_i64(CacheEntry* c, int64_t key, int64_t val);
int64_t icbrt_i64(int64_t n);
int64_t phi_i64_i64(int64_t x, int64_t a);
int64_t pi_lehmer_i64(int64_t x);
int64_t primePi_i64(int64_t x);
int64_t fibonacci_i64(int64_t n);
int64_t S_i64(int64_t n);
int32_t main(void);
static const int64_t CACHE_SIZE = 1048576;
/* Module statics */
static int64_t* g_primes = ((int64_t*)(NULL));
static int64_t* g_pi_arr = ((int64_t*)(NULL));
static int64_t g_limit = 0;
static CacheEntry* g_phi_cache = ((CacheEntry*)(NULL));
static CacheEntry* g_pi_cache = ((CacheEntry*)(NULL));
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 cache_get_ptr_CacheEntry_i64(CacheEntry* c, int64_t key) {
__int128 prod = (((__int128)(key)) * ((__int128)(2654435761)));
int64_t h = ((int64_t)((prod & ((__int128)((CACHE_SIZE - 1))))));
while (c[h].key != 0) {
if (c[h].key == key) {
return c[h].val;
}
h = ((h + 1) & (CACHE_SIZE - 1));
}
return (-1);
}
void cache_set_ptr_CacheEntry_i64_i64(CacheEntry* c, int64_t key, int64_t val) {
__int128 prod = (((__int128)(key)) * ((__int128)(2654435761)));
int64_t h = ((int64_t)((prod & ((__int128)((CACHE_SIZE - 1))))));
while (c[h].key != 0) {
if (c[h].key == key) {
c[h].val = val;
return;
}
h = ((h + 1) & (CACHE_SIZE - 1));
}
c[h].key = key;
c[h].val = val;
}
int64_t icbrt_i64(int64_t n) {
if (n <= 0) {
return 0;
}
int64_t lo = 1;
int64_t hi = 2;
while (((hi * hi) * hi) <= n) {
hi = (hi * 2);
}
while (lo < hi) {
int64_t mid = FLOW_CHECKED_DIV((((lo + hi) + 1)), (2));
if (((mid * mid) * mid) <= n) {
lo = mid;
} else {
hi = (mid - 1);
}
}
return lo;
}
int64_t phi_i64_i64(int64_t x, int64_t a) {
if (a == 0) {
return x;
}
if (a == 1) {
return (x - FLOW_CHECKED_DIV((x), (2)));
}
int64_t key = ((x * 100) + a);
int64_t cached = cache_get_ptr_CacheEntry_i64(g_phi_cache, key);
if (cached >= 0) {
return cached;
}
int64_t r = (phi_i64_i64(x, (a - 1)) - phi_i64_i64(FLOW_CHECKED_DIV((x), (g_primes[(a - 1)])), (a - 1)));
cache_set_ptr_CacheEntry_i64_i64(g_phi_cache, key, r);
return r;
}
int64_t pi_lehmer_i64(int64_t x) {
if (x <= g_limit) {
return g_pi_arr[x];
}
int64_t cached = cache_get_ptr_CacheEntry_i64(g_pi_cache, x);
if (cached >= 0) {
return cached;
}
int64_t a = pi_lehmer_i64(isqrt_i64(isqrt_i64(x)));
int64_t b = pi_lehmer_i64(isqrt_i64(x));
int64_t c = pi_lehmer_i64(icbrt_i64(x));
int64_t result = (phi_i64_i64(x, a) + FLOW_CHECKED_DIV(((((b + a) - 2) * ((b - a) + 1))), (2)));
int64_t i = (a + 1);
while (i <= b) {
int64_t w = FLOW_CHECKED_DIV((x), (g_primes[(i - 1)]));
result = (result - pi_lehmer_i64(w));
if (i <= c) {
int64_t bi = pi_lehmer_i64(isqrt_i64(w));
int64_t j = i;
while (j <= bi) {
result = (result - ((pi_lehmer_i64(FLOW_CHECKED_DIV((w), (g_primes[(j - 1)]))) - j) + 1));
j = (j + 1);
}
}
i = (i + 1);
}
cache_set_ptr_CacheEntry_i64_i64(g_pi_cache, x, result);
return result;
}
int64_t primePi_i64(int64_t x) {
if (x < 2) {
return 0;
}
g_limit = (isqrt_i64(x) + 10);
int8_t* is_comp = (int8_t*)(calloc((g_limit + 1), 1));
int64_t i = 2;
while ((i * i) <= g_limit) {
if (is_comp[i] == 0) {
int64_t j = (i * i);
while (j <= g_limit) {
is_comp[j] = 1;
j = (j + i);
}
}
i = (i + 1);
}
int64_t np = 0;
i = 2;
while (i <= g_limit) {
if (is_comp[i] == 0) {
np = (np + 1);
}
i = (i + 1);
}
g_primes = malloc((np * 8));
int64_t idx = 0;
i = 2;
while (i <= g_limit) {
if (is_comp[i] == 0) {
g_primes[idx] = i;
idx = (idx + 1);
}
i = (i + 1);
}
free(is_comp);
g_pi_arr = calloc((g_limit + 1), 8);
int64_t cnt = 0;
int64_t pidx = 0;
i = 0;
while (i <= g_limit) {
while ((pidx < np && g_primes[pidx] <= i)) {
cnt = (cnt + 1);
pidx = (pidx + 1);
}
g_pi_arr[i] = cnt;
i = (i + 1);
}
g_phi_cache = calloc(CACHE_SIZE, 16);
g_pi_cache = calloc(CACHE_SIZE, 16);
int64_t result = pi_lehmer_i64(x);
free(g_primes);
free(g_pi_arr);
free(g_phi_cache);
free(g_pi_cache);
return result;
}
int64_t fibonacci_i64(int64_t n) {
int64_t a = 0;
int64_t b = 1;
int64_t i = 0;
while (i < n) {
int64_t c = (a + b);
a = b;
b = c;
i = (i + 1);
}
return a;
}
int64_t S_i64(int64_t n) {
int64_t res = 0;
res = (res + primePi_i64(n));
if (n >= 4) {
res = ((res + FLOW_CHECKED_DIV((n), (2))) - 1);
res = ((res + primePi_i64((n - 2))) - 1);
}
if (n >= 6) {
int64_t half = FLOW_CHECKED_DIV((n), (2));
res = (((res + ((half - 2) * (n + 1))) - ((half + 1) * half)) + 6);
}
return res;
}
int32_t main(void) {
int64_t total = 0;
int64_t k = 3;
while (k <= 44) {
int64_t fib = fibonacci_i64(k);
total = (total + S_i64(fib));
k = (k + 1);
}
printf("%lld\n", total);
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) -> ()
func.func private @malloc(i64) -> !llvm.ptr
// Constant: CACHE_SIZE
llvm.mlir.global internal constant @CACHE_SIZE(1048576 : i64) : i64
// Struct: CacheEntry
// Fields:
// key: i64
// val: i64
// Module static: g_primes
llvm.mlir.global internal @g_primes() {addr_space = 0 : i32} : !llvm.ptr {
%175 = llvm.mlir.zero : !llvm.ptr
llvm.return %175 : !llvm.ptr
}
// Module static: g_pi_arr
llvm.mlir.global internal @g_pi_arr() {addr_space = 0 : i32} : !llvm.ptr {
%176 = llvm.mlir.zero : !llvm.ptr
llvm.return %176 : !llvm.ptr
}
// Module static: g_limit
llvm.mlir.global internal @g_limit(0 : i64) : i64
// Module static: g_phi_cache
llvm.mlir.global internal @g_phi_cache() {addr_space = 0 : i32} : !llvm.ptr {
%177 = llvm.mlir.zero : !llvm.ptr
llvm.return %177 : !llvm.ptr
}
// Module static: g_pi_cache
llvm.mlir.global internal @g_pi_cache() {addr_space = 0 : i32} : !llvm.ptr {
%178 = llvm.mlir.zero : !llvm.ptr
llvm.return %178 : !llvm.ptr
}
func.func @cache_get(%arg0: !llvm.ptr, %arg1: i64) -> i64 {
%179 = arith.extsi %arg1 : i64 to i128
%180 = arith.constant -1640531535 : i32
%181 = arith.extsi %180 : i32 to i128
%183 = arith.trunci %179 : i128 to i64
%184 = arith.trunci %181 : i128 to i64
%182 = arith.muli %183, %184 : i64
%185 = arith.extsi %182 : i64 to i128
%186 = llvm.mlir.addressof @CACHE_SIZE : !llvm.ptr
%187 = llvm.load %186 : !llvm.ptr -> i64
%188 = arith.constant 1 : i32
%190 = arith.extsi %188 : i32 to i64
%189 = arith.subi %187, %190 : i64
%191 = arith.extsi %189 : i64 to i128
%193 = arith.trunci %185 : i128 to i64
%194 = arith.trunci %191 : i128 to i64
%192 = arith.andi %193, %194 : i64
%195 = llvm.mlir.constant(1 : i64) : i64
%196 = llvm.alloca %195 x i64 : (i64) -> !llvm.ptr
llvm.store %192, %196 : i64, !llvm.ptr
cf.br ^bb42
^bb42:
%198 = llvm.load %196 : !llvm.ptr -> i64
%199 = llvm.getelementptr %arg0[%198] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.struct<(i64, i64)>
%197 = llvm.load %199 : !llvm.ptr -> !llvm.struct<(i64, i64)>
%200 = llvm.load %196 : !llvm.ptr -> i64
%201 = llvm.getelementptr %arg0[%200] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.struct<(i64, i64)>
%202 = llvm.getelementptr %201[0, 0] : (!llvm.ptr) -> !llvm.ptr, !llvm.struct<(i64, i64)>
%203 = llvm.load %202 : !llvm.ptr -> i64
%204 = arith.constant 0 : i32
%206 = arith.extsi %204 : i32 to i64
%205 = arith.cmpi ne, %203, %206 : i64
cf.cond_br %205, ^bb43, ^bb44
^bb43:
%208 = llvm.load %196 : !llvm.ptr -> i64
%209 = llvm.getelementptr %arg0[%208] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.struct<(i64, i64)>
%207 = llvm.load %209 : !llvm.ptr -> !llvm.struct<(i64, i64)>
%210 = llvm.load %196 : !llvm.ptr -> i64
%211 = llvm.getelementptr %arg0[%210] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.struct<(i64, i64)>
%212 = llvm.getelementptr %211[0, 0] : (!llvm.ptr) -> !llvm.ptr, !llvm.struct<(i64, i64)>
%213 = llvm.load %212 : !llvm.ptr -> i64
%214 = arith.cmpi eq, %213, %arg1 : i64
cf.cond_br %214, ^bb45, ^bb46
^bb45:
%216 = llvm.load %196 : !llvm.ptr -> i64
%217 = llvm.getelementptr %arg0[%216] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.struct<(i64, i64)>
%215 = llvm.load %217 : !llvm.ptr -> !llvm.struct<(i64, i64)>
%218 = llvm.load %196 : !llvm.ptr -> i64
%219 = llvm.getelementptr %arg0[%218] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.struct<(i64, i64)>
%220 = llvm.getelementptr %219[0, 1] : (!llvm.ptr) -> !llvm.ptr, !llvm.struct<(i64, i64)>
%221 = llvm.load %220 : !llvm.ptr -> i64
func.return %221 : i64
^bb46:
cf.br ^bb47
^bb47:
%222 = llvm.load %196 : !llvm.ptr -> i64
%223 = arith.constant 1 : i32
%225 = arith.extsi %223 : i32 to i64
%224 = arith.addi %222, %225 : i64
%226 = llvm.mlir.addressof @CACHE_SIZE : !llvm.ptr
%227 = llvm.load %226 : !llvm.ptr -> i64
%228 = arith.constant 1 : i32
%230 = arith.extsi %228 : i32 to i64
%229 = arith.subi %227, %230 : i64
%231 = arith.andi %224, %229 : i64
llvm.store %231, %196 : i64, !llvm.ptr
cf.br ^bb42
^bb44:
%232 = arith.constant 1 : i32
%234 = arith.constant 0 : i32
%233 = arith.subi %234, %232 : i32
%235 = arith.extsi %233 : i32 to i64
func.return %235 : i64
}
func.func @cache_set(%arg0: !llvm.ptr, %arg1: i64, %arg2: i64) -> () {
%236 = arith.extsi %arg1 : i64 to i128
%237 = arith.constant -1640531535 : i32
%238 = arith.extsi %237 : i32 to i128
%240 = arith.trunci %236 : i128 to i64
%241 = arith.trunci %238 : i128 to i64
%239 = arith.muli %240, %241 : i64
%242 = arith.extsi %239 : i64 to i128
%243 = llvm.mlir.addressof @CACHE_SIZE : !llvm.ptr
%244 = llvm.load %243 : !llvm.ptr -> i64
%245 = arith.constant 1 : i32
%247 = arith.extsi %245 : i32 to i64
%246 = arith.subi %244, %247 : i64
%248 = arith.extsi %246 : i64 to i128
%250 = arith.trunci %242 : i128 to i64
%251 = arith.trunci %248 : i128 to i64
%249 = arith.andi %250, %251 : i64
%252 = llvm.mlir.constant(1 : i64) : i64
%253 = llvm.alloca %252 x i64 : (i64) -> !llvm.ptr
llvm.store %249, %253 : i64, !llvm.ptr
cf.br ^bb48
^bb48:
%255 = llvm.load %253 : !llvm.ptr -> i64
%256 = llvm.getelementptr %arg0[%255] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.struct<(i64, i64)>
%254 = llvm.load %256 : !llvm.ptr -> !llvm.struct<(i64, i64)>
%257 = llvm.load %253 : !llvm.ptr -> i64
%258 = llvm.getelementptr %arg0[%257] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.struct<(i64, i64)>
%259 = llvm.getelementptr %258[0, 0] : (!llvm.ptr) -> !llvm.ptr, !llvm.struct<(i64, i64)>
%260 = llvm.load %259 : !llvm.ptr -> i64
%261 = arith.constant 0 : i32
%263 = arith.extsi %261 : i32 to i64
%262 = arith.cmpi ne, %260, %263 : i64
cf.cond_br %262, ^bb49, ^bb50
^bb49:
%265 = llvm.load %253 : !llvm.ptr -> i64
%266 = llvm.getelementptr %arg0[%265] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.struct<(i64, i64)>
%264 = llvm.load %266 : !llvm.ptr -> !llvm.struct<(i64, i64)>
%267 = llvm.load %253 : !llvm.ptr -> i64
%268 = llvm.getelementptr %arg0[%267] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.struct<(i64, i64)>
%269 = llvm.getelementptr %268[0, 0] : (!llvm.ptr) -> !llvm.ptr, !llvm.struct<(i64, i64)>
%270 = llvm.load %269 : !llvm.ptr -> i64
%271 = arith.cmpi eq, %270, %arg1 : i64
cf.cond_br %271, ^bb51, ^bb52
^bb51:
%272 = llvm.load %253 : !llvm.ptr -> i64
%273 = llvm.getelementptr %arg0[%272] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.struct<(i64, i64)>
%274 = llvm.getelementptr %273[0, 1] : (!llvm.ptr) -> !llvm.ptr, !llvm.struct<(i64, i64)>
llvm.store %arg2, %274 : i64, !llvm.ptr
func.return
^bb52:
cf.br ^bb53
^bb53:
%275 = llvm.load %253 : !llvm.ptr -> i64
%276 = arith.constant 1 : i32
%278 = arith.extsi %276 : i32 to i64
%277 = arith.addi %275, %278 : i64
%279 = llvm.mlir.addressof @CACHE_SIZE : !llvm.ptr
%280 = llvm.load %279 : !llvm.ptr -> i64
%281 = arith.constant 1 : i32
%283 = arith.extsi %281 : i32 to i64
%282 = arith.subi %280, %283 : i64
%284 = arith.andi %277, %282 : i64
llvm.store %284, %253 : i64, !llvm.ptr
cf.br ^bb48
^bb50:
%285 = llvm.load %253 : !llvm.ptr -> i64
%286 = llvm.getelementptr %arg0[%285] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.struct<(i64, i64)>
%287 = llvm.getelementptr %286[0, 0] : (!llvm.ptr) -> !llvm.ptr, !llvm.struct<(i64, i64)>
llvm.store %arg1, %287 : i64, !llvm.ptr
%288 = llvm.load %253 : !llvm.ptr -> i64
%289 = llvm.getelementptr %arg0[%288] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.struct<(i64, i64)>
%290 = llvm.getelementptr %289[0, 1] : (!llvm.ptr) -> !llvm.ptr, !llvm.struct<(i64, i64)>
llvm.store %arg2, %290 : i64, !llvm.ptr
func.return
}
func.func @icbrt(%arg0: i64) -> i64 {
%291 = arith.constant 0 : i32
%293 = arith.extsi %291 : i32 to i64
%292 = arith.cmpi sle, %arg0, %293 : i64
cf.cond_br %292, ^bb54, ^bb55
^bb54:
%294 = arith.constant 0 : i32
%295 = arith.extsi %294 : i32 to i64
func.return %295 : i64
^bb55:
cf.br ^bb56
^bb56:
%296 = arith.constant 1 : i32
%297 = arith.extsi %296 : i32 to i64
%298 = llvm.mlir.constant(1 : i64) : i64
%299 = llvm.alloca %298 x i64 : (i64) -> !llvm.ptr
llvm.store %297, %299 : i64, !llvm.ptr
%300 = arith.constant 2 : i32
%301 = arith.extsi %300 : i32 to i64
%302 = llvm.mlir.constant(1 : i64) : i64
%303 = llvm.alloca %302 x i64 : (i64) -> !llvm.ptr
llvm.store %301, %303 : i64, !llvm.ptr
cf.br ^bb57
^bb57:
%304 = llvm.load %303 : !llvm.ptr -> i64
%305 = llvm.load %303 : !llvm.ptr -> i64
%306 = arith.muli %304, %305 : i64
%307 = llvm.load %303 : !llvm.ptr -> i64
%308 = arith.muli %306, %307 : i64
%309 = arith.cmpi sle, %308, %arg0 : i64
cf.cond_br %309, ^bb58, ^bb59
^bb58:
%310 = llvm.load %303 : !llvm.ptr -> i64
%311 = arith.constant 2 : i32
%313 = arith.extsi %311 : i32 to i64
%312 = arith.muli %310, %313 : i64
llvm.store %312, %303 : i64, !llvm.ptr
cf.br ^bb57
^bb59:
cf.br ^bb60
^bb60:
%314 = llvm.load %299 : !llvm.ptr -> i64
%315 = llvm.load %303 : !llvm.ptr -> i64
%316 = arith.cmpi slt, %314, %315 : i64
cf.cond_br %316, ^bb61, ^bb62
^bb61:
%317 = llvm.load %299 : !llvm.ptr -> i64
%318 = llvm.load %303 : !llvm.ptr -> i64
%319 = arith.addi %317, %318 : i64
%320 = arith.constant 1 : i32
%322 = arith.extsi %320 : i32 to i64
%321 = arith.addi %319, %322 : i64
%323 = arith.constant 2 : i32
%325 = arith.extsi %323 : i32 to i64
%324 = arith.divsi %321, %325 : i64
%326 = arith.muli %324, %324 : i64
%327 = arith.muli %326, %324 : i64
%328 = arith.cmpi sle, %327, %arg0 : i64
cf.cond_br %328, ^bb63, ^bb64
^bb63:
llvm.store %324, %299 : i64, !llvm.ptr
cf.br ^bb65
^bb64:
%329 = arith.constant 1 : i32
%331 = arith.extsi %329 : i32 to i64
%330 = arith.subi %324, %331 : i64
llvm.store %330, %303 : i64, !llvm.ptr
cf.br ^bb65
^bb65:
cf.br ^bb60
^bb62:
%332 = llvm.load %299 : !llvm.ptr -> i64
func.return %332 : i64
}
func.func @phi(%arg0: i64, %arg1: i64) -> i64 {
%333 = arith.constant 0 : i32
%335 = arith.extsi %333 : i32 to i64
%334 = arith.cmpi eq, %arg1, %335 : i64
cf.cond_br %334, ^bb66, ^bb67
^bb66:
func.return %arg0 : i64
^bb67:
cf.br ^bb68
^bb68:
%336 = arith.constant 1 : i32
%338 = arith.extsi %336 : i32 to i64
%337 = arith.cmpi eq, %arg1, %338 : i64
cf.cond_br %337, ^bb69, ^bb70
^bb69:
%339 = arith.constant 2 : i32
%341 = arith.extsi %339 : i32 to i64
%340 = arith.divsi %arg0, %341 : i64
%342 = arith.subi %arg0, %340 : i64
func.return %342 : i64
^bb70:
cf.br ^bb71
^bb71:
%343 = arith.constant 100 : i32
%345 = arith.extsi %343 : i32 to i64
%344 = arith.muli %arg0, %345 : i64
%346 = arith.addi %344, %arg1 : i64
%348 = llvm.mlir.addressof @g_phi_cache : !llvm.ptr
%349 = llvm.load %348 : !llvm.ptr -> !llvm.ptr
%347 = func.call @cache_get(%349, %346) : (!llvm.ptr, i64) -> i64
%350 = arith.constant 0 : i32
%352 = arith.extsi %350 : i32 to i64
%351 = arith.cmpi sge, %347, %352 : i64
cf.cond_br %351, ^bb72, ^bb73
^bb72:
func.return %347 : i64
^bb73:
cf.br ^bb74
^bb74:
%354 = arith.constant 1 : i32
%356 = arith.extsi %354 : i32 to i64
%355 = arith.subi %arg1, %356 : i64
%353 = func.call @phi(%arg0, %355) : (i64, i64) -> i64
%359 = llvm.mlir.addressof @g_primes : !llvm.ptr
%360 = llvm.load %359 : !llvm.ptr -> !llvm.ptr
%361 = arith.constant 1 : i32
%363 = arith.extsi %361 : i32 to i64
%362 = arith.subi %arg1, %363 : i64
%364 = llvm.getelementptr %360[%362] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%358 = llvm.load %364 : !llvm.ptr -> i64
%365 = arith.divsi %arg0, %358 : i64
%366 = arith.constant 1 : i32
%368 = arith.extsi %366 : i32 to i64
%367 = arith.subi %arg1, %368 : i64
%357 = func.call @phi(%365, %367) : (i64, i64) -> i64
%369 = arith.subi %353, %357 : i64
%371 = llvm.mlir.addressof @g_phi_cache : !llvm.ptr
%372 = llvm.load %371 : !llvm.ptr -> !llvm.ptr
func.call @cache_set(%372, %346, %369) : (!llvm.ptr, i64, i64) -> ()
func.return %369 : i64
}
func.func @pi_lehmer(%arg0: i64) -> i64 {
%373 = llvm.mlir.addressof @g_limit : !llvm.ptr
%374 = llvm.load %373 : !llvm.ptr -> i64
%375 = arith.cmpi sle, %arg0, %374 : i64
cf.cond_br %375, ^bb75, ^bb76
^bb75:
%377 = llvm.mlir.addressof @g_pi_arr : !llvm.ptr
%378 = llvm.load %377 : !llvm.ptr -> !llvm.ptr
%379 = llvm.getelementptr %378[%arg0] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%376 = llvm.load %379 : !llvm.ptr -> i64
func.return %376 : i64
^bb76:
cf.br ^bb77
^bb77:
%381 = llvm.mlir.addressof @g_pi_cache : !llvm.ptr
%382 = llvm.load %381 : !llvm.ptr -> !llvm.ptr
%380 = func.call @cache_get(%382, %arg0) : (!llvm.ptr, i64) -> i64
%383 = arith.constant 0 : i32
%385 = arith.extsi %383 : i32 to i64
%384 = arith.cmpi sge, %380, %385 : i64
cf.cond_br %384, ^bb78, ^bb79
^bb78:
func.return %380 : i64
^bb79:
cf.br ^bb80
^bb80:
%388 = func.call @isqrt(%arg0) : (i64) -> i64
%387 = func.call @isqrt(%388) : (i64) -> i64
%386 = func.call @pi_lehmer(%387) : (i64) -> i64
%390 = func.call @isqrt(%arg0) : (i64) -> i64
%389 = func.call @pi_lehmer(%390) : (i64) -> i64
%392 = func.call @icbrt(%arg0) : (i64) -> i64
%391 = func.call @pi_lehmer(%392) : (i64) -> i64
%393 = func.call @phi(%arg0, %386) : (i64, i64) -> i64
%394 = arith.addi %389, %386 : i64
%395 = arith.constant 2 : i32
%397 = arith.extsi %395 : i32 to i64
%396 = arith.subi %394, %397 : i64
%398 = arith.subi %389, %386 : i64
%399 = arith.constant 1 : i32
%401 = arith.extsi %399 : i32 to i64
%400 = arith.addi %398, %401 : i64
%402 = arith.muli %396, %400 : i64
%403 = arith.constant 2 : i32
%405 = arith.extsi %403 : i32 to i64
%404 = arith.divsi %402, %405 : i64
%406 = arith.addi %393, %404 : i64
%407 = llvm.mlir.constant(1 : i64) : i64
%408 = llvm.alloca %407 x i64 : (i64) -> !llvm.ptr
llvm.store %406, %408 : i64, !llvm.ptr
%409 = arith.constant 1 : i32
%411 = arith.extsi %409 : i32 to i64
%410 = arith.addi %386, %411 : i64
%412 = llvm.mlir.constant(1 : i64) : i64
%413 = llvm.alloca %412 x i64 : (i64) -> !llvm.ptr
llvm.store %410, %413 : i64, !llvm.ptr
cf.br ^bb81
^bb81:
%414 = llvm.load %413 : !llvm.ptr -> i64
%415 = arith.cmpi sle, %414, %389 : i64
cf.cond_br %415, ^bb82, ^bb83
^bb82:
%417 = llvm.mlir.addressof @g_primes : !llvm.ptr
%418 = llvm.load %417 : !llvm.ptr -> !llvm.ptr
%419 = llvm.load %413 : !llvm.ptr -> i64
%420 = arith.constant 1 : i32
%422 = arith.extsi %420 : i32 to i64
%421 = arith.subi %419, %422 : i64
%423 = llvm.getelementptr %418[%421] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%416 = llvm.load %423 : !llvm.ptr -> i64
%424 = arith.divsi %arg0, %416 : i64
%425 = llvm.load %408 : !llvm.ptr -> i64
%426 = func.call @pi_lehmer(%424) : (i64) -> i64
%427 = arith.subi %425, %426 : i64
llvm.store %427, %408 : i64, !llvm.ptr
%428 = llvm.load %413 : !llvm.ptr -> i64
%429 = arith.cmpi sle, %428, %391 : i64
cf.cond_br %429, ^bb84, ^bb85
^bb84:
%431 = func.call @isqrt(%424) : (i64) -> i64
%430 = func.call @pi_lehmer(%431) : (i64) -> i64
%432 = llvm.load %413 : !llvm.ptr -> i64
%433 = llvm.mlir.constant(1 : i64) : i64
%434 = llvm.alloca %433 x i64 : (i64) -> !llvm.ptr
llvm.store %432, %434 : i64, !llvm.ptr
cf.br ^bb87
^bb87:
%435 = llvm.load %434 : !llvm.ptr -> i64
%436 = arith.cmpi sle, %435, %430 : i64
cf.cond_br %436, ^bb88, ^bb89
^bb88:
%437 = llvm.load %408 : !llvm.ptr -> i64
%440 = llvm.mlir.addressof @g_primes : !llvm.ptr
%441 = llvm.load %440 : !llvm.ptr -> !llvm.ptr
%442 = llvm.load %434 : !llvm.ptr -> i64
%443 = arith.constant 1 : i32
%445 = arith.extsi %443 : i32 to i64
%444 = arith.subi %442, %445 : i64
%446 = llvm.getelementptr %441[%444] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%439 = llvm.load %446 : !llvm.ptr -> i64
%447 = arith.divsi %424, %439 : i64
%438 = func.call @pi_lehmer(%447) : (i64) -> i64
%448 = llvm.load %434 : !llvm.ptr -> i64
%449 = arith.subi %438, %448 : i64
%450 = arith.constant 1 : i32
%452 = arith.extsi %450 : i32 to i64
%451 = arith.addi %449, %452 : i64
%453 = arith.subi %437, %451 : i64
llvm.store %453, %408 : i64, !llvm.ptr
%454 = llvm.load %434 : !llvm.ptr -> i64
%455 = arith.constant 1 : i32
%457 = arith.extsi %455 : i32 to i64
%456 = arith.addi %454, %457 : i64
llvm.store %456, %434 : i64, !llvm.ptr
cf.br ^bb87
^bb89:
cf.br ^bb86
^bb85:
cf.br ^bb86
^bb86:
%458 = llvm.load %413 : !llvm.ptr -> i64
%459 = arith.constant 1 : i32
%461 = arith.extsi %459 : i32 to i64
%460 = arith.addi %458, %461 : i64
llvm.store %460, %413 : i64, !llvm.ptr
cf.br ^bb81
^bb83:
%463 = llvm.mlir.addressof @g_pi_cache : !llvm.ptr
%464 = llvm.load %463 : !llvm.ptr -> !llvm.ptr
%465 = llvm.load %408 : !llvm.ptr -> i64
func.call @cache_set(%464, %arg0, %465) : (!llvm.ptr, i64, i64) -> ()
%466 = llvm.load %408 : !llvm.ptr -> i64
func.return %466 : i64
}
func.func @primePi(%arg0: i64) -> i64 {
%467 = arith.constant 2 : i32
%469 = arith.extsi %467 : i32 to i64
%468 = arith.cmpi slt, %arg0, %469 : i64
cf.cond_br %468, ^bb90, ^bb91
^bb90:
%470 = arith.constant 0 : i32
%471 = arith.extsi %470 : i32 to i64
func.return %471 : i64
^bb91:
cf.br ^bb92
^bb92:
%472 = func.call @isqrt(%arg0) : (i64) -> i64
%473 = arith.constant 10 : i32
%475 = arith.extsi %473 : i32 to i64
%474 = arith.addi %472, %475 : i64
%476 = llvm.mlir.addressof @g_limit : !llvm.ptr
llvm.store %474, %476 : i64, !llvm.ptr
%478 = llvm.mlir.addressof @g_limit : !llvm.ptr
%479 = llvm.load %478 : !llvm.ptr -> i64
%480 = arith.constant 1 : i32
%482 = arith.extsi %480 : i32 to i64
%481 = arith.addi %479, %482 : i64
%483 = arith.constant 1 : i32
%484 = arith.extsi %483 : i32 to i64
%477 = func.call @calloc(%481, %484) : (i64, i64) -> !llvm.ptr
%485 = arith.constant 2 : i32
%486 = arith.extsi %485 : i32 to i64
%487 = llvm.mlir.constant(1 : i64) : i64
%488 = llvm.alloca %487 x i64 : (i64) -> !llvm.ptr
llvm.store %486, %488 : i64, !llvm.ptr
cf.br ^bb93
^bb93:
%489 = llvm.load %488 : !llvm.ptr -> i64
%490 = llvm.load %488 : !llvm.ptr -> i64
%491 = arith.muli %489, %490 : i64
%492 = llvm.mlir.addressof @g_limit : !llvm.ptr
%493 = llvm.load %492 : !llvm.ptr -> i64
%494 = arith.cmpi sle, %491, %493 : i64
cf.cond_br %494, ^bb94, ^bb95
^bb94:
%496 = llvm.load %488 : !llvm.ptr -> i64
%497 = llvm.getelementptr %477[%496] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%495 = llvm.load %497 : !llvm.ptr -> i8
%498 = arith.constant 0 : i32
%500 = arith.extsi %495 : i8 to i32
%499 = arith.cmpi eq, %500, %498 : i32
cf.cond_br %499, ^bb96, ^bb97
^bb96:
%501 = llvm.load %488 : !llvm.ptr -> i64
%502 = llvm.load %488 : !llvm.ptr -> i64
%503 = arith.muli %501, %502 : i64
%504 = llvm.mlir.constant(1 : i64) : i64
%505 = llvm.alloca %504 x i64 : (i64) -> !llvm.ptr
llvm.store %503, %505 : i64, !llvm.ptr
cf.br ^bb99
^bb99:
%506 = llvm.load %505 : !llvm.ptr -> i64
%507 = llvm.mlir.addressof @g_limit : !llvm.ptr
%508 = llvm.load %507 : !llvm.ptr -> i64
%509 = arith.cmpi sle, %506, %508 : i64
cf.cond_br %509, ^bb100, ^bb101
^bb100:
%510 = arith.constant 1 : i32
%511 = llvm.load %505 : !llvm.ptr -> i64
%512 = arith.trunci %510 : i32 to i8
%513 = llvm.getelementptr %477[%511] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %512, %513 : i8, !llvm.ptr
%514 = llvm.load %505 : !llvm.ptr -> i64
%515 = llvm.load %488 : !llvm.ptr -> i64
%516 = arith.addi %514, %515 : i64
llvm.store %516, %505 : i64, !llvm.ptr
cf.br ^bb99
^bb101:
cf.br ^bb98
^bb97:
cf.br ^bb98
^bb98:
%517 = llvm.load %488 : !llvm.ptr -> i64
%518 = arith.constant 1 : i32
%520 = arith.extsi %518 : i32 to i64
%519 = arith.addi %517, %520 : i64
llvm.store %519, %488 : i64, !llvm.ptr
cf.br ^bb93
^bb95:
%521 = arith.constant 0 : i32
%522 = arith.extsi %521 : i32 to i64
%523 = llvm.mlir.constant(1 : i64) : i64
%524 = llvm.alloca %523 x i64 : (i64) -> !llvm.ptr
llvm.store %522, %524 : i64, !llvm.ptr
%525 = arith.constant 2 : i32
%526 = arith.extsi %525 : i32 to i64
llvm.store %526, %488 : i64, !llvm.ptr
cf.br ^bb102
^bb102:
%527 = llvm.load %488 : !llvm.ptr -> i64
%528 = llvm.mlir.addressof @g_limit : !llvm.ptr
%529 = llvm.load %528 : !llvm.ptr -> i64
%530 = arith.cmpi sle, %527, %529 : i64
cf.cond_br %530, ^bb103, ^bb104
^bb103:
%532 = llvm.load %488 : !llvm.ptr -> i64
%533 = llvm.getelementptr %477[%532] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%531 = llvm.load %533 : !llvm.ptr -> i8
%534 = arith.constant 0 : i32
%536 = arith.extsi %531 : i8 to i32
%535 = arith.cmpi eq, %536, %534 : i32
cf.cond_br %535, ^bb105, ^bb106
^bb105:
%537 = llvm.load %524 : !llvm.ptr -> i64
%538 = arith.constant 1 : i32
%540 = arith.extsi %538 : i32 to i64
%539 = arith.addi %537, %540 : i64
llvm.store %539, %524 : i64, !llvm.ptr
cf.br ^bb107
^bb106:
cf.br ^bb107
^bb107:
%541 = llvm.load %488 : !llvm.ptr -> i64
%542 = arith.constant 1 : i32
%544 = arith.extsi %542 : i32 to i64
%543 = arith.addi %541, %544 : i64
llvm.store %543, %488 : i64, !llvm.ptr
cf.br ^bb102
^bb104:
%546 = llvm.load %524 : !llvm.ptr -> i64
%547 = arith.constant 8 : i32
%549 = arith.extsi %547 : i32 to i64
%548 = arith.muli %546, %549 : i64
%545 = func.call @malloc(%548) : (i64) -> !llvm.ptr
%550 = llvm.mlir.addressof @g_primes : !llvm.ptr
llvm.store %545, %550 : !llvm.ptr, !llvm.ptr
%551 = arith.constant 0 : i32
%552 = arith.extsi %551 : i32 to i64
%553 = llvm.mlir.constant(1 : i64) : i64
%554 = llvm.alloca %553 x i64 : (i64) -> !llvm.ptr
llvm.store %552, %554 : i64, !llvm.ptr
%555 = arith.constant 2 : i32
%556 = arith.extsi %555 : i32 to i64
llvm.store %556, %488 : i64, !llvm.ptr
cf.br ^bb108
^bb108:
%557 = llvm.load %488 : !llvm.ptr -> i64
%558 = llvm.mlir.addressof @g_limit : !llvm.ptr
%559 = llvm.load %558 : !llvm.ptr -> i64
%560 = arith.cmpi sle, %557, %559 : i64
cf.cond_br %560, ^bb109, ^bb110
^bb109:
%562 = llvm.load %488 : !llvm.ptr -> i64
%563 = llvm.getelementptr %477[%562] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%561 = llvm.load %563 : !llvm.ptr -> i8
%564 = arith.constant 0 : i32
%566 = arith.extsi %561 : i8 to i32
%565 = arith.cmpi eq, %566, %564 : i32
cf.cond_br %565, ^bb111, ^bb112
^bb111:
%567 = llvm.load %488 : !llvm.ptr -> i64
%568 = llvm.mlir.addressof @g_primes : !llvm.ptr
%569 = llvm.load %568 : !llvm.ptr -> !llvm.ptr
%570 = llvm.load %554 : !llvm.ptr -> i64
%571 = llvm.getelementptr %569[%570] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %567, %571 : i64, !llvm.ptr
%572 = llvm.load %554 : !llvm.ptr -> i64
%573 = arith.constant 1 : i32
%575 = arith.extsi %573 : i32 to i64
%574 = arith.addi %572, %575 : i64
llvm.store %574, %554 : i64, !llvm.ptr
cf.br ^bb113
^bb112:
cf.br ^bb113
^bb113:
%576 = llvm.load %488 : !llvm.ptr -> i64
%577 = arith.constant 1 : i32
%579 = arith.extsi %577 : i32 to i64
%578 = arith.addi %576, %579 : i64
llvm.store %578, %488 : i64, !llvm.ptr
cf.br ^bb108
^bb110:
func.call @free(%477) : (!llvm.ptr) -> ()
%582 = llvm.mlir.addressof @g_limit : !llvm.ptr
%583 = llvm.load %582 : !llvm.ptr -> i64
%584 = arith.constant 1 : i32
%586 = arith.extsi %584 : i32 to i64
%585 = arith.addi %583, %586 : i64
%587 = arith.constant 8 : i32
%588 = arith.extsi %587 : i32 to i64
%581 = func.call @calloc(%585, %588) : (i64, i64) -> !llvm.ptr
%589 = llvm.mlir.addressof @g_pi_arr : !llvm.ptr
llvm.store %581, %589 : !llvm.ptr, !llvm.ptr
%590 = arith.constant 0 : i32
%591 = arith.extsi %590 : i32 to i64
%592 = llvm.mlir.constant(1 : i64) : i64
%593 = llvm.alloca %592 x i64 : (i64) -> !llvm.ptr
llvm.store %591, %593 : i64, !llvm.ptr
%594 = arith.constant 0 : i32
%595 = arith.extsi %594 : i32 to i64
%596 = llvm.mlir.constant(1 : i64) : i64
%597 = llvm.alloca %596 x i64 : (i64) -> !llvm.ptr
llvm.store %595, %597 : i64, !llvm.ptr
%598 = arith.constant 0 : i32
%599 = arith.extsi %598 : i32 to i64
llvm.store %599, %488 : i64, !llvm.ptr
cf.br ^bb114
^bb114:
%600 = llvm.load %488 : !llvm.ptr -> i64
%601 = llvm.mlir.addressof @g_limit : !llvm.ptr
%602 = llvm.load %601 : !llvm.ptr -> i64
%603 = arith.cmpi sle, %600, %602 : i64
cf.cond_br %603, ^bb115, ^bb116
^bb115:
cf.br ^bb117
^bb117:
%604 = llvm.load %597 : !llvm.ptr -> i64
%605 = llvm.load %524 : !llvm.ptr -> i64
%606 = arith.cmpi slt, %604, %605 : i64
%607 = scf.if %606 -> (i1) {
%609 = llvm.mlir.addressof @g_primes : !llvm.ptr
%610 = llvm.load %609 : !llvm.ptr -> !llvm.ptr
%611 = llvm.load %597 : !llvm.ptr -> i64
%612 = llvm.getelementptr %610[%611] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%608 = llvm.load %612 : !llvm.ptr -> i64
%613 = llvm.load %488 : !llvm.ptr -> i64
%614 = arith.cmpi sle, %608, %613 : i64
scf.yield %614 : i1
} else {
%615 = arith.constant false
scf.yield %615 : i1
}
cf.cond_br %607, ^bb118, ^bb119
^bb118:
%616 = llvm.load %593 : !llvm.ptr -> i64
%617 = arith.constant 1 : i32
%619 = arith.extsi %617 : i32 to i64
%618 = arith.addi %616, %619 : i64
llvm.store %618, %593 : i64, !llvm.ptr
%620 = llvm.load %597 : !llvm.ptr -> i64
%621 = arith.constant 1 : i32
%623 = arith.extsi %621 : i32 to i64
%622 = arith.addi %620, %623 : i64
llvm.store %622, %597 : i64, !llvm.ptr
cf.br ^bb117
^bb119:
%624 = llvm.load %593 : !llvm.ptr -> i64
%625 = llvm.mlir.addressof @g_pi_arr : !llvm.ptr
%626 = llvm.load %625 : !llvm.ptr -> !llvm.ptr
%627 = llvm.load %488 : !llvm.ptr -> i64
%628 = llvm.getelementptr %626[%627] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %624, %628 : i64, !llvm.ptr
%629 = llvm.load %488 : !llvm.ptr -> i64
%630 = arith.constant 1 : i32
%632 = arith.extsi %630 : i32 to i64
%631 = arith.addi %629, %632 : i64
llvm.store %631, %488 : i64, !llvm.ptr
cf.br ^bb114
^bb116:
%634 = llvm.mlir.addressof @CACHE_SIZE : !llvm.ptr
%635 = llvm.load %634 : !llvm.ptr -> i64
%636 = arith.constant 16 : i32
%637 = arith.extsi %636 : i32 to i64
%633 = func.call @calloc(%635, %637) : (i64, i64) -> !llvm.ptr
%638 = llvm.mlir.addressof @g_phi_cache : !llvm.ptr
llvm.store %633, %638 : !llvm.ptr, !llvm.ptr
%640 = llvm.mlir.addressof @CACHE_SIZE : !llvm.ptr
%641 = llvm.load %640 : !llvm.ptr -> i64
%642 = arith.constant 16 : i32
%643 = arith.extsi %642 : i32 to i64
%639 = func.call @calloc(%641, %643) : (i64, i64) -> !llvm.ptr
%644 = llvm.mlir.addressof @g_pi_cache : !llvm.ptr
llvm.store %639, %644 : !llvm.ptr, !llvm.ptr
%645 = func.call @pi_lehmer(%arg0) : (i64) -> i64
%647 = llvm.mlir.addressof @g_primes : !llvm.ptr
%648 = llvm.load %647 : !llvm.ptr -> !llvm.ptr
func.call @free(%648) : (!llvm.ptr) -> ()
%650 = llvm.mlir.addressof @g_pi_arr : !llvm.ptr
%651 = llvm.load %650 : !llvm.ptr -> !llvm.ptr
func.call @free(%651) : (!llvm.ptr) -> ()
%653 = llvm.mlir.addressof @g_phi_cache : !llvm.ptr
%654 = llvm.load %653 : !llvm.ptr -> !llvm.ptr
func.call @free(%654) : (!llvm.ptr) -> ()
%656 = llvm.mlir.addressof @g_pi_cache : !llvm.ptr
%657 = llvm.load %656 : !llvm.ptr -> !llvm.ptr
func.call @free(%657) : (!llvm.ptr) -> ()
func.return %645 : i64
}
func.func @fibonacci(%arg0: i64) -> i64 {
%658 = arith.constant 0 : i32
%659 = arith.extsi %658 : i32 to i64
%660 = llvm.mlir.constant(1 : i64) : i64
%661 = llvm.alloca %660 x i64 : (i64) -> !llvm.ptr
llvm.store %659, %661 : i64, !llvm.ptr
%662 = arith.constant 1 : i32
%663 = arith.extsi %662 : i32 to i64
%664 = llvm.mlir.constant(1 : i64) : i64
%665 = llvm.alloca %664 x i64 : (i64) -> !llvm.ptr
llvm.store %663, %665 : i64, !llvm.ptr
%666 = arith.constant 0 : i32
%667 = arith.extsi %666 : i32 to i64
%668 = llvm.mlir.constant(1 : i64) : i64
%669 = llvm.alloca %668 x i64 : (i64) -> !llvm.ptr
llvm.store %667, %669 : i64, !llvm.ptr
cf.br ^bb120
^bb120:
%670 = llvm.load %669 : !llvm.ptr -> i64
%671 = arith.cmpi slt, %670, %arg0 : i64
cf.cond_br %671, ^bb121, ^bb122
^bb121:
%672 = llvm.load %661 : !llvm.ptr -> i64
%673 = llvm.load %665 : !llvm.ptr -> i64
%674 = arith.addi %672, %673 : i64
%675 = llvm.load %665 : !llvm.ptr -> i64
llvm.store %675, %661 : i64, !llvm.ptr
llvm.store %674, %665 : i64, !llvm.ptr
%676 = llvm.load %669 : !llvm.ptr -> i64
%677 = arith.constant 1 : i32
%679 = arith.extsi %677 : i32 to i64
%678 = arith.addi %676, %679 : i64
llvm.store %678, %669 : i64, !llvm.ptr
cf.br ^bb120
^bb122:
%680 = llvm.load %661 : !llvm.ptr -> i64
func.return %680 : i64
}
func.func @S(%arg0: i64) -> i64 {
%681 = arith.constant 0 : i32
%682 = arith.extsi %681 : i32 to i64
%683 = llvm.mlir.constant(1 : i64) : i64
%684 = llvm.alloca %683 x i64 : (i64) -> !llvm.ptr
llvm.store %682, %684 : i64, !llvm.ptr
%685 = llvm.load %684 : !llvm.ptr -> i64
%686 = func.call @primePi(%arg0) : (i64) -> i64
%687 = arith.addi %685, %686 : i64
llvm.store %687, %684 : i64, !llvm.ptr
%688 = arith.constant 4 : i32
%690 = arith.extsi %688 : i32 to i64
%689 = arith.cmpi sge, %arg0, %690 : i64
cf.cond_br %689, ^bb123, ^bb124
^bb123:
%691 = llvm.load %684 : !llvm.ptr -> i64
%692 = arith.constant 2 : i32
%694 = arith.extsi %692 : i32 to i64
%693 = arith.divsi %arg0, %694 : i64
%695 = arith.addi %691, %693 : i64
%696 = arith.constant 1 : i32
%698 = arith.extsi %696 : i32 to i64
%697 = arith.subi %695, %698 : i64
llvm.store %697, %684 : i64, !llvm.ptr
%699 = llvm.load %684 : !llvm.ptr -> i64
%701 = arith.constant 2 : i32
%703 = arith.extsi %701 : i32 to i64
%702 = arith.subi %arg0, %703 : i64
%700 = func.call @primePi(%702) : (i64) -> i64
%704 = arith.addi %699, %700 : i64
%705 = arith.constant 1 : i32
%707 = arith.extsi %705 : i32 to i64
%706 = arith.subi %704, %707 : i64
llvm.store %706, %684 : i64, !llvm.ptr
cf.br ^bb125
^bb124:
cf.br ^bb125
^bb125:
%708 = arith.constant 6 : i32
%710 = arith.extsi %708 : i32 to i64
%709 = arith.cmpi sge, %arg0, %710 : i64
cf.cond_br %709, ^bb126, ^bb127
^bb126:
%711 = arith.constant 2 : i32
%713 = arith.extsi %711 : i32 to i64
%712 = arith.divsi %arg0, %713 : i64
%714 = llvm.load %684 : !llvm.ptr -> i64
%715 = arith.constant 2 : i32
%717 = arith.extsi %715 : i32 to i64
%716 = arith.subi %712, %717 : i64
%718 = arith.constant 1 : i32
%720 = arith.extsi %718 : i32 to i64
%719 = arith.addi %arg0, %720 : i64
%721 = arith.muli %716, %719 : i64
%722 = arith.addi %714, %721 : i64
%723 = arith.constant 1 : i32
%725 = arith.extsi %723 : i32 to i64
%724 = arith.addi %712, %725 : i64
%726 = arith.muli %724, %712 : i64
%727 = arith.subi %722, %726 : i64
%728 = arith.constant 6 : i32
%730 = arith.extsi %728 : i32 to i64
%729 = arith.addi %727, %730 : i64
llvm.store %729, %684 : i64, !llvm.ptr
cf.br ^bb128
^bb127:
cf.br ^bb128
^bb128:
%731 = llvm.load %684 : !llvm.ptr -> i64
func.return %731 : i64
}
func.func @main() -> i32 {
%732 = arith.constant 0 : i32
%733 = arith.extsi %732 : i32 to i64
%734 = llvm.mlir.constant(1 : i64) : i64
%735 = llvm.alloca %734 x i64 : (i64) -> !llvm.ptr
llvm.store %733, %735 : i64, !llvm.ptr
%736 = arith.constant 3 : i32
%737 = arith.extsi %736 : i32 to i64
%738 = llvm.mlir.constant(1 : i64) : i64
%739 = llvm.alloca %738 x i64 : (i64) -> !llvm.ptr
llvm.store %737, %739 : i64, !llvm.ptr
cf.br ^bb129
^bb129:
%740 = llvm.load %739 : !llvm.ptr -> i64
%741 = arith.constant 44 : i32
%743 = arith.extsi %741 : i32 to i64
%742 = arith.cmpi sle, %740, %743 : i64
cf.cond_br %742, ^bb130, ^bb131
^bb130:
%745 = llvm.load %739 : !llvm.ptr -> i64
%744 = func.call @fibonacci(%745) : (i64) -> i64
%746 = llvm.load %735 : !llvm.ptr -> i64
%747 = func.call @S(%744) : (i64) -> i64
%748 = arith.addi %746, %747 : i64
llvm.store %748, %735 : i64, !llvm.ptr
%749 = llvm.load %739 : !llvm.ptr -> i64
%750 = arith.constant 1 : i32
%752 = arith.extsi %750 : i32 to i64
%751 = arith.addi %749, %752 : i64
llvm.store %751, %739 : i64, !llvm.ptr
cf.br ^bb129
^bb131:
%753 = llvm.mlir.addressof @str_0 : !llvm.ptr
%754 = llvm.load %735 : !llvm.ptr -> i64
%755 = llvm.call @printf(%753, %754) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
%756 = arith.constant 0 : i32
func.return %756 : i32
}
}