Problem 708

S(N) = sum_{n<=N} 2^{Omega(n)}, computed for N = 10^14. Identity: 2^{Omega(n)} = sum_{d|n, d powerful} g(d), where a powerful number d = prod p_i^{e_i} (e_i >= 2) carries weight g(d) = prod 2^{e_i - 2}. Then S(N) = sum_{d powerful, d<=N} g(d) * D(N/d), where D(x) = sum_{k<=x} tau(k) = #{(a,b): a*b <= x} = 2*sum_{i<=s} floor(x/i) - s^2, s = isqrt(x). Small x use a precomputed prefix of tau; large x are cached.

Answer28874142998632109
Output28874142998632109
StatusPASS
Native helperno
Runtime1660 ms
Peak memory35696 KB
Time complexityO(n log n) (estimated)
Space complexityO(n^2) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n log n)?
Space complexityO(n^2)?
ApproachFlow solutionNot curated
VerdictUnknown

Flow source

# Project Euler 708: Twos Are All You Need
# S(N) = sum_{n<=N} 2^{Omega(n)}, computed for N = 10^14.
#
# Identity: 2^{Omega(n)} = sum_{d|n, d powerful} g(d), where a powerful number
# d = prod p_i^{e_i} (e_i >= 2) carries weight g(d) = prod 2^{e_i - 2}.
# Then S(N) = sum_{d powerful, d<=N} g(d) * D(N/d), where
# D(x) = sum_{k<=x} tau(k) = #{(a,b): a*b <= x} = 2*sum_{i<=s} floor(x/i) - s^2,
# s = isqrt(x). Small x use a precomputed prefix of tau; large x are cached.

import euler.nt { isqrt }

extern {
    function calloc(n: i64, size: i64) -> ptr<void>
    function free(p: ptr<void>) -> void
    function malloc(n: i64) -> ptr<void>
    function memset(dst: ptr<void>, val: i32, n: i64) -> ptr<void>
    function sqrt(x: f64) -> f64
}

const N_VAL: i64 = 100000000000000
const SMALL_LIMIT: i64 = 1000000
const CACHE_BITS: i64 = 17
const CACHE_SIZE: i64 = 131072
const CACHE_MASK: i64 = 131071

let mut g_primes: ptr<i32> = null
let mut g_prime_sq: ptr<i64> = null
let mut g_nprimes: i64 = 0
let mut g_prefix: ptr<i64> = null
let mut g_N: i64 = 0
let mut g_total: i64 = 0

let mut cache_key: ptr<i64> = null
let mut cache_val: ptr<i64> = null
let mut cache_used: ptr<i8> = null

function isqrt_i64(n: i64) -> i64 {
    if n <= 0 { return 0 }
    let mut x: i64 = sqrt(n as f64) as i64
    while x > 0 && x * x > n {
        x = x - 1
    }
    while (x + 1) * (x + 1) <= n {
        x = x + 1
    }
    return x
}

# Odd-only sieve; returns malloc'd prime list (2, 3, 5, ...).
function primes_upto(limit: i64) -> ptr<i32> {
    if limit < 2 { return null }
    let size: i64 = limit / 2 + 1
    let sieve: ptr<i8> = malloc(size) as ptr<i8>
    memset(sieve, 1, size)
    sieve[0] = 0

    let r: i64 = isqrt_i64(limit)
    let mut p: i64 = 3
    while p <= r {
        if sieve[p / 2] != 0 {
            let start: i64 = p * p
            let mut j: i64 = start
            while j <= limit {
                sieve[j / 2] = 0
                j = j + 2 * p
            }
        }
        p = p + 2
    }

    let mut cnt: i64 = 1
    let mut i: i64 = 1
    while i < size {
        if sieve[i] != 0 { cnt = cnt + 1 }
        i = i + 1
    }

    let primes: ptr<i32> = malloc(cnt * 4) as ptr<i32>
    primes[0] = 2
    let mut k: i64 = 1
    i = 1
    while i < size {
        if sieve[i] != 0 {
            primes[k] = (2 * i + 1) as i32
            k = k + 1
        }
        i = i + 1
    }
    free(sieve)
    g_nprimes = cnt
    return primes
}

# Prefix sums of tau(k) (number of divisors) for k = 1..limit.
function build_divisor_prefix(limit: i64) -> ptr<i64> {
    let spf: ptr<i32> = calloc(limit + 1, 4) as ptr<i32>
    let mut i: i64 = 2
    while i <= limit {
        if spf[i] == 0 {
            spf[i] = i as i32
            if i * i <= limit {
                let mut j: i64 = i * i
                while j <= limit {
                    if spf[j] == 0 { spf[j] = i as i32 }
                    j = j + i
                }
            }
        }
        i = i + 1
    }

    let d: ptr<i32> = calloc(limit + 1, 4) as ptr<i32>
    let exp: ptr<i32> = calloc(limit + 1, 4) as ptr<i32>
    d[1] = 1
    i = 2
    while i <= limit {
        let p: i32 = spf[i]
        let m: i64 = i / (p as i64)
        if m % (p as i64) == 0 {
            exp[i] = exp[m] + 1
            d[i] = d[m] / (exp[m] + 1) * (exp[i] + 1)
        } else {
            exp[i] = 1
            d[i] = d[m] * 2
        }
        i = i + 1
    }

    let prefix: ptr<i64> = calloc(limit + 1, 8) as ptr<i64>
    let mut total: i64 = 0
    i = 1
    while i <= limit {
        total = total + (d[i] as i64)
        prefix[i] = total
        i = i + 1
    }
    free(spf)
    free(d)
    free(exp)
    return prefix
}

function D_func(x: i64) -> i64 {
    if x <= SMALL_LIMIT { return g_prefix[x] }

    # Open-addressing hash table lookup
    let h: i64 = (x * 11400714819323198485) >> (64 - CACHE_BITS)
    let mut idx: i64 = h & CACHE_MASK
    while cache_used[idx] != 0 {
        if cache_key[idx] == x { return cache_val[idx] }
        idx = (idx + 1) & CACHE_MASK
    }

    let s: i64 = isqrt_i64(x)
    let mut total: i64 = 0
    let mut i: i64 = 1
    while i <= s {
        let q: i64 = x / i
        let j: i64 = x / q
        let jj: i64 = if j > s { s } else { j }
        total = total + q * (jj - i + 1)
        i = jj + 1
    }
    let res: i64 = 2 * total - s * s
    cache_used[idx] = 1
    cache_key[idx] = x
    cache_val[idx] = res
    return res
}

function dfs(start_idx: i64, current_n: i64, current_g: i64) -> void {
    g_total = g_total + current_g * D_func(g_N / current_n)

    let limit: i64 = g_N / current_n
    let mut i: i64 = start_idx
    while i < g_nprimes {
        let p2: i64 = g_prime_sq[i]
        if p2 > limit {
            i = g_nprimes
        } else {
            let p: i64 = g_primes[i] as i64
            let mut pow_p: i64 = p2
            let mut g: i64 = current_g
            while pow_p <= limit {
                dfs(i + 1, current_n * pow_p, g)
                if pow_p > limit / p {
                    pow_p = limit + 1
                } else {
                    pow_p = pow_p * p
                    g = g << 1
                }
            }
            i = i + 1
        }
    }
}

function main() -> i32 {
    let prime_limit: i64 = isqrt_i64(N_VAL)
    g_primes = primes_upto(prime_limit)

    g_prime_sq = malloc(g_nprimes * 8) as ptr<i64>
    let mut i: i64 = 0
    while i < g_nprimes {
        let p: i64 = g_primes[i] as i64
        g_prime_sq[i] = p * p
        i = i + 1
    }

    g_prefix = build_divisor_prefix(SMALL_LIMIT)

    cache_key = calloc(CACHE_SIZE, 8) as ptr<i64>
    cache_val = calloc(CACHE_SIZE, 8) as ptr<i64>
    cache_used = calloc(CACHE_SIZE, 1) as ptr<i8>

    g_N = N_VAL
    g_total = 0

    dfs(0, 1, 1)

    printf("%lld\n", g_total)

    free(g_primes)
    free(g_prime_sq)
    free(g_prefix)
    free(cache_key)
    free(cache_val)
    free(cache_used)
    return 0
}

Generated C

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

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

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

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

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

#include <math.h>

void* _ui_state = NULL;

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

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

int64_t gcd_i64_i64(int64_t a0, int64_t b0);
int64_t lcm_i64_i64(int64_t a, int64_t b);
int64_t isqrt_i64(int64_t n);
int64_t mulmod_i64_i64_i64(int64_t a0, int64_t b0, int64_t mod);
int64_t mod_pow_i64_i64_i64(int64_t base, int64_t exp, int64_t mod);
bool is_prime_i64(int64_t n);
int64_t isqrt_i64_i64(int64_t n);
int32_t* primes_upto_i64(int64_t limit);
int64_t* build_divisor_prefix_i64(int64_t limit);
int64_t D_func_i64(int64_t x);
void dfs_i64_i64_i64(int64_t start_idx, int64_t current_n, int64_t current_g);
int32_t main(void);

static const int64_t N_VAL = 100000000000000;
static const int64_t SMALL_LIMIT = 1000000;
static const int64_t CACHE_BITS = 17;
static const int64_t CACHE_SIZE = 131072;
static const int64_t CACHE_MASK = 131071;

