Problem 559

Permuted Matrices — factorial powers + series inversion. Ported from C to pure Flow. MOD = 1000000123.

Answer684724920
Output684724920
StatusPASS
Native helperno
Runtime4410 ms
Peak memory17408 KB
Time complexityO(n^2) (estimated)
Space complexityO(n^2) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^2)O(n)
Space complexityO(n^2)O(n)
ApproachFlow solutionBig-integer factorial
VerdictSuboptimal

Flow source

# Project Euler 559
# Permuted Matrices — factorial powers + series inversion.
# Ported from C to pure Flow. MOD = 1000000123.

import euler.nt { mod_pow }

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

const MOD: i64 = 1000000123
const P1: i64 = 998244353
const P2: i64 = 1004535809
const P3: i64 = 469762049

let mut g_inv_p1_mod_p2: i64 = -1
let mut g_inv_p12_mod_p3: i64 = -1
let mut g_P12: i128 = 0

function mod_inv(a: i64, mod: i64) -> i64 {
    return mod_pow(a, mod - 2, mod)
}

function ntt(a: ptr<i64>, n: i64, invert: i32, mod: i64, root: i64) -> void {
    let mut j: i64 = 0
    let mut i: i64 = 1
    while i < n {
        let mut bit: i64 = n >> 1
        while (j & bit) != 0 {
            j = j ^ bit
            bit = bit >> 1
        }
        j = j ^ bit
        if i < j {
            let tmp: i64 = a[i]
            a[i] = a[j]
            a[j] = tmp
        }
        i = i + 1
    }
    let mut length: i64 = 2
    while length <= n {
        let wlen: i64 = mod_pow(root, (mod - 1) / length, mod)
        let mut wl: i64 = wlen
        if invert == 1 { wl = mod_pow(wlen, mod - 2, mod) }
        let half: i64 = length >> 1
        i = 0
        while i < n {
            let mut w: i64 = 1
            let mut jj: i64 = 0
            while jj < half {
                let u: i64 = a[i + jj]
                let v: i64 = ((a[i + jj + half] as i128) * (w as i128) % (mod as i128)) as i64
                let mut x: i64 = u + v
                if x >= mod { x = x - mod }
                let mut y: i64 = u - v
                if y < 0 { y = y + mod }
                a[i + jj] = x
                a[i + jj + half] = y
                w = ((w as i128) * (wl as i128) % (mod as i128)) as i64
                jj = jj + 1
            }
            i = i + length
        }
        length = length << 1
    }
    if invert == 1 {
        let inv_n: i64 = mod_pow(n, mod - 2, mod)
        i = 0
        while i < n {
            a[i] = ((a[i] as i128) * (inv_n as i128) % (mod as i128)) as i64
            i = i + 1
        }
    }
}

function convolve_one(a: ptr<i64>, n1: i64, b: ptr<i64>, n2: i64, mod: i64, root: i64, out_n: ptr<i64>) -> ptr<i64> {
    let need: i64 = n1 + n2 - 1
    let mut n: i64 = 1
    while n < need { n = n << 1 }
    let fa: ptr<i64> = calloc(n, 8) as ptr<i64>
    let fb: ptr<i64> = calloc(n, 8) as ptr<i64>
    let mut i: i64 = 0
    while i < n1 { fa[i] = a[i] % mod; i = i + 1 }
    i = 0
    while i < n2 { fb[i] = b[i] % mod; i = i + 1 }
    ntt(fa, n, 0, mod, root)
    ntt(fb, n, 0, mod, root)
    i = 0
    while i < n {
        fa[i] = ((fa[i] as i128) * (fb[i] as i128) % (mod as i128)) as i64
        i = i + 1
    }
    ntt(fa, n, 1, mod, root)
    out_n[0] = need
    let res: ptr<i64> = malloc(need * 8) as ptr<i64>
    i = 0
    while i < need { res[i] = fa[i]; i = i + 1 }
    free(fa as ptr<void>)
    free(fb as ptr<void>)
    return res
}

function crt3(a1: i64, a2: i64, a3: i64) -> i64 {
    if g_inv_p1_mod_p2 < 0 {
        g_inv_p1_mod_p2 = mod_inv(P1 % P2, P2)
        g_P12 = (P1 as i128) * (P2 as i128)
        g_inv_p12_mod_p3 = mod_inv((g_P12 % (P3 as i128)) as i64, P3)
    }
    let mut t1: i64 = ((a2 - a1) % P2)
    if t1 < 0 { t1 = t1 + P2 }
    t1 = ((t1 as i128) * (g_inv_p1_mod_p2 as i128) % (P2 as i128)) as i64
    let x2: i128 = (a1 as i128) + (P1 as i128) * (t1 as i128)
    let mut t2: i64 = ((a3 - (x2 % (P3 as i128)) as i64) % P3)
    if t2 < 0 { t2 = t2 + P3 }
    t2 = ((t2 as i128) * (g_inv_p12_mod_p3 as i128) % (P3 as i128)) as i64
    let x: i128 = x2 + g_P12 * (t2 as i128)
    let mut r: i64 = (x % (MOD as i128)) as i64
    if r < 0 { r = r + MOD }
    return r
}

function convolve_mod(a: ptr<i64>, n1: i64, b: ptr<i64>, n2: i64, out_n: ptr<i64>) -> ptr<i64> {
    if n1 == 0 || n2 == 0 { out_n[0] = 0; return null as ptr<i64> }
    let o1p: ptr<i64> = calloc(1, 8) as ptr<i64>
    let o2p: ptr<i64> = calloc(1, 8) as ptr<i64>
    let o3p: ptr<i64> = calloc(1, 8) as ptr<i64>
    let c1: ptr<i64> = convolve_one(a, n1, b, n2, P1, 3, o1p)
    let c2: ptr<i64> = convolve_one(a, n1, b, n2, P2, 3, o2p)
    let c3: ptr<i64> = convolve_one(a, n1, b, n2, P3, 3, o3p)
    let need: i64 = n1 + n2 - 1
    let res: ptr<i64> = malloc(need * 8) as ptr<i64>
    let mut i: i64 = 0
    while i < need { res[i] = crt3(c1[i], c2[i], c3[i]); i = i + 1 }
    free(c1 as ptr<void>)
    free(c2 as ptr<void>)
    free(c3 as ptr<void>)
    free(o1p as ptr<void>)
    free(o2p as ptr<void>)
    free(o3p as ptr<void>)
    out_n[0] = need
    return res
}

function poly_mul_mod(A: ptr<i64>, n: i64, B: ptr<i64>, m: i64) -> ptr<i64> {
    if n * m <= 40000 || n < 40 || m < 40 {
        let res: ptr<i64> = calloc(n + m - 1, 8) as ptr<i64>
        let mut i: i64 = 0
        while i < n {
            if A[i] != 0 {
                let mut j: i64 = 0
                while j < m {
                    res[i + j] = (res[i + j] + ((A[i] as i128) * (B[j] as i128) % (MOD as i128)) as i64) % MOD
                    j = j + 1
                }
            }
            i = i + 1
        }
        return res
    }
    let onp: ptr<i64> = calloc(1, 8) as ptr<i64>
    let r: ptr<i64> = convolve_mod(A, n, B, m, onp)
    free(onp as ptr<void>)
    return r
}

function poly_inv_mod(f: ptr<i64>, n: i64) -> ptr<i64> {
    let mut g: ptr<i64> = calloc(n, 8) as ptr<i64>
    g[0] = mod_inv(f[0], MOD)
    let mut m: i64 = 1
    while m < n {
        let m2: i64 = m * 2
        let mut m2c: i64 = m2
        if m2c > n { m2c = n }
        let fg: ptr<i64> = poly_mul_mod(f, m2c, g, m)
        let h: ptr<i64> = calloc(m2c, 8) as ptr<i64>
        let fglen: i64 = m2c + m - 1
        let mut i: i64 = 0
        while i < m2c {
            let v: i64 = if i < fglen { fg[i] } else { 0 }
            h[i] = (MOD - v) % MOD
            i = i + 1
        }
        h[0] = (h[0] + 2) % MOD
        free(fg as ptr<void>)
        let ng: ptr<i64> = poly_mul_mod(g, m, h, m2c)
        free(g as ptr<void>)
        free(h as ptr<void>)
        let gnew: ptr<i64> = calloc(m2c, 8) as ptr<i64>
        let nglen: i64 = m + m2c - 1
        i = 0
        while i < m2c {
            gnew[i] = if i < nglen { ng[i] } else { 0 }
            i = i + 1
        }
        free(ng as ptr<void>)
        g = gnew
        m = m2c
    }
    return g
}

function pre_fac_pow(n: i64, r: i64, fac_pow: ptr<i64>, inv_fac_pow: ptr<i64>) -> void {
    fac_pow[0] = 1
    let mut i: i64 = 1
    while i <= n {
        let ip: i64 = mod_pow(i, r, MOD)
        fac_pow[i] = ((fac_pow[i - 1] as i128) * (ip as i128) % (MOD as i128)) as i64
        i = i + 1
    }
    inv_fac_pow[n] = mod_inv(fac_pow[n], MOD)
    i = n - 1
    while i >= 0 {
        let ip: i64 = mod_pow(i + 1, r, MOD)
        inv_fac_pow[i] = ((inv_fac_pow[i + 1] as i128) * (ip as i128) % (MOD as i128)) as i64
        i = i - 1
    }
}

function P_via_dp(k: i64, n: i64, fac_pow: ptr<i64>, inv_fac_pow: ptr<i64>) -> i64 {
    let q: i64 = n / k
    let rem: i64 = n % k
    let m: i64 = q + (if rem != 0 { 1 } else { 0 })
    let blocks: ptr<i64> = malloc(m * 8) as ptr<i64>
    let mut i: i64 = 0
    while i < q { blocks[i] = k; i = i + 1 }
    if rem != 0 { blocks[q] = rem }
    let f: ptr<i64> = calloc(m + 1, 8) as ptr<i64>
    f[0] = fac_pow[n]
    i = 1
    while i <= m {
        let mut seg: i64 = 0
        let mut acc: i64 = 0
        let mut j: i64 = i - 1
        while j >= 0 {
            seg = seg + blocks[j]
            let term: i64 = ((f[j] as i128) * (inv_fac_pow[seg] as i128) % (MOD as i128)) as i64
            if (i - j) % 2 == 1 { acc = acc + term } else { acc = acc - term }
            j = j - 1
        }
        acc = acc % MOD
        if acc < 0 { acc = acc + MOD }
        f[i] = acc
        i = i + 1
    }
    let ans: i64 = f[m]
    free(blocks as ptr<void>)
    free(f as ptr<void>)
    return ans
}

function P_via_inverse(k: i64, n: i64, fac_pow: ptr<i64>, inv_fac_pow: ptr<i64>) -> i64 {
    let q: i64 = n / k
    let rem: i64 = n % k
    let p: ptr<i64> = calloc(q + 1, 8) as ptr<i64>
    p[0] = 1
    let mut d: i64 = 1
    while d <= q {
        let mut coeff: i64 = inv_fac_pow[d * k]
        if d % 2 == 1 { coeff = (MOD - coeff) % MOD }
        p[d] = coeff
        d = d + 1
    }
    let s: ptr<i64> = poly_inv_mod(p, q + 1)
    let g0: i64 = fac_pow[n]
    let g: ptr<i64> = malloc((q + 1) * 8) as ptr<i64>
    let mut i: i64 = 0
    while i <= q {
        g[i] = ((g0 as i128) * (s[i] as i128) % (MOD as i128)) as i64
        i = i + 1
    }
    if rem == 0 {
        let a2: i64 = g[q]
        free(p as ptr<void>)
        free(s as ptr<void>)
        free(g as ptr<void>)
        return a2
    }
    let mut ans: i64 = 0
    i = 0
    while i <= q {
        let seg_len: i64 = (q - i) * k + rem
        let term: i64 = ((g[i] as i128) * (inv_fac_pow[seg_len] as i128) % (MOD as i128)) as i64
        if (q - i) % 2 == 1 { ans = ans - term } else { ans = ans + term }
        i = i + 1
    }
    let mut a3: i64 = ans % MOD
    if a3 < 0 { a3 = a3 + MOD }
    free(p as ptr<void>)
    free(s as ptr<void>)
    free(g as ptr<void>)
    return a3
}

function Qn(n: i64) -> i64 {
    let r: i64 = n
    let fac_pow: ptr<i64> = malloc((n + 1) * 8) as ptr<i64>
    let inv_fac_pow: ptr<i64> = malloc((n + 1) * 8) as ptr<i64>
    pre_fac_pow(n, r, fac_pow, inv_fac_pow)
    let k_inv_max: i64 = n / 200
    let mut ans: i64 = 0
    let mut k: i64 = 1
    while k <= n {
        let q: i64 = n / k
        let v: i64 = 0
        if k <= k_inv_max && q > 200 {
            v = P_via_inverse(k, n, fac_pow, inv_fac_pow)
        } else {
            v = P_via_dp(k, n, fac_pow, inv_fac_pow)
        }
        ans = ans + v
        if ans >= MOD { ans = ans - MOD }
        k = k + 1
    }
    free(fac_pow as ptr<void>)
    free(inv_fac_pow as ptr<void>)
    return ans
}

function main() -> i32 {
    printf("%lld\n", Qn(50000))
    return 0
}

Generated C

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

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

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

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

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

#include <math.h>

void* _ui_state = NULL;

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

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

int64_t gcd_i64_i64(int64_t a0, int64_t b0);
int64_t lcm_i64_i64(int64_t a, int64_t b);
int64_t isqrt_i64(int64_t n);
int64_t mulmod_i64_i64_i64(int64_t a0, int64_t b0, int64_t mod);
int64_t mod_pow_i64_i64_i64(int64_t base, int64_t exp, int64_t mod);
bool is_prime_i64(int64_t n);
int64_t mod_inv_i64_i64(int64_t a, int64_t mod);
void ntt_ptr_i64_i64_i32_i64_i64(int64_t* a, int64_t n, int32_t invert, int64_t mod, int64_t root);
int64_t* convolve_one_ptr_i64_i64_ptr_i64_i64_i64_i64_ptr_i64(int64_t* a, int64_t n1, int64_t* b, int64_t n2, int64_t mod, int64_t root, int64_t* out_n);
int64_t crt3_i64_i64_i64(int64_t a1, int64_t a2, int64_t a3);
int64_t* convolve_mod_ptr_i64_i64_ptr_i64_i64_ptr_i64(int64_t* a, int64_t n1, int64_t* b, int64_t n2, int64_t* out_n);
int64_t* poly_mul_mod_ptr_i64_i64_ptr_i64_i64(int64_t* A, int64_t n, int64_t* B, int64_t m);
int64_t* poly_inv_mod_ptr_i64_i64(int64_t* f, int64_t n);
void pre_fac_pow_i64_i64_ptr_i64_ptr_i64(int64_t n, int64_t r, int64_t* fac_pow, int64_t* inv_fac_pow);
int64_t P_via_dp_i64_i64_ptr_i64_ptr_i64(int64_t k, int64_t n, int64_t* fac_pow, int64_t* inv_fac_pow);
int64_t P_via_inverse_i64_i64_ptr_i64_ptr_i64(int64_t k, int64_t n, int64_t* fac_pow, int64_t* inv_fac_pow);
int64_t Qn_i64(int64_t n);
int32_t main(void);

static const int64_t MOD = 1000000123;
static const int64_t P1 = 998244353;
static const int64_t P2 = 1004535809;
static const int64_t P3 = 469762049;

/* Module statics */
static int64_t g_inv_p1_mod_p2 = (-1);
static int64_t g_inv_p12_mod_p3 = (-1);
static __int128 g_P12 = 0;

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

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

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

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

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

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




int64_t mod_inv_i64_i64(int64_t a, int64_t mod) {
    return mod_pow_i64_i64_i64(a, (mod - 2), mod);
}

