Problem 725

Digit Sum Numbers, S(2020) mod 10^16. Uses i128 modular arithmetic mod (2020 * 10^16) with Russian peasant mulmod to avoid overflow, then divides by 2020 for exact result mod 10^16.

Answer4598797036650685
Output4598797036650685
StatusPASS
Native helperno
Runtime0 ms
Peak memory1088 KB
Time complexityO(n^4) (estimated)
Space complexityO(n^2) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^4)O(n)
Space complexityO(n^2)O(n)
ApproachFlow solutionBig-integer arithmetic
VerdictSuboptimal

Flow source

# Project Euler 725
# Digit Sum Numbers, S(2020) mod 10^16.
# Uses i128 modular arithmetic mod (2020 * 10^16) with Russian peasant mulmod
# to avoid overflow, then divides by 2020 for exact result mod 10^16.

extern {
    function calloc(n: i64, size: i64) -> ptr<void>
    function free(p: ptr<void>)
    function memset(p: ptr<void>, c: i32, n: i64) -> ptr<void>
    function printf(fmt: ptr<i8>, ...) -> i32
}

const MOD: i64 = 10000000000000000
const N: i32 = 2020
const MAXP: i32 = 200

# M = 2020 * 10^16, stored as i128
const M_HI: i64 = 0  # M fits in i128 but not i64, so we use i128 directly
# M = 20200000000000000000

function m_add(a: i128, b: i128) -> i128 {
    let s: i128 = a + b
    let m: i128 = 20200000000000000000
    if s >= m { return s - m }
    if s < 0 { return s + m }
    return s
}

# Russian peasant multiplication mod M to avoid i128 overflow
function m_mul(a0: i128, b0: i128) -> i128 {
    let m: i128 = 20200000000000000000
    let mut a: i128 = a0 % m
    if a < 0 { a = a + m }
    let mut b: i128 = b0 % m
    if b < 0 { b = b + m }
    let mut result: i128 = 0
    while b > 0 {
        if (b & 1) != 0 {
            result = result + a
            if result >= m { result = result - m }
        }
        a = a + a
        if a >= m { a = a - m }
        b = b >> 1
    }
    return result
}

function m_pow(base0: i128, e: i32) -> i128 {
    let m: i128 = 20200000000000000000
    let mut r: i128 = 1
    let mut b: i128 = base0 % m
    let mut ee: i32 = e
    while ee > 0 {
        if (ee & 1) != 0 { r = m_mul(r, b) }
        b = m_mul(b, b)
        ee = ee >> 1
    }
    return r
}

function mod_add(a: i64, b: i64) -> i64 {
    let s: i64 = a + b
    if s >= MOD { return s - MOD }
    if s < 0 { return s + MOD }
    return s
}

function vp_factorial(p: i32, n: i32) -> i32 {
    let mut e: i32 = 0
    let mut pk: i32 = p
    while pk <= n {
        e = e + n / pk
        pk = pk * p
    }
    return e
}

