Problem 642

F(n) = sum of LPF(i) for i=2..n. Compute F(201820182018) mod 10^9. Uses Min_25-style prime sum table + recursive contribution.

Answer631499044
Output631499044
StatusPASS
Native helperno
Runtime4280 ms
Peak memory92576 KB
Time complexityO(n log n) (estimated)
Space complexityO(n^2) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n log n)O(n log n)
Space complexityO(n^2)O(n)
ApproachFlow solutionModular DP or matrix exponentiation
VerdictOptimal

Flow source

# Project Euler 642: Sum of Largest Prime Factors
# F(n) = sum of LPF(i) for i=2..n. Compute F(201820182018) mod 10^9.
# Uses Min_25-style prime sum table + recursive contribution.

import euler.nt { isqrt }

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

const MOD: i64 = 1000000000

# Globals for recursion
let mut g_N: i64 = 0
let mut g_root: i64 = 0
let mut g_nprimes: i64 = 0
let mut g_primes: ptr<i64> = null
let mut g_pi: ptr<i64> = null  # pi[x] = prime counting function
let mut g_prime_sums: ptr<i64> = null  # prime sum table
let mut g_idx_small: ptr<i64> = null
let mut g_idx_large: ptr<i64> = null
let mut g_lower_prime_sum: ptr<i64> = null

# Memoization: key = bound * (nprimes+1) + idx
# Use hash table
const HASH_SIZE: i64 = 4000007
let mut g_memo_keys: ptr<i64> = null
let mut g_memo_vals: ptr<i64> = null

function prime_sum_upto(x: i64) -> i64 {
    if x <= g_root {
        return g_prime_sums[g_idx_small[x]]
    }
    return g_prime_sums[g_idx_large[g_N / x]]
}

function terminal_prime_sum(x: i64, idx: i64) -> i64 {
    if idx >= g_nprimes {
        if x <= g_primes[g_nprimes - 1] { return 0 }
    } else {
        if x < g_primes[idx] { return 0 }
    }
    let r: i64 = (prime_sum_upto(x) - g_lower_prime_sum[idx]) % MOD
    if r < 0 { r = r + MOD }
    return r
}

function contribution(bound: i64, idx: i64) -> i64 {
    let isqrt_bound: i64 = isqrt(bound)
    # end = pi[isqrt(bound)]
    let mut end: i64 = g_pi[isqrt_bound]

    let mut total: i64 = terminal_prime_sum(bound, idx)
    if idx >= end { return total }

    # Check memo
    let key: i64 = bound * (g_nprimes + 1) + idx
    let h: i64 = key % HASH_SIZE
    if g_memo_keys[h] == key { return g_memo_vals[h] }

    for i in idx..end {
        let p: i64 = g_primes[i]
        let mut power: i64 = p
        let power_limit: i64 = bound / p
        let next_idx: i64 = i + 1

        while power <= power_limit {
            let child_bound: i64 = bound / power
            let child_end: i64 = g_pi[isqrt(child_bound)]
            let child: i64
            if next_idx >= child_end {
                child = terminal_prime_sum(child_bound, next_idx)
            } else {
                child = contribution(child_bound, next_idx)
            }
            total = (total + child + p) % MOD
            if power > bound / p { break }
            power = power * p
        }
    }

    total = total % MOD
    if total < 0 { total = total + MOD }
    g_memo_keys[h] = key
    g_memo_vals[h] = total
    return total
}

