Problem 889

Rational Blancmange: F(10^18+31, 10^14+31, 62) mod 1000062031.

Answer424315113
Output424315113
StatusPASS
Native helperno
Runtime0 ms
Peak memory1136 KB
Time complexityO(n^2) (estimated)
Space complexityO(n^2) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^2)O(n)
Space complexityO(n^2)O(1)
ApproachFlow solutionNumerical iteration
VerdictSuboptimal

Flow source

# Project Euler 889
# Rational Blancmange: F(10^18+31, 10^14+31, 62) mod 1000062031.

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

const MOD: i64 = 1000062031

function mulmod(a0: i64, b0: i64, m: i64) -> i64 {
    let a_w: i128 = a0 as i128
    let b_w: i128 = b0 as i128
    let m_w: i128 = m as i128
    let r: i128 = (a_w * b_w) % m_w
    return r as i64
}

function powmod(a0: i64, e0: i64, m: i64) -> i64 {
    let mut r: i64 = 1 % m
    let mut a: i64 = a0 % m
    let mut e: i64 = e0
    while e > 0 {
        if (e & 1) == 1 { r = mulmod(r, a, m) }
        a = mulmod(a, a, m)
        e = e >> 1
    }
    return r
}

function popcount_u64(x0: i64) -> i32 {
    let mut x: i64 = x0
    let mut count: i32 = 0
    while x != 0 {
        count = count + 1
        x = x & (x - 1)
    }
    return count
}

function bitlen_u64(x0: i64) -> i32 {
    if x0 == 0 { return 0 }
    let mut x: i64 = x0
    let mut n: i32 = 0
    while x != 0 {
        n = n + 1
        x = x >> 1
    }
    return n
}

function ctz_u64(x0: i64) -> i32 {
    if x0 == 0 { return 64 }
    let mut x: i64 = x0
    let mut n: i32 = 0
    while (x & 1) == 0 {
        n = n + 1
        x = x >> 1
    }
    return n
}

function binom_small(n: i32, k: i32) -> i64 {
    if k < 0 || k > n { return 0 }
    let mut kk: i32 = k
    if kk > n - kk { kk = n - kk }
    let mut r: i128 = 1
    let mut i: i32 = 0
    while i < kk {
        r = r * ((n - i) as i128) / ((i + 1) as i128)
        i = i + 1
    }
    return r as i64
}

function bit_positions_of_N(t: i64, r: i32, positions: ptr<i64>) -> i32 {
    let mut n: i32 = 0
    let mut u: i32 = 0
    while u <= r {
        let mut c: i64 = binom_small(r, u)
        let base: i64 = t * (u as i64)
        while c > 0 {
            let b: i32 = ctz_u64(c)
            positions[n] = base + (b as i64)
            n = n + 1
            c = c & (c - 1)
        }
        u = u + 1
    }
    # insertion sort
    let mut i: i32 = 1
    while i < n {
        let key: i64 = positions[i]
        let mut j: i32 = i - 1
        while j >= 0 && positions[j] > key {
            positions[j + 1] = positions[j]
            j = j - 1
        }
        positions[j + 1] = key
        i = i + 1
    }
    return n
}

