Problem 325
S(10^16) mod 7^10 via Beatty summatory functions.
View problem on Project Euler
Performance comparison
| Metric | Our solution | Best known |
| Time complexity | O(n) | ? |
| Space complexity | O(n^2) | ? |
| Approach | Flow solution | Not curated |
| Verdict | Unknown |
Flow source
# Project Euler 325
# S(10^16) mod 7^10 via Beatty summatory functions.
import euler.nt { isqrt }
extern {
function calloc(n: i64, size: i64) -> ptr<void>
function free(p: ptr<void>) -> void
}
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 = (r * b) % mod }
b = (b * b) % mod
e = e / 2
}
return r
}
function modinv(a0: i64, mod: i64) -> i64 {
# Extended Euclid (mod = 7^10 is composite; Fermat is invalid).
let mut a: i64 = ((a0 % mod) + mod) % mod
let mut m: i64 = mod
let mut x0: i64 = 1
let mut x1: i64 = 0
while m > 0 {
let q: i64 = a / m
let t: i64 = a - q * m
a = m
m = t
let tx: i64 = x0 - q * x1
x0 = x1
x1 = tx
}
return ((x0 % mod) + mod) % mod
}
function mul64_to_128(a: i64, b: i64, hi: ptr<i64>, lo: ptr<i64>) -> i32 {
# Unsigned 32x32->64 products (signed i64 multiply overflows for large halves).
let mask: u64 = 4294967295
let au: u64 = a as u64
let bu: u64 = b as u64
let a0: u64 = au & mask
let a1: u64 = (au >> 32) & mask
let b0: u64 = bu & mask
let b1: u64 = (bu >> 32) & mask
let u0: u64 = a0 * b0
let u1: u64 = a0 * b1
let u2: u64 = a1 * b0
let u3: u64 = a1 * b1
let mid: u64 = (u0 >> 32) + (u1 & mask) + (u2 & mask)
let lou: u64 = (u0 & mask) | ((mid & mask) << 32)
let hiu: u64 = u3 + (u1 >> 32) + (u2 >> 32) + (mid >> 32)
lo[0] = lou as i64
hi[0] = hiu as i64
return 0
}
function cmp128(ah: i64, al: i64, bh: i64, bl: i64) -> i32 {
let ahu: u64 = ah as u64
let bhu: u64 = bh as u64
if ahu > bhu { return 1 }
if ahu < bhu { return -1 }
let alu: u64 = al as u64
let blu: u64 = bl as u64
if alu > blu { return 1 }
if alu < blu { return -1 }
return 0
}
function floor_n_sqrt5(n: i64) -> i64 {
if n <= 0 { return 0 }
if n < 1000000000 {
return isqrt(5 * n * n)
}
let approx: f64 = (n as f64) * 2.2360679774997896964
let mut x: i64 = approx as i64
let mut nn_hi: i64 = 0
let mut nn_lo: i64 = 0
mul64_to_128(n, n, &nn_hi, &nn_lo)
let mut t_hi: i64 = 0
let mut t_lo: i64 = 0
mul64_to_128(nn_lo, 5, &t_hi, &t_lo)
t_hi = t_hi + nn_hi * 5
let mut xx_hi: i64 = 0
let mut xx_lo: i64 = 0
mul64_to_128(x, x, &xx_hi, &xx_lo)
while cmp128(xx_hi, xx_lo, t_hi, t_lo) > 0 {
x = x - 1
mul64_to_128(x, x, &xx_hi, &xx_lo)
}
while true {
let y: i64 = x + 1
let mut yy_hi: i64 = 0
let mut yy_lo: i64 = 0
mul64_to_128(y, y, &yy_hi, &yy_lo)
if cmp128(yy_hi, yy_lo, t_hi, t_lo) <= 0 {
x = y
} else {
break
}
}
return x
}
function slot(n: i64, keys: ptr<i64>, used: ptr<i8>, cap: i64) -> i64 {
let mut h: i64 = n % cap
if h < 0 { h = h + cap }
while used[h] == 1 && keys[h] != n {
h = h + 1
if h == cap { h = 0 }
}
return h
}
function tri(n: i64, mod: i64, inv2: i64) -> i64 {
return (n % mod) * ((n + 1) % mod) % mod * inv2 % mod
}
function sqsum(n: i64, mod: i64, inv6: i64) -> i64 {
return (n % mod) * ((n + 1) % mod) % mod * ((2 * n + 1) % mod) % mod * inv6 % mod
}
function A(n: i64, mod: i64, inv2: i64, inv6: i64, keys: ptr<i64>, valsA: ptr<i64>, valsB: ptr<i64>, valsH: ptr<i64>, used: ptr<i8>, cap: i64) -> i64
function B(n: i64, mod: i64, inv2: i64, inv6: i64, keys: ptr<i64>, valsA: ptr<i64>, valsB: ptr<i64>, valsH: ptr<i64>, used: ptr<i8>, cap: i64) -> i64
function H(n: i64, mod: i64, inv2: i64, inv6: i64, keys: ptr<i64>, valsA: ptr<i64>, valsB: ptr<i64>, valsH: ptr<i64>, used: ptr<i8>, cap: i64) -> i64
function A(n: i64, mod: i64, inv2: i64, inv6: i64, keys: ptr<i64>, valsA: ptr<i64>, valsB: ptr<i64>, valsH: ptr<i64>, used: ptr<i8>, cap: i64) -> i64 {
if n == 0 { return 0 }
let s: i64 = slot(n, keys, used, cap)
if used[s] == 1 && valsA[s] >= 0 { return valsA[s] }
# Reserve before recursion so child inserts cannot steal this slot.
if used[s] == 0 {
used[s] = 1
keys[s] = n
valsA[s] = -1
valsB[s] = -1
valsH[s] = -1
}
let t: i64 = floor_n_sqrt5(n)
let m: i64 = (n + t) / 2
let c: i64 = (t - n) / 2
let res: i64 = (tri(m, mod, inv2) - A(c, mod, inv2, inv6, keys, valsA, valsB, valsH, used, cap) - tri(c, mod, inv2) + 2 * mod) % mod
valsA[s] = res
return res
}
function H(n: i64, mod: i64, inv2: i64, inv6: i64, keys: ptr<i64>, valsA: ptr<i64>, valsB: ptr<i64>, valsH: ptr<i64>, used: ptr<i8>, cap: i64) -> i64 {
if n == 0 { return 0 }
let s: i64 = slot(n, keys, used, cap)
if used[s] == 1 && valsH[s] >= 0 { return valsH[s] }
if used[s] == 0 {
used[s] = 1
keys[s] = n
valsA[s] = -1
valsB[s] = -1
valsH[s] = -1
}
let t: i64 = floor_n_sqrt5(n)
let c: i64 = (t - n) / 2
let res: i64 = (sqsum(n, mod, inv6) + (c % mod) * tri(n, mod, inv2) % mod - (B(c, mod, inv2, inv6, keys, valsA, valsB, valsH, used, cap) + A(c, mod, inv2, inv6, keys, valsA, valsB, valsH, used, cap)) % mod * inv2 % mod + mod) % mod
valsH[s] = res
return res
}
function B(n: i64, mod: i64, inv2: i64, inv6: i64, keys: ptr<i64>, valsA: ptr<i64>, valsB: ptr<i64>, valsH: ptr<i64>, used: ptr<i8>, cap: i64) -> i64 {
if n == 0 { return 0 }
let s: i64 = slot(n, keys, used, cap)
if used[s] == 1 && valsB[s] >= 0 { return valsB[s] }
if used[s] == 0 {
used[s] = 1
keys[s] = n
valsA[s] = -1
valsB[s] = -1
valsH[s] = -1
}
let t: i64 = floor_n_sqrt5(n)
let m: i64 = (n + t) / 2
let c: i64 = (t - n) / 2
let res: i64 = (sqsum(m, mod, inv6) - B(c, mod, inv2, inv6, keys, valsA, valsB, valsH, used, cap) - 2 * H(c, mod, inv2, inv6, keys, valsA, valsB, valsH, used, cap) % mod - sqsum(c, mod, inv6) + 3 * mod) % mod
valsB[s] = res
return res
}
function main() -> i32 {
let mod: i64 = 282475249
let cap: i64 = 1048576
let keys: ptr<i64> = calloc(cap, 8)
let valsA: ptr<i64> = calloc(cap, 8)
let valsB: ptr<i64> = calloc(cap, 8)
let valsH: ptr<i64> = calloc(cap, 8)
let used: ptr<i8> = calloc(cap, 1)
if keys == null || valsA == null || valsB == null || valsH == null || used == null { return 1 }
let inv2: i64 = modinv(2, mod)
let inv6: i64 = modinv(6, mod)
let N: i64 = 10000000000000000
let tN: i64 = floor_n_sqrt5(N)
let d: i64 = (tN - N) / 2
let A_d: i64 = A(d, mod, inv2, inv6, keys, valsA, valsB, valsH, used, cap)
let B_d: i64 = B(d, mod, inv2, inv6, keys, valsA, valsB, valsH, used, cap)
let H_d: i64 = H(d, mod, inv2, inv6, keys, valsA, valsB, valsH, used, cap)
let sum_t: i64 = (A_d - tri(d, mod, inv2) + mod) % mod
let sum_xt: i64 = (H_d - sqsum(d, mod, inv6) + mod) % mod
let sum_t2: i64 = (B_d - 2 * H_d % mod + sqsum(d, mod, inv6) + 2 * mod) % mod
let part1: i64 = (2 * sum_xt % mod + (sum_t2 + sum_t) % mod * inv2 % mod) % mod
let k: i64 = (N - d - 1) % mod
let term: i64 = ((N % mod) * ((N + 1) % mod) % mod - (d % mod) * ((d + 1) % mod) % mod + mod) % mod
let part2: i64 = k * term % mod * inv2 % mod
printf("%lld\n", (part1 + part2) % mod)
free(keys); free(valsA); free(valsB); free(valsH); free(used)
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 base, int64_t exp, int64_t mod);
int64_t modinv_i64_i64(int64_t a0, int64_t mod);
int32_t mul64_to_128_i64_i64_ptr_i64_ptr_i64(int64_t a, int64_t b, int64_t* hi, int64_t* lo);
int32_t cmp128_i64_i64_i64_i64(int64_t ah, int64_t al, int64_t bh, int64_t bl);
int64_t floor_n_sqrt5_i64(int64_t n);
int64_t slot_i64_ptr_i64_ptr_i8_i64(int64_t n, int64_t* keys, int8_t* used, int64_t cap);
int64_t tri_i64_i64_i64(int64_t n, int64_t mod, int64_t inv2);
int64_t sqsum_i64_i64_i64(int64_t n, int64_t mod, int64_t inv6);
int64_t A_i64_i64_i64_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i8_i64(int64_t n, int64_t mod, int64_t inv2, int64_t inv6, int64_t* keys, int64_t* valsA, int64_t* valsB, int64_t* valsH, int8_t* used, int64_t cap);
int64_t B_i64_i64_i64_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i8_i64(int64_t n, int64_t mod, int64_t inv2, int64_t inv6, int64_t* keys, int64_t* valsA, int64_t* valsB, int64_t* valsH, int8_t* used, int64_t cap);
int64_t H_i64_i64_i64_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i8_i64(int64_t n, int64_t mod, int64_t inv2, int64_t inv6, int64_t* keys, int64_t* valsA, int64_t* valsB, int64_t* valsH, int8_t* used, int64_t cap);
int64_t A_i64_i64_i64_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i8_i64(int64_t n, int64_t mod, int64_t inv2, int64_t inv6, int64_t* keys, int64_t* valsA, int64_t* valsB, int64_t* valsH, int8_t* used, int64_t cap);
int64_t H_i64_i64_i64_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i8_i64(int64_t n, int64_t mod, int64_t inv2, int64_t inv6, int64_t* keys, int64_t* valsA, int64_t* valsB, int64_t* valsH, int8_t* used, int64_t cap);
int64_t B_i64_i64_i64_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i8_i64(int64_t n, int64_t mod, int64_t inv2, int64_t inv6, int64_t* keys, int64_t* valsA, int64_t* valsB, int64_t* valsH, int8_t* used, int64_t cap);
int32_t main(void);
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 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 = FLOW_CHECKED_MOD(((r * b)), (mod));
}
b = FLOW_CHECKED_MOD(((b * b)), (mod));
e = FLOW_CHECKED_DIV((e), (2));
}
return r;
}
int64_t modinv_i64_i64(int64_t a0, int64_t mod) {
int64_t a = FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD((a0), (mod)) + mod)), (mod));
int64_t m = mod;
int64_t x0 = 1;
int64_t x1 = 0;
while (m > 0) {
int64_t q = FLOW_CHECKED_DIV((a), (m));
int64_t t = (a - (q * m));
a = m;
m = t;
int64_t tx = (x0 - (q * x1));
x0 = x1;
x1 = tx;
}
return FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD((x0), (mod)) + mod)), (mod));
}
int32_t mul64_to_128_i64_i64_ptr_i64_ptr_i64(int64_t a, int64_t b, int64_t* hi, int64_t* lo) {
uint64_t mask = 4294967295;
uint64_t au = ((uint64_t)(a));
uint64_t bu = ((uint64_t)(b));
uint64_t a0 = (au & mask);
uint64_t a1 = (FLOW_CHECKED_SHR((au), (32)) & mask);
uint64_t b0 = (bu & mask);
uint64_t b1 = (FLOW_CHECKED_SHR((bu), (32)) & mask);
uint64_t u0 = (a0 * b0);
uint64_t u1 = (a0 * b1);
uint64_t u2 = (a1 * b0);
uint64_t u3 = (a1 * b1);
uint64_t mid = ((FLOW_CHECKED_SHR((u0), (32)) + (u1 & mask)) + (u2 & mask));
uint64_t lou = ((u0 & mask) | FLOW_CHECKED_SHL(((mid & mask)), (32)));
uint64_t hiu = (((u3 + FLOW_CHECKED_SHR((u1), (32))) + FLOW_CHECKED_SHR((u2), (32))) + FLOW_CHECKED_SHR((mid), (32)));
lo[0] = ((int64_t)(lou));
hi[0] = ((int64_t)(hiu));
return 0;
}
int32_t cmp128_i64_i64_i64_i64(int64_t ah, int64_t al, int64_t bh, int64_t bl) {
uint64_t ahu = ((uint64_t)(ah));
uint64_t bhu = ((uint64_t)(bh));
if (ahu > bhu) {
return 1;
}
if (ahu < bhu) {
return (-1);
}
uint64_t alu = ((uint64_t)(al));
uint64_t blu = ((uint64_t)(bl));
if (alu > blu) {
return 1;
}
if (alu < blu) {
return (-1);
}
return 0;
}
int64_t floor_n_sqrt5_i64(int64_t n) {
if (n <= 0) {
return 0;
}
if (n < 1000000000) {
return isqrt_i64(((5 * n) * n));
}
double approx = (((double)(n)) * 2.2360679774997896964);
int64_t x = ((int64_t)(approx));
int64_t nn_hi = 0;
int64_t nn_lo = 0;
mul64_to_128_i64_i64_ptr_i64_ptr_i64(n, n, (&(nn_hi)), (&(nn_lo)));
int64_t t_hi = 0;
int64_t t_lo = 0;
mul64_to_128_i64_i64_ptr_i64_ptr_i64(nn_lo, 5, (&(t_hi)), (&(t_lo)));
t_hi = (t_hi + (nn_hi * 5));
int64_t xx_hi = 0;
int64_t xx_lo = 0;
mul64_to_128_i64_i64_ptr_i64_ptr_i64(x, x, (&(xx_hi)), (&(xx_lo)));
while (cmp128_i64_i64_i64_i64(xx_hi, xx_lo, t_hi, t_lo) > 0) {
x = (x - 1);
mul64_to_128_i64_i64_ptr_i64_ptr_i64(x, x, (&(xx_hi)), (&(xx_lo)));
}
while (1) {
int64_t y = (x + 1);
int64_t yy_hi = 0;
int64_t yy_lo = 0;
mul64_to_128_i64_i64_ptr_i64_ptr_i64(y, y, (&(yy_hi)), (&(yy_lo)));
if (cmp128_i64_i64_i64_i64(yy_hi, yy_lo, t_hi, t_lo) <= 0) {
x = y;
} else {
break;
}
}
return x;
}
int64_t slot_i64_ptr_i64_ptr_i8_i64(int64_t n, int64_t* keys, int8_t* used, int64_t cap) {
int64_t h = FLOW_CHECKED_MOD((n), (cap));
if (h < 0) {
h = (h + cap);
}
while ((used[h] == 1 && keys[h] != n)) {
h = (h + 1);
if (h == cap) {
h = 0;
}
}
return h;
}
int64_t tri_i64_i64_i64(int64_t n, int64_t mod, int64_t inv2) {
return FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD((n), (mod)) * FLOW_CHECKED_MOD(((n + 1)), (mod)))), (mod)) * inv2)), (mod));
}
int64_t sqsum_i64_i64_i64(int64_t n, int64_t mod, int64_t inv6) {
return FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD((n), (mod)) * FLOW_CHECKED_MOD(((n + 1)), (mod)))), (mod)) * FLOW_CHECKED_MOD((((2 * n) + 1)), (mod)))), (mod)) * inv6)), (mod));
}
int64_t A_i64_i64_i64_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i8_i64(int64_t n, int64_t mod, int64_t inv2, int64_t inv6, int64_t* keys, int64_t* valsA, int64_t* valsB, int64_t* valsH, int8_t* used, int64_t cap) {
if (n == 0) {
return 0;
}
int64_t s = slot_i64_ptr_i64_ptr_i8_i64(n, keys, used, cap);
if ((used[s] == 1 && valsA[s] >= 0)) {
return valsA[s];
}
if (used[s] == 0) {
used[s] = 1;
keys[s] = n;
valsA[s] = (-1);
valsB[s] = (-1);
valsH[s] = (-1);
}
int64_t t = floor_n_sqrt5_i64(n);
int64_t m = FLOW_CHECKED_DIV(((n + t)), (2));
int64_t c = FLOW_CHECKED_DIV(((t - n)), (2));
int64_t res = FLOW_CHECKED_MOD(((((tri_i64_i64_i64(m, mod, inv2) - A_i64_i64_i64_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i8_i64(c, mod, inv2, inv6, keys, valsA, valsB, valsH, used, cap)) - tri_i64_i64_i64(c, mod, inv2)) + (2 * mod))), (mod));
valsA[s] = res;
return res;
}
int64_t H_i64_i64_i64_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i8_i64(int64_t n, int64_t mod, int64_t inv2, int64_t inv6, int64_t* keys, int64_t* valsA, int64_t* valsB, int64_t* valsH, int8_t* used, int64_t cap) {
if (n == 0) {
return 0;
}
int64_t s = slot_i64_ptr_i64_ptr_i8_i64(n, keys, used, cap);
if ((used[s] == 1 && valsH[s] >= 0)) {
return valsH[s];
}
if (used[s] == 0) {
used[s] = 1;
keys[s] = n;
valsA[s] = (-1);
valsB[s] = (-1);
valsH[s] = (-1);
}
int64_t t = floor_n_sqrt5_i64(n);
int64_t c = FLOW_CHECKED_DIV(((t - n)), (2));
int64_t res = FLOW_CHECKED_MOD(((((sqsum_i64_i64_i64(n, mod, inv6) + FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD((c), (mod)) * tri_i64_i64_i64(n, mod, inv2))), (mod))) - FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD(((B_i64_i64_i64_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i8_i64(c, mod, inv2, inv6, keys, valsA, valsB, valsH, used, cap) + A_i64_i64_i64_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i8_i64(c, mod, inv2, inv6, keys, valsA, valsB, valsH, used, cap))), (mod)) * inv2)), (mod))) + mod)), (mod));
valsH[s] = res;
return res;
}
int64_t B_i64_i64_i64_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i8_i64(int64_t n, int64_t mod, int64_t inv2, int64_t inv6, int64_t* keys, int64_t* valsA, int64_t* valsB, int64_t* valsH, int8_t* used, int64_t cap) {
if (n == 0) {
return 0;
}
int64_t s = slot_i64_ptr_i64_ptr_i8_i64(n, keys, used, cap);
if ((used[s] == 1 && valsB[s] >= 0)) {
return valsB[s];
}
if (used[s] == 0) {
used[s] = 1;
keys[s] = n;
valsA[s] = (-1);
valsB[s] = (-1);
valsH[s] = (-1);
}
int64_t t = floor_n_sqrt5_i64(n);
int64_t m = FLOW_CHECKED_DIV(((n + t)), (2));
int64_t c = FLOW_CHECKED_DIV(((t - n)), (2));
int64_t res = FLOW_CHECKED_MOD((((((sqsum_i64_i64_i64(m, mod, inv6) - B_i64_i64_i64_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i8_i64(c, mod, inv2, inv6, keys, valsA, valsB, valsH, used, cap)) - FLOW_CHECKED_MOD(((2 * H_i64_i64_i64_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i8_i64(c, mod, inv2, inv6, keys, valsA, valsB, valsH, used, cap))), (mod))) - sqsum_i64_i64_i64(c, mod, inv6)) + (3 * mod))), (mod));
valsB[s] = res;
return res;
}
int32_t main(void) {
int64_t mod = 282475249;
int64_t cap = 1048576;
int64_t* keys = (int64_t*)(calloc(cap, 8));
int64_t* valsA = (int64_t*)(calloc(cap, 8));
int64_t* valsB = (int64_t*)(calloc(cap, 8));
int64_t* valsH = (int64_t*)(calloc(cap, 8));
int8_t* used = (int8_t*)(calloc(cap, 1));
if (((((keys == NULL || valsA == NULL) || valsB == NULL) || valsH == NULL) || used == NULL)) {
return 1;
}
int64_t inv2 = modinv_i64_i64(2, mod);
int64_t inv6 = modinv_i64_i64(6, mod);
int64_t N = 10000000000000000;
int64_t tN = floor_n_sqrt5_i64(N);
int64_t d = FLOW_CHECKED_DIV(((tN - N)), (2));
int64_t A_d = A_i64_i64_i64_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i8_i64(d, mod, inv2, inv6, keys, valsA, valsB, valsH, used, cap);
int64_t B_d = B_i64_i64_i64_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i8_i64(d, mod, inv2, inv6, keys, valsA, valsB, valsH, used, cap);
int64_t H_d = H_i64_i64_i64_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i8_i64(d, mod, inv2, inv6, keys, valsA, valsB, valsH, used, cap);
int64_t sum_t = FLOW_CHECKED_MOD((((A_d - tri_i64_i64_i64(d, mod, inv2)) + mod)), (mod));
int64_t sum_xt = FLOW_CHECKED_MOD((((H_d - sqsum_i64_i64_i64(d, mod, inv6)) + mod)), (mod));
int64_t sum_t2 = FLOW_CHECKED_MOD(((((B_d - FLOW_CHECKED_MOD(((2 * H_d)), (mod))) + sqsum_i64_i64_i64(d, mod, inv6)) + (2 * mod))), (mod));
int64_t part1 = FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD(((2 * sum_xt)), (mod)) + FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD(((sum_t2 + sum_t)), (mod)) * inv2)), (mod)))), (mod));
int64_t k = FLOW_CHECKED_MOD((((N - d) - 1)), (mod));
int64_t term = FLOW_CHECKED_MOD((((FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD((N), (mod)) * FLOW_CHECKED_MOD(((N + 1)), (mod)))), (mod)) - FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD((d), (mod)) * FLOW_CHECKED_MOD(((d + 1)), (mod)))), (mod))) + mod)), (mod));
int64_t part2 = FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD(((k * term)), (mod)) * inv2)), (mod));
printf("%lld\n", FLOW_CHECKED_MOD(((part1 + part2)), (mod)));
free(keys);
free(valsA);
free(valsB);
free(valsH);
free(used);
return 0;
}
Generated MLIR
module {
llvm.func @printf(!llvm.ptr, ...) -> i32
llvm.mlir.global internal constant @str_0("%lld\n\00") {addr_space = 0 : i32} : !llvm.array<6 x i8>
func.func @gcd(%arg0: i64, %arg1: i64) -> i64 {
%0 = llvm.mlir.constant(1 : i64) : i64
%1 = llvm.alloca %0 x i64 : (i64) -> !llvm.ptr
llvm.store %arg0, %1 : i64, !llvm.ptr
%2 = llvm.mlir.constant(1 : i64) : i64
%3 = llvm.alloca %2 x i64 : (i64) -> !llvm.ptr
llvm.store %arg1, %3 : i64, !llvm.ptr
cf.br ^bb0
^bb0:
%4 = llvm.load %3 : !llvm.ptr -> i64
%5 = arith.constant 0 : i32
%7 = arith.extsi %5 : i32 to i64
%6 = arith.cmpi ne, %4, %7 : i64
cf.cond_br %6, ^bb1, ^bb2
^bb1:
%8 = llvm.load %1 : !llvm.ptr -> i64
%9 = llvm.load %3 : !llvm.ptr -> i64
%10 = arith.remsi %8, %9 : i64
%11 = llvm.load %3 : !llvm.ptr -> i64
llvm.store %11, %1 : i64, !llvm.ptr
llvm.store %10, %3 : i64, !llvm.ptr
cf.br ^bb0
^bb2:
%12 = llvm.load %1 : !llvm.ptr -> i64
func.return %12 : i64
}
func.func @lcm(%arg0: i64, %arg1: i64) -> i64 {
%13 = arith.constant 0 : i32
%15 = arith.extsi %13 : i32 to i64
%14 = arith.cmpi eq, %arg0, %15 : i64
%16 = scf.if %14 -> (i1) {
%17 = arith.constant true
scf.yield %17 : i1
} else {
%18 = arith.constant 0 : i32
%20 = arith.extsi %18 : i32 to i64
%19 = arith.cmpi eq, %arg1, %20 : i64
scf.yield %19 : i1
}
cf.cond_br %16, ^bb3, ^bb4
^bb3:
%21 = arith.constant 0 : i32
%22 = arith.extsi %21 : i32 to i64
func.return %22 : i64
^bb4:
cf.br ^bb5
^bb5:
%23 = func.call @gcd(%arg0, %arg1) : (i64, i64) -> i64
%24 = arith.divsi %arg0, %23 : i64
%25 = arith.muli %24, %arg1 : i64
func.return %25 : i64
}
func.func @isqrt(%arg0: i64) -> i64 {
%26 = arith.constant 2 : i32
%28 = arith.extsi %26 : i32 to i64
%27 = arith.cmpi slt, %arg0, %28 : i64
cf.cond_br %27, ^bb6, ^bb7
^bb6:
func.return %arg0 : i64
^bb7:
cf.br ^bb8
^bb8:
%29 = llvm.mlir.constant(1 : i64) : i64
%30 = llvm.alloca %29 x i64 : (i64) -> !llvm.ptr
llvm.store %arg0, %30 : i64, !llvm.ptr
%31 = llvm.load %30 : !llvm.ptr -> i64
%32 = arith.constant 1 : i32
%34 = arith.extsi %32 : i32 to i64
%33 = arith.addi %31, %34 : i64
%35 = arith.constant 2 : i32
%37 = arith.extsi %35 : i32 to i64
%36 = arith.divsi %33, %37 : i64
%38 = llvm.mlir.constant(1 : i64) : i64
%39 = llvm.alloca %38 x i64 : (i64) -> !llvm.ptr
llvm.store %36, %39 : i64, !llvm.ptr
cf.br ^bb9
^bb9:
%40 = llvm.load %39 : !llvm.ptr -> i64
%41 = llvm.load %30 : !llvm.ptr -> i64
%42 = arith.cmpi slt, %40, %41 : i64
cf.cond_br %42, ^bb10, ^bb11
^bb10:
%43 = llvm.load %39 : !llvm.ptr -> i64
llvm.store %43, %30 : i64, !llvm.ptr
%44 = llvm.load %30 : !llvm.ptr -> i64
%45 = llvm.load %30 : !llvm.ptr -> i64
%46 = arith.divsi %arg0, %45 : i64
%47 = arith.addi %44, %46 : i64
%48 = arith.constant 2 : i32
%50 = arith.extsi %48 : i32 to i64
%49 = arith.divsi %47, %50 : i64
llvm.store %49, %39 : i64, !llvm.ptr
cf.br ^bb9
^bb11:
%51 = llvm.load %30 : !llvm.ptr -> i64
func.return %51 : i64
}
func.func @mulmod(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
%52 = arith.remsi %arg0, %arg2 : i64
%53 = llvm.mlir.constant(1 : i64) : i64
%54 = llvm.alloca %53 x i64 : (i64) -> !llvm.ptr
llvm.store %52, %54 : i64, !llvm.ptr
%55 = arith.remsi %arg1, %arg2 : i64
%56 = llvm.mlir.constant(1 : i64) : i64
%57 = llvm.alloca %56 x i64 : (i64) -> !llvm.ptr
llvm.store %55, %57 : i64, !llvm.ptr
%58 = arith.constant 0 : i32
%59 = arith.extsi %58 : i32 to i64
%60 = llvm.mlir.constant(1 : i64) : i64
%61 = llvm.alloca %60 x i64 : (i64) -> !llvm.ptr
llvm.store %59, %61 : i64, !llvm.ptr
cf.br ^bb12
^bb12:
%62 = llvm.load %57 : !llvm.ptr -> i64
%63 = arith.constant 0 : i32
%65 = arith.extsi %63 : i32 to i64
%64 = arith.cmpi sgt, %62, %65 : i64
cf.cond_br %64, ^bb13, ^bb14
^bb13:
%66 = llvm.load %57 : !llvm.ptr -> i64
%67 = arith.constant 2 : i32
%69 = arith.extsi %67 : i32 to i64
%68 = arith.remsi %66, %69 : i64
%70 = arith.constant 1 : i32
%72 = arith.extsi %70 : i32 to i64
%71 = arith.cmpi eq, %68, %72 : i64
cf.cond_br %71, ^bb15, ^bb16
^bb15:
%73 = llvm.load %61 : !llvm.ptr -> i64
%74 = llvm.load %54 : !llvm.ptr -> i64
%75 = arith.addi %73, %74 : i64
%76 = arith.remsi %75, %arg2 : i64
llvm.store %76, %61 : i64, !llvm.ptr
cf.br ^bb17
^bb16:
cf.br ^bb17
^bb17:
%77 = llvm.load %54 : !llvm.ptr -> i64
%78 = arith.constant 2 : i32
%80 = arith.extsi %78 : i32 to i64
%79 = arith.muli %77, %80 : i64
%81 = arith.remsi %79, %arg2 : i64
llvm.store %81, %54 : i64, !llvm.ptr
%82 = llvm.load %57 : !llvm.ptr -> i64
%83 = arith.constant 2 : i32
%85 = arith.extsi %83 : i32 to i64
%84 = arith.divsi %82, %85 : i64
llvm.store %84, %57 : i64, !llvm.ptr
cf.br ^bb12
^bb14:
%86 = llvm.load %61 : !llvm.ptr -> i64
func.return %86 : i64
}
func.func @mod_pow(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
%87 = arith.constant 1 : i32
%89 = arith.extsi %87 : i32 to i64
%88 = arith.cmpi eq, %arg2, %89 : i64
cf.cond_br %88, ^bb18, ^bb19
^bb18:
%90 = arith.constant 0 : i32
%91 = arith.extsi %90 : i32 to i64
func.return %91 : i64
^bb19:
cf.br ^bb20
^bb20:
%92 = arith.constant 1 : i32
%93 = arith.extsi %92 : i32 to i64
%94 = llvm.mlir.constant(1 : i64) : i64
%95 = llvm.alloca %94 x i64 : (i64) -> !llvm.ptr
llvm.store %93, %95 : i64, !llvm.ptr
%96 = arith.remsi %arg0, %arg2 : i64
%97 = llvm.mlir.constant(1 : i64) : i64
%98 = llvm.alloca %97 x i64 : (i64) -> !llvm.ptr
llvm.store %96, %98 : i64, !llvm.ptr
%99 = llvm.mlir.constant(1 : i64) : i64
%100 = llvm.alloca %99 x i64 : (i64) -> !llvm.ptr
llvm.store %arg1, %100 : i64, !llvm.ptr
cf.br ^bb21
^bb21:
%101 = llvm.load %100 : !llvm.ptr -> i64
%102 = arith.constant 0 : i32
%104 = arith.extsi %102 : i32 to i64
%103 = arith.cmpi sgt, %101, %104 : i64
cf.cond_br %103, ^bb22, ^bb23
^bb22:
%105 = llvm.load %100 : !llvm.ptr -> i64
%106 = arith.constant 2 : i32
%108 = arith.extsi %106 : i32 to i64
%107 = arith.remsi %105, %108 : i64
%109 = arith.constant 1 : i32
%111 = arith.extsi %109 : i32 to i64
%110 = arith.cmpi eq, %107, %111 : i64
cf.cond_br %110, ^bb24, ^bb25
^bb24:
%113 = llvm.load %95 : !llvm.ptr -> i64
%114 = llvm.load %98 : !llvm.ptr -> i64
%112 = func.call @mulmod(%113, %114, %arg2) : (i64, i64, i64) -> i64
llvm.store %112, %95 : i64, !llvm.ptr
cf.br ^bb26
^bb25:
cf.br ^bb26
^bb26:
%116 = llvm.load %98 : !llvm.ptr -> i64
%117 = llvm.load %98 : !llvm.ptr -> i64
%115 = func.call @mulmod(%116, %117, %arg2) : (i64, i64, i64) -> i64
llvm.store %115, %98 : i64, !llvm.ptr
%118 = llvm.load %100 : !llvm.ptr -> i64
%119 = arith.constant 2 : i32
%121 = arith.extsi %119 : i32 to i64
%120 = arith.divsi %118, %121 : i64
llvm.store %120, %100 : i64, !llvm.ptr
cf.br ^bb21
^bb23:
%122 = llvm.load %95 : !llvm.ptr -> i64
func.return %122 : i64
}
func.func @is_prime(%arg0: i64) -> i1 {
%123 = arith.constant 2 : i32
%125 = arith.extsi %123 : i32 to i64
%124 = arith.cmpi slt, %arg0, %125 : i64
cf.cond_br %124, ^bb27, ^bb28
^bb27:
%126 = arith.constant 0 : i1
func.return %126 : i1
^bb28:
cf.br ^bb29
^bb29:
%127 = arith.constant 4 : i32
%129 = arith.extsi %127 : i32 to i64
%128 = arith.cmpi slt, %arg0, %129 : i64
cf.cond_br %128, ^bb30, ^bb31
^bb30:
%130 = arith.constant 1 : i1
func.return %130 : i1
^bb31:
cf.br ^bb32
^bb32:
%131 = arith.constant 2 : i32
%133 = arith.extsi %131 : i32 to i64
%132 = arith.remsi %arg0, %133 : i64
%134 = arith.constant 0 : i32
%136 = arith.extsi %134 : i32 to i64
%135 = arith.cmpi eq, %132, %136 : i64
%137 = scf.if %135 -> (i1) {
%138 = arith.constant true
scf.yield %138 : i1
} else {
%139 = arith.constant 3 : i32
%141 = arith.extsi %139 : i32 to i64
%140 = arith.remsi %arg0, %141 : i64
%142 = arith.constant 0 : i32
%144 = arith.extsi %142 : i32 to i64
%143 = arith.cmpi eq, %140, %144 : i64
scf.yield %143 : i1
}
cf.cond_br %137, ^bb33, ^bb34
^bb33:
%145 = arith.constant 0 : i1
func.return %145 : i1
^bb34:
cf.br ^bb35
^bb35:
%146 = arith.constant 5 : i32
%147 = arith.extsi %146 : i32 to i64
%148 = llvm.mlir.constant(1 : i64) : i64
%149 = llvm.alloca %148 x i64 : (i64) -> !llvm.ptr
llvm.store %147, %149 : i64, !llvm.ptr
cf.br ^bb36
^bb36:
%150 = llvm.load %149 : !llvm.ptr -> i64
%151 = llvm.load %149 : !llvm.ptr -> i64
%152 = arith.muli %150, %151 : i64
%153 = arith.cmpi sle, %152, %arg0 : i64
cf.cond_br %153, ^bb37, ^bb38
^bb37:
%154 = llvm.load %149 : !llvm.ptr -> i64
%155 = arith.remsi %arg0, %154 : i64
%156 = arith.constant 0 : i32
%158 = arith.extsi %156 : i32 to i64
%157 = arith.cmpi eq, %155, %158 : i64
%159 = scf.if %157 -> (i1) {
%160 = arith.constant true
scf.yield %160 : i1
} else {
%161 = llvm.load %149 : !llvm.ptr -> i64
%162 = arith.constant 2 : i32
%164 = arith.extsi %162 : i32 to i64
%163 = arith.addi %161, %164 : i64
%165 = arith.remsi %arg0, %163 : i64
%166 = arith.constant 0 : i32
%168 = arith.extsi %166 : i32 to i64
%167 = arith.cmpi eq, %165, %168 : i64
scf.yield %167 : i1
}
cf.cond_br %159, ^bb39, ^bb40
^bb39:
%169 = arith.constant 0 : i1
func.return %169 : i1
^bb40:
cf.br ^bb41
^bb41:
%170 = llvm.load %149 : !llvm.ptr -> i64
%171 = arith.constant 6 : i32
%173 = arith.extsi %171 : i32 to i64
%172 = arith.addi %170, %173 : i64
llvm.store %172, %149 : i64, !llvm.ptr
cf.br ^bb36
^bb38:
%174 = arith.constant 1 : i1
func.return %174 : i1
}
func.func private @calloc(i64, i64) -> !llvm.ptr
func.func private @free(!llvm.ptr) -> ()
func.func @modpow(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
%175 = arith.constant 1 : i32
%176 = arith.extsi %175 : i32 to i64
%177 = llvm.mlir.constant(1 : i64) : i64
%178 = llvm.alloca %177 x i64 : (i64) -> !llvm.ptr
llvm.store %176, %178 : i64, !llvm.ptr
%179 = arith.remsi %arg0, %arg2 : i64
%180 = llvm.mlir.constant(1 : i64) : i64
%181 = llvm.alloca %180 x i64 : (i64) -> !llvm.ptr
llvm.store %179, %181 : i64, !llvm.ptr
%182 = llvm.mlir.constant(1 : i64) : i64
%183 = llvm.alloca %182 x i64 : (i64) -> !llvm.ptr
llvm.store %arg1, %183 : i64, !llvm.ptr
cf.br ^bb42
^bb42:
%184 = llvm.load %183 : !llvm.ptr -> i64
%185 = arith.constant 0 : i32
%187 = arith.extsi %185 : i32 to i64
%186 = arith.cmpi sgt, %184, %187 : i64
cf.cond_br %186, ^bb43, ^bb44
^bb43:
%188 = llvm.load %183 : !llvm.ptr -> i64
%189 = arith.constant 2 : i32
%191 = arith.extsi %189 : i32 to i64
%190 = arith.remsi %188, %191 : i64
%192 = arith.constant 1 : i32
%194 = arith.extsi %192 : i32 to i64
%193 = arith.cmpi eq, %190, %194 : i64
cf.cond_br %193, ^bb45, ^bb46
^bb45:
%195 = llvm.load %178 : !llvm.ptr -> i64
%196 = llvm.load %181 : !llvm.ptr -> i64
%197 = arith.muli %195, %196 : i64
%198 = arith.remsi %197, %arg2 : i64
llvm.store %198, %178 : i64, !llvm.ptr
cf.br ^bb47
^bb46:
cf.br ^bb47
^bb47:
%199 = llvm.load %181 : !llvm.ptr -> i64
%200 = llvm.load %181 : !llvm.ptr -> i64
%201 = arith.muli %199, %200 : i64
%202 = arith.remsi %201, %arg2 : i64
llvm.store %202, %181 : i64, !llvm.ptr
%203 = llvm.load %183 : !llvm.ptr -> i64
%204 = arith.constant 2 : i32
%206 = arith.extsi %204 : i32 to i64
%205 = arith.divsi %203, %206 : i64
llvm.store %205, %183 : i64, !llvm.ptr
cf.br ^bb42
^bb44:
%207 = llvm.load %178 : !llvm.ptr -> i64
func.return %207 : i64
}
func.func @modinv(%arg0: i64, %arg1: i64) -> i64 {
%208 = arith.remsi %arg0, %arg1 : i64
%209 = arith.addi %208, %arg1 : i64
%210 = arith.remsi %209, %arg1 : i64
%211 = llvm.mlir.constant(1 : i64) : i64
%212 = llvm.alloca %211 x i64 : (i64) -> !llvm.ptr
llvm.store %210, %212 : i64, !llvm.ptr
%213 = llvm.mlir.constant(1 : i64) : i64
%214 = llvm.alloca %213 x i64 : (i64) -> !llvm.ptr
llvm.store %arg1, %214 : i64, !llvm.ptr
%215 = arith.constant 1 : i32
%216 = arith.extsi %215 : i32 to i64
%217 = llvm.mlir.constant(1 : i64) : i64
%218 = llvm.alloca %217 x i64 : (i64) -> !llvm.ptr
llvm.store %216, %218 : i64, !llvm.ptr
%219 = arith.constant 0 : i32
%220 = arith.extsi %219 : i32 to i64
%221 = llvm.mlir.constant(1 : i64) : i64
%222 = llvm.alloca %221 x i64 : (i64) -> !llvm.ptr
llvm.store %220, %222 : i64, !llvm.ptr
cf.br ^bb48
^bb48:
%223 = llvm.load %214 : !llvm.ptr -> i64
%224 = arith.constant 0 : i32
%226 = arith.extsi %224 : i32 to i64
%225 = arith.cmpi sgt, %223, %226 : i64
cf.cond_br %225, ^bb49, ^bb50
^bb49:
%227 = llvm.load %212 : !llvm.ptr -> i64
%228 = llvm.load %214 : !llvm.ptr -> i64
%229 = arith.divsi %227, %228 : i64
%230 = llvm.load %212 : !llvm.ptr -> i64
%231 = llvm.load %214 : !llvm.ptr -> i64
%232 = arith.muli %229, %231 : i64
%233 = arith.subi %230, %232 : i64
%234 = llvm.load %214 : !llvm.ptr -> i64
llvm.store %234, %212 : i64, !llvm.ptr
llvm.store %233, %214 : i64, !llvm.ptr
%235 = llvm.load %218 : !llvm.ptr -> i64
%236 = llvm.load %222 : !llvm.ptr -> i64
%237 = arith.muli %229, %236 : i64
%238 = arith.subi %235, %237 : i64
%239 = llvm.load %222 : !llvm.ptr -> i64
llvm.store %239, %218 : i64, !llvm.ptr
llvm.store %238, %222 : i64, !llvm.ptr
cf.br ^bb48
^bb50:
%240 = llvm.load %218 : !llvm.ptr -> i64
%241 = arith.remsi %240, %arg1 : i64
%242 = arith.addi %241, %arg1 : i64
%243 = arith.remsi %242, %arg1 : i64
func.return %243 : i64
}
func.func @mul64_to_128(%arg0: i64, %arg1: i64, %arg2: !llvm.ptr, %arg3: !llvm.ptr) -> i32 {
%244 = arith.constant -1 : i32
%245 = arith.extsi %244 : i32 to i64
%246 = arith.andi %arg0, %245 : i64
%247 = arith.constant 32 : i32
%249 = arith.extsi %247 : i32 to i64
%248 = arith.shrui %arg0, %249 : i64
%250 = arith.andi %248, %245 : i64
%251 = arith.andi %arg1, %245 : i64
%252 = arith.constant 32 : i32
%254 = arith.extsi %252 : i32 to i64
%253 = arith.shrui %arg1, %254 : i64
%255 = arith.andi %253, %245 : i64
%256 = arith.muli %246, %251 : i64
%257 = arith.muli %246, %255 : i64
%258 = arith.muli %250, %251 : i64
%259 = arith.muli %250, %255 : i64
%260 = arith.constant 32 : i32
%262 = arith.extsi %260 : i32 to i64
%261 = arith.shrui %256, %262 : i64
%263 = arith.andi %257, %245 : i64
%264 = arith.addi %261, %263 : i64
%265 = arith.andi %258, %245 : i64
%266 = arith.addi %264, %265 : i64
%267 = arith.andi %256, %245 : i64
%268 = arith.andi %266, %245 : i64
%269 = arith.constant 32 : i32
%271 = arith.extsi %269 : i32 to i64
%270 = arith.shli %268, %271 : i64
%272 = arith.ori %267, %270 : i64
%273 = arith.constant 32 : i32
%275 = arith.extsi %273 : i32 to i64
%274 = arith.shrui %257, %275 : i64
%276 = arith.addi %259, %274 : i64
%277 = arith.constant 32 : i32
%279 = arith.extsi %277 : i32 to i64
%278 = arith.shrui %258, %279 : i64
%280 = arith.addi %276, %278 : i64
%281 = arith.constant 32 : i32
%283 = arith.extsi %281 : i32 to i64
%282 = arith.shrui %266, %283 : i64
%284 = arith.addi %280, %282 : i64
%285 = arith.constant 0 : i32
%286 = arith.extsi %285 : i32 to i64
%287 = llvm.getelementptr %arg3[%286] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %272, %287 : i64, !llvm.ptr
%288 = arith.constant 0 : i32
%289 = arith.extsi %288 : i32 to i64
%290 = llvm.getelementptr %arg2[%289] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %284, %290 : i64, !llvm.ptr
%291 = arith.constant 0 : i32
func.return %291 : i32
}
func.func @cmp128(%arg0: i64, %arg1: i64, %arg2: i64, %arg3: i64) -> i32 {
%292 = arith.cmpi ugt, %arg0, %arg2 : i64
cf.cond_br %292, ^bb51, ^bb52
^bb51:
%293 = arith.constant 1 : i32
func.return %293 : i32
^bb52:
cf.br ^bb53
^bb53:
%294 = arith.cmpi ult, %arg0, %arg2 : i64
cf.cond_br %294, ^bb54, ^bb55
^bb54:
%295 = arith.constant 1 : i32
%297 = arith.constant 0 : i32
%296 = arith.subi %297, %295 : i32
func.return %296 : i32
^bb55:
cf.br ^bb56
^bb56:
%298 = arith.cmpi ugt, %arg1, %arg3 : i64
cf.cond_br %298, ^bb57, ^bb58
^bb57:
%299 = arith.constant 1 : i32
func.return %299 : i32
^bb58:
cf.br ^bb59
^bb59:
%300 = arith.cmpi ult, %arg1, %arg3 : i64
cf.cond_br %300, ^bb60, ^bb61
^bb60:
%301 = arith.constant 1 : i32
%303 = arith.constant 0 : i32
%302 = arith.subi %303, %301 : i32
func.return %302 : i32
^bb61:
cf.br ^bb62
^bb62:
%304 = arith.constant 0 : i32
func.return %304 : i32
}
func.func @floor_n_sqrt5(%arg0: i64) -> i64 {
%305 = arith.constant 0 : i32
%307 = arith.extsi %305 : i32 to i64
%306 = arith.cmpi sle, %arg0, %307 : i64
cf.cond_br %306, ^bb63, ^bb64
^bb63:
%308 = arith.constant 0 : i32
%309 = arith.extsi %308 : i32 to i64
func.return %309 : i64
^bb64:
cf.br ^bb65
^bb65:
%310 = arith.constant 1000000000 : i32
%312 = arith.extsi %310 : i32 to i64
%311 = arith.cmpi slt, %arg0, %312 : i64
cf.cond_br %311, ^bb66, ^bb67
^bb66:
%314 = arith.constant 5 : i32
%316 = arith.extsi %314 : i32 to i64
%315 = arith.muli %316, %arg0 : i64
%317 = arith.muli %315, %arg0 : i64
%313 = func.call @isqrt(%317) : (i64) -> i64
func.return %313 : i64
^bb67:
cf.br ^bb68
^bb68:
%318 = arith.sitofp %arg0 : i64 to f64
%319 = arith.constant 2.2360679774997896964 : f32
%321 = arith.extf %319 : f32 to f64
%320 = arith.mulf %318, %321 : f64
%322 = arith.fptosi %320 : f64 to i64
%323 = llvm.mlir.constant(1 : i64) : i64
%324 = llvm.alloca %323 x i64 : (i64) -> !llvm.ptr
llvm.store %322, %324 : i64, !llvm.ptr
%325 = arith.constant 0 : i32
%326 = arith.extsi %325 : i32 to i64
%327 = llvm.mlir.constant(1 : i64) : i64
%328 = llvm.alloca %327 x i64 : (i64) -> !llvm.ptr
llvm.store %326, %328 : i64, !llvm.ptr
%329 = arith.constant 0 : 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
%333 = func.call @mul64_to_128(%arg0, %arg0, %328, %332) : (i64, i64, !llvm.ptr, !llvm.ptr) -> i32
%334 = arith.constant 0 : 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 0 : 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
%343 = llvm.load %332 : !llvm.ptr -> i64
%344 = arith.constant 5 : i32
%345 = arith.extsi %344 : i32 to i64
%342 = func.call @mul64_to_128(%343, %345, %337, %341) : (i64, i64, !llvm.ptr, !llvm.ptr) -> i32
%346 = llvm.load %337 : !llvm.ptr -> i64
%347 = llvm.load %328 : !llvm.ptr -> i64
%348 = arith.constant 5 : i32
%350 = arith.extsi %348 : i32 to i64
%349 = arith.muli %347, %350 : i64
%351 = arith.addi %346, %349 : i64
llvm.store %351, %337 : i64, !llvm.ptr
%352 = arith.constant 0 : i32
%353 = arith.extsi %352 : i32 to i64
%354 = llvm.mlir.constant(1 : i64) : i64
%355 = llvm.alloca %354 x i64 : (i64) -> !llvm.ptr
llvm.store %353, %355 : i64, !llvm.ptr
%356 = arith.constant 0 : i32
%357 = arith.extsi %356 : i32 to i64
%358 = llvm.mlir.constant(1 : i64) : i64
%359 = llvm.alloca %358 x i64 : (i64) -> !llvm.ptr
llvm.store %357, %359 : i64, !llvm.ptr
%361 = llvm.load %324 : !llvm.ptr -> i64
%362 = llvm.load %324 : !llvm.ptr -> i64
%360 = func.call @mul64_to_128(%361, %362, %355, %359) : (i64, i64, !llvm.ptr, !llvm.ptr) -> i32
cf.br ^bb69
^bb69:
%364 = llvm.load %355 : !llvm.ptr -> i64
%365 = llvm.load %359 : !llvm.ptr -> i64
%366 = llvm.load %337 : !llvm.ptr -> i64
%367 = llvm.load %341 : !llvm.ptr -> i64
%363 = func.call @cmp128(%364, %365, %366, %367) : (i64, i64, i64, i64) -> i32
%368 = arith.constant 0 : i32
%369 = arith.cmpi sgt, %363, %368 : i32
cf.cond_br %369, ^bb70, ^bb71
^bb70:
%370 = llvm.load %324 : !llvm.ptr -> i64
%371 = arith.constant 1 : i32
%373 = arith.extsi %371 : i32 to i64
%372 = arith.subi %370, %373 : i64
llvm.store %372, %324 : i64, !llvm.ptr
%375 = llvm.load %324 : !llvm.ptr -> i64
%376 = llvm.load %324 : !llvm.ptr -> i64
%374 = func.call @mul64_to_128(%375, %376, %355, %359) : (i64, i64, !llvm.ptr, !llvm.ptr) -> i32
cf.br ^bb69
^bb71:
cf.br ^bb72
^bb72:
%377 = arith.constant 1 : i1
cf.cond_br %377, ^bb73, ^bb74
^bb73:
%378 = llvm.load %324 : !llvm.ptr -> i64
%379 = arith.constant 1 : i32
%381 = arith.extsi %379 : i32 to i64
%380 = arith.addi %378, %381 : i64
%382 = arith.constant 0 : i32
%383 = arith.extsi %382 : i32 to i64
%384 = llvm.mlir.constant(1 : i64) : i64
%385 = llvm.alloca %384 x i64 : (i64) -> !llvm.ptr
llvm.store %383, %385 : i64, !llvm.ptr
%386 = arith.constant 0 : i32
%387 = arith.extsi %386 : i32 to i64
%388 = llvm.mlir.constant(1 : i64) : i64
%389 = llvm.alloca %388 x i64 : (i64) -> !llvm.ptr
llvm.store %387, %389 : i64, !llvm.ptr
%390 = func.call @mul64_to_128(%380, %380, %385, %389) : (i64, i64, !llvm.ptr, !llvm.ptr) -> i32
%392 = llvm.load %385 : !llvm.ptr -> i64
%393 = llvm.load %389 : !llvm.ptr -> i64
%394 = llvm.load %337 : !llvm.ptr -> i64
%395 = llvm.load %341 : !llvm.ptr -> i64
%391 = func.call @cmp128(%392, %393, %394, %395) : (i64, i64, i64, i64) -> i32
%396 = arith.constant 0 : i32
%397 = arith.cmpi sle, %391, %396 : i32
cf.cond_br %397, ^bb75, ^bb76
^bb75:
llvm.store %380, %324 : i64, !llvm.ptr
cf.br ^bb77
^bb76:
cf.br ^bb74
^bb77:
cf.br ^bb72
^bb74:
%398 = llvm.load %324 : !llvm.ptr -> i64
func.return %398 : i64
}
func.func @slot(%arg0: i64, %arg1: !llvm.ptr, %arg2: !llvm.ptr, %arg3: i64) -> i64 {
%399 = arith.remsi %arg0, %arg3 : i64
%400 = llvm.mlir.constant(1 : i64) : i64
%401 = llvm.alloca %400 x i64 : (i64) -> !llvm.ptr
llvm.store %399, %401 : i64, !llvm.ptr
%402 = llvm.load %401 : !llvm.ptr -> i64
%403 = arith.constant 0 : i32
%405 = arith.extsi %403 : i32 to i64
%404 = arith.cmpi slt, %402, %405 : i64
cf.cond_br %404, ^bb78, ^bb79
^bb78:
%406 = llvm.load %401 : !llvm.ptr -> i64
%407 = arith.addi %406, %arg3 : i64
llvm.store %407, %401 : i64, !llvm.ptr
cf.br ^bb80
^bb79:
cf.br ^bb80
^bb80:
cf.br ^bb81
^bb81:
%409 = llvm.load %401 : !llvm.ptr -> i64
%410 = llvm.getelementptr %arg2[%409] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%408 = llvm.load %410 : !llvm.ptr -> i8
%411 = arith.constant 1 : i32
%413 = arith.extsi %408 : i8 to i32
%412 = arith.cmpi eq, %413, %411 : i32
%414 = scf.if %412 -> (i1) {
%416 = llvm.load %401 : !llvm.ptr -> i64
%417 = llvm.getelementptr %arg1[%416] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%415 = llvm.load %417 : !llvm.ptr -> i64
%418 = arith.cmpi ne, %415, %arg0 : i64
scf.yield %418 : i1
} else {
%419 = arith.constant false
scf.yield %419 : i1
}
cf.cond_br %414, ^bb82, ^bb83
^bb82:
%420 = llvm.load %401 : !llvm.ptr -> i64
%421 = arith.constant 1 : i32
%423 = arith.extsi %421 : i32 to i64
%422 = arith.addi %420, %423 : i64
llvm.store %422, %401 : i64, !llvm.ptr
%424 = llvm.load %401 : !llvm.ptr -> i64
%425 = arith.cmpi eq, %424, %arg3 : i64
cf.cond_br %425, ^bb84, ^bb85
^bb84:
%426 = arith.constant 0 : i32
%427 = arith.extsi %426 : i32 to i64
llvm.store %427, %401 : i64, !llvm.ptr
cf.br ^bb86
^bb85:
cf.br ^bb86
^bb86:
cf.br ^bb81
^bb83:
%428 = llvm.load %401 : !llvm.ptr -> i64
func.return %428 : i64
}
func.func @tri(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
%429 = arith.remsi %arg0, %arg1 : i64
%430 = arith.constant 1 : i32
%432 = arith.extsi %430 : i32 to i64
%431 = arith.addi %arg0, %432 : i64
%433 = arith.remsi %431, %arg1 : i64
%434 = arith.muli %429, %433 : i64
%435 = arith.remsi %434, %arg1 : i64
%436 = arith.muli %435, %arg2 : i64
%437 = arith.remsi %436, %arg1 : i64
func.return %437 : i64
}
func.func @sqsum(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
%438 = arith.remsi %arg0, %arg1 : i64
%439 = arith.constant 1 : i32
%441 = arith.extsi %439 : i32 to i64
%440 = arith.addi %arg0, %441 : i64
%442 = arith.remsi %440, %arg1 : i64
%443 = arith.muli %438, %442 : i64
%444 = arith.remsi %443, %arg1 : i64
%445 = arith.constant 2 : i32
%447 = arith.extsi %445 : i32 to i64
%446 = arith.muli %447, %arg0 : i64
%448 = arith.constant 1 : i32
%450 = arith.extsi %448 : i32 to i64
%449 = arith.addi %446, %450 : i64
%451 = arith.remsi %449, %arg1 : i64
%452 = arith.muli %444, %451 : i64
%453 = arith.remsi %452, %arg1 : i64
%454 = arith.muli %453, %arg2 : i64
%455 = arith.remsi %454, %arg1 : i64
func.return %455 : i64
}
func.func @A(%arg0: i64, %arg1: i64, %arg2: i64, %arg3: i64, %arg4: !llvm.ptr, %arg5: !llvm.ptr, %arg6: !llvm.ptr, %arg7: !llvm.ptr, %arg8: !llvm.ptr, %arg9: i64) -> i64 {
}
func.func @B(%arg0: i64, %arg1: i64, %arg2: i64, %arg3: i64, %arg4: !llvm.ptr, %arg5: !llvm.ptr, %arg6: !llvm.ptr, %arg7: !llvm.ptr, %arg8: !llvm.ptr, %arg9: i64) -> i64 {
}
func.func @H(%arg0: i64, %arg1: i64, %arg2: i64, %arg3: i64, %arg4: !llvm.ptr, %arg5: !llvm.ptr, %arg6: !llvm.ptr, %arg7: !llvm.ptr, %arg8: !llvm.ptr, %arg9: i64) -> i64 {
}
func.func @A(%arg0: i64, %arg1: i64, %arg2: i64, %arg3: i64, %arg4: !llvm.ptr, %arg5: !llvm.ptr, %arg6: !llvm.ptr, %arg7: !llvm.ptr, %arg8: !llvm.ptr, %arg9: i64) -> i64 {
%456 = arith.constant 0 : i32
%458 = arith.extsi %456 : i32 to i64
%457 = arith.cmpi eq, %arg0, %458 : i64
cf.cond_br %457, ^bb87, ^bb88
^bb87:
%459 = arith.constant 0 : i32
%460 = arith.extsi %459 : i32 to i64
func.return %460 : i64
^bb88:
cf.br ^bb89
^bb89:
%461 = func.call @slot(%arg0, %arg4, %arg8, %arg9) : (i64, !llvm.ptr, !llvm.ptr, i64) -> i64
%463 = llvm.getelementptr %arg8[%461] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%462 = llvm.load %463 : !llvm.ptr -> i8
%464 = arith.constant 1 : i32
%466 = arith.extsi %462 : i8 to i32
%465 = arith.cmpi eq, %466, %464 : i32
%467 = scf.if %465 -> (i1) {
%469 = llvm.getelementptr %arg5[%461] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%468 = llvm.load %469 : !llvm.ptr -> i64
%470 = arith.constant 0 : i32
%472 = arith.extsi %470 : i32 to i64
%471 = arith.cmpi sge, %468, %472 : i64
scf.yield %471 : i1
} else {
%473 = arith.constant false
scf.yield %473 : i1
}
cf.cond_br %467, ^bb90, ^bb91
^bb90:
%475 = llvm.getelementptr %arg5[%461] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%474 = llvm.load %475 : !llvm.ptr -> i64
func.return %474 : i64
^bb91:
cf.br ^bb92
^bb92:
%477 = llvm.getelementptr %arg8[%461] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%476 = llvm.load %477 : !llvm.ptr -> i8
%478 = arith.constant 0 : i32
%480 = arith.extsi %476 : i8 to i32
%479 = arith.cmpi eq, %480, %478 : i32
cf.cond_br %479, ^bb93, ^bb94
^bb93:
%481 = arith.constant 1 : i32
%482 = arith.trunci %481 : i32 to i8
%483 = llvm.getelementptr %arg8[%461] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %482, %483 : i8, !llvm.ptr
%484 = llvm.getelementptr %arg4[%461] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %arg0, %484 : i64, !llvm.ptr
%485 = arith.constant 1 : i32
%487 = arith.constant 0 : i32
%486 = arith.subi %487, %485 : i32
%488 = arith.extsi %486 : i32 to i64
%489 = llvm.getelementptr %arg5[%461] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %488, %489 : i64, !llvm.ptr
%490 = arith.constant 1 : i32
%492 = arith.constant 0 : i32
%491 = arith.subi %492, %490 : i32
%493 = arith.extsi %491 : i32 to i64
%494 = llvm.getelementptr %arg6[%461] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %493, %494 : i64, !llvm.ptr
%495 = arith.constant 1 : i32
%497 = arith.constant 0 : i32
%496 = arith.subi %497, %495 : i32
%498 = arith.extsi %496 : i32 to i64
%499 = llvm.getelementptr %arg7[%461] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %498, %499 : i64, !llvm.ptr
cf.br ^bb95
^bb94:
cf.br ^bb95
^bb95:
%500 = func.call @floor_n_sqrt5(%arg0) : (i64) -> i64
%501 = arith.addi %arg0, %500 : i64
%502 = arith.constant 2 : i32
%504 = arith.extsi %502 : i32 to i64
%503 = arith.divsi %501, %504 : i64
%505 = arith.subi %500, %arg0 : i64
%506 = arith.constant 2 : i32
%508 = arith.extsi %506 : i32 to i64
%507 = arith.divsi %505, %508 : i64
%509 = func.call @tri(%503, %arg1, %arg2) : (i64, i64, i64) -> i64
%510 = func.call @A(%507, %arg1, %arg2, %arg3, %arg4, %arg5, %arg6, %arg7, %arg8, %arg9) : (i64, i64, i64, i64, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, i64) -> i64
%511 = arith.subi %509, %510 : i64
%512 = func.call @tri(%507, %arg1, %arg2) : (i64, i64, i64) -> i64
%513 = arith.subi %511, %512 : i64
%514 = arith.constant 2 : i32
%516 = arith.extsi %514 : i32 to i64
%515 = arith.muli %516, %arg1 : i64
%517 = arith.addi %513, %515 : i64
%518 = arith.remsi %517, %arg1 : i64
%519 = llvm.getelementptr %arg5[%461] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %518, %519 : i64, !llvm.ptr
func.return %518 : i64
}
func.func @H(%arg0: i64, %arg1: i64, %arg2: i64, %arg3: i64, %arg4: !llvm.ptr, %arg5: !llvm.ptr, %arg6: !llvm.ptr, %arg7: !llvm.ptr, %arg8: !llvm.ptr, %arg9: i64) -> i64 {
%520 = arith.constant 0 : i32
%522 = arith.extsi %520 : i32 to i64
%521 = arith.cmpi eq, %arg0, %522 : i64
cf.cond_br %521, ^bb96, ^bb97
^bb96:
%523 = arith.constant 0 : i32
%524 = arith.extsi %523 : i32 to i64
func.return %524 : i64
^bb97:
cf.br ^bb98
^bb98:
%525 = func.call @slot(%arg0, %arg4, %arg8, %arg9) : (i64, !llvm.ptr, !llvm.ptr, i64) -> i64
%527 = llvm.getelementptr %arg8[%525] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%526 = llvm.load %527 : !llvm.ptr -> i8
%528 = arith.constant 1 : i32
%530 = arith.extsi %526 : i8 to i32
%529 = arith.cmpi eq, %530, %528 : i32
%531 = scf.if %529 -> (i1) {
%533 = llvm.getelementptr %arg7[%525] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%532 = llvm.load %533 : !llvm.ptr -> i64
%534 = arith.constant 0 : i32
%536 = arith.extsi %534 : i32 to i64
%535 = arith.cmpi sge, %532, %536 : i64
scf.yield %535 : i1
} else {
%537 = arith.constant false
scf.yield %537 : i1
}
cf.cond_br %531, ^bb99, ^bb100
^bb99:
%539 = llvm.getelementptr %arg7[%525] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%538 = llvm.load %539 : !llvm.ptr -> i64
func.return %538 : i64
^bb100:
cf.br ^bb101
^bb101:
%541 = llvm.getelementptr %arg8[%525] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%540 = llvm.load %541 : !llvm.ptr -> i8
%542 = arith.constant 0 : i32
%544 = arith.extsi %540 : i8 to i32
%543 = arith.cmpi eq, %544, %542 : i32
cf.cond_br %543, ^bb102, ^bb103
^bb102:
%545 = arith.constant 1 : i32
%546 = arith.trunci %545 : i32 to i8
%547 = llvm.getelementptr %arg8[%525] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %546, %547 : i8, !llvm.ptr
%548 = llvm.getelementptr %arg4[%525] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %arg0, %548 : i64, !llvm.ptr
%549 = arith.constant 1 : i32
%551 = arith.constant 0 : i32
%550 = arith.subi %551, %549 : i32
%552 = arith.extsi %550 : i32 to i64
%553 = llvm.getelementptr %arg5[%525] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %552, %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.getelementptr %arg6[%525] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %557, %558 : i64, !llvm.ptr
%559 = arith.constant 1 : i32
%561 = arith.constant 0 : i32
%560 = arith.subi %561, %559 : i32
%562 = arith.extsi %560 : i32 to i64
%563 = llvm.getelementptr %arg7[%525] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %562, %563 : i64, !llvm.ptr
cf.br ^bb104
^bb103:
cf.br ^bb104
^bb104:
%564 = func.call @floor_n_sqrt5(%arg0) : (i64) -> i64
%565 = arith.subi %564, %arg0 : i64
%566 = arith.constant 2 : i32
%568 = arith.extsi %566 : i32 to i64
%567 = arith.divsi %565, %568 : i64
%569 = func.call @sqsum(%arg0, %arg1, %arg3) : (i64, i64, i64) -> i64
%570 = arith.remsi %567, %arg1 : i64
%571 = func.call @tri(%arg0, %arg1, %arg2) : (i64, i64, i64) -> i64
%572 = arith.muli %570, %571 : i64
%573 = arith.remsi %572, %arg1 : i64
%574 = arith.addi %569, %573 : i64
%575 = func.call @B(%567, %arg1, %arg2, %arg3, %arg4, %arg5, %arg6, %arg7, %arg8, %arg9) : (i64, i64, i64, i64, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, i64) -> i64
%576 = func.call @A(%567, %arg1, %arg2, %arg3, %arg4, %arg5, %arg6, %arg7, %arg8, %arg9) : (i64, i64, i64, i64, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, i64) -> i64
%577 = arith.addi %575, %576 : i64
%578 = arith.remsi %577, %arg1 : i64
%579 = arith.muli %578, %arg2 : i64
%580 = arith.remsi %579, %arg1 : i64
%581 = arith.subi %574, %580 : i64
%582 = arith.addi %581, %arg1 : i64
%583 = arith.remsi %582, %arg1 : i64
%584 = llvm.getelementptr %arg7[%525] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %583, %584 : i64, !llvm.ptr
func.return %583 : i64
}
func.func @B(%arg0: i64, %arg1: i64, %arg2: i64, %arg3: i64, %arg4: !llvm.ptr, %arg5: !llvm.ptr, %arg6: !llvm.ptr, %arg7: !llvm.ptr, %arg8: !llvm.ptr, %arg9: i64) -> i64 {
%585 = arith.constant 0 : i32
%587 = arith.extsi %585 : i32 to i64
%586 = arith.cmpi eq, %arg0, %587 : i64
cf.cond_br %586, ^bb105, ^bb106
^bb105:
%588 = arith.constant 0 : i32
%589 = arith.extsi %588 : i32 to i64
func.return %589 : i64
^bb106:
cf.br ^bb107
^bb107:
%590 = func.call @slot(%arg0, %arg4, %arg8, %arg9) : (i64, !llvm.ptr, !llvm.ptr, i64) -> i64
%592 = llvm.getelementptr %arg8[%590] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%591 = llvm.load %592 : !llvm.ptr -> i8
%593 = arith.constant 1 : i32
%595 = arith.extsi %591 : i8 to i32
%594 = arith.cmpi eq, %595, %593 : i32
%596 = scf.if %594 -> (i1) {
%598 = llvm.getelementptr %arg6[%590] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%597 = llvm.load %598 : !llvm.ptr -> i64
%599 = arith.constant 0 : i32
%601 = arith.extsi %599 : i32 to i64
%600 = arith.cmpi sge, %597, %601 : i64
scf.yield %600 : i1
} else {
%602 = arith.constant false
scf.yield %602 : i1
}
cf.cond_br %596, ^bb108, ^bb109
^bb108:
%604 = llvm.getelementptr %arg6[%590] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%603 = llvm.load %604 : !llvm.ptr -> i64
func.return %603 : i64
^bb109:
cf.br ^bb110
^bb110:
%606 = llvm.getelementptr %arg8[%590] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%605 = llvm.load %606 : !llvm.ptr -> i8
%607 = arith.constant 0 : i32
%609 = arith.extsi %605 : i8 to i32
%608 = arith.cmpi eq, %609, %607 : i32
cf.cond_br %608, ^bb111, ^bb112
^bb111:
%610 = arith.constant 1 : i32
%611 = arith.trunci %610 : i32 to i8
%612 = llvm.getelementptr %arg8[%590] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %611, %612 : i8, !llvm.ptr
%613 = llvm.getelementptr %arg4[%590] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %arg0, %613 : i64, !llvm.ptr
%614 = arith.constant 1 : i32
%616 = arith.constant 0 : i32
%615 = arith.subi %616, %614 : i32
%617 = arith.extsi %615 : i32 to i64
%618 = llvm.getelementptr %arg5[%590] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %617, %618 : i64, !llvm.ptr
%619 = arith.constant 1 : i32
%621 = arith.constant 0 : i32
%620 = arith.subi %621, %619 : i32
%622 = arith.extsi %620 : i32 to i64
%623 = llvm.getelementptr %arg6[%590] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %622, %623 : i64, !llvm.ptr
%624 = arith.constant 1 : i32
%626 = arith.constant 0 : i32
%625 = arith.subi %626, %624 : i32
%627 = arith.extsi %625 : i32 to i64
%628 = llvm.getelementptr %arg7[%590] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %627, %628 : i64, !llvm.ptr
cf.br ^bb113
^bb112:
cf.br ^bb113
^bb113:
%629 = func.call @floor_n_sqrt5(%arg0) : (i64) -> i64
%630 = arith.addi %arg0, %629 : i64
%631 = arith.constant 2 : i32
%633 = arith.extsi %631 : i32 to i64
%632 = arith.divsi %630, %633 : i64
%634 = arith.subi %629, %arg0 : i64
%635 = arith.constant 2 : i32
%637 = arith.extsi %635 : i32 to i64
%636 = arith.divsi %634, %637 : i64
%638 = func.call @sqsum(%632, %arg1, %arg3) : (i64, i64, i64) -> i64
%639 = func.call @B(%636, %arg1, %arg2, %arg3, %arg4, %arg5, %arg6, %arg7, %arg8, %arg9) : (i64, i64, i64, i64, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, i64) -> i64
%640 = arith.subi %638, %639 : i64
%641 = arith.constant 2 : i32
%642 = func.call @H(%636, %arg1, %arg2, %arg3, %arg4, %arg5, %arg6, %arg7, %arg8, %arg9) : (i64, i64, i64, i64, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, i64) -> i64
%644 = arith.extsi %641 : i32 to i64
%643 = arith.muli %644, %642 : i64
%645 = arith.remsi %643, %arg1 : i64
%646 = arith.subi %640, %645 : i64
%647 = func.call @sqsum(%636, %arg1, %arg3) : (i64, i64, i64) -> i64
%648 = arith.subi %646, %647 : i64
%649 = arith.constant 3 : i32
%651 = arith.extsi %649 : i32 to i64
%650 = arith.muli %651, %arg1 : i64
%652 = arith.addi %648, %650 : i64
%653 = arith.remsi %652, %arg1 : i64
%654 = llvm.getelementptr %arg6[%590] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %653, %654 : i64, !llvm.ptr
func.return %653 : i64
}
func.func @main() -> i32 {
%655 = arith.constant 282475249 : i32
%656 = arith.extsi %655 : i32 to i64
%657 = arith.constant 1048576 : i32
%658 = arith.extsi %657 : i32 to i64
%660 = arith.constant 8 : i32
%661 = arith.extsi %660 : i32 to i64
%659 = func.call @calloc(%658, %661) : (i64, i64) -> !llvm.ptr
%663 = arith.constant 8 : i32
%664 = arith.extsi %663 : i32 to i64
%662 = func.call @calloc(%658, %664) : (i64, i64) -> !llvm.ptr
%666 = arith.constant 8 : i32
%667 = arith.extsi %666 : i32 to i64
%665 = func.call @calloc(%658, %667) : (i64, i64) -> !llvm.ptr
%669 = arith.constant 8 : i32
%670 = arith.extsi %669 : i32 to i64
%668 = func.call @calloc(%658, %670) : (i64, i64) -> !llvm.ptr
%672 = arith.constant 1 : i32
%673 = arith.extsi %672 : i32 to i64
%671 = func.call @calloc(%658, %673) : (i64, i64) -> !llvm.ptr
%674 = llvm.mlir.zero : !llvm.ptr
%675 = llvm.icmp "eq" %659, %674 : !llvm.ptr
%676 = scf.if %675 -> (i1) {
%677 = arith.constant true
scf.yield %677 : i1
} else {
%678 = llvm.mlir.zero : !llvm.ptr
%679 = llvm.icmp "eq" %662, %678 : !llvm.ptr
scf.yield %679 : i1
}
%680 = scf.if %676 -> (i1) {
%681 = arith.constant true
scf.yield %681 : i1
} else {
%682 = llvm.mlir.zero : !llvm.ptr
%683 = llvm.icmp "eq" %665, %682 : !llvm.ptr
scf.yield %683 : i1
}
%684 = scf.if %680 -> (i1) {
%685 = arith.constant true
scf.yield %685 : i1
} else {
%686 = llvm.mlir.zero : !llvm.ptr
%687 = llvm.icmp "eq" %668, %686 : !llvm.ptr
scf.yield %687 : i1
}
%688 = scf.if %684 -> (i1) {
%689 = arith.constant true
scf.yield %689 : i1
} else {
%690 = llvm.mlir.zero : !llvm.ptr
%691 = llvm.icmp "eq" %671, %690 : !llvm.ptr
scf.yield %691 : i1
}
cf.cond_br %688, ^bb114, ^bb115
^bb114:
%692 = arith.constant 1 : i32
func.return %692 : i32
^bb115:
cf.br ^bb116
^bb116:
%694 = arith.constant 2 : i32
%695 = arith.extsi %694 : i32 to i64
%693 = func.call @modinv(%695, %656) : (i64, i64) -> i64
%697 = arith.constant 6 : i32
%698 = arith.extsi %697 : i32 to i64
%696 = func.call @modinv(%698, %656) : (i64, i64) -> i64
%699 = arith.constant 9999995705032704 : i32
%700 = arith.extsi %699 : i32 to i64
%701 = func.call @floor_n_sqrt5(%700) : (i64) -> i64
%702 = arith.subi %701, %700 : i64
%703 = arith.constant 2 : i32
%705 = arith.extsi %703 : i32 to i64
%704 = arith.divsi %702, %705 : i64
%706 = func.call @A(%704, %656, %693, %696, %659, %662, %665, %668, %671, %658) : (i64, i64, i64, i64, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, i64) -> i64
%707 = func.call @B(%704, %656, %693, %696, %659, %662, %665, %668, %671, %658) : (i64, i64, i64, i64, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, i64) -> i64
%708 = func.call @H(%704, %656, %693, %696, %659, %662, %665, %668, %671, %658) : (i64, i64, i64, i64, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, i64) -> i64
%709 = func.call @tri(%704, %656, %693) : (i64, i64, i64) -> i64
%710 = arith.subi %706, %709 : i64
%711 = arith.addi %710, %656 : i64
%712 = arith.remsi %711, %656 : i64
%713 = func.call @sqsum(%704, %656, %696) : (i64, i64, i64) -> i64
%714 = arith.subi %708, %713 : i64
%715 = arith.addi %714, %656 : i64
%716 = arith.remsi %715, %656 : i64
%717 = arith.constant 2 : i32
%719 = arith.extsi %717 : i32 to i64
%718 = arith.muli %719, %708 : i64
%720 = arith.remsi %718, %656 : i64
%721 = arith.subi %707, %720 : i64
%722 = func.call @sqsum(%704, %656, %696) : (i64, i64, i64) -> i64
%723 = arith.addi %721, %722 : i64
%724 = arith.constant 2 : i32
%726 = arith.extsi %724 : i32 to i64
%725 = arith.muli %726, %656 : i64
%727 = arith.addi %723, %725 : i64
%728 = arith.remsi %727, %656 : i64
%729 = arith.constant 2 : i32
%731 = arith.extsi %729 : i32 to i64
%730 = arith.muli %731, %716 : i64
%732 = arith.remsi %730, %656 : i64
%733 = arith.addi %728, %712 : i64
%734 = arith.remsi %733, %656 : i64
%735 = arith.muli %734, %693 : i64
%736 = arith.remsi %735, %656 : i64
%737 = arith.addi %732, %736 : i64
%738 = arith.remsi %737, %656 : i64
%739 = arith.subi %700, %704 : i64
%740 = arith.constant 1 : i32
%742 = arith.extsi %740 : i32 to i64
%741 = arith.subi %739, %742 : i64
%743 = arith.remsi %741, %656 : i64
%744 = arith.remsi %700, %656 : i64
%745 = arith.constant 1 : i32
%747 = arith.extsi %745 : i32 to i64
%746 = arith.addi %700, %747 : i64
%748 = arith.remsi %746, %656 : i64
%749 = arith.muli %744, %748 : i64
%750 = arith.remsi %749, %656 : i64
%751 = arith.remsi %704, %656 : i64
%752 = arith.constant 1 : i32
%754 = arith.extsi %752 : i32 to i64
%753 = arith.addi %704, %754 : i64
%755 = arith.remsi %753, %656 : i64
%756 = arith.muli %751, %755 : i64
%757 = arith.remsi %756, %656 : i64
%758 = arith.subi %750, %757 : i64
%759 = arith.addi %758, %656 : i64
%760 = arith.remsi %759, %656 : i64
%761 = arith.muli %743, %760 : i64
%762 = arith.remsi %761, %656 : i64
%763 = arith.muli %762, %693 : i64
%764 = arith.remsi %763, %656 : i64
%765 = llvm.mlir.addressof @str_0 : !llvm.ptr
%766 = arith.addi %738, %764 : i64
%767 = arith.remsi %766, %656 : i64
%768 = llvm.call @printf(%765, %767) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
func.call @free(%659) : (!llvm.ptr) -> ()
func.call @free(%662) : (!llvm.ptr) -> ()
func.call @free(%665) : (!llvm.ptr) -> ()
func.call @free(%668) : (!llvm.ptr) -> ()
func.call @free(%671) : (!llvm.ptr) -> ()
%774 = arith.constant 0 : i32
func.return %774 : i32
}
}