Problem 927

Prime-ary Tree: R(10^7) = sum of m in S (intersection of S_p) with m <= 10^7. Pure Flow port of the native C solver.

Answer207282955
Output207282955
StatusPASS
Native helperno
Runtime6750 ms
Peak memory13616 KB
Time complexityO(n^2) (estimated)
Space complexityO(n^2) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^2)O(n^2 log n)
Space complexityO(n^2)O(n)
ApproachFlow solutionSweep line or pairwise check
VerdictOptimal

Flow source

# Project Euler 927
# Prime-ary Tree: R(10^7) = sum of m in S (intersection of S_p) with m <= 10^7.
# Pure Flow port of the native C solver.

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

const LIMIT: i64 = 10000000

let mut is_comp: ptr<i8> = null as ptr<i8>
let mut primes_arr: ptr<i32> = null as ptr<i32>
let mut num_primes: i32 = 0

function mod_pow_i64(a0: i64, e0: i64, mod: i64) -> i64 {
    let mut r: i64 = 1 % mod
    let mut a: i64 = a0 % mod
    if a < 0 { a = a + mod }
    let mut e: i64 = e0
    while e > 0 {
        if (e & 1) != 0 { r = r * a % mod }
        a = a * a % mod
        e = e >> 1
    }
    return r
}

function hits_zero_mod_prime(q: i64, k: i64) -> i32 {
    if q == 2 { return 1 }
    if (q - 1) % k != 0 { return 1 }
    let mut tortoise: i64 = 1
    let mut hare: i64 = (1 + mod_pow_i64(1, k, q)) % q
    if hare == 0 { return 1 }
    let mut power: i64 = 1
    let mut lam: i64 = 1
    while tortoise != hare {
        if hare == 0 { return 1 }
        if power == lam {
            tortoise = hare
            power = power << 1
            lam = 0
        }
        hare = (1 + mod_pow_i64(hare, k, q)) % q
        lam = lam + 1
    }
    if hare == 0 { return 1 }
    return 0
}

function hits_zero_mod_prime_k2(q: i64) -> i32 {
    if q == 2 { return 1 }
    let mut tortoise: i64 = 1
    let mut hare: i64 = (1 + 1) % q
    if hare == 0 { return 1 }
    let mut power: i64 = 1
    let mut lam: i64 = 1
    while tortoise != hare {
        if hare == 0 { return 1 }
        if power == lam {
            tortoise = hare
            power = power << 1
            lam = 0
        }
        hare = (hare * hare + 1) % q
        lam = lam + 1
    }
    if hare == 0 { return 1 }
    return 0
}

function sieve_upto(n: i64) -> void {
    is_comp = calloc(n + 1, 1) as ptr<i8>
    is_comp[0] = 1
    is_comp[1] = 1
    let lim: i64 = sqrt(n as f64) as i64
    let mut i: i64 = 2
    while i <= lim {
        if is_comp[i] == 0 {
            let mut j: i64 = i * i
            while j <= n {
                is_comp[j] = 1
                j = j + i
            }
        }
        i = i + 1
    }
    let mut cnt: i64 = 0
    i = 2
    while i <= n {
        if is_comp[i] == 0 { cnt = cnt + 1 }
        i = i + 1
    }
    primes_arr = malloc(cnt * 4) as ptr<i32>
    num_primes = 0
    i = 2
    while i <= n {
        if is_comp[i] == 0 {
            primes_arr[num_primes] = i as i32
            num_primes = num_primes + 1
        }
        i = i + 1
    }
}

function prime_factors_unique(n: i32, out: ptr<i32>) -> i32 {
    let mut x: i32 = n
    let mut cnt: i32 = 0
    let mut i: i32 = 0
    while i < num_primes {
        let p: i32 = primes_arr[i]
        if (p as i64) * (p as i64) > (x as i64) { break }
        if x % p == 0 {
            out[cnt] = p
            cnt = cnt + 1
            while x % p == 0 { x = x / p }
        }
        i = i + 1
    }
    if x > 1 {
        out[cnt] = x
        cnt = cnt + 1
    }
    return cnt
}

