Problem 805

Pure Flow port of the native C solver.

Answer119719335
Output119719335
StatusPASS
Native helperno
Runtime1530 ms
Peak memory1216 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 805: Shifted Multiples - T(200) mod 1e9+7.
# Pure Flow port of the native C solver.

import euler.nt { gcd, mod_pow }

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

const MOD: i64 = 1000000007
const M: i64 = 200

function mod_inv(a: i64) -> i64 {
    return mod_pow(a, MOD - 2, MOD)
}

# Sieve primes up to 10000 into pp; returns count.
function init_primes(pp: ptr<i64>) -> i64 {
    let limit: i64 = 10000
    let sieve: ptr<i8> = calloc(limit + 1, 1) as ptr<i8>
    let mut pc: i64 = 0
    let mut i: i64 = 2
    while i <= limit {
        if sieve[i] == 0 {
            pp[pc] = i
            pc = pc + 1
            let mut j: i64 = i * i
            while j <= limit {
                sieve[j] = 1
                j = j + i
            }
        }
        i = i + 1
    }
    free(sieve)
    return pc
}

# Factorize n into pp/ee arrays. Returns count.
function factorize(n0: i64, primes: ptr<i64>, nprimes: i64, pp: ptr<i64>, ee: ptr<i64>) -> i64 {
    let mut cnt: i64 = 0
    let mut x: i64 = n0
    let mut i: i64 = 0
    while i < nprimes {
        let p: i64 = primes[i]
        if p * p > x {
            i = nprimes
        } else {
            if x % p == 0 {
                let mut e: i64 = 0
                while x % p == 0 {
                    x = x / p
                    e = e + 1
                }
                pp[cnt] = p
                ee[cnt] = e
                cnt = cnt + 1
            }
            i = i + 1
        }
    }
    if x > 1 {
        pp[cnt] = x
        ee[cnt] = 1
        cnt = cnt + 1
    }
    return cnt
}

function euler_phi(n: i64, primes: ptr<i64>, nprimes: i64) -> i64 {
    if n == 1 {
        return 1
    }
    let pp: ptr<i64> = calloc(64, 8) as ptr<i64>
    let ee: ptr<i64> = calloc(64, 8) as ptr<i64>
    let c: i64 = factorize(n, primes, nprimes, pp, ee)
    let mut phi: i64 = n
    let mut i: i64 = 0
    while i < c {
        phi = (phi / pp[i]) * (pp[i] - 1)
        i = i + 1
    }
    free(pp)
    free(ee)
    return phi
}

# Multiplicative order of 10 mod m. Returns 0 if gcd(10,m) != 1.
function mult_order_10(m: i64, primes: ptr<i64>, nprimes: i64) -> i64 {
    if m == 1 {
        return 1
    }
    if gcd(m, 10) != 1 {
        return 0
    }
    let phi: i64 = euler_phi(m, primes, nprimes)
    let pp: ptr<i64> = calloc(64, 8) as ptr<i64>
    let ee: ptr<i64> = calloc(64, 8) as ptr<i64>
    let c: i64 = factorize(phi, primes, nprimes, pp, ee)
    let mut k: i64 = phi
    let mut i: i64 = 0
    while i < c {
        let p: i64 = pp[i]
        while k % p == 0 && mod_pow(10, k / p, m) == 1 {
            k = k / p
        }
        i = i + 1
    }
    free(pp)
    free(ee)
    return k
}

# Derive bounds on digit length k for leading digit d.
# k_low = -1 means no solution. k_high = -1 means unbounded.
function digit_k_bounds(a: i64, b: i64, d: i64, k_low: ptr<i64>, k_high: ptr<i64>) -> void {
    let mut e: i64 = 0
    let mut t: i64 = a
    while t < b {
        t = t * 10
        e = e + 1
    }
    k_low[0] = e + 1

    let denom: i64 = a * (d + 1) - 10 * b
    if denom <= 0 {
        k_high[0] = -1
        return
    }
    let max_pow10: i64 = (b * d - 1) / denom
    if max_pow10 <= 0 {
        k_low[0] = -1
        k_high[0] = -1
        return
    }
    let mut e_high: i64 = 0
    let mut pow10: i64 = 1
    while pow10 * 10 <= max_pow10 {
        pow10 = pow10 * 10
        e_high = e_high + 1
    }
    k_high[0] = e_high + 1
}

# For reduced a/b, find minimal (k,d,D). Returns 1 on success.
function find_N_params(a: i64, b: i64, primes: ptr<i64>, nprimes: i64, out_k: ptr<i64>, out_d: ptr<i64>, out_D: ptr<i64>) -> i32 {
    if a == b {
        out_k[0] = 1
        out_d[0] = 1
        out_D[0] = 9 * b
        return 1
    }
    let D: i64 = 10 * b - a
    if D <= 0 {
        return 0
    }

    let mut best_k: i64 = 0
    let mut best_d: i64 = 0
    let mut have: i32 = 0
    let kl: ptr<i64> = calloc(1, 8) as ptr<i64>
    let kh: ptr<i64> = calloc(1, 8) as ptr<i64>
    let mut d: i64 = 1
    while d <= 9 {
        digit_k_bounds(a, b, d, kl, kh)
        if kl[0] != -1 {
            let mut klow: i64 = kl[0]
            if klow < 2 {
                klow = 2
            }
            let m: i64 = D / gcd(D, d * b)
            let ord10: i64 = mult_order_10(m, primes, nprimes)
            if ord10 != 0 {
                let k: i64 = ((klow + ord10 - 1) / ord10) * ord10
                if !(kh[0] != -1 && k > kh[0]) {
                    if have == 0 || k < best_k || (k == best_k && d < best_d) {
                        best_k = k
                        best_d = d
                        have = 1
                    }
                }
            }
        }
        d = d + 1
    }
    free(kl)
    free(kh)
    if have == 0 {
        return 0
    }
    out_k[0] = best_k
    out_d[0] = best_d
    out_D[0] = D
    return 1
}

function N_mod(a0: i64, b0: i64, primes: ptr<i64>, nprimes: i64) -> i64 {
    let g: i64 = gcd(a0, b0)
    let a: i64 = a0 / g
    let b: i64 = b0 / g
    if a == b {
        return 1 % MOD
    }
    let kp: ptr<i64> = calloc(1, 8) as ptr<i64>
    let dp: ptr<i64> = calloc(1, 8) as ptr<i64>
    let Dp: ptr<i64> = calloc(1, 8) as ptr<i64>
    if find_N_params(a, b, primes, nprimes, kp, dp, Dp) == 0 {
        free(kp)
        free(dp)
        free(Dp)
        return 0
    }
    let k: i64 = kp[0]
    let d: i64 = dp[0]
    let D: i64 = Dp[0]
    free(kp)
    free(dp)
    free(Dp)
    let invD: i64 = mod_inv(D % MOD)
    let ten_k: i64 = mod_pow(10, k, MOD)
    let term: i64 = (ten_k - 1 + MOD) % MOD
    let mut res: i64 = (d % MOD) * (b % MOD) % MOD
    res = res * term % MOD
    res = res * invD % MOD
    return res
}