function fast_F_mod(k: i64, t: i64, r: i32, mod: i64) -> i64 {
    let positions: ptr<i64> = calloc(4000, 8)
    let n: i32 = bit_positions_of_N(t, r, positions)
    let max_pos: i64 = positions[n - 1]

    let pow2_k: i64 = powmod(2, k, mod)

    let vals_low: ptr<i64> = calloc(n as i64, 8)
    let vals_high: ptr<i64> = calloc(n as i64, 8)
    let mut i: i32 = 0
    while i < n {
        vals_low[i] = powmod(2, positions[i], mod)
        vals_high[i] = mulmod(pow2_k, vals_low[i], mod)
        i = i + 1
    }

    let prefix_low: ptr<i64> = calloc(((n + 1) as i64), 8)
    let prefix_high: ptr<i64> = calloc(((n + 1) as i64), 8)
    prefix_low[0] = 0
    prefix_high[0] = 0
    i = 0
    while i < n {
        prefix_low[i + 1] = (prefix_low[i] + vals_low[i]) % mod
        prefix_high[i + 1] = (prefix_high[i] + vals_high[i]) % mod
        i = i + 1
    }
    let total_low: i64 = prefix_low[n]

    let mut ans: i64 = 0
    i = 0
    while i < n {
        let p: i64 = positions[i]
        let v_low: i64 = vals_low[i]
        let v_high: i64 = vals_high[i]
        let km: i64 = k % mod
        let pm: i64 = p % mod
        let term: i64 = mulmod((km + mod - pm) % mod, v_high, mod)
        let term2: i64 = (term + mod - mulmod(pm, v_low, mod)) % mod
        ans = (ans + term2) % mod
        i = i + 1
    }

    # Corrections
    i = 1
    while i < n {
        let p0: i64 = positions[i]
        let sum_high_le: i64 = prefix_high[i + 1]
        let sum_low_gt: i64 = (total_low + mod - prefix_low[i + 1]) % mod
        let S: i64 = (sum_high_le + mod - sum_low_gt) % mod
        let pow2_p0_plus1: i64 = mulmod(vals_low[i], 2, mod)
        let q_times: i64 = mulmod((pow2_k + 1) % mod, pow2_p0_plus1, mod)
        let delta: i64 = (q_times + mod - mulmod(S, 2, mod)) % mod
        ans = (ans + delta) % mod
        i = i + 1
    }

    free(positions)
    free(vals_low)
    free(vals_high)
    free(prefix_low)
    free(prefix_high)
    return ans
}

function main() -> i32 {
    let k: i64 = 1000000000000000031
    let t: i64 = 100000000000031
    let r: i32 = 62
    let ans: i64 = fast_F_mod(k, t, r, MOD)
    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 a0, int64_t b0, int64_t m);
int64_t powmod_i64_i64_i64(int64_t a0, int64_t e0, int64_t m);
int32_t popcount_u64_i64(int64_t x0);
int32_t bitlen_u64_i64(int64_t x0);
int32_t ctz_u64_i64(int64_t x0);
int64_t binom_small_i32_i32(int32_t n, int32_t k);
int32_t bit_positions_of_N_i64_i32_ptr_i64(int64_t t, int32_t r, int64_t* positions);
int64_t fast_F_mod_i64_i64_i32_i64(int64_t k, int64_t t, int32_t r, int64_t mod);
int32_t main(void);

static const int64_t MOD = 1000062031;



int64_t mulmod_i64_i64_i64(int64_t a0, int64_t b0, int64_t m) {
    __int128 a_w = ((__int128)(a0));
    __int128 b_w = ((__int128)(b0));
    __int128 m_w = ((__int128)(m));
    __int128 r = FLOW_CHECKED_MOD(((a_w * b_w)), (m_w));
    return ((int64_t)(r));
}

int64_t powmod_i64_i64_i64(int64_t a0, int64_t e0, int64_t m) {
    int64_t r = FLOW_CHECKED_MOD((1), (m));
    int64_t a = FLOW_CHECKED_MOD((a0), (m));
    int64_t e = e0;
    while (e > 0) {
        if ((e & 1) == 1) {
            r = mulmod_i64_i64_i64(r, a, m);
        }
        a = mulmod_i64_i64_i64(a, a, m);
        e = FLOW_CHECKED_SHR((e), (1));
    }
    return r;
}

int32_t popcount_u64_i64(int64_t x0) {
    int64_t x = x0;
    int32_t count = 0;
    while (x != 0) {
        count = (count + 1);
        x = (x & (x - 1));
    }
    return count;
}

int32_t bitlen_u64_i64(int64_t x0) {
    if (x0 == 0) {
        return 0;
    }
    int64_t x = x0;
    int32_t n = 0;
    while (x != 0) {
        n = (n + 1);
        x = FLOW_CHECKED_SHR((x), (1));
    }
    return n;
}

int32_t ctz_u64_i64(int64_t x0) {
    if (x0 == 0) {
        return 64;
    }
    int64_t x = x0;
    int32_t n = 0;
    while ((x & 1) == 0) {
        n = (n + 1);
        x = FLOW_CHECKED_SHR((x), (1));
    }
    return n;
}

int64_t binom_small_i32_i32(int32_t n, int32_t k) {
    if ((k < 0 || k > n)) {
        return 0;
    }
    int32_t kk = k;
    if (kk > (n - kk)) {
        kk = (n - kk);
    }
    __int128 r = 1;
    int32_t i = 0;
    while (i < kk) {
        r = FLOW_CHECKED_DIV(((r * ((__int128)((n - i))))), (((__int128)((i + 1)))));
        i = (i + 1);
    }
    return ((int64_t)(r));
}

