Problem 969

Sum S(n) for n=1..10^18 via Lagrange interpolation. Ported from native C to pure Flow.

Answer412543690
Output412543690
StatusPASS
Native helperno
Runtime0 ms
Peak memory1088 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 969
# Sum S(n) for n=1..10^18 via Lagrange interpolation.
# Ported from native C to pure Flow.

import euler.nt { mod_pow }

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

const MOD: i64 = 1000000007

let mut primes: ptr<i32> = null
let mut num_primes: i32 = 0

function sieve(n: i32) -> void {
    num_primes = 0
    let is_composite: ptr<i8> = calloc((n + 1) as i64, 1) as ptr<i8>
    let mut i: i32 = 2
    while i <= n {
        if is_composite[i] == 0 {
            num_primes = num_primes + 1
            let mut j: i32 = i * i
            while j <= n {
                is_composite[j] = 1
                j = j + i
            }
        }
        i = i + 1
    }
    primes = calloc(num_primes as i64, 4) as ptr<i32>
    let mut k: i32 = 0
    i = 2
    while i <= n {
        if is_composite[i] == 0 {
            primes[k] = i
            k = k + 1
        }
        i = i + 1
    }
    free(is_composite as ptr<void>)
}

function modinv(x: i64) -> i64 {
    return mod_pow(x % MOD, MOD - 2, MOD)
}

# sum_{t=1}^T t^k mod MOD using Lagrange interpolation
function sum_pows_lagrange(T: i64, k: i32) -> i64 {
    let d: i32 = k + 1
    if T <= (d as i64) {
        let mut s: i64 = 0
        let mut i: i64 = 1
        while i <= T {
            s = (s + mod_pow(i, k as i64, MOD)) % MOD
            i = i + 1
        }
        return s
    }

    # y_i = sum_{t=1}^i t^k for i=0..d
    let ys: ptr<i64> = calloc(60, 8) as ptr<i64>
    ys[0] = 0
    let mut i2: i32 = 1
    while i2 <= d {
        ys[i2] = (ys[i2 - 1] + mod_pow(i2 as i64, k as i64, MOD)) % MOD
        i2 = i2 + 1
    }

    let fact: ptr<i64> = calloc(60, 8) as ptr<i64>
    fact[0] = 1
    let mut i3: i32 = 1
    while i3 <= d {
        fact[i3] = fact[i3 - 1] * (i3 as i64) % MOD
        i3 = i3 + 1
    }

    let invfact: ptr<i64> = calloc(60, 8) as ptr<i64>
    invfact[d] = modinv(fact[d])
    let mut i4: i32 = d
    while i4 >= 1 {
        invfact[i4 - 1] = invfact[i4] * (i4 as i64) % MOD
        i4 = i4 - 1
    }

    let Tmod: i64 = T % MOD

    # pre[i] = prod_{j=0..i-1} (T - j)
    let pre: ptr<i64> = calloc(60, 8) as ptr<i64>
    pre[0] = 1
    let mut i5: i32 = 1
    while i5 <= d {
        let val: i64 = (Tmod - ((i5 - 1) as i64)) % MOD
        pre[i5] = pre[i5 - 1] * val % MOD
        if pre[i5] < 0 { pre[i5] = pre[i5] + MOD }
        i5 = i5 + 1
    }

    # suf[i] = prod_{j=i..d} (T - j)
    let suf: ptr<i64> = calloc(62, 8) as ptr<i64>
    suf[d + 1] = 1
    let mut i6: i32 = d
    while i6 >= 0 {
        let val: i64 = (Tmod - (i6 as i64)) % MOD
        suf[i6] = suf[i6 + 1] * val % MOD
        if suf[i6] < 0 { suf[i6] = suf[i6] + MOD }
        i6 = i6 - 1
    }

    let mut res: i64 = 0
    let mut i7: i32 = 0
    while i7 <= d {
        let num: i64 = pre[i7] * suf[i7 + 1] % MOD
        let mut denom: i64 = fact[i7] * fact[d - i7] % MOD
        if ((d - i7) & 1) != 0 {
            denom = (MOD - denom) % MOD
        }
        let invden: i64 = modinv(denom)
        let li: i64 = num * invden % MOD
        res = (res + ys[i7] * li) % MOD
        i7 = i7 + 1
    }

    free(ys as ptr<void>)
    free(fact as ptr<void>)
    free(invfact as ptr<void>)
    free(pre as ptr<void>)
    free(suf as ptr<void>)
    return res
}

# Compute M_k = prod_{p <= k} p^{ceil(v_p(k!)/k)}
function compute_Mk(k: i32) -> i128 {
    if k == 0 { return 1 }
    let mut M: i128 = 1
    let mut pi: i32 = 0
    while pi < num_primes {
        let p: i32 = primes[pi]
        if p > k { break }
        let mut v: i32 = 0
        let mut pp: i128 = p as i128
        while pp <= (k as i128) {
            v = v + (k as i32) / (pp as i32)
            pp = pp * (p as i128)
        }
        let e: i32 = (v + k - 1) / k
        if e > 0 {
            let mut pe: i128 = 1
            let mut i: i32 = 0
            while i < e {
                pe = pe * (p as i128)
                i = i + 1
            }
            M = M * pe
        }
        pi = pi + 1
    }
    return M
}