function main() -> i32 {
    let m: i128 = 20200000000000000000

    # Sieve primes up to N
    let sieve: ptr<i8> = calloc((N + 1) as i64, 1)
    let mut i: i32 = 2
    while i <= N {
        sieve[i] = 1
        i = i + 1
    }
    let mut p: i32 = 2
    while p * p <= N {
        if sieve[p] != 0 {
            let mut mm: i32 = p * p
            while mm <= N {
                sieve[mm] = 0
                mm = mm + p
            }
        }
        p = p + 1
    }
    let primes: ptr<i32> = calloc(400, 4)
    let mut nprimes: i32 = 0
    let mut i2: i32 = 2
    while i2 <= N {
        if sieve[i2] != 0 {
            primes[nprimes] = i2
            nprimes = nprimes + 1
        }
        i2 = i2 + 1
    }

    # Build partitions
    let lens: ptr<i32> = calloc(10 * MAXP, 4)
    let digs: ptr<ptr<i32> > = calloc(10 * MAXP, 8)
    let counts: ptr<i32> = calloc(10, 4)

    counts[0] = 1
    lens[0] = 0
    digs[0] = calloc(20, 4)

    let mut opt: i32 = 1
    while opt <= 9 {
        let mut i: i32 = 0
        while i <= 9 - opt {
            let pc: i32 = counts[i]
            let mut pp: i32 = 0
            while pp < pc {
                let dst_idx: i32 = counts[i + opt]
                let dst_d: ptr<i32> = calloc(20, 4)
                let src_d: ptr<i32> = digs[i * MAXP + pp]
                let src_len: i32 = lens[i * MAXP + pp]
                let mut j: i32 = src_len
                while j > 0 {
                    dst_d[j] = src_d[j - 1]
                    j = j - 1
                }
                dst_d[0] = opt
                digs[(i + opt) * MAXP + dst_idx] = dst_d
                lens[(i + opt) * MAXP + dst_idx] = src_len + 1
                counts[i + opt] = dst_idx + 1
                pp = pp + 1
            }
            i = i + 1
        }
        opt = opt + 1
    }

    # rep = 111...1 (2020 ones) mod M
    let mut rep: i128 = 0
    let mut i3: i32 = 0
    while i3 < N {
        rep = m_mul(rep, 10)
        rep = m_add(rep, 1)
        i3 = i3 + 1
    }

    let mut total: i64 = 0
    let mut k: i32 = 0
    while k <= 9 {
        let mut pi: i32 = 0
        while pi < counts[k] {
            let p_len: i32 = lens[k * MAXP + pi]
            let p_d: ptr<i32> = digs[k * MAXP + pi]
            let d: ptr<i32> = calloc(10, 4)
            let mut sumd: i32 = 0
            let mut j: i32 = 0
            while j < p_len {
                d[p_d[j]] = d[p_d[j]] + 1
                j = j + 1
            }
            d[k] = d[k] + 1
            let mut j2: i32 = 1
            while j2 <= 9 {
                sumd = sumd + d[j2]
                j2 = j2 + 1
            }
            d[0] = N - sumd
            if d[0] >= 0 {
                if p_len < N {
                    # Compute multinomial mod M via prime factorization
                    let mut comb: i128 = 1
                    let mut pi2: i32 = 0
                    while pi2 < nprimes {
                        let pr: i32 = primes[pi2]
                        let mut e: i32 = vp_factorial(pr, N)
                        let mut v: i32 = 0
                        while v < 10 {
                            e = e - vp_factorial(pr, d[v])
                            v = v + 1
                        }
                        if e > 0 {
                            comb = m_mul(comb, m_pow((pr as i128), e))
                        }
                        pi2 = pi2 + 1
                    }
                    let mut val: i128 = m_mul(rep, comb)
                    val = m_mul(val, ((2 * k) as i128))
                    # Exact division by N=2020
                    val = val / (N as i128)
                    # Reduce mod 10^16
                    let vmod: i64 = (val % (MOD as i128)) as i64
                    total = mod_add(total, vmod)
                }
            }
            free(d)
            pi = pi + 1
        }
        k = k + 1
    }

    printf("%lld\n", total)

    let mut i4: i32 = 0
    while i4 < 10 {
        let mut j4: i32 = 0
        while j4 < counts[i4] {
            free(digs[i4 * MAXP + j4])
            j4 = j4 + 1
        }
        i4 = i4 + 1
    }
    free(lens)
    free(digs)
    free(counts)
    free(sieve)
    free(primes)
    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; }

__int128 m_add_i128_i128(__int128 a, __int128 b);
__int128 m_mul_i128_i128(__int128 a0, __int128 b0);
__int128 m_pow_i128_i32(__int128 base0, int32_t e);
int64_t mod_add_i64_i64(int64_t a, int64_t b);
int32_t vp_factorial_i32_i32(int32_t p, int32_t n);
int32_t main(void);

static const int64_t MOD = 10000000000000000;
static const int32_t N = 2020;
static const int32_t MAXP = 200;
static const int64_t M_HI = 0;





__int128 m_add_i128_i128(__int128 a, __int128 b) {
    __int128 s = (a + b);
    __int128 m = ((__int128)0x1ULL << 64 | (__int128)0x1854D0F9CEE40000ULL);
    if (s >= m) {
        return (s - m);
    }
    if (s < 0) {
        return (s + m);
    }
    return s;
}

__int128 m_mul_i128_i128(__int128 a0, __int128 b0) {
    __int128 m = ((__int128)0x1ULL << 64 | (__int128)0x1854D0F9CEE40000ULL);
    __int128 a = FLOW_CHECKED_MOD((a0), (m));
    if (a < 0) {
        a = (a + m);
    }
    __int128 b = FLOW_CHECKED_MOD((b0), (m));
    if (b < 0) {
        b = (b + m);
    }
    __int128 result = 0;
    while (b > 0) {
        if ((b & 1) != 0) {
            result = (result + a);
            if (result >= m) {
                result = (result - m);
            }
        }
        a = (a + a);
        if (a >= m) {
            a = (a - m);
        }
        b = FLOW_CHECKED_SHR((b), (1));
    }
    return result;
}

__int128 m_pow_i128_i32(__int128 base0, int32_t e) {
    __int128 m = ((__int128)0x1ULL << 64 | (__int128)0x1854D0F9CEE40000ULL);
    __int128 r = 1;
    __int128 b = FLOW_CHECKED_MOD((base0), (m));
    int32_t ee = e;
    while (ee > 0) {
        if ((ee & 1) != 0) {
            r = m_mul_i128_i128(r, b);
        }
        b = m_mul_i128_i128(b, b);
        ee = FLOW_CHECKED_SHR((ee), (1));
    }
    return r;
}

int64_t mod_add_i64_i64(int64_t a, int64_t b) {
    int64_t s = (a + b);
    if (s >= MOD) {
        return (s - MOD);
    }
    if (s < 0) {
        return (s + MOD);
    }
    return s;
}

int32_t vp_factorial_i32_i32(int32_t p, int32_t n) {
    int32_t e = 0;
    int32_t pk = p;
    while (pk <= n) {
        e = (e + FLOW_CHECKED_DIV((n), (pk)));
        pk = (pk * p);
    }
    return e;
}

