Problem 445

Retractions A: S(10^7) mod 10^9+7 via unitary sigma*. Ported from native C++ to pure Flow.

Answer659104042
Output659104042
StatusPASS
Native helperno
Runtime1490 ms
Peak memory533120 KB
Time complexityO(n^2) (estimated)
Space complexityO(n^2) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^2)O(n log log n)
Space complexityO(n^2)O(n)
ApproachFlow solutionSieve-based divisor sums
VerdictSuboptimal

Flow source

# Project Euler 445
# Retractions A: S(10^7) mod 10^9+7 via unitary sigma*.
# Ported from native C++ to pure Flow.

import euler.nt { isqrt }

extern {
    function calloc(n: i64, size: i64) -> ptr<void>
    function free(p: ptr<void>) -> void
}

const MOD: i64 = 1000000007

function modpow(a0: i64, e0: i64) -> i64 {
    let mut r: i64 = 1
    let mut a: i64 = a0 % MOD
    let mut e: i64 = e0
    while e > 0 {
        if e % 2 == 1 { r = r * a % MOD }
        a = a * a % MOD
        e = e / 2
    }
    return r
}

# ---- Sieve state (globals) ----
let mut g_spf: ptr<i32> = null
let mut g_prime_idx: ptr<i32> = null
let mut g_primes: ptr<i32> = null
let mut g_num_primes: i64 = 0

function sieve_spf(n: i64) -> void {
    g_spf = calloc(n + 1, 4) as ptr<i32>
    g_prime_idx = calloc(n + 1, 4) as ptr<i32>
    g_primes = calloc(n / 10 + 10000, 4) as ptr<i32>
    g_num_primes = 0
    # calloc zeroes, so spf and prime_idx are already 0
    g_spf[0] = 1
    g_spf[1] = 1
    if n >= 2 {
        g_spf[2] = 2
        g_primes[0] = 2
        g_num_primes = 1
        g_prime_idx[2] = 1
        let mut x: i64 = 4
        while x <= n {
            g_spf[x] = 2
            x = x + 2
        }
    }
    let limit: i64 = isqrt(n)
    let mut i: i64 = 3
    while i <= n {
        if g_spf[i] == 0 {
            g_spf[i] = i as i32
            g_primes[g_num_primes] = i as i32
            g_num_primes = g_num_primes + 1
            g_prime_idx[i] = g_num_primes as i32
            if i <= limit {
                let step: i64 = 2 * i
                let mut j: i64 = i * i
                while j <= n {
                    if g_spf[j] == 0 { g_spf[j] = i as i32 }
                    j = j + step
                }
            }
        }
        i = i + 2
    }
}

function inverses_upto(n: i64) -> ptr<i64> {
    let inv: ptr<i64> = calloc(n + 1, 8) as ptr<i64>
    inv[1] = 1
    let mut i: i64 = 2
    while i <= n {
        inv[i] = MOD - (MOD / i) * inv[MOD % i] % MOD
        i = i + 1
    }
    return inv
}

# Batch inverse: writes inverses of vals[0..n-1] to out[base..base+n-1]
function batch_inverse(vals: ptr<i64>, n: i64, out: ptr<i64>, base: i64) -> void {
    let idxs: ptr<i64> = calloc(n, 8) as ptr<i64>
    let prefix: ptr<i64> = calloc(n, 8) as ptr<i64>
    let mut count: i64 = 0
    let mut prod: i64 = 1
    let mut i: i64 = 0
    while i < n {
        if vals[i] != 0 {
            prod = prod * vals[i] % MOD
            idxs[count] = i
            prefix[count] = prod
            count = count + 1
        }
        i = i + 1
    }
    if count == 0 {
        free(idxs)
        free(prefix)
        return
    }
    let mut inv_all: i64 = modpow(prod, MOD - 2)
    let mut j: i64 = count - 1
    while j >= 0 {
        let i2: i64 = idxs[j]
        let prev: i64 = if j > 0 { prefix[j - 1] } else { 1 }
        out[base + i2] = inv_all * prev % MOD
        inv_all = inv_all * vals[i2] % MOD
        j = j - 1
    }
    free(idxs)
    free(prefix)
}

# ---- apply_factor state (globals) ----
let mut g_exp: ptr<i64> = null
let mut g_p_pow: ptr<i64> = null
let mut g_inv_terms: ptr<i64> = null
let mut g_offset: ptr<i64> = null
let mut g_inv_num: ptr<i64> = null
let mut g_prod: i64 = 1
let mut g_zero_count: i64 = 0

function apply_factor(x0: i64, sign: i64) -> void {
    let mut x: i64 = x0
    while x > 1 {
        let p: i64 = g_spf[x] as i64
        let pi: i64 = g_prime_idx[p] as i64 - 1
        let mut cnt: i64 = 0
        while x > 1 && (g_spf[x] as i64) == p {
            x = x / p
            cnt = cnt + 1
        }
        let old_e: i64 = g_exp[pi]
        if sign > 0 {
            if old_e != 0 {
                let mut term_old: i64 = g_p_pow[pi] + 1
                if term_old == MOD { term_old = 0 }
                if term_old != 0 {
                    g_prod = g_prod * g_inv_terms[g_offset[pi] + old_e - 1] % MOD
                } else {
                    g_zero_count = g_zero_count - 1
                }
            }
            let new_e: i64 = old_e + cnt
            g_exp[pi] = new_e
            if cnt == 1 {
                g_p_pow[pi] = g_p_pow[pi] * p % MOD
            } else {
                if cnt == 2 {
                    g_p_pow[pi] = g_p_pow[pi] * p % MOD * p % MOD
                } else {
                    g_p_pow[pi] = g_p_pow[pi] * modpow(p, cnt) % MOD
                }
            }
            let mut term_new: i64 = g_p_pow[pi] + 1
            if term_new == MOD { term_new = 0 }
            if term_new != 0 {
                g_prod = g_prod * term_new % MOD
            } else {
                g_zero_count = g_zero_count + 1
            }
        } else {
            let mut term_old: i64 = g_p_pow[pi] + 1
            if term_old == MOD { term_old = 0 }
            if term_old != 0 {
                g_prod = g_prod * g_inv_terms[g_offset[pi] + old_e - 1] % MOD
            } else {
                g_zero_count = g_zero_count - 1
            }
            let new_e2: i64 = old_e - cnt
            g_exp[pi] = new_e2
            let invp: i64 = g_inv_num[p]
            if cnt == 1 {
                g_p_pow[pi] = g_p_pow[pi] * invp % MOD
            } else {
                if cnt == 2 {
                    g_p_pow[pi] = g_p_pow[pi] * invp % MOD * invp % MOD
                } else {
                    g_p_pow[pi] = g_p_pow[pi] * modpow(invp, cnt) % MOD
                }
            }
            if new_e2 != 0 {
                let mut term_new2: i64 = g_p_pow[pi] + 1
                if term_new2 == MOD { term_new2 = 0 }
                if term_new2 != 0 {
                    g_prod = g_prod * term_new2 % MOD
                } else {
                    g_zero_count = g_zero_count + 1
                }
            }
        }
    }
}

function solve(N: i64) -> i64 {
    sieve_spf(N)
    let inv_num: ptr<i64> = inverses_upto(N)
    g_inv_num = inv_num

    let num_primes: i64 = g_num_primes
    let max_exp: ptr<i64> = calloc(num_primes, 8) as ptr<i64>
    let offset: ptr<i64> = calloc(num_primes, 8) as ptr<i64>
    let mut total_terms: i64 = 0
    let mut idx: i64 = 0
    while idx < num_primes {
        let p: i64 = g_primes[idx] as i64
        let mut t: i64 = N
        let mut e: i64 = 0
        while t != 0 {
            t = t / p
            e = e + t
        }
        max_exp[idx] = e
        offset[idx] = total_terms
        total_terms = total_terms + e
        idx = idx + 1
    }

    let inv_terms: ptr<i64> = calloc(total_terms, 8) as ptr<i64>
    g_inv_terms = inv_terms
    g_offset = offset

    let CHUNK: i64 = 1000000
    let vals: ptr<i64> = calloc(CHUNK, 8) as ptr<i64>
    let mut vals_count: i64 = 0
    let mut write_pos: i64 = 0
    idx = 0
    while idx < num_primes {
        let p: i64 = g_primes[idx] as i64
        let m: i64 = max_exp[idx]
        let mut pow_val: i64 = p % MOD
        let mut k: i64 = 0
        while k < m {
            vals[vals_count] = (pow_val + 1) % MOD
            vals_count = vals_count + 1
            pow_val = pow_val * p % MOD
            if vals_count >= CHUNK {
                batch_inverse(vals, vals_count, inv_terms, write_pos)
                write_pos = write_pos + vals_count
                vals_count = 0
            }
            k = k + 1
        }
        idx = idx + 1
    }
    if vals_count > 0 {
        batch_inverse(vals, vals_count, inv_terms, write_pos)
        write_pos = write_pos + vals_count
    }

    let exp_arr: ptr<i64> = calloc(num_primes, 8) as ptr<i64>
    let p_pow_arr: ptr<i64> = calloc(num_primes, 8) as ptr<i64>
    let mut pii: i64 = 0
    while pii < num_primes {
        p_pow_arr[pii] = 1
        pii = pii + 1
    }
    g_exp = exp_arr
    g_p_pow = p_pow_arr
    g_prod = 1
    g_zero_count = 0

    let mid: i64 = N / 2
    let even: bool = (N % 2 == 0)
    let mut sum_sigma: i64 = 0
    let mut k2: i64 = 1
    while k2 <= mid {
        let numer: i64 = N - k2 + 1
        let denom: i64 = k2
        apply_factor(numer, 1)
        apply_factor(denom, -1)
        let sigma_val: i64 = if g_zero_count != 0 { 0 } else { g_prod }
        if even && k2 == mid {
            sum_sigma = sum_sigma + sigma_val
        } else {
            sum_sigma = sum_sigma + 2 * sigma_val
        }
        if sum_sigma >= ((1 as i64) << 62) {
            sum_sigma = sum_sigma % MOD
        }
        k2 = k2 + 1
    }
    sum_sigma = sum_sigma % MOD
    let sum_binom: i64 = (modpow(2, N) - 2 + MOD) % MOD
    let ans: i64 = (sum_sigma - sum_binom + MOD) % MOD

    free(max_exp)
    free(offset)
    free(inv_terms)
    free(vals)
    free(exp_arr)
    free(p_pow_arr)
    free(inv_num)
    free(g_spf)
    free(g_prime_idx)
    free(g_primes)
    return ans
}

function main() -> i32 {
    printf("%lld\n", solve(10000000))
    return 0
}

Generated C

#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* Flow runtime helpers */
typedef struct flow_temp_node { struct flow_temp_node* next; } flow_temp_node;
static flow_temp_node* flow_temp_head = NULL;
static int flow_temp_atexit_set = 0;
__attribute__((unused)) static void flow_temp_free_all(void) {
    while (flow_temp_head) {
        flow_temp_node* n = flow_temp_head;
        flow_temp_head = n->next;
        free(n);
    }
}
__attribute__((unused)) static void* flow_temp_alloc(size_t nbytes) {
    flow_temp_node* node = (flow_temp_node*)malloc(sizeof(flow_temp_node) + nbytes);
    if (!node) return NULL;
    node->next = flow_temp_head;
    flow_temp_head = node;
    if (!flow_temp_atexit_set) {
        flow_temp_atexit_set = 1;
        atexit(flow_temp_free_all);
    }
    return (void*)(node + 1);
}
#ifndef FLOW_DIAG
#define FLOW_DIAG(msg) fprintf(stderr, "%s", (msg))
#endif
#ifndef FLOW_LOG
#define FLOW_LOG(fmt, ...) printf(fmt, __VA_ARGS__)
#endif
#ifndef FLOW_LOG_EMPTY
#define FLOW_LOG_EMPTY(fmt) printf(fmt)
#endif
static char* flow_strcat(const char* a, const char* b) {
    size_t la = strlen(a ? a : ""), lb = strlen(b ? b : "");
    char* r = (char*)flow_temp_alloc(la + lb + 1);
    if (!r) return NULL;
    if (la) memcpy(r, a, la);
    if (lb) memcpy(r + la, b, lb);
    r[la + lb] = '\0';
    return r;
}

#define __flow_in_arr(arr, val) __extension__ ({ \
    int _found = 0; \
    size_t _n = sizeof(arr)/sizeof((arr)[0]); \
    for (size_t _i = 0; _i < _n; _i++) { \
        if ((arr)[_i] == (val)) { _found = 1; break; } \
    } _found; })

/* Unified fault handler (MISRA #279) — override with -DFLOW_FAULT_HANDLER=fn */
#ifndef FLOW_FAULT_HANDLER
__attribute__((unused)) static inline void flow_fault_handler(const char* msg) {
    fprintf(stderr, "flow: %s\n", msg ? msg : "fault");
    abort();
#if defined(__GNUC__) || defined(__clang__)
    __builtin_unreachable();
#endif
}
#else
#define flow_fault_handler FLOW_FAULT_HANDLER
#endif
#define flow_div_by_zero_handler() flow_fault_handler("division by zero")
#define flow_shift_ub_handler() flow_fault_handler("invalid shift (amount out of range or left-shift of negative)")

#ifndef FLOW_CHECKED_DIV
#define FLOW_CHECKED_DIV(L, R) (((R) != 0) ? ((L) / (R)) : (flow_div_by_zero_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_MOD
#define FLOW_CHECKED_MOD(L, R) (((R) != 0) ? ((L) % (R)) : (flow_div_by_zero_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_SHL
#define FLOW_CHECKED_SHL(L, R) ((((R) >= 0) && ((unsigned long long)(R) < (sizeof(L) * 8ull)) && ((L) >= 0)) ? ((L) << (R)) : (flow_shift_ub_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_SHR
#define FLOW_CHECKED_SHR(L, R) ((((R) >= 0) && ((unsigned long long)(R) < (sizeof(L) * 8ull))) ? ((L) >> (R)) : (flow_shift_ub_handler(), (L) * 0))
#endif

#include <math.h>

void* _ui_state = NULL;

static inline float i32_to_f32(int32_t v) { return (float)v; }

/* Host stub for @gpu kernels (device codegen replaces this). */
static inline int32_t gpu_thread_id(void) { return 0; }

int64_t gcd_i64_i64(int64_t a0, int64_t b0);
int64_t lcm_i64_i64(int64_t a, int64_t b);
int64_t isqrt_i64(int64_t n);
int64_t mulmod_i64_i64_i64(int64_t a0, int64_t b0, int64_t mod);
int64_t mod_pow_i64_i64_i64(int64_t base, int64_t exp, int64_t mod);
bool is_prime_i64(int64_t n);
int64_t modpow_i64_i64(int64_t a0, int64_t e0);
void sieve_spf_i64(int64_t n);
int64_t* inverses_upto_i64(int64_t n);
void batch_inverse_ptr_i64_i64_ptr_i64_i64(int64_t* vals, int64_t n, int64_t* out, int64_t base);
void apply_factor_i64_i64(int64_t x0, int64_t sign);
int64_t solve_i64(int64_t N);
int32_t main(void);

