Problem 606

S(N) = sum of k <= N with g(k)=252, where g(k)=252 iff k=(p*q)^3, p<q prime. For N=10^36, M=cbrt(N)=10^12. Compute S mod 10^9.

Answer158452775
Output158452775
StatusPASS
Native helperno
Runtime1570 ms
Peak memory34016 KB
Time complexityO(n^2) (estimated)
Space complexityO(n^2) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^2)O(n log n)
Space complexityO(n^2)O(n)
ApproachFlow solutionModular DP or matrix exponentiation
VerdictSuboptimal

Flow source

# Project Euler 606: Gozinta Chains II
# S(N) = sum of k <= N with g(k)=252, where g(k)=252 iff k=(p*q)^3, p<q prime.
# For N=10^36, M=cbrt(N)=10^12. Compute S mod 10^9.

import euler.nt { isqrt }

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

const MOD: i64 = 1000000000

function icbrt(n: i64) -> i64 {
    if n < 2 { return n }
    let mut hi: i64 = 1
    let mut bits: i64 = 0
    let mut tmp: i64 = n
    while tmp > 0 { bits = bits + 1; tmp = tmp >> 1 }
    hi = 1 << ((bits + 2) / 3)
    let mut lo: i64 = hi >> 1
    while lo + 1 < hi {
        let mid: i64 = (lo + hi) >> 1
        let m3: i64 = mid * mid * mid
        if m3 <= n { lo = mid } else { hi = mid }
    }
    return lo
}

# Compute (v*(v+1)/2)^2 mod MOD, handling overflow
function sum_cubes_mod(v: i64) -> i64 {
    let a: i64
    let b: i64
    if v % 2 == 0 {
        a = v / 2
        b = v + 1
    } else {
        a = v
        b = (v + 1) / 2
    }
    let t: i64 = (a % MOD) * (b % MOD) % MOD
    return (t * t - 1) % MOD
}

function main() -> i32 {
    let M: i64 = 1000000000000  # 10^12 = cbrt(10^36)
    let r: i64 = isqrt(M)  # 10^6

    # Sieve primes up to r
    let bs: ptr<i8> = calloc(r + 1, 1)
    for i in 0..(r + 1) { bs[i] = 1 }
    bs[0] = 0
    bs[1] = 0
    let mut p: i64 = 2
    while p * p <= r {
        if bs[p] == 1 {
            let mut j: i64 = p * p
            while j <= r {
                bs[j] = 0
                j = j + p
            }
        }
        p = p + 1
    }

    # Collect primes
    let mut nprimes: i64 = 0
    for i in 0..(r + 1) {
        if bs[i] == 1 { nprimes = nprimes + 1 }
    }
    let primes: ptr<i64> = calloc(nprimes, 8)
    let mut idx: i64 = 0
    for i in 0..(r + 1) {
        if bs[i] == 1 {
            primes[idx] = i
            idx = idx + 1
        }
    }

    # Lucy sieve for prime cube sums
    # Key values: V = [M/1, M/2, ..., M/r, r-1, r-2, ..., 1]
    let big_len: i64 = r
    let small_len: i64 = r - 1
    let L: i64 = big_len + small_len  # total key values

    let V: ptr<i64> = calloc(L, 8)
    let S: ptr<i64> = calloc(L, 8)

    # Fill V: big block first (decreasing), then small block
    for i in 0..big_len {
        V[i] = M / (i + 1)
    }
    let mut vi: i64 = big_len
    let mut v: i64 = r - 1
    while v >= 1 {
        V[vi] = v
        vi = vi + 1
        v = v - 1
    }

    # Initialize S[i] = sum_{k=2..V[i]} k^3 mod MOD
    for i in 0..L {
        S[i] = sum_cubes_mod(V[i])
    }

    # Index helper: for small x <= r, index is L - x
    # For big value M/d (d <= r), index is d - 1

    # Sieve
    for pi in 0..nprimes {
        let p: i64 = primes[pi]
        let p2: i64 = p * p
        if p2 > M { break }
        let p3: i64 = (p * p % MOD) * p % MOD

        # sp = sum of prime^3 <= p-1
        let sp: i64
        if p == 2 {
            sp = 0
        } else {
            sp = S[L - (p - 1)]
        }

        # Update big block: indices i=0..min(n//p2, r)-1
        let mut blen: i64 = M / p2
        if blen > r { blen = r }

        for i in 0..blen {
            let vv: i64 = V[i]
            let denom_u: i64 = (i + 1) * p
            let Su: i64
            if denom_u <= r {
                Su = S[denom_u - 1]
            } else {
                let u: i64 = vv / p
                Su = S[L - u]
            }
            let diff: i64 = (Su - sp) % MOD
            S[i] = (S[i] - p3 * diff) % MOD
        }

        # Update small tail: values from p^2 to r-1
        let slen: i64 = r - p2
        if slen > 0 {
            let start: i64 = r  # first tail index in V
            let end: i64 = r + slen
            for j in start..end {
                let vv: i64 = V[j]
                let u: i64 = vv / p
                let Su: i64 = S[L - u]
                let diff: i64 = (Su - sp) % MOD
                S[j] = (S[j] - p3 * diff) % MOD
            }
        }
    }

    # Compute total
    let mut total: i64 = 0
    for pi in 0..nprimes {
        let p: i64 = primes[pi]
        if M / p <= p { break }
        # sum of q^3 for primes q with p < q <= M/p
        let sum_up_to_qmax: i64 = S[p - 1]
        let sum_up_to_p: i64 = S[L - p]
        let sum_q: i64 = (sum_up_to_qmax - sum_up_to_p) % MOD
        let p3: i64 = (p * p % MOD) * p % MOD
        total = (total + p3 * sum_q) % MOD
    }

    # Ensure positive
    total = total % MOD
    if total < 0 { total = total + MOD }

    printf("%lld\n", total)

    free(S)
    free(V)
    free(primes)
    free(bs)
    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 icbrt_i64(int64_t n);
int64_t sum_cubes_mod_i64(int64_t v);
int32_t main(void);

static const int64_t MOD = 1000000000;

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 icbrt_i64(int64_t n) {
    if (n < 2) {
        return n;
    }
    int64_t hi = 1;
    int64_t bits = 0;
    int64_t tmp = n;
    while (tmp > 0) {
        bits = (bits + 1);
        tmp = FLOW_CHECKED_SHR((tmp), (1));
    }
    hi = FLOW_CHECKED_SHL((1), (FLOW_CHECKED_DIV(((bits + 2)), (3))));
    int64_t lo = FLOW_CHECKED_SHR((hi), (1));
    while ((lo + 1) < hi) {
        int64_t mid = FLOW_CHECKED_SHR(((lo + hi)), (1));
        int64_t m3 = ((mid * mid) * mid);
        if (m3 <= n) {
            lo = mid;
        } else {
            hi = mid;
        }
    }
    return lo;
}

int64_t sum_cubes_mod_i64(int64_t v) {
    int64_t a;
    int64_t b;
    if (FLOW_CHECKED_MOD((v), (2)) == 0) {
        a = FLOW_CHECKED_DIV((v), (2));
        b = (v + 1);
    } else {
        a = v;
        b = FLOW_CHECKED_DIV(((v + 1)), (2));
    }
    int64_t t = FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD((a), (MOD)) * FLOW_CHECKED_MOD((b), (MOD)))), (MOD));
    return FLOW_CHECKED_MOD((((t * t) - 1)), (MOD));
}

