Problem 769

f(x,y) = x^2 + 5xy + 3y^2, i.e. f(x,y) = z^2 with z <= N, x,y>0, gcd(x,y)=1. N = 10^14. Two branches with inclusion-exclusion over distinct prime factors. Pure Flow port of the native C solver.

Answer14246712611506
Output14246712611506
StatusPASS
Native helperno
Runtime1340 ms
Peak memory26752 KB
Time complexityO(n^2) (estimated)
Space complexityO(n^2) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^2)O(1)
Space complexityO(n^2)O(1)
ApproachFlow solutionClosed-form formula
VerdictSuboptimal

Flow source

# Project Euler 769: Count primitive representations of squares by
# f(x,y) = x^2 + 5xy + 3y^2, i.e. f(x,y) = z^2 with z <= N, x,y>0, gcd(x,y)=1.
# N = 10^14. Two branches with inclusion-exclusion over distinct prime factors.
# Pure Flow port of the native C solver.

import euler.nt { isqrt }

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

const SQRT3: f64 = 1.7320508075688772

# Inverses mod 13.
let mut inv_mod13: ptr<i32> = null

function init_inv_mod13() -> void {
    inv_mod13 = calloc(13, 4) as ptr<i32>
    let mut a: i32 = 1
    while a < 13 {
        let mut x: i32 = 1
        while x < 13 {
            if (a * x) % 13 == 1 {
                inv_mod13[a] = x
                x = 13
            }
            x = x + 1
        }
        a = a + 1
    }
}

# Linear sieve for smallest prime factor.
let mut spf_arr: ptr<i32> = null

function build_spf(n: i64) -> void {
    spf_arr = calloc(n + 1, 4) as ptr<i32>
    let primes: ptr<i32> = calloc(n, 4) as ptr<i32>
    let mut pc: i64 = 0
    let mut i: i64 = 2
    while i <= n {
        if spf_arr[i] == 0 {
            spf_arr[i] = i as i32
            primes[pc] = i as i32
            pc = pc + 1
        }
        let mut j: i64 = 0
        while j < pc {
            let v: i64 = (primes[j] as i64) * i
            if v > n {
                j = pc
            } else {
                spf_arr[v] = primes[j]
                if (primes[j] as i64) == (spf_arr[i] as i64) {
                    j = pc
                } else {
                    j = j + 1
                }
            }
        }
        i = i + 1
    }
    free(primes)
}

# Distinct prime factors of n (n <= spf table size).
function distinct_prime_factors(n0: i64, out: ptr<i32>) -> i64 {
    let mut cnt: i64 = 0
    let mut n: i64 = n0
    while n > 1 {
        let p: i32 = spf_arr[n]
        out[cnt] = p
        cnt = cnt + 1
        while n % (p as i64) == 0 {
            n = n / (p as i64)
        }
    }
    return cnt
}

# Generate squarefree divisors and Mobius values.
function gen_divisors_mu(primes: ptr<i32>, np: i64, ds: ptr<i64>, mus: ptr<i32>) -> i64 {
    ds[0] = 1
    mus[0] = 1
    let mut len: i64 = 1
    let mut i: i64 = 0
    while i < np {
        let p: i64 = primes[i] as i64
        let mut j: i64 = 0
        while j < len {
            ds[j + len] = ds[j] * p
            mus[j + len] = -mus[j]
            j = j + 1
        }
        len = len * 2
        i = i + 1
    }
    return len
}

# Count integers in [L, R] with x = rem (mod modv), 0 <= rem < modv.
function count_cong(L: i64, R: i64, modv: i64, rem0: i64) -> i64 {
    let mut rem: i64 = rem0
    if rem < L {
        rem = rem + ((L - rem + modv - 1) / modv) * modv
    }
    if rem > R {
        return 0
    }
    return 1 + (R - rem) / modv
}

# Count coprime q in [L, R] with gcd(q, n) = 1.
function count_coprime_interval(L: i64, R: i64, ds: ptr<i64>, mus: ptr<i32>, nd: i64) -> i64 {
    let Lm: i64 = L - 1
    let mut total: i64 = 0
    let mut i: i64 = 0
    while i < nd {
        total = total + (mus[i] as i64) * (R / ds[i] - Lm / ds[i])
        i = i + 1
    }
    return total
}

# Count coprime q in [L, R] with q = rem13 (mod 13).
function count_coprime_mod13(ds: ptr<i64>, mus: ptr<i32>, nd: i64, L: i64, R: i64, rem13: i32) -> i64 {
    let mut total: i64 = 0
    let mut i: i64 = 0
    while i < nd {
        let d: i64 = ds[i]
        let inv: i32 = inv_mod13[(d % 13) as i32]
        let m0: i32 = (rem13 * inv) % 13
        let rem: i64 = d * (m0 as i64)
        let modv: i64 = 13 * d
        total = total + (mus[i] as i64) * count_cong(L, R, modv, rem)
        i = i + 1
    }
    return total
}

# Binary search for max a in negative branch.
function max_abs_p_negative(N: i64) -> i64 {
    let hi: i64 = isqrt(N) + 2
    let mut lo: i64 = 0
    while lo + 1 < hi {
        let a: i64 = (lo + hi) / 2
        if a == 0 {
            lo = a
        } else {
            let mut qmin: i64 = (SQRT3 * (a as f64)) as i64 + 1
            let thr: i64 = 3 * a * a
            while qmin * qmin <= thr {
                qmin = qmin + 1
            }
            let qmax: i64 = (5 * a - 1) / 2
            let mut ok: i32 = 0
            if qmin <= qmax {
                let z: i64 = -(qmin * qmin - 5 * a * qmin + 3 * a * a)
                if z <= N {
                    ok = 1
                }
            }
            if ok != 0 {
                lo = a
            } else {
                hi = a
            }
        }
    }
    return lo
}

# Main count C(N).
function C_func(N: i64) -> i64 {
    let fourN: i64 = 4 * N
    let mut total: i64 = 0

    let primes: ptr<i32> = calloc(32, 4) as ptr<i32>
    let ds: ptr<i64> = calloc(256, 8) as ptr<i64>
    let mus: ptr<i32> = calloc(256, 4) as ptr<i32>

    # Branch 1: p > 0, q > sqrt(3)*p, z = q^2 + 5pq + 3p^2
    let pmax: i64 = isqrt(N / 3)
    let mut p: i64 = 1
    while p <= pmax {
        let mut qmin: i64 = (SQRT3 * (p as f64)) as i64 + 1
        let thr: i64 = 3 * p * p
        while qmin * qmin <= thr {
            qmin = qmin + 1
        }

        let disc: i64 = 13 * p * p + fourN
        let mut qmax: i64 = (isqrt(disc) - 5 * p) / 2
        if qmax >= qmin {
            let pp3: i64 = 3 * p * p
            while qmax >= qmin && (qmax * qmax + 5 * p * qmax + pp3) > N {
                qmax = qmax - 1
            }
            if qmax >= qmin {
                let np: i64 = distinct_prime_factors(p, primes)
                let nd: i64 = gen_divisors_mu(primes, np, ds, mus)

                let mut cnt: i64 = count_coprime_interval(qmin, qmax, ds, mus, nd)

                if p % 13 != 0 {
                    let bad: i64 = count_coprime_mod13(ds, mus, nd, qmin, qmax, ((4 * p) % 13) as i32)
                    cnt = cnt - bad
                }
                total = total + cnt
            }
        }
        p = p + 1
    }

    # Branch 2: p = -a < 0, sqrt(3)*a < q < 2.5a, z = -(q^2 - 5aq + 3a^2)
    let amax: i64 = max_abs_p_negative(N)
    let threshold: i64 = isqrt(fourN / 13)

    let mut a: i64 = 1
    while a <= amax {
        let mut qmin: i64 = (SQRT3 * (a as f64)) as i64 + 1
        let thr: i64 = 3 * a * a
        while qmin * qmin <= thr {
            qmin = qmin + 1
        }

        let mut qmax: i64 = (5 * a - 1) / 2
        if qmax >= qmin {
            if a > threshold {
                let disc2: i64 = 13 * a * a - fourN
                let s: i64 = isqrt(disc2)
                let lim: i64 = (5 * a - s) / 2
                if lim < qmax {
                    qmax = lim
                }
            }

            while qmax >= qmin && (-(qmax * qmax - 5 * a * qmax + 3 * a * a)) > N {
                qmax = qmax - 1
            }
            if qmax >= qmin {
                let np: i64 = distinct_prime_factors(a, primes)
                let nd: i64 = gen_divisors_mu(primes, np, ds, mus)

                let mut cnt: i64 = count_coprime_interval(qmin, qmax, ds, mus, nd)

                if a % 13 != 0 {
                    let rem13: i32 = ((((-4 * a) % 13) + 13) % 13) as i32
                    let bad: i64 = count_coprime_mod13(ds, mus, nd, qmin, qmax, rem13)
                    cnt = cnt - bad
                }
                total = total + cnt
            }
        }
        a = a + 1
    }

    free(primes)
    free(ds)
    free(mus)
    return total
}

function main() -> i32 {
    init_inv_mod13()

    let N: i64 = 100000000000000
    let pmax: i64 = isqrt(N / 3)
    let amax: i64 = max_abs_p_negative(N)
    let mut maxp: i64 = pmax
    if amax > maxp {
        maxp = amax
    }

    build_spf(maxp)

    let ans: i64 = C_func(N)

    free(spf_arr)
    free(inv_mod13)
    printf("%lld\n", ans)
    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);
void init_inv_mod13(void);
void build_spf_i64(int64_t n);
int64_t distinct_prime_factors_i64_ptr_i32(int64_t n0, int32_t* out);
int64_t gen_divisors_mu_ptr_i32_i64_ptr_i64_ptr_i32(int32_t* primes, int64_t np, int64_t* ds, int32_t* mus);
int64_t count_cong_i64_i64_i64_i64(int64_t L, int64_t R, int64_t modv, int64_t rem0);
int64_t count_coprime_interval_i64_i64_ptr_i64_ptr_i32_i64(int64_t L, int64_t R, int64_t* ds, int32_t* mus, int64_t nd);
int64_t count_coprime_mod13_ptr_i64_ptr_i32_i64_i64_i64_i32(int64_t* ds, int32_t* mus, int64_t nd, int64_t L, int64_t R, int32_t rem13);
int64_t max_abs_p_negative_i64(int64_t N);
int64_t C_func_i64(int64_t N);
int32_t main(void);

static const double SQRT3 = 1.7320508075688772;

/* Module statics */
static int32_t* inv_mod13 = NULL;
static int32_t* spf_arr = NULL;

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

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

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

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

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

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




void init_inv_mod13(void) {
    inv_mod13 = ((int32_t*)(calloc(13, 4)));
    int32_t a = 1;
    while (a < 13) {
        int32_t x = 1;
        while (x < 13) {
            if (FLOW_CHECKED_MOD(((a * x)), (13)) == 1) {
                inv_mod13[a] = x;
                x = 13;
            }
            x = (x + 1);
        }
        a = (a + 1);
    }
}

