Problem 685

Inverse Digit Sum II: S(10^4) = sum f(n^3, n^4) mod 1e9+7, where f(s, m) is the m-th positive integer with digit sum s. Numbers with digit sum s and d digits are all-9 strings with a small total "deficiency" t = 9d - s spread over the digits (first digit loses at most 8). Choose the digit count by comparing m against per-length counts, then unrank digit by digit: at each position try the largest deficiency first, counting completions with capped-at-1e30 i128 binomials (any capped count exceeds every possible m, so comparisons stay exact). Runs of unchanged 9s are jumped in closed form. The value mod p is 10^d - 1 minus the few lowered digits.

Answer662878999
Output662878999
StatusPASS
Native helperno
Runtime20 ms
Peak memory1168 KB
Time complexityO(n) (estimated)
Space complexityO(1) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n)O(n)
Space complexityO(1)O(n)
ApproachFlow solutionBig-integer arithmetic
VerdictOptimal

Flow source

# Project Euler 685
# Inverse Digit Sum II: S(10^4) = sum f(n^3, n^4) mod 1e9+7, where f(s, m)
# is the m-th positive integer with digit sum s.
#
# Numbers with digit sum s and d digits are all-9 strings with a small
# total "deficiency" t = 9d - s spread over the digits (first digit loses
# at most 8).  Choose the digit count by comparing m against per-length
# counts, then unrank digit by digit: at each position try the largest
# deficiency first, counting completions with capped-at-1e30 i128
# binomials (any capped count exceeds every possible m, so comparisons
# stay exact).  Runs of unchanged 9s are jumped in closed form.  The value
# mod p is 10^d - 1 minus the few lowered digits.

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

const MOD: i64 = 1000000007
const KMAX: i64 = 10000

function powmod(base: i64, exp: i64) -> i64 {
    let mut result: i64 = 1
    let mut b: i64 = base % MOD
    let mut e: i64 = exp
    while e > 0 {
        if (e & 1) == 1 {
            result = result * b % MOD
        }
        b = b * b % MOD
        e = e >> 1
    }
    return result
}

function cap128() -> i128 {
    let a: i128 = 1000000000000000 as i128
    return a * a          # 1e30
}

# C(n, k) exact in i128, saturating at 1e30
function binom_capped(n: i64, k0: i64) -> i128 {
    if k0 < 0 || n < 0 || k0 > n {
        return 0 as i128
    }
    let mut k: i64 = k0
    if n - k < k {
        k = n - k
    }
    let CAP: i128 = cap128()
    let mut c: i128 = 1 as i128
    let mut i: i64 = 1
    while i <= k {
        let fac: i128 = (n - k + i) as i128
        if c > CAP / fac {
            return CAP
        }
        c = c * fac / (i as i128)
        if c >= CAP {
            return CAP
        }
        i = i + 1
    }
    return c
}

# number of ways to write tau as rho digits each in [0,9]; capped at 1e30
function Wcnt(rho: i64, tau: i64) -> i128 {
    if tau < 0 || tau > 9 * rho {
        return 0 as i128
    }
    if rho == 0 {
        if tau == 0 {
            return 1 as i128
        }
        return 0 as i128
    }
    let CAP: i128 = cap128()
    let mut tot: i128 = 0 as i128
    let mut sign: i64 = 1
    let mut k: i64 = 0
    let mut t2: i64 = tau
    while t2 >= 0 {
        let term: i128 = binom_capped(rho, k) * 1 as i128 * binom_capped(t2 + rho - 1, t2)
        # (binom_capped(rho,k) is tiny for k<=3; product cannot overflow the cap regime)
        if term >= CAP {
            # capped counts always exceed any m; sign is + here (k=0 dominates)
            return CAP
        }
        if sign == 1 {
            tot = tot + term
        } else {
            tot = tot - term
        }
        sign = 0 - sign
        k = k + 1
        t2 = t2 - 10
    }
    if tot < 0 as i128 {
        tot = 0 as i128
    }
    if tot > CAP {
        tot = CAP
    }
    return tot
}

# d-digit numbers with deficiency t (first digit >= 1)
function Wfull(d: i64, t: i64) -> i128 {
    let CAP: i128 = cap128()
    let mut tot: i128 = 0 as i128
    let mut b1: i64 = 0
    while b1 <= 8 && b1 <= t {
        tot = tot + Wcnt(d - 1, t - b1)
        if tot > CAP {
            tot = CAP
        }
        b1 = b1 + 1
    }
    return tot
}

# f(s, m) mod MOD
function f_mod(s: i64, m0: i64) -> i64 {
    let mut d: i64 = (s + 8) / 9
    let mut t: i64 = 9 * d - s
    let mut m: i64 = m0
    let mut choosing: i64 = 1
    while choosing == 1 {
        let tot: i128 = Wfull(d, t)
        if (m as i128) > tot {
            m = m - (tot as i64)
            d = d + 1
            t = t + 9
        } else {
            choosing = 0
        }
    }

    # unrank: sparse deviations (position, lowered-by)
    let dpos: ptr<i64> = calloc(64, 8)
    let dval: ptr<i64> = calloc(64, 8)
    let mut nd: i64 = 0
    let mut i: i64 = 1
    let mut trem: i64 = t
    while trem > 0 {
        let r: i64 = d - i + 1
        let mut cap: i64 = 9
        if i == 1 {
            cap = 8
        }
        let mut placed: i64 = 0
        let mut b: i64 = trem
        if b > cap {
            b = cap
        }
        while b >= 1 && placed == 0 {
            let w: i128 = Wcnt(r - 1, trem - b)
            if (m as i128) > w {
                m = m - (w as i64)
                b = b - 1
            } else {
                dpos[nd] = i
                dval[nd] = b
                nd = nd + 1
                trem = trem - b
                i = i + 1
                placed = 1
            }
        }
        if placed == 0 {
            # this position keeps digit 9; jump the run
            if trem == 1 {
                # the m-th remaining vector has its single 1 at position i+m
                dpos[nd] = i + m
                dval[nd] = 1
                nd = nd + 1
                trem = 0
            } else {
                if trem == 2 {
                    # cum(q) = sum_{j=1..q} (r-j) = q*r - q(q+1)/2 in i128
                    let mut lo: i64 = 1
                    let mut hi: i64 = r - 1
                    while lo < hi {
                        let mid: i64 = (lo + hi) / 2
                        let cum: i128 = (mid as i128) * (r as i128)
                            - (mid as i128) * ((mid + 1) as i128) / (2 as i128)
                        if cum >= (m as i128) {
                            hi = mid
                        } else {
                            lo = mid + 1
                        }
                    }
                    let q: i64 = lo
                    let used: i128 = ((q - 1) as i128) * (r as i128)
                        - ((q - 1) as i128) * (q as i128) / (2 as i128)
                    m = m - (used as i64)
                    i = i + q
                } else {
                    i = i + 1
                }
            }
        }
    }

    # value = (10^d - 1) - sum b * 10^(d - pos)  (mod MOD)
    let mut v: i64 = (powmod(10, d) - 1 + MOD) % MOD
    let mut u: i64 = 0
    while u < nd {
        v = (v - dval[u] * powmod(10, d - dpos[u]) % MOD + MOD) % MOD
        u = u + 1
    }
    free(dpos)
    free(dval)
    return v
}

