Problem 824

Chess Sliders on a cylindrical board. L(10^9, 10^15) mod (10^7+19)^2. Pure Flow port of the native C solver.

Answer26532152736197
Output26532152736197
StatusPASS
Native helperno
Runtime1200 ms
Peak memory157376 KB
Time complexityO(n) (estimated)
Space complexityO(n) (estimated)

Performance comparison

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

Flow source

# Project Euler 824
# Chess Sliders on a cylindrical board.
# L(10^9, 10^15) mod (10^7+19)^2.
# Pure Flow port of the native C solver.

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

const P: i64 = 10000019
const MOD: i64 = 100000380000361

let mut invp: ptr<i32> = null
let mut fac: ptr<i64> = null
let mut H: ptr<i32> = null
let mut w: i64 = 0

function mulmod(a: i64, b: i64, m: i64) -> i64 {
    let r: i128 = ((a as i128) * (b as i128)) % (m as i128)
    return r as i64
}

function inv_mod_p2(a0: i64) -> i64 {
    let a: i64 = a0 % MOD
    let r: i64 = a % P
    let x: i64 = invp[r] as i64
    let ax: i64 = mulmod(a, x, MOD)
    let term: i64 = (2 + MOD - ax) % MOD
    return mulmod(x, term, MOD)
}

function Fpow(u: i64) -> i64 {
    let um: i64 = u % P
    let a1: i64 = um * P
    let a2: i64 = mulmod(a1, w, MOD)
    let mut tmp: i64 = (1 + MOD - a2) % MOD
    if u % 2 == 1 { tmp = (MOD - tmp) % MOD }
    return tmp
}

function unit_factorial(n0: i64) -> i64 {
    let mut n: i64 = n0
    let mut res: i64 = 1
    while n != 0 {
        let u: i64 = n / P
        let v: i64 = n % P
        res = mulmod(res, fac[v], MOD)
        let corr: i64 = (u % P) * (H[v] as i64) % P
        res = mulmod(res, 1 + corr * P, MOD)
        res = mulmod(res, Fpow(u), MOD)
        n = u
    }
    return res
}

function vp_fact(n: i64) -> i64 {
    let q: i64 = n / P
    return q + q / P
}

function binom_mod_p2(n: i64, k: i64) -> i64 {
    if k > n { return 0 }
    let nk: i64 = n - k
    let e: i64 = vp_fact(n) - vp_fact(k) - vp_fact(nk)
    if e >= 2 { return 0 }
    let un: i64 = unit_factorial(n)
    let uk: i64 = unit_factorial(k)
    let unk: i64 = unit_factorial(nk)
    let mut val: i64 = mulmod(un, inv_mod_p2(uk), MOD)
    val = mulmod(val, inv_mod_p2(unk), MOD)
    if e == 1 { val = mulmod(val, P, MOD) }
    return val
}

function coeff_alpha_power(M: i64, d: i64) -> i64 {
    if d == 0 { return 1 }
    let B: i64 = binom_mod_p2(M - d - 1, d - 1)
    let val: i64 = mulmod(M % MOD, inv_mod_p2(d % MOD), MOD)
    return mulmod(val, B, MOD)
}

function main() -> i32 {
    invp = calloc(P, 4) as ptr<i32>
    H = calloc(P, 4) as ptr<i32>
    fac = malloc(P * 8) as ptr<i64>
    if invp == null || fac == null || H == null {
        return 1
    }

    # Inverses mod p
    invp[1] = 1
    let mut i: i64 = 2
    while i < P {
        invp[i] = ((P - (P / i) * (invp[P % i] as i64) % P) % P) as i32
        i = i + 1
    }

    # Factorial mod p^2 for 0..p-1
    let mut f: i64 = 1
    fac[0] = 1
    let mut i2: i64 = 1
    while i2 < P {
        f = mulmod(f, i2, MOD)
        fac[i2] = f
        i2 = i2 + 1
    }

    # Harmonic numbers H[v] = sum_{i<=v} 1/i mod p
    let mut h: i32 = 0
    let mut i3: i64 = 1
    while i3 < P {
        h = ((h as i64 + invp[i3] as i64) % P) as i32
        H[i3] = h
        i3 = i3 + 1
    }

    # Wilson quotient: (p-1)! = -1 + p*w (mod p^2)
    let F: i64 = fac[P - 1]
    w = ((F + 1) / P) % P

    # Main computation
    let N: i64 = 1000000000
    let K: i64 = 1000000000000000
    let t_max: i64 = K / N

    let mut comb: i64 = 1
    let mut ans: i64 = 0
    let mut d: i64 = K
    let mut M: i64 = N * N

    let mut t: i64 = 0
    while t <= t_max {
        if t != 0 {
            comb = mulmod(comb, (N - t + 1) % MOD, MOD)
            comb = mulmod(comb, inv_mod_p2(t), MOD)
        }
        ans = (ans + mulmod(comb, coeff_alpha_power(M, d), MOD)) % MOD
        d = d - N
        M = M - 2 * N
        t = t + 1
    }

    free(invp as ptr<void>)
    free(fac as ptr<void>)
    free(H as ptr<void>)

    printf("%lld\n", ans)
    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 mulmod_i64_i64_i64(int64_t a, int64_t b, int64_t m);
int64_t inv_mod_p2_i64(int64_t a0);
int64_t Fpow_i64(int64_t u);
int64_t unit_factorial_i64(int64_t n0);
int64_t vp_fact_i64(int64_t n);
int64_t binom_mod_p2_i64_i64(int64_t n, int64_t k);
int64_t coeff_alpha_power_i64_i64(int64_t M, int64_t d);
int32_t main(void);

static const int64_t P = 10000019;
static const int64_t MOD = 100000380000361;

/* Module statics */
static int32_t* invp = NULL;
static int64_t* fac = NULL;
static int32_t* H = NULL;
static int64_t w = 0;




int64_t mulmod_i64_i64_i64(int64_t a, int64_t b, int64_t m) {
    __int128 r = FLOW_CHECKED_MOD(((((__int128)(a)) * ((__int128)(b)))), (((__int128)(m))));
    return ((int64_t)(r));
}

int64_t inv_mod_p2_i64(int64_t a0) {
    int64_t a = FLOW_CHECKED_MOD((a0), (MOD));
    int64_t r = FLOW_CHECKED_MOD((a), (P));
    int64_t x = ((int64_t)(invp[r]));
    int64_t ax = mulmod_i64_i64_i64(a, x, MOD);
    int64_t term = FLOW_CHECKED_MOD((((2 + MOD) - ax)), (MOD));
    return mulmod_i64_i64_i64(x, term, MOD);
}

int64_t Fpow_i64(int64_t u) {
    int64_t um = FLOW_CHECKED_MOD((u), (P));
    int64_t a1 = (um * P);
    int64_t a2 = mulmod_i64_i64_i64(a1, w, MOD);
    int64_t tmp = FLOW_CHECKED_MOD((((1 + MOD) - a2)), (MOD));
    if (FLOW_CHECKED_MOD((u), (2)) == 1) {
        tmp = FLOW_CHECKED_MOD(((MOD - tmp)), (MOD));
    }
    return tmp;
}

int64_t unit_factorial_i64(int64_t n0) {
    int64_t n = n0;
    int64_t res = 1;
    while (n != 0) {
        int64_t u = FLOW_CHECKED_DIV((n), (P));
        int64_t v = FLOW_CHECKED_MOD((n), (P));
        res = mulmod_i64_i64_i64(res, fac[v], MOD);
        int64_t corr = FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD((u), (P)) * ((int64_t)(H[v])))), (P));
        res = mulmod_i64_i64_i64(res, (1 + (corr * P)), MOD);
        res = mulmod_i64_i64_i64(res, Fpow_i64(u), MOD);
        n = u;
    }
    return res;
}