void build_spf_i64(int64_t n) {
    spf_arr = ((int32_t*)(calloc((n + 1), 4)));
    int32_t* primes = (int32_t*)(((int32_t*)(calloc(n, 4))));
    int64_t pc = 0;
    int64_t i = 2;
    while (i <= n) {
        if (spf_arr[i] == 0) {
            spf_arr[i] = ((int32_t)(i));
            primes[pc] = ((int32_t)(i));
            pc = (pc + 1);
        }
        int64_t j = 0;
        while (j < pc) {
            int64_t v = (((int64_t)(primes[j])) * i);
            if (v > n) {
                j = pc;
            } else {
                spf_arr[v] = primes[j];
                if (((int64_t)(primes[j])) == ((int64_t)(spf_arr[i]))) {
                    j = pc;
                } else {
                    j = (j + 1);
                }
            }
        }
        i = (i + 1);
    }
    free(primes);
}

int64_t distinct_prime_factors_i64_ptr_i32(int64_t n0, int32_t* out) {
    int64_t cnt = 0;
    int64_t n = n0;
    while (n > 1) {
        int32_t p = spf_arr[n];
        out[cnt] = p;
        cnt = (cnt + 1);
        while (FLOW_CHECKED_MOD((n), (((int64_t)(p)))) == 0) {
            n = FLOW_CHECKED_DIV((n), (((int64_t)(p))));
        }
    }
    return cnt;
}

int64_t gen_divisors_mu_ptr_i32_i64_ptr_i64_ptr_i32(int32_t* primes, int64_t np, int64_t* ds, int32_t* mus) {
    ds[0] = 1;
    mus[0] = 1;
    int64_t len = 1;
    int64_t i = 0;
    while (i < np) {
        int64_t p = ((int64_t)(primes[i]));
        int64_t j = 0;
        while (j < len) {
            ds[(j + len)] = (ds[j] * p);
            mus[(j + len)] = (-mus[j]);
            j = (j + 1);
        }
        len = (len * 2);
        i = (i + 1);
    }
    return len;
}

int64_t count_cong_i64_i64_i64_i64(int64_t L, int64_t R, int64_t modv, int64_t rem0) {
    int64_t rem = rem0;
    if (rem < L) {
        rem = (rem + (FLOW_CHECKED_DIV(((((L - rem) + modv) - 1)), (modv)) * modv));
    }
    if (rem > R) {
        return 0;
    }
    return (1 + FLOW_CHECKED_DIV(((R - rem)), (modv)));
}

int64_t count_coprime_interval_i64_i64_ptr_i64_ptr_i32_i64(int64_t L, int64_t R, int64_t* ds, int32_t* mus, int64_t nd) {
    int64_t Lm = (L - 1);
    int64_t total = 0;
    int64_t i = 0;
    while (i < nd) {
        total = (total + (((int64_t)(mus[i])) * (FLOW_CHECKED_DIV((R), (ds[i])) - FLOW_CHECKED_DIV((Lm), (ds[i])))));
        i = (i + 1);
    }
    return total;
}

int64_t count_coprime_mod13_ptr_i64_ptr_i32_i64_i64_i64_i32(int64_t* ds, int32_t* mus, int64_t nd, int64_t L, int64_t R, int32_t rem13) {
    int64_t total = 0;
    int64_t i = 0;
    while (i < nd) {
        int64_t d = ds[i];
        int32_t inv = inv_mod13[((int32_t)(FLOW_CHECKED_MOD((d), (13))))];
        int32_t m0 = FLOW_CHECKED_MOD(((rem13 * inv)), (13));
        int64_t rem = (d * ((int64_t)(m0)));
        int64_t modv = (13 * d);
        total = (total + (((int64_t)(mus[i])) * count_cong_i64_i64_i64_i64(L, R, modv, rem)));
        i = (i + 1);
    }
    return total;
}

int64_t max_abs_p_negative_i64(int64_t N) {
    int64_t hi = (isqrt_i64(N) + 2);
    int64_t lo = 0;
    while ((lo + 1) < hi) {
        int64_t a = FLOW_CHECKED_DIV(((lo + hi)), (2));
        if (a == 0) {
            lo = a;
        } else {
            int64_t qmin = (((int64_t)((SQRT3 * ((double)(a))))) + 1);
            int64_t thr = ((3 * a) * a);
            while ((qmin * qmin) <= thr) {
                qmin = (qmin + 1);
            }
            int64_t qmax = FLOW_CHECKED_DIV((((5 * a) - 1)), (2));
            int32_t ok = 0;
            if (qmin <= qmax) {
                int64_t z = (-(((qmin * qmin) - ((5 * a) * qmin)) + ((3 * a) * a)));
                if (z <= N) {
                    ok = 1;
                }
            }
            if (ok != 0) {
                lo = a;
            } else {
                hi = a;
            }
        }
    }
    return lo;
}

int64_t C_func_i64(int64_t N) {
    int64_t fourN = (4 * N);
    int64_t total = 0;
    int32_t* primes = (int32_t*)(((int32_t*)(calloc(32, 4))));
    int64_t* ds = (int64_t*)(((int64_t*)(calloc(256, 8))));
    int32_t* mus = (int32_t*)(((int32_t*)(calloc(256, 4))));
    int64_t pmax = isqrt_i64(FLOW_CHECKED_DIV((N), (3)));
    int64_t p = 1;
    while (p <= pmax) {
        int64_t qmin = (((int64_t)((SQRT3 * ((double)(p))))) + 1);
        int64_t thr = ((3 * p) * p);
        while ((qmin * qmin) <= thr) {
            qmin = (qmin + 1);
        }
        int64_t disc = (((13 * p) * p) + fourN);
        int64_t qmax = FLOW_CHECKED_DIV(((isqrt_i64(disc) - (5 * p))), (2));
        if (qmax >= qmin) {
            int64_t pp3 = ((3 * p) * p);
            while ((qmax >= qmin && (((qmax * qmax) + ((5 * p) * qmax)) + pp3) > N)) {
                qmax = (qmax - 1);
            }
            if (qmax >= qmin) {
                int64_t np = distinct_prime_factors_i64_ptr_i32(p, primes);
                int64_t nd = gen_divisors_mu_ptr_i32_i64_ptr_i64_ptr_i32(primes, np, ds, mus);
                int64_t cnt = count_coprime_interval_i64_i64_ptr_i64_ptr_i32_i64(qmin, qmax, ds, mus, nd);
                if (FLOW_CHECKED_MOD((p), (13)) != 0) {
                    int64_t bad = count_coprime_mod13_ptr_i64_ptr_i32_i64_i64_i64_i32(ds, mus, nd, qmin, qmax, ((int32_t)(FLOW_CHECKED_MOD(((4 * p)), (13)))));
                    cnt = (cnt - bad);
                }
                total = (total + cnt);
            }
        }
        p = (p + 1);
    }
    int64_t amax = max_abs_p_negative_i64(N);
    int64_t threshold = isqrt_i64(FLOW_CHECKED_DIV((fourN), (13)));
    int64_t a = 1;
    while (a <= amax) {
        int64_t qmin = (((int64_t)((SQRT3 * ((double)(a))))) + 1);
        int64_t thr = ((3 * a) * a);
        while ((qmin * qmin) <= thr) {
            qmin = (qmin + 1);
        }
        int64_t qmax = FLOW_CHECKED_DIV((((5 * a) - 1)), (2));
        if (qmax >= qmin) {
            if (a > threshold) {
                int64_t disc2 = (((13 * a) * a) - fourN);
                int64_t s = isqrt_i64(disc2);
                int64_t lim = FLOW_CHECKED_DIV((((5 * a) - s)), (2));
                if (lim < qmax) {
                    qmax = lim;
                }
            }
            while ((qmax >= qmin && (-(((qmax * qmax) - ((5 * a) * qmax)) + ((3 * a) * a))) > N)) {
                qmax = (qmax - 1);
            }
            if (qmax >= qmin) {
                int64_t np = distinct_prime_factors_i64_ptr_i32(a, primes);
                int64_t nd = gen_divisors_mu_ptr_i32_i64_ptr_i64_ptr_i32(primes, np, ds, mus);
                int64_t cnt = count_coprime_interval_i64_i64_ptr_i64_ptr_i32_i64(qmin, qmax, ds, mus, nd);
                if (FLOW_CHECKED_MOD((a), (13)) != 0) {
                    int32_t rem13 = ((int32_t)(FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD((((-4) * a)), (13)) + 13)), (13))));
                    int64_t bad = count_coprime_mod13_ptr_i64_ptr_i32_i64_i64_i64_i32(ds, mus, nd, qmin, qmax, rem13);
                    cnt = (cnt - bad);
                }
                total = (total + cnt);
            }
        }
        a = (a + 1);
    }
    free(primes);
    free(ds);
    free(mus);
    return total;
}

int32_t main(void) {
    init_inv_mod13();
    int64_t N = 100000000000000;
    int64_t pmax = isqrt_i64(FLOW_CHECKED_DIV((N), (3)));
    int64_t amax = max_abs_p_negative_i64(N);
    int64_t maxp = pmax;
    if (amax > maxp) {
        maxp = amax;
    }
    build_spf_i64(maxp);
    int64_t ans = C_func_i64(N);
    free(spf_arr);
    free(inv_mod13);
    printf("%lld\n", ans);
    return 0;
}

Generated MLIR