/* Module statics */
static int32_t* g_primes = NULL;
static int64_t* g_prime_sq = NULL;
static int64_t g_nprimes = 0;
static int64_t* g_prefix = NULL;
static int64_t g_N = 0;
static int64_t g_total = 0;
static int64_t* cache_key = NULL;
static int64_t* cache_val = NULL;
static int8_t* cache_used = 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 isqrt_i64_i64(int64_t n) {
    if (n <= 0) {
        return 0;
    }
    int64_t x = ((int64_t)(sqrt(((double)(n)))));
    while ((x > 0 && (x * x) > n)) {
        x = (x - 1);
    }
    while (((x + 1) * (x + 1)) <= n) {
        x = (x + 1);
    }
    return x;
}

int32_t* primes_upto_i64(int64_t limit) {
    if (limit < 2) {
        return NULL;
    }
    int64_t size = (FLOW_CHECKED_DIV((limit), (2)) + 1);
    int8_t* sieve = (int8_t*)(((int8_t*)(malloc(size))));
    memset(sieve, 1, size);
    sieve[0] = 0;
    int64_t r = isqrt_i64_i64(limit);
    int64_t p = 3;
    while (p <= r) {
        if (sieve[FLOW_CHECKED_DIV((p), (2))] != 0) {
            int64_t start = (p * p);
            int64_t j = start;
            while (j <= limit) {
                sieve[FLOW_CHECKED_DIV((j), (2))] = 0;
                j = (j + (2 * p));
            }
        }
        p = (p + 2);
    }
    int64_t cnt = 1;
    int64_t i = 1;
    while (i < size) {
        if (sieve[i] != 0) {
            cnt = (cnt + 1);
        }
        i = (i + 1);
    }
    int32_t* primes = (int32_t*)(((int32_t*)(malloc((cnt * 4)))));
    primes[0] = 2;
    int64_t k = 1;
    i = 1;
    while (i < size) {
        if (sieve[i] != 0) {
            primes[k] = ((int32_t)(((2 * i) + 1)));
            k = (k + 1);
        }
        i = (i + 1);
    }
    free(sieve);
    g_nprimes = cnt;
    return primes;
}

int64_t* build_divisor_prefix_i64(int64_t limit) {
    int32_t* spf = (int32_t*)(((int32_t*)(calloc((limit + 1), 4))));
    int64_t i = 2;
    while (i <= limit) {
        if (spf[i] == 0) {
            spf[i] = ((int32_t)(i));
            if ((i * i) <= limit) {
                int64_t j = (i * i);
                while (j <= limit) {
                    if (spf[j] == 0) {
                        spf[j] = ((int32_t)(i));
                    }
                    j = (j + i);
                }
            }
        }
        i = (i + 1);
    }
    int32_t* d = (int32_t*)(((int32_t*)(calloc((limit + 1), 4))));
    int32_t* exp = (int32_t*)(((int32_t*)(calloc((limit + 1), 4))));
    d[1] = 1;
    i = 2;
    while (i <= limit) {
        int32_t p = spf[i];
        int64_t m = FLOW_CHECKED_DIV((i), (((int64_t)(p))));
        if (FLOW_CHECKED_MOD((m), (((int64_t)(p)))) == 0) {
            exp[i] = (exp[m] + 1);
            d[i] = (FLOW_CHECKED_DIV((d[m]), ((exp[m] + 1))) * (exp[i] + 1));
        } else {
            exp[i] = 1;
            d[i] = (d[m] * 2);
        }
        i = (i + 1);
    }
    int64_t* prefix = (int64_t*)(((int64_t*)(calloc((limit + 1), 8))));
    int64_t total = 0;
    i = 1;
    while (i <= limit) {
        total = (total + ((int64_t)(d[i])));
        prefix[i] = total;
        i = (i + 1);
    }
    free(spf);
    free(d);
    free(exp);
    return prefix;
}

int64_t D_func_i64(int64_t x) {
    if (x <= SMALL_LIMIT) {
        return g_prefix[x];
    }
    int64_t h = FLOW_CHECKED_SHR(((x * ((__int128)0x9E3779B97F4A7C15ULL))), ((64 - CACHE_BITS)));
    int64_t idx = (h & CACHE_MASK);
    while (cache_used[idx] != 0) {
        if (cache_key[idx] == x) {
            return cache_val[idx];
        }
        idx = ((idx + 1) & CACHE_MASK);
    }
    int64_t s = isqrt_i64_i64(x);
    int64_t total = 0;
    int64_t i = 1;
    while (i <= s) {
        int64_t q = FLOW_CHECKED_DIV((x), (i));
        int64_t j = FLOW_CHECKED_DIV((x), (q));
        int64_t jj = ((j > s) ? (s) : (j));
        total = (total + (q * ((jj - i) + 1)));
        i = (jj + 1);
    }
    int64_t res = ((2 * total) - (s * s));
    cache_used[idx] = 1;
    cache_key[idx] = x;
    cache_val[idx] = res;
    return res;
}

void dfs_i64_i64_i64(int64_t start_idx, int64_t current_n, int64_t current_g) {
    g_total = (g_total + (current_g * D_func_i64(FLOW_CHECKED_DIV((g_N), (current_n)))));
    int64_t limit = FLOW_CHECKED_DIV((g_N), (current_n));
    int64_t i = start_idx;
    while (i < g_nprimes) {
        int64_t p2 = g_prime_sq[i];
        if (p2 > limit) {
            i = g_nprimes;
        } else {
            int64_t p = ((int64_t)(g_primes[i]));
            int64_t pow_p = p2;
            int64_t g = current_g;
            while (pow_p <= limit) {
                dfs_i64_i64_i64((i + 1), (current_n * pow_p), g);
                if (pow_p > FLOW_CHECKED_DIV((limit), (p))) {
                    pow_p = (limit + 1);
                } else {
                    pow_p = (pow_p * p);
                    g = FLOW_CHECKED_SHL((g), (1));
                }
            }
            i = (i + 1);
        }
    }
}

int32_t main(void) {
    int64_t prime_limit = isqrt_i64_i64(N_VAL);
    g_primes = primes_upto_i64(prime_limit);
    g_prime_sq = ((int64_t*)(malloc((g_nprimes * 8))));
    int64_t i = 0;
    while (i < g_nprimes) {
        int64_t p = ((int64_t)(g_primes[i]));
        g_prime_sq[i] = (p * p);
        i = (i + 1);
    }
    g_prefix = build_divisor_prefix_i64(SMALL_LIMIT);
    cache_key = ((int64_t*)(calloc(CACHE_SIZE, 8)));
    cache_val = ((int64_t*)(calloc(CACHE_SIZE, 8)));
    cache_used = ((int8_t*)(calloc(CACHE_SIZE, 1)));
    g_N = N_VAL;
    g_total = 0;
    dfs_i64_i64_i64(0, 1, 1);
    printf("%lld\n", g_total);
    free(g_primes);
    free(g_prime_sq);
    free(g_prefix);
    free(cache_key);
    free(cache_val);
    free(cache_used);
    return 0;
}

Generated MLIR