int32_t main(void) {
    __int128 m = ((__int128)0x1ULL << 64 | (__int128)0x1854D0F9CEE40000ULL);
    int8_t* sieve = (int8_t*)(calloc(((int64_t)((N + 1))), 1));
    int32_t i = 2;
    while (i <= N) {
        sieve[i] = 1;
        i = (i + 1);
    }
    int32_t p = 2;
    while ((p * p) <= N) {
        if (sieve[p] != 0) {
            int32_t mm = (p * p);
            while (mm <= N) {
                sieve[mm] = 0;
                mm = (mm + p);
            }
        }
        p = (p + 1);
    }
    int32_t* primes = (int32_t*)(calloc(400, 4));
    int32_t nprimes = 0;
    int32_t i2 = 2;
    while (i2 <= N) {
        if (sieve[i2] != 0) {
            primes[nprimes] = i2;
            nprimes = (nprimes + 1);
        }
        i2 = (i2 + 1);
    }
    int32_t* lens = (int32_t*)(calloc((10 * MAXP), 4));
    int32_t** digs = (int32_t**)(calloc((10 * MAXP), 8));
    int32_t* counts = (int32_t*)(calloc(10, 4));
    counts[0] = 1;
    lens[0] = 0;
    digs[0] = calloc(20, 4);
    int32_t opt = 1;
    while (opt <= 9) {
        int32_t i = 0;
        while (i <= (9 - opt)) {
            int32_t pc = counts[i];
            int32_t pp = 0;
            while (pp < pc) {
                int32_t dst_idx = counts[(i + opt)];
                int32_t* dst_d = (int32_t*)(calloc(20, 4));
                int32_t* src_d = (int32_t*)(digs[((i * MAXP) + pp)]);
                int32_t src_len = lens[((i * MAXP) + pp)];
                int32_t j = src_len;
                while (j > 0) {
                    dst_d[j] = src_d[(j - 1)];
                    j = (j - 1);
                }
                dst_d[0] = opt;
                digs[(((i + opt) * MAXP) + dst_idx)] = dst_d;
                lens[(((i + opt) * MAXP) + dst_idx)] = (src_len + 1);
                counts[(i + opt)] = (dst_idx + 1);
                pp = (pp + 1);
            }
            i = (i + 1);
        }
        opt = (opt + 1);
    }
    __int128 rep = 0;
    int32_t i3 = 0;
    while (i3 < N) {
        rep = m_mul_i128_i128(rep, 10);
        rep = m_add_i128_i128(rep, 1);
        i3 = (i3 + 1);
    }
    int64_t total = 0;
    int32_t k = 0;
    while (k <= 9) {
        int32_t pi = 0;
        while (pi < counts[k]) {
            int32_t p_len = lens[((k * MAXP) + pi)];
            int32_t* p_d = (int32_t*)(digs[((k * MAXP) + pi)]);
            int32_t* d = (int32_t*)(calloc(10, 4));
            int32_t sumd = 0;
            int32_t j = 0;
            while (j < p_len) {
                d[p_d[j]] = (d[p_d[j]] + 1);
                j = (j + 1);
            }
            d[k] = (d[k] + 1);
            int32_t j2 = 1;
            while (j2 <= 9) {
                sumd = (sumd + d[j2]);
                j2 = (j2 + 1);
            }
            d[0] = (N - sumd);
            if (d[0] >= 0) {
                if (p_len < N) {
                    __int128 comb = 1;
                    int32_t pi2 = 0;
                    while (pi2 < nprimes) {
                        int32_t pr = primes[pi2];
                        int32_t e = vp_factorial_i32_i32(pr, N);
                        int32_t v = 0;
                        while (v < 10) {
                            e = (e - vp_factorial_i32_i32(pr, d[v]));
                            v = (v + 1);
                        }
                        if (e > 0) {
                            comb = m_mul_i128_i128(comb, m_pow_i128_i32(((__int128)(pr)), e));
                        }
                        pi2 = (pi2 + 1);
                    }
                    __int128 val = m_mul_i128_i128(rep, comb);
                    val = m_mul_i128_i128(val, ((__int128)((2 * k))));
                    val = FLOW_CHECKED_DIV((val), (((__int128)(N))));
                    int64_t vmod = ((int64_t)(FLOW_CHECKED_MOD((val), (((__int128)(MOD))))));
                    total = mod_add_i64_i64(total, vmod);
                }
            }
            free(d);
            pi = (pi + 1);
        }
        k = (k + 1);
    }
    printf("%lld\n", total);
    int32_t i4 = 0;
    while (i4 < 10) {
        int32_t j4 = 0;
        while (j4 < counts[i4]) {
            free(digs[((i4 * MAXP) + j4)]);
            j4 = (j4 + 1);
        }
        i4 = (i4 + 1);
    }
    free(lens);
    free(digs);
    free(counts);
    free(sieve);
    free(primes);
    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) -> ()
  func.func private @memset(!llvm.ptr, i32, i64) -> !llvm.ptr

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