Problem 658

Incomplete Words II: S(10^7, 10^12) mod 1e9+7. O(k) with linear sieve for power computation.

Answer958280177
Output958280177
StatusPASS
Native helperno
Runtime5750 ms
Peak memory240736 KB
Time complexityO(n) (estimated)
Space complexityO(n^2) (estimated)

Performance comparison

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

Flow source

# Project Euler 658
# Incomplete Words II: S(10^7, 10^12) mod 1e9+7.
# O(k) with linear sieve for power computation.

import euler.nt { mod_pow }

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

const MOD: i64 = 1000000007

function main() -> i32 {
    let k: i64 = 10000000
    let n: i64 = 1000000000000

    let limit: i64 = k - 1
    let e: i64 = (n + 1) % (MOD - 1)

    # Modular inverses up to k+1
    let inv: ptr<i64> = calloc(k + 2, 8)
    if inv == null { return 1 }
    inv[1] = 1
    for i in 2..(k + 2) {
        inv[i] = (MOD - (MOD / i) * inv[MOD % i] % MOD) % MOD
    }

    # Linear sieve for smallest prime factor and x^e mod MOD
    let spf: ptr<i64> = calloc(limit + 1, 8)
    let powe: ptr<i64> = calloc(limit + 1, 8)
    let primes: ptr<i64> = calloc(limit / 10 + 100, 8)
    let mut npc: i64 = 0

    if spf == null || powe == null { return 1 }

    powe[0] = 0
    if limit >= 1 { powe[1] = 1 }

    for i in 2..(limit + 1) {
        if spf[i] == 0 {
            spf[i] = i
            primes[npc] = i
            npc = npc + 1
            powe[i] = mod_pow(i, e, MOD)
        }
        let pi: i64 = powe[i]
        let si: i64 = spf[i]
        for j in 0..npc {
            let p: i64 = primes[j]
            let v: i64 = i * p
            if v > limit { break }
            spf[v] = p
            let t: i128 = (pi as i128) * (powe[p] as i128) % (MOD as i128)
            powe[v] = t as i64
            if p == si { break }
        }
    }

    let inv2: i64 = (MOD + 1) / 2
    let mut inv2pow: i64 = inv2
    let neg2: i64 = MOD - 2
    let k1: i64 = k + 1
    # s = (-1)^(k+1), k=10^7 even => s = -1
    let s: i64 = MOD - 1
    let n1: i64 = (n + 1) % MOD

    let mut term: i64 = 1
    let mut T: i64 = 1
    let mut ans: i64 = 0

    for m in 0..(limit + 1) {
        # G(m) = 1 + m + ... + m^n
        let mut G: i64 = 1
        if m == 1 { G = n1 }
        if m >= 2 {
            let t1: i128 = ((powe[m] - 1 + MOD) as i128) * (inv[m - 1] as i128) % (MOD as i128)
            G = t1 as i64
        }

        # A = 1 - 2^{-(m+1)} * (1 - s*T)
        let inner: i64 = (1 - s * T % MOD + MOD) % MOD
        let t2: i128 = (inv2pow as i128) * (inner as i128) % (MOD as i128)
        let A: i64 = (1 - (t2 as i64) + MOD) % MOD

        let t3: i128 = (G as i128) * (A as i128) % (MOD as i128)
        ans = (ans + (t3 as i64)) % MOD

        if m == limit { break }

        # Update term: term = term * (k+1-m)/(m+1) * (-2)
        let t4: i128 = (term as i128) * ((k1 - m) as i128) % (MOD as i128)
        term = (t4 * (inv[m + 1] as i128) % (MOD as i128)) as i64
        let t5: i128 = (term as i128) * (neg2 as i128) % (MOD as i128)
        term = t5 as i64
        T = (T + term) % MOD

        inv2pow = inv2pow * inv2 % MOD
    }

    printf("%lld\n", ans)

    free(primes)
    free(powe)
    free(spf)
    free(inv)
    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);
int32_t main(void);

static const int64_t MOD = 1000000007;

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