module {
  llvm.func @printf(!llvm.ptr, ...) -> i32
  llvm.mlir.global internal constant @str_0("%lld\n\00") {addr_space = 0 : i32} : !llvm.array<6 x i8>
  func.func @gcd(%arg0: i64, %arg1: i64) -> i64 {
    %0 = llvm.mlir.constant(1 : i64) : i64
    %1 = llvm.alloca %0 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %1 : i64, !llvm.ptr
    %2 = llvm.mlir.constant(1 : i64) : i64
    %3 = llvm.alloca %2 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %3 : i64, !llvm.ptr
    cf.br ^bb0
    ^bb0:
    %4 = llvm.load %3 : !llvm.ptr -> i64
    %5 = arith.constant 0 : i32
    %7 = arith.extsi %5 : i32 to i64
    %6 = arith.cmpi ne, %4, %7 : i64
    cf.cond_br %6, ^bb1, ^bb2
    ^bb1:
      %8 = llvm.load %1 : !llvm.ptr -> i64
      %9 = llvm.load %3 : !llvm.ptr -> i64
      %10 = arith.remsi %8, %9 : i64
      %11 = llvm.load %3 : !llvm.ptr -> i64
      llvm.store %11, %1 : i64, !llvm.ptr
      llvm.store %10, %3 : i64, !llvm.ptr
      cf.br ^bb0
    ^bb2:
    %12 = llvm.load %1 : !llvm.ptr -> i64
    func.return %12 : i64
  }
  func.func @lcm(%arg0: i64, %arg1: i64) -> i64 {
    %13 = arith.constant 0 : i32
    %15 = arith.extsi %13 : i32 to i64
    %14 = arith.cmpi eq, %arg0, %15 : i64
    %16 = scf.if %14 -> (i1) {
      %17 = arith.constant true
      scf.yield %17 : i1
    } else {
      %18 = arith.constant 0 : i32
      %20 = arith.extsi %18 : i32 to i64
      %19 = arith.cmpi eq, %arg1, %20 : i64
      scf.yield %19 : i1
    }
    cf.cond_br %16, ^bb3, ^bb4
    ^bb3:
      %21 = arith.constant 0 : i32
      %22 = arith.extsi %21 : i32 to i64
      func.return %22 : i64
    ^bb4:
      cf.br ^bb5
    ^bb5:
    %23 = func.call @gcd(%arg0, %arg1) : (i64, i64) -> i64
    %24 = arith.divsi %arg0, %23 : i64
    %25 = arith.muli %24, %arg1 : i64
    func.return %25 : i64
  }
  func.func @isqrt(%arg0: i64) -> i64 {
    %26 = arith.constant 2 : i32
    %28 = arith.extsi %26 : i32 to i64
    %27 = arith.cmpi slt, %arg0, %28 : i64
    cf.cond_br %27, ^bb6, ^bb7
    ^bb6:
      func.return %arg0 : i64
    ^bb7:
      cf.br ^bb8
    ^bb8:
    %29 = llvm.mlir.constant(1 : i64) : i64
    %30 = llvm.alloca %29 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %30 : i64, !llvm.ptr
    %31 = llvm.load %30 : !llvm.ptr -> i64
    %32 = arith.constant 1 : i32
    %34 = arith.extsi %32 : i32 to i64
    %33 = arith.addi %31, %34 : i64
    %35 = arith.constant 2 : i32
    %37 = arith.extsi %35 : i32 to i64
    %36 = arith.divsi %33, %37 : i64
    %38 = llvm.mlir.constant(1 : i64) : i64
    %39 = llvm.alloca %38 x i64 : (i64) -> !llvm.ptr
    llvm.store %36, %39 : i64, !llvm.ptr
    cf.br ^bb9
    ^bb9:
    %40 = llvm.load %39 : !llvm.ptr -> i64
    %41 = llvm.load %30 : !llvm.ptr -> i64
    %42 = arith.cmpi slt, %40, %41 : i64
    cf.cond_br %42, ^bb10, ^bb11
    ^bb10:
      %43 = llvm.load %39 : !llvm.ptr -> i64
      llvm.store %43, %30 : i64, !llvm.ptr
      %44 = llvm.load %30 : !llvm.ptr -> i64
      %45 = llvm.load %30 : !llvm.ptr -> i64
      %46 = arith.divsi %arg0, %45 : i64
      %47 = arith.addi %44, %46 : i64
      %48 = arith.constant 2 : i32
      %50 = arith.extsi %48 : i32 to i64
      %49 = arith.divsi %47, %50 : i64
      llvm.store %49, %39 : i64, !llvm.ptr
      cf.br ^bb9
    ^bb11:
    %51 = llvm.load %30 : !llvm.ptr -> i64
    func.return %51 : i64
  }
  func.func @mulmod(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %52 = arith.remsi %arg0, %arg2 : i64
    %53 = llvm.mlir.constant(1 : i64) : i64
    %54 = llvm.alloca %53 x i64 : (i64) -> !llvm.ptr
    llvm.store %52, %54 : i64, !llvm.ptr
    %55 = arith.remsi %arg1, %arg2 : i64
    %56 = llvm.mlir.constant(1 : i64) : i64
    %57 = llvm.alloca %56 x i64 : (i64) -> !llvm.ptr
    llvm.store %55, %57 : i64, !llvm.ptr
    %58 = arith.constant 0 : i32
    %59 = arith.extsi %58 : i32 to i64
    %60 = llvm.mlir.constant(1 : i64) : i64
    %61 = llvm.alloca %60 x i64 : (i64) -> !llvm.ptr
    llvm.store %59, %61 : i64, !llvm.ptr
    cf.br ^bb12
    ^bb12:
    %62 = llvm.load %57 : !llvm.ptr -> i64
    %63 = arith.constant 0 : i32
    %65 = arith.extsi %63 : i32 to i64
    %64 = arith.cmpi sgt, %62, %65 : i64
    cf.cond_br %64, ^bb13, ^bb14
    ^bb13:
      %66 = llvm.load %57 : !llvm.ptr -> i64
      %67 = arith.constant 2 : i32
      %69 = arith.extsi %67 : i32 to i64
      %68 = arith.remsi %66, %69 : i64
      %70 = arith.constant 1 : i32
      %72 = arith.extsi %70 : i32 to i64
      %71 = arith.cmpi eq, %68, %72 : i64
      cf.cond_br %71, ^bb15, ^bb16
      ^bb15:
        %73 = llvm.load %61 : !llvm.ptr -> i64
        %74 = llvm.load %54 : !llvm.ptr -> i64
        %75 = arith.addi %73, %74 : i64
        %76 = arith.remsi %75, %arg2 : i64
        llvm.store %76, %61 : i64, !llvm.ptr
        cf.br ^bb17
      ^bb16:
        cf.br ^bb17
      ^bb17:
      %77 = llvm.load %54 : !llvm.ptr -> i64
      %78 = arith.constant 2 : i32
      %80 = arith.extsi %78 : i32 to i64
      %79 = arith.muli %77, %80 : i64
      %81 = arith.remsi %79, %arg2 : i64
      llvm.store %81, %54 : i64, !llvm.ptr
      %82 = llvm.load %57 : !llvm.ptr -> i64
      %83 = arith.constant 2 : i32
      %85 = arith.extsi %83 : i32 to i64
      %84 = arith.divsi %82, %85 : i64
      llvm.store %84, %57 : i64, !llvm.ptr
      cf.br ^bb12
    ^bb14:
    %86 = llvm.load %61 : !llvm.ptr -> i64
    func.return %86 : i64
  }
  func.func @mod_pow(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %87 = arith.constant 1 : i32
    %89 = arith.extsi %87 : i32 to i64
    %88 = arith.cmpi eq, %arg2, %89 : i64
    cf.cond_br %88, ^bb18, ^bb19
    ^bb18:
      %90 = arith.constant 0 : i32
      %91 = arith.extsi %90 : i32 to i64
      func.return %91 : i64
    ^bb19:
      cf.br ^bb20
    ^bb20:
    %92 = arith.constant 1 : i32
    %93 = arith.extsi %92 : i32 to i64
    %94 = llvm.mlir.constant(1 : i64) : i64
    %95 = llvm.alloca %94 x i64 : (i64) -> !llvm.ptr
    llvm.store %93, %95 : i64, !llvm.ptr
    %96 = arith.remsi %arg0, %arg2 : i64
    %97 = llvm.mlir.constant(1 : i64) : i64
    %98 = llvm.alloca %97 x i64 : (i64) -> !llvm.ptr
    llvm.store %96, %98 : i64, !llvm.ptr
    %99 = llvm.mlir.constant(1 : i64) : i64
    %100 = llvm.alloca %99 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %100 : i64, !llvm.ptr
    cf.br ^bb21
    ^bb21:
    %101 = llvm.load %100 : !llvm.ptr -> i64
    %102 = arith.constant 0 : i32
    %104 = arith.extsi %102 : i32 to i64
    %103 = arith.cmpi sgt, %101, %104 : i64
    cf.cond_br %103, ^bb22, ^bb23
    ^bb22:
      %105 = llvm.load %100 : !llvm.ptr -> i64
      %106 = arith.constant 2 : i32
      %108 = arith.extsi %106 : i32 to i64
      %107 = arith.remsi %105, %108 : i64
      %109 = arith.constant 1 : i32
      %111 = arith.extsi %109 : i32 to i64
      %110 = arith.cmpi eq, %107, %111 : i64
      cf.cond_br %110, ^bb24, ^bb25
      ^bb24:
        %113 = llvm.load %95 : !llvm.ptr -> i64
        %114 = llvm.load %98 : !llvm.ptr -> i64
        %112 = func.call @mulmod(%113, %114, %arg2) : (i64, i64, i64) -> i64
        llvm.store %112, %95 : i64, !llvm.ptr
        cf.br ^bb26
      ^bb25:
        cf.br ^bb26
      ^bb26:
      %116 = llvm.load %98 : !llvm.ptr -> i64
      %117 = llvm.load %98 : !llvm.ptr -> i64
      %115 = func.call @mulmod(%116, %117, %arg2) : (i64, i64, i64) -> i64
      llvm.store %115, %98 : i64, !llvm.ptr
      %118 = llvm.load %100 : !llvm.ptr -> i64
      %119 = arith.constant 2 : i32
      %121 = arith.extsi %119 : i32 to i64
      %120 = arith.divsi %118, %121 : i64
      llvm.store %120, %100 : i64, !llvm.ptr
      cf.br ^bb21
    ^bb23:
    %122 = llvm.load %95 : !llvm.ptr -> i64
    func.return %122 : i64
  }
  func.func @is_prime(%arg0: i64) -> i1 {
    %123 = arith.constant 2 : i32
    %125 = arith.extsi %123 : i32 to i64
    %124 = arith.cmpi slt, %arg0, %125 : i64
    cf.cond_br %124, ^bb27, ^bb28
    ^bb27:
      %126 = arith.constant 0 : i1
      func.return %126 : i1
    ^bb28:
      cf.br ^bb29
    ^bb29:
    %127 = arith.constant 4 : i32
    %129 = arith.extsi %127 : i32 to i64
    %128 = arith.cmpi slt, %arg0, %129 : i64
    cf.cond_br %128, ^bb30, ^bb31
    ^bb30:
      %130 = arith.constant 1 : i1
      func.return %130 : i1
    ^bb31:
      cf.br ^bb32
    ^bb32:
    %131 = arith.constant 2 : i32
    %133 = arith.extsi %131 : i32 to i64
    %132 = arith.remsi %arg0, %133 : i64
    %134 = arith.constant 0 : i32
    %136 = arith.extsi %134 : i32 to i64
    %135 = arith.cmpi eq, %132, %136 : i64
    %137 = scf.if %135 -> (i1) {
      %138 = arith.constant true
      scf.yield %138 : i1
    } else {
      %139 = arith.constant 3 : i32
      %141 = arith.extsi %139 : i32 to i64
      %140 = arith.remsi %arg0, %141 : i64
      %142 = arith.constant 0 : i32
      %144 = arith.extsi %142 : i32 to i64
      %143 = arith.cmpi eq, %140, %144 : i64
      scf.yield %143 : i1
    }
    cf.cond_br %137, ^bb33, ^bb34
    ^bb33:
      %145 = arith.constant 0 : i1
      func.return %145 : i1
    ^bb34:
      cf.br ^bb35
    ^bb35:
    %146 = arith.constant 5 : i32
    %147 = arith.extsi %146 : i32 to i64
    %148 = llvm.mlir.constant(1 : i64) : i64
    %149 = llvm.alloca %148 x i64 : (i64) -> !llvm.ptr
    llvm.store %147, %149 : i64, !llvm.ptr
    cf.br ^bb36
    ^bb36:
    %150 = llvm.load %149 : !llvm.ptr -> i64
    %151 = llvm.load %149 : !llvm.ptr -> i64
    %152 = arith.muli %150, %151 : i64
    %153 = arith.cmpi sle, %152, %arg0 : i64
    cf.cond_br %153, ^bb37, ^bb38
    ^bb37:
      %154 = llvm.load %149 : !llvm.ptr -> i64
      %155 = arith.remsi %arg0, %154 : i64
      %156 = arith.constant 0 : i32
      %158 = arith.extsi %156 : i32 to i64
      %157 = arith.cmpi eq, %155, %158 : i64
      %159 = scf.if %157 -> (i1) {
        %160 = arith.constant true
        scf.yield %160 : i1
      } else {
        %161 = llvm.load %149 : !llvm.ptr -> i64
        %162 = arith.constant 2 : i32
        %164 = arith.extsi %162 : i32 to i64
        %163 = arith.addi %161, %164 : i64
        %165 = arith.remsi %arg0, %163 : i64
        %166 = arith.constant 0 : i32
        %168 = arith.extsi %166 : i32 to i64
        %167 = arith.cmpi eq, %165, %168 : i64
        scf.yield %167 : i1
      }
      cf.cond_br %159, ^bb39, ^bb40
      ^bb39:
        %169 = arith.constant 0 : i1
        func.return %169 : i1
      ^bb40:
        cf.br ^bb41
      ^bb41:
      %170 = llvm.load %149 : !llvm.ptr -> i64
      %171 = arith.constant 6 : i32
      %173 = arith.extsi %171 : i32 to i64
      %172 = arith.addi %170, %173 : i64
      llvm.store %172, %149 : i64, !llvm.ptr
      cf.br ^bb36
    ^bb38:
    %174 = arith.constant 1 : i1
    func.return %174 : i1
  }
  func.func private @calloc(i64, i64) -> !llvm.ptr
  func.func private @free(!llvm.ptr) -> ()
  func.func private @malloc(i64) -> !llvm.ptr
  func.func private @memset(!llvm.ptr, i32, i64) -> !llvm.ptr
  func.func private @sqrt(f64) -> f64
  // Constant: N_VAL
  llvm.mlir.global internal constant @N_VAL(100000000000000 : i64) : i64
  // Constant: SMALL_LIMIT
  llvm.mlir.global internal constant @SMALL_LIMIT(1000000 : i64) : i64
  // Constant: CACHE_BITS
  llvm.mlir.global internal constant @CACHE_BITS(17 : i64) : i64
  // Constant: CACHE_SIZE
  llvm.mlir.global internal constant @CACHE_SIZE(131072 : i64) : i64
  // Constant: CACHE_MASK
  llvm.mlir.global internal constant @CACHE_MASK(131071 : 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_prime_sq
  llvm.mlir.global internal @g_prime_sq() {addr_space = 0 : i32} : !llvm.ptr {
    %176 = llvm.mlir.zero : !llvm.ptr
    llvm.return %176 : !llvm.ptr
  }
  // Module static: g_nprimes
  llvm.mlir.global internal @g_nprimes(0 : i64) : i64
  // Module static: g_prefix
  llvm.mlir.global internal @g_prefix() {addr_space = 0 : i32} : !llvm.ptr {
    %177 = llvm.mlir.zero : !llvm.ptr
    llvm.return %177 : !llvm.ptr
  }
  // Module static: g_N
  llvm.mlir.global internal @g_N(0 : i64) : i64
  // Module static: g_total
  llvm.mlir.global internal @g_total(0 : i64) : i64
  // Module static: cache_key
  llvm.mlir.global internal @cache_key() {addr_space = 0 : i32} : !llvm.ptr {
    %178 = llvm.mlir.zero : !llvm.ptr
    llvm.return %178 : !llvm.ptr
  }
  // Module static: cache_val
  llvm.mlir.global internal @cache_val() {addr_space = 0 : i32} : !llvm.ptr {
    %179 = llvm.mlir.zero : !llvm.ptr
    llvm.return %179 : !llvm.ptr
  }
  // Module static: cache_used
  llvm.mlir.global internal @cache_used() {addr_space = 0 : i32} : !llvm.ptr {
    %180 = llvm.mlir.zero : !llvm.ptr
    llvm.return %180 : !llvm.ptr
  }
  func.func @isqrt_i64(%arg0: i64) -> i64 {
    %181 = arith.constant 0 : i32
    %183 = arith.extsi %181 : i32 to i64
    %182 = arith.cmpi sle, %arg0, %183 : i64
    cf.cond_br %182, ^bb42, ^bb43
    ^bb42:
      %184 = arith.constant 0 : i32
      %185 = arith.extsi %184 : i32 to i64
      func.return %185 : i64
    ^bb43:
      cf.br ^bb44
    ^bb44:
    %186 = arith.sitofp %arg0 : i64 to f64
    %187 = math.sqrt %186 : f64
    %188 = arith.fptosi %187 : f64 to i64
    %189 = llvm.mlir.constant(1 : i64) : i64
    %190 = llvm.alloca %189 x i64 : (i64) -> !llvm.ptr
    llvm.store %188, %190 : i64, !llvm.ptr
    cf.br ^bb45
    ^bb45:
    %191 = llvm.load %190 : !llvm.ptr -> i64
    %192 = arith.constant 0 : i32
    %194 = arith.extsi %192 : i32 to i64
    %193 = arith.cmpi sgt, %191, %194 : i64
    %195 = scf.if %193 -> (i1) {
      %196 = llvm.load %190 : !llvm.ptr -> i64
      %197 = llvm.load %190 : !llvm.ptr -> i64
      %198 = arith.muli %196, %197 : i64
      %199 = arith.cmpi sgt, %198, %arg0 : i64
      scf.yield %199 : i1
    } else {
      %200 = arith.constant false
      scf.yield %200 : i1
    }
    cf.cond_br %195, ^bb46, ^bb47
    ^bb46:
      %201 = llvm.load %190 : !llvm.ptr -> i64
      %202 = arith.constant 1 : i32
      %204 = arith.extsi %202 : i32 to i64
      %203 = arith.subi %201, %204 : i64
      llvm.store %203, %190 : i64, !llvm.ptr
      cf.br ^bb45
    ^bb47:
    cf.br ^bb48
    ^bb48:
    %205 = llvm.load %190 : !llvm.ptr -> i64
    %206 = arith.constant 1 : i32
    %208 = arith.extsi %206 : i32 to i64
    %207 = arith.addi %205, %208 : i64
    %209 = llvm.load %190 : !llvm.ptr -> i64
    %210 = arith.constant 1 : i32
    %212 = arith.extsi %210 : i32 to i64
    %211 = arith.addi %209, %212 : i64
    %213 = arith.muli %207, %211 : i64
    %214 = arith.cmpi sle, %213, %arg0 : i64
    cf.cond_br %214, ^bb49, ^bb50
    ^bb49:
      %215 = llvm.load %190 : !llvm.ptr -> i64
      %216 = arith.constant 1 : i32
      %218 = arith.extsi %216 : i32 to i64
      %217 = arith.addi %215, %218 : i64
      llvm.store %217, %190 : i64, !llvm.ptr
      cf.br ^bb48
    ^bb50:
    %219 = llvm.load %190 : !llvm.ptr -> i64
    func.return %219 : i64
  }
  func.func @primes_upto(%arg0: i64) -> !llvm.ptr {
    %220 = arith.constant 2 : i32
    %222 = arith.extsi %220 : i32 to i64
    %221 = arith.cmpi slt, %arg0, %222 : i64
    cf.cond_br %221, ^bb51, ^bb52
    ^bb51:
      %223 = llvm.mlir.zero : !llvm.ptr
      func.return %223 : !llvm.ptr
    ^bb52:
      cf.br ^bb53
    ^bb53:
    %224 = arith.constant 2 : i32
    %226 = arith.extsi %224 : i32 to i64
    %225 = arith.divsi %arg0, %226 : i64
    %227 = arith.constant 1 : i32
    %229 = arith.extsi %227 : i32 to i64
    %228 = arith.addi %225, %229 : i64
    %230 = func.call @malloc(%228) : (i64) -> !llvm.ptr
    %232 = arith.constant 1 : i32
    %231 = func.call @memset(%230, %232, %228) : (!llvm.ptr, i32, i64) -> !llvm.ptr
    %233 = arith.constant 0 : i32
    %234 = arith.constant 0 : i32
    %235 = arith.trunci %233 : i32 to i8
    %236 = arith.extsi %234 : i32 to i64
    %237 = llvm.getelementptr %230[%236] : (!llvm.ptr, i64) -> !llvm.ptr, i8
    llvm.store %235, %237 : i8, !llvm.ptr
    %238 = func.call @isqrt_i64(%arg0) : (i64) -> i64
    %239 = arith.constant 3 : i32
    %240 = arith.extsi %239 : i32 to i64
    %241 = llvm.mlir.constant(1 : i64) : i64
    %242 = llvm.alloca %241 x i64 : (i64) -> !llvm.ptr
    llvm.store %240, %242 : i64, !llvm.ptr
    cf.br ^bb54
    ^bb54:
    %243 = llvm.load %242 : !llvm.ptr -> i64
    %244 = arith.cmpi sle, %243, %238 : i64
    cf.cond_br %244, ^bb55, ^bb56
    ^bb55:
      %246 = llvm.load %242 : !llvm.ptr -> i64
      %247 = arith.constant 2 : i32
      %249 = arith.extsi %247 : i32 to i64
      %248 = arith.divsi %246, %249 : i64
      %250 = llvm.getelementptr %230[%248] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %245 = llvm.load %250 : !llvm.ptr -> i8
      %251 = arith.constant 0 : i32
      %253 = arith.extsi %245 : i8 to i32
      %252 = arith.cmpi ne, %253, %251 : i32
      cf.cond_br %252, ^bb57, ^bb58
      ^bb57:
        %254 = llvm.load %242 : !llvm.ptr -> i64
        %255 = llvm.load %242 : !llvm.ptr -> i64
        %256 = arith.muli %254, %255 : i64
        %257 = llvm.mlir.constant(1 : i64) : i64
        %258 = llvm.alloca %257 x i64 : (i64) -> !llvm.ptr
        llvm.store %256, %258 : i64, !llvm.ptr
        cf.br ^bb60
        ^bb60:
        %259 = llvm.load %258 : !llvm.ptr -> i64
        %260 = arith.cmpi sle, %259, %arg0 : i64
        cf.cond_br %260, ^bb61, ^bb62
        ^bb61:
          %261 = arith.constant 0 : i32
          %262 = llvm.load %258 : !llvm.ptr -> i64
          %263 = arith.constant 2 : i32
          %265 = arith.extsi %263 : i32 to i64
          %264 = arith.divsi %262, %265 : i64
          %266 = arith.trunci %261 : i32 to i8
          %267 = llvm.getelementptr %230[%264] : (!llvm.ptr, i64) -> !llvm.ptr, i8
          llvm.store %266, %267 : i8, !llvm.ptr
          %268 = llvm.load %258 : !llvm.ptr -> i64
          %269 = arith.constant 2 : i32
          %270 = llvm.load %242 : !llvm.ptr -> i64
          %272 = arith.extsi %269 : i32 to i64
          %271 = arith.muli %272, %270 : i64
          %273 = arith.addi %268, %271 : i64
          llvm.store %273, %258 : i64, !llvm.ptr
          cf.br ^bb60
        ^bb62:
        cf.br ^bb59
      ^bb58:
        cf.br ^bb59
      ^bb59:
      %274 = llvm.load %242 : !llvm.ptr -> i64
      %275 = arith.constant 2 : i32
      %277 = arith.extsi %275 : i32 to i64
      %276 = arith.addi %274, %277 : i64
      llvm.store %276, %242 : i64, !llvm.ptr
      cf.br ^bb54
    ^bb56:
    %278 = arith.constant 1 : i32
    %279 = arith.extsi %278 : i32 to i64
    %280 = llvm.mlir.constant(1 : i64) : i64
    %281 = llvm.alloca %280 x i64 : (i64) -> !llvm.ptr
    llvm.store %279, %281 : i64, !llvm.ptr
    %282 = arith.constant 1 : i32
    %283 = arith.extsi %282 : i32 to i64
    %284 = llvm.mlir.constant(1 : i64) : i64
    %285 = llvm.alloca %284 x i64 : (i64) -> !llvm.ptr
    llvm.store %283, %285 : i64, !llvm.ptr
    cf.br ^bb63
    ^bb63:
    %286 = llvm.load %285 : !llvm.ptr -> i64
    %287 = arith.cmpi slt, %286, %228 : i64
    cf.cond_br %287, ^bb64, ^bb65
    ^bb64:
      %289 = llvm.load %285 : !llvm.ptr -> i64
      %290 = llvm.getelementptr %230[%289] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %288 = llvm.load %290 : !llvm.ptr -> i8
      %291 = arith.constant 0 : i32
      %293 = arith.extsi %288 : i8 to i32
      %292 = arith.cmpi ne, %293, %291 : i32
      cf.cond_br %292, ^bb66, ^bb67
      ^bb66:
        %294 = llvm.load %281 : !llvm.ptr -> i64
        %295 = arith.constant 1 : i32
        %297 = arith.extsi %295 : i32 to i64
        %296 = arith.addi %294, %297 : i64
        llvm.store %296, %281 : i64, !llvm.ptr
        cf.br ^bb68
      ^bb67:
        cf.br ^bb68
      ^bb68:
      %298 = llvm.load %285 : !llvm.ptr -> i64
      %299 = arith.constant 1 : i32
      %301 = arith.extsi %299 : i32 to i64
      %300 = arith.addi %298, %301 : i64
      llvm.store %300, %285 : i64, !llvm.ptr
      cf.br ^bb63
    ^bb65:
    %303 = llvm.load %281 : !llvm.ptr -> i64
    %304 = arith.constant 4 : i32
    %306 = arith.extsi %304 : i32 to i64
    %305 = arith.muli %303, %306 : i64
    %302 = func.call @malloc(%305) : (i64) -> !llvm.ptr
    %307 = arith.constant 2 : i32
    %308 = arith.constant 0 : i32
    %309 = arith.extsi %308 : i32 to i64
    %310 = llvm.getelementptr %302[%309] : (!llvm.ptr, i64) -> !llvm.ptr, i32
    llvm.store %307, %310 : i32, !llvm.ptr
    %311 = arith.constant 1 : i32
    %312 = arith.extsi %311 : i32 to i64
    %313 = llvm.mlir.constant(1 : i64) : i64
    %314 = llvm.alloca %313 x i64 : (i64) -> !llvm.ptr
    llvm.store %312, %314 : i64, !llvm.ptr
    %315 = arith.constant 1 : i32
    %316 = arith.extsi %315 : i32 to i64
    llvm.store %316, %285 : i64, !llvm.ptr
    cf.br ^bb69
    ^bb69:
    %317 = llvm.load %285 : !llvm.ptr -> i64
    %318 = arith.cmpi slt, %317, %228 : i64
    cf.cond_br %318, ^bb70, ^bb71
    ^bb70:
      %320 = llvm.load %285 : !llvm.ptr -> i64
      %321 = llvm.getelementptr %230[%320] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %319 = llvm.load %321 : !llvm.ptr -> i8
      %322 = arith.constant 0 : i32
      %324 = arith.extsi %319 : i8 to i32
      %323 = arith.cmpi ne, %324, %322 : i32
      cf.cond_br %323, ^bb72, ^bb73
      ^bb72:
        %325 = arith.constant 2 : i32
        %326 = llvm.load %285 : !llvm.ptr -> i64
        %328 = arith.extsi %325 : i32 to i64
        %327 = arith.muli %328, %326 : i64
        %329 = arith.constant 1 : i32
        %331 = arith.extsi %329 : i32 to i64
        %330 = arith.addi %327, %331 : i64
        %332 = arith.trunci %330 : i64 to i32
        %333 = llvm.load %314 : !llvm.ptr -> i64
        %334 = llvm.getelementptr %302[%333] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %332, %334 : i32, !llvm.ptr
        %335 = llvm.load %314 : !llvm.ptr -> i64
        %336 = arith.constant 1 : i32
        %338 = arith.extsi %336 : i32 to i64
        %337 = arith.addi %335, %338 : i64
        llvm.store %337, %314 : i64, !llvm.ptr
        cf.br ^bb74
      ^bb73:
        cf.br ^bb74
      ^bb74:
      %339 = llvm.load %285 : !llvm.ptr -> i64
      %340 = arith.constant 1 : i32
      %342 = arith.extsi %340 : i32 to i64
      %341 = arith.addi %339, %342 : i64
      llvm.store %341, %285 : i64, !llvm.ptr
      cf.br ^bb69
    ^bb71:
    func.call @free(%230) : (!llvm.ptr) -> ()
    %344 = llvm.load %281 : !llvm.ptr -> i64
    %345 = llvm.mlir.addressof @g_nprimes : !llvm.ptr
    llvm.store %344, %345 : i64, !llvm.ptr
    func.return %302 : !llvm.ptr
  }
  func.func @build_divisor_prefix(%arg0: i64) -> !llvm.ptr {
    %347 = arith.constant 1 : i32
    %349 = arith.extsi %347 : i32 to i64
    %348 = arith.addi %arg0, %349 : i64
    %350 = arith.constant 4 : i32
    %351 = arith.extsi %350 : i32 to i64
    %346 = func.call @calloc(%348, %351) : (i64, i64) -> !llvm.ptr
    %352 = arith.constant 2 : i32
    %353 = arith.extsi %352 : i32 to i64
    %354 = llvm.mlir.constant(1 : i64) : i64
    %355 = llvm.alloca %354 x i64 : (i64) -> !llvm.ptr
    llvm.store %353, %355 : i64, !llvm.ptr
    cf.br ^bb75
    ^bb75:
    %356 = llvm.load %355 : !llvm.ptr -> i64
    %357 = arith.cmpi sle, %356, %arg0 : i64
    cf.cond_br %357, ^bb76, ^bb77
    ^bb76:
      %359 = llvm.load %355 : !llvm.ptr -> i64
      %360 = llvm.getelementptr %346[%359] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %358 = llvm.load %360 : !llvm.ptr -> i32
      %361 = arith.constant 0 : i32
      %362 = arith.cmpi eq, %358, %361 : i32
      cf.cond_br %362, ^bb78, ^bb79
      ^bb78:
        %363 = llvm.load %355 : !llvm.ptr -> i64
        %364 = arith.trunci %363 : i64 to i32
        %365 = llvm.load %355 : !llvm.ptr -> i64
        %366 = llvm.getelementptr %346[%365] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %364, %366 : i32, !llvm.ptr
        %367 = llvm.load %355 : !llvm.ptr -> i64
        %368 = llvm.load %355 : !llvm.ptr -> i64
        %369 = arith.muli %367, %368 : i64
        %370 = arith.cmpi sle, %369, %arg0 : i64
        cf.cond_br %370, ^bb81, ^bb82
        ^bb81:
          %371 = llvm.load %355 : !llvm.ptr -> i64
          %372 = llvm.load %355 : !llvm.ptr -> i64
          %373 = arith.muli %371, %372 : i64
          %374 = llvm.mlir.constant(1 : i64) : i64
          %375 = llvm.alloca %374 x i64 : (i64) -> !llvm.ptr
          llvm.store %373, %375 : i64, !llvm.ptr
          cf.br ^bb84
          ^bb84:
          %376 = llvm.load %375 : !llvm.ptr -> i64
          %377 = arith.cmpi sle, %376, %arg0 : i64
          cf.cond_br %377, ^bb85, ^bb86
          ^bb85:
            %379 = llvm.load %375 : !llvm.ptr -> i64
            %380 = llvm.getelementptr %346[%379] : (!llvm.ptr, i64) -> !llvm.ptr, i32
            %378 = llvm.load %380 : !llvm.ptr -> i32
            %381 = arith.constant 0 : i32
            %382 = arith.cmpi eq, %378, %381 : i32
            cf.cond_br %382, ^bb87, ^bb88
            ^bb87:
              %383 = llvm.load %355 : !llvm.ptr -> i64
              %384 = arith.trunci %383 : i64 to i32
              %385 = llvm.load %375 : !llvm.ptr -> i64
              %386 = llvm.getelementptr %346[%385] : (!llvm.ptr, i64) -> !llvm.ptr, i32
              llvm.store %384, %386 : i32, !llvm.ptr
              cf.br ^bb89
            ^bb88:
              cf.br ^bb89
            ^bb89:
            %387 = llvm.load %375 : !llvm.ptr -> i64
            %388 = llvm.load %355 : !llvm.ptr -> i64
            %389 = arith.addi %387, %388 : i64
            llvm.store %389, %375 : i64, !llvm.ptr
            cf.br ^bb84
          ^bb86:
          cf.br ^bb83
        ^bb82:
          cf.br ^bb83
        ^bb83:
        cf.br ^bb80
      ^bb79:
        cf.br ^bb80
      ^bb80:
      %390 = llvm.load %355 : !llvm.ptr -> i64
      %391 = arith.constant 1 : i32
      %393 = arith.extsi %391 : i32 to i64
      %392 = arith.addi %390, %393 : i64
      llvm.store %392, %355 : i64, !llvm.ptr
      cf.br ^bb75
    ^bb77:
    %395 = arith.constant 1 : i32
    %397 = arith.extsi %395 : i32 to i64
    %396 = arith.addi %arg0, %397 : i64
    %398 = arith.constant 4 : i32
    %399 = arith.extsi %398 : i32 to i64
    %394 = func.call @calloc(%396, %399) : (i64, i64) -> !llvm.ptr
    %401 = arith.constant 1 : i32
    %403 = arith.extsi %401 : i32 to i64
    %402 = arith.addi %arg0, %403 : i64
    %404 = arith.constant 4 : i32
    %405 = arith.extsi %404 : i32 to i64
    %400 = func.call @calloc(%402, %405) : (i64, i64) -> !llvm.ptr
    %406 = arith.constant 1 : i32
    %407 = arith.constant 1 : i32
    %408 = arith.extsi %407 : i32 to i64
    %409 = llvm.getelementptr %394[%408] : (!llvm.ptr, i64) -> !llvm.ptr, i32
    llvm.store %406, %409 : i32, !llvm.ptr
    %410 = arith.constant 2 : i32
    %411 = arith.extsi %410 : i32 to i64
    llvm.store %411, %355 : i64, !llvm.ptr
    cf.br ^bb90
    ^bb90:
    %412 = llvm.load %355 : !llvm.ptr -> i64
    %413 = arith.cmpi sle, %412, %arg0 : i64
    cf.cond_br %413, ^bb91, ^bb92
    ^bb91:
      %415 = llvm.load %355 : !llvm.ptr -> i64
      %416 = llvm.getelementptr %346[%415] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %414 = llvm.load %416 : !llvm.ptr -> i32
      %417 = llvm.load %355 : !llvm.ptr -> i64
      %418 = arith.extsi %414 : i32 to i64
      %419 = arith.divsi %417, %418 : i64
      %420 = arith.extsi %414 : i32 to i64
      %421 = arith.remsi %419, %420 : i64
      %422 = arith.constant 0 : i32
      %424 = arith.extsi %422 : i32 to i64
      %423 = arith.cmpi eq, %421, %424 : i64
      cf.cond_br %423, ^bb93, ^bb94
      ^bb93:
        %426 = llvm.getelementptr %400[%419] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %425 = llvm.load %426 : !llvm.ptr -> i32
        %427 = arith.constant 1 : i32
        %428 = arith.addi %425, %427 : i32
        %429 = llvm.load %355 : !llvm.ptr -> i64
        %430 = llvm.getelementptr %400[%429] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %428, %430 : i32, !llvm.ptr
        %432 = llvm.getelementptr %394[%419] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %431 = llvm.load %432 : !llvm.ptr -> i32
        %434 = llvm.getelementptr %400[%419] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %433 = llvm.load %434 : !llvm.ptr -> i32
        %435 = arith.constant 1 : i32
        %436 = arith.addi %433, %435 : i32
        %437 = arith.divsi %431, %436 : i32
        %439 = llvm.load %355 : !llvm.ptr -> i64
        %440 = llvm.getelementptr %400[%439] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %438 = llvm.load %440 : !llvm.ptr -> i32
        %441 = arith.constant 1 : i32
        %442 = arith.addi %438, %441 : i32
        %443 = arith.muli %437, %442 : i32
        %444 = llvm.load %355 : !llvm.ptr -> i64
        %445 = llvm.getelementptr %394[%444] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %443, %445 : i32, !llvm.ptr
        cf.br ^bb95
      ^bb94:
        %446 = arith.constant 1 : i32
        %447 = llvm.load %355 : !llvm.ptr -> i64
        %448 = llvm.getelementptr %400[%447] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %446, %448 : i32, !llvm.ptr
        %450 = llvm.getelementptr %394[%419] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %449 = llvm.load %450 : !llvm.ptr -> i32
        %451 = arith.constant 2 : i32
        %452 = arith.muli %449, %451 : i32
        %453 = llvm.load %355 : !llvm.ptr -> i64
        %454 = llvm.getelementptr %394[%453] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %452, %454 : i32, !llvm.ptr
        cf.br ^bb95
      ^bb95:
      %455 = llvm.load %355 : !llvm.ptr -> i64
      %456 = arith.constant 1 : i32
      %458 = arith.extsi %456 : i32 to i64
      %457 = arith.addi %455, %458 : i64
      llvm.store %457, %355 : i64, !llvm.ptr
      cf.br ^bb90
    ^bb92:
    %460 = arith.constant 1 : i32
    %462 = arith.extsi %460 : i32 to i64
    %461 = arith.addi %arg0, %462 : i64
    %463 = arith.constant 8 : i32
    %464 = arith.extsi %463 : i32 to i64
    %459 = func.call @calloc(%461, %464) : (i64, i64) -> !llvm.ptr
    %465 = arith.constant 0 : i32
    %466 = arith.extsi %465 : i32 to i64
    %467 = llvm.mlir.constant(1 : i64) : i64
    %468 = llvm.alloca %467 x i64 : (i64) -> !llvm.ptr
    llvm.store %466, %468 : i64, !llvm.ptr
    %469 = arith.constant 1 : i32
    %470 = arith.extsi %469 : i32 to i64
    llvm.store %470, %355 : i64, !llvm.ptr
    cf.br ^bb96
    ^bb96:
    %471 = llvm.load %355 : !llvm.ptr -> i64
    %472 = arith.cmpi sle, %471, %arg0 : i64
    cf.cond_br %472, ^bb97, ^bb98
    ^bb97:
      %473 = llvm.load %468 : !llvm.ptr -> i64
      %475 = llvm.load %355 : !llvm.ptr -> i64
      %476 = llvm.getelementptr %394[%475] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %474 = llvm.load %476 : !llvm.ptr -> i32
      %477 = arith.extsi %474 : i32 to i64
      %478 = arith.addi %473, %477 : i64
      llvm.store %478, %468 : i64, !llvm.ptr
      %479 = llvm.load %468 : !llvm.ptr -> i64
      %480 = llvm.load %355 : !llvm.ptr -> i64
      %481 = llvm.getelementptr %459[%480] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %479, %481 : i64, !llvm.ptr
      %482 = llvm.load %355 : !llvm.ptr -> i64
      %483 = arith.constant 1 : i32
      %485 = arith.extsi %483 : i32 to i64
      %484 = arith.addi %482, %485 : i64
      llvm.store %484, %355 : i64, !llvm.ptr
      cf.br ^bb96
    ^bb98:
    func.call @free(%346) : (!llvm.ptr) -> ()
    func.call @free(%394) : (!llvm.ptr) -> ()
    func.call @free(%400) : (!llvm.ptr) -> ()
    func.return %459 : !llvm.ptr
  }
  func.func @D_func(%arg0: i64) -> i64 {
    %489 = llvm.mlir.addressof @SMALL_LIMIT : !llvm.ptr
    %490 = llvm.load %489 : !llvm.ptr -> i64
    %491 = arith.cmpi sle, %arg0, %490 : i64
    cf.cond_br %491, ^bb99, ^bb100
    ^bb99:
      %493 = llvm.mlir.addressof @g_prefix : !llvm.ptr
      %494 = llvm.load %493 : !llvm.ptr -> !llvm.ptr
      %495 = llvm.getelementptr %494[%arg0] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %492 = llvm.load %495 : !llvm.ptr -> i64
      func.return %492 : i64
    ^bb100:
      cf.br ^bb101
    ^bb101:
    %496 = arith.constant 11400714815028231189 : i32
    %498 = arith.extsi %496 : i32 to i64
    %497 = arith.muli %arg0, %498 : i64
    %499 = arith.constant 64 : i32
    %500 = llvm.mlir.addressof @CACHE_BITS : !llvm.ptr
    %501 = llvm.load %500 : !llvm.ptr -> i64
    %503 = arith.extsi %499 : i32 to i64
    %502 = arith.subi %503, %501 : i64
    %504 = arith.shrsi %497, %502 : i64
    %505 = llvm.mlir.addressof @CACHE_MASK : !llvm.ptr
    %506 = llvm.load %505 : !llvm.ptr -> i64
    %507 = arith.andi %504, %506 : i64
    %508 = llvm.mlir.constant(1 : i64) : i64
    %509 = llvm.alloca %508 x i64 : (i64) -> !llvm.ptr
    llvm.store %507, %509 : i64, !llvm.ptr
    cf.br ^bb102
    ^bb102:
    %511 = llvm.mlir.addressof @cache_used : !llvm.ptr
    %512 = llvm.load %511 : !llvm.ptr -> !llvm.ptr
    %513 = llvm.load %509 : !llvm.ptr -> i64
    %514 = llvm.getelementptr %512[%513] : (!llvm.ptr, i64) -> !llvm.ptr, i8
    %510 = llvm.load %514 : !llvm.ptr -> i8
    %515 = arith.constant 0 : i32
    %517 = arith.extsi %510 : i8 to i32
    %516 = arith.cmpi ne, %517, %515 : i32
    cf.cond_br %516, ^bb103, ^bb104
    ^bb103:
      %519 = llvm.mlir.addressof @cache_key : !llvm.ptr
      %520 = llvm.load %519 : !llvm.ptr -> !llvm.ptr
      %521 = llvm.load %509 : !llvm.ptr -> i64
      %522 = llvm.getelementptr %520[%521] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %518 = llvm.load %522 : !llvm.ptr -> i64
      %523 = arith.cmpi eq, %518, %arg0 : i64
      cf.cond_br %523, ^bb105, ^bb106
      ^bb105:
        %525 = llvm.mlir.addressof @cache_val : !llvm.ptr
        %526 = llvm.load %525 : !llvm.ptr -> !llvm.ptr
        %527 = llvm.load %509 : !llvm.ptr -> i64
        %528 = llvm.getelementptr %526[%527] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %524 = llvm.load %528 : !llvm.ptr -> i64
        func.return %524 : i64
      ^bb106:
        cf.br ^bb107
      ^bb107:
      %529 = llvm.load %509 : !llvm.ptr -> i64
      %530 = arith.constant 1 : i32
      %532 = arith.extsi %530 : i32 to i64
      %531 = arith.addi %529, %532 : i64
      %533 = llvm.mlir.addressof @CACHE_MASK : !llvm.ptr
      %534 = llvm.load %533 : !llvm.ptr -> i64
      %535 = arith.andi %531, %534 : i64
      llvm.store %535, %509 : i64, !llvm.ptr
      cf.br ^bb102
    ^bb104:
    %536 = func.call @isqrt_i64(%arg0) : (i64) -> i64
    %537 = arith.constant 0 : i32
    %538 = arith.extsi %537 : i32 to i64
    %539 = llvm.mlir.constant(1 : i64) : i64
    %540 = llvm.alloca %539 x i64 : (i64) -> !llvm.ptr
    llvm.store %538, %540 : i64, !llvm.ptr
    %541 = arith.constant 1 : i32
    %542 = arith.extsi %541 : i32 to i64
    %543 = llvm.mlir.constant(1 : i64) : i64
    %544 = llvm.alloca %543 x i64 : (i64) -> !llvm.ptr
    llvm.store %542, %544 : i64, !llvm.ptr
    cf.br ^bb108
    ^bb108:
    %545 = llvm.load %544 : !llvm.ptr -> i64
    %546 = arith.cmpi sle, %545, %536 : i64
    cf.cond_br %546, ^bb109, ^bb110
    ^bb109:
      %547 = llvm.load %544 : !llvm.ptr -> i64
      %548 = arith.divsi %arg0, %547 : i64
      %549 = arith.divsi %arg0, %548 : i64
      %550 = arith.cmpi sgt, %549, %536 : i64
      %551 = scf.if %550 -> (i64) {
        scf.yield %536 : i64
      } else {
        scf.yield %549 : i64
      }
      %552 = llvm.load %540 : !llvm.ptr -> i64
      %553 = llvm.load %544 : !llvm.ptr -> i64
      %554 = arith.subi %551, %553 : i64
      %555 = arith.constant 1 : i32
      %557 = arith.extsi %555 : i32 to i64
      %556 = arith.addi %554, %557 : i64
      %558 = arith.muli %548, %556 : i64
      %559 = arith.addi %552, %558 : i64
      llvm.store %559, %540 : i64, !llvm.ptr
      %560 = arith.constant 1 : i32
      %562 = arith.extsi %560 : i32 to i64
      %561 = arith.addi %551, %562 : i64
      llvm.store %561, %544 : i64, !llvm.ptr
      cf.br ^bb108
    ^bb110:
    %563 = arith.constant 2 : i32
    %564 = llvm.load %540 : !llvm.ptr -> i64
    %566 = arith.extsi %563 : i32 to i64
    %565 = arith.muli %566, %564 : i64
    %567 = arith.muli %536, %536 : i64
    %568 = arith.subi %565, %567 : i64
    %569 = arith.constant 1 : i32
    %570 = llvm.mlir.addressof @cache_used : !llvm.ptr
    %571 = llvm.load %570 : !llvm.ptr -> !llvm.ptr
    %572 = llvm.load %509 : !llvm.ptr -> i64
    %573 = arith.trunci %569 : i32 to i8
    %574 = llvm.getelementptr %571[%572] : (!llvm.ptr, i64) -> !llvm.ptr, i8
    llvm.store %573, %574 : i8, !llvm.ptr
    %575 = llvm.mlir.addressof @cache_key : !llvm.ptr
    %576 = llvm.load %575 : !llvm.ptr -> !llvm.ptr
    %577 = llvm.load %509 : !llvm.ptr -> i64
    %578 = llvm.getelementptr %576[%577] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %arg0, %578 : i64, !llvm.ptr
    %579 = llvm.mlir.addressof @cache_val : !llvm.ptr
    %580 = llvm.load %579 : !llvm.ptr -> !llvm.ptr
    %581 = llvm.load %509 : !llvm.ptr -> i64
    %582 = llvm.getelementptr %580[%581] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %568, %582 : i64, !llvm.ptr
    func.return %568 : i64
  }
  func.func @dfs(%arg0: i64, %arg1: i64, %arg2: i64) -> () {
    %583 = llvm.mlir.addressof @g_total : !llvm.ptr
    %584 = llvm.load %583 : !llvm.ptr -> i64
    %586 = llvm.mlir.addressof @g_N : !llvm.ptr
    %587 = llvm.load %586 : !llvm.ptr -> i64
    %588 = arith.divsi %587, %arg1 : i64
    %585 = func.call @D_func(%588) : (i64) -> i64
    %589 = arith.muli %arg2, %585 : i64
    %590 = arith.addi %584, %589 : i64
    %591 = llvm.mlir.addressof @g_total : !llvm.ptr
    llvm.store %590, %591 : i64, !llvm.ptr
    %592 = llvm.mlir.addressof @g_N : !llvm.ptr
    %593 = llvm.load %592 : !llvm.ptr -> i64
    %594 = arith.divsi %593, %arg1 : i64
    %595 = llvm.mlir.constant(1 : i64) : i64
    %596 = llvm.alloca %595 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %596 : i64, !llvm.ptr
    cf.br ^bb111
    ^bb111:
    %597 = llvm.load %596 : !llvm.ptr -> i64
    %598 = llvm.mlir.addressof @g_nprimes : !llvm.ptr
    %599 = llvm.load %598 : !llvm.ptr -> i64
    %600 = arith.cmpi slt, %597, %599 : i64
    cf.cond_br %600, ^bb112, ^bb113
    ^bb112:
      %602 = llvm.mlir.addressof @g_prime_sq : !llvm.ptr
      %603 = llvm.load %602 : !llvm.ptr -> !llvm.ptr
      %604 = llvm.load %596 : !llvm.ptr -> i64
      %605 = llvm.getelementptr %603[%604] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %601 = llvm.load %605 : !llvm.ptr -> i64
      %606 = arith.cmpi sgt, %601, %594 : i64
      cf.cond_br %606, ^bb114, ^bb115
      ^bb114:
        %607 = llvm.mlir.addressof @g_nprimes : !llvm.ptr
        %608 = llvm.load %607 : !llvm.ptr -> i64
        llvm.store %608, %596 : i64, !llvm.ptr
        cf.br ^bb116
      ^bb115:
        %610 = llvm.mlir.addressof @g_primes : !llvm.ptr
        %611 = llvm.load %610 : !llvm.ptr -> !llvm.ptr
        %612 = llvm.load %596 : !llvm.ptr -> i64
        %613 = llvm.getelementptr %611[%612] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %609 = llvm.load %613 : !llvm.ptr -> i32
        %614 = arith.extsi %609 : i32 to i64
        %615 = llvm.mlir.constant(1 : i64) : i64
        %616 = llvm.alloca %615 x i64 : (i64) -> !llvm.ptr
        llvm.store %601, %616 : i64, !llvm.ptr
        %617 = llvm.mlir.constant(1 : i64) : i64
        %618 = llvm.alloca %617 x i64 : (i64) -> !llvm.ptr
        llvm.store %arg2, %618 : i64, !llvm.ptr
        cf.br ^bb117
        ^bb117:
        %619 = llvm.load %616 : !llvm.ptr -> i64
        %620 = arith.cmpi sle, %619, %594 : i64
        cf.cond_br %620, ^bb118, ^bb119
        ^bb118:
          %622 = llvm.load %596 : !llvm.ptr -> i64
          %623 = arith.constant 1 : i32
          %625 = arith.extsi %623 : i32 to i64
          %624 = arith.addi %622, %625 : i64
          %626 = llvm.load %616 : !llvm.ptr -> i64
          %627 = arith.muli %arg1, %626 : i64
          %628 = llvm.load %618 : !llvm.ptr -> i64
          func.call @dfs(%624, %627, %628) : (i64, i64, i64) -> ()
          %629 = llvm.load %616 : !llvm.ptr -> i64
          %630 = arith.divsi %594, %614 : i64
          %631 = arith.cmpi sgt, %629, %630 : i64
          cf.cond_br %631, ^bb120, ^bb121
          ^bb120:
            %632 = arith.constant 1 : i32
            %634 = arith.extsi %632 : i32 to i64
            %633 = arith.addi %594, %634 : i64
            llvm.store %633, %616 : i64, !llvm.ptr
            cf.br ^bb122
          ^bb121:
            %635 = llvm.load %616 : !llvm.ptr -> i64
            %636 = arith.muli %635, %614 : i64
            llvm.store %636, %616 : i64, !llvm.ptr
            %637 = llvm.load %618 : !llvm.ptr -> i64
            %638 = arith.constant 1 : i32
            %640 = arith.extsi %638 : i32 to i64
            %639 = arith.shli %637, %640 : i64
            llvm.store %639, %618 : i64, !llvm.ptr
            cf.br ^bb122
          ^bb122:
          cf.br ^bb117
        ^bb119:
        %641 = llvm.load %596 : !llvm.ptr -> i64
        %642 = arith.constant 1 : i32
        %644 = arith.extsi %642 : i32 to i64
        %643 = arith.addi %641, %644 : i64
        llvm.store %643, %596 : i64, !llvm.ptr
        cf.br ^bb116
      ^bb116:
      cf.br ^bb111
    ^bb113:
    func.return
  }
  func.func @main() -> i32 {
    %646 = llvm.mlir.addressof @N_VAL : !llvm.ptr
    %647 = llvm.load %646 : !llvm.ptr -> i64
    %645 = func.call @isqrt_i64(%647) : (i64) -> i64
    %648 = func.call @primes_upto(%645) : (i64) -> !llvm.ptr
    %649 = llvm.mlir.addressof @g_primes : !llvm.ptr
    llvm.store %648, %649 : !llvm.ptr, !llvm.ptr
    %651 = llvm.mlir.addressof @g_nprimes : !llvm.ptr
    %652 = llvm.load %651 : !llvm.ptr -> i64
    %653 = arith.constant 8 : i32
    %655 = arith.extsi %653 : i32 to i64
    %654 = arith.muli %652, %655 : i64
    %650 = func.call @malloc(%654) : (i64) -> !llvm.ptr
    %656 = llvm.mlir.addressof @g_prime_sq : !llvm.ptr
    llvm.store %650, %656 : !llvm.ptr, !llvm.ptr
    %657 = arith.constant 0 : i32
    %658 = arith.extsi %657 : i32 to i64
    %659 = llvm.mlir.constant(1 : i64) : i64
    %660 = llvm.alloca %659 x i64 : (i64) -> !llvm.ptr
    llvm.store %658, %660 : i64, !llvm.ptr
    cf.br ^bb123
    ^bb123:
    %661 = llvm.load %660 : !llvm.ptr -> i64
    %662 = llvm.mlir.addressof @g_nprimes : !llvm.ptr
    %663 = llvm.load %662 : !llvm.ptr -> i64
    %664 = arith.cmpi slt, %661, %663 : i64
    cf.cond_br %664, ^bb124, ^bb125
    ^bb124:
      %666 = llvm.mlir.addressof @g_primes : !llvm.ptr
      %667 = llvm.load %666 : !llvm.ptr -> !llvm.ptr
      %668 = llvm.load %660 : !llvm.ptr -> i64
      %669 = llvm.getelementptr %667[%668] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %665 = llvm.load %669 : !llvm.ptr -> i32
      %670 = arith.extsi %665 : i32 to i64
      %671 = arith.muli %670, %670 : i64
      %672 = llvm.mlir.addressof @g_prime_sq : !llvm.ptr
      %673 = llvm.load %672 : !llvm.ptr -> !llvm.ptr
      %674 = llvm.load %660 : !llvm.ptr -> i64
      %675 = llvm.getelementptr %673[%674] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %671, %675 : i64, !llvm.ptr
      %676 = llvm.load %660 : !llvm.ptr -> i64
      %677 = arith.constant 1 : i32
      %679 = arith.extsi %677 : i32 to i64
      %678 = arith.addi %676, %679 : i64
      llvm.store %678, %660 : i64, !llvm.ptr
      cf.br ^bb123
    ^bb125:
    %681 = llvm.mlir.addressof @SMALL_LIMIT : !llvm.ptr
    %682 = llvm.load %681 : !llvm.ptr -> i64
    %680 = func.call @build_divisor_prefix(%682) : (i64) -> !llvm.ptr
    %683 = llvm.mlir.addressof @g_prefix : !llvm.ptr
    llvm.store %680, %683 : !llvm.ptr, !llvm.ptr
    %685 = llvm.mlir.addressof @CACHE_SIZE : !llvm.ptr
    %686 = llvm.load %685 : !llvm.ptr -> i64
    %687 = arith.constant 8 : i32
    %688 = arith.extsi %687 : i32 to i64
    %684 = func.call @calloc(%686, %688) : (i64, i64) -> !llvm.ptr
    %689 = llvm.mlir.addressof @cache_key : !llvm.ptr
    llvm.store %684, %689 : !llvm.ptr, !llvm.ptr
    %691 = llvm.mlir.addressof @CACHE_SIZE : !llvm.ptr
    %692 = llvm.load %691 : !llvm.ptr -> i64
    %693 = arith.constant 8 : i32
    %694 = arith.extsi %693 : i32 to i64
    %690 = func.call @calloc(%692, %694) : (i64, i64) -> !llvm.ptr
    %695 = llvm.mlir.addressof @cache_val : !llvm.ptr
    llvm.store %690, %695 : !llvm.ptr, !llvm.ptr
    %697 = llvm.mlir.addressof @CACHE_SIZE : !llvm.ptr
    %698 = llvm.load %697 : !llvm.ptr -> i64
    %699 = arith.constant 1 : i32
    %700 = arith.extsi %699 : i32 to i64
    %696 = func.call @calloc(%698, %700) : (i64, i64) -> !llvm.ptr
    %701 = llvm.mlir.addressof @cache_used : !llvm.ptr
    llvm.store %696, %701 : !llvm.ptr, !llvm.ptr
    %702 = llvm.mlir.addressof @N_VAL : !llvm.ptr
    %703 = llvm.load %702 : !llvm.ptr -> i64
    %704 = llvm.mlir.addressof @g_N : !llvm.ptr
    llvm.store %703, %704 : i64, !llvm.ptr
    %705 = arith.constant 0 : i32
    %706 = arith.extsi %705 : i32 to i64
    %707 = llvm.mlir.addressof @g_total : !llvm.ptr
    llvm.store %706, %707 : i64, !llvm.ptr
    %709 = arith.constant 0 : i32
    %710 = arith.constant 1 : i32
    %711 = arith.constant 1 : i32
    %712 = arith.extsi %709 : i32 to i64
    %713 = arith.extsi %710 : i32 to i64
    %714 = arith.extsi %711 : i32 to i64
    func.call @dfs(%712, %713, %714) : (i64, i64, i64) -> ()
    %715 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %716 = llvm.mlir.addressof @g_total : !llvm.ptr
    %717 = llvm.load %716 : !llvm.ptr -> i64
    %718 = llvm.call @printf(%715, %717) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    %720 = llvm.mlir.addressof @g_primes : !llvm.ptr
    %721 = llvm.load %720 : !llvm.ptr -> !llvm.ptr
    func.call @free(%721) : (!llvm.ptr) -> ()
    %723 = llvm.mlir.addressof @g_prime_sq : !llvm.ptr
    %724 = llvm.load %723 : !llvm.ptr -> !llvm.ptr
    func.call @free(%724) : (!llvm.ptr) -> ()
    %726 = llvm.mlir.addressof @g_prefix : !llvm.ptr
    %727 = llvm.load %726 : !llvm.ptr -> !llvm.ptr
    func.call @free(%727) : (!llvm.ptr) -> ()
    %729 = llvm.mlir.addressof @cache_key : !llvm.ptr
    %730 = llvm.load %729 : !llvm.ptr -> !llvm.ptr
    func.call @free(%730) : (!llvm.ptr) -> ()
    %732 = llvm.mlir.addressof @cache_val : !llvm.ptr
    %733 = llvm.load %732 : !llvm.ptr -> !llvm.ptr
    func.call @free(%733) : (!llvm.ptr) -> ()
    %735 = llvm.mlir.addressof @cache_used : !llvm.ptr
    %736 = llvm.load %735 : !llvm.ptr -> !llvm.ptr
    func.call @free(%736) : (!llvm.ptr) -> ()
    %737 = arith.constant 0 : i32
    func.return %737 : i32
  }
}