void ntt_ptr_i64_i64_i32_i64_i64(int64_t* a, int64_t n, int32_t invert, int64_t mod, int64_t root) {
    int64_t j = 0;
    int64_t i = 1;
    while (i < n) {
        int64_t bit = FLOW_CHECKED_SHR((n), (1));
        while ((j & bit) != 0) {
            j = (j ^ bit);
            bit = FLOW_CHECKED_SHR((bit), (1));
        }
        j = (j ^ bit);
        if (i < j) {
            int64_t tmp = a[i];
            a[i] = a[j];
            a[j] = tmp;
        }
        i = (i + 1);
    }
    int64_t length = 2;
    while (length <= n) {
        int64_t wlen = mod_pow_i64_i64_i64(root, FLOW_CHECKED_DIV(((mod - 1)), (length)), mod);
        int64_t wl = wlen;
        if (invert == 1) {
            wl = mod_pow_i64_i64_i64(wlen, (mod - 2), mod);
        }
        int64_t half = FLOW_CHECKED_SHR((length), (1));
        i = 0;
        while (i < n) {
            int64_t w = 1;
            int64_t jj = 0;
            while (jj < half) {
                int64_t u = a[(i + jj)];
                int64_t v = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(a[((i + jj) + half)])) * ((__int128)(w)))), (((__int128)(mod))))));
                int64_t x = (u + v);
                if (x >= mod) {
                    x = (x - mod);
                }
                int64_t y = (u - v);
                if (y < 0) {
                    y = (y + mod);
                }
                a[(i + jj)] = x;
                a[((i + jj) + half)] = y;
                w = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(w)) * ((__int128)(wl)))), (((__int128)(mod))))));
                jj = (jj + 1);
            }
            i = (i + length);
        }
        length = FLOW_CHECKED_SHL((length), (1));
    }
    if (invert == 1) {
        int64_t inv_n = mod_pow_i64_i64_i64(n, (mod - 2), mod);
        i = 0;
        while (i < n) {
            a[i] = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(a[i])) * ((__int128)(inv_n)))), (((__int128)(mod))))));
            i = (i + 1);
        }
    }
}

int64_t* convolve_one_ptr_i64_i64_ptr_i64_i64_i64_i64_ptr_i64(int64_t* a, int64_t n1, int64_t* b, int64_t n2, int64_t mod, int64_t root, int64_t* out_n) {
    int64_t need = ((n1 + n2) - 1);
    int64_t n = 1;
    while (n < need) {
        n = FLOW_CHECKED_SHL((n), (1));
    }
    int64_t* fa = (int64_t*)(((int64_t*)(calloc(n, 8))));
    int64_t* fb = (int64_t*)(((int64_t*)(calloc(n, 8))));
    int64_t i = 0;
    while (i < n1) {
        fa[i] = FLOW_CHECKED_MOD((a[i]), (mod));
        i = (i + 1);
    }
    i = 0;
    while (i < n2) {
        fb[i] = FLOW_CHECKED_MOD((b[i]), (mod));
        i = (i + 1);
    }
    ntt_ptr_i64_i64_i32_i64_i64(fa, n, 0, mod, root);
    ntt_ptr_i64_i64_i32_i64_i64(fb, n, 0, mod, root);
    i = 0;
    while (i < n) {
        fa[i] = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(fa[i])) * ((__int128)(fb[i])))), (((__int128)(mod))))));
        i = (i + 1);
    }
    ntt_ptr_i64_i64_i32_i64_i64(fa, n, 1, mod, root);
    out_n[0] = need;
    int64_t* res = (int64_t*)(((int64_t*)(malloc((need * 8)))));
    i = 0;
    while (i < need) {
        res[i] = fa[i];
        i = (i + 1);
    }
    free(((void*)(fa)));
    free(((void*)(fb)));
    return res;
}

int64_t crt3_i64_i64_i64(int64_t a1, int64_t a2, int64_t a3) {
    if (g_inv_p1_mod_p2 < 0) {
        g_inv_p1_mod_p2 = mod_inv_i64_i64(FLOW_CHECKED_MOD((P1), (P2)), P2);
        g_P12 = (((__int128)(P1)) * ((__int128)(P2)));
        g_inv_p12_mod_p3 = mod_inv_i64_i64(((int64_t)(FLOW_CHECKED_MOD((g_P12), (((__int128)(P3)))))), P3);
    }
    int64_t t1 = FLOW_CHECKED_MOD(((a2 - a1)), (P2));
    if (t1 < 0) {
        t1 = (t1 + P2);
    }
    t1 = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(t1)) * ((__int128)(g_inv_p1_mod_p2)))), (((__int128)(P2))))));
    __int128 x2 = (((__int128)(a1)) + (((__int128)(P1)) * ((__int128)(t1))));
    int64_t t2 = FLOW_CHECKED_MOD(((a3 - ((int64_t)(FLOW_CHECKED_MOD((x2), (((__int128)(P3)))))))), (P3));
    if (t2 < 0) {
        t2 = (t2 + P3);
    }
    t2 = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(t2)) * ((__int128)(g_inv_p12_mod_p3)))), (((__int128)(P3))))));
    __int128 x = (x2 + (g_P12 * ((__int128)(t2))));
    int64_t r = ((int64_t)(FLOW_CHECKED_MOD((x), (((__int128)(MOD))))));
    if (r < 0) {
        r = (r + MOD);
    }
    return r;
}

int64_t* convolve_mod_ptr_i64_i64_ptr_i64_i64_ptr_i64(int64_t* a, int64_t n1, int64_t* b, int64_t n2, int64_t* out_n) {
    if ((n1 == 0 || n2 == 0)) {
        out_n[0] = 0;
        return ((int64_t*)(NULL));
    }
    int64_t* o1p = (int64_t*)(((int64_t*)(calloc(1, 8))));
    int64_t* o2p = (int64_t*)(((int64_t*)(calloc(1, 8))));
    int64_t* o3p = (int64_t*)(((int64_t*)(calloc(1, 8))));
    int64_t* c1 = (int64_t*)(convolve_one_ptr_i64_i64_ptr_i64_i64_i64_i64_ptr_i64(a, n1, b, n2, P1, 3, o1p));
    int64_t* c2 = (int64_t*)(convolve_one_ptr_i64_i64_ptr_i64_i64_i64_i64_ptr_i64(a, n1, b, n2, P2, 3, o2p));
    int64_t* c3 = (int64_t*)(convolve_one_ptr_i64_i64_ptr_i64_i64_i64_i64_ptr_i64(a, n1, b, n2, P3, 3, o3p));
    int64_t need = ((n1 + n2) - 1);
    int64_t* res = (int64_t*)(((int64_t*)(malloc((need * 8)))));
    int64_t i = 0;
    while (i < need) {
        res[i] = crt3_i64_i64_i64(c1[i], c2[i], c3[i]);
        i = (i + 1);
    }
    free(((void*)(c1)));
    free(((void*)(c2)));
    free(((void*)(c3)));
    free(((void*)(o1p)));
    free(((void*)(o2p)));
    free(((void*)(o3p)));
    out_n[0] = need;
    return res;
}

int64_t* poly_mul_mod_ptr_i64_i64_ptr_i64_i64(int64_t* A, int64_t n, int64_t* B, int64_t m) {
    if ((((n * m) <= 40000 || n < 40) || m < 40)) {
        int64_t* res = (int64_t*)(((int64_t*)(calloc(((n + m) - 1), 8))));
        int64_t i = 0;
        while (i < n) {
            if (A[i] != 0) {
                int64_t j = 0;
                while (j < m) {
                    res[(i + j)] = FLOW_CHECKED_MOD(((res[(i + j)] + ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(A[i])) * ((__int128)(B[j])))), (((__int128)(MOD)))))))), (MOD));
                    j = (j + 1);
                }
            }
            i = (i + 1);
        }
        return res;
    }
    int64_t* onp = (int64_t*)(((int64_t*)(calloc(1, 8))));
    int64_t* r = (int64_t*)(convolve_mod_ptr_i64_i64_ptr_i64_i64_ptr_i64(A, n, B, m, onp));
    free(((void*)(onp)));
    return r;
}

int64_t* poly_inv_mod_ptr_i64_i64(int64_t* f, int64_t n) {
    int64_t* g = (int64_t*)(((int64_t*)(calloc(n, 8))));
    g[0] = mod_inv_i64_i64(f[0], MOD);
    int64_t m = 1;
    while (m < n) {
        int64_t m2 = (m * 2);
        int64_t m2c = m2;
        if (m2c > n) {
            m2c = n;
        }
        int64_t* fg = (int64_t*)(poly_mul_mod_ptr_i64_i64_ptr_i64_i64(f, m2c, g, m));
        int64_t* h = (int64_t*)(((int64_t*)(calloc(m2c, 8))));
        int64_t fglen = ((m2c + m) - 1);
        int64_t i = 0;
        while (i < m2c) {
            int64_t v = ((i < fglen) ? (fg[i]) : (0));
            h[i] = FLOW_CHECKED_MOD(((MOD - v)), (MOD));
            i = (i + 1);
        }
        h[0] = FLOW_CHECKED_MOD(((h[0] + 2)), (MOD));
        free(((void*)(fg)));
        int64_t* ng = (int64_t*)(poly_mul_mod_ptr_i64_i64_ptr_i64_i64(g, m, h, m2c));
        free(((void*)(g)));
        free(((void*)(h)));
        int64_t* gnew = (int64_t*)(((int64_t*)(calloc(m2c, 8))));
        int64_t nglen = ((m + m2c) - 1);
        i = 0;
        while (i < m2c) {
            gnew[i] = ((i < nglen) ? (ng[i]) : (0));
            i = (i + 1);
        }
        free(((void*)(ng)));
        g = gnew;
        m = m2c;
    }
    return g;
}

void pre_fac_pow_i64_i64_ptr_i64_ptr_i64(int64_t n, int64_t r, int64_t* fac_pow, int64_t* inv_fac_pow) {
    fac_pow[0] = 1;
    int64_t i = 1;
    while (i <= n) {
        int64_t ip = mod_pow_i64_i64_i64(i, r, MOD);
        fac_pow[i] = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(fac_pow[(i - 1)])) * ((__int128)(ip)))), (((__int128)(MOD))))));
        i = (i + 1);
    }
    inv_fac_pow[n] = mod_inv_i64_i64(fac_pow[n], MOD);
    i = (n - 1);
    while (i >= 0) {
        int64_t ip = mod_pow_i64_i64_i64((i + 1), r, MOD);
        inv_fac_pow[i] = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(inv_fac_pow[(i + 1)])) * ((__int128)(ip)))), (((__int128)(MOD))))));
        i = (i - 1);
    }
}

int64_t P_via_dp_i64_i64_ptr_i64_ptr_i64(int64_t k, int64_t n, int64_t* fac_pow, int64_t* inv_fac_pow) {
    int64_t q = FLOW_CHECKED_DIV((n), (k));
    int64_t rem = FLOW_CHECKED_MOD((n), (k));
    int64_t m = (q + ((rem != 0) ? (1) : (0)));
    int64_t* blocks = (int64_t*)(((int64_t*)(malloc((m * 8)))));
    int64_t i = 0;
    while (i < q) {
        blocks[i] = k;
        i = (i + 1);
    }
    if (rem != 0) {
        blocks[q] = rem;
    }
    int64_t* f = (int64_t*)(((int64_t*)(calloc((m + 1), 8))));
    f[0] = fac_pow[n];
    i = 1;
    while (i <= m) {
        int64_t seg = 0;
        int64_t acc = 0;
        int64_t j = (i - 1);
        while (j >= 0) {
            seg = (seg + blocks[j]);
            int64_t term = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(f[j])) * ((__int128)(inv_fac_pow[seg])))), (((__int128)(MOD))))));
            if (FLOW_CHECKED_MOD(((i - j)), (2)) == 1) {
                acc = (acc + term);
            } else {
                acc = (acc - term);
            }
            j = (j - 1);
        }
        acc = FLOW_CHECKED_MOD((acc), (MOD));
        if (acc < 0) {
            acc = (acc + MOD);
        }
        f[i] = acc;
        i = (i + 1);
    }
    int64_t ans = f[m];
    free(((void*)(blocks)));
    free(((void*)(f)));
    return ans;
}

int64_t P_via_inverse_i64_i64_ptr_i64_ptr_i64(int64_t k, int64_t n, int64_t* fac_pow, int64_t* inv_fac_pow) {
    int64_t q = FLOW_CHECKED_DIV((n), (k));
    int64_t rem = FLOW_CHECKED_MOD((n), (k));
    int64_t* p = (int64_t*)(((int64_t*)(calloc((q + 1), 8))));
    p[0] = 1;
    int64_t d = 1;
    while (d <= q) {
        int64_t coeff = inv_fac_pow[(d * k)];
        if (FLOW_CHECKED_MOD((d), (2)) == 1) {
            coeff = FLOW_CHECKED_MOD(((MOD - coeff)), (MOD));
        }
        p[d] = coeff;
        d = (d + 1);
    }
    int64_t* s = (int64_t*)(poly_inv_mod_ptr_i64_i64(p, (q + 1)));
    int64_t g0 = fac_pow[n];
    int64_t* g = (int64_t*)(((int64_t*)(malloc(((q + 1) * 8)))));
    int64_t i = 0;
    while (i <= q) {
        g[i] = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(g0)) * ((__int128)(s[i])))), (((__int128)(MOD))))));
        i = (i + 1);
    }
    if (rem == 0) {
        int64_t a2 = g[q];
        free(((void*)(p)));
        free(((void*)(s)));
        free(((void*)(g)));
        return a2;
    }
    int64_t ans = 0;
    i = 0;
    while (i <= q) {
        int64_t seg_len = (((q - i) * k) + rem);
        int64_t term = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(g[i])) * ((__int128)(inv_fac_pow[seg_len])))), (((__int128)(MOD))))));
        if (FLOW_CHECKED_MOD(((q - i)), (2)) == 1) {
            ans = (ans - term);
        } else {
            ans = (ans + term);
        }
        i = (i + 1);
    }
    int64_t a3 = FLOW_CHECKED_MOD((ans), (MOD));
    if (a3 < 0) {
        a3 = (a3 + MOD);
    }
    free(((void*)(p)));
    free(((void*)(s)));
    free(((void*)(g)));
    return a3;
}

int64_t Qn_i64(int64_t n) {
    int64_t r = n;
    int64_t* fac_pow = (int64_t*)(((int64_t*)(malloc(((n + 1) * 8)))));
    int64_t* inv_fac_pow = (int64_t*)(((int64_t*)(malloc(((n + 1) * 8)))));
    pre_fac_pow_i64_i64_ptr_i64_ptr_i64(n, r, fac_pow, inv_fac_pow);
    int64_t k_inv_max = FLOW_CHECKED_DIV((n), (200));
    int64_t ans = 0;
    int64_t k = 1;
    while (k <= n) {
        int64_t q = FLOW_CHECKED_DIV((n), (k));
        int64_t v = 0;
        if ((k <= k_inv_max && q > 200)) {
            v = P_via_inverse_i64_i64_ptr_i64_ptr_i64(k, n, fac_pow, inv_fac_pow);
        } else {
            v = P_via_dp_i64_i64_ptr_i64_ptr_i64(k, n, fac_pow, inv_fac_pow);
        }
        ans = (ans + v);
        if (ans >= MOD) {
            ans = (ans - MOD);
        }
        k = (k + 1);
    }
    free(((void*)(fac_pow)));
    free(((void*)(inv_fac_pow)));
    return ans;
}

int32_t main(void) {
    printf("%lld\n", Qn_i64(50000));
    return 0;
}

Generated MLIR

