Problem 530

GCD of Divisors — F(10^15) via Dirichlet hyperbola.

Answer207366437157977206
Output207366437157977206
StatusPASS
Native helperno
Runtime1970 ms
Peak memory630272 KB
Time complexityO(n) (estimated)
Space complexityO(n^2) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n)O(n log log n)
Space complexityO(n^2)O(n)
ApproachFlow solutionSieve-based divisor sums
VerdictOptimal

Flow source

# Project Euler 530
# GCD of Divisors — F(10^15) via Dirichlet hyperbola.

import euler.nt { isqrt }

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

const CAP: i64 = 2097152

function divisor_summatory(n: i64) -> i64 {
    let s: i64 = isqrt(n)
    let mut acc: i64 = 0
    let mut i: i64 = 1
    while i <= s {
        acc = acc + n / i
        i = i + 1
    }
    return 2 * acc - s * s
}

function hslot(key: i64, keys: ptr<i64>, used: ptr<i8>) -> i64 {
    let mut h: i64 = key % CAP
    if h < 0 { h = h + CAP }
    while used[h] == 1 && keys[h] != key {
        h = h + 1
        if h == CAP { h = 0 }
    }
    return h
}

function D_cached(x: i64, keys: ptr<i64>, vals: ptr<i64>, used: ptr<i8>) -> i64 {
    let s: i64 = hslot(x, keys, used)
    if used[s] == 1 { return vals[s] }
    let v: i64 = divisor_summatory(x)
    used[s] = 1
    keys[s] = x
    vals[s] = v
    return v
}