static const int64_t MOD = 1000000007;

/* Module statics */
static int32_t* g_spf = NULL;
static int32_t* g_prime_idx = NULL;
static int32_t* g_primes = NULL;
static int64_t g_num_primes = 0;
static int64_t* g_exp = NULL;
static int64_t* g_p_pow = NULL;
static int64_t* g_inv_terms = NULL;
static int64_t* g_offset = NULL;
static int64_t* g_inv_num = NULL;
static int64_t g_prod = 1;
static int64_t g_zero_count = 0;

int64_t gcd_i64_i64(int64_t a0, int64_t b0) {
    int64_t a = a0;
    int64_t b = b0;
    while (b != 0) {
        int64_t t = FLOW_CHECKED_MOD((a), (b));
        a = b;
        b = t;
    }
    return a;
}

int64_t lcm_i64_i64(int64_t a, int64_t b) {
    if ((a == 0 || b == 0)) {
        return 0;
    }
    return (FLOW_CHECKED_DIV((a), (gcd_i64_i64(a, b))) * b);
}

int64_t isqrt_i64(int64_t n) {
    if (n < 2) {
        return n;
    }
    int64_t x = n;
    int64_t y = FLOW_CHECKED_DIV(((x + 1)), (2));
    while (y < x) {
        x = y;
        y = FLOW_CHECKED_DIV(((x + FLOW_CHECKED_DIV((n), (x)))), (2));
    }
    return x;
}

int64_t mulmod_i64_i64_i64(int64_t a0, int64_t b0, int64_t mod) {
    int64_t a = FLOW_CHECKED_MOD((a0), (mod));
    int64_t b = FLOW_CHECKED_MOD((b0), (mod));
    int64_t result = 0;
    while (b > 0) {
        if (FLOW_CHECKED_MOD((b), (2)) == 1) {
            result = FLOW_CHECKED_MOD(((result + a)), (mod));
        }
        a = FLOW_CHECKED_MOD(((a * 2)), (mod));
        b = FLOW_CHECKED_DIV((b), (2));
    }
    return result;
}

int64_t mod_pow_i64_i64_i64(int64_t base, int64_t exp, int64_t mod) {
    if (mod == 1) {
        return 0;
    }
    int64_t result = 1;
    int64_t b = FLOW_CHECKED_MOD((base), (mod));
    int64_t e = exp;
    while (e > 0) {
        if (FLOW_CHECKED_MOD((e), (2)) == 1) {
            result = mulmod_i64_i64_i64(result, b, mod);
        }
        b = mulmod_i64_i64_i64(b, b, mod);
        e = FLOW_CHECKED_DIV((e), (2));
    }
    return result;
}

bool is_prime_i64(int64_t n) {
    if (n < 2) {
        return 0;
    }
    if (n < 4) {
        return 1;
    }
    if ((FLOW_CHECKED_MOD((n), (2)) == 0 || FLOW_CHECKED_MOD((n), (3)) == 0)) {
        return 0;
    }
    int64_t i = 5;
    while ((i * i) <= n) {
        if ((FLOW_CHECKED_MOD((n), (i)) == 0 || FLOW_CHECKED_MOD((n), ((i + 2))) == 0)) {
            return 0;
        }
        i = (i + 6);
    }
    return 1;
}



int64_t modpow_i64_i64(int64_t a0, int64_t e0) {
    int64_t r = 1;
    int64_t a = FLOW_CHECKED_MOD((a0), (MOD));
    int64_t e = e0;
    while (e > 0) {
        if (FLOW_CHECKED_MOD((e), (2)) == 1) {
            r = FLOW_CHECKED_MOD(((r * a)), (MOD));
        }
        a = FLOW_CHECKED_MOD(((a * a)), (MOD));
        e = FLOW_CHECKED_DIV((e), (2));
    }
    return r;
}

void sieve_spf_i64(int64_t n) {
    g_spf = ((int32_t*)(calloc((n + 1), 4)));
    g_prime_idx = ((int32_t*)(calloc((n + 1), 4)));
    g_primes = ((int32_t*)(calloc((FLOW_CHECKED_DIV((n), (10)) + 10000), 4)));
    g_num_primes = 0;
    g_spf[0] = 1;
    g_spf[1] = 1;
    if (n >= 2) {
        g_spf[2] = 2;
        g_primes[0] = 2;
        g_num_primes = 1;
        g_prime_idx[2] = 1;
        int64_t x = 4;
        while (x <= n) {
            g_spf[x] = 2;
            x = (x + 2);
        }
    }
    int64_t limit = isqrt_i64(n);
    int64_t i = 3;
    while (i <= n) {
        if (g_spf[i] == 0) {
            g_spf[i] = ((int32_t)(i));
            g_primes[g_num_primes] = ((int32_t)(i));
            g_num_primes = (g_num_primes + 1);
            g_prime_idx[i] = ((int32_t)(g_num_primes));
            if (i <= limit) {
                int64_t step = (2 * i);
                int64_t j = (i * i);
                while (j <= n) {
                    if (g_spf[j] == 0) {
                        g_spf[j] = ((int32_t)(i));
                    }
                    j = (j + step);
                }
            }
        }
        i = (i + 2);
    }
}

int64_t* inverses_upto_i64(int64_t n) {
    int64_t* inv = (int64_t*)(((int64_t*)(calloc((n + 1), 8))));
    inv[1] = 1;
    int64_t i = 2;
    while (i <= n) {
        inv[i] = (MOD - FLOW_CHECKED_MOD(((FLOW_CHECKED_DIV((MOD), (i)) * inv[FLOW_CHECKED_MOD((MOD), (i))])), (MOD)));
        i = (i + 1);
    }
    return inv;
}

void batch_inverse_ptr_i64_i64_ptr_i64_i64(int64_t* vals, int64_t n, int64_t* out, int64_t base) {
    int64_t* idxs = (int64_t*)(((int64_t*)(calloc(n, 8))));
    int64_t* prefix = (int64_t*)(((int64_t*)(calloc(n, 8))));
    int64_t count = 0;
    int64_t prod = 1;
    int64_t i = 0;
    while (i < n) {
        if (vals[i] != 0) {
            prod = FLOW_CHECKED_MOD(((prod * vals[i])), (MOD));
            idxs[count] = i;
            prefix[count] = prod;
            count = (count + 1);
        }
        i = (i + 1);
    }
    if (count == 0) {
        free(idxs);
        free(prefix);
        return;
    }
    int64_t inv_all = modpow_i64_i64(prod, (MOD - 2));
    int64_t j = (count - 1);
    while (j >= 0) {
        int64_t i2 = idxs[j];
        int64_t prev = ((j > 0) ? (prefix[(j - 1)]) : (1));
        out[(base + i2)] = FLOW_CHECKED_MOD(((inv_all * prev)), (MOD));
        inv_all = FLOW_CHECKED_MOD(((inv_all * vals[i2])), (MOD));
        j = (j - 1);
    }
    free(idxs);
    free(prefix);
}

void apply_factor_i64_i64(int64_t x0, int64_t sign) {
    int64_t x = x0;
    while (x > 1) {
        int64_t p = ((int64_t)(g_spf[x]));
        int64_t pi = (((int64_t)(g_prime_idx[p])) - 1);
        int64_t cnt = 0;
        while ((x > 1 && ((int64_t)(g_spf[x])) == p)) {
            x = FLOW_CHECKED_DIV((x), (p));
            cnt = (cnt + 1);
        }
        int64_t old_e = g_exp[pi];
        if (sign > 0) {
            if (old_e != 0) {
                int64_t term_old = (g_p_pow[pi] + 1);
                if (term_old == MOD) {
                    term_old = 0;
                }
                if (term_old != 0) {
                    g_prod = FLOW_CHECKED_MOD(((g_prod * g_inv_terms[((g_offset[pi] + old_e) - 1)])), (MOD));
                } else {
                    g_zero_count = (g_zero_count - 1);
                }
            }
            int64_t new_e = (old_e + cnt);
            g_exp[pi] = new_e;
            if (cnt == 1) {
                g_p_pow[pi] = FLOW_CHECKED_MOD(((g_p_pow[pi] * p)), (MOD));
            } else {
                if (cnt == 2) {
                    g_p_pow[pi] = FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD(((g_p_pow[pi] * p)), (MOD)) * p)), (MOD));
                } else {
                    g_p_pow[pi] = FLOW_CHECKED_MOD(((g_p_pow[pi] * modpow_i64_i64(p, cnt))), (MOD));
                }
            }
            int64_t term_new = (g_p_pow[pi] + 1);
            if (term_new == MOD) {
                term_new = 0;
            }
            if (term_new != 0) {
                g_prod = FLOW_CHECKED_MOD(((g_prod * term_new)), (MOD));
            } else {
                g_zero_count = (g_zero_count + 1);
            }
        } else {
            int64_t term_old = (g_p_pow[pi] + 1);
            if (term_old == MOD) {
                term_old = 0;
            }
            if (term_old != 0) {
                g_prod = FLOW_CHECKED_MOD(((g_prod * g_inv_terms[((g_offset[pi] + old_e) - 1)])), (MOD));
            } else {
                g_zero_count = (g_zero_count - 1);
            }
            int64_t new_e2 = (old_e - cnt);
            g_exp[pi] = new_e2;
            int64_t invp = g_inv_num[p];
            if (cnt == 1) {
                g_p_pow[pi] = FLOW_CHECKED_MOD(((g_p_pow[pi] * invp)), (MOD));
            } else {
                if (cnt == 2) {
                    g_p_pow[pi] = FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD(((g_p_pow[pi] * invp)), (MOD)) * invp)), (MOD));
                } else {
                    g_p_pow[pi] = FLOW_CHECKED_MOD(((g_p_pow[pi] * modpow_i64_i64(invp, cnt))), (MOD));
                }
            }
            if (new_e2 != 0) {
                int64_t term_new2 = (g_p_pow[pi] + 1);
                if (term_new2 == MOD) {
                    term_new2 = 0;
                }
                if (term_new2 != 0) {
                    g_prod = FLOW_CHECKED_MOD(((g_prod * term_new2)), (MOD));
                } else {
                    g_zero_count = (g_zero_count + 1);
                }
            }
        }
    }
}

int64_t solve_i64(int64_t N) {
    sieve_spf_i64(N);
    int64_t* inv_num = (int64_t*)(inverses_upto_i64(N));
    g_inv_num = inv_num;
    int64_t num_primes = g_num_primes;
    int64_t* max_exp = (int64_t*)(((int64_t*)(calloc(num_primes, 8))));
    int64_t* offset = (int64_t*)(((int64_t*)(calloc(num_primes, 8))));
    int64_t total_terms = 0;
    int64_t idx = 0;
    while (idx < num_primes) {
        int64_t p = ((int64_t)(g_primes[idx]));
        int64_t t = N;
        int64_t e = 0;
        while (t != 0) {
            t = FLOW_CHECKED_DIV((t), (p));
            e = (e + t);
        }
        max_exp[idx] = e;
        offset[idx] = total_terms;
        total_terms = (total_terms + e);
        idx = (idx + 1);
    }
    int64_t* inv_terms = (int64_t*)(((int64_t*)(calloc(total_terms, 8))));
    g_inv_terms = inv_terms;
    g_offset = offset;
    int64_t CHUNK = 1000000;
    int64_t* vals = (int64_t*)(((int64_t*)(calloc(CHUNK, 8))));
    int64_t vals_count = 0;
    int64_t write_pos = 0;
    idx = 0;
    while (idx < num_primes) {
        int64_t p = ((int64_t)(g_primes[idx]));
        int64_t m = max_exp[idx];
        int64_t pow_val = FLOW_CHECKED_MOD((p), (MOD));
        int64_t k = 0;
        while (k < m) {
            vals[vals_count] = FLOW_CHECKED_MOD(((pow_val + 1)), (MOD));
            vals_count = (vals_count + 1);
            pow_val = FLOW_CHECKED_MOD(((pow_val * p)), (MOD));
            if (vals_count >= CHUNK) {
                batch_inverse_ptr_i64_i64_ptr_i64_i64(vals, vals_count, inv_terms, write_pos);
                write_pos = (write_pos + vals_count);
                vals_count = 0;
            }
            k = (k + 1);
        }
        idx = (idx + 1);
    }
    if (vals_count > 0) {
        batch_inverse_ptr_i64_i64_ptr_i64_i64(vals, vals_count, inv_terms, write_pos);
        write_pos = (write_pos + vals_count);
    }
    int64_t* exp_arr = (int64_t*)(((int64_t*)(calloc(num_primes, 8))));
    int64_t* p_pow_arr = (int64_t*)(((int64_t*)(calloc(num_primes, 8))));
    int64_t pii = 0;
    while (pii < num_primes) {
        p_pow_arr[pii] = 1;
        pii = (pii + 1);
    }
    g_exp = exp_arr;
    g_p_pow = p_pow_arr;
    g_prod = 1;
    g_zero_count = 0;
    int64_t mid = FLOW_CHECKED_DIV((N), (2));
    bool even = FLOW_CHECKED_MOD((N), (2)) == 0;
    int64_t sum_sigma = 0;
    int64_t k2 = 1;
    while (k2 <= mid) {
        int64_t numer = ((N - k2) + 1);
        int64_t denom = k2;
        apply_factor_i64_i64(numer, 1);
        apply_factor_i64_i64(denom, (-1));
        int64_t sigma_val = ((g_zero_count != 0) ? (0) : (g_prod));
        if ((even && k2 == mid)) {
            sum_sigma = (sum_sigma + sigma_val);
        } else {
            sum_sigma = (sum_sigma + (2 * sigma_val));
        }
        if (sum_sigma >= FLOW_CHECKED_SHL((((int64_t)(1))), (62))) {
            sum_sigma = FLOW_CHECKED_MOD((sum_sigma), (MOD));
        }
        k2 = (k2 + 1);
    }
    sum_sigma = FLOW_CHECKED_MOD((sum_sigma), (MOD));
    int64_t sum_binom = FLOW_CHECKED_MOD((((modpow_i64_i64(2, N) - 2) + MOD)), (MOD));
    int64_t ans = FLOW_CHECKED_MOD((((sum_sigma - sum_binom) + MOD)), (MOD));
    free(max_exp);
    free(offset);
    free(inv_terms);
    free(vals);
    free(exp_arr);
    free(p_pow_arr);
    free(inv_num);
    free(g_spf);
    free(g_prime_idx);
    free(g_primes);
    return ans;
}

int32_t main(void) {
    printf("%lld\n", solve_i64(10000000));
    return 0;
}

Generated MLIR