module {
  llvm.func @printf(!llvm.ptr, ...) -> i32
  llvm.mlir.global internal constant @str_0("%lld\n\00") {addr_space = 0 : i32} : !llvm.array<6 x i8>
  func.func @gcd(%arg0: i64, %arg1: i64) -> i64 {
    %0 = llvm.mlir.constant(1 : i64) : i64
    %1 = llvm.alloca %0 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %1 : i64, !llvm.ptr
    %2 = llvm.mlir.constant(1 : i64) : i64
    %3 = llvm.alloca %2 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %3 : i64, !llvm.ptr
    cf.br ^bb0
    ^bb0:
    %4 = llvm.load %3 : !llvm.ptr -> i64
    %5 = arith.constant 0 : i32
    %7 = arith.extsi %5 : i32 to i64
    %6 = arith.cmpi ne, %4, %7 : i64
    cf.cond_br %6, ^bb1, ^bb2
    ^bb1:
      %8 = llvm.load %1 : !llvm.ptr -> i64
      %9 = llvm.load %3 : !llvm.ptr -> i64
      %10 = arith.remsi %8, %9 : i64
      %11 = llvm.load %3 : !llvm.ptr -> i64
      llvm.store %11, %1 : i64, !llvm.ptr
      llvm.store %10, %3 : i64, !llvm.ptr
      cf.br ^bb0
    ^bb2:
    %12 = llvm.load %1 : !llvm.ptr -> i64
    func.return %12 : i64
  }
  func.func @lcm(%arg0: i64, %arg1: i64) -> i64 {
    %13 = arith.constant 0 : i32
    %15 = arith.extsi %13 : i32 to i64
    %14 = arith.cmpi eq, %arg0, %15 : i64
    %16 = scf.if %14 -> (i1) {
      %17 = arith.constant true
      scf.yield %17 : i1
    } else {
      %18 = arith.constant 0 : i32
      %20 = arith.extsi %18 : i32 to i64
      %19 = arith.cmpi eq, %arg1, %20 : i64
      scf.yield %19 : i1
    }
    cf.cond_br %16, ^bb3, ^bb4
    ^bb3:
      %21 = arith.constant 0 : i32
      %22 = arith.extsi %21 : i32 to i64
      func.return %22 : i64
    ^bb4:
      cf.br ^bb5
    ^bb5:
    %23 = func.call @gcd(%arg0, %arg1) : (i64, i64) -> i64
    %24 = arith.divsi %arg0, %23 : i64
    %25 = arith.muli %24, %arg1 : i64
    func.return %25 : i64
  }
  func.func @isqrt(%arg0: i64) -> i64 {
    %26 = arith.constant 2 : i32
    %28 = arith.extsi %26 : i32 to i64
    %27 = arith.cmpi slt, %arg0, %28 : i64
    cf.cond_br %27, ^bb6, ^bb7
    ^bb6:
      func.return %arg0 : i64
    ^bb7:
      cf.br ^bb8
    ^bb8:
    %29 = llvm.mlir.constant(1 : i64) : i64
    %30 = llvm.alloca %29 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %30 : i64, !llvm.ptr
    %31 = llvm.load %30 : !llvm.ptr -> i64
    %32 = arith.constant 1 : i32
    %34 = arith.extsi %32 : i32 to i64
    %33 = arith.addi %31, %34 : i64
    %35 = arith.constant 2 : i32
    %37 = arith.extsi %35 : i32 to i64
    %36 = arith.divsi %33, %37 : i64
    %38 = llvm.mlir.constant(1 : i64) : i64
    %39 = llvm.alloca %38 x i64 : (i64) -> !llvm.ptr
    llvm.store %36, %39 : i64, !llvm.ptr
    cf.br ^bb9
    ^bb9:
    %40 = llvm.load %39 : !llvm.ptr -> i64
    %41 = llvm.load %30 : !llvm.ptr -> i64
    %42 = arith.cmpi slt, %40, %41 : i64
    cf.cond_br %42, ^bb10, ^bb11
    ^bb10:
      %43 = llvm.load %39 : !llvm.ptr -> i64
      llvm.store %43, %30 : i64, !llvm.ptr
      %44 = llvm.load %30 : !llvm.ptr -> i64
      %45 = llvm.load %30 : !llvm.ptr -> i64
      %46 = arith.divsi %arg0, %45 : i64
      %47 = arith.addi %44, %46 : i64
      %48 = arith.constant 2 : i32
      %50 = arith.extsi %48 : i32 to i64
      %49 = arith.divsi %47, %50 : i64
      llvm.store %49, %39 : i64, !llvm.ptr
      cf.br ^bb9
    ^bb11:
    %51 = llvm.load %30 : !llvm.ptr -> i64
    func.return %51 : i64
  }
  func.func @mulmod(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %52 = arith.remsi %arg0, %arg2 : i64
    %53 = llvm.mlir.constant(1 : i64) : i64
    %54 = llvm.alloca %53 x i64 : (i64) -> !llvm.ptr
    llvm.store %52, %54 : i64, !llvm.ptr
    %55 = arith.remsi %arg1, %arg2 : i64
    %56 = llvm.mlir.constant(1 : i64) : i64
    %57 = llvm.alloca %56 x i64 : (i64) -> !llvm.ptr
    llvm.store %55, %57 : i64, !llvm.ptr
    %58 = arith.constant 0 : i32
    %59 = arith.extsi %58 : i32 to i64
    %60 = llvm.mlir.constant(1 : i64) : i64
    %61 = llvm.alloca %60 x i64 : (i64) -> !llvm.ptr
    llvm.store %59, %61 : i64, !llvm.ptr
    cf.br ^bb12
    ^bb12:
    %62 = llvm.load %57 : !llvm.ptr -> i64
    %63 = arith.constant 0 : i32
    %65 = arith.extsi %63 : i32 to i64
    %64 = arith.cmpi sgt, %62, %65 : i64
    cf.cond_br %64, ^bb13, ^bb14
    ^bb13:
      %66 = llvm.load %57 : !llvm.ptr -> i64
      %67 = arith.constant 2 : i32
      %69 = arith.extsi %67 : i32 to i64
      %68 = arith.remsi %66, %69 : i64
      %70 = arith.constant 1 : i32
      %72 = arith.extsi %70 : i32 to i64
      %71 = arith.cmpi eq, %68, %72 : i64
      cf.cond_br %71, ^bb15, ^bb16
      ^bb15:
        %73 = llvm.load %61 : !llvm.ptr -> i64
        %74 = llvm.load %54 : !llvm.ptr -> i64
        %75 = arith.addi %73, %74 : i64
        %76 = arith.remsi %75, %arg2 : i64
        llvm.store %76, %61 : i64, !llvm.ptr
        cf.br ^bb17
      ^bb16:
        cf.br ^bb17
      ^bb17:
      %77 = llvm.load %54 : !llvm.ptr -> i64
      %78 = arith.constant 2 : i32
      %80 = arith.extsi %78 : i32 to i64
      %79 = arith.muli %77, %80 : i64
      %81 = arith.remsi %79, %arg2 : i64
      llvm.store %81, %54 : i64, !llvm.ptr
      %82 = llvm.load %57 : !llvm.ptr -> i64
      %83 = arith.constant 2 : i32
      %85 = arith.extsi %83 : i32 to i64
      %84 = arith.divsi %82, %85 : i64
      llvm.store %84, %57 : i64, !llvm.ptr
      cf.br ^bb12
    ^bb14:
    %86 = llvm.load %61 : !llvm.ptr -> i64
    func.return %86 : i64
  }
  func.func @mod_pow(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %87 = arith.constant 1 : i32
    %89 = arith.extsi %87 : i32 to i64
    %88 = arith.cmpi eq, %arg2, %89 : i64
    cf.cond_br %88, ^bb18, ^bb19
    ^bb18:
      %90 = arith.constant 0 : i32
      %91 = arith.extsi %90 : i32 to i64
      func.return %91 : i64
    ^bb19:
      cf.br ^bb20
    ^bb20:
    %92 = arith.constant 1 : i32
    %93 = arith.extsi %92 : i32 to i64
    %94 = llvm.mlir.constant(1 : i64) : i64
    %95 = llvm.alloca %94 x i64 : (i64) -> !llvm.ptr
    llvm.store %93, %95 : i64, !llvm.ptr
    %96 = arith.remsi %arg0, %arg2 : i64
    %97 = llvm.mlir.constant(1 : i64) : i64
    %98 = llvm.alloca %97 x i64 : (i64) -> !llvm.ptr
    llvm.store %96, %98 : i64, !llvm.ptr
    %99 = llvm.mlir.constant(1 : i64) : i64
    %100 = llvm.alloca %99 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %100 : i64, !llvm.ptr
    cf.br ^bb21
    ^bb21:
    %101 = llvm.load %100 : !llvm.ptr -> i64
    %102 = arith.constant 0 : i32
    %104 = arith.extsi %102 : i32 to i64
    %103 = arith.cmpi sgt, %101, %104 : i64
    cf.cond_br %103, ^bb22, ^bb23
    ^bb22:
      %105 = llvm.load %100 : !llvm.ptr -> i64
      %106 = arith.constant 2 : i32
      %108 = arith.extsi %106 : i32 to i64
      %107 = arith.remsi %105, %108 : i64
      %109 = arith.constant 1 : i32
      %111 = arith.extsi %109 : i32 to i64
      %110 = arith.cmpi eq, %107, %111 : i64
      cf.cond_br %110, ^bb24, ^bb25
      ^bb24:
        %113 = llvm.load %95 : !llvm.ptr -> i64
        %114 = llvm.load %98 : !llvm.ptr -> i64
        %112 = func.call @mulmod(%113, %114, %arg2) : (i64, i64, i64) -> i64
        llvm.store %112, %95 : i64, !llvm.ptr
        cf.br ^bb26
      ^bb25:
        cf.br ^bb26
      ^bb26:
      %116 = llvm.load %98 : !llvm.ptr -> i64
      %117 = llvm.load %98 : !llvm.ptr -> i64
      %115 = func.call @mulmod(%116, %117, %arg2) : (i64, i64, i64) -> i64
      llvm.store %115, %98 : i64, !llvm.ptr
      %118 = llvm.load %100 : !llvm.ptr -> i64
      %119 = arith.constant 2 : i32
      %121 = arith.extsi %119 : i32 to i64
      %120 = arith.divsi %118, %121 : i64
      llvm.store %120, %100 : i64, !llvm.ptr
      cf.br ^bb21
    ^bb23:
    %122 = llvm.load %95 : !llvm.ptr -> i64
    func.return %122 : i64
  }
  func.func @is_prime(%arg0: i64) -> i1 {
    %123 = arith.constant 2 : i32
    %125 = arith.extsi %123 : i32 to i64
    %124 = arith.cmpi slt, %arg0, %125 : i64
    cf.cond_br %124, ^bb27, ^bb28
    ^bb27:
      %126 = arith.constant 0 : i1
      func.return %126 : i1
    ^bb28:
      cf.br ^bb29
    ^bb29:
    %127 = arith.constant 4 : i32
    %129 = arith.extsi %127 : i32 to i64
    %128 = arith.cmpi slt, %arg0, %129 : i64
    cf.cond_br %128, ^bb30, ^bb31
    ^bb30:
      %130 = arith.constant 1 : i1
      func.return %130 : i1
    ^bb31:
      cf.br ^bb32
    ^bb32:
    %131 = arith.constant 2 : i32
    %133 = arith.extsi %131 : i32 to i64
    %132 = arith.remsi %arg0, %133 : i64
    %134 = arith.constant 0 : i32
    %136 = arith.extsi %134 : i32 to i64
    %135 = arith.cmpi eq, %132, %136 : i64
    %137 = scf.if %135 -> (i1) {
      %138 = arith.constant true
      scf.yield %138 : i1
    } else {
      %139 = arith.constant 3 : i32
      %141 = arith.extsi %139 : i32 to i64
      %140 = arith.remsi %arg0, %141 : i64
      %142 = arith.constant 0 : i32
      %144 = arith.extsi %142 : i32 to i64
      %143 = arith.cmpi eq, %140, %144 : i64
      scf.yield %143 : i1
    }
    cf.cond_br %137, ^bb33, ^bb34
    ^bb33:
      %145 = arith.constant 0 : i1
      func.return %145 : i1
    ^bb34:
      cf.br ^bb35
    ^bb35:
    %146 = arith.constant 5 : i32
    %147 = arith.extsi %146 : i32 to i64
    %148 = llvm.mlir.constant(1 : i64) : i64
    %149 = llvm.alloca %148 x i64 : (i64) -> !llvm.ptr
    llvm.store %147, %149 : i64, !llvm.ptr
    cf.br ^bb36
    ^bb36:
    %150 = llvm.load %149 : !llvm.ptr -> i64
    %151 = llvm.load %149 : !llvm.ptr -> i64
    %152 = arith.muli %150, %151 : i64
    %153 = arith.cmpi sle, %152, %arg0 : i64
    cf.cond_br %153, ^bb37, ^bb38
    ^bb37:
      %154 = llvm.load %149 : !llvm.ptr -> i64
      %155 = arith.remsi %arg0, %154 : i64
      %156 = arith.constant 0 : i32
      %158 = arith.extsi %156 : i32 to i64
      %157 = arith.cmpi eq, %155, %158 : i64
      %159 = scf.if %157 -> (i1) {
        %160 = arith.constant true
        scf.yield %160 : i1
      } else {
        %161 = llvm.load %149 : !llvm.ptr -> i64
        %162 = arith.constant 2 : i32
        %164 = arith.extsi %162 : i32 to i64
        %163 = arith.addi %161, %164 : i64
        %165 = arith.remsi %arg0, %163 : i64
        %166 = arith.constant 0 : i32
        %168 = arith.extsi %166 : i32 to i64
        %167 = arith.cmpi eq, %165, %168 : i64
        scf.yield %167 : i1
      }
      cf.cond_br %159, ^bb39, ^bb40
      ^bb39:
        %169 = arith.constant 0 : i1
        func.return %169 : i1
      ^bb40:
        cf.br ^bb41
      ^bb41:
      %170 = llvm.load %149 : !llvm.ptr -> i64
      %171 = arith.constant 6 : i32
      %173 = arith.extsi %171 : i32 to i64
      %172 = arith.addi %170, %173 : i64
      llvm.store %172, %149 : i64, !llvm.ptr
      cf.br ^bb36
    ^bb38:
    %174 = arith.constant 1 : i1
    func.return %174 : i1
  }
  func.func private @calloc(i64, i64) -> !llvm.ptr
  func.func private @free(!llvm.ptr) -> ()
  func.func private @sqrt(f64) -> f64
  // Constant: SQRT3
  llvm.mlir.global internal constant @SQRT3(1.7320508075688772 : f64) : f64
  // Module static: inv_mod13
  llvm.mlir.global internal @inv_mod13() {addr_space = 0 : i32} : !llvm.ptr {
    %175 = llvm.mlir.zero : !llvm.ptr
    llvm.return %175 : !llvm.ptr
  }
  func.func @init_inv_mod13() -> () {
    %177 = arith.constant 13 : i32
    %178 = arith.constant 4 : i32
    %179 = arith.extsi %177 : i32 to i64
    %180 = arith.extsi %178 : i32 to i64
    %176 = func.call @calloc(%179, %180) : (i64, i64) -> !llvm.ptr
    %181 = llvm.mlir.addressof @inv_mod13 : !llvm.ptr
    llvm.store %176, %181 : !llvm.ptr, !llvm.ptr
    %182 = arith.constant 1 : i32
    %183 = llvm.mlir.constant(1 : i64) : i64
    %184 = llvm.alloca %183 x i32 : (i64) -> !llvm.ptr
    llvm.store %182, %184 : i32, !llvm.ptr
    cf.br ^bb42
    ^bb42:
    %185 = llvm.load %184 : !llvm.ptr -> i32
    %186 = arith.constant 13 : i32
    %187 = arith.cmpi slt, %185, %186 : i32
    cf.cond_br %187, ^bb43, ^bb44
    ^bb43:
      %188 = arith.constant 1 : i32
      %189 = llvm.mlir.constant(1 : i64) : i64
      %190 = llvm.alloca %189 x i32 : (i64) -> !llvm.ptr
      llvm.store %188, %190 : i32, !llvm.ptr
      cf.br ^bb45
      ^bb45:
      %191 = llvm.load %190 : !llvm.ptr -> i32
      %192 = arith.constant 13 : i32
      %193 = arith.cmpi slt, %191, %192 : i32
      cf.cond_br %193, ^bb46, ^bb47
      ^bb46:
        %194 = llvm.load %184 : !llvm.ptr -> i32
        %195 = llvm.load %190 : !llvm.ptr -> i32
        %196 = arith.muli %194, %195 : i32
        %197 = arith.constant 13 : i32
        %198 = arith.remsi %196, %197 : i32
        %199 = arith.constant 1 : i32
        %200 = arith.cmpi eq, %198, %199 : i32
        cf.cond_br %200, ^bb48, ^bb49
        ^bb48:
          %201 = llvm.load %190 : !llvm.ptr -> i32
          %202 = llvm.mlir.addressof @inv_mod13 : !llvm.ptr
          %203 = llvm.load %202 : !llvm.ptr -> !llvm.ptr
          %204 = llvm.load %184 : !llvm.ptr -> i32
          %205 = arith.extsi %204 : i32 to i64
          %206 = llvm.getelementptr %203[%205] : (!llvm.ptr, i64) -> !llvm.ptr, i32
          llvm.store %201, %206 : i32, !llvm.ptr
          %207 = arith.constant 13 : i32
          llvm.store %207, %190 : i32, !llvm.ptr
          cf.br ^bb50
        ^bb49:
          cf.br ^bb50
        ^bb50:
        %208 = llvm.load %190 : !llvm.ptr -> i32
        %209 = arith.constant 1 : i32
        %210 = arith.addi %208, %209 : i32
        llvm.store %210, %190 : i32, !llvm.ptr
        cf.br ^bb45
      ^bb47:
      %211 = llvm.load %184 : !llvm.ptr -> i32
      %212 = arith.constant 1 : i32
      %213 = arith.addi %211, %212 : i32
      llvm.store %213, %184 : i32, !llvm.ptr
      cf.br ^bb42
    ^bb44:
    func.return
  }
  // Module static: spf_arr
  llvm.mlir.global internal @spf_arr() {addr_space = 0 : i32} : !llvm.ptr {
    %214 = llvm.mlir.zero : !llvm.ptr
    llvm.return %214 : !llvm.ptr
  }
  func.func @build_spf(%arg0: i64) -> () {
    %216 = arith.constant 1 : i32
    %218 = arith.extsi %216 : i32 to i64
    %217 = arith.addi %arg0, %218 : i64
    %219 = arith.constant 4 : i32
    %220 = arith.extsi %219 : i32 to i64
    %215 = func.call @calloc(%217, %220) : (i64, i64) -> !llvm.ptr
    %221 = llvm.mlir.addressof @spf_arr : !llvm.ptr
    llvm.store %215, %221 : !llvm.ptr, !llvm.ptr
    %223 = arith.constant 4 : i32
    %224 = arith.extsi %223 : i32 to i64
    %222 = func.call @calloc(%arg0, %224) : (i64, i64) -> !llvm.ptr
    %225 = arith.constant 0 : i32
    %226 = arith.extsi %225 : i32 to i64
    %227 = llvm.mlir.constant(1 : i64) : i64
    %228 = llvm.alloca %227 x i64 : (i64) -> !llvm.ptr
    llvm.store %226, %228 : i64, !llvm.ptr
    %229 = arith.constant 2 : i32
    %230 = arith.extsi %229 : i32 to i64
    %231 = llvm.mlir.constant(1 : i64) : i64
    %232 = llvm.alloca %231 x i64 : (i64) -> !llvm.ptr
    llvm.store %230, %232 : i64, !llvm.ptr
    cf.br ^bb51
    ^bb51:
    %233 = llvm.load %232 : !llvm.ptr -> i64
    %234 = arith.cmpi sle, %233, %arg0 : i64
    cf.cond_br %234, ^bb52, ^bb53
    ^bb52:
      %236 = llvm.mlir.addressof @spf_arr : !llvm.ptr
      %237 = llvm.load %236 : !llvm.ptr -> !llvm.ptr
      %238 = llvm.load %232 : !llvm.ptr -> i64
      %239 = llvm.getelementptr %237[%238] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %235 = llvm.load %239 : !llvm.ptr -> i32
      %240 = arith.constant 0 : i32
      %241 = arith.cmpi eq, %235, %240 : i32
      cf.cond_br %241, ^bb54, ^bb55
      ^bb54:
        %242 = llvm.load %232 : !llvm.ptr -> i64
        %243 = arith.trunci %242 : i64 to i32
        %244 = llvm.mlir.addressof @spf_arr : !llvm.ptr
        %245 = llvm.load %244 : !llvm.ptr -> !llvm.ptr
        %246 = llvm.load %232 : !llvm.ptr -> i64
        %247 = llvm.getelementptr %245[%246] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %243, %247 : i32, !llvm.ptr
        %248 = llvm.load %232 : !llvm.ptr -> i64
        %249 = arith.trunci %248 : i64 to i32
        %250 = llvm.load %228 : !llvm.ptr -> i64
        %251 = llvm.getelementptr %222[%250] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %249, %251 : i32, !llvm.ptr
        %252 = llvm.load %228 : !llvm.ptr -> i64
        %253 = arith.constant 1 : i32
        %255 = arith.extsi %253 : i32 to i64
        %254 = arith.addi %252, %255 : i64
        llvm.store %254, %228 : i64, !llvm.ptr
        cf.br ^bb56
      ^bb55:
        cf.br ^bb56
      ^bb56:
      %256 = arith.constant 0 : i32
      %257 = arith.extsi %256 : i32 to i64
      %258 = llvm.mlir.constant(1 : i64) : i64
      %259 = llvm.alloca %258 x i64 : (i64) -> !llvm.ptr
      llvm.store %257, %259 : i64, !llvm.ptr
      cf.br ^bb57
      ^bb57:
      %260 = llvm.load %259 : !llvm.ptr -> i64
      %261 = llvm.load %228 : !llvm.ptr -> i64
      %262 = arith.cmpi slt, %260, %261 : i64
      cf.cond_br %262, ^bb58, ^bb59
      ^bb58:
        %264 = llvm.load %259 : !llvm.ptr -> i64
        %265 = llvm.getelementptr %222[%264] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %263 = llvm.load %265 : !llvm.ptr -> i32
        %266 = arith.extsi %263 : i32 to i64
        %267 = llvm.load %232 : !llvm.ptr -> i64
        %268 = arith.muli %266, %267 : i64
        %269 = arith.cmpi sgt, %268, %arg0 : i64
        cf.cond_br %269, ^bb60, ^bb61
        ^bb60:
          %270 = llvm.load %228 : !llvm.ptr -> i64
          llvm.store %270, %259 : i64, !llvm.ptr
          cf.br ^bb62
        ^bb61:
          %272 = llvm.load %259 : !llvm.ptr -> i64
          %273 = llvm.getelementptr %222[%272] : (!llvm.ptr, i64) -> !llvm.ptr, i32
          %271 = llvm.load %273 : !llvm.ptr -> i32
          %274 = llvm.mlir.addressof @spf_arr : !llvm.ptr
          %275 = llvm.load %274 : !llvm.ptr -> !llvm.ptr
          %276 = llvm.getelementptr %275[%268] : (!llvm.ptr, i64) -> !llvm.ptr, i32
          llvm.store %271, %276 : i32, !llvm.ptr
          %278 = llvm.load %259 : !llvm.ptr -> i64
          %279 = llvm.getelementptr %222[%278] : (!llvm.ptr, i64) -> !llvm.ptr, i32
          %277 = llvm.load %279 : !llvm.ptr -> i32
          %280 = arith.extsi %277 : i32 to i64
          %282 = llvm.mlir.addressof @spf_arr : !llvm.ptr
          %283 = llvm.load %282 : !llvm.ptr -> !llvm.ptr
          %284 = llvm.load %232 : !llvm.ptr -> i64
          %285 = llvm.getelementptr %283[%284] : (!llvm.ptr, i64) -> !llvm.ptr, i32
          %281 = llvm.load %285 : !llvm.ptr -> i32
          %286 = arith.extsi %281 : i32 to i64
          %287 = arith.cmpi eq, %280, %286 : i64
          cf.cond_br %287, ^bb63, ^bb64
          ^bb63:
            %288 = llvm.load %228 : !llvm.ptr -> i64
            llvm.store %288, %259 : i64, !llvm.ptr
            cf.br ^bb65
          ^bb64:
            %289 = llvm.load %259 : !llvm.ptr -> i64
            %290 = arith.constant 1 : i32
            %292 = arith.extsi %290 : i32 to i64
            %291 = arith.addi %289, %292 : i64
            llvm.store %291, %259 : i64, !llvm.ptr
            cf.br ^bb65
          ^bb65:
          cf.br ^bb62
        ^bb62:
        cf.br ^bb57
      ^bb59:
      %293 = llvm.load %232 : !llvm.ptr -> i64
      %294 = arith.constant 1 : i32
      %296 = arith.extsi %294 : i32 to i64
      %295 = arith.addi %293, %296 : i64
      llvm.store %295, %232 : i64, !llvm.ptr
      cf.br ^bb51
    ^bb53:
    func.call @free(%222) : (!llvm.ptr) -> ()
    func.return
  }
  func.func @distinct_prime_factors(%arg0: i64, %arg1: !llvm.ptr) -> i64 {
    %298 = arith.constant 0 : i32
    %299 = arith.extsi %298 : i32 to i64
    %300 = llvm.mlir.constant(1 : i64) : i64
    %301 = llvm.alloca %300 x i64 : (i64) -> !llvm.ptr
    llvm.store %299, %301 : i64, !llvm.ptr
    %302 = llvm.mlir.constant(1 : i64) : i64
    %303 = llvm.alloca %302 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %303 : i64, !llvm.ptr
    cf.br ^bb66
    ^bb66:
    %304 = llvm.load %303 : !llvm.ptr -> i64
    %305 = arith.constant 1 : i32
    %307 = arith.extsi %305 : i32 to i64
    %306 = arith.cmpi sgt, %304, %307 : i64
    cf.cond_br %306, ^bb67, ^bb68
    ^bb67:
      %309 = llvm.mlir.addressof @spf_arr : !llvm.ptr
      %310 = llvm.load %309 : !llvm.ptr -> !llvm.ptr
      %311 = llvm.load %303 : !llvm.ptr -> i64
      %312 = llvm.getelementptr %310[%311] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %308 = llvm.load %312 : !llvm.ptr -> i32
      %313 = llvm.load %301 : !llvm.ptr -> i64
      %314 = llvm.getelementptr %arg1[%313] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      llvm.store %308, %314 : i32, !llvm.ptr
      %315 = llvm.load %301 : !llvm.ptr -> i64
      %316 = arith.constant 1 : i32
      %318 = arith.extsi %316 : i32 to i64
      %317 = arith.addi %315, %318 : i64
      llvm.store %317, %301 : i64, !llvm.ptr
      cf.br ^bb69
      ^bb69:
      %319 = llvm.load %303 : !llvm.ptr -> i64
      %320 = arith.extsi %308 : i32 to i64
      %321 = arith.remsi %319, %320 : i64
      %322 = arith.constant 0 : i32
      %324 = arith.extsi %322 : i32 to i64
      %323 = arith.cmpi eq, %321, %324 : i64
      cf.cond_br %323, ^bb70, ^bb71
      ^bb70:
        %325 = llvm.load %303 : !llvm.ptr -> i64
        %326 = arith.extsi %308 : i32 to i64
        %327 = arith.divsi %325, %326 : i64
        llvm.store %327, %303 : i64, !llvm.ptr
        cf.br ^bb69
      ^bb71:
      cf.br ^bb66
    ^bb68:
    %328 = llvm.load %301 : !llvm.ptr -> i64
    func.return %328 : i64
  }
  func.func @gen_divisors_mu(%arg0: !llvm.ptr, %arg1: i64, %arg2: !llvm.ptr, %arg3: !llvm.ptr) -> i64 {
    %329 = arith.constant 1 : i32
    %330 = arith.constant 0 : i32
    %331 = arith.extsi %329 : i32 to i64
    %332 = arith.extsi %330 : i32 to i64
    %333 = llvm.getelementptr %arg2[%332] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %331, %333 : i64, !llvm.ptr
    %334 = arith.constant 1 : i32
    %335 = arith.constant 0 : i32
    %336 = arith.extsi %335 : i32 to i64
    %337 = llvm.getelementptr %arg3[%336] : (!llvm.ptr, i64) -> !llvm.ptr, i32
    llvm.store %334, %337 : i32, !llvm.ptr
    %338 = arith.constant 1 : i32
    %339 = arith.extsi %338 : i32 to i64
    %340 = llvm.mlir.constant(1 : i64) : i64
    %341 = llvm.alloca %340 x i64 : (i64) -> !llvm.ptr
    llvm.store %339, %341 : i64, !llvm.ptr
    %342 = arith.constant 0 : i32
    %343 = arith.extsi %342 : i32 to i64
    %344 = llvm.mlir.constant(1 : i64) : i64
    %345 = llvm.alloca %344 x i64 : (i64) -> !llvm.ptr
    llvm.store %343, %345 : i64, !llvm.ptr
    cf.br ^bb72
    ^bb72:
    %346 = llvm.load %345 : !llvm.ptr -> i64
    %347 = arith.cmpi slt, %346, %arg1 : i64
    cf.cond_br %347, ^bb73, ^bb74
    ^bb73:
      %349 = llvm.load %345 : !llvm.ptr -> i64
      %350 = llvm.getelementptr %arg0[%349] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %348 = llvm.load %350 : !llvm.ptr -> i32
      %351 = arith.extsi %348 : i32 to i64
      %352 = arith.constant 0 : i32
      %353 = arith.extsi %352 : i32 to i64
      %354 = llvm.mlir.constant(1 : i64) : i64
      %355 = llvm.alloca %354 x i64 : (i64) -> !llvm.ptr
      llvm.store %353, %355 : i64, !llvm.ptr
      cf.br ^bb75
      ^bb75:
      %356 = llvm.load %355 : !llvm.ptr -> i64
      %357 = llvm.load %341 : !llvm.ptr -> i64
      %358 = arith.cmpi slt, %356, %357 : i64
      cf.cond_br %358, ^bb76, ^bb77
      ^bb76:
        %360 = llvm.load %355 : !llvm.ptr -> i64
        %361 = llvm.getelementptr %arg2[%360] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %359 = llvm.load %361 : !llvm.ptr -> i64
        %362 = arith.muli %359, %351 : i64
        %363 = llvm.load %355 : !llvm.ptr -> i64
        %364 = llvm.load %341 : !llvm.ptr -> i64
        %365 = arith.addi %363, %364 : i64
        %366 = llvm.getelementptr %arg2[%365] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %362, %366 : i64, !llvm.ptr
        %368 = llvm.load %355 : !llvm.ptr -> i64
        %369 = llvm.getelementptr %arg3[%368] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %367 = llvm.load %369 : !llvm.ptr -> i32
        %371 = arith.constant 0 : i32
        %370 = arith.subi %371, %367 : i32
        %372 = llvm.load %355 : !llvm.ptr -> i64
        %373 = llvm.load %341 : !llvm.ptr -> i64
        %374 = arith.addi %372, %373 : i64
        %375 = llvm.getelementptr %arg3[%374] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %370, %375 : i32, !llvm.ptr
        %376 = llvm.load %355 : !llvm.ptr -> i64
        %377 = arith.constant 1 : i32
        %379 = arith.extsi %377 : i32 to i64
        %378 = arith.addi %376, %379 : i64
        llvm.store %378, %355 : i64, !llvm.ptr
        cf.br ^bb75
      ^bb77:
      %380 = llvm.load %341 : !llvm.ptr -> i64
      %381 = arith.constant 2 : i32
      %383 = arith.extsi %381 : i32 to i64
      %382 = arith.muli %380, %383 : i64
      llvm.store %382, %341 : i64, !llvm.ptr
      %384 = llvm.load %345 : !llvm.ptr -> i64
      %385 = arith.constant 1 : i32
      %387 = arith.extsi %385 : i32 to i64
      %386 = arith.addi %384, %387 : i64
      llvm.store %386, %345 : i64, !llvm.ptr
      cf.br ^bb72
    ^bb74:
    %388 = llvm.load %341 : !llvm.ptr -> i64
    func.return %388 : i64
  }
  func.func @count_cong(%arg0: i64, %arg1: i64, %arg2: i64, %arg3: i64) -> i64 {
    %389 = llvm.mlir.constant(1 : i64) : i64
    %390 = llvm.alloca %389 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg3, %390 : i64, !llvm.ptr
    %391 = llvm.load %390 : !llvm.ptr -> i64
    %392 = arith.cmpi slt, %391, %arg0 : i64
    cf.cond_br %392, ^bb78, ^bb79
    ^bb78:
      %393 = llvm.load %390 : !llvm.ptr -> i64
      %394 = llvm.load %390 : !llvm.ptr -> i64
      %395 = arith.subi %arg0, %394 : i64
      %396 = arith.addi %395, %arg2 : i64
      %397 = arith.constant 1 : i32
      %399 = arith.extsi %397 : i32 to i64
      %398 = arith.subi %396, %399 : i64
      %400 = arith.divsi %398, %arg2 : i64
      %401 = arith.muli %400, %arg2 : i64
      %402 = arith.addi %393, %401 : i64
      llvm.store %402, %390 : i64, !llvm.ptr
      cf.br ^bb80
    ^bb79:
      cf.br ^bb80
    ^bb80:
    %403 = llvm.load %390 : !llvm.ptr -> i64
    %404 = arith.cmpi sgt, %403, %arg1 : i64
    cf.cond_br %404, ^bb81, ^bb82
    ^bb81:
      %405 = arith.constant 0 : i32
      %406 = arith.extsi %405 : i32 to i64
      func.return %406 : i64
    ^bb82:
      cf.br ^bb83
    ^bb83:
    %407 = arith.constant 1 : i32
    %408 = llvm.load %390 : !llvm.ptr -> i64
    %409 = arith.subi %arg1, %408 : i64
    %410 = arith.divsi %409, %arg2 : i64
    %412 = arith.extsi %407 : i32 to i64
    %411 = arith.addi %412, %410 : i64
    func.return %411 : i64
  }
  func.func @count_coprime_interval(%arg0: i64, %arg1: i64, %arg2: !llvm.ptr, %arg3: !llvm.ptr, %arg4: i64) -> i64 {
    %413 = arith.constant 1 : i32
    %415 = arith.extsi %413 : i32 to i64
    %414 = arith.subi %arg0, %415 : i64
    %416 = arith.constant 0 : i32
    %417 = arith.extsi %416 : i32 to i64
    %418 = llvm.mlir.constant(1 : i64) : i64
    %419 = llvm.alloca %418 x i64 : (i64) -> !llvm.ptr
    llvm.store %417, %419 : i64, !llvm.ptr
    %420 = arith.constant 0 : i32
    %421 = arith.extsi %420 : i32 to i64
    %422 = llvm.mlir.constant(1 : i64) : i64
    %423 = llvm.alloca %422 x i64 : (i64) -> !llvm.ptr
    llvm.store %421, %423 : i64, !llvm.ptr
    cf.br ^bb84
    ^bb84:
    %424 = llvm.load %423 : !llvm.ptr -> i64
    %425 = arith.cmpi slt, %424, %arg4 : i64
    cf.cond_br %425, ^bb85, ^bb86
    ^bb85:
      %426 = llvm.load %419 : !llvm.ptr -> i64
      %428 = llvm.load %423 : !llvm.ptr -> i64
      %429 = llvm.getelementptr %arg3[%428] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %427 = llvm.load %429 : !llvm.ptr -> i32
      %430 = arith.extsi %427 : i32 to i64
      %432 = llvm.load %423 : !llvm.ptr -> i64
      %433 = llvm.getelementptr %arg2[%432] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %431 = llvm.load %433 : !llvm.ptr -> i64
      %434 = arith.divsi %arg1, %431 : i64
      %436 = llvm.load %423 : !llvm.ptr -> i64
      %437 = llvm.getelementptr %arg2[%436] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %435 = llvm.load %437 : !llvm.ptr -> i64
      %438 = arith.divsi %414, %435 : i64
      %439 = arith.subi %434, %438 : i64
      %440 = arith.muli %430, %439 : i64
      %441 = arith.addi %426, %440 : i64
      llvm.store %441, %419 : i64, !llvm.ptr
      %442 = llvm.load %423 : !llvm.ptr -> i64
      %443 = arith.constant 1 : i32
      %445 = arith.extsi %443 : i32 to i64
      %444 = arith.addi %442, %445 : i64
      llvm.store %444, %423 : i64, !llvm.ptr
      cf.br ^bb84
    ^bb86:
    %446 = llvm.load %419 : !llvm.ptr -> i64
    func.return %446 : i64
  }
  func.func @count_coprime_mod13(%arg0: !llvm.ptr, %arg1: !llvm.ptr, %arg2: i64, %arg3: i64, %arg4: i64, %arg5: i32) -> i64 {
    %447 = arith.constant 0 : i32
    %448 = arith.extsi %447 : i32 to i64
    %449 = llvm.mlir.constant(1 : i64) : i64
    %450 = llvm.alloca %449 x i64 : (i64) -> !llvm.ptr
    llvm.store %448, %450 : i64, !llvm.ptr
    %451 = arith.constant 0 : i32
    %452 = arith.extsi %451 : i32 to i64
    %453 = llvm.mlir.constant(1 : i64) : i64
    %454 = llvm.alloca %453 x i64 : (i64) -> !llvm.ptr
    llvm.store %452, %454 : i64, !llvm.ptr
    cf.br ^bb87
    ^bb87:
    %455 = llvm.load %454 : !llvm.ptr -> i64
    %456 = arith.cmpi slt, %455, %arg2 : i64
    cf.cond_br %456, ^bb88, ^bb89
    ^bb88:
      %458 = llvm.load %454 : !llvm.ptr -> i64
      %459 = llvm.getelementptr %arg0[%458] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %457 = llvm.load %459 : !llvm.ptr -> i64
      %461 = llvm.mlir.addressof @inv_mod13 : !llvm.ptr
      %462 = llvm.load %461 : !llvm.ptr -> !llvm.ptr
      %463 = arith.constant 13 : i32
      %465 = arith.extsi %463 : i32 to i64
      %464 = arith.remsi %457, %465 : i64
      %466 = arith.trunci %464 : i64 to i32
      %467 = arith.extsi %466 : i32 to i64
      %468 = llvm.getelementptr %462[%467] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %460 = llvm.load %468 : !llvm.ptr -> i32
      %469 = arith.muli %arg5, %460 : i32
      %470 = arith.constant 13 : i32
      %471 = arith.remsi %469, %470 : i32
      %472 = arith.extsi %471 : i32 to i64
      %473 = arith.muli %457, %472 : i64
      %474 = arith.constant 13 : i32
      %476 = arith.extsi %474 : i32 to i64
      %475 = arith.muli %476, %457 : i64
      %477 = llvm.load %450 : !llvm.ptr -> i64
      %479 = llvm.load %454 : !llvm.ptr -> i64
      %480 = llvm.getelementptr %arg1[%479] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %478 = llvm.load %480 : !llvm.ptr -> i32
      %481 = arith.extsi %478 : i32 to i64
      %482 = func.call @count_cong(%arg3, %arg4, %475, %473) : (i64, i64, i64, i64) -> i64
      %483 = arith.muli %481, %482 : i64
      %484 = arith.addi %477, %483 : i64
      llvm.store %484, %450 : i64, !llvm.ptr
      %485 = llvm.load %454 : !llvm.ptr -> i64
      %486 = arith.constant 1 : i32
      %488 = arith.extsi %486 : i32 to i64
      %487 = arith.addi %485, %488 : i64
      llvm.store %487, %454 : i64, !llvm.ptr
      cf.br ^bb87
    ^bb89:
    %489 = llvm.load %450 : !llvm.ptr -> i64
    func.return %489 : i64
  }
  func.func @max_abs_p_negative(%arg0: i64) -> i64 {
    %490 = func.call @isqrt(%arg0) : (i64) -> i64
    %491 = arith.constant 2 : i32
    %493 = arith.extsi %491 : i32 to i64
    %492 = arith.addi %490, %493 : i64
    %494 = arith.constant 0 : i32
    %495 = arith.extsi %494 : i32 to i64
    %496 = llvm.mlir.constant(1 : i64) : i64
    %497 = llvm.alloca %496 x i64 : (i64) -> !llvm.ptr
    llvm.store %495, %497 : i64, !llvm.ptr
    cf.br ^bb90(%492 : i64)
    ^bb90(%498: i64):
    %499 = llvm.load %497 : !llvm.ptr -> i64
    %500 = arith.constant 1 : i32
    %502 = arith.extsi %500 : i32 to i64
    %501 = arith.addi %499, %502 : i64
    %503 = arith.cmpi slt, %501, %498 : i64
    cf.cond_br %503, ^bb91(%498 : i64), ^bb92(%498 : i64)
    ^bb91(%504: i64):
      %505 = llvm.load %497 : !llvm.ptr -> i64
      %506 = arith.addi %505, %504 : i64
      %507 = arith.constant 2 : i32
      %509 = arith.extsi %507 : i32 to i64
      %508 = arith.divsi %506, %509 : i64
      %510 = arith.constant 0 : i32
      %512 = arith.extsi %510 : i32 to i64
      %511 = arith.cmpi eq, %508, %512 : i64
      cf.cond_br %511, ^bb93, ^bb94
      ^bb93:
        llvm.store %508, %497 : i64, !llvm.ptr
        cf.br ^bb95(%504 : i64)
      ^bb94:
        %513 = llvm.mlir.addressof @SQRT3 : !llvm.ptr
        %514 = llvm.load %513 : !llvm.ptr -> f64
        %515 = arith.sitofp %508 : i64 to f64
        %516 = arith.mulf %514, %515 : f64
        %517 = arith.fptosi %516 : f64 to i64
        %518 = arith.constant 1 : i32
        %520 = arith.extsi %518 : i32 to i64
        %519 = arith.addi %517, %520 : i64
        %521 = llvm.mlir.constant(1 : i64) : i64
        %522 = llvm.alloca %521 x i64 : (i64) -> !llvm.ptr
        llvm.store %519, %522 : i64, !llvm.ptr
        %523 = arith.constant 3 : i32
        %525 = arith.extsi %523 : i32 to i64
        %524 = arith.muli %525, %508 : i64
        %526 = arith.muli %524, %508 : i64
        cf.br ^bb96
        ^bb96:
        %527 = llvm.load %522 : !llvm.ptr -> i64
        %528 = llvm.load %522 : !llvm.ptr -> i64
        %529 = arith.muli %527, %528 : i64
        %530 = arith.cmpi sle, %529, %526 : i64
        cf.cond_br %530, ^bb97, ^bb98
        ^bb97:
          %531 = llvm.load %522 : !llvm.ptr -> i64
          %532 = arith.constant 1 : i32
          %534 = arith.extsi %532 : i32 to i64
          %533 = arith.addi %531, %534 : i64
          llvm.store %533, %522 : i64, !llvm.ptr
          cf.br ^bb96
        ^bb98:
        %535 = arith.constant 5 : i32
        %537 = arith.extsi %535 : i32 to i64
        %536 = arith.muli %537, %508 : i64
        %538 = arith.constant 1 : i32
        %540 = arith.extsi %538 : i32 to i64
        %539 = arith.subi %536, %540 : i64
        %541 = arith.constant 2 : i32
        %543 = arith.extsi %541 : i32 to i64
        %542 = arith.divsi %539, %543 : i64
        %544 = arith.constant 0 : i32
        %545 = llvm.mlir.constant(1 : i64) : i64
        %546 = llvm.alloca %545 x i32 : (i64) -> !llvm.ptr
        llvm.store %544, %546 : i32, !llvm.ptr
        %547 = llvm.load %522 : !llvm.ptr -> i64
        %548 = arith.cmpi sle, %547, %542 : i64
        cf.cond_br %548, ^bb99, ^bb100
        ^bb99:
          %549 = llvm.load %522 : !llvm.ptr -> i64
          %550 = llvm.load %522 : !llvm.ptr -> i64
          %551 = arith.muli %549, %550 : i64
          %552 = arith.constant 5 : i32
          %554 = arith.extsi %552 : i32 to i64
          %553 = arith.muli %554, %508 : i64
          %555 = llvm.load %522 : !llvm.ptr -> i64
          %556 = arith.muli %553, %555 : i64
          %557 = arith.subi %551, %556 : i64
          %558 = arith.constant 3 : i32
          %560 = arith.extsi %558 : i32 to i64
          %559 = arith.muli %560, %508 : i64
          %561 = arith.muli %559, %508 : i64
          %562 = arith.addi %557, %561 : i64
          %564 = arith.constant 0 : i64
          %563 = arith.subi %564, %562 : i64
          %565 = arith.cmpi sle, %563, %arg0 : i64
          cf.cond_br %565, ^bb102, ^bb103
          ^bb102:
            %566 = arith.constant 1 : i32
            llvm.store %566, %546 : i32, !llvm.ptr
            cf.br ^bb104
          ^bb103:
            cf.br ^bb104
          ^bb104:
          cf.br ^bb101
        ^bb100:
          cf.br ^bb101
        ^bb101:
        %567 = llvm.load %546 : !llvm.ptr -> i32
        %568 = arith.constant 0 : i32
        %569 = arith.cmpi ne, %567, %568 : i32
        %570 = scf.if %569 -> (i64) {
          llvm.store %508, %497 : i64, !llvm.ptr
          scf.yield %504 : i64
        } else {
          scf.yield %508 : i64
        }
        cf.br ^bb95(%570 : i64)
      ^bb95(%571: i64):
      cf.br ^bb90(%571 : i64)
    ^bb92(%572: i64):
    %573 = llvm.load %497 : !llvm.ptr -> i64
    func.return %573 : i64
  }
  func.func @C_func(%arg0: i64) -> i64 {
    %574 = arith.constant 4 : i32
    %576 = arith.extsi %574 : i32 to i64
    %575 = arith.muli %576, %arg0 : i64
    %577 = arith.constant 0 : i32
    %578 = arith.extsi %577 : i32 to i64
    %579 = llvm.mlir.constant(1 : i64) : i64
    %580 = llvm.alloca %579 x i64 : (i64) -> !llvm.ptr
    llvm.store %578, %580 : i64, !llvm.ptr
    %582 = arith.constant 32 : i32
    %583 = arith.constant 4 : i32
    %584 = arith.extsi %582 : i32 to i64
    %585 = arith.extsi %583 : i32 to i64
    %581 = func.call @calloc(%584, %585) : (i64, i64) -> !llvm.ptr
    %587 = arith.constant 256 : i32
    %588 = arith.constant 8 : i32
    %589 = arith.extsi %587 : i32 to i64
    %590 = arith.extsi %588 : i32 to i64
    %586 = func.call @calloc(%589, %590) : (i64, i64) -> !llvm.ptr
    %592 = arith.constant 256 : i32
    %593 = arith.constant 4 : i32
    %594 = arith.extsi %592 : i32 to i64
    %595 = arith.extsi %593 : i32 to i64
    %591 = func.call @calloc(%594, %595) : (i64, i64) -> !llvm.ptr
    %597 = arith.constant 3 : i32
    %599 = arith.extsi %597 : i32 to i64
    %598 = arith.divsi %arg0, %599 : i64
    %596 = func.call @isqrt(%598) : (i64) -> i64
    %600 = arith.constant 1 : i32
    %601 = arith.extsi %600 : i32 to i64
    %602 = llvm.mlir.constant(1 : i64) : i64
    %603 = llvm.alloca %602 x i64 : (i64) -> !llvm.ptr
    llvm.store %601, %603 : i64, !llvm.ptr
    cf.br ^bb105
    ^bb105:
    %604 = llvm.load %603 : !llvm.ptr -> i64
    %605 = arith.cmpi sle, %604, %596 : i64
    cf.cond_br %605, ^bb106, ^bb107
    ^bb106:
      %606 = llvm.mlir.addressof @SQRT3 : !llvm.ptr
      %607 = llvm.load %606 : !llvm.ptr -> f64
      %608 = llvm.load %603 : !llvm.ptr -> i64
      %609 = arith.sitofp %608 : i64 to f64
      %610 = arith.mulf %607, %609 : f64
      %611 = arith.fptosi %610 : f64 to i64
      %612 = arith.constant 1 : i32
      %614 = arith.extsi %612 : i32 to i64
      %613 = arith.addi %611, %614 : i64
      %615 = llvm.mlir.constant(1 : i64) : i64
      %616 = llvm.alloca %615 x i64 : (i64) -> !llvm.ptr
      llvm.store %613, %616 : i64, !llvm.ptr
      %617 = arith.constant 3 : i32
      %618 = llvm.load %603 : !llvm.ptr -> i64
      %620 = arith.extsi %617 : i32 to i64
      %619 = arith.muli %620, %618 : i64
      %621 = llvm.load %603 : !llvm.ptr -> i64
      %622 = arith.muli %619, %621 : i64
      cf.br ^bb108
      ^bb108:
      %623 = llvm.load %616 : !llvm.ptr -> i64
      %624 = llvm.load %616 : !llvm.ptr -> i64
      %625 = arith.muli %623, %624 : i64
      %626 = arith.cmpi sle, %625, %622 : i64
      cf.cond_br %626, ^bb109, ^bb110
      ^bb109:
        %627 = llvm.load %616 : !llvm.ptr -> i64
        %628 = arith.constant 1 : i32
        %630 = arith.extsi %628 : i32 to i64
        %629 = arith.addi %627, %630 : i64
        llvm.store %629, %616 : i64, !llvm.ptr
        cf.br ^bb108
      ^bb110:
      %631 = arith.constant 13 : i32
      %632 = llvm.load %603 : !llvm.ptr -> i64
      %634 = arith.extsi %631 : i32 to i64
      %633 = arith.muli %634, %632 : i64
      %635 = llvm.load %603 : !llvm.ptr -> i64
      %636 = arith.muli %633, %635 : i64
      %637 = arith.addi %636, %575 : i64
      %638 = func.call @isqrt(%637) : (i64) -> i64
      %639 = arith.constant 5 : i32
      %640 = llvm.load %603 : !llvm.ptr -> i64
      %642 = arith.extsi %639 : i32 to i64
      %641 = arith.muli %642, %640 : i64
      %643 = arith.subi %638, %641 : i64
      %644 = arith.constant 2 : i32
      %646 = arith.extsi %644 : i32 to i64
      %645 = arith.divsi %643, %646 : i64
      %647 = llvm.mlir.constant(1 : i64) : i64
      %648 = llvm.alloca %647 x i64 : (i64) -> !llvm.ptr
      llvm.store %645, %648 : i64, !llvm.ptr
      %649 = llvm.load %648 : !llvm.ptr -> i64
      %650 = llvm.load %616 : !llvm.ptr -> i64
      %651 = arith.cmpi sge, %649, %650 : i64
      cf.cond_br %651, ^bb111, ^bb112
      ^bb111:
        %652 = arith.constant 3 : i32
        %653 = llvm.load %603 : !llvm.ptr -> i64
        %655 = arith.extsi %652 : i32 to i64
        %654 = arith.muli %655, %653 : i64
        %656 = llvm.load %603 : !llvm.ptr -> i64
        %657 = arith.muli %654, %656 : i64
        cf.br ^bb114
        ^bb114:
        %658 = llvm.load %648 : !llvm.ptr -> i64
        %659 = llvm.load %616 : !llvm.ptr -> i64
        %660 = arith.cmpi sge, %658, %659 : i64
        %661 = scf.if %660 -> (i1) {
          %662 = llvm.load %648 : !llvm.ptr -> i64
          %663 = llvm.load %648 : !llvm.ptr -> i64
          %664 = arith.muli %662, %663 : i64
          %665 = arith.constant 5 : i32
          %666 = llvm.load %603 : !llvm.ptr -> i64
          %668 = arith.extsi %665 : i32 to i64
          %667 = arith.muli %668, %666 : i64
          %669 = llvm.load %648 : !llvm.ptr -> i64
          %670 = arith.muli %667, %669 : i64
          %671 = arith.addi %664, %670 : i64
          %672 = arith.addi %671, %657 : i64
          %673 = arith.cmpi sgt, %672, %arg0 : i64
          scf.yield %673 : i1
        } else {
          %674 = arith.constant false
          scf.yield %674 : i1
        }
        cf.cond_br %661, ^bb115, ^bb116
        ^bb115:
          %675 = llvm.load %648 : !llvm.ptr -> i64
          %676 = arith.constant 1 : i32
          %678 = arith.extsi %676 : i32 to i64
          %677 = arith.subi %675, %678 : i64
          llvm.store %677, %648 : i64, !llvm.ptr
          cf.br ^bb114
        ^bb116:
        %679 = llvm.load %648 : !llvm.ptr -> i64
        %680 = llvm.load %616 : !llvm.ptr -> i64
        %681 = arith.cmpi sge, %679, %680 : i64
        cf.cond_br %681, ^bb117, ^bb118
        ^bb117:
          %683 = llvm.load %603 : !llvm.ptr -> i64
          %682 = func.call @distinct_prime_factors(%683, %581) : (i64, !llvm.ptr) -> i64
          %684 = func.call @gen_divisors_mu(%581, %682, %586, %591) : (!llvm.ptr, i64, !llvm.ptr, !llvm.ptr) -> i64
          %686 = llvm.load %616 : !llvm.ptr -> i64
          %687 = llvm.load %648 : !llvm.ptr -> i64
          %685 = func.call @count_coprime_interval(%686, %687, %586, %591, %684) : (i64, i64, !llvm.ptr, !llvm.ptr, i64) -> i64
          %688 = llvm.mlir.constant(1 : i64) : i64
          %689 = llvm.alloca %688 x i64 : (i64) -> !llvm.ptr
          llvm.store %685, %689 : i64, !llvm.ptr
          %690 = llvm.load %603 : !llvm.ptr -> i64
          %691 = arith.constant 13 : i32
          %693 = arith.extsi %691 : i32 to i64
          %692 = arith.remsi %690, %693 : i64
          %694 = arith.constant 0 : i32
          %696 = arith.extsi %694 : i32 to i64
          %695 = arith.cmpi ne, %692, %696 : i64
          cf.cond_br %695, ^bb120, ^bb121
          ^bb120:
            %698 = llvm.load %616 : !llvm.ptr -> i64
            %699 = llvm.load %648 : !llvm.ptr -> i64
            %700 = arith.constant 4 : i32
            %701 = llvm.load %603 : !llvm.ptr -> i64
            %703 = arith.extsi %700 : i32 to i64
            %702 = arith.muli %703, %701 : i64
            %704 = arith.constant 13 : i32
            %706 = arith.extsi %704 : i32 to i64
            %705 = arith.remsi %702, %706 : i64
            %707 = arith.trunci %705 : i64 to i32
            %697 = func.call @count_coprime_mod13(%586, %591, %684, %698, %699, %707) : (!llvm.ptr, !llvm.ptr, i64, i64, i64, i32) -> i64
            %708 = llvm.load %689 : !llvm.ptr -> i64
            %709 = arith.subi %708, %697 : i64
            llvm.store %709, %689 : i64, !llvm.ptr
            cf.br ^bb122
          ^bb121:
            cf.br ^bb122
          ^bb122:
          %710 = llvm.load %580 : !llvm.ptr -> i64
          %711 = llvm.load %689 : !llvm.ptr -> i64
          %712 = arith.addi %710, %711 : i64
          llvm.store %712, %580 : i64, !llvm.ptr
          cf.br ^bb119
        ^bb118:
          cf.br ^bb119
        ^bb119:
        cf.br ^bb113
      ^bb112:
        cf.br ^bb113
      ^bb113:
      %713 = llvm.load %603 : !llvm.ptr -> i64
      %714 = arith.constant 1 : i32
      %716 = arith.extsi %714 : i32 to i64
      %715 = arith.addi %713, %716 : i64
      llvm.store %715, %603 : i64, !llvm.ptr
      cf.br ^bb105
    ^bb107:
    %717 = func.call @max_abs_p_negative(%arg0) : (i64) -> i64
    %719 = arith.constant 13 : i32
    %721 = arith.extsi %719 : i32 to i64
    %720 = arith.divsi %575, %721 : i64
    %718 = func.call @isqrt(%720) : (i64) -> i64
    %722 = arith.constant 1 : i32
    %723 = arith.extsi %722 : i32 to i64
    %724 = llvm.mlir.constant(1 : i64) : i64
    %725 = llvm.alloca %724 x i64 : (i64) -> !llvm.ptr
    llvm.store %723, %725 : i64, !llvm.ptr
    cf.br ^bb123
    ^bb123:
    %726 = llvm.load %725 : !llvm.ptr -> i64
    %727 = arith.cmpi sle, %726, %717 : i64
    cf.cond_br %727, ^bb124, ^bb125
    ^bb124:
      %728 = llvm.mlir.addressof @SQRT3 : !llvm.ptr
      %729 = llvm.load %728 : !llvm.ptr -> f64
      %730 = llvm.load %725 : !llvm.ptr -> i64
      %731 = arith.sitofp %730 : i64 to f64
      %732 = arith.mulf %729, %731 : f64
      %733 = arith.fptosi %732 : f64 to i64
      %734 = arith.constant 1 : i32
      %736 = arith.extsi %734 : i32 to i64
      %735 = arith.addi %733, %736 : i64
      %737 = llvm.mlir.constant(1 : i64) : i64
      %738 = llvm.alloca %737 x i64 : (i64) -> !llvm.ptr
      llvm.store %735, %738 : i64, !llvm.ptr
      %739 = arith.constant 3 : i32
      %740 = llvm.load %725 : !llvm.ptr -> i64
      %742 = arith.extsi %739 : i32 to i64
      %741 = arith.muli %742, %740 : i64
      %743 = llvm.load %725 : !llvm.ptr -> i64
      %744 = arith.muli %741, %743 : i64
      cf.br ^bb126
      ^bb126:
      %745 = llvm.load %738 : !llvm.ptr -> i64
      %746 = llvm.load %738 : !llvm.ptr -> i64
      %747 = arith.muli %745, %746 : i64
      %748 = arith.cmpi sle, %747, %744 : i64
      cf.cond_br %748, ^bb127, ^bb128
      ^bb127:
        %749 = llvm.load %738 : !llvm.ptr -> i64
        %750 = arith.constant 1 : i32
        %752 = arith.extsi %750 : i32 to i64
        %751 = arith.addi %749, %752 : i64
        llvm.store %751, %738 : i64, !llvm.ptr
        cf.br ^bb126
      ^bb128:
      %753 = arith.constant 5 : i32
      %754 = llvm.load %725 : !llvm.ptr -> i64
      %756 = arith.extsi %753 : i32 to i64
      %755 = arith.muli %756, %754 : i64
      %757 = arith.constant 1 : i32
      %759 = arith.extsi %757 : i32 to i64
      %758 = arith.subi %755, %759 : i64
      %760 = arith.constant 2 : i32
      %762 = arith.extsi %760 : i32 to i64
      %761 = arith.divsi %758, %762 : i64
      %763 = llvm.mlir.constant(1 : i64) : i64
      %764 = llvm.alloca %763 x i64 : (i64) -> !llvm.ptr
      llvm.store %761, %764 : i64, !llvm.ptr
      %765 = llvm.load %764 : !llvm.ptr -> i64
      %766 = llvm.load %738 : !llvm.ptr -> i64
      %767 = arith.cmpi sge, %765, %766 : i64
      cf.cond_br %767, ^bb129, ^bb130
      ^bb129:
        %768 = llvm.load %725 : !llvm.ptr -> i64
        %769 = arith.cmpi sgt, %768, %718 : i64
        cf.cond_br %769, ^bb132, ^bb133
        ^bb132:
          %770 = arith.constant 13 : i32
          %771 = llvm.load %725 : !llvm.ptr -> i64
          %773 = arith.extsi %770 : i32 to i64
          %772 = arith.muli %773, %771 : i64
          %774 = llvm.load %725 : !llvm.ptr -> i64
          %775 = arith.muli %772, %774 : i64
          %776 = arith.subi %775, %575 : i64
          %777 = func.call @isqrt(%776) : (i64) -> i64
          %778 = arith.constant 5 : i32
          %779 = llvm.load %725 : !llvm.ptr -> i64
          %781 = arith.extsi %778 : i32 to i64
          %780 = arith.muli %781, %779 : i64
          %782 = arith.subi %780, %777 : i64
          %783 = arith.constant 2 : i32
          %785 = arith.extsi %783 : i32 to i64
          %784 = arith.divsi %782, %785 : i64
          %786 = llvm.load %764 : !llvm.ptr -> i64
          %787 = arith.cmpi slt, %784, %786 : i64
          cf.cond_br %787, ^bb135, ^bb136
          ^bb135:
            llvm.store %784, %764 : i64, !llvm.ptr
            cf.br ^bb137
          ^bb136:
            cf.br ^bb137
          ^bb137:
          cf.br ^bb134
        ^bb133:
          cf.br ^bb134
        ^bb134:
        cf.br ^bb138
        ^bb138:
        %788 = llvm.load %764 : !llvm.ptr -> i64
        %789 = llvm.load %738 : !llvm.ptr -> i64
        %790 = arith.cmpi sge, %788, %789 : i64
        %791 = scf.if %790 -> (i1) {
          %792 = llvm.load %764 : !llvm.ptr -> i64
          %793 = llvm.load %764 : !llvm.ptr -> i64
          %794 = arith.muli %792, %793 : i64
          %795 = arith.constant 5 : i32
          %796 = llvm.load %725 : !llvm.ptr -> i64
          %798 = arith.extsi %795 : i32 to i64
          %797 = arith.muli %798, %796 : i64
          %799 = llvm.load %764 : !llvm.ptr -> i64
          %800 = arith.muli %797, %799 : i64
          %801 = arith.subi %794, %800 : i64
          %802 = arith.constant 3 : i32
          %803 = llvm.load %725 : !llvm.ptr -> i64
          %805 = arith.extsi %802 : i32 to i64
          %804 = arith.muli %805, %803 : i64
          %806 = llvm.load %725 : !llvm.ptr -> i64
          %807 = arith.muli %804, %806 : i64
          %808 = arith.addi %801, %807 : i64
          %810 = arith.constant 0 : i64
          %809 = arith.subi %810, %808 : i64
          %811 = arith.cmpi sgt, %809, %arg0 : i64
          scf.yield %811 : i1
        } else {
          %812 = arith.constant false
          scf.yield %812 : i1
        }
        cf.cond_br %791, ^bb139, ^bb140
        ^bb139:
          %813 = llvm.load %764 : !llvm.ptr -> i64
          %814 = arith.constant 1 : i32
          %816 = arith.extsi %814 : i32 to i64
          %815 = arith.subi %813, %816 : i64
          llvm.store %815, %764 : i64, !llvm.ptr
          cf.br ^bb138
        ^bb140:
        %817 = llvm.load %764 : !llvm.ptr -> i64
        %818 = llvm.load %738 : !llvm.ptr -> i64
        %819 = arith.cmpi sge, %817, %818 : i64
        cf.cond_br %819, ^bb141, ^bb142
        ^bb141:
          %821 = llvm.load %725 : !llvm.ptr -> i64
          %820 = func.call @distinct_prime_factors(%821, %581) : (i64, !llvm.ptr) -> i64
          %822 = func.call @gen_divisors_mu(%581, %820, %586, %591) : (!llvm.ptr, i64, !llvm.ptr, !llvm.ptr) -> i64
          %824 = llvm.load %738 : !llvm.ptr -> i64
          %825 = llvm.load %764 : !llvm.ptr -> i64
          %823 = func.call @count_coprime_interval(%824, %825, %586, %591, %822) : (i64, i64, !llvm.ptr, !llvm.ptr, i64) -> i64
          %826 = llvm.mlir.constant(1 : i64) : i64
          %827 = llvm.alloca %826 x i64 : (i64) -> !llvm.ptr
          llvm.store %823, %827 : i64, !llvm.ptr
          %828 = llvm.load %725 : !llvm.ptr -> i64
          %829 = arith.constant 13 : i32
          %831 = arith.extsi %829 : i32 to i64
          %830 = arith.remsi %828, %831 : i64
          %832 = arith.constant 0 : i32
          %834 = arith.extsi %832 : i32 to i64
          %833 = arith.cmpi ne, %830, %834 : i64
          cf.cond_br %833, ^bb144, ^bb145
          ^bb144:
            %835 = arith.constant 4 : i32
            %837 = arith.constant 0 : i32
            %836 = arith.subi %837, %835 : i32
            %838 = llvm.load %725 : !llvm.ptr -> i64
            %840 = arith.extsi %836 : i32 to i64
            %839 = arith.muli %840, %838 : i64
            %841 = arith.constant 13 : i32
            %843 = arith.extsi %841 : i32 to i64
            %842 = arith.remsi %839, %843 : i64
            %844 = arith.constant 13 : i32
            %846 = arith.extsi %844 : i32 to i64
            %845 = arith.addi %842, %846 : i64
            %847 = arith.constant 13 : i32
            %849 = arith.extsi %847 : i32 to i64
            %848 = arith.remsi %845, %849 : i64
            %850 = arith.trunci %848 : i64 to i32
            %852 = llvm.load %738 : !llvm.ptr -> i64
            %853 = llvm.load %764 : !llvm.ptr -> i64
            %851 = func.call @count_coprime_mod13(%586, %591, %822, %852, %853, %850) : (!llvm.ptr, !llvm.ptr, i64, i64, i64, i32) -> i64
            %854 = llvm.load %827 : !llvm.ptr -> i64
            %855 = arith.subi %854, %851 : i64
            llvm.store %855, %827 : i64, !llvm.ptr
            cf.br ^bb146
          ^bb145:
            cf.br ^bb146
          ^bb146:
          %856 = llvm.load %580 : !llvm.ptr -> i64
          %857 = llvm.load %827 : !llvm.ptr -> i64
          %858 = arith.addi %856, %857 : i64
          llvm.store %858, %580 : i64, !llvm.ptr
          cf.br ^bb143
        ^bb142:
          cf.br ^bb143
        ^bb143:
        cf.br ^bb131
      ^bb130:
        cf.br ^bb131
      ^bb131:
      %859 = llvm.load %725 : !llvm.ptr -> i64
      %860 = arith.constant 1 : i32
      %862 = arith.extsi %860 : i32 to i64
      %861 = arith.addi %859, %862 : i64
      llvm.store %861, %725 : i64, !llvm.ptr
      cf.br ^bb123
    ^bb125:
    func.call @free(%581) : (!llvm.ptr) -> ()
    func.call @free(%586) : (!llvm.ptr) -> ()
    func.call @free(%591) : (!llvm.ptr) -> ()
    %866 = llvm.load %580 : !llvm.ptr -> i64
    func.return %866 : i64
  }
  func.func @main() -> i32 {
    func.call @init_inv_mod13() : () -> ()
    %868 = arith.constant 99995705032704 : i32
    %869 = arith.extsi %868 : i32 to i64
    %871 = arith.constant 3 : i32
    %873 = arith.extsi %871 : i32 to i64
    %872 = arith.divsi %869, %873 : i64
    %870 = func.call @isqrt(%872) : (i64) -> i64
    %874 = func.call @max_abs_p_negative(%869) : (i64) -> i64
    %875 = llvm.mlir.constant(1 : i64) : i64
    %876 = llvm.alloca %875 x i64 : (i64) -> !llvm.ptr
    llvm.store %870, %876 : i64, !llvm.ptr
    %877 = llvm.load %876 : !llvm.ptr -> i64
    %878 = arith.cmpi sgt, %874, %877 : i64
    cf.cond_br %878, ^bb147, ^bb148
    ^bb147:
      llvm.store %874, %876 : i64, !llvm.ptr
      cf.br ^bb149
    ^bb148:
      cf.br ^bb149
    ^bb149:
    %880 = llvm.load %876 : !llvm.ptr -> i64
    func.call @build_spf(%880) : (i64) -> ()
    %881 = func.call @C_func(%869) : (i64) -> i64
    %883 = llvm.mlir.addressof @spf_arr : !llvm.ptr
    %884 = llvm.load %883 : !llvm.ptr -> !llvm.ptr
    func.call @free(%884) : (!llvm.ptr) -> ()
    %886 = llvm.mlir.addressof @inv_mod13 : !llvm.ptr
    %887 = llvm.load %886 : !llvm.ptr -> !llvm.ptr
    func.call @free(%887) : (!llvm.ptr) -> ()
    %888 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %889 = llvm.call @printf(%888, %881) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    %890 = arith.constant 0 : i32
    func.return %890 : i32
  }
}