Problem 408

Admissible paths (0,0)->(n,n) avoiding square-sum obstacles, mod 10^9+7.

Answer299742733
Output299742733
StatusPASS
Native helperno
Runtime2720 ms
Peak memory333472 KB
Time complexityO(n^3) (estimated)
Space complexityO(n^2) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^3)O(n log n)
Space complexityO(n^2)O(n)
ApproachFlow solutionModular DP or matrix exponentiation
VerdictSuboptimal

Flow source

# Project Euler 408
# Admissible paths (0,0)->(n,n) avoiding square-sum obstacles, mod 10^9+7.

import euler.nt { isqrt }

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

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 % 2 == 1 {
            r = ((r as i128) * (b as i128) % (mod as i128)) as i64
        }
        b = ((b as i128) * (b as i128) % (mod as i128)) as i64
        e = e / 2
    }
    return r
}

function main() -> i32 {
    let N: i64 = 10000000
    let MOD: i64 = 1000000007
    let m: i64 = isqrt(N)
    let max_sum: i64 = isqrt(2 * N)

    # Mark which numbers are perfect squares up to 2N
    let is_sq: ptr<i8> = calloc(2 * N + 1, 1)
    if is_sq == null { return 1 }
    let mut i: i64 = 1
    while i <= max_sum {
        is_sq[i * i] = 1
        i = i + 1
    }

    let xs: ptr<i64> = calloc(20000, 8)
    let ys: ptr<i64> = calloc(20000, 8)
    if xs == null || ys == null { return 1 }
    let mut k: i64 = 0
    let mut a: i64 = 1
    while a <= m {
        let a2: i64 = a * a
        let mut b: i64 = 1
        while b <= m {
            let b2: i64 = b * b
            if is_sq[a2 + b2] != 0 {
                xs[k] = a2
                ys[k] = b2
                k = k + 1
            }
            b = b + 1
        }
        a = a + 1
    }
    # sort by x+y, then x (shell sort)
    let mut gap: i64 = k / 2
    while gap > 0 {
        i = gap
        while i < k {
            let mut j: i64 = i
            while j >= gap {
                let s1: i64 = xs[j] + ys[j]
                let s0: i64 = xs[j - gap] + ys[j - gap]
                if s1 < s0 || (s1 == s0 && xs[j] < xs[j - gap]) {
                    let tx: i64 = xs[j]
                    xs[j] = xs[j - gap]
                    xs[j - gap] = tx
                    let ty: i64 = ys[j]
                    ys[j] = ys[j - gap]
                    ys[j - gap] = ty
                    j = j - gap
                } else {
                    break
                }
            }
            i = i + 1
        }
        gap = gap / 2
    }

    let limit: i64 = 2 * N
    let fact: ptr<i64> = calloc(limit + 1, 8)
    let invfact: ptr<i64> = calloc(limit + 1, 8)
    if fact == null || invfact == null { return 1 }
    fact[0] = 1
    i = 1
    while i <= limit {
        fact[i] = ((fact[i - 1] as i128) * (i as i128) % (MOD as i128)) as i64
        i = i + 1
    }
    invfact[limit] = modpow(fact[limit], MOD - 2, MOD)
    i = limit
    while i > 0 {
        invfact[i - 1] = ((invfact[i] as i128) * (i as i128) % (MOD as i128)) as i64
        i = i - 1
    }

    let ways: ptr<i64> = calloc(k, 8)
    if ways == null { return 1 }
    i = 0
    while i < k {
        let xi: i64 = xs[i]
        let yi: i64 = ys[i]
        let mut total: i64 = ((fact[xi + yi] as i128) * (invfact[xi] as i128) % (MOD as i128) * (invfact[yi] as i128) % (MOD as i128)) as i64
        let mut j: i64 = 0
        while j < i {
            let xj: i64 = xs[j]
            let yj: i64 = ys[j]
            if xj <= xi && yj <= yi {
                let dx: i64 = xi - xj
                let dy: i64 = yi - yj
                let w: i64 = ((fact[dx + dy] as i128) * (invfact[dx] as i128) % (MOD as i128) * (invfact[dy] as i128) % (MOD as i128)) as i64
                total = (total - ((ways[j] as i128) * (w as i128) % (MOD as i128)) as i64) % MOD
            }
            j = j + 1
        }
        if total < 0 { total = total + MOD }
        ways[i] = total
        i = i + 1
    }

    let mut total_paths: i64 = ((fact[2 * N] as i128) * (invfact[N] as i128) % (MOD as i128) * (invfact[N] as i128) % (MOD as i128)) as i64
    i = 0
    while i < k {
        let xi: i64 = xs[i]
        let yi: i64 = ys[i]
        let w: i64 = ((fact[N - xi + N - yi] as i128) * (invfact[N - xi] as i128) % (MOD as i128) * (invfact[N - yi] as i128) % (MOD as i128)) as i64
        total_paths = (total_paths - ((ways[i] as i128) * (w as i128) % (MOD as i128)) as i64) % MOD
        i = i + 1
    }
    if total_paths < 0 { total_paths = total_paths + MOD }
    printf("%lld\n", total_paths)

    free(ways)
    free(invfact)
    free(fact)
    free(ys)
    free(xs)
    free(is_sq)
    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 modpow_i64_i64_i64(int64_t base0, int64_t exp0, int64_t mod);
int32_t main(void);

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 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 (FLOW_CHECKED_MOD((e), (2)) == 1) {
            r = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(r)) * ((__int128)(b)))), (((__int128)(mod))))));
        }
        b = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(b)) * ((__int128)(b)))), (((__int128)(mod))))));
        e = FLOW_CHECKED_DIV((e), (2));
    }
    return r;
}