module {
  llvm.func @printf(!llvm.ptr, ...) -> i32
  llvm.mlir.global internal constant @str_0("%lld\n\00") {addr_space = 0 : i32} : !llvm.array<6 x i8>
  func.func @gcd(%arg0: i64, %arg1: i64) -> i64 {
    %0 = llvm.mlir.constant(1 : i64) : i64
    %1 = llvm.alloca %0 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %1 : i64, !llvm.ptr
    %2 = llvm.mlir.constant(1 : i64) : i64
    %3 = llvm.alloca %2 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %3 : i64, !llvm.ptr
    cf.br ^bb0
    ^bb0:
    %4 = llvm.load %3 : !llvm.ptr -> i64
    %5 = arith.constant 0 : i32
    %7 = arith.extsi %5 : i32 to i64
    %6 = arith.cmpi ne, %4, %7 : i64
    cf.cond_br %6, ^bb1, ^bb2
    ^bb1:
      %8 = llvm.load %1 : !llvm.ptr -> i64
      %9 = llvm.load %3 : !llvm.ptr -> i64
      %10 = arith.remsi %8, %9 : i64
      %11 = llvm.load %3 : !llvm.ptr -> i64
      llvm.store %11, %1 : i64, !llvm.ptr
      llvm.store %10, %3 : i64, !llvm.ptr
      cf.br ^bb0
    ^bb2:
    %12 = llvm.load %1 : !llvm.ptr -> i64
    func.return %12 : i64
  }
  func.func @lcm(%arg0: i64, %arg1: i64) -> i64 {
    %13 = arith.constant 0 : i32
    %15 = arith.extsi %13 : i32 to i64
    %14 = arith.cmpi eq, %arg0, %15 : i64
    %16 = scf.if %14 -> (i1) {
      %17 = arith.constant true
      scf.yield %17 : i1
    } else {
      %18 = arith.constant 0 : i32
      %20 = arith.extsi %18 : i32 to i64
      %19 = arith.cmpi eq, %arg1, %20 : i64
      scf.yield %19 : i1
    }
    cf.cond_br %16, ^bb3, ^bb4
    ^bb3:
      %21 = arith.constant 0 : i32
      %22 = arith.extsi %21 : i32 to i64
      func.return %22 : i64
    ^bb4:
      cf.br ^bb5
    ^bb5:
    %23 = func.call @gcd(%arg0, %arg1) : (i64, i64) -> i64
    %24 = arith.divsi %arg0, %23 : i64
    %25 = arith.muli %24, %arg1 : i64
    func.return %25 : i64
  }
  func.func @isqrt(%arg0: i64) -> i64 {
    %26 = arith.constant 2 : i32
    %28 = arith.extsi %26 : i32 to i64
    %27 = arith.cmpi slt, %arg0, %28 : i64
    cf.cond_br %27, ^bb6, ^bb7
    ^bb6:
      func.return %arg0 : i64
    ^bb7:
      cf.br ^bb8
    ^bb8:
    %29 = llvm.mlir.constant(1 : i64) : i64
    %30 = llvm.alloca %29 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %30 : i64, !llvm.ptr
    %31 = llvm.load %30 : !llvm.ptr -> i64
    %32 = arith.constant 1 : i32
    %34 = arith.extsi %32 : i32 to i64
    %33 = arith.addi %31, %34 : i64
    %35 = arith.constant 2 : i32
    %37 = arith.extsi %35 : i32 to i64
    %36 = arith.divsi %33, %37 : i64
    %38 = llvm.mlir.constant(1 : i64) : i64
    %39 = llvm.alloca %38 x i64 : (i64) -> !llvm.ptr
    llvm.store %36, %39 : i64, !llvm.ptr
    cf.br ^bb9
    ^bb9:
    %40 = llvm.load %39 : !llvm.ptr -> i64
    %41 = llvm.load %30 : !llvm.ptr -> i64
    %42 = arith.cmpi slt, %40, %41 : i64
    cf.cond_br %42, ^bb10, ^bb11
    ^bb10:
      %43 = llvm.load %39 : !llvm.ptr -> i64
      llvm.store %43, %30 : i64, !llvm.ptr
      %44 = llvm.load %30 : !llvm.ptr -> i64
      %45 = llvm.load %30 : !llvm.ptr -> i64
      %46 = arith.divsi %arg0, %45 : i64
      %47 = arith.addi %44, %46 : i64
      %48 = arith.constant 2 : i32
      %50 = arith.extsi %48 : i32 to i64
      %49 = arith.divsi %47, %50 : i64
      llvm.store %49, %39 : i64, !llvm.ptr
      cf.br ^bb9
    ^bb11:
    %51 = llvm.load %30 : !llvm.ptr -> i64
    func.return %51 : i64
  }
  func.func @mulmod(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %52 = arith.remsi %arg0, %arg2 : i64
    %53 = llvm.mlir.constant(1 : i64) : i64
    %54 = llvm.alloca %53 x i64 : (i64) -> !llvm.ptr
    llvm.store %52, %54 : i64, !llvm.ptr
    %55 = arith.remsi %arg1, %arg2 : i64
    %56 = llvm.mlir.constant(1 : i64) : i64
    %57 = llvm.alloca %56 x i64 : (i64) -> !llvm.ptr
    llvm.store %55, %57 : i64, !llvm.ptr
    %58 = arith.constant 0 : i32
    %59 = arith.extsi %58 : i32 to i64
    %60 = llvm.mlir.constant(1 : i64) : i64
    %61 = llvm.alloca %60 x i64 : (i64) -> !llvm.ptr
    llvm.store %59, %61 : i64, !llvm.ptr
    cf.br ^bb12
    ^bb12:
    %62 = llvm.load %57 : !llvm.ptr -> i64
    %63 = arith.constant 0 : i32
    %65 = arith.extsi %63 : i32 to i64
    %64 = arith.cmpi sgt, %62, %65 : i64
    cf.cond_br %64, ^bb13, ^bb14
    ^bb13:
      %66 = llvm.load %57 : !llvm.ptr -> i64
      %67 = arith.constant 2 : i32
      %69 = arith.extsi %67 : i32 to i64
      %68 = arith.remsi %66, %69 : i64
      %70 = arith.constant 1 : i32
      %72 = arith.extsi %70 : i32 to i64
      %71 = arith.cmpi eq, %68, %72 : i64
      cf.cond_br %71, ^bb15, ^bb16
      ^bb15:
        %73 = llvm.load %61 : !llvm.ptr -> i64
        %74 = llvm.load %54 : !llvm.ptr -> i64
        %75 = arith.addi %73, %74 : i64
        %76 = arith.remsi %75, %arg2 : i64
        llvm.store %76, %61 : i64, !llvm.ptr
        cf.br ^bb17
      ^bb16:
        cf.br ^bb17
      ^bb17:
      %77 = llvm.load %54 : !llvm.ptr -> i64
      %78 = arith.constant 2 : i32
      %80 = arith.extsi %78 : i32 to i64
      %79 = arith.muli %77, %80 : i64
      %81 = arith.remsi %79, %arg2 : i64
      llvm.store %81, %54 : i64, !llvm.ptr
      %82 = llvm.load %57 : !llvm.ptr -> i64
      %83 = arith.constant 2 : i32
      %85 = arith.extsi %83 : i32 to i64
      %84 = arith.divsi %82, %85 : i64
      llvm.store %84, %57 : i64, !llvm.ptr
      cf.br ^bb12
    ^bb14:
    %86 = llvm.load %61 : !llvm.ptr -> i64
    func.return %86 : i64
  }
  func.func @mod_pow(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %87 = arith.constant 1 : i32
    %89 = arith.extsi %87 : i32 to i64
    %88 = arith.cmpi eq, %arg2, %89 : i64
    cf.cond_br %88, ^bb18, ^bb19
    ^bb18:
      %90 = arith.constant 0 : i32
      %91 = arith.extsi %90 : i32 to i64
      func.return %91 : i64
    ^bb19:
      cf.br ^bb20
    ^bb20:
    %92 = arith.constant 1 : i32
    %93 = arith.extsi %92 : i32 to i64
    %94 = llvm.mlir.constant(1 : i64) : i64
    %95 = llvm.alloca %94 x i64 : (i64) -> !llvm.ptr
    llvm.store %93, %95 : i64, !llvm.ptr
    %96 = arith.remsi %arg0, %arg2 : i64
    %97 = llvm.mlir.constant(1 : i64) : i64
    %98 = llvm.alloca %97 x i64 : (i64) -> !llvm.ptr
    llvm.store %96, %98 : i64, !llvm.ptr
    %99 = llvm.mlir.constant(1 : i64) : i64
    %100 = llvm.alloca %99 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %100 : i64, !llvm.ptr
    cf.br ^bb21
    ^bb21:
    %101 = llvm.load %100 : !llvm.ptr -> i64
    %102 = arith.constant 0 : i32
    %104 = arith.extsi %102 : i32 to i64
    %103 = arith.cmpi sgt, %101, %104 : i64
    cf.cond_br %103, ^bb22, ^bb23
    ^bb22:
      %105 = llvm.load %100 : !llvm.ptr -> i64
      %106 = arith.constant 2 : i32
      %108 = arith.extsi %106 : i32 to i64
      %107 = arith.remsi %105, %108 : i64
      %109 = arith.constant 1 : i32
      %111 = arith.extsi %109 : i32 to i64
      %110 = arith.cmpi eq, %107, %111 : i64
      cf.cond_br %110, ^bb24, ^bb25
      ^bb24:
        %113 = llvm.load %95 : !llvm.ptr -> i64
        %114 = llvm.load %98 : !llvm.ptr -> i64
        %112 = func.call @mulmod(%113, %114, %arg2) : (i64, i64, i64) -> i64
        llvm.store %112, %95 : i64, !llvm.ptr
        cf.br ^bb26
      ^bb25:
        cf.br ^bb26
      ^bb26:
      %116 = llvm.load %98 : !llvm.ptr -> i64
      %117 = llvm.load %98 : !llvm.ptr -> i64
      %115 = func.call @mulmod(%116, %117, %arg2) : (i64, i64, i64) -> i64
      llvm.store %115, %98 : i64, !llvm.ptr
      %118 = llvm.load %100 : !llvm.ptr -> i64
      %119 = arith.constant 2 : i32
      %121 = arith.extsi %119 : i32 to i64
      %120 = arith.divsi %118, %121 : i64
      llvm.store %120, %100 : i64, !llvm.ptr
      cf.br ^bb21
    ^bb23:
    %122 = llvm.load %95 : !llvm.ptr -> i64
    func.return %122 : i64
  }
  func.func @is_prime(%arg0: i64) -> i1 {
    %123 = arith.constant 2 : i32
    %125 = arith.extsi %123 : i32 to i64
    %124 = arith.cmpi slt, %arg0, %125 : i64
    cf.cond_br %124, ^bb27, ^bb28
    ^bb27:
      %126 = arith.constant 0 : i1
      func.return %126 : i1
    ^bb28:
      cf.br ^bb29
    ^bb29:
    %127 = arith.constant 4 : i32
    %129 = arith.extsi %127 : i32 to i64
    %128 = arith.cmpi slt, %arg0, %129 : i64
    cf.cond_br %128, ^bb30, ^bb31
    ^bb30:
      %130 = arith.constant 1 : i1
      func.return %130 : i1
    ^bb31:
      cf.br ^bb32
    ^bb32:
    %131 = arith.constant 2 : i32
    %133 = arith.extsi %131 : i32 to i64
    %132 = arith.remsi %arg0, %133 : i64
    %134 = arith.constant 0 : i32
    %136 = arith.extsi %134 : i32 to i64
    %135 = arith.cmpi eq, %132, %136 : i64
    %137 = scf.if %135 -> (i1) {
      %138 = arith.constant true
      scf.yield %138 : i1
    } else {
      %139 = arith.constant 3 : i32
      %141 = arith.extsi %139 : i32 to i64
      %140 = arith.remsi %arg0, %141 : i64
      %142 = arith.constant 0 : i32
      %144 = arith.extsi %142 : i32 to i64
      %143 = arith.cmpi eq, %140, %144 : i64
      scf.yield %143 : i1
    }
    cf.cond_br %137, ^bb33, ^bb34
    ^bb33:
      %145 = arith.constant 0 : i1
      func.return %145 : i1
    ^bb34:
      cf.br ^bb35
    ^bb35:
    %146 = arith.constant 5 : i32
    %147 = arith.extsi %146 : i32 to i64
    %148 = llvm.mlir.constant(1 : i64) : i64
    %149 = llvm.alloca %148 x i64 : (i64) -> !llvm.ptr
    llvm.store %147, %149 : i64, !llvm.ptr
    cf.br ^bb36
    ^bb36:
    %150 = llvm.load %149 : !llvm.ptr -> i64
    %151 = llvm.load %149 : !llvm.ptr -> i64
    %152 = arith.muli %150, %151 : i64
    %153 = arith.cmpi sle, %152, %arg0 : i64
    cf.cond_br %153, ^bb37, ^bb38
    ^bb37:
      %154 = llvm.load %149 : !llvm.ptr -> i64
      %155 = arith.remsi %arg0, %154 : i64
      %156 = arith.constant 0 : i32
      %158 = arith.extsi %156 : i32 to i64
      %157 = arith.cmpi eq, %155, %158 : i64
      %159 = scf.if %157 -> (i1) {
        %160 = arith.constant true
        scf.yield %160 : i1
      } else {
        %161 = llvm.load %149 : !llvm.ptr -> i64
        %162 = arith.constant 2 : i32
        %164 = arith.extsi %162 : i32 to i64
        %163 = arith.addi %161, %164 : i64
        %165 = arith.remsi %arg0, %163 : i64
        %166 = arith.constant 0 : i32
        %168 = arith.extsi %166 : i32 to i64
        %167 = arith.cmpi eq, %165, %168 : i64
        scf.yield %167 : i1
      }
      cf.cond_br %159, ^bb39, ^bb40
      ^bb39:
        %169 = arith.constant 0 : i1
        func.return %169 : i1
      ^bb40:
        cf.br ^bb41
      ^bb41:
      %170 = llvm.load %149 : !llvm.ptr -> i64
      %171 = arith.constant 6 : i32
      %173 = arith.extsi %171 : i32 to i64
      %172 = arith.addi %170, %173 : i64
      llvm.store %172, %149 : i64, !llvm.ptr
      cf.br ^bb36
    ^bb38:
    %174 = arith.constant 1 : i1
    func.return %174 : i1
  }
  func.func private @calloc(i64, i64) -> !llvm.ptr
  func.func private @free(!llvm.ptr) -> ()
  func.func private @malloc(i64) -> !llvm.ptr
  // Constant: MOD
  llvm.mlir.global internal constant @MOD(1000000123 : i64) : i64
  // Constant: P1
  llvm.mlir.global internal constant @P1(998244353 : i64) : i64
  // Constant: P2
  llvm.mlir.global internal constant @P2(1004535809 : i64) : i64
  // Constant: P3
  llvm.mlir.global internal constant @P3(469762049 : i64) : i64
  // Module static: g_inv_p1_mod_p2
  llvm.mlir.global internal @g_inv_p1_mod_p2(0 : i64) : i64
  // Module static: g_inv_p12_mod_p3
  llvm.mlir.global internal @g_inv_p12_mod_p3(0 : i64) : i64
  // Module static: g_P12
  llvm.mlir.global internal @g_P12(0 : i128) : i128
  func.func @mod_inv(%arg0: i64, %arg1: i64) -> i64 {
    %176 = arith.constant 2 : i32
    %178 = arith.extsi %176 : i32 to i64
    %177 = arith.subi %arg1, %178 : i64
    %175 = func.call @mod_pow(%arg0, %177, %arg1) : (i64, i64, i64) -> i64
    func.return %175 : i64
  }
  func.func @ntt(%arg0: !llvm.ptr, %arg1: i64, %arg2: i32, %arg3: i64, %arg4: i64) -> () {
    %179 = arith.constant 0 : i32
    %180 = arith.extsi %179 : i32 to i64
    %181 = llvm.mlir.constant(1 : i64) : i64
    %182 = llvm.alloca %181 x i64 : (i64) -> !llvm.ptr
    llvm.store %180, %182 : i64, !llvm.ptr
    %183 = arith.constant 1 : i32
    %184 = arith.extsi %183 : i32 to i64
    %185 = llvm.mlir.constant(1 : i64) : i64
    %186 = llvm.alloca %185 x i64 : (i64) -> !llvm.ptr
    llvm.store %184, %186 : i64, !llvm.ptr
    cf.br ^bb42
    ^bb42:
    %187 = llvm.load %186 : !llvm.ptr -> i64
    %188 = arith.cmpi slt, %187, %arg1 : i64
    cf.cond_br %188, ^bb43, ^bb44
    ^bb43:
      %189 = arith.constant 1 : i32
      %191 = arith.extsi %189 : i32 to i64
      %190 = arith.shrsi %arg1, %191 : i64
      %192 = llvm.mlir.constant(1 : i64) : i64
      %193 = llvm.alloca %192 x i64 : (i64) -> !llvm.ptr
      llvm.store %190, %193 : i64, !llvm.ptr
      cf.br ^bb45
      ^bb45:
      %194 = llvm.load %182 : !llvm.ptr -> i64
      %195 = llvm.load %193 : !llvm.ptr -> i64
      %196 = arith.andi %194, %195 : i64
      %197 = arith.constant 0 : i32
      %199 = arith.extsi %197 : i32 to i64
      %198 = arith.cmpi ne, %196, %199 : i64
      cf.cond_br %198, ^bb46, ^bb47
      ^bb46:
        %200 = llvm.load %182 : !llvm.ptr -> i64
        %201 = llvm.load %193 : !llvm.ptr -> i64
        %202 = arith.xori %200, %201 : i64
        llvm.store %202, %182 : i64, !llvm.ptr
        %203 = llvm.load %193 : !llvm.ptr -> i64
        %204 = arith.constant 1 : i32
        %206 = arith.extsi %204 : i32 to i64
        %205 = arith.shrsi %203, %206 : i64
        llvm.store %205, %193 : i64, !llvm.ptr
        cf.br ^bb45
      ^bb47:
      %207 = llvm.load %182 : !llvm.ptr -> i64
      %208 = llvm.load %193 : !llvm.ptr -> i64
      %209 = arith.xori %207, %208 : i64
      llvm.store %209, %182 : i64, !llvm.ptr
      %210 = llvm.load %186 : !llvm.ptr -> i64
      %211 = llvm.load %182 : !llvm.ptr -> i64
      %212 = arith.cmpi slt, %210, %211 : i64
      cf.cond_br %212, ^bb48, ^bb49
      ^bb48:
        %214 = llvm.load %186 : !llvm.ptr -> i64
        %215 = llvm.getelementptr %arg0[%214] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %213 = llvm.load %215 : !llvm.ptr -> i64
        %217 = llvm.load %182 : !llvm.ptr -> i64
        %218 = llvm.getelementptr %arg0[%217] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %216 = llvm.load %218 : !llvm.ptr -> i64
        %219 = llvm.load %186 : !llvm.ptr -> i64
        %220 = llvm.getelementptr %arg0[%219] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %216, %220 : i64, !llvm.ptr
        %221 = llvm.load %182 : !llvm.ptr -> i64
        %222 = llvm.getelementptr %arg0[%221] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %213, %222 : i64, !llvm.ptr
        cf.br ^bb50
      ^bb49:
        cf.br ^bb50
      ^bb50:
      %223 = llvm.load %186 : !llvm.ptr -> i64
      %224 = arith.constant 1 : i32
      %226 = arith.extsi %224 : i32 to i64
      %225 = arith.addi %223, %226 : i64
      llvm.store %225, %186 : i64, !llvm.ptr
      cf.br ^bb42
    ^bb44:
    %227 = arith.constant 2 : i32
    %228 = arith.extsi %227 : i32 to i64
    %229 = llvm.mlir.constant(1 : i64) : i64
    %230 = llvm.alloca %229 x i64 : (i64) -> !llvm.ptr
    llvm.store %228, %230 : i64, !llvm.ptr
    cf.br ^bb51
    ^bb51:
    %231 = llvm.load %230 : !llvm.ptr -> i64
    %232 = arith.cmpi sle, %231, %arg1 : i64
    cf.cond_br %232, ^bb52, ^bb53
    ^bb52:
      %234 = arith.constant 1 : i32
      %236 = arith.extsi %234 : i32 to i64
      %235 = arith.subi %arg3, %236 : i64
      %237 = llvm.load %230 : !llvm.ptr -> i64
      %238 = arith.divsi %235, %237 : i64
      %233 = func.call @mod_pow(%arg4, %238, %arg3) : (i64, i64, i64) -> i64
      %239 = llvm.mlir.constant(1 : i64) : i64
      %240 = llvm.alloca %239 x i64 : (i64) -> !llvm.ptr
      llvm.store %233, %240 : i64, !llvm.ptr
      %241 = arith.constant 1 : i32
      %242 = arith.cmpi eq, %arg2, %241 : i32
      cf.cond_br %242, ^bb54, ^bb55
      ^bb54:
        %244 = arith.constant 2 : i32
        %246 = arith.extsi %244 : i32 to i64
        %245 = arith.subi %arg3, %246 : i64
        %243 = func.call @mod_pow(%233, %245, %arg3) : (i64, i64, i64) -> i64
        llvm.store %243, %240 : i64, !llvm.ptr
        cf.br ^bb56
      ^bb55:
        cf.br ^bb56
      ^bb56:
      %247 = llvm.load %230 : !llvm.ptr -> i64
      %248 = arith.constant 1 : i32
      %250 = arith.extsi %248 : i32 to i64
      %249 = arith.shrsi %247, %250 : i64
      %251 = arith.constant 0 : i32
      %252 = arith.extsi %251 : i32 to i64
      llvm.store %252, %186 : i64, !llvm.ptr
      cf.br ^bb57
      ^bb57:
      %253 = llvm.load %186 : !llvm.ptr -> i64
      %254 = arith.cmpi slt, %253, %arg1 : i64
      cf.cond_br %254, ^bb58, ^bb59
      ^bb58:
        %255 = arith.constant 1 : i32
        %256 = arith.extsi %255 : i32 to i64
        %257 = llvm.mlir.constant(1 : i64) : i64
        %258 = llvm.alloca %257 x i64 : (i64) -> !llvm.ptr
        llvm.store %256, %258 : i64, !llvm.ptr
        %259 = arith.constant 0 : i32
        %260 = arith.extsi %259 : i32 to i64
        %261 = llvm.mlir.constant(1 : i64) : i64
        %262 = llvm.alloca %261 x i64 : (i64) -> !llvm.ptr
        llvm.store %260, %262 : i64, !llvm.ptr
        cf.br ^bb60
        ^bb60:
        %263 = llvm.load %262 : !llvm.ptr -> i64
        %264 = arith.cmpi slt, %263, %249 : i64
        cf.cond_br %264, ^bb61, ^bb62
        ^bb61:
          %266 = llvm.load %186 : !llvm.ptr -> i64
          %267 = llvm.load %262 : !llvm.ptr -> i64
          %268 = arith.addi %266, %267 : i64
          %269 = llvm.getelementptr %arg0[%268] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %265 = llvm.load %269 : !llvm.ptr -> i64
          %271 = llvm.load %186 : !llvm.ptr -> i64
          %272 = llvm.load %262 : !llvm.ptr -> i64
          %273 = arith.addi %271, %272 : i64
          %274 = arith.addi %273, %249 : i64
          %275 = llvm.getelementptr %arg0[%274] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %270 = llvm.load %275 : !llvm.ptr -> i64
          %276 = arith.extsi %270 : i64 to i128
          %277 = llvm.load %258 : !llvm.ptr -> i64
          %278 = arith.extsi %277 : i64 to i128
          %280 = arith.trunci %276 : i128 to i64
          %281 = arith.trunci %278 : i128 to i64
          %279 = arith.muli %280, %281 : i64
          %282 = arith.extsi %arg3 : i64 to i128
          %284 = arith.trunci %282 : i128 to i64
          %283 = arith.remsi %279, %284 : i64
          %285 = arith.addi %265, %283 : i64
          %286 = llvm.mlir.constant(1 : i64) : i64
          %287 = llvm.alloca %286 x i64 : (i64) -> !llvm.ptr
          llvm.store %285, %287 : i64, !llvm.ptr
          %288 = llvm.load %287 : !llvm.ptr -> i64
          %289 = arith.cmpi sge, %288, %arg3 : i64
          cf.cond_br %289, ^bb63, ^bb64
          ^bb63:
            %290 = llvm.load %287 : !llvm.ptr -> i64
            %291 = arith.subi %290, %arg3 : i64
            llvm.store %291, %287 : i64, !llvm.ptr
            cf.br ^bb65
          ^bb64:
            cf.br ^bb65
          ^bb65:
          %292 = arith.subi %265, %283 : i64
          %293 = llvm.mlir.constant(1 : i64) : i64
          %294 = llvm.alloca %293 x i64 : (i64) -> !llvm.ptr
          llvm.store %292, %294 : i64, !llvm.ptr
          %295 = llvm.load %294 : !llvm.ptr -> i64
          %296 = arith.constant 0 : i32
          %298 = arith.extsi %296 : i32 to i64
          %297 = arith.cmpi slt, %295, %298 : i64
          cf.cond_br %297, ^bb66, ^bb67
          ^bb66:
            %299 = llvm.load %294 : !llvm.ptr -> i64
            %300 = arith.addi %299, %arg3 : i64
            llvm.store %300, %294 : i64, !llvm.ptr
            cf.br ^bb68
          ^bb67:
            cf.br ^bb68
          ^bb68:
          %301 = llvm.load %287 : !llvm.ptr -> i64
          %302 = llvm.load %186 : !llvm.ptr -> i64
          %303 = llvm.load %262 : !llvm.ptr -> i64
          %304 = arith.addi %302, %303 : i64
          %305 = llvm.getelementptr %arg0[%304] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          llvm.store %301, %305 : i64, !llvm.ptr
          %306 = llvm.load %294 : !llvm.ptr -> i64
          %307 = llvm.load %186 : !llvm.ptr -> i64
          %308 = llvm.load %262 : !llvm.ptr -> i64
          %309 = arith.addi %307, %308 : i64
          %310 = arith.addi %309, %249 : i64
          %311 = llvm.getelementptr %arg0[%310] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          llvm.store %306, %311 : i64, !llvm.ptr
          %312 = llvm.load %258 : !llvm.ptr -> i64
          %313 = arith.extsi %312 : i64 to i128
          %314 = llvm.load %240 : !llvm.ptr -> i64
          %315 = arith.extsi %314 : i64 to i128
          %317 = arith.trunci %313 : i128 to i64
          %318 = arith.trunci %315 : i128 to i64
          %316 = arith.muli %317, %318 : i64
          %319 = arith.extsi %arg3 : i64 to i128
          %321 = arith.trunci %319 : i128 to i64
          %320 = arith.remsi %316, %321 : i64
          llvm.store %320, %258 : i64, !llvm.ptr
          %322 = llvm.load %262 : !llvm.ptr -> i64
          %323 = arith.constant 1 : i32
          %325 = arith.extsi %323 : i32 to i64
          %324 = arith.addi %322, %325 : i64
          llvm.store %324, %262 : i64, !llvm.ptr
          cf.br ^bb60
        ^bb62:
        %326 = llvm.load %186 : !llvm.ptr -> i64
        %327 = llvm.load %230 : !llvm.ptr -> i64
        %328 = arith.addi %326, %327 : i64
        llvm.store %328, %186 : i64, !llvm.ptr
        cf.br ^bb57
      ^bb59:
      %329 = llvm.load %230 : !llvm.ptr -> i64
      %330 = arith.constant 1 : i32
      %332 = arith.extsi %330 : i32 to i64
      %331 = arith.shli %329, %332 : i64
      llvm.store %331, %230 : i64, !llvm.ptr
      cf.br ^bb51
    ^bb53:
    %333 = arith.constant 1 : i32
    %334 = arith.cmpi eq, %arg2, %333 : i32
    cf.cond_br %334, ^bb69, ^bb70
    ^bb69:
      %336 = arith.constant 2 : i32
      %338 = arith.extsi %336 : i32 to i64
      %337 = arith.subi %arg3, %338 : i64
      %335 = func.call @mod_pow(%arg1, %337, %arg3) : (i64, i64, i64) -> i64
      %339 = arith.constant 0 : i32
      %340 = arith.extsi %339 : i32 to i64
      llvm.store %340, %186 : i64, !llvm.ptr
      cf.br ^bb72
      ^bb72:
      %341 = llvm.load %186 : !llvm.ptr -> i64
      %342 = arith.cmpi slt, %341, %arg1 : i64
      cf.cond_br %342, ^bb73, ^bb74
      ^bb73:
        %344 = llvm.load %186 : !llvm.ptr -> i64
        %345 = llvm.getelementptr %arg0[%344] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %343 = llvm.load %345 : !llvm.ptr -> i64
        %346 = arith.extsi %343 : i64 to i128
        %347 = arith.extsi %335 : i64 to i128
        %349 = arith.trunci %346 : i128 to i64
        %350 = arith.trunci %347 : i128 to i64
        %348 = arith.muli %349, %350 : i64
        %351 = arith.extsi %arg3 : i64 to i128
        %353 = arith.trunci %351 : i128 to i64
        %352 = arith.remsi %348, %353 : i64
        %354 = llvm.load %186 : !llvm.ptr -> i64
        %355 = llvm.getelementptr %arg0[%354] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %352, %355 : i64, !llvm.ptr
        %356 = llvm.load %186 : !llvm.ptr -> i64
        %357 = arith.constant 1 : i32
        %359 = arith.extsi %357 : i32 to i64
        %358 = arith.addi %356, %359 : i64
        llvm.store %358, %186 : i64, !llvm.ptr
        cf.br ^bb72
      ^bb74:
      cf.br ^bb71
    ^bb70:
      cf.br ^bb71
    ^bb71:
    func.return
  }
  func.func @convolve_one(%arg0: !llvm.ptr, %arg1: i64, %arg2: !llvm.ptr, %arg3: i64, %arg4: i64, %arg5: i64, %arg6: !llvm.ptr) -> !llvm.ptr {
    %360 = arith.addi %arg1, %arg3 : i64
    %361 = arith.constant 1 : i32
    %363 = arith.extsi %361 : i32 to i64
    %362 = arith.subi %360, %363 : i64
    %364 = arith.constant 1 : i32
    %365 = arith.extsi %364 : i32 to i64
    %366 = llvm.mlir.constant(1 : i64) : i64
    %367 = llvm.alloca %366 x i64 : (i64) -> !llvm.ptr
    llvm.store %365, %367 : i64, !llvm.ptr
    cf.br ^bb75
    ^bb75:
    %368 = llvm.load %367 : !llvm.ptr -> i64
    %369 = arith.cmpi slt, %368, %362 : i64
    cf.cond_br %369, ^bb76, ^bb77
    ^bb76:
      %370 = llvm.load %367 : !llvm.ptr -> i64
      %371 = arith.constant 1 : i32
      %373 = arith.extsi %371 : i32 to i64
      %372 = arith.shli %370, %373 : i64
      llvm.store %372, %367 : i64, !llvm.ptr
      cf.br ^bb75
    ^bb77:
    %375 = llvm.load %367 : !llvm.ptr -> i64
    %376 = arith.constant 8 : i32
    %377 = arith.extsi %376 : i32 to i64
    %374 = func.call @calloc(%375, %377) : (i64, i64) -> !llvm.ptr
    %379 = llvm.load %367 : !llvm.ptr -> i64
    %380 = arith.constant 8 : i32
    %381 = arith.extsi %380 : i32 to i64
    %378 = func.call @calloc(%379, %381) : (i64, i64) -> !llvm.ptr
    %382 = arith.constant 0 : i32
    %383 = arith.extsi %382 : i32 to i64
    %384 = llvm.mlir.constant(1 : i64) : i64
    %385 = llvm.alloca %384 x i64 : (i64) -> !llvm.ptr
    llvm.store %383, %385 : i64, !llvm.ptr
    cf.br ^bb78
    ^bb78:
    %386 = llvm.load %385 : !llvm.ptr -> i64
    %387 = arith.cmpi slt, %386, %arg1 : i64
    cf.cond_br %387, ^bb79, ^bb80
    ^bb79:
      %389 = llvm.load %385 : !llvm.ptr -> i64
      %390 = llvm.getelementptr %arg0[%389] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %388 = llvm.load %390 : !llvm.ptr -> i64
      %391 = arith.remsi %388, %arg4 : i64
      %392 = llvm.load %385 : !llvm.ptr -> i64
      %393 = llvm.getelementptr %374[%392] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %391, %393 : i64, !llvm.ptr
      %394 = llvm.load %385 : !llvm.ptr -> i64
      %395 = arith.constant 1 : i32
      %397 = arith.extsi %395 : i32 to i64
      %396 = arith.addi %394, %397 : i64
      llvm.store %396, %385 : i64, !llvm.ptr
      cf.br ^bb78
    ^bb80:
    %398 = arith.constant 0 : i32
    %399 = arith.extsi %398 : i32 to i64
    llvm.store %399, %385 : i64, !llvm.ptr
    cf.br ^bb81
    ^bb81:
    %400 = llvm.load %385 : !llvm.ptr -> i64
    %401 = arith.cmpi slt, %400, %arg3 : i64
    cf.cond_br %401, ^bb82, ^bb83
    ^bb82:
      %403 = llvm.load %385 : !llvm.ptr -> i64
      %404 = llvm.getelementptr %arg2[%403] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %402 = llvm.load %404 : !llvm.ptr -> i64
      %405 = arith.remsi %402, %arg4 : i64
      %406 = llvm.load %385 : !llvm.ptr -> i64
      %407 = llvm.getelementptr %378[%406] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %405, %407 : i64, !llvm.ptr
      %408 = llvm.load %385 : !llvm.ptr -> i64
      %409 = arith.constant 1 : i32
      %411 = arith.extsi %409 : i32 to i64
      %410 = arith.addi %408, %411 : i64
      llvm.store %410, %385 : i64, !llvm.ptr
      cf.br ^bb81
    ^bb83:
    %413 = llvm.load %367 : !llvm.ptr -> i64
    %414 = arith.constant 0 : i32
    func.call @ntt(%374, %413, %414, %arg4, %arg5) : (!llvm.ptr, i64, i32, i64, i64) -> ()
    %416 = llvm.load %367 : !llvm.ptr -> i64
    %417 = arith.constant 0 : i32
    func.call @ntt(%378, %416, %417, %arg4, %arg5) : (!llvm.ptr, i64, i32, i64, i64) -> ()
    %418 = arith.constant 0 : i32
    %419 = arith.extsi %418 : i32 to i64
    llvm.store %419, %385 : i64, !llvm.ptr
    cf.br ^bb84
    ^bb84:
    %420 = llvm.load %385 : !llvm.ptr -> i64
    %421 = llvm.load %367 : !llvm.ptr -> i64
    %422 = arith.cmpi slt, %420, %421 : i64
    cf.cond_br %422, ^bb85, ^bb86
    ^bb85:
      %424 = llvm.load %385 : !llvm.ptr -> i64
      %425 = llvm.getelementptr %374[%424] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %423 = llvm.load %425 : !llvm.ptr -> i64
      %426 = arith.extsi %423 : i64 to i128
      %428 = llvm.load %385 : !llvm.ptr -> i64
      %429 = llvm.getelementptr %378[%428] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %427 = llvm.load %429 : !llvm.ptr -> i64
      %430 = arith.extsi %427 : i64 to i128
      %432 = arith.trunci %426 : i128 to i64
      %433 = arith.trunci %430 : i128 to i64
      %431 = arith.muli %432, %433 : i64
      %434 = arith.extsi %arg4 : i64 to i128
      %436 = arith.trunci %434 : i128 to i64
      %435 = arith.remsi %431, %436 : i64
      %437 = llvm.load %385 : !llvm.ptr -> i64
      %438 = llvm.getelementptr %374[%437] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %435, %438 : i64, !llvm.ptr
      %439 = llvm.load %385 : !llvm.ptr -> i64
      %440 = arith.constant 1 : i32
      %442 = arith.extsi %440 : i32 to i64
      %441 = arith.addi %439, %442 : i64
      llvm.store %441, %385 : i64, !llvm.ptr
      cf.br ^bb84
    ^bb86:
    %444 = llvm.load %367 : !llvm.ptr -> i64
    %445 = arith.constant 1 : i32
    func.call @ntt(%374, %444, %445, %arg4, %arg5) : (!llvm.ptr, i64, i32, i64, i64) -> ()
    %446 = arith.constant 0 : i32
    %447 = arith.extsi %446 : i32 to i64
    %448 = llvm.getelementptr %arg6[%447] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %362, %448 : i64, !llvm.ptr
    %450 = arith.constant 8 : i32
    %452 = arith.extsi %450 : i32 to i64
    %451 = arith.muli %362, %452 : i64
    %449 = func.call @malloc(%451) : (i64) -> !llvm.ptr
    %453 = arith.constant 0 : i32
    %454 = arith.extsi %453 : i32 to i64
    llvm.store %454, %385 : i64, !llvm.ptr
    cf.br ^bb87
    ^bb87:
    %455 = llvm.load %385 : !llvm.ptr -> i64
    %456 = arith.cmpi slt, %455, %362 : i64
    cf.cond_br %456, ^bb88, ^bb89
    ^bb88:
      %458 = llvm.load %385 : !llvm.ptr -> i64
      %459 = llvm.getelementptr %374[%458] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %457 = llvm.load %459 : !llvm.ptr -> i64
      %460 = llvm.load %385 : !llvm.ptr -> i64
      %461 = llvm.getelementptr %449[%460] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %457, %461 : i64, !llvm.ptr
      %462 = llvm.load %385 : !llvm.ptr -> i64
      %463 = arith.constant 1 : i32
      %465 = arith.extsi %463 : i32 to i64
      %464 = arith.addi %462, %465 : i64
      llvm.store %464, %385 : i64, !llvm.ptr
      cf.br ^bb87
    ^bb89:
    func.call @free(%374) : (!llvm.ptr) -> ()
    func.call @free(%378) : (!llvm.ptr) -> ()
    func.return %449 : !llvm.ptr
  }
  func.func @crt3(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %468 = llvm.mlir.addressof @g_inv_p1_mod_p2 : !llvm.ptr
    %469 = llvm.load %468 : !llvm.ptr -> i64
    %470 = arith.constant 0 : i32
    %472 = arith.extsi %470 : i32 to i64
    %471 = arith.cmpi slt, %469, %472 : i64
    cf.cond_br %471, ^bb90, ^bb91
    ^bb90:
      %474 = llvm.mlir.addressof @P1 : !llvm.ptr
      %475 = llvm.load %474 : !llvm.ptr -> i64
      %476 = llvm.mlir.addressof @P2 : !llvm.ptr
      %477 = llvm.load %476 : !llvm.ptr -> i64
      %478 = arith.remsi %475, %477 : i64
      %479 = llvm.mlir.addressof @P2 : !llvm.ptr
      %480 = llvm.load %479 : !llvm.ptr -> i64
      %473 = func.call @mod_inv(%478, %480) : (i64, i64) -> i64
      %481 = llvm.mlir.addressof @g_inv_p1_mod_p2 : !llvm.ptr
      llvm.store %473, %481 : i64, !llvm.ptr
      %482 = llvm.mlir.addressof @P1 : !llvm.ptr
      %483 = llvm.load %482 : !llvm.ptr -> i64
      %484 = arith.extsi %483 : i64 to i128
      %485 = llvm.mlir.addressof @P2 : !llvm.ptr
      %486 = llvm.load %485 : !llvm.ptr -> i64
      %487 = arith.extsi %486 : i64 to i128
      %489 = arith.trunci %484 : i128 to i64
      %490 = arith.trunci %487 : i128 to i64
      %488 = arith.muli %489, %490 : i64
      %491 = arith.extsi %488 : i64 to i128
      %492 = llvm.mlir.addressof @g_P12 : !llvm.ptr
      llvm.store %491, %492 : i128, !llvm.ptr
      %494 = llvm.mlir.addressof @g_P12 : !llvm.ptr
      %495 = llvm.load %494 : !llvm.ptr -> i128
      %496 = llvm.mlir.addressof @P3 : !llvm.ptr
      %497 = llvm.load %496 : !llvm.ptr -> i64
      %498 = arith.extsi %497 : i64 to i128
      %500 = arith.trunci %495 : i128 to i64
      %501 = arith.trunci %498 : i128 to i64
      %499 = arith.remsi %500, %501 : i64
      %502 = llvm.mlir.addressof @P3 : !llvm.ptr
      %503 = llvm.load %502 : !llvm.ptr -> i64
      %493 = func.call @mod_inv(%499, %503) : (i64, i64) -> i64
      %504 = llvm.mlir.addressof @g_inv_p12_mod_p3 : !llvm.ptr
      llvm.store %493, %504 : i64, !llvm.ptr
      cf.br ^bb92
    ^bb91:
      cf.br ^bb92
    ^bb92:
    %505 = arith.subi %arg1, %arg0 : i64
    %506 = llvm.mlir.addressof @P2 : !llvm.ptr
    %507 = llvm.load %506 : !llvm.ptr -> i64
    %508 = arith.remsi %505, %507 : i64
    %509 = llvm.mlir.constant(1 : i64) : i64
    %510 = llvm.alloca %509 x i64 : (i64) -> !llvm.ptr
    llvm.store %508, %510 : i64, !llvm.ptr
    %511 = llvm.load %510 : !llvm.ptr -> i64
    %512 = arith.constant 0 : i32
    %514 = arith.extsi %512 : i32 to i64
    %513 = arith.cmpi slt, %511, %514 : i64
    cf.cond_br %513, ^bb93, ^bb94
    ^bb93:
      %515 = llvm.load %510 : !llvm.ptr -> i64
      %516 = llvm.mlir.addressof @P2 : !llvm.ptr
      %517 = llvm.load %516 : !llvm.ptr -> i64
      %518 = arith.addi %515, %517 : i64
      llvm.store %518, %510 : i64, !llvm.ptr
      cf.br ^bb95
    ^bb94:
      cf.br ^bb95
    ^bb95:
    %519 = llvm.load %510 : !llvm.ptr -> i64
    %520 = arith.extsi %519 : i64 to i128
    %521 = llvm.mlir.addressof @g_inv_p1_mod_p2 : !llvm.ptr
    %522 = llvm.load %521 : !llvm.ptr -> i64
    %523 = arith.extsi %522 : i64 to i128
    %525 = arith.trunci %520 : i128 to i64
    %526 = arith.trunci %523 : i128 to i64
    %524 = arith.muli %525, %526 : i64
    %527 = llvm.mlir.addressof @P2 : !llvm.ptr
    %528 = llvm.load %527 : !llvm.ptr -> i64
    %529 = arith.extsi %528 : i64 to i128
    %531 = arith.trunci %529 : i128 to i64
    %530 = arith.remsi %524, %531 : i64
    llvm.store %530, %510 : i64, !llvm.ptr
    %532 = arith.extsi %arg0 : i64 to i128
    %533 = llvm.mlir.addressof @P1 : !llvm.ptr
    %534 = llvm.load %533 : !llvm.ptr -> i64
    %535 = arith.extsi %534 : i64 to i128
    %536 = llvm.load %510 : !llvm.ptr -> i64
    %537 = arith.extsi %536 : i64 to i128
    %539 = arith.trunci %535 : i128 to i64
    %540 = arith.trunci %537 : i128 to i64
    %538 = arith.muli %539, %540 : i64
    %542 = arith.trunci %532 : i128 to i64
    %541 = arith.addi %542, %538 : i64
    %543 = arith.extsi %541 : i64 to i128
    %544 = llvm.mlir.addressof @P3 : !llvm.ptr
    %545 = llvm.load %544 : !llvm.ptr -> i64
    %546 = arith.extsi %545 : i64 to i128
    %548 = arith.trunci %543 : i128 to i64
    %549 = arith.trunci %546 : i128 to i64
    %547 = arith.remsi %548, %549 : i64
    %550 = arith.subi %arg2, %547 : i64
    %551 = llvm.mlir.addressof @P3 : !llvm.ptr
    %552 = llvm.load %551 : !llvm.ptr -> i64
    %553 = arith.remsi %550, %552 : i64
    %554 = llvm.mlir.constant(1 : i64) : i64
    %555 = llvm.alloca %554 x i64 : (i64) -> !llvm.ptr
    llvm.store %553, %555 : i64, !llvm.ptr
    %556 = llvm.load %555 : !llvm.ptr -> i64
    %557 = arith.constant 0 : i32
    %559 = arith.extsi %557 : i32 to i64
    %558 = arith.cmpi slt, %556, %559 : i64
    cf.cond_br %558, ^bb96, ^bb97
    ^bb96:
      %560 = llvm.load %555 : !llvm.ptr -> i64
      %561 = llvm.mlir.addressof @P3 : !llvm.ptr
      %562 = llvm.load %561 : !llvm.ptr -> i64
      %563 = arith.addi %560, %562 : i64
      llvm.store %563, %555 : i64, !llvm.ptr
      cf.br ^bb98
    ^bb97:
      cf.br ^bb98
    ^bb98:
    %564 = llvm.load %555 : !llvm.ptr -> i64
    %565 = arith.extsi %564 : i64 to i128
    %566 = llvm.mlir.addressof @g_inv_p12_mod_p3 : !llvm.ptr
    %567 = llvm.load %566 : !llvm.ptr -> i64
    %568 = arith.extsi %567 : i64 to i128
    %570 = arith.trunci %565 : i128 to i64
    %571 = arith.trunci %568 : i128 to i64
    %569 = arith.muli %570, %571 : i64
    %572 = llvm.mlir.addressof @P3 : !llvm.ptr
    %573 = llvm.load %572 : !llvm.ptr -> i64
    %574 = arith.extsi %573 : i64 to i128
    %576 = arith.trunci %574 : i128 to i64
    %575 = arith.remsi %569, %576 : i64
    llvm.store %575, %555 : i64, !llvm.ptr
    %577 = llvm.mlir.addressof @g_P12 : !llvm.ptr
    %578 = llvm.load %577 : !llvm.ptr -> i128
    %579 = llvm.load %555 : !llvm.ptr -> i64
    %580 = arith.extsi %579 : i64 to i128
    %582 = arith.trunci %578 : i128 to i64
    %583 = arith.trunci %580 : i128 to i64
    %581 = arith.muli %582, %583 : i64
    %585 = arith.trunci %543 : i128 to i64
    %584 = arith.addi %585, %581 : i64
    %586 = arith.extsi %584 : i64 to i128
    %587 = llvm.mlir.addressof @MOD : !llvm.ptr
    %588 = llvm.load %587 : !llvm.ptr -> i64
    %589 = arith.extsi %588 : i64 to i128
    %591 = arith.trunci %586 : i128 to i64
    %592 = arith.trunci %589 : i128 to i64
    %590 = arith.remsi %591, %592 : i64
    %593 = llvm.mlir.constant(1 : i64) : i64
    %594 = llvm.alloca %593 x i64 : (i64) -> !llvm.ptr
    llvm.store %590, %594 : i64, !llvm.ptr
    %595 = llvm.load %594 : !llvm.ptr -> i64
    %596 = arith.constant 0 : i32
    %598 = arith.extsi %596 : i32 to i64
    %597 = arith.cmpi slt, %595, %598 : i64
    cf.cond_br %597, ^bb99, ^bb100
    ^bb99:
      %599 = llvm.load %594 : !llvm.ptr -> i64
      %600 = llvm.mlir.addressof @MOD : !llvm.ptr
      %601 = llvm.load %600 : !llvm.ptr -> i64
      %602 = arith.addi %599, %601 : i64
      llvm.store %602, %594 : i64, !llvm.ptr
      cf.br ^bb101
    ^bb100:
      cf.br ^bb101
    ^bb101:
    %603 = llvm.load %594 : !llvm.ptr -> i64
    func.return %603 : i64
  }
  func.func @convolve_mod(%arg0: !llvm.ptr, %arg1: i64, %arg2: !llvm.ptr, %arg3: i64, %arg4: !llvm.ptr) -> !llvm.ptr {
    %604 = arith.constant 0 : i32
    %606 = arith.extsi %604 : i32 to i64
    %605 = arith.cmpi eq, %arg1, %606 : i64
    %607 = scf.if %605 -> (i1) {
      %608 = arith.constant true
      scf.yield %608 : i1
    } else {
      %609 = arith.constant 0 : i32
      %611 = arith.extsi %609 : i32 to i64
      %610 = arith.cmpi eq, %arg3, %611 : i64
      scf.yield %610 : i1
    }
    cf.cond_br %607, ^bb102, ^bb103
    ^bb102:
      %612 = arith.constant 0 : i32
      %613 = arith.constant 0 : i32
      %614 = arith.extsi %612 : i32 to i64
      %615 = arith.extsi %613 : i32 to i64
      %616 = llvm.getelementptr %arg4[%615] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %614, %616 : i64, !llvm.ptr
      %617 = llvm.mlir.zero : !llvm.ptr
      func.return %617 : !llvm.ptr
    ^bb103:
      cf.br ^bb104
    ^bb104:
    %619 = arith.constant 1 : i32
    %620 = arith.constant 8 : i32
    %621 = arith.extsi %619 : i32 to i64
    %622 = arith.extsi %620 : i32 to i64
    %618 = func.call @calloc(%621, %622) : (i64, i64) -> !llvm.ptr
    %624 = arith.constant 1 : i32
    %625 = arith.constant 8 : i32
    %626 = arith.extsi %624 : i32 to i64
    %627 = arith.extsi %625 : i32 to i64
    %623 = func.call @calloc(%626, %627) : (i64, i64) -> !llvm.ptr
    %629 = arith.constant 1 : i32
    %630 = arith.constant 8 : i32
    %631 = arith.extsi %629 : i32 to i64
    %632 = arith.extsi %630 : i32 to i64
    %628 = func.call @calloc(%631, %632) : (i64, i64) -> !llvm.ptr
    %634 = llvm.mlir.addressof @P1 : !llvm.ptr
    %635 = llvm.load %634 : !llvm.ptr -> i64
    %636 = arith.constant 3 : i32
    %637 = arith.extsi %636 : i32 to i64
    %633 = func.call @convolve_one(%arg0, %arg1, %arg2, %arg3, %635, %637, %618) : (!llvm.ptr, i64, !llvm.ptr, i64, i64, i64, !llvm.ptr) -> !llvm.ptr
    %639 = llvm.mlir.addressof @P2 : !llvm.ptr
    %640 = llvm.load %639 : !llvm.ptr -> i64
    %641 = arith.constant 3 : i32
    %642 = arith.extsi %641 : i32 to i64
    %638 = func.call @convolve_one(%arg0, %arg1, %arg2, %arg3, %640, %642, %623) : (!llvm.ptr, i64, !llvm.ptr, i64, i64, i64, !llvm.ptr) -> !llvm.ptr
    %644 = llvm.mlir.addressof @P3 : !llvm.ptr
    %645 = llvm.load %644 : !llvm.ptr -> i64
    %646 = arith.constant 3 : i32
    %647 = arith.extsi %646 : i32 to i64
    %643 = func.call @convolve_one(%arg0, %arg1, %arg2, %arg3, %645, %647, %628) : (!llvm.ptr, i64, !llvm.ptr, i64, i64, i64, !llvm.ptr) -> !llvm.ptr
    %648 = arith.addi %arg1, %arg3 : i64
    %649 = arith.constant 1 : i32
    %651 = arith.extsi %649 : i32 to i64
    %650 = arith.subi %648, %651 : i64
    %653 = arith.constant 8 : i32
    %655 = arith.extsi %653 : i32 to i64
    %654 = arith.muli %650, %655 : i64
    %652 = func.call @malloc(%654) : (i64) -> !llvm.ptr
    %656 = arith.constant 0 : i32
    %657 = arith.extsi %656 : i32 to i64
    %658 = llvm.mlir.constant(1 : i64) : i64
    %659 = llvm.alloca %658 x i64 : (i64) -> !llvm.ptr
    llvm.store %657, %659 : i64, !llvm.ptr
    cf.br ^bb105
    ^bb105:
    %660 = llvm.load %659 : !llvm.ptr -> i64
    %661 = arith.cmpi slt, %660, %650 : i64
    cf.cond_br %661, ^bb106, ^bb107
    ^bb106:
      %664 = llvm.load %659 : !llvm.ptr -> i64
      %665 = llvm.getelementptr %633[%664] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %663 = llvm.load %665 : !llvm.ptr -> i64
      %667 = llvm.load %659 : !llvm.ptr -> i64
      %668 = llvm.getelementptr %638[%667] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %666 = llvm.load %668 : !llvm.ptr -> i64
      %670 = llvm.load %659 : !llvm.ptr -> i64
      %671 = llvm.getelementptr %643[%670] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %669 = llvm.load %671 : !llvm.ptr -> i64
      %662 = func.call @crt3(%663, %666, %669) : (i64, i64, i64) -> i64
      %672 = llvm.load %659 : !llvm.ptr -> i64
      %673 = llvm.getelementptr %652[%672] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %662, %673 : i64, !llvm.ptr
      %674 = llvm.load %659 : !llvm.ptr -> i64
      %675 = arith.constant 1 : i32
      %677 = arith.extsi %675 : i32 to i64
      %676 = arith.addi %674, %677 : i64
      llvm.store %676, %659 : i64, !llvm.ptr
      cf.br ^bb105
    ^bb107:
    func.call @free(%633) : (!llvm.ptr) -> ()
    func.call @free(%638) : (!llvm.ptr) -> ()
    func.call @free(%643) : (!llvm.ptr) -> ()
    func.call @free(%618) : (!llvm.ptr) -> ()
    func.call @free(%623) : (!llvm.ptr) -> ()
    func.call @free(%628) : (!llvm.ptr) -> ()
    %684 = arith.constant 0 : i32
    %685 = arith.extsi %684 : i32 to i64
    %686 = llvm.getelementptr %arg4[%685] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %650, %686 : i64, !llvm.ptr
    func.return %652 : !llvm.ptr
  }
  func.func @poly_mul_mod(%arg0: !llvm.ptr, %arg1: i64, %arg2: !llvm.ptr, %arg3: i64) -> !llvm.ptr {
    %687 = arith.muli %arg1, %arg3 : i64
    %688 = arith.constant 40000 : i32
    %690 = arith.extsi %688 : i32 to i64
    %689 = arith.cmpi sle, %687, %690 : i64
    %691 = scf.if %689 -> (i1) {
      %692 = arith.constant true
      scf.yield %692 : i1
    } else {
      %693 = arith.constant 40 : i32
      %695 = arith.extsi %693 : i32 to i64
      %694 = arith.cmpi slt, %arg1, %695 : i64
      scf.yield %694 : i1
    }
    %696 = scf.if %691 -> (i1) {
      %697 = arith.constant true
      scf.yield %697 : i1
    } else {
      %698 = arith.constant 40 : i32
      %700 = arith.extsi %698 : i32 to i64
      %699 = arith.cmpi slt, %arg3, %700 : i64
      scf.yield %699 : i1
    }
    cf.cond_br %696, ^bb108, ^bb109
    ^bb108:
      %702 = arith.addi %arg1, %arg3 : i64
      %703 = arith.constant 1 : i32
      %705 = arith.extsi %703 : i32 to i64
      %704 = arith.subi %702, %705 : i64
      %706 = arith.constant 8 : i32
      %707 = arith.extsi %706 : i32 to i64
      %701 = func.call @calloc(%704, %707) : (i64, i64) -> !llvm.ptr
      %708 = arith.constant 0 : i32
      %709 = arith.extsi %708 : i32 to i64
      %710 = llvm.mlir.constant(1 : i64) : i64
      %711 = llvm.alloca %710 x i64 : (i64) -> !llvm.ptr
      llvm.store %709, %711 : i64, !llvm.ptr
      cf.br ^bb111
      ^bb111:
      %712 = llvm.load %711 : !llvm.ptr -> i64
      %713 = arith.cmpi slt, %712, %arg1 : i64
      cf.cond_br %713, ^bb112, ^bb113
      ^bb112:
        %715 = llvm.load %711 : !llvm.ptr -> i64
        %716 = llvm.getelementptr %arg0[%715] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %714 = llvm.load %716 : !llvm.ptr -> i64
        %717 = arith.constant 0 : i32
        %719 = arith.extsi %717 : i32 to i64
        %718 = arith.cmpi ne, %714, %719 : i64
        cf.cond_br %718, ^bb114, ^bb115
        ^bb114:
          %720 = arith.constant 0 : i32
          %721 = arith.extsi %720 : i32 to i64
          %722 = llvm.mlir.constant(1 : i64) : i64
          %723 = llvm.alloca %722 x i64 : (i64) -> !llvm.ptr
          llvm.store %721, %723 : i64, !llvm.ptr
          cf.br ^bb117
          ^bb117:
          %724 = llvm.load %723 : !llvm.ptr -> i64
          %725 = arith.cmpi slt, %724, %arg3 : i64
          cf.cond_br %725, ^bb118, ^bb119
          ^bb118:
            %727 = llvm.load %711 : !llvm.ptr -> i64
            %728 = llvm.load %723 : !llvm.ptr -> i64
            %729 = arith.addi %727, %728 : i64
            %730 = llvm.getelementptr %701[%729] : (!llvm.ptr, i64) -> !llvm.ptr, i64
            %726 = llvm.load %730 : !llvm.ptr -> i64
            %732 = llvm.load %711 : !llvm.ptr -> i64
            %733 = llvm.getelementptr %arg0[%732] : (!llvm.ptr, i64) -> !llvm.ptr, i64
            %731 = llvm.load %733 : !llvm.ptr -> i64
            %734 = arith.extsi %731 : i64 to i128
            %736 = llvm.load %723 : !llvm.ptr -> i64
            %737 = llvm.getelementptr %arg2[%736] : (!llvm.ptr, i64) -> !llvm.ptr, i64
            %735 = llvm.load %737 : !llvm.ptr -> i64
            %738 = arith.extsi %735 : i64 to i128
            %740 = arith.trunci %734 : i128 to i64
            %741 = arith.trunci %738 : i128 to i64
            %739 = arith.muli %740, %741 : i64
            %742 = llvm.mlir.addressof @MOD : !llvm.ptr
            %743 = llvm.load %742 : !llvm.ptr -> i64
            %744 = arith.extsi %743 : i64 to i128
            %746 = arith.trunci %744 : i128 to i64
            %745 = arith.remsi %739, %746 : i64
            %747 = arith.addi %726, %745 : i64
            %748 = llvm.mlir.addressof @MOD : !llvm.ptr
            %749 = llvm.load %748 : !llvm.ptr -> i64
            %750 = arith.remsi %747, %749 : i64
            %751 = llvm.load %711 : !llvm.ptr -> i64
            %752 = llvm.load %723 : !llvm.ptr -> i64
            %753 = arith.addi %751, %752 : i64
            %754 = llvm.getelementptr %701[%753] : (!llvm.ptr, i64) -> !llvm.ptr, i64
            llvm.store %750, %754 : i64, !llvm.ptr
            %755 = llvm.load %723 : !llvm.ptr -> i64
            %756 = arith.constant 1 : i32
            %758 = arith.extsi %756 : i32 to i64
            %757 = arith.addi %755, %758 : i64
            llvm.store %757, %723 : i64, !llvm.ptr
            cf.br ^bb117
          ^bb119:
          cf.br ^bb116
        ^bb115:
          cf.br ^bb116
        ^bb116:
        %759 = llvm.load %711 : !llvm.ptr -> i64
        %760 = arith.constant 1 : i32
        %762 = arith.extsi %760 : i32 to i64
        %761 = arith.addi %759, %762 : i64
        llvm.store %761, %711 : i64, !llvm.ptr
        cf.br ^bb111
      ^bb113:
      func.return %701 : !llvm.ptr
    ^bb109:
      cf.br ^bb110
    ^bb110:
    %764 = arith.constant 1 : i32
    %765 = arith.constant 8 : i32
    %766 = arith.extsi %764 : i32 to i64
    %767 = arith.extsi %765 : i32 to i64
    %763 = func.call @calloc(%766, %767) : (i64, i64) -> !llvm.ptr
    %768 = func.call @convolve_mod(%arg0, %arg1, %arg2, %arg3, %763) : (!llvm.ptr, i64, !llvm.ptr, i64, !llvm.ptr) -> !llvm.ptr
    func.call @free(%763) : (!llvm.ptr) -> ()
    func.return %768 : !llvm.ptr
  }
  func.func @poly_inv_mod(%arg0: !llvm.ptr, %arg1: i64) -> !llvm.ptr {
    %771 = arith.constant 8 : i32
    %772 = arith.extsi %771 : i32 to i64
    %770 = func.call @calloc(%arg1, %772) : (i64, i64) -> !llvm.ptr
    %773 = llvm.mlir.constant(1 : i64) : i64
    %774 = llvm.alloca %773 x !llvm.ptr : (i64) -> !llvm.ptr
    llvm.store %770, %774 : !llvm.ptr, !llvm.ptr
    %777 = arith.constant 0 : i32
    %778 = arith.extsi %777 : i32 to i64
    %779 = llvm.getelementptr %arg0[%778] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %776 = llvm.load %779 : !llvm.ptr -> i64
    %780 = llvm.mlir.addressof @MOD : !llvm.ptr
    %781 = llvm.load %780 : !llvm.ptr -> i64
    %775 = func.call @mod_inv(%776, %781) : (i64, i64) -> i64
    %782 = llvm.load %774 : !llvm.ptr -> !llvm.ptr
    %783 = arith.constant 0 : i32
    %784 = arith.extsi %783 : i32 to i64
    %785 = llvm.getelementptr %782[%784] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %775, %785 : i64, !llvm.ptr
    %786 = arith.constant 1 : i32
    %787 = arith.extsi %786 : i32 to i64
    %788 = llvm.mlir.constant(1 : i64) : i64
    %789 = llvm.alloca %788 x i64 : (i64) -> !llvm.ptr
    llvm.store %787, %789 : i64, !llvm.ptr
    cf.br ^bb120
    ^bb120:
    %790 = llvm.load %789 : !llvm.ptr -> i64
    %791 = arith.cmpi slt, %790, %arg1 : i64
    cf.cond_br %791, ^bb121, ^bb122
    ^bb121:
      %792 = llvm.load %789 : !llvm.ptr -> i64
      %793 = arith.constant 2 : i32
      %795 = arith.extsi %793 : i32 to i64
      %794 = arith.muli %792, %795 : i64
      %796 = llvm.mlir.constant(1 : i64) : i64
      %797 = llvm.alloca %796 x i64 : (i64) -> !llvm.ptr
      llvm.store %794, %797 : i64, !llvm.ptr
      %798 = llvm.load %797 : !llvm.ptr -> i64
      %799 = arith.cmpi sgt, %798, %arg1 : i64
      cf.cond_br %799, ^bb123, ^bb124
      ^bb123:
        llvm.store %arg1, %797 : i64, !llvm.ptr
        cf.br ^bb125
      ^bb124:
        cf.br ^bb125
      ^bb125:
      %801 = llvm.load %797 : !llvm.ptr -> i64
      %802 = llvm.load %774 : !llvm.ptr -> !llvm.ptr
      %803 = llvm.load %789 : !llvm.ptr -> i64
      %800 = func.call @poly_mul_mod(%arg0, %801, %802, %803) : (!llvm.ptr, i64, !llvm.ptr, i64) -> !llvm.ptr
      %805 = llvm.load %797 : !llvm.ptr -> i64
      %806 = arith.constant 8 : i32
      %807 = arith.extsi %806 : i32 to i64
      %804 = func.call @calloc(%805, %807) : (i64, i64) -> !llvm.ptr
      %808 = llvm.load %797 : !llvm.ptr -> i64
      %809 = llvm.load %789 : !llvm.ptr -> i64
      %810 = arith.addi %808, %809 : i64
      %811 = arith.constant 1 : i32
      %813 = arith.extsi %811 : i32 to i64
      %812 = arith.subi %810, %813 : i64
      %814 = arith.constant 0 : i32
      %815 = arith.extsi %814 : i32 to i64
      %816 = llvm.mlir.constant(1 : i64) : i64
      %817 = llvm.alloca %816 x i64 : (i64) -> !llvm.ptr
      llvm.store %815, %817 : i64, !llvm.ptr
      cf.br ^bb126
      ^bb126:
      %818 = llvm.load %817 : !llvm.ptr -> i64
      %819 = llvm.load %797 : !llvm.ptr -> i64
      %820 = arith.cmpi slt, %818, %819 : i64
      cf.cond_br %820, ^bb127, ^bb128
      ^bb127:
        %821 = llvm.load %817 : !llvm.ptr -> i64
        %822 = arith.cmpi slt, %821, %812 : i64
        %823 = scf.if %822 -> (i64) {
          %825 = llvm.load %817 : !llvm.ptr -> i64
          %826 = llvm.getelementptr %800[%825] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %824 = llvm.load %826 : !llvm.ptr -> i64
          scf.yield %824 : i64
        } else {
          %827 = arith.constant 0 : i32
          scf.yield %827 : i32
        }
        %828 = llvm.mlir.addressof @MOD : !llvm.ptr
        %829 = llvm.load %828 : !llvm.ptr -> i64
        %830 = arith.subi %829, %823 : i64
        %831 = llvm.mlir.addressof @MOD : !llvm.ptr
        %832 = llvm.load %831 : !llvm.ptr -> i64
        %833 = arith.remsi %830, %832 : i64
        %834 = llvm.load %817 : !llvm.ptr -> i64
        %835 = llvm.getelementptr %804[%834] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %833, %835 : i64, !llvm.ptr
        %836 = llvm.load %817 : !llvm.ptr -> i64
        %837 = arith.constant 1 : i32
        %839 = arith.extsi %837 : i32 to i64
        %838 = arith.addi %836, %839 : i64
        llvm.store %838, %817 : i64, !llvm.ptr
        cf.br ^bb126
      ^bb128:
      %841 = arith.constant 0 : i32
      %842 = arith.extsi %841 : i32 to i64
      %843 = llvm.getelementptr %804[%842] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %840 = llvm.load %843 : !llvm.ptr -> i64
      %844 = arith.constant 2 : i32
      %846 = arith.extsi %844 : i32 to i64
      %845 = arith.addi %840, %846 : i64
      %847 = llvm.mlir.addressof @MOD : !llvm.ptr
      %848 = llvm.load %847 : !llvm.ptr -> i64
      %849 = arith.remsi %845, %848 : i64
      %850 = arith.constant 0 : i32
      %851 = arith.extsi %850 : i32 to i64
      %852 = llvm.getelementptr %804[%851] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %849, %852 : i64, !llvm.ptr
      func.call @free(%800) : (!llvm.ptr) -> ()
      %855 = llvm.load %774 : !llvm.ptr -> !llvm.ptr
      %856 = llvm.load %789 : !llvm.ptr -> i64
      %857 = llvm.load %797 : !llvm.ptr -> i64
      %854 = func.call @poly_mul_mod(%855, %856, %804, %857) : (!llvm.ptr, i64, !llvm.ptr, i64) -> !llvm.ptr
      %859 = llvm.load %774 : !llvm.ptr -> !llvm.ptr
      func.call @free(%859) : (!llvm.ptr) -> ()
      func.call @free(%804) : (!llvm.ptr) -> ()
      %862 = llvm.load %797 : !llvm.ptr -> i64
      %863 = arith.constant 8 : i32
      %864 = arith.extsi %863 : i32 to i64
      %861 = func.call @calloc(%862, %864) : (i64, i64) -> !llvm.ptr
      %865 = llvm.load %789 : !llvm.ptr -> i64
      %866 = llvm.load %797 : !llvm.ptr -> i64
      %867 = arith.addi %865, %866 : i64
      %868 = arith.constant 1 : i32
      %870 = arith.extsi %868 : i32 to i64
      %869 = arith.subi %867, %870 : i64
      %871 = arith.constant 0 : i32
      %872 = arith.extsi %871 : i32 to i64
      llvm.store %872, %817 : i64, !llvm.ptr
      cf.br ^bb129
      ^bb129:
      %873 = llvm.load %817 : !llvm.ptr -> i64
      %874 = llvm.load %797 : !llvm.ptr -> i64
      %875 = arith.cmpi slt, %873, %874 : i64
      cf.cond_br %875, ^bb130, ^bb131
      ^bb130:
        %876 = llvm.load %817 : !llvm.ptr -> i64
        %877 = arith.cmpi slt, %876, %869 : i64
        %878 = scf.if %877 -> (i64) {
          %880 = llvm.load %817 : !llvm.ptr -> i64
          %881 = llvm.getelementptr %854[%880] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %879 = llvm.load %881 : !llvm.ptr -> i64
          scf.yield %879 : i64
        } else {
          %882 = arith.constant 0 : i32
          scf.yield %882 : i32
        }
        %883 = llvm.load %817 : !llvm.ptr -> i64
        %884 = llvm.getelementptr %861[%883] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %878, %884 : i64, !llvm.ptr
        %885 = llvm.load %817 : !llvm.ptr -> i64
        %886 = arith.constant 1 : i32
        %888 = arith.extsi %886 : i32 to i64
        %887 = arith.addi %885, %888 : i64
        llvm.store %887, %817 : i64, !llvm.ptr
        cf.br ^bb129
      ^bb131:
      func.call @free(%854) : (!llvm.ptr) -> ()
      llvm.store %861, %774 : !llvm.ptr, !llvm.ptr
      %890 = llvm.load %797 : !llvm.ptr -> i64
      llvm.store %890, %789 : i64, !llvm.ptr
      cf.br ^bb120
    ^bb122:
    %891 = llvm.load %774 : !llvm.ptr -> !llvm.ptr
    func.return %891 : !llvm.ptr
  }
  func.func @pre_fac_pow(%arg0: i64, %arg1: i64, %arg2: !llvm.ptr, %arg3: !llvm.ptr) -> () {
    %892 = arith.constant 1 : i32
    %893 = arith.constant 0 : i32
    %894 = arith.extsi %892 : i32 to i64
    %895 = arith.extsi %893 : i32 to i64
    %896 = llvm.getelementptr %arg2[%895] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %894, %896 : i64, !llvm.ptr
    %897 = arith.constant 1 : i32
    %898 = arith.extsi %897 : i32 to i64
    %899 = llvm.mlir.constant(1 : i64) : i64
    %900 = llvm.alloca %899 x i64 : (i64) -> !llvm.ptr
    llvm.store %898, %900 : i64, !llvm.ptr
    cf.br ^bb132
    ^bb132:
    %901 = llvm.load %900 : !llvm.ptr -> i64
    %902 = arith.cmpi sle, %901, %arg0 : i64
    cf.cond_br %902, ^bb133, ^bb134
    ^bb133:
      %904 = llvm.load %900 : !llvm.ptr -> i64
      %905 = llvm.mlir.addressof @MOD : !llvm.ptr
      %906 = llvm.load %905 : !llvm.ptr -> i64
      %903 = func.call @mod_pow(%904, %arg1, %906) : (i64, i64, i64) -> i64
      %908 = llvm.load %900 : !llvm.ptr -> i64
      %909 = arith.constant 1 : i32
      %911 = arith.extsi %909 : i32 to i64
      %910 = arith.subi %908, %911 : i64
      %912 = llvm.getelementptr %arg2[%910] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %907 = llvm.load %912 : !llvm.ptr -> i64
      %913 = arith.extsi %907 : i64 to i128
      %914 = arith.extsi %903 : i64 to i128
      %916 = arith.trunci %913 : i128 to i64
      %917 = arith.trunci %914 : i128 to i64
      %915 = arith.muli %916, %917 : i64
      %918 = llvm.mlir.addressof @MOD : !llvm.ptr
      %919 = llvm.load %918 : !llvm.ptr -> i64
      %920 = arith.extsi %919 : i64 to i128
      %922 = arith.trunci %920 : i128 to i64
      %921 = arith.remsi %915, %922 : i64
      %923 = llvm.load %900 : !llvm.ptr -> i64
      %924 = llvm.getelementptr %arg2[%923] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %921, %924 : i64, !llvm.ptr
      %925 = llvm.load %900 : !llvm.ptr -> i64
      %926 = arith.constant 1 : i32
      %928 = arith.extsi %926 : i32 to i64
      %927 = arith.addi %925, %928 : i64
      llvm.store %927, %900 : i64, !llvm.ptr
      cf.br ^bb132
    ^bb134:
    %931 = llvm.getelementptr %arg2[%arg0] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %930 = llvm.load %931 : !llvm.ptr -> i64
    %932 = llvm.mlir.addressof @MOD : !llvm.ptr
    %933 = llvm.load %932 : !llvm.ptr -> i64
    %929 = func.call @mod_inv(%930, %933) : (i64, i64) -> i64
    %934 = llvm.getelementptr %arg3[%arg0] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %929, %934 : i64, !llvm.ptr
    %935 = arith.constant 1 : i32
    %937 = arith.extsi %935 : i32 to i64
    %936 = arith.subi %arg0, %937 : i64
    llvm.store %936, %900 : i64, !llvm.ptr
    cf.br ^bb135
    ^bb135:
    %938 = llvm.load %900 : !llvm.ptr -> i64
    %939 = arith.constant 0 : i32
    %941 = arith.extsi %939 : i32 to i64
    %940 = arith.cmpi sge, %938, %941 : i64
    cf.cond_br %940, ^bb136, ^bb137
    ^bb136:
      %943 = llvm.load %900 : !llvm.ptr -> i64
      %944 = arith.constant 1 : i32
      %946 = arith.extsi %944 : i32 to i64
      %945 = arith.addi %943, %946 : i64
      %947 = llvm.mlir.addressof @MOD : !llvm.ptr
      %948 = llvm.load %947 : !llvm.ptr -> i64
      %942 = func.call @mod_pow(%945, %arg1, %948) : (i64, i64, i64) -> i64
      %950 = llvm.load %900 : !llvm.ptr -> i64
      %951 = arith.constant 1 : i32
      %953 = arith.extsi %951 : i32 to i64
      %952 = arith.addi %950, %953 : i64
      %954 = llvm.getelementptr %arg3[%952] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %949 = llvm.load %954 : !llvm.ptr -> i64
      %955 = arith.extsi %949 : i64 to i128
      %956 = arith.extsi %942 : i64 to i128
      %958 = arith.trunci %955 : i128 to i64
      %959 = arith.trunci %956 : i128 to i64
      %957 = arith.muli %958, %959 : i64
      %960 = llvm.mlir.addressof @MOD : !llvm.ptr
      %961 = llvm.load %960 : !llvm.ptr -> i64
      %962 = arith.extsi %961 : i64 to i128
      %964 = arith.trunci %962 : i128 to i64
      %963 = arith.remsi %957, %964 : i64
      %965 = llvm.load %900 : !llvm.ptr -> i64
      %966 = llvm.getelementptr %arg3[%965] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %963, %966 : i64, !llvm.ptr
      %967 = llvm.load %900 : !llvm.ptr -> i64
      %968 = arith.constant 1 : i32
      %970 = arith.extsi %968 : i32 to i64
      %969 = arith.subi %967, %970 : i64
      llvm.store %969, %900 : i64, !llvm.ptr
      cf.br ^bb135
    ^bb137:
    func.return
  }
  func.func @P_via_dp(%arg0: i64, %arg1: i64, %arg2: !llvm.ptr, %arg3: !llvm.ptr) -> i64 {
    %971 = arith.divsi %arg1, %arg0 : i64
    %972 = arith.remsi %arg1, %arg0 : i64
    %973 = arith.constant 0 : i32
    %975 = arith.extsi %973 : i32 to i64
    %974 = arith.cmpi ne, %972, %975 : i64
    %976 = scf.if %974 -> (i32) {
      %977 = arith.constant 1 : i32
      scf.yield %977 : i32
    } else {
      %978 = arith.constant 0 : i32
      scf.yield %978 : i32
    }
    %980 = arith.extsi %976 : i32 to i64
    %979 = arith.addi %971, %980 : i64
    %982 = arith.constant 8 : i32
    %984 = arith.extsi %982 : i32 to i64
    %983 = arith.muli %979, %984 : i64
    %981 = func.call @malloc(%983) : (i64) -> !llvm.ptr
    %985 = arith.constant 0 : i32
    %986 = arith.extsi %985 : i32 to i64
    %987 = llvm.mlir.constant(1 : i64) : i64
    %988 = llvm.alloca %987 x i64 : (i64) -> !llvm.ptr
    llvm.store %986, %988 : i64, !llvm.ptr
    cf.br ^bb138
    ^bb138:
    %989 = llvm.load %988 : !llvm.ptr -> i64
    %990 = arith.cmpi slt, %989, %971 : i64
    cf.cond_br %990, ^bb139, ^bb140
    ^bb139:
      %991 = llvm.load %988 : !llvm.ptr -> i64
      %992 = llvm.getelementptr %981[%991] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %arg0, %992 : i64, !llvm.ptr
      %993 = llvm.load %988 : !llvm.ptr -> i64
      %994 = arith.constant 1 : i32
      %996 = arith.extsi %994 : i32 to i64
      %995 = arith.addi %993, %996 : i64
      llvm.store %995, %988 : i64, !llvm.ptr
      cf.br ^bb138
    ^bb140:
    %997 = arith.constant 0 : i32
    %999 = arith.extsi %997 : i32 to i64
    %998 = arith.cmpi ne, %972, %999 : i64
    cf.cond_br %998, ^bb141, ^bb142
    ^bb141:
      %1000 = llvm.getelementptr %981[%971] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %972, %1000 : i64, !llvm.ptr
      cf.br ^bb143
    ^bb142:
      cf.br ^bb143
    ^bb143:
    %1002 = arith.constant 1 : i32
    %1004 = arith.extsi %1002 : i32 to i64
    %1003 = arith.addi %979, %1004 : i64
    %1005 = arith.constant 8 : i32
    %1006 = arith.extsi %1005 : i32 to i64
    %1001 = func.call @calloc(%1003, %1006) : (i64, i64) -> !llvm.ptr
    %1008 = llvm.getelementptr %arg2[%arg1] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %1007 = llvm.load %1008 : !llvm.ptr -> i64
    %1009 = arith.constant 0 : i32
    %1010 = arith.extsi %1009 : i32 to i64
    %1011 = llvm.getelementptr %1001[%1010] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %1007, %1011 : i64, !llvm.ptr
    %1012 = arith.constant 1 : i32
    %1013 = arith.extsi %1012 : i32 to i64
    llvm.store %1013, %988 : i64, !llvm.ptr
    cf.br ^bb144
    ^bb144:
    %1014 = llvm.load %988 : !llvm.ptr -> i64
    %1015 = arith.cmpi sle, %1014, %979 : i64
    cf.cond_br %1015, ^bb145, ^bb146
    ^bb145:
      %1016 = arith.constant 0 : i32
      %1017 = arith.extsi %1016 : i32 to i64
      %1018 = llvm.mlir.constant(1 : i64) : i64
      %1019 = llvm.alloca %1018 x i64 : (i64) -> !llvm.ptr
      llvm.store %1017, %1019 : i64, !llvm.ptr
      %1020 = arith.constant 0 : i32
      %1021 = arith.extsi %1020 : i32 to i64
      %1022 = llvm.mlir.constant(1 : i64) : i64
      %1023 = llvm.alloca %1022 x i64 : (i64) -> !llvm.ptr
      llvm.store %1021, %1023 : i64, !llvm.ptr
      %1024 = llvm.load %988 : !llvm.ptr -> i64
      %1025 = arith.constant 1 : i32
      %1027 = arith.extsi %1025 : i32 to i64
      %1026 = arith.subi %1024, %1027 : i64
      %1028 = llvm.mlir.constant(1 : i64) : i64
      %1029 = llvm.alloca %1028 x i64 : (i64) -> !llvm.ptr
      llvm.store %1026, %1029 : i64, !llvm.ptr
      cf.br ^bb147
      ^bb147:
      %1030 = llvm.load %1029 : !llvm.ptr -> i64
      %1031 = arith.constant 0 : i32
      %1033 = arith.extsi %1031 : i32 to i64
      %1032 = arith.cmpi sge, %1030, %1033 : i64
      cf.cond_br %1032, ^bb148, ^bb149
      ^bb148:
        %1034 = llvm.load %1019 : !llvm.ptr -> i64
        %1036 = llvm.load %1029 : !llvm.ptr -> i64
        %1037 = llvm.getelementptr %981[%1036] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %1035 = llvm.load %1037 : !llvm.ptr -> i64
        %1038 = arith.addi %1034, %1035 : i64
        llvm.store %1038, %1019 : i64, !llvm.ptr
        %1040 = llvm.load %1029 : !llvm.ptr -> i64
        %1041 = llvm.getelementptr %1001[%1040] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %1039 = llvm.load %1041 : !llvm.ptr -> i64
        %1042 = arith.extsi %1039 : i64 to i128
        %1044 = llvm.load %1019 : !llvm.ptr -> i64
        %1045 = llvm.getelementptr %arg3[%1044] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %1043 = llvm.load %1045 : !llvm.ptr -> i64
        %1046 = arith.extsi %1043 : i64 to i128
        %1048 = arith.trunci %1042 : i128 to i64
        %1049 = arith.trunci %1046 : i128 to i64
        %1047 = arith.muli %1048, %1049 : i64
        %1050 = llvm.mlir.addressof @MOD : !llvm.ptr
        %1051 = llvm.load %1050 : !llvm.ptr -> i64
        %1052 = arith.extsi %1051 : i64 to i128
        %1054 = arith.trunci %1052 : i128 to i64
        %1053 = arith.remsi %1047, %1054 : i64
        %1055 = llvm.load %988 : !llvm.ptr -> i64
        %1056 = llvm.load %1029 : !llvm.ptr -> i64
        %1057 = arith.subi %1055, %1056 : i64
        %1058 = arith.constant 2 : i32
        %1060 = arith.extsi %1058 : i32 to i64
        %1059 = arith.remsi %1057, %1060 : i64
        %1061 = arith.constant 1 : i32
        %1063 = arith.extsi %1061 : i32 to i64
        %1062 = arith.cmpi eq, %1059, %1063 : i64
        cf.cond_br %1062, ^bb150, ^bb151
        ^bb150:
          %1064 = llvm.load %1023 : !llvm.ptr -> i64
          %1065 = arith.addi %1064, %1053 : i64
          llvm.store %1065, %1023 : i64, !llvm.ptr
          cf.br ^bb152
        ^bb151:
          %1066 = llvm.load %1023 : !llvm.ptr -> i64
          %1067 = arith.subi %1066, %1053 : i64
          llvm.store %1067, %1023 : i64, !llvm.ptr
          cf.br ^bb152
        ^bb152:
        %1068 = llvm.load %1029 : !llvm.ptr -> i64
        %1069 = arith.constant 1 : i32
        %1071 = arith.extsi %1069 : i32 to i64
        %1070 = arith.subi %1068, %1071 : i64
        llvm.store %1070, %1029 : i64, !llvm.ptr
        cf.br ^bb147
      ^bb149:
      %1072 = llvm.load %1023 : !llvm.ptr -> i64
      %1073 = llvm.mlir.addressof @MOD : !llvm.ptr
      %1074 = llvm.load %1073 : !llvm.ptr -> i64
      %1075 = arith.remsi %1072, %1074 : i64
      llvm.store %1075, %1023 : i64, !llvm.ptr
      %1076 = llvm.load %1023 : !llvm.ptr -> i64
      %1077 = arith.constant 0 : i32
      %1079 = arith.extsi %1077 : i32 to i64
      %1078 = arith.cmpi slt, %1076, %1079 : i64
      cf.cond_br %1078, ^bb153, ^bb154
      ^bb153:
        %1080 = llvm.load %1023 : !llvm.ptr -> i64
        %1081 = llvm.mlir.addressof @MOD : !llvm.ptr
        %1082 = llvm.load %1081 : !llvm.ptr -> i64
        %1083 = arith.addi %1080, %1082 : i64
        llvm.store %1083, %1023 : i64, !llvm.ptr
        cf.br ^bb155
      ^bb154:
        cf.br ^bb155
      ^bb155:
      %1084 = llvm.load %1023 : !llvm.ptr -> i64
      %1085 = llvm.load %988 : !llvm.ptr -> i64
      %1086 = llvm.getelementptr %1001[%1085] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %1084, %1086 : i64, !llvm.ptr
      %1087 = llvm.load %988 : !llvm.ptr -> i64
      %1088 = arith.constant 1 : i32
      %1090 = arith.extsi %1088 : i32 to i64
      %1089 = arith.addi %1087, %1090 : i64
      llvm.store %1089, %988 : i64, !llvm.ptr
      cf.br ^bb144
    ^bb146:
    %1092 = llvm.getelementptr %1001[%979] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %1091 = llvm.load %1092 : !llvm.ptr -> i64
    func.call @free(%981) : (!llvm.ptr) -> ()
    func.call @free(%1001) : (!llvm.ptr) -> ()
    func.return %1091 : i64
  }
  func.func @P_via_inverse(%arg0: i64, %arg1: i64, %arg2: !llvm.ptr, %arg3: !llvm.ptr) -> i64 {
    %1095 = arith.divsi %arg1, %arg0 : i64
    %1096 = arith.remsi %arg1, %arg0 : i64
    %1098 = arith.constant 1 : i32
    %1100 = arith.extsi %1098 : i32 to i64
    %1099 = arith.addi %1095, %1100 : i64
    %1101 = arith.constant 8 : i32
    %1102 = arith.extsi %1101 : i32 to i64
    %1097 = func.call @calloc(%1099, %1102) : (i64, i64) -> !llvm.ptr
    %1103 = arith.constant 1 : i32
    %1104 = arith.constant 0 : i32
    %1105 = arith.extsi %1103 : i32 to i64
    %1106 = arith.extsi %1104 : i32 to i64
    %1107 = llvm.getelementptr %1097[%1106] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %1105, %1107 : i64, !llvm.ptr
    %1108 = arith.constant 1 : i32
    %1109 = arith.extsi %1108 : i32 to i64
    %1110 = llvm.mlir.constant(1 : i64) : i64
    %1111 = llvm.alloca %1110 x i64 : (i64) -> !llvm.ptr
    llvm.store %1109, %1111 : i64, !llvm.ptr
    cf.br ^bb156
    ^bb156:
    %1112 = llvm.load %1111 : !llvm.ptr -> i64
    %1113 = arith.cmpi sle, %1112, %1095 : i64
    cf.cond_br %1113, ^bb157, ^bb158
    ^bb157:
      %1115 = llvm.load %1111 : !llvm.ptr -> i64
      %1116 = arith.muli %1115, %arg0 : i64
      %1117 = llvm.getelementptr %arg3[%1116] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %1114 = llvm.load %1117 : !llvm.ptr -> i64
      %1118 = llvm.mlir.constant(1 : i64) : i64
      %1119 = llvm.alloca %1118 x i64 : (i64) -> !llvm.ptr
      llvm.store %1114, %1119 : i64, !llvm.ptr
      %1120 = llvm.load %1111 : !llvm.ptr -> i64
      %1121 = arith.constant 2 : i32
      %1123 = arith.extsi %1121 : i32 to i64
      %1122 = arith.remsi %1120, %1123 : i64
      %1124 = arith.constant 1 : i32
      %1126 = arith.extsi %1124 : i32 to i64
      %1125 = arith.cmpi eq, %1122, %1126 : i64
      cf.cond_br %1125, ^bb159, ^bb160
      ^bb159:
        %1127 = llvm.mlir.addressof @MOD : !llvm.ptr
        %1128 = llvm.load %1127 : !llvm.ptr -> i64
        %1129 = llvm.load %1119 : !llvm.ptr -> i64
        %1130 = arith.subi %1128, %1129 : i64
        %1131 = llvm.mlir.addressof @MOD : !llvm.ptr
        %1132 = llvm.load %1131 : !llvm.ptr -> i64
        %1133 = arith.remsi %1130, %1132 : i64
        llvm.store %1133, %1119 : i64, !llvm.ptr
        cf.br ^bb161
      ^bb160:
        cf.br ^bb161
      ^bb161:
      %1134 = llvm.load %1119 : !llvm.ptr -> i64
      %1135 = llvm.load %1111 : !llvm.ptr -> i64
      %1136 = llvm.getelementptr %1097[%1135] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %1134, %1136 : i64, !llvm.ptr
      %1137 = llvm.load %1111 : !llvm.ptr -> i64
      %1138 = arith.constant 1 : i32
      %1140 = arith.extsi %1138 : i32 to i64
      %1139 = arith.addi %1137, %1140 : i64
      llvm.store %1139, %1111 : i64, !llvm.ptr
      cf.br ^bb156
    ^bb158:
    %1142 = arith.constant 1 : i32
    %1144 = arith.extsi %1142 : i32 to i64
    %1143 = arith.addi %1095, %1144 : i64
    %1141 = func.call @poly_inv_mod(%1097, %1143) : (!llvm.ptr, i64) -> !llvm.ptr
    %1146 = llvm.getelementptr %arg2[%arg1] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %1145 = llvm.load %1146 : !llvm.ptr -> i64
    %1148 = arith.constant 1 : i32
    %1150 = arith.extsi %1148 : i32 to i64
    %1149 = arith.addi %1095, %1150 : i64
    %1151 = arith.constant 8 : i32
    %1153 = arith.extsi %1151 : i32 to i64
    %1152 = arith.muli %1149, %1153 : i64
    %1147 = func.call @malloc(%1152) : (i64) -> !llvm.ptr
    %1154 = arith.constant 0 : i32
    %1155 = arith.extsi %1154 : i32 to i64
    %1156 = llvm.mlir.constant(1 : i64) : i64
    %1157 = llvm.alloca %1156 x i64 : (i64) -> !llvm.ptr
    llvm.store %1155, %1157 : i64, !llvm.ptr
    cf.br ^bb162
    ^bb162:
    %1158 = llvm.load %1157 : !llvm.ptr -> i64
    %1159 = arith.cmpi sle, %1158, %1095 : i64
    cf.cond_br %1159, ^bb163, ^bb164
    ^bb163:
      %1160 = arith.extsi %1145 : i64 to i128
      %1162 = llvm.load %1157 : !llvm.ptr -> i64
      %1163 = llvm.getelementptr %1141[%1162] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %1161 = llvm.load %1163 : !llvm.ptr -> i64
      %1164 = arith.extsi %1161 : i64 to i128
      %1166 = arith.trunci %1160 : i128 to i64
      %1167 = arith.trunci %1164 : i128 to i64
      %1165 = arith.muli %1166, %1167 : i64
      %1168 = llvm.mlir.addressof @MOD : !llvm.ptr
      %1169 = llvm.load %1168 : !llvm.ptr -> i64
      %1170 = arith.extsi %1169 : i64 to i128
      %1172 = arith.trunci %1170 : i128 to i64
      %1171 = arith.remsi %1165, %1172 : i64
      %1173 = llvm.load %1157 : !llvm.ptr -> i64
      %1174 = llvm.getelementptr %1147[%1173] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %1171, %1174 : i64, !llvm.ptr
      %1175 = llvm.load %1157 : !llvm.ptr -> i64
      %1176 = arith.constant 1 : i32
      %1178 = arith.extsi %1176 : i32 to i64
      %1177 = arith.addi %1175, %1178 : i64
      llvm.store %1177, %1157 : i64, !llvm.ptr
      cf.br ^bb162
    ^bb164:
    %1179 = arith.constant 0 : i32
    %1181 = arith.extsi %1179 : i32 to i64
    %1180 = arith.cmpi eq, %1096, %1181 : i64
    cf.cond_br %1180, ^bb165, ^bb166
    ^bb165:
      %1183 = llvm.getelementptr %1147[%1095] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %1182 = llvm.load %1183 : !llvm.ptr -> i64
      func.call @free(%1097) : (!llvm.ptr) -> ()
      func.call @free(%1141) : (!llvm.ptr) -> ()
      func.call @free(%1147) : (!llvm.ptr) -> ()
      func.return %1182 : i64
    ^bb166:
      cf.br ^bb167
    ^bb167:
    %1187 = arith.constant 0 : i32
    %1188 = arith.extsi %1187 : i32 to i64
    %1189 = llvm.mlir.constant(1 : i64) : i64
    %1190 = llvm.alloca %1189 x i64 : (i64) -> !llvm.ptr
    llvm.store %1188, %1190 : i64, !llvm.ptr
    %1191 = arith.constant 0 : i32
    %1192 = arith.extsi %1191 : i32 to i64
    llvm.store %1192, %1157 : i64, !llvm.ptr
    cf.br ^bb168
    ^bb168:
    %1193 = llvm.load %1157 : !llvm.ptr -> i64
    %1194 = arith.cmpi sle, %1193, %1095 : i64
    cf.cond_br %1194, ^bb169, ^bb170
    ^bb169:
      %1195 = llvm.load %1157 : !llvm.ptr -> i64
      %1196 = arith.subi %1095, %1195 : i64
      %1197 = arith.muli %1196, %arg0 : i64
      %1198 = arith.addi %1197, %1096 : i64
      %1200 = llvm.load %1157 : !llvm.ptr -> i64
      %1201 = llvm.getelementptr %1147[%1200] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %1199 = llvm.load %1201 : !llvm.ptr -> i64
      %1202 = arith.extsi %1199 : i64 to i128
      %1204 = llvm.getelementptr %arg3[%1198] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %1203 = llvm.load %1204 : !llvm.ptr -> i64
      %1205 = arith.extsi %1203 : i64 to i128
      %1207 = arith.trunci %1202 : i128 to i64
      %1208 = arith.trunci %1205 : i128 to i64
      %1206 = arith.muli %1207, %1208 : i64
      %1209 = llvm.mlir.addressof @MOD : !llvm.ptr
      %1210 = llvm.load %1209 : !llvm.ptr -> i64
      %1211 = arith.extsi %1210 : i64 to i128
      %1213 = arith.trunci %1211 : i128 to i64
      %1212 = arith.remsi %1206, %1213 : i64
      %1214 = llvm.load %1157 : !llvm.ptr -> i64
      %1215 = arith.subi %1095, %1214 : i64
      %1216 = arith.constant 2 : i32
      %1218 = arith.extsi %1216 : i32 to i64
      %1217 = arith.remsi %1215, %1218 : i64
      %1219 = arith.constant 1 : i32
      %1221 = arith.extsi %1219 : i32 to i64
      %1220 = arith.cmpi eq, %1217, %1221 : i64
      cf.cond_br %1220, ^bb171, ^bb172
      ^bb171:
        %1222 = llvm.load %1190 : !llvm.ptr -> i64
        %1223 = arith.subi %1222, %1212 : i64
        llvm.store %1223, %1190 : i64, !llvm.ptr
        cf.br ^bb173
      ^bb172:
        %1224 = llvm.load %1190 : !llvm.ptr -> i64
        %1225 = arith.addi %1224, %1212 : i64
        llvm.store %1225, %1190 : i64, !llvm.ptr
        cf.br ^bb173
      ^bb173:
      %1226 = llvm.load %1157 : !llvm.ptr -> i64
      %1227 = arith.constant 1 : i32
      %1229 = arith.extsi %1227 : i32 to i64
      %1228 = arith.addi %1226, %1229 : i64
      llvm.store %1228, %1157 : i64, !llvm.ptr
      cf.br ^bb168
    ^bb170:
    %1230 = llvm.load %1190 : !llvm.ptr -> i64
    %1231 = llvm.mlir.addressof @MOD : !llvm.ptr
    %1232 = llvm.load %1231 : !llvm.ptr -> i64
    %1233 = arith.remsi %1230, %1232 : i64
    %1234 = llvm.mlir.constant(1 : i64) : i64
    %1235 = llvm.alloca %1234 x i64 : (i64) -> !llvm.ptr
    llvm.store %1233, %1235 : i64, !llvm.ptr
    %1236 = llvm.load %1235 : !llvm.ptr -> i64
    %1237 = arith.constant 0 : i32
    %1239 = arith.extsi %1237 : i32 to i64
    %1238 = arith.cmpi slt, %1236, %1239 : i64
    cf.cond_br %1238, ^bb174, ^bb175
    ^bb174:
      %1240 = llvm.load %1235 : !llvm.ptr -> i64
      %1241 = llvm.mlir.addressof @MOD : !llvm.ptr
      %1242 = llvm.load %1241 : !llvm.ptr -> i64
      %1243 = arith.addi %1240, %1242 : i64
      llvm.store %1243, %1235 : i64, !llvm.ptr
      cf.br ^bb176
    ^bb175:
      cf.br ^bb176
    ^bb176:
    func.call @free(%1097) : (!llvm.ptr) -> ()
    func.call @free(%1141) : (!llvm.ptr) -> ()
    func.call @free(%1147) : (!llvm.ptr) -> ()
    %1247 = llvm.load %1235 : !llvm.ptr -> i64
    func.return %1247 : i64
  }
  func.func @Qn(%arg0: i64) -> i64 {
    %1249 = arith.constant 1 : i32
    %1251 = arith.extsi %1249 : i32 to i64
    %1250 = arith.addi %arg0, %1251 : i64
    %1252 = arith.constant 8 : i32
    %1254 = arith.extsi %1252 : i32 to i64
    %1253 = arith.muli %1250, %1254 : i64
    %1248 = func.call @malloc(%1253) : (i64) -> !llvm.ptr
    %1256 = arith.constant 1 : i32
    %1258 = arith.extsi %1256 : i32 to i64
    %1257 = arith.addi %arg0, %1258 : i64
    %1259 = arith.constant 8 : i32
    %1261 = arith.extsi %1259 : i32 to i64
    %1260 = arith.muli %1257, %1261 : i64
    %1255 = func.call @malloc(%1260) : (i64) -> !llvm.ptr
    func.call @pre_fac_pow(%arg0, %arg0, %1248, %1255) : (i64, i64, !llvm.ptr, !llvm.ptr) -> ()
    %1263 = arith.constant 200 : i32
    %1265 = arith.extsi %1263 : i32 to i64
    %1264 = arith.divsi %arg0, %1265 : i64
    %1266 = arith.constant 0 : i32
    %1267 = arith.extsi %1266 : i32 to i64
    %1268 = llvm.mlir.constant(1 : i64) : i64
    %1269 = llvm.alloca %1268 x i64 : (i64) -> !llvm.ptr
    llvm.store %1267, %1269 : i64, !llvm.ptr
    %1270 = arith.constant 1 : i32
    %1271 = arith.extsi %1270 : i32 to i64
    %1272 = llvm.mlir.constant(1 : i64) : i64
    %1273 = llvm.alloca %1272 x i64 : (i64) -> !llvm.ptr
    llvm.store %1271, %1273 : i64, !llvm.ptr
    cf.br ^bb177
    ^bb177:
    %1274 = llvm.load %1273 : !llvm.ptr -> i64
    %1275 = arith.cmpi sle, %1274, %arg0 : i64
    cf.cond_br %1275, ^bb178, ^bb179
    ^bb178:
      %1276 = llvm.load %1273 : !llvm.ptr -> i64
      %1277 = arith.divsi %arg0, %1276 : i64
      %1278 = arith.constant 0 : i32
      %1279 = arith.extsi %1278 : i32 to i64
      %1280 = llvm.load %1273 : !llvm.ptr -> i64
      %1281 = arith.cmpi sle, %1280, %1264 : i64
      %1282 = scf.if %1281 -> (i1) {
        %1283 = arith.constant 200 : i32
        %1285 = arith.extsi %1283 : i32 to i64
        %1284 = arith.cmpi sgt, %1277, %1285 : i64
        scf.yield %1284 : i1
      } else {
        %1286 = arith.constant false
        scf.yield %1286 : i1
      }
      %1287 = scf.if %1282 -> (i64) {
        %1289 = llvm.load %1273 : !llvm.ptr -> i64
        %1288 = func.call @P_via_inverse(%1289, %arg0, %1248, %1255) : (i64, i64, !llvm.ptr, !llvm.ptr) -> i64
        scf.yield %1288 : i64
      } else {
        %1291 = llvm.load %1273 : !llvm.ptr -> i64
        %1290 = func.call @P_via_dp(%1291, %arg0, %1248, %1255) : (i64, i64, !llvm.ptr, !llvm.ptr) -> i64
        scf.yield %1290 : i64
      }
      %1292 = llvm.load %1269 : !llvm.ptr -> i64
      %1293 = arith.addi %1292, %1287 : i64
      llvm.store %1293, %1269 : i64, !llvm.ptr
      %1294 = llvm.load %1269 : !llvm.ptr -> i64
      %1295 = llvm.mlir.addressof @MOD : !llvm.ptr
      %1296 = llvm.load %1295 : !llvm.ptr -> i64
      %1297 = arith.cmpi sge, %1294, %1296 : i64
      cf.cond_br %1297, ^bb180, ^bb181
      ^bb180:
        %1298 = llvm.load %1269 : !llvm.ptr -> i64
        %1299 = llvm.mlir.addressof @MOD : !llvm.ptr
        %1300 = llvm.load %1299 : !llvm.ptr -> i64
        %1301 = arith.subi %1298, %1300 : i64
        llvm.store %1301, %1269 : i64, !llvm.ptr
        cf.br ^bb182
      ^bb181:
        cf.br ^bb182
      ^bb182:
      %1302 = llvm.load %1273 : !llvm.ptr -> i64
      %1303 = arith.constant 1 : i32
      %1305 = arith.extsi %1303 : i32 to i64
      %1304 = arith.addi %1302, %1305 : i64
      llvm.store %1304, %1273 : i64, !llvm.ptr
      cf.br ^bb177
    ^bb179:
    func.call @free(%1248) : (!llvm.ptr) -> ()
    func.call @free(%1255) : (!llvm.ptr) -> ()
    %1308 = llvm.load %1269 : !llvm.ptr -> i64
    func.return %1308 : i64
  }
  func.func @main() -> i32 {
    %1309 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %1311 = arith.constant 50000 : i32
    %1312 = arith.extsi %1311 : i32 to i64
    %1310 = func.call @Qn(%1312) : (i64) -> i64
    %1313 = llvm.call @printf(%1309, %1310) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    %1314 = arith.constant 0 : i32
    func.return %1314 : i32
  }
}