Problem 657

Incomplete Words: I(10^7, 10^12) mod 1e9+7. Inclusion-exclusion: sum_{s=1..alpha} (-1)^{s+1} C(alpha,s) * geom_sum(alpha-s, n)

Answer219493139
Output219493139
StatusPASS
Native helperno
Runtime6900 ms
Peak memory157344 KB
Time complexityO(n^2) (estimated)
Space complexityO(n) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^2)O(1)
Space complexityO(n)O(1)
ApproachFlow solutionClosed-form formula
VerdictSuboptimal

Flow source

# Project Euler 657
# Incomplete Words: I(10^7, 10^12) mod 1e9+7.
# Inclusion-exclusion: sum_{s=1..alpha} (-1)^{s+1} C(alpha,s) * geom_sum(alpha-s, n)

import euler.nt { mod_pow }

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

const MOD: i64 = 1000000007

# Return sum_{k=0..n} r^k mod mod
function geom_sum(r: i64, n: i64, mod: i64) -> i64 {
    if n < 0 { return 0 }
    let r_mod: i64 = r % mod
    if r_mod == 1 { return (n + 1) % mod }
    if r_mod == 0 { return 1 }
    let rn1: i64 = mod_pow(r_mod, n + 1, mod)
    let num: i64 = (rn1 - 1 + mod) % mod
    let den: i64 = mod_pow((r_mod - 1 + mod) % mod, mod - 2, mod)
    let t: i128 = (num as i128) * (den as i128) % (mod as i128)
    return t as i64
}

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

    # Precompute modular inverses 1..alpha using linear recurrence
    let inv: ptr<i64> = calloc(alpha + 1, 8)
    if inv == null { return 1 }
    inv[1] = 1
    for i in 2..(alpha + 1) {
        inv[i] = (MOD - (MOD / i) * inv[MOD % i] % MOD) % MOD
    }

    # Effective exponent: (n+1) mod (MOD-1) by Fermat's little theorem
    let exp: i64 = (n + 1) % (MOD - 1)

    # Precompute r^exp mod MOD for r=0..alpha-1
    # r=0: 0^exp = 0 (exp > 0)
    # r=1: 1
    # For r >= 2: compute via mod_pow
    # But 10^7 mod_pow calls is too slow. Instead, note that
    # r^exp = r^(exp) and we can compute all at once using:
    # For each r, r^exp = product of r^(2^i) for set bits of exp.
    # With exp ~ 10^12 % 10^9 ~ 999994005, that's still ~30 bits.
    # Better: use baby-step giant-step or just compute in batches.
    # Actually, let's just compute r^exp for each r directly.
    # 10^7 * 30 multiplications = 3*10^8, should be ~3 seconds in C.

    let pow_table: ptr<i64> = calloc(alpha, 8)
    if pow_table == null { return 1 }
    pow_table[0] = 0  # 0^exp = 0
    if alpha > 1 { pow_table[1] = 1 }
    for r in 2..alpha {
        let mut result: i64 = 1
        let mut base: i64 = r
        let mut e: i64 = exp
        while e > 0 {
            if (e & 1) == 1 {
                let t: i128 = (result as i128) * (base as i128) % (MOD as i128)
                result = t as i64
            }
            let t2: i128 = (base as i128) * (base as i128) % (MOD as i128)
            base = t2 as i64
            e = e / 2
        }
        pow_table[r] = result
    }

    let mut res: i64 = 0
    let mut comb: i64 = 1  # C(alpha, 0)

    for s in 1..(alpha + 1) {
        # C(alpha,s) from C(alpha,s-1)
        let t1: i128 = (comb as i128) * ((alpha - s + 1) as i128) % (MOD as i128)
        comb = (t1 * (inv[s] as i128) % (MOD as i128)) as i64

        let r: i64 = alpha - s
        # geom_sum(r, n) = (r^(n+1) - 1) / (r - 1) for r >= 2
        # = (n+1) for r = 1
        # = 1 for r = 0
        let mut gs: i64 = 0
        if r == 0 {
            gs = 1
        } else {
            if r == 1 {
                gs = (n + 1) % MOD
            } else {
                let rn1: i64 = pow_table[r]
                let num: i64 = (rn1 - 1 + MOD) % MOD
                let den: i64 = inv[r - 1]
                let t: i128 = (num as i128) * (den as i128) % (MOD as i128)
                gs = t as i64
            }
        }

        let t2: i128 = (comb as i128) * (gs as i128) % (MOD as i128)

        if s % 2 == 1 {
            res = (res + (t2 as i64)) % MOD
        } else {
            res = (res - (t2 as i64) + MOD) % MOD
        }
    }

    printf("%lld\n", (res % MOD + MOD) % MOD)

    free(pow_table)
    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);
int64_t geom_sum_i64_i64_i64(int64_t r, int64_t n, int64_t mod);
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;
}



int64_t geom_sum_i64_i64_i64(int64_t r, int64_t n, int64_t mod) {
    if (n < 0) {
        return 0;
    }
    int64_t r_mod = FLOW_CHECKED_MOD((r), (mod));
    if (r_mod == 1) {
        return FLOW_CHECKED_MOD(((n + 1)), (mod));
    }
    if (r_mod == 0) {
        return 1;
    }
    int64_t rn1 = mod_pow_i64_i64_i64(r_mod, (n + 1), mod);
    int64_t num = FLOW_CHECKED_MOD((((rn1 - 1) + mod)), (mod));
    int64_t den = mod_pow_i64_i64_i64(FLOW_CHECKED_MOD((((r_mod - 1) + mod)), (mod)), (mod - 2), mod);
    __int128 t = FLOW_CHECKED_MOD(((((__int128)(num)) * ((__int128)(den)))), (((__int128)(mod))));
    return ((int64_t)(t));
}

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