int64_t vp_fact_i64(int64_t n) {
    int64_t q = FLOW_CHECKED_DIV((n), (P));
    return (q + FLOW_CHECKED_DIV((q), (P)));
}

int64_t binom_mod_p2_i64_i64(int64_t n, int64_t k) {
    if (k > n) {
        return 0;
    }
    int64_t nk = (n - k);
    int64_t e = ((vp_fact_i64(n) - vp_fact_i64(k)) - vp_fact_i64(nk));
    if (e >= 2) {
        return 0;
    }
    int64_t un = unit_factorial_i64(n);
    int64_t uk = unit_factorial_i64(k);
    int64_t unk = unit_factorial_i64(nk);
    int64_t val = mulmod_i64_i64_i64(un, inv_mod_p2_i64(uk), MOD);
    val = mulmod_i64_i64_i64(val, inv_mod_p2_i64(unk), MOD);
    if (e == 1) {
        val = mulmod_i64_i64_i64(val, P, MOD);
    }
    return val;
}

int64_t coeff_alpha_power_i64_i64(int64_t M, int64_t d) {
    if (d == 0) {
        return 1;
    }
    int64_t B = binom_mod_p2_i64_i64(((M - d) - 1), (d - 1));
    int64_t val = mulmod_i64_i64_i64(FLOW_CHECKED_MOD((M), (MOD)), inv_mod_p2_i64(FLOW_CHECKED_MOD((d), (MOD))), MOD);
    return mulmod_i64_i64_i64(val, B, MOD);
}