int32_t main(void) {
    int64_t k = 10000000;
    int64_t n = 1000000000000;
    int64_t limit = (k - 1);
    int64_t e = FLOW_CHECKED_MOD(((n + 1)), ((MOD - 1)));
    int64_t* inv = (int64_t*)(calloc((k + 2), 8));
    if (inv == NULL) {
        return 1;
    }
    inv[1] = 1;
    int32_t __flow_step_1 = 1;
    for (int32_t i = 2; (2 <= (k + 2)) ? i < (k + 2) : i > (k + 2); i += (2 <= (k + 2)) ? 1 : -1) {
        inv[i] = FLOW_CHECKED_MOD(((MOD - FLOW_CHECKED_MOD(((FLOW_CHECKED_DIV((MOD), (i)) * inv[FLOW_CHECKED_MOD((MOD), (i))])), (MOD)))), (MOD));
    }
    int64_t* spf = (int64_t*)(calloc((limit + 1), 8));
    int64_t* powe = (int64_t*)(calloc((limit + 1), 8));
    int64_t* primes = (int64_t*)(calloc((FLOW_CHECKED_DIV((limit), (10)) + 100), 8));
    int64_t npc = 0;
    if ((spf == NULL || powe == NULL)) {
        return 1;
    }
    powe[0] = 0;
    if (limit >= 1) {
        powe[1] = 1;
    }
    int32_t __flow_step_2 = 1;
    for (int32_t i = 2; (2 <= (limit + 1)) ? i < (limit + 1) : i > (limit + 1); i += (2 <= (limit + 1)) ? 1 : -1) {
        if (spf[i] == 0) {
            spf[i] = i;
            primes[npc] = i;
            npc = (npc + 1);
            powe[i] = mod_pow_i64_i64_i64(i, e, MOD);
        }
        int64_t pi = powe[i];
        int64_t si = spf[i];
        int32_t __flow_step_3 = 1;
        for (int32_t j = 0; (0 <= npc) ? j < npc : j > npc; j += (0 <= npc) ? 1 : -1) {
            int64_t p = primes[j];
            int64_t v = (i * p);
            if (v > limit) {
                break;
            }
            spf[v] = p;
            __int128 t = FLOW_CHECKED_MOD(((((__int128)(pi)) * ((__int128)(powe[p])))), (((__int128)(MOD))));
            powe[v] = ((int64_t)(t));
            if (p == si) {
                break;
            }
        }
    }
    int64_t inv2 = FLOW_CHECKED_DIV(((MOD + 1)), (2));
    int64_t inv2pow = inv2;
    int64_t neg2 = (MOD - 2);
    int64_t k1 = (k + 1);
    int64_t s = (MOD - 1);
    int64_t n1 = FLOW_CHECKED_MOD(((n + 1)), (MOD));
    int64_t term = 1;
    int64_t T = 1;
    int64_t ans = 0;
    int32_t __flow_step_4 = 1;
    for (int32_t m = 0; (0 <= (limit + 1)) ? m < (limit + 1) : m > (limit + 1); m += (0 <= (limit + 1)) ? 1 : -1) {
        int64_t G = 1;
        if (m == 1) {
            G = n1;
        }
        if (m >= 2) {
            __int128 t1 = FLOW_CHECKED_MOD(((((__int128)(((powe[m] - 1) + MOD))) * ((__int128)(inv[(m - 1)])))), (((__int128)(MOD))));
            G = ((int64_t)(t1));
        }
        int64_t inner = FLOW_CHECKED_MOD((((1 - FLOW_CHECKED_MOD(((s * T)), (MOD))) + MOD)), (MOD));
        __int128 t2 = FLOW_CHECKED_MOD(((((__int128)(inv2pow)) * ((__int128)(inner)))), (((__int128)(MOD))));
        int64_t A = FLOW_CHECKED_MOD((((1 - ((int64_t)(t2))) + MOD)), (MOD));
        __int128 t3 = FLOW_CHECKED_MOD(((((__int128)(G)) * ((__int128)(A)))), (((__int128)(MOD))));
        ans = FLOW_CHECKED_MOD(((ans + ((int64_t)(t3)))), (MOD));
        if (m == limit) {
            break;
        }
        __int128 t4 = FLOW_CHECKED_MOD(((((__int128)(term)) * ((__int128)((k1 - m))))), (((__int128)(MOD))));
        term = ((int64_t)(FLOW_CHECKED_MOD(((t4 * ((__int128)(inv[(m + 1)])))), (((__int128)(MOD))))));
        __int128 t5 = FLOW_CHECKED_MOD(((((__int128)(term)) * ((__int128)(neg2)))), (((__int128)(MOD))));
        term = ((int64_t)(t5));
        T = FLOW_CHECKED_MOD(((T + term)), (MOD));
        inv2pow = FLOW_CHECKED_MOD(((inv2pow * inv2)), (MOD));
    }
    printf("%lld\n", ans);
    free(primes);
    free(powe);
    free(spf);
    free(inv);
    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) -> ()
  // Constant: MOD
  llvm.mlir.global internal constant @MOD(1000000007 : i64) : i64
  func.func @main() -> i32 {
    %175 = arith.constant 10000000 : i32
    %176 = arith.extsi %175 : i32 to i64
    %177 = arith.constant 995705032704 : i32
    %178 = arith.extsi %177 : i32 to i64
    %179 = arith.constant 1 : i32
    %181 = arith.extsi %179 : i32 to i64
    %180 = arith.subi %176, %181 : i64
    %182 = arith.constant 1 : i32
    %184 = arith.extsi %182 : i32 to i64
    %183 = arith.addi %178, %184 : i64
    %185 = llvm.mlir.addressof @MOD : !llvm.ptr
    %186 = llvm.load %185 : !llvm.ptr -> i64
    %187 = arith.constant 1 : i32
    %189 = arith.extsi %187 : i32 to i64
    %188 = arith.subi %186, %189 : i64
    %190 = arith.remsi %183, %188 : i64
    %192 = arith.constant 2 : i32
    %194 = arith.extsi %192 : i32 to i64
    %193 = arith.addi %176, %194 : i64
    %195 = arith.constant 8 : i32
    %196 = arith.extsi %195 : i32 to i64
    %191 = func.call @calloc(%193, %196) : (i64, i64) -> !llvm.ptr
    %197 = llvm.mlir.zero : !llvm.ptr
    %198 = llvm.icmp "eq" %191, %197 : !llvm.ptr
    cf.cond_br %198, ^bb42, ^bb43
    ^bb42:
      %199 = arith.constant 1 : i32
      func.return %199 : i32
    ^bb43:
      cf.br ^bb44
    ^bb44:
    %200 = arith.constant 1 : i32
    %201 = arith.constant 1 : i32
    %202 = arith.extsi %200 : i32 to i64
    %203 = arith.extsi %201 : i32 to i64
    %204 = llvm.getelementptr %191[%203] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %202, %204 : i64, !llvm.ptr
    %205 = arith.constant 2 : i32
    %206 = arith.constant 2 : i32
    %208 = arith.extsi %206 : i32 to i64
    %207 = arith.addi %176, %208 : i64
    %209 = arith.index_cast %205 : i32 to index
    %210 = arith.index_cast %207 : i32 to index
    %212 = arith.constant 1 : index
    %213 = arith.constant -1 : index
    %214 = arith.cmpi sle, %209, %210 : index
    %211 = arith.select %214, %212, %213 : index
    cf.br ^bb45(%209 : index)
    ^bb45(%215: index):
    %216 = arith.cmpi slt, %215, %210 : index
    %217 = arith.cmpi sgt, %215, %210 : index
    %218 = arith.select %214, %216, %217 : i1
    cf.cond_br %218, ^bb46(%215 : index), ^bb47(%215 : index)
    ^bb46(%219: index):
      %220 = llvm.mlir.addressof @MOD : !llvm.ptr
      %221 = llvm.load %220 : !llvm.ptr -> i64
      %222 = llvm.mlir.addressof @MOD : !llvm.ptr
      %223 = llvm.load %222 : !llvm.ptr -> i64
      %225 = arith.trunci %223 : i64 to i32
      %226 = arith.index_cast %219 : index to i32
      %224 = arith.divsi %225, %226 : i32
      %228 = llvm.mlir.addressof @MOD : !llvm.ptr
      %229 = llvm.load %228 : !llvm.ptr -> i64
      %231 = arith.trunci %229 : i64 to i32
      %232 = arith.index_cast %219 : index to i32
      %230 = arith.remsi %231, %232 : i32
      %233 = arith.extsi %230 : i32 to i64
      %234 = llvm.getelementptr %191[%233] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %227 = llvm.load %234 : !llvm.ptr -> i64
      %236 = arith.extsi %224 : i32 to i64
      %235 = arith.muli %236, %227 : i64
      %237 = llvm.mlir.addressof @MOD : !llvm.ptr
      %238 = llvm.load %237 : !llvm.ptr -> i64
      %239 = arith.remsi %235, %238 : i64
      %240 = arith.subi %221, %239 : i64
      %241 = llvm.mlir.addressof @MOD : !llvm.ptr
      %242 = llvm.load %241 : !llvm.ptr -> i64
      %243 = arith.remsi %240, %242 : i64
      %244 = arith.index_cast %219 : index to i64
      %245 = llvm.getelementptr %191[%244] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %243, %245 : i64, !llvm.ptr
      %246 = arith.addi %219, %211 : index
      cf.br ^bb45(%246 : index)
    ^bb47(%247: index):
    %249 = arith.constant 1 : i32
    %251 = arith.extsi %249 : i32 to i64
    %250 = arith.addi %180, %251 : i64
    %252 = arith.constant 8 : i32
    %253 = arith.extsi %252 : i32 to i64
    %248 = func.call @calloc(%250, %253) : (i64, i64) -> !llvm.ptr
    %255 = arith.constant 1 : i32
    %257 = arith.extsi %255 : i32 to i64
    %256 = arith.addi %180, %257 : i64
    %258 = arith.constant 8 : i32
    %259 = arith.extsi %258 : i32 to i64
    %254 = func.call @calloc(%256, %259) : (i64, i64) -> !llvm.ptr
    %261 = arith.constant 10 : i32
    %263 = arith.extsi %261 : i32 to i64
    %262 = arith.divsi %180, %263 : i64
    %264 = arith.constant 100 : i32
    %266 = arith.extsi %264 : i32 to i64
    %265 = arith.addi %262, %266 : i64
    %267 = arith.constant 8 : i32
    %268 = arith.extsi %267 : i32 to i64
    %260 = func.call @calloc(%265, %268) : (i64, i64) -> !llvm.ptr
    %269 = arith.constant 0 : i32
    %270 = arith.extsi %269 : i32 to i64
    %271 = llvm.mlir.constant(1 : i64) : i64
    %272 = llvm.alloca %271 x i64 : (i64) -> !llvm.ptr
    llvm.store %270, %272 : i64, !llvm.ptr
    %273 = llvm.mlir.zero : !llvm.ptr
    %274 = llvm.icmp "eq" %248, %273 : !llvm.ptr
    %275 = scf.if %274 -> (i1) {
      %276 = arith.constant true
      scf.yield %276 : i1
    } else {
      %277 = llvm.mlir.zero : !llvm.ptr
      %278 = llvm.icmp "eq" %254, %277 : !llvm.ptr
      scf.yield %278 : i1
    }
    cf.cond_br %275, ^bb48, ^bb49
    ^bb48:
      %279 = arith.constant 1 : i32
      func.return %279 : i32
    ^bb49:
      cf.br ^bb50
    ^bb50:
    %280 = arith.constant 0 : i32
    %281 = arith.constant 0 : i32
    %282 = arith.extsi %280 : i32 to i64
    %283 = arith.extsi %281 : i32 to i64
    %284 = llvm.getelementptr %254[%283] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %282, %284 : i64, !llvm.ptr
    %285 = arith.constant 1 : i32
    %287 = arith.extsi %285 : i32 to i64
    %286 = arith.cmpi sge, %180, %287 : i64
    cf.cond_br %286, ^bb51, ^bb52
    ^bb51:
      %288 = arith.constant 1 : i32
      %289 = arith.constant 1 : i32
      %290 = arith.extsi %288 : i32 to i64
      %291 = arith.extsi %289 : i32 to i64
      %292 = llvm.getelementptr %254[%291] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %290, %292 : i64, !llvm.ptr
      cf.br ^bb53
    ^bb52:
      cf.br ^bb53
    ^bb53:
    %293 = arith.constant 2 : i32
    %294 = arith.constant 1 : i32
    %296 = arith.extsi %294 : i32 to i64
    %295 = arith.addi %180, %296 : i64
    %297 = arith.index_cast %293 : i32 to index
    %298 = arith.index_cast %295 : i32 to index
    %300 = arith.constant 1 : index
    %301 = arith.constant -1 : index
    %302 = arith.cmpi sle, %297, %298 : index
    %299 = arith.select %302, %300, %301 : index
    cf.br ^bb54(%297 : index)
    ^bb54(%303: index):
    %304 = arith.cmpi slt, %303, %298 : index
    %305 = arith.cmpi sgt, %303, %298 : index
    %306 = arith.select %302, %304, %305 : i1
    cf.cond_br %306, ^bb55(%303 : index), ^bb56(%303 : index)
    ^bb55(%307: index):
      %309 = arith.index_cast %307 : index to i64
      %310 = llvm.getelementptr %248[%309] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %308 = llvm.load %310 : !llvm.ptr -> i64
      %311 = arith.constant 0 : i32
      %313 = arith.extsi %311 : i32 to i64
      %312 = arith.cmpi eq, %308, %313 : i64
      cf.cond_br %312, ^bb57, ^bb58
      ^bb57:
        %314 = arith.index_cast %307 : index to i64
        %315 = arith.index_cast %307 : index to i64
        %316 = llvm.getelementptr %248[%315] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %314, %316 : i64, !llvm.ptr
        %317 = llvm.load %272 : !llvm.ptr -> i64
        %318 = arith.index_cast %307 : index to i64
        %319 = llvm.getelementptr %260[%317] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %318, %319 : i64, !llvm.ptr
        %320 = llvm.load %272 : !llvm.ptr -> i64
        %321 = arith.constant 1 : i32
        %323 = arith.extsi %321 : i32 to i64
        %322 = arith.addi %320, %323 : i64
        llvm.store %322, %272 : i64, !llvm.ptr
        %325 = llvm.mlir.addressof @MOD : !llvm.ptr
        %326 = llvm.load %325 : !llvm.ptr -> i64
        %327 = arith.index_cast %307 : index to i64
        %324 = func.call @mod_pow(%327, %190, %326) : (i64, i64, i64) -> i64
        %328 = arith.index_cast %307 : index to i64
        %329 = llvm.getelementptr %254[%328] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %324, %329 : i64, !llvm.ptr
        cf.br ^bb59
      ^bb58:
        cf.br ^bb59
      ^bb59:
      %331 = arith.index_cast %307 : index to i64
      %332 = llvm.getelementptr %254[%331] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %330 = llvm.load %332 : !llvm.ptr -> i64
      %334 = arith.index_cast %307 : index to i64
      %335 = llvm.getelementptr %248[%334] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %333 = llvm.load %335 : !llvm.ptr -> i64
      %336 = arith.constant 0 : i32
      %337 = llvm.load %272 : !llvm.ptr -> i64
      %338 = arith.index_cast %336 : i32 to index
      %339 = arith.index_cast %337 : i32 to index
      %341 = arith.constant 1 : index
      %342 = arith.constant -1 : index
      %343 = arith.cmpi sle, %338, %339 : index
      %340 = arith.select %343, %341, %342 : index
      cf.br ^bb60(%338 : index)
      ^bb60(%344: index):
      %345 = arith.cmpi slt, %344, %339 : index
      %346 = arith.cmpi sgt, %344, %339 : index
      %347 = arith.select %343, %345, %346 : i1
      cf.cond_br %347, ^bb61(%344 : index), ^bb62(%344 : index)
      ^bb61(%348: index):
        %350 = arith.index_cast %348 : index to i64
        %351 = llvm.getelementptr %260[%350] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %349 = llvm.load %351 : !llvm.ptr -> i64
        %353 = arith.index_cast %307 : index to i32
        %354 = arith.trunci %349 : i64 to i32
        %352 = arith.muli %353, %354 : i32
        %355 = arith.extsi %352 : i32 to i64
        %356 = arith.cmpi sgt, %355, %180 : i64
        cf.cond_br %356, ^bb63, ^bb64
        ^bb63:
          cf.br ^bb62(%348 : index)
        ^bb64:
          cf.br ^bb65
        ^bb65:
        %357 = llvm.getelementptr %248[%355] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %349, %357 : i64, !llvm.ptr
        %358 = arith.extsi %330 : i64 to i128
        %360 = llvm.getelementptr %254[%349] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %359 = llvm.load %360 : !llvm.ptr -> i64
        %361 = arith.extsi %359 : i64 to i128
        %363 = arith.trunci %358 : i128 to i64
        %364 = arith.trunci %361 : i128 to i64
        %362 = arith.muli %363, %364 : i64
        %365 = llvm.mlir.addressof @MOD : !llvm.ptr
        %366 = llvm.load %365 : !llvm.ptr -> i64
        %367 = arith.extsi %366 : i64 to i128
        %369 = arith.trunci %367 : i128 to i64
        %368 = arith.remsi %362, %369 : i64
        %370 = arith.extsi %368 : i64 to i128
        %371 = arith.trunci %370 : i128 to i64
        %372 = llvm.getelementptr %254[%355] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %371, %372 : i64, !llvm.ptr
        %373 = arith.cmpi eq, %349, %333 : i64
        cf.cond_br %373, ^bb66, ^bb67
        ^bb66:
          cf.br ^bb62(%348 : index)
        ^bb67:
          cf.br ^bb68
        ^bb68:
        %374 = arith.addi %348, %340 : index
        cf.br ^bb60(%374 : index)
      ^bb62(%375: index):
      %376 = arith.addi %307, %299 : index
      cf.br ^bb54(%376 : index)
    ^bb56(%377: index):
    %378 = llvm.mlir.addressof @MOD : !llvm.ptr
    %379 = llvm.load %378 : !llvm.ptr -> i64
    %380 = arith.constant 1 : i32
    %382 = arith.extsi %380 : i32 to i64
    %381 = arith.addi %379, %382 : i64
    %383 = arith.constant 2 : i32
    %385 = arith.extsi %383 : i32 to i64
    %384 = arith.divsi %381, %385 : i64
    %386 = llvm.mlir.constant(1 : i64) : i64
    %387 = llvm.alloca %386 x i64 : (i64) -> !llvm.ptr
    llvm.store %384, %387 : i64, !llvm.ptr
    %388 = llvm.mlir.addressof @MOD : !llvm.ptr
    %389 = llvm.load %388 : !llvm.ptr -> i64
    %390 = arith.constant 2 : i32
    %392 = arith.extsi %390 : i32 to i64
    %391 = arith.subi %389, %392 : i64
    %393 = arith.constant 1 : i32
    %395 = arith.extsi %393 : i32 to i64
    %394 = arith.addi %176, %395 : i64
    %396 = llvm.mlir.addressof @MOD : !llvm.ptr
    %397 = llvm.load %396 : !llvm.ptr -> i64
    %398 = arith.constant 1 : i32
    %400 = arith.extsi %398 : i32 to i64
    %399 = arith.subi %397, %400 : i64
    %401 = arith.constant 1 : i32
    %403 = arith.extsi %401 : i32 to i64
    %402 = arith.addi %178, %403 : i64
    %404 = llvm.mlir.addressof @MOD : !llvm.ptr
    %405 = llvm.load %404 : !llvm.ptr -> i64
    %406 = arith.remsi %402, %405 : i64
    %407 = arith.constant 1 : i32
    %408 = arith.extsi %407 : i32 to i64
    %409 = llvm.mlir.constant(1 : i64) : i64
    %410 = llvm.alloca %409 x i64 : (i64) -> !llvm.ptr
    llvm.store %408, %410 : i64, !llvm.ptr
    %411 = arith.constant 1 : i32
    %412 = arith.extsi %411 : i32 to i64
    %413 = llvm.mlir.constant(1 : i64) : i64
    %414 = llvm.alloca %413 x i64 : (i64) -> !llvm.ptr
    llvm.store %412, %414 : i64, !llvm.ptr
    %415 = arith.constant 0 : i32
    %416 = arith.extsi %415 : i32 to i64
    %417 = llvm.mlir.constant(1 : i64) : i64
    %418 = llvm.alloca %417 x i64 : (i64) -> !llvm.ptr
    llvm.store %416, %418 : i64, !llvm.ptr
    %419 = arith.constant 0 : i32
    %420 = arith.constant 1 : i32
    %422 = arith.extsi %420 : i32 to i64
    %421 = arith.addi %180, %422 : i64
    %423 = arith.index_cast %419 : i32 to index
    %424 = arith.index_cast %421 : i32 to index
    %426 = arith.constant 1 : index
    %427 = arith.constant -1 : index
    %428 = arith.cmpi sle, %423, %424 : index
    %425 = arith.select %428, %426, %427 : index
    cf.br ^bb69(%423 : index)
    ^bb69(%429: index):
    %430 = arith.cmpi slt, %429, %424 : index
    %431 = arith.cmpi sgt, %429, %424 : index
    %432 = arith.select %428, %430, %431 : i1
    cf.cond_br %432, ^bb70(%429 : index), ^bb71(%429 : index)
    ^bb70(%433: index):
      %434 = arith.constant 1 : i32
      %435 = arith.extsi %434 : i32 to i64
      %436 = llvm.mlir.constant(1 : i64) : i64
      %437 = llvm.alloca %436 x i64 : (i64) -> !llvm.ptr
      llvm.store %435, %437 : i64, !llvm.ptr
      %438 = arith.constant 1 : i32
      %440 = arith.index_cast %433 : index to i32
      %439 = arith.cmpi eq, %440, %438 : i32
      cf.cond_br %439, ^bb72, ^bb73
      ^bb72:
        llvm.store %406, %437 : i64, !llvm.ptr
        cf.br ^bb74
      ^bb73:
        cf.br ^bb74
      ^bb74:
      %441 = arith.constant 2 : i32
      %443 = arith.index_cast %433 : index to i32
      %442 = arith.cmpi sge, %443, %441 : i32
      cf.cond_br %442, ^bb75, ^bb76
      ^bb75:
        %445 = arith.index_cast %433 : index to i64
        %446 = llvm.getelementptr %254[%445] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %444 = llvm.load %446 : !llvm.ptr -> i64
        %447 = arith.constant 1 : i32
        %449 = arith.extsi %447 : i32 to i64
        %448 = arith.subi %444, %449 : i64
        %450 = llvm.mlir.addressof @MOD : !llvm.ptr
        %451 = llvm.load %450 : !llvm.ptr -> i64
        %452 = arith.addi %448, %451 : i64
        %453 = arith.extsi %452 : i64 to i128
        %455 = arith.constant 1 : i32
        %457 = arith.index_cast %433 : index to i32
        %456 = arith.subi %457, %455 : i32
        %458 = arith.extsi %456 : i32 to i64
        %459 = llvm.getelementptr %191[%458] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %454 = llvm.load %459 : !llvm.ptr -> i64
        %460 = arith.extsi %454 : i64 to i128
        %462 = arith.trunci %453 : i128 to i64
        %463 = arith.trunci %460 : i128 to i64
        %461 = arith.muli %462, %463 : i64
        %464 = llvm.mlir.addressof @MOD : !llvm.ptr
        %465 = llvm.load %464 : !llvm.ptr -> i64
        %466 = arith.extsi %465 : i64 to i128
        %468 = arith.trunci %466 : i128 to i64
        %467 = arith.remsi %461, %468 : i64
        %469 = arith.extsi %467 : i64 to i128
        %470 = arith.trunci %469 : i128 to i64
        llvm.store %470, %437 : i64, !llvm.ptr
        cf.br ^bb77
      ^bb76:
        cf.br ^bb77
      ^bb77:
      %471 = arith.constant 1 : i32
      %472 = llvm.load %414 : !llvm.ptr -> i64
      %473 = arith.muli %399, %472 : i64
      %474 = llvm.mlir.addressof @MOD : !llvm.ptr
      %475 = llvm.load %474 : !llvm.ptr -> i64
      %476 = arith.remsi %473, %475 : i64
      %478 = arith.extsi %471 : i32 to i64
      %477 = arith.subi %478, %476 : i64
      %479 = llvm.mlir.addressof @MOD : !llvm.ptr
      %480 = llvm.load %479 : !llvm.ptr -> i64
      %481 = arith.addi %477, %480 : i64
      %482 = llvm.mlir.addressof @MOD : !llvm.ptr
      %483 = llvm.load %482 : !llvm.ptr -> i64
      %484 = arith.remsi %481, %483 : i64
      %485 = llvm.load %387 : !llvm.ptr -> i64
      %486 = arith.extsi %485 : i64 to i128
      %487 = arith.extsi %484 : i64 to i128
      %489 = arith.trunci %486 : i128 to i64
      %490 = arith.trunci %487 : i128 to i64
      %488 = arith.muli %489, %490 : i64
      %491 = llvm.mlir.addressof @MOD : !llvm.ptr
      %492 = llvm.load %491 : !llvm.ptr -> i64
      %493 = arith.extsi %492 : i64 to i128
      %495 = arith.trunci %493 : i128 to i64
      %494 = arith.remsi %488, %495 : i64
      %496 = arith.extsi %494 : i64 to i128
      %497 = arith.constant 1 : i32
      %498 = arith.trunci %496 : i128 to i64
      %500 = arith.extsi %497 : i32 to i64
      %499 = arith.subi %500, %498 : i64
      %501 = llvm.mlir.addressof @MOD : !llvm.ptr
      %502 = llvm.load %501 : !llvm.ptr -> i64
      %503 = arith.addi %499, %502 : i64
      %504 = llvm.mlir.addressof @MOD : !llvm.ptr
      %505 = llvm.load %504 : !llvm.ptr -> i64
      %506 = arith.remsi %503, %505 : i64
      %507 = llvm.load %437 : !llvm.ptr -> i64
      %508 = arith.extsi %507 : i64 to i128
      %509 = arith.extsi %506 : i64 to i128
      %511 = arith.trunci %508 : i128 to i64
      %512 = arith.trunci %509 : i128 to i64
      %510 = arith.muli %511, %512 : i64
      %513 = llvm.mlir.addressof @MOD : !llvm.ptr
      %514 = llvm.load %513 : !llvm.ptr -> i64
      %515 = arith.extsi %514 : i64 to i128
      %517 = arith.trunci %515 : i128 to i64
      %516 = arith.remsi %510, %517 : i64
      %518 = arith.extsi %516 : i64 to i128
      %519 = llvm.load %418 : !llvm.ptr -> i64
      %520 = arith.trunci %518 : i128 to i64
      %521 = arith.addi %519, %520 : i64
      %522 = llvm.mlir.addressof @MOD : !llvm.ptr
      %523 = llvm.load %522 : !llvm.ptr -> i64
      %524 = arith.remsi %521, %523 : i64
      llvm.store %524, %418 : i64, !llvm.ptr
      %526 = arith.index_cast %433 : index to i32
      %527 = arith.trunci %180 : i64 to i32
      %525 = arith.cmpi eq, %526, %527 : i32
      cf.cond_br %525, ^bb78, ^bb79
      ^bb78:
        cf.br ^bb71(%433 : index)
      ^bb79:
        cf.br ^bb80
      ^bb80:
      %528 = llvm.load %410 : !llvm.ptr -> i64
      %529 = arith.extsi %528 : i64 to i128
      %531 = arith.trunci %394 : i64 to i32
      %532 = arith.index_cast %433 : index to i32
      %530 = arith.subi %531, %532 : i32
      %533 = arith.extsi %530 : i32 to i128
      %535 = arith.trunci %529 : i128 to i64
      %536 = arith.trunci %533 : i128 to i64
      %534 = arith.muli %535, %536 : i64
      %537 = llvm.mlir.addressof @MOD : !llvm.ptr
      %538 = llvm.load %537 : !llvm.ptr -> i64
      %539 = arith.extsi %538 : i64 to i128
      %541 = arith.trunci %539 : i128 to i64
      %540 = arith.remsi %534, %541 : i64
      %542 = arith.extsi %540 : i64 to i128
      %544 = arith.constant 1 : i32
      %546 = arith.index_cast %433 : index to i32
      %545 = arith.addi %546, %544 : i32
      %547 = arith.extsi %545 : i32 to i64
      %548 = llvm.getelementptr %191[%547] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %543 = llvm.load %548 : !llvm.ptr -> i64
      %549 = arith.extsi %543 : i64 to i128
      %551 = arith.trunci %542 : i128 to i64
      %552 = arith.trunci %549 : i128 to i64
      %550 = arith.muli %551, %552 : i64
      %553 = llvm.mlir.addressof @MOD : !llvm.ptr
      %554 = llvm.load %553 : !llvm.ptr -> i64
      %555 = arith.extsi %554 : i64 to i128
      %557 = arith.trunci %555 : i128 to i64
      %556 = arith.remsi %550, %557 : i64
      llvm.store %556, %410 : i64, !llvm.ptr
      %558 = llvm.load %410 : !llvm.ptr -> i64
      %559 = arith.extsi %558 : i64 to i128
      %560 = arith.extsi %391 : i64 to i128
      %562 = arith.trunci %559 : i128 to i64
      %563 = arith.trunci %560 : i128 to i64
      %561 = arith.muli %562, %563 : i64
      %564 = llvm.mlir.addressof @MOD : !llvm.ptr
      %565 = llvm.load %564 : !llvm.ptr -> i64
      %566 = arith.extsi %565 : i64 to i128
      %568 = arith.trunci %566 : i128 to i64
      %567 = arith.remsi %561, %568 : i64
      %569 = arith.extsi %567 : i64 to i128
      %570 = arith.trunci %569 : i128 to i64
      llvm.store %570, %410 : i64, !llvm.ptr
      %571 = llvm.load %414 : !llvm.ptr -> i64
      %572 = llvm.load %410 : !llvm.ptr -> i64
      %573 = arith.addi %571, %572 : i64
      %574 = llvm.mlir.addressof @MOD : !llvm.ptr
      %575 = llvm.load %574 : !llvm.ptr -> i64
      %576 = arith.remsi %573, %575 : i64
      llvm.store %576, %414 : i64, !llvm.ptr
      %577 = llvm.load %387 : !llvm.ptr -> i64
      %578 = arith.muli %577, %384 : i64
      %579 = llvm.mlir.addressof @MOD : !llvm.ptr
      %580 = llvm.load %579 : !llvm.ptr -> i64
      %581 = arith.remsi %578, %580 : i64
      llvm.store %581, %387 : i64, !llvm.ptr
      %582 = arith.addi %433, %425 : index
      cf.br ^bb69(%582 : index)
    ^bb71(%583: index):
    %584 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %585 = llvm.load %418 : !llvm.ptr -> i64
    %586 = llvm.call @printf(%584, %585) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    func.call @free(%260) : (!llvm.ptr) -> ()
    func.call @free(%254) : (!llvm.ptr) -> ()
    func.call @free(%248) : (!llvm.ptr) -> ()
    func.call @free(%191) : (!llvm.ptr) -> ()
    %591 = arith.constant 0 : i32
    func.return %591 : i32
  }
}