int32_t bit_positions_of_N_i64_i32_ptr_i64(int64_t t, int32_t r, int64_t* positions) {
    int32_t n = 0;
    int32_t u = 0;
    while (u <= r) {
        int64_t c = binom_small_i32_i32(r, u);
        int64_t base = (t * ((int64_t)(u)));
        while (c > 0) {
            int32_t b = ctz_u64_i64(c);
            positions[n] = (base + ((int64_t)(b)));
            n = (n + 1);
            c = (c & (c - 1));
        }
        u = (u + 1);
    }
    int32_t i = 1;
    while (i < n) {
        int64_t key = positions[i];
        int32_t j = (i - 1);
        while ((j >= 0 && positions[j] > key)) {
            positions[(j + 1)] = positions[j];
            j = (j - 1);
        }
        positions[(j + 1)] = key;
        i = (i + 1);
    }
    return n;
}

int64_t fast_F_mod_i64_i64_i32_i64(int64_t k, int64_t t, int32_t r, int64_t mod) {
    int64_t* positions = (int64_t*)(calloc(4000, 8));
    int32_t n = bit_positions_of_N_i64_i32_ptr_i64(t, r, positions);
    int64_t max_pos = positions[(n - 1)];
    int64_t pow2_k = powmod_i64_i64_i64(2, k, mod);
    int64_t* vals_low = (int64_t*)(calloc(((int64_t)(n)), 8));
    int64_t* vals_high = (int64_t*)(calloc(((int64_t)(n)), 8));
    int32_t i = 0;
    while (i < n) {
        vals_low[i] = powmod_i64_i64_i64(2, positions[i], mod);
        vals_high[i] = mulmod_i64_i64_i64(pow2_k, vals_low[i], mod);
        i = (i + 1);
    }
    int64_t* prefix_low = (int64_t*)(calloc(((int64_t)((n + 1))), 8));
    int64_t* prefix_high = (int64_t*)(calloc(((int64_t)((n + 1))), 8));
    prefix_low[0] = 0;
    prefix_high[0] = 0;
    i = 0;
    while (i < n) {
        prefix_low[(i + 1)] = FLOW_CHECKED_MOD(((prefix_low[i] + vals_low[i])), (mod));
        prefix_high[(i + 1)] = FLOW_CHECKED_MOD(((prefix_high[i] + vals_high[i])), (mod));
        i = (i + 1);
    }
    int64_t total_low = prefix_low[n];
    int64_t ans = 0;
    i = 0;
    while (i < n) {
        int64_t p = positions[i];
        int64_t v_low = vals_low[i];
        int64_t v_high = vals_high[i];
        int64_t km = FLOW_CHECKED_MOD((k), (mod));
        int64_t pm = FLOW_CHECKED_MOD((p), (mod));
        int64_t term = mulmod_i64_i64_i64(FLOW_CHECKED_MOD((((km + mod) - pm)), (mod)), v_high, mod);
        int64_t term2 = FLOW_CHECKED_MOD((((term + mod) - mulmod_i64_i64_i64(pm, v_low, mod))), (mod));
        ans = FLOW_CHECKED_MOD(((ans + term2)), (mod));
        i = (i + 1);
    }
    i = 1;
    while (i < n) {
        int64_t p0 = positions[i];
        int64_t sum_high_le = prefix_high[(i + 1)];
        int64_t sum_low_gt = FLOW_CHECKED_MOD((((total_low + mod) - prefix_low[(i + 1)])), (mod));
        int64_t S = FLOW_CHECKED_MOD((((sum_high_le + mod) - sum_low_gt)), (mod));
        int64_t pow2_p0_plus1 = mulmod_i64_i64_i64(vals_low[i], 2, mod);
        int64_t q_times = mulmod_i64_i64_i64(FLOW_CHECKED_MOD(((pow2_k + 1)), (mod)), pow2_p0_plus1, mod);
        int64_t delta = FLOW_CHECKED_MOD((((q_times + mod) - mulmod_i64_i64_i64(S, 2, mod))), (mod));
        ans = FLOW_CHECKED_MOD(((ans + delta)), (mod));
        i = (i + 1);
    }
    free(positions);
    free(vals_low);
    free(vals_high);
    free(prefix_low);
    free(prefix_high);
    return ans;
}

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