module {
  llvm.func @printf(!llvm.ptr, ...) -> i32
  llvm.mlir.global internal constant @str_0("%lld\n\00") {addr_space = 0 : i32} : !llvm.array<6 x i8>
  func.func @gcd(%arg0: i64, %arg1: i64) -> i64 {
    %0 = llvm.mlir.constant(1 : i64) : i64
    %1 = llvm.alloca %0 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %1 : i64, !llvm.ptr
    %2 = llvm.mlir.constant(1 : i64) : i64
    %3 = llvm.alloca %2 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %3 : i64, !llvm.ptr
    cf.br ^bb0
    ^bb0:
    %4 = llvm.load %3 : !llvm.ptr -> i64
    %5 = arith.constant 0 : i32
    %7 = arith.extsi %5 : i32 to i64
    %6 = arith.cmpi ne, %4, %7 : i64
    cf.cond_br %6, ^bb1, ^bb2
    ^bb1:
      %8 = llvm.load %1 : !llvm.ptr -> i64
      %9 = llvm.load %3 : !llvm.ptr -> i64
      %10 = arith.remsi %8, %9 : i64
      %11 = llvm.load %3 : !llvm.ptr -> i64
      llvm.store %11, %1 : i64, !llvm.ptr
      llvm.store %10, %3 : i64, !llvm.ptr
      cf.br ^bb0
    ^bb2:
    %12 = llvm.load %1 : !llvm.ptr -> i64
    func.return %12 : i64
  }
  func.func @lcm(%arg0: i64, %arg1: i64) -> i64 {
    %13 = arith.constant 0 : i32
    %15 = arith.extsi %13 : i32 to i64
    %14 = arith.cmpi eq, %arg0, %15 : i64
    %16 = scf.if %14 -> (i1) {
      %17 = arith.constant true
      scf.yield %17 : i1
    } else {
      %18 = arith.constant 0 : i32
      %20 = arith.extsi %18 : i32 to i64
      %19 = arith.cmpi eq, %arg1, %20 : i64
      scf.yield %19 : i1
    }
    cf.cond_br %16, ^bb3, ^bb4
    ^bb3:
      %21 = arith.constant 0 : i32
      %22 = arith.extsi %21 : i32 to i64
      func.return %22 : i64
    ^bb4:
      cf.br ^bb5
    ^bb5:
    %23 = func.call @gcd(%arg0, %arg1) : (i64, i64) -> i64
    %24 = arith.divsi %arg0, %23 : i64
    %25 = arith.muli %24, %arg1 : i64
    func.return %25 : i64
  }
  func.func @isqrt(%arg0: i64) -> i64 {
    %26 = arith.constant 2 : i32
    %28 = arith.extsi %26 : i32 to i64
    %27 = arith.cmpi slt, %arg0, %28 : i64
    cf.cond_br %27, ^bb6, ^bb7
    ^bb6:
      func.return %arg0 : i64
    ^bb7:
      cf.br ^bb8
    ^bb8:
    %29 = llvm.mlir.constant(1 : i64) : i64
    %30 = llvm.alloca %29 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %30 : i64, !llvm.ptr
    %31 = llvm.load %30 : !llvm.ptr -> i64
    %32 = arith.constant 1 : i32
    %34 = arith.extsi %32 : i32 to i64
    %33 = arith.addi %31, %34 : i64
    %35 = arith.constant 2 : i32
    %37 = arith.extsi %35 : i32 to i64
    %36 = arith.divsi %33, %37 : i64
    %38 = llvm.mlir.constant(1 : i64) : i64
    %39 = llvm.alloca %38 x i64 : (i64) -> !llvm.ptr
    llvm.store %36, %39 : i64, !llvm.ptr
    cf.br ^bb9
    ^bb9:
    %40 = llvm.load %39 : !llvm.ptr -> i64
    %41 = llvm.load %30 : !llvm.ptr -> i64
    %42 = arith.cmpi slt, %40, %41 : i64
    cf.cond_br %42, ^bb10, ^bb11
    ^bb10:
      %43 = llvm.load %39 : !llvm.ptr -> i64
      llvm.store %43, %30 : i64, !llvm.ptr
      %44 = llvm.load %30 : !llvm.ptr -> i64
      %45 = llvm.load %30 : !llvm.ptr -> i64
      %46 = arith.divsi %arg0, %45 : i64
      %47 = arith.addi %44, %46 : i64
      %48 = arith.constant 2 : i32
      %50 = arith.extsi %48 : i32 to i64
      %49 = arith.divsi %47, %50 : i64
      llvm.store %49, %39 : i64, !llvm.ptr
      cf.br ^bb9
    ^bb11:
    %51 = llvm.load %30 : !llvm.ptr -> i64
    func.return %51 : i64
  }
  func.func @mulmod(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %52 = arith.remsi %arg0, %arg2 : i64
    %53 = llvm.mlir.constant(1 : i64) : i64
    %54 = llvm.alloca %53 x i64 : (i64) -> !llvm.ptr
    llvm.store %52, %54 : i64, !llvm.ptr
    %55 = arith.remsi %arg1, %arg2 : i64
    %56 = llvm.mlir.constant(1 : i64) : i64
    %57 = llvm.alloca %56 x i64 : (i64) -> !llvm.ptr
    llvm.store %55, %57 : i64, !llvm.ptr
    %58 = arith.constant 0 : i32
    %59 = arith.extsi %58 : i32 to i64
    %60 = llvm.mlir.constant(1 : i64) : i64
    %61 = llvm.alloca %60 x i64 : (i64) -> !llvm.ptr
    llvm.store %59, %61 : i64, !llvm.ptr
    cf.br ^bb12
    ^bb12:
    %62 = llvm.load %57 : !llvm.ptr -> i64
    %63 = arith.constant 0 : i32
    %65 = arith.extsi %63 : i32 to i64
    %64 = arith.cmpi sgt, %62, %65 : i64
    cf.cond_br %64, ^bb13, ^bb14
    ^bb13:
      %66 = llvm.load %57 : !llvm.ptr -> i64
      %67 = arith.constant 2 : i32
      %69 = arith.extsi %67 : i32 to i64
      %68 = arith.remsi %66, %69 : i64
      %70 = arith.constant 1 : i32
      %72 = arith.extsi %70 : i32 to i64
      %71 = arith.cmpi eq, %68, %72 : i64
      cf.cond_br %71, ^bb15, ^bb16
      ^bb15:
        %73 = llvm.load %61 : !llvm.ptr -> i64
        %74 = llvm.load %54 : !llvm.ptr -> i64
        %75 = arith.addi %73, %74 : i64
        %76 = arith.remsi %75, %arg2 : i64
        llvm.store %76, %61 : i64, !llvm.ptr
        cf.br ^bb17
      ^bb16:
        cf.br ^bb17
      ^bb17:
      %77 = llvm.load %54 : !llvm.ptr -> i64
      %78 = arith.constant 2 : i32
      %80 = arith.extsi %78 : i32 to i64
      %79 = arith.muli %77, %80 : i64
      %81 = arith.remsi %79, %arg2 : i64
      llvm.store %81, %54 : i64, !llvm.ptr
      %82 = llvm.load %57 : !llvm.ptr -> i64
      %83 = arith.constant 2 : i32
      %85 = arith.extsi %83 : i32 to i64
      %84 = arith.divsi %82, %85 : i64
      llvm.store %84, %57 : i64, !llvm.ptr
      cf.br ^bb12
    ^bb14:
    %86 = llvm.load %61 : !llvm.ptr -> i64
    func.return %86 : i64
  }
  func.func @mod_pow(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %87 = arith.constant 1 : i32
    %89 = arith.extsi %87 : i32 to i64
    %88 = arith.cmpi eq, %arg2, %89 : i64
    cf.cond_br %88, ^bb18, ^bb19
    ^bb18:
      %90 = arith.constant 0 : i32
      %91 = arith.extsi %90 : i32 to i64
      func.return %91 : i64
    ^bb19:
      cf.br ^bb20
    ^bb20:
    %92 = arith.constant 1 : i32
    %93 = arith.extsi %92 : i32 to i64
    %94 = llvm.mlir.constant(1 : i64) : i64
    %95 = llvm.alloca %94 x i64 : (i64) -> !llvm.ptr
    llvm.store %93, %95 : i64, !llvm.ptr
    %96 = arith.remsi %arg0, %arg2 : i64
    %97 = llvm.mlir.constant(1 : i64) : i64
    %98 = llvm.alloca %97 x i64 : (i64) -> !llvm.ptr
    llvm.store %96, %98 : i64, !llvm.ptr
    %99 = llvm.mlir.constant(1 : i64) : i64
    %100 = llvm.alloca %99 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %100 : i64, !llvm.ptr
    cf.br ^bb21
    ^bb21:
    %101 = llvm.load %100 : !llvm.ptr -> i64
    %102 = arith.constant 0 : i32
    %104 = arith.extsi %102 : i32 to i64
    %103 = arith.cmpi sgt, %101, %104 : i64
    cf.cond_br %103, ^bb22, ^bb23
    ^bb22:
      %105 = llvm.load %100 : !llvm.ptr -> i64
      %106 = arith.constant 2 : i32
      %108 = arith.extsi %106 : i32 to i64
      %107 = arith.remsi %105, %108 : i64
      %109 = arith.constant 1 : i32
      %111 = arith.extsi %109 : i32 to i64
      %110 = arith.cmpi eq, %107, %111 : i64
      cf.cond_br %110, ^bb24, ^bb25
      ^bb24:
        %113 = llvm.load %95 : !llvm.ptr -> i64
        %114 = llvm.load %98 : !llvm.ptr -> i64
        %112 = func.call @mulmod(%113, %114, %arg2) : (i64, i64, i64) -> i64
        llvm.store %112, %95 : i64, !llvm.ptr
        cf.br ^bb26
      ^bb25:
        cf.br ^bb26
      ^bb26:
      %116 = llvm.load %98 : !llvm.ptr -> i64
      %117 = llvm.load %98 : !llvm.ptr -> i64
      %115 = func.call @mulmod(%116, %117, %arg2) : (i64, i64, i64) -> i64
      llvm.store %115, %98 : i64, !llvm.ptr
      %118 = llvm.load %100 : !llvm.ptr -> i64
      %119 = arith.constant 2 : i32
      %121 = arith.extsi %119 : i32 to i64
      %120 = arith.divsi %118, %121 : i64
      llvm.store %120, %100 : i64, !llvm.ptr
      cf.br ^bb21
    ^bb23:
    %122 = llvm.load %95 : !llvm.ptr -> i64
    func.return %122 : i64
  }
  func.func @is_prime(%arg0: i64) -> i1 {
    %123 = arith.constant 2 : i32
    %125 = arith.extsi %123 : i32 to i64
    %124 = arith.cmpi slt, %arg0, %125 : i64
    cf.cond_br %124, ^bb27, ^bb28
    ^bb27:
      %126 = arith.constant 0 : i1
      func.return %126 : i1
    ^bb28:
      cf.br ^bb29
    ^bb29:
    %127 = arith.constant 4 : i32
    %129 = arith.extsi %127 : i32 to i64
    %128 = arith.cmpi slt, %arg0, %129 : i64
    cf.cond_br %128, ^bb30, ^bb31
    ^bb30:
      %130 = arith.constant 1 : i1
      func.return %130 : i1
    ^bb31:
      cf.br ^bb32
    ^bb32:
    %131 = arith.constant 2 : i32
    %133 = arith.extsi %131 : i32 to i64
    %132 = arith.remsi %arg0, %133 : i64
    %134 = arith.constant 0 : i32
    %136 = arith.extsi %134 : i32 to i64
    %135 = arith.cmpi eq, %132, %136 : i64
    %137 = scf.if %135 -> (i1) {
      %138 = arith.constant true
      scf.yield %138 : i1
    } else {
      %139 = arith.constant 3 : i32
      %141 = arith.extsi %139 : i32 to i64
      %140 = arith.remsi %arg0, %141 : i64
      %142 = arith.constant 0 : i32
      %144 = arith.extsi %142 : i32 to i64
      %143 = arith.cmpi eq, %140, %144 : i64
      scf.yield %143 : i1
    }
    cf.cond_br %137, ^bb33, ^bb34
    ^bb33:
      %145 = arith.constant 0 : i1
      func.return %145 : i1
    ^bb34:
      cf.br ^bb35
    ^bb35:
    %146 = arith.constant 5 : i32
    %147 = arith.extsi %146 : i32 to i64
    %148 = llvm.mlir.constant(1 : i64) : i64
    %149 = llvm.alloca %148 x i64 : (i64) -> !llvm.ptr
    llvm.store %147, %149 : i64, !llvm.ptr
    cf.br ^bb36
    ^bb36:
    %150 = llvm.load %149 : !llvm.ptr -> i64
    %151 = llvm.load %149 : !llvm.ptr -> i64
    %152 = arith.muli %150, %151 : i64
    %153 = arith.cmpi sle, %152, %arg0 : i64
    cf.cond_br %153, ^bb37, ^bb38
    ^bb37:
      %154 = llvm.load %149 : !llvm.ptr -> i64
      %155 = arith.remsi %arg0, %154 : i64
      %156 = arith.constant 0 : i32
      %158 = arith.extsi %156 : i32 to i64
      %157 = arith.cmpi eq, %155, %158 : i64
      %159 = scf.if %157 -> (i1) {
        %160 = arith.constant true
        scf.yield %160 : i1
      } else {
        %161 = llvm.load %149 : !llvm.ptr -> i64
        %162 = arith.constant 2 : i32
        %164 = arith.extsi %162 : i32 to i64
        %163 = arith.addi %161, %164 : i64
        %165 = arith.remsi %arg0, %163 : i64
        %166 = arith.constant 0 : i32
        %168 = arith.extsi %166 : i32 to i64
        %167 = arith.cmpi eq, %165, %168 : i64
        scf.yield %167 : i1
      }
      cf.cond_br %159, ^bb39, ^bb40
      ^bb39:
        %169 = arith.constant 0 : i1
        func.return %169 : i1
      ^bb40:
        cf.br ^bb41
      ^bb41:
      %170 = llvm.load %149 : !llvm.ptr -> i64
      %171 = arith.constant 6 : i32
      %173 = arith.extsi %171 : i32 to i64
      %172 = arith.addi %170, %173 : i64
      llvm.store %172, %149 : i64, !llvm.ptr
      cf.br ^bb36
    ^bb38:
    %174 = arith.constant 1 : i1
    func.return %174 : i1
  }
  func.func private @calloc(i64, i64) -> !llvm.ptr
  func.func private @free(!llvm.ptr) -> ()
  // Constant: MOD
  llvm.mlir.global internal constant @MOD(1000000007 : i64) : i64
  func.func @modpow(%arg0: i64, %arg1: i64) -> 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 = llvm.mlir.addressof @MOD : !llvm.ptr
    %180 = llvm.load %179 : !llvm.ptr -> i64
    %181 = arith.remsi %arg0, %180 : i64
    %182 = llvm.mlir.constant(1 : i64) : i64
    %183 = llvm.alloca %182 x i64 : (i64) -> !llvm.ptr
    llvm.store %181, %183 : i64, !llvm.ptr
    %184 = llvm.mlir.constant(1 : i64) : i64
    %185 = llvm.alloca %184 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %185 : i64, !llvm.ptr
    cf.br ^bb42
    ^bb42:
    %186 = llvm.load %185 : !llvm.ptr -> i64
    %187 = arith.constant 0 : i32
    %189 = arith.extsi %187 : i32 to i64
    %188 = arith.cmpi sgt, %186, %189 : i64
    cf.cond_br %188, ^bb43, ^bb44
    ^bb43:
      %190 = llvm.load %185 : !llvm.ptr -> i64
      %191 = arith.constant 2 : i32
      %193 = arith.extsi %191 : i32 to i64
      %192 = arith.remsi %190, %193 : i64
      %194 = arith.constant 1 : i32
      %196 = arith.extsi %194 : i32 to i64
      %195 = arith.cmpi eq, %192, %196 : i64
      cf.cond_br %195, ^bb45, ^bb46
      ^bb45:
        %197 = llvm.load %178 : !llvm.ptr -> i64
        %198 = llvm.load %183 : !llvm.ptr -> i64
        %199 = arith.muli %197, %198 : i64
        %200 = llvm.mlir.addressof @MOD : !llvm.ptr
        %201 = llvm.load %200 : !llvm.ptr -> i64
        %202 = arith.remsi %199, %201 : i64
        llvm.store %202, %178 : i64, !llvm.ptr
        cf.br ^bb47
      ^bb46:
        cf.br ^bb47
      ^bb47:
      %203 = llvm.load %183 : !llvm.ptr -> i64
      %204 = llvm.load %183 : !llvm.ptr -> i64
      %205 = arith.muli %203, %204 : i64
      %206 = llvm.mlir.addressof @MOD : !llvm.ptr
      %207 = llvm.load %206 : !llvm.ptr -> i64
      %208 = arith.remsi %205, %207 : i64
      llvm.store %208, %183 : i64, !llvm.ptr
      %209 = llvm.load %185 : !llvm.ptr -> i64
      %210 = arith.constant 2 : i32
      %212 = arith.extsi %210 : i32 to i64
      %211 = arith.divsi %209, %212 : i64
      llvm.store %211, %185 : i64, !llvm.ptr
      cf.br ^bb42
    ^bb44:
    %213 = llvm.load %178 : !llvm.ptr -> i64
    func.return %213 : i64
  }
  // Module static: g_spf
  llvm.mlir.global internal @g_spf() {addr_space = 0 : i32} : !llvm.ptr {
    %214 = llvm.mlir.zero : !llvm.ptr
    llvm.return %214 : !llvm.ptr
  }
  // Module static: g_prime_idx
  llvm.mlir.global internal @g_prime_idx() {addr_space = 0 : i32} : !llvm.ptr {
    %215 = llvm.mlir.zero : !llvm.ptr
    llvm.return %215 : !llvm.ptr
  }
  // Module static: g_primes
  llvm.mlir.global internal @g_primes() {addr_space = 0 : i32} : !llvm.ptr {
    %216 = llvm.mlir.zero : !llvm.ptr
    llvm.return %216 : !llvm.ptr
  }
  // Module static: g_num_primes
  llvm.mlir.global internal @g_num_primes(0 : i64) : i64
  func.func @sieve_spf(%arg0: i64) -> () {
    %218 = arith.constant 1 : i32
    %220 = arith.extsi %218 : i32 to i64
    %219 = arith.addi %arg0, %220 : i64
    %221 = arith.constant 4 : i32
    %222 = arith.extsi %221 : i32 to i64
    %217 = func.call @calloc(%219, %222) : (i64, i64) -> !llvm.ptr
    %223 = llvm.mlir.addressof @g_spf : !llvm.ptr
    llvm.store %217, %223 : !llvm.ptr, !llvm.ptr
    %225 = arith.constant 1 : i32
    %227 = arith.extsi %225 : i32 to i64
    %226 = arith.addi %arg0, %227 : i64
    %228 = arith.constant 4 : i32
    %229 = arith.extsi %228 : i32 to i64
    %224 = func.call @calloc(%226, %229) : (i64, i64) -> !llvm.ptr
    %230 = llvm.mlir.addressof @g_prime_idx : !llvm.ptr
    llvm.store %224, %230 : !llvm.ptr, !llvm.ptr
    %232 = arith.constant 10 : i32
    %234 = arith.extsi %232 : i32 to i64
    %233 = arith.divsi %arg0, %234 : i64
    %235 = arith.constant 10000 : i32
    %237 = arith.extsi %235 : i32 to i64
    %236 = arith.addi %233, %237 : i64
    %238 = arith.constant 4 : i32
    %239 = arith.extsi %238 : i32 to i64
    %231 = func.call @calloc(%236, %239) : (i64, i64) -> !llvm.ptr
    %240 = llvm.mlir.addressof @g_primes : !llvm.ptr
    llvm.store %231, %240 : !llvm.ptr, !llvm.ptr
    %241 = arith.constant 0 : i32
    %242 = arith.extsi %241 : i32 to i64
    %243 = llvm.mlir.addressof @g_num_primes : !llvm.ptr
    llvm.store %242, %243 : i64, !llvm.ptr
    %244 = arith.constant 1 : i32
    %245 = llvm.mlir.addressof @g_spf : !llvm.ptr
    %246 = llvm.load %245 : !llvm.ptr -> !llvm.ptr
    %247 = arith.constant 0 : i32
    %248 = arith.extsi %247 : i32 to i64
    %249 = llvm.getelementptr %246[%248] : (!llvm.ptr, i64) -> !llvm.ptr, i32
    llvm.store %244, %249 : i32, !llvm.ptr
    %250 = arith.constant 1 : i32
    %251 = llvm.mlir.addressof @g_spf : !llvm.ptr
    %252 = llvm.load %251 : !llvm.ptr -> !llvm.ptr
    %253 = arith.constant 1 : i32
    %254 = arith.extsi %253 : i32 to i64
    %255 = llvm.getelementptr %252[%254] : (!llvm.ptr, i64) -> !llvm.ptr, i32
    llvm.store %250, %255 : i32, !llvm.ptr
    %256 = arith.constant 2 : i32
    %258 = arith.extsi %256 : i32 to i64
    %257 = arith.cmpi sge, %arg0, %258 : i64
    cf.cond_br %257, ^bb48, ^bb49
    ^bb48:
      %259 = arith.constant 2 : i32
      %260 = llvm.mlir.addressof @g_spf : !llvm.ptr
      %261 = llvm.load %260 : !llvm.ptr -> !llvm.ptr
      %262 = arith.constant 2 : i32
      %263 = arith.extsi %262 : i32 to i64
      %264 = llvm.getelementptr %261[%263] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      llvm.store %259, %264 : i32, !llvm.ptr
      %265 = arith.constant 2 : i32
      %266 = llvm.mlir.addressof @g_primes : !llvm.ptr
      %267 = llvm.load %266 : !llvm.ptr -> !llvm.ptr
      %268 = arith.constant 0 : i32
      %269 = arith.extsi %268 : i32 to i64
      %270 = llvm.getelementptr %267[%269] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      llvm.store %265, %270 : i32, !llvm.ptr
      %271 = arith.constant 1 : i32
      %272 = arith.extsi %271 : i32 to i64
      %273 = llvm.mlir.addressof @g_num_primes : !llvm.ptr
      llvm.store %272, %273 : i64, !llvm.ptr
      %274 = arith.constant 1 : i32
      %275 = llvm.mlir.addressof @g_prime_idx : !llvm.ptr
      %276 = llvm.load %275 : !llvm.ptr -> !llvm.ptr
      %277 = arith.constant 2 : i32
      %278 = arith.extsi %277 : i32 to i64
      %279 = llvm.getelementptr %276[%278] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      llvm.store %274, %279 : i32, !llvm.ptr
      %280 = arith.constant 4 : i32
      %281 = arith.extsi %280 : i32 to i64
      %282 = llvm.mlir.constant(1 : i64) : i64
      %283 = llvm.alloca %282 x i64 : (i64) -> !llvm.ptr
      llvm.store %281, %283 : i64, !llvm.ptr
      cf.br ^bb51
      ^bb51:
      %284 = llvm.load %283 : !llvm.ptr -> i64
      %285 = arith.cmpi sle, %284, %arg0 : i64
      cf.cond_br %285, ^bb52, ^bb53
      ^bb52:
        %286 = arith.constant 2 : i32
        %287 = llvm.mlir.addressof @g_spf : !llvm.ptr
        %288 = llvm.load %287 : !llvm.ptr -> !llvm.ptr
        %289 = llvm.load %283 : !llvm.ptr -> i64
        %290 = llvm.getelementptr %288[%289] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %286, %290 : i32, !llvm.ptr
        %291 = llvm.load %283 : !llvm.ptr -> i64
        %292 = arith.constant 2 : i32
        %294 = arith.extsi %292 : i32 to i64
        %293 = arith.addi %291, %294 : i64
        llvm.store %293, %283 : i64, !llvm.ptr
        cf.br ^bb51
      ^bb53:
      cf.br ^bb50
    ^bb49:
      cf.br ^bb50
    ^bb50:
    %295 = func.call @isqrt(%arg0) : (i64) -> i64
    %296 = arith.constant 3 : i32
    %297 = arith.extsi %296 : i32 to i64
    %298 = llvm.mlir.constant(1 : i64) : i64
    %299 = llvm.alloca %298 x i64 : (i64) -> !llvm.ptr
    llvm.store %297, %299 : i64, !llvm.ptr
    cf.br ^bb54
    ^bb54:
    %300 = llvm.load %299 : !llvm.ptr -> i64
    %301 = arith.cmpi sle, %300, %arg0 : i64
    cf.cond_br %301, ^bb55, ^bb56
    ^bb55:
      %303 = llvm.mlir.addressof @g_spf : !llvm.ptr
      %304 = llvm.load %303 : !llvm.ptr -> !llvm.ptr
      %305 = llvm.load %299 : !llvm.ptr -> i64
      %306 = llvm.getelementptr %304[%305] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %302 = llvm.load %306 : !llvm.ptr -> i32
      %307 = arith.constant 0 : i32
      %308 = arith.cmpi eq, %302, %307 : i32
      cf.cond_br %308, ^bb57, ^bb58
      ^bb57:
        %309 = llvm.load %299 : !llvm.ptr -> i64
        %310 = arith.trunci %309 : i64 to i32
        %311 = llvm.mlir.addressof @g_spf : !llvm.ptr
        %312 = llvm.load %311 : !llvm.ptr -> !llvm.ptr
        %313 = llvm.load %299 : !llvm.ptr -> i64
        %314 = llvm.getelementptr %312[%313] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %310, %314 : i32, !llvm.ptr
        %315 = llvm.load %299 : !llvm.ptr -> i64
        %316 = arith.trunci %315 : i64 to i32
        %317 = llvm.mlir.addressof @g_primes : !llvm.ptr
        %318 = llvm.load %317 : !llvm.ptr -> !llvm.ptr
        %319 = llvm.mlir.addressof @g_num_primes : !llvm.ptr
        %320 = llvm.load %319 : !llvm.ptr -> i64
        %321 = llvm.getelementptr %318[%320] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %316, %321 : i32, !llvm.ptr
        %322 = llvm.mlir.addressof @g_num_primes : !llvm.ptr
        %323 = llvm.load %322 : !llvm.ptr -> i64
        %324 = arith.constant 1 : i32
        %326 = arith.extsi %324 : i32 to i64
        %325 = arith.addi %323, %326 : i64
        %327 = llvm.mlir.addressof @g_num_primes : !llvm.ptr
        llvm.store %325, %327 : i64, !llvm.ptr
        %328 = llvm.mlir.addressof @g_num_primes : !llvm.ptr
        %329 = llvm.load %328 : !llvm.ptr -> i64
        %330 = arith.trunci %329 : i64 to i32
        %331 = llvm.mlir.addressof @g_prime_idx : !llvm.ptr
        %332 = llvm.load %331 : !llvm.ptr -> !llvm.ptr
        %333 = llvm.load %299 : !llvm.ptr -> i64
        %334 = llvm.getelementptr %332[%333] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %330, %334 : i32, !llvm.ptr
        %335 = llvm.load %299 : !llvm.ptr -> i64
        %336 = arith.cmpi sle, %335, %295 : i64
        cf.cond_br %336, ^bb60, ^bb61
        ^bb60:
          %337 = arith.constant 2 : i32
          %338 = llvm.load %299 : !llvm.ptr -> i64
          %340 = arith.extsi %337 : i32 to i64
          %339 = arith.muli %340, %338 : i64
          %341 = llvm.load %299 : !llvm.ptr -> i64
          %342 = llvm.load %299 : !llvm.ptr -> i64
          %343 = arith.muli %341, %342 : 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 ^bb63
          ^bb63:
          %346 = llvm.load %345 : !llvm.ptr -> i64
          %347 = arith.cmpi sle, %346, %arg0 : i64
          cf.cond_br %347, ^bb64, ^bb65
          ^bb64:
            %349 = llvm.mlir.addressof @g_spf : !llvm.ptr
            %350 = llvm.load %349 : !llvm.ptr -> !llvm.ptr
            %351 = llvm.load %345 : !llvm.ptr -> i64
            %352 = llvm.getelementptr %350[%351] : (!llvm.ptr, i64) -> !llvm.ptr, i32
            %348 = llvm.load %352 : !llvm.ptr -> i32
            %353 = arith.constant 0 : i32
            %354 = arith.cmpi eq, %348, %353 : i32
            cf.cond_br %354, ^bb66, ^bb67
            ^bb66:
              %355 = llvm.load %299 : !llvm.ptr -> i64
              %356 = arith.trunci %355 : i64 to i32
              %357 = llvm.mlir.addressof @g_spf : !llvm.ptr
              %358 = llvm.load %357 : !llvm.ptr -> !llvm.ptr
              %359 = llvm.load %345 : !llvm.ptr -> i64
              %360 = llvm.getelementptr %358[%359] : (!llvm.ptr, i64) -> !llvm.ptr, i32
              llvm.store %356, %360 : i32, !llvm.ptr
              cf.br ^bb68
            ^bb67:
              cf.br ^bb68
            ^bb68:
            %361 = llvm.load %345 : !llvm.ptr -> i64
            %362 = arith.addi %361, %339 : i64
            llvm.store %362, %345 : i64, !llvm.ptr
            cf.br ^bb63
          ^bb65:
          cf.br ^bb62
        ^bb61:
          cf.br ^bb62
        ^bb62:
        cf.br ^bb59
      ^bb58:
        cf.br ^bb59
      ^bb59:
      %363 = llvm.load %299 : !llvm.ptr -> i64
      %364 = arith.constant 2 : i32
      %366 = arith.extsi %364 : i32 to i64
      %365 = arith.addi %363, %366 : i64
      llvm.store %365, %299 : i64, !llvm.ptr
      cf.br ^bb54
    ^bb56:
    func.return
  }
  func.func @inverses_upto(%arg0: i64) -> !llvm.ptr {
    %368 = arith.constant 1 : i32
    %370 = arith.extsi %368 : i32 to i64
    %369 = arith.addi %arg0, %370 : i64
    %371 = arith.constant 8 : i32
    %372 = arith.extsi %371 : i32 to i64
    %367 = func.call @calloc(%369, %372) : (i64, i64) -> !llvm.ptr
    %373 = arith.constant 1 : i32
    %374 = arith.constant 1 : i32
    %375 = arith.extsi %373 : i32 to i64
    %376 = arith.extsi %374 : i32 to i64
    %377 = llvm.getelementptr %367[%376] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %375, %377 : i64, !llvm.ptr
    %378 = arith.constant 2 : i32
    %379 = arith.extsi %378 : i32 to i64
    %380 = llvm.mlir.constant(1 : i64) : i64
    %381 = llvm.alloca %380 x i64 : (i64) -> !llvm.ptr
    llvm.store %379, %381 : i64, !llvm.ptr
    cf.br ^bb69
    ^bb69:
    %382 = llvm.load %381 : !llvm.ptr -> i64
    %383 = arith.cmpi sle, %382, %arg0 : i64
    cf.cond_br %383, ^bb70, ^bb71
    ^bb70:
      %384 = llvm.mlir.addressof @MOD : !llvm.ptr
      %385 = llvm.load %384 : !llvm.ptr -> i64
      %386 = llvm.mlir.addressof @MOD : !llvm.ptr
      %387 = llvm.load %386 : !llvm.ptr -> i64
      %388 = llvm.load %381 : !llvm.ptr -> i64
      %389 = arith.divsi %387, %388 : i64
      %391 = llvm.mlir.addressof @MOD : !llvm.ptr
      %392 = llvm.load %391 : !llvm.ptr -> i64
      %393 = llvm.load %381 : !llvm.ptr -> i64
      %394 = arith.remsi %392, %393 : i64
      %395 = llvm.getelementptr %367[%394] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %390 = llvm.load %395 : !llvm.ptr -> i64
      %396 = arith.muli %389, %390 : i64
      %397 = llvm.mlir.addressof @MOD : !llvm.ptr
      %398 = llvm.load %397 : !llvm.ptr -> i64
      %399 = arith.remsi %396, %398 : i64
      %400 = arith.subi %385, %399 : i64
      %401 = llvm.load %381 : !llvm.ptr -> i64
      %402 = llvm.getelementptr %367[%401] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %400, %402 : i64, !llvm.ptr
      %403 = llvm.load %381 : !llvm.ptr -> i64
      %404 = arith.constant 1 : i32
      %406 = arith.extsi %404 : i32 to i64
      %405 = arith.addi %403, %406 : i64
      llvm.store %405, %381 : i64, !llvm.ptr
      cf.br ^bb69
    ^bb71:
    func.return %367 : !llvm.ptr
  }
  func.func @batch_inverse(%arg0: !llvm.ptr, %arg1: i64, %arg2: !llvm.ptr, %arg3: i64) -> () {
    %408 = arith.constant 8 : i32
    %409 = arith.extsi %408 : i32 to i64
    %407 = func.call @calloc(%arg1, %409) : (i64, i64) -> !llvm.ptr
    %411 = arith.constant 8 : i32
    %412 = arith.extsi %411 : i32 to i64
    %410 = func.call @calloc(%arg1, %412) : (i64, i64) -> !llvm.ptr
    %413 = arith.constant 0 : i32
    %414 = arith.extsi %413 : i32 to i64
    %415 = llvm.mlir.constant(1 : i64) : i64
    %416 = llvm.alloca %415 x i64 : (i64) -> !llvm.ptr
    llvm.store %414, %416 : i64, !llvm.ptr
    %417 = arith.constant 1 : i32
    %418 = arith.extsi %417 : i32 to i64
    %419 = llvm.mlir.constant(1 : i64) : i64
    %420 = llvm.alloca %419 x i64 : (i64) -> !llvm.ptr
    llvm.store %418, %420 : i64, !llvm.ptr
    %421 = arith.constant 0 : i32
    %422 = arith.extsi %421 : i32 to i64
    %423 = llvm.mlir.constant(1 : i64) : i64
    %424 = llvm.alloca %423 x i64 : (i64) -> !llvm.ptr
    llvm.store %422, %424 : i64, !llvm.ptr
    cf.br ^bb72
    ^bb72:
    %425 = llvm.load %424 : !llvm.ptr -> i64
    %426 = arith.cmpi slt, %425, %arg1 : i64
    cf.cond_br %426, ^bb73, ^bb74
    ^bb73:
      %428 = llvm.load %424 : !llvm.ptr -> i64
      %429 = llvm.getelementptr %arg0[%428] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %427 = llvm.load %429 : !llvm.ptr -> i64
      %430 = arith.constant 0 : i32
      %432 = arith.extsi %430 : i32 to i64
      %431 = arith.cmpi ne, %427, %432 : i64
      cf.cond_br %431, ^bb75, ^bb76
      ^bb75:
        %433 = llvm.load %420 : !llvm.ptr -> i64
        %435 = llvm.load %424 : !llvm.ptr -> i64
        %436 = llvm.getelementptr %arg0[%435] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %434 = llvm.load %436 : !llvm.ptr -> i64
        %437 = arith.muli %433, %434 : i64
        %438 = llvm.mlir.addressof @MOD : !llvm.ptr
        %439 = llvm.load %438 : !llvm.ptr -> i64
        %440 = arith.remsi %437, %439 : i64
        llvm.store %440, %420 : i64, !llvm.ptr
        %441 = llvm.load %424 : !llvm.ptr -> i64
        %442 = llvm.load %416 : !llvm.ptr -> i64
        %443 = llvm.getelementptr %407[%442] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %441, %443 : i64, !llvm.ptr
        %444 = llvm.load %420 : !llvm.ptr -> i64
        %445 = llvm.load %416 : !llvm.ptr -> i64
        %446 = llvm.getelementptr %410[%445] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %444, %446 : i64, !llvm.ptr
        %447 = llvm.load %416 : !llvm.ptr -> i64
        %448 = arith.constant 1 : i32
        %450 = arith.extsi %448 : i32 to i64
        %449 = arith.addi %447, %450 : i64
        llvm.store %449, %416 : i64, !llvm.ptr
        cf.br ^bb77
      ^bb76:
        cf.br ^bb77
      ^bb77:
      %451 = llvm.load %424 : !llvm.ptr -> i64
      %452 = arith.constant 1 : i32
      %454 = arith.extsi %452 : i32 to i64
      %453 = arith.addi %451, %454 : i64
      llvm.store %453, %424 : i64, !llvm.ptr
      cf.br ^bb72
    ^bb74:
    %455 = llvm.load %416 : !llvm.ptr -> i64
    %456 = arith.constant 0 : i32
    %458 = arith.extsi %456 : i32 to i64
    %457 = arith.cmpi eq, %455, %458 : i64
    cf.cond_br %457, ^bb78, ^bb79
    ^bb78:
      func.call @free(%407) : (!llvm.ptr) -> ()
      func.call @free(%410) : (!llvm.ptr) -> ()
      func.return
    ^bb79:
      cf.br ^bb80
    ^bb80:
    %462 = llvm.load %420 : !llvm.ptr -> i64
    %463 = llvm.mlir.addressof @MOD : !llvm.ptr
    %464 = llvm.load %463 : !llvm.ptr -> i64
    %465 = arith.constant 2 : i32
    %467 = arith.extsi %465 : i32 to i64
    %466 = arith.subi %464, %467 : i64
    %461 = func.call @modpow(%462, %466) : (i64, i64) -> i64
    %468 = llvm.mlir.constant(1 : i64) : i64
    %469 = llvm.alloca %468 x i64 : (i64) -> !llvm.ptr
    llvm.store %461, %469 : i64, !llvm.ptr
    %470 = llvm.load %416 : !llvm.ptr -> i64
    %471 = arith.constant 1 : i32
    %473 = arith.extsi %471 : i32 to i64
    %472 = arith.subi %470, %473 : i64
    %474 = llvm.mlir.constant(1 : i64) : i64
    %475 = llvm.alloca %474 x i64 : (i64) -> !llvm.ptr
    llvm.store %472, %475 : i64, !llvm.ptr
    cf.br ^bb81
    ^bb81:
    %476 = llvm.load %475 : !llvm.ptr -> i64
    %477 = arith.constant 0 : i32
    %479 = arith.extsi %477 : i32 to i64
    %478 = arith.cmpi sge, %476, %479 : i64
    cf.cond_br %478, ^bb82, ^bb83
    ^bb82:
      %481 = llvm.load %475 : !llvm.ptr -> i64
      %482 = llvm.getelementptr %407[%481] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %480 = llvm.load %482 : !llvm.ptr -> i64
      %483 = llvm.load %475 : !llvm.ptr -> i64
      %484 = arith.constant 0 : i32
      %486 = arith.extsi %484 : i32 to i64
      %485 = arith.cmpi sgt, %483, %486 : i64
      %487 = scf.if %485 -> (i64) {
        %489 = llvm.load %475 : !llvm.ptr -> i64
        %490 = arith.constant 1 : i32
        %492 = arith.extsi %490 : i32 to i64
        %491 = arith.subi %489, %492 : i64
        %493 = llvm.getelementptr %410[%491] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %488 = llvm.load %493 : !llvm.ptr -> i64
        scf.yield %488 : i64
      } else {
        %494 = arith.constant 1 : i32
        scf.yield %494 : i32
      }
      %495 = llvm.load %469 : !llvm.ptr -> i64
      %496 = arith.muli %495, %487 : i64
      %497 = llvm.mlir.addressof @MOD : !llvm.ptr
      %498 = llvm.load %497 : !llvm.ptr -> i64
      %499 = arith.remsi %496, %498 : i64
      %500 = arith.addi %arg3, %480 : i64
      %501 = llvm.getelementptr %arg2[%500] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %499, %501 : i64, !llvm.ptr
      %502 = llvm.load %469 : !llvm.ptr -> i64
      %504 = llvm.getelementptr %arg0[%480] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %503 = llvm.load %504 : !llvm.ptr -> i64
      %505 = arith.muli %502, %503 : i64
      %506 = llvm.mlir.addressof @MOD : !llvm.ptr
      %507 = llvm.load %506 : !llvm.ptr -> i64
      %508 = arith.remsi %505, %507 : i64
      llvm.store %508, %469 : i64, !llvm.ptr
      %509 = llvm.load %475 : !llvm.ptr -> i64
      %510 = arith.constant 1 : i32
      %512 = arith.extsi %510 : i32 to i64
      %511 = arith.subi %509, %512 : i64
      llvm.store %511, %475 : i64, !llvm.ptr
      cf.br ^bb81
    ^bb83:
    func.call @free(%407) : (!llvm.ptr) -> ()
    func.call @free(%410) : (!llvm.ptr) -> ()
    func.return
  }
  // Module static: g_exp
  llvm.mlir.global internal @g_exp() {addr_space = 0 : i32} : !llvm.ptr {
    %515 = llvm.mlir.zero : !llvm.ptr
    llvm.return %515 : !llvm.ptr
  }
  // Module static: g_p_pow
  llvm.mlir.global internal @g_p_pow() {addr_space = 0 : i32} : !llvm.ptr {
    %516 = llvm.mlir.zero : !llvm.ptr
    llvm.return %516 : !llvm.ptr
  }
  // Module static: g_inv_terms
  llvm.mlir.global internal @g_inv_terms() {addr_space = 0 : i32} : !llvm.ptr {
    %517 = llvm.mlir.zero : !llvm.ptr
    llvm.return %517 : !llvm.ptr
  }
  // Module static: g_offset
  llvm.mlir.global internal @g_offset() {addr_space = 0 : i32} : !llvm.ptr {
    %518 = llvm.mlir.zero : !llvm.ptr
    llvm.return %518 : !llvm.ptr
  }
  // Module static: g_inv_num
  llvm.mlir.global internal @g_inv_num() {addr_space = 0 : i32} : !llvm.ptr {
    %519 = llvm.mlir.zero : !llvm.ptr
    llvm.return %519 : !llvm.ptr
  }
  // Module static: g_prod
  llvm.mlir.global internal @g_prod(1 : i64) : i64
  // Module static: g_zero_count
  llvm.mlir.global internal @g_zero_count(0 : i64) : i64
  func.func @apply_factor(%arg0: i64, %arg1: i64) -> () {
    %520 = llvm.mlir.constant(1 : i64) : i64
    %521 = llvm.alloca %520 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %521 : i64, !llvm.ptr
    cf.br ^bb84
    ^bb84:
    %522 = llvm.load %521 : !llvm.ptr -> i64
    %523 = arith.constant 1 : i32
    %525 = arith.extsi %523 : i32 to i64
    %524 = arith.cmpi sgt, %522, %525 : i64
    cf.cond_br %524, ^bb85, ^bb86
    ^bb85:
      %527 = llvm.mlir.addressof @g_spf : !llvm.ptr
      %528 = llvm.load %527 : !llvm.ptr -> !llvm.ptr
      %529 = llvm.load %521 : !llvm.ptr -> i64
      %530 = llvm.getelementptr %528[%529] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %526 = llvm.load %530 : !llvm.ptr -> i32
      %531 = arith.extsi %526 : i32 to i64
      %533 = llvm.mlir.addressof @g_prime_idx : !llvm.ptr
      %534 = llvm.load %533 : !llvm.ptr -> !llvm.ptr
      %535 = llvm.getelementptr %534[%531] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %532 = llvm.load %535 : !llvm.ptr -> i32
      %536 = arith.extsi %532 : i32 to i64
      %537 = arith.constant 1 : i32
      %539 = arith.extsi %537 : i32 to i64
      %538 = arith.subi %536, %539 : i64
      %540 = arith.constant 0 : i32
      %541 = arith.extsi %540 : i32 to i64
      %542 = llvm.mlir.constant(1 : i64) : i64
      %543 = llvm.alloca %542 x i64 : (i64) -> !llvm.ptr
      llvm.store %541, %543 : i64, !llvm.ptr
      cf.br ^bb87
      ^bb87:
      %544 = llvm.load %521 : !llvm.ptr -> i64
      %545 = arith.constant 1 : i32
      %547 = arith.extsi %545 : i32 to i64
      %546 = arith.cmpi sgt, %544, %547 : i64
      %548 = scf.if %546 -> (i1) {
        %550 = llvm.mlir.addressof @g_spf : !llvm.ptr
        %551 = llvm.load %550 : !llvm.ptr -> !llvm.ptr
        %552 = llvm.load %521 : !llvm.ptr -> i64
        %553 = llvm.getelementptr %551[%552] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %549 = llvm.load %553 : !llvm.ptr -> i32
        %554 = arith.extsi %549 : i32 to i64
        %555 = arith.cmpi eq, %554, %531 : i64
        scf.yield %555 : i1
      } else {
        %556 = arith.constant false
        scf.yield %556 : i1
      }
      cf.cond_br %548, ^bb88, ^bb89
      ^bb88:
        %557 = llvm.load %521 : !llvm.ptr -> i64
        %558 = arith.divsi %557, %531 : i64
        llvm.store %558, %521 : i64, !llvm.ptr
        %559 = llvm.load %543 : !llvm.ptr -> i64
        %560 = arith.constant 1 : i32
        %562 = arith.extsi %560 : i32 to i64
        %561 = arith.addi %559, %562 : i64
        llvm.store %561, %543 : i64, !llvm.ptr
        cf.br ^bb87
      ^bb89:
      %564 = llvm.mlir.addressof @g_exp : !llvm.ptr
      %565 = llvm.load %564 : !llvm.ptr -> !llvm.ptr
      %566 = llvm.getelementptr %565[%538] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %563 = llvm.load %566 : !llvm.ptr -> i64
      %567 = arith.constant 0 : i32
      %569 = arith.extsi %567 : i32 to i64
      %568 = arith.cmpi sgt, %arg1, %569 : i64
      cf.cond_br %568, ^bb90, ^bb91
      ^bb90:
        %570 = arith.constant 0 : i32
        %572 = arith.extsi %570 : i32 to i64
        %571 = arith.cmpi ne, %563, %572 : i64
        cf.cond_br %571, ^bb93, ^bb94
        ^bb93:
          %574 = llvm.mlir.addressof @g_p_pow : !llvm.ptr
          %575 = llvm.load %574 : !llvm.ptr -> !llvm.ptr
          %576 = llvm.getelementptr %575[%538] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %573 = llvm.load %576 : !llvm.ptr -> i64
          %577 = arith.constant 1 : i32
          %579 = arith.extsi %577 : i32 to i64
          %578 = arith.addi %573, %579 : i64
          %580 = llvm.mlir.constant(1 : i64) : i64
          %581 = llvm.alloca %580 x i64 : (i64) -> !llvm.ptr
          llvm.store %578, %581 : i64, !llvm.ptr
          %582 = llvm.load %581 : !llvm.ptr -> i64
          %583 = llvm.mlir.addressof @MOD : !llvm.ptr
          %584 = llvm.load %583 : !llvm.ptr -> i64
          %585 = arith.cmpi eq, %582, %584 : i64
          cf.cond_br %585, ^bb96, ^bb97
          ^bb96:
            %586 = arith.constant 0 : i32
            %587 = arith.extsi %586 : i32 to i64
            llvm.store %587, %581 : i64, !llvm.ptr
            cf.br ^bb98
          ^bb97:
            cf.br ^bb98
          ^bb98:
          %588 = llvm.load %581 : !llvm.ptr -> i64
          %589 = arith.constant 0 : i32
          %591 = arith.extsi %589 : i32 to i64
          %590 = arith.cmpi ne, %588, %591 : i64
          cf.cond_br %590, ^bb99, ^bb100
          ^bb99:
            %592 = llvm.mlir.addressof @g_prod : !llvm.ptr
            %593 = llvm.load %592 : !llvm.ptr -> i64
            %595 = llvm.mlir.addressof @g_inv_terms : !llvm.ptr
            %596 = llvm.load %595 : !llvm.ptr -> !llvm.ptr
            %598 = llvm.mlir.addressof @g_offset : !llvm.ptr
            %599 = llvm.load %598 : !llvm.ptr -> !llvm.ptr
            %600 = llvm.getelementptr %599[%538] : (!llvm.ptr, i64) -> !llvm.ptr, i64
            %597 = llvm.load %600 : !llvm.ptr -> i64
            %601 = arith.addi %597, %563 : i64
            %602 = arith.constant 1 : i32
            %604 = arith.extsi %602 : i32 to i64
            %603 = arith.subi %601, %604 : i64
            %605 = llvm.getelementptr %596[%603] : (!llvm.ptr, i64) -> !llvm.ptr, i64
            %594 = llvm.load %605 : !llvm.ptr -> i64
            %606 = arith.muli %593, %594 : i64
            %607 = llvm.mlir.addressof @MOD : !llvm.ptr
            %608 = llvm.load %607 : !llvm.ptr -> i64
            %609 = arith.remsi %606, %608 : i64
            %610 = llvm.mlir.addressof @g_prod : !llvm.ptr
            llvm.store %609, %610 : i64, !llvm.ptr
            cf.br ^bb101
          ^bb100:
            %611 = llvm.mlir.addressof @g_zero_count : !llvm.ptr
            %612 = llvm.load %611 : !llvm.ptr -> i64
            %613 = arith.constant 1 : i32
            %615 = arith.extsi %613 : i32 to i64
            %614 = arith.subi %612, %615 : i64
            %616 = llvm.mlir.addressof @g_zero_count : !llvm.ptr
            llvm.store %614, %616 : i64, !llvm.ptr
            cf.br ^bb101
          ^bb101:
          cf.br ^bb95
        ^bb94:
          cf.br ^bb95
        ^bb95:
        %617 = llvm.load %543 : !llvm.ptr -> i64
        %618 = arith.addi %563, %617 : i64
        %619 = llvm.mlir.addressof @g_exp : !llvm.ptr
        %620 = llvm.load %619 : !llvm.ptr -> !llvm.ptr
        %621 = llvm.getelementptr %620[%538] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %618, %621 : i64, !llvm.ptr
        %622 = llvm.load %543 : !llvm.ptr -> i64
        %623 = arith.constant 1 : i32
        %625 = arith.extsi %623 : i32 to i64
        %624 = arith.cmpi eq, %622, %625 : i64
        cf.cond_br %624, ^bb102, ^bb103
        ^bb102:
          %627 = llvm.mlir.addressof @g_p_pow : !llvm.ptr
          %628 = llvm.load %627 : !llvm.ptr -> !llvm.ptr
          %629 = llvm.getelementptr %628[%538] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %626 = llvm.load %629 : !llvm.ptr -> i64
          %630 = arith.muli %626, %531 : i64
          %631 = llvm.mlir.addressof @MOD : !llvm.ptr
          %632 = llvm.load %631 : !llvm.ptr -> i64
          %633 = arith.remsi %630, %632 : i64
          %634 = llvm.mlir.addressof @g_p_pow : !llvm.ptr
          %635 = llvm.load %634 : !llvm.ptr -> !llvm.ptr
          %636 = llvm.getelementptr %635[%538] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          llvm.store %633, %636 : i64, !llvm.ptr
          cf.br ^bb104
        ^bb103:
          %637 = llvm.load %543 : !llvm.ptr -> i64
          %638 = arith.constant 2 : i32
          %640 = arith.extsi %638 : i32 to i64
          %639 = arith.cmpi eq, %637, %640 : i64
          cf.cond_br %639, ^bb105, ^bb106
          ^bb105:
            %642 = llvm.mlir.addressof @g_p_pow : !llvm.ptr
            %643 = llvm.load %642 : !llvm.ptr -> !llvm.ptr
            %644 = llvm.getelementptr %643[%538] : (!llvm.ptr, i64) -> !llvm.ptr, i64
            %641 = llvm.load %644 : !llvm.ptr -> i64
            %645 = arith.muli %641, %531 : i64
            %646 = llvm.mlir.addressof @MOD : !llvm.ptr
            %647 = llvm.load %646 : !llvm.ptr -> i64
            %648 = arith.remsi %645, %647 : i64
            %649 = arith.muli %648, %531 : i64
            %650 = llvm.mlir.addressof @MOD : !llvm.ptr
            %651 = llvm.load %650 : !llvm.ptr -> i64
            %652 = arith.remsi %649, %651 : i64
            %653 = llvm.mlir.addressof @g_p_pow : !llvm.ptr
            %654 = llvm.load %653 : !llvm.ptr -> !llvm.ptr
            %655 = llvm.getelementptr %654[%538] : (!llvm.ptr, i64) -> !llvm.ptr, i64
            llvm.store %652, %655 : i64, !llvm.ptr
            cf.br ^bb107
          ^bb106:
            %657 = llvm.mlir.addressof @g_p_pow : !llvm.ptr
            %658 = llvm.load %657 : !llvm.ptr -> !llvm.ptr
            %659 = llvm.getelementptr %658[%538] : (!llvm.ptr, i64) -> !llvm.ptr, i64
            %656 = llvm.load %659 : !llvm.ptr -> i64
            %661 = llvm.load %543 : !llvm.ptr -> i64
            %660 = func.call @modpow(%531, %661) : (i64, i64) -> i64
            %662 = arith.muli %656, %660 : i64
            %663 = llvm.mlir.addressof @MOD : !llvm.ptr
            %664 = llvm.load %663 : !llvm.ptr -> i64
            %665 = arith.remsi %662, %664 : i64
            %666 = llvm.mlir.addressof @g_p_pow : !llvm.ptr
            %667 = llvm.load %666 : !llvm.ptr -> !llvm.ptr
            %668 = llvm.getelementptr %667[%538] : (!llvm.ptr, i64) -> !llvm.ptr, i64
            llvm.store %665, %668 : i64, !llvm.ptr
            cf.br ^bb107
          ^bb107:
          cf.br ^bb104
        ^bb104:
        %670 = llvm.mlir.addressof @g_p_pow : !llvm.ptr
        %671 = llvm.load %670 : !llvm.ptr -> !llvm.ptr
        %672 = llvm.getelementptr %671[%538] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %669 = llvm.load %672 : !llvm.ptr -> i64
        %673 = arith.constant 1 : i32
        %675 = arith.extsi %673 : i32 to i64
        %674 = arith.addi %669, %675 : i64
        %676 = llvm.mlir.constant(1 : i64) : i64
        %677 = llvm.alloca %676 x i64 : (i64) -> !llvm.ptr
        llvm.store %674, %677 : i64, !llvm.ptr
        %678 = llvm.load %677 : !llvm.ptr -> i64
        %679 = llvm.mlir.addressof @MOD : !llvm.ptr
        %680 = llvm.load %679 : !llvm.ptr -> i64
        %681 = arith.cmpi eq, %678, %680 : i64
        cf.cond_br %681, ^bb108, ^bb109
        ^bb108:
          %682 = arith.constant 0 : i32
          %683 = arith.extsi %682 : i32 to i64
          llvm.store %683, %677 : i64, !llvm.ptr
          cf.br ^bb110
        ^bb109:
          cf.br ^bb110
        ^bb110:
        %684 = llvm.load %677 : !llvm.ptr -> i64
        %685 = arith.constant 0 : i32
        %687 = arith.extsi %685 : i32 to i64
        %686 = arith.cmpi ne, %684, %687 : i64
        cf.cond_br %686, ^bb111, ^bb112
        ^bb111:
          %688 = llvm.mlir.addressof @g_prod : !llvm.ptr
          %689 = llvm.load %688 : !llvm.ptr -> i64
          %690 = llvm.load %677 : !llvm.ptr -> i64
          %691 = arith.muli %689, %690 : i64
          %692 = llvm.mlir.addressof @MOD : !llvm.ptr
          %693 = llvm.load %692 : !llvm.ptr -> i64
          %694 = arith.remsi %691, %693 : i64
          %695 = llvm.mlir.addressof @g_prod : !llvm.ptr
          llvm.store %694, %695 : i64, !llvm.ptr
          cf.br ^bb113
        ^bb112:
          %696 = llvm.mlir.addressof @g_zero_count : !llvm.ptr
          %697 = llvm.load %696 : !llvm.ptr -> i64
          %698 = arith.constant 1 : i32
          %700 = arith.extsi %698 : i32 to i64
          %699 = arith.addi %697, %700 : i64
          %701 = llvm.mlir.addressof @g_zero_count : !llvm.ptr
          llvm.store %699, %701 : i64, !llvm.ptr
          cf.br ^bb113
        ^bb113:
        cf.br ^bb92
      ^bb91:
        %703 = llvm.mlir.addressof @g_p_pow : !llvm.ptr
        %704 = llvm.load %703 : !llvm.ptr -> !llvm.ptr
        %705 = llvm.getelementptr %704[%538] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %702 = llvm.load %705 : !llvm.ptr -> i64
        %706 = arith.constant 1 : i32
        %708 = arith.extsi %706 : i32 to i64
        %707 = arith.addi %702, %708 : i64
        %709 = llvm.mlir.constant(1 : i64) : i64
        %710 = llvm.alloca %709 x i64 : (i64) -> !llvm.ptr
        llvm.store %707, %710 : i64, !llvm.ptr
        %711 = llvm.load %710 : !llvm.ptr -> i64
        %712 = llvm.mlir.addressof @MOD : !llvm.ptr
        %713 = llvm.load %712 : !llvm.ptr -> i64
        %714 = arith.cmpi eq, %711, %713 : i64
        cf.cond_br %714, ^bb114, ^bb115
        ^bb114:
          %715 = arith.constant 0 : i32
          %716 = arith.extsi %715 : i32 to i64
          llvm.store %716, %710 : i64, !llvm.ptr
          cf.br ^bb116
        ^bb115:
          cf.br ^bb116
        ^bb116:
        %717 = llvm.load %710 : !llvm.ptr -> i64
        %718 = arith.constant 0 : i32
        %720 = arith.extsi %718 : i32 to i64
        %719 = arith.cmpi ne, %717, %720 : i64
        cf.cond_br %719, ^bb117, ^bb118
        ^bb117:
          %721 = llvm.mlir.addressof @g_prod : !llvm.ptr
          %722 = llvm.load %721 : !llvm.ptr -> i64
          %724 = llvm.mlir.addressof @g_inv_terms : !llvm.ptr
          %725 = llvm.load %724 : !llvm.ptr -> !llvm.ptr
          %727 = llvm.mlir.addressof @g_offset : !llvm.ptr
          %728 = llvm.load %727 : !llvm.ptr -> !llvm.ptr
          %729 = llvm.getelementptr %728[%538] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %726 = llvm.load %729 : !llvm.ptr -> i64
          %730 = arith.addi %726, %563 : i64
          %731 = arith.constant 1 : i32
          %733 = arith.extsi %731 : i32 to i64
          %732 = arith.subi %730, %733 : i64
          %734 = llvm.getelementptr %725[%732] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %723 = llvm.load %734 : !llvm.ptr -> i64
          %735 = arith.muli %722, %723 : i64
          %736 = llvm.mlir.addressof @MOD : !llvm.ptr
          %737 = llvm.load %736 : !llvm.ptr -> i64
          %738 = arith.remsi %735, %737 : i64
          %739 = llvm.mlir.addressof @g_prod : !llvm.ptr
          llvm.store %738, %739 : i64, !llvm.ptr
          cf.br ^bb119
        ^bb118:
          %740 = llvm.mlir.addressof @g_zero_count : !llvm.ptr
          %741 = llvm.load %740 : !llvm.ptr -> i64
          %742 = arith.constant 1 : i32
          %744 = arith.extsi %742 : i32 to i64
          %743 = arith.subi %741, %744 : i64
          %745 = llvm.mlir.addressof @g_zero_count : !llvm.ptr
          llvm.store %743, %745 : i64, !llvm.ptr
          cf.br ^bb119
        ^bb119:
        %746 = llvm.load %543 : !llvm.ptr -> i64
        %747 = arith.subi %563, %746 : i64
        %748 = llvm.mlir.addressof @g_exp : !llvm.ptr
        %749 = llvm.load %748 : !llvm.ptr -> !llvm.ptr
        %750 = llvm.getelementptr %749[%538] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %747, %750 : i64, !llvm.ptr
        %752 = llvm.mlir.addressof @g_inv_num : !llvm.ptr
        %753 = llvm.load %752 : !llvm.ptr -> !llvm.ptr
        %754 = llvm.getelementptr %753[%531] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %751 = llvm.load %754 : !llvm.ptr -> i64
        %755 = llvm.load %543 : !llvm.ptr -> i64
        %756 = arith.constant 1 : i32
        %758 = arith.extsi %756 : i32 to i64
        %757 = arith.cmpi eq, %755, %758 : i64
        cf.cond_br %757, ^bb120, ^bb121
        ^bb120:
          %760 = llvm.mlir.addressof @g_p_pow : !llvm.ptr
          %761 = llvm.load %760 : !llvm.ptr -> !llvm.ptr
          %762 = llvm.getelementptr %761[%538] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %759 = llvm.load %762 : !llvm.ptr -> i64
          %763 = arith.muli %759, %751 : i64
          %764 = llvm.mlir.addressof @MOD : !llvm.ptr
          %765 = llvm.load %764 : !llvm.ptr -> i64
          %766 = arith.remsi %763, %765 : i64
          %767 = llvm.mlir.addressof @g_p_pow : !llvm.ptr
          %768 = llvm.load %767 : !llvm.ptr -> !llvm.ptr
          %769 = llvm.getelementptr %768[%538] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          llvm.store %766, %769 : i64, !llvm.ptr
          cf.br ^bb122
        ^bb121:
          %770 = llvm.load %543 : !llvm.ptr -> i64
          %771 = arith.constant 2 : i32
          %773 = arith.extsi %771 : i32 to i64
          %772 = arith.cmpi eq, %770, %773 : i64
          cf.cond_br %772, ^bb123, ^bb124
          ^bb123:
            %775 = llvm.mlir.addressof @g_p_pow : !llvm.ptr
            %776 = llvm.load %775 : !llvm.ptr -> !llvm.ptr
            %777 = llvm.getelementptr %776[%538] : (!llvm.ptr, i64) -> !llvm.ptr, i64
            %774 = llvm.load %777 : !llvm.ptr -> i64
            %778 = arith.muli %774, %751 : i64
            %779 = llvm.mlir.addressof @MOD : !llvm.ptr
            %780 = llvm.load %779 : !llvm.ptr -> i64
            %781 = arith.remsi %778, %780 : i64
            %782 = arith.muli %781, %751 : i64
            %783 = llvm.mlir.addressof @MOD : !llvm.ptr
            %784 = llvm.load %783 : !llvm.ptr -> i64
            %785 = arith.remsi %782, %784 : i64
            %786 = llvm.mlir.addressof @g_p_pow : !llvm.ptr
            %787 = llvm.load %786 : !llvm.ptr -> !llvm.ptr
            %788 = llvm.getelementptr %787[%538] : (!llvm.ptr, i64) -> !llvm.ptr, i64
            llvm.store %785, %788 : i64, !llvm.ptr
            cf.br ^bb125
          ^bb124:
            %790 = llvm.mlir.addressof @g_p_pow : !llvm.ptr
            %791 = llvm.load %790 : !llvm.ptr -> !llvm.ptr
            %792 = llvm.getelementptr %791[%538] : (!llvm.ptr, i64) -> !llvm.ptr, i64
            %789 = llvm.load %792 : !llvm.ptr -> i64
            %794 = llvm.load %543 : !llvm.ptr -> i64
            %793 = func.call @modpow(%751, %794) : (i64, i64) -> i64
            %795 = arith.muli %789, %793 : i64
            %796 = llvm.mlir.addressof @MOD : !llvm.ptr
            %797 = llvm.load %796 : !llvm.ptr -> i64
            %798 = arith.remsi %795, %797 : i64
            %799 = llvm.mlir.addressof @g_p_pow : !llvm.ptr
            %800 = llvm.load %799 : !llvm.ptr -> !llvm.ptr
            %801 = llvm.getelementptr %800[%538] : (!llvm.ptr, i64) -> !llvm.ptr, i64
            llvm.store %798, %801 : i64, !llvm.ptr
            cf.br ^bb125
          ^bb125:
          cf.br ^bb122
        ^bb122:
        %802 = arith.constant 0 : i32
        %804 = arith.extsi %802 : i32 to i64
        %803 = arith.cmpi ne, %747, %804 : i64
        cf.cond_br %803, ^bb126, ^bb127
        ^bb126:
          %806 = llvm.mlir.addressof @g_p_pow : !llvm.ptr
          %807 = llvm.load %806 : !llvm.ptr -> !llvm.ptr
          %808 = llvm.getelementptr %807[%538] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %805 = llvm.load %808 : !llvm.ptr -> i64
          %809 = arith.constant 1 : i32
          %811 = arith.extsi %809 : i32 to i64
          %810 = arith.addi %805, %811 : i64
          %812 = llvm.mlir.constant(1 : i64) : i64
          %813 = llvm.alloca %812 x i64 : (i64) -> !llvm.ptr
          llvm.store %810, %813 : i64, !llvm.ptr
          %814 = llvm.load %813 : !llvm.ptr -> i64
          %815 = llvm.mlir.addressof @MOD : !llvm.ptr
          %816 = llvm.load %815 : !llvm.ptr -> i64
          %817 = arith.cmpi eq, %814, %816 : i64
          cf.cond_br %817, ^bb129, ^bb130
          ^bb129:
            %818 = arith.constant 0 : i32
            %819 = arith.extsi %818 : i32 to i64
            llvm.store %819, %813 : i64, !llvm.ptr
            cf.br ^bb131
          ^bb130:
            cf.br ^bb131
          ^bb131:
          %820 = llvm.load %813 : !llvm.ptr -> i64
          %821 = arith.constant 0 : i32
          %823 = arith.extsi %821 : i32 to i64
          %822 = arith.cmpi ne, %820, %823 : i64
          cf.cond_br %822, ^bb132, ^bb133
          ^bb132:
            %824 = llvm.mlir.addressof @g_prod : !llvm.ptr
            %825 = llvm.load %824 : !llvm.ptr -> i64
            %826 = llvm.load %813 : !llvm.ptr -> i64
            %827 = arith.muli %825, %826 : i64
            %828 = llvm.mlir.addressof @MOD : !llvm.ptr
            %829 = llvm.load %828 : !llvm.ptr -> i64
            %830 = arith.remsi %827, %829 : i64
            %831 = llvm.mlir.addressof @g_prod : !llvm.ptr
            llvm.store %830, %831 : i64, !llvm.ptr
            cf.br ^bb134
          ^bb133:
            %832 = llvm.mlir.addressof @g_zero_count : !llvm.ptr
            %833 = llvm.load %832 : !llvm.ptr -> i64
            %834 = arith.constant 1 : i32
            %836 = arith.extsi %834 : i32 to i64
            %835 = arith.addi %833, %836 : i64
            %837 = llvm.mlir.addressof @g_zero_count : !llvm.ptr
            llvm.store %835, %837 : i64, !llvm.ptr
            cf.br ^bb134
          ^bb134:
          cf.br ^bb128
        ^bb127:
          cf.br ^bb128
        ^bb128:
        cf.br ^bb92
      ^bb92:
      cf.br ^bb84
    ^bb86:
    func.return
  }
  func.func @solve(%arg0: i64) -> i64 {
    func.call @sieve_spf(%arg0) : (i64) -> ()
    %839 = func.call @inverses_upto(%arg0) : (i64) -> !llvm.ptr
    %840 = llvm.mlir.addressof @g_inv_num : !llvm.ptr
    llvm.store %839, %840 : !llvm.ptr, !llvm.ptr
    %841 = llvm.mlir.addressof @g_num_primes : !llvm.ptr
    %842 = llvm.load %841 : !llvm.ptr -> i64
    %844 = arith.constant 8 : i32
    %845 = arith.extsi %844 : i32 to i64
    %843 = func.call @calloc(%842, %845) : (i64, i64) -> !llvm.ptr
    %847 = arith.constant 8 : i32
    %848 = arith.extsi %847 : i32 to i64
    %846 = func.call @calloc(%842, %848) : (i64, i64) -> !llvm.ptr
    %849 = arith.constant 0 : i32
    %850 = arith.extsi %849 : i32 to i64
    %851 = llvm.mlir.constant(1 : i64) : i64
    %852 = llvm.alloca %851 x i64 : (i64) -> !llvm.ptr
    llvm.store %850, %852 : i64, !llvm.ptr
    %853 = arith.constant 0 : i32
    %854 = arith.extsi %853 : i32 to i64
    %855 = llvm.mlir.constant(1 : i64) : i64
    %856 = llvm.alloca %855 x i64 : (i64) -> !llvm.ptr
    llvm.store %854, %856 : i64, !llvm.ptr
    cf.br ^bb135
    ^bb135:
    %857 = llvm.load %856 : !llvm.ptr -> i64
    %858 = arith.cmpi slt, %857, %842 : i64
    cf.cond_br %858, ^bb136, ^bb137
    ^bb136:
      %860 = llvm.mlir.addressof @g_primes : !llvm.ptr
      %861 = llvm.load %860 : !llvm.ptr -> !llvm.ptr
      %862 = llvm.load %856 : !llvm.ptr -> i64
      %863 = llvm.getelementptr %861[%862] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %859 = llvm.load %863 : !llvm.ptr -> i32
      %864 = arith.extsi %859 : i32 to i64
      %865 = llvm.mlir.constant(1 : i64) : i64
      %866 = llvm.alloca %865 x i64 : (i64) -> !llvm.ptr
      llvm.store %arg0, %866 : i64, !llvm.ptr
      %867 = arith.constant 0 : i32
      %868 = arith.extsi %867 : i32 to i64
      %869 = llvm.mlir.constant(1 : i64) : i64
      %870 = llvm.alloca %869 x i64 : (i64) -> !llvm.ptr
      llvm.store %868, %870 : i64, !llvm.ptr
      cf.br ^bb138
      ^bb138:
      %871 = llvm.load %866 : !llvm.ptr -> i64
      %872 = arith.constant 0 : i32
      %874 = arith.extsi %872 : i32 to i64
      %873 = arith.cmpi ne, %871, %874 : i64
      cf.cond_br %873, ^bb139, ^bb140
      ^bb139:
        %875 = llvm.load %866 : !llvm.ptr -> i64
        %876 = arith.divsi %875, %864 : i64
        llvm.store %876, %866 : i64, !llvm.ptr
        %877 = llvm.load %870 : !llvm.ptr -> i64
        %878 = llvm.load %866 : !llvm.ptr -> i64
        %879 = arith.addi %877, %878 : i64
        llvm.store %879, %870 : i64, !llvm.ptr
        cf.br ^bb138
      ^bb140:
      %880 = llvm.load %870 : !llvm.ptr -> i64
      %881 = llvm.load %856 : !llvm.ptr -> i64
      %882 = llvm.getelementptr %843[%881] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %880, %882 : i64, !llvm.ptr
      %883 = llvm.load %852 : !llvm.ptr -> i64
      %884 = llvm.load %856 : !llvm.ptr -> i64
      %885 = llvm.getelementptr %846[%884] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %883, %885 : i64, !llvm.ptr
      %886 = llvm.load %852 : !llvm.ptr -> i64
      %887 = llvm.load %870 : !llvm.ptr -> i64
      %888 = arith.addi %886, %887 : i64
      llvm.store %888, %852 : i64, !llvm.ptr
      %889 = llvm.load %856 : !llvm.ptr -> i64
      %890 = arith.constant 1 : i32
      %892 = arith.extsi %890 : i32 to i64
      %891 = arith.addi %889, %892 : i64
      llvm.store %891, %856 : i64, !llvm.ptr
      cf.br ^bb135
    ^bb137:
    %894 = llvm.load %852 : !llvm.ptr -> i64
    %895 = arith.constant 8 : i32
    %896 = arith.extsi %895 : i32 to i64
    %893 = func.call @calloc(%894, %896) : (i64, i64) -> !llvm.ptr
    %897 = llvm.mlir.addressof @g_inv_terms : !llvm.ptr
    llvm.store %893, %897 : !llvm.ptr, !llvm.ptr
    %898 = llvm.mlir.addressof @g_offset : !llvm.ptr
    llvm.store %846, %898 : !llvm.ptr, !llvm.ptr
    %899 = arith.constant 1000000 : i32
    %900 = arith.extsi %899 : i32 to i64
    %902 = arith.constant 8 : i32
    %903 = arith.extsi %902 : i32 to i64
    %901 = func.call @calloc(%900, %903) : (i64, i64) -> !llvm.ptr
    %904 = arith.constant 0 : i32
    %905 = arith.extsi %904 : i32 to i64
    %906 = llvm.mlir.constant(1 : i64) : i64
    %907 = llvm.alloca %906 x i64 : (i64) -> !llvm.ptr
    llvm.store %905, %907 : i64, !llvm.ptr
    %908 = arith.constant 0 : i32
    %909 = arith.extsi %908 : i32 to i64
    %910 = llvm.mlir.constant(1 : i64) : i64
    %911 = llvm.alloca %910 x i64 : (i64) -> !llvm.ptr
    llvm.store %909, %911 : i64, !llvm.ptr
    %912 = arith.constant 0 : i32
    %913 = arith.extsi %912 : i32 to i64
    llvm.store %913, %856 : i64, !llvm.ptr
    cf.br ^bb141
    ^bb141:
    %914 = llvm.load %856 : !llvm.ptr -> i64
    %915 = arith.cmpi slt, %914, %842 : i64
    cf.cond_br %915, ^bb142, ^bb143
    ^bb142:
      %917 = llvm.mlir.addressof @g_primes : !llvm.ptr
      %918 = llvm.load %917 : !llvm.ptr -> !llvm.ptr
      %919 = llvm.load %856 : !llvm.ptr -> i64
      %920 = llvm.getelementptr %918[%919] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %916 = llvm.load %920 : !llvm.ptr -> i32
      %921 = arith.extsi %916 : i32 to i64
      %923 = llvm.load %856 : !llvm.ptr -> i64
      %924 = llvm.getelementptr %843[%923] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %922 = llvm.load %924 : !llvm.ptr -> i64
      %925 = llvm.mlir.addressof @MOD : !llvm.ptr
      %926 = llvm.load %925 : !llvm.ptr -> i64
      %927 = arith.remsi %921, %926 : i64
      %928 = llvm.mlir.constant(1 : i64) : i64
      %929 = llvm.alloca %928 x i64 : (i64) -> !llvm.ptr
      llvm.store %927, %929 : i64, !llvm.ptr
      %930 = arith.constant 0 : i32
      %931 = arith.extsi %930 : i32 to i64
      %932 = llvm.mlir.constant(1 : i64) : i64
      %933 = llvm.alloca %932 x i64 : (i64) -> !llvm.ptr
      llvm.store %931, %933 : i64, !llvm.ptr
      cf.br ^bb144
      ^bb144:
      %934 = llvm.load %933 : !llvm.ptr -> i64
      %935 = arith.cmpi slt, %934, %922 : i64
      cf.cond_br %935, ^bb145, ^bb146
      ^bb145:
        %936 = llvm.load %929 : !llvm.ptr -> i64
        %937 = arith.constant 1 : i32
        %939 = arith.extsi %937 : i32 to i64
        %938 = arith.addi %936, %939 : i64
        %940 = llvm.mlir.addressof @MOD : !llvm.ptr
        %941 = llvm.load %940 : !llvm.ptr -> i64
        %942 = arith.remsi %938, %941 : i64
        %943 = llvm.load %907 : !llvm.ptr -> i64
        %944 = llvm.getelementptr %901[%943] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %942, %944 : i64, !llvm.ptr
        %945 = llvm.load %907 : !llvm.ptr -> i64
        %946 = arith.constant 1 : i32
        %948 = arith.extsi %946 : i32 to i64
        %947 = arith.addi %945, %948 : i64
        llvm.store %947, %907 : i64, !llvm.ptr
        %949 = llvm.load %929 : !llvm.ptr -> i64
        %950 = arith.muli %949, %921 : i64
        %951 = llvm.mlir.addressof @MOD : !llvm.ptr
        %952 = llvm.load %951 : !llvm.ptr -> i64
        %953 = arith.remsi %950, %952 : i64
        llvm.store %953, %929 : i64, !llvm.ptr
        %954 = llvm.load %907 : !llvm.ptr -> i64
        %955 = arith.cmpi sge, %954, %900 : i64
        cf.cond_br %955, ^bb147, ^bb148
        ^bb147:
          %957 = llvm.load %907 : !llvm.ptr -> i64
          %958 = llvm.load %911 : !llvm.ptr -> i64
          func.call @batch_inverse(%901, %957, %893, %958) : (!llvm.ptr, i64, !llvm.ptr, i64) -> ()
          %959 = llvm.load %911 : !llvm.ptr -> i64
          %960 = llvm.load %907 : !llvm.ptr -> i64
          %961 = arith.addi %959, %960 : i64
          llvm.store %961, %911 : i64, !llvm.ptr
          %962 = arith.constant 0 : i32
          %963 = arith.extsi %962 : i32 to i64
          llvm.store %963, %907 : i64, !llvm.ptr
          cf.br ^bb149
        ^bb148:
          cf.br ^bb149
        ^bb149:
        %964 = llvm.load %933 : !llvm.ptr -> i64
        %965 = arith.constant 1 : i32
        %967 = arith.extsi %965 : i32 to i64
        %966 = arith.addi %964, %967 : i64
        llvm.store %966, %933 : i64, !llvm.ptr
        cf.br ^bb144
      ^bb146:
      %968 = llvm.load %856 : !llvm.ptr -> i64
      %969 = arith.constant 1 : i32
      %971 = arith.extsi %969 : i32 to i64
      %970 = arith.addi %968, %971 : i64
      llvm.store %970, %856 : i64, !llvm.ptr
      cf.br ^bb141
    ^bb143:
    %972 = llvm.load %907 : !llvm.ptr -> i64
    %973 = arith.constant 0 : i32
    %975 = arith.extsi %973 : i32 to i64
    %974 = arith.cmpi sgt, %972, %975 : i64
    cf.cond_br %974, ^bb150, ^bb151
    ^bb150:
      %977 = llvm.load %907 : !llvm.ptr -> i64
      %978 = llvm.load %911 : !llvm.ptr -> i64
      func.call @batch_inverse(%901, %977, %893, %978) : (!llvm.ptr, i64, !llvm.ptr, i64) -> ()
      %979 = llvm.load %911 : !llvm.ptr -> i64
      %980 = llvm.load %907 : !llvm.ptr -> i64
      %981 = arith.addi %979, %980 : i64
      llvm.store %981, %911 : i64, !llvm.ptr
      cf.br ^bb152
    ^bb151:
      cf.br ^bb152
    ^bb152:
    %983 = arith.constant 8 : i32
    %984 = arith.extsi %983 : i32 to i64
    %982 = func.call @calloc(%842, %984) : (i64, i64) -> !llvm.ptr
    %986 = arith.constant 8 : i32
    %987 = arith.extsi %986 : i32 to i64
    %985 = func.call @calloc(%842, %987) : (i64, i64) -> !llvm.ptr
    %988 = arith.constant 0 : i32
    %989 = arith.extsi %988 : i32 to i64
    %990 = llvm.mlir.constant(1 : i64) : i64
    %991 = llvm.alloca %990 x i64 : (i64) -> !llvm.ptr
    llvm.store %989, %991 : i64, !llvm.ptr
    cf.br ^bb153
    ^bb153:
    %992 = llvm.load %991 : !llvm.ptr -> i64
    %993 = arith.cmpi slt, %992, %842 : i64
    cf.cond_br %993, ^bb154, ^bb155
    ^bb154:
      %994 = arith.constant 1 : i32
      %995 = llvm.load %991 : !llvm.ptr -> i64
      %996 = arith.extsi %994 : i32 to i64
      %997 = llvm.getelementptr %985[%995] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %996, %997 : i64, !llvm.ptr
      %998 = llvm.load %991 : !llvm.ptr -> i64
      %999 = arith.constant 1 : i32
      %1001 = arith.extsi %999 : i32 to i64
      %1000 = arith.addi %998, %1001 : i64
      llvm.store %1000, %991 : i64, !llvm.ptr
      cf.br ^bb153
    ^bb155:
    %1002 = llvm.mlir.addressof @g_exp : !llvm.ptr
    llvm.store %982, %1002 : !llvm.ptr, !llvm.ptr
    %1003 = llvm.mlir.addressof @g_p_pow : !llvm.ptr
    llvm.store %985, %1003 : !llvm.ptr, !llvm.ptr
    %1004 = arith.constant 1 : i32
    %1005 = arith.extsi %1004 : i32 to i64
    %1006 = llvm.mlir.addressof @g_prod : !llvm.ptr
    llvm.store %1005, %1006 : i64, !llvm.ptr
    %1007 = arith.constant 0 : i32
    %1008 = arith.extsi %1007 : i32 to i64
    %1009 = llvm.mlir.addressof @g_zero_count : !llvm.ptr
    llvm.store %1008, %1009 : i64, !llvm.ptr
    %1010 = arith.constant 2 : i32
    %1012 = arith.extsi %1010 : i32 to i64
    %1011 = arith.divsi %arg0, %1012 : i64
    %1013 = arith.constant 2 : i32
    %1015 = arith.extsi %1013 : i32 to i64
    %1014 = arith.remsi %arg0, %1015 : i64
    %1016 = arith.constant 0 : i32
    %1018 = arith.extsi %1016 : i32 to i64
    %1017 = arith.cmpi eq, %1014, %1018 : i64
    %1019 = arith.constant 0 : i32
    %1020 = arith.extsi %1019 : i32 to i64
    %1021 = llvm.mlir.constant(1 : i64) : i64
    %1022 = llvm.alloca %1021 x i64 : (i64) -> !llvm.ptr
    llvm.store %1020, %1022 : i64, !llvm.ptr
    %1023 = arith.constant 1 : i32
    %1024 = arith.extsi %1023 : i32 to i64
    %1025 = llvm.mlir.constant(1 : i64) : i64
    %1026 = llvm.alloca %1025 x i64 : (i64) -> !llvm.ptr
    llvm.store %1024, %1026 : i64, !llvm.ptr
    cf.br ^bb156
    ^bb156:
    %1027 = llvm.load %1026 : !llvm.ptr -> i64
    %1028 = arith.cmpi sle, %1027, %1011 : i64
    cf.cond_br %1028, ^bb157, ^bb158
    ^bb157:
      %1029 = llvm.load %1026 : !llvm.ptr -> i64
      %1030 = arith.subi %arg0, %1029 : i64
      %1031 = arith.constant 1 : i32
      %1033 = arith.extsi %1031 : i32 to i64
      %1032 = arith.addi %1030, %1033 : i64
      %1034 = llvm.load %1026 : !llvm.ptr -> i64
      %1036 = arith.constant 1 : i32
      %1037 = arith.extsi %1036 : i32 to i64
      func.call @apply_factor(%1032, %1037) : (i64, i64) -> ()
      %1039 = arith.constant 1 : i32
      %1041 = arith.constant 0 : i32
      %1040 = arith.subi %1041, %1039 : i32
      %1042 = arith.extsi %1040 : i32 to i64
      func.call @apply_factor(%1034, %1042) : (i64, i64) -> ()
      %1043 = llvm.mlir.addressof @g_zero_count : !llvm.ptr
      %1044 = llvm.load %1043 : !llvm.ptr -> i64
      %1045 = arith.constant 0 : i32
      %1047 = arith.extsi %1045 : i32 to i64
      %1046 = arith.cmpi ne, %1044, %1047 : i64
      %1048 = scf.if %1046 -> (i32) {
        %1049 = arith.constant 0 : i32
        scf.yield %1049 : i32
      } else {
        %1050 = llvm.mlir.addressof @g_prod : !llvm.ptr
        %1051 = llvm.load %1050 : !llvm.ptr -> i64
        scf.yield %1051 : i64
      }
      %1052 = arith.extsi %1048 : i32 to i64
      %1053 = scf.if %1017 -> (i1) {
        %1054 = llvm.load %1026 : !llvm.ptr -> i64
        %1055 = arith.cmpi eq, %1054, %1011 : i64
        scf.yield %1055 : i1
      } else {
        %1056 = arith.constant false
        scf.yield %1056 : i1
      }
      cf.cond_br %1053, ^bb159, ^bb160
      ^bb159:
        %1057 = llvm.load %1022 : !llvm.ptr -> i64
        %1058 = arith.addi %1057, %1052 : i64
        llvm.store %1058, %1022 : i64, !llvm.ptr
        cf.br ^bb161
      ^bb160:
        %1059 = llvm.load %1022 : !llvm.ptr -> i64
        %1060 = arith.constant 2 : i32
        %1062 = arith.extsi %1060 : i32 to i64
        %1061 = arith.muli %1062, %1052 : i64
        %1063 = arith.addi %1059, %1061 : i64
        llvm.store %1063, %1022 : i64, !llvm.ptr
        cf.br ^bb161
      ^bb161:
      %1064 = llvm.load %1022 : !llvm.ptr -> i64
      %1065 = arith.constant 1 : i32
      %1066 = arith.extsi %1065 : i32 to i64
      %1067 = arith.constant 62 : i32
      %1069 = arith.extsi %1067 : i32 to i64
      %1068 = arith.shli %1066, %1069 : i64
      %1070 = arith.cmpi sge, %1064, %1068 : i64
      cf.cond_br %1070, ^bb162, ^bb163
      ^bb162:
        %1071 = llvm.load %1022 : !llvm.ptr -> i64
        %1072 = llvm.mlir.addressof @MOD : !llvm.ptr
        %1073 = llvm.load %1072 : !llvm.ptr -> i64
        %1074 = arith.remsi %1071, %1073 : i64
        llvm.store %1074, %1022 : i64, !llvm.ptr
        cf.br ^bb164
      ^bb163:
        cf.br ^bb164
      ^bb164:
      %1075 = llvm.load %1026 : !llvm.ptr -> i64
      %1076 = arith.constant 1 : i32
      %1078 = arith.extsi %1076 : i32 to i64
      %1077 = arith.addi %1075, %1078 : i64
      llvm.store %1077, %1026 : i64, !llvm.ptr
      cf.br ^bb156
    ^bb158:
    %1079 = llvm.load %1022 : !llvm.ptr -> i64
    %1080 = llvm.mlir.addressof @MOD : !llvm.ptr
    %1081 = llvm.load %1080 : !llvm.ptr -> i64
    %1082 = arith.remsi %1079, %1081 : i64
    llvm.store %1082, %1022 : i64, !llvm.ptr
    %1084 = arith.constant 2 : i32
    %1085 = arith.extsi %1084 : i32 to i64
    %1083 = func.call @modpow(%1085, %arg0) : (i64, i64) -> i64
    %1086 = arith.constant 2 : i32
    %1088 = arith.extsi %1086 : i32 to i64
    %1087 = arith.subi %1083, %1088 : i64
    %1089 = llvm.mlir.addressof @MOD : !llvm.ptr
    %1090 = llvm.load %1089 : !llvm.ptr -> i64
    %1091 = arith.addi %1087, %1090 : i64
    %1092 = llvm.mlir.addressof @MOD : !llvm.ptr
    %1093 = llvm.load %1092 : !llvm.ptr -> i64
    %1094 = arith.remsi %1091, %1093 : i64
    %1095 = llvm.load %1022 : !llvm.ptr -> i64
    %1096 = arith.subi %1095, %1094 : i64
    %1097 = llvm.mlir.addressof @MOD : !llvm.ptr
    %1098 = llvm.load %1097 : !llvm.ptr -> i64
    %1099 = arith.addi %1096, %1098 : i64
    %1100 = llvm.mlir.addressof @MOD : !llvm.ptr
    %1101 = llvm.load %1100 : !llvm.ptr -> i64
    %1102 = arith.remsi %1099, %1101 : i64
    func.call @free(%843) : (!llvm.ptr) -> ()
    func.call @free(%846) : (!llvm.ptr) -> ()
    func.call @free(%893) : (!llvm.ptr) -> ()
    func.call @free(%901) : (!llvm.ptr) -> ()
    func.call @free(%982) : (!llvm.ptr) -> ()
    func.call @free(%985) : (!llvm.ptr) -> ()
    func.call @free(%839) : (!llvm.ptr) -> ()
    %1111 = llvm.mlir.addressof @g_spf : !llvm.ptr
    %1112 = llvm.load %1111 : !llvm.ptr -> !llvm.ptr
    func.call @free(%1112) : (!llvm.ptr) -> ()
    %1114 = llvm.mlir.addressof @g_prime_idx : !llvm.ptr
    %1115 = llvm.load %1114 : !llvm.ptr -> !llvm.ptr
    func.call @free(%1115) : (!llvm.ptr) -> ()
    %1117 = llvm.mlir.addressof @g_primes : !llvm.ptr
    %1118 = llvm.load %1117 : !llvm.ptr -> !llvm.ptr
    func.call @free(%1118) : (!llvm.ptr) -> ()
    func.return %1102 : i64
  }
  func.func @main() -> i32 {
    %1119 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %1121 = arith.constant 10000000 : i32
    %1122 = arith.extsi %1121 : i32 to i64
    %1120 = func.call @solve(%1122) : (i64) -> i64
    %1123 = llvm.call @printf(%1119, %1120) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    %1124 = arith.constant 0 : i32
    func.return %1124 : i32
  }
}