Problem 864

Square + 1 = Squarefree: count squarefree x^2+1 for 1<=x<=n. Ported from native C to pure Flow.

Answer110572936177
Output110572936177
StatusPASS
Native helperno
Runtime1440 ms
Peak memory107088 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 log n)
Space complexityO(n^2)O(n)
ApproachFlow solutionMobius sieve
VerdictSuboptimal

Flow source

# Project Euler 864
# Square + 1 = Squarefree: count squarefree x^2+1 for 1<=x<=n.
# Ported from native C to pure Flow.

import euler.nt { isqrt }

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

const N_VAL: i64 = 123567101113
const D_VAL: i64 = 30000000

# Globals for roots_minus_one_mod_p2 output
let mut g_r1: i64 = 0
let mut g_r2: i64 = 0

# Globals for negative_pell output
let mut g_pell_x: i64 = 0
let mut g_pell_y: i64 = 0

# dms globals
let mut g_dms_n: i64 = 0
let mut g_dms_D: i64 = 0
let mut g_dms_ans: i64 = 0
let mut g_dms_primes: ptr<i32> = null
let mut g_dms_roots: ptr<i64> = null
let mut g_dms_P: i32 = 0

# Mobius sieve globals
let mut g_spf_kmax: ptr<i32> = null
let mut g_mu_kmax: ptr<i8> = null

# Factoring globals
let mut g_primes_for_fact: ptr<i32> = null
let mut g_primes_for_fact_count: i32 = 0

function mod_pow_u32(a0: i32, e0: i64, p: i32) -> i32 {
    let mut r: i64 = 1
    let mut b: i64 = (a0 as i64) % (p as i64)
    let mut e: i64 = e0
    while e > 0 {
        if (e & 1) == 1 { r = r * b % (p as i64) }
        b = b * b % (p as i64)
        e = e >> 1
    }
    return r as i32
}

# Modular inverse of m mod p2 using extended GCD with i128
function mod_inv_i128(m: i64, p2: i64) -> i64 {
    let mut old_r: i128 = (m as i128) % (p2 as i128)
    let mut r: i128 = p2 as i128
    let mut old_s: i128 = 1
    let mut s: i128 = 0
    while r != 0 {
        let q: i128 = old_r / r
        let tmp: i128 = old_r - q * r
        old_r = r
        r = tmp
        let tmp2: i128 = old_s - q * s
        old_s = s
        s = tmp2
    }
    return ((old_s % (p2 as i128) + (p2 as i128)) % (p2 as i128)) as i64
}

function primes_1mod4_upto(limit: i64) -> ptr<i32> {
    if limit < 5 { return null }
    let size: i32 = (limit / 2 + 1) as i32
    let sieve: ptr<i8> = calloc(size as i64, 1)
    let mut i: i32 = 0
    while i < size {
        sieve[i] = 1
        i = i + 1
    }
    sieve[0] = 0
    let r: i32 = isqrt(limit) as i32
    let mut p: i32 = 3
    while p <= r {
        if sieve[p / 2] != 0 {
            let mut j: i32 = (p * p) / 2
            while j < size {
                sieve[j] = 0
                j = j + p
            }
        }
        p = p + 2
    }
    let mut cnt: i32 = 0
    i = 1
    while i < size {
        if sieve[i] != 0 && (2 * i + 1) % 4 == 1 { cnt = cnt + 1 }
        i = i + 1
    }
    let result: ptr<i32> = calloc((cnt + 1) as i64, 4)
    let mut idx: i32 = 0
    i = 1
    while i < size {
        if sieve[i] != 0 && (2 * i + 1) % 4 == 1 {
            result[idx] = 2 * i + 1
            idx = idx + 1
        }
        i = i + 1
    }
    free(sieve)
    return result
}

function sqrt_minus_one_mod_p(p: i32) -> i32 {
    let exp: i64 = ((p - 1) as i64) / 2
    let mut g: i32 = 2
    while mod_pow_u32(g, exp, p) != p - 1 {
        g = g + 1
    }
    return mod_pow_u32(g, ((p - 1) as i64) / 4, p)
}

function roots_minus_one_mod_p2(p: i32) -> void {
    let r: i32 = sqrt_minus_one_mod_p(p)
    let p2: i64 = (p as i64) * (p as i64)
    let s: i64 = ((r as i64) * (r as i64) + 1) / (p as i64)
    let inv: i32 = mod_pow_u32((2 * r) % p, (p - 2) as i64, p)
    let t: i64 = (((p - (s % (p as i64))) as i64) * (inv as i64)) % (p as i64)
    let R: i64 = ((r as i64) + t * (p as i64)) % p2
    g_r1 = R
    g_r2 = (p2 - R) % p2
}

function crt_combine(out: ptr<i64>, residues: ptr<i64>, len: i32, m: i64, a1: i64, a2: i64, p2: i64) -> void {
    let inv: i64 = mod_inv_i128(m, p2)
    let mut i: i32 = 0
    while i < len {
        let r: i64 = residues[i]
        let r_mod: i64 = r % p2
        let diff1: i64 = (a1 + p2 - r_mod) % p2
        let t1: i64 = ((diff1 as i128) * (inv as i128) % (p2 as i128)) as i64
        out[2 * i] = (r + m * t1) as i64
        let diff2: i64 = (a2 + p2 - r_mod) % p2
        let t2: i64 = ((diff2 as i128) * (inv as i128) % (p2 as i128)) as i64
        out[2 * i + 1] = (r + m * t2) as i64
        i = i + 1
    }
}

function dms_dfs(start_idx: i32, d: i64, mod: i64, residues: ptr<i64>, len: i32, mu_sign: i32) -> void {
    let mut i: i32 = start_idx
    while i < g_dms_P {
        let p: i32 = g_dms_primes[i]
        let nd: i64 = d * (p as i64)
        if nd > g_dms_D { break }

        let p2: i64 = (p as i64) * (p as i64)
        let a1: i64 = g_dms_roots[2 * i]
        let a2: i64 = g_dms_roots[2 * i + 1]
        let nmod: i64 = ((mod as i128) * (p2 as i128)) as i64
        let nlen: i32 = len * 2

        let nres: ptr<i64> = calloc(nlen as i64, 8)
        crt_combine(nres, residues, len, mod, a1, a2, p2)

        let mut A: i64 = 0
        if nmod <= g_dms_n {
            let q: i64 = g_dms_n / nmod
            let rem: i64 = g_dms_n % nmod
            A = q * (nlen as i64)
            let mut j: i32 = 0
            while j < nlen {
                if nres[j] <= rem { A = A + 1 }
                j = j + 1
            }
        } else {
            let mut j: i32 = 0
            while j < nlen {
                if nres[j] <= g_dms_n { A = A + 1 }
                j = j + 1
            }
        }

        let neg_mu: i64 = (0 - (mu_sign as i64)) * A
        g_dms_ans = g_dms_ans + neg_mu

        dms_dfs(i + 1, nd, nmod, nres, nlen, 0 - mu_sign)
        free(nres)
        i = i + 1
    }
}

function direct_mobius_sum(n: i64, D: i64) -> i64 {
    let primes: ptr<i32> = primes_1mod4_upto(D)

    # Count primes
    let mut pcnt: i32 = 0
    let mut pi: i32 = 0
    while true {
        let p: i32 = primes[pi]
        if p == 0 { break }
        pcnt = pcnt + 1
        pi = pi + 1
    }

    g_dms_roots = calloc((pcnt * 2) as i64, 8)
    let mut i: i32 = 0
    while i < pcnt {
        roots_minus_one_mod_p2(primes[i])
        g_dms_roots[2 * i] = g_r1
        g_dms_roots[2 * i + 1] = g_r2
        i = i + 1
    }

    g_dms_n = n
    g_dms_D = D
    g_dms_primes = primes
    g_dms_P = pcnt
    g_dms_ans = n

    let root_res: ptr<i64> = calloc(1, 8)
    root_res[0] = 0
    dms_dfs(0, 1, 1, root_res, 1, 1)
    free(root_res)

    free(g_dms_roots)
    free(primes)
    return g_dms_ans
}

function negative_pell_fundamental(D: i64, x_limit: i64) -> i32 {
    let a0: i64 = isqrt(D)
    if a0 * a0 == D { return 0 }

    let mut m: i64 = 0
    let mut d: i64 = 1
    let mut a: i64 = a0
    let mut p_prev: i64 = 1
    let mut p: i64 = a0
    let mut q_prev: i64 = 0
    let mut q: i64 = 1
    let mut period: i32 = 0

    while true {
        m = d * a - m
        d = (D - m * m) / d
        a = (a0 + m) / d

        let new_p: i64 = a * p + p_prev
        let new_q: i64 = a * q + q_prev
        p_prev = p
        p = new_p
        q_prev = q
        q = new_q

        period = period + 1
        if p_prev > x_limit { return 0 }
        if a == 2 * a0 { break }
    }

    if period % 2 == 0 { return 0 }
    if p_prev * p_prev - D * q_prev * q_prev != 0 - 1 { return 0 }

    g_pell_x = p_prev
    g_pell_y = q_prev
    return 1
}

function linear_sieve_kmax(Kmax: i64) -> void {
    g_spf_kmax = calloc(Kmax + 1, 4)
    g_mu_kmax = calloc(Kmax + 1, 1)
    let primes: ptr<i32> = calloc(Kmax / 10 + 10000, 4)
    let mut pc: i32 = 0
    g_mu_kmax[1] = 1
    let mut i: i32 = 2
    while (i as i64) <= Kmax {
        if g_spf_kmax[i] == 0 {
            g_spf_kmax[i] = i
            primes[pc] = i
            pc = pc + 1
            g_mu_kmax[i] = 0 - 1
        }
        let mut j: i32 = 0
        while j < pc {
            let p: i32 = primes[j]
            let ip: i64 = (i as i64) * (p as i64)
            if ip > Kmax { break }
            g_spf_kmax[ip as i32] = p
            if i % p == 0 {
                g_mu_kmax[ip as i32] = 0
                break
            }
            g_mu_kmax[ip as i32] = 0 - g_mu_kmax[i]
            j = j + 1
        }
        i = i + 1
    }
    free(primes)
}

function build_primes_for_factoring(limit: i64) -> void {
    g_primes_for_fact = null
    g_primes_for_fact_count = 0
    if limit < 2 { return }
    let size: i32 = (limit / 2 + 1) as i32
    let sieve: ptr<i8> = calloc(size as i64, 1)
    let mut i: i32 = 0
    while i < size {
        sieve[i] = 1
        i = i + 1
    }
    sieve[0] = 0
    let r: i32 = isqrt(limit) as i32
    let mut p: i32 = 3
    while p <= r {
        if sieve[p / 2] != 0 {
            let mut j: i32 = (p * p) / 2
            while j < size {
                sieve[j] = 0
                j = j + p
            }
        }
        p = p + 2
    }
    let mut cnt: i32 = 1
    i = 1
    while i < size {
        if sieve[i] != 0 { cnt = cnt + 1 }
        i = i + 1
    }
    g_primes_for_fact = calloc(cnt as i64, 4)
    g_primes_for_fact[g_primes_for_fact_count] = 2
    g_primes_for_fact_count = g_primes_for_fact_count + 1
    i = 1
    while i < size {
        if sieve[i] != 0 {
            g_primes_for_fact[g_primes_for_fact_count] = 2 * i + 1
            g_primes_for_fact_count = g_primes_for_fact_count + 1
        }
        i = i + 1
    }
    free(sieve)
}

function factor_distinct_primes(n: i64, out: ptr<i32>) -> i32 {
    let mut cnt: i32 = 0
    let mut t: i64 = n
    let mut i: i32 = 0
    while i < g_primes_for_fact_count {
        let p: i32 = g_primes_for_fact[i]
        if (p as i64) * (p as i64) > t { break }
        if t % (p as i64) == 0 {
            out[cnt] = p
            cnt = cnt + 1
            while t % (p as i64) == 0 { t = t / (p as i64) }
        }
        i = i + 1
    }
    if t > 1 {
        out[cnt] = t as i32
        cnt = cnt + 1
    }
    return cnt
}

function mobius_tail_sum_for_y(y: i64, D: i64) -> i64 {
    let pf: ptr<i32> = calloc(64, 4)
    let npf: i32 = factor_distinct_primes(y, pf)
    let mut total: i64 = 0
    let subsets: i32 = 1 << npf
    let mut mask: i32 = 0
    while mask < subsets {
        let mut prod: i64 = 1
        let mut parity: i32 = 0
        let mut b: i32 = 0
        while b < npf {
            if (mask & (1 << b)) != 0 {
                prod = prod * (pf[b] as i64)
                parity = parity ^ 1
            }
            b = b + 1
        }
        if prod > D {
            if parity != 0 {
                total = total - 1
            } else {
                total = total + 1
            }
        }
        mask = mask + 1
    }
    free(pf)
    return total
}

function correction_via_pell(n: i64, D: i64) -> i64 {
    let Kmax: i64 = (((n as i128) * (n as i128) + 1) / ((D as i128) * (D as i128))) as i64
    if Kmax < 2 { return 0 }

    linear_sieve_kmax(Kmax)

    let isqrt_n: i64 = isqrt(n)
    build_primes_for_factoring(isqrt_n + 1)

    let mut corr: i64 = 0

    let mut k: i64 = 2
    while k <= Kmax {
        if g_mu_kmax[k] != 0 {
            # Filter: if an odd prime p == 3 (mod 4) divides k, skip
            let mut t: i64 = k
            let mut ok: i32 = 1
            while t > 1 {
                let p: i32 = g_spf_kmax[t as i32]
                t = t / (p as i64)
                if p != 2 && (p & 3) == 3 {
                    ok = 0
                    break
                }
            }
            if ok != 0 {
                if negative_pell_fundamental(k, n) != 0 {
                    let x: i64 = g_pell_x
                    let y: i64 = g_pell_y

                    let A: i128 = (x as i128) * (x as i128) + (k as i128) * (y as i128) * (y as i128)
                    let B: i128 = (2 as i128) * (x as i128) * (y as i128)

                    let mut cx: i64 = x
                    let mut cy: i64 = y
                    while cx <= n {
                        if cy > D {
                            corr = corr + mobius_tail_sum_for_y(cy, D)
                        }
                        let new_x: i128 = A * (cx as i128) + (k as i128) * B * (cy as i128)
                        let new_y: i128 = B * (cx as i128) + A * (cy as i128)
                        if new_x > (n as i128) { break }
                        cx = new_x as i64
                        cy = new_y as i64
                    }
                }
            }
        }
        k = k + 1
    }

    free(g_spf_kmax)
    free(g_mu_kmax)
    free(g_primes_for_fact)
    return corr
}

function main() -> i32 {
    let direct: i64 = direct_mobius_sum(N_VAL, D_VAL)
    let corr: i64 = correction_via_pell(N_VAL, D_VAL)
    printf("%lld\n", direct + corr)
    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);
int32_t mod_pow_u32_i32_i64_i32(int32_t a0, int64_t e0, int32_t p);
int64_t mod_inv_i128_i64_i64(int64_t m, int64_t p2);
int32_t* primes_1mod4_upto_i64(int64_t limit);
int32_t sqrt_minus_one_mod_p_i32(int32_t p);
void roots_minus_one_mod_p2_i32(int32_t p);
void crt_combine_ptr_i64_ptr_i64_i32_i64_i64_i64_i64(int64_t* out, int64_t* residues, int32_t len, int64_t m, int64_t a1, int64_t a2, int64_t p2);
void dms_dfs_i32_i64_i64_ptr_i64_i32_i32(int32_t start_idx, int64_t d, int64_t mod, int64_t* residues, int32_t len, int32_t mu_sign);
int64_t direct_mobius_sum_i64_i64(int64_t n, int64_t D);
int32_t negative_pell_fundamental_i64_i64(int64_t D, int64_t x_limit);
void linear_sieve_kmax_i64(int64_t Kmax);
void build_primes_for_factoring_i64(int64_t limit);
int32_t factor_distinct_primes_i64_ptr_i32(int64_t n, int32_t* out);
int64_t mobius_tail_sum_for_y_i64_i64(int64_t y, int64_t D);
int64_t correction_via_pell_i64_i64(int64_t n, int64_t D);
int32_t main(void);

static const int64_t N_VAL = 123567101113;
static const int64_t D_VAL = 30000000;

/* Module statics */
static int64_t g_r1 = 0;
static int64_t g_r2 = 0;
static int64_t g_pell_x = 0;
static int64_t g_pell_y = 0;
static int64_t g_dms_n = 0;
static int64_t g_dms_D = 0;
static int64_t g_dms_ans = 0;
static int32_t* g_dms_primes = NULL;
static int64_t* g_dms_roots = NULL;
static int32_t g_dms_P = 0;
static int32_t* g_spf_kmax = NULL;
static int8_t* g_mu_kmax = NULL;
static int32_t* g_primes_for_fact = NULL;
static int32_t g_primes_for_fact_count = 0;

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

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

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

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

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

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