function main() -> i32 {
    let N: i64 = 1000000000000000
    let k: i64 = isqrt(N)
    let l: i64 = N / k
    let tmax: i64 = isqrt(l)

    let phi: ptr<i32> = calloc(k + 1, 4)
    let tau: ptr<i16> = calloc(k + 1, 2)
    let lp: ptr<i32> = calloc(k + 1, 4)
    let expv: ptr<i8> = calloc(k + 1, 1)
    let primes: ptr<i32> = calloc(k / 5 + 10, 4)
    let Phi: ptr<i64> = calloc(k + 1, 8)
    if phi == null || tau == null || lp == null || expv == null || primes == null || Phi == null {
        return 1
    }
    phi[1] = 1
    tau[1] = 1
    let mut pn: i64 = 0
    let mut i: i64 = 2
    while i <= k {
        if lp[i] == 0 {
            lp[i] = i as i32
            primes[pn] = i as i32
            pn = pn + 1
            phi[i] = (i - 1) as i32
            tau[i] = 2
            expv[i] = 1
        }
        let mut pi: i64 = 0
        while pi < pn {
            let p: i64 = primes[pi] as i64
            let ip: i64 = i * p
            if ip > k { break }
            lp[ip] = p as i32
            if i % p == 0 {
                phi[ip] = (phi[i] as i64 * p) as i32
                let e: i64 = (expv[i] as i64) + 1
                expv[ip] = e as i8
                tau[ip] = ((tau[i] as i64) / ((expv[i] as i64) + 1) * (e + 1)) as i16
                break
            } else {
                phi[ip] = (phi[i] as i64 * (p - 1)) as i32
                expv[ip] = 1
                tau[ip] = ((tau[i] as i64) * 2) as i16
            }
            pi = pi + 1
        }
        i = i + 1
    }
    let mut running: i64 = 0
    i = 1
    while i <= k {
        running = running + (phi[i] as i64)
        Phi[i] = running
        i = i + 1
    }
    let phi_small: ptr<i32> = calloc(tmax + 1, 4)
    if phi_small == null { return 1 }
    i = 1
    while i <= tmax {
        phi_small[i] = phi[i]
        i = i + 1
    }

    let mut sum1: i64 = 0
    let mut sum_tau: i64 = 0
    i = 1
    while i <= k {
        let ti: i64 = tau[i] as i64
        sum_tau = sum_tau + ti
        let m: i64 = isqrt(N / i)
        sum1 = sum1 + ti * Phi[m]
        i = i + 1
    }

    let keys: ptr<i64> = calloc(CAP, 8)
    let vals: ptr<i64> = calloc(CAP, 8)
    let used: ptr<i8> = calloc(CAP, 1)
    if keys == null || vals == null || used == null { return 1 }
    let s0: i64 = hslot(k, keys, used)
    used[s0] = 1
    keys[s0] = k
    vals[s0] = sum_tau

    let mut sum2: i64 = 0
    let mut t: i64 = 1
    while t <= tmax {
        sum2 = sum2 + (phi_small[t] as i64) * D_cached(N / (t * t), keys, vals, used)
        t = t + 1
    }
    let result: i64 = sum1 + sum2 - sum_tau * Phi[tmax]
    printf("%lld\n", result)
    free(phi); free(tau); free(lp); free(expv); free(primes); free(Phi)
    free(phi_small); free(keys); free(vals); free(used)
    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 divisor_summatory_i64(int64_t n);
int64_t hslot_i64_ptr_i64_ptr_i8(int64_t key, int64_t* keys, int8_t* used);
int64_t D_cached_i64_ptr_i64_ptr_i64_ptr_i8(int64_t x, int64_t* keys, int64_t* vals, int8_t* used);
int32_t main(void);

static const int64_t CAP = 2097152;

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 divisor_summatory_i64(int64_t n) {
    int64_t s = isqrt_i64(n);
    int64_t acc = 0;
    int64_t i = 1;
    while (i <= s) {
        acc = (acc + FLOW_CHECKED_DIV((n), (i)));
        i = (i + 1);
    }
    return ((2 * acc) - (s * s));
}

int64_t hslot_i64_ptr_i64_ptr_i8(int64_t key, int64_t* keys, int8_t* used) {
    int64_t h = FLOW_CHECKED_MOD((key), (CAP));
    if (h < 0) {
        h = (h + CAP);
    }
    while ((used[h] == 1 && keys[h] != key)) {
        h = (h + 1);
        if (h == CAP) {
            h = 0;
        }
    }
    return h;
}

int64_t D_cached_i64_ptr_i64_ptr_i64_ptr_i8(int64_t x, int64_t* keys, int64_t* vals, int8_t* used) {
    int64_t s = hslot_i64_ptr_i64_ptr_i8(x, keys, used);
    if (used[s] == 1) {
        return vals[s];
    }
    int64_t v = divisor_summatory_i64(x);
    used[s] = 1;
    keys[s] = x;
    vals[s] = v;
    return v;
}

int32_t main(void) {
    int64_t N = 1000000000000000;
    int64_t k = isqrt_i64(N);
    int64_t l = FLOW_CHECKED_DIV((N), (k));
    int64_t tmax = isqrt_i64(l);
    int32_t* phi = (int32_t*)(calloc((k + 1), 4));
    int16_t* tau = (int16_t*)(calloc((k + 1), 2));
    int32_t* lp = (int32_t*)(calloc((k + 1), 4));
    int8_t* expv = (int8_t*)(calloc((k + 1), 1));
    int32_t* primes = (int32_t*)(calloc((FLOW_CHECKED_DIV((k), (5)) + 10), 4));
    int64_t* Phi = (int64_t*)(calloc((k + 1), 8));
    if ((((((phi == NULL || tau == NULL) || lp == NULL) || expv == NULL) || primes == NULL) || Phi == NULL)) {
        return 1;
    }
    phi[1] = 1;
    tau[1] = 1;
    int64_t pn = 0;
    int64_t i = 2;
    while (i <= k) {
        if (lp[i] == 0) {
            lp[i] = ((int32_t)(i));
            primes[pn] = ((int32_t)(i));
            pn = (pn + 1);
            phi[i] = ((int32_t)((i - 1)));
            tau[i] = 2;
            expv[i] = 1;
        }
        int64_t pi = 0;
        while (pi < pn) {
            int64_t p = ((int64_t)(primes[pi]));
            int64_t ip = (i * p);
            if (ip > k) {
                break;
            }
            lp[ip] = ((int32_t)(p));
            if (FLOW_CHECKED_MOD((i), (p)) == 0) {
                phi[ip] = ((int32_t)((((int64_t)(phi[i])) * p)));
                int64_t e = (((int64_t)(expv[i])) + 1);
                expv[ip] = ((int8_t)(e));
                tau[ip] = ((int16_t)((FLOW_CHECKED_DIV((((int64_t)(tau[i]))), ((((int64_t)(expv[i])) + 1))) * (e + 1))));
                break;
            } else {
                phi[ip] = ((int32_t)((((int64_t)(phi[i])) * (p - 1))));
                expv[ip] = 1;
                tau[ip] = ((int16_t)((((int64_t)(tau[i])) * 2)));
            }
            pi = (pi + 1);
        }
        i = (i + 1);
    }
    int64_t running = 0;
    i = 1;
    while (i <= k) {
        running = (running + ((int64_t)(phi[i])));
        Phi[i] = running;
        i = (i + 1);
    }
    int32_t* phi_small = (int32_t*)(calloc((tmax + 1), 4));
    if (phi_small == NULL) {
        return 1;
    }
    i = 1;
    while (i <= tmax) {
        phi_small[i] = phi[i];
        i = (i + 1);
    }
    int64_t sum1 = 0;
    int64_t sum_tau = 0;
    i = 1;
    while (i <= k) {
        int64_t ti = ((int64_t)(tau[i]));
        sum_tau = (sum_tau + ti);
        int64_t m = isqrt_i64(FLOW_CHECKED_DIV((N), (i)));
        sum1 = (sum1 + (ti * Phi[m]));
        i = (i + 1);
    }
    int64_t* keys = (int64_t*)(calloc(CAP, 8));
    int64_t* vals = (int64_t*)(calloc(CAP, 8));
    int8_t* used = (int8_t*)(calloc(CAP, 1));
    if (((keys == NULL || vals == NULL) || used == NULL)) {
        return 1;
    }
    int64_t s0 = hslot_i64_ptr_i64_ptr_i8(k, keys, used);
    used[s0] = 1;
    keys[s0] = k;
    vals[s0] = sum_tau;
    int64_t sum2 = 0;
    int64_t t = 1;
    while (t <= tmax) {
        sum2 = (sum2 + (((int64_t)(phi_small[t])) * D_cached_i64_ptr_i64_ptr_i64_ptr_i8(FLOW_CHECKED_DIV((N), ((t * t))), keys, vals, used)));
        t = (t + 1);
    }
    int64_t result = ((sum1 + sum2) - (sum_tau * Phi[tmax]));
    printf("%lld\n", result);
    free(phi);
    free(tau);
    free(lp);
    free(expv);
    free(primes);
    free(Phi);
    free(phi_small);
    free(keys);
    free(vals);
    free(used);
    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: CAP
  llvm.mlir.global internal constant @CAP(2097152 : i64) : i64
  func.func @divisor_summatory(%arg0: i64) -> i64 {
    %175 = func.call @isqrt(%arg0) : (i64) -> i64
    %176 = arith.constant 0 : i32
    %177 = arith.extsi %176 : i32 to i64
    %178 = llvm.mlir.constant(1 : i64) : i64
    %179 = llvm.alloca %178 x i64 : (i64) -> !llvm.ptr
    llvm.store %177, %179 : i64, !llvm.ptr
    %180 = arith.constant 1 : i32
    %181 = arith.extsi %180 : i32 to i64
    %182 = llvm.mlir.constant(1 : i64) : i64
    %183 = llvm.alloca %182 x i64 : (i64) -> !llvm.ptr
    llvm.store %181, %183 : i64, !llvm.ptr
    cf.br ^bb42
    ^bb42:
    %184 = llvm.load %183 : !llvm.ptr -> i64
    %185 = arith.cmpi sle, %184, %175 : i64
    cf.cond_br %185, ^bb43, ^bb44
    ^bb43:
      %186 = llvm.load %179 : !llvm.ptr -> i64
      %187 = llvm.load %183 : !llvm.ptr -> i64
      %188 = arith.divsi %arg0, %187 : i64
      %189 = arith.addi %186, %188 : i64
      llvm.store %189, %179 : i64, !llvm.ptr
      %190 = llvm.load %183 : !llvm.ptr -> i64
      %191 = arith.constant 1 : i32
      %193 = arith.extsi %191 : i32 to i64
      %192 = arith.addi %190, %193 : i64
      llvm.store %192, %183 : i64, !llvm.ptr
      cf.br ^bb42
    ^bb44:
    %194 = arith.constant 2 : i32
    %195 = llvm.load %179 : !llvm.ptr -> i64
    %197 = arith.extsi %194 : i32 to i64
    %196 = arith.muli %197, %195 : i64
    %198 = arith.muli %175, %175 : i64
    %199 = arith.subi %196, %198 : i64
    func.return %199 : i64
  }
  func.func @hslot(%arg0: i64, %arg1: !llvm.ptr, %arg2: !llvm.ptr) -> i64 {
    %200 = llvm.mlir.addressof @CAP : !llvm.ptr
    %201 = llvm.load %200 : !llvm.ptr -> i64
    %202 = arith.remsi %arg0, %201 : i64
    %203 = llvm.mlir.constant(1 : i64) : i64
    %204 = llvm.alloca %203 x i64 : (i64) -> !llvm.ptr
    llvm.store %202, %204 : i64, !llvm.ptr
    %205 = llvm.load %204 : !llvm.ptr -> i64
    %206 = arith.constant 0 : i32
    %208 = arith.extsi %206 : i32 to i64
    %207 = arith.cmpi slt, %205, %208 : i64
    cf.cond_br %207, ^bb45, ^bb46
    ^bb45:
      %209 = llvm.load %204 : !llvm.ptr -> i64
      %210 = llvm.mlir.addressof @CAP : !llvm.ptr
      %211 = llvm.load %210 : !llvm.ptr -> i64
      %212 = arith.addi %209, %211 : i64
      llvm.store %212, %204 : i64, !llvm.ptr
      cf.br ^bb47
    ^bb46:
      cf.br ^bb47
    ^bb47:
    cf.br ^bb48
    ^bb48:
    %214 = llvm.load %204 : !llvm.ptr -> i64
    %215 = llvm.getelementptr %arg2[%214] : (!llvm.ptr, i64) -> !llvm.ptr, i8
    %213 = llvm.load %215 : !llvm.ptr -> i8
    %216 = arith.constant 1 : i32
    %218 = arith.extsi %213 : i8 to i32
    %217 = arith.cmpi eq, %218, %216 : i32
    %219 = scf.if %217 -> (i1) {
      %221 = llvm.load %204 : !llvm.ptr -> i64
      %222 = llvm.getelementptr %arg1[%221] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %220 = llvm.load %222 : !llvm.ptr -> i64
      %223 = arith.cmpi ne, %220, %arg0 : i64
      scf.yield %223 : i1
    } else {
      %224 = arith.constant false
      scf.yield %224 : i1
    }
    cf.cond_br %219, ^bb49, ^bb50
    ^bb49:
      %225 = llvm.load %204 : !llvm.ptr -> i64
      %226 = arith.constant 1 : i32
      %228 = arith.extsi %226 : i32 to i64
      %227 = arith.addi %225, %228 : i64
      llvm.store %227, %204 : i64, !llvm.ptr
      %229 = llvm.load %204 : !llvm.ptr -> i64
      %230 = llvm.mlir.addressof @CAP : !llvm.ptr
      %231 = llvm.load %230 : !llvm.ptr -> i64
      %232 = arith.cmpi eq, %229, %231 : i64
      cf.cond_br %232, ^bb51, ^bb52
      ^bb51:
        %233 = arith.constant 0 : i32
        %234 = arith.extsi %233 : i32 to i64
        llvm.store %234, %204 : i64, !llvm.ptr
        cf.br ^bb53
      ^bb52:
        cf.br ^bb53
      ^bb53:
      cf.br ^bb48
    ^bb50:
    %235 = llvm.load %204 : !llvm.ptr -> i64
    func.return %235 : i64
  }
  func.func @D_cached(%arg0: i64, %arg1: !llvm.ptr, %arg2: !llvm.ptr, %arg3: !llvm.ptr) -> i64 {
    %236 = func.call @hslot(%arg0, %arg1, %arg3) : (i64, !llvm.ptr, !llvm.ptr) -> i64
    %238 = llvm.getelementptr %arg3[%236] : (!llvm.ptr, i64) -> !llvm.ptr, i8
    %237 = llvm.load %238 : !llvm.ptr -> i8
    %239 = arith.constant 1 : i32
    %241 = arith.extsi %237 : i8 to i32
    %240 = arith.cmpi eq, %241, %239 : i32
    cf.cond_br %240, ^bb54, ^bb55
    ^bb54:
      %243 = llvm.getelementptr %arg2[%236] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %242 = llvm.load %243 : !llvm.ptr -> i64
      func.return %242 : i64
    ^bb55:
      cf.br ^bb56
    ^bb56:
    %244 = func.call @divisor_summatory(%arg0) : (i64) -> i64
    %245 = arith.constant 1 : i32
    %246 = arith.trunci %245 : i32 to i8
    %247 = llvm.getelementptr %arg3[%236] : (!llvm.ptr, i64) -> !llvm.ptr, i8
    llvm.store %246, %247 : i8, !llvm.ptr
    %248 = llvm.getelementptr %arg1[%236] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %arg0, %248 : i64, !llvm.ptr
    %249 = llvm.getelementptr %arg2[%236] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %244, %249 : i64, !llvm.ptr
    func.return %244 : i64
  }
  func.func @main() -> i32 {
    %250 = arith.constant 999995705032704 : i32
    %251 = arith.extsi %250 : i32 to i64
    %252 = func.call @isqrt(%251) : (i64) -> i64
    %253 = arith.divsi %251, %252 : i64
    %254 = func.call @isqrt(%253) : (i64) -> i64
    %256 = arith.constant 1 : i32
    %258 = arith.extsi %256 : i32 to i64
    %257 = arith.addi %252, %258 : i64
    %259 = arith.constant 4 : i32
    %260 = arith.extsi %259 : i32 to i64
    %255 = func.call @calloc(%257, %260) : (i64, i64) -> !llvm.ptr
    %262 = arith.constant 1 : i32
    %264 = arith.extsi %262 : i32 to i64
    %263 = arith.addi %252, %264 : i64
    %265 = arith.constant 2 : i32
    %266 = arith.extsi %265 : i32 to i64
    %261 = func.call @calloc(%263, %266) : (i64, i64) -> !llvm.ptr
    %268 = arith.constant 1 : i32
    %270 = arith.extsi %268 : i32 to i64
    %269 = arith.addi %252, %270 : i64
    %271 = arith.constant 4 : i32
    %272 = arith.extsi %271 : i32 to i64
    %267 = func.call @calloc(%269, %272) : (i64, i64) -> !llvm.ptr
    %274 = arith.constant 1 : i32
    %276 = arith.extsi %274 : i32 to i64
    %275 = arith.addi %252, %276 : i64
    %277 = arith.constant 1 : i32
    %278 = arith.extsi %277 : i32 to i64
    %273 = func.call @calloc(%275, %278) : (i64, i64) -> !llvm.ptr
    %280 = arith.constant 5 : i32
    %282 = arith.extsi %280 : i32 to i64
    %281 = arith.divsi %252, %282 : i64
    %283 = arith.constant 10 : i32
    %285 = arith.extsi %283 : i32 to i64
    %284 = arith.addi %281, %285 : i64
    %286 = arith.constant 4 : i32
    %287 = arith.extsi %286 : i32 to i64
    %279 = func.call @calloc(%284, %287) : (i64, i64) -> !llvm.ptr
    %289 = arith.constant 1 : i32
    %291 = arith.extsi %289 : i32 to i64
    %290 = arith.addi %252, %291 : i64
    %292 = arith.constant 8 : i32
    %293 = arith.extsi %292 : i32 to i64
    %288 = func.call @calloc(%290, %293) : (i64, i64) -> !llvm.ptr
    %294 = llvm.mlir.zero : !llvm.ptr
    %295 = llvm.icmp "eq" %255, %294 : !llvm.ptr
    %296 = scf.if %295 -> (i1) {
      %297 = arith.constant true
      scf.yield %297 : i1
    } else {
      %298 = llvm.mlir.zero : !llvm.ptr
      %299 = llvm.icmp "eq" %261, %298 : !llvm.ptr
      scf.yield %299 : i1
    }
    %300 = scf.if %296 -> (i1) {
      %301 = arith.constant true
      scf.yield %301 : i1
    } else {
      %302 = llvm.mlir.zero : !llvm.ptr
      %303 = llvm.icmp "eq" %267, %302 : !llvm.ptr
      scf.yield %303 : i1
    }
    %304 = scf.if %300 -> (i1) {
      %305 = arith.constant true
      scf.yield %305 : i1
    } else {
      %306 = llvm.mlir.zero : !llvm.ptr
      %307 = llvm.icmp "eq" %273, %306 : !llvm.ptr
      scf.yield %307 : i1
    }
    %308 = scf.if %304 -> (i1) {
      %309 = arith.constant true
      scf.yield %309 : i1
    } else {
      %310 = llvm.mlir.zero : !llvm.ptr
      %311 = llvm.icmp "eq" %279, %310 : !llvm.ptr
      scf.yield %311 : i1
    }
    %312 = scf.if %308 -> (i1) {
      %313 = arith.constant true
      scf.yield %313 : i1
    } else {
      %314 = llvm.mlir.zero : !llvm.ptr
      %315 = llvm.icmp "eq" %288, %314 : !llvm.ptr
      scf.yield %315 : i1
    }
    cf.cond_br %312, ^bb57, ^bb58
    ^bb57:
      %316 = arith.constant 1 : i32
      func.return %316 : i32
    ^bb58:
      cf.br ^bb59
    ^bb59:
    %317 = arith.constant 1 : i32
    %318 = arith.constant 1 : i32
    %319 = arith.extsi %318 : i32 to i64
    %320 = llvm.getelementptr %255[%319] : (!llvm.ptr, i64) -> !llvm.ptr, i32
    llvm.store %317, %320 : i32, !llvm.ptr
    %321 = arith.constant 1 : i32
    %322 = arith.constant 1 : i32
    %323 = arith.trunci %321 : i32 to i16
    %324 = arith.extsi %322 : i32 to i64
    %325 = llvm.getelementptr %261[%324] : (!llvm.ptr, i64) -> !llvm.ptr, i16
    llvm.store %323, %325 : i16, !llvm.ptr
    %326 = arith.constant 0 : i32
    %327 = arith.extsi %326 : i32 to i64
    %328 = llvm.mlir.constant(1 : i64) : i64
    %329 = llvm.alloca %328 x i64 : (i64) -> !llvm.ptr
    llvm.store %327, %329 : i64, !llvm.ptr
    %330 = arith.constant 2 : i32
    %331 = arith.extsi %330 : i32 to i64
    %332 = llvm.mlir.constant(1 : i64) : i64
    %333 = llvm.alloca %332 x i64 : (i64) -> !llvm.ptr
    llvm.store %331, %333 : i64, !llvm.ptr
    cf.br ^bb60
    ^bb60:
    %334 = llvm.load %333 : !llvm.ptr -> i64
    %335 = arith.cmpi sle, %334, %252 : i64
    cf.cond_br %335, ^bb61, ^bb62
    ^bb61:
      %337 = llvm.load %333 : !llvm.ptr -> i64
      %338 = llvm.getelementptr %267[%337] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %336 = llvm.load %338 : !llvm.ptr -> i32
      %339 = arith.constant 0 : i32
      %340 = arith.cmpi eq, %336, %339 : i32
      cf.cond_br %340, ^bb63, ^bb64
      ^bb63:
        %341 = llvm.load %333 : !llvm.ptr -> i64
        %342 = arith.trunci %341 : i64 to i32
        %343 = llvm.load %333 : !llvm.ptr -> i64
        %344 = llvm.getelementptr %267[%343] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %342, %344 : i32, !llvm.ptr
        %345 = llvm.load %333 : !llvm.ptr -> i64
        %346 = arith.trunci %345 : i64 to i32
        %347 = llvm.load %329 : !llvm.ptr -> i64
        %348 = llvm.getelementptr %279[%347] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %346, %348 : i32, !llvm.ptr
        %349 = llvm.load %329 : !llvm.ptr -> i64
        %350 = arith.constant 1 : i32
        %352 = arith.extsi %350 : i32 to i64
        %351 = arith.addi %349, %352 : i64
        llvm.store %351, %329 : i64, !llvm.ptr
        %353 = llvm.load %333 : !llvm.ptr -> i64
        %354 = arith.constant 1 : i32
        %356 = arith.extsi %354 : i32 to i64
        %355 = arith.subi %353, %356 : i64
        %357 = arith.trunci %355 : i64 to i32
        %358 = llvm.load %333 : !llvm.ptr -> i64
        %359 = llvm.getelementptr %255[%358] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %357, %359 : i32, !llvm.ptr
        %360 = arith.constant 2 : i32
        %361 = llvm.load %333 : !llvm.ptr -> i64
        %362 = arith.trunci %360 : i32 to i16
        %363 = llvm.getelementptr %261[%361] : (!llvm.ptr, i64) -> !llvm.ptr, i16
        llvm.store %362, %363 : i16, !llvm.ptr
        %364 = arith.constant 1 : i32
        %365 = llvm.load %333 : !llvm.ptr -> i64
        %366 = arith.trunci %364 : i32 to i8
        %367 = llvm.getelementptr %273[%365] : (!llvm.ptr, i64) -> !llvm.ptr, i8
        llvm.store %366, %367 : i8, !llvm.ptr
        cf.br ^bb65
      ^bb64:
        cf.br ^bb65
      ^bb65:
      %368 = arith.constant 0 : i32
      %369 = arith.extsi %368 : i32 to i64
      %370 = llvm.mlir.constant(1 : i64) : i64
      %371 = llvm.alloca %370 x i64 : (i64) -> !llvm.ptr
      llvm.store %369, %371 : i64, !llvm.ptr
      cf.br ^bb66
      ^bb66:
      %372 = llvm.load %371 : !llvm.ptr -> i64
      %373 = llvm.load %329 : !llvm.ptr -> i64
      %374 = arith.cmpi slt, %372, %373 : i64
      cf.cond_br %374, ^bb67, ^bb68
      ^bb67:
        %376 = llvm.load %371 : !llvm.ptr -> i64
        %377 = llvm.getelementptr %279[%376] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %375 = llvm.load %377 : !llvm.ptr -> i32
        %378 = arith.extsi %375 : i32 to i64
        %379 = llvm.load %333 : !llvm.ptr -> i64
        %380 = arith.muli %379, %378 : i64
        %381 = arith.cmpi sgt, %380, %252 : i64
        cf.cond_br %381, ^bb69, ^bb70
        ^bb69:
          cf.br ^bb68
        ^bb70:
          cf.br ^bb71
        ^bb71:
        %382 = arith.trunci %378 : i64 to i32
        %383 = llvm.getelementptr %267[%380] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %382, %383 : i32, !llvm.ptr
        %384 = llvm.load %333 : !llvm.ptr -> i64
        %385 = arith.remsi %384, %378 : i64
        %386 = arith.constant 0 : i32
        %388 = arith.extsi %386 : i32 to i64
        %387 = arith.cmpi eq, %385, %388 : i64
        cf.cond_br %387, ^bb72, ^bb73
        ^bb72:
          %390 = llvm.load %333 : !llvm.ptr -> i64
          %391 = llvm.getelementptr %255[%390] : (!llvm.ptr, i64) -> !llvm.ptr, i32
          %389 = llvm.load %391 : !llvm.ptr -> i32
          %392 = arith.extsi %389 : i32 to i64
          %393 = arith.muli %392, %378 : i64
          %394 = arith.trunci %393 : i64 to i32
          %395 = llvm.getelementptr %255[%380] : (!llvm.ptr, i64) -> !llvm.ptr, i32
          llvm.store %394, %395 : i32, !llvm.ptr
          %397 = llvm.load %333 : !llvm.ptr -> i64
          %398 = llvm.getelementptr %273[%397] : (!llvm.ptr, i64) -> !llvm.ptr, i8
          %396 = llvm.load %398 : !llvm.ptr -> i8
          %399 = arith.extsi %396 : i8 to i64
          %400 = arith.constant 1 : i32
          %402 = arith.extsi %400 : i32 to i64
          %401 = arith.addi %399, %402 : i64
          %403 = arith.trunci %401 : i64 to i8
          %404 = llvm.getelementptr %273[%380] : (!llvm.ptr, i64) -> !llvm.ptr, i8
          llvm.store %403, %404 : i8, !llvm.ptr
          %406 = llvm.load %333 : !llvm.ptr -> i64
          %407 = llvm.getelementptr %261[%406] : (!llvm.ptr, i64) -> !llvm.ptr, i16
          %405 = llvm.load %407 : !llvm.ptr -> i16
          %408 = arith.extsi %405 : i16 to i64
          %410 = llvm.load %333 : !llvm.ptr -> i64
          %411 = llvm.getelementptr %273[%410] : (!llvm.ptr, i64) -> !llvm.ptr, i8
          %409 = llvm.load %411 : !llvm.ptr -> i8
          %412 = arith.extsi %409 : i8 to i64
          %413 = arith.constant 1 : i32
          %415 = arith.extsi %413 : i32 to i64
          %414 = arith.addi %412, %415 : i64
          %416 = arith.divsi %408, %414 : i64
          %417 = arith.constant 1 : i32
          %419 = arith.extsi %417 : i32 to i64
          %418 = arith.addi %401, %419 : i64
          %420 = arith.muli %416, %418 : i64
          %421 = arith.trunci %420 : i64 to i16
          %422 = llvm.getelementptr %261[%380] : (!llvm.ptr, i64) -> !llvm.ptr, i16
          llvm.store %421, %422 : i16, !llvm.ptr
          cf.br ^bb68
        ^bb73:
          %424 = llvm.load %333 : !llvm.ptr -> i64
          %425 = llvm.getelementptr %255[%424] : (!llvm.ptr, i64) -> !llvm.ptr, i32
          %423 = llvm.load %425 : !llvm.ptr -> i32
          %426 = arith.extsi %423 : i32 to i64
          %427 = arith.constant 1 : i32
          %429 = arith.extsi %427 : i32 to i64
          %428 = arith.subi %378, %429 : i64
          %430 = arith.muli %426, %428 : i64
          %431 = arith.trunci %430 : i64 to i32
          %432 = llvm.getelementptr %255[%380] : (!llvm.ptr, i64) -> !llvm.ptr, i32
          llvm.store %431, %432 : i32, !llvm.ptr
          %433 = arith.constant 1 : i32
          %434 = arith.trunci %433 : i32 to i8
          %435 = llvm.getelementptr %273[%380] : (!llvm.ptr, i64) -> !llvm.ptr, i8
          llvm.store %434, %435 : i8, !llvm.ptr
          %437 = llvm.load %333 : !llvm.ptr -> i64
          %438 = llvm.getelementptr %261[%437] : (!llvm.ptr, i64) -> !llvm.ptr, i16
          %436 = llvm.load %438 : !llvm.ptr -> i16
          %439 = arith.extsi %436 : i16 to i64
          %440 = arith.constant 2 : i32
          %442 = arith.extsi %440 : i32 to i64
          %441 = arith.muli %439, %442 : i64
          %443 = arith.trunci %441 : i64 to i16
          %444 = llvm.getelementptr %261[%380] : (!llvm.ptr, i64) -> !llvm.ptr, i16
          llvm.store %443, %444 : i16, !llvm.ptr
          cf.br ^bb74
        ^bb74:
        %445 = llvm.load %371 : !llvm.ptr -> i64
        %446 = arith.constant 1 : i32
        %448 = arith.extsi %446 : i32 to i64
        %447 = arith.addi %445, %448 : i64
        llvm.store %447, %371 : i64, !llvm.ptr
        cf.br ^bb66
      ^bb68:
      %449 = llvm.load %333 : !llvm.ptr -> i64
      %450 = arith.constant 1 : i32
      %452 = arith.extsi %450 : i32 to i64
      %451 = arith.addi %449, %452 : i64
      llvm.store %451, %333 : i64, !llvm.ptr
      cf.br ^bb60
    ^bb62:
    %453 = arith.constant 0 : i32
    %454 = arith.extsi %453 : i32 to i64
    %455 = llvm.mlir.constant(1 : i64) : i64
    %456 = llvm.alloca %455 x i64 : (i64) -> !llvm.ptr
    llvm.store %454, %456 : i64, !llvm.ptr
    %457 = arith.constant 1 : i32
    %458 = arith.extsi %457 : i32 to i64
    llvm.store %458, %333 : i64, !llvm.ptr
    cf.br ^bb75
    ^bb75:
    %459 = llvm.load %333 : !llvm.ptr -> i64
    %460 = arith.cmpi sle, %459, %252 : i64
    cf.cond_br %460, ^bb76, ^bb77
    ^bb76:
      %461 = llvm.load %456 : !llvm.ptr -> i64
      %463 = llvm.load %333 : !llvm.ptr -> i64
      %464 = llvm.getelementptr %255[%463] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %462 = llvm.load %464 : !llvm.ptr -> i32
      %465 = arith.extsi %462 : i32 to i64
      %466 = arith.addi %461, %465 : i64
      llvm.store %466, %456 : i64, !llvm.ptr
      %467 = llvm.load %456 : !llvm.ptr -> i64
      %468 = llvm.load %333 : !llvm.ptr -> i64
      %469 = llvm.getelementptr %288[%468] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %467, %469 : i64, !llvm.ptr
      %470 = llvm.load %333 : !llvm.ptr -> i64
      %471 = arith.constant 1 : i32
      %473 = arith.extsi %471 : i32 to i64
      %472 = arith.addi %470, %473 : i64
      llvm.store %472, %333 : i64, !llvm.ptr
      cf.br ^bb75
    ^bb77:
    %475 = arith.constant 1 : i32
    %477 = arith.extsi %475 : i32 to i64
    %476 = arith.addi %254, %477 : i64
    %478 = arith.constant 4 : i32
    %479 = arith.extsi %478 : i32 to i64
    %474 = func.call @calloc(%476, %479) : (i64, i64) -> !llvm.ptr
    %480 = llvm.mlir.zero : !llvm.ptr
    %481 = llvm.icmp "eq" %474, %480 : !llvm.ptr
    cf.cond_br %481, ^bb78, ^bb79
    ^bb78:
      %482 = arith.constant 1 : i32
      func.return %482 : i32
    ^bb79:
      cf.br ^bb80
    ^bb80:
    %483 = arith.constant 1 : i32
    %484 = arith.extsi %483 : i32 to i64
    llvm.store %484, %333 : i64, !llvm.ptr
    cf.br ^bb81
    ^bb81:
    %485 = llvm.load %333 : !llvm.ptr -> i64
    %486 = arith.cmpi sle, %485, %254 : i64
    cf.cond_br %486, ^bb82, ^bb83
    ^bb82:
      %488 = llvm.load %333 : !llvm.ptr -> i64
      %489 = llvm.getelementptr %255[%488] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %487 = llvm.load %489 : !llvm.ptr -> i32
      %490 = llvm.load %333 : !llvm.ptr -> i64
      %491 = llvm.getelementptr %474[%490] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      llvm.store %487, %491 : i32, !llvm.ptr
      %492 = llvm.load %333 : !llvm.ptr -> i64
      %493 = arith.constant 1 : i32
      %495 = arith.extsi %493 : i32 to i64
      %494 = arith.addi %492, %495 : i64
      llvm.store %494, %333 : i64, !llvm.ptr
      cf.br ^bb81
    ^bb83:
    %496 = arith.constant 0 : i32
    %497 = arith.extsi %496 : i32 to i64
    %498 = llvm.mlir.constant(1 : i64) : i64
    %499 = llvm.alloca %498 x i64 : (i64) -> !llvm.ptr
    llvm.store %497, %499 : i64, !llvm.ptr
    %500 = arith.constant 0 : i32
    %501 = arith.extsi %500 : i32 to i64
    %502 = llvm.mlir.constant(1 : i64) : i64
    %503 = llvm.alloca %502 x i64 : (i64) -> !llvm.ptr
    llvm.store %501, %503 : i64, !llvm.ptr
    %504 = arith.constant 1 : i32
    %505 = arith.extsi %504 : i32 to i64
    llvm.store %505, %333 : i64, !llvm.ptr
    cf.br ^bb84
    ^bb84:
    %506 = llvm.load %333 : !llvm.ptr -> i64
    %507 = arith.cmpi sle, %506, %252 : i64
    cf.cond_br %507, ^bb85, ^bb86
    ^bb85:
      %509 = llvm.load %333 : !llvm.ptr -> i64
      %510 = llvm.getelementptr %261[%509] : (!llvm.ptr, i64) -> !llvm.ptr, i16
      %508 = llvm.load %510 : !llvm.ptr -> i16
      %511 = arith.extsi %508 : i16 to i64
      %512 = llvm.load %503 : !llvm.ptr -> i64
      %513 = arith.addi %512, %511 : i64
      llvm.store %513, %503 : i64, !llvm.ptr
      %515 = llvm.load %333 : !llvm.ptr -> i64
      %516 = arith.divsi %251, %515 : i64
      %514 = func.call @isqrt(%516) : (i64) -> i64
      %517 = llvm.load %499 : !llvm.ptr -> i64
      %519 = llvm.getelementptr %288[%514] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %518 = llvm.load %519 : !llvm.ptr -> i64
      %520 = arith.muli %511, %518 : i64
      %521 = arith.addi %517, %520 : i64
      llvm.store %521, %499 : i64, !llvm.ptr
      %522 = llvm.load %333 : !llvm.ptr -> i64
      %523 = arith.constant 1 : i32
      %525 = arith.extsi %523 : i32 to i64
      %524 = arith.addi %522, %525 : i64
      llvm.store %524, %333 : i64, !llvm.ptr
      cf.br ^bb84
    ^bb86:
    %527 = llvm.mlir.addressof @CAP : !llvm.ptr
    %528 = llvm.load %527 : !llvm.ptr -> i64
    %529 = arith.constant 8 : i32
    %530 = arith.extsi %529 : i32 to i64
    %526 = func.call @calloc(%528, %530) : (i64, i64) -> !llvm.ptr
    %532 = llvm.mlir.addressof @CAP : !llvm.ptr
    %533 = llvm.load %532 : !llvm.ptr -> i64
    %534 = arith.constant 8 : i32
    %535 = arith.extsi %534 : i32 to i64
    %531 = func.call @calloc(%533, %535) : (i64, i64) -> !llvm.ptr
    %537 = llvm.mlir.addressof @CAP : !llvm.ptr
    %538 = llvm.load %537 : !llvm.ptr -> i64
    %539 = arith.constant 1 : i32
    %540 = arith.extsi %539 : i32 to i64
    %536 = func.call @calloc(%538, %540) : (i64, i64) -> !llvm.ptr
    %541 = llvm.mlir.zero : !llvm.ptr
    %542 = llvm.icmp "eq" %526, %541 : !llvm.ptr
    %543 = scf.if %542 -> (i1) {
      %544 = arith.constant true
      scf.yield %544 : i1
    } else {
      %545 = llvm.mlir.zero : !llvm.ptr
      %546 = llvm.icmp "eq" %531, %545 : !llvm.ptr
      scf.yield %546 : i1
    }
    %547 = scf.if %543 -> (i1) {
      %548 = arith.constant true
      scf.yield %548 : i1
    } else {
      %549 = llvm.mlir.zero : !llvm.ptr
      %550 = llvm.icmp "eq" %536, %549 : !llvm.ptr
      scf.yield %550 : i1
    }
    cf.cond_br %547, ^bb87, ^bb88
    ^bb87:
      %551 = arith.constant 1 : i32
      func.return %551 : i32
    ^bb88:
      cf.br ^bb89
    ^bb89:
    %552 = func.call @hslot(%252, %526, %536) : (i64, !llvm.ptr, !llvm.ptr) -> i64
    %553 = arith.constant 1 : i32
    %554 = arith.trunci %553 : i32 to i8
    %555 = llvm.getelementptr %536[%552] : (!llvm.ptr, i64) -> !llvm.ptr, i8
    llvm.store %554, %555 : i8, !llvm.ptr
    %556 = llvm.getelementptr %526[%552] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %252, %556 : i64, !llvm.ptr
    %557 = llvm.load %503 : !llvm.ptr -> i64
    %558 = llvm.getelementptr %531[%552] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %557, %558 : i64, !llvm.ptr
    %559 = arith.constant 0 : i32
    %560 = arith.extsi %559 : i32 to i64
    %561 = llvm.mlir.constant(1 : i64) : i64
    %562 = llvm.alloca %561 x i64 : (i64) -> !llvm.ptr
    llvm.store %560, %562 : i64, !llvm.ptr
    %563 = arith.constant 1 : i32
    %564 = arith.extsi %563 : i32 to i64
    %565 = llvm.mlir.constant(1 : i64) : i64
    %566 = llvm.alloca %565 x i64 : (i64) -> !llvm.ptr
    llvm.store %564, %566 : i64, !llvm.ptr
    cf.br ^bb90
    ^bb90:
    %567 = llvm.load %566 : !llvm.ptr -> i64
    %568 = arith.cmpi sle, %567, %254 : i64
    cf.cond_br %568, ^bb91, ^bb92
    ^bb91:
      %569 = llvm.load %562 : !llvm.ptr -> i64
      %571 = llvm.load %566 : !llvm.ptr -> i64
      %572 = llvm.getelementptr %474[%571] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %570 = llvm.load %572 : !llvm.ptr -> i32
      %573 = arith.extsi %570 : i32 to i64
      %575 = llvm.load %566 : !llvm.ptr -> i64
      %576 = llvm.load %566 : !llvm.ptr -> i64
      %577 = arith.muli %575, %576 : i64
      %578 = arith.divsi %251, %577 : i64
      %574 = func.call @D_cached(%578, %526, %531, %536) : (i64, !llvm.ptr, !llvm.ptr, !llvm.ptr) -> i64
      %579 = arith.muli %573, %574 : i64
      %580 = arith.addi %569, %579 : i64
      llvm.store %580, %562 : i64, !llvm.ptr
      %581 = llvm.load %566 : !llvm.ptr -> i64
      %582 = arith.constant 1 : i32
      %584 = arith.extsi %582 : i32 to i64
      %583 = arith.addi %581, %584 : i64
      llvm.store %583, %566 : i64, !llvm.ptr
      cf.br ^bb90
    ^bb92:
    %585 = llvm.load %499 : !llvm.ptr -> i64
    %586 = llvm.load %562 : !llvm.ptr -> i64
    %587 = arith.addi %585, %586 : i64
    %588 = llvm.load %503 : !llvm.ptr -> i64
    %590 = llvm.getelementptr %288[%254] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %589 = llvm.load %590 : !llvm.ptr -> i64
    %591 = arith.muli %588, %589 : i64
    %592 = arith.subi %587, %591 : i64
    %593 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %594 = llvm.call @printf(%593, %592) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    func.call @free(%255) : (!llvm.ptr) -> ()
    func.call @free(%261) : (!llvm.ptr) -> ()
    func.call @free(%267) : (!llvm.ptr) -> ()
    func.call @free(%273) : (!llvm.ptr) -> ()
    func.call @free(%279) : (!llvm.ptr) -> ()
    func.call @free(%288) : (!llvm.ptr) -> ()
    func.call @free(%474) : (!llvm.ptr) -> ()
    func.call @free(%526) : (!llvm.ptr) -> ()
    func.call @free(%531) : (!llvm.ptr) -> ()
    func.call @free(%536) : (!llvm.ptr) -> ()
    %605 = arith.constant 0 : i32
    func.return %605 : i32
  }
}