Problem 537

Counting Tuples — T(20000,20000) via NTT polynomial powering.

Answer779429131
Output779429131
StatusPASS
Native helperno
Runtime660 ms
Peak memory3008 KB
Time complexityO(n^3) (estimated)
Space complexityO(n^2) (estimated)

Performance comparison

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

Flow source

# Project Euler 537
# Counting Tuples — T(20000,20000) via NTT polynomial powering.

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

const MOD: i64 = 1004535809
const ROOT: i64 = 3

function modpow(base0: i64, exp0: i64, mod: i64) -> i64 {
    let mut r: i64 = 1
    let mut b: i64 = base0 % mod
    let mut e: i64 = exp0
    while e > 0 {
        if (e & 1) == 1 {
            let t: i128 = (r as i128) * (b as i128) % (mod as i128)
            r = t as i64
        }
        let t2: i128 = (b as i128) * (b as i128) % (mod as i128)
        b = t2 as i64
        e = e / 2
    }
    return r
}

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

function ntt(a: ptr<i64>, n: i64, invert: i32) -> 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 = modpow(ROOT, (MOD - 1) / length, MOD)
        let mut wl: i64 = wlen
        if invert == 1 { wl = modpow(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 = modpow(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 multiply(a: ptr<i64>, alen: i64, b: ptr<i64>, blen: i64, degree: i64,
                  out: ptr<i64>, out_len: ptr<i64>,
                  fa: ptr<i64>, fb: ptr<i64>) -> void {
    if alen == 1 {
        let factor: i64 = a[0]
        let mut lim: i64 = blen
        if lim > degree + 1 { lim = degree + 1 }
        let mut i: i64 = 0
        while i < lim {
            out[i] = ((factor as i128) * (b[i] as i128) % (MOD as i128)) as i64
            i = i + 1
        }
        out_len[0] = lim
        return
    }
    if blen == 1 {
        let factor2: i64 = b[0]
        let mut lim2: i64 = alen
        if lim2 > degree + 1 { lim2 = degree + 1 }
        let mut i2: i64 = 0
        while i2 < lim2 {
            out[i2] = ((factor2 as i128) * (a[i2] as i128) % (MOD as i128)) as i64
            i2 = i2 + 1
        }
        out_len[0] = lim2
        return
    }
    let mut result_len: i64 = alen + blen - 1
    if result_len > degree + 1 { result_len = degree + 1 }
    let full_len: i64 = alen + blen - 1
    let mut size: i64 = 1
    while size < full_len { size = size << 1 }
    let mut i: i64 = 0
    while i < size {
        fa[i] = 0
        fb[i] = 0
        i = i + 1
    }
    i = 0
    while i < alen { fa[i] = a[i]; i = i + 1 }
    i = 0
    while i < blen { fb[i] = b[i]; i = i + 1 }
    ntt(fa, size, 0)
    ntt(fb, size, 0)
    i = 0
    while i < size {
        fa[i] = ((fa[i] as i128) * (fb[i] as i128) % (MOD as i128)) as i64
        i = i + 1
    }
    ntt(fa, size, 1)
    i = 0
    while i < result_len {
        out[i] = fa[i]
        i = i + 1
    }
    out_len[0] = result_len
}

function main() -> i32 {
    let n: i64 = 20000
    let k0: i64 = 20000
    # sieve first n+1 primes
    let mut limit: i64 = 300000
    let sieve: ptr<i8> = calloc(limit + 1, 1)
    let primes: ptr<i32> = calloc(n + 5, 4)
    if sieve == null || primes == null { return 1 }
    let mut pn: i64 = 0
    while pn < n + 1 {
        let mut i: i64 = 0
        while i <= limit { sieve[i] = 1; i = i + 1 }
        sieve[0] = 0; sieve[1] = 0
        i = 2
        while i * i <= limit {
            if sieve[i] == 1 {
                let mut j: i64 = i * i
                while j <= limit { sieve[j] = 0; j = j + i }
            }
            i = i + 1
        }
        pn = 0
        i = 2
        while i <= limit && pn < n + 1 {
            if sieve[i] == 1 {
                primes[pn] = i as i32
                pn = pn + 1
            }
            i = i + 1
        }
        if pn < n + 1 { limit = limit * 2 }
    }
    let degree: i64 = n
    let max_size: i64 = 1
    while max_size < 2 * (degree + 1) { max_size = max_size << 1 }
    let base: ptr<i64> = calloc(degree + 2, 8)
    let result: ptr<i64> = calloc(degree + 2, 8)
    let tmp: ptr<i64> = calloc(degree + 2, 8)
    let fa: ptr<i64> = calloc(max_size, 8)
    let fb: ptr<i64> = calloc(max_size, 8)
    let olen: ptr<i64> = calloc(1, 8)
    if base == null || result == null || tmp == null || fa == null || fb == null || olen == null {
        return 1
    }
    base[0] = 1
    let mut r: i64 = 1
    while r <= n {
        base[r] = (primes[r] as i64) - (primes[r - 1] as i64)
        r = r + 1
    }
    let mut blen: i64 = n + 1
    result[0] = 1
    let mut rlen: i64 = 1
    let mut k: i64 = k0
    while k > 0 {
        if (k & 1) == 1 {
            multiply(result, rlen, base, blen, degree, tmp, olen, fa, fb)
            rlen = olen[0]
            let mut i: i64 = 0
            while i < rlen { result[i] = tmp[i]; i = i + 1 }
        }
        k = k >> 1
        if k > 0 {
            multiply(base, blen, base, blen, degree, tmp, olen, fa, fb)
            blen = olen[0]
            let mut i2: i64 = 0
            while i2 < blen { base[i2] = tmp[i2]; i2 = i2 + 1 }
        }
    }
    let ans: i64 = 0
    if n < rlen { ans = result[n] }
    printf("%lld\n", ans)
    free(sieve); free(primes); free(base); free(result); free(tmp); free(fa); free(fb); free(olen)
    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 modpow_i64_i64_i64(int64_t base0, int64_t exp0, int64_t mod);
int64_t isqrt_i64(int64_t n);
void ntt_ptr_i64_i64_i32(int64_t* a, int64_t n, int32_t invert);
void multiply_ptr_i64_i64_ptr_i64_i64_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i64(int64_t* a, int64_t alen, int64_t* b, int64_t blen, int64_t degree, int64_t* out, int64_t* out_len, int64_t* fa, int64_t* fb);
int32_t main(void);

static const int64_t MOD = 1004535809;
static const int64_t ROOT = 3;



int64_t modpow_i64_i64_i64(int64_t base0, int64_t exp0, int64_t mod) {
    int64_t r = 1;
    int64_t b = FLOW_CHECKED_MOD((base0), (mod));
    int64_t e = exp0;
    while (e > 0) {
        if ((e & 1) == 1) {
            __int128 t = FLOW_CHECKED_MOD(((((__int128)(r)) * ((__int128)(b)))), (((__int128)(mod))));
            r = ((int64_t)(t));
        }
        __int128 t2 = FLOW_CHECKED_MOD(((((__int128)(b)) * ((__int128)(b)))), (((__int128)(mod))));
        b = ((int64_t)(t2));
        e = FLOW_CHECKED_DIV((e), (2));
    }
    return r;
}

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;
}

void ntt_ptr_i64_i64_i32(int64_t* a, int64_t n, int32_t invert) {
    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 = modpow_i64_i64_i64(ROOT, FLOW_CHECKED_DIV(((MOD - 1)), (length)), MOD);
        int64_t wl = wlen;
        if (invert == 1) {
            wl = modpow_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 = modpow_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);
        }
    }
}

void multiply_ptr_i64_i64_ptr_i64_i64_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i64(int64_t* a, int64_t alen, int64_t* b, int64_t blen, int64_t degree, int64_t* out, int64_t* out_len, int64_t* fa, int64_t* fb) {
    if (alen == 1) {
        int64_t factor = a[0];
        int64_t lim = blen;
        if (lim > (degree + 1)) {
            lim = (degree + 1);
        }
        int64_t i = 0;
        while (i < lim) {
            out[i] = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(factor)) * ((__int128)(b[i])))), (((__int128)(MOD))))));
            i = (i + 1);
        }
        out_len[0] = lim;
        return;
    }
    if (blen == 1) {
        int64_t factor2 = b[0];
        int64_t lim2 = alen;
        if (lim2 > (degree + 1)) {
            lim2 = (degree + 1);
        }
        int64_t i2 = 0;
        while (i2 < lim2) {
            out[i2] = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(factor2)) * ((__int128)(a[i2])))), (((__int128)(MOD))))));
            i2 = (i2 + 1);
        }
        out_len[0] = lim2;
        return;
    }
    int64_t result_len = ((alen + blen) - 1);
    if (result_len > (degree + 1)) {
        result_len = (degree + 1);
    }
    int64_t full_len = ((alen + blen) - 1);
    int64_t size = 1;
    while (size < full_len) {
        size = FLOW_CHECKED_SHL((size), (1));
    }
    int64_t i = 0;
    while (i < size) {
        fa[i] = 0;
        fb[i] = 0;
        i = (i + 1);
    }
    i = 0;
    while (i < alen) {
        fa[i] = a[i];
        i = (i + 1);
    }
    i = 0;
    while (i < blen) {
        fb[i] = b[i];
        i = (i + 1);
    }
    ntt_ptr_i64_i64_i32(fa, size, 0);
    ntt_ptr_i64_i64_i32(fb, size, 0);
    i = 0;
    while (i < size) {
        fa[i] = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(fa[i])) * ((__int128)(fb[i])))), (((__int128)(MOD))))));
        i = (i + 1);
    }
    ntt_ptr_i64_i64_i32(fa, size, 1);
    i = 0;
    while (i < result_len) {
        out[i] = fa[i];
        i = (i + 1);
    }
    out_len[0] = result_len;
}

