Problem 420

F(10^7): 2x2 matrices with two distinct positive integer square roots.

Answer145159332
Output145159332
StatusPASS
Native helperno
Runtime250 ms
Peak memory238144 KB
Time complexityO(n^2) (estimated)
Space complexityO(n^2) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^2)?
Space complexityO(n^2)?
ApproachFlow solutionNot curated
VerdictUnknown

Flow source

# Project Euler 420
# F(10^7): 2x2 matrices with two distinct positive integer square roots.

import euler.nt { gcd, isqrt }

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

function main() -> i32 {
    let N: i64 = 10000000
    let Umax: i64 = isqrt(N - 2)
    let Kmax: i64 = 2 * Umax
    let M: i64 = (Kmax * Kmax) / 4

    let d: ptr<i32> = calloc(M + 1, 4)
    let spf: ptr<i32> = calloc(M + 1, 4)
    let expn: ptr<i8> = calloc(M + 1, 1)
    let primes: ptr<i32> = calloc(M / 5 + 10, 4)
    if d == null || spf == null || expn == null || primes == null { return 1 }

    d[1] = 1
    let mut pc: i64 = 0
    let mut i: i64 = 2
    while i <= M {
        if spf[i] == 0 {
            spf[i] = i as i32
            primes[pc] = i as i32
            pc = pc + 1
            expn[i] = 1
            d[i] = 2
        }
        let si: i64 = spf[i] as i64
        let di: i64 = d[i] as i64
        let ei: i64 = expn[i] as i64
        let mut pi: i64 = 0
        while pi < pc {
            let p: i64 = primes[pi] as i64
            let ip: i64 = i * p
            if ip > M { break }
            spf[ip] = p as i32
            if p == si {
                expn[ip] = (ei + 1) as i8
                d[ip] = (di / (ei + 1) * (ei + 2)) as i32
                break
            } else {
                expn[ip] = 1
                d[ip] = (di * 2) as i32
            }
            pi = pi + 1
        }
        i = i + 1
    }

    # prefix[K] stored flat: for each K, K entries. Total sum_{K=2}^{Kmax} K ~ Kmax^2/2
    let pref_size: i64 = (Kmax + 1) * (Kmax + 1)
    let prefix: ptr<i32> = calloc(pref_size, 4)
    if prefix == null { return 1 }
    let mut K: i64 = 2
    while K <= Kmax {
        let base: i64 = K * (Kmax + 1)
        let mut s: i64 = 0
        let mut a: i64 = 1
        while a < K {
            s = s + (d[a * (K - a)] as i64)
            prefix[base + a] = s as i32
            a = a + 1
        }
        K = K + 1
    }

    let mut total: i64 = 0
    let mut u: i64 = 2
    while u <= Umax {
        let mut vmax: i64 = isqrt(N - 1 - u * u)
        if vmax >= u { vmax = u - 1 }
        let mut v: i64 = 1
        while v <= vmax {
            let g: i64 = gcd(u, v)
            let uu: i64 = u / g
            let vv: i64 = v / g
            let mut delta: i64 = 1
            if (uu % 2 == 1) && (vv % 2 == 1) { delta = 2 }
            K = g * delta
            if K > 1 {
                let s: i64 = u + v
                let mut low: i64 = (v * K) / s + 1
                let mut high: i64 = (u * K - 1) / s
                if low < 1 { low = 1 }
                if high > K - 1 { high = K - 1 }
                if low <= high {
                    let base: i64 = K * (Kmax + 1)
                    total = total + (prefix[base + high] as i64) - (prefix[base + low - 1] as i64)
                }
            }
            v = v + 1
        }
        u = u + 1
    }
    printf("%lld\n", total)
    free(prefix)
    free(primes)
    free(expn)
    free(spf)
    free(d)
    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);
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;
}