function compute_sum_S_upto_N(N: i64) -> i64 {
    let mut total: i64 = 0

    # Precompute factorials mod MOD up to 200
    let MAXF: i32 = 200
    let fact: ptr<i64> = calloc(201, 8) as ptr<i64>
    fact[0] = 1
    let mut i: i32 = 1
    while i <= MAXF {
        fact[i] = fact[i - 1] * (i as i64) % MOD
        i = i + 1
    }

    let mut k: i32 = 0
    while true {
        let M: i128 = compute_Mk(k)
        if M > (N as i128) { break }

        let T: i64
        if k == 0 {
            T = N
        } else {
            if N < (k as i64) { break }
            T = (N - (k as i64)) / (M as i64)
            if T <= 0 {
                k = k + 1
                continue
            }
        }

        # C_k = (-1)^k * M^k / k! mod MOD
        let C: i64
        if k == 0 {
            C = 1
        } else {
            C = mod_pow((M % (MOD as i128)) as i64, k as i64, MOD) * modinv(fact[k]) % MOD
            if (k & 1) != 0 {
                C = (MOD - C) % MOD
            }
        }

        let sum_tk: i64 = sum_pows_lagrange(T, k)
        let contrib: i64 = C * sum_tk % MOD
        total = (total + contrib) % MOD

        k = k + 1
    }

    free(fact as ptr<void>)
    return total
}

function main() -> i32 {
    sieve(1000)
    let result: i64 = compute_sum_S_upto_N(1000000000000000000)
    printf("%lld\n", result)
    free(primes as ptr<void>)
    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);
void sieve_i32(int32_t n);
int64_t modinv_i64(int64_t x);
int64_t sum_pows_lagrange_i64_i32(int64_t T, int32_t k);
__int128 compute_Mk_i32(int32_t k);
int64_t compute_sum_S_upto_N_i64(int64_t N);
int32_t main(void);

static const int64_t MOD = 1000000007;

/* Module statics */
static int32_t* primes = NULL;
static int32_t num_primes = 0;

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;
}




void sieve_i32(int32_t n) {
    num_primes = 0;
    int8_t* is_composite = (int8_t*)(((int8_t*)(calloc(((int64_t)((n + 1))), 1))));
    int32_t i = 2;
    while (i <= n) {
        if (is_composite[i] == 0) {
            num_primes = (num_primes + 1);
            int32_t j = (i * i);
            while (j <= n) {
                is_composite[j] = 1;
                j = (j + i);
            }
        }
        i = (i + 1);
    }
    primes = ((int32_t*)(calloc(((int64_t)(num_primes)), 4)));
    int32_t k = 0;
    i = 2;
    while (i <= n) {
        if (is_composite[i] == 0) {
            primes[k] = i;
            k = (k + 1);
        }
        i = (i + 1);
    }
    free(((void*)(is_composite)));
}

int64_t modinv_i64(int64_t x) {
    return mod_pow_i64_i64_i64(FLOW_CHECKED_MOD((x), (MOD)), (MOD - 2), MOD);
}