int32_t main(void) {
    int64_t n = 20000;
    int64_t k0 = 20000;
    int64_t limit = 300000;
    int8_t* sieve = (int8_t*)(calloc((limit + 1), 1));
    int32_t* primes = (int32_t*)(calloc((n + 5), 4));
    if ((sieve == NULL || primes == NULL)) {
        return 1;
    }
    int64_t pn = 0;
    while (pn < (n + 1)) {
        int64_t i = 0;
        while (i <= limit) {
            sieve[i] = 1;
            i = (i + 1);
        }
        sieve[0] = 0;
        sieve[1] = 0;
        i = 2;
        while ((i * i) <= limit) {
            if (sieve[i] == 1) {
                int64_t j = (i * i);
                while (j <= limit) {
                    sieve[j] = 0;
                    j = (j + i);
                }
            }
            i = (i + 1);
        }
        pn = 0;
        i = 2;
        while ((i <= limit && pn < (n + 1))) {
            if (sieve[i] == 1) {
                primes[pn] = ((int32_t)(i));
                pn = (pn + 1);
            }
            i = (i + 1);
        }
        if (pn < (n + 1)) {
            limit = (limit * 2);
        }
    }
    int64_t degree = n;
    int64_t max_size = 1;
    while (max_size < (2 * (degree + 1))) {
        max_size = FLOW_CHECKED_SHL((max_size), (1));
    }
    int64_t* base = (int64_t*)(calloc((degree + 2), 8));
    int64_t* result = (int64_t*)(calloc((degree + 2), 8));
    int64_t* tmp = (int64_t*)(calloc((degree + 2), 8));
    int64_t* fa = (int64_t*)(calloc(max_size, 8));
    int64_t* fb = (int64_t*)(calloc(max_size, 8));
    int64_t* olen = (int64_t*)(calloc(1, 8));
    if ((((((base == NULL || result == NULL) || tmp == NULL) || fa == NULL) || fb == NULL) || olen == NULL)) {
        return 1;
    }
    base[0] = 1;
    int64_t r = 1;
    while (r <= n) {
        base[r] = (((int64_t)(primes[r])) - ((int64_t)(primes[(r - 1)])));
        r = (r + 1);
    }
    int64_t blen = (n + 1);
    result[0] = 1;
    int64_t rlen = 1;
    int64_t k = k0;
    while (k > 0) {
        if ((k & 1) == 1) {
            multiply_ptr_i64_i64_ptr_i64_i64_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i64(result, rlen, base, blen, degree, tmp, olen, fa, fb);
            rlen = olen[0];
            int64_t i = 0;
            while (i < rlen) {
                result[i] = tmp[i];
                i = (i + 1);
            }
        }
        k = FLOW_CHECKED_SHR((k), (1));
        if (k > 0) {
            multiply_ptr_i64_i64_ptr_i64_i64_i64_ptr_i64_ptr_i64_ptr_i64_ptr_i64(base, blen, base, blen, degree, tmp, olen, fa, fb);
            blen = olen[0];
            int64_t i2 = 0;
            while (i2 < blen) {
                base[i2] = tmp[i2];
                i2 = (i2 + 1);
            }
        }
    }
    int64_t ans = 0;
    if (n < rlen) {
        ans = result[n];
    }
    printf("%lld\n", ans);
    free(sieve);
    free(primes);
    free(base);
    free(result);
    free(tmp);
    free(fa);
    free(fb);
    free(olen);
    return 0;
}

Generated MLIR

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