Problem 370

Count geometric integer triangles with perimeter ≤ 2.5·10^13.

Answer41791929448408
Output41791929448408
StatusPASS
Native helperno
Runtime11480 ms
Peak memory13360 KB
Time complexityO(n^2) (estimated)
Space complexityO(n^2) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^2)O(n^2)
Space complexityO(n^2)O(n^2)
ApproachFlow solutionBottom-up DP
VerdictOptimal

Flow source

# Project Euler 370
# Count geometric integer triangles with perimeter ≤ 2.5·10^13.

import euler.nt { gcd }

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

# Hardware-sqrt integer square root (much faster than Newton iteration,
# which was called ~35M times in the inner loop).
function isq(n: i64) -> i64 {
    if n <= 0 { return 0 }
    let r: i64 = sqrt(n as f64) as i64
    while r > 0 && r * r > n { r = r - 1 }
    while (r + 1) * (r + 1) <= n { r = r + 1 }
    return r
}

function main() -> i32 {
    let N: i64 = 25000000000000
    let n_max: i64 = isq(N / 3)
    let spf: ptr<i32> = calloc(n_max + 1, 4)
    let primes: ptr<i32> = calloc(n_max / 5 + 10, 4)
    if spf == null || primes == null { return 1 }

    let mut pc: i64 = 0
    for i in 2..(n_max + 1) {
        if spf[i] == 0 {
            spf[i] = i as i32
            primes[pc] = i as i32
            pc = pc + 1
        }
        let mut j: i64 = 0
        while j < pc {
            let p: i64 = primes[j] as i64
            let v: i64 = i * p
            if v > n_max { break }
            spf[v] = p as i32
            if p == (spf[i] as i64) { break }
            j = j + 1
        }
    }
    if n_max >= 1 { spf[1] = 1 }

    # threshold heuristic
    let mut threshold: i64 = 200
    let t3: i64 = isq(isq(N / 16))
    # (N/16)^(1/3) approx
    let mut lo: i64 = 1
    let mut hi: i64 = 1000000
    while lo + 1 < hi {
        let mid: i64 = (lo + hi) / 2
        if mid * mid * mid <= N / 16 { lo = mid } else { hi = mid }
    }
    if lo > threshold { threshold = lo }

    let mut total: i64 = 0
    let mut n: i64 = 1
    while n <= n_max {
        let nn: i64 = n * n
        let m_ratio: i64 = (n + isq(5 * nn)) / 2
        let disc: i64 = 4 * N - 3 * nn
        if disc >= 0 {
            let m_perim: i64 = (isq(disc) - n) / 2
            let mut m_max: i64 = m_ratio
            if m_perim < m_max { m_max = m_perim }
            if m_max >= n {
                if n <= threshold {
                    let mut m: i64 = n
                    while m <= m_max {
                        if gcd(m, n) == 1 {
                            total = total + N / (m * m + m * n + nn)
                        }
                        m = m + 1
                    }
                } else {
                    # squarefree divisors of n via distinct primes
                    # n can have seven distinct prime factors (2·3·5·7·11·13·17),
                    # hence up to 128 square-free divisors.
                    let divs: ptr<i64> = calloc(128, 8)
                    let mus: ptr<i32> = calloc(128, 4)
                    if divs == null || mus == null { return 1 }
                    divs[0] = 1
                    mus[0] = 1
                    let mut dlen: i64 = 1
                    let mut x: i64 = n
                    while x > 1 {
                        let p: i64 = spf[x] as i64
                        while x % p == 0 { x = x / p }
                        let L: i64 = dlen
                        for t in 0..L {
                            divs[dlen] = divs[t] * p
                            mus[dlen] = 0 - mus[t]
                            dlen = dlen + 1
                        }
                    }
                    let mut m: i64 = n
                    while m <= m_max {
                        let S: i64 = m * m + m * n + nn
                        let q: i64 = N / S
                        let Thigh: i64 = N / q
                        let disc2: i64 = 4 * Thigh - 3 * nn
                        let mut mend: i64 = (isq(disc2) - n) / 2
                        if mend > m_max { mend = m_max }
                        # count coprime m in [m,mend]
                        let mut cnt: i64 = 0
                        let a_minus_1: i64 = m - 1
                        for di in 0..dlen {
                            let d: i64 = divs[di]
                            let mu: i64 = mus[di] as i64
                            cnt = cnt + mu * (mend / d - a_minus_1 / d)
                        }
                        total = total + q * cnt
                        m = mend + 1
                    }
                    free(mus)
                    free(divs)
                }
            }
        }
        n = n + 1
    }

    printf("%lld\n", total)
    free(primes)
    free(spf)
    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 isq_i64(int64_t n);
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 isq_i64(int64_t n) {
    if (n <= 0) {
        return 0;
    }
    int64_t r = ((int64_t)(sqrt(((double)(n)))));
    while ((r > 0 && (r * r) > n)) {
        r = (r - 1);
    }
    while (((r + 1) * (r + 1)) <= n) {
        r = (r + 1);
    }
    return r;
}

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