Problem 492

Exploding Sequence — B(10^9, 10^7, 10^15).

Answer242586962923928
Output242586962923928
StatusPASS
Native helperno
Runtime460 ms
Peak memory6112 KB
Time complexityO(n^2) (estimated)
Space complexityO(n^2) (estimated)

Performance comparison

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

Flow source

# Project Euler 492
# Exploding Sequence — B(10^9, 10^7, 10^15).

import euler.nt { isqrt }

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

let mut P_LUCAS: i64 = 11

function modpow(base0: i64, exp0: i64, mod: i64) -> i64 {
    let mut r: i64 = 1
    let mut b: i64 = base0 % mod
    let mut e: i64 = exp0
    if b < 0 { b = b + mod }
    while e > 0 {
        if e % 2 == 1 {
            r = (r * b) % mod
        }
        b = (b * b) % mod
        e = e / 2
    }
    return r
}

function bit_length(n0: i64) -> i64 {
    let mut n: i64 = n0
    let mut k: i64 = 0
    while n > 0 {
        n = n / 2
        k = k + 1
    }
    return k
}

# Return U_n mod mod for Lucas(P=11, Q=1); also writes U_{n+1} into up1_out[0].
function lucas_U_pair(n0: i64, mod: i64, up1_out: ptr<i64>) -> i64 {
    if n0 == 0 {
        up1_out[0] = 1
        return 0
    }
    let mut u: i64 = 0
    let mut up1: i64 = 1
    let mut mask: i64 = 1
    let bl: i64 = bit_length(n0)
    let mut s: i64 = 1
    while s < bl {
        mask = mask * 2
        s = s + 1
    }
    # mask = 2^(bit_length-1)
    while mask > 0 {
        let mut v: i64 = (2 * up1 - P_LUCAS * u) % mod
        if v < 0 { v = v + mod }
        let u2k: i64 = (u * v) % mod
        let mut u2k1: i64 = (up1 * v - 1) % mod
        if u2k1 < 0 { u2k1 = u2k1 + mod }
        if (n0 & mask) != 0 {
            let mut u2k2: i64 = (P_LUCAS * u2k1 - u2k) % mod
            if u2k2 < 0 { u2k2 = u2k2 + mod }
            u = u2k1
            up1 = u2k2
        } else {
            u = u2k
            up1 = u2k1
        }
        mask = mask / 2
    }
    up1_out[0] = up1
    return u
}

function lucas_V(n: i64, mod: i64) -> i64 {
    let up1_out: ptr<i64> = calloc(1, 8)
    let u: i64 = lucas_U_pair(n, mod, up1_out)
    let up1: i64 = up1_out[0]
    free(up1_out)
    let mut r: i64 = (2 * up1 - P_LUCAS * u) % mod
    if r < 0 { r = r + mod }
    return r
}

function residue13(p: i64) -> bool {
    let r: i64 = p % 13
    if r == 1 { return true }
    if r == 3 { return true }
    if r == 4 { return true }
    if r == 9 { return true }
    if r == 10 { return true }
    if r == 12 { return true }
    return false
}

function a_mod_prime(n: i64, p: i64) -> i64 {
    if p == 2 {
        return 1 % p
    }
    if p == 3 {
        let mut a: i64 = 1 % p
        let mut t: i64 = 1
        while t < n {
            a = (6 * a * a + 10 * a + 3) % p
            t = t + 1
        }
        return a
    }
    let mut leg: i64 = 0 - 1
    if residue13(p) {
        leg = 1
    }
    let mm: i64 = p - leg
    let e: i64 = modpow(2, n - 1, mm)
    let u_n: i64 = lucas_V(e, p)
    let inv6: i64 = modpow(6, p - 2, p)
    let mut r: i64 = ((u_n - 5) % p) * inv6 % p
    if r < 0 { r = r + p }
    return r
}

function main() -> i32 {
    let X: i64 = 1000000000
    let Y: i64 = 10000000
    let N: i64 = 1000000000000000
    let high: i64 = X + Y
    let base_limit: i64 = isqrt(high) + 1

    let sieve: ptr<i8> = calloc(base_limit + 1, 1)
    if sieve == null { return 1 }
    let mut i: i64 = 0
    while i <= base_limit {
        sieve[i] = 1
        i = i + 1
    }
    if base_limit >= 0 { sieve[0] = 0 }
    if base_limit >= 1 { sieve[1] = 0 }
    i = 2
    while i * i <= base_limit {
        if sieve[i] == 1 {
            let mut j: i64 = i * i
            while j <= base_limit {
                sieve[j] = 0
                j = j + i
            }
        }
        i = i + 1
    }

    let mut nbase: i64 = 0
    i = 2
    while i <= base_limit {
        if sieve[i] == 1 { nbase = nbase + 1 }
        i = i + 1
    }
    let base_primes: ptr<i64> = calloc(nbase, 8)
    if base_primes == null { return 1 }
    let mut bi: i64 = 0
    i = 2
    while i <= base_limit {
        if sieve[i] == 1 {
            base_primes[bi] = i
            bi = bi + 1
        }
        i = i + 1
    }

    # Segmented sieve over [X, X+Y], odd-only.
    let mut start: i64 = X
    if (start & 1) == 0 { start = start + 1 }
    let seg_size: i64 = ((high - start) / 2) + 1
    let seg: ptr<i8> = calloc(seg_size, 1)
    if seg == null { return 1 }
    i = 0
    while i < seg_size {
        seg[i] = 1
        i = i + 1
    }

    bi = 0
    while bi < nbase {
        let q: i64 = base_primes[bi]
        if q == 2 {
            bi = bi + 1
            continue
        }
        let qq: i64 = q * q
        if qq > high { break }
        let mut first: i64 = 0
        if qq >= start {
            first = qq
        } else {
            first = ((start + q - 1) / q) * q
        }
        if (first & 1) == 0 { first = first + q }
        let mut idx: i64 = (first - start) / 2
        while idx < seg_size {
            seg[idx] = 0
            idx = idx + q
        }
        bi = bi + 1
    }

    let mut total: i64 = 0
    if X <= 2 {
        if 2 <= high {
            total = total + a_mod_prime(N, 2)
        }
    }
    i = 0
    while i < seg_size {
        if seg[i] == 1 {
            let p: i64 = start + 2 * i
            if p >= X {
                if p <= high {
                    total = total + a_mod_prime(N, p)
                }
            }
        }
        i = i + 1
    }

    printf("%lld\n", total)
    free(sieve)
    free(base_primes)
    free(seg)
    return 0
}

Generated C

#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* Flow runtime helpers */
typedef struct flow_temp_node { struct flow_temp_node* next; } flow_temp_node;
static flow_temp_node* flow_temp_head = NULL;
static int flow_temp_atexit_set = 0;
__attribute__((unused)) static void flow_temp_free_all(void) {
    while (flow_temp_head) {
        flow_temp_node* n = flow_temp_head;
        flow_temp_head = n->next;
        free(n);
    }
}
__attribute__((unused)) static void* flow_temp_alloc(size_t nbytes) {
    flow_temp_node* node = (flow_temp_node*)malloc(sizeof(flow_temp_node) + nbytes);
    if (!node) return NULL;
    node->next = flow_temp_head;
    flow_temp_head = node;
    if (!flow_temp_atexit_set) {
        flow_temp_atexit_set = 1;
        atexit(flow_temp_free_all);
    }
    return (void*)(node + 1);
}
#ifndef FLOW_DIAG
#define FLOW_DIAG(msg) fprintf(stderr, "%s", (msg))
#endif
#ifndef FLOW_LOG
#define FLOW_LOG(fmt, ...) printf(fmt, __VA_ARGS__)
#endif
#ifndef FLOW_LOG_EMPTY
#define FLOW_LOG_EMPTY(fmt) printf(fmt)
#endif
static char* flow_strcat(const char* a, const char* b) {
    size_t la = strlen(a ? a : ""), lb = strlen(b ? b : "");
    char* r = (char*)flow_temp_alloc(la + lb + 1);
    if (!r) return NULL;
    if (la) memcpy(r, a, la);
    if (lb) memcpy(r + la, b, lb);
    r[la + lb] = '\0';
    return r;
}

#define __flow_in_arr(arr, val) __extension__ ({ \
    int _found = 0; \
    size_t _n = sizeof(arr)/sizeof((arr)[0]); \
    for (size_t _i = 0; _i < _n; _i++) { \
        if ((arr)[_i] == (val)) { _found = 1; break; } \
    } _found; })

/* Unified fault handler (MISRA #279) — override with -DFLOW_FAULT_HANDLER=fn */
#ifndef FLOW_FAULT_HANDLER
__attribute__((unused)) static inline void flow_fault_handler(const char* msg) {
    fprintf(stderr, "flow: %s\n", msg ? msg : "fault");
    abort();
#if defined(__GNUC__) || defined(__clang__)
    __builtin_unreachable();
#endif
}
#else
#define flow_fault_handler FLOW_FAULT_HANDLER
#endif
#define flow_div_by_zero_handler() flow_fault_handler("division by zero")
#define flow_shift_ub_handler() flow_fault_handler("invalid shift (amount out of range or left-shift of negative)")

#ifndef FLOW_CHECKED_DIV
#define FLOW_CHECKED_DIV(L, R) (((R) != 0) ? ((L) / (R)) : (flow_div_by_zero_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_MOD
#define FLOW_CHECKED_MOD(L, R) (((R) != 0) ? ((L) % (R)) : (flow_div_by_zero_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_SHL
#define FLOW_CHECKED_SHL(L, R) ((((R) >= 0) && ((unsigned long long)(R) < (sizeof(L) * 8ull)) && ((L) >= 0)) ? ((L) << (R)) : (flow_shift_ub_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_SHR
#define FLOW_CHECKED_SHR(L, R) ((((R) >= 0) && ((unsigned long long)(R) < (sizeof(L) * 8ull))) ? ((L) >> (R)) : (flow_shift_ub_handler(), (L) * 0))
#endif

#include <math.h>

void* _ui_state = NULL;

static inline float i32_to_f32(int32_t v) { return (float)v; }

/* Host stub for @gpu kernels (device codegen replaces this). */
static inline int32_t gpu_thread_id(void) { return 0; }