function main() -> i32 {
    let mut S: i64 = 0
    let mut n: i64 = 1
    while n <= KMAX {
        let s: i64 = n * n * n
        let m: i64 = s * n
        S = (S + f_mod(s, m)) % MOD
        n = n + 1
    }
    printf("%lld\n", S)
    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 powmod_i64_i64(int64_t base, int64_t exp);
__int128 cap128(void);
__int128 binom_capped_i64_i64(int64_t n, int64_t k0);
__int128 Wcnt_i64_i64(int64_t rho, int64_t tau);
__int128 Wfull_i64_i64(int64_t d, int64_t t);
int64_t f_mod_i64_i64(int64_t s, int64_t m0);
int32_t main(void);

static const int64_t MOD = 1000000007;
static const int64_t KMAX = 10000;



int64_t powmod_i64_i64(int64_t base, int64_t exp) {
    int64_t result = 1;
    int64_t b = FLOW_CHECKED_MOD((base), (MOD));
    int64_t e = exp;
    while (e > 0) {
        if ((e & 1) == 1) {
            result = FLOW_CHECKED_MOD(((result * b)), (MOD));
        }
        b = FLOW_CHECKED_MOD(((b * b)), (MOD));
        e = FLOW_CHECKED_SHR((e), (1));
    }
    return result;
}

__int128 cap128(void) {
    __int128 a = ((__int128)(1000000000000000));
    return (a * a);
}

__int128 binom_capped_i64_i64(int64_t n, int64_t k0) {
    if (((k0 < 0 || n < 0) || k0 > n)) {
        return ((__int128)(0));
    }
    int64_t k = k0;
    if ((n - k) < k) {
        k = (n - k);
    }
    __int128 CAP = cap128();
    __int128 c = ((__int128)(1));
    int64_t i = 1;
    while (i <= k) {
        __int128 fac = ((__int128)(((n - k) + i)));
        if (c > FLOW_CHECKED_DIV((CAP), (fac))) {
            return CAP;
        }
        c = FLOW_CHECKED_DIV(((c * fac)), (((__int128)(i))));
        if (c >= CAP) {
            return CAP;
        }
        i = (i + 1);
    }
    return c;
}

__int128 Wcnt_i64_i64(int64_t rho, int64_t tau) {
    if ((tau < 0 || tau > (9 * rho))) {
        return ((__int128)(0));
    }
    if (rho == 0) {
        if (tau == 0) {
            return ((__int128)(1));
        }
        return ((__int128)(0));
    }
    __int128 CAP = cap128();
    __int128 tot = ((__int128)(0));
    int64_t sign = 1;
    int64_t k = 0;
    int64_t t2 = tau;
    while (t2 >= 0) {
        __int128 term = ((binom_capped_i64_i64(rho, k) * ((__int128)(1))) * binom_capped_i64_i64(((t2 + rho) - 1), t2));
        if (term >= CAP) {
            return CAP;
        }
        if (sign == 1) {
            tot = (tot + term);
        } else {
            tot = (tot - term);
        }
        sign = (0 - sign);
        k = (k + 1);
        t2 = (t2 - 10);
    }
    if (tot < ((__int128)(0))) {
        tot = ((__int128)(0));
    }
    if (tot > CAP) {
        tot = CAP;
    }
    return tot;
}

__int128 Wfull_i64_i64(int64_t d, int64_t t) {
    __int128 CAP = cap128();
    __int128 tot = ((__int128)(0));
    int64_t b1 = 0;
    while ((b1 <= 8 && b1 <= t)) {
        tot = (tot + Wcnt_i64_i64((d - 1), (t - b1)));
        if (tot > CAP) {
            tot = CAP;
        }
        b1 = (b1 + 1);
    }
    return tot;
}

int64_t f_mod_i64_i64(int64_t s, int64_t m0) {
    int64_t d = FLOW_CHECKED_DIV(((s + 8)), (9));
    int64_t t = ((9 * d) - s);
    int64_t m = m0;
    int64_t choosing = 1;
    while (choosing == 1) {
        __int128 tot = Wfull_i64_i64(d, t);
        if (((__int128)(m)) > tot) {
            m = (m - ((int64_t)(tot)));
            d = (d + 1);
            t = (t + 9);
        } else {
            choosing = 0;
        }
    }
    int64_t* dpos = (int64_t*)(calloc(64, 8));
    int64_t* dval = (int64_t*)(calloc(64, 8));
    int64_t nd = 0;
    int64_t i = 1;
    int64_t trem = t;
    while (trem > 0) {
        int64_t r = ((d - i) + 1);
        int64_t cap = 9;
        if (i == 1) {
            cap = 8;
        }
        int64_t placed = 0;
        int64_t b = trem;
        if (b > cap) {
            b = cap;
        }
        while ((b >= 1 && placed == 0)) {
            __int128 w = Wcnt_i64_i64((r - 1), (trem - b));
            if (((__int128)(m)) > w) {
                m = (m - ((int64_t)(w)));
                b = (b - 1);
            } else {
                dpos[nd] = i;
                dval[nd] = b;
                nd = (nd + 1);
                trem = (trem - b);
                i = (i + 1);
                placed = 1;
            }
        }
        if (placed == 0) {
            if (trem == 1) {
                dpos[nd] = (i + m);
                dval[nd] = 1;
                nd = (nd + 1);
                trem = 0;
            } else {
                if (trem == 2) {
                    int64_t lo = 1;
                    int64_t hi = (r - 1);
                    while (lo < hi) {
                        int64_t mid = FLOW_CHECKED_DIV(((lo + hi)), (2));
                        __int128 cum = ((((__int128)(mid)) * ((__int128)(r))) - FLOW_CHECKED_DIV(((((__int128)(mid)) * ((__int128)((mid + 1))))), (((__int128)(2)))));
                        if (cum >= ((__int128)(m))) {
                            hi = mid;
                        } else {
                            lo = (mid + 1);
                        }
                    }
                    int64_t q = lo;
                    __int128 used = ((((__int128)((q - 1))) * ((__int128)(r))) - FLOW_CHECKED_DIV(((((__int128)((q - 1))) * ((__int128)(q)))), (((__int128)(2)))));
                    m = (m - ((int64_t)(used)));
                    i = (i + q);
                } else {
                    i = (i + 1);
                }
            }
        }
    }
    int64_t v = FLOW_CHECKED_MOD((((powmod_i64_i64(10, d) - 1) + MOD)), (MOD));
    int64_t u = 0;
    while (u < nd) {
        v = FLOW_CHECKED_MOD((((v - FLOW_CHECKED_MOD(((dval[u] * powmod_i64_i64(10, (d - dpos[u])))), (MOD))) + MOD)), (MOD));
        u = (u + 1);
    }
    free(dpos);
    free(dval);
    return v;
}

int32_t main(void) {
    int64_t S = 0;
    int64_t n = 1;
    while (n <= KMAX) {
        int64_t s = ((n * n) * n);
        int64_t m = (s * n);
        S = FLOW_CHECKED_MOD(((S + f_mod_i64_i64(s, m))), (MOD));
        n = (n + 1);
    }
    printf("%lld\n", S);
    return 0;
}

Generated MLIR

module {
  llvm.func @printf(!llvm.ptr, ...) -> i32
  llvm.mlir.global internal constant @str_0("%lld\n\00") {addr_space = 0 : i32} : !llvm.array<6 x i8>
  func.func private @calloc(i64, i64) -> !llvm.ptr
  func.func private @free(!llvm.ptr) -> ()
  // Constant: MOD
  llvm.mlir.global internal constant @MOD(1000000007 : i64) : i64
  // Constant: KMAX
  llvm.mlir.global internal constant @KMAX(10000 : i64) : i64
  func.func @powmod(%arg0: i64, %arg1: i64) -> i64 {
    %0 = arith.constant 1 : i32
    %1 = arith.extsi %0 : i32 to i64
    %2 = llvm.mlir.constant(1 : i64) : i64
    %3 = llvm.alloca %2 x i64 : (i64) -> !llvm.ptr
    llvm.store %1, %3 : i64, !llvm.ptr
    %4 = llvm.mlir.addressof @MOD : !llvm.ptr
    %5 = llvm.load %4 : !llvm.ptr -> i64
    %6 = arith.remsi %arg0, %5 : i64
    %7 = llvm.mlir.constant(1 : i64) : i64
    %8 = llvm.alloca %7 x i64 : (i64) -> !llvm.ptr
    llvm.store %6, %8 : i64, !llvm.ptr
    %9 = llvm.mlir.constant(1 : i64) : i64
    %10 = llvm.alloca %9 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %10 : i64, !llvm.ptr
    cf.br ^bb0
    ^bb0:
    %11 = llvm.load %10 : !llvm.ptr -> i64
    %12 = arith.constant 0 : i32
    %14 = arith.extsi %12 : i32 to i64
    %13 = arith.cmpi sgt, %11, %14 : i64
    cf.cond_br %13, ^bb1, ^bb2
    ^bb1:
      %15 = llvm.load %10 : !llvm.ptr -> i64
      %16 = arith.constant 1 : i32
      %18 = arith.extsi %16 : i32 to i64
      %17 = arith.andi %15, %18 : i64
      %19 = arith.constant 1 : i32
      %21 = arith.extsi %19 : i32 to i64
      %20 = arith.cmpi eq, %17, %21 : i64
      cf.cond_br %20, ^bb3, ^bb4
      ^bb3:
        %22 = llvm.load %3 : !llvm.ptr -> i64
        %23 = llvm.load %8 : !llvm.ptr -> i64
        %24 = arith.muli %22, %23 : i64
        %25 = llvm.mlir.addressof @MOD : !llvm.ptr
        %26 = llvm.load %25 : !llvm.ptr -> i64
        %27 = arith.remsi %24, %26 : i64
        llvm.store %27, %3 : i64, !llvm.ptr
        cf.br ^bb5
      ^bb4:
        cf.br ^bb5
      ^bb5:
      %28 = llvm.load %8 : !llvm.ptr -> i64
      %29 = llvm.load %8 : !llvm.ptr -> i64
      %30 = arith.muli %28, %29 : i64
      %31 = llvm.mlir.addressof @MOD : !llvm.ptr
      %32 = llvm.load %31 : !llvm.ptr -> i64
      %33 = arith.remsi %30, %32 : i64
      llvm.store %33, %8 : i64, !llvm.ptr
      %34 = llvm.load %10 : !llvm.ptr -> i64
      %35 = arith.constant 1 : i32
      %37 = arith.extsi %35 : i32 to i64
      %36 = arith.shrsi %34, %37 : i64
      llvm.store %36, %10 : i64, !llvm.ptr
      cf.br ^bb0
    ^bb2:
    %38 = llvm.load %3 : !llvm.ptr -> i64
    func.return %38 : i64
  }
  func.func @cap128() -> i128 {
    %39 = arith.constant 999995705032704 : i32
    %40 = arith.extsi %39 : i32 to i128
    %42 = arith.trunci %40 : i128 to i64
    %43 = arith.trunci %40 : i128 to i64
    %41 = arith.muli %42, %43 : i64
    %44 = arith.extsi %41 : i64 to i128
    func.return %44 : i128
  }
  func.func @binom_capped(%arg0: i64, %arg1: i64) -> i128 {
    %45 = arith.constant 0 : i32
    %47 = arith.extsi %45 : i32 to i64
    %46 = arith.cmpi slt, %arg1, %47 : i64
    %48 = scf.if %46 -> (i1) {
      %49 = arith.constant true
      scf.yield %49 : i1
    } else {
      %50 = arith.constant 0 : i32
      %52 = arith.extsi %50 : i32 to i64
      %51 = arith.cmpi slt, %arg0, %52 : i64
      scf.yield %51 : i1
    }
    %53 = scf.if %48 -> (i1) {
      %54 = arith.constant true
      scf.yield %54 : i1
    } else {
      %55 = arith.cmpi sgt, %arg1, %arg0 : i64
      scf.yield %55 : i1
    }
    cf.cond_br %53, ^bb6, ^bb7
    ^bb6:
      %56 = arith.constant 0 : i32
      %57 = arith.extsi %56 : i32 to i128
      func.return %57 : i128
    ^bb7:
      cf.br ^bb8
    ^bb8:
    %58 = llvm.mlir.constant(1 : i64) : i64
    %59 = llvm.alloca %58 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %59 : i64, !llvm.ptr
    %60 = llvm.load %59 : !llvm.ptr -> i64
    %61 = arith.subi %arg0, %60 : i64
    %62 = llvm.load %59 : !llvm.ptr -> i64
    %63 = arith.cmpi slt, %61, %62 : i64
    cf.cond_br %63, ^bb9, ^bb10
    ^bb9:
      %64 = llvm.load %59 : !llvm.ptr -> i64
      %65 = arith.subi %arg0, %64 : i64
      llvm.store %65, %59 : i64, !llvm.ptr
      cf.br ^bb11
    ^bb10:
      cf.br ^bb11
    ^bb11:
    %66 = func.call @cap128() : () -> i128
    %67 = arith.constant 1 : i32
    %68 = arith.extsi %67 : i32 to i128
    %69 = llvm.mlir.constant(1 : i64) : i64
    %70 = llvm.alloca %69 x i128 : (i64) -> !llvm.ptr
    llvm.store %68, %70 : i128, !llvm.ptr
    %71 = arith.constant 1 : i32
    %72 = arith.extsi %71 : i32 to i64
    %73 = llvm.mlir.constant(1 : i64) : i64
    %74 = llvm.alloca %73 x i64 : (i64) -> !llvm.ptr
    llvm.store %72, %74 : i64, !llvm.ptr
    cf.br ^bb12
    ^bb12:
    %75 = llvm.load %74 : !llvm.ptr -> i64
    %76 = llvm.load %59 : !llvm.ptr -> i64
    %77 = arith.cmpi sle, %75, %76 : i64
    cf.cond_br %77, ^bb13, ^bb14
    ^bb13:
      %78 = llvm.load %59 : !llvm.ptr -> i64
      %79 = arith.subi %arg0, %78 : i64
      %80 = llvm.load %74 : !llvm.ptr -> i64
      %81 = arith.addi %79, %80 : i64
      %82 = arith.extsi %81 : i64 to i128
      %83 = llvm.load %70 : !llvm.ptr -> i128
      %85 = arith.trunci %66 : i128 to i64
      %86 = arith.trunci %82 : i128 to i64
      %84 = arith.divsi %85, %86 : i64
      %88 = arith.trunci %83 : i128 to i64
      %87 = arith.cmpi sgt, %88, %84 : i64
      cf.cond_br %87, ^bb15, ^bb16
      ^bb15:
        func.return %66 : i128
      ^bb16:
        cf.br ^bb17
      ^bb17:
      %89 = llvm.load %70 : !llvm.ptr -> i128
      %91 = arith.trunci %89 : i128 to i64
      %92 = arith.trunci %82 : i128 to i64
      %90 = arith.muli %91, %92 : i64
      %93 = llvm.load %74 : !llvm.ptr -> i64
      %94 = arith.extsi %93 : i64 to i128
      %96 = arith.trunci %94 : i128 to i64
      %95 = arith.divsi %90, %96 : i64
      %97 = arith.extsi %95 : i64 to i128
      llvm.store %97, %70 : i128, !llvm.ptr
      %98 = llvm.load %70 : !llvm.ptr -> i128
      %100 = arith.trunci %98 : i128 to i64
      %101 = arith.trunci %66 : i128 to i64
      %99 = arith.cmpi sge, %100, %101 : i64
      cf.cond_br %99, ^bb18, ^bb19
      ^bb18:
        func.return %66 : i128
      ^bb19:
        cf.br ^bb20
      ^bb20:
      %102 = llvm.load %74 : !llvm.ptr -> i64
      %103 = arith.constant 1 : i32
      %105 = arith.extsi %103 : i32 to i64
      %104 = arith.addi %102, %105 : i64
      llvm.store %104, %74 : i64, !llvm.ptr
      cf.br ^bb12
    ^bb14:
    %106 = llvm.load %70 : !llvm.ptr -> i128
    func.return %106 : i128
  }
  func.func @Wcnt(%arg0: i64, %arg1: i64) -> i128 {
    %107 = arith.constant 0 : i32
    %109 = arith.extsi %107 : i32 to i64
    %108 = arith.cmpi slt, %arg1, %109 : i64
    %110 = scf.if %108 -> (i1) {
      %111 = arith.constant true
      scf.yield %111 : i1
    } else {
      %112 = arith.constant 9 : i32
      %114 = arith.extsi %112 : i32 to i64
      %113 = arith.muli %114, %arg0 : i64
      %115 = arith.cmpi sgt, %arg1, %113 : i64
      scf.yield %115 : i1
    }
    cf.cond_br %110, ^bb21, ^bb22
    ^bb21:
      %116 = arith.constant 0 : i32
      %117 = arith.extsi %116 : i32 to i128
      func.return %117 : i128
    ^bb22:
      cf.br ^bb23
    ^bb23:
    %118 = arith.constant 0 : i32
    %120 = arith.extsi %118 : i32 to i64
    %119 = arith.cmpi eq, %arg0, %120 : i64
    cf.cond_br %119, ^bb24, ^bb25
    ^bb24:
      %121 = arith.constant 0 : i32
      %123 = arith.extsi %121 : i32 to i64
      %122 = arith.cmpi eq, %arg1, %123 : i64
      cf.cond_br %122, ^bb27, ^bb28
      ^bb27:
        %124 = arith.constant 1 : i32
        %125 = arith.extsi %124 : i32 to i128
        func.return %125 : i128
      ^bb28:
        cf.br ^bb29
      ^bb29:
      %126 = arith.constant 0 : i32
      %127 = arith.extsi %126 : i32 to i128
      func.return %127 : i128
    ^bb25:
      cf.br ^bb26
    ^bb26:
    %128 = func.call @cap128() : () -> i128
    %129 = arith.constant 0 : i32
    %130 = arith.extsi %129 : i32 to i128
    %131 = llvm.mlir.constant(1 : i64) : i64
    %132 = llvm.alloca %131 x i128 : (i64) -> !llvm.ptr
    llvm.store %130, %132 : i128, !llvm.ptr
    %133 = arith.constant 1 : i32
    %134 = arith.extsi %133 : i32 to i64
    %135 = llvm.mlir.constant(1 : i64) : i64
    %136 = llvm.alloca %135 x i64 : (i64) -> !llvm.ptr
    llvm.store %134, %136 : i64, !llvm.ptr
    %137 = arith.constant 0 : i32
    %138 = arith.extsi %137 : i32 to i64
    %139 = llvm.mlir.constant(1 : i64) : i64
    %140 = llvm.alloca %139 x i64 : (i64) -> !llvm.ptr
    llvm.store %138, %140 : i64, !llvm.ptr
    %141 = llvm.mlir.constant(1 : i64) : i64
    %142 = llvm.alloca %141 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %142 : i64, !llvm.ptr
    cf.br ^bb30
    ^bb30:
    %143 = llvm.load %142 : !llvm.ptr -> i64
    %144 = arith.constant 0 : i32
    %146 = arith.extsi %144 : i32 to i64
    %145 = arith.cmpi sge, %143, %146 : i64
    cf.cond_br %145, ^bb31, ^bb32
    ^bb31:
      %148 = llvm.load %140 : !llvm.ptr -> i64
      %147 = func.call @binom_capped(%arg0, %148) : (i64, i64) -> i128
      %149 = arith.constant 1 : i32
      %150 = arith.extsi %149 : i32 to i128
      %152 = arith.trunci %147 : i128 to i64
      %153 = arith.trunci %150 : i128 to i64
      %151 = arith.muli %152, %153 : i64
      %155 = llvm.load %142 : !llvm.ptr -> i64
      %156 = arith.addi %155, %arg0 : i64
      %157 = arith.constant 1 : i32
      %159 = arith.extsi %157 : i32 to i64
      %158 = arith.subi %156, %159 : i64
      %160 = llvm.load %142 : !llvm.ptr -> i64
      %154 = func.call @binom_capped(%158, %160) : (i64, i64) -> i128
      %162 = arith.trunci %154 : i128 to i64
      %161 = arith.muli %151, %162 : i64
      %163 = arith.extsi %161 : i64 to i128
      %165 = arith.trunci %163 : i128 to i64
      %166 = arith.trunci %128 : i128 to i64
      %164 = arith.cmpi sge, %165, %166 : i64
      cf.cond_br %164, ^bb33, ^bb34
      ^bb33:
        func.return %128 : i128
      ^bb34:
        cf.br ^bb35
      ^bb35:
      %167 = llvm.load %136 : !llvm.ptr -> i64
      %168 = arith.constant 1 : i32
      %170 = arith.extsi %168 : i32 to i64
      %169 = arith.cmpi eq, %167, %170 : i64
      cf.cond_br %169, ^bb36, ^bb37
      ^bb36:
        %171 = llvm.load %132 : !llvm.ptr -> i128
        %173 = arith.trunci %171 : i128 to i64
        %174 = arith.trunci %163 : i128 to i64
        %172 = arith.addi %173, %174 : i64
        %175 = arith.extsi %172 : i64 to i128
        llvm.store %175, %132 : i128, !llvm.ptr
        cf.br ^bb38
      ^bb37:
        %176 = llvm.load %132 : !llvm.ptr -> i128
        %178 = arith.trunci %176 : i128 to i64
        %179 = arith.trunci %163 : i128 to i64
        %177 = arith.subi %178, %179 : i64
        %180 = arith.extsi %177 : i64 to i128
        llvm.store %180, %132 : i128, !llvm.ptr
        cf.br ^bb38
      ^bb38:
      %181 = arith.constant 0 : i32
      %182 = llvm.load %136 : !llvm.ptr -> i64
      %184 = arith.extsi %181 : i32 to i64
      %183 = arith.subi %184, %182 : i64
      llvm.store %183, %136 : i64, !llvm.ptr
      %185 = llvm.load %140 : !llvm.ptr -> i64
      %186 = arith.constant 1 : i32
      %188 = arith.extsi %186 : i32 to i64
      %187 = arith.addi %185, %188 : i64
      llvm.store %187, %140 : i64, !llvm.ptr
      %189 = llvm.load %142 : !llvm.ptr -> i64
      %190 = arith.constant 10 : i32
      %192 = arith.extsi %190 : i32 to i64
      %191 = arith.subi %189, %192 : i64
      llvm.store %191, %142 : i64, !llvm.ptr
      cf.br ^bb30
    ^bb32:
    %193 = llvm.load %132 : !llvm.ptr -> i128
    %194 = arith.constant 0 : i32
    %195 = arith.extsi %194 : i32 to i128
    %197 = arith.trunci %193 : i128 to i64
    %198 = arith.trunci %195 : i128 to i64
    %196 = arith.cmpi slt, %197, %198 : i64
    cf.cond_br %196, ^bb39, ^bb40
    ^bb39:
      %199 = arith.constant 0 : i32
      %200 = arith.extsi %199 : i32 to i128
      llvm.store %200, %132 : i128, !llvm.ptr
      cf.br ^bb41
    ^bb40:
      cf.br ^bb41
    ^bb41:
    %201 = llvm.load %132 : !llvm.ptr -> i128
    %203 = arith.trunci %201 : i128 to i64
    %204 = arith.trunci %128 : i128 to i64
    %202 = arith.cmpi sgt, %203, %204 : i64
    cf.cond_br %202, ^bb42, ^bb43
    ^bb42:
      llvm.store %128, %132 : i128, !llvm.ptr
      cf.br ^bb44
    ^bb43:
      cf.br ^bb44
    ^bb44:
    %205 = llvm.load %132 : !llvm.ptr -> i128
    func.return %205 : i128
  }
  func.func @Wfull(%arg0: i64, %arg1: i64) -> i128 {
    %206 = func.call @cap128() : () -> i128
    %207 = arith.constant 0 : i32
    %208 = arith.extsi %207 : i32 to i128
    %209 = llvm.mlir.constant(1 : i64) : i64
    %210 = llvm.alloca %209 x i128 : (i64) -> !llvm.ptr
    llvm.store %208, %210 : i128, !llvm.ptr
    %211 = arith.constant 0 : i32
    %212 = arith.extsi %211 : i32 to i64
    %213 = llvm.mlir.constant(1 : i64) : i64
    %214 = llvm.alloca %213 x i64 : (i64) -> !llvm.ptr
    llvm.store %212, %214 : i64, !llvm.ptr
    cf.br ^bb45
    ^bb45:
    %215 = llvm.load %214 : !llvm.ptr -> i64
    %216 = arith.constant 8 : i32
    %218 = arith.extsi %216 : i32 to i64
    %217 = arith.cmpi sle, %215, %218 : i64
    %219 = scf.if %217 -> (i1) {
      %220 = llvm.load %214 : !llvm.ptr -> i64
      %221 = arith.cmpi sle, %220, %arg1 : i64
      scf.yield %221 : i1
    } else {
      %222 = arith.constant false
      scf.yield %222 : i1
    }
    cf.cond_br %219, ^bb46, ^bb47
    ^bb46:
      %223 = llvm.load %210 : !llvm.ptr -> i128
      %225 = arith.constant 1 : i32
      %227 = arith.extsi %225 : i32 to i64
      %226 = arith.subi %arg0, %227 : i64
      %228 = llvm.load %214 : !llvm.ptr -> i64
      %229 = arith.subi %arg1, %228 : i64
      %224 = func.call @Wcnt(%226, %229) : (i64, i64) -> i128
      %231 = arith.trunci %223 : i128 to i64
      %232 = arith.trunci %224 : i128 to i64
      %230 = arith.addi %231, %232 : i64
      %233 = arith.extsi %230 : i64 to i128
      llvm.store %233, %210 : i128, !llvm.ptr
      %234 = llvm.load %210 : !llvm.ptr -> i128
      %236 = arith.trunci %234 : i128 to i64
      %237 = arith.trunci %206 : i128 to i64
      %235 = arith.cmpi sgt, %236, %237 : i64
      cf.cond_br %235, ^bb48, ^bb49
      ^bb48:
        llvm.store %206, %210 : i128, !llvm.ptr
        cf.br ^bb50
      ^bb49:
        cf.br ^bb50
      ^bb50:
      %238 = llvm.load %214 : !llvm.ptr -> i64
      %239 = arith.constant 1 : i32
      %241 = arith.extsi %239 : i32 to i64
      %240 = arith.addi %238, %241 : i64
      llvm.store %240, %214 : i64, !llvm.ptr
      cf.br ^bb45
    ^bb47:
    %242 = llvm.load %210 : !llvm.ptr -> i128
    func.return %242 : i128
  }
  func.func @f_mod(%arg0: i64, %arg1: i64) -> i64 {
    %243 = arith.constant 8 : i32
    %245 = arith.extsi %243 : i32 to i64
    %244 = arith.addi %arg0, %245 : i64
    %246 = arith.constant 9 : i32
    %248 = arith.extsi %246 : i32 to i64
    %247 = arith.divsi %244, %248 : i64
    %249 = llvm.mlir.constant(1 : i64) : i64
    %250 = llvm.alloca %249 x i64 : (i64) -> !llvm.ptr
    llvm.store %247, %250 : i64, !llvm.ptr
    %251 = arith.constant 9 : i32
    %252 = llvm.load %250 : !llvm.ptr -> i64
    %254 = arith.extsi %251 : i32 to i64
    %253 = arith.muli %254, %252 : i64
    %255 = arith.subi %253, %arg0 : i64
    %256 = llvm.mlir.constant(1 : i64) : i64
    %257 = llvm.alloca %256 x i64 : (i64) -> !llvm.ptr
    llvm.store %255, %257 : i64, !llvm.ptr
    %258 = llvm.mlir.constant(1 : i64) : i64
    %259 = llvm.alloca %258 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %259 : i64, !llvm.ptr
    %260 = arith.constant 1 : i32
    %261 = arith.extsi %260 : i32 to i64
    %262 = llvm.mlir.constant(1 : i64) : i64
    %263 = llvm.alloca %262 x i64 : (i64) -> !llvm.ptr
    llvm.store %261, %263 : i64, !llvm.ptr
    cf.br ^bb51
    ^bb51:
    %264 = llvm.load %263 : !llvm.ptr -> i64
    %265 = arith.constant 1 : i32
    %267 = arith.extsi %265 : i32 to i64
    %266 = arith.cmpi eq, %264, %267 : i64
    cf.cond_br %266, ^bb52, ^bb53
    ^bb52:
      %269 = llvm.load %250 : !llvm.ptr -> i64
      %270 = llvm.load %257 : !llvm.ptr -> i64
      %268 = func.call @Wfull(%269, %270) : (i64, i64) -> i128
      %271 = llvm.load %259 : !llvm.ptr -> i64
      %272 = arith.extsi %271 : i64 to i128
      %274 = arith.trunci %272 : i128 to i64
      %275 = arith.trunci %268 : i128 to i64
      %273 = arith.cmpi sgt, %274, %275 : i64
      cf.cond_br %273, ^bb54, ^bb55
      ^bb54:
        %276 = llvm.load %259 : !llvm.ptr -> i64
        %277 = arith.trunci %268 : i128 to i64
        %278 = arith.subi %276, %277 : i64
        llvm.store %278, %259 : i64, !llvm.ptr
        %279 = llvm.load %250 : !llvm.ptr -> i64
        %280 = arith.constant 1 : i32
        %282 = arith.extsi %280 : i32 to i64
        %281 = arith.addi %279, %282 : i64
        llvm.store %281, %250 : i64, !llvm.ptr
        %283 = llvm.load %257 : !llvm.ptr -> i64
        %284 = arith.constant 9 : i32
        %286 = arith.extsi %284 : i32 to i64
        %285 = arith.addi %283, %286 : i64
        llvm.store %285, %257 : i64, !llvm.ptr
        cf.br ^bb56
      ^bb55:
        %287 = arith.constant 0 : i32
        %288 = arith.extsi %287 : i32 to i64
        llvm.store %288, %263 : i64, !llvm.ptr
        cf.br ^bb56
      ^bb56:
      cf.br ^bb51
    ^bb53:
    %290 = arith.constant 64 : i32
    %291 = arith.constant 8 : i32
    %292 = arith.extsi %290 : i32 to i64
    %293 = arith.extsi %291 : i32 to i64
    %289 = func.call @calloc(%292, %293) : (i64, i64) -> !llvm.ptr
    %295 = arith.constant 64 : i32
    %296 = arith.constant 8 : i32
    %297 = arith.extsi %295 : i32 to i64
    %298 = arith.extsi %296 : i32 to i64
    %294 = func.call @calloc(%297, %298) : (i64, i64) -> !llvm.ptr
    %299 = arith.constant 0 : i32
    %300 = arith.extsi %299 : i32 to i64
    %301 = llvm.mlir.constant(1 : i64) : i64
    %302 = llvm.alloca %301 x i64 : (i64) -> !llvm.ptr
    llvm.store %300, %302 : i64, !llvm.ptr
    %303 = arith.constant 1 : i32
    %304 = arith.extsi %303 : i32 to i64
    %305 = llvm.mlir.constant(1 : i64) : i64
    %306 = llvm.alloca %305 x i64 : (i64) -> !llvm.ptr
    llvm.store %304, %306 : i64, !llvm.ptr
    %307 = llvm.load %257 : !llvm.ptr -> i64
    %308 = llvm.mlir.constant(1 : i64) : i64
    %309 = llvm.alloca %308 x i64 : (i64) -> !llvm.ptr
    llvm.store %307, %309 : i64, !llvm.ptr
    cf.br ^bb57
    ^bb57:
    %310 = llvm.load %309 : !llvm.ptr -> i64
    %311 = arith.constant 0 : i32
    %313 = arith.extsi %311 : i32 to i64
    %312 = arith.cmpi sgt, %310, %313 : i64
    cf.cond_br %312, ^bb58, ^bb59
    ^bb58:
      %314 = llvm.load %250 : !llvm.ptr -> i64
      %315 = llvm.load %306 : !llvm.ptr -> i64
      %316 = arith.subi %314, %315 : i64
      %317 = arith.constant 1 : i32
      %319 = arith.extsi %317 : i32 to i64
      %318 = arith.addi %316, %319 : i64
      %320 = arith.constant 9 : i32
      %321 = arith.extsi %320 : i32 to i64
      %322 = llvm.mlir.constant(1 : i64) : i64
      %323 = llvm.alloca %322 x i64 : (i64) -> !llvm.ptr
      llvm.store %321, %323 : i64, !llvm.ptr
      %324 = llvm.load %306 : !llvm.ptr -> i64
      %325 = arith.constant 1 : i32
      %327 = arith.extsi %325 : i32 to i64
      %326 = arith.cmpi eq, %324, %327 : i64
      cf.cond_br %326, ^bb60, ^bb61
      ^bb60:
        %328 = arith.constant 8 : i32
        %329 = arith.extsi %328 : i32 to i64
        llvm.store %329, %323 : i64, !llvm.ptr
        cf.br ^bb62
      ^bb61:
        cf.br ^bb62
      ^bb62:
      %330 = arith.constant 0 : i32
      %331 = arith.extsi %330 : i32 to i64
      %332 = llvm.mlir.constant(1 : i64) : i64
      %333 = llvm.alloca %332 x i64 : (i64) -> !llvm.ptr
      llvm.store %331, %333 : i64, !llvm.ptr
      %334 = llvm.load %309 : !llvm.ptr -> i64
      %335 = llvm.mlir.constant(1 : i64) : i64
      %336 = llvm.alloca %335 x i64 : (i64) -> !llvm.ptr
      llvm.store %334, %336 : i64, !llvm.ptr
      %337 = llvm.load %336 : !llvm.ptr -> i64
      %338 = llvm.load %323 : !llvm.ptr -> i64
      %339 = arith.cmpi sgt, %337, %338 : i64
      cf.cond_br %339, ^bb63, ^bb64
      ^bb63:
        %340 = llvm.load %323 : !llvm.ptr -> i64
        llvm.store %340, %336 : i64, !llvm.ptr
        cf.br ^bb65
      ^bb64:
        cf.br ^bb65
      ^bb65:
      cf.br ^bb66
      ^bb66:
      %341 = llvm.load %336 : !llvm.ptr -> i64
      %342 = arith.constant 1 : i32
      %344 = arith.extsi %342 : i32 to i64
      %343 = arith.cmpi sge, %341, %344 : i64
      %345 = scf.if %343 -> (i1) {
        %346 = llvm.load %333 : !llvm.ptr -> i64
        %347 = arith.constant 0 : i32
        %349 = arith.extsi %347 : i32 to i64
        %348 = arith.cmpi eq, %346, %349 : i64
        scf.yield %348 : i1
      } else {
        %350 = arith.constant false
        scf.yield %350 : i1
      }
      cf.cond_br %345, ^bb67, ^bb68
      ^bb67:
        %352 = arith.constant 1 : i32
        %354 = arith.extsi %352 : i32 to i64
        %353 = arith.subi %318, %354 : i64
        %355 = llvm.load %309 : !llvm.ptr -> i64
        %356 = llvm.load %336 : !llvm.ptr -> i64
        %357 = arith.subi %355, %356 : i64
        %351 = func.call @Wcnt(%353, %357) : (i64, i64) -> i128
        %358 = llvm.load %259 : !llvm.ptr -> i64
        %359 = arith.extsi %358 : i64 to i128
        %361 = arith.trunci %359 : i128 to i64
        %362 = arith.trunci %351 : i128 to i64
        %360 = arith.cmpi sgt, %361, %362 : i64
        cf.cond_br %360, ^bb69, ^bb70
        ^bb69:
          %363 = llvm.load %259 : !llvm.ptr -> i64
          %364 = arith.trunci %351 : i128 to i64
          %365 = arith.subi %363, %364 : i64
          llvm.store %365, %259 : i64, !llvm.ptr
          %366 = llvm.load %336 : !llvm.ptr -> i64
          %367 = arith.constant 1 : i32
          %369 = arith.extsi %367 : i32 to i64
          %368 = arith.subi %366, %369 : i64
          llvm.store %368, %336 : i64, !llvm.ptr
          cf.br ^bb71
        ^bb70:
          %370 = llvm.load %306 : !llvm.ptr -> i64
          %371 = llvm.load %302 : !llvm.ptr -> i64
          %372 = llvm.getelementptr %289[%371] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          llvm.store %370, %372 : i64, !llvm.ptr
          %373 = llvm.load %336 : !llvm.ptr -> i64
          %374 = llvm.load %302 : !llvm.ptr -> i64
          %375 = llvm.getelementptr %294[%374] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          llvm.store %373, %375 : i64, !llvm.ptr
          %376 = llvm.load %302 : !llvm.ptr -> i64
          %377 = arith.constant 1 : i32
          %379 = arith.extsi %377 : i32 to i64
          %378 = arith.addi %376, %379 : i64
          llvm.store %378, %302 : i64, !llvm.ptr
          %380 = llvm.load %309 : !llvm.ptr -> i64
          %381 = llvm.load %336 : !llvm.ptr -> i64
          %382 = arith.subi %380, %381 : i64
          llvm.store %382, %309 : i64, !llvm.ptr
          %383 = llvm.load %306 : !llvm.ptr -> i64
          %384 = arith.constant 1 : i32
          %386 = arith.extsi %384 : i32 to i64
          %385 = arith.addi %383, %386 : i64
          llvm.store %385, %306 : i64, !llvm.ptr
          %387 = arith.constant 1 : i32
          %388 = arith.extsi %387 : i32 to i64
          llvm.store %388, %333 : i64, !llvm.ptr
          cf.br ^bb71
        ^bb71:
        cf.br ^bb66
      ^bb68:
      %389 = llvm.load %333 : !llvm.ptr -> i64
      %390 = arith.constant 0 : i32
      %392 = arith.extsi %390 : i32 to i64
      %391 = arith.cmpi eq, %389, %392 : i64
      cf.cond_br %391, ^bb72, ^bb73
      ^bb72:
        %393 = llvm.load %309 : !llvm.ptr -> i64
        %394 = arith.constant 1 : i32
        %396 = arith.extsi %394 : i32 to i64
        %395 = arith.cmpi eq, %393, %396 : i64
        cf.cond_br %395, ^bb75, ^bb76
        ^bb75:
          %397 = llvm.load %306 : !llvm.ptr -> i64
          %398 = llvm.load %259 : !llvm.ptr -> i64
          %399 = arith.addi %397, %398 : i64
          %400 = llvm.load %302 : !llvm.ptr -> i64
          %401 = llvm.getelementptr %289[%400] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          llvm.store %399, %401 : i64, !llvm.ptr
          %402 = arith.constant 1 : i32
          %403 = llvm.load %302 : !llvm.ptr -> i64
          %404 = arith.extsi %402 : i32 to i64
          %405 = llvm.getelementptr %294[%403] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          llvm.store %404, %405 : i64, !llvm.ptr
          %406 = llvm.load %302 : !llvm.ptr -> i64
          %407 = arith.constant 1 : i32
          %409 = arith.extsi %407 : i32 to i64
          %408 = arith.addi %406, %409 : i64
          llvm.store %408, %302 : i64, !llvm.ptr
          %410 = arith.constant 0 : i32
          %411 = arith.extsi %410 : i32 to i64
          llvm.store %411, %309 : i64, !llvm.ptr
          cf.br ^bb77
        ^bb76:
          %412 = llvm.load %309 : !llvm.ptr -> i64
          %413 = arith.constant 2 : i32
          %415 = arith.extsi %413 : i32 to i64
          %414 = arith.cmpi eq, %412, %415 : i64
          cf.cond_br %414, ^bb78, ^bb79
          ^bb78:
            %416 = arith.constant 1 : i32
            %417 = arith.extsi %416 : i32 to i64
            %418 = llvm.mlir.constant(1 : i64) : i64
            %419 = llvm.alloca %418 x i64 : (i64) -> !llvm.ptr
            llvm.store %417, %419 : i64, !llvm.ptr
            %420 = arith.constant 1 : i32
            %422 = arith.extsi %420 : i32 to i64
            %421 = arith.subi %318, %422 : i64
            %423 = llvm.mlir.constant(1 : i64) : i64
            %424 = llvm.alloca %423 x i64 : (i64) -> !llvm.ptr
            llvm.store %421, %424 : i64, !llvm.ptr
            cf.br ^bb81
            ^bb81:
            %425 = llvm.load %419 : !llvm.ptr -> i64
            %426 = llvm.load %424 : !llvm.ptr -> i64
            %427 = arith.cmpi slt, %425, %426 : i64
            cf.cond_br %427, ^bb82, ^bb83
            ^bb82:
              %428 = llvm.load %419 : !llvm.ptr -> i64
              %429 = llvm.load %424 : !llvm.ptr -> i64
              %430 = arith.addi %428, %429 : i64
              %431 = arith.constant 2 : i32
              %433 = arith.extsi %431 : i32 to i64
              %432 = arith.divsi %430, %433 : i64
              %434 = arith.extsi %432 : i64 to i128
              %435 = arith.extsi %318 : i64 to i128
              %437 = arith.trunci %434 : i128 to i64
              %438 = arith.trunci %435 : i128 to i64
              %436 = arith.muli %437, %438 : i64
              %439 = arith.extsi %432 : i64 to i128
              %440 = arith.constant 1 : i32
              %442 = arith.extsi %440 : i32 to i64
              %441 = arith.addi %432, %442 : i64
              %443 = arith.extsi %441 : i64 to i128
              %445 = arith.trunci %439 : i128 to i64
              %446 = arith.trunci %443 : i128 to i64
              %444 = arith.muli %445, %446 : i64
              %447 = arith.constant 2 : i32
              %448 = arith.extsi %447 : i32 to i128
              %450 = arith.trunci %448 : i128 to i64
              %449 = arith.divsi %444, %450 : i64
              %451 = arith.subi %436, %449 : i64
              %452 = arith.extsi %451 : i64 to i128
              %453 = llvm.load %259 : !llvm.ptr -> i64
              %454 = arith.extsi %453 : i64 to i128
              %456 = arith.trunci %452 : i128 to i64
              %457 = arith.trunci %454 : i128 to i64
              %455 = arith.cmpi sge, %456, %457 : i64
              cf.cond_br %455, ^bb84, ^bb85
              ^bb84:
                llvm.store %432, %424 : i64, !llvm.ptr
                cf.br ^bb86
              ^bb85:
                %458 = arith.constant 1 : i32
                %460 = arith.extsi %458 : i32 to i64
                %459 = arith.addi %432, %460 : i64
                llvm.store %459, %419 : i64, !llvm.ptr
                cf.br ^bb86
              ^bb86:
              cf.br ^bb81
            ^bb83:
            %461 = llvm.load %419 : !llvm.ptr -> i64
            %462 = arith.constant 1 : i32
            %464 = arith.extsi %462 : i32 to i64
            %463 = arith.subi %461, %464 : i64
            %465 = arith.extsi %463 : i64 to i128
            %466 = arith.extsi %318 : i64 to i128
            %468 = arith.trunci %465 : i128 to i64
            %469 = arith.trunci %466 : i128 to i64
            %467 = arith.muli %468, %469 : i64
            %470 = arith.constant 1 : i32
            %472 = arith.extsi %470 : i32 to i64
            %471 = arith.subi %461, %472 : i64
            %473 = arith.extsi %471 : i64 to i128
            %474 = arith.extsi %461 : i64 to i128
            %476 = arith.trunci %473 : i128 to i64
            %477 = arith.trunci %474 : i128 to i64
            %475 = arith.muli %476, %477 : i64
            %478 = arith.constant 2 : i32
            %479 = arith.extsi %478 : i32 to i128
            %481 = arith.trunci %479 : i128 to i64
            %480 = arith.divsi %475, %481 : i64
            %482 = arith.subi %467, %480 : i64
            %483 = arith.extsi %482 : i64 to i128
            %484 = llvm.load %259 : !llvm.ptr -> i64
            %485 = arith.trunci %483 : i128 to i64
            %486 = arith.subi %484, %485 : i64
            llvm.store %486, %259 : i64, !llvm.ptr
            %487 = llvm.load %306 : !llvm.ptr -> i64
            %488 = arith.addi %487, %461 : i64
            llvm.store %488, %306 : i64, !llvm.ptr
            cf.br ^bb80
          ^bb79:
            %489 = llvm.load %306 : !llvm.ptr -> i64
            %490 = arith.constant 1 : i32
            %492 = arith.extsi %490 : i32 to i64
            %491 = arith.addi %489, %492 : i64
            llvm.store %491, %306 : i64, !llvm.ptr
            cf.br ^bb80
          ^bb80:
          cf.br ^bb77
        ^bb77:
        cf.br ^bb74
      ^bb73:
        cf.br ^bb74
      ^bb74:
      cf.br ^bb57
    ^bb59:
    %494 = arith.constant 10 : i32
    %495 = llvm.load %250 : !llvm.ptr -> i64
    %496 = arith.extsi %494 : i32 to i64
    %493 = func.call @powmod(%496, %495) : (i64, i64) -> i64
    %497 = arith.constant 1 : i32
    %499 = arith.extsi %497 : i32 to i64
    %498 = arith.subi %493, %499 : i64
    %500 = llvm.mlir.addressof @MOD : !llvm.ptr
    %501 = llvm.load %500 : !llvm.ptr -> i64
    %502 = arith.addi %498, %501 : i64
    %503 = llvm.mlir.addressof @MOD : !llvm.ptr
    %504 = llvm.load %503 : !llvm.ptr -> i64
    %505 = arith.remsi %502, %504 : i64
    %506 = llvm.mlir.constant(1 : i64) : i64
    %507 = llvm.alloca %506 x i64 : (i64) -> !llvm.ptr
    llvm.store %505, %507 : i64, !llvm.ptr
    %508 = arith.constant 0 : i32
    %509 = arith.extsi %508 : i32 to i64
    %510 = llvm.mlir.constant(1 : i64) : i64
    %511 = llvm.alloca %510 x i64 : (i64) -> !llvm.ptr
    llvm.store %509, %511 : i64, !llvm.ptr
    cf.br ^bb87
    ^bb87:
    %512 = llvm.load %511 : !llvm.ptr -> i64
    %513 = llvm.load %302 : !llvm.ptr -> i64
    %514 = arith.cmpi slt, %512, %513 : i64
    cf.cond_br %514, ^bb88, ^bb89
    ^bb88:
      %515 = llvm.load %507 : !llvm.ptr -> i64
      %517 = llvm.load %511 : !llvm.ptr -> i64
      %518 = llvm.getelementptr %294[%517] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %516 = llvm.load %518 : !llvm.ptr -> i64
      %520 = arith.constant 10 : i32
      %521 = llvm.load %250 : !llvm.ptr -> i64
      %523 = llvm.load %511 : !llvm.ptr -> i64
      %524 = llvm.getelementptr %289[%523] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %522 = llvm.load %524 : !llvm.ptr -> i64
      %525 = arith.subi %521, %522 : i64
      %526 = arith.extsi %520 : i32 to i64
      %519 = func.call @powmod(%526, %525) : (i64, i64) -> i64
      %527 = arith.muli %516, %519 : i64
      %528 = llvm.mlir.addressof @MOD : !llvm.ptr
      %529 = llvm.load %528 : !llvm.ptr -> i64
      %530 = arith.remsi %527, %529 : i64
      %531 = arith.subi %515, %530 : i64
      %532 = llvm.mlir.addressof @MOD : !llvm.ptr
      %533 = llvm.load %532 : !llvm.ptr -> i64
      %534 = arith.addi %531, %533 : i64
      %535 = llvm.mlir.addressof @MOD : !llvm.ptr
      %536 = llvm.load %535 : !llvm.ptr -> i64
      %537 = arith.remsi %534, %536 : i64
      llvm.store %537, %507 : i64, !llvm.ptr
      %538 = llvm.load %511 : !llvm.ptr -> i64
      %539 = arith.constant 1 : i32
      %541 = arith.extsi %539 : i32 to i64
      %540 = arith.addi %538, %541 : i64
      llvm.store %540, %511 : i64, !llvm.ptr
      cf.br ^bb87
    ^bb89:
    func.call @free(%289) : (!llvm.ptr) -> ()
    func.call @free(%294) : (!llvm.ptr) -> ()
    %544 = llvm.load %507 : !llvm.ptr -> i64
    func.return %544 : i64
  }
  func.func @main() -> i32 {
    %545 = arith.constant 0 : i32
    %546 = arith.extsi %545 : i32 to i64
    %547 = llvm.mlir.constant(1 : i64) : i64
    %548 = llvm.alloca %547 x i64 : (i64) -> !llvm.ptr
    llvm.store %546, %548 : i64, !llvm.ptr
    %549 = arith.constant 1 : i32
    %550 = arith.extsi %549 : i32 to i64
    %551 = llvm.mlir.constant(1 : i64) : i64
    %552 = llvm.alloca %551 x i64 : (i64) -> !llvm.ptr
    llvm.store %550, %552 : i64, !llvm.ptr
    cf.br ^bb90
    ^bb90:
    %553 = llvm.load %552 : !llvm.ptr -> i64
    %554 = llvm.mlir.addressof @KMAX : !llvm.ptr
    %555 = llvm.load %554 : !llvm.ptr -> i64
    %556 = arith.cmpi sle, %553, %555 : i64
    cf.cond_br %556, ^bb91, ^bb92
    ^bb91:
      %557 = llvm.load %552 : !llvm.ptr -> i64
      %558 = llvm.load %552 : !llvm.ptr -> i64
      %559 = arith.muli %557, %558 : i64
      %560 = llvm.load %552 : !llvm.ptr -> i64
      %561 = arith.muli %559, %560 : i64
      %562 = llvm.load %552 : !llvm.ptr -> i64
      %563 = arith.muli %561, %562 : i64
      %564 = llvm.load %548 : !llvm.ptr -> i64
      %565 = func.call @f_mod(%561, %563) : (i64, i64) -> i64
      %566 = arith.addi %564, %565 : i64
      %567 = llvm.mlir.addressof @MOD : !llvm.ptr
      %568 = llvm.load %567 : !llvm.ptr -> i64
      %569 = arith.remsi %566, %568 : i64
      llvm.store %569, %548 : i64, !llvm.ptr
      %570 = llvm.load %552 : !llvm.ptr -> i64
      %571 = arith.constant 1 : i32
      %573 = arith.extsi %571 : i32 to i64
      %572 = arith.addi %570, %573 : i64
      llvm.store %572, %552 : i64, !llvm.ptr
      cf.br ^bb90
    ^bb92:
    %574 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %575 = llvm.load %548 : !llvm.ptr -> i64
    %576 = llvm.call @printf(%574, %575) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    %577 = arith.constant 0 : i32
    func.return %577 : i32
  }
}