Problem 501

Eight Divisors — count n<=10^12 with d(n)=8 via fixed-limit pi table.

Answer197912312715
Output197912312715
StatusPASS
Native helperno
Runtime370 ms
Peak memory18608 KB
Time complexityO(n^2) (estimated)
Space complexityO(n^2) (estimated)

Performance comparison

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

Flow source

# Project Euler 501
# Eight Divisors — count n<=10^12 with d(n)=8 via fixed-limit pi table.

import euler.nt { isqrt }

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

function iroot(n: i64, k: i32) -> i64 {
    if n < 2 { return n }
    let mut lo: i64 = 1
    let mut hi: i64 = n
    if k >= 2 {
        hi = isqrt(n) + 2
        if hi > n { hi = n }
    }
    while lo < hi {
        let mid: i64 = (lo + hi + 1) / 2
        let mut p: i64 = 1
        let mut i: i32 = 0
        let mut ov: i32 = 0
        while i < k {
            if p > n / mid { ov = 1; break }
            p = p * mid
            i = i + 1
        }
        if ov == 1 || p > n { hi = mid - 1 } else { lo = mid }
    }
    return lo
}

function main() -> i32 {
    let limit: i64 = 1000000000000
    let root: i64 = isqrt(limit)
    let sieve: ptr<i8> = calloc(root + 1, 1)
    let primes: ptr<i32> = calloc(root / 5 + 100, 4)
    let small: ptr<i64> = calloc(root + 1, 8)
    let large: ptr<i64> = calloc(root + 1, 8)
    if sieve == null || primes == null || small == null || large == null { return 1 }
    let mut i: i64 = 2
    while i <= root {
        sieve[i] = 1
        i = i + 1
    }
    i = 2
    while i * i <= root {
        if sieve[i] == 1 {
            let mut j: i64 = i * i
            while j <= root {
                sieve[j] = 0
                j = j + i
            }
        }
        i = i + 1
    }
    let mut pn: i64 = 0
    i = 2
    while i <= root {
        if sieve[i] == 1 {
            primes[pn] = i as i32
            pn = pn + 1
        }
        i = i + 1
    }
    let mut x: i64 = 2
    while x <= root {
        small[x] = x - 1
        x = x + 1
    }
    let mut d: i64 = 1
    while d <= root {
        large[d] = limit / d - 1
        d = d + 1
    }
    let mut pi: i64 = 0
    while pi < pn {
        let p: i64 = primes[pi] as i64
        let p2: i64 = p * p
        if p2 > limit { break }
        let before_p: i64 = small[p - 1]
        let mut last_d: i64 = root
        if limit / p2 < last_d { last_d = limit / p2 }
        d = 1
        while d <= last_d {
            let pd: i64 = p * d
            if pd <= root {
                large[d] = large[d] - (large[pd] - before_p)
            } else {
                large[d] = large[d] - (small[limit / pd] - before_p)
            }
            d = d + 1
        }
        x = root
        while x >= p2 {
            small[x] = small[x] - (small[x / p] - before_p)
            x = x - 1
        }
        pi = pi + 1
    }

    # pi(x) helper inline
    let mut count: i64 = 0
    # p*q*r
    let p_stop_val: i64 = iroot(limit, 3)
    let mut p_stop: i64 = 0
    while p_stop < pn && (primes[p_stop] as i64) <= p_stop_val {
        p_stop = p_stop + 1
    }
    let mut ii: i64 = 0
    while ii < p_stop {
        let p: i64 = primes[ii] as i64
        if p * p * p >= limit { break }
        let qmax: i64 = isqrt(limit / p)
        let mut q_stop: i64 = 0
        while q_stop < pn && (primes[q_stop] as i64) <= qmax {
            q_stop = q_stop + 1
        }
        let mut jj: i64 = ii + 1
        while jj < q_stop {
            let q: i64 = primes[jj] as i64
            let max_r: i64 = limit / (p * q)
            if max_r <= q { break }
            let mut pir: i64 = 0
            if max_r <= root { pir = small[max_r] } else { pir = large[limit / max_r] }
            count = count + pir - (jj + 1)
            jj = jj + 1
        }
        ii = ii + 1
    }
    # p^3*q
    ii = 0
    while ii < p_stop {
        let p: i64 = primes[ii] as i64
        let p3: i64 = p * p * p
        if p3 > limit { break }
        let mx: i64 = limit / p3
        let mut pix: i64 = 0
        if mx <= root { pix = small[mx] } else { pix = large[limit / mx] }
        count = count + pix
        ii = ii + 1
    }
    let r4: i64 = iroot(limit, 4)
    if r4 <= root { count = count - small[r4] } else { count = count - large[limit / r4] }
    let r7: i64 = iroot(limit, 7)
    if r7 <= root { count = count + small[r7] } else { count = count + large[limit / r7] }
    printf("%lld\n", count)
    free(sieve); free(primes); free(small); free(large)
    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 iroot_i64_i32(int64_t n, int32_t k);
int32_t main(void);

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 iroot_i64_i32(int64_t n, int32_t k) {
    if (n < 2) {
        return n;
    }
    int64_t lo = 1;
    int64_t hi = n;
    if (k >= 2) {
        hi = (isqrt_i64(n) + 2);
        if (hi > n) {
            hi = n;
        }
    }
    while (lo < hi) {
        int64_t mid = FLOW_CHECKED_DIV((((lo + hi) + 1)), (2));
        int64_t p = 1;
        int32_t i = 0;
        int32_t ov = 0;
        while (i < k) {
            if (p > FLOW_CHECKED_DIV((n), (mid))) {
                ov = 1;
                break;
            }
            p = (p * mid);
            i = (i + 1);
        }
        if ((ov == 1 || p > n)) {
            hi = (mid - 1);
        } else {
            lo = mid;
        }
    }
    return lo;
}

int32_t main(void) {
    int64_t limit = 1000000000000;
    int64_t root = isqrt_i64(limit);
    int8_t* sieve = (int8_t*)(calloc((root + 1), 1));
    int32_t* primes = (int32_t*)(calloc((FLOW_CHECKED_DIV((root), (5)) + 100), 4));
    int64_t* small = (int64_t*)(calloc((root + 1), 8));
    int64_t* large = (int64_t*)(calloc((root + 1), 8));
    if ((((sieve == NULL || primes == NULL) || small == NULL) || large == NULL)) {
        return 1;
    }
    int64_t i = 2;
    while (i <= root) {
        sieve[i] = 1;
        i = (i + 1);
    }
    i = 2;
    while ((i * i) <= root) {
        if (sieve[i] == 1) {
            int64_t j = (i * i);
            while (j <= root) {
                sieve[j] = 0;
                j = (j + i);
            }
        }
        i = (i + 1);
    }
    int64_t pn = 0;
    i = 2;
    while (i <= root) {
        if (sieve[i] == 1) {
            primes[pn] = ((int32_t)(i));
            pn = (pn + 1);
        }
        i = (i + 1);
    }
    int64_t x = 2;
    while (x <= root) {
        small[x] = (x - 1);
        x = (x + 1);
    }
    int64_t d = 1;
    while (d <= root) {
        large[d] = (FLOW_CHECKED_DIV((limit), (d)) - 1);
        d = (d + 1);
    }
    int64_t pi = 0;
    while (pi < pn) {
        int64_t p = ((int64_t)(primes[pi]));
        int64_t p2 = (p * p);
        if (p2 > limit) {
            break;
        }
        int64_t before_p = small[(p - 1)];
        int64_t last_d = root;
        if (FLOW_CHECKED_DIV((limit), (p2)) < last_d) {
            last_d = FLOW_CHECKED_DIV((limit), (p2));
        }
        d = 1;
        while (d <= last_d) {
            int64_t pd = (p * d);
            if (pd <= root) {
                large[d] = (large[d] - (large[pd] - before_p));
            } else {
                large[d] = (large[d] - (small[FLOW_CHECKED_DIV((limit), (pd))] - before_p));
            }
            d = (d + 1);
        }
        x = root;
        while (x >= p2) {
            small[x] = (small[x] - (small[FLOW_CHECKED_DIV((x), (p))] - before_p));
            x = (x - 1);
        }
        pi = (pi + 1);
    }
    int64_t count = 0;
    int64_t p_stop_val = iroot_i64_i32(limit, 3);
    int64_t p_stop = 0;
    while ((p_stop < pn && ((int64_t)(primes[p_stop])) <= p_stop_val)) {
        p_stop = (p_stop + 1);
    }
    int64_t ii = 0;
    while (ii < p_stop) {
        int64_t p = ((int64_t)(primes[ii]));
        if (((p * p) * p) >= limit) {
            break;
        }
        int64_t qmax = isqrt_i64(FLOW_CHECKED_DIV((limit), (p)));
        int64_t q_stop = 0;
        while ((q_stop < pn && ((int64_t)(primes[q_stop])) <= qmax)) {
            q_stop = (q_stop + 1);
        }
        int64_t jj = (ii + 1);
        while (jj < q_stop) {
            int64_t q = ((int64_t)(primes[jj]));
            int64_t max_r = FLOW_CHECKED_DIV((limit), ((p * q)));
            if (max_r <= q) {
                break;
            }
            int64_t pir = 0;
            if (max_r <= root) {
                pir = small[max_r];
            } else {
                pir = large[FLOW_CHECKED_DIV((limit), (max_r))];
            }
            count = ((count + pir) - (jj + 1));
            jj = (jj + 1);
        }
        ii = (ii + 1);
    }
    ii = 0;
    while (ii < p_stop) {
        int64_t p = ((int64_t)(primes[ii]));
        int64_t p3 = ((p * p) * p);
        if (p3 > limit) {
            break;
        }
        int64_t mx = FLOW_CHECKED_DIV((limit), (p3));
        int64_t pix = 0;
        if (mx <= root) {
            pix = small[mx];
        } else {
            pix = large[FLOW_CHECKED_DIV((limit), (mx))];
        }
        count = (count + pix);
        ii = (ii + 1);
    }
    int64_t r4 = iroot_i64_i32(limit, 4);
    if (r4 <= root) {
        count = (count - small[r4]);
    } else {
        count = (count - large[FLOW_CHECKED_DIV((limit), (r4))]);
    }
    int64_t r7 = iroot_i64_i32(limit, 7);
    if (r7 <= root) {
        count = (count + small[r7]);
    } else {
        count = (count + large[FLOW_CHECKED_DIV((limit), (r7))]);
    }
    printf("%lld\n", count);
    free(sieve);
    free(primes);
    free(small);
    free(large);
    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) -> ()
  func.func @iroot(%arg0: i64, %arg1: i32) -> 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 = llvm.mlir.constant(1 : i64) : i64
    %183 = llvm.alloca %182 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %183 : i64, !llvm.ptr
    %184 = arith.constant 2 : i32
    %185 = arith.cmpi sge, %arg1, %184 : i32
    cf.cond_br %185, ^bb45, ^bb46
    ^bb45:
      %186 = func.call @isqrt(%arg0) : (i64) -> i64
      %187 = arith.constant 2 : i32
      %189 = arith.extsi %187 : i32 to i64
      %188 = arith.addi %186, %189 : i64
      llvm.store %188, %183 : i64, !llvm.ptr
      %190 = llvm.load %183 : !llvm.ptr -> i64
      %191 = arith.cmpi sgt, %190, %arg0 : i64
      cf.cond_br %191, ^bb48, ^bb49
      ^bb48:
        llvm.store %arg0, %183 : i64, !llvm.ptr
        cf.br ^bb50
      ^bb49:
        cf.br ^bb50
      ^bb50:
      cf.br ^bb47
    ^bb46:
      cf.br ^bb47
    ^bb47:
    cf.br ^bb51
    ^bb51:
    %192 = llvm.load %181 : !llvm.ptr -> i64
    %193 = llvm.load %183 : !llvm.ptr -> i64
    %194 = arith.cmpi slt, %192, %193 : i64
    cf.cond_br %194, ^bb52, ^bb53
    ^bb52:
      %195 = llvm.load %181 : !llvm.ptr -> i64
      %196 = llvm.load %183 : !llvm.ptr -> i64
      %197 = arith.addi %195, %196 : i64
      %198 = arith.constant 1 : i32
      %200 = arith.extsi %198 : i32 to i64
      %199 = arith.addi %197, %200 : i64
      %201 = arith.constant 2 : i32
      %203 = arith.extsi %201 : i32 to i64
      %202 = arith.divsi %199, %203 : i64
      %204 = arith.constant 1 : i32
      %205 = arith.extsi %204 : i32 to i64
      %206 = llvm.mlir.constant(1 : i64) : i64
      %207 = llvm.alloca %206 x i64 : (i64) -> !llvm.ptr
      llvm.store %205, %207 : i64, !llvm.ptr
      %208 = arith.constant 0 : i32
      %209 = llvm.mlir.constant(1 : i64) : i64
      %210 = llvm.alloca %209 x i32 : (i64) -> !llvm.ptr
      llvm.store %208, %210 : i32, !llvm.ptr
      %211 = arith.constant 0 : i32
      %212 = llvm.mlir.constant(1 : i64) : i64
      %213 = llvm.alloca %212 x i32 : (i64) -> !llvm.ptr
      llvm.store %211, %213 : i32, !llvm.ptr
      cf.br ^bb54
      ^bb54:
      %214 = llvm.load %210 : !llvm.ptr -> i32
      %215 = arith.cmpi slt, %214, %arg1 : i32
      cf.cond_br %215, ^bb55, ^bb56
      ^bb55:
        %216 = llvm.load %207 : !llvm.ptr -> i64
        %217 = arith.divsi %arg0, %202 : i64
        %218 = arith.cmpi sgt, %216, %217 : i64
        cf.cond_br %218, ^bb57, ^bb58
        ^bb57:
          %219 = arith.constant 1 : i32
          llvm.store %219, %213 : i32, !llvm.ptr
          cf.br ^bb56
        ^bb58:
          cf.br ^bb59
        ^bb59:
        %220 = llvm.load %207 : !llvm.ptr -> i64
        %221 = arith.muli %220, %202 : i64
        llvm.store %221, %207 : i64, !llvm.ptr
        %222 = llvm.load %210 : !llvm.ptr -> i32
        %223 = arith.constant 1 : i32
        %224 = arith.addi %222, %223 : i32
        llvm.store %224, %210 : i32, !llvm.ptr
        cf.br ^bb54
      ^bb56:
      %225 = llvm.load %213 : !llvm.ptr -> i32
      %226 = arith.constant 1 : i32
      %227 = arith.cmpi eq, %225, %226 : i32
      %228 = scf.if %227 -> (i1) {
        %229 = arith.constant true
        scf.yield %229 : i1
      } else {
        %230 = llvm.load %207 : !llvm.ptr -> i64
        %231 = arith.cmpi sgt, %230, %arg0 : i64
        scf.yield %231 : i1
      }
      cf.cond_br %228, ^bb60, ^bb61
      ^bb60:
        %232 = arith.constant 1 : i32
        %234 = arith.extsi %232 : i32 to i64
        %233 = arith.subi %202, %234 : i64
        llvm.store %233, %183 : i64, !llvm.ptr
        cf.br ^bb62
      ^bb61:
        llvm.store %202, %181 : i64, !llvm.ptr
        cf.br ^bb62
      ^bb62:
      cf.br ^bb51
    ^bb53:
    %235 = llvm.load %181 : !llvm.ptr -> i64
    func.return %235 : i64
  }
  func.func @main() -> i32 {
    %236 = arith.constant 995705032704 : i32
    %237 = arith.extsi %236 : i32 to i64
    %238 = func.call @isqrt(%237) : (i64) -> i64
    %240 = arith.constant 1 : i32
    %242 = arith.extsi %240 : i32 to i64
    %241 = arith.addi %238, %242 : i64
    %243 = arith.constant 1 : i32
    %244 = arith.extsi %243 : i32 to i64
    %239 = func.call @calloc(%241, %244) : (i64, i64) -> !llvm.ptr
    %246 = arith.constant 5 : i32
    %248 = arith.extsi %246 : i32 to i64
    %247 = arith.divsi %238, %248 : i64
    %249 = arith.constant 100 : i32
    %251 = arith.extsi %249 : i32 to i64
    %250 = arith.addi %247, %251 : i64
    %252 = arith.constant 4 : i32
    %253 = arith.extsi %252 : i32 to i64
    %245 = func.call @calloc(%250, %253) : (i64, i64) -> !llvm.ptr
    %255 = arith.constant 1 : i32
    %257 = arith.extsi %255 : i32 to i64
    %256 = arith.addi %238, %257 : i64
    %258 = arith.constant 8 : i32
    %259 = arith.extsi %258 : i32 to i64
    %254 = func.call @calloc(%256, %259) : (i64, i64) -> !llvm.ptr
    %261 = arith.constant 1 : i32
    %263 = arith.extsi %261 : i32 to i64
    %262 = arith.addi %238, %263 : i64
    %264 = arith.constant 8 : i32
    %265 = arith.extsi %264 : i32 to i64
    %260 = func.call @calloc(%262, %265) : (i64, i64) -> !llvm.ptr
    %266 = llvm.mlir.zero : !llvm.ptr
    %267 = llvm.icmp "eq" %239, %266 : !llvm.ptr
    %268 = scf.if %267 -> (i1) {
      %269 = arith.constant true
      scf.yield %269 : i1
    } else {
      %270 = llvm.mlir.zero : !llvm.ptr
      %271 = llvm.icmp "eq" %245, %270 : !llvm.ptr
      scf.yield %271 : i1
    }
    %272 = scf.if %268 -> (i1) {
      %273 = arith.constant true
      scf.yield %273 : i1
    } else {
      %274 = llvm.mlir.zero : !llvm.ptr
      %275 = llvm.icmp "eq" %254, %274 : !llvm.ptr
      scf.yield %275 : i1
    }
    %276 = scf.if %272 -> (i1) {
      %277 = arith.constant true
      scf.yield %277 : i1
    } else {
      %278 = llvm.mlir.zero : !llvm.ptr
      %279 = llvm.icmp "eq" %260, %278 : !llvm.ptr
      scf.yield %279 : i1
    }
    cf.cond_br %276, ^bb63, ^bb64
    ^bb63:
      %280 = arith.constant 1 : i32
      func.return %280 : i32
    ^bb64:
      cf.br ^bb65
    ^bb65:
    %281 = arith.constant 2 : i32
    %282 = arith.extsi %281 : i32 to i64
    %283 = llvm.mlir.constant(1 : i64) : i64
    %284 = llvm.alloca %283 x i64 : (i64) -> !llvm.ptr
    llvm.store %282, %284 : i64, !llvm.ptr
    cf.br ^bb66
    ^bb66:
    %285 = llvm.load %284 : !llvm.ptr -> i64
    %286 = arith.cmpi sle, %285, %238 : i64
    cf.cond_br %286, ^bb67, ^bb68
    ^bb67:
      %287 = arith.constant 1 : i32
      %288 = llvm.load %284 : !llvm.ptr -> i64
      %289 = arith.trunci %287 : i32 to i8
      %290 = llvm.getelementptr %239[%288] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      llvm.store %289, %290 : i8, !llvm.ptr
      %291 = llvm.load %284 : !llvm.ptr -> i64
      %292 = arith.constant 1 : i32
      %294 = arith.extsi %292 : i32 to i64
      %293 = arith.addi %291, %294 : i64
      llvm.store %293, %284 : i64, !llvm.ptr
      cf.br ^bb66
    ^bb68:
    %295 = arith.constant 2 : i32
    %296 = arith.extsi %295 : i32 to i64
    llvm.store %296, %284 : i64, !llvm.ptr
    cf.br ^bb69
    ^bb69:
    %297 = llvm.load %284 : !llvm.ptr -> i64
    %298 = llvm.load %284 : !llvm.ptr -> i64
    %299 = arith.muli %297, %298 : i64
    %300 = arith.cmpi sle, %299, %238 : i64
    cf.cond_br %300, ^bb70, ^bb71
    ^bb70:
      %302 = llvm.load %284 : !llvm.ptr -> i64
      %303 = llvm.getelementptr %239[%302] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %301 = llvm.load %303 : !llvm.ptr -> i8
      %304 = arith.constant 1 : i32
      %306 = arith.extsi %301 : i8 to i32
      %305 = arith.cmpi eq, %306, %304 : i32
      cf.cond_br %305, ^bb72, ^bb73
      ^bb72:
        %307 = llvm.load %284 : !llvm.ptr -> i64
        %308 = llvm.load %284 : !llvm.ptr -> i64
        %309 = arith.muli %307, %308 : i64
        %310 = llvm.mlir.constant(1 : i64) : i64
        %311 = llvm.alloca %310 x i64 : (i64) -> !llvm.ptr
        llvm.store %309, %311 : i64, !llvm.ptr
        cf.br ^bb75
        ^bb75:
        %312 = llvm.load %311 : !llvm.ptr -> i64
        %313 = arith.cmpi sle, %312, %238 : i64
        cf.cond_br %313, ^bb76, ^bb77
        ^bb76:
          %314 = arith.constant 0 : i32
          %315 = llvm.load %311 : !llvm.ptr -> i64
          %316 = arith.trunci %314 : i32 to i8
          %317 = llvm.getelementptr %239[%315] : (!llvm.ptr, i64) -> !llvm.ptr, i8
          llvm.store %316, %317 : i8, !llvm.ptr
          %318 = llvm.load %311 : !llvm.ptr -> i64
          %319 = llvm.load %284 : !llvm.ptr -> i64
          %320 = arith.addi %318, %319 : i64
          llvm.store %320, %311 : i64, !llvm.ptr
          cf.br ^bb75
        ^bb77:
        cf.br ^bb74
      ^bb73:
        cf.br ^bb74
      ^bb74:
      %321 = llvm.load %284 : !llvm.ptr -> i64
      %322 = arith.constant 1 : i32
      %324 = arith.extsi %322 : i32 to i64
      %323 = arith.addi %321, %324 : i64
      llvm.store %323, %284 : i64, !llvm.ptr
      cf.br ^bb69
    ^bb71:
    %325 = arith.constant 0 : i32
    %326 = arith.extsi %325 : i32 to i64
    %327 = llvm.mlir.constant(1 : i64) : i64
    %328 = llvm.alloca %327 x i64 : (i64) -> !llvm.ptr
    llvm.store %326, %328 : i64, !llvm.ptr
    %329 = arith.constant 2 : i32
    %330 = arith.extsi %329 : i32 to i64
    llvm.store %330, %284 : i64, !llvm.ptr
    cf.br ^bb78
    ^bb78:
    %331 = llvm.load %284 : !llvm.ptr -> i64
    %332 = arith.cmpi sle, %331, %238 : i64
    cf.cond_br %332, ^bb79, ^bb80
    ^bb79:
      %334 = llvm.load %284 : !llvm.ptr -> i64
      %335 = llvm.getelementptr %239[%334] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %333 = llvm.load %335 : !llvm.ptr -> i8
      %336 = arith.constant 1 : i32
      %338 = arith.extsi %333 : i8 to i32
      %337 = arith.cmpi eq, %338, %336 : i32
      cf.cond_br %337, ^bb81, ^bb82
      ^bb81:
        %339 = llvm.load %284 : !llvm.ptr -> i64
        %340 = arith.trunci %339 : i64 to i32
        %341 = llvm.load %328 : !llvm.ptr -> i64
        %342 = llvm.getelementptr %245[%341] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %340, %342 : i32, !llvm.ptr
        %343 = llvm.load %328 : !llvm.ptr -> i64
        %344 = arith.constant 1 : i32
        %346 = arith.extsi %344 : i32 to i64
        %345 = arith.addi %343, %346 : i64
        llvm.store %345, %328 : i64, !llvm.ptr
        cf.br ^bb83
      ^bb82:
        cf.br ^bb83
      ^bb83:
      %347 = llvm.load %284 : !llvm.ptr -> i64
      %348 = arith.constant 1 : i32
      %350 = arith.extsi %348 : i32 to i64
      %349 = arith.addi %347, %350 : i64
      llvm.store %349, %284 : i64, !llvm.ptr
      cf.br ^bb78
    ^bb80:
    %351 = arith.constant 2 : i32
    %352 = arith.extsi %351 : i32 to i64
    %353 = llvm.mlir.constant(1 : i64) : i64
    %354 = llvm.alloca %353 x i64 : (i64) -> !llvm.ptr
    llvm.store %352, %354 : i64, !llvm.ptr
    cf.br ^bb84
    ^bb84:
    %355 = llvm.load %354 : !llvm.ptr -> i64
    %356 = arith.cmpi sle, %355, %238 : i64
    cf.cond_br %356, ^bb85, ^bb86
    ^bb85:
      %357 = llvm.load %354 : !llvm.ptr -> i64
      %358 = arith.constant 1 : i32
      %360 = arith.extsi %358 : i32 to i64
      %359 = arith.subi %357, %360 : i64
      %361 = llvm.load %354 : !llvm.ptr -> i64
      %362 = llvm.getelementptr %254[%361] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %359, %362 : i64, !llvm.ptr
      %363 = llvm.load %354 : !llvm.ptr -> i64
      %364 = arith.constant 1 : i32
      %366 = arith.extsi %364 : i32 to i64
      %365 = arith.addi %363, %366 : i64
      llvm.store %365, %354 : i64, !llvm.ptr
      cf.br ^bb84
    ^bb86:
    %367 = arith.constant 1 : i32
    %368 = arith.extsi %367 : i32 to i64
    %369 = llvm.mlir.constant(1 : i64) : i64
    %370 = llvm.alloca %369 x i64 : (i64) -> !llvm.ptr
    llvm.store %368, %370 : i64, !llvm.ptr
    cf.br ^bb87
    ^bb87:
    %371 = llvm.load %370 : !llvm.ptr -> i64
    %372 = arith.cmpi sle, %371, %238 : i64
    cf.cond_br %372, ^bb88, ^bb89
    ^bb88:
      %373 = llvm.load %370 : !llvm.ptr -> i64
      %374 = arith.divsi %237, %373 : i64
      %375 = arith.constant 1 : i32
      %377 = arith.extsi %375 : i32 to i64
      %376 = arith.subi %374, %377 : i64
      %378 = llvm.load %370 : !llvm.ptr -> i64
      %379 = llvm.getelementptr %260[%378] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %376, %379 : i64, !llvm.ptr
      %380 = llvm.load %370 : !llvm.ptr -> i64
      %381 = arith.constant 1 : i32
      %383 = arith.extsi %381 : i32 to i64
      %382 = arith.addi %380, %383 : i64
      llvm.store %382, %370 : i64, !llvm.ptr
      cf.br ^bb87
    ^bb89:
    %384 = arith.constant 0 : i32
    %385 = arith.extsi %384 : i32 to i64
    %386 = llvm.mlir.constant(1 : i64) : i64
    %387 = llvm.alloca %386 x i64 : (i64) -> !llvm.ptr
    llvm.store %385, %387 : i64, !llvm.ptr
    cf.br ^bb90
    ^bb90:
    %388 = llvm.load %387 : !llvm.ptr -> i64
    %389 = llvm.load %328 : !llvm.ptr -> i64
    %390 = arith.cmpi slt, %388, %389 : i64
    cf.cond_br %390, ^bb91, ^bb92
    ^bb91:
      %392 = llvm.load %387 : !llvm.ptr -> i64
      %393 = llvm.getelementptr %245[%392] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %391 = llvm.load %393 : !llvm.ptr -> i32
      %394 = arith.extsi %391 : i32 to i64
      %395 = arith.muli %394, %394 : i64
      %396 = arith.cmpi sgt, %395, %237 : i64
      cf.cond_br %396, ^bb93, ^bb94
      ^bb93:
        cf.br ^bb92
      ^bb94:
        cf.br ^bb95
      ^bb95:
      %398 = arith.constant 1 : i32
      %400 = arith.extsi %398 : i32 to i64
      %399 = arith.subi %394, %400 : i64
      %401 = llvm.getelementptr %254[%399] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %397 = llvm.load %401 : !llvm.ptr -> i64
      %402 = llvm.mlir.constant(1 : i64) : i64
      %403 = llvm.alloca %402 x i64 : (i64) -> !llvm.ptr
      llvm.store %238, %403 : i64, !llvm.ptr
      %404 = arith.divsi %237, %395 : i64
      %405 = llvm.load %403 : !llvm.ptr -> i64
      %406 = arith.cmpi slt, %404, %405 : i64
      cf.cond_br %406, ^bb96, ^bb97
      ^bb96:
        %407 = arith.divsi %237, %395 : i64
        llvm.store %407, %403 : i64, !llvm.ptr
        cf.br ^bb98
      ^bb97:
        cf.br ^bb98
      ^bb98:
      %408 = arith.constant 1 : i32
      %409 = arith.extsi %408 : i32 to i64
      llvm.store %409, %370 : i64, !llvm.ptr
      cf.br ^bb99
      ^bb99:
      %410 = llvm.load %370 : !llvm.ptr -> i64
      %411 = llvm.load %403 : !llvm.ptr -> i64
      %412 = arith.cmpi sle, %410, %411 : i64
      cf.cond_br %412, ^bb100, ^bb101
      ^bb100:
        %413 = llvm.load %370 : !llvm.ptr -> i64
        %414 = arith.muli %394, %413 : i64
        %415 = arith.cmpi sle, %414, %238 : i64
        cf.cond_br %415, ^bb102, ^bb103
        ^bb102:
          %417 = llvm.load %370 : !llvm.ptr -> i64
          %418 = llvm.getelementptr %260[%417] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %416 = llvm.load %418 : !llvm.ptr -> i64
          %420 = llvm.getelementptr %260[%414] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %419 = llvm.load %420 : !llvm.ptr -> i64
          %421 = arith.subi %419, %397 : i64
          %422 = arith.subi %416, %421 : i64
          %423 = llvm.load %370 : !llvm.ptr -> i64
          %424 = llvm.getelementptr %260[%423] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          llvm.store %422, %424 : i64, !llvm.ptr
          cf.br ^bb104
        ^bb103:
          %426 = llvm.load %370 : !llvm.ptr -> i64
          %427 = llvm.getelementptr %260[%426] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %425 = llvm.load %427 : !llvm.ptr -> i64
          %429 = arith.divsi %237, %414 : i64
          %430 = llvm.getelementptr %254[%429] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %428 = llvm.load %430 : !llvm.ptr -> i64
          %431 = arith.subi %428, %397 : i64
          %432 = arith.subi %425, %431 : i64
          %433 = llvm.load %370 : !llvm.ptr -> i64
          %434 = llvm.getelementptr %260[%433] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          llvm.store %432, %434 : i64, !llvm.ptr
          cf.br ^bb104
        ^bb104:
        %435 = llvm.load %370 : !llvm.ptr -> i64
        %436 = arith.constant 1 : i32
        %438 = arith.extsi %436 : i32 to i64
        %437 = arith.addi %435, %438 : i64
        llvm.store %437, %370 : i64, !llvm.ptr
        cf.br ^bb99
      ^bb101:
      llvm.store %238, %354 : i64, !llvm.ptr
      cf.br ^bb105
      ^bb105:
      %439 = llvm.load %354 : !llvm.ptr -> i64
      %440 = arith.cmpi sge, %439, %395 : i64
      cf.cond_br %440, ^bb106, ^bb107
      ^bb106:
        %442 = llvm.load %354 : !llvm.ptr -> i64
        %443 = llvm.getelementptr %254[%442] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %441 = llvm.load %443 : !llvm.ptr -> i64
        %445 = llvm.load %354 : !llvm.ptr -> i64
        %446 = arith.divsi %445, %394 : i64
        %447 = llvm.getelementptr %254[%446] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %444 = llvm.load %447 : !llvm.ptr -> i64
        %448 = arith.subi %444, %397 : i64
        %449 = arith.subi %441, %448 : i64
        %450 = llvm.load %354 : !llvm.ptr -> i64
        %451 = llvm.getelementptr %254[%450] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %449, %451 : i64, !llvm.ptr
        %452 = llvm.load %354 : !llvm.ptr -> i64
        %453 = arith.constant 1 : i32
        %455 = arith.extsi %453 : i32 to i64
        %454 = arith.subi %452, %455 : i64
        llvm.store %454, %354 : i64, !llvm.ptr
        cf.br ^bb105
      ^bb107:
      %456 = llvm.load %387 : !llvm.ptr -> i64
      %457 = arith.constant 1 : i32
      %459 = arith.extsi %457 : i32 to i64
      %458 = arith.addi %456, %459 : i64
      llvm.store %458, %387 : i64, !llvm.ptr
      cf.br ^bb90
    ^bb92:
    %460 = arith.constant 0 : i32
    %461 = arith.extsi %460 : i32 to i64
    %462 = llvm.mlir.constant(1 : i64) : i64
    %463 = llvm.alloca %462 x i64 : (i64) -> !llvm.ptr
    llvm.store %461, %463 : i64, !llvm.ptr
    %465 = arith.constant 3 : i32
    %464 = func.call @iroot(%237, %465) : (i64, i32) -> i64
    %466 = arith.constant 0 : i32
    %467 = arith.extsi %466 : i32 to i64
    %468 = llvm.mlir.constant(1 : i64) : i64
    %469 = llvm.alloca %468 x i64 : (i64) -> !llvm.ptr
    llvm.store %467, %469 : i64, !llvm.ptr
    cf.br ^bb108
    ^bb108:
    %470 = llvm.load %469 : !llvm.ptr -> i64
    %471 = llvm.load %328 : !llvm.ptr -> i64
    %472 = arith.cmpi slt, %470, %471 : i64
    %473 = scf.if %472 -> (i1) {
      %475 = llvm.load %469 : !llvm.ptr -> i64
      %476 = llvm.getelementptr %245[%475] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %474 = llvm.load %476 : !llvm.ptr -> i32
      %477 = arith.extsi %474 : i32 to i64
      %478 = arith.cmpi sle, %477, %464 : i64
      scf.yield %478 : i1
    } else {
      %479 = arith.constant false
      scf.yield %479 : i1
    }
    cf.cond_br %473, ^bb109, ^bb110
    ^bb109:
      %480 = llvm.load %469 : !llvm.ptr -> i64
      %481 = arith.constant 1 : i32
      %483 = arith.extsi %481 : i32 to i64
      %482 = arith.addi %480, %483 : i64
      llvm.store %482, %469 : i64, !llvm.ptr
      cf.br ^bb108
    ^bb110:
    %484 = arith.constant 0 : i32
    %485 = arith.extsi %484 : i32 to i64
    %486 = llvm.mlir.constant(1 : i64) : i64
    %487 = llvm.alloca %486 x i64 : (i64) -> !llvm.ptr
    llvm.store %485, %487 : i64, !llvm.ptr
    cf.br ^bb111
    ^bb111:
    %488 = llvm.load %487 : !llvm.ptr -> i64
    %489 = llvm.load %469 : !llvm.ptr -> i64
    %490 = arith.cmpi slt, %488, %489 : i64
    cf.cond_br %490, ^bb112, ^bb113
    ^bb112:
      %492 = llvm.load %487 : !llvm.ptr -> i64
      %493 = llvm.getelementptr %245[%492] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %491 = llvm.load %493 : !llvm.ptr -> i32
      %494 = arith.extsi %491 : i32 to i64
      %495 = arith.muli %494, %494 : i64
      %496 = arith.muli %495, %494 : i64
      %497 = arith.cmpi sge, %496, %237 : i64
      cf.cond_br %497, ^bb114, ^bb115
      ^bb114:
        cf.br ^bb113
      ^bb115:
        cf.br ^bb116
      ^bb116:
      %499 = arith.divsi %237, %494 : i64
      %498 = func.call @isqrt(%499) : (i64) -> i64
      %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
      cf.br ^bb117
      ^bb117:
      %504 = llvm.load %503 : !llvm.ptr -> i64
      %505 = llvm.load %328 : !llvm.ptr -> i64
      %506 = arith.cmpi slt, %504, %505 : i64
      %507 = scf.if %506 -> (i1) {
        %509 = llvm.load %503 : !llvm.ptr -> i64
        %510 = llvm.getelementptr %245[%509] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %508 = llvm.load %510 : !llvm.ptr -> i32
        %511 = arith.extsi %508 : i32 to i64
        %512 = arith.cmpi sle, %511, %498 : i64
        scf.yield %512 : i1
      } else {
        %513 = arith.constant false
        scf.yield %513 : i1
      }
      cf.cond_br %507, ^bb118, ^bb119
      ^bb118:
        %514 = llvm.load %503 : !llvm.ptr -> i64
        %515 = arith.constant 1 : i32
        %517 = arith.extsi %515 : i32 to i64
        %516 = arith.addi %514, %517 : i64
        llvm.store %516, %503 : i64, !llvm.ptr
        cf.br ^bb117
      ^bb119:
      %518 = llvm.load %487 : !llvm.ptr -> i64
      %519 = arith.constant 1 : i32
      %521 = arith.extsi %519 : i32 to i64
      %520 = arith.addi %518, %521 : i64
      %522 = llvm.mlir.constant(1 : i64) : i64
      %523 = llvm.alloca %522 x i64 : (i64) -> !llvm.ptr
      llvm.store %520, %523 : i64, !llvm.ptr
      cf.br ^bb120
      ^bb120:
      %524 = llvm.load %523 : !llvm.ptr -> i64
      %525 = llvm.load %503 : !llvm.ptr -> i64
      %526 = arith.cmpi slt, %524, %525 : i64
      cf.cond_br %526, ^bb121, ^bb122
      ^bb121:
        %528 = llvm.load %523 : !llvm.ptr -> i64
        %529 = llvm.getelementptr %245[%528] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %527 = llvm.load %529 : !llvm.ptr -> i32
        %530 = arith.extsi %527 : i32 to i64
        %531 = arith.muli %494, %530 : i64
        %532 = arith.divsi %237, %531 : i64
        %533 = arith.cmpi sle, %532, %530 : i64
        cf.cond_br %533, ^bb123, ^bb124
        ^bb123:
          cf.br ^bb122
        ^bb124:
          cf.br ^bb125
        ^bb125:
        %534 = arith.constant 0 : i32
        %535 = arith.extsi %534 : i32 to i64
        %536 = llvm.mlir.constant(1 : i64) : i64
        %537 = llvm.alloca %536 x i64 : (i64) -> !llvm.ptr
        llvm.store %535, %537 : i64, !llvm.ptr
        %538 = arith.cmpi sle, %532, %238 : i64
        cf.cond_br %538, ^bb126, ^bb127
        ^bb126:
          %540 = llvm.getelementptr %254[%532] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %539 = llvm.load %540 : !llvm.ptr -> i64
          llvm.store %539, %537 : i64, !llvm.ptr
          cf.br ^bb128
        ^bb127:
          %542 = arith.divsi %237, %532 : i64
          %543 = llvm.getelementptr %260[%542] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %541 = llvm.load %543 : !llvm.ptr -> i64
          llvm.store %541, %537 : i64, !llvm.ptr
          cf.br ^bb128
        ^bb128:
        %544 = llvm.load %463 : !llvm.ptr -> i64
        %545 = llvm.load %537 : !llvm.ptr -> i64
        %546 = arith.addi %544, %545 : i64
        %547 = llvm.load %523 : !llvm.ptr -> i64
        %548 = arith.constant 1 : i32
        %550 = arith.extsi %548 : i32 to i64
        %549 = arith.addi %547, %550 : i64
        %551 = arith.subi %546, %549 : i64
        llvm.store %551, %463 : i64, !llvm.ptr
        %552 = llvm.load %523 : !llvm.ptr -> i64
        %553 = arith.constant 1 : i32
        %555 = arith.extsi %553 : i32 to i64
        %554 = arith.addi %552, %555 : i64
        llvm.store %554, %523 : i64, !llvm.ptr
        cf.br ^bb120
      ^bb122:
      %556 = llvm.load %487 : !llvm.ptr -> i64
      %557 = arith.constant 1 : i32
      %559 = arith.extsi %557 : i32 to i64
      %558 = arith.addi %556, %559 : i64
      llvm.store %558, %487 : i64, !llvm.ptr
      cf.br ^bb111
    ^bb113:
    %560 = arith.constant 0 : i32
    %561 = arith.extsi %560 : i32 to i64
    llvm.store %561, %487 : i64, !llvm.ptr
    cf.br ^bb129
    ^bb129:
    %562 = llvm.load %487 : !llvm.ptr -> i64
    %563 = llvm.load %469 : !llvm.ptr -> i64
    %564 = arith.cmpi slt, %562, %563 : i64
    cf.cond_br %564, ^bb130, ^bb131
    ^bb130:
      %566 = llvm.load %487 : !llvm.ptr -> i64
      %567 = llvm.getelementptr %245[%566] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %565 = llvm.load %567 : !llvm.ptr -> i32
      %568 = arith.extsi %565 : i32 to i64
      %569 = arith.muli %568, %568 : i64
      %570 = arith.muli %569, %568 : i64
      %571 = arith.cmpi sgt, %570, %237 : i64
      cf.cond_br %571, ^bb132, ^bb133
      ^bb132:
        cf.br ^bb131
      ^bb133:
        cf.br ^bb134
      ^bb134:
      %572 = arith.divsi %237, %570 : i64
      %573 = arith.constant 0 : i32
      %574 = arith.extsi %573 : i32 to i64
      %575 = llvm.mlir.constant(1 : i64) : i64
      %576 = llvm.alloca %575 x i64 : (i64) -> !llvm.ptr
      llvm.store %574, %576 : i64, !llvm.ptr
      %577 = arith.cmpi sle, %572, %238 : i64
      cf.cond_br %577, ^bb135, ^bb136
      ^bb135:
        %579 = llvm.getelementptr %254[%572] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %578 = llvm.load %579 : !llvm.ptr -> i64
        llvm.store %578, %576 : i64, !llvm.ptr
        cf.br ^bb137
      ^bb136:
        %581 = arith.divsi %237, %572 : i64
        %582 = llvm.getelementptr %260[%581] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %580 = llvm.load %582 : !llvm.ptr -> i64
        llvm.store %580, %576 : i64, !llvm.ptr
        cf.br ^bb137
      ^bb137:
      %583 = llvm.load %463 : !llvm.ptr -> i64
      %584 = llvm.load %576 : !llvm.ptr -> i64
      %585 = arith.addi %583, %584 : i64
      llvm.store %585, %463 : i64, !llvm.ptr
      %586 = llvm.load %487 : !llvm.ptr -> i64
      %587 = arith.constant 1 : i32
      %589 = arith.extsi %587 : i32 to i64
      %588 = arith.addi %586, %589 : i64
      llvm.store %588, %487 : i64, !llvm.ptr
      cf.br ^bb129
    ^bb131:
    %591 = arith.constant 4 : i32
    %590 = func.call @iroot(%237, %591) : (i64, i32) -> i64
    %592 = arith.cmpi sle, %590, %238 : i64
    cf.cond_br %592, ^bb138, ^bb139
    ^bb138:
      %593 = llvm.load %463 : !llvm.ptr -> i64
      %595 = llvm.getelementptr %254[%590] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %594 = llvm.load %595 : !llvm.ptr -> i64
      %596 = arith.subi %593, %594 : i64
      llvm.store %596, %463 : i64, !llvm.ptr
      cf.br ^bb140
    ^bb139:
      %597 = llvm.load %463 : !llvm.ptr -> i64
      %599 = arith.divsi %237, %590 : i64
      %600 = llvm.getelementptr %260[%599] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %598 = llvm.load %600 : !llvm.ptr -> i64
      %601 = arith.subi %597, %598 : i64
      llvm.store %601, %463 : i64, !llvm.ptr
      cf.br ^bb140
    ^bb140:
    %603 = arith.constant 7 : i32
    %602 = func.call @iroot(%237, %603) : (i64, i32) -> i64
    %604 = arith.cmpi sle, %602, %238 : i64
    cf.cond_br %604, ^bb141, ^bb142
    ^bb141:
      %605 = llvm.load %463 : !llvm.ptr -> i64
      %607 = llvm.getelementptr %254[%602] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %606 = llvm.load %607 : !llvm.ptr -> i64
      %608 = arith.addi %605, %606 : i64
      llvm.store %608, %463 : i64, !llvm.ptr
      cf.br ^bb143
    ^bb142:
      %609 = llvm.load %463 : !llvm.ptr -> i64
      %611 = arith.divsi %237, %602 : i64
      %612 = llvm.getelementptr %260[%611] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %610 = llvm.load %612 : !llvm.ptr -> i64
      %613 = arith.addi %609, %610 : i64
      llvm.store %613, %463 : i64, !llvm.ptr
      cf.br ^bb143
    ^bb143:
    %614 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %615 = llvm.load %463 : !llvm.ptr -> i64
    %616 = llvm.call @printf(%614, %615) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    func.call @free(%239) : (!llvm.ptr) -> ()
    func.call @free(%245) : (!llvm.ptr) -> ()
    func.call @free(%254) : (!llvm.ptr) -> ()
    func.call @free(%260) : (!llvm.ptr) -> ()
    %621 = arith.constant 0 : i32
    func.return %621 : i32
  }
}