int64_t gcd_i64_i64(int64_t a0, int64_t b0);
int64_t lcm_i64_i64(int64_t a, int64_t b);
int64_t isqrt_i64(int64_t n);
int64_t mulmod_i64_i64_i64(int64_t a0, int64_t b0, int64_t mod);
int64_t mod_pow_i64_i64_i64(int64_t base, int64_t exp, int64_t mod);
bool is_prime_i64(int64_t n);
int64_t modpow_i64_i64_i64(int64_t base0, int64_t exp0, int64_t mod);
int64_t bit_length_i64(int64_t n0);
int64_t lucas_U_pair_i64_i64_ptr_i64(int64_t n0, int64_t mod, int64_t* up1_out);
int64_t lucas_V_i64_i64(int64_t n, int64_t mod);
bool residue13_i64(int64_t p);
int64_t a_mod_prime_i64_i64(int64_t n, int64_t p);
int32_t main(void);

/* Module statics */
static int64_t P_LUCAS = 11;

int64_t gcd_i64_i64(int64_t a0, int64_t b0) {
    int64_t a = a0;
    int64_t b = b0;
    while (b != 0) {
        int64_t t = FLOW_CHECKED_MOD((a), (b));
        a = b;
        b = t;
    }
    return a;
}

int64_t lcm_i64_i64(int64_t a, int64_t b) {
    if ((a == 0 || b == 0)) {
        return 0;
    }
    return (FLOW_CHECKED_DIV((a), (gcd_i64_i64(a, b))) * b);
}

int64_t isqrt_i64(int64_t n) {
    if (n < 2) {
        return n;
    }
    int64_t x = n;
    int64_t y = FLOW_CHECKED_DIV(((x + 1)), (2));
    while (y < x) {
        x = y;
        y = FLOW_CHECKED_DIV(((x + FLOW_CHECKED_DIV((n), (x)))), (2));
    }
    return x;
}

int64_t mulmod_i64_i64_i64(int64_t a0, int64_t b0, int64_t mod) {
    int64_t a = FLOW_CHECKED_MOD((a0), (mod));
    int64_t b = FLOW_CHECKED_MOD((b0), (mod));
    int64_t result = 0;
    while (b > 0) {
        if (FLOW_CHECKED_MOD((b), (2)) == 1) {
            result = FLOW_CHECKED_MOD(((result + a)), (mod));
        }
        a = FLOW_CHECKED_MOD(((a * 2)), (mod));
        b = FLOW_CHECKED_DIV((b), (2));
    }
    return result;
}

int64_t mod_pow_i64_i64_i64(int64_t base, int64_t exp, int64_t mod) {
    if (mod == 1) {
        return 0;
    }
    int64_t result = 1;
    int64_t b = FLOW_CHECKED_MOD((base), (mod));
    int64_t e = exp;
    while (e > 0) {
        if (FLOW_CHECKED_MOD((e), (2)) == 1) {
            result = mulmod_i64_i64_i64(result, b, mod);
        }
        b = mulmod_i64_i64_i64(b, b, mod);
        e = FLOW_CHECKED_DIV((e), (2));
    }
    return result;
}

bool is_prime_i64(int64_t n) {
    if (n < 2) {
        return 0;
    }
    if (n < 4) {
        return 1;
    }
    if ((FLOW_CHECKED_MOD((n), (2)) == 0 || FLOW_CHECKED_MOD((n), (3)) == 0)) {
        return 0;
    }
    int64_t i = 5;
    while ((i * i) <= n) {
        if ((FLOW_CHECKED_MOD((n), (i)) == 0 || FLOW_CHECKED_MOD((n), ((i + 2))) == 0)) {
            return 0;
        }
        i = (i + 6);
    }
    return 1;
}



int64_t modpow_i64_i64_i64(int64_t base0, int64_t exp0, int64_t mod) {
    int64_t r = 1;
    int64_t b = FLOW_CHECKED_MOD((base0), (mod));
    int64_t e = exp0;
    if (b < 0) {
        b = (b + mod);
    }
    while (e > 0) {
        if (FLOW_CHECKED_MOD((e), (2)) == 1) {
            r = FLOW_CHECKED_MOD(((r * b)), (mod));
        }
        b = FLOW_CHECKED_MOD(((b * b)), (mod));
        e = FLOW_CHECKED_DIV((e), (2));
    }
    return r;
}

int64_t bit_length_i64(int64_t n0) {
    int64_t n = n0;
    int64_t k = 0;
    while (n > 0) {
        n = FLOW_CHECKED_DIV((n), (2));
        k = (k + 1);
    }
    return k;
}

int64_t lucas_U_pair_i64_i64_ptr_i64(int64_t n0, int64_t mod, int64_t* up1_out) {
    if (n0 == 0) {
        up1_out[0] = 1;
        return 0;
    }
    int64_t u = 0;
    int64_t up1 = 1;
    int64_t mask = 1;
    int64_t bl = bit_length_i64(n0);
    int64_t s = 1;
    while (s < bl) {
        mask = (mask * 2);
        s = (s + 1);
    }
    while (mask > 0) {
        int64_t v = FLOW_CHECKED_MOD((((2 * up1) - (P_LUCAS * u))), (mod));
        if (v < 0) {
            v = (v + mod);
        }
        int64_t u2k = FLOW_CHECKED_MOD(((u * v)), (mod));
        int64_t u2k1 = FLOW_CHECKED_MOD((((up1 * v) - 1)), (mod));
        if (u2k1 < 0) {
            u2k1 = (u2k1 + mod);
        }
        if ((n0 & mask) != 0) {
            int64_t u2k2 = FLOW_CHECKED_MOD((((P_LUCAS * u2k1) - u2k)), (mod));
            if (u2k2 < 0) {
                u2k2 = (u2k2 + mod);
            }
            u = u2k1;
            up1 = u2k2;
        } else {
            u = u2k;
            up1 = u2k1;
        }
        mask = FLOW_CHECKED_DIV((mask), (2));
    }
    up1_out[0] = up1;
    return u;
}

int64_t lucas_V_i64_i64(int64_t n, int64_t mod) {
    int64_t* up1_out = (int64_t*)(calloc(1, 8));
    int64_t u = lucas_U_pair_i64_i64_ptr_i64(n, mod, up1_out);
    int64_t up1 = up1_out[0];
    free(up1_out);
    int64_t r = FLOW_CHECKED_MOD((((2 * up1) - (P_LUCAS * u))), (mod));
    if (r < 0) {
        r = (r + mod);
    }
    return r;
}

bool residue13_i64(int64_t p) {
    int64_t r = FLOW_CHECKED_MOD((p), (13));
    if (r == 1) {
        return 1;
    }
    if (r == 3) {
        return 1;
    }
    if (r == 4) {
        return 1;
    }
    if (r == 9) {
        return 1;
    }
    if (r == 10) {
        return 1;
    }
    if (r == 12) {
        return 1;
    }
    return 0;
}

int64_t a_mod_prime_i64_i64(int64_t n, int64_t p) {
    if (p == 2) {
        return FLOW_CHECKED_MOD((1), (p));
    }
    if (p == 3) {
        int64_t a = FLOW_CHECKED_MOD((1), (p));
        int64_t t = 1;
        while (t < n) {
            a = FLOW_CHECKED_MOD((((((6 * a) * a) + (10 * a)) + 3)), (p));
            t = (t + 1);
        }
        return a;
    }
    int64_t leg = (0 - 1);
    if (residue13_i64(p)) {
        leg = 1;
    }
    int64_t mm = (p - leg);
    int64_t e = modpow_i64_i64_i64(2, (n - 1), mm);
    int64_t u_n = lucas_V_i64_i64(e, p);
    int64_t inv6 = modpow_i64_i64_i64(6, (p - 2), p);
    int64_t r = FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD(((u_n - 5)), (p)) * inv6)), (p));
    if (r < 0) {
        r = (r + p);
    }
    return r;
}

int32_t main(void) {
    int64_t X = 1000000000;
    int64_t Y = 10000000;
    int64_t N = 1000000000000000;
    int64_t high = (X + Y);
    int64_t base_limit = (isqrt_i64(high) + 1);
    int8_t* sieve = (int8_t*)(calloc((base_limit + 1), 1));
    if (sieve == NULL) {
        return 1;
    }
    int64_t i = 0;
    while (i <= base_limit) {
        sieve[i] = 1;
        i = (i + 1);
    }
    if (base_limit >= 0) {
        sieve[0] = 0;
    }
    if (base_limit >= 1) {
        sieve[1] = 0;
    }
    i = 2;
    while ((i * i) <= base_limit) {
        if (sieve[i] == 1) {
            int64_t j = (i * i);
            while (j <= base_limit) {
                sieve[j] = 0;
                j = (j + i);
            }
        }
        i = (i + 1);
    }
    int64_t nbase = 0;
    i = 2;
    while (i <= base_limit) {
        if (sieve[i] == 1) {
            nbase = (nbase + 1);
        }
        i = (i + 1);
    }
    int64_t* base_primes = (int64_t*)(calloc(nbase, 8));
    if (base_primes == NULL) {
        return 1;
    }
    int64_t bi = 0;
    i = 2;
    while (i <= base_limit) {
        if (sieve[i] == 1) {
            base_primes[bi] = i;
            bi = (bi + 1);
        }
        i = (i + 1);
    }
    int64_t start = X;
    if ((start & 1) == 0) {
        start = (start + 1);
    }
    int64_t seg_size = (FLOW_CHECKED_DIV(((high - start)), (2)) + 1);
    int8_t* seg = (int8_t*)(calloc(seg_size, 1));
    if (seg == NULL) {
        return 1;
    }
    i = 0;
    while (i < seg_size) {
        seg[i] = 1;
        i = (i + 1);
    }
    bi = 0;
    while (bi < nbase) {
        int64_t q = base_primes[bi];
        if (q == 2) {
            bi = (bi + 1);
            continue;
        }
        int64_t qq = (q * q);
        if (qq > high) {
            break;
        }
        int64_t first = 0;
        if (qq >= start) {
            first = qq;
        } else {
            first = (FLOW_CHECKED_DIV((((start + q) - 1)), (q)) * q);
        }
        if ((first & 1) == 0) {
            first = (first + q);
        }
        int64_t idx = FLOW_CHECKED_DIV(((first - start)), (2));
        while (idx < seg_size) {
            seg[idx] = 0;
            idx = (idx + q);
        }
        bi = (bi + 1);
    }
    int64_t total = 0;
    if (X <= 2) {
        if (2 <= high) {
            total = (total + a_mod_prime_i64_i64(N, 2));
        }
    }
    i = 0;
    while (i < seg_size) {
        if (seg[i] == 1) {
            int64_t p = (start + (2 * i));
            if (p >= X) {
                if (p <= high) {
                    total = (total + a_mod_prime_i64_i64(N, p));
                }
            }
        }
        i = (i + 1);
    }
    printf("%lld\n", total);
    free(sieve);
    free(base_primes);
    free(seg);
    return 0;
}