int32_t main(void) {
    int64_t M = 1000000000000;
    int64_t r = isqrt_i64(M);
    int8_t* bs = (int8_t*)(calloc((r + 1), 1));
    int32_t __flow_step_1 = 1;
    for (int32_t i = 0; (0 <= (r + 1)) ? i < (r + 1) : i > (r + 1); i += (0 <= (r + 1)) ? 1 : -1) {
        bs[i] = 1;
    }
    bs[0] = 0;
    bs[1] = 0;
    int64_t p = 2;
    while ((p * p) <= r) {
        if (bs[p] == 1) {
            int64_t j = (p * p);
            while (j <= r) {
                bs[j] = 0;
                j = (j + p);
            }
        }
        p = (p + 1);
    }
    int64_t nprimes = 0;
    int32_t __flow_step_2 = 1;
    for (int32_t i = 0; (0 <= (r + 1)) ? i < (r + 1) : i > (r + 1); i += (0 <= (r + 1)) ? 1 : -1) {
        if (bs[i] == 1) {
            nprimes = (nprimes + 1);
        }
    }
    int64_t* primes = (int64_t*)(calloc(nprimes, 8));
    int64_t idx = 0;
    int32_t __flow_step_3 = 1;
    for (int32_t i = 0; (0 <= (r + 1)) ? i < (r + 1) : i > (r + 1); i += (0 <= (r + 1)) ? 1 : -1) {
        if (bs[i] == 1) {
            primes[idx] = i;
            idx = (idx + 1);
        }
    }
    int64_t big_len = r;
    int64_t small_len = (r - 1);
    int64_t L = (big_len + small_len);
    int64_t* V = (int64_t*)(calloc(L, 8));
    int64_t* S = (int64_t*)(calloc(L, 8));
    int32_t __flow_step_4 = 1;
    for (int32_t i = 0; (0 <= big_len) ? i < big_len : i > big_len; i += (0 <= big_len) ? 1 : -1) {
        V[i] = FLOW_CHECKED_DIV((M), ((i + 1)));
    }
    int64_t vi = big_len;
    int64_t v = (r - 1);
    while (v >= 1) {
        V[vi] = v;
        vi = (vi + 1);
        v = (v - 1);
    }
    int32_t __flow_step_5 = 1;
    for (int32_t i = 0; (0 <= L) ? i < L : i > L; i += (0 <= L) ? 1 : -1) {
        S[i] = sum_cubes_mod_i64(V[i]);
    }
    int32_t __flow_step_6 = 1;
    for (int32_t pi = 0; (0 <= nprimes) ? pi < nprimes : pi > nprimes; pi += (0 <= nprimes) ? 1 : -1) {
        int64_t p = primes[pi];
        int64_t p2 = (p * p);
        if (p2 > M) {
            break;
        }
        int64_t p3 = FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD(((p * p)), (MOD)) * p)), (MOD));
        int64_t sp;
        if (p == 2) {
            sp = 0;
        } else {
            sp = S[(L - (p - 1))];
        }
        int64_t blen = FLOW_CHECKED_DIV((M), (p2));
        if (blen > r) {
            blen = r;
        }
        int32_t __flow_step_7 = 1;
        for (int32_t i = 0; (0 <= blen) ? i < blen : i > blen; i += (0 <= blen) ? 1 : -1) {
            int64_t vv = V[i];
            int64_t denom_u = ((i + 1) * p);
            int64_t Su;
            if (denom_u <= r) {
                Su = S[(denom_u - 1)];
            } else {
                int64_t u = FLOW_CHECKED_DIV((vv), (p));
                Su = S[(L - u)];
            }
            int64_t diff = FLOW_CHECKED_MOD(((Su - sp)), (MOD));
            S[i] = FLOW_CHECKED_MOD(((S[i] - (p3 * diff))), (MOD));
        }
        int64_t slen = (r - p2);
        if (slen > 0) {
            int64_t start = r;
            int64_t end = (r + slen);
            int32_t __flow_step_8 = 1;
            for (int32_t j = start; (start <= end) ? j < end : j > end; j += (start <= end) ? 1 : -1) {
                int64_t vv = V[j];
                int64_t u = FLOW_CHECKED_DIV((vv), (p));
                int64_t Su = S[(L - u)];
                int64_t diff = FLOW_CHECKED_MOD(((Su - sp)), (MOD));
                S[j] = FLOW_CHECKED_MOD(((S[j] - (p3 * diff))), (MOD));
            }
        }
    }
    int64_t total = 0;
    int32_t __flow_step_9 = 1;
    for (int32_t pi = 0; (0 <= nprimes) ? pi < nprimes : pi > nprimes; pi += (0 <= nprimes) ? 1 : -1) {
        int64_t p = primes[pi];
        if (FLOW_CHECKED_DIV((M), (p)) <= p) {
            break;
        }
        int64_t sum_up_to_qmax = S[(p - 1)];
        int64_t sum_up_to_p = S[(L - p)];
        int64_t sum_q = FLOW_CHECKED_MOD(((sum_up_to_qmax - sum_up_to_p)), (MOD));
        int64_t p3 = FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD(((p * p)), (MOD)) * p)), (MOD));
        total = FLOW_CHECKED_MOD(((total + (p3 * sum_q))), (MOD));
    }
    total = FLOW_CHECKED_MOD((total), (MOD));
    if (total < 0) {
        total = (total + MOD);
    }
    printf("%lld\n", total);
    free(S);
    free(V);
    free(primes);
    free(bs);
    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(1000000000 : i64) : i64
  func.func @icbrt(%arg0: i64) -> i64 {
    %175 = arith.constant 2 : i32
    %177 = arith.extsi %175 : i32 to i64
    %176 = arith.cmpi slt, %arg0, %177 : i64
    cf.cond_br %176, ^bb42, ^bb43
    ^bb42:
      func.return %arg0 : i64
    ^bb43:
      cf.br ^bb44
    ^bb44:
    %178 = arith.constant 1 : i32
    %179 = arith.extsi %178 : i32 to i64
    %180 = llvm.mlir.constant(1 : i64) : i64
    %181 = llvm.alloca %180 x i64 : (i64) -> !llvm.ptr
    llvm.store %179, %181 : i64, !llvm.ptr
    %182 = arith.constant 0 : i32
    %183 = arith.extsi %182 : i32 to i64
    %184 = llvm.mlir.constant(1 : i64) : i64
    %185 = llvm.alloca %184 x i64 : (i64) -> !llvm.ptr
    llvm.store %183, %185 : i64, !llvm.ptr
    %186 = llvm.mlir.constant(1 : i64) : i64
    %187 = llvm.alloca %186 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %187 : i64, !llvm.ptr
    cf.br ^bb45
    ^bb45:
    %188 = llvm.load %187 : !llvm.ptr -> i64
    %189 = arith.constant 0 : i32
    %191 = arith.extsi %189 : i32 to i64
    %190 = arith.cmpi sgt, %188, %191 : i64
    cf.cond_br %190, ^bb46, ^bb47
    ^bb46:
      %192 = llvm.load %185 : !llvm.ptr -> i64
      %193 = arith.constant 1 : i32
      %195 = arith.extsi %193 : i32 to i64
      %194 = arith.addi %192, %195 : i64
      llvm.store %194, %185 : i64, !llvm.ptr
      %196 = llvm.load %187 : !llvm.ptr -> i64
      %197 = arith.constant 1 : i32
      %199 = arith.extsi %197 : i32 to i64
      %198 = arith.shrsi %196, %199 : i64
      llvm.store %198, %187 : i64, !llvm.ptr
      cf.br ^bb45
    ^bb47:
    %200 = arith.constant 1 : i32
    %201 = llvm.load %185 : !llvm.ptr -> i64
    %202 = arith.constant 2 : i32
    %204 = arith.extsi %202 : i32 to i64
    %203 = arith.addi %201, %204 : i64
    %205 = arith.constant 3 : i32
    %207 = arith.extsi %205 : i32 to i64
    %206 = arith.divsi %203, %207 : i64
    %209 = arith.extsi %200 : i32 to i64
    %208 = arith.shli %209, %206 : i64
    llvm.store %208, %181 : i64, !llvm.ptr
    %210 = llvm.load %181 : !llvm.ptr -> i64
    %211 = arith.constant 1 : i32
    %213 = arith.extsi %211 : i32 to i64
    %212 = arith.shrsi %210, %213 : i64
    %214 = llvm.mlir.constant(1 : i64) : i64
    %215 = llvm.alloca %214 x i64 : (i64) -> !llvm.ptr
    llvm.store %212, %215 : i64, !llvm.ptr
    cf.br ^bb48
    ^bb48:
    %216 = llvm.load %215 : !llvm.ptr -> i64
    %217 = arith.constant 1 : i32
    %219 = arith.extsi %217 : i32 to i64
    %218 = arith.addi %216, %219 : i64
    %220 = llvm.load %181 : !llvm.ptr -> i64
    %221 = arith.cmpi slt, %218, %220 : i64
    cf.cond_br %221, ^bb49, ^bb50
    ^bb49:
      %222 = llvm.load %215 : !llvm.ptr -> i64
      %223 = llvm.load %181 : !llvm.ptr -> i64
      %224 = arith.addi %222, %223 : i64
      %225 = arith.constant 1 : i32
      %227 = arith.extsi %225 : i32 to i64
      %226 = arith.shrsi %224, %227 : i64
      %228 = arith.muli %226, %226 : i64
      %229 = arith.muli %228, %226 : i64
      %230 = arith.cmpi sle, %229, %arg0 : i64
      cf.cond_br %230, ^bb51, ^bb52
      ^bb51:
        llvm.store %226, %215 : i64, !llvm.ptr
        cf.br ^bb53
      ^bb52:
        llvm.store %226, %181 : i64, !llvm.ptr
        cf.br ^bb53
      ^bb53:
      cf.br ^bb48
    ^bb50:
    %231 = llvm.load %215 : !llvm.ptr -> i64
    func.return %231 : i64
  }
  func.func @sum_cubes_mod(%arg0: i64) -> i64 {
    %232 = llvm.mlir.undef : i64
    %233 = llvm.mlir.undef : i64
    %234 = arith.constant 2 : i32
    %236 = arith.extsi %234 : i32 to i64
    %235 = arith.remsi %arg0, %236 : i64
    %237 = arith.constant 0 : i32
    %239 = arith.extsi %237 : i32 to i64
    %238 = arith.cmpi eq, %235, %239 : i64
    %240, %241 = scf.if %238 -> (i64, i64) {
      %242 = arith.constant 2 : i32
      %244 = arith.extsi %242 : i32 to i64
      %243 = arith.divsi %arg0, %244 : i64
      %245 = arith.constant 1 : i32
      %247 = arith.extsi %245 : i32 to i64
      %246 = arith.addi %arg0, %247 : i64
      scf.yield %243, %246 : i64, i64
    } else {
      %248 = arith.constant 1 : i32
      %250 = arith.extsi %248 : i32 to i64
      %249 = arith.addi %arg0, %250 : i64
      %251 = arith.constant 2 : i32
      %253 = arith.extsi %251 : i32 to i64
      %252 = arith.divsi %249, %253 : i64
      scf.yield %arg0, %252 : i64, i64
    }
    %254 = llvm.mlir.addressof @MOD : !llvm.ptr
    %255 = llvm.load %254 : !llvm.ptr -> i64
    %256 = arith.remsi %240, %255 : i64
    %257 = llvm.mlir.addressof @MOD : !llvm.ptr
    %258 = llvm.load %257 : !llvm.ptr -> i64
    %259 = arith.remsi %241, %258 : i64
    %260 = arith.muli %256, %259 : i64
    %261 = llvm.mlir.addressof @MOD : !llvm.ptr
    %262 = llvm.load %261 : !llvm.ptr -> i64
    %263 = arith.remsi %260, %262 : i64
    %264 = arith.muli %263, %263 : i64
    %265 = arith.constant 1 : i32
    %267 = arith.extsi %265 : i32 to i64
    %266 = arith.subi %264, %267 : i64
    %268 = llvm.mlir.addressof @MOD : !llvm.ptr
    %269 = llvm.load %268 : !llvm.ptr -> i64
    %270 = arith.remsi %266, %269 : i64
    func.return %270 : i64
  }
  func.func @main() -> i32 {
    %271 = arith.constant 995705032704 : i32
    %272 = arith.extsi %271 : i32 to i64
    %273 = func.call @isqrt(%272) : (i64) -> i64
    %275 = arith.constant 1 : i32
    %277 = arith.extsi %275 : i32 to i64
    %276 = arith.addi %273, %277 : i64
    %278 = arith.constant 1 : i32
    %279 = arith.extsi %278 : i32 to i64
    %274 = func.call @calloc(%276, %279) : (i64, i64) -> !llvm.ptr
    %280 = arith.constant 0 : i32
    %281 = arith.constant 1 : i32
    %283 = arith.extsi %281 : i32 to i64
    %282 = arith.addi %273, %283 : i64
    %284 = arith.index_cast %280 : i32 to index
    %285 = arith.index_cast %282 : i32 to index
    %287 = arith.constant 1 : index
    %288 = arith.constant -1 : index
    %289 = arith.cmpi sle, %284, %285 : index
    %286 = arith.select %289, %287, %288 : index
    cf.br ^bb54(%284 : index)
    ^bb54(%290: index):
    %291 = arith.cmpi slt, %290, %285 : index
    %292 = arith.cmpi sgt, %290, %285 : index
    %293 = arith.select %289, %291, %292 : i1
    cf.cond_br %293, ^bb55(%290 : index), ^bb56(%290 : index)
    ^bb55(%294: index):
      %295 = arith.constant 1 : i32
      %296 = arith.trunci %295 : i32 to i8
      %297 = arith.index_cast %294 : index to i64
      %298 = llvm.getelementptr %274[%297] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      llvm.store %296, %298 : i8, !llvm.ptr
      %299 = arith.addi %294, %286 : index
      cf.br ^bb54(%299 : index)
    ^bb56(%300: index):
    %301 = arith.constant 0 : i32
    %302 = arith.constant 0 : i32
    %303 = arith.trunci %301 : i32 to i8
    %304 = arith.extsi %302 : i32 to i64
    %305 = llvm.getelementptr %274[%304] : (!llvm.ptr, i64) -> !llvm.ptr, i8
    llvm.store %303, %305 : i8, !llvm.ptr
    %306 = arith.constant 0 : i32
    %307 = arith.constant 1 : i32
    %308 = arith.trunci %306 : i32 to i8
    %309 = arith.extsi %307 : i32 to i64
    %310 = llvm.getelementptr %274[%309] : (!llvm.ptr, i64) -> !llvm.ptr, i8
    llvm.store %308, %310 : i8, !llvm.ptr
    %311 = arith.constant 2 : i32
    %312 = arith.extsi %311 : i32 to i64
    %313 = llvm.mlir.constant(1 : i64) : i64
    %314 = llvm.alloca %313 x i64 : (i64) -> !llvm.ptr
    llvm.store %312, %314 : i64, !llvm.ptr
    cf.br ^bb57
    ^bb57:
    %315 = llvm.load %314 : !llvm.ptr -> i64
    %316 = llvm.load %314 : !llvm.ptr -> i64
    %317 = arith.muli %315, %316 : i64
    %318 = arith.cmpi sle, %317, %273 : i64
    cf.cond_br %318, ^bb58, ^bb59
    ^bb58:
      %320 = llvm.load %314 : !llvm.ptr -> i64
      %321 = llvm.getelementptr %274[%320] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %319 = llvm.load %321 : !llvm.ptr -> i8
      %322 = arith.constant 1 : i32
      %324 = arith.extsi %319 : i8 to i32
      %323 = arith.cmpi eq, %324, %322 : i32
      cf.cond_br %323, ^bb60, ^bb61
      ^bb60:
        %325 = llvm.load %314 : !llvm.ptr -> i64
        %326 = llvm.load %314 : !llvm.ptr -> i64
        %327 = arith.muli %325, %326 : i64
        %328 = llvm.mlir.constant(1 : i64) : i64
        %329 = llvm.alloca %328 x i64 : (i64) -> !llvm.ptr
        llvm.store %327, %329 : i64, !llvm.ptr
        cf.br ^bb63
        ^bb63:
        %330 = llvm.load %329 : !llvm.ptr -> i64
        %331 = arith.cmpi sle, %330, %273 : i64
        cf.cond_br %331, ^bb64, ^bb65
        ^bb64:
          %332 = arith.constant 0 : i32
          %333 = llvm.load %329 : !llvm.ptr -> i64
          %334 = arith.trunci %332 : i32 to i8
          %335 = llvm.getelementptr %274[%333] : (!llvm.ptr, i64) -> !llvm.ptr, i8
          llvm.store %334, %335 : i8, !llvm.ptr
          %336 = llvm.load %329 : !llvm.ptr -> i64
          %337 = llvm.load %314 : !llvm.ptr -> i64
          %338 = arith.addi %336, %337 : i64
          llvm.store %338, %329 : i64, !llvm.ptr
          cf.br ^bb63
        ^bb65:
        cf.br ^bb62
      ^bb61:
        cf.br ^bb62
      ^bb62:
      %339 = llvm.load %314 : !llvm.ptr -> i64
      %340 = arith.constant 1 : i32
      %342 = arith.extsi %340 : i32 to i64
      %341 = arith.addi %339, %342 : i64
      llvm.store %341, %314 : i64, !llvm.ptr
      cf.br ^bb57
    ^bb59:
    %343 = arith.constant 0 : i32
    %344 = arith.extsi %343 : i32 to i64
    %345 = llvm.mlir.constant(1 : i64) : i64
    %346 = llvm.alloca %345 x i64 : (i64) -> !llvm.ptr
    llvm.store %344, %346 : i64, !llvm.ptr
    %347 = arith.constant 0 : i32
    %348 = arith.constant 1 : i32
    %350 = arith.extsi %348 : i32 to i64
    %349 = arith.addi %273, %350 : i64
    %351 = arith.index_cast %347 : i32 to index
    %352 = arith.index_cast %349 : i32 to index
    %354 = arith.constant 1 : index
    %355 = arith.constant -1 : index
    %356 = arith.cmpi sle, %351, %352 : index
    %353 = arith.select %356, %354, %355 : index
    cf.br ^bb66(%351 : index)
    ^bb66(%357: index):
    %358 = arith.cmpi slt, %357, %352 : index
    %359 = arith.cmpi sgt, %357, %352 : index
    %360 = arith.select %356, %358, %359 : i1
    cf.cond_br %360, ^bb67(%357 : index), ^bb68(%357 : index)
    ^bb67(%361: index):
      %363 = arith.index_cast %361 : index to i64
      %364 = llvm.getelementptr %274[%363] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %362 = llvm.load %364 : !llvm.ptr -> i8
      %365 = arith.constant 1 : i32
      %367 = arith.extsi %362 : i8 to i32
      %366 = arith.cmpi eq, %367, %365 : i32
      cf.cond_br %366, ^bb69, ^bb70
      ^bb69:
        %368 = llvm.load %346 : !llvm.ptr -> i64
        %369 = arith.constant 1 : i32
        %371 = arith.extsi %369 : i32 to i64
        %370 = arith.addi %368, %371 : i64
        llvm.store %370, %346 : i64, !llvm.ptr
        cf.br ^bb71
      ^bb70:
        cf.br ^bb71
      ^bb71:
      %372 = arith.addi %361, %353 : index
      cf.br ^bb66(%372 : index)
    ^bb68(%373: index):
    %375 = llvm.load %346 : !llvm.ptr -> i64
    %376 = arith.constant 8 : i32
    %377 = arith.extsi %376 : i32 to i64
    %374 = func.call @calloc(%375, %377) : (i64, i64) -> !llvm.ptr
    %378 = arith.constant 0 : i32
    %379 = arith.extsi %378 : i32 to i64
    %380 = llvm.mlir.constant(1 : i64) : i64
    %381 = llvm.alloca %380 x i64 : (i64) -> !llvm.ptr
    llvm.store %379, %381 : i64, !llvm.ptr
    %382 = arith.constant 0 : i32
    %383 = arith.constant 1 : i32
    %385 = arith.extsi %383 : i32 to i64
    %384 = arith.addi %273, %385 : i64
    %386 = arith.index_cast %382 : i32 to index
    %387 = arith.index_cast %384 : i32 to index
    %389 = arith.constant 1 : index
    %390 = arith.constant -1 : index
    %391 = arith.cmpi sle, %386, %387 : index
    %388 = arith.select %391, %389, %390 : index
    cf.br ^bb72(%386 : index)
    ^bb72(%392: index):
    %393 = arith.cmpi slt, %392, %387 : index
    %394 = arith.cmpi sgt, %392, %387 : index
    %395 = arith.select %391, %393, %394 : i1
    cf.cond_br %395, ^bb73(%392 : index), ^bb74(%392 : index)
    ^bb73(%396: index):
      %398 = arith.index_cast %396 : index to i64
      %399 = llvm.getelementptr %274[%398] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %397 = llvm.load %399 : !llvm.ptr -> i8
      %400 = arith.constant 1 : i32
      %402 = arith.extsi %397 : i8 to i32
      %401 = arith.cmpi eq, %402, %400 : i32
      cf.cond_br %401, ^bb75, ^bb76
      ^bb75:
        %403 = llvm.load %381 : !llvm.ptr -> i64
        %404 = arith.index_cast %396 : index to i64
        %405 = llvm.getelementptr %374[%403] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %404, %405 : i64, !llvm.ptr
        %406 = llvm.load %381 : !llvm.ptr -> i64
        %407 = arith.constant 1 : i32
        %409 = arith.extsi %407 : i32 to i64
        %408 = arith.addi %406, %409 : i64
        llvm.store %408, %381 : i64, !llvm.ptr
        cf.br ^bb77
      ^bb76:
        cf.br ^bb77
      ^bb77:
      %410 = arith.addi %396, %388 : index
      cf.br ^bb72(%410 : index)
    ^bb74(%411: index):
    %412 = arith.constant 1 : i32
    %414 = arith.extsi %412 : i32 to i64
    %413 = arith.subi %273, %414 : i64
    %415 = arith.addi %273, %413 : i64
    %417 = arith.constant 8 : i32
    %418 = arith.extsi %417 : i32 to i64
    %416 = func.call @calloc(%415, %418) : (i64, i64) -> !llvm.ptr
    %420 = arith.constant 8 : i32
    %421 = arith.extsi %420 : i32 to i64
    %419 = func.call @calloc(%415, %421) : (i64, i64) -> !llvm.ptr
    %422 = arith.constant 0 : i32
    %423 = arith.index_cast %422 : i32 to index
    %424 = arith.index_cast %273 : i32 to index
    %426 = arith.constant 1 : index
    %427 = arith.constant -1 : index
    %428 = arith.cmpi sle, %423, %424 : index
    %425 = arith.select %428, %426, %427 : index
    cf.br ^bb78(%423 : index)
    ^bb78(%429: index):
    %430 = arith.cmpi slt, %429, %424 : index
    %431 = arith.cmpi sgt, %429, %424 : index
    %432 = arith.select %428, %430, %431 : i1
    cf.cond_br %432, ^bb79(%429 : index), ^bb80(%429 : index)
    ^bb79(%433: index):
      %434 = arith.constant 1 : i32
      %436 = arith.index_cast %433 : index to i32
      %435 = arith.addi %436, %434 : i32
      %438 = arith.extsi %435 : i32 to i64
      %437 = arith.divsi %272, %438 : i64
      %439 = arith.index_cast %433 : index to i64
      %440 = llvm.getelementptr %416[%439] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %437, %440 : i64, !llvm.ptr
      %441 = arith.addi %433, %425 : index
      cf.br ^bb78(%441 : index)
    ^bb80(%442: index):
    %443 = llvm.mlir.constant(1 : i64) : i64
    %444 = llvm.alloca %443 x i64 : (i64) -> !llvm.ptr
    llvm.store %273, %444 : i64, !llvm.ptr
    %445 = arith.constant 1 : i32
    %447 = arith.extsi %445 : i32 to i64
    %446 = arith.subi %273, %447 : i64
    %448 = llvm.mlir.constant(1 : i64) : i64
    %449 = llvm.alloca %448 x i64 : (i64) -> !llvm.ptr
    llvm.store %446, %449 : i64, !llvm.ptr
    cf.br ^bb81
    ^bb81:
    %450 = llvm.load %449 : !llvm.ptr -> i64
    %451 = arith.constant 1 : i32
    %453 = arith.extsi %451 : i32 to i64
    %452 = arith.cmpi sge, %450, %453 : i64
    cf.cond_br %452, ^bb82, ^bb83
    ^bb82:
      %454 = llvm.load %449 : !llvm.ptr -> i64
      %455 = llvm.load %444 : !llvm.ptr -> i64
      %456 = llvm.getelementptr %416[%455] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %454, %456 : i64, !llvm.ptr
      %457 = llvm.load %444 : !llvm.ptr -> i64
      %458 = arith.constant 1 : i32
      %460 = arith.extsi %458 : i32 to i64
      %459 = arith.addi %457, %460 : i64
      llvm.store %459, %444 : i64, !llvm.ptr
      %461 = llvm.load %449 : !llvm.ptr -> i64
      %462 = arith.constant 1 : i32
      %464 = arith.extsi %462 : i32 to i64
      %463 = arith.subi %461, %464 : i64
      llvm.store %463, %449 : i64, !llvm.ptr
      cf.br ^bb81
    ^bb83:
    %465 = arith.constant 0 : i32
    %466 = arith.index_cast %465 : i32 to index
    %467 = arith.index_cast %415 : i32 to index
    %469 = arith.constant 1 : index
    %470 = arith.constant -1 : index
    %471 = arith.cmpi sle, %466, %467 : index
    %468 = arith.select %471, %469, %470 : index
    cf.br ^bb84(%466 : index)
    ^bb84(%472: index):
    %473 = arith.cmpi slt, %472, %467 : index
    %474 = arith.cmpi sgt, %472, %467 : index
    %475 = arith.select %471, %473, %474 : i1
    cf.cond_br %475, ^bb85(%472 : index), ^bb86(%472 : index)
    ^bb85(%476: index):
      %479 = arith.index_cast %476 : index to i64
      %480 = llvm.getelementptr %416[%479] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %478 = llvm.load %480 : !llvm.ptr -> i64
      %477 = func.call @sum_cubes_mod(%478) : (i64) -> i64
      %481 = arith.index_cast %476 : index to i64
      %482 = llvm.getelementptr %419[%481] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %477, %482 : i64, !llvm.ptr
      %483 = arith.addi %476, %468 : index
      cf.br ^bb84(%483 : index)
    ^bb86(%484: index):
    %485 = arith.constant 0 : i32
    %486 = llvm.load %346 : !llvm.ptr -> i64
    %487 = arith.index_cast %485 : i32 to index
    %488 = arith.index_cast %486 : i32 to index
    %490 = arith.constant 1 : index
    %491 = arith.constant -1 : index
    %492 = arith.cmpi sle, %487, %488 : index
    %489 = arith.select %492, %490, %491 : index
    cf.br ^bb87(%487 : index)
    ^bb87(%493: index):
    %494 = arith.cmpi slt, %493, %488 : index
    %495 = arith.cmpi sgt, %493, %488 : index
    %496 = arith.select %492, %494, %495 : i1
    cf.cond_br %496, ^bb88(%493 : index), ^bb89(%493 : index)
    ^bb88(%497: index):
      %499 = arith.index_cast %497 : index to i64
      %500 = llvm.getelementptr %374[%499] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %498 = llvm.load %500 : !llvm.ptr -> i64
      %501 = arith.muli %498, %498 : i64
      %502 = arith.cmpi sgt, %501, %272 : i64
      cf.cond_br %502, ^bb90, ^bb91
      ^bb90:
        cf.br ^bb89(%497 : index)
      ^bb91:
        cf.br ^bb92
      ^bb92:
      %503 = arith.muli %498, %498 : i64
      %504 = llvm.mlir.addressof @MOD : !llvm.ptr
      %505 = llvm.load %504 : !llvm.ptr -> i64
      %506 = arith.remsi %503, %505 : i64
      %507 = arith.muli %506, %498 : i64
      %508 = llvm.mlir.addressof @MOD : !llvm.ptr
      %509 = llvm.load %508 : !llvm.ptr -> i64
      %510 = arith.remsi %507, %509 : i64
      %511 = llvm.mlir.undef : i64
      %512 = arith.constant 2 : i32
      %514 = arith.extsi %512 : i32 to i64
      %513 = arith.cmpi eq, %498, %514 : i64
      %515 = scf.if %513 -> (i64) {
        %516 = arith.constant 0 : i32
        %517 = arith.extsi %516 : i32 to i64
        scf.yield %517 : i64
      } else {
        %519 = arith.constant 1 : i32
        %521 = arith.extsi %519 : i32 to i64
        %520 = arith.subi %498, %521 : i64
        %522 = arith.subi %415, %520 : i64
        %523 = llvm.getelementptr %419[%522] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %518 = llvm.load %523 : !llvm.ptr -> i64
        scf.yield %518 : i64
      }
      %524 = arith.divsi %272, %501 : i64
      %525 = llvm.mlir.constant(1 : i64) : i64
      %526 = llvm.alloca %525 x i64 : (i64) -> !llvm.ptr
      llvm.store %524, %526 : i64, !llvm.ptr
      %527 = llvm.load %526 : !llvm.ptr -> i64
      %528 = arith.cmpi sgt, %527, %273 : i64
      cf.cond_br %528, ^bb93, ^bb94
      ^bb93:
        llvm.store %273, %526 : i64, !llvm.ptr
        cf.br ^bb95
      ^bb94:
        cf.br ^bb95
      ^bb95:
      %529 = arith.constant 0 : i32
      %530 = llvm.load %526 : !llvm.ptr -> i64
      %531 = arith.index_cast %529 : i32 to index
      %532 = arith.index_cast %530 : i32 to index
      %534 = arith.constant 1 : index
      %535 = arith.constant -1 : index
      %536 = arith.cmpi sle, %531, %532 : index
      %533 = arith.select %536, %534, %535 : index
      cf.br ^bb96(%531 : index)
      ^bb96(%537: index):
      %538 = arith.cmpi slt, %537, %532 : index
      %539 = arith.cmpi sgt, %537, %532 : index
      %540 = arith.select %536, %538, %539 : i1
      cf.cond_br %540, ^bb97(%537 : index), ^bb98(%537 : index)
      ^bb97(%541: index):
        %543 = arith.index_cast %541 : index to i64
        %544 = llvm.getelementptr %416[%543] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %542 = llvm.load %544 : !llvm.ptr -> i64
        %545 = arith.constant 1 : i32
        %547 = arith.index_cast %541 : index to i32
        %546 = arith.addi %547, %545 : i32
        %549 = arith.extsi %546 : i32 to i64
        %548 = arith.muli %549, %498 : i64
        %550 = llvm.mlir.undef : i64
        %551 = arith.cmpi sle, %548, %273 : i64
        %552 = scf.if %551 -> (i64) {
          %554 = arith.constant 1 : i32
          %556 = arith.extsi %554 : i32 to i64
          %555 = arith.subi %548, %556 : i64
          %557 = llvm.getelementptr %419[%555] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %553 = llvm.load %557 : !llvm.ptr -> i64
          scf.yield %553 : i64
        } else {
          %558 = arith.divsi %542, %498 : i64
          %560 = arith.subi %415, %558 : i64
          %561 = llvm.getelementptr %419[%560] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %559 = llvm.load %561 : !llvm.ptr -> i64
          scf.yield %559 : i64
        }
        %562 = arith.subi %552, %515 : i64
        %563 = llvm.mlir.addressof @MOD : !llvm.ptr
        %564 = llvm.load %563 : !llvm.ptr -> i64
        %565 = arith.remsi %562, %564 : i64
        %567 = arith.index_cast %541 : index to i64
        %568 = llvm.getelementptr %419[%567] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %566 = llvm.load %568 : !llvm.ptr -> i64
        %569 = arith.muli %510, %565 : i64
        %570 = arith.subi %566, %569 : i64
        %571 = llvm.mlir.addressof @MOD : !llvm.ptr
        %572 = llvm.load %571 : !llvm.ptr -> i64
        %573 = arith.remsi %570, %572 : i64
        %574 = arith.index_cast %541 : index to i64
        %575 = llvm.getelementptr %419[%574] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %573, %575 : i64, !llvm.ptr
        %576 = arith.addi %541, %533 : index
        cf.br ^bb96(%576 : index)
      ^bb98(%577: index):
      %578 = arith.subi %273, %501 : i64
      %579 = arith.constant 0 : i32
      %581 = arith.extsi %579 : i32 to i64
      %580 = arith.cmpi sgt, %578, %581 : i64
      cf.cond_br %580, ^bb99, ^bb100
      ^bb99:
        %582 = arith.addi %273, %578 : i64
        %583 = arith.index_cast %273 : i32 to index
        %584 = arith.index_cast %582 : i32 to index
        %586 = arith.constant 1 : index
        %587 = arith.constant -1 : index
        %588 = arith.cmpi sle, %583, %584 : index
        %585 = arith.select %588, %586, %587 : index
        cf.br ^bb102(%583 : index)
        ^bb102(%589: index):
        %590 = arith.cmpi slt, %589, %584 : index
        %591 = arith.cmpi sgt, %589, %584 : index
        %592 = arith.select %588, %590, %591 : i1
        cf.cond_br %592, ^bb103(%589 : index), ^bb104(%589 : index)
        ^bb103(%593: index):
          %595 = arith.index_cast %593 : index to i64
          %596 = llvm.getelementptr %416[%595] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %594 = llvm.load %596 : !llvm.ptr -> i64
          %597 = arith.divsi %594, %498 : i64
          %599 = arith.subi %415, %597 : i64
          %600 = llvm.getelementptr %419[%599] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %598 = llvm.load %600 : !llvm.ptr -> i64
          %601 = arith.subi %598, %515 : i64
          %602 = llvm.mlir.addressof @MOD : !llvm.ptr
          %603 = llvm.load %602 : !llvm.ptr -> i64
          %604 = arith.remsi %601, %603 : i64
          %606 = arith.index_cast %593 : index to i64
          %607 = llvm.getelementptr %419[%606] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %605 = llvm.load %607 : !llvm.ptr -> i64
          %608 = arith.muli %510, %604 : i64
          %609 = arith.subi %605, %608 : i64
          %610 = llvm.mlir.addressof @MOD : !llvm.ptr
          %611 = llvm.load %610 : !llvm.ptr -> i64
          %612 = arith.remsi %609, %611 : i64
          %613 = arith.index_cast %593 : index to i64
          %614 = llvm.getelementptr %419[%613] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          llvm.store %612, %614 : i64, !llvm.ptr
          %615 = arith.addi %593, %585 : index
          cf.br ^bb102(%615 : index)
        ^bb104(%616: index):
        cf.br ^bb101
      ^bb100:
        cf.br ^bb101
      ^bb101:
      %617 = arith.addi %497, %489 : index
      cf.br ^bb87(%617 : index)
    ^bb89(%618: index):
    %619 = arith.constant 0 : i32
    %620 = arith.extsi %619 : i32 to i64
    %621 = llvm.mlir.constant(1 : i64) : i64
    %622 = llvm.alloca %621 x i64 : (i64) -> !llvm.ptr
    llvm.store %620, %622 : i64, !llvm.ptr
    %623 = arith.constant 0 : i32
    %624 = llvm.load %346 : !llvm.ptr -> i64
    %625 = arith.index_cast %623 : i32 to index
    %626 = arith.index_cast %624 : i32 to index
    %628 = arith.constant 1 : index
    %629 = arith.constant -1 : index
    %630 = arith.cmpi sle, %625, %626 : index
    %627 = arith.select %630, %628, %629 : index
    cf.br ^bb105(%625 : index)
    ^bb105(%631: index):
    %632 = arith.cmpi slt, %631, %626 : index
    %633 = arith.cmpi sgt, %631, %626 : index
    %634 = arith.select %630, %632, %633 : i1
    cf.cond_br %634, ^bb106(%631 : index), ^bb107(%631 : index)
    ^bb106(%635: index):
      %637 = arith.index_cast %635 : index to i64
      %638 = llvm.getelementptr %374[%637] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %636 = llvm.load %638 : !llvm.ptr -> i64
      %639 = arith.divsi %272, %636 : i64
      %640 = arith.cmpi sle, %639, %636 : i64
      cf.cond_br %640, ^bb108, ^bb109
      ^bb108:
        cf.br ^bb107(%635 : index)
      ^bb109:
        cf.br ^bb110
      ^bb110:
      %642 = arith.constant 1 : i32
      %644 = arith.extsi %642 : i32 to i64
      %643 = arith.subi %636, %644 : i64
      %645 = llvm.getelementptr %419[%643] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %641 = llvm.load %645 : !llvm.ptr -> i64
      %647 = arith.subi %415, %636 : i64
      %648 = llvm.getelementptr %419[%647] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %646 = llvm.load %648 : !llvm.ptr -> i64
      %649 = arith.subi %641, %646 : i64
      %650 = llvm.mlir.addressof @MOD : !llvm.ptr
      %651 = llvm.load %650 : !llvm.ptr -> i64
      %652 = arith.remsi %649, %651 : i64
      %653 = arith.muli %636, %636 : i64
      %654 = llvm.mlir.addressof @MOD : !llvm.ptr
      %655 = llvm.load %654 : !llvm.ptr -> i64
      %656 = arith.remsi %653, %655 : i64
      %657 = arith.muli %656, %636 : i64
      %658 = llvm.mlir.addressof @MOD : !llvm.ptr
      %659 = llvm.load %658 : !llvm.ptr -> i64
      %660 = arith.remsi %657, %659 : i64
      %661 = llvm.load %622 : !llvm.ptr -> i64
      %662 = arith.muli %660, %652 : i64
      %663 = arith.addi %661, %662 : i64
      %664 = llvm.mlir.addressof @MOD : !llvm.ptr
      %665 = llvm.load %664 : !llvm.ptr -> i64
      %666 = arith.remsi %663, %665 : i64
      llvm.store %666, %622 : i64, !llvm.ptr
      %667 = arith.addi %635, %627 : index
      cf.br ^bb105(%667 : index)
    ^bb107(%668: index):
    %669 = llvm.load %622 : !llvm.ptr -> i64
    %670 = llvm.mlir.addressof @MOD : !llvm.ptr
    %671 = llvm.load %670 : !llvm.ptr -> i64
    %672 = arith.remsi %669, %671 : i64
    llvm.store %672, %622 : i64, !llvm.ptr
    %673 = llvm.load %622 : !llvm.ptr -> i64
    %674 = arith.constant 0 : i32
    %676 = arith.extsi %674 : i32 to i64
    %675 = arith.cmpi slt, %673, %676 : i64
    cf.cond_br %675, ^bb111, ^bb112
    ^bb111:
      %677 = llvm.load %622 : !llvm.ptr -> i64
      %678 = llvm.mlir.addressof @MOD : !llvm.ptr
      %679 = llvm.load %678 : !llvm.ptr -> i64
      %680 = arith.addi %677, %679 : i64
      llvm.store %680, %622 : i64, !llvm.ptr
      cf.br ^bb113
    ^bb112:
      cf.br ^bb113
    ^bb113:
    %681 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %682 = llvm.load %622 : !llvm.ptr -> i64
    %683 = llvm.call @printf(%681, %682) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    func.call @free(%419) : (!llvm.ptr) -> ()
    func.call @free(%416) : (!llvm.ptr) -> ()
    func.call @free(%374) : (!llvm.ptr) -> ()
    func.call @free(%274) : (!llvm.ptr) -> ()
    %688 = arith.constant 0 : i32
    func.return %688 : i32
  }
}