Problem 780

Toriangulations: count tilings of a x b tori by unit equilateral triangles, up to continuous motion of the triangles. G(N) = sum F(n), n <= N = 10^9. Every tiling is a strip tiling: rows of 2*lambda triangles between parallel full lines, s rows, n = 2*lambda*s. On a fixed ordered a x b torus each valid strip direction gives one connected family, and families merge exactly at edge-to-edge tilings, i.e. at copies of the triangular lattice T that contain the torus lattice. With m = n/2 this gives G(N) = 2*D(M) + 4*T(M) - (4/3)*R(M), M = N/2, where D(M) = sum_{m<=M} d(m) (axis-parallel directions), T(M) = #{(lambda,s,p,q): gcd(p,q)=1, p,q>=1, sqrt(3)*p*q*s < lambda, lambda*s <= M} (tilted directions; counted via 2^omega(k) over k = p*q, segmented sieve), R(M) = # rectangular sublattices of T with index <= M = (1/2) sum over primitive Eisenstein points u, 3 !| norm(u), of D(floor(M/2 / norm(u))) (axes t*u and r*u*sqrt(-3)), computed with Moebius over content, the ellipse point count Circ(z) = 6*sum chi_3(d)*floor(z/d), and floor-value blocks. Verified: G(6)=14, G(100)=8090, G(10^5) = 645124048 (mod 1e9+7).

Answer613979935
Output613979935
StatusPASS
Native helperno
Runtime4920 ms
Peak memory18352 KB
Time complexityO(n^3) (estimated)
Space complexityO(n^2) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^3)O(n^2)
Space complexityO(n^2)O(n^2)
ApproachFlow solutionCombinatorial or DP counting
VerdictSuboptimal

Flow source

# Project Euler 780
# Toriangulations: count tilings of a x b tori by unit equilateral triangles,
# up to continuous motion of the triangles. G(N) = sum F(n), n <= N = 10^9.
#
# Every tiling is a strip tiling: rows of 2*lambda triangles between parallel
# full lines, s rows, n = 2*lambda*s. On a fixed ordered a x b torus each
# valid strip direction gives one connected family, and families merge exactly
# at edge-to-edge tilings, i.e. at copies of the triangular lattice T that
# contain the torus lattice. With m = n/2 this gives
#   G(N) = 2*D(M) + 4*T(M) - (4/3)*R(M),  M = N/2, where
#   D(M) = sum_{m<=M} d(m)                       (axis-parallel directions),
#   T(M) = #{(lambda,s,p,q): gcd(p,q)=1, p,q>=1,
#            sqrt(3)*p*q*s < lambda, lambda*s <= M}   (tilted directions;
#            counted via 2^omega(k) over k = p*q, segmented sieve),
#   R(M) = # rectangular sublattices of T with index <= M
#        = (1/2) sum over primitive Eisenstein points u, 3 !| norm(u),
#          of D(floor(M/2 / norm(u)))   (axes t*u and r*u*sqrt(-3)),
#          computed with Moebius over content, the ellipse point count
#          Circ(z) = 6*sum chi_3(d)*floor(z/d), and floor-value blocks.
# Verified: G(6)=14, G(100)=8090, G(10^5) = 645124048 (mod 1e9+7).

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

const N: i64 = 1000000000
const MOD: i64 = 1000000007
const INV3: i64 = 333333336
const PLIM: i64 = 17000
const BS: i64 = 1048576

function isqrt64(n: i64) -> i64 {
    if n <= 0 {
        return 0
    }
    let mut x: i64 = n
    let mut y: i64 = (x + 1) / 2
    while y < x {
        x = y
        y = (x + n / x) / 2
    }
    return x
}

# D(v) = sum_{t<=v} d(t) via the hyperbola method (exact, fits i64)
function dbig(v: i64) -> i64 {
    if v <= 0 {
        return 0
    }
    let q: i64 = isqrt64(v)
    let mut s: i64 = 0
    let mut k: i64 = 1
    while k <= q {
        s = s + v / k
        k = k + 1
    }
    return 2 * s - q * q
}

# Nonzero Eisenstein points with norm <= z: Circ(z) = 6*sum_d chi(d)*floor(z/d),
# chi the character mod 3; partial sum of chi over 1..t is (t % 3 == 1).
function circ(z: i64) -> i64 {
    if z <= 0 {
        return 0
    }
    let mut tot: i64 = 0
    let mut d: i64 = 1
    while d <= z {
        let v: i64 = z / d
        let d2: i64 = z / v
        let mut x2: i64 = 0
        if d2 % 3 == 1 {
            x2 = 1
        }
        let mut x1: i64 = 0
        if (d - 1) % 3 == 1 {
            x1 = 1
        }
        tot = tot + v * (x2 - x1)
        d = d2 + 1
    }
    return 6 * tot
}