function main() -> i32 {
    g_N = 201820182018
    g_root = isqrt(g_N)

    # Build prime sum table (Min_25 sieve)
    # Values: descending distinct floor(N/i)
    let vals: ptr<i64> = calloc(2 * g_root + 10, 8)
    let mut m: i64 = 0
    let mut i_val: i64 = 1
    while i_val <= g_N {
        let q: i64 = g_N / i_val
        vals[m] = q
        m = m + 1
        i_val = g_N / q + 1
    }

    g_idx_small = calloc(g_root + 1, 8)
    g_idx_large = calloc(g_root + 1, 8)
    for idx in 0..m {
        let v: i64 = vals[idx]
        if v <= g_root {
            g_idx_small[v] = idx
        } else {
            g_idx_large[g_N / v] = idx
        }
    }

    # Initialize prime_sums = v*(v+1)/2 - 1 mod MOD
    g_prime_sums = calloc(m, 8)
    for idx in 0..m {
        let v: i64 = vals[idx]
        let mut s: i128 = (v as i128) * ((v + 1) as i128) / 2 - 1
        s = s % (MOD as i128)
        g_prime_sums[idx] = s as i64
    }

    # Sieve primes up to root
    let is_comp: ptr<i64> = calloc(g_root + 1, 8)
    g_primes = calloc(g_root / 10 + 100, 8)
    g_nprimes = 0
    for i in 2..(g_root + 1) {
        if is_comp[i] == 0 {
            g_primes[g_nprimes] = i
            g_nprimes = g_nprimes + 1
            let mut j: i64 = (i as i64) * (i as i64)
            while j <= g_root {
                is_comp[j] = 1
                j = j + i
            }
        }
    }
    free(is_comp)

    # Min_25 sieve: for each prime p, update prime_sums
    for pi in 0..g_nprimes {
        let p: i64 = g_primes[pi]
        let p2: i64 = (p as i64) * (p as i64)
        if p2 > g_N { break }

        # Find limit: number of vals >= p2
        let mut lo_k: i64 = 0
        let mut hi_k: i64 = m
        while lo_k < hi_k {
            let mid: i64 = (lo_k + hi_k) / 2
            if vals[mid] >= p2 { lo_k = mid + 1 } else { hi_k = mid }
        }
        let limit: i64 = lo_k
        if limit == 0 { continue }

        let base_idx: i64 = g_idx_small[p - 1]
        let sum_before_p: i64 = g_prime_sums[base_idx]

        for j in 0..limit {
            let v: i64 = vals[j]
            let quotient: i64 = v / p
            let qidx: i64
            if quotient <= g_root {
                qidx = g_idx_small[quotient]
            } else {
                qidx = g_idx_large[g_N / quotient]
            }
            let mut delta: i128 = (p as i128) * ((g_prime_sums[qidx] - sum_before_p) as i128)
            delta = delta % (MOD as i128)
            let mut new_val: i128 = (g_prime_sums[j] as i128) - delta
            new_val = new_val % (MOD as i128)
            if new_val < 0 { new_val = new_val + (MOD as i128) }
            g_prime_sums[j] = new_val as i64
        }
    }

    # Build pi[x] = prime counting function for x = 0..root
    g_pi = calloc(g_root + 1, 8)
    let mut count: i64 = 0
    let mut pidx: i64 = 0
    for v in 0..(g_root + 1) {
        if pidx < g_nprimes && g_primes[pidx] == v {
            count = count + 1
            pidx = pidx + 1
        }
        g_pi[v] = count
    }

    # Build lower_prime_sum
    g_lower_prime_sum = calloc(g_nprimes + 1, 8)
    for idx in 0..g_nprimes {
        let p: i64 = g_primes[idx]
        g_lower_prime_sum[idx] = g_prime_sums[g_idx_small[p - 1]]
    }
    g_lower_prime_sum[g_nprimes] = g_prime_sums[g_idx_small[g_primes[g_nprimes - 1]]]

    # Init memo
    g_memo_keys = calloc(HASH_SIZE, 8)
    g_memo_vals = calloc(HASH_SIZE, 8)

    let ans: i64 = contribution(g_N, 0)
    printf("%lld\n", ans)

    free(g_memo_vals)
    free(g_memo_keys)
    free(g_lower_prime_sum)
    free(g_pi)
    free(g_primes)
    free(g_prime_sums)
    free(g_idx_large)
    free(g_idx_small)
    free(vals)
    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 prime_sum_upto_i64(int64_t x);
int64_t terminal_prime_sum_i64_i64(int64_t x, int64_t idx);
int64_t contribution_i64_i64(int64_t bound, int64_t idx);
int32_t main(void);

static const int64_t MOD = 1000000000;
static const int64_t HASH_SIZE = 4000007;

/* Module statics */
static int64_t g_N = 0;
static int64_t g_root = 0;
static int64_t g_nprimes = 0;
static int64_t* g_primes = NULL;
static int64_t* g_pi = NULL;
static int64_t* g_prime_sums = NULL;
static int64_t* g_idx_small = NULL;
static int64_t* g_idx_large = NULL;
static int64_t* g_lower_prime_sum = NULL;
static int64_t* g_memo_keys = NULL;
static int64_t* g_memo_vals = NULL;

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

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

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

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

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

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



int64_t prime_sum_upto_i64(int64_t x) {
    if (x <= g_root) {
        return g_prime_sums[g_idx_small[x]];
    }
    return g_prime_sums[g_idx_large[FLOW_CHECKED_DIV((g_N), (x))]];
}

int64_t terminal_prime_sum_i64_i64(int64_t x, int64_t idx) {
    if (idx >= g_nprimes) {
        if (x <= g_primes[(g_nprimes - 1)]) {
            return 0;
        }
    } else {
        if (x < g_primes[idx]) {
            return 0;
        }
    }
    int64_t r = FLOW_CHECKED_MOD(((prime_sum_upto_i64(x) - g_lower_prime_sum[idx])), (MOD));
    if (r < 0) {
        r = (r + MOD);
    }
    return r;
}

int64_t contribution_i64_i64(int64_t bound, int64_t idx) {
    int64_t isqrt_bound = isqrt_i64(bound);
    int64_t end = g_pi[isqrt_bound];
    int64_t total = terminal_prime_sum_i64_i64(bound, idx);
    if (idx >= end) {
        return total;
    }
    int64_t key = ((bound * (g_nprimes + 1)) + idx);
    int64_t h = FLOW_CHECKED_MOD((key), (HASH_SIZE));
    if (g_memo_keys[h] == key) {
        return g_memo_vals[h];
    }
    int32_t __flow_step_1 = 1;
    for (int32_t i = idx; (idx <= end) ? i < end : i > end; i += (idx <= end) ? 1 : -1) {
        int64_t p = g_primes[i];
        int64_t power = p;
        int64_t power_limit = FLOW_CHECKED_DIV((bound), (p));
        int64_t next_idx = (i + 1);
        while (power <= power_limit) {
            int64_t child_bound = FLOW_CHECKED_DIV((bound), (power));
            int64_t child_end = g_pi[isqrt_i64(child_bound)];
            int64_t child;
            if (next_idx >= child_end) {
                child = terminal_prime_sum_i64_i64(child_bound, next_idx);
            } else {
                child = contribution_i64_i64(child_bound, next_idx);
            }
            total = FLOW_CHECKED_MOD((((total + child) + p)), (MOD));
            if (power > FLOW_CHECKED_DIV((bound), (p))) {
                break;
            }
            power = (power * p);
        }
    }
    total = FLOW_CHECKED_MOD((total), (MOD));
    if (total < 0) {
        total = (total + MOD);
    }
    g_memo_keys[h] = key;
    g_memo_vals[h] = total;
    return total;
}

int32_t main(void) {
    g_N = 201820182018;
    g_root = isqrt_i64(g_N);
    int64_t* vals = (int64_t*)(calloc(((2 * g_root) + 10), 8));
    int64_t m = 0;
    int64_t i_val = 1;
    while (i_val <= g_N) {
        int64_t q = FLOW_CHECKED_DIV((g_N), (i_val));
        vals[m] = q;
        m = (m + 1);
        i_val = (FLOW_CHECKED_DIV((g_N), (q)) + 1);
    }
    g_idx_small = calloc((g_root + 1), 8);
    g_idx_large = calloc((g_root + 1), 8);
    int32_t __flow_step_2 = 1;
    for (int32_t idx = 0; (0 <= m) ? idx < m : idx > m; idx += (0 <= m) ? 1 : -1) {
        int64_t v = vals[idx];
        if (v <= g_root) {
            g_idx_small[v] = idx;
        } else {
            g_idx_large[FLOW_CHECKED_DIV((g_N), (v))] = idx;
        }
    }
    g_prime_sums = calloc(m, 8);
    int32_t __flow_step_3 = 1;
    for (int32_t idx = 0; (0 <= m) ? idx < m : idx > m; idx += (0 <= m) ? 1 : -1) {
        int64_t v = vals[idx];
        __int128 s = (FLOW_CHECKED_DIV(((((__int128)(v)) * ((__int128)((v + 1))))), (2)) - 1);
        s = FLOW_CHECKED_MOD((s), (((__int128)(MOD))));
        g_prime_sums[idx] = ((int64_t)(s));
    }
    int64_t* is_comp = (int64_t*)(calloc((g_root + 1), 8));
    g_primes = calloc((FLOW_CHECKED_DIV((g_root), (10)) + 100), 8);
    g_nprimes = 0;
    int32_t __flow_step_4 = 1;
    for (int32_t i = 2; (2 <= (g_root + 1)) ? i < (g_root + 1) : i > (g_root + 1); i += (2 <= (g_root + 1)) ? 1 : -1) {
        if (is_comp[i] == 0) {
            g_primes[g_nprimes] = i;
            g_nprimes = (g_nprimes + 1);
            int64_t j = (((int64_t)(i)) * ((int64_t)(i)));
            while (j <= g_root) {
                is_comp[j] = 1;
                j = (j + i);
            }
        }
    }
    free(is_comp);
    int32_t __flow_step_5 = 1;
    for (int32_t pi = 0; (0 <= g_nprimes) ? pi < g_nprimes : pi > g_nprimes; pi += (0 <= g_nprimes) ? 1 : -1) {
        int64_t p = g_primes[pi];
        int64_t p2 = (((int64_t)(p)) * ((int64_t)(p)));
        if (p2 > g_N) {
            break;
        }
        int64_t lo_k = 0;
        int64_t hi_k = m;
        while (lo_k < hi_k) {
            int64_t mid = FLOW_CHECKED_DIV(((lo_k + hi_k)), (2));
            if (vals[mid] >= p2) {
                lo_k = (mid + 1);
            } else {
                hi_k = mid;
            }
        }
        int64_t limit = lo_k;
        if (limit == 0) {
            continue;
        }
        int64_t base_idx = g_idx_small[(p - 1)];
        int64_t sum_before_p = g_prime_sums[base_idx];
        int32_t __flow_step_6 = 1;
        for (int32_t j = 0; (0 <= limit) ? j < limit : j > limit; j += (0 <= limit) ? 1 : -1) {
            int64_t v = vals[j];
            int64_t quotient = FLOW_CHECKED_DIV((v), (p));
            int64_t qidx;
            if (quotient <= g_root) {
                qidx = g_idx_small[quotient];
            } else {
                qidx = g_idx_large[FLOW_CHECKED_DIV((g_N), (quotient))];
            }
            __int128 delta = (((__int128)(p)) * ((__int128)((g_prime_sums[qidx] - sum_before_p))));
            delta = FLOW_CHECKED_MOD((delta), (((__int128)(MOD))));
            __int128 new_val = (((__int128)(g_prime_sums[j])) - delta);
            new_val = FLOW_CHECKED_MOD((new_val), (((__int128)(MOD))));
            if (new_val < 0) {
                new_val = (new_val + ((__int128)(MOD)));
            }
            g_prime_sums[j] = ((int64_t)(new_val));
        }
    }
    g_pi = calloc((g_root + 1), 8);
    int64_t count = 0;
    int64_t pidx = 0;
    int32_t __flow_step_7 = 1;
    for (int32_t v = 0; (0 <= (g_root + 1)) ? v < (g_root + 1) : v > (g_root + 1); v += (0 <= (g_root + 1)) ? 1 : -1) {
        if ((pidx < g_nprimes && g_primes[pidx] == v)) {
            count = (count + 1);
            pidx = (pidx + 1);
        }
        g_pi[v] = count;
    }
    g_lower_prime_sum = calloc((g_nprimes + 1), 8);
    int32_t __flow_step_8 = 1;
    for (int32_t idx = 0; (0 <= g_nprimes) ? idx < g_nprimes : idx > g_nprimes; idx += (0 <= g_nprimes) ? 1 : -1) {
        int64_t p = g_primes[idx];
        g_lower_prime_sum[idx] = g_prime_sums[g_idx_small[(p - 1)]];
    }
    g_lower_prime_sum[g_nprimes] = g_prime_sums[g_idx_small[g_primes[(g_nprimes - 1)]]];
    g_memo_keys = calloc(HASH_SIZE, 8);
    g_memo_vals = calloc(HASH_SIZE, 8);
    int64_t ans = contribution_i64_i64(g_N, 0);
    printf("%lld\n", ans);
    free(g_memo_vals);
    free(g_memo_keys);
    free(g_lower_prime_sum);
    free(g_pi);
    free(g_primes);
    free(g_prime_sums);
    free(g_idx_large);
    free(g_idx_small);
    free(vals);
    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(1000000000 : i64) : i64
  // Module static: g_N
  llvm.mlir.global internal @g_N(0 : i64) : i64
  // Module static: g_root
  llvm.mlir.global internal @g_root(0 : i64) : i64
  // Module static: g_nprimes
  llvm.mlir.global internal @g_nprimes(0 : i64) : i64
  // Module static: g_primes
  llvm.mlir.global internal @g_primes() {addr_space = 0 : i32} : !llvm.ptr {
    %175 = llvm.mlir.zero : !llvm.ptr
    llvm.return %175 : !llvm.ptr
  }
  // Module static: g_pi
  llvm.mlir.global internal @g_pi() {addr_space = 0 : i32} : !llvm.ptr {
    %176 = llvm.mlir.zero : !llvm.ptr
    llvm.return %176 : !llvm.ptr
  }
  // Module static: g_prime_sums
  llvm.mlir.global internal @g_prime_sums() {addr_space = 0 : i32} : !llvm.ptr {
    %177 = llvm.mlir.zero : !llvm.ptr
    llvm.return %177 : !llvm.ptr
  }
  // Module static: g_idx_small
  llvm.mlir.global internal @g_idx_small() {addr_space = 0 : i32} : !llvm.ptr {
    %178 = llvm.mlir.zero : !llvm.ptr
    llvm.return %178 : !llvm.ptr
  }
  // Module static: g_idx_large
  llvm.mlir.global internal @g_idx_large() {addr_space = 0 : i32} : !llvm.ptr {
    %179 = llvm.mlir.zero : !llvm.ptr
    llvm.return %179 : !llvm.ptr
  }
  // Module static: g_lower_prime_sum
  llvm.mlir.global internal @g_lower_prime_sum() {addr_space = 0 : i32} : !llvm.ptr {
    %180 = llvm.mlir.zero : !llvm.ptr
    llvm.return %180 : !llvm.ptr
  }
  // Constant: HASH_SIZE
  llvm.mlir.global internal constant @HASH_SIZE(4000007 : i64) : i64
  // Module static: g_memo_keys
  llvm.mlir.global internal @g_memo_keys() {addr_space = 0 : i32} : !llvm.ptr {
    %181 = llvm.mlir.zero : !llvm.ptr
    llvm.return %181 : !llvm.ptr
  }
  // Module static: g_memo_vals
  llvm.mlir.global internal @g_memo_vals() {addr_space = 0 : i32} : !llvm.ptr {
    %182 = llvm.mlir.zero : !llvm.ptr
    llvm.return %182 : !llvm.ptr
  }
  func.func @prime_sum_upto(%arg0: i64) -> i64 {
    %183 = llvm.mlir.addressof @g_root : !llvm.ptr
    %184 = llvm.load %183 : !llvm.ptr -> i64
    %185 = arith.cmpi sle, %arg0, %184 : i64
    cf.cond_br %185, ^bb42, ^bb43
    ^bb42:
      %187 = llvm.mlir.addressof @g_prime_sums : !llvm.ptr
      %188 = llvm.load %187 : !llvm.ptr -> !llvm.ptr
      %190 = llvm.mlir.addressof @g_idx_small : !llvm.ptr
      %191 = llvm.load %190 : !llvm.ptr -> !llvm.ptr
      %192 = llvm.getelementptr %191[%arg0] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %189 = llvm.load %192 : !llvm.ptr -> i64
      %193 = llvm.getelementptr %188[%189] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %186 = llvm.load %193 : !llvm.ptr -> i64
      func.return %186 : i64
    ^bb43:
      cf.br ^bb44
    ^bb44:
    %195 = llvm.mlir.addressof @g_prime_sums : !llvm.ptr
    %196 = llvm.load %195 : !llvm.ptr -> !llvm.ptr
    %198 = llvm.mlir.addressof @g_idx_large : !llvm.ptr
    %199 = llvm.load %198 : !llvm.ptr -> !llvm.ptr
    %200 = llvm.mlir.addressof @g_N : !llvm.ptr
    %201 = llvm.load %200 : !llvm.ptr -> i64
    %202 = arith.divsi %201, %arg0 : i64
    %203 = llvm.getelementptr %199[%202] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %197 = llvm.load %203 : !llvm.ptr -> i64
    %204 = llvm.getelementptr %196[%197] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %194 = llvm.load %204 : !llvm.ptr -> i64
    func.return %194 : i64
  }
  func.func @terminal_prime_sum(%arg0: i64, %arg1: i64) -> i64 {
    %205 = llvm.mlir.addressof @g_nprimes : !llvm.ptr
    %206 = llvm.load %205 : !llvm.ptr -> i64
    %207 = arith.cmpi sge, %arg1, %206 : i64
    cf.cond_br %207, ^bb45, ^bb46
    ^bb45:
      %209 = llvm.mlir.addressof @g_primes : !llvm.ptr
      %210 = llvm.load %209 : !llvm.ptr -> !llvm.ptr
      %211 = llvm.mlir.addressof @g_nprimes : !llvm.ptr
      %212 = llvm.load %211 : !llvm.ptr -> i64
      %213 = arith.constant 1 : i32
      %215 = arith.extsi %213 : i32 to i64
      %214 = arith.subi %212, %215 : i64
      %216 = llvm.getelementptr %210[%214] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %208 = llvm.load %216 : !llvm.ptr -> i64
      %217 = arith.cmpi sle, %arg0, %208 : i64
      cf.cond_br %217, ^bb48, ^bb49
      ^bb48:
        %218 = arith.constant 0 : i32
        %219 = arith.extsi %218 : i32 to i64
        func.return %219 : i64
      ^bb49:
        cf.br ^bb50
      ^bb50:
      cf.br ^bb47
    ^bb46:
      %221 = llvm.mlir.addressof @g_primes : !llvm.ptr
      %222 = llvm.load %221 : !llvm.ptr -> !llvm.ptr
      %223 = llvm.getelementptr %222[%arg1] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %220 = llvm.load %223 : !llvm.ptr -> i64
      %224 = arith.cmpi slt, %arg0, %220 : i64
      cf.cond_br %224, ^bb51, ^bb52
      ^bb51:
        %225 = arith.constant 0 : i32
        %226 = arith.extsi %225 : i32 to i64
        func.return %226 : i64
      ^bb52:
        cf.br ^bb53
      ^bb53:
      cf.br ^bb47
    ^bb47:
    %227 = func.call @prime_sum_upto(%arg0) : (i64) -> i64
    %229 = llvm.mlir.addressof @g_lower_prime_sum : !llvm.ptr
    %230 = llvm.load %229 : !llvm.ptr -> !llvm.ptr
    %231 = llvm.getelementptr %230[%arg1] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %228 = llvm.load %231 : !llvm.ptr -> i64
    %232 = arith.subi %227, %228 : i64
    %233 = llvm.mlir.addressof @MOD : !llvm.ptr
    %234 = llvm.load %233 : !llvm.ptr -> i64
    %235 = arith.remsi %232, %234 : i64
    %236 = arith.constant 0 : i32
    %238 = arith.extsi %236 : i32 to i64
    %237 = arith.cmpi slt, %235, %238 : i64
    %239 = scf.if %237 -> (i64) {
      %240 = llvm.mlir.addressof @MOD : !llvm.ptr
      %241 = llvm.load %240 : !llvm.ptr -> i64
      %242 = arith.addi %235, %241 : i64
      scf.yield %242 : i64
    } else {
      scf.yield %235 : i64
    }
    func.return %239 : i64
  }
  func.func @contribution(%arg0: i64, %arg1: i64) -> i64 {
    %243 = func.call @isqrt(%arg0) : (i64) -> i64
    %245 = llvm.mlir.addressof @g_pi : !llvm.ptr
    %246 = llvm.load %245 : !llvm.ptr -> !llvm.ptr
    %247 = llvm.getelementptr %246[%243] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %244 = llvm.load %247 : !llvm.ptr -> i64
    %248 = llvm.mlir.constant(1 : i64) : i64
    %249 = llvm.alloca %248 x i64 : (i64) -> !llvm.ptr
    llvm.store %244, %249 : i64, !llvm.ptr
    %250 = func.call @terminal_prime_sum(%arg0, %arg1) : (i64, i64) -> i64
    %251 = llvm.mlir.constant(1 : i64) : i64
    %252 = llvm.alloca %251 x i64 : (i64) -> !llvm.ptr
    llvm.store %250, %252 : i64, !llvm.ptr
    %253 = llvm.load %249 : !llvm.ptr -> i64
    %254 = arith.cmpi sge, %arg1, %253 : i64
    cf.cond_br %254, ^bb54, ^bb55
    ^bb54:
      %255 = llvm.load %252 : !llvm.ptr -> i64
      func.return %255 : i64
    ^bb55:
      cf.br ^bb56
    ^bb56:
    %256 = llvm.mlir.addressof @g_nprimes : !llvm.ptr
    %257 = llvm.load %256 : !llvm.ptr -> i64
    %258 = arith.constant 1 : i32
    %260 = arith.extsi %258 : i32 to i64
    %259 = arith.addi %257, %260 : i64
    %261 = arith.muli %arg0, %259 : i64
    %262 = arith.addi %261, %arg1 : i64
    %263 = llvm.mlir.addressof @HASH_SIZE : !llvm.ptr
    %264 = llvm.load %263 : !llvm.ptr -> i64
    %265 = arith.remsi %262, %264 : i64
    %267 = llvm.mlir.addressof @g_memo_keys : !llvm.ptr
    %268 = llvm.load %267 : !llvm.ptr -> !llvm.ptr
    %269 = llvm.getelementptr %268[%265] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %266 = llvm.load %269 : !llvm.ptr -> i64
    %270 = arith.cmpi eq, %266, %262 : i64
    cf.cond_br %270, ^bb57, ^bb58
    ^bb57:
      %272 = llvm.mlir.addressof @g_memo_vals : !llvm.ptr
      %273 = llvm.load %272 : !llvm.ptr -> !llvm.ptr
      %274 = llvm.getelementptr %273[%265] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %271 = llvm.load %274 : !llvm.ptr -> i64
      func.return %271 : i64
    ^bb58:
      cf.br ^bb59
    ^bb59:
    %275 = llvm.load %249 : !llvm.ptr -> i64
    %276 = arith.index_cast %arg1 : i32 to index
    %277 = arith.index_cast %275 : i32 to index
    %279 = arith.constant 1 : index
    %280 = arith.constant -1 : index
    %281 = arith.cmpi sle, %276, %277 : index
    %278 = arith.select %281, %279, %280 : index
    cf.br ^bb60(%276 : index)
    ^bb60(%282: index):
    %283 = arith.cmpi slt, %282, %277 : index
    %284 = arith.cmpi sgt, %282, %277 : index
    %285 = arith.select %281, %283, %284 : i1
    cf.cond_br %285, ^bb61(%282 : index), ^bb62(%282 : index)
    ^bb61(%286: index):
      %288 = llvm.mlir.addressof @g_primes : !llvm.ptr
      %289 = llvm.load %288 : !llvm.ptr -> !llvm.ptr
      %290 = arith.index_cast %286 : index to i64
      %291 = llvm.getelementptr %289[%290] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %287 = llvm.load %291 : !llvm.ptr -> i64
      %292 = llvm.mlir.constant(1 : i64) : i64
      %293 = llvm.alloca %292 x i64 : (i64) -> !llvm.ptr
      llvm.store %287, %293 : i64, !llvm.ptr
      %294 = arith.divsi %arg0, %287 : i64
      %295 = arith.constant 1 : i32
      %297 = arith.index_cast %286 : index to i32
      %296 = arith.addi %297, %295 : i32
      %298 = arith.extsi %296 : i32 to i64
      cf.br ^bb63
      ^bb63:
      %299 = llvm.load %293 : !llvm.ptr -> i64
      %300 = arith.cmpi sle, %299, %294 : i64
      cf.cond_br %300, ^bb64, ^bb65
      ^bb64:
        %301 = llvm.load %293 : !llvm.ptr -> i64
        %302 = arith.divsi %arg0, %301 : i64
        %304 = llvm.mlir.addressof @g_pi : !llvm.ptr
        %305 = llvm.load %304 : !llvm.ptr -> !llvm.ptr
        %306 = func.call @isqrt(%302) : (i64) -> i64
        %307 = llvm.getelementptr %305[%306] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %303 = llvm.load %307 : !llvm.ptr -> i64
        %308 = llvm.mlir.undef : i64
        %309 = arith.cmpi sge, %298, %303 : i64
        %310 = scf.if %309 -> (i64) {
          %311 = func.call @terminal_prime_sum(%302, %298) : (i64, i64) -> i64
          scf.yield %311 : i64
        } else {
          %312 = func.call @contribution(%302, %298) : (i64, i64) -> i64
          scf.yield %312 : i64
        }
        %313 = llvm.load %252 : !llvm.ptr -> i64
        %314 = arith.addi %313, %310 : i64
        %315 = arith.addi %314, %287 : i64
        %316 = llvm.mlir.addressof @MOD : !llvm.ptr
        %317 = llvm.load %316 : !llvm.ptr -> i64
        %318 = arith.remsi %315, %317 : i64
        llvm.store %318, %252 : i64, !llvm.ptr
        %319 = llvm.load %293 : !llvm.ptr -> i64
        %320 = arith.divsi %arg0, %287 : i64
        %321 = arith.cmpi sgt, %319, %320 : i64
        cf.cond_br %321, ^bb66, ^bb67
        ^bb66:
          cf.br ^bb65
        ^bb67:
          cf.br ^bb68
        ^bb68:
        %322 = llvm.load %293 : !llvm.ptr -> i64
        %323 = arith.muli %322, %287 : i64
        llvm.store %323, %293 : i64, !llvm.ptr
        cf.br ^bb63
      ^bb65:
      %324 = arith.addi %286, %278 : index
      cf.br ^bb60(%324 : index)
    ^bb62(%325: index):
    %326 = llvm.load %252 : !llvm.ptr -> i64
    %327 = llvm.mlir.addressof @MOD : !llvm.ptr
    %328 = llvm.load %327 : !llvm.ptr -> i64
    %329 = arith.remsi %326, %328 : i64
    llvm.store %329, %252 : i64, !llvm.ptr
    %330 = llvm.load %252 : !llvm.ptr -> i64
    %331 = arith.constant 0 : i32
    %333 = arith.extsi %331 : i32 to i64
    %332 = arith.cmpi slt, %330, %333 : i64
    cf.cond_br %332, ^bb69, ^bb70
    ^bb69:
      %334 = llvm.load %252 : !llvm.ptr -> i64
      %335 = llvm.mlir.addressof @MOD : !llvm.ptr
      %336 = llvm.load %335 : !llvm.ptr -> i64
      %337 = arith.addi %334, %336 : i64
      llvm.store %337, %252 : i64, !llvm.ptr
      cf.br ^bb71
    ^bb70:
      cf.br ^bb71
    ^bb71:
    %338 = llvm.mlir.addressof @g_memo_keys : !llvm.ptr
    %339 = llvm.load %338 : !llvm.ptr -> !llvm.ptr
    %340 = llvm.getelementptr %339[%265] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %262, %340 : i64, !llvm.ptr
    %341 = llvm.load %252 : !llvm.ptr -> i64
    %342 = llvm.mlir.addressof @g_memo_vals : !llvm.ptr
    %343 = llvm.load %342 : !llvm.ptr -> !llvm.ptr
    %344 = llvm.getelementptr %343[%265] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %341, %344 : i64, !llvm.ptr
    %345 = llvm.load %252 : !llvm.ptr -> i64
    func.return %345 : i64
  }
  func.func @main() -> i32 {
    %346 = arith.constant 197525214722 : i32
    %347 = arith.extsi %346 : i32 to i64
    %348 = llvm.mlir.addressof @g_N : !llvm.ptr
    llvm.store %347, %348 : i64, !llvm.ptr
    %350 = llvm.mlir.addressof @g_N : !llvm.ptr
    %351 = llvm.load %350 : !llvm.ptr -> i64
    %349 = func.call @isqrt(%351) : (i64) -> i64
    %352 = llvm.mlir.addressof @g_root : !llvm.ptr
    llvm.store %349, %352 : i64, !llvm.ptr
    %354 = arith.constant 2 : i32
    %355 = llvm.mlir.addressof @g_root : !llvm.ptr
    %356 = llvm.load %355 : !llvm.ptr -> i64
    %358 = arith.extsi %354 : i32 to i64
    %357 = arith.muli %358, %356 : i64
    %359 = arith.constant 10 : i32
    %361 = arith.extsi %359 : i32 to i64
    %360 = arith.addi %357, %361 : i64
    %362 = arith.constant 8 : i32
    %363 = arith.extsi %362 : i32 to i64
    %353 = func.call @calloc(%360, %363) : (i64, i64) -> !llvm.ptr
    %364 = arith.constant 0 : i32
    %365 = arith.extsi %364 : i32 to i64
    %366 = llvm.mlir.constant(1 : i64) : i64
    %367 = llvm.alloca %366 x i64 : (i64) -> !llvm.ptr
    llvm.store %365, %367 : i64, !llvm.ptr
    %368 = arith.constant 1 : i32
    %369 = arith.extsi %368 : i32 to i64
    %370 = llvm.mlir.constant(1 : i64) : i64
    %371 = llvm.alloca %370 x i64 : (i64) -> !llvm.ptr
    llvm.store %369, %371 : i64, !llvm.ptr
    cf.br ^bb72
    ^bb72:
    %372 = llvm.load %371 : !llvm.ptr -> i64
    %373 = llvm.mlir.addressof @g_N : !llvm.ptr
    %374 = llvm.load %373 : !llvm.ptr -> i64
    %375 = arith.cmpi sle, %372, %374 : i64
    cf.cond_br %375, ^bb73, ^bb74
    ^bb73:
      %376 = llvm.mlir.addressof @g_N : !llvm.ptr
      %377 = llvm.load %376 : !llvm.ptr -> i64
      %378 = llvm.load %371 : !llvm.ptr -> i64
      %379 = arith.divsi %377, %378 : i64
      %380 = llvm.load %367 : !llvm.ptr -> i64
      %381 = llvm.getelementptr %353[%380] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %379, %381 : i64, !llvm.ptr
      %382 = llvm.load %367 : !llvm.ptr -> i64
      %383 = arith.constant 1 : i32
      %385 = arith.extsi %383 : i32 to i64
      %384 = arith.addi %382, %385 : i64
      llvm.store %384, %367 : i64, !llvm.ptr
      %386 = llvm.mlir.addressof @g_N : !llvm.ptr
      %387 = llvm.load %386 : !llvm.ptr -> i64
      %388 = arith.divsi %387, %379 : i64
      %389 = arith.constant 1 : i32
      %391 = arith.extsi %389 : i32 to i64
      %390 = arith.addi %388, %391 : i64
      llvm.store %390, %371 : i64, !llvm.ptr
      cf.br ^bb72
    ^bb74:
    %393 = llvm.mlir.addressof @g_root : !llvm.ptr
    %394 = llvm.load %393 : !llvm.ptr -> i64
    %395 = arith.constant 1 : i32
    %397 = arith.extsi %395 : i32 to i64
    %396 = arith.addi %394, %397 : i64
    %398 = arith.constant 8 : i32
    %399 = arith.extsi %398 : i32 to i64
    %392 = func.call @calloc(%396, %399) : (i64, i64) -> !llvm.ptr
    %400 = llvm.mlir.addressof @g_idx_small : !llvm.ptr
    llvm.store %392, %400 : !llvm.ptr, !llvm.ptr
    %402 = llvm.mlir.addressof @g_root : !llvm.ptr
    %403 = llvm.load %402 : !llvm.ptr -> i64
    %404 = arith.constant 1 : i32
    %406 = arith.extsi %404 : i32 to i64
    %405 = arith.addi %403, %406 : i64
    %407 = arith.constant 8 : i32
    %408 = arith.extsi %407 : i32 to i64
    %401 = func.call @calloc(%405, %408) : (i64, i64) -> !llvm.ptr
    %409 = llvm.mlir.addressof @g_idx_large : !llvm.ptr
    llvm.store %401, %409 : !llvm.ptr, !llvm.ptr
    %410 = arith.constant 0 : i32
    %411 = llvm.load %367 : !llvm.ptr -> i64
    %412 = arith.index_cast %410 : i32 to index
    %413 = arith.index_cast %411 : i32 to index
    %415 = arith.constant 1 : index
    %416 = arith.constant -1 : index
    %417 = arith.cmpi sle, %412, %413 : index
    %414 = arith.select %417, %415, %416 : index
    cf.br ^bb75(%412 : index)
    ^bb75(%418: index):
    %419 = arith.cmpi slt, %418, %413 : index
    %420 = arith.cmpi sgt, %418, %413 : index
    %421 = arith.select %417, %419, %420 : i1
    cf.cond_br %421, ^bb76(%418 : index), ^bb77(%418 : index)
    ^bb76(%422: index):
      %424 = arith.index_cast %422 : index to i64
      %425 = llvm.getelementptr %353[%424] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %423 = llvm.load %425 : !llvm.ptr -> i64
      %426 = llvm.mlir.addressof @g_root : !llvm.ptr
      %427 = llvm.load %426 : !llvm.ptr -> i64
      %428 = arith.cmpi sle, %423, %427 : i64
      cf.cond_br %428, ^bb78, ^bb79
      ^bb78:
        %429 = llvm.mlir.addressof @g_idx_small : !llvm.ptr
        %430 = llvm.load %429 : !llvm.ptr -> !llvm.ptr
        %431 = arith.index_cast %422 : index to i64
        %432 = llvm.getelementptr %430[%423] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %431, %432 : i64, !llvm.ptr
        cf.br ^bb80
      ^bb79:
        %433 = llvm.mlir.addressof @g_idx_large : !llvm.ptr
        %434 = llvm.load %433 : !llvm.ptr -> !llvm.ptr
        %435 = llvm.mlir.addressof @g_N : !llvm.ptr
        %436 = llvm.load %435 : !llvm.ptr -> i64
        %437 = arith.divsi %436, %423 : i64
        %438 = arith.index_cast %422 : index to i64
        %439 = llvm.getelementptr %434[%437] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %438, %439 : i64, !llvm.ptr
        cf.br ^bb80
      ^bb80:
      %440 = arith.addi %422, %414 : index
      cf.br ^bb75(%440 : index)
    ^bb77(%441: index):
    %443 = llvm.load %367 : !llvm.ptr -> i64
    %444 = arith.constant 8 : i32
    %445 = arith.extsi %444 : i32 to i64
    %442 = func.call @calloc(%443, %445) : (i64, i64) -> !llvm.ptr
    %446 = llvm.mlir.addressof @g_prime_sums : !llvm.ptr
    llvm.store %442, %446 : !llvm.ptr, !llvm.ptr
    %447 = arith.constant 0 : i32
    %448 = llvm.load %367 : !llvm.ptr -> i64
    %449 = arith.index_cast %447 : i32 to index
    %450 = arith.index_cast %448 : i32 to index
    %452 = arith.constant 1 : index
    %453 = arith.constant -1 : index
    %454 = arith.cmpi sle, %449, %450 : index
    %451 = arith.select %454, %452, %453 : index
    cf.br ^bb81(%449 : index)
    ^bb81(%455: index):
    %456 = arith.cmpi slt, %455, %450 : index
    %457 = arith.cmpi sgt, %455, %450 : index
    %458 = arith.select %454, %456, %457 : i1
    cf.cond_br %458, ^bb82(%455 : index), ^bb83(%455 : index)
    ^bb82(%459: index):
      %461 = arith.index_cast %459 : index to i64
      %462 = llvm.getelementptr %353[%461] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %460 = llvm.load %462 : !llvm.ptr -> i64
      %463 = arith.extsi %460 : i64 to i128
      %464 = arith.constant 1 : i32
      %466 = arith.extsi %464 : i32 to i64
      %465 = arith.addi %460, %466 : i64
      %467 = arith.extsi %465 : i64 to i128
      %469 = arith.trunci %463 : i128 to i64
      %470 = arith.trunci %467 : i128 to i64
      %468 = arith.muli %469, %470 : i64
      %471 = arith.constant 2 : i32
      %473 = arith.extsi %471 : i32 to i64
      %472 = arith.divsi %468, %473 : i64
      %474 = arith.constant 1 : i32
      %476 = arith.extsi %474 : i32 to i64
      %475 = arith.subi %472, %476 : i64
      %477 = arith.extsi %475 : i64 to i128
      %478 = llvm.mlir.constant(1 : i64) : i64
      %479 = llvm.alloca %478 x i128 : (i64) -> !llvm.ptr
      llvm.store %477, %479 : i128, !llvm.ptr
      %480 = llvm.load %479 : !llvm.ptr -> i128
      %481 = llvm.mlir.addressof @MOD : !llvm.ptr
      %482 = llvm.load %481 : !llvm.ptr -> i64
      %483 = arith.extsi %482 : i64 to i128
      %485 = arith.trunci %480 : i128 to i64
      %486 = arith.trunci %483 : i128 to i64
      %484 = arith.remsi %485, %486 : i64
      %487 = arith.extsi %484 : i64 to i128
      llvm.store %487, %479 : i128, !llvm.ptr
      %488 = llvm.load %479 : !llvm.ptr -> i128
      %489 = arith.trunci %488 : i128 to i64
      %490 = llvm.mlir.addressof @g_prime_sums : !llvm.ptr
      %491 = llvm.load %490 : !llvm.ptr -> !llvm.ptr
      %492 = arith.index_cast %459 : index to i64
      %493 = llvm.getelementptr %491[%492] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %489, %493 : i64, !llvm.ptr
      %494 = arith.addi %459, %451 : index
      cf.br ^bb81(%494 : index)
    ^bb83(%495: index):
    %497 = llvm.mlir.addressof @g_root : !llvm.ptr
    %498 = llvm.load %497 : !llvm.ptr -> i64
    %499 = arith.constant 1 : i32
    %501 = arith.extsi %499 : i32 to i64
    %500 = arith.addi %498, %501 : i64
    %502 = arith.constant 8 : i32
    %503 = arith.extsi %502 : i32 to i64
    %496 = func.call @calloc(%500, %503) : (i64, i64) -> !llvm.ptr
    %505 = llvm.mlir.addressof @g_root : !llvm.ptr
    %506 = llvm.load %505 : !llvm.ptr -> i64
    %507 = arith.constant 10 : i32
    %509 = arith.extsi %507 : i32 to i64
    %508 = arith.divsi %506, %509 : i64
    %510 = arith.constant 100 : i32
    %512 = arith.extsi %510 : i32 to i64
    %511 = arith.addi %508, %512 : i64
    %513 = arith.constant 8 : i32
    %514 = arith.extsi %513 : i32 to i64
    %504 = func.call @calloc(%511, %514) : (i64, i64) -> !llvm.ptr
    %515 = llvm.mlir.addressof @g_primes : !llvm.ptr
    llvm.store %504, %515 : !llvm.ptr, !llvm.ptr
    %516 = arith.constant 0 : i32
    %517 = arith.extsi %516 : i32 to i64
    %518 = llvm.mlir.addressof @g_nprimes : !llvm.ptr
    llvm.store %517, %518 : i64, !llvm.ptr
    %519 = arith.constant 2 : i32
    %520 = llvm.mlir.addressof @g_root : !llvm.ptr
    %521 = llvm.load %520 : !llvm.ptr -> i64
    %522 = arith.constant 1 : i32
    %524 = arith.extsi %522 : i32 to i64
    %523 = arith.addi %521, %524 : i64
    %525 = arith.index_cast %519 : i32 to index
    %526 = arith.index_cast %523 : i32 to index
    %528 = arith.constant 1 : index
    %529 = arith.constant -1 : index
    %530 = arith.cmpi sle, %525, %526 : index
    %527 = arith.select %530, %528, %529 : index
    cf.br ^bb84(%525 : index)
    ^bb84(%531: index):
    %532 = arith.cmpi slt, %531, %526 : index
    %533 = arith.cmpi sgt, %531, %526 : index
    %534 = arith.select %530, %532, %533 : i1
    cf.cond_br %534, ^bb85(%531 : index), ^bb86(%531 : index)
    ^bb85(%535: index):
      %537 = arith.index_cast %535 : index to i64
      %538 = llvm.getelementptr %496[%537] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %536 = llvm.load %538 : !llvm.ptr -> i64
      %539 = arith.constant 0 : i32
      %541 = arith.extsi %539 : i32 to i64
      %540 = arith.cmpi eq, %536, %541 : i64
      cf.cond_br %540, ^bb87, ^bb88
      ^bb87:
        %542 = llvm.mlir.addressof @g_primes : !llvm.ptr
        %543 = llvm.load %542 : !llvm.ptr -> !llvm.ptr
        %544 = llvm.mlir.addressof @g_nprimes : !llvm.ptr
        %545 = llvm.load %544 : !llvm.ptr -> i64
        %546 = arith.index_cast %535 : index to i64
        %547 = llvm.getelementptr %543[%545] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %546, %547 : i64, !llvm.ptr
        %548 = llvm.mlir.addressof @g_nprimes : !llvm.ptr
        %549 = llvm.load %548 : !llvm.ptr -> i64
        %550 = arith.constant 1 : i32
        %552 = arith.extsi %550 : i32 to i64
        %551 = arith.addi %549, %552 : i64
        %553 = llvm.mlir.addressof @g_nprimes : !llvm.ptr
        llvm.store %551, %553 : i64, !llvm.ptr
        %554 = arith.index_cast %535 : index to i64
        %555 = arith.index_cast %535 : index to i64
        %556 = arith.muli %554, %555 : i64
        %557 = llvm.mlir.constant(1 : i64) : i64
        %558 = llvm.alloca %557 x i64 : (i64) -> !llvm.ptr
        llvm.store %556, %558 : i64, !llvm.ptr
        cf.br ^bb90
        ^bb90:
        %559 = llvm.load %558 : !llvm.ptr -> i64
        %560 = llvm.mlir.addressof @g_root : !llvm.ptr
        %561 = llvm.load %560 : !llvm.ptr -> i64
        %562 = arith.cmpi sle, %559, %561 : i64
        cf.cond_br %562, ^bb91, ^bb92
        ^bb91:
          %563 = arith.constant 1 : i32
          %564 = llvm.load %558 : !llvm.ptr -> i64
          %565 = arith.extsi %563 : i32 to i64
          %566 = llvm.getelementptr %496[%564] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          llvm.store %565, %566 : i64, !llvm.ptr
          %567 = llvm.load %558 : !llvm.ptr -> i64
          %569 = arith.trunci %567 : i64 to i32
          %570 = arith.index_cast %535 : index to i32
          %568 = arith.addi %569, %570 : i32
          %571 = arith.extsi %568 : i32 to i64
          llvm.store %571, %558 : i64, !llvm.ptr
          cf.br ^bb90
        ^bb92:
        cf.br ^bb89
      ^bb88:
        cf.br ^bb89
      ^bb89:
      %572 = arith.addi %535, %527 : index
      cf.br ^bb84(%572 : index)
    ^bb86(%573: index):
    func.call @free(%496) : (!llvm.ptr) -> ()
    %575 = arith.constant 0 : i32
    %576 = llvm.mlir.addressof @g_nprimes : !llvm.ptr
    %577 = llvm.load %576 : !llvm.ptr -> i64
    %578 = arith.index_cast %575 : i32 to index
    %579 = arith.index_cast %577 : i32 to index
    %581 = arith.constant 1 : index
    %582 = arith.constant -1 : index
    %583 = arith.cmpi sle, %578, %579 : index
    %580 = arith.select %583, %581, %582 : index
    cf.br ^bb93(%578 : index)
    ^bb93(%584: index):
    %585 = arith.cmpi slt, %584, %579 : index
    %586 = arith.cmpi sgt, %584, %579 : index
    %587 = arith.select %583, %585, %586 : i1
    cf.cond_br %587, ^bb94(%584 : index), ^bb95(%584 : index)
    ^bb94(%588: index):
      %590 = llvm.mlir.addressof @g_primes : !llvm.ptr
      %591 = llvm.load %590 : !llvm.ptr -> !llvm.ptr
      %592 = arith.index_cast %588 : index to i64
      %593 = llvm.getelementptr %591[%592] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %589 = llvm.load %593 : !llvm.ptr -> i64
      %594 = arith.muli %589, %589 : i64
      %595 = llvm.mlir.addressof @g_N : !llvm.ptr
      %596 = llvm.load %595 : !llvm.ptr -> i64
      %597 = arith.cmpi sgt, %594, %596 : i64
      cf.cond_br %597, ^bb96, ^bb97
      ^bb96:
        cf.br ^bb95(%588 : index)
      ^bb97:
        cf.br ^bb98
      ^bb98:
      %598 = arith.constant 0 : i32
      %599 = arith.extsi %598 : i32 to i64
      %600 = llvm.mlir.constant(1 : i64) : i64
      %601 = llvm.alloca %600 x i64 : (i64) -> !llvm.ptr
      llvm.store %599, %601 : i64, !llvm.ptr
      %602 = llvm.load %367 : !llvm.ptr -> i64
      %603 = llvm.mlir.constant(1 : i64) : i64
      %604 = llvm.alloca %603 x i64 : (i64) -> !llvm.ptr
      llvm.store %602, %604 : i64, !llvm.ptr
      cf.br ^bb99
      ^bb99:
      %605 = llvm.load %601 : !llvm.ptr -> i64
      %606 = llvm.load %604 : !llvm.ptr -> i64
      %607 = arith.cmpi slt, %605, %606 : i64
      cf.cond_br %607, ^bb100, ^bb101
      ^bb100:
        %608 = llvm.load %601 : !llvm.ptr -> i64
        %609 = llvm.load %604 : !llvm.ptr -> i64
        %610 = arith.addi %608, %609 : i64
        %611 = arith.constant 2 : i32
        %613 = arith.extsi %611 : i32 to i64
        %612 = arith.divsi %610, %613 : i64
        %615 = llvm.getelementptr %353[%612] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %614 = llvm.load %615 : !llvm.ptr -> i64
        %616 = arith.cmpi sge, %614, %594 : i64
        cf.cond_br %616, ^bb102, ^bb103
        ^bb102:
          %617 = arith.constant 1 : i32
          %619 = arith.extsi %617 : i32 to i64
          %618 = arith.addi %612, %619 : i64
          llvm.store %618, %601 : i64, !llvm.ptr
          cf.br ^bb104
        ^bb103:
          llvm.store %612, %604 : i64, !llvm.ptr
          cf.br ^bb104
        ^bb104:
        cf.br ^bb99
      ^bb101:
      %620 = llvm.load %601 : !llvm.ptr -> i64
      %621 = arith.constant 0 : i32
      %623 = arith.extsi %621 : i32 to i64
      %622 = arith.cmpi eq, %620, %623 : i64
      cf.cond_br %622, ^bb105, ^bb106
      ^bb105:
        %624 = arith.addi %588, %580 : index
        cf.br ^bb93(%624 : index)
      ^bb106:
        cf.br ^bb107
      ^bb107:
      %626 = llvm.mlir.addressof @g_idx_small : !llvm.ptr
      %627 = llvm.load %626 : !llvm.ptr -> !llvm.ptr
      %628 = arith.constant 1 : i32
      %630 = arith.extsi %628 : i32 to i64
      %629 = arith.subi %589, %630 : i64
      %631 = llvm.getelementptr %627[%629] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %625 = llvm.load %631 : !llvm.ptr -> i64
      %633 = llvm.mlir.addressof @g_prime_sums : !llvm.ptr
      %634 = llvm.load %633 : !llvm.ptr -> !llvm.ptr
      %635 = llvm.getelementptr %634[%625] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %632 = llvm.load %635 : !llvm.ptr -> i64
      %636 = arith.constant 0 : i32
      %637 = arith.index_cast %636 : i32 to index
      %638 = arith.index_cast %620 : i32 to index
      %640 = arith.constant 1 : index
      %641 = arith.constant -1 : index
      %642 = arith.cmpi sle, %637, %638 : index
      %639 = arith.select %642, %640, %641 : index
      cf.br ^bb108(%637 : index)
      ^bb108(%643: index):
      %644 = arith.cmpi slt, %643, %638 : index
      %645 = arith.cmpi sgt, %643, %638 : index
      %646 = arith.select %642, %644, %645 : i1
      cf.cond_br %646, ^bb109(%643 : index), ^bb110(%643 : index)
      ^bb109(%647: index):
        %649 = arith.index_cast %647 : index to i64
        %650 = llvm.getelementptr %353[%649] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %648 = llvm.load %650 : !llvm.ptr -> i64
        %651 = arith.divsi %648, %589 : i64
        %652 = llvm.mlir.undef : i64
        %653 = llvm.mlir.addressof @g_root : !llvm.ptr
        %654 = llvm.load %653 : !llvm.ptr -> i64
        %655 = arith.cmpi sle, %651, %654 : i64
        %656 = scf.if %655 -> (i64) {
          %658 = llvm.mlir.addressof @g_idx_small : !llvm.ptr
          %659 = llvm.load %658 : !llvm.ptr -> !llvm.ptr
          %660 = llvm.getelementptr %659[%651] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %657 = llvm.load %660 : !llvm.ptr -> i64
          scf.yield %657 : i64
        } else {
          %662 = llvm.mlir.addressof @g_idx_large : !llvm.ptr
          %663 = llvm.load %662 : !llvm.ptr -> !llvm.ptr
          %664 = llvm.mlir.addressof @g_N : !llvm.ptr
          %665 = llvm.load %664 : !llvm.ptr -> i64
          %666 = arith.divsi %665, %651 : i64
          %667 = llvm.getelementptr %663[%666] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %661 = llvm.load %667 : !llvm.ptr -> i64
          scf.yield %661 : i64
        }
        %668 = arith.extsi %589 : i64 to i128
        %670 = llvm.mlir.addressof @g_prime_sums : !llvm.ptr
        %671 = llvm.load %670 : !llvm.ptr -> !llvm.ptr
        %672 = llvm.getelementptr %671[%656] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %669 = llvm.load %672 : !llvm.ptr -> i64
        %673 = arith.subi %669, %632 : i64
        %674 = arith.extsi %673 : i64 to i128
        %676 = arith.trunci %668 : i128 to i64
        %677 = arith.trunci %674 : i128 to i64
        %675 = arith.muli %676, %677 : i64
        %678 = arith.extsi %675 : i64 to i128
        %679 = llvm.mlir.constant(1 : i64) : i64
        %680 = llvm.alloca %679 x i128 : (i64) -> !llvm.ptr
        llvm.store %678, %680 : i128, !llvm.ptr
        %681 = llvm.load %680 : !llvm.ptr -> i128
        %682 = llvm.mlir.addressof @MOD : !llvm.ptr
        %683 = llvm.load %682 : !llvm.ptr -> i64
        %684 = arith.extsi %683 : i64 to i128
        %686 = arith.trunci %681 : i128 to i64
        %687 = arith.trunci %684 : i128 to i64
        %685 = arith.remsi %686, %687 : i64
        %688 = arith.extsi %685 : i64 to i128
        llvm.store %688, %680 : i128, !llvm.ptr
        %690 = llvm.mlir.addressof @g_prime_sums : !llvm.ptr
        %691 = llvm.load %690 : !llvm.ptr -> !llvm.ptr
        %692 = arith.index_cast %647 : index to i64
        %693 = llvm.getelementptr %691[%692] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %689 = llvm.load %693 : !llvm.ptr -> i64
        %694 = arith.extsi %689 : i64 to i128
        %695 = llvm.load %680 : !llvm.ptr -> i128
        %697 = arith.trunci %694 : i128 to i64
        %698 = arith.trunci %695 : i128 to i64
        %696 = arith.subi %697, %698 : i64
        %699 = arith.extsi %696 : i64 to i128
        %700 = llvm.mlir.constant(1 : i64) : i64
        %701 = llvm.alloca %700 x i128 : (i64) -> !llvm.ptr
        llvm.store %699, %701 : i128, !llvm.ptr
        %702 = llvm.load %701 : !llvm.ptr -> i128
        %703 = llvm.mlir.addressof @MOD : !llvm.ptr
        %704 = llvm.load %703 : !llvm.ptr -> i64
        %705 = arith.extsi %704 : i64 to i128
        %707 = arith.trunci %702 : i128 to i64
        %708 = arith.trunci %705 : i128 to i64
        %706 = arith.remsi %707, %708 : i64
        %709 = arith.extsi %706 : i64 to i128
        llvm.store %709, %701 : i128, !llvm.ptr
        %710 = llvm.load %701 : !llvm.ptr -> i128
        %711 = arith.constant 0 : i32
        %713 = arith.trunci %710 : i128 to i64
        %714 = arith.extsi %711 : i32 to i64
        %712 = arith.cmpi slt, %713, %714 : i64
        cf.cond_br %712, ^bb111, ^bb112
        ^bb111:
          %715 = llvm.load %701 : !llvm.ptr -> i128
          %716 = llvm.mlir.addressof @MOD : !llvm.ptr
          %717 = llvm.load %716 : !llvm.ptr -> i64
          %718 = arith.extsi %717 : i64 to i128
          %720 = arith.trunci %715 : i128 to i64
          %721 = arith.trunci %718 : i128 to i64
          %719 = arith.addi %720, %721 : i64
          %722 = arith.extsi %719 : i64 to i128
          llvm.store %722, %701 : i128, !llvm.ptr
          cf.br ^bb113
        ^bb112:
          cf.br ^bb113
        ^bb113:
        %723 = llvm.load %701 : !llvm.ptr -> i128
        %724 = arith.trunci %723 : i128 to i64
        %725 = llvm.mlir.addressof @g_prime_sums : !llvm.ptr
        %726 = llvm.load %725 : !llvm.ptr -> !llvm.ptr
        %727 = arith.index_cast %647 : index to i64
        %728 = llvm.getelementptr %726[%727] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %724, %728 : i64, !llvm.ptr
        %729 = arith.addi %647, %639 : index
        cf.br ^bb108(%729 : index)
      ^bb110(%730: index):
      %731 = arith.addi %588, %580 : index
      cf.br ^bb93(%731 : index)
    ^bb95(%732: index):
    %734 = llvm.mlir.addressof @g_root : !llvm.ptr
    %735 = llvm.load %734 : !llvm.ptr -> i64
    %736 = arith.constant 1 : i32
    %738 = arith.extsi %736 : i32 to i64
    %737 = arith.addi %735, %738 : i64
    %739 = arith.constant 8 : i32
    %740 = arith.extsi %739 : i32 to i64
    %733 = func.call @calloc(%737, %740) : (i64, i64) -> !llvm.ptr
    %741 = llvm.mlir.addressof @g_pi : !llvm.ptr
    llvm.store %733, %741 : !llvm.ptr, !llvm.ptr
    %742 = arith.constant 0 : i32
    %743 = arith.extsi %742 : i32 to i64
    %744 = llvm.mlir.constant(1 : i64) : i64
    %745 = llvm.alloca %744 x i64 : (i64) -> !llvm.ptr
    llvm.store %743, %745 : i64, !llvm.ptr
    %746 = arith.constant 0 : i32
    %747 = arith.extsi %746 : i32 to i64
    %748 = llvm.mlir.constant(1 : i64) : i64
    %749 = llvm.alloca %748 x i64 : (i64) -> !llvm.ptr
    llvm.store %747, %749 : i64, !llvm.ptr
    %750 = arith.constant 0 : i32
    %751 = llvm.mlir.addressof @g_root : !llvm.ptr
    %752 = llvm.load %751 : !llvm.ptr -> i64
    %753 = arith.constant 1 : i32
    %755 = arith.extsi %753 : i32 to i64
    %754 = arith.addi %752, %755 : i64
    %756 = arith.index_cast %750 : i32 to index
    %757 = arith.index_cast %754 : i32 to index
    %759 = arith.constant 1 : index
    %760 = arith.constant -1 : index
    %761 = arith.cmpi sle, %756, %757 : index
    %758 = arith.select %761, %759, %760 : index
    cf.br ^bb114(%756 : index)
    ^bb114(%762: index):
    %763 = arith.cmpi slt, %762, %757 : index
    %764 = arith.cmpi sgt, %762, %757 : index
    %765 = arith.select %761, %763, %764 : i1
    cf.cond_br %765, ^bb115(%762 : index), ^bb116(%762 : index)
    ^bb115(%766: index):
      %767 = llvm.load %749 : !llvm.ptr -> i64
      %768 = llvm.mlir.addressof @g_nprimes : !llvm.ptr
      %769 = llvm.load %768 : !llvm.ptr -> i64
      %770 = arith.cmpi slt, %767, %769 : i64
      %771 = scf.if %770 -> (i1) {
        %773 = llvm.mlir.addressof @g_primes : !llvm.ptr
        %774 = llvm.load %773 : !llvm.ptr -> !llvm.ptr
        %775 = llvm.load %749 : !llvm.ptr -> i64
        %776 = llvm.getelementptr %774[%775] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %772 = llvm.load %776 : !llvm.ptr -> i64
        %778 = arith.trunci %772 : i64 to i32
        %779 = arith.index_cast %766 : index to i32
        %777 = arith.cmpi eq, %778, %779 : i32
        scf.yield %777 : i1
      } else {
        %780 = arith.constant false
        scf.yield %780 : i1
      }
      cf.cond_br %771, ^bb117, ^bb118
      ^bb117:
        %781 = llvm.load %745 : !llvm.ptr -> i64
        %782 = arith.constant 1 : i32
        %784 = arith.extsi %782 : i32 to i64
        %783 = arith.addi %781, %784 : i64
        llvm.store %783, %745 : i64, !llvm.ptr
        %785 = llvm.load %749 : !llvm.ptr -> i64
        %786 = arith.constant 1 : i32
        %788 = arith.extsi %786 : i32 to i64
        %787 = arith.addi %785, %788 : i64
        llvm.store %787, %749 : i64, !llvm.ptr
        cf.br ^bb119
      ^bb118:
        cf.br ^bb119
      ^bb119:
      %789 = llvm.load %745 : !llvm.ptr -> i64
      %790 = llvm.mlir.addressof @g_pi : !llvm.ptr
      %791 = llvm.load %790 : !llvm.ptr -> !llvm.ptr
      %792 = arith.index_cast %766 : index to i64
      %793 = llvm.getelementptr %791[%792] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %789, %793 : i64, !llvm.ptr
      %794 = arith.addi %766, %758 : index
      cf.br ^bb114(%794 : index)
    ^bb116(%795: index):
    %797 = llvm.mlir.addressof @g_nprimes : !llvm.ptr
    %798 = llvm.load %797 : !llvm.ptr -> i64
    %799 = arith.constant 1 : i32
    %801 = arith.extsi %799 : i32 to i64
    %800 = arith.addi %798, %801 : i64
    %802 = arith.constant 8 : i32
    %803 = arith.extsi %802 : i32 to i64
    %796 = func.call @calloc(%800, %803) : (i64, i64) -> !llvm.ptr
    %804 = llvm.mlir.addressof @g_lower_prime_sum : !llvm.ptr
    llvm.store %796, %804 : !llvm.ptr, !llvm.ptr
    %805 = arith.constant 0 : i32
    %806 = llvm.mlir.addressof @g_nprimes : !llvm.ptr
    %807 = llvm.load %806 : !llvm.ptr -> i64
    %808 = arith.index_cast %805 : i32 to index
    %809 = arith.index_cast %807 : i32 to index
    %811 = arith.constant 1 : index
    %812 = arith.constant -1 : index
    %813 = arith.cmpi sle, %808, %809 : index
    %810 = arith.select %813, %811, %812 : index
    cf.br ^bb120(%808 : index)
    ^bb120(%814: index):
    %815 = arith.cmpi slt, %814, %809 : index
    %816 = arith.cmpi sgt, %814, %809 : index
    %817 = arith.select %813, %815, %816 : i1
    cf.cond_br %817, ^bb121(%814 : index), ^bb122(%814 : index)
    ^bb121(%818: index):
      %820 = llvm.mlir.addressof @g_primes : !llvm.ptr
      %821 = llvm.load %820 : !llvm.ptr -> !llvm.ptr
      %822 = arith.index_cast %818 : index to i64
      %823 = llvm.getelementptr %821[%822] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %819 = llvm.load %823 : !llvm.ptr -> i64
      %825 = llvm.mlir.addressof @g_prime_sums : !llvm.ptr
      %826 = llvm.load %825 : !llvm.ptr -> !llvm.ptr
      %828 = llvm.mlir.addressof @g_idx_small : !llvm.ptr
      %829 = llvm.load %828 : !llvm.ptr -> !llvm.ptr
      %830 = arith.constant 1 : i32
      %832 = arith.extsi %830 : i32 to i64
      %831 = arith.subi %819, %832 : i64
      %833 = llvm.getelementptr %829[%831] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %827 = llvm.load %833 : !llvm.ptr -> i64
      %834 = llvm.getelementptr %826[%827] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %824 = llvm.load %834 : !llvm.ptr -> i64
      %835 = llvm.mlir.addressof @g_lower_prime_sum : !llvm.ptr
      %836 = llvm.load %835 : !llvm.ptr -> !llvm.ptr
      %837 = arith.index_cast %818 : index to i64
      %838 = llvm.getelementptr %836[%837] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %824, %838 : i64, !llvm.ptr
      %839 = arith.addi %818, %810 : index
      cf.br ^bb120(%839 : index)
    ^bb122(%840: index):
    %842 = llvm.mlir.addressof @g_prime_sums : !llvm.ptr
    %843 = llvm.load %842 : !llvm.ptr -> !llvm.ptr
    %845 = llvm.mlir.addressof @g_idx_small : !llvm.ptr
    %846 = llvm.load %845 : !llvm.ptr -> !llvm.ptr
    %848 = llvm.mlir.addressof @g_primes : !llvm.ptr
    %849 = llvm.load %848 : !llvm.ptr -> !llvm.ptr
    %850 = llvm.mlir.addressof @g_nprimes : !llvm.ptr
    %851 = llvm.load %850 : !llvm.ptr -> i64
    %852 = arith.constant 1 : i32
    %854 = arith.extsi %852 : i32 to i64
    %853 = arith.subi %851, %854 : i64
    %855 = llvm.getelementptr %849[%853] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %847 = llvm.load %855 : !llvm.ptr -> i64
    %856 = llvm.getelementptr %846[%847] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %844 = llvm.load %856 : !llvm.ptr -> i64
    %857 = llvm.getelementptr %843[%844] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %841 = llvm.load %857 : !llvm.ptr -> i64
    %858 = llvm.mlir.addressof @g_lower_prime_sum : !llvm.ptr
    %859 = llvm.load %858 : !llvm.ptr -> !llvm.ptr
    %860 = llvm.mlir.addressof @g_nprimes : !llvm.ptr
    %861 = llvm.load %860 : !llvm.ptr -> i64
    %862 = llvm.getelementptr %859[%861] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %841, %862 : i64, !llvm.ptr
    %864 = llvm.mlir.addressof @HASH_SIZE : !llvm.ptr
    %865 = llvm.load %864 : !llvm.ptr -> i64
    %866 = arith.constant 8 : i32
    %867 = arith.extsi %866 : i32 to i64
    %863 = func.call @calloc(%865, %867) : (i64, i64) -> !llvm.ptr
    %868 = llvm.mlir.addressof @g_memo_keys : !llvm.ptr
    llvm.store %863, %868 : !llvm.ptr, !llvm.ptr
    %870 = llvm.mlir.addressof @HASH_SIZE : !llvm.ptr
    %871 = llvm.load %870 : !llvm.ptr -> i64
    %872 = arith.constant 8 : i32
    %873 = arith.extsi %872 : i32 to i64
    %869 = func.call @calloc(%871, %873) : (i64, i64) -> !llvm.ptr
    %874 = llvm.mlir.addressof @g_memo_vals : !llvm.ptr
    llvm.store %869, %874 : !llvm.ptr, !llvm.ptr
    %876 = llvm.mlir.addressof @g_N : !llvm.ptr
    %877 = llvm.load %876 : !llvm.ptr -> i64
    %878 = arith.constant 0 : i32
    %879 = arith.extsi %878 : i32 to i64
    %875 = func.call @contribution(%877, %879) : (i64, i64) -> i64
    %880 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %881 = llvm.call @printf(%880, %875) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    %883 = llvm.mlir.addressof @g_memo_vals : !llvm.ptr
    %884 = llvm.load %883 : !llvm.ptr -> !llvm.ptr
    func.call @free(%884) : (!llvm.ptr) -> ()
    %886 = llvm.mlir.addressof @g_memo_keys : !llvm.ptr
    %887 = llvm.load %886 : !llvm.ptr -> !llvm.ptr
    func.call @free(%887) : (!llvm.ptr) -> ()
    %889 = llvm.mlir.addressof @g_lower_prime_sum : !llvm.ptr
    %890 = llvm.load %889 : !llvm.ptr -> !llvm.ptr
    func.call @free(%890) : (!llvm.ptr) -> ()
    %892 = llvm.mlir.addressof @g_pi : !llvm.ptr
    %893 = llvm.load %892 : !llvm.ptr -> !llvm.ptr
    func.call @free(%893) : (!llvm.ptr) -> ()
    %895 = llvm.mlir.addressof @g_primes : !llvm.ptr
    %896 = llvm.load %895 : !llvm.ptr -> !llvm.ptr
    func.call @free(%896) : (!llvm.ptr) -> ()
    %898 = llvm.mlir.addressof @g_prime_sums : !llvm.ptr
    %899 = llvm.load %898 : !llvm.ptr -> !llvm.ptr
    func.call @free(%899) : (!llvm.ptr) -> ()
    %901 = llvm.mlir.addressof @g_idx_large : !llvm.ptr
    %902 = llvm.load %901 : !llvm.ptr -> !llvm.ptr
    func.call @free(%902) : (!llvm.ptr) -> ()
    %904 = llvm.mlir.addressof @g_idx_small : !llvm.ptr
    %905 = llvm.load %904 : !llvm.ptr -> !llvm.ptr
    func.call @free(%905) : (!llvm.ptr) -> ()
    func.call @free(%353) : (!llvm.ptr) -> ()
    %907 = arith.constant 0 : i32
    func.return %907 : i32
  }
}