← All problems
Problem 245
Coresilience: sum of n <= 2e11 with (n-phi)/ (n-1) reciprocal integer.
View problem on Project Euler
Performance comparison
Metric Our solution Best known
Time complexity O(n^3)O(n log log n)
Space complexity O(n^2)O(n)
Approach Flow solution Sieve or enumeration
Verdict Suboptimal
Flow source
# Project Euler 245
# Coresilience: sum of n <= 2e11 with (n-phi)/ (n-1) reciprocal integer.
extern {
function calloc(n: i64, size: i64) -> ptr<void>
function free(p: ptr<void>) -> void
}
function gcd(a0: i64, b0: i64) -> i64 {
let mut a: i64 = a0
let mut b: i64 = b0
while b != 0 {
let t: i64 = a % b
a = b
b = t
}
return a
}
function addmod(a: i64, b: i64, mod: i64) -> i64 {
let s: i64 = a + b
if s >= mod || s < a { return s - mod }
return s
}
function mulmod(a0: i64, b0: i64, mod: i64) -> i64 {
let mut a: i64 = a0 % mod
let mut b: i64 = b0 % mod
if a < 0 { a = a + mod }
if b < 0 { b = b + mod }
let mut result: i64 = 0
while b > 0 {
if b % 2 == 1 { result = addmod(result, a, mod) }
a = addmod(a, a, mod)
b = b / 2
}
return result
}
function modpow(base: i64, exp: i64, mod: i64) -> i64 {
let mut r: i64 = 1
let mut b: i64 = base % mod
let mut e: i64 = exp
while e > 0 {
if e % 2 == 1 { r = mulmod(r, b, mod) }
b = mulmod(b, b, mod)
e = e / 2
}
return r
}
function is_prime(value: i64) -> bool {
if value < 2 { return false }
if value % 2 == 0 { return value == 2 }
if value % 3 == 0 { return value == 3 }
if value % 5 == 0 { return value == 5 }
if value % 7 == 0 { return value == 7 }
if value % 11 == 0 { return value == 11 }
if value % 13 == 0 { return value == 13 }
if value % 17 == 0 { return value == 17 }
if value % 19 == 0 { return value == 19 }
if value % 23 == 0 { return value == 23 }
if value % 29 == 0 { return value == 29 }
let mut d: i64 = value - 1
let mut shifts: i32 = 0
while d % 2 == 0 { d = d / 2; shifts = shifts + 1 }
let bases: ptr<i64> = calloc(7, 8)
bases[0] = 2; bases[1] = 325; bases[2] = 9375; bases[3] = 28178
bases[4] = 450775; bases[5] = 9780504; bases[6] = 1795265022
for bi in 0..7 {
let base: i64 = bases[bi] % value
if base != 0 {
let mut x: i64 = modpow(base, d, value)
if !(x == 1 || x == value - 1) {
let mut ok: bool = false
let mut r: i32 = 0
while r < shifts - 1 {
x = mulmod(x, x, value)
if x == value - 1 { ok = true; break }
r = r + 1
}
if !ok { free(bases); return false }
}
}
}
free(bases)
return true
}
function pollard_rho(n: i64) -> i64 {
if n % 2 == 0 { return 2 }
let mut c: i64 = 1
while true {
let mut x: i64 = 2
let mut y: i64 = 2
let mut d: i64 = 1
while d == 1 {
x = addmod(mulmod(x, x, n), c, n)
y = addmod(mulmod(y, y, n), c, n)
y = addmod(mulmod(y, y, n), c, n)
let mut diff: i64 = x - y
if diff < 0 { diff = 0 - diff }
d = gcd(diff, n)
}
if d != n { return d }
c = c + 1
}
return n
}
# Factor into primes array (with multiplicity), then group
function factor_into(n0: i64, out: ptr<i64>, oc: ptr<i32>) -> void {
let mut n: i64 = n0
oc[0] = 0
if n <= 1 { return }
let mut p: i64 = 2
while p * p <= n && p <= 1000000 {
if n % p == 0 {
while n % p == 0 {
out[oc[0]] = p
oc[0] = oc[0] + 1
n = n / p
}
}
if p == 2 { p = 3 } else { p = p + 2 }
}
while n > 1 && !is_prime(n) {
let f: i64 = pollard_rho(n)
let mut g: i64 = f
while !is_prime(g) { g = pollard_rho(g) }
while n % g == 0 {
out[oc[0]] = g
oc[0] = oc[0] + 1
n = n / g
}
}
if n > 1 {
out[oc[0]] = n
oc[0] = oc[0] + 1
}
}
function divisors_from(fac: ptr<i64>, fc: i32, divs: ptr<i64>, dc: ptr<i32>) -> void {
dc[0] = 1
divs[0] = 1
# group factors
let mut i: i32 = 0
while i < fc {
let p: i64 = fac[i]
let mut e: i32 = 0
while i < fc && fac[i] == p {
e = e + 1
i = i + 1
}
let cur: i32 = dc[0]
let mut power: i64 = 1
for k in 0..e {
power = power * p
for j in 0..cur {
divs[dc[0]] = divs[j] * power
dc[0] = dc[0] + 1
}
}
}
}
function isqrt(n: i64) -> i64 {
if n <= 0 { return 0 }
let mut x: i64 = n
let mut y: i64 = (x + 1) / 2
while y < x { x = y; y = (x + n / x) / 2 }
return x
}
function iroot(n: i64, k: i32) -> i64 {
if k == 1 { return n }
if k == 2 { return isqrt(n) }
let mut x: i64 = (n |> isqrt |> isqrt) + 2
while true {
let mut p: i64 = 1
let mut i: i32 = 0
let mut ov: bool = false
while i < k {
if p > n / x { ov = true; break }
p = p * x
i = i + 1
}
if !ov && p <= n {
let mut p2: i64 = 1
let mut ok: bool = true
i = 0
while i < k {
if p2 > n / (x + 1) { ok = false; break }
p2 = p2 * (x + 1)
i = i + 1
}
if ok && p2 <= n { x = x + 1; continue }
return x
}
x = x - 1
if x <= 0 { return 0 }
}
return x
}
const LIMIT: i64 = 200000000000
let mut PRIMES: ptr<i64> = null
let mut NP: i64 = 0
let mut SOLS: ptr<i64> = null
let mut NS: i64 = 0
let mut SEEN_KEYS: ptr<i64> = null
let mut SEEN: ptr<i8> = null
const SCAP: i64 = 1048576
function sol_add(v: i64) -> void {
let mut h: i64 = v % SCAP
if h < 0 { h = 0 - h }
while SEEN[h] == 1 {
if SEEN_KEYS[h] == v { return }
h = h + 1
if h >= SCAP { h = 0 }
}
SEEN[h] = 1
SEEN_KEYS[h] = v
SOLS[NS] = v
NS = NS + 1
}
function try_last(A: i64, B: i64, last_p: i64) -> void {
let D: i64 = A - B
if D <= 0 { return }
let r_max: i64 = LIMIT / A
if r_max <= last_p { return }
let num_min: i64 = B * (last_p - 1) - 1
let den_min: i64 = B + last_p * D
let mut u_min: i64 = num_min / den_min + 1
if u_min < 1 { u_min = 1 }
let num_max: i64 = B * (r_max - 1) - 1
let den_max: i64 = B + r_max * D
if num_max < 0 { return }
let mut u_max: i64 = num_max / den_max
let u2: i64 = (B - 1) / D
if u2 < u_max { u_max = u2 }
if u_max < u_min { return }
let mut u: i64 = u_min
while u <= u_max {
let denom: i64 = B - u * D
if denom <= 0 { break }
let numer: i64 = B * (u + 1) + 1
if numer % denom == 0 {
let r: i64 = numer / denom
if r > last_p && A <= LIMIT / r {
if is_prime(r) {
let n: i64 = A * r
let phi: i64 = B * (r - 1)
if (n - 1) % (n - phi) == 0 {
sol_add(n)
}
}
}
}
u = u + 1
}
}
function dfs(idx: i64, remaining: i32, A: i64, B: i64, last_p: i64) -> void {
if remaining == 0 {
try_last(A, B, last_p)
return
}
let max_p_local: i64 = iroot(LIMIT / A, remaining + 1)
let mut i: i64 = idx
while i < NP {
let p: i64 = PRIMES[i]
if p > max_p_local { break }
dfs(i + 1, remaining - 1, A * p, B * (p - 1), p)
i = i + 1
}
}
function main() -> i32 {
let max_p: i64 = isqrt(LIMIT) + 1
let sieve: ptr<i8> = calloc(max_p + 1, 1)
PRIMES = calloc(max_p / 5, 8)
SOLS = calloc(100000, 8)
SEEN_KEYS = calloc(SCAP, 8)
SEEN = calloc(SCAP, 1)
if sieve == null || PRIMES == null { return 1 }
let mut i: i64 = 0
while i <= max_p { sieve[i] = 1; i = i + 1 }
sieve[0] = 0; sieve[1] = 0
i = 2
while i * i <= max_p {
if sieve[i] == 1 {
let mut j: i64 = i * i
while j <= max_p { sieve[j] = 0; j = j + i }
}
i = i + 1
}
NP = 0
i = 3
while i <= max_p {
if sieve[i] == 1 {
PRIMES[NP] = i
NP = NP + 1
}
i = i + 1
}
let fac: ptr<i64> = calloc(64, 8)
let oc: ptr<i32> = calloc(1, 4)
let divs: ptr<i64> = calloc(10000, 8)
let dc: ptr<i32> = calloc(1, 4)
i = 0
while i < NP {
let p: i64 = PRIMES[i]
let s: i64 = p * p - p + 1
factor_into(s, fac, oc)
# sort fac small
for a in 0..oc[0] {
for b in (a + 1)..oc[0] {
if fac[b] < fac[a] {
let t: i64 = fac[a]; fac[a] = fac[b]; fac[b] = t
}
}
}
divisors_from(fac, oc[0], divs, dc)
for j in 0..dc[0] {
let d: i64 = divs[j]
if d >= 2 * p - 1 {
let q: i64 = d - p + 1
if q > p && p <= LIMIT / q {
if is_prime(q) {
sol_add(p * q)
}
}
}
}
i = i + 1
}
let mut prod: i64 = 1
let mut max_k: i32 = 0
i = 0
while i < NP {
if prod > LIMIT / PRIMES[i] { break }
prod = prod * PRIMES[i]
max_k = max_k + 1
i = i + 1
}
for k in 3..(max_k + 1) {
let m: i32 = k - 1
if m >= 2 {
dfs(0, m, 1, 1, 2)
}
}
let mut total: i64 = 0
i = 0
while i < NS {
total = total + SOLS[i]
i = i + 1
}
printf("%lld\n", total)
return 0
}
Generated C
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* Flow runtime helpers */
typedef struct flow_temp_node { struct flow_temp_node* next; } flow_temp_node;
static flow_temp_node* flow_temp_head = NULL;
static int flow_temp_atexit_set = 0;
__attribute__((unused)) static void flow_temp_free_all(void) {
while (flow_temp_head) {
flow_temp_node* n = flow_temp_head;
flow_temp_head = n->next;
free(n);
}
}
__attribute__((unused)) static void* flow_temp_alloc(size_t nbytes) {
flow_temp_node* node = (flow_temp_node*)malloc(sizeof(flow_temp_node) + nbytes);
if (!node) return NULL;
node->next = flow_temp_head;
flow_temp_head = node;
if (!flow_temp_atexit_set) {
flow_temp_atexit_set = 1;
atexit(flow_temp_free_all);
}
return (void*)(node + 1);
}
#ifndef FLOW_DIAG
#define FLOW_DIAG(msg) fprintf(stderr, "%s", (msg))
#endif
#ifndef FLOW_LOG
#define FLOW_LOG(fmt, ...) printf(fmt, __VA_ARGS__)
#endif
#ifndef FLOW_LOG_EMPTY
#define FLOW_LOG_EMPTY(fmt) printf(fmt)
#endif
static char* flow_strcat(const char* a, const char* b) {
size_t la = strlen(a ? a : ""), lb = strlen(b ? b : "");
char* r = (char*)flow_temp_alloc(la + lb + 1);
if (!r) return NULL;
if (la) memcpy(r, a, la);
if (lb) memcpy(r + la, b, lb);
r[la + lb] = '\0';
return r;
}
#define __flow_in_arr(arr, val) __extension__ ({ \
int _found = 0; \
size_t _n = sizeof(arr)/sizeof((arr)[0]); \
for (size_t _i = 0; _i < _n; _i++) { \
if ((arr)[_i] == (val)) { _found = 1; break; } \
} _found; })
/* Unified fault handler (MISRA #279) — override with -DFLOW_FAULT_HANDLER=fn */
#ifndef FLOW_FAULT_HANDLER
__attribute__((unused)) static inline void flow_fault_handler(const char* msg) {
fprintf(stderr, "flow: %s\n", msg ? msg : "fault");
abort();
#if defined(__GNUC__) || defined(__clang__)
__builtin_unreachable();
#endif
}
#else
#define flow_fault_handler FLOW_FAULT_HANDLER
#endif
#define flow_div_by_zero_handler() flow_fault_handler("division by zero")
#define flow_shift_ub_handler() flow_fault_handler("invalid shift (amount out of range or left-shift of negative)")
#ifndef FLOW_CHECKED_DIV
#define FLOW_CHECKED_DIV(L, R) (((R) != 0) ? ((L) / (R)) : (flow_div_by_zero_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_MOD
#define FLOW_CHECKED_MOD(L, R) (((R) != 0) ? ((L) % (R)) : (flow_div_by_zero_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_SHL
#define FLOW_CHECKED_SHL(L, R) ((((R) >= 0) && ((unsigned long long)(R) < (sizeof(L) * 8ull)) && ((L) >= 0)) ? ((L) << (R)) : (flow_shift_ub_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_SHR
#define FLOW_CHECKED_SHR(L, R) ((((R) >= 0) && ((unsigned long long)(R) < (sizeof(L) * 8ull))) ? ((L) >> (R)) : (flow_shift_ub_handler(), (L) * 0))
#endif
#include <math.h>
void* _ui_state = NULL;
static inline float i32_to_f32(int32_t v) { return (float)v; }
/* Host stub for @gpu kernels (device codegen replaces this). */
static inline int32_t gpu_thread_id(void) { return 0; }
int64_t gcd_i64_i64(int64_t a0, int64_t b0);
int64_t addmod_i64_i64_i64(int64_t a, int64_t b, int64_t mod);
int64_t mulmod_i64_i64_i64(int64_t a0, int64_t b0, int64_t mod);
int64_t modpow_i64_i64_i64(int64_t base, int64_t exp, int64_t mod);
bool is_prime_i64(int64_t value);
int64_t pollard_rho_i64(int64_t n);
void factor_into_i64_ptr_i64_ptr_i32(int64_t n0, int64_t* out, int32_t* oc);
void divisors_from_ptr_i64_i32_ptr_i64_ptr_i32(int64_t* fac, int32_t fc, int64_t* divs, int32_t* dc);
int64_t isqrt_i64(int64_t n);
int64_t iroot_i64_i32(int64_t n, int32_t k);
void sol_add_i64(int64_t v);
void try_last_i64_i64_i64(int64_t A, int64_t B, int64_t last_p);
void dfs_i64_i32_i64_i64_i64(int64_t idx, int32_t remaining, int64_t A, int64_t B, int64_t last_p);
int32_t main(void);
static const int64_t LIMIT = 200000000000;
static const int64_t SCAP = 1048576;
/* Module statics */
static int64_t* PRIMES = NULL;
static int64_t NP = 0;
static int64_t* SOLS = NULL;
static int64_t NS = 0;
static int64_t* SEEN_KEYS = NULL;
static int8_t* SEEN = 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 addmod_i64_i64_i64(int64_t a, int64_t b, int64_t mod) {
int64_t s = (a + b);
if ((s >= mod || s < a)) {
return (s - mod);
}
return s;
}
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));
if (a < 0) {
a = (a + mod);
}
if (b < 0) {
b = (b + mod);
}
int64_t result = 0;
while (b > 0) {
if (FLOW_CHECKED_MOD((b), (2)) == 1) {
result = addmod_i64_i64_i64(result, a, mod);
}
a = addmod_i64_i64_i64(a, a, mod);
b = FLOW_CHECKED_DIV((b), (2));
}
return result;
}
int64_t modpow_i64_i64_i64(int64_t base, int64_t exp, int64_t mod) {
int64_t r = 1;
int64_t b = FLOW_CHECKED_MOD((base), (mod));
int64_t e = exp;
while (e > 0) {
if (FLOW_CHECKED_MOD((e), (2)) == 1) {
r = mulmod_i64_i64_i64(r, b, mod);
}
b = mulmod_i64_i64_i64(b, b, mod);
e = FLOW_CHECKED_DIV((e), (2));
}
return r;
}
bool is_prime_i64(int64_t value) {
if (value < 2) {
return 0;
}
if (FLOW_CHECKED_MOD((value), (2)) == 0) {
return value == 2;
}
if (FLOW_CHECKED_MOD((value), (3)) == 0) {
return value == 3;
}
if (FLOW_CHECKED_MOD((value), (5)) == 0) {
return value == 5;
}
if (FLOW_CHECKED_MOD((value), (7)) == 0) {
return value == 7;
}
if (FLOW_CHECKED_MOD((value), (11)) == 0) {
return value == 11;
}
if (FLOW_CHECKED_MOD((value), (13)) == 0) {
return value == 13;
}
if (FLOW_CHECKED_MOD((value), (17)) == 0) {
return value == 17;
}
if (FLOW_CHECKED_MOD((value), (19)) == 0) {
return value == 19;
}
if (FLOW_CHECKED_MOD((value), (23)) == 0) {
return value == 23;
}
if (FLOW_CHECKED_MOD((value), (29)) == 0) {
return value == 29;
}
int64_t d = (value - 1);
int32_t shifts = 0;
while (FLOW_CHECKED_MOD((d), (2)) == 0) {
d = FLOW_CHECKED_DIV((d), (2));
shifts = (shifts + 1);
}
int64_t* bases = (int64_t*)(calloc(7, 8));
bases[0] = 2;
bases[1] = 325;
bases[2] = 9375;
bases[3] = 28178;
bases[4] = 450775;
bases[5] = 9780504;
bases[6] = 1795265022;
int32_t __flow_step_1 = 1;
for (int32_t bi = 0; (0 <= 7) ? bi < 7 : bi > 7; bi += (0 <= 7) ? 1 : -1) {
int64_t base = FLOW_CHECKED_MOD((bases[bi]), (value));
if (base != 0) {
int64_t x = modpow_i64_i64_i64(base, d, value);
if ((!((x == 1 || x == (value - 1))))) {
bool ok = 0;
int32_t r = 0;
while (r < (shifts - 1)) {
x = mulmod_i64_i64_i64(x, x, value);
if (x == (value - 1)) {
ok = 1;
break;
}
r = (r + 1);
}
if ((!(ok))) {
free(bases);
return 0;
}
}
}
}
free(bases);
return 1;
}
int64_t pollard_rho_i64(int64_t n) {
if (FLOW_CHECKED_MOD((n), (2)) == 0) {
return 2;
}
int64_t c = 1;
while (1) {
int64_t x = 2;
int64_t y = 2;
int64_t d = 1;
while (d == 1) {
x = addmod_i64_i64_i64(mulmod_i64_i64_i64(x, x, n), c, n);
y = addmod_i64_i64_i64(mulmod_i64_i64_i64(y, y, n), c, n);
y = addmod_i64_i64_i64(mulmod_i64_i64_i64(y, y, n), c, n);
int64_t diff = (x - y);
if (diff < 0) {
diff = (0 - diff);
}
d = gcd_i64_i64(diff, n);
}
if (d != n) {
return d;
}
c = (c + 1);
}
return n;
}
void factor_into_i64_ptr_i64_ptr_i32(int64_t n0, int64_t* out, int32_t* oc) {
int64_t n = n0;
oc[0] = 0;
if (n <= 1) {
return;
}
int64_t p = 2;
while (((p * p) <= n && p <= 1000000)) {
if (FLOW_CHECKED_MOD((n), (p)) == 0) {
while (FLOW_CHECKED_MOD((n), (p)) == 0) {
out[oc[0]] = p;
oc[0] = (oc[0] + 1);
n = FLOW_CHECKED_DIV((n), (p));
}
}
if (p == 2) {
p = 3;
} else {
p = (p + 2);
}
}
while ((n > 1 && (!(is_prime_i64(n))))) {
int64_t f = pollard_rho_i64(n);
int64_t g = f;
while ((!(is_prime_i64(g)))) {
g = pollard_rho_i64(g);
}
while (FLOW_CHECKED_MOD((n), (g)) == 0) {
out[oc[0]] = g;
oc[0] = (oc[0] + 1);
n = FLOW_CHECKED_DIV((n), (g));
}
}
if (n > 1) {
out[oc[0]] = n;
oc[0] = (oc[0] + 1);
}
}
void divisors_from_ptr_i64_i32_ptr_i64_ptr_i32(int64_t* fac, int32_t fc, int64_t* divs, int32_t* dc) {
dc[0] = 1;
divs[0] = 1;
int32_t i = 0;
while (i < fc) {
int64_t p = fac[i];
int32_t e = 0;
while ((i < fc && fac[i] == p)) {
e = (e + 1);
i = (i + 1);
}
int32_t cur = dc[0];
int64_t power = 1;
int32_t __flow_step_2 = 1;
for (int32_t k = 0; (0 <= e) ? k < e : k > e; k += (0 <= e) ? 1 : -1) {
power = (power * p);
int32_t __flow_step_3 = 1;
for (int32_t j = 0; (0 <= cur) ? j < cur : j > cur; j += (0 <= cur) ? 1 : -1) {
divs[dc[0]] = (divs[j] * power);
dc[0] = (dc[0] + 1);
}
}
}
}
int64_t isqrt_i64(int64_t n) {
if (n <= 0) {
return 0;
}
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 iroot_i64_i32(int64_t n, int32_t k) {
if (k == 1) {
return n;
}
if (k == 2) {
return isqrt_i64(n);
}
int64_t x = (isqrt_i64(isqrt_i64(n)) + 2);
while (1) {
int64_t p = 1;
int32_t i = 0;
bool ov = 0;
while (i < k) {
if (p > FLOW_CHECKED_DIV((n), (x))) {
ov = 1;
break;
}
p = (p * x);
i = (i + 1);
}
if (((!(ov)) && p <= n)) {
int64_t p2 = 1;
bool ok = 1;
i = 0;
while (i < k) {
if (p2 > FLOW_CHECKED_DIV((n), ((x + 1)))) {
ok = 0;
break;
}
p2 = (p2 * (x + 1));
i = (i + 1);
}
if ((ok && p2 <= n)) {
x = (x + 1);
continue;
}
return x;
}
x = (x - 1);
if (x <= 0) {
return 0;
}
}
return x;
}
void sol_add_i64(int64_t v) {
int64_t h = FLOW_CHECKED_MOD((v), (SCAP));
if (h < 0) {
h = (0 - h);
}
while (SEEN[h] == 1) {
if (SEEN_KEYS[h] == v) {
return;
}
h = (h + 1);
if (h >= SCAP) {
h = 0;
}
}
SEEN[h] = 1;
SEEN_KEYS[h] = v;
SOLS[NS] = v;
NS = (NS + 1);
}
void try_last_i64_i64_i64(int64_t A, int64_t B, int64_t last_p) {
int64_t D = (A - B);
if (D <= 0) {
return;
}
int64_t r_max = FLOW_CHECKED_DIV((LIMIT), (A));
if (r_max <= last_p) {
return;
}
int64_t num_min = ((B * (last_p - 1)) - 1);
int64_t den_min = (B + (last_p * D));
int64_t u_min = (FLOW_CHECKED_DIV((num_min), (den_min)) + 1);
if (u_min < 1) {
u_min = 1;
}
int64_t num_max = ((B * (r_max - 1)) - 1);
int64_t den_max = (B + (r_max * D));
if (num_max < 0) {
return;
}
int64_t u_max = FLOW_CHECKED_DIV((num_max), (den_max));
int64_t u2 = FLOW_CHECKED_DIV(((B - 1)), (D));
if (u2 < u_max) {
u_max = u2;
}
if (u_max < u_min) {
return;
}
int64_t u = u_min;
while (u <= u_max) {
int64_t denom = (B - (u * D));
if (denom <= 0) {
break;
}
int64_t numer = ((B * (u + 1)) + 1);
if (FLOW_CHECKED_MOD((numer), (denom)) == 0) {
int64_t r = FLOW_CHECKED_DIV((numer), (denom));
if ((r > last_p && A <= FLOW_CHECKED_DIV((LIMIT), (r)))) {
if (is_prime_i64(r)) {
int64_t n = (A * r);
int64_t phi = (B * (r - 1));
if (FLOW_CHECKED_MOD(((n - 1)), ((n - phi))) == 0) {
sol_add_i64(n);
}
}
}
}
u = (u + 1);
}
}
void dfs_i64_i32_i64_i64_i64(int64_t idx, int32_t remaining, int64_t A, int64_t B, int64_t last_p) {
if (remaining == 0) {
try_last_i64_i64_i64(A, B, last_p);
return;
}
int64_t max_p_local = iroot_i64_i32(FLOW_CHECKED_DIV((LIMIT), (A)), (remaining + 1));
int64_t i = idx;
while (i < NP) {
int64_t p = PRIMES[i];
if (p > max_p_local) {
break;
}
dfs_i64_i32_i64_i64_i64((i + 1), (remaining - 1), (A * p), (B * (p - 1)), p);
i = (i + 1);
}
}
int32_t main(void) {
int64_t max_p = (isqrt_i64(LIMIT) + 1);
int8_t* sieve = (int8_t*)(calloc((max_p + 1), 1));
PRIMES = calloc(FLOW_CHECKED_DIV((max_p), (5)), 8);
SOLS = calloc(100000, 8);
SEEN_KEYS = calloc(SCAP, 8);
SEEN = calloc(SCAP, 1);
if ((sieve == NULL || PRIMES == NULL)) {
return 1;
}
int64_t i = 0;
while (i <= max_p) {
sieve[i] = 1;
i = (i + 1);
}
sieve[0] = 0;
sieve[1] = 0;
i = 2;
while ((i * i) <= max_p) {
if (sieve[i] == 1) {
int64_t j = (i * i);
while (j <= max_p) {
sieve[j] = 0;
j = (j + i);
}
}
i = (i + 1);
}
NP = 0;
i = 3;
while (i <= max_p) {
if (sieve[i] == 1) {
PRIMES[NP] = i;
NP = (NP + 1);
}
i = (i + 1);
}
int64_t* fac = (int64_t*)(calloc(64, 8));
int32_t* oc = (int32_t*)(calloc(1, 4));
int64_t* divs = (int64_t*)(calloc(10000, 8));
int32_t* dc = (int32_t*)(calloc(1, 4));
i = 0;
while (i < NP) {
int64_t p = PRIMES[i];
int64_t s = (((p * p) - p) + 1);
factor_into_i64_ptr_i64_ptr_i32(s, fac, oc);
int32_t __flow_step_4 = 1;
for (int32_t a = 0; (0 <= oc[0]) ? a < oc[0] : a > oc[0]; a += (0 <= oc[0]) ? 1 : -1) {
int32_t __flow_step_5 = 1;
for (int32_t b = (a + 1); ((a + 1) <= oc[0]) ? b < oc[0] : b > oc[0]; b += ((a + 1) <= oc[0]) ? 1 : -1) {
if (fac[b] < fac[a]) {
int64_t t = fac[a];
fac[a] = fac[b];
fac[b] = t;
}
}
}
divisors_from_ptr_i64_i32_ptr_i64_ptr_i32(fac, oc[0], divs, dc);
int32_t __flow_step_6 = 1;
for (int32_t j = 0; (0 <= dc[0]) ? j < dc[0] : j > dc[0]; j += (0 <= dc[0]) ? 1 : -1) {
int64_t d = divs[j];
if (d >= ((2 * p) - 1)) {
int64_t q = ((d - p) + 1);
if ((q > p && p <= FLOW_CHECKED_DIV((LIMIT), (q)))) {
if (is_prime_i64(q)) {
sol_add_i64((p * q));
}
}
}
}
i = (i + 1);
}
int64_t prod = 1;
int32_t max_k = 0;
i = 0;
while (i < NP) {
if (prod > FLOW_CHECKED_DIV((LIMIT), (PRIMES[i]))) {
break;
}
prod = (prod * PRIMES[i]);
max_k = (max_k + 1);
i = (i + 1);
}
int32_t __flow_step_7 = 1;
for (int32_t k = 3; (3 <= (max_k + 1)) ? k < (max_k + 1) : k > (max_k + 1); k += (3 <= (max_k + 1)) ? 1 : -1) {
int32_t m = (k - 1);
if (m >= 2) {
dfs_i64_i32_i64_i64_i64(0, m, 1, 1, 2);
}
}
int64_t total = 0;
i = 0;
while (i < NS) {
total = (total + SOLS[i]);
i = (i + 1);
}
printf("%lld\n", total);
return 0;
}
Generated MLIR
module {
llvm.func @printf(!llvm.ptr, ...) -> i32
llvm.mlir.global internal constant @str_0("%lld\n\00") {addr_space = 0 : i32} : !llvm.array<6 x i8>
func.func private @calloc(i64, i64) -> !llvm.ptr
func.func private @free(!llvm.ptr) -> ()
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 @addmod(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
%13 = arith.addi %arg0, %arg1 : i64
%14 = arith.cmpi sge, %13, %arg2 : i64
%15 = scf.if %14 -> (i1) {
%16 = arith.constant true
scf.yield %16 : i1
} else {
%17 = arith.cmpi slt, %13, %arg0 : i64
scf.yield %17 : i1
}
cf.cond_br %15, ^bb3, ^bb4
^bb3:
%18 = arith.subi %13, %arg2 : i64
func.return %18 : i64
^bb4:
cf.br ^bb5
^bb5:
func.return %13 : i64
}
func.func @mulmod(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
%19 = arith.remsi %arg0, %arg2 : i64
%20 = llvm.mlir.constant(1 : i64) : i64
%21 = llvm.alloca %20 x i64 : (i64) -> !llvm.ptr
llvm.store %19, %21 : i64, !llvm.ptr
%22 = arith.remsi %arg1, %arg2 : i64
%23 = llvm.mlir.constant(1 : i64) : i64
%24 = llvm.alloca %23 x i64 : (i64) -> !llvm.ptr
llvm.store %22, %24 : i64, !llvm.ptr
%25 = llvm.load %21 : !llvm.ptr -> i64
%26 = arith.constant 0 : i32
%28 = arith.extsi %26 : i32 to i64
%27 = arith.cmpi slt, %25, %28 : i64
cf.cond_br %27, ^bb6, ^bb7
^bb6:
%29 = llvm.load %21 : !llvm.ptr -> i64
%30 = arith.addi %29, %arg2 : i64
llvm.store %30, %21 : i64, !llvm.ptr
cf.br ^bb8
^bb7:
cf.br ^bb8
^bb8:
%31 = llvm.load %24 : !llvm.ptr -> i64
%32 = arith.constant 0 : i32
%34 = arith.extsi %32 : i32 to i64
%33 = arith.cmpi slt, %31, %34 : i64
cf.cond_br %33, ^bb9, ^bb10
^bb9:
%35 = llvm.load %24 : !llvm.ptr -> i64
%36 = arith.addi %35, %arg2 : i64
llvm.store %36, %24 : i64, !llvm.ptr
cf.br ^bb11
^bb10:
cf.br ^bb11
^bb11:
%37 = arith.constant 0 : i32
%38 = arith.extsi %37 : i32 to i64
%39 = llvm.mlir.constant(1 : i64) : i64
%40 = llvm.alloca %39 x i64 : (i64) -> !llvm.ptr
llvm.store %38, %40 : i64, !llvm.ptr
cf.br ^bb12
^bb12:
%41 = llvm.load %24 : !llvm.ptr -> i64
%42 = arith.constant 0 : i32
%44 = arith.extsi %42 : i32 to i64
%43 = arith.cmpi sgt, %41, %44 : i64
cf.cond_br %43, ^bb13, ^bb14
^bb13:
%45 = llvm.load %24 : !llvm.ptr -> i64
%46 = arith.constant 2 : i32
%48 = arith.extsi %46 : i32 to i64
%47 = arith.remsi %45, %48 : i64
%49 = arith.constant 1 : i32
%51 = arith.extsi %49 : i32 to i64
%50 = arith.cmpi eq, %47, %51 : i64
cf.cond_br %50, ^bb15, ^bb16
^bb15:
%53 = llvm.load %40 : !llvm.ptr -> i64
%54 = llvm.load %21 : !llvm.ptr -> i64
%52 = func.call @addmod(%53, %54, %arg2) : (i64, i64, i64) -> i64
llvm.store %52, %40 : i64, !llvm.ptr
cf.br ^bb17
^bb16:
cf.br ^bb17
^bb17:
%56 = llvm.load %21 : !llvm.ptr -> i64
%57 = llvm.load %21 : !llvm.ptr -> i64
%55 = func.call @addmod(%56, %57, %arg2) : (i64, i64, i64) -> i64
llvm.store %55, %21 : i64, !llvm.ptr
%58 = llvm.load %24 : !llvm.ptr -> i64
%59 = arith.constant 2 : i32
%61 = arith.extsi %59 : i32 to i64
%60 = arith.divsi %58, %61 : i64
llvm.store %60, %24 : i64, !llvm.ptr
cf.br ^bb12
^bb14:
%62 = llvm.load %40 : !llvm.ptr -> i64
func.return %62 : i64
}
func.func @modpow(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
%63 = arith.constant 1 : i32
%64 = arith.extsi %63 : i32 to i64
%65 = llvm.mlir.constant(1 : i64) : i64
%66 = llvm.alloca %65 x i64 : (i64) -> !llvm.ptr
llvm.store %64, %66 : i64, !llvm.ptr
%67 = arith.remsi %arg0, %arg2 : i64
%68 = llvm.mlir.constant(1 : i64) : i64
%69 = llvm.alloca %68 x i64 : (i64) -> !llvm.ptr
llvm.store %67, %69 : i64, !llvm.ptr
%70 = llvm.mlir.constant(1 : i64) : i64
%71 = llvm.alloca %70 x i64 : (i64) -> !llvm.ptr
llvm.store %arg1, %71 : i64, !llvm.ptr
cf.br ^bb18
^bb18:
%72 = llvm.load %71 : !llvm.ptr -> i64
%73 = arith.constant 0 : i32
%75 = arith.extsi %73 : i32 to i64
%74 = arith.cmpi sgt, %72, %75 : i64
cf.cond_br %74, ^bb19, ^bb20
^bb19:
%76 = llvm.load %71 : !llvm.ptr -> i64
%77 = arith.constant 2 : i32
%79 = arith.extsi %77 : i32 to i64
%78 = arith.remsi %76, %79 : i64
%80 = arith.constant 1 : i32
%82 = arith.extsi %80 : i32 to i64
%81 = arith.cmpi eq, %78, %82 : i64
cf.cond_br %81, ^bb21, ^bb22
^bb21:
%84 = llvm.load %66 : !llvm.ptr -> i64
%85 = llvm.load %69 : !llvm.ptr -> i64
%83 = func.call @mulmod(%84, %85, %arg2) : (i64, i64, i64) -> i64
llvm.store %83, %66 : i64, !llvm.ptr
cf.br ^bb23
^bb22:
cf.br ^bb23
^bb23:
%87 = llvm.load %69 : !llvm.ptr -> i64
%88 = llvm.load %69 : !llvm.ptr -> i64
%86 = func.call @mulmod(%87, %88, %arg2) : (i64, i64, i64) -> i64
llvm.store %86, %69 : i64, !llvm.ptr
%89 = llvm.load %71 : !llvm.ptr -> i64
%90 = arith.constant 2 : i32
%92 = arith.extsi %90 : i32 to i64
%91 = arith.divsi %89, %92 : i64
llvm.store %91, %71 : i64, !llvm.ptr
cf.br ^bb18
^bb20:
%93 = llvm.load %66 : !llvm.ptr -> i64
func.return %93 : i64
}
func.func @is_prime(%arg0: i64) -> i1 {
%94 = arith.constant 2 : i32
%96 = arith.extsi %94 : i32 to i64
%95 = arith.cmpi slt, %arg0, %96 : i64
cf.cond_br %95, ^bb24, ^bb25
^bb24:
%97 = arith.constant 0 : i1
func.return %97 : i1
^bb25:
cf.br ^bb26
^bb26:
%98 = arith.constant 2 : i32
%100 = arith.extsi %98 : i32 to i64
%99 = arith.remsi %arg0, %100 : i64
%101 = arith.constant 0 : i32
%103 = arith.extsi %101 : i32 to i64
%102 = arith.cmpi eq, %99, %103 : i64
cf.cond_br %102, ^bb27, ^bb28
^bb27:
%104 = arith.constant 2 : i32
%106 = arith.extsi %104 : i32 to i64
%105 = arith.cmpi eq, %arg0, %106 : i64
func.return %105 : i1
^bb28:
cf.br ^bb29
^bb29:
%107 = arith.constant 3 : i32
%109 = arith.extsi %107 : i32 to i64
%108 = arith.remsi %arg0, %109 : i64
%110 = arith.constant 0 : i32
%112 = arith.extsi %110 : i32 to i64
%111 = arith.cmpi eq, %108, %112 : i64
cf.cond_br %111, ^bb30, ^bb31
^bb30:
%113 = arith.constant 3 : i32
%115 = arith.extsi %113 : i32 to i64
%114 = arith.cmpi eq, %arg0, %115 : i64
func.return %114 : i1
^bb31:
cf.br ^bb32
^bb32:
%116 = arith.constant 5 : i32
%118 = arith.extsi %116 : i32 to i64
%117 = arith.remsi %arg0, %118 : i64
%119 = arith.constant 0 : i32
%121 = arith.extsi %119 : i32 to i64
%120 = arith.cmpi eq, %117, %121 : i64
cf.cond_br %120, ^bb33, ^bb34
^bb33:
%122 = arith.constant 5 : i32
%124 = arith.extsi %122 : i32 to i64
%123 = arith.cmpi eq, %arg0, %124 : i64
func.return %123 : i1
^bb34:
cf.br ^bb35
^bb35:
%125 = arith.constant 7 : i32
%127 = arith.extsi %125 : i32 to i64
%126 = arith.remsi %arg0, %127 : i64
%128 = arith.constant 0 : i32
%130 = arith.extsi %128 : i32 to i64
%129 = arith.cmpi eq, %126, %130 : i64
cf.cond_br %129, ^bb36, ^bb37
^bb36:
%131 = arith.constant 7 : i32
%133 = arith.extsi %131 : i32 to i64
%132 = arith.cmpi eq, %arg0, %133 : i64
func.return %132 : i1
^bb37:
cf.br ^bb38
^bb38:
%134 = arith.constant 11 : i32
%136 = arith.extsi %134 : i32 to i64
%135 = arith.remsi %arg0, %136 : i64
%137 = arith.constant 0 : i32
%139 = arith.extsi %137 : i32 to i64
%138 = arith.cmpi eq, %135, %139 : i64
cf.cond_br %138, ^bb39, ^bb40
^bb39:
%140 = arith.constant 11 : i32
%142 = arith.extsi %140 : i32 to i64
%141 = arith.cmpi eq, %arg0, %142 : i64
func.return %141 : i1
^bb40:
cf.br ^bb41
^bb41:
%143 = arith.constant 13 : i32
%145 = arith.extsi %143 : i32 to i64
%144 = arith.remsi %arg0, %145 : i64
%146 = arith.constant 0 : i32
%148 = arith.extsi %146 : i32 to i64
%147 = arith.cmpi eq, %144, %148 : i64
cf.cond_br %147, ^bb42, ^bb43
^bb42:
%149 = arith.constant 13 : i32
%151 = arith.extsi %149 : i32 to i64
%150 = arith.cmpi eq, %arg0, %151 : i64
func.return %150 : i1
^bb43:
cf.br ^bb44
^bb44:
%152 = arith.constant 17 : i32
%154 = arith.extsi %152 : i32 to i64
%153 = arith.remsi %arg0, %154 : i64
%155 = arith.constant 0 : i32
%157 = arith.extsi %155 : i32 to i64
%156 = arith.cmpi eq, %153, %157 : i64
cf.cond_br %156, ^bb45, ^bb46
^bb45:
%158 = arith.constant 17 : i32
%160 = arith.extsi %158 : i32 to i64
%159 = arith.cmpi eq, %arg0, %160 : i64
func.return %159 : i1
^bb46:
cf.br ^bb47
^bb47:
%161 = arith.constant 19 : i32
%163 = arith.extsi %161 : i32 to i64
%162 = arith.remsi %arg0, %163 : i64
%164 = arith.constant 0 : i32
%166 = arith.extsi %164 : i32 to i64
%165 = arith.cmpi eq, %162, %166 : i64
cf.cond_br %165, ^bb48, ^bb49
^bb48:
%167 = arith.constant 19 : i32
%169 = arith.extsi %167 : i32 to i64
%168 = arith.cmpi eq, %arg0, %169 : i64
func.return %168 : i1
^bb49:
cf.br ^bb50
^bb50:
%170 = arith.constant 23 : i32
%172 = arith.extsi %170 : i32 to i64
%171 = arith.remsi %arg0, %172 : i64
%173 = arith.constant 0 : i32
%175 = arith.extsi %173 : i32 to i64
%174 = arith.cmpi eq, %171, %175 : i64
cf.cond_br %174, ^bb51, ^bb52
^bb51:
%176 = arith.constant 23 : i32
%178 = arith.extsi %176 : i32 to i64
%177 = arith.cmpi eq, %arg0, %178 : i64
func.return %177 : i1
^bb52:
cf.br ^bb53
^bb53:
%179 = arith.constant 29 : i32
%181 = arith.extsi %179 : i32 to i64
%180 = arith.remsi %arg0, %181 : i64
%182 = arith.constant 0 : i32
%184 = arith.extsi %182 : i32 to i64
%183 = arith.cmpi eq, %180, %184 : i64
cf.cond_br %183, ^bb54, ^bb55
^bb54:
%185 = arith.constant 29 : i32
%187 = arith.extsi %185 : i32 to i64
%186 = arith.cmpi eq, %arg0, %187 : i64
func.return %186 : i1
^bb55:
cf.br ^bb56
^bb56:
%188 = arith.constant 1 : i32
%190 = arith.extsi %188 : i32 to i64
%189 = arith.subi %arg0, %190 : i64
%191 = llvm.mlir.constant(1 : i64) : i64
%192 = llvm.alloca %191 x i64 : (i64) -> !llvm.ptr
llvm.store %189, %192 : i64, !llvm.ptr
%193 = arith.constant 0 : i32
%194 = llvm.mlir.constant(1 : i64) : i64
%195 = llvm.alloca %194 x i32 : (i64) -> !llvm.ptr
llvm.store %193, %195 : i32, !llvm.ptr
cf.br ^bb57
^bb57:
%196 = llvm.load %192 : !llvm.ptr -> i64
%197 = arith.constant 2 : i32
%199 = arith.extsi %197 : i32 to i64
%198 = arith.remsi %196, %199 : i64
%200 = arith.constant 0 : i32
%202 = arith.extsi %200 : i32 to i64
%201 = arith.cmpi eq, %198, %202 : i64
cf.cond_br %201, ^bb58, ^bb59
^bb58:
%203 = llvm.load %192 : !llvm.ptr -> i64
%204 = arith.constant 2 : i32
%206 = arith.extsi %204 : i32 to i64
%205 = arith.divsi %203, %206 : i64
llvm.store %205, %192 : i64, !llvm.ptr
%207 = llvm.load %195 : !llvm.ptr -> i32
%208 = arith.constant 1 : i32
%209 = arith.addi %207, %208 : i32
llvm.store %209, %195 : i32, !llvm.ptr
cf.br ^bb57
^bb59:
%211 = arith.constant 7 : i32
%212 = arith.constant 8 : i32
%213 = arith.extsi %211 : i32 to i64
%214 = arith.extsi %212 : i32 to i64
%210 = func.call @calloc(%213, %214) : (i64, i64) -> !llvm.ptr
%215 = arith.constant 2 : i32
%216 = arith.constant 0 : i32
%217 = arith.extsi %215 : i32 to i64
%218 = arith.extsi %216 : i32 to i64
%219 = llvm.getelementptr %210[%218] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %217, %219 : i64, !llvm.ptr
%220 = arith.constant 325 : i32
%221 = arith.constant 1 : i32
%222 = arith.extsi %220 : i32 to i64
%223 = arith.extsi %221 : i32 to i64
%224 = llvm.getelementptr %210[%223] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %222, %224 : i64, !llvm.ptr
%225 = arith.constant 9375 : i32
%226 = arith.constant 2 : i32
%227 = arith.extsi %225 : i32 to i64
%228 = arith.extsi %226 : i32 to i64
%229 = llvm.getelementptr %210[%228] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %227, %229 : i64, !llvm.ptr
%230 = arith.constant 28178 : i32
%231 = arith.constant 3 : i32
%232 = arith.extsi %230 : i32 to i64
%233 = arith.extsi %231 : i32 to i64
%234 = llvm.getelementptr %210[%233] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %232, %234 : i64, !llvm.ptr
%235 = arith.constant 450775 : i32
%236 = arith.constant 4 : i32
%237 = arith.extsi %235 : i32 to i64
%238 = arith.extsi %236 : i32 to i64
%239 = llvm.getelementptr %210[%238] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %237, %239 : i64, !llvm.ptr
%240 = arith.constant 9780504 : i32
%241 = arith.constant 5 : i32
%242 = arith.extsi %240 : i32 to i64
%243 = arith.extsi %241 : i32 to i64
%244 = llvm.getelementptr %210[%243] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %242, %244 : i64, !llvm.ptr
%245 = arith.constant 1795265022 : i32
%246 = arith.constant 6 : i32
%247 = arith.extsi %245 : i32 to i64
%248 = arith.extsi %246 : i32 to i64
%249 = llvm.getelementptr %210[%248] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %247, %249 : i64, !llvm.ptr
%250 = arith.constant 0 : i32
%251 = arith.constant 7 : i32
%252 = arith.index_cast %250 : i32 to index
%253 = arith.index_cast %251 : i32 to index
%255 = arith.constant 1 : index
%256 = arith.constant -1 : index
%257 = arith.cmpi sle, %252, %253 : index
%254 = arith.select %257, %255, %256 : index
cf.br ^bb60(%252 : index)
^bb60(%258: index):
%259 = arith.cmpi slt, %258, %253 : index
%260 = arith.cmpi sgt, %258, %253 : index
%261 = arith.select %257, %259, %260 : i1
cf.cond_br %261, ^bb61(%258 : index), ^bb62(%258 : index)
^bb61(%262: index):
%264 = arith.index_cast %262 : index to i64
%265 = llvm.getelementptr %210[%264] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%263 = llvm.load %265 : !llvm.ptr -> i64
%266 = arith.remsi %263, %arg0 : i64
%267 = arith.constant 0 : i32
%269 = arith.extsi %267 : i32 to i64
%268 = arith.cmpi ne, %266, %269 : i64
cf.cond_br %268, ^bb63, ^bb64
^bb63:
%271 = llvm.load %192 : !llvm.ptr -> i64
%270 = func.call @modpow(%266, %271, %arg0) : (i64, i64, i64) -> i64
%272 = llvm.mlir.constant(1 : i64) : i64
%273 = llvm.alloca %272 x i64 : (i64) -> !llvm.ptr
llvm.store %270, %273 : i64, !llvm.ptr
%274 = llvm.load %273 : !llvm.ptr -> i64
%275 = arith.constant 1 : i32
%277 = arith.extsi %275 : i32 to i64
%276 = arith.cmpi eq, %274, %277 : i64
%278 = scf.if %276 -> (i1) {
%279 = arith.constant true
scf.yield %279 : i1
} else {
%280 = llvm.load %273 : !llvm.ptr -> i64
%281 = arith.constant 1 : i32
%283 = arith.extsi %281 : i32 to i64
%282 = arith.subi %arg0, %283 : i64
%284 = arith.cmpi eq, %280, %282 : i64
scf.yield %284 : i1
}
%286 = arith.constant 1 : i1
%285 = arith.xori %278, %286 : i1
cf.cond_br %285, ^bb66, ^bb67
^bb66:
%288 = arith.constant 0 : i1
%289 = llvm.mlir.constant(1 : i64) : i64
%290 = llvm.alloca %289 x i1 : (i64) -> !llvm.ptr
llvm.store %288, %290 : i1, !llvm.ptr
%291 = arith.constant 0 : i32
%292 = llvm.mlir.constant(1 : i64) : i64
%293 = llvm.alloca %292 x i32 : (i64) -> !llvm.ptr
llvm.store %291, %293 : i32, !llvm.ptr
cf.br ^bb69
^bb69:
%294 = llvm.load %293 : !llvm.ptr -> i32
%295 = llvm.load %195 : !llvm.ptr -> i32
%296 = arith.constant 1 : i32
%297 = arith.subi %295, %296 : i32
%298 = arith.cmpi slt, %294, %297 : i32
cf.cond_br %298, ^bb70, ^bb71
^bb70:
%300 = llvm.load %273 : !llvm.ptr -> i64
%301 = llvm.load %273 : !llvm.ptr -> i64
%299 = func.call @mulmod(%300, %301, %arg0) : (i64, i64, i64) -> i64
llvm.store %299, %273 : i64, !llvm.ptr
%302 = llvm.load %273 : !llvm.ptr -> i64
%303 = arith.constant 1 : i32
%305 = arith.extsi %303 : i32 to i64
%304 = arith.subi %arg0, %305 : i64
%306 = arith.cmpi eq, %302, %304 : i64
cf.cond_br %306, ^bb72, ^bb73
^bb72:
%307 = arith.constant 1 : i1
llvm.store %307, %290 : i1, !llvm.ptr
cf.br ^bb71
^bb73:
cf.br ^bb74
^bb74:
%308 = llvm.load %293 : !llvm.ptr -> i32
%309 = arith.constant 1 : i32
%310 = arith.addi %308, %309 : i32
llvm.store %310, %293 : i32, !llvm.ptr
cf.br ^bb69
^bb71:
%311 = llvm.load %290 : !llvm.ptr -> i1
%313 = arith.constant 1 : i1
%312 = arith.xori %311, %313 : i1
cf.cond_br %312, ^bb75, ^bb76
^bb75:
func.call @free(%210) : (!llvm.ptr) -> ()
%316 = arith.constant 0 : i1
func.return %316 : i1
^bb76:
cf.br ^bb77
^bb77:
cf.br ^bb68
^bb67:
cf.br ^bb68
^bb68:
cf.br ^bb65
^bb64:
cf.br ^bb65
^bb65:
%317 = arith.addi %262, %254 : index
cf.br ^bb60(%317 : index)
^bb62(%318: index):
func.call @free(%210) : (!llvm.ptr) -> ()
%320 = arith.constant 1 : i1
func.return %320 : i1
}
func.func @pollard_rho(%arg0: i64) -> i64 {
%321 = arith.constant 2 : i32
%323 = arith.extsi %321 : i32 to i64
%322 = arith.remsi %arg0, %323 : i64
%324 = arith.constant 0 : i32
%326 = arith.extsi %324 : i32 to i64
%325 = arith.cmpi eq, %322, %326 : i64
cf.cond_br %325, ^bb78, ^bb79
^bb78:
%327 = arith.constant 2 : i32
%328 = arith.extsi %327 : i32 to i64
func.return %328 : i64
^bb79:
cf.br ^bb80
^bb80:
%329 = arith.constant 1 : i32
%330 = arith.extsi %329 : i32 to i64
%331 = llvm.mlir.constant(1 : i64) : i64
%332 = llvm.alloca %331 x i64 : (i64) -> !llvm.ptr
llvm.store %330, %332 : i64, !llvm.ptr
cf.br ^bb81
^bb81:
%333 = arith.constant 1 : i1
cf.cond_br %333, ^bb82, ^bb83
^bb82:
%334 = arith.constant 2 : i32
%335 = arith.extsi %334 : i32 to i64
%336 = llvm.mlir.constant(1 : i64) : i64
%337 = llvm.alloca %336 x i64 : (i64) -> !llvm.ptr
llvm.store %335, %337 : i64, !llvm.ptr
%338 = arith.constant 2 : i32
%339 = arith.extsi %338 : i32 to i64
%340 = llvm.mlir.constant(1 : i64) : i64
%341 = llvm.alloca %340 x i64 : (i64) -> !llvm.ptr
llvm.store %339, %341 : i64, !llvm.ptr
%342 = arith.constant 1 : i32
%343 = arith.extsi %342 : i32 to i64
%344 = llvm.mlir.constant(1 : i64) : i64
%345 = llvm.alloca %344 x i64 : (i64) -> !llvm.ptr
llvm.store %343, %345 : i64, !llvm.ptr
cf.br ^bb84
^bb84:
%346 = llvm.load %345 : !llvm.ptr -> i64
%347 = arith.constant 1 : i32
%349 = arith.extsi %347 : i32 to i64
%348 = arith.cmpi eq, %346, %349 : i64
cf.cond_br %348, ^bb85, ^bb86
^bb85:
%352 = llvm.load %337 : !llvm.ptr -> i64
%353 = llvm.load %337 : !llvm.ptr -> i64
%351 = func.call @mulmod(%352, %353, %arg0) : (i64, i64, i64) -> i64
%354 = llvm.load %332 : !llvm.ptr -> i64
%350 = func.call @addmod(%351, %354, %arg0) : (i64, i64, i64) -> i64
llvm.store %350, %337 : i64, !llvm.ptr
%357 = llvm.load %341 : !llvm.ptr -> i64
%358 = llvm.load %341 : !llvm.ptr -> i64
%356 = func.call @mulmod(%357, %358, %arg0) : (i64, i64, i64) -> i64
%359 = llvm.load %332 : !llvm.ptr -> i64
%355 = func.call @addmod(%356, %359, %arg0) : (i64, i64, i64) -> i64
llvm.store %355, %341 : i64, !llvm.ptr
%362 = llvm.load %341 : !llvm.ptr -> i64
%363 = llvm.load %341 : !llvm.ptr -> i64
%361 = func.call @mulmod(%362, %363, %arg0) : (i64, i64, i64) -> i64
%364 = llvm.load %332 : !llvm.ptr -> i64
%360 = func.call @addmod(%361, %364, %arg0) : (i64, i64, i64) -> i64
llvm.store %360, %341 : i64, !llvm.ptr
%365 = llvm.load %337 : !llvm.ptr -> i64
%366 = llvm.load %341 : !llvm.ptr -> i64
%367 = arith.subi %365, %366 : i64
%368 = llvm.mlir.constant(1 : i64) : i64
%369 = llvm.alloca %368 x i64 : (i64) -> !llvm.ptr
llvm.store %367, %369 : i64, !llvm.ptr
%370 = llvm.load %369 : !llvm.ptr -> i64
%371 = arith.constant 0 : i32
%373 = arith.extsi %371 : i32 to i64
%372 = arith.cmpi slt, %370, %373 : i64
cf.cond_br %372, ^bb87, ^bb88
^bb87:
%374 = arith.constant 0 : i32
%375 = llvm.load %369 : !llvm.ptr -> i64
%377 = arith.extsi %374 : i32 to i64
%376 = arith.subi %377, %375 : i64
llvm.store %376, %369 : i64, !llvm.ptr
cf.br ^bb89
^bb88:
cf.br ^bb89
^bb89:
%379 = llvm.load %369 : !llvm.ptr -> i64
%378 = func.call @gcd(%379, %arg0) : (i64, i64) -> i64
llvm.store %378, %345 : i64, !llvm.ptr
cf.br ^bb84
^bb86:
%380 = llvm.load %345 : !llvm.ptr -> i64
%381 = arith.cmpi ne, %380, %arg0 : i64
cf.cond_br %381, ^bb90, ^bb91
^bb90:
%382 = llvm.load %345 : !llvm.ptr -> i64
func.return %382 : i64
^bb91:
cf.br ^bb92
^bb92:
%383 = llvm.load %332 : !llvm.ptr -> i64
%384 = arith.constant 1 : i32
%386 = arith.extsi %384 : i32 to i64
%385 = arith.addi %383, %386 : i64
llvm.store %385, %332 : i64, !llvm.ptr
cf.br ^bb81
^bb83:
func.return %arg0 : i64
}
func.func @factor_into(%arg0: i64, %arg1: !llvm.ptr, %arg2: !llvm.ptr) -> () {
%387 = llvm.mlir.constant(1 : i64) : i64
%388 = llvm.alloca %387 x i64 : (i64) -> !llvm.ptr
llvm.store %arg0, %388 : i64, !llvm.ptr
%389 = arith.constant 0 : i32
%390 = arith.constant 0 : i32
%391 = arith.extsi %390 : i32 to i64
%392 = llvm.getelementptr %arg2[%391] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %389, %392 : i32, !llvm.ptr
%393 = llvm.load %388 : !llvm.ptr -> i64
%394 = arith.constant 1 : i32
%396 = arith.extsi %394 : i32 to i64
%395 = arith.cmpi sle, %393, %396 : i64
cf.cond_br %395, ^bb93, ^bb94
^bb93:
func.return
^bb94:
cf.br ^bb95
^bb95:
%397 = arith.constant 2 : i32
%398 = arith.extsi %397 : i32 to i64
%399 = llvm.mlir.constant(1 : i64) : i64
%400 = llvm.alloca %399 x i64 : (i64) -> !llvm.ptr
llvm.store %398, %400 : i64, !llvm.ptr
cf.br ^bb96
^bb96:
%401 = llvm.load %400 : !llvm.ptr -> i64
%402 = llvm.load %400 : !llvm.ptr -> i64
%403 = arith.muli %401, %402 : i64
%404 = llvm.load %388 : !llvm.ptr -> i64
%405 = arith.cmpi sle, %403, %404 : i64
%406 = scf.if %405 -> (i1) {
%407 = llvm.load %400 : !llvm.ptr -> i64
%408 = arith.constant 1000000 : i32
%410 = arith.extsi %408 : i32 to i64
%409 = arith.cmpi sle, %407, %410 : i64
scf.yield %409 : i1
} else {
%411 = arith.constant false
scf.yield %411 : i1
}
cf.cond_br %406, ^bb97, ^bb98
^bb97:
%412 = llvm.load %388 : !llvm.ptr -> i64
%413 = llvm.load %400 : !llvm.ptr -> i64
%414 = arith.remsi %412, %413 : i64
%415 = arith.constant 0 : i32
%417 = arith.extsi %415 : i32 to i64
%416 = arith.cmpi eq, %414, %417 : i64
cf.cond_br %416, ^bb99, ^bb100
^bb99:
cf.br ^bb102
^bb102:
%418 = llvm.load %388 : !llvm.ptr -> i64
%419 = llvm.load %400 : !llvm.ptr -> i64
%420 = arith.remsi %418, %419 : i64
%421 = arith.constant 0 : i32
%423 = arith.extsi %421 : i32 to i64
%422 = arith.cmpi eq, %420, %423 : i64
cf.cond_br %422, ^bb103, ^bb104
^bb103:
%424 = llvm.load %400 : !llvm.ptr -> i64
%426 = arith.constant 0 : i32
%427 = arith.extsi %426 : i32 to i64
%428 = llvm.getelementptr %arg2[%427] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%425 = llvm.load %428 : !llvm.ptr -> i32
%429 = arith.extsi %425 : i32 to i64
%430 = llvm.getelementptr %arg1[%429] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %424, %430 : i64, !llvm.ptr
%432 = arith.constant 0 : i32
%433 = arith.extsi %432 : i32 to i64
%434 = llvm.getelementptr %arg2[%433] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%431 = llvm.load %434 : !llvm.ptr -> i32
%435 = arith.constant 1 : i32
%436 = arith.addi %431, %435 : i32
%437 = arith.constant 0 : i32
%438 = arith.extsi %437 : i32 to i64
%439 = llvm.getelementptr %arg2[%438] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %436, %439 : i32, !llvm.ptr
%440 = llvm.load %388 : !llvm.ptr -> i64
%441 = llvm.load %400 : !llvm.ptr -> i64
%442 = arith.divsi %440, %441 : i64
llvm.store %442, %388 : i64, !llvm.ptr
cf.br ^bb102
^bb104:
cf.br ^bb101
^bb100:
cf.br ^bb101
^bb101:
%443 = llvm.load %400 : !llvm.ptr -> i64
%444 = arith.constant 2 : i32
%446 = arith.extsi %444 : i32 to i64
%445 = arith.cmpi eq, %443, %446 : i64
cf.cond_br %445, ^bb105, ^bb106
^bb105:
%447 = arith.constant 3 : i32
%448 = arith.extsi %447 : i32 to i64
llvm.store %448, %400 : i64, !llvm.ptr
cf.br ^bb107
^bb106:
%449 = llvm.load %400 : !llvm.ptr -> i64
%450 = arith.constant 2 : i32
%452 = arith.extsi %450 : i32 to i64
%451 = arith.addi %449, %452 : i64
llvm.store %451, %400 : i64, !llvm.ptr
cf.br ^bb107
^bb107:
cf.br ^bb96
^bb98:
cf.br ^bb108
^bb108:
%453 = llvm.load %388 : !llvm.ptr -> i64
%454 = arith.constant 1 : i32
%456 = arith.extsi %454 : i32 to i64
%455 = arith.cmpi sgt, %453, %456 : i64
%457 = scf.if %455 -> (i1) {
%459 = llvm.load %388 : !llvm.ptr -> i64
%458 = func.call @is_prime(%459) : (i64) -> i1
%461 = arith.constant 1 : i1
%460 = arith.xori %458, %461 : i1
scf.yield %460 : i1
} else {
%463 = arith.constant false
scf.yield %463 : i1
}
cf.cond_br %457, ^bb109, ^bb110
^bb109:
%465 = llvm.load %388 : !llvm.ptr -> i64
%464 = func.call @pollard_rho(%465) : (i64) -> i64
%466 = llvm.mlir.constant(1 : i64) : i64
%467 = llvm.alloca %466 x i64 : (i64) -> !llvm.ptr
llvm.store %464, %467 : i64, !llvm.ptr
cf.br ^bb111
^bb111:
%469 = llvm.load %467 : !llvm.ptr -> i64
%468 = func.call @is_prime(%469) : (i64) -> i1
%471 = arith.constant 1 : i1
%470 = arith.xori %468, %471 : i1
cf.cond_br %470, ^bb112, ^bb113
^bb112:
%474 = llvm.load %467 : !llvm.ptr -> i64
%473 = func.call @pollard_rho(%474) : (i64) -> i64
llvm.store %473, %467 : i64, !llvm.ptr
cf.br ^bb111
^bb113:
cf.br ^bb114
^bb114:
%475 = llvm.load %388 : !llvm.ptr -> i64
%476 = llvm.load %467 : !llvm.ptr -> i64
%477 = arith.remsi %475, %476 : i64
%478 = arith.constant 0 : i32
%480 = arith.extsi %478 : i32 to i64
%479 = arith.cmpi eq, %477, %480 : i64
cf.cond_br %479, ^bb115, ^bb116
^bb115:
%481 = llvm.load %467 : !llvm.ptr -> i64
%483 = arith.constant 0 : i32
%484 = arith.extsi %483 : i32 to i64
%485 = llvm.getelementptr %arg2[%484] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%482 = llvm.load %485 : !llvm.ptr -> i32
%486 = arith.extsi %482 : i32 to i64
%487 = llvm.getelementptr %arg1[%486] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %481, %487 : i64, !llvm.ptr
%489 = arith.constant 0 : i32
%490 = arith.extsi %489 : i32 to i64
%491 = llvm.getelementptr %arg2[%490] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%488 = llvm.load %491 : !llvm.ptr -> i32
%492 = arith.constant 1 : i32
%493 = arith.addi %488, %492 : i32
%494 = arith.constant 0 : i32
%495 = arith.extsi %494 : i32 to i64
%496 = llvm.getelementptr %arg2[%495] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %493, %496 : i32, !llvm.ptr
%497 = llvm.load %388 : !llvm.ptr -> i64
%498 = llvm.load %467 : !llvm.ptr -> i64
%499 = arith.divsi %497, %498 : i64
llvm.store %499, %388 : i64, !llvm.ptr
cf.br ^bb114
^bb116:
cf.br ^bb108
^bb110:
%500 = llvm.load %388 : !llvm.ptr -> i64
%501 = arith.constant 1 : i32
%503 = arith.extsi %501 : i32 to i64
%502 = arith.cmpi sgt, %500, %503 : i64
cf.cond_br %502, ^bb117, ^bb118
^bb117:
%504 = llvm.load %388 : !llvm.ptr -> i64
%506 = arith.constant 0 : i32
%507 = arith.extsi %506 : i32 to i64
%508 = llvm.getelementptr %arg2[%507] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%505 = llvm.load %508 : !llvm.ptr -> i32
%509 = arith.extsi %505 : i32 to i64
%510 = llvm.getelementptr %arg1[%509] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %504, %510 : i64, !llvm.ptr
%512 = arith.constant 0 : i32
%513 = arith.extsi %512 : i32 to i64
%514 = llvm.getelementptr %arg2[%513] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%511 = llvm.load %514 : !llvm.ptr -> i32
%515 = arith.constant 1 : i32
%516 = arith.addi %511, %515 : i32
%517 = arith.constant 0 : i32
%518 = arith.extsi %517 : i32 to i64
%519 = llvm.getelementptr %arg2[%518] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %516, %519 : i32, !llvm.ptr
cf.br ^bb119
^bb118:
cf.br ^bb119
^bb119:
func.return
}
func.func @divisors_from(%arg0: !llvm.ptr, %arg1: i32, %arg2: !llvm.ptr, %arg3: !llvm.ptr) -> () {
%520 = arith.constant 1 : i32
%521 = arith.constant 0 : i32
%522 = arith.extsi %521 : i32 to i64
%523 = llvm.getelementptr %arg3[%522] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %520, %523 : i32, !llvm.ptr
%524 = arith.constant 1 : i32
%525 = arith.constant 0 : i32
%526 = arith.extsi %524 : i32 to i64
%527 = arith.extsi %525 : i32 to i64
%528 = llvm.getelementptr %arg2[%527] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %526, %528 : i64, !llvm.ptr
%529 = arith.constant 0 : i32
%530 = llvm.mlir.constant(1 : i64) : i64
%531 = llvm.alloca %530 x i32 : (i64) -> !llvm.ptr
llvm.store %529, %531 : i32, !llvm.ptr
cf.br ^bb120
^bb120:
%532 = llvm.load %531 : !llvm.ptr -> i32
%533 = arith.cmpi slt, %532, %arg1 : i32
cf.cond_br %533, ^bb121, ^bb122
^bb121:
%535 = llvm.load %531 : !llvm.ptr -> i32
%536 = arith.extsi %535 : i32 to i64
%537 = llvm.getelementptr %arg0[%536] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%534 = llvm.load %537 : !llvm.ptr -> i64
%538 = arith.constant 0 : i32
%539 = llvm.mlir.constant(1 : i64) : i64
%540 = llvm.alloca %539 x i32 : (i64) -> !llvm.ptr
llvm.store %538, %540 : i32, !llvm.ptr
cf.br ^bb123
^bb123:
%541 = llvm.load %531 : !llvm.ptr -> i32
%542 = arith.cmpi slt, %541, %arg1 : i32
%543 = scf.if %542 -> (i1) {
%545 = llvm.load %531 : !llvm.ptr -> i32
%546 = arith.extsi %545 : i32 to i64
%547 = llvm.getelementptr %arg0[%546] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%544 = llvm.load %547 : !llvm.ptr -> i64
%548 = arith.cmpi eq, %544, %534 : i64
scf.yield %548 : i1
} else {
%549 = arith.constant false
scf.yield %549 : i1
}
cf.cond_br %543, ^bb124, ^bb125
^bb124:
%550 = llvm.load %540 : !llvm.ptr -> i32
%551 = arith.constant 1 : i32
%552 = arith.addi %550, %551 : i32
llvm.store %552, %540 : i32, !llvm.ptr
%553 = llvm.load %531 : !llvm.ptr -> i32
%554 = arith.constant 1 : i32
%555 = arith.addi %553, %554 : i32
llvm.store %555, %531 : i32, !llvm.ptr
cf.br ^bb123
^bb125:
%557 = arith.constant 0 : i32
%558 = arith.extsi %557 : i32 to i64
%559 = llvm.getelementptr %arg3[%558] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%556 = llvm.load %559 : !llvm.ptr -> i32
%560 = arith.constant 1 : i32
%561 = arith.extsi %560 : i32 to i64
%562 = llvm.mlir.constant(1 : i64) : i64
%563 = llvm.alloca %562 x i64 : (i64) -> !llvm.ptr
llvm.store %561, %563 : i64, !llvm.ptr
%564 = arith.constant 0 : i32
%565 = llvm.load %540 : !llvm.ptr -> i32
%566 = arith.index_cast %564 : i32 to index
%567 = arith.index_cast %565 : i32 to index
%569 = arith.constant 1 : index
%570 = arith.constant -1 : index
%571 = arith.cmpi sle, %566, %567 : index
%568 = arith.select %571, %569, %570 : index
cf.br ^bb126(%566 : index)
^bb126(%572: index):
%573 = arith.cmpi slt, %572, %567 : index
%574 = arith.cmpi sgt, %572, %567 : index
%575 = arith.select %571, %573, %574 : i1
cf.cond_br %575, ^bb127(%572 : index), ^bb128(%572 : index)
^bb127(%576: index):
%577 = llvm.load %563 : !llvm.ptr -> i64
%578 = arith.muli %577, %534 : i64
llvm.store %578, %563 : i64, !llvm.ptr
%579 = arith.constant 0 : i32
%580 = arith.index_cast %579 : i32 to index
%581 = arith.index_cast %556 : i32 to index
%583 = arith.constant 1 : index
%584 = arith.constant -1 : index
%585 = arith.cmpi sle, %580, %581 : index
%582 = arith.select %585, %583, %584 : index
cf.br ^bb129(%580 : index)
^bb129(%586: index):
%587 = arith.cmpi slt, %586, %581 : index
%588 = arith.cmpi sgt, %586, %581 : index
%589 = arith.select %585, %587, %588 : i1
cf.cond_br %589, ^bb130(%586 : index), ^bb131(%586 : index)
^bb130(%590: index):
%592 = arith.index_cast %590 : index to i64
%593 = llvm.getelementptr %arg2[%592] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%591 = llvm.load %593 : !llvm.ptr -> i64
%594 = llvm.load %563 : !llvm.ptr -> i64
%595 = arith.muli %591, %594 : i64
%597 = arith.constant 0 : i32
%598 = arith.extsi %597 : i32 to i64
%599 = llvm.getelementptr %arg3[%598] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%596 = llvm.load %599 : !llvm.ptr -> i32
%600 = arith.extsi %596 : i32 to i64
%601 = llvm.getelementptr %arg2[%600] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %595, %601 : i64, !llvm.ptr
%603 = arith.constant 0 : i32
%604 = arith.extsi %603 : i32 to i64
%605 = llvm.getelementptr %arg3[%604] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%602 = llvm.load %605 : !llvm.ptr -> i32
%606 = arith.constant 1 : i32
%607 = arith.addi %602, %606 : i32
%608 = arith.constant 0 : i32
%609 = arith.extsi %608 : i32 to i64
%610 = llvm.getelementptr %arg3[%609] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %607, %610 : i32, !llvm.ptr
%611 = arith.addi %590, %582 : index
cf.br ^bb129(%611 : index)
^bb131(%612: index):
%613 = arith.addi %576, %568 : index
cf.br ^bb126(%613 : index)
^bb128(%614: index):
cf.br ^bb120
^bb122:
func.return
}
func.func @isqrt(%arg0: i64) -> i64 {
%615 = arith.constant 0 : i32
%617 = arith.extsi %615 : i32 to i64
%616 = arith.cmpi sle, %arg0, %617 : i64
cf.cond_br %616, ^bb132, ^bb133
^bb132:
%618 = arith.constant 0 : i32
%619 = arith.extsi %618 : i32 to i64
func.return %619 : i64
^bb133:
cf.br ^bb134
^bb134:
%620 = llvm.mlir.constant(1 : i64) : i64
%621 = llvm.alloca %620 x i64 : (i64) -> !llvm.ptr
llvm.store %arg0, %621 : i64, !llvm.ptr
%622 = llvm.load %621 : !llvm.ptr -> i64
%623 = arith.constant 1 : i32
%625 = arith.extsi %623 : i32 to i64
%624 = arith.addi %622, %625 : i64
%626 = arith.constant 2 : i32
%628 = arith.extsi %626 : i32 to i64
%627 = arith.divsi %624, %628 : i64
%629 = llvm.mlir.constant(1 : i64) : i64
%630 = llvm.alloca %629 x i64 : (i64) -> !llvm.ptr
llvm.store %627, %630 : i64, !llvm.ptr
cf.br ^bb135
^bb135:
%631 = llvm.load %630 : !llvm.ptr -> i64
%632 = llvm.load %621 : !llvm.ptr -> i64
%633 = arith.cmpi slt, %631, %632 : i64
cf.cond_br %633, ^bb136, ^bb137
^bb136:
%634 = llvm.load %630 : !llvm.ptr -> i64
llvm.store %634, %621 : i64, !llvm.ptr
%635 = llvm.load %621 : !llvm.ptr -> i64
%636 = llvm.load %621 : !llvm.ptr -> i64
%637 = arith.divsi %arg0, %636 : i64
%638 = arith.addi %635, %637 : i64
%639 = arith.constant 2 : i32
%641 = arith.extsi %639 : i32 to i64
%640 = arith.divsi %638, %641 : i64
llvm.store %640, %630 : i64, !llvm.ptr
cf.br ^bb135
^bb137:
%642 = llvm.load %621 : !llvm.ptr -> i64
func.return %642 : i64
}
func.func @iroot(%arg0: i64, %arg1: i32) -> i64 {
%643 = arith.constant 1 : i32
%644 = arith.cmpi eq, %arg1, %643 : i32
cf.cond_br %644, ^bb138, ^bb139
^bb138:
func.return %arg0 : i64
^bb139:
cf.br ^bb140
^bb140:
%645 = arith.constant 2 : i32
%646 = arith.cmpi eq, %arg1, %645 : i32
cf.cond_br %646, ^bb141, ^bb142
^bb141:
%647 = func.call @isqrt(%arg0) : (i64) -> i64
func.return %647 : i64
^bb142:
cf.br ^bb143
^bb143:
%649 = func.call @isqrt(%arg0) : (i64) -> i64
%648 = func.call @isqrt(%649) : (i64) -> i64
%650 = arith.constant 2 : i32
%652 = arith.extsi %650 : i32 to i64
%651 = arith.addi %648, %652 : i64
%653 = llvm.mlir.constant(1 : i64) : i64
%654 = llvm.alloca %653 x i64 : (i64) -> !llvm.ptr
llvm.store %651, %654 : i64, !llvm.ptr
cf.br ^bb144
^bb144:
%655 = arith.constant 1 : i1
cf.cond_br %655, ^bb145, ^bb146
^bb145:
%656 = arith.constant 1 : i32
%657 = arith.extsi %656 : i32 to i64
%658 = llvm.mlir.constant(1 : i64) : i64
%659 = llvm.alloca %658 x i64 : (i64) -> !llvm.ptr
llvm.store %657, %659 : i64, !llvm.ptr
%660 = arith.constant 0 : i32
%661 = llvm.mlir.constant(1 : i64) : i64
%662 = llvm.alloca %661 x i32 : (i64) -> !llvm.ptr
llvm.store %660, %662 : i32, !llvm.ptr
%663 = arith.constant 0 : i1
%664 = llvm.mlir.constant(1 : i64) : i64
%665 = llvm.alloca %664 x i1 : (i64) -> !llvm.ptr
llvm.store %663, %665 : i1, !llvm.ptr
cf.br ^bb147
^bb147:
%666 = llvm.load %662 : !llvm.ptr -> i32
%667 = arith.cmpi slt, %666, %arg1 : i32
cf.cond_br %667, ^bb148, ^bb149
^bb148:
%668 = llvm.load %659 : !llvm.ptr -> i64
%669 = llvm.load %654 : !llvm.ptr -> i64
%670 = arith.divsi %arg0, %669 : i64
%671 = arith.cmpi sgt, %668, %670 : i64
cf.cond_br %671, ^bb150, ^bb151
^bb150:
%672 = arith.constant 1 : i1
llvm.store %672, %665 : i1, !llvm.ptr
cf.br ^bb149
^bb151:
cf.br ^bb152
^bb152:
%673 = llvm.load %659 : !llvm.ptr -> i64
%674 = llvm.load %654 : !llvm.ptr -> i64
%675 = arith.muli %673, %674 : i64
llvm.store %675, %659 : i64, !llvm.ptr
%676 = llvm.load %662 : !llvm.ptr -> i32
%677 = arith.constant 1 : i32
%678 = arith.addi %676, %677 : i32
llvm.store %678, %662 : i32, !llvm.ptr
cf.br ^bb147
^bb149:
%679 = llvm.load %665 : !llvm.ptr -> i1
%681 = arith.constant 1 : i1
%680 = arith.xori %679, %681 : i1
%683 = scf.if %680 -> (i1) {
%684 = llvm.load %659 : !llvm.ptr -> i64
%685 = arith.cmpi sle, %684, %arg0 : i64
scf.yield %685 : i1
} else {
%686 = arith.constant false
scf.yield %686 : i1
}
cf.cond_br %683, ^bb153, ^bb154
^bb153:
%687 = arith.constant 1 : i32
%688 = arith.extsi %687 : i32 to i64
%689 = llvm.mlir.constant(1 : i64) : i64
%690 = llvm.alloca %689 x i64 : (i64) -> !llvm.ptr
llvm.store %688, %690 : i64, !llvm.ptr
%691 = arith.constant 1 : i1
%692 = llvm.mlir.constant(1 : i64) : i64
%693 = llvm.alloca %692 x i1 : (i64) -> !llvm.ptr
llvm.store %691, %693 : i1, !llvm.ptr
%694 = arith.constant 0 : i32
llvm.store %694, %662 : i32, !llvm.ptr
cf.br ^bb156
^bb156:
%695 = llvm.load %662 : !llvm.ptr -> i32
%696 = arith.cmpi slt, %695, %arg1 : i32
cf.cond_br %696, ^bb157, ^bb158
^bb157:
%697 = llvm.load %690 : !llvm.ptr -> i64
%698 = llvm.load %654 : !llvm.ptr -> i64
%699 = arith.constant 1 : i32
%701 = arith.extsi %699 : i32 to i64
%700 = arith.addi %698, %701 : i64
%702 = arith.divsi %arg0, %700 : i64
%703 = arith.cmpi sgt, %697, %702 : i64
cf.cond_br %703, ^bb159, ^bb160
^bb159:
%704 = arith.constant 0 : i1
llvm.store %704, %693 : i1, !llvm.ptr
cf.br ^bb158
^bb160:
cf.br ^bb161
^bb161:
%705 = llvm.load %690 : !llvm.ptr -> i64
%706 = llvm.load %654 : !llvm.ptr -> i64
%707 = arith.constant 1 : i32
%709 = arith.extsi %707 : i32 to i64
%708 = arith.addi %706, %709 : i64
%710 = arith.muli %705, %708 : i64
llvm.store %710, %690 : i64, !llvm.ptr
%711 = llvm.load %662 : !llvm.ptr -> i32
%712 = arith.constant 1 : i32
%713 = arith.addi %711, %712 : i32
llvm.store %713, %662 : i32, !llvm.ptr
cf.br ^bb156
^bb158:
%714 = llvm.load %693 : !llvm.ptr -> i1
%715 = scf.if %714 -> (i1) {
%716 = llvm.load %690 : !llvm.ptr -> i64
%717 = arith.cmpi sle, %716, %arg0 : i64
scf.yield %717 : i1
} else {
%718 = arith.constant false
scf.yield %718 : i1
}
cf.cond_br %715, ^bb162, ^bb163
^bb162:
%719 = llvm.load %654 : !llvm.ptr -> i64
%720 = arith.constant 1 : i32
%722 = arith.extsi %720 : i32 to i64
%721 = arith.addi %719, %722 : i64
llvm.store %721, %654 : i64, !llvm.ptr
cf.br ^bb144
^bb163:
cf.br ^bb164
^bb164:
%723 = llvm.load %654 : !llvm.ptr -> i64
func.return %723 : i64
^bb154:
cf.br ^bb155
^bb155:
%724 = llvm.load %654 : !llvm.ptr -> i64
%725 = arith.constant 1 : i32
%727 = arith.extsi %725 : i32 to i64
%726 = arith.subi %724, %727 : i64
llvm.store %726, %654 : i64, !llvm.ptr
%728 = llvm.load %654 : !llvm.ptr -> i64
%729 = arith.constant 0 : i32
%731 = arith.extsi %729 : i32 to i64
%730 = arith.cmpi sle, %728, %731 : i64
cf.cond_br %730, ^bb165, ^bb166
^bb165:
%732 = arith.constant 0 : i32
%733 = arith.extsi %732 : i32 to i64
func.return %733 : i64
^bb166:
cf.br ^bb167
^bb167:
cf.br ^bb144
^bb146:
%734 = llvm.load %654 : !llvm.ptr -> i64
func.return %734 : i64
}
// Constant: LIMIT
llvm.mlir.global internal constant @LIMIT(200000000000 : i64) : i64
// Module static: PRIMES
llvm.mlir.global internal @PRIMES() {addr_space = 0 : i32} : !llvm.ptr {
%735 = llvm.mlir.zero : !llvm.ptr
llvm.return %735 : !llvm.ptr
}
// Module static: NP
llvm.mlir.global internal @NP(0 : i64) : i64
// Module static: SOLS
llvm.mlir.global internal @SOLS() {addr_space = 0 : i32} : !llvm.ptr {
%736 = llvm.mlir.zero : !llvm.ptr
llvm.return %736 : !llvm.ptr
}
// Module static: NS
llvm.mlir.global internal @NS(0 : i64) : i64
// Module static: SEEN_KEYS
llvm.mlir.global internal @SEEN_KEYS() {addr_space = 0 : i32} : !llvm.ptr {
%737 = llvm.mlir.zero : !llvm.ptr
llvm.return %737 : !llvm.ptr
}
// Module static: SEEN
llvm.mlir.global internal @SEEN() {addr_space = 0 : i32} : !llvm.ptr {
%738 = llvm.mlir.zero : !llvm.ptr
llvm.return %738 : !llvm.ptr
}
// Constant: SCAP
llvm.mlir.global internal constant @SCAP(1048576 : i64) : i64
func.func @sol_add(%arg0: i64) -> () {
%739 = llvm.mlir.addressof @SCAP : !llvm.ptr
%740 = llvm.load %739 : !llvm.ptr -> i64
%741 = arith.remsi %arg0, %740 : i64
%742 = llvm.mlir.constant(1 : i64) : i64
%743 = llvm.alloca %742 x i64 : (i64) -> !llvm.ptr
llvm.store %741, %743 : i64, !llvm.ptr
%744 = llvm.load %743 : !llvm.ptr -> i64
%745 = arith.constant 0 : i32
%747 = arith.extsi %745 : i32 to i64
%746 = arith.cmpi slt, %744, %747 : i64
cf.cond_br %746, ^bb168, ^bb169
^bb168:
%748 = arith.constant 0 : i32
%749 = llvm.load %743 : !llvm.ptr -> i64
%751 = arith.extsi %748 : i32 to i64
%750 = arith.subi %751, %749 : i64
llvm.store %750, %743 : i64, !llvm.ptr
cf.br ^bb170
^bb169:
cf.br ^bb170
^bb170:
cf.br ^bb171
^bb171:
%753 = llvm.mlir.addressof @SEEN : !llvm.ptr
%754 = llvm.load %753 : !llvm.ptr -> !llvm.ptr
%755 = llvm.load %743 : !llvm.ptr -> i64
%756 = llvm.getelementptr %754[%755] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%752 = llvm.load %756 : !llvm.ptr -> i8
%757 = arith.constant 1 : i32
%759 = arith.extsi %752 : i8 to i32
%758 = arith.cmpi eq, %759, %757 : i32
cf.cond_br %758, ^bb172, ^bb173
^bb172:
%761 = llvm.mlir.addressof @SEEN_KEYS : !llvm.ptr
%762 = llvm.load %761 : !llvm.ptr -> !llvm.ptr
%763 = llvm.load %743 : !llvm.ptr -> i64
%764 = llvm.getelementptr %762[%763] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%760 = llvm.load %764 : !llvm.ptr -> i64
%765 = arith.cmpi eq, %760, %arg0 : i64
cf.cond_br %765, ^bb174, ^bb175
^bb174:
func.return
^bb175:
cf.br ^bb176
^bb176:
%766 = llvm.load %743 : !llvm.ptr -> i64
%767 = arith.constant 1 : i32
%769 = arith.extsi %767 : i32 to i64
%768 = arith.addi %766, %769 : i64
llvm.store %768, %743 : i64, !llvm.ptr
%770 = llvm.load %743 : !llvm.ptr -> i64
%771 = llvm.mlir.addressof @SCAP : !llvm.ptr
%772 = llvm.load %771 : !llvm.ptr -> i64
%773 = arith.cmpi sge, %770, %772 : i64
cf.cond_br %773, ^bb177, ^bb178
^bb177:
%774 = arith.constant 0 : i32
%775 = arith.extsi %774 : i32 to i64
llvm.store %775, %743 : i64, !llvm.ptr
cf.br ^bb179
^bb178:
cf.br ^bb179
^bb179:
cf.br ^bb171
^bb173:
%776 = arith.constant 1 : i32
%777 = llvm.mlir.addressof @SEEN : !llvm.ptr
%778 = llvm.load %777 : !llvm.ptr -> !llvm.ptr
%779 = llvm.load %743 : !llvm.ptr -> i64
%780 = arith.trunci %776 : i32 to i8
%781 = llvm.getelementptr %778[%779] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %780, %781 : i8, !llvm.ptr
%782 = llvm.mlir.addressof @SEEN_KEYS : !llvm.ptr
%783 = llvm.load %782 : !llvm.ptr -> !llvm.ptr
%784 = llvm.load %743 : !llvm.ptr -> i64
%785 = llvm.getelementptr %783[%784] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %arg0, %785 : i64, !llvm.ptr
%786 = llvm.mlir.addressof @SOLS : !llvm.ptr
%787 = llvm.load %786 : !llvm.ptr -> !llvm.ptr
%788 = llvm.mlir.addressof @NS : !llvm.ptr
%789 = llvm.load %788 : !llvm.ptr -> i64
%790 = llvm.getelementptr %787[%789] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %arg0, %790 : i64, !llvm.ptr
%791 = llvm.mlir.addressof @NS : !llvm.ptr
%792 = llvm.load %791 : !llvm.ptr -> i64
%793 = arith.constant 1 : i32
%795 = arith.extsi %793 : i32 to i64
%794 = arith.addi %792, %795 : i64
%796 = llvm.mlir.addressof @NS : !llvm.ptr
llvm.store %794, %796 : i64, !llvm.ptr
func.return
}
func.func @try_last(%arg0: i64, %arg1: i64, %arg2: i64) -> () {
%797 = arith.subi %arg0, %arg1 : i64
%798 = arith.constant 0 : i32
%800 = arith.extsi %798 : i32 to i64
%799 = arith.cmpi sle, %797, %800 : i64
cf.cond_br %799, ^bb180, ^bb181
^bb180:
func.return
^bb181:
cf.br ^bb182
^bb182:
%801 = llvm.mlir.addressof @LIMIT : !llvm.ptr
%802 = llvm.load %801 : !llvm.ptr -> i64
%803 = arith.divsi %802, %arg0 : i64
%804 = arith.cmpi sle, %803, %arg2 : i64
cf.cond_br %804, ^bb183, ^bb184
^bb183:
func.return
^bb184:
cf.br ^bb185
^bb185:
%805 = arith.constant 1 : i32
%807 = arith.extsi %805 : i32 to i64
%806 = arith.subi %arg2, %807 : i64
%808 = arith.muli %arg1, %806 : i64
%809 = arith.constant 1 : i32
%811 = arith.extsi %809 : i32 to i64
%810 = arith.subi %808, %811 : i64
%812 = arith.muli %arg2, %797 : i64
%813 = arith.addi %arg1, %812 : i64
%814 = arith.divsi %810, %813 : i64
%815 = arith.constant 1 : i32
%817 = arith.extsi %815 : i32 to i64
%816 = arith.addi %814, %817 : i64
%818 = llvm.mlir.constant(1 : i64) : i64
%819 = llvm.alloca %818 x i64 : (i64) -> !llvm.ptr
llvm.store %816, %819 : i64, !llvm.ptr
%820 = llvm.load %819 : !llvm.ptr -> i64
%821 = arith.constant 1 : i32
%823 = arith.extsi %821 : i32 to i64
%822 = arith.cmpi slt, %820, %823 : i64
cf.cond_br %822, ^bb186, ^bb187
^bb186:
%824 = arith.constant 1 : i32
%825 = arith.extsi %824 : i32 to i64
llvm.store %825, %819 : i64, !llvm.ptr
cf.br ^bb188
^bb187:
cf.br ^bb188
^bb188:
%826 = arith.constant 1 : i32
%828 = arith.extsi %826 : i32 to i64
%827 = arith.subi %803, %828 : i64
%829 = arith.muli %arg1, %827 : i64
%830 = arith.constant 1 : i32
%832 = arith.extsi %830 : i32 to i64
%831 = arith.subi %829, %832 : i64
%833 = arith.muli %803, %797 : i64
%834 = arith.addi %arg1, %833 : i64
%835 = arith.constant 0 : i32
%837 = arith.extsi %835 : i32 to i64
%836 = arith.cmpi slt, %831, %837 : i64
cf.cond_br %836, ^bb189, ^bb190
^bb189:
func.return
^bb190:
cf.br ^bb191
^bb191:
%838 = arith.divsi %831, %834 : i64
%839 = llvm.mlir.constant(1 : i64) : i64
%840 = llvm.alloca %839 x i64 : (i64) -> !llvm.ptr
llvm.store %838, %840 : i64, !llvm.ptr
%841 = arith.constant 1 : i32
%843 = arith.extsi %841 : i32 to i64
%842 = arith.subi %arg1, %843 : i64
%844 = arith.divsi %842, %797 : i64
%845 = llvm.load %840 : !llvm.ptr -> i64
%846 = arith.cmpi slt, %844, %845 : i64
cf.cond_br %846, ^bb192, ^bb193
^bb192:
llvm.store %844, %840 : i64, !llvm.ptr
cf.br ^bb194
^bb193:
cf.br ^bb194
^bb194:
%847 = llvm.load %840 : !llvm.ptr -> i64
%848 = llvm.load %819 : !llvm.ptr -> i64
%849 = arith.cmpi slt, %847, %848 : i64
cf.cond_br %849, ^bb195, ^bb196
^bb195:
func.return
^bb196:
cf.br ^bb197
^bb197:
%850 = llvm.load %819 : !llvm.ptr -> i64
%851 = llvm.mlir.constant(1 : i64) : i64
%852 = llvm.alloca %851 x i64 : (i64) -> !llvm.ptr
llvm.store %850, %852 : i64, !llvm.ptr
cf.br ^bb198
^bb198:
%853 = llvm.load %852 : !llvm.ptr -> i64
%854 = llvm.load %840 : !llvm.ptr -> i64
%855 = arith.cmpi sle, %853, %854 : i64
cf.cond_br %855, ^bb199, ^bb200
^bb199:
%856 = llvm.load %852 : !llvm.ptr -> i64
%857 = arith.muli %856, %797 : i64
%858 = arith.subi %arg1, %857 : i64
%859 = arith.constant 0 : i32
%861 = arith.extsi %859 : i32 to i64
%860 = arith.cmpi sle, %858, %861 : i64
cf.cond_br %860, ^bb201, ^bb202
^bb201:
cf.br ^bb200
^bb202:
cf.br ^bb203
^bb203:
%862 = llvm.load %852 : !llvm.ptr -> i64
%863 = arith.constant 1 : i32
%865 = arith.extsi %863 : i32 to i64
%864 = arith.addi %862, %865 : i64
%866 = arith.muli %arg1, %864 : i64
%867 = arith.constant 1 : i32
%869 = arith.extsi %867 : i32 to i64
%868 = arith.addi %866, %869 : i64
%870 = arith.remsi %868, %858 : i64
%871 = arith.constant 0 : i32
%873 = arith.extsi %871 : i32 to i64
%872 = arith.cmpi eq, %870, %873 : i64
cf.cond_br %872, ^bb204, ^bb205
^bb204:
%874 = arith.divsi %868, %858 : i64
%875 = arith.cmpi sgt, %874, %arg2 : i64
%876 = scf.if %875 -> (i1) {
%877 = llvm.mlir.addressof @LIMIT : !llvm.ptr
%878 = llvm.load %877 : !llvm.ptr -> i64
%879 = arith.divsi %878, %874 : i64
%880 = arith.cmpi sle, %arg0, %879 : i64
scf.yield %880 : i1
} else {
%881 = arith.constant false
scf.yield %881 : i1
}
cf.cond_br %876, ^bb207, ^bb208
^bb207:
%882 = func.call @is_prime(%874) : (i64) -> i1
cf.cond_br %882, ^bb210, ^bb211
^bb210:
%883 = arith.muli %arg0, %874 : i64
%884 = arith.constant 1 : i32
%886 = arith.extsi %884 : i32 to i64
%885 = arith.subi %874, %886 : i64
%887 = arith.muli %arg1, %885 : i64
%888 = arith.constant 1 : i32
%890 = arith.extsi %888 : i32 to i64
%889 = arith.subi %883, %890 : i64
%891 = arith.subi %883, %887 : i64
%892 = arith.remsi %889, %891 : i64
%893 = arith.constant 0 : i32
%895 = arith.extsi %893 : i32 to i64
%894 = arith.cmpi eq, %892, %895 : i64
cf.cond_br %894, ^bb213, ^bb214
^bb213:
func.call @sol_add(%883) : (i64) -> ()
cf.br ^bb215
^bb214:
cf.br ^bb215
^bb215:
cf.br ^bb212
^bb211:
cf.br ^bb212
^bb212:
cf.br ^bb209
^bb208:
cf.br ^bb209
^bb209:
cf.br ^bb206
^bb205:
cf.br ^bb206
^bb206:
%897 = llvm.load %852 : !llvm.ptr -> i64
%898 = arith.constant 1 : i32
%900 = arith.extsi %898 : i32 to i64
%899 = arith.addi %897, %900 : i64
llvm.store %899, %852 : i64, !llvm.ptr
cf.br ^bb198
^bb200:
func.return
}
func.func @dfs(%arg0: i64, %arg1: i32, %arg2: i64, %arg3: i64, %arg4: i64) -> () {
%901 = arith.constant 0 : i32
%902 = arith.cmpi eq, %arg1, %901 : i32
cf.cond_br %902, ^bb216, ^bb217
^bb216:
func.call @try_last(%arg2, %arg3, %arg4) : (i64, i64, i64) -> ()
func.return
^bb217:
cf.br ^bb218
^bb218:
%905 = llvm.mlir.addressof @LIMIT : !llvm.ptr
%906 = llvm.load %905 : !llvm.ptr -> i64
%907 = arith.divsi %906, %arg2 : i64
%908 = arith.constant 1 : i32
%909 = arith.addi %arg1, %908 : i32
%904 = func.call @iroot(%907, %909) : (i64, i32) -> i64
%910 = llvm.mlir.constant(1 : i64) : i64
%911 = llvm.alloca %910 x i64 : (i64) -> !llvm.ptr
llvm.store %arg0, %911 : i64, !llvm.ptr
cf.br ^bb219
^bb219:
%912 = llvm.load %911 : !llvm.ptr -> i64
%913 = llvm.mlir.addressof @NP : !llvm.ptr
%914 = llvm.load %913 : !llvm.ptr -> i64
%915 = arith.cmpi slt, %912, %914 : i64
cf.cond_br %915, ^bb220, ^bb221
^bb220:
%917 = llvm.mlir.addressof @PRIMES : !llvm.ptr
%918 = llvm.load %917 : !llvm.ptr -> !llvm.ptr
%919 = llvm.load %911 : !llvm.ptr -> i64
%920 = llvm.getelementptr %918[%919] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%916 = llvm.load %920 : !llvm.ptr -> i64
%921 = arith.cmpi sgt, %916, %904 : i64
cf.cond_br %921, ^bb222, ^bb223
^bb222:
cf.br ^bb221
^bb223:
cf.br ^bb224
^bb224:
%923 = llvm.load %911 : !llvm.ptr -> i64
%924 = arith.constant 1 : i32
%926 = arith.extsi %924 : i32 to i64
%925 = arith.addi %923, %926 : i64
%927 = arith.constant 1 : i32
%928 = arith.subi %arg1, %927 : i32
%929 = arith.muli %arg2, %916 : i64
%930 = arith.constant 1 : i32
%932 = arith.extsi %930 : i32 to i64
%931 = arith.subi %916, %932 : i64
%933 = arith.muli %arg3, %931 : i64
func.call @dfs(%925, %928, %929, %933, %916) : (i64, i32, i64, i64, i64) -> ()
%934 = llvm.load %911 : !llvm.ptr -> i64
%935 = arith.constant 1 : i32
%937 = arith.extsi %935 : i32 to i64
%936 = arith.addi %934, %937 : i64
llvm.store %936, %911 : i64, !llvm.ptr
cf.br ^bb219
^bb221:
func.return
}
func.func @main() -> i32 {
%939 = llvm.mlir.addressof @LIMIT : !llvm.ptr
%940 = llvm.load %939 : !llvm.ptr -> i64
%938 = func.call @isqrt(%940) : (i64) -> i64
%941 = arith.constant 1 : i32
%943 = arith.extsi %941 : i32 to i64
%942 = arith.addi %938, %943 : i64
%945 = arith.constant 1 : i32
%947 = arith.extsi %945 : i32 to i64
%946 = arith.addi %942, %947 : i64
%948 = arith.constant 1 : i32
%949 = arith.extsi %948 : i32 to i64
%944 = func.call @calloc(%946, %949) : (i64, i64) -> !llvm.ptr
%951 = arith.constant 5 : i32
%953 = arith.extsi %951 : i32 to i64
%952 = arith.divsi %942, %953 : i64
%954 = arith.constant 8 : i32
%955 = arith.extsi %954 : i32 to i64
%950 = func.call @calloc(%952, %955) : (i64, i64) -> !llvm.ptr
%956 = llvm.mlir.addressof @PRIMES : !llvm.ptr
llvm.store %950, %956 : !llvm.ptr, !llvm.ptr
%958 = arith.constant 100000 : i32
%959 = arith.constant 8 : i32
%960 = arith.extsi %958 : i32 to i64
%961 = arith.extsi %959 : i32 to i64
%957 = func.call @calloc(%960, %961) : (i64, i64) -> !llvm.ptr
%962 = llvm.mlir.addressof @SOLS : !llvm.ptr
llvm.store %957, %962 : !llvm.ptr, !llvm.ptr
%964 = llvm.mlir.addressof @SCAP : !llvm.ptr
%965 = llvm.load %964 : !llvm.ptr -> i64
%966 = arith.constant 8 : i32
%967 = arith.extsi %966 : i32 to i64
%963 = func.call @calloc(%965, %967) : (i64, i64) -> !llvm.ptr
%968 = llvm.mlir.addressof @SEEN_KEYS : !llvm.ptr
llvm.store %963, %968 : !llvm.ptr, !llvm.ptr
%970 = llvm.mlir.addressof @SCAP : !llvm.ptr
%971 = llvm.load %970 : !llvm.ptr -> i64
%972 = arith.constant 1 : i32
%973 = arith.extsi %972 : i32 to i64
%969 = func.call @calloc(%971, %973) : (i64, i64) -> !llvm.ptr
%974 = llvm.mlir.addressof @SEEN : !llvm.ptr
llvm.store %969, %974 : !llvm.ptr, !llvm.ptr
%975 = llvm.mlir.zero : !llvm.ptr
%976 = llvm.icmp "eq" %944, %975 : !llvm.ptr
%977 = scf.if %976 -> (i1) {
%978 = arith.constant true
scf.yield %978 : i1
} else {
%979 = llvm.mlir.addressof @PRIMES : !llvm.ptr
%980 = llvm.load %979 : !llvm.ptr -> !llvm.ptr
%981 = llvm.mlir.zero : !llvm.ptr
%982 = llvm.icmp "eq" %980, %981 : !llvm.ptr
scf.yield %982 : i1
}
cf.cond_br %977, ^bb225, ^bb226
^bb225:
%983 = arith.constant 1 : i32
func.return %983 : i32
^bb226:
cf.br ^bb227
^bb227:
%984 = arith.constant 0 : i32
%985 = arith.extsi %984 : i32 to i64
%986 = llvm.mlir.constant(1 : i64) : i64
%987 = llvm.alloca %986 x i64 : (i64) -> !llvm.ptr
llvm.store %985, %987 : i64, !llvm.ptr
cf.br ^bb228
^bb228:
%988 = llvm.load %987 : !llvm.ptr -> i64
%989 = arith.cmpi sle, %988, %942 : i64
cf.cond_br %989, ^bb229, ^bb230
^bb229:
%990 = arith.constant 1 : i32
%991 = llvm.load %987 : !llvm.ptr -> i64
%992 = arith.trunci %990 : i32 to i8
%993 = llvm.getelementptr %944[%991] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %992, %993 : i8, !llvm.ptr
%994 = llvm.load %987 : !llvm.ptr -> i64
%995 = arith.constant 1 : i32
%997 = arith.extsi %995 : i32 to i64
%996 = arith.addi %994, %997 : i64
llvm.store %996, %987 : i64, !llvm.ptr
cf.br ^bb228
^bb230:
%998 = arith.constant 0 : i32
%999 = arith.constant 0 : i32
%1000 = arith.trunci %998 : i32 to i8
%1001 = arith.extsi %999 : i32 to i64
%1002 = llvm.getelementptr %944[%1001] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %1000, %1002 : i8, !llvm.ptr
%1003 = arith.constant 0 : i32
%1004 = arith.constant 1 : i32
%1005 = arith.trunci %1003 : i32 to i8
%1006 = arith.extsi %1004 : i32 to i64
%1007 = llvm.getelementptr %944[%1006] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %1005, %1007 : i8, !llvm.ptr
%1008 = arith.constant 2 : i32
%1009 = arith.extsi %1008 : i32 to i64
llvm.store %1009, %987 : i64, !llvm.ptr
cf.br ^bb231
^bb231:
%1010 = llvm.load %987 : !llvm.ptr -> i64
%1011 = llvm.load %987 : !llvm.ptr -> i64
%1012 = arith.muli %1010, %1011 : i64
%1013 = arith.cmpi sle, %1012, %942 : i64
cf.cond_br %1013, ^bb232, ^bb233
^bb232:
%1015 = llvm.load %987 : !llvm.ptr -> i64
%1016 = llvm.getelementptr %944[%1015] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%1014 = llvm.load %1016 : !llvm.ptr -> i8
%1017 = arith.constant 1 : i32
%1019 = arith.extsi %1014 : i8 to i32
%1018 = arith.cmpi eq, %1019, %1017 : i32
cf.cond_br %1018, ^bb234, ^bb235
^bb234:
%1020 = llvm.load %987 : !llvm.ptr -> i64
%1021 = llvm.load %987 : !llvm.ptr -> i64
%1022 = arith.muli %1020, %1021 : i64
%1023 = llvm.mlir.constant(1 : i64) : i64
%1024 = llvm.alloca %1023 x i64 : (i64) -> !llvm.ptr
llvm.store %1022, %1024 : i64, !llvm.ptr
cf.br ^bb237
^bb237:
%1025 = llvm.load %1024 : !llvm.ptr -> i64
%1026 = arith.cmpi sle, %1025, %942 : i64
cf.cond_br %1026, ^bb238, ^bb239
^bb238:
%1027 = arith.constant 0 : i32
%1028 = llvm.load %1024 : !llvm.ptr -> i64
%1029 = arith.trunci %1027 : i32 to i8
%1030 = llvm.getelementptr %944[%1028] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %1029, %1030 : i8, !llvm.ptr
%1031 = llvm.load %1024 : !llvm.ptr -> i64
%1032 = llvm.load %987 : !llvm.ptr -> i64
%1033 = arith.addi %1031, %1032 : i64
llvm.store %1033, %1024 : i64, !llvm.ptr
cf.br ^bb237
^bb239:
cf.br ^bb236
^bb235:
cf.br ^bb236
^bb236:
%1034 = llvm.load %987 : !llvm.ptr -> i64
%1035 = arith.constant 1 : i32
%1037 = arith.extsi %1035 : i32 to i64
%1036 = arith.addi %1034, %1037 : i64
llvm.store %1036, %987 : i64, !llvm.ptr
cf.br ^bb231
^bb233:
%1038 = arith.constant 0 : i32
%1039 = arith.extsi %1038 : i32 to i64
%1040 = llvm.mlir.addressof @NP : !llvm.ptr
llvm.store %1039, %1040 : i64, !llvm.ptr
%1041 = arith.constant 3 : i32
%1042 = arith.extsi %1041 : i32 to i64
llvm.store %1042, %987 : i64, !llvm.ptr
cf.br ^bb240
^bb240:
%1043 = llvm.load %987 : !llvm.ptr -> i64
%1044 = arith.cmpi sle, %1043, %942 : i64
cf.cond_br %1044, ^bb241, ^bb242
^bb241:
%1046 = llvm.load %987 : !llvm.ptr -> i64
%1047 = llvm.getelementptr %944[%1046] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%1045 = llvm.load %1047 : !llvm.ptr -> i8
%1048 = arith.constant 1 : i32
%1050 = arith.extsi %1045 : i8 to i32
%1049 = arith.cmpi eq, %1050, %1048 : i32
cf.cond_br %1049, ^bb243, ^bb244
^bb243:
%1051 = llvm.load %987 : !llvm.ptr -> i64
%1052 = llvm.mlir.addressof @PRIMES : !llvm.ptr
%1053 = llvm.load %1052 : !llvm.ptr -> !llvm.ptr
%1054 = llvm.mlir.addressof @NP : !llvm.ptr
%1055 = llvm.load %1054 : !llvm.ptr -> i64
%1056 = llvm.getelementptr %1053[%1055] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %1051, %1056 : i64, !llvm.ptr
%1057 = llvm.mlir.addressof @NP : !llvm.ptr
%1058 = llvm.load %1057 : !llvm.ptr -> i64
%1059 = arith.constant 1 : i32
%1061 = arith.extsi %1059 : i32 to i64
%1060 = arith.addi %1058, %1061 : i64
%1062 = llvm.mlir.addressof @NP : !llvm.ptr
llvm.store %1060, %1062 : i64, !llvm.ptr
cf.br ^bb245
^bb244:
cf.br ^bb245
^bb245:
%1063 = llvm.load %987 : !llvm.ptr -> i64
%1064 = arith.constant 1 : i32
%1066 = arith.extsi %1064 : i32 to i64
%1065 = arith.addi %1063, %1066 : i64
llvm.store %1065, %987 : i64, !llvm.ptr
cf.br ^bb240
^bb242:
%1068 = arith.constant 64 : i32
%1069 = arith.constant 8 : i32
%1070 = arith.extsi %1068 : i32 to i64
%1071 = arith.extsi %1069 : i32 to i64
%1067 = func.call @calloc(%1070, %1071) : (i64, i64) -> !llvm.ptr
%1073 = arith.constant 1 : i32
%1074 = arith.constant 4 : i32
%1075 = arith.extsi %1073 : i32 to i64
%1076 = arith.extsi %1074 : i32 to i64
%1072 = func.call @calloc(%1075, %1076) : (i64, i64) -> !llvm.ptr
%1078 = arith.constant 10000 : i32
%1079 = arith.constant 8 : i32
%1080 = arith.extsi %1078 : i32 to i64
%1081 = arith.extsi %1079 : i32 to i64
%1077 = func.call @calloc(%1080, %1081) : (i64, i64) -> !llvm.ptr
%1083 = arith.constant 1 : i32
%1084 = arith.constant 4 : i32
%1085 = arith.extsi %1083 : i32 to i64
%1086 = arith.extsi %1084 : i32 to i64
%1082 = func.call @calloc(%1085, %1086) : (i64, i64) -> !llvm.ptr
%1087 = arith.constant 0 : i32
%1088 = arith.extsi %1087 : i32 to i64
llvm.store %1088, %987 : i64, !llvm.ptr
cf.br ^bb246
^bb246:
%1089 = llvm.load %987 : !llvm.ptr -> i64
%1090 = llvm.mlir.addressof @NP : !llvm.ptr
%1091 = llvm.load %1090 : !llvm.ptr -> i64
%1092 = arith.cmpi slt, %1089, %1091 : i64
cf.cond_br %1092, ^bb247, ^bb248
^bb247:
%1094 = llvm.mlir.addressof @PRIMES : !llvm.ptr
%1095 = llvm.load %1094 : !llvm.ptr -> !llvm.ptr
%1096 = llvm.load %987 : !llvm.ptr -> i64
%1097 = llvm.getelementptr %1095[%1096] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%1093 = llvm.load %1097 : !llvm.ptr -> i64
%1098 = arith.muli %1093, %1093 : i64
%1099 = arith.subi %1098, %1093 : i64
%1100 = arith.constant 1 : i32
%1102 = arith.extsi %1100 : i32 to i64
%1101 = arith.addi %1099, %1102 : i64
func.call @factor_into(%1101, %1067, %1072) : (i64, !llvm.ptr, !llvm.ptr) -> ()
%1104 = arith.constant 0 : i32
%1106 = arith.constant 0 : i32
%1107 = arith.extsi %1106 : i32 to i64
%1108 = llvm.getelementptr %1072[%1107] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%1105 = llvm.load %1108 : !llvm.ptr -> i32
%1109 = arith.index_cast %1104 : i32 to index
%1110 = arith.index_cast %1105 : i32 to index
%1112 = arith.constant 1 : index
%1113 = arith.constant -1 : index
%1114 = arith.cmpi sle, %1109, %1110 : index
%1111 = arith.select %1114, %1112, %1113 : index
cf.br ^bb249(%1109 : index)
^bb249(%1115: index):
%1116 = arith.cmpi slt, %1115, %1110 : index
%1117 = arith.cmpi sgt, %1115, %1110 : index
%1118 = arith.select %1114, %1116, %1117 : i1
cf.cond_br %1118, ^bb250(%1115 : index), ^bb251(%1115 : index)
^bb250(%1119: index):
%1120 = arith.constant 1 : i32
%1122 = arith.index_cast %1119 : index to i32
%1121 = arith.addi %1122, %1120 : i32
%1124 = arith.constant 0 : i32
%1125 = arith.extsi %1124 : i32 to i64
%1126 = llvm.getelementptr %1072[%1125] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%1123 = llvm.load %1126 : !llvm.ptr -> i32
%1127 = arith.index_cast %1121 : i32 to index
%1128 = arith.index_cast %1123 : i32 to index
%1130 = arith.constant 1 : index
%1131 = arith.constant -1 : index
%1132 = arith.cmpi sle, %1127, %1128 : index
%1129 = arith.select %1132, %1130, %1131 : index
cf.br ^bb252(%1127 : index)
^bb252(%1133: index):
%1134 = arith.cmpi slt, %1133, %1128 : index
%1135 = arith.cmpi sgt, %1133, %1128 : index
%1136 = arith.select %1132, %1134, %1135 : i1
cf.cond_br %1136, ^bb253(%1133 : index), ^bb254(%1133 : index)
^bb253(%1137: index):
%1139 = arith.index_cast %1137 : index to i64
%1140 = llvm.getelementptr %1067[%1139] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%1138 = llvm.load %1140 : !llvm.ptr -> i64
%1142 = arith.index_cast %1119 : index to i64
%1143 = llvm.getelementptr %1067[%1142] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%1141 = llvm.load %1143 : !llvm.ptr -> i64
%1144 = arith.cmpi slt, %1138, %1141 : i64
cf.cond_br %1144, ^bb255, ^bb256
^bb255:
%1146 = arith.index_cast %1119 : index to i64
%1147 = llvm.getelementptr %1067[%1146] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%1145 = llvm.load %1147 : !llvm.ptr -> i64
%1149 = arith.index_cast %1137 : index to i64
%1150 = llvm.getelementptr %1067[%1149] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%1148 = llvm.load %1150 : !llvm.ptr -> i64
%1151 = arith.index_cast %1119 : index to i64
%1152 = llvm.getelementptr %1067[%1151] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %1148, %1152 : i64, !llvm.ptr
%1153 = arith.index_cast %1137 : index to i64
%1154 = llvm.getelementptr %1067[%1153] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %1145, %1154 : i64, !llvm.ptr
cf.br ^bb257
^bb256:
cf.br ^bb257
^bb257:
%1155 = arith.addi %1137, %1129 : index
cf.br ^bb252(%1155 : index)
^bb254(%1156: index):
%1157 = arith.addi %1119, %1111 : index
cf.br ^bb249(%1157 : index)
^bb251(%1158: index):
%1161 = arith.constant 0 : i32
%1162 = arith.extsi %1161 : i32 to i64
%1163 = llvm.getelementptr %1072[%1162] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%1160 = llvm.load %1163 : !llvm.ptr -> i32
func.call @divisors_from(%1067, %1160, %1077, %1082) : (!llvm.ptr, i32, !llvm.ptr, !llvm.ptr) -> ()
%1164 = arith.constant 0 : i32
%1166 = arith.constant 0 : i32
%1167 = arith.extsi %1166 : i32 to i64
%1168 = llvm.getelementptr %1082[%1167] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%1165 = llvm.load %1168 : !llvm.ptr -> i32
%1169 = arith.index_cast %1164 : i32 to index
%1170 = arith.index_cast %1165 : i32 to index
%1172 = arith.constant 1 : index
%1173 = arith.constant -1 : index
%1174 = arith.cmpi sle, %1169, %1170 : index
%1171 = arith.select %1174, %1172, %1173 : index
cf.br ^bb258(%1169 : index)
^bb258(%1175: index):
%1176 = arith.cmpi slt, %1175, %1170 : index
%1177 = arith.cmpi sgt, %1175, %1170 : index
%1178 = arith.select %1174, %1176, %1177 : i1
cf.cond_br %1178, ^bb259(%1175 : index), ^bb260(%1175 : index)
^bb259(%1179: index):
%1181 = arith.index_cast %1179 : index to i64
%1182 = llvm.getelementptr %1077[%1181] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%1180 = llvm.load %1182 : !llvm.ptr -> i64
%1183 = arith.constant 2 : i32
%1185 = arith.extsi %1183 : i32 to i64
%1184 = arith.muli %1185, %1093 : i64
%1186 = arith.constant 1 : i32
%1188 = arith.extsi %1186 : i32 to i64
%1187 = arith.subi %1184, %1188 : i64
%1189 = arith.cmpi sge, %1180, %1187 : i64
cf.cond_br %1189, ^bb261, ^bb262
^bb261:
%1190 = arith.subi %1180, %1093 : i64
%1191 = arith.constant 1 : i32
%1193 = arith.extsi %1191 : i32 to i64
%1192 = arith.addi %1190, %1193 : i64
%1194 = arith.cmpi sgt, %1192, %1093 : i64
%1195 = scf.if %1194 -> (i1) {
%1196 = llvm.mlir.addressof @LIMIT : !llvm.ptr
%1197 = llvm.load %1196 : !llvm.ptr -> i64
%1198 = arith.divsi %1197, %1192 : i64
%1199 = arith.cmpi sle, %1093, %1198 : i64
scf.yield %1199 : i1
} else {
%1200 = arith.constant false
scf.yield %1200 : i1
}
cf.cond_br %1195, ^bb264, ^bb265
^bb264:
%1201 = func.call @is_prime(%1192) : (i64) -> i1
cf.cond_br %1201, ^bb267, ^bb268
^bb267:
%1203 = arith.muli %1093, %1192 : i64
func.call @sol_add(%1203) : (i64) -> ()
cf.br ^bb269
^bb268:
cf.br ^bb269
^bb269:
cf.br ^bb266
^bb265:
cf.br ^bb266
^bb266:
cf.br ^bb263
^bb262:
cf.br ^bb263
^bb263:
%1204 = arith.addi %1179, %1171 : index
cf.br ^bb258(%1204 : index)
^bb260(%1205: index):
%1206 = llvm.load %987 : !llvm.ptr -> i64
%1207 = arith.constant 1 : i32
%1209 = arith.extsi %1207 : i32 to i64
%1208 = arith.addi %1206, %1209 : i64
llvm.store %1208, %987 : i64, !llvm.ptr
cf.br ^bb246
^bb248:
%1210 = arith.constant 1 : i32
%1211 = arith.extsi %1210 : i32 to i64
%1212 = llvm.mlir.constant(1 : i64) : i64
%1213 = llvm.alloca %1212 x i64 : (i64) -> !llvm.ptr
llvm.store %1211, %1213 : i64, !llvm.ptr
%1214 = arith.constant 0 : i32
%1215 = llvm.mlir.constant(1 : i64) : i64
%1216 = llvm.alloca %1215 x i32 : (i64) -> !llvm.ptr
llvm.store %1214, %1216 : i32, !llvm.ptr
%1217 = arith.constant 0 : i32
%1218 = arith.extsi %1217 : i32 to i64
llvm.store %1218, %987 : i64, !llvm.ptr
cf.br ^bb270
^bb270:
%1219 = llvm.load %987 : !llvm.ptr -> i64
%1220 = llvm.mlir.addressof @NP : !llvm.ptr
%1221 = llvm.load %1220 : !llvm.ptr -> i64
%1222 = arith.cmpi slt, %1219, %1221 : i64
cf.cond_br %1222, ^bb271, ^bb272
^bb271:
%1223 = llvm.load %1213 : !llvm.ptr -> i64
%1224 = llvm.mlir.addressof @LIMIT : !llvm.ptr
%1225 = llvm.load %1224 : !llvm.ptr -> i64
%1227 = llvm.mlir.addressof @PRIMES : !llvm.ptr
%1228 = llvm.load %1227 : !llvm.ptr -> !llvm.ptr
%1229 = llvm.load %987 : !llvm.ptr -> i64
%1230 = llvm.getelementptr %1228[%1229] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%1226 = llvm.load %1230 : !llvm.ptr -> i64
%1231 = arith.divsi %1225, %1226 : i64
%1232 = arith.cmpi sgt, %1223, %1231 : i64
cf.cond_br %1232, ^bb273, ^bb274
^bb273:
cf.br ^bb272
^bb274:
cf.br ^bb275
^bb275:
%1233 = llvm.load %1213 : !llvm.ptr -> i64
%1235 = llvm.mlir.addressof @PRIMES : !llvm.ptr
%1236 = llvm.load %1235 : !llvm.ptr -> !llvm.ptr
%1237 = llvm.load %987 : !llvm.ptr -> i64
%1238 = llvm.getelementptr %1236[%1237] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%1234 = llvm.load %1238 : !llvm.ptr -> i64
%1239 = arith.muli %1233, %1234 : i64
llvm.store %1239, %1213 : i64, !llvm.ptr
%1240 = llvm.load %1216 : !llvm.ptr -> i32
%1241 = arith.constant 1 : i32
%1242 = arith.addi %1240, %1241 : i32
llvm.store %1242, %1216 : i32, !llvm.ptr
%1243 = llvm.load %987 : !llvm.ptr -> i64
%1244 = arith.constant 1 : i32
%1246 = arith.extsi %1244 : i32 to i64
%1245 = arith.addi %1243, %1246 : i64
llvm.store %1245, %987 : i64, !llvm.ptr
cf.br ^bb270
^bb272:
%1247 = arith.constant 3 : i32
%1248 = llvm.load %1216 : !llvm.ptr -> i32
%1249 = arith.constant 1 : i32
%1250 = arith.addi %1248, %1249 : i32
%1251 = arith.index_cast %1247 : i32 to index
%1252 = arith.index_cast %1250 : i32 to index
%1254 = arith.constant 1 : index
%1255 = arith.constant -1 : index
%1256 = arith.cmpi sle, %1251, %1252 : index
%1253 = arith.select %1256, %1254, %1255 : index
cf.br ^bb276(%1251 : index)
^bb276(%1257: index):
%1258 = arith.cmpi slt, %1257, %1252 : index
%1259 = arith.cmpi sgt, %1257, %1252 : index
%1260 = arith.select %1256, %1258, %1259 : i1
cf.cond_br %1260, ^bb277(%1257 : index), ^bb278(%1257 : index)
^bb277(%1261: index):
%1262 = arith.constant 1 : i32
%1264 = arith.index_cast %1261 : index to i32
%1263 = arith.subi %1264, %1262 : i32
%1265 = arith.constant 2 : i32
%1266 = arith.cmpi sge, %1263, %1265 : i32
cf.cond_br %1266, ^bb279, ^bb280
^bb279:
%1268 = arith.constant 0 : i32
%1269 = arith.constant 1 : i32
%1270 = arith.constant 1 : i32
%1271 = arith.constant 2 : i32
%1272 = arith.extsi %1268 : i32 to i64
%1273 = arith.extsi %1269 : i32 to i64
%1274 = arith.extsi %1270 : i32 to i64
%1275 = arith.extsi %1271 : i32 to i64
func.call @dfs(%1272, %1263, %1273, %1274, %1275) : (i64, i32, i64, i64, i64) -> ()
cf.br ^bb281
^bb280:
cf.br ^bb281
^bb281:
%1276 = arith.addi %1261, %1253 : index
cf.br ^bb276(%1276 : index)
^bb278(%1277: index):
%1278 = arith.constant 0 : i32
%1279 = arith.extsi %1278 : i32 to i64
%1280 = llvm.mlir.constant(1 : i64) : i64
%1281 = llvm.alloca %1280 x i64 : (i64) -> !llvm.ptr
llvm.store %1279, %1281 : i64, !llvm.ptr
%1282 = arith.constant 0 : i32
%1283 = arith.extsi %1282 : i32 to i64
llvm.store %1283, %987 : i64, !llvm.ptr
cf.br ^bb282
^bb282:
%1284 = llvm.load %987 : !llvm.ptr -> i64
%1285 = llvm.mlir.addressof @NS : !llvm.ptr
%1286 = llvm.load %1285 : !llvm.ptr -> i64
%1287 = arith.cmpi slt, %1284, %1286 : i64
cf.cond_br %1287, ^bb283, ^bb284
^bb283:
%1288 = llvm.load %1281 : !llvm.ptr -> i64
%1290 = llvm.mlir.addressof @SOLS : !llvm.ptr
%1291 = llvm.load %1290 : !llvm.ptr -> !llvm.ptr
%1292 = llvm.load %987 : !llvm.ptr -> i64
%1293 = llvm.getelementptr %1291[%1292] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%1289 = llvm.load %1293 : !llvm.ptr -> i64
%1294 = arith.addi %1288, %1289 : i64
llvm.store %1294, %1281 : i64, !llvm.ptr
%1295 = llvm.load %987 : !llvm.ptr -> i64
%1296 = arith.constant 1 : i32
%1298 = arith.extsi %1296 : i32 to i64
%1297 = arith.addi %1295, %1298 : i64
llvm.store %1297, %987 : i64, !llvm.ptr
cf.br ^bb282
^bb284:
%1299 = llvm.mlir.addressof @str_0 : !llvm.ptr
%1300 = llvm.load %1281 : !llvm.ptr -> i64
%1301 = llvm.call @printf(%1299, %1300) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
%1302 = arith.constant 0 : i32
func.return %1302 : i32
}
}