int32_t mod_pow_u32_i32_i64_i32(int32_t a0, int64_t e0, int32_t p) {
    int64_t r = 1;
    int64_t b = FLOW_CHECKED_MOD((((int64_t)(a0))), (((int64_t)(p))));
    int64_t e = e0;
    while (e > 0) {
        if ((e & 1) == 1) {
            r = FLOW_CHECKED_MOD(((r * b)), (((int64_t)(p))));
        }
        b = FLOW_CHECKED_MOD(((b * b)), (((int64_t)(p))));
        e = FLOW_CHECKED_SHR((e), (1));
    }
    return ((int32_t)(r));
}

int64_t mod_inv_i128_i64_i64(int64_t m, int64_t p2) {
    __int128 old_r = FLOW_CHECKED_MOD((((__int128)(m))), (((__int128)(p2))));
    __int128 r = ((__int128)(p2));
    __int128 old_s = 1;
    __int128 s = 0;
    while (r != 0) {
        __int128 q = FLOW_CHECKED_DIV((old_r), (r));
        __int128 tmp = (old_r - (q * r));
        old_r = r;
        r = tmp;
        __int128 tmp2 = (old_s - (q * s));
        old_s = s;
        s = tmp2;
    }
    return ((int64_t)(FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD((old_s), (((__int128)(p2)))) + ((__int128)(p2)))), (((__int128)(p2))))));
}

int32_t* primes_1mod4_upto_i64(int64_t limit) {
    if (limit < 5) {
        return NULL;
    }
    int32_t size = ((int32_t)((FLOW_CHECKED_DIV((limit), (2)) + 1)));
    int8_t* sieve = (int8_t*)(calloc(((int64_t)(size)), 1));
    int32_t i = 0;
    while (i < size) {
        sieve[i] = 1;
        i = (i + 1);
    }
    sieve[0] = 0;
    int32_t r = ((int32_t)(isqrt_i64(limit)));
    int32_t p = 3;
    while (p <= r) {
        if (sieve[FLOW_CHECKED_DIV((p), (2))] != 0) {
            int32_t j = FLOW_CHECKED_DIV(((p * p)), (2));
            while (j < size) {
                sieve[j] = 0;
                j = (j + p);
            }
        }
        p = (p + 2);
    }
    int32_t cnt = 0;
    i = 1;
    while (i < size) {
        if ((sieve[i] != 0 && FLOW_CHECKED_MOD((((2 * i) + 1)), (4)) == 1)) {
            cnt = (cnt + 1);
        }
        i = (i + 1);
    }
    int32_t* result = (int32_t*)(calloc(((int64_t)((cnt + 1))), 4));
    int32_t idx = 0;
    i = 1;
    while (i < size) {
        if ((sieve[i] != 0 && FLOW_CHECKED_MOD((((2 * i) + 1)), (4)) == 1)) {
            result[idx] = ((2 * i) + 1);
            idx = (idx + 1);
        }
        i = (i + 1);
    }
    free(sieve);
    return result;
}

int32_t sqrt_minus_one_mod_p_i32(int32_t p) {
    int64_t exp = FLOW_CHECKED_DIV((((int64_t)((p - 1)))), (2));
    int32_t g = 2;
    while (mod_pow_u32_i32_i64_i32(g, exp, p) != (p - 1)) {
        g = (g + 1);
    }
    return mod_pow_u32_i32_i64_i32(g, FLOW_CHECKED_DIV((((int64_t)((p - 1)))), (4)), p);
}

void roots_minus_one_mod_p2_i32(int32_t p) {
    int32_t r = sqrt_minus_one_mod_p_i32(p);
    int64_t p2 = (((int64_t)(p)) * ((int64_t)(p)));
    int64_t s = FLOW_CHECKED_DIV((((((int64_t)(r)) * ((int64_t)(r))) + 1)), (((int64_t)(p))));
    int32_t inv = mod_pow_u32_i32_i64_i32(FLOW_CHECKED_MOD(((2 * r)), (p)), ((int64_t)((p - 2))), p);
    int64_t t = FLOW_CHECKED_MOD(((((int64_t)((p - FLOW_CHECKED_MOD((s), (((int64_t)(p))))))) * ((int64_t)(inv)))), (((int64_t)(p))));
    int64_t R = FLOW_CHECKED_MOD(((((int64_t)(r)) + (t * ((int64_t)(p))))), (p2));
    g_r1 = R;
    g_r2 = FLOW_CHECKED_MOD(((p2 - R)), (p2));
}

void crt_combine_ptr_i64_ptr_i64_i32_i64_i64_i64_i64(int64_t* out, int64_t* residues, int32_t len, int64_t m, int64_t a1, int64_t a2, int64_t p2) {
    int64_t inv = mod_inv_i128_i64_i64(m, p2);
    int32_t i = 0;
    while (i < len) {
        int64_t r = residues[i];
        int64_t r_mod = FLOW_CHECKED_MOD((r), (p2));
        int64_t diff1 = FLOW_CHECKED_MOD((((a1 + p2) - r_mod)), (p2));
        int64_t t1 = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(diff1)) * ((__int128)(inv)))), (((__int128)(p2))))));
        out[(2 * i)] = ((int64_t)((r + (m * t1))));
        int64_t diff2 = FLOW_CHECKED_MOD((((a2 + p2) - r_mod)), (p2));
        int64_t t2 = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(diff2)) * ((__int128)(inv)))), (((__int128)(p2))))));
        out[((2 * i) + 1)] = ((int64_t)((r + (m * t2))));
        i = (i + 1);
    }
}

void dms_dfs_i32_i64_i64_ptr_i64_i32_i32(int32_t start_idx, int64_t d, int64_t mod, int64_t* residues, int32_t len, int32_t mu_sign) {
    int32_t i = start_idx;
    while (i < g_dms_P) {
        int32_t p = g_dms_primes[i];
        int64_t nd = (d * ((int64_t)(p)));
        if (nd > g_dms_D) {
            break;
        }
        int64_t p2 = (((int64_t)(p)) * ((int64_t)(p)));
        int64_t a1 = g_dms_roots[(2 * i)];
        int64_t a2 = g_dms_roots[((2 * i) + 1)];
        int64_t nmod = ((int64_t)((((__int128)(mod)) * ((__int128)(p2)))));
        int32_t nlen = (len * 2);
        int64_t* nres = (int64_t*)(calloc(((int64_t)(nlen)), 8));
        crt_combine_ptr_i64_ptr_i64_i32_i64_i64_i64_i64(nres, residues, len, mod, a1, a2, p2);
        int64_t A = 0;
        if (nmod <= g_dms_n) {
            int64_t q = FLOW_CHECKED_DIV((g_dms_n), (nmod));
            int64_t rem = FLOW_CHECKED_MOD((g_dms_n), (nmod));
            A = (q * ((int64_t)(nlen)));
            int32_t j = 0;
            while (j < nlen) {
                if (nres[j] <= rem) {
                    A = (A + 1);
                }
                j = (j + 1);
            }
        } else {
            int32_t j = 0;
            while (j < nlen) {
                if (nres[j] <= g_dms_n) {
                    A = (A + 1);
                }
                j = (j + 1);
            }
        }
        int64_t neg_mu = ((0 - ((int64_t)(mu_sign))) * A);
        g_dms_ans = (g_dms_ans + neg_mu);
        dms_dfs_i32_i64_i64_ptr_i64_i32_i32((i + 1), nd, nmod, nres, nlen, (0 - mu_sign));
        free(nres);
        i = (i + 1);
    }
}

int64_t direct_mobius_sum_i64_i64(int64_t n, int64_t D) {
    int32_t* primes = (int32_t*)(primes_1mod4_upto_i64(D));
    int32_t pcnt = 0;
    int32_t pi = 0;
    while (1) {
        int32_t p = primes[pi];
        if (p == 0) {
            break;
        }
        pcnt = (pcnt + 1);
        pi = (pi + 1);
    }
    g_dms_roots = calloc(((int64_t)((pcnt * 2))), 8);
    int32_t i = 0;
    while (i < pcnt) {
        roots_minus_one_mod_p2_i32(primes[i]);
        g_dms_roots[(2 * i)] = g_r1;
        g_dms_roots[((2 * i) + 1)] = g_r2;
        i = (i + 1);
    }
    g_dms_n = n;
    g_dms_D = D;
    g_dms_primes = primes;
    g_dms_P = pcnt;
    g_dms_ans = n;
    int64_t* root_res = (int64_t*)(calloc(1, 8));
    root_res[0] = 0;
    dms_dfs_i32_i64_i64_ptr_i64_i32_i32(0, 1, 1, root_res, 1, 1);
    free(root_res);
    free(g_dms_roots);
    free(primes);
    return g_dms_ans;
}

int32_t negative_pell_fundamental_i64_i64(int64_t D, int64_t x_limit) {
    int64_t a0 = isqrt_i64(D);
    if ((a0 * a0) == D) {
        return 0;
    }
    int64_t m = 0;
    int64_t d = 1;
    int64_t a = a0;
    int64_t p_prev = 1;
    int64_t p = a0;
    int64_t q_prev = 0;
    int64_t q = 1;
    int32_t period = 0;
    while (1) {
        m = ((d * a) - m);
        d = FLOW_CHECKED_DIV(((D - (m * m))), (d));
        a = FLOW_CHECKED_DIV(((a0 + m)), (d));
        int64_t new_p = ((a * p) + p_prev);
        int64_t new_q = ((a * q) + q_prev);
        p_prev = p;
        p = new_p;
        q_prev = q;
        q = new_q;
        period = (period + 1);
        if (p_prev > x_limit) {
            return 0;
        }
        if (a == (2 * a0)) {
            break;
        }
    }
    if (FLOW_CHECKED_MOD((period), (2)) == 0) {
        return 0;
    }
    if (((p_prev * p_prev) - ((D * q_prev) * q_prev)) != (0 - 1)) {
        return 0;
    }
    g_pell_x = p_prev;
    g_pell_y = q_prev;
    return 1;
}

void linear_sieve_kmax_i64(int64_t Kmax) {
    g_spf_kmax = calloc((Kmax + 1), 4);
    g_mu_kmax = calloc((Kmax + 1), 1);
    int32_t* primes = (int32_t*)(calloc((FLOW_CHECKED_DIV((Kmax), (10)) + 10000), 4));
    int32_t pc = 0;
    g_mu_kmax[1] = 1;
    int32_t i = 2;
    while (((int64_t)(i)) <= Kmax) {
        if (g_spf_kmax[i] == 0) {
            g_spf_kmax[i] = i;
            primes[pc] = i;
            pc = (pc + 1);
            g_mu_kmax[i] = (0 - 1);
        }
        int32_t j = 0;
        while (j < pc) {
            int32_t p = primes[j];
            int64_t ip = (((int64_t)(i)) * ((int64_t)(p)));
            if (ip > Kmax) {
                break;
            }
            g_spf_kmax[((int32_t)(ip))] = p;
            if (FLOW_CHECKED_MOD((i), (p)) == 0) {
                g_mu_kmax[((int32_t)(ip))] = 0;
                break;
            }
            g_mu_kmax[((int32_t)(ip))] = (0 - g_mu_kmax[i]);
            j = (j + 1);
        }
        i = (i + 1);
    }
    free(primes);
}

void build_primes_for_factoring_i64(int64_t limit) {
    g_primes_for_fact = NULL;
    g_primes_for_fact_count = 0;
    if (limit < 2) {
        return;
    }
    int32_t size = ((int32_t)((FLOW_CHECKED_DIV((limit), (2)) + 1)));
    int8_t* sieve = (int8_t*)(calloc(((int64_t)(size)), 1));
    int32_t i = 0;
    while (i < size) {
        sieve[i] = 1;
        i = (i + 1);
    }
    sieve[0] = 0;
    int32_t r = ((int32_t)(isqrt_i64(limit)));
    int32_t p = 3;
    while (p <= r) {
        if (sieve[FLOW_CHECKED_DIV((p), (2))] != 0) {
            int32_t j = FLOW_CHECKED_DIV(((p * p)), (2));
            while (j < size) {
                sieve[j] = 0;
                j = (j + p);
            }
        }
        p = (p + 2);
    }
    int32_t cnt = 1;
    i = 1;
    while (i < size) {
        if (sieve[i] != 0) {
            cnt = (cnt + 1);
        }
        i = (i + 1);
    }
    g_primes_for_fact = calloc(((int64_t)(cnt)), 4);
    g_primes_for_fact[g_primes_for_fact_count] = 2;
    g_primes_for_fact_count = (g_primes_for_fact_count + 1);
    i = 1;
    while (i < size) {
        if (sieve[i] != 0) {
            g_primes_for_fact[g_primes_for_fact_count] = ((2 * i) + 1);
            g_primes_for_fact_count = (g_primes_for_fact_count + 1);
        }
        i = (i + 1);
    }
    free(sieve);
}

int32_t factor_distinct_primes_i64_ptr_i32(int64_t n, int32_t* out) {
    int32_t cnt = 0;
    int64_t t = n;
    int32_t i = 0;
    while (i < g_primes_for_fact_count) {
        int32_t p = g_primes_for_fact[i];
        if ((((int64_t)(p)) * ((int64_t)(p))) > t) {
            break;
        }
        if (FLOW_CHECKED_MOD((t), (((int64_t)(p)))) == 0) {
            out[cnt] = p;
            cnt = (cnt + 1);
            while (FLOW_CHECKED_MOD((t), (((int64_t)(p)))) == 0) {
                t = FLOW_CHECKED_DIV((t), (((int64_t)(p))));
            }
        }
        i = (i + 1);
    }
    if (t > 1) {
        out[cnt] = ((int32_t)(t));
        cnt = (cnt + 1);
    }
    return cnt;
}

int64_t mobius_tail_sum_for_y_i64_i64(int64_t y, int64_t D) {
    int32_t* pf = (int32_t*)(calloc(64, 4));
    int32_t npf = factor_distinct_primes_i64_ptr_i32(y, pf);
    int64_t total = 0;
    int32_t subsets = FLOW_CHECKED_SHL((1), (npf));
    int32_t mask = 0;
    while (mask < subsets) {
        int64_t prod = 1;
        int32_t parity = 0;
        int32_t b = 0;
        while (b < npf) {
            if ((mask & FLOW_CHECKED_SHL((1), (b))) != 0) {
                prod = (prod * ((int64_t)(pf[b])));
                parity = (parity ^ 1);
            }
            b = (b + 1);
        }
        if (prod > D) {
            if (parity != 0) {
                total = (total - 1);
            } else {
                total = (total + 1);
            }
        }
        mask = (mask + 1);
    }
    free(pf);
    return total;
}

int64_t correction_via_pell_i64_i64(int64_t n, int64_t D) {
    int64_t Kmax = ((int64_t)(FLOW_CHECKED_DIV((((((__int128)(n)) * ((__int128)(n))) + 1)), ((((__int128)(D)) * ((__int128)(D)))))));
    if (Kmax < 2) {
        return 0;
    }
    linear_sieve_kmax_i64(Kmax);
    int64_t isqrt_n = isqrt_i64(n);
    build_primes_for_factoring_i64((isqrt_n + 1));
    int64_t corr = 0;
    int64_t k = 2;
    while (k <= Kmax) {
        if (g_mu_kmax[k] != 0) {
            int64_t t = k;
            int32_t ok = 1;
            while (t > 1) {
                int32_t p = g_spf_kmax[((int32_t)(t))];
                t = FLOW_CHECKED_DIV((t), (((int64_t)(p))));
                if ((p != 2 && (p & 3) == 3)) {
                    ok = 0;
                    break;
                }
            }
            if (ok != 0) {
                if (negative_pell_fundamental_i64_i64(k, n) != 0) {
                    int64_t x = g_pell_x;
                    int64_t y = g_pell_y;
                    __int128 A = ((((__int128)(x)) * ((__int128)(x))) + ((((__int128)(k)) * ((__int128)(y))) * ((__int128)(y))));
                    __int128 B = ((((__int128)(2)) * ((__int128)(x))) * ((__int128)(y)));
                    int64_t cx = x;
                    int64_t cy = y;
                    while (cx <= n) {
                        if (cy > D) {
                            corr = (corr + mobius_tail_sum_for_y_i64_i64(cy, D));
                        }
                        __int128 new_x = ((A * ((__int128)(cx))) + ((((__int128)(k)) * B) * ((__int128)(cy))));
                        __int128 new_y = ((B * ((__int128)(cx))) + (A * ((__int128)(cy))));
                        if (new_x > ((__int128)(n))) {
                            break;
                        }
                        cx = ((int64_t)(new_x));
                        cy = ((int64_t)(new_y));
                    }
                }
            }
        }
        k = (k + 1);
    }
    free(g_spf_kmax);
    free(g_mu_kmax);
    free(g_primes_for_fact);
    return corr;
}