int32_t main(void) {
    invp = ((int32_t*)(calloc(P, 4)));
    H = ((int32_t*)(calloc(P, 4)));
    fac = ((int64_t*)(malloc((P * 8))));
    if (((invp == NULL || fac == NULL) || H == NULL)) {
        return 1;
    }
    invp[1] = 1;
    int64_t i = 2;
    while (i < P) {
        invp[i] = ((int32_t)(FLOW_CHECKED_MOD(((P - FLOW_CHECKED_MOD(((FLOW_CHECKED_DIV((P), (i)) * ((int64_t)(invp[FLOW_CHECKED_MOD((P), (i))])))), (P)))), (P))));
        i = (i + 1);
    }
    int64_t f = 1;
    fac[0] = 1;
    int64_t i2 = 1;
    while (i2 < P) {
        f = mulmod_i64_i64_i64(f, i2, MOD);
        fac[i2] = f;
        i2 = (i2 + 1);
    }
    int32_t h = 0;
    int64_t i3 = 1;
    while (i3 < P) {
        h = ((int32_t)(FLOW_CHECKED_MOD(((((int64_t)(h)) + ((int64_t)(invp[i3])))), (P))));
        H[i3] = h;
        i3 = (i3 + 1);
    }
    int64_t F = fac[(P - 1)];
    w = FLOW_CHECKED_MOD((FLOW_CHECKED_DIV(((F + 1)), (P))), (P));
    int64_t N = 1000000000;
    int64_t K = 1000000000000000;
    int64_t t_max = FLOW_CHECKED_DIV((K), (N));
    int64_t comb = 1;
    int64_t ans = 0;
    int64_t d = K;
    int64_t M = (N * N);
    int64_t t = 0;
    while (t <= t_max) {
        if (t != 0) {
            comb = mulmod_i64_i64_i64(comb, FLOW_CHECKED_MOD((((N - t) + 1)), (MOD)), MOD);
            comb = mulmod_i64_i64_i64(comb, inv_mod_p2_i64(t), MOD);
        }
        ans = FLOW_CHECKED_MOD(((ans + mulmod_i64_i64_i64(comb, coeff_alpha_power_i64_i64(M, d), MOD))), (MOD));
        d = (d - N);
        M = (M - (2 * N));
        t = (t + 1);
    }
    free(((void*)(invp)));
    free(((void*)(fac)));
    free(((void*)(H)));
    printf("%lld\n", ans);
    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 @malloc(i64) -> !llvm.ptr
  func.func private @free(!llvm.ptr) -> ()
  // Constant: P
  llvm.mlir.global internal constant @P(10000019 : i64) : i64
  // Constant: MOD
  llvm.mlir.global internal constant @MOD(100000380000361 : i64) : i64
  // Module static: invp
  llvm.mlir.global internal @invp() {addr_space = 0 : i32} : !llvm.ptr {
    %0 = llvm.mlir.zero : !llvm.ptr
    llvm.return %0 : !llvm.ptr
  }
  // Module static: fac
  llvm.mlir.global internal @fac() {addr_space = 0 : i32} : !llvm.ptr {
    %1 = llvm.mlir.zero : !llvm.ptr
    llvm.return %1 : !llvm.ptr
  }
  // Module static: H
  llvm.mlir.global internal @H() {addr_space = 0 : i32} : !llvm.ptr {
    %2 = llvm.mlir.zero : !llvm.ptr
    llvm.return %2 : !llvm.ptr
  }
  // Module static: w
  llvm.mlir.global internal @w(0 : i64) : i64
  func.func @mulmod(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %3 = arith.extsi %arg0 : i64 to i128
    %4 = arith.extsi %arg1 : i64 to i128
    %6 = arith.trunci %3 : i128 to i64
    %7 = arith.trunci %4 : i128 to i64
    %5 = arith.muli %6, %7 : i64
    %8 = arith.extsi %arg2 : i64 to i128
    %10 = arith.trunci %8 : i128 to i64
    %9 = arith.remsi %5, %10 : i64
    %11 = arith.extsi %9 : i64 to i128
    %12 = arith.trunci %11 : i128 to i64
    func.return %12 : i64
  }
  func.func @inv_mod_p2(%arg0: i64) -> i64 {
    %13 = llvm.mlir.addressof @MOD : !llvm.ptr
    %14 = llvm.load %13 : !llvm.ptr -> i64
    %15 = arith.remsi %arg0, %14 : i64
    %16 = llvm.mlir.addressof @P : !llvm.ptr
    %17 = llvm.load %16 : !llvm.ptr -> i64
    %18 = arith.remsi %15, %17 : i64
    %20 = llvm.mlir.addressof @invp : !llvm.ptr
    %21 = llvm.load %20 : !llvm.ptr -> !llvm.ptr
    %22 = llvm.getelementptr %21[%18] : (!llvm.ptr, i64) -> !llvm.ptr, i32
    %19 = llvm.load %22 : !llvm.ptr -> i32
    %23 = arith.extsi %19 : i32 to i64
    %25 = llvm.mlir.addressof @MOD : !llvm.ptr
    %26 = llvm.load %25 : !llvm.ptr -> i64
    %24 = func.call @mulmod(%15, %23, %26) : (i64, i64, i64) -> i64
    %27 = arith.constant 2 : i32
    %28 = llvm.mlir.addressof @MOD : !llvm.ptr
    %29 = llvm.load %28 : !llvm.ptr -> i64
    %31 = arith.extsi %27 : i32 to i64
    %30 = arith.addi %31, %29 : i64
    %32 = arith.subi %30, %24 : i64
    %33 = llvm.mlir.addressof @MOD : !llvm.ptr
    %34 = llvm.load %33 : !llvm.ptr -> i64
    %35 = arith.remsi %32, %34 : i64
    %37 = llvm.mlir.addressof @MOD : !llvm.ptr
    %38 = llvm.load %37 : !llvm.ptr -> i64
    %36 = func.call @mulmod(%23, %35, %38) : (i64, i64, i64) -> i64
    func.return %36 : i64
  }
  func.func @Fpow(%arg0: i64) -> i64 {
    %39 = llvm.mlir.addressof @P : !llvm.ptr
    %40 = llvm.load %39 : !llvm.ptr -> i64
    %41 = arith.remsi %arg0, %40 : i64
    %42 = llvm.mlir.addressof @P : !llvm.ptr
    %43 = llvm.load %42 : !llvm.ptr -> i64
    %44 = arith.muli %41, %43 : i64
    %46 = llvm.mlir.addressof @w : !llvm.ptr
    %47 = llvm.load %46 : !llvm.ptr -> i64
    %48 = llvm.mlir.addressof @MOD : !llvm.ptr
    %49 = llvm.load %48 : !llvm.ptr -> i64
    %45 = func.call @mulmod(%44, %47, %49) : (i64, i64, i64) -> i64
    %50 = arith.constant 1 : i32
    %51 = llvm.mlir.addressof @MOD : !llvm.ptr
    %52 = llvm.load %51 : !llvm.ptr -> i64
    %54 = arith.extsi %50 : i32 to i64
    %53 = arith.addi %54, %52 : i64
    %55 = arith.subi %53, %45 : i64
    %56 = llvm.mlir.addressof @MOD : !llvm.ptr
    %57 = llvm.load %56 : !llvm.ptr -> i64
    %58 = arith.remsi %55, %57 : i64
    %59 = llvm.mlir.constant(1 : i64) : i64
    %60 = llvm.alloca %59 x i64 : (i64) -> !llvm.ptr
    llvm.store %58, %60 : i64, !llvm.ptr
    %61 = arith.constant 2 : i32
    %63 = arith.extsi %61 : i32 to i64
    %62 = arith.remsi %arg0, %63 : i64
    %64 = arith.constant 1 : i32
    %66 = arith.extsi %64 : i32 to i64
    %65 = arith.cmpi eq, %62, %66 : i64
    cf.cond_br %65, ^bb0, ^bb1
    ^bb0:
      %67 = llvm.mlir.addressof @MOD : !llvm.ptr
      %68 = llvm.load %67 : !llvm.ptr -> i64
      %69 = llvm.load %60 : !llvm.ptr -> i64
      %70 = arith.subi %68, %69 : i64
      %71 = llvm.mlir.addressof @MOD : !llvm.ptr
      %72 = llvm.load %71 : !llvm.ptr -> i64
      %73 = arith.remsi %70, %72 : i64
      llvm.store %73, %60 : i64, !llvm.ptr
      cf.br ^bb2
    ^bb1:
      cf.br ^bb2
    ^bb2:
    %74 = llvm.load %60 : !llvm.ptr -> i64
    func.return %74 : i64
  }
  func.func @unit_factorial(%arg0: i64) -> i64 {
    %75 = llvm.mlir.constant(1 : i64) : i64
    %76 = llvm.alloca %75 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %76 : i64, !llvm.ptr
    %77 = arith.constant 1 : i32
    %78 = arith.extsi %77 : i32 to i64
    %79 = llvm.mlir.constant(1 : i64) : i64
    %80 = llvm.alloca %79 x i64 : (i64) -> !llvm.ptr
    llvm.store %78, %80 : i64, !llvm.ptr
    cf.br ^bb3
    ^bb3:
    %81 = llvm.load %76 : !llvm.ptr -> i64
    %82 = arith.constant 0 : i32
    %84 = arith.extsi %82 : i32 to i64
    %83 = arith.cmpi ne, %81, %84 : i64
    cf.cond_br %83, ^bb4, ^bb5
    ^bb4:
      %85 = llvm.load %76 : !llvm.ptr -> i64
      %86 = llvm.mlir.addressof @P : !llvm.ptr
      %87 = llvm.load %86 : !llvm.ptr -> i64
      %88 = arith.divsi %85, %87 : i64
      %89 = llvm.load %76 : !llvm.ptr -> i64
      %90 = llvm.mlir.addressof @P : !llvm.ptr
      %91 = llvm.load %90 : !llvm.ptr -> i64
      %92 = arith.remsi %89, %91 : i64
      %94 = llvm.load %80 : !llvm.ptr -> i64
      %96 = llvm.mlir.addressof @fac : !llvm.ptr
      %97 = llvm.load %96 : !llvm.ptr -> !llvm.ptr
      %98 = llvm.getelementptr %97[%92] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %95 = llvm.load %98 : !llvm.ptr -> i64
      %99 = llvm.mlir.addressof @MOD : !llvm.ptr
      %100 = llvm.load %99 : !llvm.ptr -> i64
      %93 = func.call @mulmod(%94, %95, %100) : (i64, i64, i64) -> i64
      llvm.store %93, %80 : i64, !llvm.ptr
      %101 = llvm.mlir.addressof @P : !llvm.ptr
      %102 = llvm.load %101 : !llvm.ptr -> i64
      %103 = arith.remsi %88, %102 : i64
      %105 = llvm.mlir.addressof @H : !llvm.ptr
      %106 = llvm.load %105 : !llvm.ptr -> !llvm.ptr
      %107 = llvm.getelementptr %106[%92] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %104 = llvm.load %107 : !llvm.ptr -> i32
      %108 = arith.extsi %104 : i32 to i64
      %109 = arith.muli %103, %108 : i64
      %110 = llvm.mlir.addressof @P : !llvm.ptr
      %111 = llvm.load %110 : !llvm.ptr -> i64
      %112 = arith.remsi %109, %111 : i64
      %114 = llvm.load %80 : !llvm.ptr -> i64
      %115 = arith.constant 1 : i32
      %116 = llvm.mlir.addressof @P : !llvm.ptr
      %117 = llvm.load %116 : !llvm.ptr -> i64
      %118 = arith.muli %112, %117 : i64
      %120 = arith.extsi %115 : i32 to i64
      %119 = arith.addi %120, %118 : i64
      %121 = llvm.mlir.addressof @MOD : !llvm.ptr
      %122 = llvm.load %121 : !llvm.ptr -> i64
      %113 = func.call @mulmod(%114, %119, %122) : (i64, i64, i64) -> i64
      llvm.store %113, %80 : i64, !llvm.ptr
      %124 = llvm.load %80 : !llvm.ptr -> i64
      %125 = func.call @Fpow(%88) : (i64) -> i64
      %126 = llvm.mlir.addressof @MOD : !llvm.ptr
      %127 = llvm.load %126 : !llvm.ptr -> i64
      %123 = func.call @mulmod(%124, %125, %127) : (i64, i64, i64) -> i64
      llvm.store %123, %80 : i64, !llvm.ptr
      llvm.store %88, %76 : i64, !llvm.ptr
      cf.br ^bb3
    ^bb5:
    %128 = llvm.load %80 : !llvm.ptr -> i64
    func.return %128 : i64
  }
  func.func @vp_fact(%arg0: i64) -> i64 {
    %129 = llvm.mlir.addressof @P : !llvm.ptr
    %130 = llvm.load %129 : !llvm.ptr -> i64
    %131 = arith.divsi %arg0, %130 : i64
    %132 = llvm.mlir.addressof @P : !llvm.ptr
    %133 = llvm.load %132 : !llvm.ptr -> i64
    %134 = arith.divsi %131, %133 : i64
    %135 = arith.addi %131, %134 : i64
    func.return %135 : i64
  }
  func.func @binom_mod_p2(%arg0: i64, %arg1: i64) -> i64 {
    %136 = arith.cmpi sgt, %arg1, %arg0 : i64
    cf.cond_br %136, ^bb6, ^bb7
    ^bb6:
      %137 = arith.constant 0 : i32
      %138 = arith.extsi %137 : i32 to i64
      func.return %138 : i64
    ^bb7:
      cf.br ^bb8
    ^bb8:
    %139 = arith.subi %arg0, %arg1 : i64
    %140 = func.call @vp_fact(%arg0) : (i64) -> i64
    %141 = func.call @vp_fact(%arg1) : (i64) -> i64
    %142 = arith.subi %140, %141 : i64
    %143 = func.call @vp_fact(%139) : (i64) -> i64
    %144 = arith.subi %142, %143 : i64
    %145 = arith.constant 2 : i32
    %147 = arith.extsi %145 : i32 to i64
    %146 = arith.cmpi sge, %144, %147 : i64
    cf.cond_br %146, ^bb9, ^bb10
    ^bb9:
      %148 = arith.constant 0 : i32
      %149 = arith.extsi %148 : i32 to i64
      func.return %149 : i64
    ^bb10:
      cf.br ^bb11
    ^bb11:
    %150 = func.call @unit_factorial(%arg0) : (i64) -> i64
    %151 = func.call @unit_factorial(%arg1) : (i64) -> i64
    %152 = func.call @unit_factorial(%139) : (i64) -> i64
    %154 = func.call @inv_mod_p2(%151) : (i64) -> i64
    %155 = llvm.mlir.addressof @MOD : !llvm.ptr
    %156 = llvm.load %155 : !llvm.ptr -> i64
    %153 = func.call @mulmod(%150, %154, %156) : (i64, i64, i64) -> i64
    %157 = llvm.mlir.constant(1 : i64) : i64
    %158 = llvm.alloca %157 x i64 : (i64) -> !llvm.ptr
    llvm.store %153, %158 : i64, !llvm.ptr
    %160 = llvm.load %158 : !llvm.ptr -> i64
    %161 = func.call @inv_mod_p2(%152) : (i64) -> i64
    %162 = llvm.mlir.addressof @MOD : !llvm.ptr
    %163 = llvm.load %162 : !llvm.ptr -> i64
    %159 = func.call @mulmod(%160, %161, %163) : (i64, i64, i64) -> i64
    llvm.store %159, %158 : i64, !llvm.ptr
    %164 = arith.constant 1 : i32
    %166 = arith.extsi %164 : i32 to i64
    %165 = arith.cmpi eq, %144, %166 : i64
    cf.cond_br %165, ^bb12, ^bb13
    ^bb12:
      %168 = llvm.load %158 : !llvm.ptr -> i64
      %169 = llvm.mlir.addressof @P : !llvm.ptr
      %170 = llvm.load %169 : !llvm.ptr -> i64
      %171 = llvm.mlir.addressof @MOD : !llvm.ptr
      %172 = llvm.load %171 : !llvm.ptr -> i64
      %167 = func.call @mulmod(%168, %170, %172) : (i64, i64, i64) -> i64
      llvm.store %167, %158 : i64, !llvm.ptr
      cf.br ^bb14
    ^bb13:
      cf.br ^bb14
    ^bb14:
    %173 = llvm.load %158 : !llvm.ptr -> i64
    func.return %173 : i64
  }
  func.func @coeff_alpha_power(%arg0: i64, %arg1: i64) -> i64 {
    %174 = arith.constant 0 : i32
    %176 = arith.extsi %174 : i32 to i64
    %175 = arith.cmpi eq, %arg1, %176 : i64
    cf.cond_br %175, ^bb15, ^bb16
    ^bb15:
      %177 = arith.constant 1 : i32
      %178 = arith.extsi %177 : i32 to i64
      func.return %178 : i64
    ^bb16:
      cf.br ^bb17
    ^bb17:
    %180 = arith.subi %arg0, %arg1 : i64
    %181 = arith.constant 1 : i32
    %183 = arith.extsi %181 : i32 to i64
    %182 = arith.subi %180, %183 : i64
    %184 = arith.constant 1 : i32
    %186 = arith.extsi %184 : i32 to i64
    %185 = arith.subi %arg1, %186 : i64
    %179 = func.call @binom_mod_p2(%182, %185) : (i64, i64) -> i64
    %188 = llvm.mlir.addressof @MOD : !llvm.ptr
    %189 = llvm.load %188 : !llvm.ptr -> i64
    %190 = arith.remsi %arg0, %189 : i64
    %192 = llvm.mlir.addressof @MOD : !llvm.ptr
    %193 = llvm.load %192 : !llvm.ptr -> i64
    %194 = arith.remsi %arg1, %193 : i64
    %191 = func.call @inv_mod_p2(%194) : (i64) -> i64
    %195 = llvm.mlir.addressof @MOD : !llvm.ptr
    %196 = llvm.load %195 : !llvm.ptr -> i64
    %187 = func.call @mulmod(%190, %191, %196) : (i64, i64, i64) -> i64
    %198 = llvm.mlir.addressof @MOD : !llvm.ptr
    %199 = llvm.load %198 : !llvm.ptr -> i64
    %197 = func.call @mulmod(%187, %179, %199) : (i64, i64, i64) -> i64
    func.return %197 : i64
  }
  func.func @main() -> i32 {
    %201 = llvm.mlir.addressof @P : !llvm.ptr
    %202 = llvm.load %201 : !llvm.ptr -> i64
    %203 = arith.constant 4 : i32
    %204 = arith.extsi %203 : i32 to i64
    %200 = func.call @calloc(%202, %204) : (i64, i64) -> !llvm.ptr
    %205 = llvm.mlir.addressof @invp : !llvm.ptr
    llvm.store %200, %205 : !llvm.ptr, !llvm.ptr
    %207 = llvm.mlir.addressof @P : !llvm.ptr
    %208 = llvm.load %207 : !llvm.ptr -> i64
    %209 = arith.constant 4 : i32
    %210 = arith.extsi %209 : i32 to i64
    %206 = func.call @calloc(%208, %210) : (i64, i64) -> !llvm.ptr
    %211 = llvm.mlir.addressof @H : !llvm.ptr
    llvm.store %206, %211 : !llvm.ptr, !llvm.ptr
    %213 = llvm.mlir.addressof @P : !llvm.ptr
    %214 = llvm.load %213 : !llvm.ptr -> i64
    %215 = arith.constant 8 : i32
    %217 = arith.extsi %215 : i32 to i64
    %216 = arith.muli %214, %217 : i64
    %212 = func.call @malloc(%216) : (i64) -> !llvm.ptr
    %218 = llvm.mlir.addressof @fac : !llvm.ptr
    llvm.store %212, %218 : !llvm.ptr, !llvm.ptr
    %219 = llvm.mlir.addressof @invp : !llvm.ptr
    %220 = llvm.load %219 : !llvm.ptr -> !llvm.ptr
    %221 = llvm.mlir.zero : !llvm.ptr
    %222 = llvm.icmp "eq" %220, %221 : !llvm.ptr
    %223 = scf.if %222 -> (i1) {
      %224 = arith.constant true
      scf.yield %224 : i1
    } else {
      %225 = llvm.mlir.addressof @fac : !llvm.ptr
      %226 = llvm.load %225 : !llvm.ptr -> !llvm.ptr
      %227 = llvm.mlir.zero : !llvm.ptr
      %228 = llvm.icmp "eq" %226, %227 : !llvm.ptr
      scf.yield %228 : i1
    }
    %229 = scf.if %223 -> (i1) {
      %230 = arith.constant true
      scf.yield %230 : i1
    } else {
      %231 = llvm.mlir.addressof @H : !llvm.ptr
      %232 = llvm.load %231 : !llvm.ptr -> !llvm.ptr
      %233 = llvm.mlir.zero : !llvm.ptr
      %234 = llvm.icmp "eq" %232, %233 : !llvm.ptr
      scf.yield %234 : i1
    }
    cf.cond_br %229, ^bb18, ^bb19
    ^bb18:
      %235 = arith.constant 1 : i32
      func.return %235 : i32
    ^bb19:
      cf.br ^bb20
    ^bb20:
    %236 = arith.constant 1 : i32
    %237 = llvm.mlir.addressof @invp : !llvm.ptr
    %238 = llvm.load %237 : !llvm.ptr -> !llvm.ptr
    %239 = arith.constant 1 : i32
    %240 = arith.extsi %239 : i32 to i64
    %241 = llvm.getelementptr %238[%240] : (!llvm.ptr, i64) -> !llvm.ptr, i32
    llvm.store %236, %241 : i32, !llvm.ptr
    %242 = arith.constant 2 : i32
    %243 = arith.extsi %242 : i32 to i64
    %244 = llvm.mlir.constant(1 : i64) : i64
    %245 = llvm.alloca %244 x i64 : (i64) -> !llvm.ptr
    llvm.store %243, %245 : i64, !llvm.ptr
    cf.br ^bb21
    ^bb21:
    %246 = llvm.load %245 : !llvm.ptr -> i64
    %247 = llvm.mlir.addressof @P : !llvm.ptr
    %248 = llvm.load %247 : !llvm.ptr -> i64
    %249 = arith.cmpi slt, %246, %248 : i64
    cf.cond_br %249, ^bb22, ^bb23
    ^bb22:
      %250 = llvm.mlir.addressof @P : !llvm.ptr
      %251 = llvm.load %250 : !llvm.ptr -> i64
      %252 = llvm.mlir.addressof @P : !llvm.ptr
      %253 = llvm.load %252 : !llvm.ptr -> i64
      %254 = llvm.load %245 : !llvm.ptr -> i64
      %255 = arith.divsi %253, %254 : i64
      %257 = llvm.mlir.addressof @invp : !llvm.ptr
      %258 = llvm.load %257 : !llvm.ptr -> !llvm.ptr
      %259 = llvm.mlir.addressof @P : !llvm.ptr
      %260 = llvm.load %259 : !llvm.ptr -> i64
      %261 = llvm.load %245 : !llvm.ptr -> i64
      %262 = arith.remsi %260, %261 : i64
      %263 = llvm.getelementptr %258[%262] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %256 = llvm.load %263 : !llvm.ptr -> i32
      %264 = arith.extsi %256 : i32 to i64
      %265 = arith.muli %255, %264 : i64
      %266 = llvm.mlir.addressof @P : !llvm.ptr
      %267 = llvm.load %266 : !llvm.ptr -> i64
      %268 = arith.remsi %265, %267 : i64
      %269 = arith.subi %251, %268 : i64
      %270 = llvm.mlir.addressof @P : !llvm.ptr
      %271 = llvm.load %270 : !llvm.ptr -> i64
      %272 = arith.remsi %269, %271 : i64
      %273 = arith.trunci %272 : i64 to i32
      %274 = llvm.mlir.addressof @invp : !llvm.ptr
      %275 = llvm.load %274 : !llvm.ptr -> !llvm.ptr
      %276 = llvm.load %245 : !llvm.ptr -> i64
      %277 = llvm.getelementptr %275[%276] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      llvm.store %273, %277 : i32, !llvm.ptr
      %278 = llvm.load %245 : !llvm.ptr -> i64
      %279 = arith.constant 1 : i32
      %281 = arith.extsi %279 : i32 to i64
      %280 = arith.addi %278, %281 : i64
      llvm.store %280, %245 : i64, !llvm.ptr
      cf.br ^bb21
    ^bb23:
    %282 = arith.constant 1 : i32
    %283 = arith.extsi %282 : i32 to i64
    %284 = llvm.mlir.constant(1 : i64) : i64
    %285 = llvm.alloca %284 x i64 : (i64) -> !llvm.ptr
    llvm.store %283, %285 : i64, !llvm.ptr
    %286 = arith.constant 1 : i32
    %287 = llvm.mlir.addressof @fac : !llvm.ptr
    %288 = llvm.load %287 : !llvm.ptr -> !llvm.ptr
    %289 = arith.constant 0 : i32
    %290 = arith.extsi %286 : i32 to i64
    %291 = arith.extsi %289 : i32 to i64
    %292 = llvm.getelementptr %288[%291] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %290, %292 : i64, !llvm.ptr
    %293 = arith.constant 1 : i32
    %294 = arith.extsi %293 : i32 to i64
    %295 = llvm.mlir.constant(1 : i64) : i64
    %296 = llvm.alloca %295 x i64 : (i64) -> !llvm.ptr
    llvm.store %294, %296 : i64, !llvm.ptr
    cf.br ^bb24
    ^bb24:
    %297 = llvm.load %296 : !llvm.ptr -> i64
    %298 = llvm.mlir.addressof @P : !llvm.ptr
    %299 = llvm.load %298 : !llvm.ptr -> i64
    %300 = arith.cmpi slt, %297, %299 : i64
    cf.cond_br %300, ^bb25, ^bb26
    ^bb25:
      %302 = llvm.load %285 : !llvm.ptr -> i64
      %303 = llvm.load %296 : !llvm.ptr -> i64
      %304 = llvm.mlir.addressof @MOD : !llvm.ptr
      %305 = llvm.load %304 : !llvm.ptr -> i64
      %301 = func.call @mulmod(%302, %303, %305) : (i64, i64, i64) -> i64
      llvm.store %301, %285 : i64, !llvm.ptr
      %306 = llvm.load %285 : !llvm.ptr -> i64
      %307 = llvm.mlir.addressof @fac : !llvm.ptr
      %308 = llvm.load %307 : !llvm.ptr -> !llvm.ptr
      %309 = llvm.load %296 : !llvm.ptr -> i64
      %310 = llvm.getelementptr %308[%309] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %306, %310 : i64, !llvm.ptr
      %311 = llvm.load %296 : !llvm.ptr -> i64
      %312 = arith.constant 1 : i32
      %314 = arith.extsi %312 : i32 to i64
      %313 = arith.addi %311, %314 : i64
      llvm.store %313, %296 : i64, !llvm.ptr
      cf.br ^bb24
    ^bb26:
    %315 = arith.constant 0 : i32
    %316 = llvm.mlir.constant(1 : i64) : i64
    %317 = llvm.alloca %316 x i32 : (i64) -> !llvm.ptr
    llvm.store %315, %317 : i32, !llvm.ptr
    %318 = arith.constant 1 : i32
    %319 = arith.extsi %318 : i32 to i64
    %320 = llvm.mlir.constant(1 : i64) : i64
    %321 = llvm.alloca %320 x i64 : (i64) -> !llvm.ptr
    llvm.store %319, %321 : i64, !llvm.ptr
    cf.br ^bb27
    ^bb27:
    %322 = llvm.load %321 : !llvm.ptr -> i64
    %323 = llvm.mlir.addressof @P : !llvm.ptr
    %324 = llvm.load %323 : !llvm.ptr -> i64
    %325 = arith.cmpi slt, %322, %324 : i64
    cf.cond_br %325, ^bb28, ^bb29
    ^bb28:
      %326 = llvm.load %317 : !llvm.ptr -> i32
      %327 = arith.extsi %326 : i32 to i64
      %329 = llvm.mlir.addressof @invp : !llvm.ptr
      %330 = llvm.load %329 : !llvm.ptr -> !llvm.ptr
      %331 = llvm.load %321 : !llvm.ptr -> i64
      %332 = llvm.getelementptr %330[%331] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %328 = llvm.load %332 : !llvm.ptr -> i32
      %333 = arith.extsi %328 : i32 to i64
      %334 = arith.addi %327, %333 : i64
      %335 = llvm.mlir.addressof @P : !llvm.ptr
      %336 = llvm.load %335 : !llvm.ptr -> i64
      %337 = arith.remsi %334, %336 : i64
      %338 = arith.trunci %337 : i64 to i32
      llvm.store %338, %317 : i32, !llvm.ptr
      %339 = llvm.load %317 : !llvm.ptr -> i32
      %340 = llvm.mlir.addressof @H : !llvm.ptr
      %341 = llvm.load %340 : !llvm.ptr -> !llvm.ptr
      %342 = llvm.load %321 : !llvm.ptr -> i64
      %343 = llvm.getelementptr %341[%342] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      llvm.store %339, %343 : i32, !llvm.ptr
      %344 = llvm.load %321 : !llvm.ptr -> i64
      %345 = arith.constant 1 : i32
      %347 = arith.extsi %345 : i32 to i64
      %346 = arith.addi %344, %347 : i64
      llvm.store %346, %321 : i64, !llvm.ptr
      cf.br ^bb27
    ^bb29:
    %349 = llvm.mlir.addressof @fac : !llvm.ptr
    %350 = llvm.load %349 : !llvm.ptr -> !llvm.ptr
    %351 = llvm.mlir.addressof @P : !llvm.ptr
    %352 = llvm.load %351 : !llvm.ptr -> i64
    %353 = arith.constant 1 : i32
    %355 = arith.extsi %353 : i32 to i64
    %354 = arith.subi %352, %355 : i64
    %356 = llvm.getelementptr %350[%354] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %348 = llvm.load %356 : !llvm.ptr -> i64
    %357 = arith.constant 1 : i32
    %359 = arith.extsi %357 : i32 to i64
    %358 = arith.addi %348, %359 : i64
    %360 = llvm.mlir.addressof @P : !llvm.ptr
    %361 = llvm.load %360 : !llvm.ptr -> i64
    %362 = arith.divsi %358, %361 : i64
    %363 = llvm.mlir.addressof @P : !llvm.ptr
    %364 = llvm.load %363 : !llvm.ptr -> i64
    %365 = arith.remsi %362, %364 : i64
    %366 = llvm.mlir.addressof @w : !llvm.ptr
    llvm.store %365, %366 : i64, !llvm.ptr
    %367 = arith.constant 1000000000 : i32
    %368 = arith.extsi %367 : i32 to i64
    %369 = arith.constant 999995705032704 : i32
    %370 = arith.extsi %369 : i32 to i64
    %371 = arith.divsi %370, %368 : i64
    %372 = arith.constant 1 : i32
    %373 = arith.extsi %372 : i32 to i64
    %374 = llvm.mlir.constant(1 : i64) : i64
    %375 = llvm.alloca %374 x i64 : (i64) -> !llvm.ptr
    llvm.store %373, %375 : i64, !llvm.ptr
    %376 = arith.constant 0 : i32
    %377 = arith.extsi %376 : i32 to i64
    %378 = llvm.mlir.constant(1 : i64) : i64
    %379 = llvm.alloca %378 x i64 : (i64) -> !llvm.ptr
    llvm.store %377, %379 : i64, !llvm.ptr
    %380 = llvm.mlir.constant(1 : i64) : i64
    %381 = llvm.alloca %380 x i64 : (i64) -> !llvm.ptr
    llvm.store %370, %381 : i64, !llvm.ptr
    %382 = arith.muli %368, %368 : i64
    %383 = llvm.mlir.constant(1 : i64) : i64
    %384 = llvm.alloca %383 x i64 : (i64) -> !llvm.ptr
    llvm.store %382, %384 : i64, !llvm.ptr
    %385 = arith.constant 0 : i32
    %386 = arith.extsi %385 : i32 to i64
    %387 = llvm.mlir.constant(1 : i64) : i64
    %388 = llvm.alloca %387 x i64 : (i64) -> !llvm.ptr
    llvm.store %386, %388 : i64, !llvm.ptr
    cf.br ^bb30
    ^bb30:
    %389 = llvm.load %388 : !llvm.ptr -> i64
    %390 = arith.cmpi sle, %389, %371 : i64
    cf.cond_br %390, ^bb31, ^bb32
    ^bb31:
      %391 = llvm.load %388 : !llvm.ptr -> i64
      %392 = arith.constant 0 : i32
      %394 = arith.extsi %392 : i32 to i64
      %393 = arith.cmpi ne, %391, %394 : i64
      cf.cond_br %393, ^bb33, ^bb34
      ^bb33:
        %396 = llvm.load %375 : !llvm.ptr -> i64
        %397 = llvm.load %388 : !llvm.ptr -> i64
        %398 = arith.subi %368, %397 : i64
        %399 = arith.constant 1 : i32
        %401 = arith.extsi %399 : i32 to i64
        %400 = arith.addi %398, %401 : i64
        %402 = llvm.mlir.addressof @MOD : !llvm.ptr
        %403 = llvm.load %402 : !llvm.ptr -> i64
        %404 = arith.remsi %400, %403 : i64
        %405 = llvm.mlir.addressof @MOD : !llvm.ptr
        %406 = llvm.load %405 : !llvm.ptr -> i64
        %395 = func.call @mulmod(%396, %404, %406) : (i64, i64, i64) -> i64
        llvm.store %395, %375 : i64, !llvm.ptr
        %408 = llvm.load %375 : !llvm.ptr -> i64
        %410 = llvm.load %388 : !llvm.ptr -> i64
        %409 = func.call @inv_mod_p2(%410) : (i64) -> i64
        %411 = llvm.mlir.addressof @MOD : !llvm.ptr
        %412 = llvm.load %411 : !llvm.ptr -> i64
        %407 = func.call @mulmod(%408, %409, %412) : (i64, i64, i64) -> i64
        llvm.store %407, %375 : i64, !llvm.ptr
        cf.br ^bb35
      ^bb34:
        cf.br ^bb35
      ^bb35:
      %413 = llvm.load %379 : !llvm.ptr -> i64
      %415 = llvm.load %375 : !llvm.ptr -> i64
      %417 = llvm.load %384 : !llvm.ptr -> i64
      %418 = llvm.load %381 : !llvm.ptr -> i64
      %416 = func.call @coeff_alpha_power(%417, %418) : (i64, i64) -> i64
      %419 = llvm.mlir.addressof @MOD : !llvm.ptr
      %420 = llvm.load %419 : !llvm.ptr -> i64
      %414 = func.call @mulmod(%415, %416, %420) : (i64, i64, i64) -> i64
      %421 = arith.addi %413, %414 : i64
      %422 = llvm.mlir.addressof @MOD : !llvm.ptr
      %423 = llvm.load %422 : !llvm.ptr -> i64
      %424 = arith.remsi %421, %423 : i64
      llvm.store %424, %379 : i64, !llvm.ptr
      %425 = llvm.load %381 : !llvm.ptr -> i64
      %426 = arith.subi %425, %368 : i64
      llvm.store %426, %381 : i64, !llvm.ptr
      %427 = llvm.load %384 : !llvm.ptr -> i64
      %428 = arith.constant 2 : i32
      %430 = arith.extsi %428 : i32 to i64
      %429 = arith.muli %430, %368 : i64
      %431 = arith.subi %427, %429 : i64
      llvm.store %431, %384 : i64, !llvm.ptr
      %432 = llvm.load %388 : !llvm.ptr -> i64
      %433 = arith.constant 1 : i32
      %435 = arith.extsi %433 : i32 to i64
      %434 = arith.addi %432, %435 : i64
      llvm.store %434, %388 : i64, !llvm.ptr
      cf.br ^bb30
    ^bb32:
    %437 = llvm.mlir.addressof @invp : !llvm.ptr
    %438 = llvm.load %437 : !llvm.ptr -> !llvm.ptr
    func.call @free(%438) : (!llvm.ptr) -> ()
    %440 = llvm.mlir.addressof @fac : !llvm.ptr
    %441 = llvm.load %440 : !llvm.ptr -> !llvm.ptr
    func.call @free(%441) : (!llvm.ptr) -> ()
    %443 = llvm.mlir.addressof @H : !llvm.ptr
    %444 = llvm.load %443 : !llvm.ptr -> !llvm.ptr
    func.call @free(%444) : (!llvm.ptr) -> ()
    %445 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %446 = llvm.load %379 : !llvm.ptr -> i64
    %447 = llvm.call @printf(%445, %446) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    %448 = arith.constant 0 : i32
    func.return %448 : i32
  }
}