← All problems
Problem 452
Minimal Product-sum Numbers II — summatory multiplicative g via Lehmer π.
View problem on Project Euler
Performance comparison
Metric Our solution Best known
Time complexity O(n^2)O(n * m)
Space complexity O(n^2)O(n)
Approach Flow solution Dynamic programming or generating function
Verdict Unknown
Flow source
# Project Euler 452
# Minimal Product-sum Numbers II — summatory multiplicative g via Lehmer π.
import euler.nt { isqrt }
extern {
function calloc(n: i64, size: i64) -> ptr<void>
function free(p: ptr<void>) -> void
}
const MOD: i64 = 1234567891
const N: i64 = 1000000000
const SIEVE_MAX: i64 = 1000000
const PI_CAP: i64 = 2097152
const PHI_CAP: i64 = 4194304
const S_CAP: i64 = 4194304
let mut G_primes: ptr<i32> = null
let mut G_pc: i64 = 0
let mut G_pi_small: ptr<i32> = null
let mut G_w: ptr<i64> = null
let mut G_max_e: i64 = 0
let mut G_pi_k: ptr<i64> = null
let mut G_pi_v: ptr<i64> = null
let mut G_pi_u: ptr<i8> = null
let mut G_phi_k1: ptr<i64> = null
let mut G_phi_k2: ptr<i64> = null
let mut G_phi_v: ptr<i64> = null
let mut G_phi_u: ptr<i8> = null
let mut G_s_k1: ptr<i64> = null
let mut G_s_k2: ptr<i64> = null
let mut G_s_v: ptr<i64> = null
let mut G_s_u: ptr<i8> = null
function modpow(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 {
r = ((r as i128) * (b as i128) % (mod as i128)) as i64
}
b = ((b as i128) * (b as i128) % (mod as i128)) as i64
e = e / 2
}
return r
}
function iroot(n: i64, k: i64) -> i64 {
if n < 2 { return n }
let mut lo: i64 = 1
let mut hi: i64 = 2
while true {
let mut p: i64 = 1
let mut t: i64 = 0
while t < k {
if p > n / hi { break }
p = p * hi
t = t + 1
}
if t == k && p <= n {
hi = hi * 2
} else {
break
}
}
lo = hi / 2
while lo + 1 < hi {
let mid: i64 = (lo + hi) / 2
let mut p: i64 = 1
let mut t: i64 = 0
let mut ok: i64 = 1
while t < k {
if p > n / mid {
ok = 0
break
}
p = p * mid
t = t + 1
}
if ok == 1 && p <= n {
lo = mid
} else {
hi = mid
}
}
return lo
}
function phi(x: i64, a: i64) -> i64 {
if a == 0 { return x }
if a == 1 { return x - x / 2 }
if a == 2 { return x - x / 2 - x / 3 + x / 6 }
let mut h: i64 = (x * 1315423911 + a) % PHI_CAP
if h < 0 { h = h + PHI_CAP }
while G_phi_u[h] != 0 {
if G_phi_k1[h] == x && G_phi_k2[h] == a {
return G_phi_v[h]
}
h = h + 1
if h == PHI_CAP { h = 0 }
}
let r: i64 = phi(x, a - 1) - phi(x / (G_primes[a - 1] as i64), a - 1)
G_phi_u[h] = 1
G_phi_k1[h] = x
G_phi_k2[h] = a
G_phi_v[h] = r
return r
}
function prime_pi(n: i64) -> i64 {
if n < SIEVE_MAX { return G_pi_small[n] as i64 }
if n < 2 { return 0 }
let mut h: i64 = n % PI_CAP
if h < 0 { h = h + PI_CAP }
while G_pi_u[h] != 0 {
if G_pi_k[h] == n {
return G_pi_v[h]
}
h = h + 1
if h == PI_CAP { h = 0 }
}
let a: i64 = prime_pi(iroot(n, 4))
let b: i64 = prime_pi(isqrt(n))
let c: i64 = prime_pi(iroot(n, 3))
let mut res: i64 = phi(n, a) + ((b + a - 2) * (b - a + 1)) / 2
let mut i: i64 = a
while i < b {
let p: i64 = G_primes[i] as i64
let w: i64 = n / p
res = res - prime_pi(w)
if i < c {
let lim: i64 = prime_pi(isqrt(w))
let mut j: i64 = i
while j < lim {
res = res - (prime_pi(w / (G_primes[j] as i64)) - j)
j = j + 1
}
}
i = i + 1
}
G_pi_u[h] = 1
G_pi_k[h] = n
G_pi_v[h] = res
return res
}
function S(limit: i64, idx: i64) -> i64 {
if limit < 2 { return 1 }
if idx >= G_pc || (G_primes[idx] as i64) > limit { return 1 }
let mut h: i64 = (limit * 1315423911 + idx) % S_CAP
if h < 0 { h = h + S_CAP }
while G_s_u[h] != 0 {
if G_s_k1[h] == limit && G_s_k2[h] == idx {
return G_s_v[h]
}
h = h + 1
if h == S_CAP { h = 0 }
}
let p0: i64 = G_primes[idx] as i64
let w1: i64 = G_w[1]
if p0 * p0 > limit {
let cnt: i64 = prime_pi(limit) - prime_pi(p0 - 1)
let r: i64 = (1 + (cnt % MOD) * w1) % MOD
G_s_u[h] = 1
G_s_k1[h] = limit
G_s_k2[h] = idx
G_s_v[h] = r
return r
}
let mut res: i64 = 1
let root: i64 = isqrt(limit)
let cnt_large: i64 = prime_pi(limit) - prime_pi(root)
res = (res + (cnt_large % MOD) * w1) % MOD
let mut i: i64 = idx
while i < G_pc {
let p: i64 = G_primes[i] as i64
if p > root { break }
let mut pe: i64 = p
let mut e: i64 = 1
while pe <= limit {
res = (res + G_w[e] * S(limit / pe, i + 1)) % MOD
e = e + 1
if e > G_max_e { break }
if pe > limit / p { break }
pe = pe * p
}
i = i + 1
}
G_s_u[h] = 1
G_s_k1[h] = limit
G_s_k2[h] = idx
G_s_v[h] = res
return res
}
function main() -> i32 {
let is_p: ptr<i8> = calloc(SIEVE_MAX + 1, 1)
G_primes = calloc(SIEVE_MAX / 5 + 16, 4)
G_pi_small = calloc(SIEVE_MAX + 1, 4)
G_w = calloc(64, 8)
G_pi_k = calloc(PI_CAP, 8)
G_pi_v = calloc(PI_CAP, 8)
G_pi_u = calloc(PI_CAP, 1)
G_phi_k1 = calloc(PHI_CAP, 8)
G_phi_k2 = calloc(PHI_CAP, 8)
G_phi_v = calloc(PHI_CAP, 8)
G_phi_u = calloc(PHI_CAP, 1)
G_s_k1 = calloc(S_CAP, 8)
G_s_k2 = calloc(S_CAP, 8)
G_s_v = calloc(S_CAP, 8)
G_s_u = calloc(S_CAP, 1)
if is_p == null || G_primes == null || G_pi_small == null || G_w == null { return 1 }
let mut i: i64 = 0
while i <= SIEVE_MAX {
is_p[i] = 1
i = i + 1
}
is_p[0] = 0
is_p[1] = 0
i = 2
while i * i <= SIEVE_MAX {
if is_p[i] != 0 {
let mut j: i64 = i * i
while j <= SIEVE_MAX {
is_p[j] = 0
j = j + i
}
}
i = i + 1
}
let mut c: i64 = 0
i = 0
while i <= SIEVE_MAX {
if is_p[i] != 0 {
G_primes[G_pc] = i as i32
G_pc = G_pc + 1
c = c + 1
}
G_pi_small[i] = c as i32
i = i + 1
}
free(is_p)
G_max_e = 0
let mut t: i64 = N
while t > 1 {
t = t / 2
G_max_e = G_max_e + 1
}
G_w[0] = 1
let mut cur: i64 = 1
let mut e: i64 = 1
while e <= G_max_e {
cur = (cur * ((N + e - 1) % MOD)) % MOD
cur = (cur * modpow(e, MOD - 2, MOD)) % MOD
G_w[e] = cur
e = e + 1
}
printf("%lld\n", S(N, 0))
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 modpow_i64_i64_i64(int64_t base0, int64_t exp0, int64_t mod);
int64_t iroot_i64_i64(int64_t n, int64_t k);
int64_t phi_i64_i64(int64_t x, int64_t a);
int64_t prime_pi_i64(int64_t n);
int64_t S_i64_i64(int64_t limit, int64_t idx);
int32_t main(void);
static const int64_t MOD = 1234567891;
static const int64_t N = 1000000000;
static const int64_t SIEVE_MAX = 1000000;
static const int64_t PI_CAP = 2097152;
static const int64_t PHI_CAP = 4194304;
static const int64_t S_CAP = 4194304;
/* Module statics */
static int32_t* G_primes = NULL;
static int64_t G_pc = 0;
static int32_t* G_pi_small = NULL;
static int64_t* G_w = NULL;
static int64_t G_max_e = 0;
static int64_t* G_pi_k = NULL;
static int64_t* G_pi_v = NULL;
static int8_t* G_pi_u = NULL;
static int64_t* G_phi_k1 = NULL;
static int64_t* G_phi_k2 = NULL;
static int64_t* G_phi_v = NULL;
static int8_t* G_phi_u = NULL;
static int64_t* G_s_k1 = NULL;
static int64_t* G_s_k2 = NULL;
static int64_t* G_s_v = NULL;
static int8_t* G_s_u = 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 modpow_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) {
r = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(r)) * ((__int128)(b)))), (((__int128)(mod))))));
}
b = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(b)) * ((__int128)(b)))), (((__int128)(mod))))));
e = FLOW_CHECKED_DIV((e), (2));
}
return r;
}
int64_t iroot_i64_i64(int64_t n, int64_t k) {
if (n < 2) {
return n;
}
int64_t lo = 1;
int64_t hi = 2;
while (1) {
int64_t p = 1;
int64_t t = 0;
while (t < k) {
if (p > FLOW_CHECKED_DIV((n), (hi))) {
break;
}
p = (p * hi);
t = (t + 1);
}
if ((t == k && p <= n)) {
hi = (hi * 2);
} else {
break;
}
}
lo = FLOW_CHECKED_DIV((hi), (2));
while ((lo + 1) < hi) {
int64_t mid = FLOW_CHECKED_DIV(((lo + hi)), (2));
int64_t p = 1;
int64_t t = 0;
int64_t ok = 1;
while (t < k) {
if (p > FLOW_CHECKED_DIV((n), (mid))) {
ok = 0;
break;
}
p = (p * mid);
t = (t + 1);
}
if ((ok == 1 && p <= n)) {
lo = mid;
} else {
hi = mid;
}
}
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)));
}
if (a == 2) {
return (((x - FLOW_CHECKED_DIV((x), (2))) - FLOW_CHECKED_DIV((x), (3))) + FLOW_CHECKED_DIV((x), (6)));
}
int64_t h = FLOW_CHECKED_MOD((((x * 1315423911) + a)), (PHI_CAP));
if (h < 0) {
h = (h + PHI_CAP);
}
while (G_phi_u[h] != 0) {
if ((G_phi_k1[h] == x && G_phi_k2[h] == a)) {
return G_phi_v[h];
}
h = (h + 1);
if (h == PHI_CAP) {
h = 0;
}
}
int64_t r = (phi_i64_i64(x, (a - 1)) - phi_i64_i64(FLOW_CHECKED_DIV((x), (((int64_t)(G_primes[(a - 1)])))), (a - 1)));
G_phi_u[h] = 1;
G_phi_k1[h] = x;
G_phi_k2[h] = a;
G_phi_v[h] = r;
return r;
}
int64_t prime_pi_i64(int64_t n) {
if (n < SIEVE_MAX) {
return ((int64_t)(G_pi_small[n]));
}
if (n < 2) {
return 0;
}
int64_t h = FLOW_CHECKED_MOD((n), (PI_CAP));
if (h < 0) {
h = (h + PI_CAP);
}
while (G_pi_u[h] != 0) {
if (G_pi_k[h] == n) {
return G_pi_v[h];
}
h = (h + 1);
if (h == PI_CAP) {
h = 0;
}
}
int64_t a = prime_pi_i64(iroot_i64_i64(n, 4));
int64_t b = prime_pi_i64(isqrt_i64(n));
int64_t c = prime_pi_i64(iroot_i64_i64(n, 3));
int64_t res = (phi_i64_i64(n, a) + FLOW_CHECKED_DIV(((((b + a) - 2) * ((b - a) + 1))), (2)));
int64_t i = a;
while (i < b) {
int64_t p = ((int64_t)(G_primes[i]));
int64_t w = FLOW_CHECKED_DIV((n), (p));
res = (res - prime_pi_i64(w));
if (i < c) {
int64_t lim = prime_pi_i64(isqrt_i64(w));
int64_t j = i;
while (j < lim) {
res = (res - (prime_pi_i64(FLOW_CHECKED_DIV((w), (((int64_t)(G_primes[j]))))) - j));
j = (j + 1);
}
}
i = (i + 1);
}
G_pi_u[h] = 1;
G_pi_k[h] = n;
G_pi_v[h] = res;
return res;
}
int64_t S_i64_i64(int64_t limit, int64_t idx) {
if (limit < 2) {
return 1;
}
if ((idx >= G_pc || ((int64_t)(G_primes[idx])) > limit)) {
return 1;
}
int64_t h = FLOW_CHECKED_MOD((((limit * 1315423911) + idx)), (S_CAP));
if (h < 0) {
h = (h + S_CAP);
}
while (G_s_u[h] != 0) {
if ((G_s_k1[h] == limit && G_s_k2[h] == idx)) {
return G_s_v[h];
}
h = (h + 1);
if (h == S_CAP) {
h = 0;
}
}
int64_t p0 = ((int64_t)(G_primes[idx]));
int64_t w1 = G_w[1];
if ((p0 * p0) > limit) {
int64_t cnt = (prime_pi_i64(limit) - prime_pi_i64((p0 - 1)));
int64_t r = FLOW_CHECKED_MOD(((1 + (FLOW_CHECKED_MOD((cnt), (MOD)) * w1))), (MOD));
G_s_u[h] = 1;
G_s_k1[h] = limit;
G_s_k2[h] = idx;
G_s_v[h] = r;
return r;
}
int64_t res = 1;
int64_t root = isqrt_i64(limit);
int64_t cnt_large = (prime_pi_i64(limit) - prime_pi_i64(root));
res = FLOW_CHECKED_MOD(((res + (FLOW_CHECKED_MOD((cnt_large), (MOD)) * w1))), (MOD));
int64_t i = idx;
while (i < G_pc) {
int64_t p = ((int64_t)(G_primes[i]));
if (p > root) {
break;
}
int64_t pe = p;
int64_t e = 1;
while (pe <= limit) {
res = FLOW_CHECKED_MOD(((res + (G_w[e] * S_i64_i64(FLOW_CHECKED_DIV((limit), (pe)), (i + 1))))), (MOD));
e = (e + 1);
if (e > G_max_e) {
break;
}
if (pe > FLOW_CHECKED_DIV((limit), (p))) {
break;
}
pe = (pe * p);
}
i = (i + 1);
}
G_s_u[h] = 1;
G_s_k1[h] = limit;
G_s_k2[h] = idx;
G_s_v[h] = res;
return res;
}
int32_t main(void) {
int8_t* is_p = (int8_t*)(calloc((SIEVE_MAX + 1), 1));
G_primes = calloc((FLOW_CHECKED_DIV((SIEVE_MAX), (5)) + 16), 4);
G_pi_small = calloc((SIEVE_MAX + 1), 4);
G_w = calloc(64, 8);
G_pi_k = calloc(PI_CAP, 8);
G_pi_v = calloc(PI_CAP, 8);
G_pi_u = calloc(PI_CAP, 1);
G_phi_k1 = calloc(PHI_CAP, 8);
G_phi_k2 = calloc(PHI_CAP, 8);
G_phi_v = calloc(PHI_CAP, 8);
G_phi_u = calloc(PHI_CAP, 1);
G_s_k1 = calloc(S_CAP, 8);
G_s_k2 = calloc(S_CAP, 8);
G_s_v = calloc(S_CAP, 8);
G_s_u = calloc(S_CAP, 1);
if ((((is_p == NULL || G_primes == NULL) || G_pi_small == NULL) || G_w == NULL)) {
return 1;
}
int64_t i = 0;
while (i <= SIEVE_MAX) {
is_p[i] = 1;
i = (i + 1);
}
is_p[0] = 0;
is_p[1] = 0;
i = 2;
while ((i * i) <= SIEVE_MAX) {
if (is_p[i] != 0) {
int64_t j = (i * i);
while (j <= SIEVE_MAX) {
is_p[j] = 0;
j = (j + i);
}
}
i = (i + 1);
}
int64_t c = 0;
i = 0;
while (i <= SIEVE_MAX) {
if (is_p[i] != 0) {
G_primes[G_pc] = ((int32_t)(i));
G_pc = (G_pc + 1);
c = (c + 1);
}
G_pi_small[i] = ((int32_t)(c));
i = (i + 1);
}
free(is_p);
G_max_e = 0;
int64_t t = N;
while (t > 1) {
t = FLOW_CHECKED_DIV((t), (2));
G_max_e = (G_max_e + 1);
}
G_w[0] = 1;
int64_t cur = 1;
int64_t e = 1;
while (e <= G_max_e) {
cur = FLOW_CHECKED_MOD(((cur * FLOW_CHECKED_MOD((((N + e) - 1)), (MOD)))), (MOD));
cur = FLOW_CHECKED_MOD(((cur * modpow_i64_i64_i64(e, (MOD - 2), MOD))), (MOD));
G_w[e] = cur;
e = (e + 1);
}
printf("%lld\n", S_i64_i64(N, 0));
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(1234567891 : i64) : i64
// Constant: N
llvm.mlir.global internal constant @N(1000000000 : i64) : i64
// Constant: SIEVE_MAX
llvm.mlir.global internal constant @SIEVE_MAX(1000000 : i64) : i64
// Constant: PI_CAP
llvm.mlir.global internal constant @PI_CAP(2097152 : i64) : i64
// Constant: PHI_CAP
llvm.mlir.global internal constant @PHI_CAP(4194304 : i64) : i64
// Constant: S_CAP
llvm.mlir.global internal constant @S_CAP(4194304 : i64) : 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_pc
llvm.mlir.global internal @G_pc(0 : i64) : i64
// Module static: G_pi_small
llvm.mlir.global internal @G_pi_small() {addr_space = 0 : i32} : !llvm.ptr {
%176 = llvm.mlir.zero : !llvm.ptr
llvm.return %176 : !llvm.ptr
}
// Module static: G_w
llvm.mlir.global internal @G_w() {addr_space = 0 : i32} : !llvm.ptr {
%177 = llvm.mlir.zero : !llvm.ptr
llvm.return %177 : !llvm.ptr
}
// Module static: G_max_e
llvm.mlir.global internal @G_max_e(0 : i64) : i64
// Module static: G_pi_k
llvm.mlir.global internal @G_pi_k() {addr_space = 0 : i32} : !llvm.ptr {
%178 = llvm.mlir.zero : !llvm.ptr
llvm.return %178 : !llvm.ptr
}
// Module static: G_pi_v
llvm.mlir.global internal @G_pi_v() {addr_space = 0 : i32} : !llvm.ptr {
%179 = llvm.mlir.zero : !llvm.ptr
llvm.return %179 : !llvm.ptr
}
// Module static: G_pi_u
llvm.mlir.global internal @G_pi_u() {addr_space = 0 : i32} : !llvm.ptr {
%180 = llvm.mlir.zero : !llvm.ptr
llvm.return %180 : !llvm.ptr
}
// Module static: G_phi_k1
llvm.mlir.global internal @G_phi_k1() {addr_space = 0 : i32} : !llvm.ptr {
%181 = llvm.mlir.zero : !llvm.ptr
llvm.return %181 : !llvm.ptr
}
// Module static: G_phi_k2
llvm.mlir.global internal @G_phi_k2() {addr_space = 0 : i32} : !llvm.ptr {
%182 = llvm.mlir.zero : !llvm.ptr
llvm.return %182 : !llvm.ptr
}
// Module static: G_phi_v
llvm.mlir.global internal @G_phi_v() {addr_space = 0 : i32} : !llvm.ptr {
%183 = llvm.mlir.zero : !llvm.ptr
llvm.return %183 : !llvm.ptr
}
// Module static: G_phi_u
llvm.mlir.global internal @G_phi_u() {addr_space = 0 : i32} : !llvm.ptr {
%184 = llvm.mlir.zero : !llvm.ptr
llvm.return %184 : !llvm.ptr
}
// Module static: G_s_k1
llvm.mlir.global internal @G_s_k1() {addr_space = 0 : i32} : !llvm.ptr {
%185 = llvm.mlir.zero : !llvm.ptr
llvm.return %185 : !llvm.ptr
}
// Module static: G_s_k2
llvm.mlir.global internal @G_s_k2() {addr_space = 0 : i32} : !llvm.ptr {
%186 = llvm.mlir.zero : !llvm.ptr
llvm.return %186 : !llvm.ptr
}
// Module static: G_s_v
llvm.mlir.global internal @G_s_v() {addr_space = 0 : i32} : !llvm.ptr {
%187 = llvm.mlir.zero : !llvm.ptr
llvm.return %187 : !llvm.ptr
}
// Module static: G_s_u
llvm.mlir.global internal @G_s_u() {addr_space = 0 : i32} : !llvm.ptr {
%188 = llvm.mlir.zero : !llvm.ptr
llvm.return %188 : !llvm.ptr
}
func.func @modpow(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
%189 = arith.constant 1 : i32
%190 = arith.extsi %189 : i32 to i64
%191 = llvm.mlir.constant(1 : i64) : i64
%192 = llvm.alloca %191 x i64 : (i64) -> !llvm.ptr
llvm.store %190, %192 : i64, !llvm.ptr
%193 = arith.remsi %arg0, %arg2 : i64
%194 = llvm.mlir.constant(1 : i64) : i64
%195 = llvm.alloca %194 x i64 : (i64) -> !llvm.ptr
llvm.store %193, %195 : i64, !llvm.ptr
%196 = llvm.mlir.constant(1 : i64) : i64
%197 = llvm.alloca %196 x i64 : (i64) -> !llvm.ptr
llvm.store %arg1, %197 : i64, !llvm.ptr
cf.br ^bb42
^bb42:
%198 = llvm.load %197 : !llvm.ptr -> i64
%199 = arith.constant 0 : i32
%201 = arith.extsi %199 : i32 to i64
%200 = arith.cmpi sgt, %198, %201 : i64
cf.cond_br %200, ^bb43, ^bb44
^bb43:
%202 = llvm.load %197 : !llvm.ptr -> i64
%203 = arith.constant 1 : i32
%205 = arith.extsi %203 : i32 to i64
%204 = arith.andi %202, %205 : i64
%206 = arith.constant 1 : i32
%208 = arith.extsi %206 : i32 to i64
%207 = arith.cmpi eq, %204, %208 : i64
cf.cond_br %207, ^bb45, ^bb46
^bb45:
%209 = llvm.load %192 : !llvm.ptr -> i64
%210 = arith.extsi %209 : i64 to i128
%211 = llvm.load %195 : !llvm.ptr -> i64
%212 = arith.extsi %211 : i64 to i128
%214 = arith.trunci %210 : i128 to i64
%215 = arith.trunci %212 : i128 to i64
%213 = arith.muli %214, %215 : i64
%216 = arith.extsi %arg2 : i64 to i128
%218 = arith.trunci %216 : i128 to i64
%217 = arith.remsi %213, %218 : i64
llvm.store %217, %192 : i64, !llvm.ptr
cf.br ^bb47
^bb46:
cf.br ^bb47
^bb47:
%219 = llvm.load %195 : !llvm.ptr -> i64
%220 = arith.extsi %219 : i64 to i128
%221 = llvm.load %195 : !llvm.ptr -> i64
%222 = arith.extsi %221 : i64 to i128
%224 = arith.trunci %220 : i128 to i64
%225 = arith.trunci %222 : i128 to i64
%223 = arith.muli %224, %225 : i64
%226 = arith.extsi %arg2 : i64 to i128
%228 = arith.trunci %226 : i128 to i64
%227 = arith.remsi %223, %228 : i64
llvm.store %227, %195 : i64, !llvm.ptr
%229 = llvm.load %197 : !llvm.ptr -> i64
%230 = arith.constant 2 : i32
%232 = arith.extsi %230 : i32 to i64
%231 = arith.divsi %229, %232 : i64
llvm.store %231, %197 : i64, !llvm.ptr
cf.br ^bb42
^bb44:
%233 = llvm.load %192 : !llvm.ptr -> i64
func.return %233 : i64
}
func.func @iroot(%arg0: i64, %arg1: i64) -> i64 {
%234 = arith.constant 2 : i32
%236 = arith.extsi %234 : i32 to i64
%235 = arith.cmpi slt, %arg0, %236 : i64
cf.cond_br %235, ^bb48, ^bb49
^bb48:
func.return %arg0 : i64
^bb49:
cf.br ^bb50
^bb50:
%237 = arith.constant 1 : i32
%238 = arith.extsi %237 : i32 to i64
%239 = llvm.mlir.constant(1 : i64) : i64
%240 = llvm.alloca %239 x i64 : (i64) -> !llvm.ptr
llvm.store %238, %240 : i64, !llvm.ptr
%241 = arith.constant 2 : i32
%242 = arith.extsi %241 : i32 to i64
%243 = llvm.mlir.constant(1 : i64) : i64
%244 = llvm.alloca %243 x i64 : (i64) -> !llvm.ptr
llvm.store %242, %244 : i64, !llvm.ptr
cf.br ^bb51
^bb51:
%245 = arith.constant 1 : i1
cf.cond_br %245, ^bb52, ^bb53
^bb52:
%246 = arith.constant 1 : i32
%247 = arith.extsi %246 : i32 to i64
%248 = llvm.mlir.constant(1 : i64) : i64
%249 = llvm.alloca %248 x i64 : (i64) -> !llvm.ptr
llvm.store %247, %249 : i64, !llvm.ptr
%250 = arith.constant 0 : i32
%251 = arith.extsi %250 : i32 to i64
%252 = llvm.mlir.constant(1 : i64) : i64
%253 = llvm.alloca %252 x i64 : (i64) -> !llvm.ptr
llvm.store %251, %253 : i64, !llvm.ptr
cf.br ^bb54
^bb54:
%254 = llvm.load %253 : !llvm.ptr -> i64
%255 = arith.cmpi slt, %254, %arg1 : i64
cf.cond_br %255, ^bb55, ^bb56
^bb55:
%256 = llvm.load %249 : !llvm.ptr -> i64
%257 = llvm.load %244 : !llvm.ptr -> i64
%258 = arith.divsi %arg0, %257 : i64
%259 = arith.cmpi sgt, %256, %258 : i64
cf.cond_br %259, ^bb57, ^bb58
^bb57:
cf.br ^bb56
^bb58:
cf.br ^bb59
^bb59:
%260 = llvm.load %249 : !llvm.ptr -> i64
%261 = llvm.load %244 : !llvm.ptr -> i64
%262 = arith.muli %260, %261 : i64
llvm.store %262, %249 : i64, !llvm.ptr
%263 = llvm.load %253 : !llvm.ptr -> i64
%264 = arith.constant 1 : i32
%266 = arith.extsi %264 : i32 to i64
%265 = arith.addi %263, %266 : i64
llvm.store %265, %253 : i64, !llvm.ptr
cf.br ^bb54
^bb56:
%267 = llvm.load %253 : !llvm.ptr -> i64
%268 = arith.cmpi eq, %267, %arg1 : i64
%269 = scf.if %268 -> (i1) {
%270 = llvm.load %249 : !llvm.ptr -> i64
%271 = arith.cmpi sle, %270, %arg0 : i64
scf.yield %271 : i1
} else {
%272 = arith.constant false
scf.yield %272 : i1
}
cf.cond_br %269, ^bb60, ^bb61
^bb60:
%273 = llvm.load %244 : !llvm.ptr -> i64
%274 = arith.constant 2 : i32
%276 = arith.extsi %274 : i32 to i64
%275 = arith.muli %273, %276 : i64
llvm.store %275, %244 : i64, !llvm.ptr
cf.br ^bb62
^bb61:
cf.br ^bb53
^bb62:
cf.br ^bb51
^bb53:
%277 = llvm.load %244 : !llvm.ptr -> i64
%278 = arith.constant 2 : i32
%280 = arith.extsi %278 : i32 to i64
%279 = arith.divsi %277, %280 : i64
llvm.store %279, %240 : i64, !llvm.ptr
cf.br ^bb63
^bb63:
%281 = llvm.load %240 : !llvm.ptr -> i64
%282 = arith.constant 1 : i32
%284 = arith.extsi %282 : i32 to i64
%283 = arith.addi %281, %284 : i64
%285 = llvm.load %244 : !llvm.ptr -> i64
%286 = arith.cmpi slt, %283, %285 : i64
cf.cond_br %286, ^bb64, ^bb65
^bb64:
%287 = llvm.load %240 : !llvm.ptr -> i64
%288 = llvm.load %244 : !llvm.ptr -> i64
%289 = arith.addi %287, %288 : i64
%290 = arith.constant 2 : i32
%292 = arith.extsi %290 : i32 to i64
%291 = arith.divsi %289, %292 : i64
%293 = arith.constant 1 : i32
%294 = arith.extsi %293 : i32 to i64
%295 = llvm.mlir.constant(1 : i64) : i64
%296 = llvm.alloca %295 x i64 : (i64) -> !llvm.ptr
llvm.store %294, %296 : i64, !llvm.ptr
%297 = arith.constant 0 : i32
%298 = arith.extsi %297 : i32 to i64
%299 = llvm.mlir.constant(1 : i64) : i64
%300 = llvm.alloca %299 x i64 : (i64) -> !llvm.ptr
llvm.store %298, %300 : i64, !llvm.ptr
%301 = arith.constant 1 : i32
%302 = arith.extsi %301 : i32 to i64
%303 = llvm.mlir.constant(1 : i64) : i64
%304 = llvm.alloca %303 x i64 : (i64) -> !llvm.ptr
llvm.store %302, %304 : i64, !llvm.ptr
cf.br ^bb66
^bb66:
%305 = llvm.load %300 : !llvm.ptr -> i64
%306 = arith.cmpi slt, %305, %arg1 : i64
cf.cond_br %306, ^bb67, ^bb68
^bb67:
%307 = llvm.load %296 : !llvm.ptr -> i64
%308 = arith.divsi %arg0, %291 : i64
%309 = arith.cmpi sgt, %307, %308 : i64
cf.cond_br %309, ^bb69, ^bb70
^bb69:
%310 = arith.constant 0 : i32
%311 = arith.extsi %310 : i32 to i64
llvm.store %311, %304 : i64, !llvm.ptr
cf.br ^bb68
^bb70:
cf.br ^bb71
^bb71:
%312 = llvm.load %296 : !llvm.ptr -> i64
%313 = arith.muli %312, %291 : i64
llvm.store %313, %296 : i64, !llvm.ptr
%314 = llvm.load %300 : !llvm.ptr -> i64
%315 = arith.constant 1 : i32
%317 = arith.extsi %315 : i32 to i64
%316 = arith.addi %314, %317 : i64
llvm.store %316, %300 : i64, !llvm.ptr
cf.br ^bb66
^bb68:
%318 = llvm.load %304 : !llvm.ptr -> i64
%319 = arith.constant 1 : i32
%321 = arith.extsi %319 : i32 to i64
%320 = arith.cmpi eq, %318, %321 : i64
%322 = scf.if %320 -> (i1) {
%323 = llvm.load %296 : !llvm.ptr -> i64
%324 = arith.cmpi sle, %323, %arg0 : i64
scf.yield %324 : i1
} else {
%325 = arith.constant false
scf.yield %325 : i1
}
cf.cond_br %322, ^bb72, ^bb73
^bb72:
llvm.store %291, %240 : i64, !llvm.ptr
cf.br ^bb74
^bb73:
llvm.store %291, %244 : i64, !llvm.ptr
cf.br ^bb74
^bb74:
cf.br ^bb63
^bb65:
%326 = llvm.load %240 : !llvm.ptr -> i64
func.return %326 : i64
}
func.func @phi(%arg0: i64, %arg1: i64) -> i64 {
%327 = arith.constant 0 : i32
%329 = arith.extsi %327 : i32 to i64
%328 = arith.cmpi eq, %arg1, %329 : i64
cf.cond_br %328, ^bb75, ^bb76
^bb75:
func.return %arg0 : i64
^bb76:
cf.br ^bb77
^bb77:
%330 = arith.constant 1 : i32
%332 = arith.extsi %330 : i32 to i64
%331 = arith.cmpi eq, %arg1, %332 : i64
cf.cond_br %331, ^bb78, ^bb79
^bb78:
%333 = arith.constant 2 : i32
%335 = arith.extsi %333 : i32 to i64
%334 = arith.divsi %arg0, %335 : i64
%336 = arith.subi %arg0, %334 : i64
func.return %336 : i64
^bb79:
cf.br ^bb80
^bb80:
%337 = arith.constant 2 : i32
%339 = arith.extsi %337 : i32 to i64
%338 = arith.cmpi eq, %arg1, %339 : i64
cf.cond_br %338, ^bb81, ^bb82
^bb81:
%340 = arith.constant 2 : i32
%342 = arith.extsi %340 : i32 to i64
%341 = arith.divsi %arg0, %342 : i64
%343 = arith.subi %arg0, %341 : i64
%344 = arith.constant 3 : i32
%346 = arith.extsi %344 : i32 to i64
%345 = arith.divsi %arg0, %346 : i64
%347 = arith.subi %343, %345 : i64
%348 = arith.constant 6 : i32
%350 = arith.extsi %348 : i32 to i64
%349 = arith.divsi %arg0, %350 : i64
%351 = arith.addi %347, %349 : i64
func.return %351 : i64
^bb82:
cf.br ^bb83
^bb83:
%352 = arith.constant 1315423911 : i32
%354 = arith.extsi %352 : i32 to i64
%353 = arith.muli %arg0, %354 : i64
%355 = arith.addi %353, %arg1 : i64
%356 = llvm.mlir.addressof @PHI_CAP : !llvm.ptr
%357 = llvm.load %356 : !llvm.ptr -> i64
%358 = arith.remsi %355, %357 : i64
%359 = llvm.mlir.constant(1 : i64) : i64
%360 = llvm.alloca %359 x i64 : (i64) -> !llvm.ptr
llvm.store %358, %360 : i64, !llvm.ptr
%361 = llvm.load %360 : !llvm.ptr -> i64
%362 = arith.constant 0 : i32
%364 = arith.extsi %362 : i32 to i64
%363 = arith.cmpi slt, %361, %364 : i64
cf.cond_br %363, ^bb84, ^bb85
^bb84:
%365 = llvm.load %360 : !llvm.ptr -> i64
%366 = llvm.mlir.addressof @PHI_CAP : !llvm.ptr
%367 = llvm.load %366 : !llvm.ptr -> i64
%368 = arith.addi %365, %367 : i64
llvm.store %368, %360 : i64, !llvm.ptr
cf.br ^bb86
^bb85:
cf.br ^bb86
^bb86:
cf.br ^bb87
^bb87:
%370 = llvm.mlir.addressof @G_phi_u : !llvm.ptr
%371 = llvm.load %370 : !llvm.ptr -> !llvm.ptr
%372 = llvm.load %360 : !llvm.ptr -> i64
%373 = llvm.getelementptr %371[%372] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%369 = llvm.load %373 : !llvm.ptr -> i8
%374 = arith.constant 0 : i32
%376 = arith.extsi %369 : i8 to i32
%375 = arith.cmpi ne, %376, %374 : i32
cf.cond_br %375, ^bb88, ^bb89
^bb88:
%378 = llvm.mlir.addressof @G_phi_k1 : !llvm.ptr
%379 = llvm.load %378 : !llvm.ptr -> !llvm.ptr
%380 = llvm.load %360 : !llvm.ptr -> i64
%381 = llvm.getelementptr %379[%380] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%377 = llvm.load %381 : !llvm.ptr -> i64
%382 = arith.cmpi eq, %377, %arg0 : i64
%383 = scf.if %382 -> (i1) {
%385 = llvm.mlir.addressof @G_phi_k2 : !llvm.ptr
%386 = llvm.load %385 : !llvm.ptr -> !llvm.ptr
%387 = llvm.load %360 : !llvm.ptr -> i64
%388 = llvm.getelementptr %386[%387] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%384 = llvm.load %388 : !llvm.ptr -> i64
%389 = arith.cmpi eq, %384, %arg1 : i64
scf.yield %389 : i1
} else {
%390 = arith.constant false
scf.yield %390 : i1
}
cf.cond_br %383, ^bb90, ^bb91
^bb90:
%392 = llvm.mlir.addressof @G_phi_v : !llvm.ptr
%393 = llvm.load %392 : !llvm.ptr -> !llvm.ptr
%394 = llvm.load %360 : !llvm.ptr -> i64
%395 = llvm.getelementptr %393[%394] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%391 = llvm.load %395 : !llvm.ptr -> i64
func.return %391 : i64
^bb91:
cf.br ^bb92
^bb92:
%396 = llvm.load %360 : !llvm.ptr -> i64
%397 = arith.constant 1 : i32
%399 = arith.extsi %397 : i32 to i64
%398 = arith.addi %396, %399 : i64
llvm.store %398, %360 : i64, !llvm.ptr
%400 = llvm.load %360 : !llvm.ptr -> i64
%401 = llvm.mlir.addressof @PHI_CAP : !llvm.ptr
%402 = llvm.load %401 : !llvm.ptr -> i64
%403 = arith.cmpi eq, %400, %402 : i64
cf.cond_br %403, ^bb93, ^bb94
^bb93:
%404 = arith.constant 0 : i32
%405 = arith.extsi %404 : i32 to i64
llvm.store %405, %360 : i64, !llvm.ptr
cf.br ^bb95
^bb94:
cf.br ^bb95
^bb95:
cf.br ^bb87
^bb89:
%407 = arith.constant 1 : i32
%409 = arith.extsi %407 : i32 to i64
%408 = arith.subi %arg1, %409 : i64
%406 = func.call @phi(%arg0, %408) : (i64, i64) -> i64
%412 = llvm.mlir.addressof @G_primes : !llvm.ptr
%413 = llvm.load %412 : !llvm.ptr -> !llvm.ptr
%414 = arith.constant 1 : i32
%416 = arith.extsi %414 : i32 to i64
%415 = arith.subi %arg1, %416 : i64
%417 = llvm.getelementptr %413[%415] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%411 = llvm.load %417 : !llvm.ptr -> i32
%418 = arith.extsi %411 : i32 to i64
%419 = arith.divsi %arg0, %418 : i64
%420 = arith.constant 1 : i32
%422 = arith.extsi %420 : i32 to i64
%421 = arith.subi %arg1, %422 : i64
%410 = func.call @phi(%419, %421) : (i64, i64) -> i64
%423 = arith.subi %406, %410 : i64
%424 = arith.constant 1 : i32
%425 = llvm.mlir.addressof @G_phi_u : !llvm.ptr
%426 = llvm.load %425 : !llvm.ptr -> !llvm.ptr
%427 = llvm.load %360 : !llvm.ptr -> i64
%428 = arith.trunci %424 : i32 to i8
%429 = llvm.getelementptr %426[%427] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %428, %429 : i8, !llvm.ptr
%430 = llvm.mlir.addressof @G_phi_k1 : !llvm.ptr
%431 = llvm.load %430 : !llvm.ptr -> !llvm.ptr
%432 = llvm.load %360 : !llvm.ptr -> i64
%433 = llvm.getelementptr %431[%432] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %arg0, %433 : i64, !llvm.ptr
%434 = llvm.mlir.addressof @G_phi_k2 : !llvm.ptr
%435 = llvm.load %434 : !llvm.ptr -> !llvm.ptr
%436 = llvm.load %360 : !llvm.ptr -> i64
%437 = llvm.getelementptr %435[%436] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %arg1, %437 : i64, !llvm.ptr
%438 = llvm.mlir.addressof @G_phi_v : !llvm.ptr
%439 = llvm.load %438 : !llvm.ptr -> !llvm.ptr
%440 = llvm.load %360 : !llvm.ptr -> i64
%441 = llvm.getelementptr %439[%440] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %423, %441 : i64, !llvm.ptr
func.return %423 : i64
}
func.func @prime_pi(%arg0: i64) -> i64 {
%442 = llvm.mlir.addressof @SIEVE_MAX : !llvm.ptr
%443 = llvm.load %442 : !llvm.ptr -> i64
%444 = arith.cmpi slt, %arg0, %443 : i64
cf.cond_br %444, ^bb96, ^bb97
^bb96:
%446 = llvm.mlir.addressof @G_pi_small : !llvm.ptr
%447 = llvm.load %446 : !llvm.ptr -> !llvm.ptr
%448 = llvm.getelementptr %447[%arg0] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%445 = llvm.load %448 : !llvm.ptr -> i32
%449 = arith.extsi %445 : i32 to i64
func.return %449 : i64
^bb97:
cf.br ^bb98
^bb98:
%450 = arith.constant 2 : i32
%452 = arith.extsi %450 : i32 to i64
%451 = arith.cmpi slt, %arg0, %452 : i64
cf.cond_br %451, ^bb99, ^bb100
^bb99:
%453 = arith.constant 0 : i32
%454 = arith.extsi %453 : i32 to i64
func.return %454 : i64
^bb100:
cf.br ^bb101
^bb101:
%455 = llvm.mlir.addressof @PI_CAP : !llvm.ptr
%456 = llvm.load %455 : !llvm.ptr -> i64
%457 = arith.remsi %arg0, %456 : i64
%458 = llvm.mlir.constant(1 : i64) : i64
%459 = llvm.alloca %458 x i64 : (i64) -> !llvm.ptr
llvm.store %457, %459 : i64, !llvm.ptr
%460 = llvm.load %459 : !llvm.ptr -> i64
%461 = arith.constant 0 : i32
%463 = arith.extsi %461 : i32 to i64
%462 = arith.cmpi slt, %460, %463 : i64
cf.cond_br %462, ^bb102, ^bb103
^bb102:
%464 = llvm.load %459 : !llvm.ptr -> i64
%465 = llvm.mlir.addressof @PI_CAP : !llvm.ptr
%466 = llvm.load %465 : !llvm.ptr -> i64
%467 = arith.addi %464, %466 : i64
llvm.store %467, %459 : i64, !llvm.ptr
cf.br ^bb104
^bb103:
cf.br ^bb104
^bb104:
cf.br ^bb105
^bb105:
%469 = llvm.mlir.addressof @G_pi_u : !llvm.ptr
%470 = llvm.load %469 : !llvm.ptr -> !llvm.ptr
%471 = llvm.load %459 : !llvm.ptr -> i64
%472 = llvm.getelementptr %470[%471] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%468 = llvm.load %472 : !llvm.ptr -> i8
%473 = arith.constant 0 : i32
%475 = arith.extsi %468 : i8 to i32
%474 = arith.cmpi ne, %475, %473 : i32
cf.cond_br %474, ^bb106, ^bb107
^bb106:
%477 = llvm.mlir.addressof @G_pi_k : !llvm.ptr
%478 = llvm.load %477 : !llvm.ptr -> !llvm.ptr
%479 = llvm.load %459 : !llvm.ptr -> i64
%480 = llvm.getelementptr %478[%479] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%476 = llvm.load %480 : !llvm.ptr -> i64
%481 = arith.cmpi eq, %476, %arg0 : i64
cf.cond_br %481, ^bb108, ^bb109
^bb108:
%483 = llvm.mlir.addressof @G_pi_v : !llvm.ptr
%484 = llvm.load %483 : !llvm.ptr -> !llvm.ptr
%485 = llvm.load %459 : !llvm.ptr -> i64
%486 = llvm.getelementptr %484[%485] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%482 = llvm.load %486 : !llvm.ptr -> i64
func.return %482 : i64
^bb109:
cf.br ^bb110
^bb110:
%487 = llvm.load %459 : !llvm.ptr -> i64
%488 = arith.constant 1 : i32
%490 = arith.extsi %488 : i32 to i64
%489 = arith.addi %487, %490 : i64
llvm.store %489, %459 : i64, !llvm.ptr
%491 = llvm.load %459 : !llvm.ptr -> i64
%492 = llvm.mlir.addressof @PI_CAP : !llvm.ptr
%493 = llvm.load %492 : !llvm.ptr -> i64
%494 = arith.cmpi eq, %491, %493 : i64
cf.cond_br %494, ^bb111, ^bb112
^bb111:
%495 = arith.constant 0 : i32
%496 = arith.extsi %495 : i32 to i64
llvm.store %496, %459 : i64, !llvm.ptr
cf.br ^bb113
^bb112:
cf.br ^bb113
^bb113:
cf.br ^bb105
^bb107:
%499 = arith.constant 4 : i32
%500 = arith.extsi %499 : i32 to i64
%498 = func.call @iroot(%arg0, %500) : (i64, i64) -> i64
%497 = func.call @prime_pi(%498) : (i64) -> i64
%502 = func.call @isqrt(%arg0) : (i64) -> i64
%501 = func.call @prime_pi(%502) : (i64) -> i64
%505 = arith.constant 3 : i32
%506 = arith.extsi %505 : i32 to i64
%504 = func.call @iroot(%arg0, %506) : (i64, i64) -> i64
%503 = func.call @prime_pi(%504) : (i64) -> i64
%507 = func.call @phi(%arg0, %497) : (i64, i64) -> i64
%508 = arith.addi %501, %497 : i64
%509 = arith.constant 2 : i32
%511 = arith.extsi %509 : i32 to i64
%510 = arith.subi %508, %511 : i64
%512 = arith.subi %501, %497 : i64
%513 = arith.constant 1 : i32
%515 = arith.extsi %513 : i32 to i64
%514 = arith.addi %512, %515 : i64
%516 = arith.muli %510, %514 : i64
%517 = arith.constant 2 : i32
%519 = arith.extsi %517 : i32 to i64
%518 = arith.divsi %516, %519 : i64
%520 = arith.addi %507, %518 : i64
%521 = llvm.mlir.constant(1 : i64) : i64
%522 = llvm.alloca %521 x i64 : (i64) -> !llvm.ptr
llvm.store %520, %522 : i64, !llvm.ptr
%523 = llvm.mlir.constant(1 : i64) : i64
%524 = llvm.alloca %523 x i64 : (i64) -> !llvm.ptr
llvm.store %497, %524 : i64, !llvm.ptr
cf.br ^bb114
^bb114:
%525 = llvm.load %524 : !llvm.ptr -> i64
%526 = arith.cmpi slt, %525, %501 : i64
cf.cond_br %526, ^bb115, ^bb116
^bb115:
%528 = llvm.mlir.addressof @G_primes : !llvm.ptr
%529 = llvm.load %528 : !llvm.ptr -> !llvm.ptr
%530 = llvm.load %524 : !llvm.ptr -> i64
%531 = llvm.getelementptr %529[%530] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%527 = llvm.load %531 : !llvm.ptr -> i32
%532 = arith.extsi %527 : i32 to i64
%533 = arith.divsi %arg0, %532 : i64
%534 = llvm.load %522 : !llvm.ptr -> i64
%535 = func.call @prime_pi(%533) : (i64) -> i64
%536 = arith.subi %534, %535 : i64
llvm.store %536, %522 : i64, !llvm.ptr
%537 = llvm.load %524 : !llvm.ptr -> i64
%538 = arith.cmpi slt, %537, %503 : i64
cf.cond_br %538, ^bb117, ^bb118
^bb117:
%540 = func.call @isqrt(%533) : (i64) -> i64
%539 = func.call @prime_pi(%540) : (i64) -> i64
%541 = llvm.load %524 : !llvm.ptr -> i64
%542 = llvm.mlir.constant(1 : i64) : i64
%543 = llvm.alloca %542 x i64 : (i64) -> !llvm.ptr
llvm.store %541, %543 : i64, !llvm.ptr
cf.br ^bb120
^bb120:
%544 = llvm.load %543 : !llvm.ptr -> i64
%545 = arith.cmpi slt, %544, %539 : i64
cf.cond_br %545, ^bb121, ^bb122
^bb121:
%546 = llvm.load %522 : !llvm.ptr -> i64
%549 = llvm.mlir.addressof @G_primes : !llvm.ptr
%550 = llvm.load %549 : !llvm.ptr -> !llvm.ptr
%551 = llvm.load %543 : !llvm.ptr -> i64
%552 = llvm.getelementptr %550[%551] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%548 = llvm.load %552 : !llvm.ptr -> i32
%553 = arith.extsi %548 : i32 to i64
%554 = arith.divsi %533, %553 : i64
%547 = func.call @prime_pi(%554) : (i64) -> i64
%555 = llvm.load %543 : !llvm.ptr -> i64
%556 = arith.subi %547, %555 : i64
%557 = arith.subi %546, %556 : i64
llvm.store %557, %522 : i64, !llvm.ptr
%558 = llvm.load %543 : !llvm.ptr -> i64
%559 = arith.constant 1 : i32
%561 = arith.extsi %559 : i32 to i64
%560 = arith.addi %558, %561 : i64
llvm.store %560, %543 : i64, !llvm.ptr
cf.br ^bb120
^bb122:
cf.br ^bb119
^bb118:
cf.br ^bb119
^bb119:
%562 = llvm.load %524 : !llvm.ptr -> i64
%563 = arith.constant 1 : i32
%565 = arith.extsi %563 : i32 to i64
%564 = arith.addi %562, %565 : i64
llvm.store %564, %524 : i64, !llvm.ptr
cf.br ^bb114
^bb116:
%566 = arith.constant 1 : i32
%567 = llvm.mlir.addressof @G_pi_u : !llvm.ptr
%568 = llvm.load %567 : !llvm.ptr -> !llvm.ptr
%569 = llvm.load %459 : !llvm.ptr -> i64
%570 = arith.trunci %566 : i32 to i8
%571 = llvm.getelementptr %568[%569] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %570, %571 : i8, !llvm.ptr
%572 = llvm.mlir.addressof @G_pi_k : !llvm.ptr
%573 = llvm.load %572 : !llvm.ptr -> !llvm.ptr
%574 = llvm.load %459 : !llvm.ptr -> i64
%575 = llvm.getelementptr %573[%574] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %arg0, %575 : i64, !llvm.ptr
%576 = llvm.load %522 : !llvm.ptr -> i64
%577 = llvm.mlir.addressof @G_pi_v : !llvm.ptr
%578 = llvm.load %577 : !llvm.ptr -> !llvm.ptr
%579 = llvm.load %459 : !llvm.ptr -> i64
%580 = llvm.getelementptr %578[%579] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %576, %580 : i64, !llvm.ptr
%581 = llvm.load %522 : !llvm.ptr -> i64
func.return %581 : i64
}
func.func @S(%arg0: i64, %arg1: i64) -> i64 {
%582 = arith.constant 2 : i32
%584 = arith.extsi %582 : i32 to i64
%583 = arith.cmpi slt, %arg0, %584 : i64
cf.cond_br %583, ^bb123, ^bb124
^bb123:
%585 = arith.constant 1 : i32
%586 = arith.extsi %585 : i32 to i64
func.return %586 : i64
^bb124:
cf.br ^bb125
^bb125:
%587 = llvm.mlir.addressof @G_pc : !llvm.ptr
%588 = llvm.load %587 : !llvm.ptr -> i64
%589 = arith.cmpi sge, %arg1, %588 : i64
%590 = scf.if %589 -> (i1) {
%591 = arith.constant true
scf.yield %591 : i1
} else {
%593 = llvm.mlir.addressof @G_primes : !llvm.ptr
%594 = llvm.load %593 : !llvm.ptr -> !llvm.ptr
%595 = llvm.getelementptr %594[%arg1] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%592 = llvm.load %595 : !llvm.ptr -> i32
%596 = arith.extsi %592 : i32 to i64
%597 = arith.cmpi sgt, %596, %arg0 : i64
scf.yield %597 : i1
}
cf.cond_br %590, ^bb126, ^bb127
^bb126:
%598 = arith.constant 1 : i32
%599 = arith.extsi %598 : i32 to i64
func.return %599 : i64
^bb127:
cf.br ^bb128
^bb128:
%600 = arith.constant 1315423911 : i32
%602 = arith.extsi %600 : i32 to i64
%601 = arith.muli %arg0, %602 : i64
%603 = arith.addi %601, %arg1 : i64
%604 = llvm.mlir.addressof @S_CAP : !llvm.ptr
%605 = llvm.load %604 : !llvm.ptr -> i64
%606 = arith.remsi %603, %605 : i64
%607 = llvm.mlir.constant(1 : i64) : i64
%608 = llvm.alloca %607 x i64 : (i64) -> !llvm.ptr
llvm.store %606, %608 : i64, !llvm.ptr
%609 = llvm.load %608 : !llvm.ptr -> i64
%610 = arith.constant 0 : i32
%612 = arith.extsi %610 : i32 to i64
%611 = arith.cmpi slt, %609, %612 : i64
cf.cond_br %611, ^bb129, ^bb130
^bb129:
%613 = llvm.load %608 : !llvm.ptr -> i64
%614 = llvm.mlir.addressof @S_CAP : !llvm.ptr
%615 = llvm.load %614 : !llvm.ptr -> i64
%616 = arith.addi %613, %615 : i64
llvm.store %616, %608 : i64, !llvm.ptr
cf.br ^bb131
^bb130:
cf.br ^bb131
^bb131:
cf.br ^bb132
^bb132:
%618 = llvm.mlir.addressof @G_s_u : !llvm.ptr
%619 = llvm.load %618 : !llvm.ptr -> !llvm.ptr
%620 = llvm.load %608 : !llvm.ptr -> i64
%621 = llvm.getelementptr %619[%620] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%617 = llvm.load %621 : !llvm.ptr -> i8
%622 = arith.constant 0 : i32
%624 = arith.extsi %617 : i8 to i32
%623 = arith.cmpi ne, %624, %622 : i32
cf.cond_br %623, ^bb133, ^bb134
^bb133:
%626 = llvm.mlir.addressof @G_s_k1 : !llvm.ptr
%627 = llvm.load %626 : !llvm.ptr -> !llvm.ptr
%628 = llvm.load %608 : !llvm.ptr -> i64
%629 = llvm.getelementptr %627[%628] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%625 = llvm.load %629 : !llvm.ptr -> i64
%630 = arith.cmpi eq, %625, %arg0 : i64
%631 = scf.if %630 -> (i1) {
%633 = llvm.mlir.addressof @G_s_k2 : !llvm.ptr
%634 = llvm.load %633 : !llvm.ptr -> !llvm.ptr
%635 = llvm.load %608 : !llvm.ptr -> i64
%636 = llvm.getelementptr %634[%635] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%632 = llvm.load %636 : !llvm.ptr -> i64
%637 = arith.cmpi eq, %632, %arg1 : i64
scf.yield %637 : i1
} else {
%638 = arith.constant false
scf.yield %638 : i1
}
cf.cond_br %631, ^bb135, ^bb136
^bb135:
%640 = llvm.mlir.addressof @G_s_v : !llvm.ptr
%641 = llvm.load %640 : !llvm.ptr -> !llvm.ptr
%642 = llvm.load %608 : !llvm.ptr -> i64
%643 = llvm.getelementptr %641[%642] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%639 = llvm.load %643 : !llvm.ptr -> i64
func.return %639 : i64
^bb136:
cf.br ^bb137
^bb137:
%644 = llvm.load %608 : !llvm.ptr -> i64
%645 = arith.constant 1 : i32
%647 = arith.extsi %645 : i32 to i64
%646 = arith.addi %644, %647 : i64
llvm.store %646, %608 : i64, !llvm.ptr
%648 = llvm.load %608 : !llvm.ptr -> i64
%649 = llvm.mlir.addressof @S_CAP : !llvm.ptr
%650 = llvm.load %649 : !llvm.ptr -> i64
%651 = arith.cmpi eq, %648, %650 : i64
cf.cond_br %651, ^bb138, ^bb139
^bb138:
%652 = arith.constant 0 : i32
%653 = arith.extsi %652 : i32 to i64
llvm.store %653, %608 : i64, !llvm.ptr
cf.br ^bb140
^bb139:
cf.br ^bb140
^bb140:
cf.br ^bb132
^bb134:
%655 = llvm.mlir.addressof @G_primes : !llvm.ptr
%656 = llvm.load %655 : !llvm.ptr -> !llvm.ptr
%657 = llvm.getelementptr %656[%arg1] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%654 = llvm.load %657 : !llvm.ptr -> i32
%658 = arith.extsi %654 : i32 to i64
%660 = llvm.mlir.addressof @G_w : !llvm.ptr
%661 = llvm.load %660 : !llvm.ptr -> !llvm.ptr
%662 = arith.constant 1 : i32
%663 = arith.extsi %662 : i32 to i64
%664 = llvm.getelementptr %661[%663] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%659 = llvm.load %664 : !llvm.ptr -> i64
%665 = arith.muli %658, %658 : i64
%666 = arith.cmpi sgt, %665, %arg0 : i64
cf.cond_br %666, ^bb141, ^bb142
^bb141:
%667 = func.call @prime_pi(%arg0) : (i64) -> i64
%669 = arith.constant 1 : i32
%671 = arith.extsi %669 : i32 to i64
%670 = arith.subi %658, %671 : i64
%668 = func.call @prime_pi(%670) : (i64) -> i64
%672 = arith.subi %667, %668 : i64
%673 = arith.constant 1 : i32
%674 = llvm.mlir.addressof @MOD : !llvm.ptr
%675 = llvm.load %674 : !llvm.ptr -> i64
%676 = arith.remsi %672, %675 : i64
%677 = arith.muli %676, %659 : i64
%679 = arith.extsi %673 : i32 to i64
%678 = arith.addi %679, %677 : i64
%680 = llvm.mlir.addressof @MOD : !llvm.ptr
%681 = llvm.load %680 : !llvm.ptr -> i64
%682 = arith.remsi %678, %681 : i64
%683 = arith.constant 1 : i32
%684 = llvm.mlir.addressof @G_s_u : !llvm.ptr
%685 = llvm.load %684 : !llvm.ptr -> !llvm.ptr
%686 = llvm.load %608 : !llvm.ptr -> i64
%687 = arith.trunci %683 : i32 to i8
%688 = llvm.getelementptr %685[%686] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %687, %688 : i8, !llvm.ptr
%689 = llvm.mlir.addressof @G_s_k1 : !llvm.ptr
%690 = llvm.load %689 : !llvm.ptr -> !llvm.ptr
%691 = llvm.load %608 : !llvm.ptr -> i64
%692 = llvm.getelementptr %690[%691] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %arg0, %692 : i64, !llvm.ptr
%693 = llvm.mlir.addressof @G_s_k2 : !llvm.ptr
%694 = llvm.load %693 : !llvm.ptr -> !llvm.ptr
%695 = llvm.load %608 : !llvm.ptr -> i64
%696 = llvm.getelementptr %694[%695] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %arg1, %696 : i64, !llvm.ptr
%697 = llvm.mlir.addressof @G_s_v : !llvm.ptr
%698 = llvm.load %697 : !llvm.ptr -> !llvm.ptr
%699 = llvm.load %608 : !llvm.ptr -> i64
%700 = llvm.getelementptr %698[%699] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %682, %700 : i64, !llvm.ptr
func.return %682 : i64
^bb142:
cf.br ^bb143
^bb143:
%701 = arith.constant 1 : i32
%702 = arith.extsi %701 : i32 to i64
%703 = llvm.mlir.constant(1 : i64) : i64
%704 = llvm.alloca %703 x i64 : (i64) -> !llvm.ptr
llvm.store %702, %704 : i64, !llvm.ptr
%705 = func.call @isqrt(%arg0) : (i64) -> i64
%706 = func.call @prime_pi(%arg0) : (i64) -> i64
%707 = func.call @prime_pi(%705) : (i64) -> i64
%708 = arith.subi %706, %707 : i64
%709 = llvm.load %704 : !llvm.ptr -> i64
%710 = llvm.mlir.addressof @MOD : !llvm.ptr
%711 = llvm.load %710 : !llvm.ptr -> i64
%712 = arith.remsi %708, %711 : i64
%713 = arith.muli %712, %659 : i64
%714 = arith.addi %709, %713 : i64
%715 = llvm.mlir.addressof @MOD : !llvm.ptr
%716 = llvm.load %715 : !llvm.ptr -> i64
%717 = arith.remsi %714, %716 : i64
llvm.store %717, %704 : i64, !llvm.ptr
%718 = llvm.mlir.constant(1 : i64) : i64
%719 = llvm.alloca %718 x i64 : (i64) -> !llvm.ptr
llvm.store %arg1, %719 : i64, !llvm.ptr
cf.br ^bb144
^bb144:
%720 = llvm.load %719 : !llvm.ptr -> i64
%721 = llvm.mlir.addressof @G_pc : !llvm.ptr
%722 = llvm.load %721 : !llvm.ptr -> i64
%723 = arith.cmpi slt, %720, %722 : i64
cf.cond_br %723, ^bb145, ^bb146
^bb145:
%725 = llvm.mlir.addressof @G_primes : !llvm.ptr
%726 = llvm.load %725 : !llvm.ptr -> !llvm.ptr
%727 = llvm.load %719 : !llvm.ptr -> i64
%728 = llvm.getelementptr %726[%727] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%724 = llvm.load %728 : !llvm.ptr -> i32
%729 = arith.extsi %724 : i32 to i64
%730 = arith.cmpi sgt, %729, %705 : i64
cf.cond_br %730, ^bb147, ^bb148
^bb147:
cf.br ^bb146
^bb148:
cf.br ^bb149
^bb149:
%731 = llvm.mlir.constant(1 : i64) : i64
%732 = llvm.alloca %731 x i64 : (i64) -> !llvm.ptr
llvm.store %729, %732 : i64, !llvm.ptr
%733 = arith.constant 1 : i32
%734 = arith.extsi %733 : i32 to i64
%735 = llvm.mlir.constant(1 : i64) : i64
%736 = llvm.alloca %735 x i64 : (i64) -> !llvm.ptr
llvm.store %734, %736 : i64, !llvm.ptr
cf.br ^bb150
^bb150:
%737 = llvm.load %732 : !llvm.ptr -> i64
%738 = arith.cmpi sle, %737, %arg0 : i64
cf.cond_br %738, ^bb151, ^bb152
^bb151:
%739 = llvm.load %704 : !llvm.ptr -> i64
%741 = llvm.mlir.addressof @G_w : !llvm.ptr
%742 = llvm.load %741 : !llvm.ptr -> !llvm.ptr
%743 = llvm.load %736 : !llvm.ptr -> i64
%744 = llvm.getelementptr %742[%743] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%740 = llvm.load %744 : !llvm.ptr -> i64
%746 = llvm.load %732 : !llvm.ptr -> i64
%747 = arith.divsi %arg0, %746 : i64
%748 = llvm.load %719 : !llvm.ptr -> i64
%749 = arith.constant 1 : i32
%751 = arith.extsi %749 : i32 to i64
%750 = arith.addi %748, %751 : i64
%745 = func.call @S(%747, %750) : (i64, i64) -> i64
%752 = arith.muli %740, %745 : i64
%753 = arith.addi %739, %752 : i64
%754 = llvm.mlir.addressof @MOD : !llvm.ptr
%755 = llvm.load %754 : !llvm.ptr -> i64
%756 = arith.remsi %753, %755 : i64
llvm.store %756, %704 : i64, !llvm.ptr
%757 = llvm.load %736 : !llvm.ptr -> i64
%758 = arith.constant 1 : i32
%760 = arith.extsi %758 : i32 to i64
%759 = arith.addi %757, %760 : i64
llvm.store %759, %736 : i64, !llvm.ptr
%761 = llvm.load %736 : !llvm.ptr -> i64
%762 = llvm.mlir.addressof @G_max_e : !llvm.ptr
%763 = llvm.load %762 : !llvm.ptr -> i64
%764 = arith.cmpi sgt, %761, %763 : i64
cf.cond_br %764, ^bb153, ^bb154
^bb153:
cf.br ^bb152
^bb154:
cf.br ^bb155
^bb155:
%765 = llvm.load %732 : !llvm.ptr -> i64
%766 = arith.divsi %arg0, %729 : i64
%767 = arith.cmpi sgt, %765, %766 : i64
cf.cond_br %767, ^bb156, ^bb157
^bb156:
cf.br ^bb152
^bb157:
cf.br ^bb158
^bb158:
%768 = llvm.load %732 : !llvm.ptr -> i64
%769 = arith.muli %768, %729 : i64
llvm.store %769, %732 : i64, !llvm.ptr
cf.br ^bb150
^bb152:
%770 = llvm.load %719 : !llvm.ptr -> i64
%771 = arith.constant 1 : i32
%773 = arith.extsi %771 : i32 to i64
%772 = arith.addi %770, %773 : i64
llvm.store %772, %719 : i64, !llvm.ptr
cf.br ^bb144
^bb146:
%774 = arith.constant 1 : i32
%775 = llvm.mlir.addressof @G_s_u : !llvm.ptr
%776 = llvm.load %775 : !llvm.ptr -> !llvm.ptr
%777 = llvm.load %608 : !llvm.ptr -> i64
%778 = arith.trunci %774 : i32 to i8
%779 = llvm.getelementptr %776[%777] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %778, %779 : i8, !llvm.ptr
%780 = llvm.mlir.addressof @G_s_k1 : !llvm.ptr
%781 = llvm.load %780 : !llvm.ptr -> !llvm.ptr
%782 = llvm.load %608 : !llvm.ptr -> i64
%783 = llvm.getelementptr %781[%782] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %arg0, %783 : i64, !llvm.ptr
%784 = llvm.mlir.addressof @G_s_k2 : !llvm.ptr
%785 = llvm.load %784 : !llvm.ptr -> !llvm.ptr
%786 = llvm.load %608 : !llvm.ptr -> i64
%787 = llvm.getelementptr %785[%786] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %arg1, %787 : i64, !llvm.ptr
%788 = llvm.load %704 : !llvm.ptr -> i64
%789 = llvm.mlir.addressof @G_s_v : !llvm.ptr
%790 = llvm.load %789 : !llvm.ptr -> !llvm.ptr
%791 = llvm.load %608 : !llvm.ptr -> i64
%792 = llvm.getelementptr %790[%791] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %788, %792 : i64, !llvm.ptr
%793 = llvm.load %704 : !llvm.ptr -> i64
func.return %793 : i64
}
func.func @main() -> i32 {
%795 = llvm.mlir.addressof @SIEVE_MAX : !llvm.ptr
%796 = llvm.load %795 : !llvm.ptr -> i64
%797 = arith.constant 1 : i32
%799 = arith.extsi %797 : i32 to i64
%798 = arith.addi %796, %799 : i64
%800 = arith.constant 1 : i32
%801 = arith.extsi %800 : i32 to i64
%794 = func.call @calloc(%798, %801) : (i64, i64) -> !llvm.ptr
%803 = llvm.mlir.addressof @SIEVE_MAX : !llvm.ptr
%804 = llvm.load %803 : !llvm.ptr -> i64
%805 = arith.constant 5 : i32
%807 = arith.extsi %805 : i32 to i64
%806 = arith.divsi %804, %807 : i64
%808 = arith.constant 16 : i32
%810 = arith.extsi %808 : i32 to i64
%809 = arith.addi %806, %810 : i64
%811 = arith.constant 4 : i32
%812 = arith.extsi %811 : i32 to i64
%802 = func.call @calloc(%809, %812) : (i64, i64) -> !llvm.ptr
%813 = llvm.mlir.addressof @G_primes : !llvm.ptr
llvm.store %802, %813 : !llvm.ptr, !llvm.ptr
%815 = llvm.mlir.addressof @SIEVE_MAX : !llvm.ptr
%816 = llvm.load %815 : !llvm.ptr -> i64
%817 = arith.constant 1 : i32
%819 = arith.extsi %817 : i32 to i64
%818 = arith.addi %816, %819 : i64
%820 = arith.constant 4 : i32
%821 = arith.extsi %820 : i32 to i64
%814 = func.call @calloc(%818, %821) : (i64, i64) -> !llvm.ptr
%822 = llvm.mlir.addressof @G_pi_small : !llvm.ptr
llvm.store %814, %822 : !llvm.ptr, !llvm.ptr
%824 = arith.constant 64 : i32
%825 = arith.constant 8 : i32
%826 = arith.extsi %824 : i32 to i64
%827 = arith.extsi %825 : i32 to i64
%823 = func.call @calloc(%826, %827) : (i64, i64) -> !llvm.ptr
%828 = llvm.mlir.addressof @G_w : !llvm.ptr
llvm.store %823, %828 : !llvm.ptr, !llvm.ptr
%830 = llvm.mlir.addressof @PI_CAP : !llvm.ptr
%831 = llvm.load %830 : !llvm.ptr -> i64
%832 = arith.constant 8 : i32
%833 = arith.extsi %832 : i32 to i64
%829 = func.call @calloc(%831, %833) : (i64, i64) -> !llvm.ptr
%834 = llvm.mlir.addressof @G_pi_k : !llvm.ptr
llvm.store %829, %834 : !llvm.ptr, !llvm.ptr
%836 = llvm.mlir.addressof @PI_CAP : !llvm.ptr
%837 = llvm.load %836 : !llvm.ptr -> i64
%838 = arith.constant 8 : i32
%839 = arith.extsi %838 : i32 to i64
%835 = func.call @calloc(%837, %839) : (i64, i64) -> !llvm.ptr
%840 = llvm.mlir.addressof @G_pi_v : !llvm.ptr
llvm.store %835, %840 : !llvm.ptr, !llvm.ptr
%842 = llvm.mlir.addressof @PI_CAP : !llvm.ptr
%843 = llvm.load %842 : !llvm.ptr -> i64
%844 = arith.constant 1 : i32
%845 = arith.extsi %844 : i32 to i64
%841 = func.call @calloc(%843, %845) : (i64, i64) -> !llvm.ptr
%846 = llvm.mlir.addressof @G_pi_u : !llvm.ptr
llvm.store %841, %846 : !llvm.ptr, !llvm.ptr
%848 = llvm.mlir.addressof @PHI_CAP : !llvm.ptr
%849 = llvm.load %848 : !llvm.ptr -> i64
%850 = arith.constant 8 : i32
%851 = arith.extsi %850 : i32 to i64
%847 = func.call @calloc(%849, %851) : (i64, i64) -> !llvm.ptr
%852 = llvm.mlir.addressof @G_phi_k1 : !llvm.ptr
llvm.store %847, %852 : !llvm.ptr, !llvm.ptr
%854 = llvm.mlir.addressof @PHI_CAP : !llvm.ptr
%855 = llvm.load %854 : !llvm.ptr -> i64
%856 = arith.constant 8 : i32
%857 = arith.extsi %856 : i32 to i64
%853 = func.call @calloc(%855, %857) : (i64, i64) -> !llvm.ptr
%858 = llvm.mlir.addressof @G_phi_k2 : !llvm.ptr
llvm.store %853, %858 : !llvm.ptr, !llvm.ptr
%860 = llvm.mlir.addressof @PHI_CAP : !llvm.ptr
%861 = llvm.load %860 : !llvm.ptr -> i64
%862 = arith.constant 8 : i32
%863 = arith.extsi %862 : i32 to i64
%859 = func.call @calloc(%861, %863) : (i64, i64) -> !llvm.ptr
%864 = llvm.mlir.addressof @G_phi_v : !llvm.ptr
llvm.store %859, %864 : !llvm.ptr, !llvm.ptr
%866 = llvm.mlir.addressof @PHI_CAP : !llvm.ptr
%867 = llvm.load %866 : !llvm.ptr -> i64
%868 = arith.constant 1 : i32
%869 = arith.extsi %868 : i32 to i64
%865 = func.call @calloc(%867, %869) : (i64, i64) -> !llvm.ptr
%870 = llvm.mlir.addressof @G_phi_u : !llvm.ptr
llvm.store %865, %870 : !llvm.ptr, !llvm.ptr
%872 = llvm.mlir.addressof @S_CAP : !llvm.ptr
%873 = llvm.load %872 : !llvm.ptr -> i64
%874 = arith.constant 8 : i32
%875 = arith.extsi %874 : i32 to i64
%871 = func.call @calloc(%873, %875) : (i64, i64) -> !llvm.ptr
%876 = llvm.mlir.addressof @G_s_k1 : !llvm.ptr
llvm.store %871, %876 : !llvm.ptr, !llvm.ptr
%878 = llvm.mlir.addressof @S_CAP : !llvm.ptr
%879 = llvm.load %878 : !llvm.ptr -> i64
%880 = arith.constant 8 : i32
%881 = arith.extsi %880 : i32 to i64
%877 = func.call @calloc(%879, %881) : (i64, i64) -> !llvm.ptr
%882 = llvm.mlir.addressof @G_s_k2 : !llvm.ptr
llvm.store %877, %882 : !llvm.ptr, !llvm.ptr
%884 = llvm.mlir.addressof @S_CAP : !llvm.ptr
%885 = llvm.load %884 : !llvm.ptr -> i64
%886 = arith.constant 8 : i32
%887 = arith.extsi %886 : i32 to i64
%883 = func.call @calloc(%885, %887) : (i64, i64) -> !llvm.ptr
%888 = llvm.mlir.addressof @G_s_v : !llvm.ptr
llvm.store %883, %888 : !llvm.ptr, !llvm.ptr
%890 = llvm.mlir.addressof @S_CAP : !llvm.ptr
%891 = llvm.load %890 : !llvm.ptr -> i64
%892 = arith.constant 1 : i32
%893 = arith.extsi %892 : i32 to i64
%889 = func.call @calloc(%891, %893) : (i64, i64) -> !llvm.ptr
%894 = llvm.mlir.addressof @G_s_u : !llvm.ptr
llvm.store %889, %894 : !llvm.ptr, !llvm.ptr
%895 = llvm.mlir.zero : !llvm.ptr
%896 = llvm.icmp "eq" %794, %895 : !llvm.ptr
%897 = scf.if %896 -> (i1) {
%898 = arith.constant true
scf.yield %898 : i1
} else {
%899 = llvm.mlir.addressof @G_primes : !llvm.ptr
%900 = llvm.load %899 : !llvm.ptr -> !llvm.ptr
%901 = llvm.mlir.zero : !llvm.ptr
%902 = llvm.icmp "eq" %900, %901 : !llvm.ptr
scf.yield %902 : i1
}
%903 = scf.if %897 -> (i1) {
%904 = arith.constant true
scf.yield %904 : i1
} else {
%905 = llvm.mlir.addressof @G_pi_small : !llvm.ptr
%906 = llvm.load %905 : !llvm.ptr -> !llvm.ptr
%907 = llvm.mlir.zero : !llvm.ptr
%908 = llvm.icmp "eq" %906, %907 : !llvm.ptr
scf.yield %908 : i1
}
%909 = scf.if %903 -> (i1) {
%910 = arith.constant true
scf.yield %910 : i1
} else {
%911 = llvm.mlir.addressof @G_w : !llvm.ptr
%912 = llvm.load %911 : !llvm.ptr -> !llvm.ptr
%913 = llvm.mlir.zero : !llvm.ptr
%914 = llvm.icmp "eq" %912, %913 : !llvm.ptr
scf.yield %914 : i1
}
cf.cond_br %909, ^bb159, ^bb160
^bb159:
%915 = arith.constant 1 : i32
func.return %915 : i32
^bb160:
cf.br ^bb161
^bb161:
%916 = arith.constant 0 : i32
%917 = arith.extsi %916 : i32 to i64
%918 = llvm.mlir.constant(1 : i64) : i64
%919 = llvm.alloca %918 x i64 : (i64) -> !llvm.ptr
llvm.store %917, %919 : i64, !llvm.ptr
cf.br ^bb162
^bb162:
%920 = llvm.load %919 : !llvm.ptr -> i64
%921 = llvm.mlir.addressof @SIEVE_MAX : !llvm.ptr
%922 = llvm.load %921 : !llvm.ptr -> i64
%923 = arith.cmpi sle, %920, %922 : i64
cf.cond_br %923, ^bb163, ^bb164
^bb163:
%924 = arith.constant 1 : i32
%925 = llvm.load %919 : !llvm.ptr -> i64
%926 = arith.trunci %924 : i32 to i8
%927 = llvm.getelementptr %794[%925] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %926, %927 : i8, !llvm.ptr
%928 = llvm.load %919 : !llvm.ptr -> i64
%929 = arith.constant 1 : i32
%931 = arith.extsi %929 : i32 to i64
%930 = arith.addi %928, %931 : i64
llvm.store %930, %919 : i64, !llvm.ptr
cf.br ^bb162
^bb164:
%932 = arith.constant 0 : i32
%933 = arith.constant 0 : i32
%934 = arith.trunci %932 : i32 to i8
%935 = arith.extsi %933 : i32 to i64
%936 = llvm.getelementptr %794[%935] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %934, %936 : i8, !llvm.ptr
%937 = arith.constant 0 : i32
%938 = arith.constant 1 : i32
%939 = arith.trunci %937 : i32 to i8
%940 = arith.extsi %938 : i32 to i64
%941 = llvm.getelementptr %794[%940] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %939, %941 : i8, !llvm.ptr
%942 = arith.constant 2 : i32
%943 = arith.extsi %942 : i32 to i64
llvm.store %943, %919 : i64, !llvm.ptr
cf.br ^bb165
^bb165:
%944 = llvm.load %919 : !llvm.ptr -> i64
%945 = llvm.load %919 : !llvm.ptr -> i64
%946 = arith.muli %944, %945 : i64
%947 = llvm.mlir.addressof @SIEVE_MAX : !llvm.ptr
%948 = llvm.load %947 : !llvm.ptr -> i64
%949 = arith.cmpi sle, %946, %948 : i64
cf.cond_br %949, ^bb166, ^bb167
^bb166:
%951 = llvm.load %919 : !llvm.ptr -> i64
%952 = llvm.getelementptr %794[%951] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%950 = llvm.load %952 : !llvm.ptr -> i8
%953 = arith.constant 0 : i32
%955 = arith.extsi %950 : i8 to i32
%954 = arith.cmpi ne, %955, %953 : i32
cf.cond_br %954, ^bb168, ^bb169
^bb168:
%956 = llvm.load %919 : !llvm.ptr -> i64
%957 = llvm.load %919 : !llvm.ptr -> i64
%958 = arith.muli %956, %957 : i64
%959 = llvm.mlir.constant(1 : i64) : i64
%960 = llvm.alloca %959 x i64 : (i64) -> !llvm.ptr
llvm.store %958, %960 : i64, !llvm.ptr
cf.br ^bb171
^bb171:
%961 = llvm.load %960 : !llvm.ptr -> i64
%962 = llvm.mlir.addressof @SIEVE_MAX : !llvm.ptr
%963 = llvm.load %962 : !llvm.ptr -> i64
%964 = arith.cmpi sle, %961, %963 : i64
cf.cond_br %964, ^bb172, ^bb173
^bb172:
%965 = arith.constant 0 : i32
%966 = llvm.load %960 : !llvm.ptr -> i64
%967 = arith.trunci %965 : i32 to i8
%968 = llvm.getelementptr %794[%966] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %967, %968 : i8, !llvm.ptr
%969 = llvm.load %960 : !llvm.ptr -> i64
%970 = llvm.load %919 : !llvm.ptr -> i64
%971 = arith.addi %969, %970 : i64
llvm.store %971, %960 : i64, !llvm.ptr
cf.br ^bb171
^bb173:
cf.br ^bb170
^bb169:
cf.br ^bb170
^bb170:
%972 = llvm.load %919 : !llvm.ptr -> i64
%973 = arith.constant 1 : i32
%975 = arith.extsi %973 : i32 to i64
%974 = arith.addi %972, %975 : i64
llvm.store %974, %919 : i64, !llvm.ptr
cf.br ^bb165
^bb167:
%976 = arith.constant 0 : i32
%977 = arith.extsi %976 : i32 to i64
%978 = llvm.mlir.constant(1 : i64) : i64
%979 = llvm.alloca %978 x i64 : (i64) -> !llvm.ptr
llvm.store %977, %979 : i64, !llvm.ptr
%980 = arith.constant 0 : i32
%981 = arith.extsi %980 : i32 to i64
llvm.store %981, %919 : i64, !llvm.ptr
cf.br ^bb174
^bb174:
%982 = llvm.load %919 : !llvm.ptr -> i64
%983 = llvm.mlir.addressof @SIEVE_MAX : !llvm.ptr
%984 = llvm.load %983 : !llvm.ptr -> i64
%985 = arith.cmpi sle, %982, %984 : i64
cf.cond_br %985, ^bb175, ^bb176
^bb175:
%987 = llvm.load %919 : !llvm.ptr -> i64
%988 = llvm.getelementptr %794[%987] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%986 = llvm.load %988 : !llvm.ptr -> i8
%989 = arith.constant 0 : i32
%991 = arith.extsi %986 : i8 to i32
%990 = arith.cmpi ne, %991, %989 : i32
cf.cond_br %990, ^bb177, ^bb178
^bb177:
%992 = llvm.load %919 : !llvm.ptr -> i64
%993 = arith.trunci %992 : i64 to i32
%994 = llvm.mlir.addressof @G_primes : !llvm.ptr
%995 = llvm.load %994 : !llvm.ptr -> !llvm.ptr
%996 = llvm.mlir.addressof @G_pc : !llvm.ptr
%997 = llvm.load %996 : !llvm.ptr -> i64
%998 = llvm.getelementptr %995[%997] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %993, %998 : i32, !llvm.ptr
%999 = llvm.mlir.addressof @G_pc : !llvm.ptr
%1000 = llvm.load %999 : !llvm.ptr -> i64
%1001 = arith.constant 1 : i32
%1003 = arith.extsi %1001 : i32 to i64
%1002 = arith.addi %1000, %1003 : i64
%1004 = llvm.mlir.addressof @G_pc : !llvm.ptr
llvm.store %1002, %1004 : i64, !llvm.ptr
%1005 = llvm.load %979 : !llvm.ptr -> i64
%1006 = arith.constant 1 : i32
%1008 = arith.extsi %1006 : i32 to i64
%1007 = arith.addi %1005, %1008 : i64
llvm.store %1007, %979 : i64, !llvm.ptr
cf.br ^bb179
^bb178:
cf.br ^bb179
^bb179:
%1009 = llvm.load %979 : !llvm.ptr -> i64
%1010 = arith.trunci %1009 : i64 to i32
%1011 = llvm.mlir.addressof @G_pi_small : !llvm.ptr
%1012 = llvm.load %1011 : !llvm.ptr -> !llvm.ptr
%1013 = llvm.load %919 : !llvm.ptr -> i64
%1014 = llvm.getelementptr %1012[%1013] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %1010, %1014 : i32, !llvm.ptr
%1015 = llvm.load %919 : !llvm.ptr -> i64
%1016 = arith.constant 1 : i32
%1018 = arith.extsi %1016 : i32 to i64
%1017 = arith.addi %1015, %1018 : i64
llvm.store %1017, %919 : i64, !llvm.ptr
cf.br ^bb174
^bb176:
func.call @free(%794) : (!llvm.ptr) -> ()
%1020 = arith.constant 0 : i32
%1021 = arith.extsi %1020 : i32 to i64
%1022 = llvm.mlir.addressof @G_max_e : !llvm.ptr
llvm.store %1021, %1022 : i64, !llvm.ptr
%1023 = llvm.mlir.addressof @N : !llvm.ptr
%1024 = llvm.load %1023 : !llvm.ptr -> i64
%1025 = llvm.mlir.constant(1 : i64) : i64
%1026 = llvm.alloca %1025 x i64 : (i64) -> !llvm.ptr
llvm.store %1024, %1026 : i64, !llvm.ptr
cf.br ^bb180
^bb180:
%1027 = llvm.load %1026 : !llvm.ptr -> i64
%1028 = arith.constant 1 : i32
%1030 = arith.extsi %1028 : i32 to i64
%1029 = arith.cmpi sgt, %1027, %1030 : i64
cf.cond_br %1029, ^bb181, ^bb182
^bb181:
%1031 = llvm.load %1026 : !llvm.ptr -> i64
%1032 = arith.constant 2 : i32
%1034 = arith.extsi %1032 : i32 to i64
%1033 = arith.divsi %1031, %1034 : i64
llvm.store %1033, %1026 : i64, !llvm.ptr
%1035 = llvm.mlir.addressof @G_max_e : !llvm.ptr
%1036 = llvm.load %1035 : !llvm.ptr -> i64
%1037 = arith.constant 1 : i32
%1039 = arith.extsi %1037 : i32 to i64
%1038 = arith.addi %1036, %1039 : i64
%1040 = llvm.mlir.addressof @G_max_e : !llvm.ptr
llvm.store %1038, %1040 : i64, !llvm.ptr
cf.br ^bb180
^bb182:
%1041 = arith.constant 1 : i32
%1042 = llvm.mlir.addressof @G_w : !llvm.ptr
%1043 = llvm.load %1042 : !llvm.ptr -> !llvm.ptr
%1044 = arith.constant 0 : i32
%1045 = arith.extsi %1041 : i32 to i64
%1046 = arith.extsi %1044 : i32 to i64
%1047 = llvm.getelementptr %1043[%1046] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %1045, %1047 : i64, !llvm.ptr
%1048 = arith.constant 1 : i32
%1049 = arith.extsi %1048 : i32 to i64
%1050 = llvm.mlir.constant(1 : i64) : i64
%1051 = llvm.alloca %1050 x i64 : (i64) -> !llvm.ptr
llvm.store %1049, %1051 : i64, !llvm.ptr
%1052 = arith.constant 1 : i32
%1053 = arith.extsi %1052 : i32 to i64
%1054 = llvm.mlir.constant(1 : i64) : i64
%1055 = llvm.alloca %1054 x i64 : (i64) -> !llvm.ptr
llvm.store %1053, %1055 : i64, !llvm.ptr
cf.br ^bb183
^bb183:
%1056 = llvm.load %1055 : !llvm.ptr -> i64
%1057 = llvm.mlir.addressof @G_max_e : !llvm.ptr
%1058 = llvm.load %1057 : !llvm.ptr -> i64
%1059 = arith.cmpi sle, %1056, %1058 : i64
cf.cond_br %1059, ^bb184, ^bb185
^bb184:
%1060 = llvm.load %1051 : !llvm.ptr -> i64
%1061 = llvm.mlir.addressof @N : !llvm.ptr
%1062 = llvm.load %1061 : !llvm.ptr -> i64
%1063 = llvm.load %1055 : !llvm.ptr -> i64
%1064 = arith.addi %1062, %1063 : i64
%1065 = arith.constant 1 : i32
%1067 = arith.extsi %1065 : i32 to i64
%1066 = arith.subi %1064, %1067 : i64
%1068 = llvm.mlir.addressof @MOD : !llvm.ptr
%1069 = llvm.load %1068 : !llvm.ptr -> i64
%1070 = arith.remsi %1066, %1069 : i64
%1071 = arith.muli %1060, %1070 : i64
%1072 = llvm.mlir.addressof @MOD : !llvm.ptr
%1073 = llvm.load %1072 : !llvm.ptr -> i64
%1074 = arith.remsi %1071, %1073 : i64
llvm.store %1074, %1051 : i64, !llvm.ptr
%1075 = llvm.load %1051 : !llvm.ptr -> i64
%1077 = llvm.load %1055 : !llvm.ptr -> i64
%1078 = llvm.mlir.addressof @MOD : !llvm.ptr
%1079 = llvm.load %1078 : !llvm.ptr -> i64
%1080 = arith.constant 2 : i32
%1082 = arith.extsi %1080 : i32 to i64
%1081 = arith.subi %1079, %1082 : i64
%1083 = llvm.mlir.addressof @MOD : !llvm.ptr
%1084 = llvm.load %1083 : !llvm.ptr -> i64
%1076 = func.call @modpow(%1077, %1081, %1084) : (i64, i64, i64) -> i64
%1085 = arith.muli %1075, %1076 : i64
%1086 = llvm.mlir.addressof @MOD : !llvm.ptr
%1087 = llvm.load %1086 : !llvm.ptr -> i64
%1088 = arith.remsi %1085, %1087 : i64
llvm.store %1088, %1051 : i64, !llvm.ptr
%1089 = llvm.load %1051 : !llvm.ptr -> i64
%1090 = llvm.mlir.addressof @G_w : !llvm.ptr
%1091 = llvm.load %1090 : !llvm.ptr -> !llvm.ptr
%1092 = llvm.load %1055 : !llvm.ptr -> i64
%1093 = llvm.getelementptr %1091[%1092] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %1089, %1093 : i64, !llvm.ptr
%1094 = llvm.load %1055 : !llvm.ptr -> i64
%1095 = arith.constant 1 : i32
%1097 = arith.extsi %1095 : i32 to i64
%1096 = arith.addi %1094, %1097 : i64
llvm.store %1096, %1055 : i64, !llvm.ptr
cf.br ^bb183
^bb185:
%1098 = llvm.mlir.addressof @str_0 : !llvm.ptr
%1100 = llvm.mlir.addressof @N : !llvm.ptr
%1101 = llvm.load %1100 : !llvm.ptr -> i64
%1102 = arith.constant 0 : i32
%1103 = arith.extsi %1102 : i32 to i64
%1099 = func.call @S(%1101, %1103) : (i64, i64) -> i64
%1104 = llvm.call @printf(%1098, %1099) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
%1105 = arith.constant 0 : i32
func.return %1105 : i32
}
}