int32_t main(void) {
    int64_t N = 10000000;
    int64_t MOD = 1000000007;
    int64_t m = isqrt_i64(N);
    int64_t max_sum = isqrt_i64((2 * N));
    int8_t* is_sq = (int8_t*)(calloc(((2 * N) + 1), 1));
    if (is_sq == NULL) {
        return 1;
    }
    int64_t i = 1;
    while (i <= max_sum) {
        is_sq[(i * i)] = 1;
        i = (i + 1);
    }
    int64_t* xs = (int64_t*)(calloc(20000, 8));
    int64_t* ys = (int64_t*)(calloc(20000, 8));
    if ((xs == NULL || ys == NULL)) {
        return 1;
    }
    int64_t k = 0;
    int64_t a = 1;
    while (a <= m) {
        int64_t a2 = (a * a);
        int64_t b = 1;
        while (b <= m) {
            int64_t b2 = (b * b);
            if (is_sq[(a2 + b2)] != 0) {
                xs[k] = a2;
                ys[k] = b2;
                k = (k + 1);
            }
            b = (b + 1);
        }
        a = (a + 1);
    }
    int64_t gap = FLOW_CHECKED_DIV((k), (2));
    while (gap > 0) {
        i = gap;
        while (i < k) {
            int64_t j = i;
            while (j >= gap) {
                int64_t s1 = (xs[j] + ys[j]);
                int64_t s0 = (xs[(j - gap)] + ys[(j - gap)]);
                if ((s1 < s0 || (s1 == s0 && xs[j] < xs[(j - gap)]))) {
                    int64_t tx = xs[j];
                    xs[j] = xs[(j - gap)];
                    xs[(j - gap)] = tx;
                    int64_t ty = ys[j];
                    ys[j] = ys[(j - gap)];
                    ys[(j - gap)] = ty;
                    j = (j - gap);
                } else {
                    break;
                }
            }
            i = (i + 1);
        }
        gap = FLOW_CHECKED_DIV((gap), (2));
    }
    int64_t limit = (2 * N);
    int64_t* fact = (int64_t*)(calloc((limit + 1), 8));
    int64_t* invfact = (int64_t*)(calloc((limit + 1), 8));
    if ((fact == NULL || invfact == NULL)) {
        return 1;
    }
    fact[0] = 1;
    i = 1;
    while (i <= limit) {
        fact[i] = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(fact[(i - 1)])) * ((__int128)(i)))), (((__int128)(MOD))))));
        i = (i + 1);
    }
    invfact[limit] = modpow_i64_i64_i64(fact[limit], (MOD - 2), MOD);
    i = limit;
    while (i > 0) {
        invfact[(i - 1)] = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(invfact[i])) * ((__int128)(i)))), (((__int128)(MOD))))));
        i = (i - 1);
    }
    int64_t* ways = (int64_t*)(calloc(k, 8));
    if (ways == NULL) {
        return 1;
    }
    i = 0;
    while (i < k) {
        int64_t xi = xs[i];
        int64_t yi = ys[i];
        int64_t total = ((int64_t)(FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD(((((__int128)(fact[(xi + yi)])) * ((__int128)(invfact[xi])))), (((__int128)(MOD)))) * ((__int128)(invfact[yi])))), (((__int128)(MOD))))));
        int64_t j = 0;
        while (j < i) {
            int64_t xj = xs[j];
            int64_t yj = ys[j];
            if ((xj <= xi && yj <= yi)) {
                int64_t dx = (xi - xj);
                int64_t dy = (yi - yj);
                int64_t w = ((int64_t)(FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD(((((__int128)(fact[(dx + dy)])) * ((__int128)(invfact[dx])))), (((__int128)(MOD)))) * ((__int128)(invfact[dy])))), (((__int128)(MOD))))));
                total = FLOW_CHECKED_MOD(((total - ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(ways[j])) * ((__int128)(w)))), (((__int128)(MOD)))))))), (MOD));
            }
            j = (j + 1);
        }
        if (total < 0) {
            total = (total + MOD);
        }
        ways[i] = total;
        i = (i + 1);
    }
    int64_t total_paths = ((int64_t)(FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD(((((__int128)(fact[(2 * N)])) * ((__int128)(invfact[N])))), (((__int128)(MOD)))) * ((__int128)(invfact[N])))), (((__int128)(MOD))))));
    i = 0;
    while (i < k) {
        int64_t xi = xs[i];
        int64_t yi = ys[i];
        int64_t w = ((int64_t)(FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD(((((__int128)(fact[(((N - xi) + N) - yi)])) * ((__int128)(invfact[(N - xi)])))), (((__int128)(MOD)))) * ((__int128)(invfact[(N - yi)])))), (((__int128)(MOD))))));
        total_paths = FLOW_CHECKED_MOD(((total_paths - ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(ways[i])) * ((__int128)(w)))), (((__int128)(MOD)))))))), (MOD));
        i = (i + 1);
    }
    if (total_paths < 0) {
        total_paths = (total_paths + MOD);
    }
    printf("%lld\n", total_paths);
    free(ways);
    free(invfact);
    free(fact);
    free(ys);
    free(xs);
    free(is_sq);
    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 @modpow(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %175 = arith.constant 1 : i32
    %176 = arith.extsi %175 : i32 to i64
    %177 = llvm.mlir.constant(1 : i64) : i64
    %178 = llvm.alloca %177 x i64 : (i64) -> !llvm.ptr
    llvm.store %176, %178 : i64, !llvm.ptr
    %179 = arith.remsi %arg0, %arg2 : i64
    %180 = llvm.mlir.constant(1 : i64) : i64
    %181 = llvm.alloca %180 x i64 : (i64) -> !llvm.ptr
    llvm.store %179, %181 : i64, !llvm.ptr
    %182 = llvm.mlir.constant(1 : i64) : i64
    %183 = llvm.alloca %182 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %183 : i64, !llvm.ptr
    cf.br ^bb42
    ^bb42:
    %184 = llvm.load %183 : !llvm.ptr -> i64
    %185 = arith.constant 0 : i32
    %187 = arith.extsi %185 : i32 to i64
    %186 = arith.cmpi sgt, %184, %187 : i64
    cf.cond_br %186, ^bb43, ^bb44
    ^bb43:
      %188 = llvm.load %183 : !llvm.ptr -> i64
      %189 = arith.constant 2 : i32
      %191 = arith.extsi %189 : i32 to i64
      %190 = arith.remsi %188, %191 : i64
      %192 = arith.constant 1 : i32
      %194 = arith.extsi %192 : i32 to i64
      %193 = arith.cmpi eq, %190, %194 : i64
      cf.cond_br %193, ^bb45, ^bb46
      ^bb45:
        %195 = llvm.load %178 : !llvm.ptr -> i64
        %196 = arith.extsi %195 : i64 to i128
        %197 = llvm.load %181 : !llvm.ptr -> i64
        %198 = arith.extsi %197 : i64 to i128
        %200 = arith.trunci %196 : i128 to i64
        %201 = arith.trunci %198 : i128 to i64
        %199 = arith.muli %200, %201 : i64
        %202 = arith.extsi %arg2 : i64 to i128
        %204 = arith.trunci %202 : i128 to i64
        %203 = arith.remsi %199, %204 : i64
        llvm.store %203, %178 : i64, !llvm.ptr
        cf.br ^bb47
      ^bb46:
        cf.br ^bb47
      ^bb47:
      %205 = llvm.load %181 : !llvm.ptr -> i64
      %206 = arith.extsi %205 : i64 to i128
      %207 = llvm.load %181 : !llvm.ptr -> i64
      %208 = arith.extsi %207 : i64 to i128
      %210 = arith.trunci %206 : i128 to i64
      %211 = arith.trunci %208 : i128 to i64
      %209 = arith.muli %210, %211 : i64
      %212 = arith.extsi %arg2 : i64 to i128
      %214 = arith.trunci %212 : i128 to i64
      %213 = arith.remsi %209, %214 : i64
      llvm.store %213, %181 : i64, !llvm.ptr
      %215 = llvm.load %183 : !llvm.ptr -> i64
      %216 = arith.constant 2 : i32
      %218 = arith.extsi %216 : i32 to i64
      %217 = arith.divsi %215, %218 : i64
      llvm.store %217, %183 : i64, !llvm.ptr
      cf.br ^bb42
    ^bb44:
    %219 = llvm.load %178 : !llvm.ptr -> i64
    func.return %219 : i64
  }
  func.func @main() -> i32 {
    %220 = arith.constant 10000000 : i32
    %221 = arith.extsi %220 : i32 to i64
    %222 = arith.constant 1000000007 : i32
    %223 = arith.extsi %222 : i32 to i64
    %224 = func.call @isqrt(%221) : (i64) -> i64
    %226 = arith.constant 2 : i32
    %228 = arith.extsi %226 : i32 to i64
    %227 = arith.muli %228, %221 : i64
    %225 = func.call @isqrt(%227) : (i64) -> i64
    %230 = arith.constant 2 : i32
    %232 = arith.extsi %230 : i32 to i64
    %231 = arith.muli %232, %221 : i64
    %233 = arith.constant 1 : i32
    %235 = arith.extsi %233 : i32 to i64
    %234 = arith.addi %231, %235 : i64
    %236 = arith.constant 1 : i32
    %237 = arith.extsi %236 : i32 to i64
    %229 = func.call @calloc(%234, %237) : (i64, i64) -> !llvm.ptr
    %238 = llvm.mlir.zero : !llvm.ptr
    %239 = llvm.icmp "eq" %229, %238 : !llvm.ptr
    cf.cond_br %239, ^bb48, ^bb49
    ^bb48:
      %240 = arith.constant 1 : i32
      func.return %240 : i32
    ^bb49:
      cf.br ^bb50
    ^bb50:
    %241 = arith.constant 1 : i32
    %242 = arith.extsi %241 : i32 to i64
    %243 = llvm.mlir.constant(1 : i64) : i64
    %244 = llvm.alloca %243 x i64 : (i64) -> !llvm.ptr
    llvm.store %242, %244 : i64, !llvm.ptr
    cf.br ^bb51
    ^bb51:
    %245 = llvm.load %244 : !llvm.ptr -> i64
    %246 = arith.cmpi sle, %245, %225 : i64
    cf.cond_br %246, ^bb52, ^bb53
    ^bb52:
      %247 = arith.constant 1 : i32
      %248 = llvm.load %244 : !llvm.ptr -> i64
      %249 = llvm.load %244 : !llvm.ptr -> i64
      %250 = arith.muli %248, %249 : i64
      %251 = arith.trunci %247 : i32 to i8
      %252 = llvm.getelementptr %229[%250] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      llvm.store %251, %252 : i8, !llvm.ptr
      %253 = llvm.load %244 : !llvm.ptr -> i64
      %254 = arith.constant 1 : i32
      %256 = arith.extsi %254 : i32 to i64
      %255 = arith.addi %253, %256 : i64
      llvm.store %255, %244 : i64, !llvm.ptr
      cf.br ^bb51
    ^bb53:
    %258 = arith.constant 20000 : i32
    %259 = arith.constant 8 : i32
    %260 = arith.extsi %258 : i32 to i64
    %261 = arith.extsi %259 : i32 to i64
    %257 = func.call @calloc(%260, %261) : (i64, i64) -> !llvm.ptr
    %263 = arith.constant 20000 : i32
    %264 = arith.constant 8 : i32
    %265 = arith.extsi %263 : i32 to i64
    %266 = arith.extsi %264 : i32 to i64
    %262 = func.call @calloc(%265, %266) : (i64, i64) -> !llvm.ptr
    %267 = llvm.mlir.zero : !llvm.ptr
    %268 = llvm.icmp "eq" %257, %267 : !llvm.ptr
    %269 = scf.if %268 -> (i1) {
      %270 = arith.constant true
      scf.yield %270 : i1
    } else {
      %271 = llvm.mlir.zero : !llvm.ptr
      %272 = llvm.icmp "eq" %262, %271 : !llvm.ptr
      scf.yield %272 : i1
    }
    cf.cond_br %269, ^bb54, ^bb55
    ^bb54:
      %273 = arith.constant 1 : i32
      func.return %273 : i32
    ^bb55:
      cf.br ^bb56
    ^bb56:
    %274 = arith.constant 0 : i32
    %275 = arith.extsi %274 : i32 to i64
    %276 = llvm.mlir.constant(1 : i64) : i64
    %277 = llvm.alloca %276 x i64 : (i64) -> !llvm.ptr
    llvm.store %275, %277 : i64, !llvm.ptr
    %278 = arith.constant 1 : i32
    %279 = arith.extsi %278 : i32 to i64
    %280 = llvm.mlir.constant(1 : i64) : i64
    %281 = llvm.alloca %280 x i64 : (i64) -> !llvm.ptr
    llvm.store %279, %281 : i64, !llvm.ptr
    cf.br ^bb57
    ^bb57:
    %282 = llvm.load %281 : !llvm.ptr -> i64
    %283 = arith.cmpi sle, %282, %224 : i64
    cf.cond_br %283, ^bb58, ^bb59
    ^bb58:
      %284 = llvm.load %281 : !llvm.ptr -> i64
      %285 = llvm.load %281 : !llvm.ptr -> i64
      %286 = arith.muli %284, %285 : i64
      %287 = arith.constant 1 : i32
      %288 = arith.extsi %287 : i32 to i64
      %289 = llvm.mlir.constant(1 : i64) : i64
      %290 = llvm.alloca %289 x i64 : (i64) -> !llvm.ptr
      llvm.store %288, %290 : i64, !llvm.ptr
      cf.br ^bb60
      ^bb60:
      %291 = llvm.load %290 : !llvm.ptr -> i64
      %292 = arith.cmpi sle, %291, %224 : i64
      cf.cond_br %292, ^bb61, ^bb62
      ^bb61:
        %293 = llvm.load %290 : !llvm.ptr -> i64
        %294 = llvm.load %290 : !llvm.ptr -> i64
        %295 = arith.muli %293, %294 : i64
        %297 = arith.addi %286, %295 : i64
        %298 = llvm.getelementptr %229[%297] : (!llvm.ptr, i64) -> !llvm.ptr, i8
        %296 = llvm.load %298 : !llvm.ptr -> i8
        %299 = arith.constant 0 : i32
        %301 = arith.extsi %296 : i8 to i32
        %300 = arith.cmpi ne, %301, %299 : i32
        cf.cond_br %300, ^bb63, ^bb64
        ^bb63:
          %302 = llvm.load %277 : !llvm.ptr -> i64
          %303 = llvm.getelementptr %257[%302] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          llvm.store %286, %303 : i64, !llvm.ptr
          %304 = llvm.load %277 : !llvm.ptr -> i64
          %305 = llvm.getelementptr %262[%304] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          llvm.store %295, %305 : i64, !llvm.ptr
          %306 = llvm.load %277 : !llvm.ptr -> i64
          %307 = arith.constant 1 : i32
          %309 = arith.extsi %307 : i32 to i64
          %308 = arith.addi %306, %309 : i64
          llvm.store %308, %277 : i64, !llvm.ptr
          cf.br ^bb65
        ^bb64:
          cf.br ^bb65
        ^bb65:
        %310 = llvm.load %290 : !llvm.ptr -> i64
        %311 = arith.constant 1 : i32
        %313 = arith.extsi %311 : i32 to i64
        %312 = arith.addi %310, %313 : i64
        llvm.store %312, %290 : i64, !llvm.ptr
        cf.br ^bb60
      ^bb62:
      %314 = llvm.load %281 : !llvm.ptr -> i64
      %315 = arith.constant 1 : i32
      %317 = arith.extsi %315 : i32 to i64
      %316 = arith.addi %314, %317 : i64
      llvm.store %316, %281 : i64, !llvm.ptr
      cf.br ^bb57
    ^bb59:
    %318 = llvm.load %277 : !llvm.ptr -> i64
    %319 = arith.constant 2 : i32
    %321 = arith.extsi %319 : i32 to i64
    %320 = arith.divsi %318, %321 : i64
    %322 = llvm.mlir.constant(1 : i64) : i64
    %323 = llvm.alloca %322 x i64 : (i64) -> !llvm.ptr
    llvm.store %320, %323 : i64, !llvm.ptr
    cf.br ^bb66
    ^bb66:
    %324 = llvm.load %323 : !llvm.ptr -> i64
    %325 = arith.constant 0 : i32
    %327 = arith.extsi %325 : i32 to i64
    %326 = arith.cmpi sgt, %324, %327 : i64
    cf.cond_br %326, ^bb67, ^bb68
    ^bb67:
      %328 = llvm.load %323 : !llvm.ptr -> i64
      llvm.store %328, %244 : i64, !llvm.ptr
      cf.br ^bb69
      ^bb69:
      %329 = llvm.load %244 : !llvm.ptr -> i64
      %330 = llvm.load %277 : !llvm.ptr -> i64
      %331 = arith.cmpi slt, %329, %330 : i64
      cf.cond_br %331, ^bb70, ^bb71
      ^bb70:
        %332 = llvm.load %244 : !llvm.ptr -> i64
        %333 = llvm.mlir.constant(1 : i64) : i64
        %334 = llvm.alloca %333 x i64 : (i64) -> !llvm.ptr
        llvm.store %332, %334 : i64, !llvm.ptr
        cf.br ^bb72
        ^bb72:
        %335 = llvm.load %334 : !llvm.ptr -> i64
        %336 = llvm.load %323 : !llvm.ptr -> i64
        %337 = arith.cmpi sge, %335, %336 : i64
        cf.cond_br %337, ^bb73, ^bb74
        ^bb73:
          %339 = llvm.load %334 : !llvm.ptr -> i64
          %340 = llvm.getelementptr %257[%339] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %338 = llvm.load %340 : !llvm.ptr -> i64
          %342 = llvm.load %334 : !llvm.ptr -> i64
          %343 = llvm.getelementptr %262[%342] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %341 = llvm.load %343 : !llvm.ptr -> i64
          %344 = arith.addi %338, %341 : i64
          %346 = llvm.load %334 : !llvm.ptr -> i64
          %347 = llvm.load %323 : !llvm.ptr -> i64
          %348 = arith.subi %346, %347 : i64
          %349 = llvm.getelementptr %257[%348] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %345 = llvm.load %349 : !llvm.ptr -> i64
          %351 = llvm.load %334 : !llvm.ptr -> i64
          %352 = llvm.load %323 : !llvm.ptr -> i64
          %353 = arith.subi %351, %352 : i64
          %354 = llvm.getelementptr %262[%353] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %350 = llvm.load %354 : !llvm.ptr -> i64
          %355 = arith.addi %345, %350 : i64
          %356 = arith.cmpi slt, %344, %355 : i64
          %357 = scf.if %356 -> (i1) {
            %358 = arith.constant true
            scf.yield %358 : i1
          } else {
            %359 = arith.cmpi eq, %344, %355 : i64
            %360 = scf.if %359 -> (i1) {
              %362 = llvm.load %334 : !llvm.ptr -> i64
              %363 = llvm.getelementptr %257[%362] : (!llvm.ptr, i64) -> !llvm.ptr, i64
              %361 = llvm.load %363 : !llvm.ptr -> i64
              %365 = llvm.load %334 : !llvm.ptr -> i64
              %366 = llvm.load %323 : !llvm.ptr -> i64
              %367 = arith.subi %365, %366 : i64
              %368 = llvm.getelementptr %257[%367] : (!llvm.ptr, i64) -> !llvm.ptr, i64
              %364 = llvm.load %368 : !llvm.ptr -> i64
              %369 = arith.cmpi slt, %361, %364 : i64
              scf.yield %369 : i1
            } else {
              %370 = arith.constant false
              scf.yield %370 : i1
            }
            scf.yield %360 : i1
          }
          cf.cond_br %357, ^bb75, ^bb76
          ^bb75:
            %372 = llvm.load %334 : !llvm.ptr -> i64
            %373 = llvm.getelementptr %257[%372] : (!llvm.ptr, i64) -> !llvm.ptr, i64
            %371 = llvm.load %373 : !llvm.ptr -> i64
            %375 = llvm.load %334 : !llvm.ptr -> i64
            %376 = llvm.load %323 : !llvm.ptr -> i64
            %377 = arith.subi %375, %376 : i64
            %378 = llvm.getelementptr %257[%377] : (!llvm.ptr, i64) -> !llvm.ptr, i64
            %374 = llvm.load %378 : !llvm.ptr -> i64
            %379 = llvm.load %334 : !llvm.ptr -> i64
            %380 = llvm.getelementptr %257[%379] : (!llvm.ptr, i64) -> !llvm.ptr, i64
            llvm.store %374, %380 : i64, !llvm.ptr
            %381 = llvm.load %334 : !llvm.ptr -> i64
            %382 = llvm.load %323 : !llvm.ptr -> i64
            %383 = arith.subi %381, %382 : i64
            %384 = llvm.getelementptr %257[%383] : (!llvm.ptr, i64) -> !llvm.ptr, i64
            llvm.store %371, %384 : i64, !llvm.ptr
            %386 = llvm.load %334 : !llvm.ptr -> i64
            %387 = llvm.getelementptr %262[%386] : (!llvm.ptr, i64) -> !llvm.ptr, i64
            %385 = llvm.load %387 : !llvm.ptr -> i64
            %389 = llvm.load %334 : !llvm.ptr -> i64
            %390 = llvm.load %323 : !llvm.ptr -> i64
            %391 = arith.subi %389, %390 : i64
            %392 = llvm.getelementptr %262[%391] : (!llvm.ptr, i64) -> !llvm.ptr, i64
            %388 = llvm.load %392 : !llvm.ptr -> i64
            %393 = llvm.load %334 : !llvm.ptr -> i64
            %394 = llvm.getelementptr %262[%393] : (!llvm.ptr, i64) -> !llvm.ptr, i64
            llvm.store %388, %394 : i64, !llvm.ptr
            %395 = llvm.load %334 : !llvm.ptr -> i64
            %396 = llvm.load %323 : !llvm.ptr -> i64
            %397 = arith.subi %395, %396 : i64
            %398 = llvm.getelementptr %262[%397] : (!llvm.ptr, i64) -> !llvm.ptr, i64
            llvm.store %385, %398 : i64, !llvm.ptr
            %399 = llvm.load %334 : !llvm.ptr -> i64
            %400 = llvm.load %323 : !llvm.ptr -> i64
            %401 = arith.subi %399, %400 : i64
            llvm.store %401, %334 : i64, !llvm.ptr
            cf.br ^bb77
          ^bb76:
            cf.br ^bb74
          ^bb77:
          cf.br ^bb72
        ^bb74:
        %402 = llvm.load %244 : !llvm.ptr -> i64
        %403 = arith.constant 1 : i32
        %405 = arith.extsi %403 : i32 to i64
        %404 = arith.addi %402, %405 : i64
        llvm.store %404, %244 : i64, !llvm.ptr
        cf.br ^bb69
      ^bb71:
      %406 = llvm.load %323 : !llvm.ptr -> i64
      %407 = arith.constant 2 : i32
      %409 = arith.extsi %407 : i32 to i64
      %408 = arith.divsi %406, %409 : i64
      llvm.store %408, %323 : i64, !llvm.ptr
      cf.br ^bb66
    ^bb68:
    %410 = arith.constant 2 : i32
    %412 = arith.extsi %410 : i32 to i64
    %411 = arith.muli %412, %221 : i64
    %414 = arith.constant 1 : i32
    %416 = arith.extsi %414 : i32 to i64
    %415 = arith.addi %411, %416 : i64
    %417 = arith.constant 8 : i32
    %418 = arith.extsi %417 : i32 to i64
    %413 = func.call @calloc(%415, %418) : (i64, i64) -> !llvm.ptr
    %420 = arith.constant 1 : i32
    %422 = arith.extsi %420 : i32 to i64
    %421 = arith.addi %411, %422 : i64
    %423 = arith.constant 8 : i32
    %424 = arith.extsi %423 : i32 to i64
    %419 = func.call @calloc(%421, %424) : (i64, i64) -> !llvm.ptr
    %425 = llvm.mlir.zero : !llvm.ptr
    %426 = llvm.icmp "eq" %413, %425 : !llvm.ptr
    %427 = scf.if %426 -> (i1) {
      %428 = arith.constant true
      scf.yield %428 : i1
    } else {
      %429 = llvm.mlir.zero : !llvm.ptr
      %430 = llvm.icmp "eq" %419, %429 : !llvm.ptr
      scf.yield %430 : i1
    }
    cf.cond_br %427, ^bb78, ^bb79
    ^bb78:
      %431 = arith.constant 1 : i32
      func.return %431 : i32
    ^bb79:
      cf.br ^bb80
    ^bb80:
    %432 = arith.constant 1 : i32
    %433 = arith.constant 0 : i32
    %434 = arith.extsi %432 : i32 to i64
    %435 = arith.extsi %433 : i32 to i64
    %436 = llvm.getelementptr %413[%435] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %434, %436 : i64, !llvm.ptr
    %437 = arith.constant 1 : i32
    %438 = arith.extsi %437 : i32 to i64
    llvm.store %438, %244 : i64, !llvm.ptr
    cf.br ^bb81
    ^bb81:
    %439 = llvm.load %244 : !llvm.ptr -> i64
    %440 = arith.cmpi sle, %439, %411 : i64
    cf.cond_br %440, ^bb82, ^bb83
    ^bb82:
      %442 = llvm.load %244 : !llvm.ptr -> i64
      %443 = arith.constant 1 : i32
      %445 = arith.extsi %443 : i32 to i64
      %444 = arith.subi %442, %445 : i64
      %446 = llvm.getelementptr %413[%444] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %441 = llvm.load %446 : !llvm.ptr -> i64
      %447 = arith.extsi %441 : i64 to i128
      %448 = llvm.load %244 : !llvm.ptr -> i64
      %449 = arith.extsi %448 : i64 to i128
      %451 = arith.trunci %447 : i128 to i64
      %452 = arith.trunci %449 : i128 to i64
      %450 = arith.muli %451, %452 : i64
      %453 = arith.extsi %223 : i64 to i128
      %455 = arith.trunci %453 : i128 to i64
      %454 = arith.remsi %450, %455 : i64
      %456 = llvm.load %244 : !llvm.ptr -> i64
      %457 = llvm.getelementptr %413[%456] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %454, %457 : i64, !llvm.ptr
      %458 = llvm.load %244 : !llvm.ptr -> i64
      %459 = arith.constant 1 : i32
      %461 = arith.extsi %459 : i32 to i64
      %460 = arith.addi %458, %461 : i64
      llvm.store %460, %244 : i64, !llvm.ptr
      cf.br ^bb81
    ^bb83:
    %464 = llvm.getelementptr %413[%411] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %463 = llvm.load %464 : !llvm.ptr -> i64
    %465 = arith.constant 2 : i32
    %467 = arith.extsi %465 : i32 to i64
    %466 = arith.subi %223, %467 : i64
    %462 = func.call @modpow(%463, %466, %223) : (i64, i64, i64) -> i64
    %468 = llvm.getelementptr %419[%411] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %462, %468 : i64, !llvm.ptr
    llvm.store %411, %244 : i64, !llvm.ptr
    cf.br ^bb84
    ^bb84:
    %469 = llvm.load %244 : !llvm.ptr -> i64
    %470 = arith.constant 0 : i32
    %472 = arith.extsi %470 : i32 to i64
    %471 = arith.cmpi sgt, %469, %472 : i64
    cf.cond_br %471, ^bb85, ^bb86
    ^bb85:
      %474 = llvm.load %244 : !llvm.ptr -> i64
      %475 = llvm.getelementptr %419[%474] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %473 = llvm.load %475 : !llvm.ptr -> i64
      %476 = arith.extsi %473 : i64 to i128
      %477 = llvm.load %244 : !llvm.ptr -> i64
      %478 = arith.extsi %477 : i64 to i128
      %480 = arith.trunci %476 : i128 to i64
      %481 = arith.trunci %478 : i128 to i64
      %479 = arith.muli %480, %481 : i64
      %482 = arith.extsi %223 : i64 to i128
      %484 = arith.trunci %482 : i128 to i64
      %483 = arith.remsi %479, %484 : i64
      %485 = llvm.load %244 : !llvm.ptr -> i64
      %486 = arith.constant 1 : i32
      %488 = arith.extsi %486 : i32 to i64
      %487 = arith.subi %485, %488 : i64
      %489 = llvm.getelementptr %419[%487] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %483, %489 : i64, !llvm.ptr
      %490 = llvm.load %244 : !llvm.ptr -> i64
      %491 = arith.constant 1 : i32
      %493 = arith.extsi %491 : i32 to i64
      %492 = arith.subi %490, %493 : i64
      llvm.store %492, %244 : i64, !llvm.ptr
      cf.br ^bb84
    ^bb86:
    %495 = llvm.load %277 : !llvm.ptr -> i64
    %496 = arith.constant 8 : i32
    %497 = arith.extsi %496 : i32 to i64
    %494 = func.call @calloc(%495, %497) : (i64, i64) -> !llvm.ptr
    %498 = llvm.mlir.zero : !llvm.ptr
    %499 = llvm.icmp "eq" %494, %498 : !llvm.ptr
    cf.cond_br %499, ^bb87, ^bb88
    ^bb87:
      %500 = arith.constant 1 : i32
      func.return %500 : i32
    ^bb88:
      cf.br ^bb89
    ^bb89:
    %501 = arith.constant 0 : i32
    %502 = arith.extsi %501 : i32 to i64
    llvm.store %502, %244 : i64, !llvm.ptr
    cf.br ^bb90
    ^bb90:
    %503 = llvm.load %244 : !llvm.ptr -> i64
    %504 = llvm.load %277 : !llvm.ptr -> i64
    %505 = arith.cmpi slt, %503, %504 : i64
    cf.cond_br %505, ^bb91, ^bb92
    ^bb91:
      %507 = llvm.load %244 : !llvm.ptr -> i64
      %508 = llvm.getelementptr %257[%507] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %506 = llvm.load %508 : !llvm.ptr -> i64
      %510 = llvm.load %244 : !llvm.ptr -> i64
      %511 = llvm.getelementptr %262[%510] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %509 = llvm.load %511 : !llvm.ptr -> i64
      %513 = arith.addi %506, %509 : i64
      %514 = llvm.getelementptr %413[%513] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %512 = llvm.load %514 : !llvm.ptr -> i64
      %515 = arith.extsi %512 : i64 to i128
      %517 = llvm.getelementptr %419[%506] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %516 = llvm.load %517 : !llvm.ptr -> i64
      %518 = arith.extsi %516 : i64 to i128
      %520 = arith.trunci %515 : i128 to i64
      %521 = arith.trunci %518 : i128 to i64
      %519 = arith.muli %520, %521 : i64
      %522 = arith.extsi %223 : i64 to i128
      %524 = arith.trunci %522 : i128 to i64
      %523 = arith.remsi %519, %524 : i64
      %526 = llvm.getelementptr %419[%509] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %525 = llvm.load %526 : !llvm.ptr -> i64
      %527 = arith.extsi %525 : i64 to i128
      %529 = arith.trunci %527 : i128 to i64
      %528 = arith.muli %523, %529 : i64
      %530 = arith.extsi %223 : i64 to i128
      %532 = arith.trunci %530 : i128 to i64
      %531 = arith.remsi %528, %532 : i64
      %533 = llvm.mlir.constant(1 : i64) : i64
      %534 = llvm.alloca %533 x i64 : (i64) -> !llvm.ptr
      llvm.store %531, %534 : i64, !llvm.ptr
      %535 = arith.constant 0 : i32
      %536 = arith.extsi %535 : i32 to i64
      %537 = llvm.mlir.constant(1 : i64) : i64
      %538 = llvm.alloca %537 x i64 : (i64) -> !llvm.ptr
      llvm.store %536, %538 : i64, !llvm.ptr
      cf.br ^bb93
      ^bb93:
      %539 = llvm.load %538 : !llvm.ptr -> i64
      %540 = llvm.load %244 : !llvm.ptr -> i64
      %541 = arith.cmpi slt, %539, %540 : i64
      cf.cond_br %541, ^bb94, ^bb95
      ^bb94:
        %543 = llvm.load %538 : !llvm.ptr -> i64
        %544 = llvm.getelementptr %257[%543] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %542 = llvm.load %544 : !llvm.ptr -> i64
        %546 = llvm.load %538 : !llvm.ptr -> i64
        %547 = llvm.getelementptr %262[%546] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %545 = llvm.load %547 : !llvm.ptr -> i64
        %548 = arith.cmpi sle, %542, %506 : i64
        %549 = scf.if %548 -> (i1) {
          %550 = arith.cmpi sle, %545, %509 : i64
          scf.yield %550 : i1
        } else {
          %551 = arith.constant false
          scf.yield %551 : i1
        }
        cf.cond_br %549, ^bb96, ^bb97
        ^bb96:
          %552 = arith.subi %506, %542 : i64
          %553 = arith.subi %509, %545 : i64
          %555 = arith.addi %552, %553 : i64
          %556 = llvm.getelementptr %413[%555] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %554 = llvm.load %556 : !llvm.ptr -> i64
          %557 = arith.extsi %554 : i64 to i128
          %559 = llvm.getelementptr %419[%552] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %558 = llvm.load %559 : !llvm.ptr -> i64
          %560 = arith.extsi %558 : i64 to i128
          %562 = arith.trunci %557 : i128 to i64
          %563 = arith.trunci %560 : i128 to i64
          %561 = arith.muli %562, %563 : i64
          %564 = arith.extsi %223 : i64 to i128
          %566 = arith.trunci %564 : i128 to i64
          %565 = arith.remsi %561, %566 : i64
          %568 = llvm.getelementptr %419[%553] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %567 = llvm.load %568 : !llvm.ptr -> i64
          %569 = arith.extsi %567 : i64 to i128
          %571 = arith.trunci %569 : i128 to i64
          %570 = arith.muli %565, %571 : i64
          %572 = arith.extsi %223 : i64 to i128
          %574 = arith.trunci %572 : i128 to i64
          %573 = arith.remsi %570, %574 : i64
          %575 = llvm.load %534 : !llvm.ptr -> i64
          %577 = llvm.load %538 : !llvm.ptr -> i64
          %578 = llvm.getelementptr %494[%577] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %576 = llvm.load %578 : !llvm.ptr -> i64
          %579 = arith.extsi %576 : i64 to i128
          %580 = arith.extsi %573 : i64 to i128
          %582 = arith.trunci %579 : i128 to i64
          %583 = arith.trunci %580 : i128 to i64
          %581 = arith.muli %582, %583 : i64
          %584 = arith.extsi %223 : i64 to i128
          %586 = arith.trunci %584 : i128 to i64
          %585 = arith.remsi %581, %586 : i64
          %587 = arith.subi %575, %585 : i64
          %588 = arith.remsi %587, %223 : i64
          llvm.store %588, %534 : i64, !llvm.ptr
          cf.br ^bb98
        ^bb97:
          cf.br ^bb98
        ^bb98:
        %589 = llvm.load %538 : !llvm.ptr -> i64
        %590 = arith.constant 1 : i32
        %592 = arith.extsi %590 : i32 to i64
        %591 = arith.addi %589, %592 : i64
        llvm.store %591, %538 : i64, !llvm.ptr
        cf.br ^bb93
      ^bb95:
      %593 = llvm.load %534 : !llvm.ptr -> i64
      %594 = arith.constant 0 : i32
      %596 = arith.extsi %594 : i32 to i64
      %595 = arith.cmpi slt, %593, %596 : i64
      cf.cond_br %595, ^bb99, ^bb100
      ^bb99:
        %597 = llvm.load %534 : !llvm.ptr -> i64
        %598 = arith.addi %597, %223 : i64
        llvm.store %598, %534 : i64, !llvm.ptr
        cf.br ^bb101
      ^bb100:
        cf.br ^bb101
      ^bb101:
      %599 = llvm.load %534 : !llvm.ptr -> i64
      %600 = llvm.load %244 : !llvm.ptr -> i64
      %601 = llvm.getelementptr %494[%600] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %599, %601 : i64, !llvm.ptr
      %602 = llvm.load %244 : !llvm.ptr -> i64
      %603 = arith.constant 1 : i32
      %605 = arith.extsi %603 : i32 to i64
      %604 = arith.addi %602, %605 : i64
      llvm.store %604, %244 : i64, !llvm.ptr
      cf.br ^bb90
    ^bb92:
    %607 = arith.constant 2 : i32
    %609 = arith.extsi %607 : i32 to i64
    %608 = arith.muli %609, %221 : i64
    %610 = llvm.getelementptr %413[%608] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %606 = llvm.load %610 : !llvm.ptr -> i64
    %611 = arith.extsi %606 : i64 to i128
    %613 = llvm.getelementptr %419[%221] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %612 = llvm.load %613 : !llvm.ptr -> i64
    %614 = arith.extsi %612 : i64 to i128
    %616 = arith.trunci %611 : i128 to i64
    %617 = arith.trunci %614 : i128 to i64
    %615 = arith.muli %616, %617 : i64
    %618 = arith.extsi %223 : i64 to i128
    %620 = arith.trunci %618 : i128 to i64
    %619 = arith.remsi %615, %620 : i64
    %622 = llvm.getelementptr %419[%221] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %621 = llvm.load %622 : !llvm.ptr -> i64
    %623 = arith.extsi %621 : i64 to i128
    %625 = arith.trunci %623 : i128 to i64
    %624 = arith.muli %619, %625 : i64
    %626 = arith.extsi %223 : i64 to i128
    %628 = arith.trunci %626 : i128 to i64
    %627 = arith.remsi %624, %628 : i64
    %629 = llvm.mlir.constant(1 : i64) : i64
    %630 = llvm.alloca %629 x i64 : (i64) -> !llvm.ptr
    llvm.store %627, %630 : i64, !llvm.ptr
    %631 = arith.constant 0 : i32
    %632 = arith.extsi %631 : i32 to i64
    llvm.store %632, %244 : i64, !llvm.ptr
    cf.br ^bb102
    ^bb102:
    %633 = llvm.load %244 : !llvm.ptr -> i64
    %634 = llvm.load %277 : !llvm.ptr -> i64
    %635 = arith.cmpi slt, %633, %634 : i64
    cf.cond_br %635, ^bb103, ^bb104
    ^bb103:
      %637 = llvm.load %244 : !llvm.ptr -> i64
      %638 = llvm.getelementptr %257[%637] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %636 = llvm.load %638 : !llvm.ptr -> i64
      %640 = llvm.load %244 : !llvm.ptr -> i64
      %641 = llvm.getelementptr %262[%640] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %639 = llvm.load %641 : !llvm.ptr -> i64
      %643 = arith.subi %221, %636 : i64
      %644 = arith.addi %643, %221 : i64
      %645 = arith.subi %644, %639 : i64
      %646 = llvm.getelementptr %413[%645] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %642 = llvm.load %646 : !llvm.ptr -> i64
      %647 = arith.extsi %642 : i64 to i128
      %649 = arith.subi %221, %636 : i64
      %650 = llvm.getelementptr %419[%649] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %648 = llvm.load %650 : !llvm.ptr -> i64
      %651 = arith.extsi %648 : i64 to i128
      %653 = arith.trunci %647 : i128 to i64
      %654 = arith.trunci %651 : i128 to i64
      %652 = arith.muli %653, %654 : i64
      %655 = arith.extsi %223 : i64 to i128
      %657 = arith.trunci %655 : i128 to i64
      %656 = arith.remsi %652, %657 : i64
      %659 = arith.subi %221, %639 : i64
      %660 = llvm.getelementptr %419[%659] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %658 = llvm.load %660 : !llvm.ptr -> i64
      %661 = arith.extsi %658 : i64 to i128
      %663 = arith.trunci %661 : i128 to i64
      %662 = arith.muli %656, %663 : i64
      %664 = arith.extsi %223 : i64 to i128
      %666 = arith.trunci %664 : i128 to i64
      %665 = arith.remsi %662, %666 : i64
      %667 = llvm.load %630 : !llvm.ptr -> i64
      %669 = llvm.load %244 : !llvm.ptr -> i64
      %670 = llvm.getelementptr %494[%669] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %668 = llvm.load %670 : !llvm.ptr -> i64
      %671 = arith.extsi %668 : i64 to i128
      %672 = arith.extsi %665 : i64 to i128
      %674 = arith.trunci %671 : i128 to i64
      %675 = arith.trunci %672 : i128 to i64
      %673 = arith.muli %674, %675 : i64
      %676 = arith.extsi %223 : i64 to i128
      %678 = arith.trunci %676 : i128 to i64
      %677 = arith.remsi %673, %678 : i64
      %679 = arith.subi %667, %677 : i64
      %680 = arith.remsi %679, %223 : i64
      llvm.store %680, %630 : i64, !llvm.ptr
      %681 = llvm.load %244 : !llvm.ptr -> i64
      %682 = arith.constant 1 : i32
      %684 = arith.extsi %682 : i32 to i64
      %683 = arith.addi %681, %684 : i64
      llvm.store %683, %244 : i64, !llvm.ptr
      cf.br ^bb102
    ^bb104:
    %685 = llvm.load %630 : !llvm.ptr -> i64
    %686 = arith.constant 0 : i32
    %688 = arith.extsi %686 : i32 to i64
    %687 = arith.cmpi slt, %685, %688 : i64
    cf.cond_br %687, ^bb105, ^bb106
    ^bb105:
      %689 = llvm.load %630 : !llvm.ptr -> i64
      %690 = arith.addi %689, %223 : i64
      llvm.store %690, %630 : i64, !llvm.ptr
      cf.br ^bb107
    ^bb106:
      cf.br ^bb107
    ^bb107:
    %691 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %692 = llvm.load %630 : !llvm.ptr -> i64
    %693 = llvm.call @printf(%691, %692) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    func.call @free(%494) : (!llvm.ptr) -> ()
    func.call @free(%419) : (!llvm.ptr) -> ()
    func.call @free(%413) : (!llvm.ptr) -> ()
    func.call @free(%262) : (!llvm.ptr) -> ()
    func.call @free(%257) : (!llvm.ptr) -> ()
    func.call @free(%229) : (!llvm.ptr) -> ()
    %700 = arith.constant 0 : i32
    func.return %700 : i32
  }
}