int32_t main(void) {
    int64_t N = 10000000;
    int64_t Umax = isqrt_i64((N - 2));
    int64_t Kmax = (2 * Umax);
    int64_t M = FLOW_CHECKED_DIV(((Kmax * Kmax)), (4));
    int32_t* d = (int32_t*)(calloc((M + 1), 4));
    int32_t* spf = (int32_t*)(calloc((M + 1), 4));
    int8_t* expn = (int8_t*)(calloc((M + 1), 1));
    int32_t* primes = (int32_t*)(calloc((FLOW_CHECKED_DIV((M), (5)) + 10), 4));
    if ((((d == NULL || spf == NULL) || expn == NULL) || primes == NULL)) {
        return 1;
    }
    d[1] = 1;
    int64_t pc = 0;
    int64_t i = 2;
    while (i <= M) {
        if (spf[i] == 0) {
            spf[i] = ((int32_t)(i));
            primes[pc] = ((int32_t)(i));
            pc = (pc + 1);
            expn[i] = 1;
            d[i] = 2;
        }
        int64_t si = ((int64_t)(spf[i]));
        int64_t di = ((int64_t)(d[i]));
        int64_t ei = ((int64_t)(expn[i]));
        int64_t pi = 0;
        while (pi < pc) {
            int64_t p = ((int64_t)(primes[pi]));
            int64_t ip = (i * p);
            if (ip > M) {
                break;
            }
            spf[ip] = ((int32_t)(p));
            if (p == si) {
                expn[ip] = ((int8_t)((ei + 1)));
                d[ip] = ((int32_t)((FLOW_CHECKED_DIV((di), ((ei + 1))) * (ei + 2))));
                break;
            } else {
                expn[ip] = 1;
                d[ip] = ((int32_t)((di * 2)));
            }
            pi = (pi + 1);
        }
        i = (i + 1);
    }
    int64_t pref_size = ((Kmax + 1) * (Kmax + 1));
    int32_t* prefix = (int32_t*)(calloc(pref_size, 4));
    if (prefix == NULL) {
        return 1;
    }
    int64_t K = 2;
    while (K <= Kmax) {
        int64_t base = (K * (Kmax + 1));
        int64_t s = 0;
        int64_t a = 1;
        while (a < K) {
            s = (s + ((int64_t)(d[(a * (K - a))])));
            prefix[(base + a)] = ((int32_t)(s));
            a = (a + 1);
        }
        K = (K + 1);
    }
    int64_t total = 0;
    int64_t u = 2;
    while (u <= Umax) {
        int64_t vmax = isqrt_i64(((N - 1) - (u * u)));
        if (vmax >= u) {
            vmax = (u - 1);
        }
        int64_t v = 1;
        while (v <= vmax) {
            int64_t g = gcd_i64_i64(u, v);
            int64_t uu = FLOW_CHECKED_DIV((u), (g));
            int64_t vv = FLOW_CHECKED_DIV((v), (g));
            int64_t delta = 1;
            if ((FLOW_CHECKED_MOD((uu), (2)) == 1 && FLOW_CHECKED_MOD((vv), (2)) == 1)) {
                delta = 2;
            }
            K = (g * delta);
            if (K > 1) {
                int64_t s = (u + v);
                int64_t low = (FLOW_CHECKED_DIV(((v * K)), (s)) + 1);
                int64_t high = FLOW_CHECKED_DIV((((u * K) - 1)), (s));
                if (low < 1) {
                    low = 1;
                }
                if (high > (K - 1)) {
                    high = (K - 1);
                }
                if (low <= high) {
                    int64_t base = (K * (Kmax + 1));
                    total = ((total + ((int64_t)(prefix[(base + high)]))) - ((int64_t)(prefix[((base + low) - 1)])));
                }
            }
            v = (v + 1);
        }
        u = (u + 1);
    }
    printf("%lld\n", total);
    free(prefix);
    free(primes);
    free(expn);
    free(spf);
    free(d);
    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 @main() -> i32 {
    %175 = arith.constant 10000000 : i32
    %176 = arith.extsi %175 : i32 to i64
    %178 = arith.constant 2 : i32
    %180 = arith.extsi %178 : i32 to i64
    %179 = arith.subi %176, %180 : i64
    %177 = func.call @isqrt(%179) : (i64) -> i64
    %181 = arith.constant 2 : i32
    %183 = arith.extsi %181 : i32 to i64
    %182 = arith.muli %183, %177 : i64
    %184 = arith.muli %182, %182 : i64
    %185 = arith.constant 4 : i32
    %187 = arith.extsi %185 : i32 to i64
    %186 = arith.divsi %184, %187 : i64
    %189 = arith.constant 1 : i32
    %191 = arith.extsi %189 : i32 to i64
    %190 = arith.addi %186, %191 : i64
    %192 = arith.constant 4 : i32
    %193 = arith.extsi %192 : i32 to i64
    %188 = func.call @calloc(%190, %193) : (i64, i64) -> !llvm.ptr
    %195 = arith.constant 1 : i32
    %197 = arith.extsi %195 : i32 to i64
    %196 = arith.addi %186, %197 : i64
    %198 = arith.constant 4 : i32
    %199 = arith.extsi %198 : i32 to i64
    %194 = func.call @calloc(%196, %199) : (i64, i64) -> !llvm.ptr
    %201 = arith.constant 1 : i32
    %203 = arith.extsi %201 : i32 to i64
    %202 = arith.addi %186, %203 : i64
    %204 = arith.constant 1 : i32
    %205 = arith.extsi %204 : i32 to i64
    %200 = func.call @calloc(%202, %205) : (i64, i64) -> !llvm.ptr
    %207 = arith.constant 5 : i32
    %209 = arith.extsi %207 : i32 to i64
    %208 = arith.divsi %186, %209 : i64
    %210 = arith.constant 10 : i32
    %212 = arith.extsi %210 : i32 to i64
    %211 = arith.addi %208, %212 : i64
    %213 = arith.constant 4 : i32
    %214 = arith.extsi %213 : i32 to i64
    %206 = func.call @calloc(%211, %214) : (i64, i64) -> !llvm.ptr
    %215 = llvm.mlir.zero : !llvm.ptr
    %216 = llvm.icmp "eq" %188, %215 : !llvm.ptr
    %217 = scf.if %216 -> (i1) {
      %218 = arith.constant true
      scf.yield %218 : i1
    } else {
      %219 = llvm.mlir.zero : !llvm.ptr
      %220 = llvm.icmp "eq" %194, %219 : !llvm.ptr
      scf.yield %220 : i1
    }
    %221 = scf.if %217 -> (i1) {
      %222 = arith.constant true
      scf.yield %222 : i1
    } else {
      %223 = llvm.mlir.zero : !llvm.ptr
      %224 = llvm.icmp "eq" %200, %223 : !llvm.ptr
      scf.yield %224 : i1
    }
    %225 = scf.if %221 -> (i1) {
      %226 = arith.constant true
      scf.yield %226 : i1
    } else {
      %227 = llvm.mlir.zero : !llvm.ptr
      %228 = llvm.icmp "eq" %206, %227 : !llvm.ptr
      scf.yield %228 : i1
    }
    cf.cond_br %225, ^bb42, ^bb43
    ^bb42:
      %229 = arith.constant 1 : i32
      func.return %229 : i32
    ^bb43:
      cf.br ^bb44
    ^bb44:
    %230 = arith.constant 1 : i32
    %231 = arith.constant 1 : i32
    %232 = arith.extsi %231 : i32 to i64
    %233 = llvm.getelementptr %188[%232] : (!llvm.ptr, i64) -> !llvm.ptr, i32
    llvm.store %230, %233 : i32, !llvm.ptr
    %234 = arith.constant 0 : i32
    %235 = arith.extsi %234 : i32 to i64
    %236 = llvm.mlir.constant(1 : i64) : i64
    %237 = llvm.alloca %236 x i64 : (i64) -> !llvm.ptr
    llvm.store %235, %237 : i64, !llvm.ptr
    %238 = arith.constant 2 : 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
    cf.br ^bb45
    ^bb45:
    %242 = llvm.load %241 : !llvm.ptr -> i64
    %243 = arith.cmpi sle, %242, %186 : i64
    cf.cond_br %243, ^bb46, ^bb47
    ^bb46:
      %245 = llvm.load %241 : !llvm.ptr -> i64
      %246 = llvm.getelementptr %194[%245] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %244 = llvm.load %246 : !llvm.ptr -> i32
      %247 = arith.constant 0 : i32
      %248 = arith.cmpi eq, %244, %247 : i32
      cf.cond_br %248, ^bb48, ^bb49
      ^bb48:
        %249 = llvm.load %241 : !llvm.ptr -> i64
        %250 = arith.trunci %249 : i64 to i32
        %251 = llvm.load %241 : !llvm.ptr -> i64
        %252 = llvm.getelementptr %194[%251] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %250, %252 : i32, !llvm.ptr
        %253 = llvm.load %241 : !llvm.ptr -> i64
        %254 = arith.trunci %253 : i64 to i32
        %255 = llvm.load %237 : !llvm.ptr -> i64
        %256 = llvm.getelementptr %206[%255] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %254, %256 : i32, !llvm.ptr
        %257 = llvm.load %237 : !llvm.ptr -> i64
        %258 = arith.constant 1 : i32
        %260 = arith.extsi %258 : i32 to i64
        %259 = arith.addi %257, %260 : i64
        llvm.store %259, %237 : i64, !llvm.ptr
        %261 = arith.constant 1 : i32
        %262 = llvm.load %241 : !llvm.ptr -> i64
        %263 = arith.trunci %261 : i32 to i8
        %264 = llvm.getelementptr %200[%262] : (!llvm.ptr, i64) -> !llvm.ptr, i8
        llvm.store %263, %264 : i8, !llvm.ptr
        %265 = arith.constant 2 : i32
        %266 = llvm.load %241 : !llvm.ptr -> i64
        %267 = llvm.getelementptr %188[%266] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %265, %267 : i32, !llvm.ptr
        cf.br ^bb50
      ^bb49:
        cf.br ^bb50
      ^bb50:
      %269 = llvm.load %241 : !llvm.ptr -> i64
      %270 = llvm.getelementptr %194[%269] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %268 = llvm.load %270 : !llvm.ptr -> i32
      %271 = arith.extsi %268 : i32 to i64
      %273 = llvm.load %241 : !llvm.ptr -> i64
      %274 = llvm.getelementptr %188[%273] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %272 = llvm.load %274 : !llvm.ptr -> i32
      %275 = arith.extsi %272 : i32 to i64
      %277 = llvm.load %241 : !llvm.ptr -> i64
      %278 = llvm.getelementptr %200[%277] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %276 = llvm.load %278 : !llvm.ptr -> i8
      %279 = arith.extsi %276 : i8 to i64
      %280 = arith.constant 0 : i32
      %281 = arith.extsi %280 : i32 to i64
      %282 = llvm.mlir.constant(1 : i64) : i64
      %283 = llvm.alloca %282 x i64 : (i64) -> !llvm.ptr
      llvm.store %281, %283 : i64, !llvm.ptr
      cf.br ^bb51
      ^bb51:
      %284 = llvm.load %283 : !llvm.ptr -> i64
      %285 = llvm.load %237 : !llvm.ptr -> i64
      %286 = arith.cmpi slt, %284, %285 : i64
      cf.cond_br %286, ^bb52, ^bb53
      ^bb52:
        %288 = llvm.load %283 : !llvm.ptr -> i64
        %289 = llvm.getelementptr %206[%288] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %287 = llvm.load %289 : !llvm.ptr -> i32
        %290 = arith.extsi %287 : i32 to i64
        %291 = llvm.load %241 : !llvm.ptr -> i64
        %292 = arith.muli %291, %290 : i64
        %293 = arith.cmpi sgt, %292, %186 : i64
        cf.cond_br %293, ^bb54, ^bb55
        ^bb54:
          cf.br ^bb53
        ^bb55:
          cf.br ^bb56
        ^bb56:
        %294 = arith.trunci %290 : i64 to i32
        %295 = llvm.getelementptr %194[%292] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %294, %295 : i32, !llvm.ptr
        %296 = arith.cmpi eq, %290, %271 : i64
        cf.cond_br %296, ^bb57, ^bb58
        ^bb57:
          %297 = arith.constant 1 : i32
          %299 = arith.extsi %297 : i32 to i64
          %298 = arith.addi %279, %299 : i64
          %300 = arith.trunci %298 : i64 to i8
          %301 = llvm.getelementptr %200[%292] : (!llvm.ptr, i64) -> !llvm.ptr, i8
          llvm.store %300, %301 : i8, !llvm.ptr
          %302 = arith.constant 1 : i32
          %304 = arith.extsi %302 : i32 to i64
          %303 = arith.addi %279, %304 : i64
          %305 = arith.divsi %275, %303 : i64
          %306 = arith.constant 2 : i32
          %308 = arith.extsi %306 : i32 to i64
          %307 = arith.addi %279, %308 : i64
          %309 = arith.muli %305, %307 : i64
          %310 = arith.trunci %309 : i64 to i32
          %311 = llvm.getelementptr %188[%292] : (!llvm.ptr, i64) -> !llvm.ptr, i32
          llvm.store %310, %311 : i32, !llvm.ptr
          cf.br ^bb53
        ^bb58:
          %312 = arith.constant 1 : i32
          %313 = arith.trunci %312 : i32 to i8
          %314 = llvm.getelementptr %200[%292] : (!llvm.ptr, i64) -> !llvm.ptr, i8
          llvm.store %313, %314 : i8, !llvm.ptr
          %315 = arith.constant 2 : i32
          %317 = arith.extsi %315 : i32 to i64
          %316 = arith.muli %275, %317 : i64
          %318 = arith.trunci %316 : i64 to i32
          %319 = llvm.getelementptr %188[%292] : (!llvm.ptr, i64) -> !llvm.ptr, i32
          llvm.store %318, %319 : i32, !llvm.ptr
          cf.br ^bb59
        ^bb59:
        %320 = llvm.load %283 : !llvm.ptr -> i64
        %321 = arith.constant 1 : i32
        %323 = arith.extsi %321 : i32 to i64
        %322 = arith.addi %320, %323 : i64
        llvm.store %322, %283 : i64, !llvm.ptr
        cf.br ^bb51
      ^bb53:
      %324 = llvm.load %241 : !llvm.ptr -> i64
      %325 = arith.constant 1 : i32
      %327 = arith.extsi %325 : i32 to i64
      %326 = arith.addi %324, %327 : i64
      llvm.store %326, %241 : i64, !llvm.ptr
      cf.br ^bb45
    ^bb47:
    %328 = arith.constant 1 : i32
    %330 = arith.extsi %328 : i32 to i64
    %329 = arith.addi %182, %330 : i64
    %331 = arith.constant 1 : i32
    %333 = arith.extsi %331 : i32 to i64
    %332 = arith.addi %182, %333 : i64
    %334 = arith.muli %329, %332 : i64
    %336 = arith.constant 4 : i32
    %337 = arith.extsi %336 : i32 to i64
    %335 = func.call @calloc(%334, %337) : (i64, i64) -> !llvm.ptr
    %338 = llvm.mlir.zero : !llvm.ptr
    %339 = llvm.icmp "eq" %335, %338 : !llvm.ptr
    cf.cond_br %339, ^bb60, ^bb61
    ^bb60:
      %340 = arith.constant 1 : i32
      func.return %340 : i32
    ^bb61:
      cf.br ^bb62
    ^bb62:
    %341 = arith.constant 2 : i32
    %342 = arith.extsi %341 : i32 to i64
    %343 = llvm.mlir.constant(1 : i64) : i64
    %344 = llvm.alloca %343 x i64 : (i64) -> !llvm.ptr
    llvm.store %342, %344 : i64, !llvm.ptr
    cf.br ^bb63
    ^bb63:
    %345 = llvm.load %344 : !llvm.ptr -> i64
    %346 = arith.cmpi sle, %345, %182 : i64
    cf.cond_br %346, ^bb64, ^bb65
    ^bb64:
      %347 = llvm.load %344 : !llvm.ptr -> i64
      %348 = arith.constant 1 : i32
      %350 = arith.extsi %348 : i32 to i64
      %349 = arith.addi %182, %350 : i64
      %351 = arith.muli %347, %349 : i64
      %352 = arith.constant 0 : i32
      %353 = arith.extsi %352 : i32 to i64
      %354 = llvm.mlir.constant(1 : i64) : i64
      %355 = llvm.alloca %354 x i64 : (i64) -> !llvm.ptr
      llvm.store %353, %355 : i64, !llvm.ptr
      %356 = arith.constant 1 : i32
      %357 = arith.extsi %356 : i32 to i64
      %358 = llvm.mlir.constant(1 : i64) : i64
      %359 = llvm.alloca %358 x i64 : (i64) -> !llvm.ptr
      llvm.store %357, %359 : i64, !llvm.ptr
      cf.br ^bb66
      ^bb66:
      %360 = llvm.load %359 : !llvm.ptr -> i64
      %361 = llvm.load %344 : !llvm.ptr -> i64
      %362 = arith.cmpi slt, %360, %361 : i64
      cf.cond_br %362, ^bb67, ^bb68
      ^bb67:
        %363 = llvm.load %355 : !llvm.ptr -> i64
        %365 = llvm.load %359 : !llvm.ptr -> i64
        %366 = llvm.load %344 : !llvm.ptr -> i64
        %367 = llvm.load %359 : !llvm.ptr -> i64
        %368 = arith.subi %366, %367 : i64
        %369 = arith.muli %365, %368 : i64
        %370 = llvm.getelementptr %188[%369] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %364 = llvm.load %370 : !llvm.ptr -> i32
        %371 = arith.extsi %364 : i32 to i64
        %372 = arith.addi %363, %371 : i64
        llvm.store %372, %355 : i64, !llvm.ptr
        %373 = llvm.load %355 : !llvm.ptr -> i64
        %374 = arith.trunci %373 : i64 to i32
        %375 = llvm.load %359 : !llvm.ptr -> i64
        %376 = arith.addi %351, %375 : i64
        %377 = llvm.getelementptr %335[%376] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %374, %377 : i32, !llvm.ptr
        %378 = llvm.load %359 : !llvm.ptr -> i64
        %379 = arith.constant 1 : i32
        %381 = arith.extsi %379 : i32 to i64
        %380 = arith.addi %378, %381 : i64
        llvm.store %380, %359 : i64, !llvm.ptr
        cf.br ^bb66
      ^bb68:
      %382 = llvm.load %344 : !llvm.ptr -> i64
      %383 = arith.constant 1 : i32
      %385 = arith.extsi %383 : i32 to i64
      %384 = arith.addi %382, %385 : i64
      llvm.store %384, %344 : i64, !llvm.ptr
      cf.br ^bb63
    ^bb65:
    %386 = arith.constant 0 : i32
    %387 = arith.extsi %386 : i32 to i64
    %388 = llvm.mlir.constant(1 : i64) : i64
    %389 = llvm.alloca %388 x i64 : (i64) -> !llvm.ptr
    llvm.store %387, %389 : i64, !llvm.ptr
    %390 = arith.constant 2 : i32
    %391 = arith.extsi %390 : i32 to i64
    %392 = llvm.mlir.constant(1 : i64) : i64
    %393 = llvm.alloca %392 x i64 : (i64) -> !llvm.ptr
    llvm.store %391, %393 : i64, !llvm.ptr
    cf.br ^bb69
    ^bb69:
    %394 = llvm.load %393 : !llvm.ptr -> i64
    %395 = arith.cmpi sle, %394, %177 : i64
    cf.cond_br %395, ^bb70, ^bb71
    ^bb70:
      %397 = arith.constant 1 : i32
      %399 = arith.extsi %397 : i32 to i64
      %398 = arith.subi %176, %399 : i64
      %400 = llvm.load %393 : !llvm.ptr -> i64
      %401 = llvm.load %393 : !llvm.ptr -> i64
      %402 = arith.muli %400, %401 : i64
      %403 = arith.subi %398, %402 : i64
      %396 = func.call @isqrt(%403) : (i64) -> i64
      %404 = llvm.mlir.constant(1 : i64) : i64
      %405 = llvm.alloca %404 x i64 : (i64) -> !llvm.ptr
      llvm.store %396, %405 : i64, !llvm.ptr
      %406 = llvm.load %405 : !llvm.ptr -> i64
      %407 = llvm.load %393 : !llvm.ptr -> i64
      %408 = arith.cmpi sge, %406, %407 : i64
      cf.cond_br %408, ^bb72, ^bb73
      ^bb72:
        %409 = llvm.load %393 : !llvm.ptr -> i64
        %410 = arith.constant 1 : i32
        %412 = arith.extsi %410 : i32 to i64
        %411 = arith.subi %409, %412 : i64
        llvm.store %411, %405 : i64, !llvm.ptr
        cf.br ^bb74
      ^bb73:
        cf.br ^bb74
      ^bb74:
      %413 = arith.constant 1 : i32
      %414 = arith.extsi %413 : i32 to i64
      %415 = llvm.mlir.constant(1 : i64) : i64
      %416 = llvm.alloca %415 x i64 : (i64) -> !llvm.ptr
      llvm.store %414, %416 : i64, !llvm.ptr
      cf.br ^bb75
      ^bb75:
      %417 = llvm.load %416 : !llvm.ptr -> i64
      %418 = llvm.load %405 : !llvm.ptr -> i64
      %419 = arith.cmpi sle, %417, %418 : i64
      cf.cond_br %419, ^bb76, ^bb77
      ^bb76:
        %421 = llvm.load %393 : !llvm.ptr -> i64
        %422 = llvm.load %416 : !llvm.ptr -> i64
        %420 = func.call @gcd(%421, %422) : (i64, i64) -> i64
        %423 = llvm.load %393 : !llvm.ptr -> i64
        %424 = arith.divsi %423, %420 : i64
        %425 = llvm.load %416 : !llvm.ptr -> i64
        %426 = arith.divsi %425, %420 : i64
        %427 = arith.constant 1 : i32
        %428 = arith.extsi %427 : i32 to i64
        %429 = llvm.mlir.constant(1 : i64) : i64
        %430 = llvm.alloca %429 x i64 : (i64) -> !llvm.ptr
        llvm.store %428, %430 : i64, !llvm.ptr
        %431 = arith.constant 2 : i32
        %433 = arith.extsi %431 : i32 to i64
        %432 = arith.remsi %424, %433 : i64
        %434 = arith.constant 1 : i32
        %436 = arith.extsi %434 : i32 to i64
        %435 = arith.cmpi eq, %432, %436 : i64
        %437 = scf.if %435 -> (i1) {
          %438 = arith.constant 2 : i32
          %440 = arith.extsi %438 : i32 to i64
          %439 = arith.remsi %426, %440 : i64
          %441 = arith.constant 1 : i32
          %443 = arith.extsi %441 : i32 to i64
          %442 = arith.cmpi eq, %439, %443 : i64
          scf.yield %442 : i1
        } else {
          %444 = arith.constant false
          scf.yield %444 : i1
        }
        cf.cond_br %437, ^bb78, ^bb79
        ^bb78:
          %445 = arith.constant 2 : i32
          %446 = arith.extsi %445 : i32 to i64
          llvm.store %446, %430 : i64, !llvm.ptr
          cf.br ^bb80
        ^bb79:
          cf.br ^bb80
        ^bb80:
        %447 = llvm.load %430 : !llvm.ptr -> i64
        %448 = arith.muli %420, %447 : i64
        llvm.store %448, %344 : i64, !llvm.ptr
        %449 = llvm.load %344 : !llvm.ptr -> i64
        %450 = arith.constant 1 : i32
        %452 = arith.extsi %450 : i32 to i64
        %451 = arith.cmpi sgt, %449, %452 : i64
        cf.cond_br %451, ^bb81, ^bb82
        ^bb81:
          %453 = llvm.load %393 : !llvm.ptr -> i64
          %454 = llvm.load %416 : !llvm.ptr -> i64
          %455 = arith.addi %453, %454 : i64
          %456 = llvm.load %416 : !llvm.ptr -> i64
          %457 = llvm.load %344 : !llvm.ptr -> i64
          %458 = arith.muli %456, %457 : i64
          %459 = arith.divsi %458, %455 : i64
          %460 = arith.constant 1 : i32
          %462 = arith.extsi %460 : i32 to i64
          %461 = arith.addi %459, %462 : i64
          %463 = llvm.mlir.constant(1 : i64) : i64
          %464 = llvm.alloca %463 x i64 : (i64) -> !llvm.ptr
          llvm.store %461, %464 : i64, !llvm.ptr
          %465 = llvm.load %393 : !llvm.ptr -> i64
          %466 = llvm.load %344 : !llvm.ptr -> i64
          %467 = arith.muli %465, %466 : i64
          %468 = arith.constant 1 : i32
          %470 = arith.extsi %468 : i32 to i64
          %469 = arith.subi %467, %470 : i64
          %471 = arith.divsi %469, %455 : i64
          %472 = llvm.mlir.constant(1 : i64) : i64
          %473 = llvm.alloca %472 x i64 : (i64) -> !llvm.ptr
          llvm.store %471, %473 : i64, !llvm.ptr
          %474 = llvm.load %464 : !llvm.ptr -> i64
          %475 = arith.constant 1 : i32
          %477 = arith.extsi %475 : i32 to i64
          %476 = arith.cmpi slt, %474, %477 : i64
          cf.cond_br %476, ^bb84, ^bb85
          ^bb84:
            %478 = arith.constant 1 : i32
            %479 = arith.extsi %478 : i32 to i64
            llvm.store %479, %464 : i64, !llvm.ptr
            cf.br ^bb86
          ^bb85:
            cf.br ^bb86
          ^bb86:
          %480 = llvm.load %473 : !llvm.ptr -> i64
          %481 = llvm.load %344 : !llvm.ptr -> i64
          %482 = arith.constant 1 : i32
          %484 = arith.extsi %482 : i32 to i64
          %483 = arith.subi %481, %484 : i64
          %485 = arith.cmpi sgt, %480, %483 : i64
          cf.cond_br %485, ^bb87, ^bb88
          ^bb87:
            %486 = llvm.load %344 : !llvm.ptr -> i64
            %487 = arith.constant 1 : i32
            %489 = arith.extsi %487 : i32 to i64
            %488 = arith.subi %486, %489 : i64
            llvm.store %488, %473 : i64, !llvm.ptr
            cf.br ^bb89
          ^bb88:
            cf.br ^bb89
          ^bb89:
          %490 = llvm.load %464 : !llvm.ptr -> i64
          %491 = llvm.load %473 : !llvm.ptr -> i64
          %492 = arith.cmpi sle, %490, %491 : i64
          cf.cond_br %492, ^bb90, ^bb91
          ^bb90:
            %493 = llvm.load %344 : !llvm.ptr -> i64
            %494 = arith.constant 1 : i32
            %496 = arith.extsi %494 : i32 to i64
            %495 = arith.addi %182, %496 : i64
            %497 = arith.muli %493, %495 : i64
            %498 = llvm.load %389 : !llvm.ptr -> i64
            %500 = llvm.load %473 : !llvm.ptr -> i64
            %501 = arith.addi %497, %500 : i64
            %502 = llvm.getelementptr %335[%501] : (!llvm.ptr, i64) -> !llvm.ptr, i32
            %499 = llvm.load %502 : !llvm.ptr -> i32
            %503 = arith.extsi %499 : i32 to i64
            %504 = arith.addi %498, %503 : i64
            %506 = llvm.load %464 : !llvm.ptr -> i64
            %507 = arith.addi %497, %506 : i64
            %508 = arith.constant 1 : i32
            %510 = arith.extsi %508 : i32 to i64
            %509 = arith.subi %507, %510 : i64
            %511 = llvm.getelementptr %335[%509] : (!llvm.ptr, i64) -> !llvm.ptr, i32
            %505 = llvm.load %511 : !llvm.ptr -> i32
            %512 = arith.extsi %505 : i32 to i64
            %513 = arith.subi %504, %512 : i64
            llvm.store %513, %389 : i64, !llvm.ptr
            cf.br ^bb92
          ^bb91:
            cf.br ^bb92
          ^bb92:
          cf.br ^bb83
        ^bb82:
          cf.br ^bb83
        ^bb83:
        %514 = llvm.load %416 : !llvm.ptr -> i64
        %515 = arith.constant 1 : i32
        %517 = arith.extsi %515 : i32 to i64
        %516 = arith.addi %514, %517 : i64
        llvm.store %516, %416 : i64, !llvm.ptr
        cf.br ^bb75
      ^bb77:
      %518 = llvm.load %393 : !llvm.ptr -> i64
      %519 = arith.constant 1 : i32
      %521 = arith.extsi %519 : i32 to i64
      %520 = arith.addi %518, %521 : i64
      llvm.store %520, %393 : i64, !llvm.ptr
      cf.br ^bb69
    ^bb71:
    %522 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %523 = llvm.load %389 : !llvm.ptr -> i64
    %524 = llvm.call @printf(%522, %523) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    func.call @free(%335) : (!llvm.ptr) -> ()
    func.call @free(%206) : (!llvm.ptr) -> ()
    func.call @free(%200) : (!llvm.ptr) -> ()
    func.call @free(%194) : (!llvm.ptr) -> ()
    func.call @free(%188) : (!llvm.ptr) -> ()
    %530 = arith.constant 0 : i32
    func.return %530 : i32
  }
}