function main() -> i32 {
    let primes: ptr<i64> = calloc(2000, 8) as ptr<i64>
    let nprimes: i64 = init_primes(primes)
    let mut total: i64 = 0
    let mut u: i64 = 1
    while u <= M {
        let a: i64 = u * u * u
        let mut v: i64 = 1
        while v <= M {
            if gcd(u, v) == 1 {
                let b: i64 = v * v * v
                total = (total + N_mod(a, b, primes, nprimes)) % MOD
            }
            v = v + 1
        }
        u = u + 1
    }
    free(primes)
    printf("%lld\n", total)
    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 mod_inv_i64(int64_t a);
int64_t init_primes_ptr_i64(int64_t* pp);
int64_t factorize_i64_ptr_i64_i64_ptr_i64_ptr_i64(int64_t n0, int64_t* primes, int64_t nprimes, int64_t* pp, int64_t* ee);
int64_t euler_phi_i64_ptr_i64_i64(int64_t n, int64_t* primes, int64_t nprimes);
int64_t mult_order_10_i64_ptr_i64_i64(int64_t m, int64_t* primes, int64_t nprimes);
void digit_k_bounds_i64_i64_i64_ptr_i64_ptr_i64(int64_t a, int64_t b, int64_t d, int64_t* k_low, int64_t* k_high);
int32_t find_N_params_i64_i64_ptr_i64_i64_ptr_i64_ptr_i64_ptr_i64(int64_t a, int64_t b, int64_t* primes, int64_t nprimes, int64_t* out_k, int64_t* out_d, int64_t* out_D);
int64_t N_mod_i64_i64_ptr_i64_i64(int64_t a0, int64_t b0, int64_t* primes, int64_t nprimes);
int32_t main(void);

static const int64_t MOD = 1000000007;
static const int64_t M = 200;

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 mod_inv_i64(int64_t a) {
    return mod_pow_i64_i64_i64(a, (MOD - 2), MOD);
}

int64_t init_primes_ptr_i64(int64_t* pp) {
    int64_t limit = 10000;
    int8_t* sieve = (int8_t*)(((int8_t*)(calloc((limit + 1), 1))));
    int64_t pc = 0;
    int64_t i = 2;
    while (i <= limit) {
        if (sieve[i] == 0) {
            pp[pc] = i;
            pc = (pc + 1);
            int64_t j = (i * i);
            while (j <= limit) {
                sieve[j] = 1;
                j = (j + i);
            }
        }
        i = (i + 1);
    }
    free(sieve);
    return pc;
}

int64_t factorize_i64_ptr_i64_i64_ptr_i64_ptr_i64(int64_t n0, int64_t* primes, int64_t nprimes, int64_t* pp, int64_t* ee) {
    int64_t cnt = 0;
    int64_t x = n0;
    int64_t i = 0;
    while (i < nprimes) {
        int64_t p = primes[i];
        if ((p * p) > x) {
            i = nprimes;
        } else {
            if (FLOW_CHECKED_MOD((x), (p)) == 0) {
                int64_t e = 0;
                while (FLOW_CHECKED_MOD((x), (p)) == 0) {
                    x = FLOW_CHECKED_DIV((x), (p));
                    e = (e + 1);
                }
                pp[cnt] = p;
                ee[cnt] = e;
                cnt = (cnt + 1);
            }
            i = (i + 1);
        }
    }
    if (x > 1) {
        pp[cnt] = x;
        ee[cnt] = 1;
        cnt = (cnt + 1);
    }
    return cnt;
}

int64_t euler_phi_i64_ptr_i64_i64(int64_t n, int64_t* primes, int64_t nprimes) {
    if (n == 1) {
        return 1;
    }
    int64_t* pp = (int64_t*)(((int64_t*)(calloc(64, 8))));
    int64_t* ee = (int64_t*)(((int64_t*)(calloc(64, 8))));
    int64_t c = factorize_i64_ptr_i64_i64_ptr_i64_ptr_i64(n, primes, nprimes, pp, ee);
    int64_t phi = n;
    int64_t i = 0;
    while (i < c) {
        phi = (FLOW_CHECKED_DIV((phi), (pp[i])) * (pp[i] - 1));
        i = (i + 1);
    }
    free(pp);
    free(ee);
    return phi;
}

int64_t mult_order_10_i64_ptr_i64_i64(int64_t m, int64_t* primes, int64_t nprimes) {
    if (m == 1) {
        return 1;
    }
    if (gcd_i64_i64(m, 10) != 1) {
        return 0;
    }
    int64_t phi = euler_phi_i64_ptr_i64_i64(m, primes, nprimes);
    int64_t* pp = (int64_t*)(((int64_t*)(calloc(64, 8))));
    int64_t* ee = (int64_t*)(((int64_t*)(calloc(64, 8))));
    int64_t c = factorize_i64_ptr_i64_i64_ptr_i64_ptr_i64(phi, primes, nprimes, pp, ee);
    int64_t k = phi;
    int64_t i = 0;
    while (i < c) {
        int64_t p = pp[i];
        while ((FLOW_CHECKED_MOD((k), (p)) == 0 && mod_pow_i64_i64_i64(10, FLOW_CHECKED_DIV((k), (p)), m) == 1)) {
            k = FLOW_CHECKED_DIV((k), (p));
        }
        i = (i + 1);
    }
    free(pp);
    free(ee);
    return k;
}

void digit_k_bounds_i64_i64_i64_ptr_i64_ptr_i64(int64_t a, int64_t b, int64_t d, int64_t* k_low, int64_t* k_high) {
    int64_t e = 0;
    int64_t t = a;
    while (t < b) {
        t = (t * 10);
        e = (e + 1);
    }
    k_low[0] = (e + 1);
    int64_t denom = ((a * (d + 1)) - (10 * b));
    if (denom <= 0) {
        k_high[0] = (-1);
        return;
    }
    int64_t max_pow10 = FLOW_CHECKED_DIV((((b * d) - 1)), (denom));
    if (max_pow10 <= 0) {
        k_low[0] = (-1);
        k_high[0] = (-1);
        return;
    }
    int64_t e_high = 0;
    int64_t pow10 = 1;
    while ((pow10 * 10) <= max_pow10) {
        pow10 = (pow10 * 10);
        e_high = (e_high + 1);
    }
    k_high[0] = (e_high + 1);
}

int32_t find_N_params_i64_i64_ptr_i64_i64_ptr_i64_ptr_i64_ptr_i64(int64_t a, int64_t b, int64_t* primes, int64_t nprimes, int64_t* out_k, int64_t* out_d, int64_t* out_D) {
    if (a == b) {
        out_k[0] = 1;
        out_d[0] = 1;
        out_D[0] = (9 * b);
        return 1;
    }
    int64_t D = ((10 * b) - a);
    if (D <= 0) {
        return 0;
    }
    int64_t best_k = 0;
    int64_t best_d = 0;
    int32_t have = 0;
    int64_t* kl = (int64_t*)(((int64_t*)(calloc(1, 8))));
    int64_t* kh = (int64_t*)(((int64_t*)(calloc(1, 8))));
    int64_t d = 1;
    while (d <= 9) {
        digit_k_bounds_i64_i64_i64_ptr_i64_ptr_i64(a, b, d, kl, kh);
        if (kl[0] != (-1)) {
            int64_t klow = kl[0];
            if (klow < 2) {
                klow = 2;
            }
            int64_t m = FLOW_CHECKED_DIV((D), (gcd_i64_i64(D, (d * b))));
            int64_t ord10 = mult_order_10_i64_ptr_i64_i64(m, primes, nprimes);
            if (ord10 != 0) {
                int64_t k = (FLOW_CHECKED_DIV((((klow + ord10) - 1)), (ord10)) * ord10);
                if ((!((kh[0] != (-1) && k > kh[0])))) {
                    if (((have == 0 || k < best_k) || (k == best_k && d < best_d))) {
                        best_k = k;
                        best_d = d;
                        have = 1;
                    }
                }
            }
        }
        d = (d + 1);
    }
    free(kl);
    free(kh);
    if (have == 0) {
        return 0;
    }
    out_k[0] = best_k;
    out_d[0] = best_d;
    out_D[0] = D;
    return 1;
}

int64_t N_mod_i64_i64_ptr_i64_i64(int64_t a0, int64_t b0, int64_t* primes, int64_t nprimes) {
    int64_t g = gcd_i64_i64(a0, b0);
    int64_t a = FLOW_CHECKED_DIV((a0), (g));
    int64_t b = FLOW_CHECKED_DIV((b0), (g));
    if (a == b) {
        return FLOW_CHECKED_MOD((1), (MOD));
    }
    int64_t* kp = (int64_t*)(((int64_t*)(calloc(1, 8))));
    int64_t* dp = (int64_t*)(((int64_t*)(calloc(1, 8))));
    int64_t* Dp = (int64_t*)(((int64_t*)(calloc(1, 8))));
    if (find_N_params_i64_i64_ptr_i64_i64_ptr_i64_ptr_i64_ptr_i64(a, b, primes, nprimes, kp, dp, Dp) == 0) {
        free(kp);
        free(dp);
        free(Dp);
        return 0;
    }
    int64_t k = kp[0];
    int64_t d = dp[0];
    int64_t D = Dp[0];
    free(kp);
    free(dp);
    free(Dp);
    int64_t invD = mod_inv_i64(FLOW_CHECKED_MOD((D), (MOD)));
    int64_t ten_k = mod_pow_i64_i64_i64(10, k, MOD);
    int64_t term = FLOW_CHECKED_MOD((((ten_k - 1) + MOD)), (MOD));
    int64_t res = FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD((d), (MOD)) * FLOW_CHECKED_MOD((b), (MOD)))), (MOD));
    res = FLOW_CHECKED_MOD(((res * term)), (MOD));
    res = FLOW_CHECKED_MOD(((res * invD)), (MOD));
    return res;
}