int64_t sum_pows_lagrange_i64_i32(int64_t T, int32_t k) {
    int32_t d = (k + 1);
    if (T <= ((int64_t)(d))) {
        int64_t s = 0;
        int64_t i = 1;
        while (i <= T) {
            s = FLOW_CHECKED_MOD(((s + mod_pow_i64_i64_i64(i, ((int64_t)(k)), MOD))), (MOD));
            i = (i + 1);
        }
        return s;
    }
    int64_t* ys = (int64_t*)(((int64_t*)(calloc(60, 8))));
    ys[0] = 0;
    int32_t i2 = 1;
    while (i2 <= d) {
        ys[i2] = FLOW_CHECKED_MOD(((ys[(i2 - 1)] + mod_pow_i64_i64_i64(((int64_t)(i2)), ((int64_t)(k)), MOD))), (MOD));
        i2 = (i2 + 1);
    }
    int64_t* fact = (int64_t*)(((int64_t*)(calloc(60, 8))));
    fact[0] = 1;
    int32_t i3 = 1;
    while (i3 <= d) {
        fact[i3] = FLOW_CHECKED_MOD(((fact[(i3 - 1)] * ((int64_t)(i3)))), (MOD));
        i3 = (i3 + 1);
    }
    int64_t* invfact = (int64_t*)(((int64_t*)(calloc(60, 8))));
    invfact[d] = modinv_i64(fact[d]);
    int32_t i4 = d;
    while (i4 >= 1) {
        invfact[(i4 - 1)] = FLOW_CHECKED_MOD(((invfact[i4] * ((int64_t)(i4)))), (MOD));
        i4 = (i4 - 1);
    }
    int64_t Tmod = FLOW_CHECKED_MOD((T), (MOD));
    int64_t* pre = (int64_t*)(((int64_t*)(calloc(60, 8))));
    pre[0] = 1;
    int32_t i5 = 1;
    while (i5 <= d) {
        int64_t val = FLOW_CHECKED_MOD(((Tmod - ((int64_t)((i5 - 1))))), (MOD));
        pre[i5] = FLOW_CHECKED_MOD(((pre[(i5 - 1)] * val)), (MOD));
        if (pre[i5] < 0) {
            pre[i5] = (pre[i5] + MOD);
        }
        i5 = (i5 + 1);
    }
    int64_t* suf = (int64_t*)(((int64_t*)(calloc(62, 8))));
    suf[(d + 1)] = 1;
    int32_t i6 = d;
    while (i6 >= 0) {
        int64_t val = FLOW_CHECKED_MOD(((Tmod - ((int64_t)(i6)))), (MOD));
        suf[i6] = FLOW_CHECKED_MOD(((suf[(i6 + 1)] * val)), (MOD));
        if (suf[i6] < 0) {
            suf[i6] = (suf[i6] + MOD);
        }
        i6 = (i6 - 1);
    }
    int64_t res = 0;
    int32_t i7 = 0;
    while (i7 <= d) {
        int64_t num = FLOW_CHECKED_MOD(((pre[i7] * suf[(i7 + 1)])), (MOD));
        int64_t denom = FLOW_CHECKED_MOD(((fact[i7] * fact[(d - i7)])), (MOD));
        if (((d - i7) & 1) != 0) {
            denom = FLOW_CHECKED_MOD(((MOD - denom)), (MOD));
        }
        int64_t invden = modinv_i64(denom);
        int64_t li = FLOW_CHECKED_MOD(((num * invden)), (MOD));
        res = FLOW_CHECKED_MOD(((res + (ys[i7] * li))), (MOD));
        i7 = (i7 + 1);
    }
    free(((void*)(ys)));
    free(((void*)(fact)));
    free(((void*)(invfact)));
    free(((void*)(pre)));
    free(((void*)(suf)));
    return res;
}

__int128 compute_Mk_i32(int32_t k) {
    if (k == 0) {
        return 1;
    }
    __int128 M = 1;
    int32_t pi = 0;
    while (pi < num_primes) {
        int32_t p = primes[pi];
        if (p > k) {
            break;
        }
        int32_t v = 0;
        __int128 pp = ((__int128)(p));
        while (pp <= ((__int128)(k))) {
            v = (v + FLOW_CHECKED_DIV((((int32_t)(k))), (((int32_t)(pp)))));
            pp = (pp * ((__int128)(p)));
        }
        int32_t e = FLOW_CHECKED_DIV((((v + k) - 1)), (k));
        if (e > 0) {
            __int128 pe = 1;
            int32_t i = 0;
            while (i < e) {
                pe = (pe * ((__int128)(p)));
                i = (i + 1);
            }
            M = (M * pe);
        }
        pi = (pi + 1);
    }
    return M;
}

int64_t compute_sum_S_upto_N_i64(int64_t N) {
    int64_t total = 0;
    int32_t MAXF = 200;
    int64_t* fact = (int64_t*)(((int64_t*)(calloc(201, 8))));
    fact[0] = 1;
    int32_t i = 1;
    while (i <= MAXF) {
        fact[i] = FLOW_CHECKED_MOD(((fact[(i - 1)] * ((int64_t)(i)))), (MOD));
        i = (i + 1);
    }
    int32_t k = 0;
    while (1) {
        __int128 M = compute_Mk_i32(k);
        if (M > ((__int128)(N))) {
            break;
        }
        int64_t T;
        if (k == 0) {
            T = N;
        } else {
            if (N < ((int64_t)(k))) {
                break;
            }
            T = FLOW_CHECKED_DIV(((N - ((int64_t)(k)))), (((int64_t)(M))));
            if (T <= 0) {
                k = (k + 1);
                continue;
            }
        }
        int64_t C;
        if (k == 0) {
            C = 1;
        } else {
            C = FLOW_CHECKED_MOD(((mod_pow_i64_i64_i64(((int64_t)(FLOW_CHECKED_MOD((M), (((__int128)(MOD)))))), ((int64_t)(k)), MOD) * modinv_i64(fact[k]))), (MOD));
            if ((k & 1) != 0) {
                C = FLOW_CHECKED_MOD(((MOD - C)), (MOD));
            }
        }
        int64_t sum_tk = sum_pows_lagrange_i64_i32(T, k);
        int64_t contrib = FLOW_CHECKED_MOD(((C * sum_tk)), (MOD));
        total = FLOW_CHECKED_MOD(((total + contrib)), (MOD));
        k = (k + 1);
    }
    free(((void*)(fact)));
    return total;
}

int32_t main(void) {
    sieve_i32(1000);
    int64_t result = compute_sum_S_upto_N_i64(1000000000000000000);
    printf("%lld\n", result);
    free(((void*)(primes)));
    return 0;
}

Generated MLIR

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