int32_t main(void) {
    int64_t direct = direct_mobius_sum_i64_i64(N_VAL, D_VAL);
    int64_t corr = correction_via_pell_i64_i64(N_VAL, D_VAL);
    printf("%lld\n", (direct + corr));
    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: N_VAL
  llvm.mlir.global internal constant @N_VAL(123567101113 : i64) : i64
  // Constant: D_VAL
  llvm.mlir.global internal constant @D_VAL(30000000 : i64) : i64
  // Module static: g_r1
  llvm.mlir.global internal @g_r1(0 : i64) : i64
  // Module static: g_r2
  llvm.mlir.global internal @g_r2(0 : i64) : i64
  // Module static: g_pell_x
  llvm.mlir.global internal @g_pell_x(0 : i64) : i64
  // Module static: g_pell_y
  llvm.mlir.global internal @g_pell_y(0 : i64) : i64
  // Module static: g_dms_n
  llvm.mlir.global internal @g_dms_n(0 : i64) : i64
  // Module static: g_dms_D
  llvm.mlir.global internal @g_dms_D(0 : i64) : i64
  // Module static: g_dms_ans
  llvm.mlir.global internal @g_dms_ans(0 : i64) : i64
  // Module static: g_dms_primes
  llvm.mlir.global internal @g_dms_primes() {addr_space = 0 : i32} : !llvm.ptr {
    %175 = llvm.mlir.zero : !llvm.ptr
    llvm.return %175 : !llvm.ptr
  }
  // Module static: g_dms_roots
  llvm.mlir.global internal @g_dms_roots() {addr_space = 0 : i32} : !llvm.ptr {
    %176 = llvm.mlir.zero : !llvm.ptr
    llvm.return %176 : !llvm.ptr
  }
  // Module static: g_dms_P
  llvm.mlir.global internal @g_dms_P(0 : i32) : i32
  // Module static: g_spf_kmax
  llvm.mlir.global internal @g_spf_kmax() {addr_space = 0 : i32} : !llvm.ptr {
    %177 = llvm.mlir.zero : !llvm.ptr
    llvm.return %177 : !llvm.ptr
  }
  // Module static: g_mu_kmax
  llvm.mlir.global internal @g_mu_kmax() {addr_space = 0 : i32} : !llvm.ptr {
    %178 = llvm.mlir.zero : !llvm.ptr
    llvm.return %178 : !llvm.ptr
  }
  // Module static: g_primes_for_fact
  llvm.mlir.global internal @g_primes_for_fact() {addr_space = 0 : i32} : !llvm.ptr {
    %179 = llvm.mlir.zero : !llvm.ptr
    llvm.return %179 : !llvm.ptr
  }
  // Module static: g_primes_for_fact_count
  llvm.mlir.global internal @g_primes_for_fact_count(0 : i32) : i32
  func.func @mod_pow_u32(%arg0: i32, %arg1: i64, %arg2: i32) -> i32 {
    %180 = arith.constant 1 : i32
    %181 = arith.extsi %180 : i32 to i64
    %182 = llvm.mlir.constant(1 : i64) : i64
    %183 = llvm.alloca %182 x i64 : (i64) -> !llvm.ptr
    llvm.store %181, %183 : i64, !llvm.ptr
    %184 = arith.extsi %arg0 : i32 to i64
    %185 = arith.extsi %arg2 : i32 to i64
    %186 = arith.remsi %184, %185 : i64
    %187 = llvm.mlir.constant(1 : i64) : i64
    %188 = llvm.alloca %187 x i64 : (i64) -> !llvm.ptr
    llvm.store %186, %188 : i64, !llvm.ptr
    %189 = llvm.mlir.constant(1 : i64) : i64
    %190 = llvm.alloca %189 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %190 : i64, !llvm.ptr
    cf.br ^bb42
    ^bb42:
    %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
    cf.cond_br %193, ^bb43, ^bb44
    ^bb43:
      %195 = llvm.load %190 : !llvm.ptr -> i64
      %196 = arith.constant 1 : i32
      %198 = arith.extsi %196 : i32 to i64
      %197 = arith.andi %195, %198 : i64
      %199 = arith.constant 1 : i32
      %201 = arith.extsi %199 : i32 to i64
      %200 = arith.cmpi eq, %197, %201 : i64
      cf.cond_br %200, ^bb45, ^bb46
      ^bb45:
        %202 = llvm.load %183 : !llvm.ptr -> i64
        %203 = llvm.load %188 : !llvm.ptr -> i64
        %204 = arith.muli %202, %203 : i64
        %205 = arith.extsi %arg2 : i32 to i64
        %206 = arith.remsi %204, %205 : i64
        llvm.store %206, %183 : i64, !llvm.ptr
        cf.br ^bb47
      ^bb46:
        cf.br ^bb47
      ^bb47:
      %207 = llvm.load %188 : !llvm.ptr -> i64
      %208 = llvm.load %188 : !llvm.ptr -> i64
      %209 = arith.muli %207, %208 : i64
      %210 = arith.extsi %arg2 : i32 to i64
      %211 = arith.remsi %209, %210 : i64
      llvm.store %211, %188 : i64, !llvm.ptr
      %212 = llvm.load %190 : !llvm.ptr -> i64
      %213 = arith.constant 1 : i32
      %215 = arith.extsi %213 : i32 to i64
      %214 = arith.shrsi %212, %215 : i64
      llvm.store %214, %190 : i64, !llvm.ptr
      cf.br ^bb42
    ^bb44:
    %216 = llvm.load %183 : !llvm.ptr -> i64
    %217 = arith.trunci %216 : i64 to i32
    func.return %217 : i32
  }
  func.func @mod_inv_i128(%arg0: i64, %arg1: i64) -> i64 {
    %218 = arith.extsi %arg0 : i64 to i128
    %219 = arith.extsi %arg1 : i64 to i128
    %221 = arith.trunci %218 : i128 to i64
    %222 = arith.trunci %219 : i128 to i64
    %220 = arith.remsi %221, %222 : i64
    %223 = arith.extsi %220 : i64 to i128
    %224 = llvm.mlir.constant(1 : i64) : i64
    %225 = llvm.alloca %224 x i128 : (i64) -> !llvm.ptr
    llvm.store %223, %225 : i128, !llvm.ptr
    %226 = arith.extsi %arg1 : i64 to i128
    %227 = llvm.mlir.constant(1 : i64) : i64
    %228 = llvm.alloca %227 x i128 : (i64) -> !llvm.ptr
    llvm.store %226, %228 : i128, !llvm.ptr
    %229 = arith.constant 1 : i32
    %230 = arith.extsi %229 : i32 to i128
    %231 = llvm.mlir.constant(1 : i64) : i64
    %232 = llvm.alloca %231 x i128 : (i64) -> !llvm.ptr
    llvm.store %230, %232 : i128, !llvm.ptr
    %233 = arith.constant 0 : i32
    %234 = arith.extsi %233 : i32 to i128
    %235 = llvm.mlir.constant(1 : i64) : i64
    %236 = llvm.alloca %235 x i128 : (i64) -> !llvm.ptr
    llvm.store %234, %236 : i128, !llvm.ptr
    cf.br ^bb48
    ^bb48:
    %237 = llvm.load %228 : !llvm.ptr -> i128
    %238 = arith.constant 0 : i32
    %240 = arith.trunci %237 : i128 to i64
    %241 = arith.extsi %238 : i32 to i64
    %239 = arith.cmpi ne, %240, %241 : i64
    cf.cond_br %239, ^bb49, ^bb50
    ^bb49:
      %242 = llvm.load %225 : !llvm.ptr -> i128
      %243 = llvm.load %228 : !llvm.ptr -> i128
      %245 = arith.trunci %242 : i128 to i64
      %246 = arith.trunci %243 : i128 to i64
      %244 = arith.divsi %245, %246 : i64
      %247 = arith.extsi %244 : i64 to i128
      %248 = llvm.load %225 : !llvm.ptr -> i128
      %249 = llvm.load %228 : !llvm.ptr -> i128
      %251 = arith.trunci %247 : i128 to i64
      %252 = arith.trunci %249 : i128 to i64
      %250 = arith.muli %251, %252 : i64
      %254 = arith.trunci %248 : i128 to i64
      %253 = arith.subi %254, %250 : i64
      %255 = arith.extsi %253 : i64 to i128
      %256 = llvm.load %228 : !llvm.ptr -> i128
      llvm.store %256, %225 : i128, !llvm.ptr
      llvm.store %255, %228 : i128, !llvm.ptr
      %257 = llvm.load %232 : !llvm.ptr -> i128
      %258 = llvm.load %236 : !llvm.ptr -> i128
      %260 = arith.trunci %247 : i128 to i64
      %261 = arith.trunci %258 : i128 to i64
      %259 = arith.muli %260, %261 : i64
      %263 = arith.trunci %257 : i128 to i64
      %262 = arith.subi %263, %259 : i64
      %264 = arith.extsi %262 : i64 to i128
      %265 = llvm.load %236 : !llvm.ptr -> i128
      llvm.store %265, %232 : i128, !llvm.ptr
      llvm.store %264, %236 : i128, !llvm.ptr
      cf.br ^bb48
    ^bb50:
    %266 = llvm.load %232 : !llvm.ptr -> i128
    %267 = arith.extsi %arg1 : i64 to i128
    %269 = arith.trunci %266 : i128 to i64
    %270 = arith.trunci %267 : i128 to i64
    %268 = arith.remsi %269, %270 : i64
    %271 = arith.extsi %arg1 : i64 to i128
    %273 = arith.trunci %271 : i128 to i64
    %272 = arith.addi %268, %273 : i64
    %274 = arith.extsi %arg1 : i64 to i128
    %276 = arith.trunci %274 : i128 to i64
    %275 = arith.remsi %272, %276 : i64
    func.return %275 : i64
  }
  func.func @primes_1mod4_upto(%arg0: i64) -> !llvm.ptr {
    %277 = arith.constant 5 : i32
    %279 = arith.extsi %277 : i32 to i64
    %278 = arith.cmpi slt, %arg0, %279 : i64
    cf.cond_br %278, ^bb51, ^bb52
    ^bb51:
      %280 = llvm.mlir.zero : !llvm.ptr
      func.return %280 : !llvm.ptr
    ^bb52:
      cf.br ^bb53
    ^bb53:
    %281 = arith.constant 2 : i32
    %283 = arith.extsi %281 : i32 to i64
    %282 = arith.divsi %arg0, %283 : i64
    %284 = arith.constant 1 : i32
    %286 = arith.extsi %284 : i32 to i64
    %285 = arith.addi %282, %286 : i64
    %287 = arith.trunci %285 : i64 to i32
    %289 = arith.extsi %287 : i32 to i64
    %290 = arith.constant 1 : i32
    %291 = arith.extsi %290 : i32 to i64
    %288 = func.call @calloc(%289, %291) : (i64, i64) -> !llvm.ptr
    %292 = arith.constant 0 : i32
    %293 = llvm.mlir.constant(1 : i64) : i64
    %294 = llvm.alloca %293 x i32 : (i64) -> !llvm.ptr
    llvm.store %292, %294 : i32, !llvm.ptr
    cf.br ^bb54
    ^bb54:
    %295 = llvm.load %294 : !llvm.ptr -> i32
    %296 = arith.cmpi slt, %295, %287 : i32
    cf.cond_br %296, ^bb55, ^bb56
    ^bb55:
      %297 = arith.constant 1 : i32
      %298 = llvm.load %294 : !llvm.ptr -> i32
      %299 = arith.trunci %297 : i32 to i8
      %300 = arith.extsi %298 : i32 to i64
      %301 = llvm.getelementptr %288[%300] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      llvm.store %299, %301 : i8, !llvm.ptr
      %302 = llvm.load %294 : !llvm.ptr -> i32
      %303 = arith.constant 1 : i32
      %304 = arith.addi %302, %303 : i32
      llvm.store %304, %294 : i32, !llvm.ptr
      cf.br ^bb54
    ^bb56:
    %305 = arith.constant 0 : i32
    %306 = arith.constant 0 : i32
    %307 = arith.trunci %305 : i32 to i8
    %308 = arith.extsi %306 : i32 to i64
    %309 = llvm.getelementptr %288[%308] : (!llvm.ptr, i64) -> !llvm.ptr, i8
    llvm.store %307, %309 : i8, !llvm.ptr
    %310 = func.call @isqrt(%arg0) : (i64) -> i64
    %311 = arith.trunci %310 : i64 to i32
    %312 = arith.constant 3 : i32
    %313 = llvm.mlir.constant(1 : i64) : i64
    %314 = llvm.alloca %313 x i32 : (i64) -> !llvm.ptr
    llvm.store %312, %314 : i32, !llvm.ptr
    cf.br ^bb57
    ^bb57:
    %315 = llvm.load %314 : !llvm.ptr -> i32
    %316 = arith.cmpi sle, %315, %311 : i32
    cf.cond_br %316, ^bb58, ^bb59
    ^bb58:
      %318 = llvm.load %314 : !llvm.ptr -> i32
      %319 = arith.constant 2 : i32
      %320 = arith.divsi %318, %319 : i32
      %321 = arith.extsi %320 : i32 to i64
      %322 = llvm.getelementptr %288[%321] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %317 = llvm.load %322 : !llvm.ptr -> i8
      %323 = arith.constant 0 : i32
      %325 = arith.extsi %317 : i8 to i32
      %324 = arith.cmpi ne, %325, %323 : i32
      cf.cond_br %324, ^bb60, ^bb61
      ^bb60:
        %326 = llvm.load %314 : !llvm.ptr -> i32
        %327 = llvm.load %314 : !llvm.ptr -> i32
        %328 = arith.muli %326, %327 : i32
        %329 = arith.constant 2 : i32
        %330 = arith.divsi %328, %329 : i32
        %331 = llvm.mlir.constant(1 : i64) : i64
        %332 = llvm.alloca %331 x i32 : (i64) -> !llvm.ptr
        llvm.store %330, %332 : i32, !llvm.ptr
        cf.br ^bb63
        ^bb63:
        %333 = llvm.load %332 : !llvm.ptr -> i32
        %334 = arith.cmpi slt, %333, %287 : i32
        cf.cond_br %334, ^bb64, ^bb65
        ^bb64:
          %335 = arith.constant 0 : i32
          %336 = llvm.load %332 : !llvm.ptr -> i32
          %337 = arith.trunci %335 : i32 to i8
          %338 = arith.extsi %336 : i32 to i64
          %339 = llvm.getelementptr %288[%338] : (!llvm.ptr, i64) -> !llvm.ptr, i8
          llvm.store %337, %339 : i8, !llvm.ptr
          %340 = llvm.load %332 : !llvm.ptr -> i32
          %341 = llvm.load %314 : !llvm.ptr -> i32
          %342 = arith.addi %340, %341 : i32
          llvm.store %342, %332 : i32, !llvm.ptr
          cf.br ^bb63
        ^bb65:
        cf.br ^bb62
      ^bb61:
        cf.br ^bb62
      ^bb62:
      %343 = llvm.load %314 : !llvm.ptr -> i32
      %344 = arith.constant 2 : i32
      %345 = arith.addi %343, %344 : i32
      llvm.store %345, %314 : i32, !llvm.ptr
      cf.br ^bb57
    ^bb59:
    %346 = arith.constant 0 : i32
    %347 = llvm.mlir.constant(1 : i64) : i64
    %348 = llvm.alloca %347 x i32 : (i64) -> !llvm.ptr
    llvm.store %346, %348 : i32, !llvm.ptr
    %349 = arith.constant 1 : i32
    llvm.store %349, %294 : i32, !llvm.ptr
    cf.br ^bb66
    ^bb66:
    %350 = llvm.load %294 : !llvm.ptr -> i32
    %351 = arith.cmpi slt, %350, %287 : i32
    cf.cond_br %351, ^bb67, ^bb68
    ^bb67:
      %353 = llvm.load %294 : !llvm.ptr -> i32
      %354 = arith.extsi %353 : i32 to i64
      %355 = llvm.getelementptr %288[%354] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %352 = llvm.load %355 : !llvm.ptr -> i8
      %356 = arith.constant 0 : i32
      %358 = arith.extsi %352 : i8 to i32
      %357 = arith.cmpi ne, %358, %356 : i32
      %359 = scf.if %357 -> (i1) {
        %360 = arith.constant 2 : i32
        %361 = llvm.load %294 : !llvm.ptr -> i32
        %362 = arith.muli %360, %361 : i32
        %363 = arith.constant 1 : i32
        %364 = arith.addi %362, %363 : i32
        %365 = arith.constant 4 : i32
        %366 = arith.remsi %364, %365 : i32
        %367 = arith.constant 1 : i32
        %368 = arith.cmpi eq, %366, %367 : i32
        scf.yield %368 : i1
      } else {
        %369 = arith.constant false
        scf.yield %369 : i1
      }
      cf.cond_br %359, ^bb69, ^bb70
      ^bb69:
        %370 = llvm.load %348 : !llvm.ptr -> i32
        %371 = arith.constant 1 : i32
        %372 = arith.addi %370, %371 : i32
        llvm.store %372, %348 : i32, !llvm.ptr
        cf.br ^bb71
      ^bb70:
        cf.br ^bb71
      ^bb71:
      %373 = llvm.load %294 : !llvm.ptr -> i32
      %374 = arith.constant 1 : i32
      %375 = arith.addi %373, %374 : i32
      llvm.store %375, %294 : i32, !llvm.ptr
      cf.br ^bb66
    ^bb68:
    %377 = llvm.load %348 : !llvm.ptr -> i32
    %378 = arith.constant 1 : i32
    %379 = arith.addi %377, %378 : i32
    %380 = arith.extsi %379 : i32 to i64
    %381 = arith.constant 4 : i32
    %382 = arith.extsi %381 : i32 to i64
    %376 = func.call @calloc(%380, %382) : (i64, i64) -> !llvm.ptr
    %383 = arith.constant 0 : i32
    %384 = llvm.mlir.constant(1 : i64) : i64
    %385 = llvm.alloca %384 x i32 : (i64) -> !llvm.ptr
    llvm.store %383, %385 : i32, !llvm.ptr
    %386 = arith.constant 1 : i32
    llvm.store %386, %294 : i32, !llvm.ptr
    cf.br ^bb72
    ^bb72:
    %387 = llvm.load %294 : !llvm.ptr -> i32
    %388 = arith.cmpi slt, %387, %287 : i32
    cf.cond_br %388, ^bb73, ^bb74
    ^bb73:
      %390 = llvm.load %294 : !llvm.ptr -> i32
      %391 = arith.extsi %390 : i32 to i64
      %392 = llvm.getelementptr %288[%391] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %389 = llvm.load %392 : !llvm.ptr -> i8
      %393 = arith.constant 0 : i32
      %395 = arith.extsi %389 : i8 to i32
      %394 = arith.cmpi ne, %395, %393 : i32
      %396 = scf.if %394 -> (i1) {
        %397 = arith.constant 2 : i32
        %398 = llvm.load %294 : !llvm.ptr -> i32
        %399 = arith.muli %397, %398 : i32
        %400 = arith.constant 1 : i32
        %401 = arith.addi %399, %400 : i32
        %402 = arith.constant 4 : i32
        %403 = arith.remsi %401, %402 : i32
        %404 = arith.constant 1 : i32
        %405 = arith.cmpi eq, %403, %404 : i32
        scf.yield %405 : i1
      } else {
        %406 = arith.constant false
        scf.yield %406 : i1
      }
      cf.cond_br %396, ^bb75, ^bb76
      ^bb75:
        %407 = arith.constant 2 : i32
        %408 = llvm.load %294 : !llvm.ptr -> i32
        %409 = arith.muli %407, %408 : i32
        %410 = arith.constant 1 : i32
        %411 = arith.addi %409, %410 : i32
        %412 = llvm.load %385 : !llvm.ptr -> i32
        %413 = arith.extsi %412 : i32 to i64
        %414 = llvm.getelementptr %376[%413] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %411, %414 : i32, !llvm.ptr
        %415 = llvm.load %385 : !llvm.ptr -> i32
        %416 = arith.constant 1 : i32
        %417 = arith.addi %415, %416 : i32
        llvm.store %417, %385 : i32, !llvm.ptr
        cf.br ^bb77
      ^bb76:
        cf.br ^bb77
      ^bb77:
      %418 = llvm.load %294 : !llvm.ptr -> i32
      %419 = arith.constant 1 : i32
      %420 = arith.addi %418, %419 : i32
      llvm.store %420, %294 : i32, !llvm.ptr
      cf.br ^bb72
    ^bb74:
    func.call @free(%288) : (!llvm.ptr) -> ()
    func.return %376 : !llvm.ptr
  }
  func.func @sqrt_minus_one_mod_p(%arg0: i32) -> i32 {
    %422 = arith.constant 1 : i32
    %423 = arith.subi %arg0, %422 : i32
    %424 = arith.extsi %423 : i32 to i64
    %425 = arith.constant 2 : i32
    %427 = arith.extsi %425 : i32 to i64
    %426 = arith.divsi %424, %427 : i64
    %428 = arith.constant 2 : i32
    %429 = llvm.mlir.constant(1 : i64) : i64
    %430 = llvm.alloca %429 x i32 : (i64) -> !llvm.ptr
    llvm.store %428, %430 : i32, !llvm.ptr
    cf.br ^bb78
    ^bb78:
    %432 = llvm.load %430 : !llvm.ptr -> i32
    %431 = func.call @mod_pow_u32(%432, %426, %arg0) : (i32, i64, i32) -> i32
    %433 = arith.constant 1 : i32
    %434 = arith.subi %arg0, %433 : i32
    %435 = arith.cmpi ne, %431, %434 : i32
    cf.cond_br %435, ^bb79, ^bb80
    ^bb79:
      %436 = llvm.load %430 : !llvm.ptr -> i32
      %437 = arith.constant 1 : i32
      %438 = arith.addi %436, %437 : i32
      llvm.store %438, %430 : i32, !llvm.ptr
      cf.br ^bb78
    ^bb80:
    %440 = llvm.load %430 : !llvm.ptr -> i32
    %441 = arith.constant 1 : i32
    %442 = arith.subi %arg0, %441 : i32
    %443 = arith.extsi %442 : i32 to i64
    %444 = arith.constant 4 : i32
    %446 = arith.extsi %444 : i32 to i64
    %445 = arith.divsi %443, %446 : i64
    %439 = func.call @mod_pow_u32(%440, %445, %arg0) : (i32, i64, i32) -> i32
    func.return %439 : i32
  }
  func.func @roots_minus_one_mod_p2(%arg0: i32) -> () {
    %447 = func.call @sqrt_minus_one_mod_p(%arg0) : (i32) -> i32
    %448 = arith.extsi %arg0 : i32 to i64
    %449 = arith.extsi %arg0 : i32 to i64
    %450 = arith.muli %448, %449 : i64
    %451 = arith.extsi %447 : i32 to i64
    %452 = arith.extsi %447 : i32 to i64
    %453 = arith.muli %451, %452 : i64
    %454 = arith.constant 1 : i32
    %456 = arith.extsi %454 : i32 to i64
    %455 = arith.addi %453, %456 : i64
    %457 = arith.extsi %arg0 : i32 to i64
    %458 = arith.divsi %455, %457 : i64
    %460 = arith.constant 2 : i32
    %461 = arith.muli %460, %447 : i32
    %462 = arith.remsi %461, %arg0 : i32
    %463 = arith.constant 2 : i32
    %464 = arith.subi %arg0, %463 : i32
    %465 = arith.extsi %464 : i32 to i64
    %459 = func.call @mod_pow_u32(%462, %465, %arg0) : (i32, i64, i32) -> i32
    %466 = arith.extsi %arg0 : i32 to i64
    %467 = arith.remsi %458, %466 : i64
    %469 = arith.extsi %arg0 : i32 to i64
    %468 = arith.subi %469, %467 : i64
    %470 = arith.extsi %459 : i32 to i64
    %471 = arith.muli %468, %470 : i64
    %472 = arith.extsi %arg0 : i32 to i64
    %473 = arith.remsi %471, %472 : i64
    %474 = arith.extsi %447 : i32 to i64
    %475 = arith.extsi %arg0 : i32 to i64
    %476 = arith.muli %473, %475 : i64
    %477 = arith.addi %474, %476 : i64
    %478 = arith.remsi %477, %450 : i64
    %479 = llvm.mlir.addressof @g_r1 : !llvm.ptr
    llvm.store %478, %479 : i64, !llvm.ptr
    %480 = arith.subi %450, %478 : i64
    %481 = arith.remsi %480, %450 : i64
    %482 = llvm.mlir.addressof @g_r2 : !llvm.ptr
    llvm.store %481, %482 : i64, !llvm.ptr
    func.return
  }
  func.func @crt_combine(%arg0: !llvm.ptr, %arg1: !llvm.ptr, %arg2: i32, %arg3: i64, %arg4: i64, %arg5: i64, %arg6: i64) -> () {
    %483 = func.call @mod_inv_i128(%arg3, %arg6) : (i64, i64) -> i64
    %484 = arith.constant 0 : i32
    %485 = llvm.mlir.constant(1 : i64) : i64
    %486 = llvm.alloca %485 x i32 : (i64) -> !llvm.ptr
    llvm.store %484, %486 : i32, !llvm.ptr
    cf.br ^bb81
    ^bb81:
    %487 = llvm.load %486 : !llvm.ptr -> i32
    %488 = arith.cmpi slt, %487, %arg2 : i32
    cf.cond_br %488, ^bb82, ^bb83
    ^bb82:
      %490 = llvm.load %486 : !llvm.ptr -> i32
      %491 = arith.extsi %490 : i32 to i64
      %492 = llvm.getelementptr %arg1[%491] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %489 = llvm.load %492 : !llvm.ptr -> i64
      %493 = arith.remsi %489, %arg6 : i64
      %494 = arith.addi %arg4, %arg6 : i64
      %495 = arith.subi %494, %493 : i64
      %496 = arith.remsi %495, %arg6 : i64
      %497 = arith.extsi %496 : i64 to i128
      %498 = arith.extsi %483 : i64 to i128
      %500 = arith.trunci %497 : i128 to i64
      %501 = arith.trunci %498 : i128 to i64
      %499 = arith.muli %500, %501 : i64
      %502 = arith.extsi %arg6 : i64 to i128
      %504 = arith.trunci %502 : i128 to i64
      %503 = arith.remsi %499, %504 : i64
      %505 = arith.muli %arg3, %503 : i64
      %506 = arith.addi %489, %505 : i64
      %507 = arith.constant 2 : i32
      %508 = llvm.load %486 : !llvm.ptr -> i32
      %509 = arith.muli %507, %508 : i32
      %510 = arith.extsi %509 : i32 to i64
      %511 = llvm.getelementptr %arg0[%510] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %506, %511 : i64, !llvm.ptr
      %512 = arith.addi %arg5, %arg6 : i64
      %513 = arith.subi %512, %493 : i64
      %514 = arith.remsi %513, %arg6 : i64
      %515 = arith.extsi %514 : i64 to i128
      %516 = arith.extsi %483 : i64 to i128
      %518 = arith.trunci %515 : i128 to i64
      %519 = arith.trunci %516 : i128 to i64
      %517 = arith.muli %518, %519 : i64
      %520 = arith.extsi %arg6 : i64 to i128
      %522 = arith.trunci %520 : i128 to i64
      %521 = arith.remsi %517, %522 : i64
      %523 = arith.muli %arg3, %521 : i64
      %524 = arith.addi %489, %523 : i64
      %525 = arith.constant 2 : i32
      %526 = llvm.load %486 : !llvm.ptr -> i32
      %527 = arith.muli %525, %526 : i32
      %528 = arith.constant 1 : i32
      %529 = arith.addi %527, %528 : i32
      %530 = arith.extsi %529 : i32 to i64
      %531 = llvm.getelementptr %arg0[%530] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %524, %531 : i64, !llvm.ptr
      %532 = llvm.load %486 : !llvm.ptr -> i32
      %533 = arith.constant 1 : i32
      %534 = arith.addi %532, %533 : i32
      llvm.store %534, %486 : i32, !llvm.ptr
      cf.br ^bb81
    ^bb83:
    func.return
  }
  func.func @dms_dfs(%arg0: i32, %arg1: i64, %arg2: i64, %arg3: !llvm.ptr, %arg4: i32, %arg5: i32) -> () {
    %535 = llvm.mlir.constant(1 : i64) : i64
    %536 = llvm.alloca %535 x i32 : (i64) -> !llvm.ptr
    llvm.store %arg0, %536 : i32, !llvm.ptr
    cf.br ^bb84
    ^bb84:
    %537 = llvm.load %536 : !llvm.ptr -> i32
    %538 = llvm.mlir.addressof @g_dms_P : !llvm.ptr
    %539 = llvm.load %538 : !llvm.ptr -> i32
    %540 = arith.cmpi slt, %537, %539 : i32
    cf.cond_br %540, ^bb85, ^bb86
    ^bb85:
      %542 = llvm.mlir.addressof @g_dms_primes : !llvm.ptr
      %543 = llvm.load %542 : !llvm.ptr -> !llvm.ptr
      %544 = llvm.load %536 : !llvm.ptr -> i32
      %545 = arith.extsi %544 : i32 to i64
      %546 = llvm.getelementptr %543[%545] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %541 = llvm.load %546 : !llvm.ptr -> i32
      %547 = arith.extsi %541 : i32 to i64
      %548 = arith.muli %arg1, %547 : i64
      %549 = llvm.mlir.addressof @g_dms_D : !llvm.ptr
      %550 = llvm.load %549 : !llvm.ptr -> i64
      %551 = arith.cmpi sgt, %548, %550 : i64
      cf.cond_br %551, ^bb87, ^bb88
      ^bb87:
        cf.br ^bb86
      ^bb88:
        cf.br ^bb89
      ^bb89:
      %552 = arith.extsi %541 : i32 to i64
      %553 = arith.extsi %541 : i32 to i64
      %554 = arith.muli %552, %553 : i64
      %556 = llvm.mlir.addressof @g_dms_roots : !llvm.ptr
      %557 = llvm.load %556 : !llvm.ptr -> !llvm.ptr
      %558 = arith.constant 2 : i32
      %559 = llvm.load %536 : !llvm.ptr -> i32
      %560 = arith.muli %558, %559 : i32
      %561 = arith.extsi %560 : i32 to i64
      %562 = llvm.getelementptr %557[%561] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %555 = llvm.load %562 : !llvm.ptr -> i64
      %564 = llvm.mlir.addressof @g_dms_roots : !llvm.ptr
      %565 = llvm.load %564 : !llvm.ptr -> !llvm.ptr
      %566 = arith.constant 2 : i32
      %567 = llvm.load %536 : !llvm.ptr -> i32
      %568 = arith.muli %566, %567 : i32
      %569 = arith.constant 1 : i32
      %570 = arith.addi %568, %569 : i32
      %571 = arith.extsi %570 : i32 to i64
      %572 = llvm.getelementptr %565[%571] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %563 = llvm.load %572 : !llvm.ptr -> i64
      %573 = arith.extsi %arg2 : i64 to i128
      %574 = arith.extsi %554 : i64 to i128
      %576 = arith.trunci %573 : i128 to i64
      %577 = arith.trunci %574 : i128 to i64
      %575 = arith.muli %576, %577 : i64
      %578 = arith.constant 2 : i32
      %579 = arith.muli %arg4, %578 : i32
      %581 = arith.extsi %579 : i32 to i64
      %582 = arith.constant 8 : i32
      %583 = arith.extsi %582 : i32 to i64
      %580 = func.call @calloc(%581, %583) : (i64, i64) -> !llvm.ptr
      func.call @crt_combine(%580, %arg3, %arg4, %arg2, %555, %563, %554) : (!llvm.ptr, !llvm.ptr, i32, i64, i64, i64, i64) -> ()
      %585 = arith.constant 0 : i32
      %586 = arith.extsi %585 : i32 to i64
      %587 = llvm.mlir.constant(1 : i64) : i64
      %588 = llvm.alloca %587 x i64 : (i64) -> !llvm.ptr
      llvm.store %586, %588 : i64, !llvm.ptr
      %589 = llvm.mlir.addressof @g_dms_n : !llvm.ptr
      %590 = llvm.load %589 : !llvm.ptr -> i64
      %591 = arith.cmpi sle, %575, %590 : i64
      cf.cond_br %591, ^bb90, ^bb91
      ^bb90:
        %592 = llvm.mlir.addressof @g_dms_n : !llvm.ptr
        %593 = llvm.load %592 : !llvm.ptr -> i64
        %594 = arith.divsi %593, %575 : i64
        %595 = llvm.mlir.addressof @g_dms_n : !llvm.ptr
        %596 = llvm.load %595 : !llvm.ptr -> i64
        %597 = arith.remsi %596, %575 : i64
        %598 = arith.extsi %579 : i32 to i64
        %599 = arith.muli %594, %598 : i64
        llvm.store %599, %588 : i64, !llvm.ptr
        %600 = arith.constant 0 : i32
        %601 = llvm.mlir.constant(1 : i64) : i64
        %602 = llvm.alloca %601 x i32 : (i64) -> !llvm.ptr
        llvm.store %600, %602 : i32, !llvm.ptr
        cf.br ^bb93
        ^bb93:
        %603 = llvm.load %602 : !llvm.ptr -> i32
        %604 = arith.cmpi slt, %603, %579 : i32
        cf.cond_br %604, ^bb94, ^bb95
        ^bb94:
          %606 = llvm.load %602 : !llvm.ptr -> i32
          %607 = arith.extsi %606 : i32 to i64
          %608 = llvm.getelementptr %580[%607] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %605 = llvm.load %608 : !llvm.ptr -> i64
          %609 = arith.cmpi sle, %605, %597 : i64
          cf.cond_br %609, ^bb96, ^bb97
          ^bb96:
            %610 = llvm.load %588 : !llvm.ptr -> i64
            %611 = arith.constant 1 : i32
            %613 = arith.extsi %611 : i32 to i64
            %612 = arith.addi %610, %613 : i64
            llvm.store %612, %588 : i64, !llvm.ptr
            cf.br ^bb98
          ^bb97:
            cf.br ^bb98
          ^bb98:
          %614 = llvm.load %602 : !llvm.ptr -> i32
          %615 = arith.constant 1 : i32
          %616 = arith.addi %614, %615 : i32
          llvm.store %616, %602 : i32, !llvm.ptr
          cf.br ^bb93
        ^bb95:
        cf.br ^bb92
      ^bb91:
        %617 = arith.constant 0 : i32
        %618 = llvm.mlir.constant(1 : i64) : i64
        %619 = llvm.alloca %618 x i32 : (i64) -> !llvm.ptr
        llvm.store %617, %619 : i32, !llvm.ptr
        cf.br ^bb99
        ^bb99:
        %620 = llvm.load %619 : !llvm.ptr -> i32
        %621 = arith.cmpi slt, %620, %579 : i32
        cf.cond_br %621, ^bb100, ^bb101
        ^bb100:
          %623 = llvm.load %619 : !llvm.ptr -> i32
          %624 = arith.extsi %623 : i32 to i64
          %625 = llvm.getelementptr %580[%624] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %622 = llvm.load %625 : !llvm.ptr -> i64
          %626 = llvm.mlir.addressof @g_dms_n : !llvm.ptr
          %627 = llvm.load %626 : !llvm.ptr -> i64
          %628 = arith.cmpi sle, %622, %627 : i64
          cf.cond_br %628, ^bb102, ^bb103
          ^bb102:
            %629 = llvm.load %588 : !llvm.ptr -> i64
            %630 = arith.constant 1 : i32
            %632 = arith.extsi %630 : i32 to i64
            %631 = arith.addi %629, %632 : i64
            llvm.store %631, %588 : i64, !llvm.ptr
            cf.br ^bb104
          ^bb103:
            cf.br ^bb104
          ^bb104:
          %633 = llvm.load %619 : !llvm.ptr -> i32
          %634 = arith.constant 1 : i32
          %635 = arith.addi %633, %634 : i32
          llvm.store %635, %619 : i32, !llvm.ptr
          cf.br ^bb99
        ^bb101:
        cf.br ^bb92
      ^bb92:
      %636 = arith.constant 0 : i32
      %637 = arith.extsi %arg5 : i32 to i64
      %639 = arith.extsi %636 : i32 to i64
      %638 = arith.subi %639, %637 : i64
      %640 = llvm.load %588 : !llvm.ptr -> i64
      %641 = arith.muli %638, %640 : i64
      %642 = llvm.mlir.addressof @g_dms_ans : !llvm.ptr
      %643 = llvm.load %642 : !llvm.ptr -> i64
      %644 = arith.addi %643, %641 : i64
      %645 = llvm.mlir.addressof @g_dms_ans : !llvm.ptr
      llvm.store %644, %645 : i64, !llvm.ptr
      %647 = llvm.load %536 : !llvm.ptr -> i32
      %648 = arith.constant 1 : i32
      %649 = arith.addi %647, %648 : i32
      %650 = arith.constant 0 : i32
      %651 = arith.subi %650, %arg5 : i32
      func.call @dms_dfs(%649, %548, %575, %580, %579, %651) : (i32, i64, i64, !llvm.ptr, i32, i32) -> ()
      func.call @free(%580) : (!llvm.ptr) -> ()
      %653 = llvm.load %536 : !llvm.ptr -> i32
      %654 = arith.constant 1 : i32
      %655 = arith.addi %653, %654 : i32
      llvm.store %655, %536 : i32, !llvm.ptr
      cf.br ^bb84
    ^bb86:
    func.return
  }
  func.func @direct_mobius_sum(%arg0: i64, %arg1: i64) -> i64 {
    %656 = func.call @primes_1mod4_upto(%arg1) : (i64) -> !llvm.ptr
    %657 = arith.constant 0 : i32
    %658 = llvm.mlir.constant(1 : i64) : i64
    %659 = llvm.alloca %658 x i32 : (i64) -> !llvm.ptr
    llvm.store %657, %659 : i32, !llvm.ptr
    %660 = arith.constant 0 : i32
    %661 = llvm.mlir.constant(1 : i64) : i64
    %662 = llvm.alloca %661 x i32 : (i64) -> !llvm.ptr
    llvm.store %660, %662 : i32, !llvm.ptr
    cf.br ^bb105
    ^bb105:
    %663 = arith.constant 1 : i1
    cf.cond_br %663, ^bb106, ^bb107
    ^bb106:
      %665 = llvm.load %662 : !llvm.ptr -> i32
      %666 = arith.extsi %665 : i32 to i64
      %667 = llvm.getelementptr %656[%666] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %664 = llvm.load %667 : !llvm.ptr -> i32
      %668 = arith.constant 0 : i32
      %669 = arith.cmpi eq, %664, %668 : i32
      cf.cond_br %669, ^bb108, ^bb109
      ^bb108:
        cf.br ^bb107
      ^bb109:
        cf.br ^bb110
      ^bb110:
      %670 = llvm.load %659 : !llvm.ptr -> i32
      %671 = arith.constant 1 : i32
      %672 = arith.addi %670, %671 : i32
      llvm.store %672, %659 : i32, !llvm.ptr
      %673 = llvm.load %662 : !llvm.ptr -> i32
      %674 = arith.constant 1 : i32
      %675 = arith.addi %673, %674 : i32
      llvm.store %675, %662 : i32, !llvm.ptr
      cf.br ^bb105
    ^bb107:
    %677 = llvm.load %659 : !llvm.ptr -> i32
    %678 = arith.constant 2 : i32
    %679 = arith.muli %677, %678 : i32
    %680 = arith.extsi %679 : i32 to i64
    %681 = arith.constant 8 : i32
    %682 = arith.extsi %681 : i32 to i64
    %676 = func.call @calloc(%680, %682) : (i64, i64) -> !llvm.ptr
    %683 = llvm.mlir.addressof @g_dms_roots : !llvm.ptr
    llvm.store %676, %683 : !llvm.ptr, !llvm.ptr
    %684 = arith.constant 0 : i32
    %685 = llvm.mlir.constant(1 : i64) : i64
    %686 = llvm.alloca %685 x i32 : (i64) -> !llvm.ptr
    llvm.store %684, %686 : i32, !llvm.ptr
    cf.br ^bb111
    ^bb111:
    %687 = llvm.load %686 : !llvm.ptr -> i32
    %688 = llvm.load %659 : !llvm.ptr -> i32
    %689 = arith.cmpi slt, %687, %688 : i32
    cf.cond_br %689, ^bb112, ^bb113
    ^bb112:
      %692 = llvm.load %686 : !llvm.ptr -> i32
      %693 = arith.extsi %692 : i32 to i64
      %694 = llvm.getelementptr %656[%693] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %691 = llvm.load %694 : !llvm.ptr -> i32
      func.call @roots_minus_one_mod_p2(%691) : (i32) -> ()
      %695 = llvm.mlir.addressof @g_r1 : !llvm.ptr
      %696 = llvm.load %695 : !llvm.ptr -> i64
      %697 = llvm.mlir.addressof @g_dms_roots : !llvm.ptr
      %698 = llvm.load %697 : !llvm.ptr -> !llvm.ptr
      %699 = arith.constant 2 : i32
      %700 = llvm.load %686 : !llvm.ptr -> i32
      %701 = arith.muli %699, %700 : i32
      %702 = arith.extsi %701 : i32 to i64
      %703 = llvm.getelementptr %698[%702] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %696, %703 : i64, !llvm.ptr
      %704 = llvm.mlir.addressof @g_r2 : !llvm.ptr
      %705 = llvm.load %704 : !llvm.ptr -> i64
      %706 = llvm.mlir.addressof @g_dms_roots : !llvm.ptr
      %707 = llvm.load %706 : !llvm.ptr -> !llvm.ptr
      %708 = arith.constant 2 : i32
      %709 = llvm.load %686 : !llvm.ptr -> i32
      %710 = arith.muli %708, %709 : i32
      %711 = arith.constant 1 : i32
      %712 = arith.addi %710, %711 : i32
      %713 = arith.extsi %712 : i32 to i64
      %714 = llvm.getelementptr %707[%713] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %705, %714 : i64, !llvm.ptr
      %715 = llvm.load %686 : !llvm.ptr -> i32
      %716 = arith.constant 1 : i32
      %717 = arith.addi %715, %716 : i32
      llvm.store %717, %686 : i32, !llvm.ptr
      cf.br ^bb111
    ^bb113:
    %718 = llvm.mlir.addressof @g_dms_n : !llvm.ptr
    llvm.store %arg0, %718 : i64, !llvm.ptr
    %719 = llvm.mlir.addressof @g_dms_D : !llvm.ptr
    llvm.store %arg1, %719 : i64, !llvm.ptr
    %720 = llvm.mlir.addressof @g_dms_primes : !llvm.ptr
    llvm.store %656, %720 : !llvm.ptr, !llvm.ptr
    %721 = llvm.load %659 : !llvm.ptr -> i32
    %722 = llvm.mlir.addressof @g_dms_P : !llvm.ptr
    llvm.store %721, %722 : i32, !llvm.ptr
    %723 = llvm.mlir.addressof @g_dms_ans : !llvm.ptr
    llvm.store %arg0, %723 : i64, !llvm.ptr
    %725 = arith.constant 1 : i32
    %726 = arith.constant 8 : i32
    %727 = arith.extsi %725 : i32 to i64
    %728 = arith.extsi %726 : i32 to i64
    %724 = func.call @calloc(%727, %728) : (i64, i64) -> !llvm.ptr
    %729 = arith.constant 0 : i32
    %730 = arith.constant 0 : i32
    %731 = arith.extsi %729 : i32 to i64
    %732 = arith.extsi %730 : i32 to i64
    %733 = llvm.getelementptr %724[%732] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %731, %733 : i64, !llvm.ptr
    %735 = arith.constant 0 : i32
    %736 = arith.constant 1 : i32
    %737 = arith.constant 1 : i32
    %738 = arith.constant 1 : i32
    %739 = arith.constant 1 : i32
    %740 = arith.extsi %736 : i32 to i64
    %741 = arith.extsi %737 : i32 to i64
    func.call @dms_dfs(%735, %740, %741, %724, %738, %739) : (i32, i64, i64, !llvm.ptr, i32, i32) -> ()
    func.call @free(%724) : (!llvm.ptr) -> ()
    %744 = llvm.mlir.addressof @g_dms_roots : !llvm.ptr
    %745 = llvm.load %744 : !llvm.ptr -> !llvm.ptr
    func.call @free(%745) : (!llvm.ptr) -> ()
    func.call @free(%656) : (!llvm.ptr) -> ()
    %747 = llvm.mlir.addressof @g_dms_ans : !llvm.ptr
    %748 = llvm.load %747 : !llvm.ptr -> i64
    func.return %748 : i64
  }
  func.func @negative_pell_fundamental(%arg0: i64, %arg1: i64) -> i32 {
    %749 = func.call @isqrt(%arg0) : (i64) -> i64
    %750 = arith.muli %749, %749 : i64
    %751 = arith.cmpi eq, %750, %arg0 : i64
    cf.cond_br %751, ^bb114, ^bb115
    ^bb114:
      %752 = arith.constant 0 : i32
      func.return %752 : i32
    ^bb115:
      cf.br ^bb116
    ^bb116:
    %753 = arith.constant 0 : i32
    %754 = arith.extsi %753 : i32 to i64
    %755 = llvm.mlir.constant(1 : i64) : i64
    %756 = llvm.alloca %755 x i64 : (i64) -> !llvm.ptr
    llvm.store %754, %756 : i64, !llvm.ptr
    %757 = arith.constant 1 : i32
    %758 = arith.extsi %757 : i32 to i64
    %759 = llvm.mlir.constant(1 : i64) : i64
    %760 = llvm.alloca %759 x i64 : (i64) -> !llvm.ptr
    llvm.store %758, %760 : i64, !llvm.ptr
    %761 = llvm.mlir.constant(1 : i64) : i64
    %762 = llvm.alloca %761 x i64 : (i64) -> !llvm.ptr
    llvm.store %749, %762 : i64, !llvm.ptr
    %763 = arith.constant 1 : i32
    %764 = arith.extsi %763 : i32 to i64
    %765 = llvm.mlir.constant(1 : i64) : i64
    %766 = llvm.alloca %765 x i64 : (i64) -> !llvm.ptr
    llvm.store %764, %766 : i64, !llvm.ptr
    %767 = llvm.mlir.constant(1 : i64) : i64
    %768 = llvm.alloca %767 x i64 : (i64) -> !llvm.ptr
    llvm.store %749, %768 : i64, !llvm.ptr
    %769 = arith.constant 0 : i32
    %770 = arith.extsi %769 : i32 to i64
    %771 = llvm.mlir.constant(1 : i64) : i64
    %772 = llvm.alloca %771 x i64 : (i64) -> !llvm.ptr
    llvm.store %770, %772 : i64, !llvm.ptr
    %773 = arith.constant 1 : i32
    %774 = arith.extsi %773 : i32 to i64
    %775 = llvm.mlir.constant(1 : i64) : i64
    %776 = llvm.alloca %775 x i64 : (i64) -> !llvm.ptr
    llvm.store %774, %776 : i64, !llvm.ptr
    %777 = arith.constant 0 : i32
    %778 = llvm.mlir.constant(1 : i64) : i64
    %779 = llvm.alloca %778 x i32 : (i64) -> !llvm.ptr
    llvm.store %777, %779 : i32, !llvm.ptr
    cf.br ^bb117
    ^bb117:
    %780 = arith.constant 1 : i1
    cf.cond_br %780, ^bb118, ^bb119
    ^bb118:
      %781 = llvm.load %760 : !llvm.ptr -> i64
      %782 = llvm.load %762 : !llvm.ptr -> i64
      %783 = arith.muli %781, %782 : i64
      %784 = llvm.load %756 : !llvm.ptr -> i64
      %785 = arith.subi %783, %784 : i64
      llvm.store %785, %756 : i64, !llvm.ptr
      %786 = llvm.load %756 : !llvm.ptr -> i64
      %787 = llvm.load %756 : !llvm.ptr -> i64
      %788 = arith.muli %786, %787 : i64
      %789 = arith.subi %arg0, %788 : i64
      %790 = llvm.load %760 : !llvm.ptr -> i64
      %791 = arith.divsi %789, %790 : i64
      llvm.store %791, %760 : i64, !llvm.ptr
      %792 = llvm.load %756 : !llvm.ptr -> i64
      %793 = arith.addi %749, %792 : i64
      %794 = llvm.load %760 : !llvm.ptr -> i64
      %795 = arith.divsi %793, %794 : i64
      llvm.store %795, %762 : i64, !llvm.ptr
      %796 = llvm.load %762 : !llvm.ptr -> i64
      %797 = llvm.load %768 : !llvm.ptr -> i64
      %798 = arith.muli %796, %797 : i64
      %799 = llvm.load %766 : !llvm.ptr -> i64
      %800 = arith.addi %798, %799 : i64
      %801 = llvm.load %762 : !llvm.ptr -> i64
      %802 = llvm.load %776 : !llvm.ptr -> i64
      %803 = arith.muli %801, %802 : i64
      %804 = llvm.load %772 : !llvm.ptr -> i64
      %805 = arith.addi %803, %804 : i64
      %806 = llvm.load %768 : !llvm.ptr -> i64
      llvm.store %806, %766 : i64, !llvm.ptr
      llvm.store %800, %768 : i64, !llvm.ptr
      %807 = llvm.load %776 : !llvm.ptr -> i64
      llvm.store %807, %772 : i64, !llvm.ptr
      llvm.store %805, %776 : i64, !llvm.ptr
      %808 = llvm.load %779 : !llvm.ptr -> i32
      %809 = arith.constant 1 : i32
      %810 = arith.addi %808, %809 : i32
      llvm.store %810, %779 : i32, !llvm.ptr
      %811 = llvm.load %766 : !llvm.ptr -> i64
      %812 = arith.cmpi sgt, %811, %arg1 : i64
      cf.cond_br %812, ^bb120, ^bb121
      ^bb120:
        %813 = arith.constant 0 : i32
        func.return %813 : i32
      ^bb121:
        cf.br ^bb122
      ^bb122:
      %814 = llvm.load %762 : !llvm.ptr -> i64
      %815 = arith.constant 2 : i32
      %817 = arith.extsi %815 : i32 to i64
      %816 = arith.muli %817, %749 : i64
      %818 = arith.cmpi eq, %814, %816 : i64
      cf.cond_br %818, ^bb123, ^bb124
      ^bb123:
        cf.br ^bb119
      ^bb124:
        cf.br ^bb125
      ^bb125:
      cf.br ^bb117
    ^bb119:
    %819 = llvm.load %779 : !llvm.ptr -> i32
    %820 = arith.constant 2 : i32
    %821 = arith.remsi %819, %820 : i32
    %822 = arith.constant 0 : i32
    %823 = arith.cmpi eq, %821, %822 : i32
    cf.cond_br %823, ^bb126, ^bb127
    ^bb126:
      %824 = arith.constant 0 : i32
      func.return %824 : i32
    ^bb127:
      cf.br ^bb128
    ^bb128:
    %825 = llvm.load %766 : !llvm.ptr -> i64
    %826 = llvm.load %766 : !llvm.ptr -> i64
    %827 = arith.muli %825, %826 : i64
    %828 = llvm.load %772 : !llvm.ptr -> i64
    %829 = arith.muli %arg0, %828 : i64
    %830 = llvm.load %772 : !llvm.ptr -> i64
    %831 = arith.muli %829, %830 : i64
    %832 = arith.subi %827, %831 : i64
    %833 = arith.constant 0 : i32
    %834 = arith.constant 1 : i32
    %835 = arith.subi %833, %834 : i32
    %837 = arith.extsi %835 : i32 to i64
    %836 = arith.cmpi ne, %832, %837 : i64
    cf.cond_br %836, ^bb129, ^bb130
    ^bb129:
      %838 = arith.constant 0 : i32
      func.return %838 : i32
    ^bb130:
      cf.br ^bb131
    ^bb131:
    %839 = llvm.load %766 : !llvm.ptr -> i64
    %840 = llvm.mlir.addressof @g_pell_x : !llvm.ptr
    llvm.store %839, %840 : i64, !llvm.ptr
    %841 = llvm.load %772 : !llvm.ptr -> i64
    %842 = llvm.mlir.addressof @g_pell_y : !llvm.ptr
    llvm.store %841, %842 : i64, !llvm.ptr
    %843 = arith.constant 1 : i32
    func.return %843 : i32
  }
  func.func @linear_sieve_kmax(%arg0: i64) -> () {
    %845 = arith.constant 1 : i32
    %847 = arith.extsi %845 : i32 to i64
    %846 = arith.addi %arg0, %847 : i64
    %848 = arith.constant 4 : i32
    %849 = arith.extsi %848 : i32 to i64
    %844 = func.call @calloc(%846, %849) : (i64, i64) -> !llvm.ptr
    %850 = llvm.mlir.addressof @g_spf_kmax : !llvm.ptr
    llvm.store %844, %850 : !llvm.ptr, !llvm.ptr
    %852 = arith.constant 1 : i32
    %854 = arith.extsi %852 : i32 to i64
    %853 = arith.addi %arg0, %854 : i64
    %855 = arith.constant 1 : i32
    %856 = arith.extsi %855 : i32 to i64
    %851 = func.call @calloc(%853, %856) : (i64, i64) -> !llvm.ptr
    %857 = llvm.mlir.addressof @g_mu_kmax : !llvm.ptr
    llvm.store %851, %857 : !llvm.ptr, !llvm.ptr
    %859 = arith.constant 10 : i32
    %861 = arith.extsi %859 : i32 to i64
    %860 = arith.divsi %arg0, %861 : i64
    %862 = arith.constant 10000 : i32
    %864 = arith.extsi %862 : i32 to i64
    %863 = arith.addi %860, %864 : i64
    %865 = arith.constant 4 : i32
    %866 = arith.extsi %865 : i32 to i64
    %858 = func.call @calloc(%863, %866) : (i64, i64) -> !llvm.ptr
    %867 = arith.constant 0 : i32
    %868 = llvm.mlir.constant(1 : i64) : i64
    %869 = llvm.alloca %868 x i32 : (i64) -> !llvm.ptr
    llvm.store %867, %869 : i32, !llvm.ptr
    %870 = arith.constant 1 : i32
    %871 = llvm.mlir.addressof @g_mu_kmax : !llvm.ptr
    %872 = llvm.load %871 : !llvm.ptr -> !llvm.ptr
    %873 = arith.constant 1 : i32
    %874 = arith.trunci %870 : i32 to i8
    %875 = arith.extsi %873 : i32 to i64
    %876 = llvm.getelementptr %872[%875] : (!llvm.ptr, i64) -> !llvm.ptr, i8
    llvm.store %874, %876 : i8, !llvm.ptr
    %877 = arith.constant 2 : i32
    %878 = llvm.mlir.constant(1 : i64) : i64
    %879 = llvm.alloca %878 x i32 : (i64) -> !llvm.ptr
    llvm.store %877, %879 : i32, !llvm.ptr
    cf.br ^bb132
    ^bb132:
    %880 = llvm.load %879 : !llvm.ptr -> i32
    %881 = arith.extsi %880 : i32 to i64
    %882 = arith.cmpi sle, %881, %arg0 : i64
    cf.cond_br %882, ^bb133, ^bb134
    ^bb133:
      %884 = llvm.mlir.addressof @g_spf_kmax : !llvm.ptr
      %885 = llvm.load %884 : !llvm.ptr -> !llvm.ptr
      %886 = llvm.load %879 : !llvm.ptr -> i32
      %887 = arith.extsi %886 : i32 to i64
      %888 = llvm.getelementptr %885[%887] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %883 = llvm.load %888 : !llvm.ptr -> i32
      %889 = arith.constant 0 : i32
      %890 = arith.cmpi eq, %883, %889 : i32
      cf.cond_br %890, ^bb135, ^bb136
      ^bb135:
        %891 = llvm.load %879 : !llvm.ptr -> i32
        %892 = llvm.mlir.addressof @g_spf_kmax : !llvm.ptr
        %893 = llvm.load %892 : !llvm.ptr -> !llvm.ptr
        %894 = llvm.load %879 : !llvm.ptr -> i32
        %895 = arith.extsi %894 : i32 to i64
        %896 = llvm.getelementptr %893[%895] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %891, %896 : i32, !llvm.ptr
        %897 = llvm.load %879 : !llvm.ptr -> i32
        %898 = llvm.load %869 : !llvm.ptr -> i32
        %899 = arith.extsi %898 : i32 to i64
        %900 = llvm.getelementptr %858[%899] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %897, %900 : i32, !llvm.ptr
        %901 = llvm.load %869 : !llvm.ptr -> i32
        %902 = arith.constant 1 : i32
        %903 = arith.addi %901, %902 : i32
        llvm.store %903, %869 : i32, !llvm.ptr
        %904 = arith.constant 0 : i32
        %905 = arith.constant 1 : i32
        %906 = arith.subi %904, %905 : i32
        %907 = llvm.mlir.addressof @g_mu_kmax : !llvm.ptr
        %908 = llvm.load %907 : !llvm.ptr -> !llvm.ptr
        %909 = llvm.load %879 : !llvm.ptr -> i32
        %910 = arith.trunci %906 : i32 to i8
        %911 = arith.extsi %909 : i32 to i64
        %912 = llvm.getelementptr %908[%911] : (!llvm.ptr, i64) -> !llvm.ptr, i8
        llvm.store %910, %912 : i8, !llvm.ptr
        cf.br ^bb137
      ^bb136:
        cf.br ^bb137
      ^bb137:
      %913 = arith.constant 0 : i32
      %914 = llvm.mlir.constant(1 : i64) : i64
      %915 = llvm.alloca %914 x i32 : (i64) -> !llvm.ptr
      llvm.store %913, %915 : i32, !llvm.ptr
      cf.br ^bb138
      ^bb138:
      %916 = llvm.load %915 : !llvm.ptr -> i32
      %917 = llvm.load %869 : !llvm.ptr -> i32
      %918 = arith.cmpi slt, %916, %917 : i32
      cf.cond_br %918, ^bb139, ^bb140
      ^bb139:
        %920 = llvm.load %915 : !llvm.ptr -> i32
        %921 = arith.extsi %920 : i32 to i64
        %922 = llvm.getelementptr %858[%921] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %919 = llvm.load %922 : !llvm.ptr -> i32
        %923 = llvm.load %879 : !llvm.ptr -> i32
        %924 = arith.extsi %923 : i32 to i64
        %925 = arith.extsi %919 : i32 to i64
        %926 = arith.muli %924, %925 : i64
        %927 = arith.cmpi sgt, %926, %arg0 : i64
        cf.cond_br %927, ^bb141, ^bb142
        ^bb141:
          cf.br ^bb140
        ^bb142:
          cf.br ^bb143
        ^bb143:
        %928 = llvm.mlir.addressof @g_spf_kmax : !llvm.ptr
        %929 = llvm.load %928 : !llvm.ptr -> !llvm.ptr
        %930 = arith.trunci %926 : i64 to i32
        %931 = arith.extsi %930 : i32 to i64
        %932 = llvm.getelementptr %929[%931] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %919, %932 : i32, !llvm.ptr
        %933 = llvm.load %879 : !llvm.ptr -> i32
        %934 = arith.remsi %933, %919 : i32
        %935 = arith.constant 0 : i32
        %936 = arith.cmpi eq, %934, %935 : i32
        cf.cond_br %936, ^bb144, ^bb145
        ^bb144:
          %937 = arith.constant 0 : i32
          %938 = llvm.mlir.addressof @g_mu_kmax : !llvm.ptr
          %939 = llvm.load %938 : !llvm.ptr -> !llvm.ptr
          %940 = arith.trunci %926 : i64 to i32
          %941 = arith.trunci %937 : i32 to i8
          %942 = arith.extsi %940 : i32 to i64
          %943 = llvm.getelementptr %939[%942] : (!llvm.ptr, i64) -> !llvm.ptr, i8
          llvm.store %941, %943 : i8, !llvm.ptr
          cf.br ^bb140
        ^bb145:
          cf.br ^bb146
        ^bb146:
        %944 = arith.constant 0 : i32
        %946 = llvm.mlir.addressof @g_mu_kmax : !llvm.ptr
        %947 = llvm.load %946 : !llvm.ptr -> !llvm.ptr
        %948 = llvm.load %879 : !llvm.ptr -> i32
        %949 = arith.extsi %948 : i32 to i64
        %950 = llvm.getelementptr %947[%949] : (!llvm.ptr, i64) -> !llvm.ptr, i8
        %945 = llvm.load %950 : !llvm.ptr -> i8
        %952 = arith.extsi %945 : i8 to i32
        %951 = arith.subi %944, %952 : i32
        %953 = llvm.mlir.addressof @g_mu_kmax : !llvm.ptr
        %954 = llvm.load %953 : !llvm.ptr -> !llvm.ptr
        %955 = arith.trunci %926 : i64 to i32
        %956 = arith.trunci %951 : i32 to i8
        %957 = arith.extsi %955 : i32 to i64
        %958 = llvm.getelementptr %954[%957] : (!llvm.ptr, i64) -> !llvm.ptr, i8
        llvm.store %956, %958 : i8, !llvm.ptr
        %959 = llvm.load %915 : !llvm.ptr -> i32
        %960 = arith.constant 1 : i32
        %961 = arith.addi %959, %960 : i32
        llvm.store %961, %915 : i32, !llvm.ptr
        cf.br ^bb138
      ^bb140:
      %962 = llvm.load %879 : !llvm.ptr -> i32
      %963 = arith.constant 1 : i32
      %964 = arith.addi %962, %963 : i32
      llvm.store %964, %879 : i32, !llvm.ptr
      cf.br ^bb132
    ^bb134:
    func.call @free(%858) : (!llvm.ptr) -> ()
    func.return
  }
  func.func @build_primes_for_factoring(%arg0: i64) -> () {
    %966 = llvm.mlir.zero : !llvm.ptr
    %967 = llvm.mlir.addressof @g_primes_for_fact : !llvm.ptr
    llvm.store %966, %967 : !llvm.ptr, !llvm.ptr
    %968 = arith.constant 0 : i32
    %969 = llvm.mlir.addressof @g_primes_for_fact_count : !llvm.ptr
    llvm.store %968, %969 : i32, !llvm.ptr
    %970 = arith.constant 2 : i32
    %972 = arith.extsi %970 : i32 to i64
    %971 = arith.cmpi slt, %arg0, %972 : i64
    cf.cond_br %971, ^bb147, ^bb148
    ^bb147:
      func.return
    ^bb148:
      cf.br ^bb149
    ^bb149:
    %973 = arith.constant 2 : i32
    %975 = arith.extsi %973 : i32 to i64
    %974 = arith.divsi %arg0, %975 : i64
    %976 = arith.constant 1 : i32
    %978 = arith.extsi %976 : i32 to i64
    %977 = arith.addi %974, %978 : i64
    %979 = arith.trunci %977 : i64 to i32
    %981 = arith.extsi %979 : i32 to i64
    %982 = arith.constant 1 : i32
    %983 = arith.extsi %982 : i32 to i64
    %980 = func.call @calloc(%981, %983) : (i64, i64) -> !llvm.ptr
    %984 = arith.constant 0 : i32
    %985 = llvm.mlir.constant(1 : i64) : i64
    %986 = llvm.alloca %985 x i32 : (i64) -> !llvm.ptr
    llvm.store %984, %986 : i32, !llvm.ptr
    cf.br ^bb150
    ^bb150:
    %987 = llvm.load %986 : !llvm.ptr -> i32
    %988 = arith.cmpi slt, %987, %979 : i32
    cf.cond_br %988, ^bb151, ^bb152
    ^bb151:
      %989 = arith.constant 1 : i32
      %990 = llvm.load %986 : !llvm.ptr -> i32
      %991 = arith.trunci %989 : i32 to i8
      %992 = arith.extsi %990 : i32 to i64
      %993 = llvm.getelementptr %980[%992] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      llvm.store %991, %993 : i8, !llvm.ptr
      %994 = llvm.load %986 : !llvm.ptr -> i32
      %995 = arith.constant 1 : i32
      %996 = arith.addi %994, %995 : i32
      llvm.store %996, %986 : i32, !llvm.ptr
      cf.br ^bb150
    ^bb152:
    %997 = arith.constant 0 : i32
    %998 = arith.constant 0 : i32
    %999 = arith.trunci %997 : i32 to i8
    %1000 = arith.extsi %998 : i32 to i64
    %1001 = llvm.getelementptr %980[%1000] : (!llvm.ptr, i64) -> !llvm.ptr, i8
    llvm.store %999, %1001 : i8, !llvm.ptr
    %1002 = func.call @isqrt(%arg0) : (i64) -> i64
    %1003 = arith.trunci %1002 : i64 to i32
    %1004 = arith.constant 3 : i32
    %1005 = llvm.mlir.constant(1 : i64) : i64
    %1006 = llvm.alloca %1005 x i32 : (i64) -> !llvm.ptr
    llvm.store %1004, %1006 : i32, !llvm.ptr
    cf.br ^bb153
    ^bb153:
    %1007 = llvm.load %1006 : !llvm.ptr -> i32
    %1008 = arith.cmpi sle, %1007, %1003 : i32
    cf.cond_br %1008, ^bb154, ^bb155
    ^bb154:
      %1010 = llvm.load %1006 : !llvm.ptr -> i32
      %1011 = arith.constant 2 : i32
      %1012 = arith.divsi %1010, %1011 : i32
      %1013 = arith.extsi %1012 : i32 to i64
      %1014 = llvm.getelementptr %980[%1013] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %1009 = llvm.load %1014 : !llvm.ptr -> i8
      %1015 = arith.constant 0 : i32
      %1017 = arith.extsi %1009 : i8 to i32
      %1016 = arith.cmpi ne, %1017, %1015 : i32
      cf.cond_br %1016, ^bb156, ^bb157
      ^bb156:
        %1018 = llvm.load %1006 : !llvm.ptr -> i32
        %1019 = llvm.load %1006 : !llvm.ptr -> i32
        %1020 = arith.muli %1018, %1019 : i32
        %1021 = arith.constant 2 : i32
        %1022 = arith.divsi %1020, %1021 : i32
        %1023 = llvm.mlir.constant(1 : i64) : i64
        %1024 = llvm.alloca %1023 x i32 : (i64) -> !llvm.ptr
        llvm.store %1022, %1024 : i32, !llvm.ptr
        cf.br ^bb159
        ^bb159:
        %1025 = llvm.load %1024 : !llvm.ptr -> i32
        %1026 = arith.cmpi slt, %1025, %979 : i32
        cf.cond_br %1026, ^bb160, ^bb161
        ^bb160:
          %1027 = arith.constant 0 : i32
          %1028 = llvm.load %1024 : !llvm.ptr -> i32
          %1029 = arith.trunci %1027 : i32 to i8
          %1030 = arith.extsi %1028 : i32 to i64
          %1031 = llvm.getelementptr %980[%1030] : (!llvm.ptr, i64) -> !llvm.ptr, i8
          llvm.store %1029, %1031 : i8, !llvm.ptr
          %1032 = llvm.load %1024 : !llvm.ptr -> i32
          %1033 = llvm.load %1006 : !llvm.ptr -> i32
          %1034 = arith.addi %1032, %1033 : i32
          llvm.store %1034, %1024 : i32, !llvm.ptr
          cf.br ^bb159
        ^bb161:
        cf.br ^bb158
      ^bb157:
        cf.br ^bb158
      ^bb158:
      %1035 = llvm.load %1006 : !llvm.ptr -> i32
      %1036 = arith.constant 2 : i32
      %1037 = arith.addi %1035, %1036 : i32
      llvm.store %1037, %1006 : i32, !llvm.ptr
      cf.br ^bb153
    ^bb155:
    %1038 = arith.constant 1 : i32
    %1039 = llvm.mlir.constant(1 : i64) : i64
    %1040 = llvm.alloca %1039 x i32 : (i64) -> !llvm.ptr
    llvm.store %1038, %1040 : i32, !llvm.ptr
    %1041 = arith.constant 1 : i32
    llvm.store %1041, %986 : i32, !llvm.ptr
    cf.br ^bb162
    ^bb162:
    %1042 = llvm.load %986 : !llvm.ptr -> i32
    %1043 = arith.cmpi slt, %1042, %979 : i32
    cf.cond_br %1043, ^bb163, ^bb164
    ^bb163:
      %1045 = llvm.load %986 : !llvm.ptr -> i32
      %1046 = arith.extsi %1045 : i32 to i64
      %1047 = llvm.getelementptr %980[%1046] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %1044 = llvm.load %1047 : !llvm.ptr -> i8
      %1048 = arith.constant 0 : i32
      %1050 = arith.extsi %1044 : i8 to i32
      %1049 = arith.cmpi ne, %1050, %1048 : i32
      cf.cond_br %1049, ^bb165, ^bb166
      ^bb165:
        %1051 = llvm.load %1040 : !llvm.ptr -> i32
        %1052 = arith.constant 1 : i32
        %1053 = arith.addi %1051, %1052 : i32
        llvm.store %1053, %1040 : i32, !llvm.ptr
        cf.br ^bb167
      ^bb166:
        cf.br ^bb167
      ^bb167:
      %1054 = llvm.load %986 : !llvm.ptr -> i32
      %1055 = arith.constant 1 : i32
      %1056 = arith.addi %1054, %1055 : i32
      llvm.store %1056, %986 : i32, !llvm.ptr
      cf.br ^bb162
    ^bb164:
    %1058 = llvm.load %1040 : !llvm.ptr -> i32
    %1059 = arith.extsi %1058 : i32 to i64
    %1060 = arith.constant 4 : i32
    %1061 = arith.extsi %1060 : i32 to i64
    %1057 = func.call @calloc(%1059, %1061) : (i64, i64) -> !llvm.ptr
    %1062 = llvm.mlir.addressof @g_primes_for_fact : !llvm.ptr
    llvm.store %1057, %1062 : !llvm.ptr, !llvm.ptr
    %1063 = arith.constant 2 : i32
    %1064 = llvm.mlir.addressof @g_primes_for_fact : !llvm.ptr
    %1065 = llvm.load %1064 : !llvm.ptr -> !llvm.ptr
    %1066 = llvm.mlir.addressof @g_primes_for_fact_count : !llvm.ptr
    %1067 = llvm.load %1066 : !llvm.ptr -> i32
    %1068 = arith.extsi %1067 : i32 to i64
    %1069 = llvm.getelementptr %1065[%1068] : (!llvm.ptr, i64) -> !llvm.ptr, i32
    llvm.store %1063, %1069 : i32, !llvm.ptr
    %1070 = llvm.mlir.addressof @g_primes_for_fact_count : !llvm.ptr
    %1071 = llvm.load %1070 : !llvm.ptr -> i32
    %1072 = arith.constant 1 : i32
    %1073 = arith.addi %1071, %1072 : i32
    %1074 = llvm.mlir.addressof @g_primes_for_fact_count : !llvm.ptr
    llvm.store %1073, %1074 : i32, !llvm.ptr
    %1075 = arith.constant 1 : i32
    llvm.store %1075, %986 : i32, !llvm.ptr
    cf.br ^bb168
    ^bb168:
    %1076 = llvm.load %986 : !llvm.ptr -> i32
    %1077 = arith.cmpi slt, %1076, %979 : i32
    cf.cond_br %1077, ^bb169, ^bb170
    ^bb169:
      %1079 = llvm.load %986 : !llvm.ptr -> i32
      %1080 = arith.extsi %1079 : i32 to i64
      %1081 = llvm.getelementptr %980[%1080] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %1078 = llvm.load %1081 : !llvm.ptr -> i8
      %1082 = arith.constant 0 : i32
      %1084 = arith.extsi %1078 : i8 to i32
      %1083 = arith.cmpi ne, %1084, %1082 : i32
      cf.cond_br %1083, ^bb171, ^bb172
      ^bb171:
        %1085 = arith.constant 2 : i32
        %1086 = llvm.load %986 : !llvm.ptr -> i32
        %1087 = arith.muli %1085, %1086 : i32
        %1088 = arith.constant 1 : i32
        %1089 = arith.addi %1087, %1088 : i32
        %1090 = llvm.mlir.addressof @g_primes_for_fact : !llvm.ptr
        %1091 = llvm.load %1090 : !llvm.ptr -> !llvm.ptr
        %1092 = llvm.mlir.addressof @g_primes_for_fact_count : !llvm.ptr
        %1093 = llvm.load %1092 : !llvm.ptr -> i32
        %1094 = arith.extsi %1093 : i32 to i64
        %1095 = llvm.getelementptr %1091[%1094] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %1089, %1095 : i32, !llvm.ptr
        %1096 = llvm.mlir.addressof @g_primes_for_fact_count : !llvm.ptr
        %1097 = llvm.load %1096 : !llvm.ptr -> i32
        %1098 = arith.constant 1 : i32
        %1099 = arith.addi %1097, %1098 : i32
        %1100 = llvm.mlir.addressof @g_primes_for_fact_count : !llvm.ptr
        llvm.store %1099, %1100 : i32, !llvm.ptr
        cf.br ^bb173
      ^bb172:
        cf.br ^bb173
      ^bb173:
      %1101 = llvm.load %986 : !llvm.ptr -> i32
      %1102 = arith.constant 1 : i32
      %1103 = arith.addi %1101, %1102 : i32
      llvm.store %1103, %986 : i32, !llvm.ptr
      cf.br ^bb168
    ^bb170:
    func.call @free(%980) : (!llvm.ptr) -> ()
    func.return
  }
  func.func @factor_distinct_primes(%arg0: i64, %arg1: !llvm.ptr) -> i32 {
    %1105 = arith.constant 0 : i32
    %1106 = llvm.mlir.constant(1 : i64) : i64
    %1107 = llvm.alloca %1106 x i32 : (i64) -> !llvm.ptr
    llvm.store %1105, %1107 : i32, !llvm.ptr
    %1108 = llvm.mlir.constant(1 : i64) : i64
    %1109 = llvm.alloca %1108 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %1109 : i64, !llvm.ptr
    %1110 = arith.constant 0 : i32
    %1111 = llvm.mlir.constant(1 : i64) : i64
    %1112 = llvm.alloca %1111 x i32 : (i64) -> !llvm.ptr
    llvm.store %1110, %1112 : i32, !llvm.ptr
    cf.br ^bb174
    ^bb174:
    %1113 = llvm.load %1112 : !llvm.ptr -> i32
    %1114 = llvm.mlir.addressof @g_primes_for_fact_count : !llvm.ptr
    %1115 = llvm.load %1114 : !llvm.ptr -> i32
    %1116 = arith.cmpi slt, %1113, %1115 : i32
    cf.cond_br %1116, ^bb175, ^bb176
    ^bb175:
      %1118 = llvm.mlir.addressof @g_primes_for_fact : !llvm.ptr
      %1119 = llvm.load %1118 : !llvm.ptr -> !llvm.ptr
      %1120 = llvm.load %1112 : !llvm.ptr -> i32
      %1121 = arith.extsi %1120 : i32 to i64
      %1122 = llvm.getelementptr %1119[%1121] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %1117 = llvm.load %1122 : !llvm.ptr -> i32
      %1123 = arith.extsi %1117 : i32 to i64
      %1124 = arith.extsi %1117 : i32 to i64
      %1125 = arith.muli %1123, %1124 : i64
      %1126 = llvm.load %1109 : !llvm.ptr -> i64
      %1127 = arith.cmpi sgt, %1125, %1126 : i64
      cf.cond_br %1127, ^bb177, ^bb178
      ^bb177:
        cf.br ^bb176
      ^bb178:
        cf.br ^bb179
      ^bb179:
      %1128 = llvm.load %1109 : !llvm.ptr -> i64
      %1129 = arith.extsi %1117 : i32 to i64
      %1130 = arith.remsi %1128, %1129 : i64
      %1131 = arith.constant 0 : i32
      %1133 = arith.extsi %1131 : i32 to i64
      %1132 = arith.cmpi eq, %1130, %1133 : i64
      cf.cond_br %1132, ^bb180, ^bb181
      ^bb180:
        %1134 = llvm.load %1107 : !llvm.ptr -> i32
        %1135 = arith.extsi %1134 : i32 to i64
        %1136 = llvm.getelementptr %arg1[%1135] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %1117, %1136 : i32, !llvm.ptr
        %1137 = llvm.load %1107 : !llvm.ptr -> i32
        %1138 = arith.constant 1 : i32
        %1139 = arith.addi %1137, %1138 : i32
        llvm.store %1139, %1107 : i32, !llvm.ptr
        cf.br ^bb183
        ^bb183:
        %1140 = llvm.load %1109 : !llvm.ptr -> i64
        %1141 = arith.extsi %1117 : i32 to i64
        %1142 = arith.remsi %1140, %1141 : i64
        %1143 = arith.constant 0 : i32
        %1145 = arith.extsi %1143 : i32 to i64
        %1144 = arith.cmpi eq, %1142, %1145 : i64
        cf.cond_br %1144, ^bb184, ^bb185
        ^bb184:
          %1146 = llvm.load %1109 : !llvm.ptr -> i64
          %1147 = arith.extsi %1117 : i32 to i64
          %1148 = arith.divsi %1146, %1147 : i64
          llvm.store %1148, %1109 : i64, !llvm.ptr
          cf.br ^bb183
        ^bb185:
        cf.br ^bb182
      ^bb181:
        cf.br ^bb182
      ^bb182:
      %1149 = llvm.load %1112 : !llvm.ptr -> i32
      %1150 = arith.constant 1 : i32
      %1151 = arith.addi %1149, %1150 : i32
      llvm.store %1151, %1112 : i32, !llvm.ptr
      cf.br ^bb174
    ^bb176:
    %1152 = llvm.load %1109 : !llvm.ptr -> i64
    %1153 = arith.constant 1 : i32
    %1155 = arith.extsi %1153 : i32 to i64
    %1154 = arith.cmpi sgt, %1152, %1155 : i64
    cf.cond_br %1154, ^bb186, ^bb187
    ^bb186:
      %1156 = llvm.load %1109 : !llvm.ptr -> i64
      %1157 = arith.trunci %1156 : i64 to i32
      %1158 = llvm.load %1107 : !llvm.ptr -> i32
      %1159 = arith.extsi %1158 : i32 to i64
      %1160 = llvm.getelementptr %arg1[%1159] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      llvm.store %1157, %1160 : i32, !llvm.ptr
      %1161 = llvm.load %1107 : !llvm.ptr -> i32
      %1162 = arith.constant 1 : i32
      %1163 = arith.addi %1161, %1162 : i32
      llvm.store %1163, %1107 : i32, !llvm.ptr
      cf.br ^bb188
    ^bb187:
      cf.br ^bb188
    ^bb188:
    %1164 = llvm.load %1107 : !llvm.ptr -> i32
    func.return %1164 : i32
  }
  func.func @mobius_tail_sum_for_y(%arg0: i64, %arg1: i64) -> i64 {
    %1166 = arith.constant 64 : i32
    %1167 = arith.constant 4 : i32
    %1168 = arith.extsi %1166 : i32 to i64
    %1169 = arith.extsi %1167 : i32 to i64
    %1165 = func.call @calloc(%1168, %1169) : (i64, i64) -> !llvm.ptr
    %1170 = func.call @factor_distinct_primes(%arg0, %1165) : (i64, !llvm.ptr) -> i32
    %1171 = arith.constant 0 : i32
    %1172 = arith.extsi %1171 : i32 to i64
    %1173 = llvm.mlir.constant(1 : i64) : i64
    %1174 = llvm.alloca %1173 x i64 : (i64) -> !llvm.ptr
    llvm.store %1172, %1174 : i64, !llvm.ptr
    %1175 = arith.constant 1 : i32
    %1176 = arith.shli %1175, %1170 : i32
    %1177 = arith.constant 0 : i32
    %1178 = llvm.mlir.constant(1 : i64) : i64
    %1179 = llvm.alloca %1178 x i32 : (i64) -> !llvm.ptr
    llvm.store %1177, %1179 : i32, !llvm.ptr
    cf.br ^bb189
    ^bb189:
    %1180 = llvm.load %1179 : !llvm.ptr -> i32
    %1181 = arith.cmpi slt, %1180, %1176 : i32
    cf.cond_br %1181, ^bb190, ^bb191
    ^bb190:
      %1182 = arith.constant 1 : i32
      %1183 = arith.extsi %1182 : i32 to i64
      %1184 = llvm.mlir.constant(1 : i64) : i64
      %1185 = llvm.alloca %1184 x i64 : (i64) -> !llvm.ptr
      llvm.store %1183, %1185 : i64, !llvm.ptr
      %1186 = arith.constant 0 : i32
      %1187 = llvm.mlir.constant(1 : i64) : i64
      %1188 = llvm.alloca %1187 x i32 : (i64) -> !llvm.ptr
      llvm.store %1186, %1188 : i32, !llvm.ptr
      %1189 = arith.constant 0 : i32
      %1190 = llvm.mlir.constant(1 : i64) : i64
      %1191 = llvm.alloca %1190 x i32 : (i64) -> !llvm.ptr
      llvm.store %1189, %1191 : i32, !llvm.ptr
      cf.br ^bb192
      ^bb192:
      %1192 = llvm.load %1191 : !llvm.ptr -> i32
      %1193 = arith.cmpi slt, %1192, %1170 : i32
      cf.cond_br %1193, ^bb193, ^bb194
      ^bb193:
        %1194 = llvm.load %1179 : !llvm.ptr -> i32
        %1195 = arith.constant 1 : i32
        %1196 = llvm.load %1191 : !llvm.ptr -> i32
        %1197 = arith.shli %1195, %1196 : i32
        %1198 = arith.andi %1194, %1197 : i32
        %1199 = arith.constant 0 : i32
        %1200 = arith.cmpi ne, %1198, %1199 : i32
        cf.cond_br %1200, ^bb195, ^bb196
        ^bb195:
          %1201 = llvm.load %1185 : !llvm.ptr -> i64
          %1203 = llvm.load %1191 : !llvm.ptr -> i32
          %1204 = arith.extsi %1203 : i32 to i64
          %1205 = llvm.getelementptr %1165[%1204] : (!llvm.ptr, i64) -> !llvm.ptr, i32
          %1202 = llvm.load %1205 : !llvm.ptr -> i32
          %1206 = arith.extsi %1202 : i32 to i64
          %1207 = arith.muli %1201, %1206 : i64
          llvm.store %1207, %1185 : i64, !llvm.ptr
          %1208 = llvm.load %1188 : !llvm.ptr -> i32
          %1209 = arith.constant 1 : i32
          %1210 = arith.xori %1208, %1209 : i32
          llvm.store %1210, %1188 : i32, !llvm.ptr
          cf.br ^bb197
        ^bb196:
          cf.br ^bb197
        ^bb197:
        %1211 = llvm.load %1191 : !llvm.ptr -> i32
        %1212 = arith.constant 1 : i32
        %1213 = arith.addi %1211, %1212 : i32
        llvm.store %1213, %1191 : i32, !llvm.ptr
        cf.br ^bb192
      ^bb194:
      %1214 = llvm.load %1185 : !llvm.ptr -> i64
      %1215 = arith.cmpi sgt, %1214, %arg1 : i64
      cf.cond_br %1215, ^bb198, ^bb199
      ^bb198:
        %1216 = llvm.load %1188 : !llvm.ptr -> i32
        %1217 = arith.constant 0 : i32
        %1218 = arith.cmpi ne, %1216, %1217 : i32
        cf.cond_br %1218, ^bb201, ^bb202
        ^bb201:
          %1219 = llvm.load %1174 : !llvm.ptr -> i64
          %1220 = arith.constant 1 : i32
          %1222 = arith.extsi %1220 : i32 to i64
          %1221 = arith.subi %1219, %1222 : i64
          llvm.store %1221, %1174 : i64, !llvm.ptr
          cf.br ^bb203
        ^bb202:
          %1223 = llvm.load %1174 : !llvm.ptr -> i64
          %1224 = arith.constant 1 : i32
          %1226 = arith.extsi %1224 : i32 to i64
          %1225 = arith.addi %1223, %1226 : i64
          llvm.store %1225, %1174 : i64, !llvm.ptr
          cf.br ^bb203
        ^bb203:
        cf.br ^bb200
      ^bb199:
        cf.br ^bb200
      ^bb200:
      %1227 = llvm.load %1179 : !llvm.ptr -> i32
      %1228 = arith.constant 1 : i32
      %1229 = arith.addi %1227, %1228 : i32
      llvm.store %1229, %1179 : i32, !llvm.ptr
      cf.br ^bb189
    ^bb191:
    func.call @free(%1165) : (!llvm.ptr) -> ()
    %1231 = llvm.load %1174 : !llvm.ptr -> i64
    func.return %1231 : i64
  }
  func.func @correction_via_pell(%arg0: i64, %arg1: i64) -> i64 {
    %1232 = arith.extsi %arg0 : i64 to i128
    %1233 = arith.extsi %arg0 : i64 to i128
    %1235 = arith.trunci %1232 : i128 to i64
    %1236 = arith.trunci %1233 : i128 to i64
    %1234 = arith.muli %1235, %1236 : i64
    %1237 = arith.constant 1 : i32
    %1239 = arith.extsi %1237 : i32 to i64
    %1238 = arith.addi %1234, %1239 : i64
    %1240 = arith.extsi %arg1 : i64 to i128
    %1241 = arith.extsi %arg1 : i64 to i128
    %1243 = arith.trunci %1240 : i128 to i64
    %1244 = arith.trunci %1241 : i128 to i64
    %1242 = arith.muli %1243, %1244 : i64
    %1245 = arith.divsi %1238, %1242 : i64
    %1246 = arith.constant 2 : i32
    %1248 = arith.extsi %1246 : i32 to i64
    %1247 = arith.cmpi slt, %1245, %1248 : i64
    cf.cond_br %1247, ^bb204, ^bb205
    ^bb204:
      %1249 = arith.constant 0 : i32
      %1250 = arith.extsi %1249 : i32 to i64
      func.return %1250 : i64
    ^bb205:
      cf.br ^bb206
    ^bb206:
    func.call @linear_sieve_kmax(%1245) : (i64) -> ()
    %1252 = func.call @isqrt(%arg0) : (i64) -> i64
    %1254 = arith.constant 1 : i32
    %1256 = arith.extsi %1254 : i32 to i64
    %1255 = arith.addi %1252, %1256 : i64
    func.call @build_primes_for_factoring(%1255) : (i64) -> ()
    %1257 = arith.constant 0 : i32
    %1258 = arith.extsi %1257 : i32 to i64
    %1259 = llvm.mlir.constant(1 : i64) : i64
    %1260 = llvm.alloca %1259 x i64 : (i64) -> !llvm.ptr
    llvm.store %1258, %1260 : i64, !llvm.ptr
    %1261 = arith.constant 2 : i32
    %1262 = arith.extsi %1261 : i32 to i64
    %1263 = llvm.mlir.constant(1 : i64) : i64
    %1264 = llvm.alloca %1263 x i64 : (i64) -> !llvm.ptr
    llvm.store %1262, %1264 : i64, !llvm.ptr
    cf.br ^bb207
    ^bb207:
    %1265 = llvm.load %1264 : !llvm.ptr -> i64
    %1266 = arith.cmpi sle, %1265, %1245 : i64
    cf.cond_br %1266, ^bb208, ^bb209
    ^bb208:
      %1268 = llvm.mlir.addressof @g_mu_kmax : !llvm.ptr
      %1269 = llvm.load %1268 : !llvm.ptr -> !llvm.ptr
      %1270 = llvm.load %1264 : !llvm.ptr -> i64
      %1271 = llvm.getelementptr %1269[%1270] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %1267 = llvm.load %1271 : !llvm.ptr -> i8
      %1272 = arith.constant 0 : i32
      %1274 = arith.extsi %1267 : i8 to i32
      %1273 = arith.cmpi ne, %1274, %1272 : i32
      cf.cond_br %1273, ^bb210, ^bb211
      ^bb210:
        %1275 = llvm.load %1264 : !llvm.ptr -> i64
        %1276 = llvm.mlir.constant(1 : i64) : i64
        %1277 = llvm.alloca %1276 x i64 : (i64) -> !llvm.ptr
        llvm.store %1275, %1277 : i64, !llvm.ptr
        %1278 = arith.constant 1 : i32
        %1279 = llvm.mlir.constant(1 : i64) : i64
        %1280 = llvm.alloca %1279 x i32 : (i64) -> !llvm.ptr
        llvm.store %1278, %1280 : i32, !llvm.ptr
        cf.br ^bb213
        ^bb213:
        %1281 = llvm.load %1277 : !llvm.ptr -> i64
        %1282 = arith.constant 1 : i32
        %1284 = arith.extsi %1282 : i32 to i64
        %1283 = arith.cmpi sgt, %1281, %1284 : i64
        cf.cond_br %1283, ^bb214, ^bb215
        ^bb214:
          %1286 = llvm.mlir.addressof @g_spf_kmax : !llvm.ptr
          %1287 = llvm.load %1286 : !llvm.ptr -> !llvm.ptr
          %1288 = llvm.load %1277 : !llvm.ptr -> i64
          %1289 = arith.trunci %1288 : i64 to i32
          %1290 = arith.extsi %1289 : i32 to i64
          %1291 = llvm.getelementptr %1287[%1290] : (!llvm.ptr, i64) -> !llvm.ptr, i32
          %1285 = llvm.load %1291 : !llvm.ptr -> i32
          %1292 = llvm.load %1277 : !llvm.ptr -> i64
          %1293 = arith.extsi %1285 : i32 to i64
          %1294 = arith.divsi %1292, %1293 : i64
          llvm.store %1294, %1277 : i64, !llvm.ptr
          %1295 = arith.constant 2 : i32
          %1296 = arith.cmpi ne, %1285, %1295 : i32
          %1297 = scf.if %1296 -> (i1) {
            %1298 = arith.constant 3 : i32
            %1299 = arith.andi %1285, %1298 : i32
            %1300 = arith.constant 3 : i32
            %1301 = arith.cmpi eq, %1299, %1300 : i32
            scf.yield %1301 : i1
          } else {
            %1302 = arith.constant false
            scf.yield %1302 : i1
          }
          cf.cond_br %1297, ^bb216, ^bb217
          ^bb216:
            %1303 = arith.constant 0 : i32
            llvm.store %1303, %1280 : i32, !llvm.ptr
            cf.br ^bb215
          ^bb217:
            cf.br ^bb218
          ^bb218:
          cf.br ^bb213
        ^bb215:
        %1304 = llvm.load %1280 : !llvm.ptr -> i32
        %1305 = arith.constant 0 : i32
        %1306 = arith.cmpi ne, %1304, %1305 : i32
        cf.cond_br %1306, ^bb219, ^bb220
        ^bb219:
          %1308 = llvm.load %1264 : !llvm.ptr -> i64
          %1307 = func.call @negative_pell_fundamental(%1308, %arg0) : (i64, i64) -> i32
          %1309 = arith.constant 0 : i32
          %1310 = arith.cmpi ne, %1307, %1309 : i32
          cf.cond_br %1310, ^bb222, ^bb223
          ^bb222:
            %1311 = llvm.mlir.addressof @g_pell_x : !llvm.ptr
            %1312 = llvm.load %1311 : !llvm.ptr -> i64
            %1313 = llvm.mlir.addressof @g_pell_y : !llvm.ptr
            %1314 = llvm.load %1313 : !llvm.ptr -> i64
            %1315 = arith.extsi %1312 : i64 to i128
            %1316 = arith.extsi %1312 : i64 to i128
            %1318 = arith.trunci %1315 : i128 to i64
            %1319 = arith.trunci %1316 : i128 to i64
            %1317 = arith.muli %1318, %1319 : i64
            %1320 = llvm.load %1264 : !llvm.ptr -> i64
            %1321 = arith.extsi %1320 : i64 to i128
            %1322 = arith.extsi %1314 : i64 to i128
            %1324 = arith.trunci %1321 : i128 to i64
            %1325 = arith.trunci %1322 : i128 to i64
            %1323 = arith.muli %1324, %1325 : i64
            %1326 = arith.extsi %1314 : i64 to i128
            %1328 = arith.trunci %1326 : i128 to i64
            %1327 = arith.muli %1323, %1328 : i64
            %1329 = arith.addi %1317, %1327 : i64
            %1330 = arith.extsi %1329 : i64 to i128
            %1331 = arith.constant 2 : i32
            %1332 = arith.extsi %1331 : i32 to i128
            %1333 = arith.extsi %1312 : i64 to i128
            %1335 = arith.trunci %1332 : i128 to i64
            %1336 = arith.trunci %1333 : i128 to i64
            %1334 = arith.muli %1335, %1336 : i64
            %1337 = arith.extsi %1314 : i64 to i128
            %1339 = arith.trunci %1337 : i128 to i64
            %1338 = arith.muli %1334, %1339 : i64
            %1340 = arith.extsi %1338 : i64 to i128
            %1341 = llvm.mlir.constant(1 : i64) : i64
            %1342 = llvm.alloca %1341 x i64 : (i64) -> !llvm.ptr
            llvm.store %1312, %1342 : i64, !llvm.ptr
            %1343 = llvm.mlir.constant(1 : i64) : i64
            %1344 = llvm.alloca %1343 x i64 : (i64) -> !llvm.ptr
            llvm.store %1314, %1344 : i64, !llvm.ptr
            cf.br ^bb225
            ^bb225:
            %1345 = llvm.load %1342 : !llvm.ptr -> i64
            %1346 = arith.cmpi sle, %1345, %arg0 : i64
            cf.cond_br %1346, ^bb226, ^bb227
            ^bb226:
              %1347 = llvm.load %1344 : !llvm.ptr -> i64
              %1348 = arith.cmpi sgt, %1347, %arg1 : i64
              cf.cond_br %1348, ^bb228, ^bb229
              ^bb228:
                %1349 = llvm.load %1260 : !llvm.ptr -> i64
                %1351 = llvm.load %1344 : !llvm.ptr -> i64
                %1350 = func.call @mobius_tail_sum_for_y(%1351, %arg1) : (i64, i64) -> i64
                %1352 = arith.addi %1349, %1350 : i64
                llvm.store %1352, %1260 : i64, !llvm.ptr
                cf.br ^bb230
              ^bb229:
                cf.br ^bb230
              ^bb230:
              %1353 = llvm.load %1342 : !llvm.ptr -> i64
              %1354 = arith.extsi %1353 : i64 to i128
              %1356 = arith.trunci %1330 : i128 to i64
              %1357 = arith.trunci %1354 : i128 to i64
              %1355 = arith.muli %1356, %1357 : i64
              %1358 = llvm.load %1264 : !llvm.ptr -> i64
              %1359 = arith.extsi %1358 : i64 to i128
              %1361 = arith.trunci %1359 : i128 to i64
              %1362 = arith.trunci %1340 : i128 to i64
              %1360 = arith.muli %1361, %1362 : i64
              %1363 = llvm.load %1344 : !llvm.ptr -> i64
              %1364 = arith.extsi %1363 : i64 to i128
              %1366 = arith.trunci %1364 : i128 to i64
              %1365 = arith.muli %1360, %1366 : i64
              %1367 = arith.addi %1355, %1365 : i64
              %1368 = arith.extsi %1367 : i64 to i128
              %1369 = llvm.load %1342 : !llvm.ptr -> i64
              %1370 = arith.extsi %1369 : i64 to i128
              %1372 = arith.trunci %1340 : i128 to i64
              %1373 = arith.trunci %1370 : i128 to i64
              %1371 = arith.muli %1372, %1373 : i64
              %1374 = llvm.load %1344 : !llvm.ptr -> i64
              %1375 = arith.extsi %1374 : i64 to i128
              %1377 = arith.trunci %1330 : i128 to i64
              %1378 = arith.trunci %1375 : i128 to i64
              %1376 = arith.muli %1377, %1378 : i64
              %1379 = arith.addi %1371, %1376 : i64
              %1380 = arith.extsi %1379 : i64 to i128
              %1381 = arith.extsi %arg0 : i64 to i128
              %1383 = arith.trunci %1368 : i128 to i64
              %1384 = arith.trunci %1381 : i128 to i64
              %1382 = arith.cmpi sgt, %1383, %1384 : i64
              cf.cond_br %1382, ^bb231, ^bb232
              ^bb231:
                cf.br ^bb227
              ^bb232:
                cf.br ^bb233
              ^bb233:
              %1385 = arith.trunci %1368 : i128 to i64
              llvm.store %1385, %1342 : i64, !llvm.ptr
              %1386 = arith.trunci %1380 : i128 to i64
              llvm.store %1386, %1344 : i64, !llvm.ptr
              cf.br ^bb225
            ^bb227:
            cf.br ^bb224
          ^bb223:
            cf.br ^bb224
          ^bb224:
          cf.br ^bb221
        ^bb220:
          cf.br ^bb221
        ^bb221:
        cf.br ^bb212
      ^bb211:
        cf.br ^bb212
      ^bb212:
      %1387 = llvm.load %1264 : !llvm.ptr -> i64
      %1388 = arith.constant 1 : i32
      %1390 = arith.extsi %1388 : i32 to i64
      %1389 = arith.addi %1387, %1390 : i64
      llvm.store %1389, %1264 : i64, !llvm.ptr
      cf.br ^bb207
    ^bb209:
    %1392 = llvm.mlir.addressof @g_spf_kmax : !llvm.ptr
    %1393 = llvm.load %1392 : !llvm.ptr -> !llvm.ptr
    func.call @free(%1393) : (!llvm.ptr) -> ()
    %1395 = llvm.mlir.addressof @g_mu_kmax : !llvm.ptr
    %1396 = llvm.load %1395 : !llvm.ptr -> !llvm.ptr
    func.call @free(%1396) : (!llvm.ptr) -> ()
    %1398 = llvm.mlir.addressof @g_primes_for_fact : !llvm.ptr
    %1399 = llvm.load %1398 : !llvm.ptr -> !llvm.ptr
    func.call @free(%1399) : (!llvm.ptr) -> ()
    %1400 = llvm.load %1260 : !llvm.ptr -> i64
    func.return %1400 : i64
  }
  func.func @main() -> i32 {
    %1402 = llvm.mlir.addressof @N_VAL : !llvm.ptr
    %1403 = llvm.load %1402 : !llvm.ptr -> i64
    %1404 = llvm.mlir.addressof @D_VAL : !llvm.ptr
    %1405 = llvm.load %1404 : !llvm.ptr -> i64
    %1401 = func.call @direct_mobius_sum(%1403, %1405) : (i64, i64) -> i64
    %1407 = llvm.mlir.addressof @N_VAL : !llvm.ptr
    %1408 = llvm.load %1407 : !llvm.ptr -> i64
    %1409 = llvm.mlir.addressof @D_VAL : !llvm.ptr
    %1410 = llvm.load %1409 : !llvm.ptr -> i64
    %1406 = func.call @correction_via_pell(%1408, %1410) : (i64, i64) -> i64
    %1411 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %1412 = arith.addi %1401, %1406 : i64
    %1413 = llvm.call @printf(%1411, %1412) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    %1414 = arith.constant 0 : i32
    func.return %1414 : i32
  }
}