# Primitive nonzero points with norm <= y (Moebius over content)
function primall(y: i64, mu: ptr<i64>) -> i64 {
    if y <= 0 {
        return 0
    }
    let q: i64 = isqrt64(y)
    let mut tot: i64 = 0
    let mut g: i64 = 1
    while g <= q {
        if mu[g] != 0 {
            tot = tot + mu[g] * circ(y / (g * g))
        }
        g = g + 1
    }
    return tot
}

# Primitive points with norm <= x and norm not divisible by 3:
# PF(x) = sum_i (-1)^i * primall(x / 3^i)
function pfree(x: i64, mu: ptr<i64>) -> i64 {
    let mut tot: i64 = 0
    let mut sign: i64 = 1
    let mut y: i64 = x
    while y >= 1 {
        tot = tot + sign * primall(y, mu)
        sign = 0 - sign
        y = y / 3
    }
    return tot
}

function main() -> i32 {
    let M: i64 = N / 2

    # ---- part A: 2*D(M) ----
    let dm: i64 = dbig(M) % MOD

    # ---- part B: T(M), tilted (torus, direction) nodes / 4 ----
    let m2m1: i64 = M * M - 1
    let kmax: i64 = isqrt64(m2m1 / 3)
    let smax: i64 = isqrt64(kmax)

    let hh: ptr<i64> = calloc(smax + 2, 8)
    let mut s: i64 = 1
    while s <= smax {
        hh[s] = hh[s - 1] + M / s
        s = s + 1
    }

    # primes up to PLIM for the segmented 2^omega sieve
    let comp: ptr<i64> = calloc(PLIM + 1, 8)
    let prlist: ptr<i64> = calloc(2100, 8)
    let mut npr: i64 = 0
    let mut i: i64 = 2
    while i <= PLIM {
        if comp[i] == 0 {
            prlist[npr] = i
            npr = npr + 1
            let mut j: i64 = i * i
            while j <= PLIM {
                comp[j] = 1
                j = j + i
            }
        }
        i = i + 1
    }

    let pw2: ptr<i64> = calloc(16, 8)
    pw2[0] = 1
    i = 1
    while i < 16 {
        pw2[i] = pw2[i - 1] * 2
        i = i + 1
    }

    let cnt: ptr<i64> = calloc(BS, 8)
    let rem: ptr<i64> = calloc(BS, 8)

    let mut tmod: i64 = 0
    let mut base: i64 = 0      # floor(sqrt(3)*k), maintained incrementally
    let mut scur: i64 = smax   # S_k, nonincreasing in k

    let mut lo: i64 = 1
    while lo <= kmax {
        let mut hi: i64 = lo + BS
        if hi > kmax + 1 {
            hi = kmax + 1
        }
        let blen: i64 = hi - lo
        i = 0
        while i < blen {
            cnt[i] = 0
            rem[i] = lo + i
            i = i + 1
        }
        let mut pi: i64 = 0
        while pi < npr {
            let pr: i64 = prlist[pi]
            let mut st: i64 = ((lo + pr - 1) / pr) * pr
            let mut j: i64 = st - lo
            while j < blen {
                cnt[j] = cnt[j] + 1
                rem[j] = rem[j] / pr
                j = j + pr
            }
            let mut pe: i64 = pr * pr
            while pe < hi {
                st = ((lo + pe - 1) / pe) * pe
                j = st - lo
                while j < blen {
                    rem[j] = rem[j] / pr
                    j = j + pe
                }
                pe = pe * pr
            }
            pi = pi + 1
        }

        i = 0
        while i < blen {
            let k: i64 = lo + i
            # advance base = floor(sqrt(3*k*k))
            base = base + 1
            while (base + 1) * (base + 1) <= 3 * k * k {
                base = base + 1
            }
            # shrink S_k: largest s with 3*k^2*s^4 <= M^2-1
            let qk: i64 = m2m1 / (3 * k * k)
            while scur > 0 && scur * scur * scur * scur > qk {
                scur = scur - 1
            }
            if scur > 0 {
                # sub = sum_{s<=S_k} floor(sqrt(3)*k*s), incremental
                let mut sub: i64 = 0
                let mut v: i64 = 0
                let mut t: i64 = 0
                let mut ss: i64 = 1
                while ss <= scur {
                    t = t + k
                    v = v + base
                    let tgt: i64 = 3 * t * t
                    while (v + 1) * (v + 1) <= tgt {
                        v = v + 1
                    }
                    sub = sub + v
                    ss = ss + 1
                }
                let mut wexp: i64 = cnt[i]
                if rem[i] > 1 {
                    wexp = wexp + 1
                }
                tmod = (tmod + pw2[wexp] * ((hh[scur] - sub) % MOD)) % MOD
            }
            i = i + 1
        }
        lo = hi
    }

    # ---- part C: R(M) = (1/2) sum_{k<=J, 3!|k} primpts(k) * D(J/k) ----
    let jj: i64 = M / 2
    let vj: i64 = isqrt64(jj)

    # Moebius sieve up to vj
    let mu: ptr<i64> = calloc(vj + 2, 8)
    let isc: ptr<i64> = calloc(vj + 2, 8)
    i = 0
    while i <= vj {
        mu[i] = 1
        i = i + 1
    }
    i = 2
    while i <= vj {
        if isc[i] == 0 {
            let mut j: i64 = i
            while j <= vj {
                if j > i {
                    isc[j] = 1
                }
                mu[j] = 0 - mu[j]
                j = j + i
            }
            let pp: i64 = i * i
            j = pp
            while j <= vj {
                mu[j] = 0
                j = j + pp
            }
        }
        i = i + 1
    }

    # small divisor-summatory prefix D(v) for v <= vj
    let dcnt: ptr<i64> = calloc(vj + 2, 8)
    i = 1
    while i <= vj {
        let mut j: i64 = i
        while j <= vj {
            dcnt[j] = dcnt[j] + 1
            j = j + i
        }
        i = i + 1
    }
    let dpre: ptr<i64> = calloc(vj + 2, 8)
    i = 1
    while i <= vj {
        dpre[i] = dpre[i - 1] + dcnt[i]
        i = i + 1
    }

    let mut r2mod: i64 = 0     # 2*R(M) mod p
    let mut k2: i64 = 0
    let mut pfprev: i64 = 0
    let mut k: i64 = 1
    while k <= jj {
        let v: i64 = jj / k
        k2 = jj / v
        let mut dv: i64 = 0
        if v <= vj {
            dv = dpre[v]
        } else {
            dv = dbig(v)
        }
        let pf2: i64 = pfree(k2, mu)
        let diff: i64 = pf2 - pfprev
        r2mod = (r2mod + (diff % MOD) * (dv % MOD)) % MOD
        pfprev = pf2
        k = k2 + 1
    }

    # ---- assemble: G = 2*D(M) + 4*T - (4/3)*R = 2*D + 4*T - (2/3)*(2R) ----
    let mut g: i64 = (2 * dm + 4 * tmod) % MOD
    let rterm: i64 = ((r2mod * 2) % MOD) * INV3 % MOD
    g = (g + MOD - rterm) % MOD
    printf("%lld\n", g)

    free(hh)
    free(comp)
    free(prlist)
    free(pw2)
    free(cnt)
    free(rem)
    free(mu)
    free(isc)
    free(dcnt)
    free(dpre)
    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 isqrt64_i64(int64_t n);
int64_t dbig_i64(int64_t v);
int64_t circ_i64(int64_t z);
int64_t primall_i64_ptr_i64(int64_t y, int64_t* mu);
int64_t pfree_i64_ptr_i64(int64_t x, int64_t* mu);
int32_t main(void);

static const int64_t N = 1000000000;
static const int64_t MOD = 1000000007;
static const int64_t INV3 = 333333336;
static const int64_t PLIM = 17000;
static const int64_t BS = 1048576;



int64_t isqrt64_i64(int64_t n) {
    if (n <= 0) {
        return 0;
    }
    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 dbig_i64(int64_t v) {
    if (v <= 0) {
        return 0;
    }
    int64_t q = isqrt64_i64(v);
    int64_t s = 0;
    int64_t k = 1;
    while (k <= q) {
        s = (s + FLOW_CHECKED_DIV((v), (k)));
        k = (k + 1);
    }
    return ((2 * s) - (q * q));
}

int64_t circ_i64(int64_t z) {
    if (z <= 0) {
        return 0;
    }
    int64_t tot = 0;
    int64_t d = 1;
    while (d <= z) {
        int64_t v = FLOW_CHECKED_DIV((z), (d));
        int64_t d2 = FLOW_CHECKED_DIV((z), (v));
        int64_t x2 = 0;
        if (FLOW_CHECKED_MOD((d2), (3)) == 1) {
            x2 = 1;
        }
        int64_t x1 = 0;
        if (FLOW_CHECKED_MOD(((d - 1)), (3)) == 1) {
            x1 = 1;
        }
        tot = (tot + (v * (x2 - x1)));
        d = (d2 + 1);
    }
    return (6 * tot);
}

int64_t primall_i64_ptr_i64(int64_t y, int64_t* mu) {
    if (y <= 0) {
        return 0;
    }
    int64_t q = isqrt64_i64(y);
    int64_t tot = 0;
    int64_t g = 1;
    while (g <= q) {
        if (mu[g] != 0) {
            tot = (tot + (mu[g] * circ_i64(FLOW_CHECKED_DIV((y), ((g * g))))));
        }
        g = (g + 1);
    }
    return tot;
}

int64_t pfree_i64_ptr_i64(int64_t x, int64_t* mu) {
    int64_t tot = 0;
    int64_t sign = 1;
    int64_t y = x;
    while (y >= 1) {
        tot = (tot + (sign * primall_i64_ptr_i64(y, mu)));
        sign = (0 - sign);
        y = FLOW_CHECKED_DIV((y), (3));
    }
    return tot;
}

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