Generated MLIR

module {
  llvm.func @printf(!llvm.ptr, ...) -> i32
  llvm.mlir.global internal constant @str_0("%lld\n\00") {addr_space = 0 : i32} : !llvm.array<6 x i8>
  func.func @gcd(%arg0: i64, %arg1: i64) -> i64 {
    %0 = llvm.mlir.constant(1 : i64) : i64
    %1 = llvm.alloca %0 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %1 : i64, !llvm.ptr
    %2 = llvm.mlir.constant(1 : i64) : i64
    %3 = llvm.alloca %2 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %3 : i64, !llvm.ptr
    cf.br ^bb0
    ^bb0:
    %4 = llvm.load %3 : !llvm.ptr -> i64
    %5 = arith.constant 0 : i32
    %7 = arith.extsi %5 : i32 to i64
    %6 = arith.cmpi ne, %4, %7 : i64
    cf.cond_br %6, ^bb1, ^bb2
    ^bb1:
      %8 = llvm.load %1 : !llvm.ptr -> i64
      %9 = llvm.load %3 : !llvm.ptr -> i64
      %10 = arith.remsi %8, %9 : i64
      %11 = llvm.load %3 : !llvm.ptr -> i64
      llvm.store %11, %1 : i64, !llvm.ptr
      llvm.store %10, %3 : i64, !llvm.ptr
      cf.br ^bb0
    ^bb2:
    %12 = llvm.load %1 : !llvm.ptr -> i64
    func.return %12 : i64
  }
  func.func @lcm(%arg0: i64, %arg1: i64) -> i64 {
    %13 = arith.constant 0 : i32
    %15 = arith.extsi %13 : i32 to i64
    %14 = arith.cmpi eq, %arg0, %15 : i64
    %16 = scf.if %14 -> (i1) {
      %17 = arith.constant true
      scf.yield %17 : i1
    } else {
      %18 = arith.constant 0 : i32
      %20 = arith.extsi %18 : i32 to i64
      %19 = arith.cmpi eq, %arg1, %20 : i64
      scf.yield %19 : i1
    }
    cf.cond_br %16, ^bb3, ^bb4
    ^bb3:
      %21 = arith.constant 0 : i32
      %22 = arith.extsi %21 : i32 to i64
      func.return %22 : i64
    ^bb4:
      cf.br ^bb5
    ^bb5:
    %23 = func.call @gcd(%arg0, %arg1) : (i64, i64) -> i64
    %24 = arith.divsi %arg0, %23 : i64
    %25 = arith.muli %24, %arg1 : i64
    func.return %25 : i64
  }
  func.func @isqrt(%arg0: i64) -> i64 {
    %26 = arith.constant 2 : i32
    %28 = arith.extsi %26 : i32 to i64
    %27 = arith.cmpi slt, %arg0, %28 : i64
    cf.cond_br %27, ^bb6, ^bb7
    ^bb6:
      func.return %arg0 : i64
    ^bb7:
      cf.br ^bb8
    ^bb8:
    %29 = llvm.mlir.constant(1 : i64) : i64
    %30 = llvm.alloca %29 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %30 : i64, !llvm.ptr
    %31 = llvm.load %30 : !llvm.ptr -> i64
    %32 = arith.constant 1 : i32
    %34 = arith.extsi %32 : i32 to i64
    %33 = arith.addi %31, %34 : i64
    %35 = arith.constant 2 : i32
    %37 = arith.extsi %35 : i32 to i64
    %36 = arith.divsi %33, %37 : i64
    %38 = llvm.mlir.constant(1 : i64) : i64
    %39 = llvm.alloca %38 x i64 : (i64) -> !llvm.ptr
    llvm.store %36, %39 : i64, !llvm.ptr
    cf.br ^bb9
    ^bb9:
    %40 = llvm.load %39 : !llvm.ptr -> i64
    %41 = llvm.load %30 : !llvm.ptr -> i64
    %42 = arith.cmpi slt, %40, %41 : i64
    cf.cond_br %42, ^bb10, ^bb11
    ^bb10:
      %43 = llvm.load %39 : !llvm.ptr -> i64
      llvm.store %43, %30 : i64, !llvm.ptr
      %44 = llvm.load %30 : !llvm.ptr -> i64
      %45 = llvm.load %30 : !llvm.ptr -> i64
      %46 = arith.divsi %arg0, %45 : i64
      %47 = arith.addi %44, %46 : i64
      %48 = arith.constant 2 : i32
      %50 = arith.extsi %48 : i32 to i64
      %49 = arith.divsi %47, %50 : i64
      llvm.store %49, %39 : i64, !llvm.ptr
      cf.br ^bb9
    ^bb11:
    %51 = llvm.load %30 : !llvm.ptr -> i64
    func.return %51 : i64
  }
  func.func @mulmod(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %52 = arith.remsi %arg0, %arg2 : i64
    %53 = llvm.mlir.constant(1 : i64) : i64
    %54 = llvm.alloca %53 x i64 : (i64) -> !llvm.ptr
    llvm.store %52, %54 : i64, !llvm.ptr
    %55 = arith.remsi %arg1, %arg2 : i64
    %56 = llvm.mlir.constant(1 : i64) : i64
    %57 = llvm.alloca %56 x i64 : (i64) -> !llvm.ptr
    llvm.store %55, %57 : i64, !llvm.ptr
    %58 = arith.constant 0 : i32
    %59 = arith.extsi %58 : i32 to i64
    %60 = llvm.mlir.constant(1 : i64) : i64
    %61 = llvm.alloca %60 x i64 : (i64) -> !llvm.ptr
    llvm.store %59, %61 : i64, !llvm.ptr
    cf.br ^bb12
    ^bb12:
    %62 = llvm.load %57 : !llvm.ptr -> i64
    %63 = arith.constant 0 : i32
    %65 = arith.extsi %63 : i32 to i64
    %64 = arith.cmpi sgt, %62, %65 : i64
    cf.cond_br %64, ^bb13, ^bb14
    ^bb13:
      %66 = llvm.load %57 : !llvm.ptr -> i64
      %67 = arith.constant 2 : i32
      %69 = arith.extsi %67 : i32 to i64
      %68 = arith.remsi %66, %69 : i64
      %70 = arith.constant 1 : i32
      %72 = arith.extsi %70 : i32 to i64
      %71 = arith.cmpi eq, %68, %72 : i64
      cf.cond_br %71, ^bb15, ^bb16
      ^bb15:
        %73 = llvm.load %61 : !llvm.ptr -> i64
        %74 = llvm.load %54 : !llvm.ptr -> i64
        %75 = arith.addi %73, %74 : i64
        %76 = arith.remsi %75, %arg2 : i64
        llvm.store %76, %61 : i64, !llvm.ptr
        cf.br ^bb17
      ^bb16:
        cf.br ^bb17
      ^bb17:
      %77 = llvm.load %54 : !llvm.ptr -> i64
      %78 = arith.constant 2 : i32
      %80 = arith.extsi %78 : i32 to i64
      %79 = arith.muli %77, %80 : i64
      %81 = arith.remsi %79, %arg2 : i64
      llvm.store %81, %54 : i64, !llvm.ptr
      %82 = llvm.load %57 : !llvm.ptr -> i64
      %83 = arith.constant 2 : i32
      %85 = arith.extsi %83 : i32 to i64
      %84 = arith.divsi %82, %85 : i64
      llvm.store %84, %57 : i64, !llvm.ptr
      cf.br ^bb12
    ^bb14:
    %86 = llvm.load %61 : !llvm.ptr -> i64
    func.return %86 : i64
  }
  func.func @mod_pow(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %87 = arith.constant 1 : i32
    %89 = arith.extsi %87 : i32 to i64
    %88 = arith.cmpi eq, %arg2, %89 : i64
    cf.cond_br %88, ^bb18, ^bb19
    ^bb18:
      %90 = arith.constant 0 : i32
      %91 = arith.extsi %90 : i32 to i64
      func.return %91 : i64
    ^bb19:
      cf.br ^bb20
    ^bb20:
    %92 = arith.constant 1 : i32
    %93 = arith.extsi %92 : i32 to i64
    %94 = llvm.mlir.constant(1 : i64) : i64
    %95 = llvm.alloca %94 x i64 : (i64) -> !llvm.ptr
    llvm.store %93, %95 : i64, !llvm.ptr
    %96 = arith.remsi %arg0, %arg2 : i64
    %97 = llvm.mlir.constant(1 : i64) : i64
    %98 = llvm.alloca %97 x i64 : (i64) -> !llvm.ptr
    llvm.store %96, %98 : i64, !llvm.ptr
    %99 = llvm.mlir.constant(1 : i64) : i64
    %100 = llvm.alloca %99 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %100 : i64, !llvm.ptr
    cf.br ^bb21
    ^bb21:
    %101 = llvm.load %100 : !llvm.ptr -> i64
    %102 = arith.constant 0 : i32
    %104 = arith.extsi %102 : i32 to i64
    %103 = arith.cmpi sgt, %101, %104 : i64
    cf.cond_br %103, ^bb22, ^bb23
    ^bb22:
      %105 = llvm.load %100 : !llvm.ptr -> i64
      %106 = arith.constant 2 : i32
      %108 = arith.extsi %106 : i32 to i64
      %107 = arith.remsi %105, %108 : i64
      %109 = arith.constant 1 : i32
      %111 = arith.extsi %109 : i32 to i64
      %110 = arith.cmpi eq, %107, %111 : i64
      cf.cond_br %110, ^bb24, ^bb25
      ^bb24:
        %113 = llvm.load %95 : !llvm.ptr -> i64
        %114 = llvm.load %98 : !llvm.ptr -> i64
        %112 = func.call @mulmod(%113, %114, %arg2) : (i64, i64, i64) -> i64
        llvm.store %112, %95 : i64, !llvm.ptr
        cf.br ^bb26
      ^bb25:
        cf.br ^bb26
      ^bb26:
      %116 = llvm.load %98 : !llvm.ptr -> i64
      %117 = llvm.load %98 : !llvm.ptr -> i64
      %115 = func.call @mulmod(%116, %117, %arg2) : (i64, i64, i64) -> i64
      llvm.store %115, %98 : i64, !llvm.ptr
      %118 = llvm.load %100 : !llvm.ptr -> i64
      %119 = arith.constant 2 : i32
      %121 = arith.extsi %119 : i32 to i64
      %120 = arith.divsi %118, %121 : i64
      llvm.store %120, %100 : i64, !llvm.ptr
      cf.br ^bb21
    ^bb23:
    %122 = llvm.load %95 : !llvm.ptr -> i64
    func.return %122 : i64
  }
  func.func @is_prime(%arg0: i64) -> i1 {
    %123 = arith.constant 2 : i32
    %125 = arith.extsi %123 : i32 to i64
    %124 = arith.cmpi slt, %arg0, %125 : i64
    cf.cond_br %124, ^bb27, ^bb28
    ^bb27:
      %126 = arith.constant 0 : i1
      func.return %126 : i1
    ^bb28:
      cf.br ^bb29
    ^bb29:
    %127 = arith.constant 4 : i32
    %129 = arith.extsi %127 : i32 to i64
    %128 = arith.cmpi slt, %arg0, %129 : i64
    cf.cond_br %128, ^bb30, ^bb31
    ^bb30:
      %130 = arith.constant 1 : i1
      func.return %130 : i1
    ^bb31:
      cf.br ^bb32
    ^bb32:
    %131 = arith.constant 2 : i32
    %133 = arith.extsi %131 : i32 to i64
    %132 = arith.remsi %arg0, %133 : i64
    %134 = arith.constant 0 : i32
    %136 = arith.extsi %134 : i32 to i64
    %135 = arith.cmpi eq, %132, %136 : i64
    %137 = scf.if %135 -> (i1) {
      %138 = arith.constant true
      scf.yield %138 : i1
    } else {
      %139 = arith.constant 3 : i32
      %141 = arith.extsi %139 : i32 to i64
      %140 = arith.remsi %arg0, %141 : i64
      %142 = arith.constant 0 : i32
      %144 = arith.extsi %142 : i32 to i64
      %143 = arith.cmpi eq, %140, %144 : i64
      scf.yield %143 : i1
    }
    cf.cond_br %137, ^bb33, ^bb34
    ^bb33:
      %145 = arith.constant 0 : i1
      func.return %145 : i1
    ^bb34:
      cf.br ^bb35
    ^bb35:
    %146 = arith.constant 5 : i32
    %147 = arith.extsi %146 : i32 to i64
    %148 = llvm.mlir.constant(1 : i64) : i64
    %149 = llvm.alloca %148 x i64 : (i64) -> !llvm.ptr
    llvm.store %147, %149 : i64, !llvm.ptr
    cf.br ^bb36
    ^bb36:
    %150 = llvm.load %149 : !llvm.ptr -> i64
    %151 = llvm.load %149 : !llvm.ptr -> i64
    %152 = arith.muli %150, %151 : i64
    %153 = arith.cmpi sle, %152, %arg0 : i64
    cf.cond_br %153, ^bb37, ^bb38
    ^bb37:
      %154 = llvm.load %149 : !llvm.ptr -> i64
      %155 = arith.remsi %arg0, %154 : i64
      %156 = arith.constant 0 : i32
      %158 = arith.extsi %156 : i32 to i64
      %157 = arith.cmpi eq, %155, %158 : i64
      %159 = scf.if %157 -> (i1) {
        %160 = arith.constant true
        scf.yield %160 : i1
      } else {
        %161 = llvm.load %149 : !llvm.ptr -> i64
        %162 = arith.constant 2 : i32
        %164 = arith.extsi %162 : i32 to i64
        %163 = arith.addi %161, %164 : i64
        %165 = arith.remsi %arg0, %163 : i64
        %166 = arith.constant 0 : i32
        %168 = arith.extsi %166 : i32 to i64
        %167 = arith.cmpi eq, %165, %168 : i64
        scf.yield %167 : i1
      }
      cf.cond_br %159, ^bb39, ^bb40
      ^bb39:
        %169 = arith.constant 0 : i1
        func.return %169 : i1
      ^bb40:
        cf.br ^bb41
      ^bb41:
      %170 = llvm.load %149 : !llvm.ptr -> i64
      %171 = arith.constant 6 : i32
      %173 = arith.extsi %171 : i32 to i64
      %172 = arith.addi %170, %173 : i64
      llvm.store %172, %149 : i64, !llvm.ptr
      cf.br ^bb36
    ^bb38:
    %174 = arith.constant 1 : i1
    func.return %174 : i1
  }
  func.func private @calloc(i64, i64) -> !llvm.ptr
  func.func private @free(!llvm.ptr) -> ()
  // Module static: P_LUCAS
  llvm.mlir.global internal @P_LUCAS(11 : i64) : i64
  func.func @modpow(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %175 = arith.constant 1 : i32
    %176 = arith.extsi %175 : i32 to i64
    %177 = llvm.mlir.constant(1 : i64) : i64
    %178 = llvm.alloca %177 x i64 : (i64) -> !llvm.ptr
    llvm.store %176, %178 : i64, !llvm.ptr
    %179 = arith.remsi %arg0, %arg2 : i64
    %180 = llvm.mlir.constant(1 : i64) : i64
    %181 = llvm.alloca %180 x i64 : (i64) -> !llvm.ptr
    llvm.store %179, %181 : i64, !llvm.ptr
    %182 = llvm.mlir.constant(1 : i64) : i64
    %183 = llvm.alloca %182 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %183 : i64, !llvm.ptr
    %184 = llvm.load %181 : !llvm.ptr -> i64
    %185 = arith.constant 0 : i32
    %187 = arith.extsi %185 : i32 to i64
    %186 = arith.cmpi slt, %184, %187 : i64
    cf.cond_br %186, ^bb42, ^bb43
    ^bb42:
      %188 = llvm.load %181 : !llvm.ptr -> i64
      %189 = arith.addi %188, %arg2 : i64
      llvm.store %189, %181 : i64, !llvm.ptr
      cf.br ^bb44
    ^bb43:
      cf.br ^bb44
    ^bb44:
    cf.br ^bb45
    ^bb45:
    %190 = llvm.load %183 : !llvm.ptr -> i64
    %191 = arith.constant 0 : i32
    %193 = arith.extsi %191 : i32 to i64
    %192 = arith.cmpi sgt, %190, %193 : i64
    cf.cond_br %192, ^bb46, ^bb47
    ^bb46:
      %194 = llvm.load %183 : !llvm.ptr -> i64
      %195 = arith.constant 2 : i32
      %197 = arith.extsi %195 : i32 to i64
      %196 = arith.remsi %194, %197 : i64
      %198 = arith.constant 1 : i32
      %200 = arith.extsi %198 : i32 to i64
      %199 = arith.cmpi eq, %196, %200 : i64
      cf.cond_br %199, ^bb48, ^bb49
      ^bb48:
        %201 = llvm.load %178 : !llvm.ptr -> i64
        %202 = llvm.load %181 : !llvm.ptr -> i64
        %203 = arith.muli %201, %202 : i64
        %204 = arith.remsi %203, %arg2 : i64
        llvm.store %204, %178 : i64, !llvm.ptr
        cf.br ^bb50
      ^bb49:
        cf.br ^bb50
      ^bb50:
      %205 = llvm.load %181 : !llvm.ptr -> i64
      %206 = llvm.load %181 : !llvm.ptr -> i64
      %207 = arith.muli %205, %206 : i64
      %208 = arith.remsi %207, %arg2 : i64
      llvm.store %208, %181 : i64, !llvm.ptr
      %209 = llvm.load %183 : !llvm.ptr -> i64
      %210 = arith.constant 2 : i32
      %212 = arith.extsi %210 : i32 to i64
      %211 = arith.divsi %209, %212 : i64
      llvm.store %211, %183 : i64, !llvm.ptr
      cf.br ^bb45
    ^bb47:
    %213 = llvm.load %178 : !llvm.ptr -> i64
    func.return %213 : i64
  }
  func.func @bit_length(%arg0: i64) -> i64 {
    %214 = llvm.mlir.constant(1 : i64) : i64
    %215 = llvm.alloca %214 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %215 : i64, !llvm.ptr
    %216 = arith.constant 0 : i32
    %217 = arith.extsi %216 : i32 to i64
    %218 = llvm.mlir.constant(1 : i64) : i64
    %219 = llvm.alloca %218 x i64 : (i64) -> !llvm.ptr
    llvm.store %217, %219 : i64, !llvm.ptr
    cf.br ^bb51
    ^bb51:
    %220 = llvm.load %215 : !llvm.ptr -> i64
    %221 = arith.constant 0 : i32
    %223 = arith.extsi %221 : i32 to i64
    %222 = arith.cmpi sgt, %220, %223 : i64
    cf.cond_br %222, ^bb52, ^bb53
    ^bb52:
      %224 = llvm.load %215 : !llvm.ptr -> i64
      %225 = arith.constant 2 : i32
      %227 = arith.extsi %225 : i32 to i64
      %226 = arith.divsi %224, %227 : i64
      llvm.store %226, %215 : i64, !llvm.ptr
      %228 = llvm.load %219 : !llvm.ptr -> i64
      %229 = arith.constant 1 : i32
      %231 = arith.extsi %229 : i32 to i64
      %230 = arith.addi %228, %231 : i64
      llvm.store %230, %219 : i64, !llvm.ptr
      cf.br ^bb51
    ^bb53:
    %232 = llvm.load %219 : !llvm.ptr -> i64
    func.return %232 : i64
  }
  func.func @lucas_U_pair(%arg0: i64, %arg1: i64, %arg2: !llvm.ptr) -> i64 {
    %233 = arith.constant 0 : i32
    %235 = arith.extsi %233 : i32 to i64
    %234 = arith.cmpi eq, %arg0, %235 : i64
    cf.cond_br %234, ^bb54, ^bb55
    ^bb54:
      %236 = arith.constant 1 : i32
      %237 = arith.constant 0 : i32
      %238 = arith.extsi %236 : i32 to i64
      %239 = arith.extsi %237 : i32 to i64
      %240 = llvm.getelementptr %arg2[%239] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %238, %240 : i64, !llvm.ptr
      %241 = arith.constant 0 : i32
      %242 = arith.extsi %241 : i32 to i64
      func.return %242 : i64
    ^bb55:
      cf.br ^bb56
    ^bb56:
    %243 = arith.constant 0 : i32
    %244 = arith.extsi %243 : i32 to i64
    %245 = llvm.mlir.constant(1 : i64) : i64
    %246 = llvm.alloca %245 x i64 : (i64) -> !llvm.ptr
    llvm.store %244, %246 : i64, !llvm.ptr
    %247 = arith.constant 1 : i32
    %248 = arith.extsi %247 : i32 to i64
    %249 = llvm.mlir.constant(1 : i64) : i64
    %250 = llvm.alloca %249 x i64 : (i64) -> !llvm.ptr
    llvm.store %248, %250 : i64, !llvm.ptr
    %251 = arith.constant 1 : i32
    %252 = arith.extsi %251 : i32 to i64
    %253 = llvm.mlir.constant(1 : i64) : i64
    %254 = llvm.alloca %253 x i64 : (i64) -> !llvm.ptr
    llvm.store %252, %254 : i64, !llvm.ptr
    %255 = func.call @bit_length(%arg0) : (i64) -> i64
    %256 = arith.constant 1 : i32
    %257 = arith.extsi %256 : i32 to i64
    %258 = llvm.mlir.constant(1 : i64) : i64
    %259 = llvm.alloca %258 x i64 : (i64) -> !llvm.ptr
    llvm.store %257, %259 : i64, !llvm.ptr
    cf.br ^bb57
    ^bb57:
    %260 = llvm.load %259 : !llvm.ptr -> i64
    %261 = arith.cmpi slt, %260, %255 : i64
    cf.cond_br %261, ^bb58, ^bb59
    ^bb58:
      %262 = llvm.load %254 : !llvm.ptr -> i64
      %263 = arith.constant 2 : i32
      %265 = arith.extsi %263 : i32 to i64
      %264 = arith.muli %262, %265 : i64
      llvm.store %264, %254 : i64, !llvm.ptr
      %266 = llvm.load %259 : !llvm.ptr -> i64
      %267 = arith.constant 1 : i32
      %269 = arith.extsi %267 : i32 to i64
      %268 = arith.addi %266, %269 : i64
      llvm.store %268, %259 : i64, !llvm.ptr
      cf.br ^bb57
    ^bb59:
    cf.br ^bb60
    ^bb60:
    %270 = llvm.load %254 : !llvm.ptr -> i64
    %271 = arith.constant 0 : i32
    %273 = arith.extsi %271 : i32 to i64
    %272 = arith.cmpi sgt, %270, %273 : i64
    cf.cond_br %272, ^bb61, ^bb62
    ^bb61:
      %274 = arith.constant 2 : i32
      %275 = llvm.load %250 : !llvm.ptr -> i64
      %277 = arith.extsi %274 : i32 to i64
      %276 = arith.muli %277, %275 : i64
      %278 = llvm.mlir.addressof @P_LUCAS : !llvm.ptr
      %279 = llvm.load %278 : !llvm.ptr -> i64
      %280 = llvm.load %246 : !llvm.ptr -> i64
      %281 = arith.muli %279, %280 : i64
      %282 = arith.subi %276, %281 : i64
      %283 = arith.remsi %282, %arg1 : 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 = llvm.load %285 : !llvm.ptr -> i64
      %287 = arith.constant 0 : i32
      %289 = arith.extsi %287 : i32 to i64
      %288 = arith.cmpi slt, %286, %289 : i64
      cf.cond_br %288, ^bb63, ^bb64
      ^bb63:
        %290 = llvm.load %285 : !llvm.ptr -> i64
        %291 = arith.addi %290, %arg1 : i64
        llvm.store %291, %285 : i64, !llvm.ptr
        cf.br ^bb65
      ^bb64:
        cf.br ^bb65
      ^bb65:
      %292 = llvm.load %246 : !llvm.ptr -> i64
      %293 = llvm.load %285 : !llvm.ptr -> i64
      %294 = arith.muli %292, %293 : i64
      %295 = arith.remsi %294, %arg1 : i64
      %296 = llvm.load %250 : !llvm.ptr -> i64
      %297 = llvm.load %285 : !llvm.ptr -> i64
      %298 = arith.muli %296, %297 : i64
      %299 = arith.constant 1 : i32
      %301 = arith.extsi %299 : i32 to i64
      %300 = arith.subi %298, %301 : i64
      %302 = arith.remsi %300, %arg1 : i64
      %303 = llvm.mlir.constant(1 : i64) : i64
      %304 = llvm.alloca %303 x i64 : (i64) -> !llvm.ptr
      llvm.store %302, %304 : i64, !llvm.ptr
      %305 = llvm.load %304 : !llvm.ptr -> i64
      %306 = arith.constant 0 : i32
      %308 = arith.extsi %306 : i32 to i64
      %307 = arith.cmpi slt, %305, %308 : i64
      cf.cond_br %307, ^bb66, ^bb67
      ^bb66:
        %309 = llvm.load %304 : !llvm.ptr -> i64
        %310 = arith.addi %309, %arg1 : i64
        llvm.store %310, %304 : i64, !llvm.ptr
        cf.br ^bb68
      ^bb67:
        cf.br ^bb68
      ^bb68:
      %311 = llvm.load %254 : !llvm.ptr -> i64
      %312 = arith.andi %arg0, %311 : i64
      %313 = arith.constant 0 : i32
      %315 = arith.extsi %313 : i32 to i64
      %314 = arith.cmpi ne, %312, %315 : i64
      cf.cond_br %314, ^bb69, ^bb70
      ^bb69:
        %316 = llvm.mlir.addressof @P_LUCAS : !llvm.ptr
        %317 = llvm.load %316 : !llvm.ptr -> i64
        %318 = llvm.load %304 : !llvm.ptr -> i64
        %319 = arith.muli %317, %318 : i64
        %320 = arith.subi %319, %295 : i64
        %321 = arith.remsi %320, %arg1 : i64
        %322 = llvm.mlir.constant(1 : i64) : i64
        %323 = llvm.alloca %322 x i64 : (i64) -> !llvm.ptr
        llvm.store %321, %323 : i64, !llvm.ptr
        %324 = llvm.load %323 : !llvm.ptr -> i64
        %325 = arith.constant 0 : i32
        %327 = arith.extsi %325 : i32 to i64
        %326 = arith.cmpi slt, %324, %327 : i64
        cf.cond_br %326, ^bb72, ^bb73
        ^bb72:
          %328 = llvm.load %323 : !llvm.ptr -> i64
          %329 = arith.addi %328, %arg1 : i64
          llvm.store %329, %323 : i64, !llvm.ptr
          cf.br ^bb74
        ^bb73:
          cf.br ^bb74
        ^bb74:
        %330 = llvm.load %304 : !llvm.ptr -> i64
        llvm.store %330, %246 : i64, !llvm.ptr
        %331 = llvm.load %323 : !llvm.ptr -> i64
        llvm.store %331, %250 : i64, !llvm.ptr
        cf.br ^bb71
      ^bb70:
        llvm.store %295, %246 : i64, !llvm.ptr
        %332 = llvm.load %304 : !llvm.ptr -> i64
        llvm.store %332, %250 : i64, !llvm.ptr
        cf.br ^bb71
      ^bb71:
      %333 = llvm.load %254 : !llvm.ptr -> i64
      %334 = arith.constant 2 : i32
      %336 = arith.extsi %334 : i32 to i64
      %335 = arith.divsi %333, %336 : i64
      llvm.store %335, %254 : i64, !llvm.ptr
      cf.br ^bb60
    ^bb62:
    %337 = llvm.load %250 : !llvm.ptr -> i64
    %338 = arith.constant 0 : i32
    %339 = arith.extsi %338 : i32 to i64
    %340 = llvm.getelementptr %arg2[%339] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %337, %340 : i64, !llvm.ptr
    %341 = llvm.load %246 : !llvm.ptr -> i64
    func.return %341 : i64
  }
  func.func @lucas_V(%arg0: i64, %arg1: i64) -> i64 {
    %343 = arith.constant 1 : i32
    %344 = arith.constant 8 : i32
    %345 = arith.extsi %343 : i32 to i64
    %346 = arith.extsi %344 : i32 to i64
    %342 = func.call @calloc(%345, %346) : (i64, i64) -> !llvm.ptr
    %347 = func.call @lucas_U_pair(%arg0, %arg1, %342) : (i64, i64, !llvm.ptr) -> i64
    %349 = arith.constant 0 : i32
    %350 = arith.extsi %349 : i32 to i64
    %351 = llvm.getelementptr %342[%350] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %348 = llvm.load %351 : !llvm.ptr -> i64
    func.call @free(%342) : (!llvm.ptr) -> ()
    %353 = arith.constant 2 : i32
    %355 = arith.extsi %353 : i32 to i64
    %354 = arith.muli %355, %348 : i64
    %356 = llvm.mlir.addressof @P_LUCAS : !llvm.ptr
    %357 = llvm.load %356 : !llvm.ptr -> i64
    %358 = arith.muli %357, %347 : i64
    %359 = arith.subi %354, %358 : i64
    %360 = arith.remsi %359, %arg1 : i64
    %361 = llvm.mlir.constant(1 : i64) : i64
    %362 = llvm.alloca %361 x i64 : (i64) -> !llvm.ptr
    llvm.store %360, %362 : i64, !llvm.ptr
    %363 = llvm.load %362 : !llvm.ptr -> i64
    %364 = arith.constant 0 : i32
    %366 = arith.extsi %364 : i32 to i64
    %365 = arith.cmpi slt, %363, %366 : i64
    cf.cond_br %365, ^bb75, ^bb76
    ^bb75:
      %367 = llvm.load %362 : !llvm.ptr -> i64
      %368 = arith.addi %367, %arg1 : i64
      llvm.store %368, %362 : i64, !llvm.ptr
      cf.br ^bb77
    ^bb76:
      cf.br ^bb77
    ^bb77:
    %369 = llvm.load %362 : !llvm.ptr -> i64
    func.return %369 : i64
  }
  func.func @residue13(%arg0: i64) -> i1 {
    %370 = arith.constant 13 : i32
    %372 = arith.extsi %370 : i32 to i64
    %371 = arith.remsi %arg0, %372 : i64
    %373 = arith.constant 1 : i32
    %375 = arith.extsi %373 : i32 to i64
    %374 = arith.cmpi eq, %371, %375 : i64
    cf.cond_br %374, ^bb78, ^bb79
    ^bb78:
      %376 = arith.constant 1 : i1
      func.return %376 : i1
    ^bb79:
      cf.br ^bb80
    ^bb80:
    %377 = arith.constant 3 : i32
    %379 = arith.extsi %377 : i32 to i64
    %378 = arith.cmpi eq, %371, %379 : i64
    cf.cond_br %378, ^bb81, ^bb82
    ^bb81:
      %380 = arith.constant 1 : i1
      func.return %380 : i1
    ^bb82:
      cf.br ^bb83
    ^bb83:
    %381 = arith.constant 4 : i32
    %383 = arith.extsi %381 : i32 to i64
    %382 = arith.cmpi eq, %371, %383 : i64
    cf.cond_br %382, ^bb84, ^bb85
    ^bb84:
      %384 = arith.constant 1 : i1
      func.return %384 : i1
    ^bb85:
      cf.br ^bb86
    ^bb86:
    %385 = arith.constant 9 : i32
    %387 = arith.extsi %385 : i32 to i64
    %386 = arith.cmpi eq, %371, %387 : i64
    cf.cond_br %386, ^bb87, ^bb88
    ^bb87:
      %388 = arith.constant 1 : i1
      func.return %388 : i1
    ^bb88:
      cf.br ^bb89
    ^bb89:
    %389 = arith.constant 10 : i32
    %391 = arith.extsi %389 : i32 to i64
    %390 = arith.cmpi eq, %371, %391 : i64
    cf.cond_br %390, ^bb90, ^bb91
    ^bb90:
      %392 = arith.constant 1 : i1
      func.return %392 : i1
    ^bb91:
      cf.br ^bb92
    ^bb92:
    %393 = arith.constant 12 : i32
    %395 = arith.extsi %393 : i32 to i64
    %394 = arith.cmpi eq, %371, %395 : i64
    cf.cond_br %394, ^bb93, ^bb94
    ^bb93:
      %396 = arith.constant 1 : i1
      func.return %396 : i1
    ^bb94:
      cf.br ^bb95
    ^bb95:
    %397 = arith.constant 0 : i1
    func.return %397 : i1
  }
  func.func @a_mod_prime(%arg0: i64, %arg1: i64) -> i64 {
    %398 = arith.constant 2 : i32
    %400 = arith.extsi %398 : i32 to i64
    %399 = arith.cmpi eq, %arg1, %400 : i64
    cf.cond_br %399, ^bb96, ^bb97
    ^bb96:
      %401 = arith.constant 1 : i32
      %403 = arith.extsi %401 : i32 to i64
      %402 = arith.remsi %403, %arg1 : i64
      func.return %402 : i64
    ^bb97:
      cf.br ^bb98
    ^bb98:
    %404 = arith.constant 3 : i32
    %406 = arith.extsi %404 : i32 to i64
    %405 = arith.cmpi eq, %arg1, %406 : i64
    cf.cond_br %405, ^bb99, ^bb100
    ^bb99:
      %407 = arith.constant 1 : i32
      %409 = arith.extsi %407 : i32 to i64
      %408 = arith.remsi %409, %arg1 : i64
      %410 = llvm.mlir.constant(1 : i64) : i64
      %411 = llvm.alloca %410 x i64 : (i64) -> !llvm.ptr
      llvm.store %408, %411 : i64, !llvm.ptr
      %412 = arith.constant 1 : i32
      %413 = arith.extsi %412 : i32 to i64
      %414 = llvm.mlir.constant(1 : i64) : i64
      %415 = llvm.alloca %414 x i64 : (i64) -> !llvm.ptr
      llvm.store %413, %415 : i64, !llvm.ptr
      cf.br ^bb102
      ^bb102:
      %416 = llvm.load %415 : !llvm.ptr -> i64
      %417 = arith.cmpi slt, %416, %arg0 : i64
      cf.cond_br %417, ^bb103, ^bb104
      ^bb103:
        %418 = arith.constant 6 : i32
        %419 = llvm.load %411 : !llvm.ptr -> i64
        %421 = arith.extsi %418 : i32 to i64
        %420 = arith.muli %421, %419 : i64
        %422 = llvm.load %411 : !llvm.ptr -> i64
        %423 = arith.muli %420, %422 : i64
        %424 = arith.constant 10 : i32
        %425 = llvm.load %411 : !llvm.ptr -> i64
        %427 = arith.extsi %424 : i32 to i64
        %426 = arith.muli %427, %425 : i64
        %428 = arith.addi %423, %426 : i64
        %429 = arith.constant 3 : i32
        %431 = arith.extsi %429 : i32 to i64
        %430 = arith.addi %428, %431 : i64
        %432 = arith.remsi %430, %arg1 : i64
        llvm.store %432, %411 : i64, !llvm.ptr
        %433 = llvm.load %415 : !llvm.ptr -> i64
        %434 = arith.constant 1 : i32
        %436 = arith.extsi %434 : i32 to i64
        %435 = arith.addi %433, %436 : i64
        llvm.store %435, %415 : i64, !llvm.ptr
        cf.br ^bb102
      ^bb104:
      %437 = llvm.load %411 : !llvm.ptr -> i64
      func.return %437 : i64
    ^bb100:
      cf.br ^bb101
    ^bb101:
    %438 = arith.constant 0 : i32
    %439 = arith.constant 1 : i32
    %440 = arith.subi %438, %439 : i32
    %441 = arith.extsi %440 : i32 to i64
    %442 = llvm.mlir.constant(1 : i64) : i64
    %443 = llvm.alloca %442 x i64 : (i64) -> !llvm.ptr
    llvm.store %441, %443 : i64, !llvm.ptr
    %444 = func.call @residue13(%arg1) : (i64) -> i1
    cf.cond_br %444, ^bb105, ^bb106
    ^bb105:
      %445 = arith.constant 1 : i32
      %446 = arith.extsi %445 : i32 to i64
      llvm.store %446, %443 : i64, !llvm.ptr
      cf.br ^bb107
    ^bb106:
      cf.br ^bb107
    ^bb107:
    %447 = llvm.load %443 : !llvm.ptr -> i64
    %448 = arith.subi %arg1, %447 : i64
    %450 = arith.constant 2 : i32
    %451 = arith.constant 1 : i32
    %453 = arith.extsi %451 : i32 to i64
    %452 = arith.subi %arg0, %453 : i64
    %454 = arith.extsi %450 : i32 to i64
    %449 = func.call @modpow(%454, %452, %448) : (i64, i64, i64) -> i64
    %455 = func.call @lucas_V(%449, %arg1) : (i64, i64) -> i64
    %457 = arith.constant 6 : i32
    %458 = arith.constant 2 : i32
    %460 = arith.extsi %458 : i32 to i64
    %459 = arith.subi %arg1, %460 : i64
    %461 = arith.extsi %457 : i32 to i64
    %456 = func.call @modpow(%461, %459, %arg1) : (i64, i64, i64) -> i64
    %462 = arith.constant 5 : i32
    %464 = arith.extsi %462 : i32 to i64
    %463 = arith.subi %455, %464 : i64
    %465 = arith.remsi %463, %arg1 : i64
    %466 = arith.muli %465, %456 : i64
    %467 = arith.remsi %466, %arg1 : i64
    %468 = llvm.mlir.constant(1 : i64) : i64
    %469 = llvm.alloca %468 x i64 : (i64) -> !llvm.ptr
    llvm.store %467, %469 : i64, !llvm.ptr
    %470 = llvm.load %469 : !llvm.ptr -> i64
    %471 = arith.constant 0 : i32
    %473 = arith.extsi %471 : i32 to i64
    %472 = arith.cmpi slt, %470, %473 : i64
    cf.cond_br %472, ^bb108, ^bb109
    ^bb108:
      %474 = llvm.load %469 : !llvm.ptr -> i64
      %475 = arith.addi %474, %arg1 : i64
      llvm.store %475, %469 : i64, !llvm.ptr
      cf.br ^bb110
    ^bb109:
      cf.br ^bb110
    ^bb110:
    %476 = llvm.load %469 : !llvm.ptr -> i64
    func.return %476 : i64
  }
  func.func @main() -> i32 {
    %477 = arith.constant 1000000000 : i32
    %478 = arith.extsi %477 : i32 to i64
    %479 = arith.constant 10000000 : i32
    %480 = arith.extsi %479 : i32 to i64
    %481 = arith.constant 999995705032704 : i32
    %482 = arith.extsi %481 : i32 to i64
    %483 = arith.addi %478, %480 : i64
    %484 = func.call @isqrt(%483) : (i64) -> i64
    %485 = arith.constant 1 : i32
    %487 = arith.extsi %485 : i32 to i64
    %486 = arith.addi %484, %487 : i64
    %489 = arith.constant 1 : i32
    %491 = arith.extsi %489 : i32 to i64
    %490 = arith.addi %486, %491 : i64
    %492 = arith.constant 1 : i32
    %493 = arith.extsi %492 : i32 to i64
    %488 = func.call @calloc(%490, %493) : (i64, i64) -> !llvm.ptr
    %494 = llvm.mlir.zero : !llvm.ptr
    %495 = llvm.icmp "eq" %488, %494 : !llvm.ptr
    cf.cond_br %495, ^bb111, ^bb112
    ^bb111:
      %496 = arith.constant 1 : i32
      func.return %496 : i32
    ^bb112:
      cf.br ^bb113
    ^bb113:
    %497 = arith.constant 0 : i32
    %498 = arith.extsi %497 : i32 to i64
    %499 = llvm.mlir.constant(1 : i64) : i64
    %500 = llvm.alloca %499 x i64 : (i64) -> !llvm.ptr
    llvm.store %498, %500 : i64, !llvm.ptr
    cf.br ^bb114
    ^bb114:
    %501 = llvm.load %500 : !llvm.ptr -> i64
    %502 = arith.cmpi sle, %501, %486 : i64
    cf.cond_br %502, ^bb115, ^bb116
    ^bb115:
      %503 = arith.constant 1 : i32
      %504 = llvm.load %500 : !llvm.ptr -> i64
      %505 = arith.trunci %503 : i32 to i8
      %506 = llvm.getelementptr %488[%504] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      llvm.store %505, %506 : i8, !llvm.ptr
      %507 = llvm.load %500 : !llvm.ptr -> i64
      %508 = arith.constant 1 : i32
      %510 = arith.extsi %508 : i32 to i64
      %509 = arith.addi %507, %510 : i64
      llvm.store %509, %500 : i64, !llvm.ptr
      cf.br ^bb114
    ^bb116:
    %511 = arith.constant 0 : i32
    %513 = arith.extsi %511 : i32 to i64
    %512 = arith.cmpi sge, %486, %513 : i64
    cf.cond_br %512, ^bb117, ^bb118
    ^bb117:
      %514 = arith.constant 0 : i32
      %515 = arith.constant 0 : i32
      %516 = arith.trunci %514 : i32 to i8
      %517 = arith.extsi %515 : i32 to i64
      %518 = llvm.getelementptr %488[%517] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      llvm.store %516, %518 : i8, !llvm.ptr
      cf.br ^bb119
    ^bb118:
      cf.br ^bb119
    ^bb119:
    %519 = arith.constant 1 : i32
    %521 = arith.extsi %519 : i32 to i64
    %520 = arith.cmpi sge, %486, %521 : i64
    cf.cond_br %520, ^bb120, ^bb121
    ^bb120:
      %522 = arith.constant 0 : i32
      %523 = arith.constant 1 : i32
      %524 = arith.trunci %522 : i32 to i8
      %525 = arith.extsi %523 : i32 to i64
      %526 = llvm.getelementptr %488[%525] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      llvm.store %524, %526 : i8, !llvm.ptr
      cf.br ^bb122
    ^bb121:
      cf.br ^bb122
    ^bb122:
    %527 = arith.constant 2 : i32
    %528 = arith.extsi %527 : i32 to i64
    llvm.store %528, %500 : i64, !llvm.ptr
    cf.br ^bb123
    ^bb123:
    %529 = llvm.load %500 : !llvm.ptr -> i64
    %530 = llvm.load %500 : !llvm.ptr -> i64
    %531 = arith.muli %529, %530 : i64
    %532 = arith.cmpi sle, %531, %486 : i64
    cf.cond_br %532, ^bb124, ^bb125
    ^bb124:
      %534 = llvm.load %500 : !llvm.ptr -> i64
      %535 = llvm.getelementptr %488[%534] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %533 = llvm.load %535 : !llvm.ptr -> i8
      %536 = arith.constant 1 : i32
      %538 = arith.extsi %533 : i8 to i32
      %537 = arith.cmpi eq, %538, %536 : i32
      cf.cond_br %537, ^bb126, ^bb127
      ^bb126:
        %539 = llvm.load %500 : !llvm.ptr -> i64
        %540 = llvm.load %500 : !llvm.ptr -> i64
        %541 = arith.muli %539, %540 : i64
        %542 = llvm.mlir.constant(1 : i64) : i64
        %543 = llvm.alloca %542 x i64 : (i64) -> !llvm.ptr
        llvm.store %541, %543 : i64, !llvm.ptr
        cf.br ^bb129
        ^bb129:
        %544 = llvm.load %543 : !llvm.ptr -> i64
        %545 = arith.cmpi sle, %544, %486 : i64
        cf.cond_br %545, ^bb130, ^bb131
        ^bb130:
          %546 = arith.constant 0 : i32
          %547 = llvm.load %543 : !llvm.ptr -> i64
          %548 = arith.trunci %546 : i32 to i8
          %549 = llvm.getelementptr %488[%547] : (!llvm.ptr, i64) -> !llvm.ptr, i8
          llvm.store %548, %549 : i8, !llvm.ptr
          %550 = llvm.load %543 : !llvm.ptr -> i64
          %551 = llvm.load %500 : !llvm.ptr -> i64
          %552 = arith.addi %550, %551 : i64
          llvm.store %552, %543 : i64, !llvm.ptr
          cf.br ^bb129
        ^bb131:
        cf.br ^bb128
      ^bb127:
        cf.br ^bb128
      ^bb128:
      %553 = llvm.load %500 : !llvm.ptr -> i64
      %554 = arith.constant 1 : i32
      %556 = arith.extsi %554 : i32 to i64
      %555 = arith.addi %553, %556 : i64
      llvm.store %555, %500 : i64, !llvm.ptr
      cf.br ^bb123
    ^bb125:
    %557 = arith.constant 0 : i32
    %558 = arith.extsi %557 : i32 to i64
    %559 = llvm.mlir.constant(1 : i64) : i64
    %560 = llvm.alloca %559 x i64 : (i64) -> !llvm.ptr
    llvm.store %558, %560 : i64, !llvm.ptr
    %561 = arith.constant 2 : i32
    %562 = arith.extsi %561 : i32 to i64
    llvm.store %562, %500 : i64, !llvm.ptr
    cf.br ^bb132
    ^bb132:
    %563 = llvm.load %500 : !llvm.ptr -> i64
    %564 = arith.cmpi sle, %563, %486 : i64
    cf.cond_br %564, ^bb133, ^bb134
    ^bb133:
      %566 = llvm.load %500 : !llvm.ptr -> i64
      %567 = llvm.getelementptr %488[%566] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %565 = llvm.load %567 : !llvm.ptr -> i8
      %568 = arith.constant 1 : i32
      %570 = arith.extsi %565 : i8 to i32
      %569 = arith.cmpi eq, %570, %568 : i32
      cf.cond_br %569, ^bb135, ^bb136
      ^bb135:
        %571 = llvm.load %560 : !llvm.ptr -> i64
        %572 = arith.constant 1 : i32
        %574 = arith.extsi %572 : i32 to i64
        %573 = arith.addi %571, %574 : i64
        llvm.store %573, %560 : i64, !llvm.ptr
        cf.br ^bb137
      ^bb136:
        cf.br ^bb137
      ^bb137:
      %575 = llvm.load %500 : !llvm.ptr -> i64
      %576 = arith.constant 1 : i32
      %578 = arith.extsi %576 : i32 to i64
      %577 = arith.addi %575, %578 : i64
      llvm.store %577, %500 : i64, !llvm.ptr
      cf.br ^bb132
    ^bb134:
    %580 = llvm.load %560 : !llvm.ptr -> i64
    %581 = arith.constant 8 : i32
    %582 = arith.extsi %581 : i32 to i64
    %579 = func.call @calloc(%580, %582) : (i64, i64) -> !llvm.ptr
    %583 = llvm.mlir.zero : !llvm.ptr
    %584 = llvm.icmp "eq" %579, %583 : !llvm.ptr
    cf.cond_br %584, ^bb138, ^bb139
    ^bb138:
      %585 = arith.constant 1 : i32
      func.return %585 : i32
    ^bb139:
      cf.br ^bb140
    ^bb140:
    %586 = arith.constant 0 : i32
    %587 = arith.extsi %586 : i32 to i64
    %588 = llvm.mlir.constant(1 : i64) : i64
    %589 = llvm.alloca %588 x i64 : (i64) -> !llvm.ptr
    llvm.store %587, %589 : i64, !llvm.ptr
    %590 = arith.constant 2 : i32
    %591 = arith.extsi %590 : i32 to i64
    llvm.store %591, %500 : i64, !llvm.ptr
    cf.br ^bb141
    ^bb141:
    %592 = llvm.load %500 : !llvm.ptr -> i64
    %593 = arith.cmpi sle, %592, %486 : i64
    cf.cond_br %593, ^bb142, ^bb143
    ^bb142:
      %595 = llvm.load %500 : !llvm.ptr -> i64
      %596 = llvm.getelementptr %488[%595] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %594 = llvm.load %596 : !llvm.ptr -> i8
      %597 = arith.constant 1 : i32
      %599 = arith.extsi %594 : i8 to i32
      %598 = arith.cmpi eq, %599, %597 : i32
      cf.cond_br %598, ^bb144, ^bb145
      ^bb144:
        %600 = llvm.load %500 : !llvm.ptr -> i64
        %601 = llvm.load %589 : !llvm.ptr -> i64
        %602 = llvm.getelementptr %579[%601] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %600, %602 : i64, !llvm.ptr
        %603 = llvm.load %589 : !llvm.ptr -> i64
        %604 = arith.constant 1 : i32
        %606 = arith.extsi %604 : i32 to i64
        %605 = arith.addi %603, %606 : i64
        llvm.store %605, %589 : i64, !llvm.ptr
        cf.br ^bb146
      ^bb145:
        cf.br ^bb146
      ^bb146:
      %607 = llvm.load %500 : !llvm.ptr -> i64
      %608 = arith.constant 1 : i32
      %610 = arith.extsi %608 : i32 to i64
      %609 = arith.addi %607, %610 : i64
      llvm.store %609, %500 : i64, !llvm.ptr
      cf.br ^bb141
    ^bb143:
    %611 = llvm.mlir.constant(1 : i64) : i64
    %612 = llvm.alloca %611 x i64 : (i64) -> !llvm.ptr
    llvm.store %478, %612 : i64, !llvm.ptr
    %613 = llvm.load %612 : !llvm.ptr -> i64
    %614 = arith.constant 1 : i32
    %616 = arith.extsi %614 : i32 to i64
    %615 = arith.andi %613, %616 : i64
    %617 = arith.constant 0 : i32
    %619 = arith.extsi %617 : i32 to i64
    %618 = arith.cmpi eq, %615, %619 : i64
    cf.cond_br %618, ^bb147, ^bb148
    ^bb147:
      %620 = llvm.load %612 : !llvm.ptr -> i64
      %621 = arith.constant 1 : i32
      %623 = arith.extsi %621 : i32 to i64
      %622 = arith.addi %620, %623 : i64
      llvm.store %622, %612 : i64, !llvm.ptr
      cf.br ^bb149
    ^bb148:
      cf.br ^bb149
    ^bb149:
    %624 = llvm.load %612 : !llvm.ptr -> i64
    %625 = arith.subi %483, %624 : i64
    %626 = arith.constant 2 : i32
    %628 = arith.extsi %626 : i32 to i64
    %627 = arith.divsi %625, %628 : i64
    %629 = arith.constant 1 : i32
    %631 = arith.extsi %629 : i32 to i64
    %630 = arith.addi %627, %631 : i64
    %633 = arith.constant 1 : i32
    %634 = arith.extsi %633 : i32 to i64
    %632 = func.call @calloc(%630, %634) : (i64, i64) -> !llvm.ptr
    %635 = llvm.mlir.zero : !llvm.ptr
    %636 = llvm.icmp "eq" %632, %635 : !llvm.ptr
    cf.cond_br %636, ^bb150, ^bb151
    ^bb150:
      %637 = arith.constant 1 : i32
      func.return %637 : i32
    ^bb151:
      cf.br ^bb152
    ^bb152:
    %638 = arith.constant 0 : i32
    %639 = arith.extsi %638 : i32 to i64
    llvm.store %639, %500 : i64, !llvm.ptr
    cf.br ^bb153
    ^bb153:
    %640 = llvm.load %500 : !llvm.ptr -> i64
    %641 = arith.cmpi slt, %640, %630 : i64
    cf.cond_br %641, ^bb154, ^bb155
    ^bb154:
      %642 = arith.constant 1 : i32
      %643 = llvm.load %500 : !llvm.ptr -> i64
      %644 = arith.trunci %642 : i32 to i8
      %645 = llvm.getelementptr %632[%643] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      llvm.store %644, %645 : i8, !llvm.ptr
      %646 = llvm.load %500 : !llvm.ptr -> i64
      %647 = arith.constant 1 : i32
      %649 = arith.extsi %647 : i32 to i64
      %648 = arith.addi %646, %649 : i64
      llvm.store %648, %500 : i64, !llvm.ptr
      cf.br ^bb153
    ^bb155:
    %650 = arith.constant 0 : i32
    %651 = arith.extsi %650 : i32 to i64
    llvm.store %651, %589 : i64, !llvm.ptr
    cf.br ^bb156
    ^bb156:
    %652 = llvm.load %589 : !llvm.ptr -> i64
    %653 = llvm.load %560 : !llvm.ptr -> i64
    %654 = arith.cmpi slt, %652, %653 : i64
    cf.cond_br %654, ^bb157, ^bb158
    ^bb157:
      %656 = llvm.load %589 : !llvm.ptr -> i64
      %657 = llvm.getelementptr %579[%656] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %655 = llvm.load %657 : !llvm.ptr -> i64
      %658 = arith.constant 2 : i32
      %660 = arith.extsi %658 : i32 to i64
      %659 = arith.cmpi eq, %655, %660 : i64
      cf.cond_br %659, ^bb159, ^bb160
      ^bb159:
        %661 = llvm.load %589 : !llvm.ptr -> i64
        %662 = arith.constant 1 : i32
        %664 = arith.extsi %662 : i32 to i64
        %663 = arith.addi %661, %664 : i64
        llvm.store %663, %589 : i64, !llvm.ptr
        cf.br ^bb156
      ^bb160:
        cf.br ^bb161
      ^bb161:
      %665 = arith.muli %655, %655 : i64
      %666 = arith.cmpi sgt, %665, %483 : i64
      cf.cond_br %666, ^bb162, ^bb163
      ^bb162:
        cf.br ^bb158
      ^bb163:
        cf.br ^bb164
      ^bb164:
      %667 = arith.constant 0 : i32
      %668 = arith.extsi %667 : i32 to i64
      %669 = llvm.mlir.constant(1 : i64) : i64
      %670 = llvm.alloca %669 x i64 : (i64) -> !llvm.ptr
      llvm.store %668, %670 : i64, !llvm.ptr
      %671 = llvm.load %612 : !llvm.ptr -> i64
      %672 = arith.cmpi sge, %665, %671 : i64
      cf.cond_br %672, ^bb165, ^bb166
      ^bb165:
        llvm.store %665, %670 : i64, !llvm.ptr
        cf.br ^bb167
      ^bb166:
        %673 = llvm.load %612 : !llvm.ptr -> i64
        %674 = arith.addi %673, %655 : i64
        %675 = arith.constant 1 : i32
        %677 = arith.extsi %675 : i32 to i64
        %676 = arith.subi %674, %677 : i64
        %678 = arith.divsi %676, %655 : i64
        %679 = arith.muli %678, %655 : i64
        llvm.store %679, %670 : i64, !llvm.ptr
        cf.br ^bb167
      ^bb167:
      %680 = llvm.load %670 : !llvm.ptr -> i64
      %681 = arith.constant 1 : i32
      %683 = arith.extsi %681 : i32 to i64
      %682 = arith.andi %680, %683 : i64
      %684 = arith.constant 0 : i32
      %686 = arith.extsi %684 : i32 to i64
      %685 = arith.cmpi eq, %682, %686 : i64
      cf.cond_br %685, ^bb168, ^bb169
      ^bb168:
        %687 = llvm.load %670 : !llvm.ptr -> i64
        %688 = arith.addi %687, %655 : i64
        llvm.store %688, %670 : i64, !llvm.ptr
        cf.br ^bb170
      ^bb169:
        cf.br ^bb170
      ^bb170:
      %689 = llvm.load %670 : !llvm.ptr -> i64
      %690 = llvm.load %612 : !llvm.ptr -> i64
      %691 = arith.subi %689, %690 : i64
      %692 = arith.constant 2 : i32
      %694 = arith.extsi %692 : i32 to i64
      %693 = arith.divsi %691, %694 : i64
      %695 = llvm.mlir.constant(1 : i64) : i64
      %696 = llvm.alloca %695 x i64 : (i64) -> !llvm.ptr
      llvm.store %693, %696 : i64, !llvm.ptr
      cf.br ^bb171
      ^bb171:
      %697 = llvm.load %696 : !llvm.ptr -> i64
      %698 = arith.cmpi slt, %697, %630 : i64
      cf.cond_br %698, ^bb172, ^bb173
      ^bb172:
        %699 = arith.constant 0 : i32
        %700 = llvm.load %696 : !llvm.ptr -> i64
        %701 = arith.trunci %699 : i32 to i8
        %702 = llvm.getelementptr %632[%700] : (!llvm.ptr, i64) -> !llvm.ptr, i8
        llvm.store %701, %702 : i8, !llvm.ptr
        %703 = llvm.load %696 : !llvm.ptr -> i64
        %704 = arith.addi %703, %655 : i64
        llvm.store %704, %696 : i64, !llvm.ptr
        cf.br ^bb171
      ^bb173:
      %705 = llvm.load %589 : !llvm.ptr -> i64
      %706 = arith.constant 1 : i32
      %708 = arith.extsi %706 : i32 to i64
      %707 = arith.addi %705, %708 : i64
      llvm.store %707, %589 : i64, !llvm.ptr
      cf.br ^bb156
    ^bb158:
    %709 = arith.constant 0 : i32
    %710 = arith.extsi %709 : i32 to i64
    %711 = llvm.mlir.constant(1 : i64) : i64
    %712 = llvm.alloca %711 x i64 : (i64) -> !llvm.ptr
    llvm.store %710, %712 : i64, !llvm.ptr
    %713 = arith.constant 2 : i32
    %715 = arith.extsi %713 : i32 to i64
    %714 = arith.cmpi sle, %478, %715 : i64
    cf.cond_br %714, ^bb174, ^bb175
    ^bb174:
      %716 = arith.constant 2 : i32
      %718 = arith.extsi %716 : i32 to i64
      %717 = arith.cmpi sle, %718, %483 : i64
      cf.cond_br %717, ^bb177, ^bb178
      ^bb177:
        %719 = llvm.load %712 : !llvm.ptr -> i64
        %721 = arith.constant 2 : i32
        %722 = arith.extsi %721 : i32 to i64
        %720 = func.call @a_mod_prime(%482, %722) : (i64, i64) -> i64
        %723 = arith.addi %719, %720 : i64
        llvm.store %723, %712 : i64, !llvm.ptr
        cf.br ^bb179
      ^bb178:
        cf.br ^bb179
      ^bb179:
      cf.br ^bb176
    ^bb175:
      cf.br ^bb176
    ^bb176:
    %724 = arith.constant 0 : i32
    %725 = arith.extsi %724 : i32 to i64
    llvm.store %725, %500 : i64, !llvm.ptr
    cf.br ^bb180
    ^bb180:
    %726 = llvm.load %500 : !llvm.ptr -> i64
    %727 = arith.cmpi slt, %726, %630 : i64
    cf.cond_br %727, ^bb181, ^bb182
    ^bb181:
      %729 = llvm.load %500 : !llvm.ptr -> i64
      %730 = llvm.getelementptr %632[%729] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %728 = llvm.load %730 : !llvm.ptr -> i8
      %731 = arith.constant 1 : i32
      %733 = arith.extsi %728 : i8 to i32
      %732 = arith.cmpi eq, %733, %731 : i32
      cf.cond_br %732, ^bb183, ^bb184
      ^bb183:
        %734 = llvm.load %612 : !llvm.ptr -> i64
        %735 = arith.constant 2 : i32
        %736 = llvm.load %500 : !llvm.ptr -> i64
        %738 = arith.extsi %735 : i32 to i64
        %737 = arith.muli %738, %736 : i64
        %739 = arith.addi %734, %737 : i64
        %740 = arith.cmpi sge, %739, %478 : i64
        cf.cond_br %740, ^bb186, ^bb187
        ^bb186:
          %741 = arith.cmpi sle, %739, %483 : i64
          cf.cond_br %741, ^bb189, ^bb190
          ^bb189:
            %742 = llvm.load %712 : !llvm.ptr -> i64
            %743 = func.call @a_mod_prime(%482, %739) : (i64, i64) -> i64
            %744 = arith.addi %742, %743 : i64
            llvm.store %744, %712 : i64, !llvm.ptr
            cf.br ^bb191
          ^bb190:
            cf.br ^bb191
          ^bb191:
          cf.br ^bb188
        ^bb187:
          cf.br ^bb188
        ^bb188:
        cf.br ^bb185
      ^bb184:
        cf.br ^bb185
      ^bb185:
      %745 = llvm.load %500 : !llvm.ptr -> i64
      %746 = arith.constant 1 : i32
      %748 = arith.extsi %746 : i32 to i64
      %747 = arith.addi %745, %748 : i64
      llvm.store %747, %500 : i64, !llvm.ptr
      cf.br ^bb180
    ^bb182:
    %749 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %750 = llvm.load %712 : !llvm.ptr -> i64
    %751 = llvm.call @printf(%749, %750) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    func.call @free(%488) : (!llvm.ptr) -> ()
    func.call @free(%579) : (!llvm.ptr) -> ()
    func.call @free(%632) : (!llvm.ptr) -> ()
    %755 = arith.constant 0 : i32
    func.return %755 : i32
  }
}