← All problems
Problem 446
Retractions B, F(10^7) mod 10^9+7. Ported from native C++ to pure Flow.
View problem on Project Euler
Performance comparison
Metric Our solution Best known
Time complexity O(n^2)O(n log n)
Space complexity O(n^2)O(n)
Approach Flow solution Modular DP or matrix exponentiation
Verdict Suboptimal
Flow source
# Project Euler 446
# Retractions B, F(10^7) mod 10^9+7.
# Ported from native C++ to pure Flow.
import euler.nt { isqrt }
extern {
function calloc(n: i64, size: i64) -> ptr<void>
function free(p: ptr<void>) -> void
}
const MOD: i64 = 1000000007
function modpow(a0: i64, e0: i64, mod: i64) -> i64 {
let mut r: i64 = 1 % mod
let mut a: i64 = a0 % mod
let mut e: i64 = e0
while e > 0 {
if e % 2 == 1 { r = r * a % mod }
a = a * a % mod
e = e / 2
}
return r
}
function modinv(a: i64, mod: i64) -> i64 {
return modpow(a, mod - 2, mod)
}
function primes_upto(limit: i64) -> ptr<i32> {
let sieve: ptr<i8> = calloc(limit / 2 + 2, 1) as ptr<i8>
let mut i: i64 = 0
while i < limit / 2 + 2 {
sieve[i] = 1
i = i + 1
}
sieve[0] = 0
let r: i64 = isqrt(limit)
let mut x: i64 = 3
while x <= r {
if sieve[x / 2] == 1 {
let start: i64 = x * x / 2
let mut j: i64 = start
while j < limit / 2 + 2 {
sieve[j] = 0
j = j + x
}
}
x = x + 2
}
# count primes
let mut count: i64 = 1
let mut ii: i64 = 1
while ii < limit / 2 + 2 {
if sieve[ii] == 1 { count = count + 1 }
ii = ii + 1
}
let primes: ptr<i32> = calloc(count, 4) as ptr<i32>
primes[0] = 2
let mut idx: i64 = 1
ii = 1
while ii < limit / 2 + 2 {
if sieve[ii] == 1 {
primes[idx] = (2 * ii + 1) as i32
idx = idx + 1
}
ii = ii + 1
}
free(sieve)
return primes
}
# Returns number of primes stored in the returned array (via out param)
let mut g_p_list: ptr<i32> = null
let mut g_r_list: ptr<i32> = null
let mut g_pcount: i64 = 0
function sqrt_minus_one(p: i64) -> i64 {
let leg: i64 = (p - 1) / 2
let quarter: i64 = (p - 1) / 4
# Try small non-residues first
let mut g: i64 = 2
while g <= 113 {
if g >= p { break }
if modpow(g, leg, p) == p - 1 {
return modpow(g, quarter, p)
}
g = g + 1
}
g = 115
while true {
if modpow(g, leg, p) == p - 1 {
return modpow(g, quarter, p)
}
g = g + 2
}
return 0
}
function build_primes_with_sqrtm1(k_max: i64) -> void {
let all_primes: ptr<i32> = primes_upto(k_max)
# count primes
let mut total: i64 = 0
let mut i: i64 = 0
while i < k_max + 1 {
if all_primes[i] == 0 { break }
total = total + 1
i = i + 1
}
# p=2 is first, then primes p=1 mod 4
g_p_list = calloc(total, 4) as ptr<i32>
g_r_list = calloc(total, 4) as ptr<i32>
g_p_list[0] = 2
g_r_list[0] = 1
g_pcount = 1
i = 1
while i < total {
let p: i64 = all_primes[i] as i64
if p % 4 == 1 {
g_p_list[g_pcount] = p as i32
g_r_list[g_pcount] = sqrt_minus_one(p) as i32
g_pcount = g_pcount + 1
}
i = i + 1
}
free(all_primes)
}
function solve(N: i64) -> i64 {
if N < 1 { return 0 }
let k_max: i64 = N + 1
build_primes_with_sqrtm1(k_max)
let correction_even: i64 = 5 * modpow(9, MOD - 2, MOD) % MOD
let block_size: i64 = 1000000
let mut total: i64 = 0
let mut prev2_P: i64 = -1
let mut prev1_P: i64 = -1
let mut prev2_C: i64 = -1
let mut prev1_C: i64 = -1
let mut L: i64 = 0
while L <= k_max {
let R: i64 = if L + block_size < k_max + 1 { L + block_size } else { k_max + 1 }
let size: i64 = R - L
let rem: ptr<i64> = calloc(size, 8) as ptr<i64>
let prod: ptr<i64> = calloc(size, 8) as ptr<i64>
let cmod: ptr<i64> = calloc(size, 8) as ptr<i64>
let mut k: i64 = L
let mut v: i64 = k * k + 1
let mut i: i64 = 0
while i < size {
rem[i] = v
cmod[i] = v % MOD
prod[i] = 1
v = v + 2 * k + 1
k = k + 1
i = i + 1
}
let mut j: i64 = 0
while j < g_pcount {
let p: i64 = g_p_list[j] as i64
let r: i64 = g_r_list[j] as i64
if p == 2 {
let start: i64 = (1 - L) & 1
let mut idx: i64 = start
while idx < size {
rem[idx] = rem[idx] / 2
prod[idx] = prod[idx] * 3 % MOD
idx = idx + 2
}
} else {
# process root r
let mut start: i64 = ((r - L) % p + p) % p
let mut idx: i64 = start
while idx < size {
let mut x: i64 = rem[idx] / p
let mut pe: i64 = p
while x % p == 0 {
x = x / p
pe = pe * p
}
rem[idx] = x
let mut t: i64 = pe + 1
if t >= MOD { t = t % MOD }
prod[idx] = prod[idx] * t % MOD
idx = idx + p
}
# process root p - r
start = ((p - r - L) % p + p) % p
idx = start
while idx < size {
let mut x: i64 = rem[idx] / p
let mut pe: i64 = p
while x % p == 0 {
x = x / p
pe = pe * p
}
rem[idx] = x
let mut t: i64 = pe + 1
if t >= MOD { t = t % MOD }
prod[idx] = prod[idx] * t % MOD
idx = idx + p
}
}
j = j + 1
}
i = 0
while i < size {
if rem[i] > 1 {
let mut t: i64 = rem[i] + 1
if t >= MOD { t = t % MOD }
prod[i] = prod[i] * t % MOD
}
i = i + 1
}
i = 0
while i < size {
let kk: i64 = L + i
let Pk: i64 = prod[i]
let Ck: i64 = cmod[i]
if prev2_P >= 0 {
let n: i64 = kk - 1
if n <= N {
let mut pm: i64 = prev2_P * Pk % MOD
if n % 2 == 0 { pm = pm * correction_even % MOD }
let mm: i64 = prev2_C * Ck % MOD
total = (total + pm - mm) % MOD
if total < 0 { total = total + MOD }
}
}
prev2_P = prev1_P
prev1_P = Pk
prev2_C = prev1_C
prev1_C = Ck
i = i + 1
}
free(rem)
free(prod)
free(cmod)
L = L + block_size
}
free(g_p_list)
free(g_r_list)
return total % MOD
}
function main() -> i32 {
printf("%lld\n", solve(10000000))
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 a0, int64_t e0, int64_t mod);
int64_t modinv_i64_i64(int64_t a, int64_t mod);
int32_t* primes_upto_i64(int64_t limit);
int64_t sqrt_minus_one_i64(int64_t p);
void build_primes_with_sqrtm1_i64(int64_t k_max);
int64_t solve_i64(int64_t N);
int32_t main(void);
static const int64_t MOD = 1000000007;
/* Module statics */
static int32_t* g_p_list = NULL;
static int32_t* g_r_list = NULL;
static int64_t g_pcount = 0;
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 a0, int64_t e0, int64_t mod) {
int64_t r = FLOW_CHECKED_MOD((1), (mod));
int64_t a = FLOW_CHECKED_MOD((a0), (mod));
int64_t e = e0;
while (e > 0) {
if (FLOW_CHECKED_MOD((e), (2)) == 1) {
r = FLOW_CHECKED_MOD(((r * a)), (mod));
}
a = FLOW_CHECKED_MOD(((a * a)), (mod));
e = FLOW_CHECKED_DIV((e), (2));
}
return r;
}
int64_t modinv_i64_i64(int64_t a, int64_t mod) {
return modpow_i64_i64_i64(a, (mod - 2), mod);
}
int32_t* primes_upto_i64(int64_t limit) {
int8_t* sieve = (int8_t*)(((int8_t*)(calloc((FLOW_CHECKED_DIV((limit), (2)) + 2), 1))));
int64_t i = 0;
while (i < (FLOW_CHECKED_DIV((limit), (2)) + 2)) {
sieve[i] = 1;
i = (i + 1);
}
sieve[0] = 0;
int64_t r = isqrt_i64(limit);
int64_t x = 3;
while (x <= r) {
if (sieve[FLOW_CHECKED_DIV((x), (2))] == 1) {
int64_t start = FLOW_CHECKED_DIV(((x * x)), (2));
int64_t j = start;
while (j < (FLOW_CHECKED_DIV((limit), (2)) + 2)) {
sieve[j] = 0;
j = (j + x);
}
}
x = (x + 2);
}
int64_t count = 1;
int64_t ii = 1;
while (ii < (FLOW_CHECKED_DIV((limit), (2)) + 2)) {
if (sieve[ii] == 1) {
count = (count + 1);
}
ii = (ii + 1);
}
int32_t* primes = (int32_t*)(((int32_t*)(calloc(count, 4))));
primes[0] = 2;
int64_t idx = 1;
ii = 1;
while (ii < (FLOW_CHECKED_DIV((limit), (2)) + 2)) {
if (sieve[ii] == 1) {
primes[idx] = ((int32_t)(((2 * ii) + 1)));
idx = (idx + 1);
}
ii = (ii + 1);
}
free(sieve);
return primes;
}
int64_t sqrt_minus_one_i64(int64_t p) {
int64_t leg = FLOW_CHECKED_DIV(((p - 1)), (2));
int64_t quarter = FLOW_CHECKED_DIV(((p - 1)), (4));
int64_t g = 2;
while (g <= 113) {
if (g >= p) {
break;
}
if (modpow_i64_i64_i64(g, leg, p) == (p - 1)) {
return modpow_i64_i64_i64(g, quarter, p);
}
g = (g + 1);
}
g = 115;
while (1) {
if (modpow_i64_i64_i64(g, leg, p) == (p - 1)) {
return modpow_i64_i64_i64(g, quarter, p);
}
g = (g + 2);
}
return 0;
}
void build_primes_with_sqrtm1_i64(int64_t k_max) {
int32_t* all_primes = (int32_t*)(primes_upto_i64(k_max));
int64_t total = 0;
int64_t i = 0;
while (i < (k_max + 1)) {
if (all_primes[i] == 0) {
break;
}
total = (total + 1);
i = (i + 1);
}
g_p_list = ((int32_t*)(calloc(total, 4)));
g_r_list = ((int32_t*)(calloc(total, 4)));
g_p_list[0] = 2;
g_r_list[0] = 1;
g_pcount = 1;
i = 1;
while (i < total) {
int64_t p = ((int64_t)(all_primes[i]));
if (FLOW_CHECKED_MOD((p), (4)) == 1) {
g_p_list[g_pcount] = ((int32_t)(p));
g_r_list[g_pcount] = ((int32_t)(sqrt_minus_one_i64(p)));
g_pcount = (g_pcount + 1);
}
i = (i + 1);
}
free(all_primes);
}
int64_t solve_i64(int64_t N) {
if (N < 1) {
return 0;
}
int64_t k_max = (N + 1);
build_primes_with_sqrtm1_i64(k_max);
int64_t correction_even = FLOW_CHECKED_MOD(((5 * modpow_i64_i64_i64(9, (MOD - 2), MOD))), (MOD));
int64_t block_size = 1000000;
int64_t total = 0;
int64_t prev2_P = (-1);
int64_t prev1_P = (-1);
int64_t prev2_C = (-1);
int64_t prev1_C = (-1);
int64_t L = 0;
while (L <= k_max) {
int64_t R = (((L + block_size) < (k_max + 1)) ? ((L + block_size)) : ((k_max + 1)));
int64_t size = (R - L);
int64_t* rem = (int64_t*)(((int64_t*)(calloc(size, 8))));
int64_t* prod = (int64_t*)(((int64_t*)(calloc(size, 8))));
int64_t* cmod = (int64_t*)(((int64_t*)(calloc(size, 8))));
int64_t k = L;
int64_t v = ((k * k) + 1);
int64_t i = 0;
while (i < size) {
rem[i] = v;
cmod[i] = FLOW_CHECKED_MOD((v), (MOD));
prod[i] = 1;
v = ((v + (2 * k)) + 1);
k = (k + 1);
i = (i + 1);
}
int64_t j = 0;
while (j < g_pcount) {
int64_t p = ((int64_t)(g_p_list[j]));
int64_t r = ((int64_t)(g_r_list[j]));
if (p == 2) {
int64_t start = ((1 - L) & 1);
int64_t idx = start;
while (idx < size) {
rem[idx] = FLOW_CHECKED_DIV((rem[idx]), (2));
prod[idx] = FLOW_CHECKED_MOD(((prod[idx] * 3)), (MOD));
idx = (idx + 2);
}
} else {
int64_t start = FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD(((r - L)), (p)) + p)), (p));
int64_t idx = start;
while (idx < size) {
int64_t x = FLOW_CHECKED_DIV((rem[idx]), (p));
int64_t pe = p;
while (FLOW_CHECKED_MOD((x), (p)) == 0) {
x = FLOW_CHECKED_DIV((x), (p));
pe = (pe * p);
}
rem[idx] = x;
int64_t t = (pe + 1);
if (t >= MOD) {
t = FLOW_CHECKED_MOD((t), (MOD));
}
prod[idx] = FLOW_CHECKED_MOD(((prod[idx] * t)), (MOD));
idx = (idx + p);
}
start = FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD((((p - r) - L)), (p)) + p)), (p));
idx = start;
while (idx < size) {
int64_t x = FLOW_CHECKED_DIV((rem[idx]), (p));
int64_t pe = p;
while (FLOW_CHECKED_MOD((x), (p)) == 0) {
x = FLOW_CHECKED_DIV((x), (p));
pe = (pe * p);
}
rem[idx] = x;
int64_t t = (pe + 1);
if (t >= MOD) {
t = FLOW_CHECKED_MOD((t), (MOD));
}
prod[idx] = FLOW_CHECKED_MOD(((prod[idx] * t)), (MOD));
idx = (idx + p);
}
}
j = (j + 1);
}
i = 0;
while (i < size) {
if (rem[i] > 1) {
int64_t t = (rem[i] + 1);
if (t >= MOD) {
t = FLOW_CHECKED_MOD((t), (MOD));
}
prod[i] = FLOW_CHECKED_MOD(((prod[i] * t)), (MOD));
}
i = (i + 1);
}
i = 0;
while (i < size) {
int64_t kk = (L + i);
int64_t Pk = prod[i];
int64_t Ck = cmod[i];
if (prev2_P >= 0) {
int64_t n = (kk - 1);
if (n <= N) {
int64_t pm = FLOW_CHECKED_MOD(((prev2_P * Pk)), (MOD));
if (FLOW_CHECKED_MOD((n), (2)) == 0) {
pm = FLOW_CHECKED_MOD(((pm * correction_even)), (MOD));
}
int64_t mm = FLOW_CHECKED_MOD(((prev2_C * Ck)), (MOD));
total = FLOW_CHECKED_MOD((((total + pm) - mm)), (MOD));
if (total < 0) {
total = (total + MOD);
}
}
}
prev2_P = prev1_P;
prev1_P = Pk;
prev2_C = prev1_C;
prev1_C = Ck;
i = (i + 1);
}
free(rem);
free(prod);
free(cmod);
L = (L + block_size);
}
free(g_p_list);
free(g_r_list);
return FLOW_CHECKED_MOD((total), (MOD));
}
int32_t main(void) {
printf("%lld\n", solve_i64(10000000));
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(1000000007 : i64) : i64
func.func @modpow(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
%175 = arith.constant 1 : i32
%177 = arith.extsi %175 : i32 to i64
%176 = arith.remsi %177, %arg2 : i64
%178 = llvm.mlir.constant(1 : i64) : i64
%179 = llvm.alloca %178 x i64 : (i64) -> !llvm.ptr
llvm.store %176, %179 : i64, !llvm.ptr
%180 = arith.remsi %arg0, %arg2 : i64
%181 = llvm.mlir.constant(1 : i64) : i64
%182 = llvm.alloca %181 x i64 : (i64) -> !llvm.ptr
llvm.store %180, %182 : i64, !llvm.ptr
%183 = llvm.mlir.constant(1 : i64) : i64
%184 = llvm.alloca %183 x i64 : (i64) -> !llvm.ptr
llvm.store %arg1, %184 : i64, !llvm.ptr
cf.br ^bb42
^bb42:
%185 = llvm.load %184 : !llvm.ptr -> i64
%186 = arith.constant 0 : i32
%188 = arith.extsi %186 : i32 to i64
%187 = arith.cmpi sgt, %185, %188 : i64
cf.cond_br %187, ^bb43, ^bb44
^bb43:
%189 = llvm.load %184 : !llvm.ptr -> i64
%190 = arith.constant 2 : i32
%192 = arith.extsi %190 : i32 to i64
%191 = arith.remsi %189, %192 : i64
%193 = arith.constant 1 : i32
%195 = arith.extsi %193 : i32 to i64
%194 = arith.cmpi eq, %191, %195 : i64
cf.cond_br %194, ^bb45, ^bb46
^bb45:
%196 = llvm.load %179 : !llvm.ptr -> i64
%197 = llvm.load %182 : !llvm.ptr -> i64
%198 = arith.muli %196, %197 : i64
%199 = arith.remsi %198, %arg2 : i64
llvm.store %199, %179 : i64, !llvm.ptr
cf.br ^bb47
^bb46:
cf.br ^bb47
^bb47:
%200 = llvm.load %182 : !llvm.ptr -> i64
%201 = llvm.load %182 : !llvm.ptr -> i64
%202 = arith.muli %200, %201 : i64
%203 = arith.remsi %202, %arg2 : i64
llvm.store %203, %182 : i64, !llvm.ptr
%204 = llvm.load %184 : !llvm.ptr -> i64
%205 = arith.constant 2 : i32
%207 = arith.extsi %205 : i32 to i64
%206 = arith.divsi %204, %207 : i64
llvm.store %206, %184 : i64, !llvm.ptr
cf.br ^bb42
^bb44:
%208 = llvm.load %179 : !llvm.ptr -> i64
func.return %208 : i64
}
func.func @modinv(%arg0: i64, %arg1: i64) -> i64 {
%210 = arith.constant 2 : i32
%212 = arith.extsi %210 : i32 to i64
%211 = arith.subi %arg1, %212 : i64
%209 = func.call @modpow(%arg0, %211, %arg1) : (i64, i64, i64) -> i64
func.return %209 : i64
}
func.func @primes_upto(%arg0: i64) -> !llvm.ptr {
%214 = arith.constant 2 : i32
%216 = arith.extsi %214 : i32 to i64
%215 = arith.divsi %arg0, %216 : i64
%217 = arith.constant 2 : i32
%219 = arith.extsi %217 : i32 to i64
%218 = arith.addi %215, %219 : i64
%220 = arith.constant 1 : i32
%221 = arith.extsi %220 : i32 to i64
%213 = func.call @calloc(%218, %221) : (i64, i64) -> !llvm.ptr
%222 = arith.constant 0 : i32
%223 = arith.extsi %222 : i32 to i64
%224 = llvm.mlir.constant(1 : i64) : i64
%225 = llvm.alloca %224 x i64 : (i64) -> !llvm.ptr
llvm.store %223, %225 : i64, !llvm.ptr
cf.br ^bb48
^bb48:
%226 = llvm.load %225 : !llvm.ptr -> i64
%227 = arith.constant 2 : i32
%229 = arith.extsi %227 : i32 to i64
%228 = arith.divsi %arg0, %229 : i64
%230 = arith.constant 2 : i32
%232 = arith.extsi %230 : i32 to i64
%231 = arith.addi %228, %232 : i64
%233 = arith.cmpi slt, %226, %231 : i64
cf.cond_br %233, ^bb49, ^bb50
^bb49:
%234 = arith.constant 1 : i32
%235 = llvm.load %225 : !llvm.ptr -> i64
%236 = arith.trunci %234 : i32 to i8
%237 = llvm.getelementptr %213[%235] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %236, %237 : i8, !llvm.ptr
%238 = llvm.load %225 : !llvm.ptr -> i64
%239 = arith.constant 1 : i32
%241 = arith.extsi %239 : i32 to i64
%240 = arith.addi %238, %241 : i64
llvm.store %240, %225 : i64, !llvm.ptr
cf.br ^bb48
^bb50:
%242 = arith.constant 0 : i32
%243 = arith.constant 0 : i32
%244 = arith.trunci %242 : i32 to i8
%245 = arith.extsi %243 : i32 to i64
%246 = llvm.getelementptr %213[%245] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %244, %246 : i8, !llvm.ptr
%247 = func.call @isqrt(%arg0) : (i64) -> i64
%248 = arith.constant 3 : i32
%249 = arith.extsi %248 : i32 to i64
%250 = llvm.mlir.constant(1 : i64) : i64
%251 = llvm.alloca %250 x i64 : (i64) -> !llvm.ptr
llvm.store %249, %251 : i64, !llvm.ptr
cf.br ^bb51
^bb51:
%252 = llvm.load %251 : !llvm.ptr -> i64
%253 = arith.cmpi sle, %252, %247 : i64
cf.cond_br %253, ^bb52, ^bb53
^bb52:
%255 = llvm.load %251 : !llvm.ptr -> i64
%256 = arith.constant 2 : i32
%258 = arith.extsi %256 : i32 to i64
%257 = arith.divsi %255, %258 : i64
%259 = llvm.getelementptr %213[%257] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%254 = llvm.load %259 : !llvm.ptr -> i8
%260 = arith.constant 1 : i32
%262 = arith.extsi %254 : i8 to i32
%261 = arith.cmpi eq, %262, %260 : i32
cf.cond_br %261, ^bb54, ^bb55
^bb54:
%263 = llvm.load %251 : !llvm.ptr -> i64
%264 = llvm.load %251 : !llvm.ptr -> i64
%265 = arith.muli %263, %264 : i64
%266 = arith.constant 2 : i32
%268 = arith.extsi %266 : i32 to i64
%267 = arith.divsi %265, %268 : i64
%269 = llvm.mlir.constant(1 : i64) : i64
%270 = llvm.alloca %269 x i64 : (i64) -> !llvm.ptr
llvm.store %267, %270 : i64, !llvm.ptr
cf.br ^bb57
^bb57:
%271 = llvm.load %270 : !llvm.ptr -> i64
%272 = arith.constant 2 : i32
%274 = arith.extsi %272 : i32 to i64
%273 = arith.divsi %arg0, %274 : i64
%275 = arith.constant 2 : i32
%277 = arith.extsi %275 : i32 to i64
%276 = arith.addi %273, %277 : i64
%278 = arith.cmpi slt, %271, %276 : i64
cf.cond_br %278, ^bb58, ^bb59
^bb58:
%279 = arith.constant 0 : i32
%280 = llvm.load %270 : !llvm.ptr -> i64
%281 = arith.trunci %279 : i32 to i8
%282 = llvm.getelementptr %213[%280] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %281, %282 : i8, !llvm.ptr
%283 = llvm.load %270 : !llvm.ptr -> i64
%284 = llvm.load %251 : !llvm.ptr -> i64
%285 = arith.addi %283, %284 : i64
llvm.store %285, %270 : i64, !llvm.ptr
cf.br ^bb57
^bb59:
cf.br ^bb56
^bb55:
cf.br ^bb56
^bb56:
%286 = llvm.load %251 : !llvm.ptr -> i64
%287 = arith.constant 2 : i32
%289 = arith.extsi %287 : i32 to i64
%288 = arith.addi %286, %289 : i64
llvm.store %288, %251 : i64, !llvm.ptr
cf.br ^bb51
^bb53:
%290 = arith.constant 1 : i32
%291 = arith.extsi %290 : i32 to i64
%292 = llvm.mlir.constant(1 : i64) : i64
%293 = llvm.alloca %292 x i64 : (i64) -> !llvm.ptr
llvm.store %291, %293 : i64, !llvm.ptr
%294 = arith.constant 1 : i32
%295 = arith.extsi %294 : i32 to i64
%296 = llvm.mlir.constant(1 : i64) : i64
%297 = llvm.alloca %296 x i64 : (i64) -> !llvm.ptr
llvm.store %295, %297 : i64, !llvm.ptr
cf.br ^bb60
^bb60:
%298 = llvm.load %297 : !llvm.ptr -> i64
%299 = arith.constant 2 : i32
%301 = arith.extsi %299 : i32 to i64
%300 = arith.divsi %arg0, %301 : i64
%302 = arith.constant 2 : i32
%304 = arith.extsi %302 : i32 to i64
%303 = arith.addi %300, %304 : i64
%305 = arith.cmpi slt, %298, %303 : i64
cf.cond_br %305, ^bb61, ^bb62
^bb61:
%307 = llvm.load %297 : !llvm.ptr -> i64
%308 = llvm.getelementptr %213[%307] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%306 = llvm.load %308 : !llvm.ptr -> i8
%309 = arith.constant 1 : i32
%311 = arith.extsi %306 : i8 to i32
%310 = arith.cmpi eq, %311, %309 : i32
cf.cond_br %310, ^bb63, ^bb64
^bb63:
%312 = llvm.load %293 : !llvm.ptr -> i64
%313 = arith.constant 1 : i32
%315 = arith.extsi %313 : i32 to i64
%314 = arith.addi %312, %315 : i64
llvm.store %314, %293 : i64, !llvm.ptr
cf.br ^bb65
^bb64:
cf.br ^bb65
^bb65:
%316 = llvm.load %297 : !llvm.ptr -> i64
%317 = arith.constant 1 : i32
%319 = arith.extsi %317 : i32 to i64
%318 = arith.addi %316, %319 : i64
llvm.store %318, %297 : i64, !llvm.ptr
cf.br ^bb60
^bb62:
%321 = llvm.load %293 : !llvm.ptr -> i64
%322 = arith.constant 4 : i32
%323 = arith.extsi %322 : i32 to i64
%320 = func.call @calloc(%321, %323) : (i64, i64) -> !llvm.ptr
%324 = arith.constant 2 : i32
%325 = arith.constant 0 : i32
%326 = arith.extsi %325 : i32 to i64
%327 = llvm.getelementptr %320[%326] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %324, %327 : i32, !llvm.ptr
%328 = arith.constant 1 : i32
%329 = arith.extsi %328 : i32 to i64
%330 = llvm.mlir.constant(1 : i64) : i64
%331 = llvm.alloca %330 x i64 : (i64) -> !llvm.ptr
llvm.store %329, %331 : i64, !llvm.ptr
%332 = arith.constant 1 : i32
%333 = arith.extsi %332 : i32 to i64
llvm.store %333, %297 : i64, !llvm.ptr
cf.br ^bb66
^bb66:
%334 = llvm.load %297 : !llvm.ptr -> i64
%335 = arith.constant 2 : i32
%337 = arith.extsi %335 : i32 to i64
%336 = arith.divsi %arg0, %337 : i64
%338 = arith.constant 2 : i32
%340 = arith.extsi %338 : i32 to i64
%339 = arith.addi %336, %340 : i64
%341 = arith.cmpi slt, %334, %339 : i64
cf.cond_br %341, ^bb67, ^bb68
^bb67:
%343 = llvm.load %297 : !llvm.ptr -> i64
%344 = llvm.getelementptr %213[%343] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%342 = llvm.load %344 : !llvm.ptr -> i8
%345 = arith.constant 1 : i32
%347 = arith.extsi %342 : i8 to i32
%346 = arith.cmpi eq, %347, %345 : i32
cf.cond_br %346, ^bb69, ^bb70
^bb69:
%348 = arith.constant 2 : i32
%349 = llvm.load %297 : !llvm.ptr -> i64
%351 = arith.extsi %348 : i32 to i64
%350 = arith.muli %351, %349 : i64
%352 = arith.constant 1 : i32
%354 = arith.extsi %352 : i32 to i64
%353 = arith.addi %350, %354 : i64
%355 = arith.trunci %353 : i64 to i32
%356 = llvm.load %331 : !llvm.ptr -> i64
%357 = llvm.getelementptr %320[%356] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %355, %357 : i32, !llvm.ptr
%358 = llvm.load %331 : !llvm.ptr -> i64
%359 = arith.constant 1 : i32
%361 = arith.extsi %359 : i32 to i64
%360 = arith.addi %358, %361 : i64
llvm.store %360, %331 : i64, !llvm.ptr
cf.br ^bb71
^bb70:
cf.br ^bb71
^bb71:
%362 = llvm.load %297 : !llvm.ptr -> i64
%363 = arith.constant 1 : i32
%365 = arith.extsi %363 : i32 to i64
%364 = arith.addi %362, %365 : i64
llvm.store %364, %297 : i64, !llvm.ptr
cf.br ^bb66
^bb68:
func.call @free(%213) : (!llvm.ptr) -> ()
func.return %320 : !llvm.ptr
}
// Module static: g_p_list
llvm.mlir.global internal @g_p_list() {addr_space = 0 : i32} : !llvm.ptr {
%367 = llvm.mlir.zero : !llvm.ptr
llvm.return %367 : !llvm.ptr
}
// Module static: g_r_list
llvm.mlir.global internal @g_r_list() {addr_space = 0 : i32} : !llvm.ptr {
%368 = llvm.mlir.zero : !llvm.ptr
llvm.return %368 : !llvm.ptr
}
// Module static: g_pcount
llvm.mlir.global internal @g_pcount(0 : i64) : i64
func.func @sqrt_minus_one(%arg0: i64) -> i64 {
%369 = arith.constant 1 : i32
%371 = arith.extsi %369 : i32 to i64
%370 = arith.subi %arg0, %371 : i64
%372 = arith.constant 2 : i32
%374 = arith.extsi %372 : i32 to i64
%373 = arith.divsi %370, %374 : i64
%375 = arith.constant 1 : i32
%377 = arith.extsi %375 : i32 to i64
%376 = arith.subi %arg0, %377 : i64
%378 = arith.constant 4 : i32
%380 = arith.extsi %378 : i32 to i64
%379 = arith.divsi %376, %380 : i64
%381 = arith.constant 2 : i32
%382 = arith.extsi %381 : i32 to i64
%383 = llvm.mlir.constant(1 : i64) : i64
%384 = llvm.alloca %383 x i64 : (i64) -> !llvm.ptr
llvm.store %382, %384 : i64, !llvm.ptr
cf.br ^bb72
^bb72:
%385 = llvm.load %384 : !llvm.ptr -> i64
%386 = arith.constant 113 : i32
%388 = arith.extsi %386 : i32 to i64
%387 = arith.cmpi sle, %385, %388 : i64
cf.cond_br %387, ^bb73, ^bb74
^bb73:
%389 = llvm.load %384 : !llvm.ptr -> i64
%390 = arith.cmpi sge, %389, %arg0 : i64
cf.cond_br %390, ^bb75, ^bb76
^bb75:
cf.br ^bb74
^bb76:
cf.br ^bb77
^bb77:
%392 = llvm.load %384 : !llvm.ptr -> i64
%391 = func.call @modpow(%392, %373, %arg0) : (i64, i64, i64) -> i64
%393 = arith.constant 1 : i32
%395 = arith.extsi %393 : i32 to i64
%394 = arith.subi %arg0, %395 : i64
%396 = arith.cmpi eq, %391, %394 : i64
cf.cond_br %396, ^bb78, ^bb79
^bb78:
%398 = llvm.load %384 : !llvm.ptr -> i64
%397 = func.call @modpow(%398, %379, %arg0) : (i64, i64, i64) -> i64
func.return %397 : i64
^bb79:
cf.br ^bb80
^bb80:
%399 = llvm.load %384 : !llvm.ptr -> i64
%400 = arith.constant 1 : i32
%402 = arith.extsi %400 : i32 to i64
%401 = arith.addi %399, %402 : i64
llvm.store %401, %384 : i64, !llvm.ptr
cf.br ^bb72
^bb74:
%403 = arith.constant 115 : i32
%404 = arith.extsi %403 : i32 to i64
llvm.store %404, %384 : i64, !llvm.ptr
cf.br ^bb81
^bb81:
%405 = arith.constant 1 : i1
cf.cond_br %405, ^bb82, ^bb83
^bb82:
%407 = llvm.load %384 : !llvm.ptr -> i64
%406 = func.call @modpow(%407, %373, %arg0) : (i64, i64, i64) -> i64
%408 = arith.constant 1 : i32
%410 = arith.extsi %408 : i32 to i64
%409 = arith.subi %arg0, %410 : i64
%411 = arith.cmpi eq, %406, %409 : i64
cf.cond_br %411, ^bb84, ^bb85
^bb84:
%413 = llvm.load %384 : !llvm.ptr -> i64
%412 = func.call @modpow(%413, %379, %arg0) : (i64, i64, i64) -> i64
func.return %412 : i64
^bb85:
cf.br ^bb86
^bb86:
%414 = llvm.load %384 : !llvm.ptr -> i64
%415 = arith.constant 2 : i32
%417 = arith.extsi %415 : i32 to i64
%416 = arith.addi %414, %417 : i64
llvm.store %416, %384 : i64, !llvm.ptr
cf.br ^bb81
^bb83:
%418 = arith.constant 0 : i32
%419 = arith.extsi %418 : i32 to i64
func.return %419 : i64
}
func.func @build_primes_with_sqrtm1(%arg0: i64) -> () {
%420 = func.call @primes_upto(%arg0) : (i64) -> !llvm.ptr
%421 = arith.constant 0 : i32
%422 = arith.extsi %421 : i32 to i64
%423 = llvm.mlir.constant(1 : i64) : i64
%424 = llvm.alloca %423 x i64 : (i64) -> !llvm.ptr
llvm.store %422, %424 : i64, !llvm.ptr
%425 = arith.constant 0 : i32
%426 = arith.extsi %425 : i32 to i64
%427 = llvm.mlir.constant(1 : i64) : i64
%428 = llvm.alloca %427 x i64 : (i64) -> !llvm.ptr
llvm.store %426, %428 : i64, !llvm.ptr
cf.br ^bb87
^bb87:
%429 = llvm.load %428 : !llvm.ptr -> i64
%430 = arith.constant 1 : i32
%432 = arith.extsi %430 : i32 to i64
%431 = arith.addi %arg0, %432 : i64
%433 = arith.cmpi slt, %429, %431 : i64
cf.cond_br %433, ^bb88, ^bb89
^bb88:
%435 = llvm.load %428 : !llvm.ptr -> i64
%436 = llvm.getelementptr %420[%435] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%434 = llvm.load %436 : !llvm.ptr -> i32
%437 = arith.constant 0 : i32
%438 = arith.cmpi eq, %434, %437 : i32
cf.cond_br %438, ^bb90, ^bb91
^bb90:
cf.br ^bb89
^bb91:
cf.br ^bb92
^bb92:
%439 = llvm.load %424 : !llvm.ptr -> i64
%440 = arith.constant 1 : i32
%442 = arith.extsi %440 : i32 to i64
%441 = arith.addi %439, %442 : i64
llvm.store %441, %424 : i64, !llvm.ptr
%443 = llvm.load %428 : !llvm.ptr -> i64
%444 = arith.constant 1 : i32
%446 = arith.extsi %444 : i32 to i64
%445 = arith.addi %443, %446 : i64
llvm.store %445, %428 : i64, !llvm.ptr
cf.br ^bb87
^bb89:
%448 = llvm.load %424 : !llvm.ptr -> i64
%449 = arith.constant 4 : i32
%450 = arith.extsi %449 : i32 to i64
%447 = func.call @calloc(%448, %450) : (i64, i64) -> !llvm.ptr
%451 = llvm.mlir.addressof @g_p_list : !llvm.ptr
llvm.store %447, %451 : !llvm.ptr, !llvm.ptr
%453 = llvm.load %424 : !llvm.ptr -> i64
%454 = arith.constant 4 : i32
%455 = arith.extsi %454 : i32 to i64
%452 = func.call @calloc(%453, %455) : (i64, i64) -> !llvm.ptr
%456 = llvm.mlir.addressof @g_r_list : !llvm.ptr
llvm.store %452, %456 : !llvm.ptr, !llvm.ptr
%457 = arith.constant 2 : i32
%458 = llvm.mlir.addressof @g_p_list : !llvm.ptr
%459 = llvm.load %458 : !llvm.ptr -> !llvm.ptr
%460 = arith.constant 0 : i32
%461 = arith.extsi %460 : i32 to i64
%462 = llvm.getelementptr %459[%461] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %457, %462 : i32, !llvm.ptr
%463 = arith.constant 1 : i32
%464 = llvm.mlir.addressof @g_r_list : !llvm.ptr
%465 = llvm.load %464 : !llvm.ptr -> !llvm.ptr
%466 = arith.constant 0 : i32
%467 = arith.extsi %466 : i32 to i64
%468 = llvm.getelementptr %465[%467] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %463, %468 : i32, !llvm.ptr
%469 = arith.constant 1 : i32
%470 = arith.extsi %469 : i32 to i64
%471 = llvm.mlir.addressof @g_pcount : !llvm.ptr
llvm.store %470, %471 : i64, !llvm.ptr
%472 = arith.constant 1 : i32
%473 = arith.extsi %472 : i32 to i64
llvm.store %473, %428 : i64, !llvm.ptr
cf.br ^bb93
^bb93:
%474 = llvm.load %428 : !llvm.ptr -> i64
%475 = llvm.load %424 : !llvm.ptr -> i64
%476 = arith.cmpi slt, %474, %475 : i64
cf.cond_br %476, ^bb94, ^bb95
^bb94:
%478 = llvm.load %428 : !llvm.ptr -> i64
%479 = llvm.getelementptr %420[%478] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%477 = llvm.load %479 : !llvm.ptr -> i32
%480 = arith.extsi %477 : i32 to i64
%481 = arith.constant 4 : i32
%483 = arith.extsi %481 : i32 to i64
%482 = arith.remsi %480, %483 : i64
%484 = arith.constant 1 : i32
%486 = arith.extsi %484 : i32 to i64
%485 = arith.cmpi eq, %482, %486 : i64
cf.cond_br %485, ^bb96, ^bb97
^bb96:
%487 = arith.trunci %480 : i64 to i32
%488 = llvm.mlir.addressof @g_p_list : !llvm.ptr
%489 = llvm.load %488 : !llvm.ptr -> !llvm.ptr
%490 = llvm.mlir.addressof @g_pcount : !llvm.ptr
%491 = llvm.load %490 : !llvm.ptr -> i64
%492 = llvm.getelementptr %489[%491] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %487, %492 : i32, !llvm.ptr
%493 = func.call @sqrt_minus_one(%480) : (i64) -> i64
%494 = arith.trunci %493 : i64 to i32
%495 = llvm.mlir.addressof @g_r_list : !llvm.ptr
%496 = llvm.load %495 : !llvm.ptr -> !llvm.ptr
%497 = llvm.mlir.addressof @g_pcount : !llvm.ptr
%498 = llvm.load %497 : !llvm.ptr -> i64
%499 = llvm.getelementptr %496[%498] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %494, %499 : i32, !llvm.ptr
%500 = llvm.mlir.addressof @g_pcount : !llvm.ptr
%501 = llvm.load %500 : !llvm.ptr -> i64
%502 = arith.constant 1 : i32
%504 = arith.extsi %502 : i32 to i64
%503 = arith.addi %501, %504 : i64
%505 = llvm.mlir.addressof @g_pcount : !llvm.ptr
llvm.store %503, %505 : i64, !llvm.ptr
cf.br ^bb98
^bb97:
cf.br ^bb98
^bb98:
%506 = llvm.load %428 : !llvm.ptr -> i64
%507 = arith.constant 1 : i32
%509 = arith.extsi %507 : i32 to i64
%508 = arith.addi %506, %509 : i64
llvm.store %508, %428 : i64, !llvm.ptr
cf.br ^bb93
^bb95:
func.call @free(%420) : (!llvm.ptr) -> ()
func.return
}
func.func @solve(%arg0: i64) -> i64 {
%511 = arith.constant 1 : i32
%513 = arith.extsi %511 : i32 to i64
%512 = arith.cmpi slt, %arg0, %513 : i64
cf.cond_br %512, ^bb99, ^bb100
^bb99:
%514 = arith.constant 0 : i32
%515 = arith.extsi %514 : i32 to i64
func.return %515 : i64
^bb100:
cf.br ^bb101
^bb101:
%516 = arith.constant 1 : i32
%518 = arith.extsi %516 : i32 to i64
%517 = arith.addi %arg0, %518 : i64
func.call @build_primes_with_sqrtm1(%517) : (i64) -> ()
%520 = arith.constant 5 : i32
%522 = arith.constant 9 : i32
%523 = llvm.mlir.addressof @MOD : !llvm.ptr
%524 = llvm.load %523 : !llvm.ptr -> i64
%525 = arith.constant 2 : i32
%527 = arith.extsi %525 : i32 to i64
%526 = arith.subi %524, %527 : i64
%528 = llvm.mlir.addressof @MOD : !llvm.ptr
%529 = llvm.load %528 : !llvm.ptr -> i64
%530 = arith.extsi %522 : i32 to i64
%521 = func.call @modpow(%530, %526, %529) : (i64, i64, i64) -> i64
%532 = arith.extsi %520 : i32 to i64
%531 = arith.muli %532, %521 : i64
%533 = llvm.mlir.addressof @MOD : !llvm.ptr
%534 = llvm.load %533 : !llvm.ptr -> i64
%535 = arith.remsi %531, %534 : i64
%536 = arith.constant 1000000 : i32
%537 = arith.extsi %536 : i32 to i64
%538 = arith.constant 0 : i32
%539 = arith.extsi %538 : i32 to i64
%540 = llvm.mlir.constant(1 : i64) : i64
%541 = llvm.alloca %540 x i64 : (i64) -> !llvm.ptr
llvm.store %539, %541 : i64, !llvm.ptr
%542 = arith.constant 1 : i32
%544 = arith.constant 0 : i32
%543 = arith.subi %544, %542 : i32
%545 = arith.extsi %543 : i32 to i64
%546 = llvm.mlir.constant(1 : i64) : i64
%547 = llvm.alloca %546 x i64 : (i64) -> !llvm.ptr
llvm.store %545, %547 : i64, !llvm.ptr
%548 = arith.constant 1 : i32
%550 = arith.constant 0 : i32
%549 = arith.subi %550, %548 : i32
%551 = arith.extsi %549 : i32 to i64
%552 = llvm.mlir.constant(1 : i64) : i64
%553 = llvm.alloca %552 x i64 : (i64) -> !llvm.ptr
llvm.store %551, %553 : i64, !llvm.ptr
%554 = arith.constant 1 : i32
%556 = arith.constant 0 : i32
%555 = arith.subi %556, %554 : i32
%557 = arith.extsi %555 : i32 to i64
%558 = llvm.mlir.constant(1 : i64) : i64
%559 = llvm.alloca %558 x i64 : (i64) -> !llvm.ptr
llvm.store %557, %559 : i64, !llvm.ptr
%560 = arith.constant 1 : i32
%562 = arith.constant 0 : i32
%561 = arith.subi %562, %560 : i32
%563 = arith.extsi %561 : i32 to i64
%564 = llvm.mlir.constant(1 : i64) : i64
%565 = llvm.alloca %564 x i64 : (i64) -> !llvm.ptr
llvm.store %563, %565 : i64, !llvm.ptr
%566 = arith.constant 0 : i32
%567 = arith.extsi %566 : i32 to i64
%568 = llvm.mlir.constant(1 : i64) : i64
%569 = llvm.alloca %568 x i64 : (i64) -> !llvm.ptr
llvm.store %567, %569 : i64, !llvm.ptr
cf.br ^bb102
^bb102:
%570 = llvm.load %569 : !llvm.ptr -> i64
%571 = arith.cmpi sle, %570, %517 : i64
cf.cond_br %571, ^bb103, ^bb104
^bb103:
%572 = llvm.load %569 : !llvm.ptr -> i64
%573 = arith.addi %572, %537 : i64
%574 = arith.constant 1 : i32
%576 = arith.extsi %574 : i32 to i64
%575 = arith.addi %517, %576 : i64
%577 = arith.cmpi slt, %573, %575 : i64
%578 = scf.if %577 -> (i64) {
%579 = llvm.load %569 : !llvm.ptr -> i64
%580 = arith.addi %579, %537 : i64
scf.yield %580 : i64
} else {
%581 = arith.constant 1 : i32
%583 = arith.extsi %581 : i32 to i64
%582 = arith.addi %517, %583 : i64
scf.yield %582 : i64
}
%584 = llvm.load %569 : !llvm.ptr -> i64
%585 = arith.subi %578, %584 : i64
%587 = arith.constant 8 : i32
%588 = arith.extsi %587 : i32 to i64
%586 = func.call @calloc(%585, %588) : (i64, i64) -> !llvm.ptr
%590 = arith.constant 8 : i32
%591 = arith.extsi %590 : i32 to i64
%589 = func.call @calloc(%585, %591) : (i64, i64) -> !llvm.ptr
%593 = arith.constant 8 : i32
%594 = arith.extsi %593 : i32 to i64
%592 = func.call @calloc(%585, %594) : (i64, i64) -> !llvm.ptr
%595 = llvm.load %569 : !llvm.ptr -> 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 = llvm.load %597 : !llvm.ptr -> i64
%599 = llvm.load %597 : !llvm.ptr -> i64
%600 = arith.muli %598, %599 : i64
%601 = arith.constant 1 : i32
%603 = arith.extsi %601 : i32 to i64
%602 = arith.addi %600, %603 : i64
%604 = llvm.mlir.constant(1 : i64) : i64
%605 = llvm.alloca %604 x i64 : (i64) -> !llvm.ptr
llvm.store %602, %605 : i64, !llvm.ptr
%606 = arith.constant 0 : i32
%607 = arith.extsi %606 : i32 to i64
%608 = llvm.mlir.constant(1 : i64) : i64
%609 = llvm.alloca %608 x i64 : (i64) -> !llvm.ptr
llvm.store %607, %609 : i64, !llvm.ptr
cf.br ^bb105
^bb105:
%610 = llvm.load %609 : !llvm.ptr -> i64
%611 = arith.cmpi slt, %610, %585 : i64
cf.cond_br %611, ^bb106, ^bb107
^bb106:
%612 = llvm.load %605 : !llvm.ptr -> i64
%613 = llvm.load %609 : !llvm.ptr -> i64
%614 = llvm.getelementptr %586[%613] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %612, %614 : i64, !llvm.ptr
%615 = llvm.load %605 : !llvm.ptr -> i64
%616 = llvm.mlir.addressof @MOD : !llvm.ptr
%617 = llvm.load %616 : !llvm.ptr -> i64
%618 = arith.remsi %615, %617 : i64
%619 = llvm.load %609 : !llvm.ptr -> i64
%620 = llvm.getelementptr %592[%619] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %618, %620 : i64, !llvm.ptr
%621 = arith.constant 1 : i32
%622 = llvm.load %609 : !llvm.ptr -> i64
%623 = arith.extsi %621 : i32 to i64
%624 = llvm.getelementptr %589[%622] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %623, %624 : i64, !llvm.ptr
%625 = llvm.load %605 : !llvm.ptr -> i64
%626 = arith.constant 2 : i32
%627 = llvm.load %597 : !llvm.ptr -> i64
%629 = arith.extsi %626 : i32 to i64
%628 = arith.muli %629, %627 : i64
%630 = arith.addi %625, %628 : i64
%631 = arith.constant 1 : i32
%633 = arith.extsi %631 : i32 to i64
%632 = arith.addi %630, %633 : i64
llvm.store %632, %605 : i64, !llvm.ptr
%634 = llvm.load %597 : !llvm.ptr -> i64
%635 = arith.constant 1 : i32
%637 = arith.extsi %635 : i32 to i64
%636 = arith.addi %634, %637 : i64
llvm.store %636, %597 : i64, !llvm.ptr
%638 = llvm.load %609 : !llvm.ptr -> i64
%639 = arith.constant 1 : i32
%641 = arith.extsi %639 : i32 to i64
%640 = arith.addi %638, %641 : i64
llvm.store %640, %609 : i64, !llvm.ptr
cf.br ^bb105
^bb107:
%642 = arith.constant 0 : i32
%643 = arith.extsi %642 : i32 to i64
%644 = llvm.mlir.constant(1 : i64) : i64
%645 = llvm.alloca %644 x i64 : (i64) -> !llvm.ptr
llvm.store %643, %645 : i64, !llvm.ptr
cf.br ^bb108
^bb108:
%646 = llvm.load %645 : !llvm.ptr -> i64
%647 = llvm.mlir.addressof @g_pcount : !llvm.ptr
%648 = llvm.load %647 : !llvm.ptr -> i64
%649 = arith.cmpi slt, %646, %648 : i64
cf.cond_br %649, ^bb109, ^bb110
^bb109:
%651 = llvm.mlir.addressof @g_p_list : !llvm.ptr
%652 = llvm.load %651 : !llvm.ptr -> !llvm.ptr
%653 = llvm.load %645 : !llvm.ptr -> i64
%654 = llvm.getelementptr %652[%653] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%650 = llvm.load %654 : !llvm.ptr -> i32
%655 = arith.extsi %650 : i32 to i64
%657 = llvm.mlir.addressof @g_r_list : !llvm.ptr
%658 = llvm.load %657 : !llvm.ptr -> !llvm.ptr
%659 = llvm.load %645 : !llvm.ptr -> i64
%660 = llvm.getelementptr %658[%659] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%656 = llvm.load %660 : !llvm.ptr -> i32
%661 = arith.extsi %656 : i32 to i64
%662 = arith.constant 2 : i32
%664 = arith.extsi %662 : i32 to i64
%663 = arith.cmpi eq, %655, %664 : i64
cf.cond_br %663, ^bb111, ^bb112
^bb111:
%665 = arith.constant 1 : i32
%666 = llvm.load %569 : !llvm.ptr -> i64
%668 = arith.extsi %665 : i32 to i64
%667 = arith.subi %668, %666 : i64
%669 = arith.constant 1 : i32
%671 = arith.extsi %669 : i32 to i64
%670 = arith.andi %667, %671 : i64
%672 = llvm.mlir.constant(1 : i64) : i64
%673 = llvm.alloca %672 x i64 : (i64) -> !llvm.ptr
llvm.store %670, %673 : i64, !llvm.ptr
cf.br ^bb114
^bb114:
%674 = llvm.load %673 : !llvm.ptr -> i64
%675 = arith.cmpi slt, %674, %585 : i64
cf.cond_br %675, ^bb115, ^bb116
^bb115:
%677 = llvm.load %673 : !llvm.ptr -> i64
%678 = llvm.getelementptr %586[%677] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%676 = llvm.load %678 : !llvm.ptr -> i64
%679 = arith.constant 2 : i32
%681 = arith.extsi %679 : i32 to i64
%680 = arith.divsi %676, %681 : i64
%682 = llvm.load %673 : !llvm.ptr -> i64
%683 = llvm.getelementptr %586[%682] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %680, %683 : i64, !llvm.ptr
%685 = llvm.load %673 : !llvm.ptr -> i64
%686 = llvm.getelementptr %589[%685] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%684 = llvm.load %686 : !llvm.ptr -> i64
%687 = arith.constant 3 : i32
%689 = arith.extsi %687 : i32 to i64
%688 = arith.muli %684, %689 : i64
%690 = llvm.mlir.addressof @MOD : !llvm.ptr
%691 = llvm.load %690 : !llvm.ptr -> i64
%692 = arith.remsi %688, %691 : i64
%693 = llvm.load %673 : !llvm.ptr -> i64
%694 = llvm.getelementptr %589[%693] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %692, %694 : i64, !llvm.ptr
%695 = llvm.load %673 : !llvm.ptr -> i64
%696 = arith.constant 2 : i32
%698 = arith.extsi %696 : i32 to i64
%697 = arith.addi %695, %698 : i64
llvm.store %697, %673 : i64, !llvm.ptr
cf.br ^bb114
^bb116:
cf.br ^bb113
^bb112:
%699 = llvm.load %569 : !llvm.ptr -> i64
%700 = arith.subi %661, %699 : i64
%701 = arith.remsi %700, %655 : i64
%702 = arith.addi %701, %655 : i64
%703 = arith.remsi %702, %655 : i64
%704 = llvm.mlir.constant(1 : i64) : i64
%705 = llvm.alloca %704 x i64 : (i64) -> !llvm.ptr
llvm.store %703, %705 : i64, !llvm.ptr
%706 = llvm.load %705 : !llvm.ptr -> i64
%707 = llvm.mlir.constant(1 : i64) : i64
%708 = llvm.alloca %707 x i64 : (i64) -> !llvm.ptr
llvm.store %706, %708 : i64, !llvm.ptr
cf.br ^bb117
^bb117:
%709 = llvm.load %708 : !llvm.ptr -> i64
%710 = arith.cmpi slt, %709, %585 : i64
cf.cond_br %710, ^bb118, ^bb119
^bb118:
%712 = llvm.load %708 : !llvm.ptr -> i64
%713 = llvm.getelementptr %586[%712] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%711 = llvm.load %713 : !llvm.ptr -> i64
%714 = arith.divsi %711, %655 : i64
%715 = llvm.mlir.constant(1 : i64) : i64
%716 = llvm.alloca %715 x i64 : (i64) -> !llvm.ptr
llvm.store %714, %716 : i64, !llvm.ptr
%717 = llvm.mlir.constant(1 : i64) : i64
%718 = llvm.alloca %717 x i64 : (i64) -> !llvm.ptr
llvm.store %655, %718 : i64, !llvm.ptr
cf.br ^bb120
^bb120:
%719 = llvm.load %716 : !llvm.ptr -> i64
%720 = arith.remsi %719, %655 : i64
%721 = arith.constant 0 : i32
%723 = arith.extsi %721 : i32 to i64
%722 = arith.cmpi eq, %720, %723 : i64
cf.cond_br %722, ^bb121, ^bb122
^bb121:
%724 = llvm.load %716 : !llvm.ptr -> i64
%725 = arith.divsi %724, %655 : i64
llvm.store %725, %716 : i64, !llvm.ptr
%726 = llvm.load %718 : !llvm.ptr -> i64
%727 = arith.muli %726, %655 : i64
llvm.store %727, %718 : i64, !llvm.ptr
cf.br ^bb120
^bb122:
%728 = llvm.load %716 : !llvm.ptr -> i64
%729 = llvm.load %708 : !llvm.ptr -> i64
%730 = llvm.getelementptr %586[%729] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %728, %730 : i64, !llvm.ptr
%731 = llvm.load %718 : !llvm.ptr -> i64
%732 = arith.constant 1 : i32
%734 = arith.extsi %732 : i32 to i64
%733 = arith.addi %731, %734 : i64
%735 = llvm.mlir.constant(1 : i64) : i64
%736 = llvm.alloca %735 x i64 : (i64) -> !llvm.ptr
llvm.store %733, %736 : i64, !llvm.ptr
%737 = llvm.load %736 : !llvm.ptr -> i64
%738 = llvm.mlir.addressof @MOD : !llvm.ptr
%739 = llvm.load %738 : !llvm.ptr -> i64
%740 = arith.cmpi sge, %737, %739 : i64
cf.cond_br %740, ^bb123, ^bb124
^bb123:
%741 = llvm.load %736 : !llvm.ptr -> i64
%742 = llvm.mlir.addressof @MOD : !llvm.ptr
%743 = llvm.load %742 : !llvm.ptr -> i64
%744 = arith.remsi %741, %743 : i64
llvm.store %744, %736 : i64, !llvm.ptr
cf.br ^bb125
^bb124:
cf.br ^bb125
^bb125:
%746 = llvm.load %708 : !llvm.ptr -> i64
%747 = llvm.getelementptr %589[%746] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%745 = llvm.load %747 : !llvm.ptr -> i64
%748 = llvm.load %736 : !llvm.ptr -> i64
%749 = arith.muli %745, %748 : i64
%750 = llvm.mlir.addressof @MOD : !llvm.ptr
%751 = llvm.load %750 : !llvm.ptr -> i64
%752 = arith.remsi %749, %751 : i64
%753 = llvm.load %708 : !llvm.ptr -> i64
%754 = llvm.getelementptr %589[%753] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %752, %754 : i64, !llvm.ptr
%755 = llvm.load %708 : !llvm.ptr -> i64
%756 = arith.addi %755, %655 : i64
llvm.store %756, %708 : i64, !llvm.ptr
cf.br ^bb117
^bb119:
%757 = arith.subi %655, %661 : i64
%758 = llvm.load %569 : !llvm.ptr -> i64
%759 = arith.subi %757, %758 : i64
%760 = arith.remsi %759, %655 : i64
%761 = arith.addi %760, %655 : i64
%762 = arith.remsi %761, %655 : i64
llvm.store %762, %705 : i64, !llvm.ptr
%763 = llvm.load %705 : !llvm.ptr -> i64
llvm.store %763, %708 : i64, !llvm.ptr
cf.br ^bb126
^bb126:
%764 = llvm.load %708 : !llvm.ptr -> i64
%765 = arith.cmpi slt, %764, %585 : i64
cf.cond_br %765, ^bb127, ^bb128
^bb127:
%767 = llvm.load %708 : !llvm.ptr -> i64
%768 = llvm.getelementptr %586[%767] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%766 = llvm.load %768 : !llvm.ptr -> i64
%769 = arith.divsi %766, %655 : i64
%770 = llvm.mlir.constant(1 : i64) : i64
%771 = llvm.alloca %770 x i64 : (i64) -> !llvm.ptr
llvm.store %769, %771 : i64, !llvm.ptr
%772 = llvm.mlir.constant(1 : i64) : i64
%773 = llvm.alloca %772 x i64 : (i64) -> !llvm.ptr
llvm.store %655, %773 : i64, !llvm.ptr
cf.br ^bb129
^bb129:
%774 = llvm.load %771 : !llvm.ptr -> i64
%775 = arith.remsi %774, %655 : i64
%776 = arith.constant 0 : i32
%778 = arith.extsi %776 : i32 to i64
%777 = arith.cmpi eq, %775, %778 : i64
cf.cond_br %777, ^bb130, ^bb131
^bb130:
%779 = llvm.load %771 : !llvm.ptr -> i64
%780 = arith.divsi %779, %655 : i64
llvm.store %780, %771 : i64, !llvm.ptr
%781 = llvm.load %773 : !llvm.ptr -> i64
%782 = arith.muli %781, %655 : i64
llvm.store %782, %773 : i64, !llvm.ptr
cf.br ^bb129
^bb131:
%783 = llvm.load %771 : !llvm.ptr -> i64
%784 = llvm.load %708 : !llvm.ptr -> i64
%785 = llvm.getelementptr %586[%784] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %783, %785 : i64, !llvm.ptr
%786 = llvm.load %773 : !llvm.ptr -> i64
%787 = arith.constant 1 : i32
%789 = arith.extsi %787 : i32 to i64
%788 = arith.addi %786, %789 : i64
%790 = llvm.mlir.constant(1 : i64) : i64
%791 = llvm.alloca %790 x i64 : (i64) -> !llvm.ptr
llvm.store %788, %791 : i64, !llvm.ptr
%792 = llvm.load %791 : !llvm.ptr -> i64
%793 = llvm.mlir.addressof @MOD : !llvm.ptr
%794 = llvm.load %793 : !llvm.ptr -> i64
%795 = arith.cmpi sge, %792, %794 : i64
cf.cond_br %795, ^bb132, ^bb133
^bb132:
%796 = llvm.load %791 : !llvm.ptr -> i64
%797 = llvm.mlir.addressof @MOD : !llvm.ptr
%798 = llvm.load %797 : !llvm.ptr -> i64
%799 = arith.remsi %796, %798 : i64
llvm.store %799, %791 : i64, !llvm.ptr
cf.br ^bb134
^bb133:
cf.br ^bb134
^bb134:
%801 = llvm.load %708 : !llvm.ptr -> i64
%802 = llvm.getelementptr %589[%801] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%800 = llvm.load %802 : !llvm.ptr -> i64
%803 = llvm.load %791 : !llvm.ptr -> i64
%804 = arith.muli %800, %803 : i64
%805 = llvm.mlir.addressof @MOD : !llvm.ptr
%806 = llvm.load %805 : !llvm.ptr -> i64
%807 = arith.remsi %804, %806 : i64
%808 = llvm.load %708 : !llvm.ptr -> i64
%809 = llvm.getelementptr %589[%808] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %807, %809 : i64, !llvm.ptr
%810 = llvm.load %708 : !llvm.ptr -> i64
%811 = arith.addi %810, %655 : i64
llvm.store %811, %708 : i64, !llvm.ptr
cf.br ^bb126
^bb128:
cf.br ^bb113
^bb113:
%812 = llvm.load %645 : !llvm.ptr -> i64
%813 = arith.constant 1 : i32
%815 = arith.extsi %813 : i32 to i64
%814 = arith.addi %812, %815 : i64
llvm.store %814, %645 : i64, !llvm.ptr
cf.br ^bb108
^bb110:
%816 = arith.constant 0 : i32
%817 = arith.extsi %816 : i32 to i64
llvm.store %817, %609 : i64, !llvm.ptr
cf.br ^bb135
^bb135:
%818 = llvm.load %609 : !llvm.ptr -> i64
%819 = arith.cmpi slt, %818, %585 : i64
cf.cond_br %819, ^bb136, ^bb137
^bb136:
%821 = llvm.load %609 : !llvm.ptr -> i64
%822 = llvm.getelementptr %586[%821] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%820 = llvm.load %822 : !llvm.ptr -> i64
%823 = arith.constant 1 : i32
%825 = arith.extsi %823 : i32 to i64
%824 = arith.cmpi sgt, %820, %825 : i64
cf.cond_br %824, ^bb138, ^bb139
^bb138:
%827 = llvm.load %609 : !llvm.ptr -> i64
%828 = llvm.getelementptr %586[%827] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%826 = llvm.load %828 : !llvm.ptr -> i64
%829 = arith.constant 1 : i32
%831 = arith.extsi %829 : i32 to i64
%830 = arith.addi %826, %831 : i64
%832 = llvm.mlir.constant(1 : i64) : i64
%833 = llvm.alloca %832 x i64 : (i64) -> !llvm.ptr
llvm.store %830, %833 : i64, !llvm.ptr
%834 = llvm.load %833 : !llvm.ptr -> i64
%835 = llvm.mlir.addressof @MOD : !llvm.ptr
%836 = llvm.load %835 : !llvm.ptr -> i64
%837 = arith.cmpi sge, %834, %836 : i64
cf.cond_br %837, ^bb141, ^bb142
^bb141:
%838 = llvm.load %833 : !llvm.ptr -> i64
%839 = llvm.mlir.addressof @MOD : !llvm.ptr
%840 = llvm.load %839 : !llvm.ptr -> i64
%841 = arith.remsi %838, %840 : i64
llvm.store %841, %833 : i64, !llvm.ptr
cf.br ^bb143
^bb142:
cf.br ^bb143
^bb143:
%843 = llvm.load %609 : !llvm.ptr -> i64
%844 = llvm.getelementptr %589[%843] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%842 = llvm.load %844 : !llvm.ptr -> i64
%845 = llvm.load %833 : !llvm.ptr -> i64
%846 = arith.muli %842, %845 : i64
%847 = llvm.mlir.addressof @MOD : !llvm.ptr
%848 = llvm.load %847 : !llvm.ptr -> i64
%849 = arith.remsi %846, %848 : i64
%850 = llvm.load %609 : !llvm.ptr -> i64
%851 = llvm.getelementptr %589[%850] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %849, %851 : i64, !llvm.ptr
cf.br ^bb140
^bb139:
cf.br ^bb140
^bb140:
%852 = llvm.load %609 : !llvm.ptr -> i64
%853 = arith.constant 1 : i32
%855 = arith.extsi %853 : i32 to i64
%854 = arith.addi %852, %855 : i64
llvm.store %854, %609 : i64, !llvm.ptr
cf.br ^bb135
^bb137:
%856 = arith.constant 0 : i32
%857 = arith.extsi %856 : i32 to i64
llvm.store %857, %609 : i64, !llvm.ptr
cf.br ^bb144
^bb144:
%858 = llvm.load %609 : !llvm.ptr -> i64
%859 = arith.cmpi slt, %858, %585 : i64
cf.cond_br %859, ^bb145, ^bb146
^bb145:
%860 = llvm.load %569 : !llvm.ptr -> i64
%861 = llvm.load %609 : !llvm.ptr -> i64
%862 = arith.addi %860, %861 : i64
%864 = llvm.load %609 : !llvm.ptr -> i64
%865 = llvm.getelementptr %589[%864] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%863 = llvm.load %865 : !llvm.ptr -> i64
%867 = llvm.load %609 : !llvm.ptr -> i64
%868 = llvm.getelementptr %592[%867] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%866 = llvm.load %868 : !llvm.ptr -> i64
%869 = llvm.load %547 : !llvm.ptr -> i64
%870 = arith.constant 0 : i32
%872 = arith.extsi %870 : i32 to i64
%871 = arith.cmpi sge, %869, %872 : i64
cf.cond_br %871, ^bb147, ^bb148
^bb147:
%873 = arith.constant 1 : i32
%875 = arith.extsi %873 : i32 to i64
%874 = arith.subi %862, %875 : i64
%876 = arith.cmpi sle, %874, %arg0 : i64
cf.cond_br %876, ^bb150, ^bb151
^bb150:
%877 = llvm.load %547 : !llvm.ptr -> i64
%878 = arith.muli %877, %863 : i64
%879 = llvm.mlir.addressof @MOD : !llvm.ptr
%880 = llvm.load %879 : !llvm.ptr -> i64
%881 = arith.remsi %878, %880 : i64
%882 = llvm.mlir.constant(1 : i64) : i64
%883 = llvm.alloca %882 x i64 : (i64) -> !llvm.ptr
llvm.store %881, %883 : i64, !llvm.ptr
%884 = arith.constant 2 : i32
%886 = arith.extsi %884 : i32 to i64
%885 = arith.remsi %874, %886 : i64
%887 = arith.constant 0 : i32
%889 = arith.extsi %887 : i32 to i64
%888 = arith.cmpi eq, %885, %889 : i64
cf.cond_br %888, ^bb153, ^bb154
^bb153:
%890 = llvm.load %883 : !llvm.ptr -> i64
%891 = arith.muli %890, %535 : i64
%892 = llvm.mlir.addressof @MOD : !llvm.ptr
%893 = llvm.load %892 : !llvm.ptr -> i64
%894 = arith.remsi %891, %893 : i64
llvm.store %894, %883 : i64, !llvm.ptr
cf.br ^bb155
^bb154:
cf.br ^bb155
^bb155:
%895 = llvm.load %559 : !llvm.ptr -> i64
%896 = arith.muli %895, %866 : i64
%897 = llvm.mlir.addressof @MOD : !llvm.ptr
%898 = llvm.load %897 : !llvm.ptr -> i64
%899 = arith.remsi %896, %898 : i64
%900 = llvm.load %541 : !llvm.ptr -> i64
%901 = llvm.load %883 : !llvm.ptr -> i64
%902 = arith.addi %900, %901 : i64
%903 = arith.subi %902, %899 : i64
%904 = llvm.mlir.addressof @MOD : !llvm.ptr
%905 = llvm.load %904 : !llvm.ptr -> i64
%906 = arith.remsi %903, %905 : i64
llvm.store %906, %541 : i64, !llvm.ptr
%907 = llvm.load %541 : !llvm.ptr -> i64
%908 = arith.constant 0 : i32
%910 = arith.extsi %908 : i32 to i64
%909 = arith.cmpi slt, %907, %910 : i64
cf.cond_br %909, ^bb156, ^bb157
^bb156:
%911 = llvm.load %541 : !llvm.ptr -> i64
%912 = llvm.mlir.addressof @MOD : !llvm.ptr
%913 = llvm.load %912 : !llvm.ptr -> i64
%914 = arith.addi %911, %913 : i64
llvm.store %914, %541 : i64, !llvm.ptr
cf.br ^bb158
^bb157:
cf.br ^bb158
^bb158:
cf.br ^bb152
^bb151:
cf.br ^bb152
^bb152:
cf.br ^bb149
^bb148:
cf.br ^bb149
^bb149:
%915 = llvm.load %553 : !llvm.ptr -> i64
llvm.store %915, %547 : i64, !llvm.ptr
llvm.store %863, %553 : i64, !llvm.ptr
%916 = llvm.load %565 : !llvm.ptr -> i64
llvm.store %916, %559 : i64, !llvm.ptr
llvm.store %866, %565 : i64, !llvm.ptr
%917 = llvm.load %609 : !llvm.ptr -> i64
%918 = arith.constant 1 : i32
%920 = arith.extsi %918 : i32 to i64
%919 = arith.addi %917, %920 : i64
llvm.store %919, %609 : i64, !llvm.ptr
cf.br ^bb144
^bb146:
func.call @free(%586) : (!llvm.ptr) -> ()
func.call @free(%589) : (!llvm.ptr) -> ()
func.call @free(%592) : (!llvm.ptr) -> ()
%924 = llvm.load %569 : !llvm.ptr -> i64
%925 = arith.addi %924, %537 : i64
llvm.store %925, %569 : i64, !llvm.ptr
cf.br ^bb102
^bb104:
%927 = llvm.mlir.addressof @g_p_list : !llvm.ptr
%928 = llvm.load %927 : !llvm.ptr -> !llvm.ptr
func.call @free(%928) : (!llvm.ptr) -> ()
%930 = llvm.mlir.addressof @g_r_list : !llvm.ptr
%931 = llvm.load %930 : !llvm.ptr -> !llvm.ptr
func.call @free(%931) : (!llvm.ptr) -> ()
%932 = llvm.load %541 : !llvm.ptr -> i64
%933 = llvm.mlir.addressof @MOD : !llvm.ptr
%934 = llvm.load %933 : !llvm.ptr -> i64
%935 = arith.remsi %932, %934 : i64
func.return %935 : i64
}
func.func @main() -> i32 {
%936 = llvm.mlir.addressof @str_0 : !llvm.ptr
%938 = arith.constant 10000000 : i32
%939 = arith.extsi %938 : i32 to i64
%937 = func.call @solve(%939) : (i64) -> i64
%940 = llvm.call @printf(%936, %937) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
%941 = arith.constant 0 : i32
func.return %941 : i32
}
}