function main() -> i32 {
    sieve_upto(LIMIT)

    # Find good primes
    let good_primes: ptr<i32> = malloc((num_primes as i64) * 4) as ptr<i32>
    let mut num_good: i32 = 0
    let factors_buf: ptr<i32> = malloc(32 * 4) as ptr<i32>

    let mut pi: i32 = 0
    while pi < num_primes {
        let q: i32 = primes_arr[pi]
        if q == 2 {
            good_primes[num_good] = q
            num_good = num_good + 1
        } else {
            if (q & 3) == 1 {
                if hits_zero_mod_prime_k2(q as i64) != 0 {
                    let nf: i32 = prime_factors_unique(q - 1, factors_buf)
                    let mut ok: i32 = 1
                    let mut fi: i32 = 0
                    while fi < nf {
                        let p: i32 = factors_buf[fi]
                        if p != 2 {
                            if hits_zero_mod_prime(q as i64, p as i64) == 0 {
                                ok = 0
                            }
                        }
                        if ok == 0 { break }
                        fi = fi + 1
                    }
                    if ok != 0 {
                        good_primes[num_good] = q
                        num_good = num_good + 1
                    }
                }
            }
        }
        pi = pi + 1
    }

    # Sum of squarefree products <= LIMIT
    let mut cap: i64 = 1 << 20
    let mut prods: ptr<i32> = malloc(cap * 4) as ptr<i32>
    let mut len: i64 = 1
    prods[0] = 1

    let mut pidx: i32 = 0
    while pidx < num_good {
        let p: i32 = good_primes[pidx]
        let base_len: i64 = len
        let mut i: i64 = 0
        while i < base_len {
            let v: i64 = (prods[i] as i64) * (p as i64)
            if v <= LIMIT {
                if len >= cap {
                    let new_cap: i64 = cap << 1
                    let newp: ptr<i32> = malloc(new_cap * 4) as ptr<i32>
                    memcpy(newp as ptr<void>, prods as ptr<void>, cap * 4)
                    free(prods)
                    prods = newp
                    cap = new_cap
                }
                prods[len] = v as i32
                len = len + 1
            }
            i = i + 1
        }
        pidx = pidx + 1
    }

    let mut total: i64 = 0
    let mut i: i64 = 0
    while i < len {
        total = total + (prods[i] as i64)
        i = i + 1
    }

    printf("%lld\n", total)

    free(is_comp)
    free(primes_arr)
    free(good_primes)
    free(factors_buf)
    free(prods)
    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 mod_pow_i64_i64_i64_i64(int64_t a0, int64_t e0, int64_t mod);
int32_t hits_zero_mod_prime_i64_i64(int64_t q, int64_t k);
int32_t hits_zero_mod_prime_k2_i64(int64_t q);
void sieve_upto_i64(int64_t n);
int32_t prime_factors_unique_i32_ptr_i32(int32_t n, int32_t* out);
int32_t main(void);

static const int64_t LIMIT = 10000000;

/* Module statics */
static int8_t* is_comp = ((int8_t*)(NULL));
static int32_t* primes_arr = ((int32_t*)(NULL));
static int32_t num_primes = 0;






int64_t mod_pow_i64_i64_i64_i64(int64_t a0, int64_t e0, int64_t mod) {
    int64_t r = FLOW_CHECKED_MOD((1), (mod));
    int64_t a = FLOW_CHECKED_MOD((a0), (mod));
    if (a < 0) {
        a = (a + mod);
    }
    int64_t e = e0;
    while (e > 0) {
        if ((e & 1) != 0) {
            r = FLOW_CHECKED_MOD(((r * a)), (mod));
        }
        a = FLOW_CHECKED_MOD(((a * a)), (mod));
        e = FLOW_CHECKED_SHR((e), (1));
    }
    return r;
}

int32_t hits_zero_mod_prime_i64_i64(int64_t q, int64_t k) {
    if (q == 2) {
        return 1;
    }
    if (FLOW_CHECKED_MOD(((q - 1)), (k)) != 0) {
        return 1;
    }
    int64_t tortoise = 1;
    int64_t hare = FLOW_CHECKED_MOD(((1 + mod_pow_i64_i64_i64_i64(1, k, q))), (q));
    if (hare == 0) {
        return 1;
    }
    int64_t power = 1;
    int64_t lam = 1;
    while (tortoise != hare) {
        if (hare == 0) {
            return 1;
        }
        if (power == lam) {
            tortoise = hare;
            power = FLOW_CHECKED_SHL((power), (1));
            lam = 0;
        }
        hare = FLOW_CHECKED_MOD(((1 + mod_pow_i64_i64_i64_i64(hare, k, q))), (q));
        lam = (lam + 1);
    }
    if (hare == 0) {
        return 1;
    }
    return 0;
}

int32_t hits_zero_mod_prime_k2_i64(int64_t q) {
    if (q == 2) {
        return 1;
    }
    int64_t tortoise = 1;
    int64_t hare = FLOW_CHECKED_MOD(((1 + 1)), (q));
    if (hare == 0) {
        return 1;
    }
    int64_t power = 1;
    int64_t lam = 1;
    while (tortoise != hare) {
        if (hare == 0) {
            return 1;
        }
        if (power == lam) {
            tortoise = hare;
            power = FLOW_CHECKED_SHL((power), (1));
            lam = 0;
        }
        hare = FLOW_CHECKED_MOD((((hare * hare) + 1)), (q));
        lam = (lam + 1);
    }
    if (hare == 0) {
        return 1;
    }
    return 0;
}

void sieve_upto_i64(int64_t n) {
    is_comp = ((int8_t*)(calloc((n + 1), 1)));
    is_comp[0] = 1;
    is_comp[1] = 1;
    int64_t lim = ((int64_t)(sqrt(((double)(n)))));
    int64_t i = 2;
    while (i <= lim) {
        if (is_comp[i] == 0) {
            int64_t j = (i * i);
            while (j <= n) {
                is_comp[j] = 1;
                j = (j + i);
            }
        }
        i = (i + 1);
    }
    int64_t cnt = 0;
    i = 2;
    while (i <= n) {
        if (is_comp[i] == 0) {
            cnt = (cnt + 1);
        }
        i = (i + 1);
    }
    primes_arr = ((int32_t*)(malloc((cnt * 4))));
    num_primes = 0;
    i = 2;
    while (i <= n) {
        if (is_comp[i] == 0) {
            primes_arr[num_primes] = ((int32_t)(i));
            num_primes = (num_primes + 1);
        }
        i = (i + 1);
    }
}

int32_t prime_factors_unique_i32_ptr_i32(int32_t n, int32_t* out) {
    int32_t x = n;
    int32_t cnt = 0;
    int32_t i = 0;
    while (i < num_primes) {
        int32_t p = primes_arr[i];
        if ((((int64_t)(p)) * ((int64_t)(p))) > ((int64_t)(x))) {
            break;
        }
        if (FLOW_CHECKED_MOD((x), (p)) == 0) {
            out[cnt] = p;
            cnt = (cnt + 1);
            while (FLOW_CHECKED_MOD((x), (p)) == 0) {
                x = FLOW_CHECKED_DIV((x), (p));
            }
        }
        i = (i + 1);
    }
    if (x > 1) {
        out[cnt] = x;
        cnt = (cnt + 1);
    }
    return cnt;
}

int32_t main(void) {
    sieve_upto_i64(LIMIT);
    int32_t* good_primes = (int32_t*)(((int32_t*)(malloc((((int64_t)(num_primes)) * 4)))));
    int32_t num_good = 0;
    int32_t* factors_buf = (int32_t*)(((int32_t*)(malloc((32 * 4)))));
    int32_t pi = 0;
    while (pi < num_primes) {
        int32_t q = primes_arr[pi];
        if (q == 2) {
            good_primes[num_good] = q;
            num_good = (num_good + 1);
        } else {
            if ((q & 3) == 1) {
                if (hits_zero_mod_prime_k2_i64(((int64_t)(q))) != 0) {
                    int32_t nf = prime_factors_unique_i32_ptr_i32((q - 1), factors_buf);
                    int32_t ok = 1;
                    int32_t fi = 0;
                    while (fi < nf) {
                        int32_t p = factors_buf[fi];
                        if (p != 2) {
                            if (hits_zero_mod_prime_i64_i64(((int64_t)(q)), ((int64_t)(p))) == 0) {
                                ok = 0;
                            }
                        }
                        if (ok == 0) {
                            break;
                        }
                        fi = (fi + 1);
                    }
                    if (ok != 0) {
                        good_primes[num_good] = q;
                        num_good = (num_good + 1);
                    }
                }
            }
        }
        pi = (pi + 1);
    }
    int64_t cap = FLOW_CHECKED_SHL((1), (20));
    int32_t* prods = (int32_t*)(((int32_t*)(malloc((cap * 4)))));
    int64_t len = 1;
    prods[0] = 1;
    int32_t pidx = 0;
    while (pidx < num_good) {
        int32_t p = good_primes[pidx];
        int64_t base_len = len;
        int64_t i = 0;
        while (i < base_len) {
            int64_t v = (((int64_t)(prods[i])) * ((int64_t)(p)));
            if (v <= LIMIT) {
                if (len >= cap) {
                    int64_t new_cap = FLOW_CHECKED_SHL((cap), (1));
                    int32_t* newp = (int32_t*)(((int32_t*)(malloc((new_cap * 4)))));
                    memcpy(((void*)(newp)), ((void*)(prods)), (cap * 4));
                    free(prods);
                    prods = newp;
                    cap = new_cap;
                }
                prods[len] = ((int32_t)(v));
                len = (len + 1);
            }
            i = (i + 1);
        }
        pidx = (pidx + 1);
    }
    int64_t total = 0;
    int64_t i = 0;
    while (i < len) {
        total = (total + ((int64_t)(prods[i])));
        i = (i + 1);
    }
    printf("%lld\n", total);
    free(is_comp);
    free(primes_arr);
    free(good_primes);
    free(factors_buf);
    free(prods);
    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 private @calloc(i64, i64) -> !llvm.ptr
  func.func private @free(!llvm.ptr) -> ()
  func.func private @malloc(i64) -> !llvm.ptr
  func.func private @memcpy(!llvm.ptr, !llvm.ptr, i64) -> !llvm.ptr
  func.func private @sqrt(f64) -> f64
  // Constant: LIMIT
  llvm.mlir.global internal constant @LIMIT(10000000 : i64) : i64
  // Module static: is_comp
  llvm.mlir.global internal @is_comp() {addr_space = 0 : i32} : !llvm.ptr {
    %0 = llvm.mlir.zero : !llvm.ptr
    llvm.return %0 : !llvm.ptr
  }
  // Module static: primes_arr
  llvm.mlir.global internal @primes_arr() {addr_space = 0 : i32} : !llvm.ptr {
    %1 = llvm.mlir.zero : !llvm.ptr
    llvm.return %1 : !llvm.ptr
  }
  // Module static: num_primes
  llvm.mlir.global internal @num_primes(0 : i32) : i32
  func.func @mod_pow_i64(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %2 = arith.constant 1 : i32
    %4 = arith.extsi %2 : i32 to i64
    %3 = arith.remsi %4, %arg2 : i64
    %5 = llvm.mlir.constant(1 : i64) : i64
    %6 = llvm.alloca %5 x i64 : (i64) -> !llvm.ptr
    llvm.store %3, %6 : i64, !llvm.ptr
    %7 = arith.remsi %arg0, %arg2 : i64
    %8 = llvm.mlir.constant(1 : i64) : i64
    %9 = llvm.alloca %8 x i64 : (i64) -> !llvm.ptr
    llvm.store %7, %9 : i64, !llvm.ptr
    %10 = llvm.load %9 : !llvm.ptr -> i64
    %11 = arith.constant 0 : i32
    %13 = arith.extsi %11 : i32 to i64
    %12 = arith.cmpi slt, %10, %13 : i64
    cf.cond_br %12, ^bb0, ^bb1
    ^bb0:
      %14 = llvm.load %9 : !llvm.ptr -> i64
      %15 = arith.addi %14, %arg2 : i64
      llvm.store %15, %9 : i64, !llvm.ptr
      cf.br ^bb2
    ^bb1:
      cf.br ^bb2
    ^bb2:
    %16 = llvm.mlir.constant(1 : i64) : i64
    %17 = llvm.alloca %16 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %17 : i64, !llvm.ptr
    cf.br ^bb3
    ^bb3:
    %18 = llvm.load %17 : !llvm.ptr -> i64
    %19 = arith.constant 0 : i32
    %21 = arith.extsi %19 : i32 to i64
    %20 = arith.cmpi sgt, %18, %21 : i64
    cf.cond_br %20, ^bb4, ^bb5
    ^bb4:
      %22 = llvm.load %17 : !llvm.ptr -> i64
      %23 = arith.constant 1 : i32
      %25 = arith.extsi %23 : i32 to i64
      %24 = arith.andi %22, %25 : i64
      %26 = arith.constant 0 : i32
      %28 = arith.extsi %26 : i32 to i64
      %27 = arith.cmpi ne, %24, %28 : i64
      cf.cond_br %27, ^bb6, ^bb7
      ^bb6:
        %29 = llvm.load %6 : !llvm.ptr -> i64
        %30 = llvm.load %9 : !llvm.ptr -> i64
        %31 = arith.muli %29, %30 : i64
        %32 = arith.remsi %31, %arg2 : i64
        llvm.store %32, %6 : i64, !llvm.ptr
        cf.br ^bb8
      ^bb7:
        cf.br ^bb8
      ^bb8:
      %33 = llvm.load %9 : !llvm.ptr -> i64
      %34 = llvm.load %9 : !llvm.ptr -> i64
      %35 = arith.muli %33, %34 : i64
      %36 = arith.remsi %35, %arg2 : i64
      llvm.store %36, %9 : i64, !llvm.ptr
      %37 = llvm.load %17 : !llvm.ptr -> i64
      %38 = arith.constant 1 : i32
      %40 = arith.extsi %38 : i32 to i64
      %39 = arith.shrsi %37, %40 : i64
      llvm.store %39, %17 : i64, !llvm.ptr
      cf.br ^bb3
    ^bb5:
    %41 = llvm.load %6 : !llvm.ptr -> i64
    func.return %41 : i64
  }
  func.func @hits_zero_mod_prime(%arg0: i64, %arg1: i64) -> i32 {
    %42 = arith.constant 2 : i32
    %44 = arith.extsi %42 : i32 to i64
    %43 = arith.cmpi eq, %arg0, %44 : i64
    cf.cond_br %43, ^bb9, ^bb10
    ^bb9:
      %45 = arith.constant 1 : i32
      func.return %45 : i32
    ^bb10:
      cf.br ^bb11
    ^bb11:
    %46 = arith.constant 1 : i32
    %48 = arith.extsi %46 : i32 to i64
    %47 = arith.subi %arg0, %48 : i64
    %49 = arith.remsi %47, %arg1 : i64
    %50 = arith.constant 0 : i32
    %52 = arith.extsi %50 : i32 to i64
    %51 = arith.cmpi ne, %49, %52 : i64
    cf.cond_br %51, ^bb12, ^bb13
    ^bb12:
      %53 = arith.constant 1 : i32
      func.return %53 : i32
    ^bb13:
      cf.br ^bb14
    ^bb14:
    %54 = arith.constant 1 : i32
    %55 = arith.extsi %54 : i32 to 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 1 : i32
    %60 = arith.constant 1 : i32
    %61 = arith.extsi %60 : i32 to i64
    %59 = func.call @mod_pow_i64(%61, %arg1, %arg0) : (i64, i64, i64) -> i64
    %63 = arith.extsi %58 : i32 to i64
    %62 = arith.addi %63, %59 : i64
    %64 = arith.remsi %62, %arg0 : i64
    %65 = llvm.mlir.constant(1 : i64) : i64
    %66 = llvm.alloca %65 x i64 : (i64) -> !llvm.ptr
    llvm.store %64, %66 : i64, !llvm.ptr
    %67 = llvm.load %66 : !llvm.ptr -> i64
    %68 = arith.constant 0 : i32
    %70 = arith.extsi %68 : i32 to i64
    %69 = arith.cmpi eq, %67, %70 : i64
    cf.cond_br %69, ^bb15, ^bb16
    ^bb15:
      %71 = arith.constant 1 : i32
      func.return %71 : i32
    ^bb16:
      cf.br ^bb17
    ^bb17:
    %72 = arith.constant 1 : i32
    %73 = arith.extsi %72 : i32 to i64
    %74 = llvm.mlir.constant(1 : i64) : i64
    %75 = llvm.alloca %74 x i64 : (i64) -> !llvm.ptr
    llvm.store %73, %75 : i64, !llvm.ptr
    %76 = arith.constant 1 : i32
    %77 = arith.extsi %76 : i32 to i64
    %78 = llvm.mlir.constant(1 : i64) : i64
    %79 = llvm.alloca %78 x i64 : (i64) -> !llvm.ptr
    llvm.store %77, %79 : i64, !llvm.ptr
    cf.br ^bb18
    ^bb18:
    %80 = llvm.load %57 : !llvm.ptr -> i64
    %81 = llvm.load %66 : !llvm.ptr -> i64
    %82 = arith.cmpi ne, %80, %81 : i64
    cf.cond_br %82, ^bb19, ^bb20
    ^bb19:
      %83 = llvm.load %66 : !llvm.ptr -> i64
      %84 = arith.constant 0 : i32
      %86 = arith.extsi %84 : i32 to i64
      %85 = arith.cmpi eq, %83, %86 : i64
      cf.cond_br %85, ^bb21, ^bb22
      ^bb21:
        %87 = arith.constant 1 : i32
        func.return %87 : i32
      ^bb22:
        cf.br ^bb23
      ^bb23:
      %88 = llvm.load %75 : !llvm.ptr -> i64
      %89 = llvm.load %79 : !llvm.ptr -> i64
      %90 = arith.cmpi eq, %88, %89 : i64
      cf.cond_br %90, ^bb24, ^bb25
      ^bb24:
        %91 = llvm.load %66 : !llvm.ptr -> i64
        llvm.store %91, %57 : i64, !llvm.ptr
        %92 = llvm.load %75 : !llvm.ptr -> i64
        %93 = arith.constant 1 : i32
        %95 = arith.extsi %93 : i32 to i64
        %94 = arith.shli %92, %95 : i64
        llvm.store %94, %75 : i64, !llvm.ptr
        %96 = arith.constant 0 : i32
        %97 = arith.extsi %96 : i32 to i64
        llvm.store %97, %79 : i64, !llvm.ptr
        cf.br ^bb26
      ^bb25:
        cf.br ^bb26
      ^bb26:
      %98 = arith.constant 1 : i32
      %100 = llvm.load %66 : !llvm.ptr -> i64
      %99 = func.call @mod_pow_i64(%100, %arg1, %arg0) : (i64, i64, i64) -> i64
      %102 = arith.extsi %98 : i32 to i64
      %101 = arith.addi %102, %99 : i64
      %103 = arith.remsi %101, %arg0 : i64
      llvm.store %103, %66 : i64, !llvm.ptr
      %104 = llvm.load %79 : !llvm.ptr -> i64
      %105 = arith.constant 1 : i32
      %107 = arith.extsi %105 : i32 to i64
      %106 = arith.addi %104, %107 : i64
      llvm.store %106, %79 : i64, !llvm.ptr
      cf.br ^bb18
    ^bb20:
    %108 = llvm.load %66 : !llvm.ptr -> i64
    %109 = arith.constant 0 : i32
    %111 = arith.extsi %109 : i32 to i64
    %110 = arith.cmpi eq, %108, %111 : i64
    cf.cond_br %110, ^bb27, ^bb28
    ^bb27:
      %112 = arith.constant 1 : i32
      func.return %112 : i32
    ^bb28:
      cf.br ^bb29
    ^bb29:
    %113 = arith.constant 0 : i32
    func.return %113 : i32
  }
  func.func @hits_zero_mod_prime_k2(%arg0: i64) -> i32 {
    %114 = arith.constant 2 : i32
    %116 = arith.extsi %114 : i32 to i64
    %115 = arith.cmpi eq, %arg0, %116 : i64
    cf.cond_br %115, ^bb30, ^bb31
    ^bb30:
      %117 = arith.constant 1 : i32
      func.return %117 : i32
    ^bb31:
      cf.br ^bb32
    ^bb32:
    %118 = arith.constant 1 : i32
    %119 = arith.extsi %118 : i32 to i64
    %120 = llvm.mlir.constant(1 : i64) : i64
    %121 = llvm.alloca %120 x i64 : (i64) -> !llvm.ptr
    llvm.store %119, %121 : i64, !llvm.ptr
    %122 = arith.constant 1 : i32
    %123 = arith.constant 1 : i32
    %124 = arith.addi %122, %123 : i32
    %126 = arith.extsi %124 : i32 to i64
    %125 = arith.remsi %126, %arg0 : i64
    %127 = llvm.mlir.constant(1 : i64) : i64
    %128 = llvm.alloca %127 x i64 : (i64) -> !llvm.ptr
    llvm.store %125, %128 : i64, !llvm.ptr
    %129 = llvm.load %128 : !llvm.ptr -> i64
    %130 = arith.constant 0 : i32
    %132 = arith.extsi %130 : i32 to i64
    %131 = arith.cmpi eq, %129, %132 : i64
    cf.cond_br %131, ^bb33, ^bb34
    ^bb33:
      %133 = arith.constant 1 : i32
      func.return %133 : i32
    ^bb34:
      cf.br ^bb35
    ^bb35:
    %134 = arith.constant 1 : i32
    %135 = arith.extsi %134 : i32 to i64
    %136 = llvm.mlir.constant(1 : i64) : i64
    %137 = llvm.alloca %136 x i64 : (i64) -> !llvm.ptr
    llvm.store %135, %137 : i64, !llvm.ptr
    %138 = arith.constant 1 : i32
    %139 = arith.extsi %138 : i32 to i64
    %140 = llvm.mlir.constant(1 : i64) : i64
    %141 = llvm.alloca %140 x i64 : (i64) -> !llvm.ptr
    llvm.store %139, %141 : i64, !llvm.ptr
    cf.br ^bb36
    ^bb36:
    %142 = llvm.load %121 : !llvm.ptr -> i64
    %143 = llvm.load %128 : !llvm.ptr -> i64
    %144 = arith.cmpi ne, %142, %143 : i64
    cf.cond_br %144, ^bb37, ^bb38
    ^bb37:
      %145 = llvm.load %128 : !llvm.ptr -> i64
      %146 = arith.constant 0 : i32
      %148 = arith.extsi %146 : i32 to i64
      %147 = arith.cmpi eq, %145, %148 : i64
      cf.cond_br %147, ^bb39, ^bb40
      ^bb39:
        %149 = arith.constant 1 : i32
        func.return %149 : i32
      ^bb40:
        cf.br ^bb41
      ^bb41:
      %150 = llvm.load %137 : !llvm.ptr -> i64
      %151 = llvm.load %141 : !llvm.ptr -> i64
      %152 = arith.cmpi eq, %150, %151 : i64
      cf.cond_br %152, ^bb42, ^bb43
      ^bb42:
        %153 = llvm.load %128 : !llvm.ptr -> i64
        llvm.store %153, %121 : i64, !llvm.ptr
        %154 = llvm.load %137 : !llvm.ptr -> i64
        %155 = arith.constant 1 : i32
        %157 = arith.extsi %155 : i32 to i64
        %156 = arith.shli %154, %157 : i64
        llvm.store %156, %137 : i64, !llvm.ptr
        %158 = arith.constant 0 : i32
        %159 = arith.extsi %158 : i32 to i64
        llvm.store %159, %141 : i64, !llvm.ptr
        cf.br ^bb44
      ^bb43:
        cf.br ^bb44
      ^bb44:
      %160 = llvm.load %128 : !llvm.ptr -> i64
      %161 = llvm.load %128 : !llvm.ptr -> i64
      %162 = arith.muli %160, %161 : i64
      %163 = arith.constant 1 : i32
      %165 = arith.extsi %163 : i32 to i64
      %164 = arith.addi %162, %165 : i64
      %166 = arith.remsi %164, %arg0 : i64
      llvm.store %166, %128 : i64, !llvm.ptr
      %167 = llvm.load %141 : !llvm.ptr -> i64
      %168 = arith.constant 1 : i32
      %170 = arith.extsi %168 : i32 to i64
      %169 = arith.addi %167, %170 : i64
      llvm.store %169, %141 : i64, !llvm.ptr
      cf.br ^bb36
    ^bb38:
    %171 = llvm.load %128 : !llvm.ptr -> i64
    %172 = arith.constant 0 : i32
    %174 = arith.extsi %172 : i32 to i64
    %173 = arith.cmpi eq, %171, %174 : i64
    cf.cond_br %173, ^bb45, ^bb46
    ^bb45:
      %175 = arith.constant 1 : i32
      func.return %175 : i32
    ^bb46:
      cf.br ^bb47
    ^bb47:
    %176 = arith.constant 0 : i32
    func.return %176 : i32
  }
  func.func @sieve_upto(%arg0: i64) -> () {
    %178 = arith.constant 1 : i32
    %180 = arith.extsi %178 : i32 to i64
    %179 = arith.addi %arg0, %180 : i64
    %181 = arith.constant 1 : i32
    %182 = arith.extsi %181 : i32 to i64
    %177 = func.call @calloc(%179, %182) : (i64, i64) -> !llvm.ptr
    %183 = llvm.mlir.addressof @is_comp : !llvm.ptr
    llvm.store %177, %183 : !llvm.ptr, !llvm.ptr
    %184 = arith.constant 1 : i32
    %185 = llvm.mlir.addressof @is_comp : !llvm.ptr
    %186 = llvm.load %185 : !llvm.ptr -> !llvm.ptr
    %187 = arith.constant 0 : i32
    %188 = arith.trunci %184 : i32 to i8
    %189 = arith.extsi %187 : i32 to i64
    %190 = llvm.getelementptr %186[%189] : (!llvm.ptr, i64) -> !llvm.ptr, i8
    llvm.store %188, %190 : i8, !llvm.ptr
    %191 = arith.constant 1 : i32
    %192 = llvm.mlir.addressof @is_comp : !llvm.ptr
    %193 = llvm.load %192 : !llvm.ptr -> !llvm.ptr
    %194 = arith.constant 1 : i32
    %195 = arith.trunci %191 : i32 to i8
    %196 = arith.extsi %194 : i32 to i64
    %197 = llvm.getelementptr %193[%196] : (!llvm.ptr, i64) -> !llvm.ptr, i8
    llvm.store %195, %197 : i8, !llvm.ptr
    %198 = arith.sitofp %arg0 : i64 to f64
    %199 = math.sqrt %198 : f64
    %200 = arith.fptosi %199 : f64 to i64
    %201 = arith.constant 2 : i32
    %202 = arith.extsi %201 : i32 to i64
    %203 = llvm.mlir.constant(1 : i64) : i64
    %204 = llvm.alloca %203 x i64 : (i64) -> !llvm.ptr
    llvm.store %202, %204 : i64, !llvm.ptr
    cf.br ^bb48
    ^bb48:
    %205 = llvm.load %204 : !llvm.ptr -> i64
    %206 = arith.cmpi sle, %205, %200 : i64
    cf.cond_br %206, ^bb49, ^bb50
    ^bb49:
      %208 = llvm.mlir.addressof @is_comp : !llvm.ptr
      %209 = llvm.load %208 : !llvm.ptr -> !llvm.ptr
      %210 = llvm.load %204 : !llvm.ptr -> i64
      %211 = llvm.getelementptr %209[%210] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %207 = llvm.load %211 : !llvm.ptr -> i8
      %212 = arith.constant 0 : i32
      %214 = arith.extsi %207 : i8 to i32
      %213 = arith.cmpi eq, %214, %212 : i32
      cf.cond_br %213, ^bb51, ^bb52
      ^bb51:
        %215 = llvm.load %204 : !llvm.ptr -> i64
        %216 = llvm.load %204 : !llvm.ptr -> i64
        %217 = arith.muli %215, %216 : i64
        %218 = llvm.mlir.constant(1 : i64) : i64
        %219 = llvm.alloca %218 x i64 : (i64) -> !llvm.ptr
        llvm.store %217, %219 : i64, !llvm.ptr
        cf.br ^bb54
        ^bb54:
        %220 = llvm.load %219 : !llvm.ptr -> i64
        %221 = arith.cmpi sle, %220, %arg0 : i64
        cf.cond_br %221, ^bb55, ^bb56
        ^bb55:
          %222 = arith.constant 1 : i32
          %223 = llvm.mlir.addressof @is_comp : !llvm.ptr
          %224 = llvm.load %223 : !llvm.ptr -> !llvm.ptr
          %225 = llvm.load %219 : !llvm.ptr -> i64
          %226 = arith.trunci %222 : i32 to i8
          %227 = llvm.getelementptr %224[%225] : (!llvm.ptr, i64) -> !llvm.ptr, i8
          llvm.store %226, %227 : i8, !llvm.ptr
          %228 = llvm.load %219 : !llvm.ptr -> i64
          %229 = llvm.load %204 : !llvm.ptr -> i64
          %230 = arith.addi %228, %229 : i64
          llvm.store %230, %219 : i64, !llvm.ptr
          cf.br ^bb54
        ^bb56:
        cf.br ^bb53
      ^bb52:
        cf.br ^bb53
      ^bb53:
      %231 = llvm.load %204 : !llvm.ptr -> i64
      %232 = arith.constant 1 : i32
      %234 = arith.extsi %232 : i32 to i64
      %233 = arith.addi %231, %234 : i64
      llvm.store %233, %204 : i64, !llvm.ptr
      cf.br ^bb48
    ^bb50:
    %235 = arith.constant 0 : i32
    %236 = arith.extsi %235 : i32 to i64
    %237 = llvm.mlir.constant(1 : i64) : i64
    %238 = llvm.alloca %237 x i64 : (i64) -> !llvm.ptr
    llvm.store %236, %238 : i64, !llvm.ptr
    %239 = arith.constant 2 : i32
    %240 = arith.extsi %239 : i32 to i64
    llvm.store %240, %204 : i64, !llvm.ptr
    cf.br ^bb57
    ^bb57:
    %241 = llvm.load %204 : !llvm.ptr -> i64
    %242 = arith.cmpi sle, %241, %arg0 : i64
    cf.cond_br %242, ^bb58, ^bb59
    ^bb58:
      %244 = llvm.mlir.addressof @is_comp : !llvm.ptr
      %245 = llvm.load %244 : !llvm.ptr -> !llvm.ptr
      %246 = llvm.load %204 : !llvm.ptr -> i64
      %247 = llvm.getelementptr %245[%246] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %243 = llvm.load %247 : !llvm.ptr -> i8
      %248 = arith.constant 0 : i32
      %250 = arith.extsi %243 : i8 to i32
      %249 = arith.cmpi eq, %250, %248 : i32
      cf.cond_br %249, ^bb60, ^bb61
      ^bb60:
        %251 = llvm.load %238 : !llvm.ptr -> i64
        %252 = arith.constant 1 : i32
        %254 = arith.extsi %252 : i32 to i64
        %253 = arith.addi %251, %254 : i64
        llvm.store %253, %238 : i64, !llvm.ptr
        cf.br ^bb62
      ^bb61:
        cf.br ^bb62
      ^bb62:
      %255 = llvm.load %204 : !llvm.ptr -> i64
      %256 = arith.constant 1 : i32
      %258 = arith.extsi %256 : i32 to i64
      %257 = arith.addi %255, %258 : i64
      llvm.store %257, %204 : i64, !llvm.ptr
      cf.br ^bb57
    ^bb59:
    %260 = llvm.load %238 : !llvm.ptr -> i64
    %261 = arith.constant 4 : i32
    %263 = arith.extsi %261 : i32 to i64
    %262 = arith.muli %260, %263 : i64
    %259 = func.call @malloc(%262) : (i64) -> !llvm.ptr
    %264 = llvm.mlir.addressof @primes_arr : !llvm.ptr
    llvm.store %259, %264 : !llvm.ptr, !llvm.ptr
    %265 = arith.constant 0 : i32
    %266 = llvm.mlir.addressof @num_primes : !llvm.ptr
    llvm.store %265, %266 : i32, !llvm.ptr
    %267 = arith.constant 2 : i32
    %268 = arith.extsi %267 : i32 to i64
    llvm.store %268, %204 : i64, !llvm.ptr
    cf.br ^bb63
    ^bb63:
    %269 = llvm.load %204 : !llvm.ptr -> i64
    %270 = arith.cmpi sle, %269, %arg0 : i64
    cf.cond_br %270, ^bb64, ^bb65
    ^bb64:
      %272 = llvm.mlir.addressof @is_comp : !llvm.ptr
      %273 = llvm.load %272 : !llvm.ptr -> !llvm.ptr
      %274 = llvm.load %204 : !llvm.ptr -> i64
      %275 = llvm.getelementptr %273[%274] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %271 = llvm.load %275 : !llvm.ptr -> i8
      %276 = arith.constant 0 : i32
      %278 = arith.extsi %271 : i8 to i32
      %277 = arith.cmpi eq, %278, %276 : i32
      cf.cond_br %277, ^bb66, ^bb67
      ^bb66:
        %279 = llvm.load %204 : !llvm.ptr -> i64
        %280 = arith.trunci %279 : i64 to i32
        %281 = llvm.mlir.addressof @primes_arr : !llvm.ptr
        %282 = llvm.load %281 : !llvm.ptr -> !llvm.ptr
        %283 = llvm.mlir.addressof @num_primes : !llvm.ptr
        %284 = llvm.load %283 : !llvm.ptr -> i32
        %285 = arith.extsi %284 : i32 to i64
        %286 = llvm.getelementptr %282[%285] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %280, %286 : i32, !llvm.ptr
        %287 = llvm.mlir.addressof @num_primes : !llvm.ptr
        %288 = llvm.load %287 : !llvm.ptr -> i32
        %289 = arith.constant 1 : i32
        %290 = arith.addi %288, %289 : i32
        %291 = llvm.mlir.addressof @num_primes : !llvm.ptr
        llvm.store %290, %291 : i32, !llvm.ptr
        cf.br ^bb68
      ^bb67:
        cf.br ^bb68
      ^bb68:
      %292 = llvm.load %204 : !llvm.ptr -> i64
      %293 = arith.constant 1 : i32
      %295 = arith.extsi %293 : i32 to i64
      %294 = arith.addi %292, %295 : i64
      llvm.store %294, %204 : i64, !llvm.ptr
      cf.br ^bb63
    ^bb65:
    func.return
  }
  func.func @prime_factors_unique(%arg0: i32, %arg1: !llvm.ptr) -> i32 {
    %296 = llvm.mlir.constant(1 : i64) : i64
    %297 = llvm.alloca %296 x i32 : (i64) -> !llvm.ptr
    llvm.store %arg0, %297 : i32, !llvm.ptr
    %298 = arith.constant 0 : i32
    %299 = llvm.mlir.constant(1 : i64) : i64
    %300 = llvm.alloca %299 x i32 : (i64) -> !llvm.ptr
    llvm.store %298, %300 : i32, !llvm.ptr
    %301 = arith.constant 0 : i32
    %302 = llvm.mlir.constant(1 : i64) : i64
    %303 = llvm.alloca %302 x i32 : (i64) -> !llvm.ptr
    llvm.store %301, %303 : i32, !llvm.ptr
    cf.br ^bb69
    ^bb69:
    %304 = llvm.load %303 : !llvm.ptr -> i32
    %305 = llvm.mlir.addressof @num_primes : !llvm.ptr
    %306 = llvm.load %305 : !llvm.ptr -> i32
    %307 = arith.cmpi slt, %304, %306 : i32
    cf.cond_br %307, ^bb70, ^bb71
    ^bb70:
      %309 = llvm.mlir.addressof @primes_arr : !llvm.ptr
      %310 = llvm.load %309 : !llvm.ptr -> !llvm.ptr
      %311 = llvm.load %303 : !llvm.ptr -> i32
      %312 = arith.extsi %311 : i32 to i64
      %313 = llvm.getelementptr %310[%312] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %308 = llvm.load %313 : !llvm.ptr -> i32
      %314 = arith.extsi %308 : i32 to i64
      %315 = arith.extsi %308 : i32 to i64
      %316 = arith.muli %314, %315 : i64
      %317 = llvm.load %297 : !llvm.ptr -> i32
      %318 = arith.extsi %317 : i32 to i64
      %319 = arith.cmpi sgt, %316, %318 : i64
      cf.cond_br %319, ^bb72, ^bb73
      ^bb72:
        cf.br ^bb71
      ^bb73:
        cf.br ^bb74
      ^bb74:
      %320 = llvm.load %297 : !llvm.ptr -> i32
      %321 = arith.remsi %320, %308 : i32
      %322 = arith.constant 0 : i32
      %323 = arith.cmpi eq, %321, %322 : i32
      cf.cond_br %323, ^bb75, ^bb76
      ^bb75:
        %324 = llvm.load %300 : !llvm.ptr -> i32
        %325 = arith.extsi %324 : i32 to i64
        %326 = llvm.getelementptr %arg1[%325] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %308, %326 : i32, !llvm.ptr
        %327 = llvm.load %300 : !llvm.ptr -> i32
        %328 = arith.constant 1 : i32
        %329 = arith.addi %327, %328 : i32
        llvm.store %329, %300 : i32, !llvm.ptr
        cf.br ^bb78
        ^bb78:
        %330 = llvm.load %297 : !llvm.ptr -> i32
        %331 = arith.remsi %330, %308 : i32
        %332 = arith.constant 0 : i32
        %333 = arith.cmpi eq, %331, %332 : i32
        cf.cond_br %333, ^bb79, ^bb80
        ^bb79:
          %334 = llvm.load %297 : !llvm.ptr -> i32
          %335 = arith.divsi %334, %308 : i32
          llvm.store %335, %297 : i32, !llvm.ptr
          cf.br ^bb78
        ^bb80:
        cf.br ^bb77
      ^bb76:
        cf.br ^bb77
      ^bb77:
      %336 = llvm.load %303 : !llvm.ptr -> i32
      %337 = arith.constant 1 : i32
      %338 = arith.addi %336, %337 : i32
      llvm.store %338, %303 : i32, !llvm.ptr
      cf.br ^bb69
    ^bb71:
    %339 = llvm.load %297 : !llvm.ptr -> i32
    %340 = arith.constant 1 : i32
    %341 = arith.cmpi sgt, %339, %340 : i32
    cf.cond_br %341, ^bb81, ^bb82
    ^bb81:
      %342 = llvm.load %297 : !llvm.ptr -> i32
      %343 = llvm.load %300 : !llvm.ptr -> i32
      %344 = arith.extsi %343 : i32 to i64
      %345 = llvm.getelementptr %arg1[%344] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      llvm.store %342, %345 : i32, !llvm.ptr
      %346 = llvm.load %300 : !llvm.ptr -> i32
      %347 = arith.constant 1 : i32
      %348 = arith.addi %346, %347 : i32
      llvm.store %348, %300 : i32, !llvm.ptr
      cf.br ^bb83
    ^bb82:
      cf.br ^bb83
    ^bb83:
    %349 = llvm.load %300 : !llvm.ptr -> i32
    func.return %349 : i32
  }
  func.func @main() -> i32 {
    %351 = llvm.mlir.addressof @LIMIT : !llvm.ptr
    %352 = llvm.load %351 : !llvm.ptr -> i64
    func.call @sieve_upto(%352) : (i64) -> ()
    %354 = llvm.mlir.addressof @num_primes : !llvm.ptr
    %355 = llvm.load %354 : !llvm.ptr -> i32
    %356 = arith.extsi %355 : i32 to i64
    %357 = arith.constant 4 : i32
    %359 = arith.extsi %357 : i32 to i64
    %358 = arith.muli %356, %359 : i64
    %353 = func.call @malloc(%358) : (i64) -> !llvm.ptr
    %360 = arith.constant 0 : i32
    %361 = llvm.mlir.constant(1 : i64) : i64
    %362 = llvm.alloca %361 x i32 : (i64) -> !llvm.ptr
    llvm.store %360, %362 : i32, !llvm.ptr
    %364 = arith.constant 32 : i32
    %365 = arith.constant 4 : i32
    %366 = arith.muli %364, %365 : i32
    %367 = arith.extsi %366 : i32 to i64
    %363 = func.call @malloc(%367) : (i64) -> !llvm.ptr
    %368 = arith.constant 0 : i32
    %369 = llvm.mlir.constant(1 : i64) : i64
    %370 = llvm.alloca %369 x i32 : (i64) -> !llvm.ptr
    llvm.store %368, %370 : i32, !llvm.ptr
    cf.br ^bb84
    ^bb84:
    %371 = llvm.load %370 : !llvm.ptr -> i32
    %372 = llvm.mlir.addressof @num_primes : !llvm.ptr
    %373 = llvm.load %372 : !llvm.ptr -> i32
    %374 = arith.cmpi slt, %371, %373 : i32
    cf.cond_br %374, ^bb85, ^bb86
    ^bb85:
      %376 = llvm.mlir.addressof @primes_arr : !llvm.ptr
      %377 = llvm.load %376 : !llvm.ptr -> !llvm.ptr
      %378 = llvm.load %370 : !llvm.ptr -> i32
      %379 = arith.extsi %378 : i32 to i64
      %380 = llvm.getelementptr %377[%379] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %375 = llvm.load %380 : !llvm.ptr -> i32
      %381 = arith.constant 2 : i32
      %382 = arith.cmpi eq, %375, %381 : i32
      cf.cond_br %382, ^bb87, ^bb88
      ^bb87:
        %383 = llvm.load %362 : !llvm.ptr -> i32
        %384 = arith.extsi %383 : i32 to i64
        %385 = llvm.getelementptr %353[%384] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %375, %385 : i32, !llvm.ptr
        %386 = llvm.load %362 : !llvm.ptr -> i32
        %387 = arith.constant 1 : i32
        %388 = arith.addi %386, %387 : i32
        llvm.store %388, %362 : i32, !llvm.ptr
        cf.br ^bb89
      ^bb88:
        %389 = arith.constant 3 : i32
        %390 = arith.andi %375, %389 : i32
        %391 = arith.constant 1 : i32
        %392 = arith.cmpi eq, %390, %391 : i32
        cf.cond_br %392, ^bb90, ^bb91
        ^bb90:
          %394 = arith.extsi %375 : i32 to i64
          %393 = func.call @hits_zero_mod_prime_k2(%394) : (i64) -> i32
          %395 = arith.constant 0 : i32
          %396 = arith.cmpi ne, %393, %395 : i32
          cf.cond_br %396, ^bb93, ^bb94
          ^bb93:
            %398 = arith.constant 1 : i32
            %399 = arith.subi %375, %398 : i32
            %397 = func.call @prime_factors_unique(%399, %363) : (i32, !llvm.ptr) -> i32
            %400 = arith.constant 1 : i32
            %401 = llvm.mlir.constant(1 : i64) : i64
            %402 = llvm.alloca %401 x i32 : (i64) -> !llvm.ptr
            llvm.store %400, %402 : i32, !llvm.ptr
            %403 = arith.constant 0 : i32
            %404 = llvm.mlir.constant(1 : i64) : i64
            %405 = llvm.alloca %404 x i32 : (i64) -> !llvm.ptr
            llvm.store %403, %405 : i32, !llvm.ptr
            cf.br ^bb96
            ^bb96:
            %406 = llvm.load %405 : !llvm.ptr -> i32
            %407 = arith.cmpi slt, %406, %397 : i32
            cf.cond_br %407, ^bb97, ^bb98
            ^bb97:
              %409 = llvm.load %405 : !llvm.ptr -> i32
              %410 = arith.extsi %409 : i32 to i64
              %411 = llvm.getelementptr %363[%410] : (!llvm.ptr, i64) -> !llvm.ptr, i32
              %408 = llvm.load %411 : !llvm.ptr -> i32
              %412 = arith.constant 2 : i32
              %413 = arith.cmpi ne, %408, %412 : i32
              cf.cond_br %413, ^bb99, ^bb100
              ^bb99:
                %415 = arith.extsi %375 : i32 to i64
                %416 = arith.extsi %408 : i32 to i64
                %414 = func.call @hits_zero_mod_prime(%415, %416) : (i64, i64) -> i32
                %417 = arith.constant 0 : i32
                %418 = arith.cmpi eq, %414, %417 : i32
                cf.cond_br %418, ^bb102, ^bb103
                ^bb102:
                  %419 = arith.constant 0 : i32
                  llvm.store %419, %402 : i32, !llvm.ptr
                  cf.br ^bb104
                ^bb103:
                  cf.br ^bb104
                ^bb104:
                cf.br ^bb101
              ^bb100:
                cf.br ^bb101
              ^bb101:
              %420 = llvm.load %402 : !llvm.ptr -> i32
              %421 = arith.constant 0 : i32
              %422 = arith.cmpi eq, %420, %421 : i32
              cf.cond_br %422, ^bb105, ^bb106
              ^bb105:
                cf.br ^bb98
              ^bb106:
                cf.br ^bb107
              ^bb107:
              %423 = llvm.load %405 : !llvm.ptr -> i32
              %424 = arith.constant 1 : i32
              %425 = arith.addi %423, %424 : i32
              llvm.store %425, %405 : i32, !llvm.ptr
              cf.br ^bb96
            ^bb98:
            %426 = llvm.load %402 : !llvm.ptr -> i32
            %427 = arith.constant 0 : i32
            %428 = arith.cmpi ne, %426, %427 : i32
            cf.cond_br %428, ^bb108, ^bb109
            ^bb108:
              %429 = llvm.load %362 : !llvm.ptr -> i32
              %430 = arith.extsi %429 : i32 to i64
              %431 = llvm.getelementptr %353[%430] : (!llvm.ptr, i64) -> !llvm.ptr, i32
              llvm.store %375, %431 : i32, !llvm.ptr
              %432 = llvm.load %362 : !llvm.ptr -> i32
              %433 = arith.constant 1 : i32
              %434 = arith.addi %432, %433 : i32
              llvm.store %434, %362 : i32, !llvm.ptr
              cf.br ^bb110
            ^bb109:
              cf.br ^bb110
            ^bb110:
            cf.br ^bb95
          ^bb94:
            cf.br ^bb95
          ^bb95:
          cf.br ^bb92
        ^bb91:
          cf.br ^bb92
        ^bb92:
        cf.br ^bb89
      ^bb89:
      %435 = llvm.load %370 : !llvm.ptr -> i32
      %436 = arith.constant 1 : i32
      %437 = arith.addi %435, %436 : i32
      llvm.store %437, %370 : i32, !llvm.ptr
      cf.br ^bb84
    ^bb86:
    %438 = arith.constant 1 : i32
    %439 = arith.constant 20 : i32
    %440 = arith.shli %438, %439 : i32
    %441 = arith.extsi %440 : i32 to i64
    %442 = llvm.mlir.constant(1 : i64) : i64
    %443 = llvm.alloca %442 x i64 : (i64) -> !llvm.ptr
    llvm.store %441, %443 : i64, !llvm.ptr
    %445 = llvm.load %443 : !llvm.ptr -> i64
    %446 = arith.constant 4 : i32
    %448 = arith.extsi %446 : i32 to i64
    %447 = arith.muli %445, %448 : i64
    %444 = func.call @malloc(%447) : (i64) -> !llvm.ptr
    %449 = llvm.mlir.constant(1 : i64) : i64
    %450 = llvm.alloca %449 x !llvm.ptr : (i64) -> !llvm.ptr
    llvm.store %444, %450 : !llvm.ptr, !llvm.ptr
    %451 = arith.constant 1 : i32
    %452 = arith.extsi %451 : i32 to i64
    %453 = llvm.mlir.constant(1 : i64) : i64
    %454 = llvm.alloca %453 x i64 : (i64) -> !llvm.ptr
    llvm.store %452, %454 : i64, !llvm.ptr
    %455 = arith.constant 1 : i32
    %456 = llvm.load %450 : !llvm.ptr -> !llvm.ptr
    %457 = arith.constant 0 : i32
    %458 = arith.extsi %457 : i32 to i64
    %459 = llvm.getelementptr %456[%458] : (!llvm.ptr, i64) -> !llvm.ptr, i32
    llvm.store %455, %459 : i32, !llvm.ptr
    %460 = arith.constant 0 : i32
    %461 = llvm.mlir.constant(1 : i64) : i64
    %462 = llvm.alloca %461 x i32 : (i64) -> !llvm.ptr
    llvm.store %460, %462 : i32, !llvm.ptr
    cf.br ^bb111
    ^bb111:
    %463 = llvm.load %462 : !llvm.ptr -> i32
    %464 = llvm.load %362 : !llvm.ptr -> i32
    %465 = arith.cmpi slt, %463, %464 : i32
    cf.cond_br %465, ^bb112, ^bb113
    ^bb112:
      %467 = llvm.load %462 : !llvm.ptr -> i32
      %468 = arith.extsi %467 : i32 to i64
      %469 = llvm.getelementptr %353[%468] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %466 = llvm.load %469 : !llvm.ptr -> i32
      %470 = llvm.load %454 : !llvm.ptr -> i64
      %471 = arith.constant 0 : i32
      %472 = arith.extsi %471 : i32 to i64
      %473 = llvm.mlir.constant(1 : i64) : i64
      %474 = llvm.alloca %473 x i64 : (i64) -> !llvm.ptr
      llvm.store %472, %474 : i64, !llvm.ptr
      cf.br ^bb114
      ^bb114:
      %475 = llvm.load %474 : !llvm.ptr -> i64
      %476 = arith.cmpi slt, %475, %470 : i64
      cf.cond_br %476, ^bb115, ^bb116
      ^bb115:
        %478 = llvm.load %450 : !llvm.ptr -> !llvm.ptr
        %479 = llvm.load %474 : !llvm.ptr -> i64
        %480 = llvm.getelementptr %478[%479] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %477 = llvm.load %480 : !llvm.ptr -> i32
        %481 = arith.extsi %477 : i32 to i64
        %482 = arith.extsi %466 : i32 to i64
        %483 = arith.muli %481, %482 : i64
        %484 = llvm.mlir.addressof @LIMIT : !llvm.ptr
        %485 = llvm.load %484 : !llvm.ptr -> i64
        %486 = arith.cmpi sle, %483, %485 : i64
        cf.cond_br %486, ^bb117, ^bb118
        ^bb117:
          %487 = llvm.load %454 : !llvm.ptr -> i64
          %488 = llvm.load %443 : !llvm.ptr -> i64
          %489 = arith.cmpi sge, %487, %488 : i64
          cf.cond_br %489, ^bb120, ^bb121
          ^bb120:
            %490 = llvm.load %443 : !llvm.ptr -> i64
            %491 = arith.constant 1 : i32
            %493 = arith.extsi %491 : i32 to i64
            %492 = arith.shli %490, %493 : i64
            %495 = arith.constant 4 : i32
            %497 = arith.extsi %495 : i32 to i64
            %496 = arith.muli %492, %497 : i64
            %494 = func.call @malloc(%496) : (i64) -> !llvm.ptr
            %499 = llvm.load %450 : !llvm.ptr -> !llvm.ptr
            %500 = llvm.load %443 : !llvm.ptr -> i64
            %501 = arith.constant 4 : i32
            %503 = arith.extsi %501 : i32 to i64
            %502 = arith.muli %500, %503 : i64
            %498 = func.call @memcpy(%494, %499, %502) : (!llvm.ptr, !llvm.ptr, i64) -> !llvm.ptr
            %505 = llvm.load %450 : !llvm.ptr -> !llvm.ptr
            func.call @free(%505) : (!llvm.ptr) -> ()
            llvm.store %494, %450 : !llvm.ptr, !llvm.ptr
            llvm.store %492, %443 : i64, !llvm.ptr
            cf.br ^bb122
          ^bb121:
            cf.br ^bb122
          ^bb122:
          %506 = arith.trunci %483 : i64 to i32
          %507 = llvm.load %450 : !llvm.ptr -> !llvm.ptr
          %508 = llvm.load %454 : !llvm.ptr -> i64
          %509 = llvm.getelementptr %507[%508] : (!llvm.ptr, i64) -> !llvm.ptr, i32
          llvm.store %506, %509 : i32, !llvm.ptr
          %510 = llvm.load %454 : !llvm.ptr -> i64
          %511 = arith.constant 1 : i32
          %513 = arith.extsi %511 : i32 to i64
          %512 = arith.addi %510, %513 : i64
          llvm.store %512, %454 : i64, !llvm.ptr
          cf.br ^bb119
        ^bb118:
          cf.br ^bb119
        ^bb119:
        %514 = llvm.load %474 : !llvm.ptr -> i64
        %515 = arith.constant 1 : i32
        %517 = arith.extsi %515 : i32 to i64
        %516 = arith.addi %514, %517 : i64
        llvm.store %516, %474 : i64, !llvm.ptr
        cf.br ^bb114
      ^bb116:
      %518 = llvm.load %462 : !llvm.ptr -> i32
      %519 = arith.constant 1 : i32
      %520 = arith.addi %518, %519 : i32
      llvm.store %520, %462 : i32, !llvm.ptr
      cf.br ^bb111
    ^bb113:
    %521 = arith.constant 0 : i32
    %522 = arith.extsi %521 : i32 to i64
    %523 = llvm.mlir.constant(1 : i64) : i64
    %524 = llvm.alloca %523 x i64 : (i64) -> !llvm.ptr
    llvm.store %522, %524 : i64, !llvm.ptr
    %525 = arith.constant 0 : i32
    %526 = arith.extsi %525 : i32 to i64
    %527 = llvm.mlir.constant(1 : i64) : i64
    %528 = llvm.alloca %527 x i64 : (i64) -> !llvm.ptr
    llvm.store %526, %528 : i64, !llvm.ptr
    cf.br ^bb123
    ^bb123:
    %529 = llvm.load %528 : !llvm.ptr -> i64
    %530 = llvm.load %454 : !llvm.ptr -> i64
    %531 = arith.cmpi slt, %529, %530 : i64
    cf.cond_br %531, ^bb124, ^bb125
    ^bb124:
      %532 = llvm.load %524 : !llvm.ptr -> i64
      %534 = llvm.load %450 : !llvm.ptr -> !llvm.ptr
      %535 = llvm.load %528 : !llvm.ptr -> i64
      %536 = llvm.getelementptr %534[%535] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %533 = llvm.load %536 : !llvm.ptr -> i32
      %537 = arith.extsi %533 : i32 to i64
      %538 = arith.addi %532, %537 : i64
      llvm.store %538, %524 : i64, !llvm.ptr
      %539 = llvm.load %528 : !llvm.ptr -> i64
      %540 = arith.constant 1 : i32
      %542 = arith.extsi %540 : i32 to i64
      %541 = arith.addi %539, %542 : i64
      llvm.store %541, %528 : i64, !llvm.ptr
      cf.br ^bb123
    ^bb125:
    %543 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %544 = llvm.load %524 : !llvm.ptr -> i64
    %545 = llvm.call @printf(%543, %544) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    %547 = llvm.mlir.addressof @is_comp : !llvm.ptr
    %548 = llvm.load %547 : !llvm.ptr -> !llvm.ptr
    func.call @free(%548) : (!llvm.ptr) -> ()
    %550 = llvm.mlir.addressof @primes_arr : !llvm.ptr
    %551 = llvm.load %550 : !llvm.ptr -> !llvm.ptr
    func.call @free(%551) : (!llvm.ptr) -> ()
    func.call @free(%353) : (!llvm.ptr) -> ()
    func.call @free(%363) : (!llvm.ptr) -> ()
    %555 = llvm.load %450 : !llvm.ptr -> !llvm.ptr
    func.call @free(%555) : (!llvm.ptr) -> ()
    %556 = arith.constant 0 : i32
    func.return %556 : i32
  }
}