int32_t main(void) {
    int64_t* primes = (int64_t*)(((int64_t*)(calloc(2000, 8))));
    int64_t nprimes = init_primes_ptr_i64(primes);
    int64_t total = 0;
    int64_t u = 1;
    while (u <= M) {
        int64_t a = ((u * u) * u);
        int64_t v = 1;
        while (v <= M) {
            if (gcd_i64_i64(u, v) == 1) {
                int64_t b = ((v * v) * v);
                total = FLOW_CHECKED_MOD(((total + N_mod_i64_i64_ptr_i64_i64(a, b, primes, nprimes))), (MOD));
            }
            v = (v + 1);
        }
        u = (u + 1);
    }
    free(primes);
    printf("%lld\n", total);
    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) -> ()
  // Constant: MOD
  llvm.mlir.global internal constant @MOD(1000000007 : i64) : i64
  // Constant: M
  llvm.mlir.global internal constant @M(200 : i64) : i64
  func.func @mod_inv(%arg0: i64) -> i64 {
    %176 = llvm.mlir.addressof @MOD : !llvm.ptr
    %177 = llvm.load %176 : !llvm.ptr -> i64
    %178 = arith.constant 2 : i32
    %180 = arith.extsi %178 : i32 to i64
    %179 = arith.subi %177, %180 : i64
    %181 = llvm.mlir.addressof @MOD : !llvm.ptr
    %182 = llvm.load %181 : !llvm.ptr -> i64
    %175 = func.call @mod_pow(%arg0, %179, %182) : (i64, i64, i64) -> i64
    func.return %175 : i64
  }
  func.func @init_primes(%arg0: !llvm.ptr) -> i64 {
    %183 = arith.constant 10000 : i32
    %184 = arith.extsi %183 : i32 to i64
    %186 = arith.constant 1 : i32
    %188 = arith.extsi %186 : i32 to i64
    %187 = arith.addi %184, %188 : i64
    %189 = arith.constant 1 : i32
    %190 = arith.extsi %189 : i32 to i64
    %185 = func.call @calloc(%187, %190) : (i64, i64) -> !llvm.ptr
    %191 = arith.constant 0 : i32
    %192 = arith.extsi %191 : i32 to i64
    %193 = llvm.mlir.constant(1 : i64) : i64
    %194 = llvm.alloca %193 x i64 : (i64) -> !llvm.ptr
    llvm.store %192, %194 : i64, !llvm.ptr
    %195 = arith.constant 2 : i32
    %196 = arith.extsi %195 : i32 to i64
    %197 = llvm.mlir.constant(1 : i64) : i64
    %198 = llvm.alloca %197 x i64 : (i64) -> !llvm.ptr
    llvm.store %196, %198 : i64, !llvm.ptr
    cf.br ^bb42
    ^bb42:
    %199 = llvm.load %198 : !llvm.ptr -> i64
    %200 = arith.cmpi sle, %199, %184 : i64
    cf.cond_br %200, ^bb43, ^bb44
    ^bb43:
      %202 = llvm.load %198 : !llvm.ptr -> i64
      %203 = llvm.getelementptr %185[%202] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %201 = llvm.load %203 : !llvm.ptr -> i8
      %204 = arith.constant 0 : i32
      %206 = arith.extsi %201 : i8 to i32
      %205 = arith.cmpi eq, %206, %204 : i32
      cf.cond_br %205, ^bb45, ^bb46
      ^bb45:
        %207 = llvm.load %198 : !llvm.ptr -> i64
        %208 = llvm.load %194 : !llvm.ptr -> i64
        %209 = llvm.getelementptr %arg0[%208] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %207, %209 : i64, !llvm.ptr
        %210 = llvm.load %194 : !llvm.ptr -> i64
        %211 = arith.constant 1 : i32
        %213 = arith.extsi %211 : i32 to i64
        %212 = arith.addi %210, %213 : i64
        llvm.store %212, %194 : i64, !llvm.ptr
        %214 = llvm.load %198 : !llvm.ptr -> i64
        %215 = llvm.load %198 : !llvm.ptr -> i64
        %216 = arith.muli %214, %215 : i64
        %217 = llvm.mlir.constant(1 : i64) : i64
        %218 = llvm.alloca %217 x i64 : (i64) -> !llvm.ptr
        llvm.store %216, %218 : i64, !llvm.ptr
        cf.br ^bb48
        ^bb48:
        %219 = llvm.load %218 : !llvm.ptr -> i64
        %220 = arith.cmpi sle, %219, %184 : i64
        cf.cond_br %220, ^bb49, ^bb50
        ^bb49:
          %221 = arith.constant 1 : i32
          %222 = llvm.load %218 : !llvm.ptr -> i64
          %223 = arith.trunci %221 : i32 to i8
          %224 = llvm.getelementptr %185[%222] : (!llvm.ptr, i64) -> !llvm.ptr, i8
          llvm.store %223, %224 : i8, !llvm.ptr
          %225 = llvm.load %218 : !llvm.ptr -> i64
          %226 = llvm.load %198 : !llvm.ptr -> i64
          %227 = arith.addi %225, %226 : i64
          llvm.store %227, %218 : i64, !llvm.ptr
          cf.br ^bb48
        ^bb50:
        cf.br ^bb47
      ^bb46:
        cf.br ^bb47
      ^bb47:
      %228 = llvm.load %198 : !llvm.ptr -> i64
      %229 = arith.constant 1 : i32
      %231 = arith.extsi %229 : i32 to i64
      %230 = arith.addi %228, %231 : i64
      llvm.store %230, %198 : i64, !llvm.ptr
      cf.br ^bb42
    ^bb44:
    func.call @free(%185) : (!llvm.ptr) -> ()
    %233 = llvm.load %194 : !llvm.ptr -> i64
    func.return %233 : i64
  }
  func.func @factorize(%arg0: i64, %arg1: !llvm.ptr, %arg2: i64, %arg3: !llvm.ptr, %arg4: !llvm.ptr) -> i64 {
    %234 = arith.constant 0 : i32
    %235 = arith.extsi %234 : i32 to i64
    %236 = llvm.mlir.constant(1 : i64) : i64
    %237 = llvm.alloca %236 x i64 : (i64) -> !llvm.ptr
    llvm.store %235, %237 : i64, !llvm.ptr
    %238 = llvm.mlir.constant(1 : i64) : i64
    %239 = llvm.alloca %238 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %239 : i64, !llvm.ptr
    %240 = arith.constant 0 : i32
    %241 = arith.extsi %240 : i32 to i64
    %242 = llvm.mlir.constant(1 : i64) : i64
    %243 = llvm.alloca %242 x i64 : (i64) -> !llvm.ptr
    llvm.store %241, %243 : i64, !llvm.ptr
    cf.br ^bb51
    ^bb51:
    %244 = llvm.load %243 : !llvm.ptr -> i64
    %245 = arith.cmpi slt, %244, %arg2 : i64
    cf.cond_br %245, ^bb52, ^bb53
    ^bb52:
      %247 = llvm.load %243 : !llvm.ptr -> i64
      %248 = llvm.getelementptr %arg1[%247] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %246 = llvm.load %248 : !llvm.ptr -> i64
      %249 = arith.muli %246, %246 : i64
      %250 = llvm.load %239 : !llvm.ptr -> i64
      %251 = arith.cmpi sgt, %249, %250 : i64
      cf.cond_br %251, ^bb54, ^bb55
      ^bb54:
        llvm.store %arg2, %243 : i64, !llvm.ptr
        cf.br ^bb56
      ^bb55:
        %252 = llvm.load %239 : !llvm.ptr -> i64
        %253 = arith.remsi %252, %246 : i64
        %254 = arith.constant 0 : i32
        %256 = arith.extsi %254 : i32 to i64
        %255 = arith.cmpi eq, %253, %256 : i64
        cf.cond_br %255, ^bb57, ^bb58
        ^bb57:
          %257 = arith.constant 0 : i32
          %258 = arith.extsi %257 : i32 to i64
          %259 = llvm.mlir.constant(1 : i64) : i64
          %260 = llvm.alloca %259 x i64 : (i64) -> !llvm.ptr
          llvm.store %258, %260 : i64, !llvm.ptr
          cf.br ^bb60
          ^bb60:
          %261 = llvm.load %239 : !llvm.ptr -> i64
          %262 = arith.remsi %261, %246 : i64
          %263 = arith.constant 0 : i32
          %265 = arith.extsi %263 : i32 to i64
          %264 = arith.cmpi eq, %262, %265 : i64
          cf.cond_br %264, ^bb61, ^bb62
          ^bb61:
            %266 = llvm.load %239 : !llvm.ptr -> i64
            %267 = arith.divsi %266, %246 : i64
            llvm.store %267, %239 : i64, !llvm.ptr
            %268 = llvm.load %260 : !llvm.ptr -> i64
            %269 = arith.constant 1 : i32
            %271 = arith.extsi %269 : i32 to i64
            %270 = arith.addi %268, %271 : i64
            llvm.store %270, %260 : i64, !llvm.ptr
            cf.br ^bb60
          ^bb62:
          %272 = llvm.load %237 : !llvm.ptr -> i64
          %273 = llvm.getelementptr %arg3[%272] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          llvm.store %246, %273 : i64, !llvm.ptr
          %274 = llvm.load %260 : !llvm.ptr -> i64
          %275 = llvm.load %237 : !llvm.ptr -> i64
          %276 = llvm.getelementptr %arg4[%275] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          llvm.store %274, %276 : i64, !llvm.ptr
          %277 = llvm.load %237 : !llvm.ptr -> i64
          %278 = arith.constant 1 : i32
          %280 = arith.extsi %278 : i32 to i64
          %279 = arith.addi %277, %280 : i64
          llvm.store %279, %237 : i64, !llvm.ptr
          cf.br ^bb59
        ^bb58:
          cf.br ^bb59
        ^bb59:
        %281 = llvm.load %243 : !llvm.ptr -> i64
        %282 = arith.constant 1 : i32
        %284 = arith.extsi %282 : i32 to i64
        %283 = arith.addi %281, %284 : i64
        llvm.store %283, %243 : i64, !llvm.ptr
        cf.br ^bb56
      ^bb56:
      cf.br ^bb51
    ^bb53:
    %285 = llvm.load %239 : !llvm.ptr -> i64
    %286 = arith.constant 1 : i32
    %288 = arith.extsi %286 : i32 to i64
    %287 = arith.cmpi sgt, %285, %288 : i64
    cf.cond_br %287, ^bb63, ^bb64
    ^bb63:
      %289 = llvm.load %239 : !llvm.ptr -> i64
      %290 = llvm.load %237 : !llvm.ptr -> i64
      %291 = llvm.getelementptr %arg3[%290] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %289, %291 : i64, !llvm.ptr
      %292 = arith.constant 1 : i32
      %293 = llvm.load %237 : !llvm.ptr -> i64
      %294 = arith.extsi %292 : i32 to i64
      %295 = llvm.getelementptr %arg4[%293] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %294, %295 : i64, !llvm.ptr
      %296 = llvm.load %237 : !llvm.ptr -> i64
      %297 = arith.constant 1 : i32
      %299 = arith.extsi %297 : i32 to i64
      %298 = arith.addi %296, %299 : i64
      llvm.store %298, %237 : i64, !llvm.ptr
      cf.br ^bb65
    ^bb64:
      cf.br ^bb65
    ^bb65:
    %300 = llvm.load %237 : !llvm.ptr -> i64
    func.return %300 : i64
  }
  func.func @euler_phi(%arg0: i64, %arg1: !llvm.ptr, %arg2: i64) -> i64 {
    %301 = arith.constant 1 : i32
    %303 = arith.extsi %301 : i32 to i64
    %302 = arith.cmpi eq, %arg0, %303 : i64
    cf.cond_br %302, ^bb66, ^bb67
    ^bb66:
      %304 = arith.constant 1 : i32
      %305 = arith.extsi %304 : i32 to i64
      func.return %305 : i64
    ^bb67:
      cf.br ^bb68
    ^bb68:
    %307 = arith.constant 64 : i32
    %308 = arith.constant 8 : i32
    %309 = arith.extsi %307 : i32 to i64
    %310 = arith.extsi %308 : i32 to i64
    %306 = func.call @calloc(%309, %310) : (i64, i64) -> !llvm.ptr
    %312 = arith.constant 64 : i32
    %313 = arith.constant 8 : i32
    %314 = arith.extsi %312 : i32 to i64
    %315 = arith.extsi %313 : i32 to i64
    %311 = func.call @calloc(%314, %315) : (i64, i64) -> !llvm.ptr
    %316 = func.call @factorize(%arg0, %arg1, %arg2, %306, %311) : (i64, !llvm.ptr, i64, !llvm.ptr, !llvm.ptr) -> i64
    %317 = llvm.mlir.constant(1 : i64) : i64
    %318 = llvm.alloca %317 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %318 : i64, !llvm.ptr
    %319 = arith.constant 0 : i32
    %320 = arith.extsi %319 : i32 to i64
    %321 = llvm.mlir.constant(1 : i64) : i64
    %322 = llvm.alloca %321 x i64 : (i64) -> !llvm.ptr
    llvm.store %320, %322 : i64, !llvm.ptr
    cf.br ^bb69
    ^bb69:
    %323 = llvm.load %322 : !llvm.ptr -> i64
    %324 = arith.cmpi slt, %323, %316 : i64
    cf.cond_br %324, ^bb70, ^bb71
    ^bb70:
      %325 = llvm.load %318 : !llvm.ptr -> i64
      %327 = llvm.load %322 : !llvm.ptr -> i64
      %328 = llvm.getelementptr %306[%327] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %326 = llvm.load %328 : !llvm.ptr -> i64
      %329 = arith.divsi %325, %326 : i64
      %331 = llvm.load %322 : !llvm.ptr -> i64
      %332 = llvm.getelementptr %306[%331] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %330 = llvm.load %332 : !llvm.ptr -> i64
      %333 = arith.constant 1 : i32
      %335 = arith.extsi %333 : i32 to i64
      %334 = arith.subi %330, %335 : i64
      %336 = arith.muli %329, %334 : i64
      llvm.store %336, %318 : i64, !llvm.ptr
      %337 = llvm.load %322 : !llvm.ptr -> i64
      %338 = arith.constant 1 : i32
      %340 = arith.extsi %338 : i32 to i64
      %339 = arith.addi %337, %340 : i64
      llvm.store %339, %322 : i64, !llvm.ptr
      cf.br ^bb69
    ^bb71:
    func.call @free(%306) : (!llvm.ptr) -> ()
    func.call @free(%311) : (!llvm.ptr) -> ()
    %343 = llvm.load %318 : !llvm.ptr -> i64
    func.return %343 : i64
  }
  func.func @mult_order_10(%arg0: i64, %arg1: !llvm.ptr, %arg2: i64) -> i64 {
    %344 = arith.constant 1 : i32
    %346 = arith.extsi %344 : i32 to i64
    %345 = arith.cmpi eq, %arg0, %346 : i64
    cf.cond_br %345, ^bb72, ^bb73
    ^bb72:
      %347 = arith.constant 1 : i32
      %348 = arith.extsi %347 : i32 to i64
      func.return %348 : i64
    ^bb73:
      cf.br ^bb74
    ^bb74:
    %350 = arith.constant 10 : i32
    %351 = arith.extsi %350 : i32 to i64
    %349 = func.call @gcd(%arg0, %351) : (i64, i64) -> i64
    %352 = arith.constant 1 : i32
    %354 = arith.extsi %352 : i32 to i64
    %353 = arith.cmpi ne, %349, %354 : i64
    cf.cond_br %353, ^bb75, ^bb76
    ^bb75:
      %355 = arith.constant 0 : i32
      %356 = arith.extsi %355 : i32 to i64
      func.return %356 : i64
    ^bb76:
      cf.br ^bb77
    ^bb77:
    %357 = func.call @euler_phi(%arg0, %arg1, %arg2) : (i64, !llvm.ptr, i64) -> i64
    %359 = arith.constant 64 : i32
    %360 = arith.constant 8 : i32
    %361 = arith.extsi %359 : i32 to i64
    %362 = arith.extsi %360 : i32 to i64
    %358 = func.call @calloc(%361, %362) : (i64, i64) -> !llvm.ptr
    %364 = arith.constant 64 : i32
    %365 = arith.constant 8 : i32
    %366 = arith.extsi %364 : i32 to i64
    %367 = arith.extsi %365 : i32 to i64
    %363 = func.call @calloc(%366, %367) : (i64, i64) -> !llvm.ptr
    %368 = func.call @factorize(%357, %arg1, %arg2, %358, %363) : (i64, !llvm.ptr, i64, !llvm.ptr, !llvm.ptr) -> i64
    %369 = llvm.mlir.constant(1 : i64) : i64
    %370 = llvm.alloca %369 x i64 : (i64) -> !llvm.ptr
    llvm.store %357, %370 : i64, !llvm.ptr
    %371 = arith.constant 0 : i32
    %372 = arith.extsi %371 : i32 to i64
    %373 = llvm.mlir.constant(1 : i64) : i64
    %374 = llvm.alloca %373 x i64 : (i64) -> !llvm.ptr
    llvm.store %372, %374 : i64, !llvm.ptr
    cf.br ^bb78
    ^bb78:
    %375 = llvm.load %374 : !llvm.ptr -> i64
    %376 = arith.cmpi slt, %375, %368 : i64
    cf.cond_br %376, ^bb79, ^bb80
    ^bb79:
      %378 = llvm.load %374 : !llvm.ptr -> i64
      %379 = llvm.getelementptr %358[%378] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %377 = llvm.load %379 : !llvm.ptr -> i64
      cf.br ^bb81
      ^bb81:
      %380 = llvm.load %370 : !llvm.ptr -> i64
      %381 = arith.remsi %380, %377 : i64
      %382 = arith.constant 0 : i32
      %384 = arith.extsi %382 : i32 to i64
      %383 = arith.cmpi eq, %381, %384 : i64
      %385 = scf.if %383 -> (i1) {
        %387 = arith.constant 10 : i32
        %388 = llvm.load %370 : !llvm.ptr -> i64
        %389 = arith.divsi %388, %377 : i64
        %390 = arith.extsi %387 : i32 to i64
        %386 = func.call @mod_pow(%390, %389, %arg0) : (i64, i64, i64) -> i64
        %391 = arith.constant 1 : i32
        %393 = arith.extsi %391 : i32 to i64
        %392 = arith.cmpi eq, %386, %393 : i64
        scf.yield %392 : i1
      } else {
        %394 = arith.constant false
        scf.yield %394 : i1
      }
      cf.cond_br %385, ^bb82, ^bb83
      ^bb82:
        %395 = llvm.load %370 : !llvm.ptr -> i64
        %396 = arith.divsi %395, %377 : i64
        llvm.store %396, %370 : i64, !llvm.ptr
        cf.br ^bb81
      ^bb83:
      %397 = llvm.load %374 : !llvm.ptr -> i64
      %398 = arith.constant 1 : i32
      %400 = arith.extsi %398 : i32 to i64
      %399 = arith.addi %397, %400 : i64
      llvm.store %399, %374 : i64, !llvm.ptr
      cf.br ^bb78
    ^bb80:
    func.call @free(%358) : (!llvm.ptr) -> ()
    func.call @free(%363) : (!llvm.ptr) -> ()
    %403 = llvm.load %370 : !llvm.ptr -> i64
    func.return %403 : i64
  }
  func.func @digit_k_bounds(%arg0: i64, %arg1: i64, %arg2: i64, %arg3: !llvm.ptr, %arg4: !llvm.ptr) -> () {
    %404 = arith.constant 0 : i32
    %405 = arith.extsi %404 : i32 to i64
    %406 = llvm.mlir.constant(1 : i64) : i64
    %407 = llvm.alloca %406 x i64 : (i64) -> !llvm.ptr
    llvm.store %405, %407 : i64, !llvm.ptr
    %408 = llvm.mlir.constant(1 : i64) : i64
    %409 = llvm.alloca %408 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %409 : i64, !llvm.ptr
    cf.br ^bb84
    ^bb84:
    %410 = llvm.load %409 : !llvm.ptr -> i64
    %411 = arith.cmpi slt, %410, %arg1 : i64
    cf.cond_br %411, ^bb85, ^bb86
    ^bb85:
      %412 = llvm.load %409 : !llvm.ptr -> i64
      %413 = arith.constant 10 : i32
      %415 = arith.extsi %413 : i32 to i64
      %414 = arith.muli %412, %415 : i64
      llvm.store %414, %409 : i64, !llvm.ptr
      %416 = llvm.load %407 : !llvm.ptr -> i64
      %417 = arith.constant 1 : i32
      %419 = arith.extsi %417 : i32 to i64
      %418 = arith.addi %416, %419 : i64
      llvm.store %418, %407 : i64, !llvm.ptr
      cf.br ^bb84
    ^bb86:
    %420 = llvm.load %407 : !llvm.ptr -> i64
    %421 = arith.constant 1 : i32
    %423 = arith.extsi %421 : i32 to i64
    %422 = arith.addi %420, %423 : i64
    %424 = arith.constant 0 : i32
    %425 = arith.extsi %424 : i32 to i64
    %426 = llvm.getelementptr %arg3[%425] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %422, %426 : i64, !llvm.ptr
    %427 = arith.constant 1 : i32
    %429 = arith.extsi %427 : i32 to i64
    %428 = arith.addi %arg2, %429 : i64
    %430 = arith.muli %arg0, %428 : i64
    %431 = arith.constant 10 : i32
    %433 = arith.extsi %431 : i32 to i64
    %432 = arith.muli %433, %arg1 : i64
    %434 = arith.subi %430, %432 : i64
    %435 = arith.constant 0 : i32
    %437 = arith.extsi %435 : i32 to i64
    %436 = arith.cmpi sle, %434, %437 : i64
    cf.cond_br %436, ^bb87, ^bb88
    ^bb87:
      %438 = arith.constant 1 : i32
      %440 = arith.constant 0 : i32
      %439 = arith.subi %440, %438 : i32
      %441 = arith.constant 0 : i32
      %442 = arith.extsi %439 : i32 to i64
      %443 = arith.extsi %441 : i32 to i64
      %444 = llvm.getelementptr %arg4[%443] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %442, %444 : i64, !llvm.ptr
      func.return
    ^bb88:
      cf.br ^bb89
    ^bb89:
    %445 = arith.muli %arg1, %arg2 : i64
    %446 = arith.constant 1 : i32
    %448 = arith.extsi %446 : i32 to i64
    %447 = arith.subi %445, %448 : i64
    %449 = arith.divsi %447, %434 : i64
    %450 = arith.constant 0 : i32
    %452 = arith.extsi %450 : i32 to i64
    %451 = arith.cmpi sle, %449, %452 : i64
    cf.cond_br %451, ^bb90, ^bb91
    ^bb90:
      %453 = arith.constant 1 : i32
      %455 = arith.constant 0 : i32
      %454 = arith.subi %455, %453 : i32
      %456 = arith.constant 0 : i32
      %457 = arith.extsi %454 : i32 to i64
      %458 = arith.extsi %456 : i32 to i64
      %459 = llvm.getelementptr %arg3[%458] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %457, %459 : i64, !llvm.ptr
      %460 = arith.constant 1 : i32
      %462 = arith.constant 0 : i32
      %461 = arith.subi %462, %460 : i32
      %463 = arith.constant 0 : i32
      %464 = arith.extsi %461 : i32 to i64
      %465 = arith.extsi %463 : i32 to i64
      %466 = llvm.getelementptr %arg4[%465] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %464, %466 : i64, !llvm.ptr
      func.return
    ^bb91:
      cf.br ^bb92
    ^bb92:
    %467 = arith.constant 0 : i32
    %468 = arith.extsi %467 : i32 to i64
    %469 = llvm.mlir.constant(1 : i64) : i64
    %470 = llvm.alloca %469 x i64 : (i64) -> !llvm.ptr
    llvm.store %468, %470 : i64, !llvm.ptr
    %471 = arith.constant 1 : i32
    %472 = arith.extsi %471 : i32 to i64
    %473 = llvm.mlir.constant(1 : i64) : i64
    %474 = llvm.alloca %473 x i64 : (i64) -> !llvm.ptr
    llvm.store %472, %474 : i64, !llvm.ptr
    cf.br ^bb93
    ^bb93:
    %475 = llvm.load %474 : !llvm.ptr -> i64
    %476 = arith.constant 10 : i32
    %478 = arith.extsi %476 : i32 to i64
    %477 = arith.muli %475, %478 : i64
    %479 = arith.cmpi sle, %477, %449 : i64
    cf.cond_br %479, ^bb94, ^bb95
    ^bb94:
      %480 = llvm.load %474 : !llvm.ptr -> i64
      %481 = arith.constant 10 : i32
      %483 = arith.extsi %481 : i32 to i64
      %482 = arith.muli %480, %483 : i64
      llvm.store %482, %474 : i64, !llvm.ptr
      %484 = llvm.load %470 : !llvm.ptr -> i64
      %485 = arith.constant 1 : i32
      %487 = arith.extsi %485 : i32 to i64
      %486 = arith.addi %484, %487 : i64
      llvm.store %486, %470 : i64, !llvm.ptr
      cf.br ^bb93
    ^bb95:
    %488 = llvm.load %470 : !llvm.ptr -> i64
    %489 = arith.constant 1 : i32
    %491 = arith.extsi %489 : i32 to i64
    %490 = arith.addi %488, %491 : i64
    %492 = arith.constant 0 : i32
    %493 = arith.extsi %492 : i32 to i64
    %494 = llvm.getelementptr %arg4[%493] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %490, %494 : i64, !llvm.ptr
    func.return
  }
  func.func @find_N_params(%arg0: i64, %arg1: i64, %arg2: !llvm.ptr, %arg3: i64, %arg4: !llvm.ptr, %arg5: !llvm.ptr, %arg6: !llvm.ptr) -> i32 {
    %495 = arith.cmpi eq, %arg0, %arg1 : i64
    cf.cond_br %495, ^bb96, ^bb97
    ^bb96:
      %496 = arith.constant 1 : i32
      %497 = arith.constant 0 : i32
      %498 = arith.extsi %496 : i32 to i64
      %499 = arith.extsi %497 : i32 to i64
      %500 = llvm.getelementptr %arg4[%499] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %498, %500 : i64, !llvm.ptr
      %501 = arith.constant 1 : i32
      %502 = arith.constant 0 : i32
      %503 = arith.extsi %501 : i32 to i64
      %504 = arith.extsi %502 : i32 to i64
      %505 = llvm.getelementptr %arg5[%504] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %503, %505 : i64, !llvm.ptr
      %506 = arith.constant 9 : i32
      %508 = arith.extsi %506 : i32 to i64
      %507 = arith.muli %508, %arg1 : i64
      %509 = arith.constant 0 : i32
      %510 = arith.extsi %509 : i32 to i64
      %511 = llvm.getelementptr %arg6[%510] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %507, %511 : i64, !llvm.ptr
      %512 = arith.constant 1 : i32
      func.return %512 : i32
    ^bb97:
      cf.br ^bb98
    ^bb98:
    %513 = arith.constant 10 : i32
    %515 = arith.extsi %513 : i32 to i64
    %514 = arith.muli %515, %arg1 : i64
    %516 = arith.subi %514, %arg0 : i64
    %517 = arith.constant 0 : i32
    %519 = arith.extsi %517 : i32 to i64
    %518 = arith.cmpi sle, %516, %519 : i64
    cf.cond_br %518, ^bb99, ^bb100
    ^bb99:
      %520 = arith.constant 0 : i32
      func.return %520 : i32
    ^bb100:
      cf.br ^bb101
    ^bb101:
    %521 = arith.constant 0 : i32
    %522 = arith.extsi %521 : i32 to i64
    %523 = llvm.mlir.constant(1 : i64) : i64
    %524 = llvm.alloca %523 x i64 : (i64) -> !llvm.ptr
    llvm.store %522, %524 : i64, !llvm.ptr
    %525 = arith.constant 0 : i32
    %526 = arith.extsi %525 : i32 to i64
    %527 = llvm.mlir.constant(1 : i64) : i64
    %528 = llvm.alloca %527 x i64 : (i64) -> !llvm.ptr
    llvm.store %526, %528 : i64, !llvm.ptr
    %529 = arith.constant 0 : i32
    %530 = llvm.mlir.constant(1 : i64) : i64
    %531 = llvm.alloca %530 x i32 : (i64) -> !llvm.ptr
    llvm.store %529, %531 : i32, !llvm.ptr
    %533 = arith.constant 1 : i32
    %534 = arith.constant 8 : i32
    %535 = arith.extsi %533 : i32 to i64
    %536 = arith.extsi %534 : i32 to i64
    %532 = func.call @calloc(%535, %536) : (i64, i64) -> !llvm.ptr
    %538 = arith.constant 1 : i32
    %539 = arith.constant 8 : i32
    %540 = arith.extsi %538 : i32 to i64
    %541 = arith.extsi %539 : i32 to i64
    %537 = func.call @calloc(%540, %541) : (i64, i64) -> !llvm.ptr
    %542 = arith.constant 1 : i32
    %543 = arith.extsi %542 : i32 to i64
    %544 = llvm.mlir.constant(1 : i64) : i64
    %545 = llvm.alloca %544 x i64 : (i64) -> !llvm.ptr
    llvm.store %543, %545 : i64, !llvm.ptr
    cf.br ^bb102
    ^bb102:
    %546 = llvm.load %545 : !llvm.ptr -> i64
    %547 = arith.constant 9 : i32
    %549 = arith.extsi %547 : i32 to i64
    %548 = arith.cmpi sle, %546, %549 : i64
    cf.cond_br %548, ^bb103, ^bb104
    ^bb103:
      %551 = llvm.load %545 : !llvm.ptr -> i64
      func.call @digit_k_bounds(%arg0, %arg1, %551, %532, %537) : (i64, i64, i64, !llvm.ptr, !llvm.ptr) -> ()
      %553 = arith.constant 0 : i32
      %554 = arith.extsi %553 : i32 to i64
      %555 = llvm.getelementptr %532[%554] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %552 = llvm.load %555 : !llvm.ptr -> i64
      %556 = arith.constant 1 : i32
      %558 = arith.constant 0 : i32
      %557 = arith.subi %558, %556 : i32
      %560 = arith.extsi %557 : i32 to i64
      %559 = arith.cmpi ne, %552, %560 : i64
      cf.cond_br %559, ^bb105, ^bb106
      ^bb105:
        %562 = arith.constant 0 : i32
        %563 = arith.extsi %562 : i32 to i64
        %564 = llvm.getelementptr %532[%563] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %561 = llvm.load %564 : !llvm.ptr -> i64
        %565 = llvm.mlir.constant(1 : i64) : i64
        %566 = llvm.alloca %565 x i64 : (i64) -> !llvm.ptr
        llvm.store %561, %566 : i64, !llvm.ptr
        %567 = llvm.load %566 : !llvm.ptr -> i64
        %568 = arith.constant 2 : i32
        %570 = arith.extsi %568 : i32 to i64
        %569 = arith.cmpi slt, %567, %570 : i64
        cf.cond_br %569, ^bb108, ^bb109
        ^bb108:
          %571 = arith.constant 2 : i32
          %572 = arith.extsi %571 : i32 to i64
          llvm.store %572, %566 : i64, !llvm.ptr
          cf.br ^bb110
        ^bb109:
          cf.br ^bb110
        ^bb110:
        %574 = llvm.load %545 : !llvm.ptr -> i64
        %575 = arith.muli %574, %arg1 : i64
        %573 = func.call @gcd(%516, %575) : (i64, i64) -> i64
        %576 = arith.divsi %516, %573 : i64
        %577 = func.call @mult_order_10(%576, %arg2, %arg3) : (i64, !llvm.ptr, i64) -> i64
        %578 = arith.constant 0 : i32
        %580 = arith.extsi %578 : i32 to i64
        %579 = arith.cmpi ne, %577, %580 : i64
        cf.cond_br %579, ^bb111, ^bb112
        ^bb111:
          %581 = llvm.load %566 : !llvm.ptr -> i64
          %582 = arith.addi %581, %577 : i64
          %583 = arith.constant 1 : i32
          %585 = arith.extsi %583 : i32 to i64
          %584 = arith.subi %582, %585 : i64
          %586 = arith.divsi %584, %577 : i64
          %587 = arith.muli %586, %577 : i64
          %589 = arith.constant 0 : i32
          %590 = arith.extsi %589 : i32 to i64
          %591 = llvm.getelementptr %537[%590] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %588 = llvm.load %591 : !llvm.ptr -> i64
          %592 = arith.constant 1 : i32
          %594 = arith.constant 0 : i32
          %593 = arith.subi %594, %592 : i32
          %596 = arith.extsi %593 : i32 to i64
          %595 = arith.cmpi ne, %588, %596 : i64
          %597 = scf.if %595 -> (i1) {
            %599 = arith.constant 0 : i32
            %600 = arith.extsi %599 : i32 to i64
            %601 = llvm.getelementptr %537[%600] : (!llvm.ptr, i64) -> !llvm.ptr, i64
            %598 = llvm.load %601 : !llvm.ptr -> i64
            %602 = arith.cmpi sgt, %587, %598 : i64
            scf.yield %602 : i1
          } else {
            %603 = arith.constant false
            scf.yield %603 : i1
          }
          %605 = arith.constant 1 : i1
          %604 = arith.xori %597, %605 : i1
          cf.cond_br %604, ^bb114, ^bb115
          ^bb114:
            %607 = llvm.load %531 : !llvm.ptr -> i32
            %608 = arith.constant 0 : i32
            %609 = arith.cmpi eq, %607, %608 : i32
            %610 = scf.if %609 -> (i1) {
              %611 = arith.constant true
              scf.yield %611 : i1
            } else {
              %612 = llvm.load %524 : !llvm.ptr -> i64
              %613 = arith.cmpi slt, %587, %612 : i64
              scf.yield %613 : i1
            }
            %614 = scf.if %610 -> (i1) {
              %615 = arith.constant true
              scf.yield %615 : i1
            } else {
              %616 = llvm.load %524 : !llvm.ptr -> i64
              %617 = arith.cmpi eq, %587, %616 : i64
              %618 = scf.if %617 -> (i1) {
                %619 = llvm.load %545 : !llvm.ptr -> i64
                %620 = llvm.load %528 : !llvm.ptr -> i64
                %621 = arith.cmpi slt, %619, %620 : i64
                scf.yield %621 : i1
              } else {
                %622 = arith.constant false
                scf.yield %622 : i1
              }
              scf.yield %618 : i1
            }
            cf.cond_br %614, ^bb117, ^bb118
            ^bb117:
              llvm.store %587, %524 : i64, !llvm.ptr
              %623 = llvm.load %545 : !llvm.ptr -> i64
              llvm.store %623, %528 : i64, !llvm.ptr
              %624 = arith.constant 1 : i32
              llvm.store %624, %531 : i32, !llvm.ptr
              cf.br ^bb119
            ^bb118:
              cf.br ^bb119
            ^bb119:
            cf.br ^bb116
          ^bb115:
            cf.br ^bb116
          ^bb116:
          cf.br ^bb113
        ^bb112:
          cf.br ^bb113
        ^bb113:
        cf.br ^bb107
      ^bb106:
        cf.br ^bb107
      ^bb107:
      %625 = llvm.load %545 : !llvm.ptr -> i64
      %626 = arith.constant 1 : i32
      %628 = arith.extsi %626 : i32 to i64
      %627 = arith.addi %625, %628 : i64
      llvm.store %627, %545 : i64, !llvm.ptr
      cf.br ^bb102
    ^bb104:
    func.call @free(%532) : (!llvm.ptr) -> ()
    func.call @free(%537) : (!llvm.ptr) -> ()
    %631 = llvm.load %531 : !llvm.ptr -> i32
    %632 = arith.constant 0 : i32
    %633 = arith.cmpi eq, %631, %632 : i32
    cf.cond_br %633, ^bb120, ^bb121
    ^bb120:
      %634 = arith.constant 0 : i32
      func.return %634 : i32
    ^bb121:
      cf.br ^bb122
    ^bb122:
    %635 = llvm.load %524 : !llvm.ptr -> i64
    %636 = arith.constant 0 : i32
    %637 = arith.extsi %636 : i32 to i64
    %638 = llvm.getelementptr %arg4[%637] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %635, %638 : i64, !llvm.ptr
    %639 = llvm.load %528 : !llvm.ptr -> i64
    %640 = arith.constant 0 : i32
    %641 = arith.extsi %640 : i32 to i64
    %642 = llvm.getelementptr %arg5[%641] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %639, %642 : i64, !llvm.ptr
    %643 = arith.constant 0 : i32
    %644 = arith.extsi %643 : i32 to i64
    %645 = llvm.getelementptr %arg6[%644] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %516, %645 : i64, !llvm.ptr
    %646 = arith.constant 1 : i32
    func.return %646 : i32
  }
  func.func @N_mod(%arg0: i64, %arg1: i64, %arg2: !llvm.ptr, %arg3: i64) -> i64 {
    %647 = func.call @gcd(%arg0, %arg1) : (i64, i64) -> i64
    %648 = arith.divsi %arg0, %647 : i64
    %649 = arith.divsi %arg1, %647 : i64
    %650 = arith.cmpi eq, %648, %649 : i64
    cf.cond_br %650, ^bb123, ^bb124
    ^bb123:
      %651 = arith.constant 1 : i32
      %652 = llvm.mlir.addressof @MOD : !llvm.ptr
      %653 = llvm.load %652 : !llvm.ptr -> i64
      %655 = arith.extsi %651 : i32 to i64
      %654 = arith.remsi %655, %653 : i64
      func.return %654 : i64
    ^bb124:
      cf.br ^bb125
    ^bb125:
    %657 = arith.constant 1 : i32
    %658 = arith.constant 8 : i32
    %659 = arith.extsi %657 : i32 to i64
    %660 = arith.extsi %658 : i32 to i64
    %656 = func.call @calloc(%659, %660) : (i64, i64) -> !llvm.ptr
    %662 = arith.constant 1 : i32
    %663 = arith.constant 8 : i32
    %664 = arith.extsi %662 : i32 to i64
    %665 = arith.extsi %663 : i32 to i64
    %661 = func.call @calloc(%664, %665) : (i64, i64) -> !llvm.ptr
    %667 = arith.constant 1 : i32
    %668 = arith.constant 8 : i32
    %669 = arith.extsi %667 : i32 to i64
    %670 = arith.extsi %668 : i32 to i64
    %666 = func.call @calloc(%669, %670) : (i64, i64) -> !llvm.ptr
    %671 = func.call @find_N_params(%648, %649, %arg2, %arg3, %656, %661, %666) : (i64, i64, !llvm.ptr, i64, !llvm.ptr, !llvm.ptr, !llvm.ptr) -> i32
    %672 = arith.constant 0 : i32
    %673 = arith.cmpi eq, %671, %672 : i32
    cf.cond_br %673, ^bb126, ^bb127
    ^bb126:
      func.call @free(%656) : (!llvm.ptr) -> ()
      func.call @free(%661) : (!llvm.ptr) -> ()
      func.call @free(%666) : (!llvm.ptr) -> ()
      %677 = arith.constant 0 : i32
      %678 = arith.extsi %677 : i32 to i64
      func.return %678 : i64
    ^bb127:
      cf.br ^bb128
    ^bb128:
    %680 = arith.constant 0 : i32
    %681 = arith.extsi %680 : i32 to i64
    %682 = llvm.getelementptr %656[%681] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %679 = llvm.load %682 : !llvm.ptr -> i64
    %684 = arith.constant 0 : i32
    %685 = arith.extsi %684 : i32 to i64
    %686 = llvm.getelementptr %661[%685] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %683 = llvm.load %686 : !llvm.ptr -> i64
    %688 = arith.constant 0 : i32
    %689 = arith.extsi %688 : i32 to i64
    %690 = llvm.getelementptr %666[%689] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %687 = llvm.load %690 : !llvm.ptr -> i64
    func.call @free(%656) : (!llvm.ptr) -> ()
    func.call @free(%661) : (!llvm.ptr) -> ()
    func.call @free(%666) : (!llvm.ptr) -> ()
    %695 = llvm.mlir.addressof @MOD : !llvm.ptr
    %696 = llvm.load %695 : !llvm.ptr -> i64
    %697 = arith.remsi %687, %696 : i64
    %694 = func.call @mod_inv(%697) : (i64) -> i64
    %699 = arith.constant 10 : i32
    %700 = llvm.mlir.addressof @MOD : !llvm.ptr
    %701 = llvm.load %700 : !llvm.ptr -> i64
    %702 = arith.extsi %699 : i32 to i64
    %698 = func.call @mod_pow(%702, %679, %701) : (i64, i64, i64) -> i64
    %703 = arith.constant 1 : i32
    %705 = arith.extsi %703 : i32 to i64
    %704 = arith.subi %698, %705 : i64
    %706 = llvm.mlir.addressof @MOD : !llvm.ptr
    %707 = llvm.load %706 : !llvm.ptr -> i64
    %708 = arith.addi %704, %707 : i64
    %709 = llvm.mlir.addressof @MOD : !llvm.ptr
    %710 = llvm.load %709 : !llvm.ptr -> i64
    %711 = arith.remsi %708, %710 : i64
    %712 = llvm.mlir.addressof @MOD : !llvm.ptr
    %713 = llvm.load %712 : !llvm.ptr -> i64
    %714 = arith.remsi %683, %713 : i64
    %715 = llvm.mlir.addressof @MOD : !llvm.ptr
    %716 = llvm.load %715 : !llvm.ptr -> i64
    %717 = arith.remsi %649, %716 : i64
    %718 = arith.muli %714, %717 : i64
    %719 = llvm.mlir.addressof @MOD : !llvm.ptr
    %720 = llvm.load %719 : !llvm.ptr -> i64
    %721 = arith.remsi %718, %720 : i64
    %722 = llvm.mlir.constant(1 : i64) : i64
    %723 = llvm.alloca %722 x i64 : (i64) -> !llvm.ptr
    llvm.store %721, %723 : i64, !llvm.ptr
    %724 = llvm.load %723 : !llvm.ptr -> i64
    %725 = arith.muli %724, %711 : i64
    %726 = llvm.mlir.addressof @MOD : !llvm.ptr
    %727 = llvm.load %726 : !llvm.ptr -> i64
    %728 = arith.remsi %725, %727 : i64
    llvm.store %728, %723 : i64, !llvm.ptr
    %729 = llvm.load %723 : !llvm.ptr -> i64
    %730 = arith.muli %729, %694 : i64
    %731 = llvm.mlir.addressof @MOD : !llvm.ptr
    %732 = llvm.load %731 : !llvm.ptr -> i64
    %733 = arith.remsi %730, %732 : i64
    llvm.store %733, %723 : i64, !llvm.ptr
    %734 = llvm.load %723 : !llvm.ptr -> i64
    func.return %734 : i64
  }
  func.func @main() -> i32 {
    %736 = arith.constant 2000 : i32
    %737 = arith.constant 8 : i32
    %738 = arith.extsi %736 : i32 to i64
    %739 = arith.extsi %737 : i32 to i64
    %735 = func.call @calloc(%738, %739) : (i64, i64) -> !llvm.ptr
    %740 = func.call @init_primes(%735) : (!llvm.ptr) -> i64
    %741 = arith.constant 0 : i32
    %742 = arith.extsi %741 : i32 to i64
    %743 = llvm.mlir.constant(1 : i64) : i64
    %744 = llvm.alloca %743 x i64 : (i64) -> !llvm.ptr
    llvm.store %742, %744 : i64, !llvm.ptr
    %745 = arith.constant 1 : i32
    %746 = arith.extsi %745 : i32 to i64
    %747 = llvm.mlir.constant(1 : i64) : i64
    %748 = llvm.alloca %747 x i64 : (i64) -> !llvm.ptr
    llvm.store %746, %748 : i64, !llvm.ptr
    cf.br ^bb129
    ^bb129:
    %749 = llvm.load %748 : !llvm.ptr -> i64
    %750 = llvm.mlir.addressof @M : !llvm.ptr
    %751 = llvm.load %750 : !llvm.ptr -> i64
    %752 = arith.cmpi sle, %749, %751 : i64
    cf.cond_br %752, ^bb130, ^bb131
    ^bb130:
      %753 = llvm.load %748 : !llvm.ptr -> i64
      %754 = llvm.load %748 : !llvm.ptr -> i64
      %755 = arith.muli %753, %754 : i64
      %756 = llvm.load %748 : !llvm.ptr -> i64
      %757 = arith.muli %755, %756 : i64
      %758 = arith.constant 1 : i32
      %759 = arith.extsi %758 : i32 to i64
      %760 = llvm.mlir.constant(1 : i64) : i64
      %761 = llvm.alloca %760 x i64 : (i64) -> !llvm.ptr
      llvm.store %759, %761 : i64, !llvm.ptr
      cf.br ^bb132
      ^bb132:
      %762 = llvm.load %761 : !llvm.ptr -> i64
      %763 = llvm.mlir.addressof @M : !llvm.ptr
      %764 = llvm.load %763 : !llvm.ptr -> i64
      %765 = arith.cmpi sle, %762, %764 : i64
      cf.cond_br %765, ^bb133, ^bb134
      ^bb133:
        %767 = llvm.load %748 : !llvm.ptr -> i64
        %768 = llvm.load %761 : !llvm.ptr -> i64
        %766 = func.call @gcd(%767, %768) : (i64, i64) -> i64
        %769 = arith.constant 1 : i32
        %771 = arith.extsi %769 : i32 to i64
        %770 = arith.cmpi eq, %766, %771 : i64
        cf.cond_br %770, ^bb135, ^bb136
        ^bb135:
          %772 = llvm.load %761 : !llvm.ptr -> i64
          %773 = llvm.load %761 : !llvm.ptr -> i64
          %774 = arith.muli %772, %773 : i64
          %775 = llvm.load %761 : !llvm.ptr -> i64
          %776 = arith.muli %774, %775 : i64
          %777 = llvm.load %744 : !llvm.ptr -> i64
          %778 = func.call @N_mod(%757, %776, %735, %740) : (i64, i64, !llvm.ptr, i64) -> i64
          %779 = arith.addi %777, %778 : i64
          %780 = llvm.mlir.addressof @MOD : !llvm.ptr
          %781 = llvm.load %780 : !llvm.ptr -> i64
          %782 = arith.remsi %779, %781 : i64
          llvm.store %782, %744 : i64, !llvm.ptr
          cf.br ^bb137
        ^bb136:
          cf.br ^bb137
        ^bb137:
        %783 = llvm.load %761 : !llvm.ptr -> i64
        %784 = arith.constant 1 : i32
        %786 = arith.extsi %784 : i32 to i64
        %785 = arith.addi %783, %786 : i64
        llvm.store %785, %761 : i64, !llvm.ptr
        cf.br ^bb132
      ^bb134:
      %787 = llvm.load %748 : !llvm.ptr -> i64
      %788 = arith.constant 1 : i32
      %790 = arith.extsi %788 : i32 to i64
      %789 = arith.addi %787, %790 : i64
      llvm.store %789, %748 : i64, !llvm.ptr
      cf.br ^bb129
    ^bb131:
    func.call @free(%735) : (!llvm.ptr) -> ()
    %792 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %793 = llvm.load %744 : !llvm.ptr -> i64
    %794 = llvm.call @printf(%792, %793) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    %795 = arith.constant 0 : i32
    func.return %795 : i32
  }
}