Problem 443

g(10^15): jump via least prime factor of 2n-1.

Answer2744233049300770
Output2744233049300770
StatusPASS
Native helperno
Runtime0 ms
Peak memory1104 KB
Time complexityO(n) (estimated)
Space complexityO(1) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n)O(sqrt(n))
Space complexityO(1)O(1)
ApproachFlow solutionTrial division or Pollard rho
VerdictSuboptimal

Flow source

# Project Euler 443
# g(10^15): jump via least prime factor of 2n-1.

import euler.nt { gcd }

function modpow(base0: i64, exp0: i64, mod: i64) -> i64 {
    let mut r: i64 = 1
    let mut b: i64 = base0 % mod
    let mut e: i64 = exp0
    while e > 0 {
        if e % 2 == 1 {
            let t: i128 = (r as i128) * (b as i128) % (mod as i128)
            r = t as i64
        }
        let t2: i128 = (b as i128) * (b as i128) % (mod as i128)
        b = t2 as i64
        e = e / 2
    }
    return r
}

function is_prime_mr(n: i64) -> bool {
    if n < 2 { return false }
    let small: array<i64, 12> = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]
    let mut i: i32 = 0
    while i < 12 {
        let p: i64 = small[i]
        if n == p { return true }
        if n % p == 0 { return false }
        i = i + 1
    }
    let mut d: i64 = n - 1
    let mut s: i32 = 0
    while d % 2 == 0 {
        d = d / 2
        s = s + 1
    }
    let bases: array<i64, 7> = [2, 325, 9375, 28178, 450775, 9780504, 1795265022]
    i = 0
    while i < 7 {
        let a: i64 = bases[i] % n
        if a != 0 {
            let mut x: i64 = modpow(a, d, n)
            if x != 1 && x != n - 1 {
                let mut r: i32 = 1
                let mut ok: bool = false
                while r < s {
                    let t: i128 = (x as i128) * (x as i128) % (n as i128)
                    x = t as i64
                    if x == n - 1 {
                        ok = true
                        break
                    }
                    r = r + 1
                }
                if !ok { return false }
            }
        }
        i = i + 1
    }
    return true
}

function smallest_prime_factor(n0: i64) -> i64 {
    if is_prime_mr(n0) { return n0 }
    if n0 % 3 == 0 { return 3 }
    let mut f: i64 = 5
    let mut step: i64 = 2
    while f * f <= n0 {
        if n0 % f == 0 { return f }
        f = f + step
        step = 6 - step
    }
    return n0
}

function main() -> i32 {
    let N: i64 = 1000000000000000
    let mut idx: i64 = 9
    let mut ans: i64 = 0
    while true {
        let p: i64 = smallest_prime_factor(2 * idx - 1)
        let next: i64 = idx + (p - 1) / 2
        if next > N {
            ans = N + 2 * idx
            break
        }
        if next == N {
            ans = 3 * N
            break
        }
        idx = next
    }
    printf("%lld\n", ans)
    return 0
}

Generated C

#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* Flow runtime helpers */
typedef struct flow_temp_node { struct flow_temp_node* next; } flow_temp_node;
static flow_temp_node* flow_temp_head = NULL;
static int flow_temp_atexit_set = 0;
__attribute__((unused)) static void flow_temp_free_all(void) {
    while (flow_temp_head) {
        flow_temp_node* n = flow_temp_head;
        flow_temp_head = n->next;
        free(n);
    }
}
__attribute__((unused)) static void* flow_temp_alloc(size_t nbytes) {
    flow_temp_node* node = (flow_temp_node*)malloc(sizeof(flow_temp_node) + nbytes);
    if (!node) return NULL;
    node->next = flow_temp_head;
    flow_temp_head = node;
    if (!flow_temp_atexit_set) {
        flow_temp_atexit_set = 1;
        atexit(flow_temp_free_all);
    }
    return (void*)(node + 1);
}
#ifndef FLOW_DIAG
#define FLOW_DIAG(msg) fprintf(stderr, "%s", (msg))
#endif
#ifndef FLOW_LOG
#define FLOW_LOG(fmt, ...) printf(fmt, __VA_ARGS__)
#endif
#ifndef FLOW_LOG_EMPTY
#define FLOW_LOG_EMPTY(fmt) printf(fmt)
#endif
static char* flow_strcat(const char* a, const char* b) {
    size_t la = strlen(a ? a : ""), lb = strlen(b ? b : "");
    char* r = (char*)flow_temp_alloc(la + lb + 1);
    if (!r) return NULL;
    if (la) memcpy(r, a, la);
    if (lb) memcpy(r + la, b, lb);
    r[la + lb] = '\0';
    return r;
}

#define __flow_in_arr(arr, val) __extension__ ({ \
    int _found = 0; \
    size_t _n = sizeof(arr)/sizeof((arr)[0]); \
    for (size_t _i = 0; _i < _n; _i++) { \
        if ((arr)[_i] == (val)) { _found = 1; break; } \
    } _found; })

/* Unified fault handler (MISRA #279) — override with -DFLOW_FAULT_HANDLER=fn */
#ifndef FLOW_FAULT_HANDLER
__attribute__((unused)) static inline void flow_fault_handler(const char* msg) {
    fprintf(stderr, "flow: %s\n", msg ? msg : "fault");
    abort();
#if defined(__GNUC__) || defined(__clang__)
    __builtin_unreachable();
#endif
}
#else
#define flow_fault_handler FLOW_FAULT_HANDLER
#endif
#define flow_div_by_zero_handler() flow_fault_handler("division by zero")
#define flow_shift_ub_handler() flow_fault_handler("invalid shift (amount out of range or left-shift of negative)")

#ifndef FLOW_CHECKED_DIV
#define FLOW_CHECKED_DIV(L, R) (((R) != 0) ? ((L) / (R)) : (flow_div_by_zero_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_MOD
#define FLOW_CHECKED_MOD(L, R) (((R) != 0) ? ((L) % (R)) : (flow_div_by_zero_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_SHL
#define FLOW_CHECKED_SHL(L, R) ((((R) >= 0) && ((unsigned long long)(R) < (sizeof(L) * 8ull)) && ((L) >= 0)) ? ((L) << (R)) : (flow_shift_ub_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_SHR
#define FLOW_CHECKED_SHR(L, R) ((((R) >= 0) && ((unsigned long long)(R) < (sizeof(L) * 8ull))) ? ((L) >> (R)) : (flow_shift_ub_handler(), (L) * 0))
#endif

#include <math.h>

void* _ui_state = NULL;

static inline float i32_to_f32(int32_t v) { return (float)v; }

/* Host stub for @gpu kernels (device codegen replaces this). */
static inline int32_t gpu_thread_id(void) { return 0; }

int64_t gcd_i64_i64(int64_t a0, int64_t b0);
int64_t lcm_i64_i64(int64_t a, int64_t b);
int64_t isqrt_i64(int64_t n);
int64_t mulmod_i64_i64_i64(int64_t a0, int64_t b0, int64_t mod);
int64_t mod_pow_i64_i64_i64(int64_t base, int64_t exp, int64_t mod);
bool is_prime_i64(int64_t n);
int64_t modpow_i64_i64_i64(int64_t base0, int64_t exp0, int64_t mod);
bool is_prime_mr_i64(int64_t n);
int64_t smallest_prime_factor_i64(int64_t n0);
int32_t main(void);

int64_t gcd_i64_i64(int64_t a0, int64_t b0) {
    int64_t a = a0;
    int64_t b = b0;
    while (b != 0) {
        int64_t t = FLOW_CHECKED_MOD((a), (b));
        a = b;
        b = t;
    }
    return a;
}

int64_t lcm_i64_i64(int64_t a, int64_t b) {
    if ((a == 0 || b == 0)) {
        return 0;
    }
    return (FLOW_CHECKED_DIV((a), (gcd_i64_i64(a, b))) * b);
}

int64_t isqrt_i64(int64_t n) {
    if (n < 2) {
        return n;
    }
    int64_t x = n;
    int64_t y = FLOW_CHECKED_DIV(((x + 1)), (2));
    while (y < x) {
        x = y;
        y = FLOW_CHECKED_DIV(((x + FLOW_CHECKED_DIV((n), (x)))), (2));
    }
    return x;
}

int64_t mulmod_i64_i64_i64(int64_t a0, int64_t b0, int64_t mod) {
    int64_t a = FLOW_CHECKED_MOD((a0), (mod));
    int64_t b = FLOW_CHECKED_MOD((b0), (mod));
    int64_t result = 0;
    while (b > 0) {
        if (FLOW_CHECKED_MOD((b), (2)) == 1) {
            result = FLOW_CHECKED_MOD(((result + a)), (mod));
        }
        a = FLOW_CHECKED_MOD(((a * 2)), (mod));
        b = FLOW_CHECKED_DIV((b), (2));
    }
    return result;
}

int64_t mod_pow_i64_i64_i64(int64_t base, int64_t exp, int64_t mod) {
    if (mod == 1) {
        return 0;
    }
    int64_t result = 1;
    int64_t b = FLOW_CHECKED_MOD((base), (mod));
    int64_t e = exp;
    while (e > 0) {
        if (FLOW_CHECKED_MOD((e), (2)) == 1) {
            result = mulmod_i64_i64_i64(result, b, mod);
        }
        b = mulmod_i64_i64_i64(b, b, mod);
        e = FLOW_CHECKED_DIV((e), (2));
    }
    return result;
}

bool is_prime_i64(int64_t n) {
    if (n < 2) {
        return 0;
    }
    if (n < 4) {
        return 1;
    }
    if ((FLOW_CHECKED_MOD((n), (2)) == 0 || FLOW_CHECKED_MOD((n), (3)) == 0)) {
        return 0;
    }
    int64_t i = 5;
    while ((i * i) <= n) {
        if ((FLOW_CHECKED_MOD((n), (i)) == 0 || FLOW_CHECKED_MOD((n), ((i + 2))) == 0)) {
            return 0;
        }
        i = (i + 6);
    }
    return 1;
}

int64_t modpow_i64_i64_i64(int64_t base0, int64_t exp0, int64_t mod) {
    int64_t r = 1;
    int64_t b = FLOW_CHECKED_MOD((base0), (mod));
    int64_t e = exp0;
    while (e > 0) {
        if (FLOW_CHECKED_MOD((e), (2)) == 1) {
            __int128 t = FLOW_CHECKED_MOD(((((__int128)(r)) * ((__int128)(b)))), (((__int128)(mod))));
            r = ((int64_t)(t));
        }
        __int128 t2 = FLOW_CHECKED_MOD(((((__int128)(b)) * ((__int128)(b)))), (((__int128)(mod))));
        b = ((int64_t)(t2));
        e = FLOW_CHECKED_DIV((e), (2));
    }
    return r;
}

bool is_prime_mr_i64(int64_t n) {
    if (n < 2) {
        return 0;
    }
    int64_t small[12] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37 };
    int32_t i = 0;
    while (i < 12) {
        int64_t p = (((unsigned)(i) < 12) ? small[i] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)(i), 12), flow_fault_handler("array index out of bounds"), small[0]));
        if (n == p) {
            return 1;
        }
        if (FLOW_CHECKED_MOD((n), (p)) == 0) {
            return 0;
        }
        i = (i + 1);
    }
    int64_t d = (n - 1);
    int32_t s = 0;
    while (FLOW_CHECKED_MOD((d), (2)) == 0) {
        d = FLOW_CHECKED_DIV((d), (2));
        s = (s + 1);
    }
    int64_t bases[7] = { 2, 325, 9375, 28178, 450775, 9780504, 1795265022 };
    i = 0;
    while (i < 7) {
        int64_t a = FLOW_CHECKED_MOD(((((unsigned)(i) < 7) ? bases[i] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)(i), 7), flow_fault_handler("array index out of bounds"), bases[0]))), (n));
        if (a != 0) {
            int64_t x = modpow_i64_i64_i64(a, d, n);
            if ((x != 1 && x != (n - 1))) {
                int32_t r = 1;
                bool ok = 0;
                while (r < s) {
                    __int128 t = FLOW_CHECKED_MOD(((((__int128)(x)) * ((__int128)(x)))), (((__int128)(n))));
                    x = ((int64_t)(t));
                    if (x == (n - 1)) {
                        ok = 1;
                        break;
                    }
                    r = (r + 1);
                }
                if ((!(ok))) {
                    return 0;
                }
            }
        }
        i = (i + 1);
    }
    return 1;
}

int64_t smallest_prime_factor_i64(int64_t n0) {
    if (is_prime_mr_i64(n0)) {
        return n0;
    }
    if (FLOW_CHECKED_MOD((n0), (3)) == 0) {
        return 3;
    }
    int64_t f = 5;
    int64_t step = 2;
    while ((f * f) <= n0) {
        if (FLOW_CHECKED_MOD((n0), (f)) == 0) {
            return f;
        }
        f = (f + step);
        step = (6 - step);
    }
    return n0;
}

int32_t main(void) {
    int64_t N = 1000000000000000;
    int64_t idx = 9;
    int64_t ans = 0;
    while (1) {
        int64_t p = smallest_prime_factor_i64(((2 * idx) - 1));
        int64_t next = (idx + FLOW_CHECKED_DIV(((p - 1)), (2)));
        if (next > N) {
            ans = (N + (2 * idx));
            break;
        }
        if (next == N) {
            ans = (3 * N);
            break;
        }
        idx = next;
    }
    printf("%lld\n", ans);
    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 @modpow(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %175 = arith.constant 1 : i32
    %176 = arith.extsi %175 : i32 to i64
    %177 = llvm.mlir.constant(1 : i64) : i64
    %178 = llvm.alloca %177 x i64 : (i64) -> !llvm.ptr
    llvm.store %176, %178 : i64, !llvm.ptr
    %179 = arith.remsi %arg0, %arg2 : i64
    %180 = llvm.mlir.constant(1 : i64) : i64
    %181 = llvm.alloca %180 x i64 : (i64) -> !llvm.ptr
    llvm.store %179, %181 : i64, !llvm.ptr
    %182 = llvm.mlir.constant(1 : i64) : i64
    %183 = llvm.alloca %182 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %183 : i64, !llvm.ptr
    cf.br ^bb42
    ^bb42:
    %184 = llvm.load %183 : !llvm.ptr -> i64
    %185 = arith.constant 0 : i32
    %187 = arith.extsi %185 : i32 to i64
    %186 = arith.cmpi sgt, %184, %187 : i64
    cf.cond_br %186, ^bb43, ^bb44
    ^bb43:
      %188 = llvm.load %183 : !llvm.ptr -> i64
      %189 = arith.constant 2 : i32
      %191 = arith.extsi %189 : i32 to i64
      %190 = arith.remsi %188, %191 : i64
      %192 = arith.constant 1 : i32
      %194 = arith.extsi %192 : i32 to i64
      %193 = arith.cmpi eq, %190, %194 : i64
      cf.cond_br %193, ^bb45, ^bb46
      ^bb45:
        %195 = llvm.load %178 : !llvm.ptr -> i64
        %196 = arith.extsi %195 : i64 to i128
        %197 = llvm.load %181 : !llvm.ptr -> i64
        %198 = arith.extsi %197 : i64 to i128
        %200 = arith.trunci %196 : i128 to i64
        %201 = arith.trunci %198 : i128 to i64
        %199 = arith.muli %200, %201 : i64
        %202 = arith.extsi %arg2 : i64 to i128
        %204 = arith.trunci %202 : i128 to i64
        %203 = arith.remsi %199, %204 : i64
        %205 = arith.extsi %203 : i64 to i128
        %206 = arith.trunci %205 : i128 to i64
        llvm.store %206, %178 : i64, !llvm.ptr
        cf.br ^bb47
      ^bb46:
        cf.br ^bb47
      ^bb47:
      %207 = llvm.load %181 : !llvm.ptr -> i64
      %208 = arith.extsi %207 : i64 to i128
      %209 = llvm.load %181 : !llvm.ptr -> i64
      %210 = arith.extsi %209 : i64 to i128
      %212 = arith.trunci %208 : i128 to i64
      %213 = arith.trunci %210 : i128 to i64
      %211 = arith.muli %212, %213 : i64
      %214 = arith.extsi %arg2 : i64 to i128
      %216 = arith.trunci %214 : i128 to i64
      %215 = arith.remsi %211, %216 : i64
      %217 = arith.extsi %215 : i64 to i128
      %218 = arith.trunci %217 : i128 to i64
      llvm.store %218, %181 : i64, !llvm.ptr
      %219 = llvm.load %183 : !llvm.ptr -> i64
      %220 = arith.constant 2 : i32
      %222 = arith.extsi %220 : i32 to i64
      %221 = arith.divsi %219, %222 : i64
      llvm.store %221, %183 : i64, !llvm.ptr
      cf.br ^bb42
    ^bb44:
    %223 = llvm.load %178 : !llvm.ptr -> i64
    func.return %223 : i64
  }
  func.func @is_prime_mr(%arg0: i64) -> i1 {
    %224 = arith.constant 2 : i32
    %226 = arith.extsi %224 : i32 to i64
    %225 = arith.cmpi slt, %arg0, %226 : i64
    cf.cond_br %225, ^bb48, ^bb49
    ^bb48:
      %227 = arith.constant 0 : i1
      func.return %227 : i1
    ^bb49:
      cf.br ^bb50
    ^bb50:
    %229 = arith.constant 2 : i32
    %230 = arith.constant 3 : i32
    %231 = arith.constant 5 : i32
    %232 = arith.constant 7 : i32
    %233 = arith.constant 11 : i32
    %234 = arith.constant 13 : i32
    %235 = arith.constant 17 : i32
    %236 = arith.constant 19 : i32
    %237 = arith.constant 23 : i32
    %238 = arith.constant 29 : i32
    %239 = arith.constant 31 : i32
    %240 = arith.constant 37 : i32
    %241 = llvm.mlir.constant(1 : i64) : i64
    %242 = llvm.alloca %241 x !llvm.array<12 x i64> : (i64) -> !llvm.ptr
    %243 = llvm.mlir.zero : !llvm.array<12 x i64>
    llvm.store %243, %242 : !llvm.array<12 x i64>, !llvm.ptr
    %244 = arith.extsi %229 : i32 to i64
    %245 = arith.extsi %230 : i32 to i64
    %246 = arith.extsi %231 : i32 to i64
    %247 = arith.extsi %232 : i32 to i64
    %248 = arith.extsi %233 : i32 to i64
    %249 = arith.extsi %234 : i32 to i64
    %250 = arith.extsi %235 : i32 to i64
    %251 = arith.extsi %236 : i32 to i64
    %252 = arith.extsi %237 : i32 to i64
    %253 = arith.extsi %238 : i32 to i64
    %254 = arith.extsi %239 : i32 to i64
    %255 = arith.extsi %240 : i32 to i64
    %256 = llvm.mlir.constant(0 : i64) : i64
    %257 = llvm.getelementptr %242[0, %256] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<12 x i64>
    llvm.store %244, %257 : i64, !llvm.ptr
    %258 = llvm.mlir.constant(1 : i64) : i64
    %259 = llvm.getelementptr %242[0, %258] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<12 x i64>
    llvm.store %245, %259 : i64, !llvm.ptr
    %260 = llvm.mlir.constant(2 : i64) : i64
    %261 = llvm.getelementptr %242[0, %260] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<12 x i64>
    llvm.store %246, %261 : i64, !llvm.ptr
    %262 = llvm.mlir.constant(3 : i64) : i64
    %263 = llvm.getelementptr %242[0, %262] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<12 x i64>
    llvm.store %247, %263 : i64, !llvm.ptr
    %264 = llvm.mlir.constant(4 : i64) : i64
    %265 = llvm.getelementptr %242[0, %264] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<12 x i64>
    llvm.store %248, %265 : i64, !llvm.ptr
    %266 = llvm.mlir.constant(5 : i64) : i64
    %267 = llvm.getelementptr %242[0, %266] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<12 x i64>
    llvm.store %249, %267 : i64, !llvm.ptr
    %268 = llvm.mlir.constant(6 : i64) : i64
    %269 = llvm.getelementptr %242[0, %268] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<12 x i64>
    llvm.store %250, %269 : i64, !llvm.ptr
    %270 = llvm.mlir.constant(7 : i64) : i64
    %271 = llvm.getelementptr %242[0, %270] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<12 x i64>
    llvm.store %251, %271 : i64, !llvm.ptr
    %272 = llvm.mlir.constant(8 : i64) : i64
    %273 = llvm.getelementptr %242[0, %272] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<12 x i64>
    llvm.store %252, %273 : i64, !llvm.ptr
    %274 = llvm.mlir.constant(9 : i64) : i64
    %275 = llvm.getelementptr %242[0, %274] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<12 x i64>
    llvm.store %253, %275 : i64, !llvm.ptr
    %276 = llvm.mlir.constant(10 : i64) : i64
    %277 = llvm.getelementptr %242[0, %276] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<12 x i64>
    llvm.store %254, %277 : i64, !llvm.ptr
    %278 = llvm.mlir.constant(11 : i64) : i64
    %279 = llvm.getelementptr %242[0, %278] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<12 x i64>
    llvm.store %255, %279 : i64, !llvm.ptr
    %280 = arith.constant 0 : i32
    %281 = llvm.mlir.constant(1 : i64) : i64
    %282 = llvm.alloca %281 x i32 : (i64) -> !llvm.ptr
    llvm.store %280, %282 : i32, !llvm.ptr
    cf.br ^bb51
    ^bb51:
    %283 = llvm.load %282 : !llvm.ptr -> i32
    %284 = arith.constant 12 : i32
    %285 = arith.cmpi slt, %283, %284 : i32
    cf.cond_br %285, ^bb52, ^bb53
    ^bb52:
      %287 = llvm.load %282 : !llvm.ptr -> i32
      %288 = arith.extsi %287 : i32 to i64
      %289 = llvm.getelementptr %242[0, %288] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<12 x i64>
      %286 = llvm.load %289 : !llvm.ptr -> i64
      %290 = arith.cmpi eq, %arg0, %286 : i64
      cf.cond_br %290, ^bb54, ^bb55
      ^bb54:
        %291 = arith.constant 1 : i1
        func.return %291 : i1
      ^bb55:
        cf.br ^bb56
      ^bb56:
      %292 = arith.remsi %arg0, %286 : i64
      %293 = arith.constant 0 : i32
      %295 = arith.extsi %293 : i32 to i64
      %294 = arith.cmpi eq, %292, %295 : i64
      cf.cond_br %294, ^bb57, ^bb58
      ^bb57:
        %296 = arith.constant 0 : i1
        func.return %296 : i1
      ^bb58:
        cf.br ^bb59
      ^bb59:
      %297 = llvm.load %282 : !llvm.ptr -> i32
      %298 = arith.constant 1 : i32
      %299 = arith.addi %297, %298 : i32
      llvm.store %299, %282 : i32, !llvm.ptr
      cf.br ^bb51
    ^bb53:
    %300 = arith.constant 1 : i32
    %302 = arith.extsi %300 : i32 to i64
    %301 = arith.subi %arg0, %302 : i64
    %303 = llvm.mlir.constant(1 : i64) : i64
    %304 = llvm.alloca %303 x i64 : (i64) -> !llvm.ptr
    llvm.store %301, %304 : i64, !llvm.ptr
    %305 = arith.constant 0 : i32
    %306 = llvm.mlir.constant(1 : i64) : i64
    %307 = llvm.alloca %306 x i32 : (i64) -> !llvm.ptr
    llvm.store %305, %307 : i32, !llvm.ptr
    cf.br ^bb60
    ^bb60:
    %308 = llvm.load %304 : !llvm.ptr -> i64
    %309 = arith.constant 2 : i32
    %311 = arith.extsi %309 : i32 to i64
    %310 = arith.remsi %308, %311 : i64
    %312 = arith.constant 0 : i32
    %314 = arith.extsi %312 : i32 to i64
    %313 = arith.cmpi eq, %310, %314 : i64
    cf.cond_br %313, ^bb61, ^bb62
    ^bb61:
      %315 = llvm.load %304 : !llvm.ptr -> i64
      %316 = arith.constant 2 : i32
      %318 = arith.extsi %316 : i32 to i64
      %317 = arith.divsi %315, %318 : i64
      llvm.store %317, %304 : i64, !llvm.ptr
      %319 = llvm.load %307 : !llvm.ptr -> i32
      %320 = arith.constant 1 : i32
      %321 = arith.addi %319, %320 : i32
      llvm.store %321, %307 : i32, !llvm.ptr
      cf.br ^bb60
    ^bb62:
    %323 = arith.constant 2 : i32
    %324 = arith.constant 325 : i32
    %325 = arith.constant 9375 : i32
    %326 = arith.constant 28178 : i32
    %327 = arith.constant 450775 : i32
    %328 = arith.constant 9780504 : i32
    %329 = arith.constant 1795265022 : i32
    %330 = llvm.mlir.constant(1 : i64) : i64
    %331 = llvm.alloca %330 x !llvm.array<7 x i64> : (i64) -> !llvm.ptr
    %332 = llvm.mlir.zero : !llvm.array<7 x i64>
    llvm.store %332, %331 : !llvm.array<7 x i64>, !llvm.ptr
    %333 = arith.extsi %323 : i32 to i64
    %334 = arith.extsi %324 : i32 to i64
    %335 = arith.extsi %325 : i32 to i64
    %336 = arith.extsi %326 : i32 to i64
    %337 = arith.extsi %327 : i32 to i64
    %338 = arith.extsi %328 : i32 to i64
    %339 = arith.extsi %329 : i32 to i64
    %340 = llvm.mlir.constant(0 : i64) : i64
    %341 = llvm.getelementptr %331[0, %340] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<7 x i64>
    llvm.store %333, %341 : i64, !llvm.ptr
    %342 = llvm.mlir.constant(1 : i64) : i64
    %343 = llvm.getelementptr %331[0, %342] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<7 x i64>
    llvm.store %334, %343 : i64, !llvm.ptr
    %344 = llvm.mlir.constant(2 : i64) : i64
    %345 = llvm.getelementptr %331[0, %344] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<7 x i64>
    llvm.store %335, %345 : i64, !llvm.ptr
    %346 = llvm.mlir.constant(3 : i64) : i64
    %347 = llvm.getelementptr %331[0, %346] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<7 x i64>
    llvm.store %336, %347 : i64, !llvm.ptr
    %348 = llvm.mlir.constant(4 : i64) : i64
    %349 = llvm.getelementptr %331[0, %348] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<7 x i64>
    llvm.store %337, %349 : i64, !llvm.ptr
    %350 = llvm.mlir.constant(5 : i64) : i64
    %351 = llvm.getelementptr %331[0, %350] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<7 x i64>
    llvm.store %338, %351 : i64, !llvm.ptr
    %352 = llvm.mlir.constant(6 : i64) : i64
    %353 = llvm.getelementptr %331[0, %352] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<7 x i64>
    llvm.store %339, %353 : i64, !llvm.ptr
    %354 = arith.constant 0 : i32
    llvm.store %354, %282 : i32, !llvm.ptr
    cf.br ^bb63
    ^bb63:
    %355 = llvm.load %282 : !llvm.ptr -> i32
    %356 = arith.constant 7 : i32
    %357 = arith.cmpi slt, %355, %356 : i32
    cf.cond_br %357, ^bb64, ^bb65
    ^bb64:
      %359 = llvm.load %282 : !llvm.ptr -> i32
      %360 = arith.extsi %359 : i32 to i64
      %361 = llvm.getelementptr %331[0, %360] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<7 x i64>
      %358 = llvm.load %361 : !llvm.ptr -> i64
      %362 = arith.remsi %358, %arg0 : i64
      %363 = arith.constant 0 : i32
      %365 = arith.extsi %363 : i32 to i64
      %364 = arith.cmpi ne, %362, %365 : i64
      cf.cond_br %364, ^bb66, ^bb67
      ^bb66:
        %367 = llvm.load %304 : !llvm.ptr -> i64
        %366 = func.call @modpow(%362, %367, %arg0) : (i64, i64, i64) -> i64
        %368 = llvm.mlir.constant(1 : i64) : i64
        %369 = llvm.alloca %368 x i64 : (i64) -> !llvm.ptr
        llvm.store %366, %369 : i64, !llvm.ptr
        %370 = llvm.load %369 : !llvm.ptr -> i64
        %371 = arith.constant 1 : i32
        %373 = arith.extsi %371 : i32 to i64
        %372 = arith.cmpi ne, %370, %373 : i64
        %374 = scf.if %372 -> (i1) {
          %375 = llvm.load %369 : !llvm.ptr -> i64
          %376 = arith.constant 1 : i32
          %378 = arith.extsi %376 : i32 to i64
          %377 = arith.subi %arg0, %378 : i64
          %379 = arith.cmpi ne, %375, %377 : i64
          scf.yield %379 : i1
        } else {
          %380 = arith.constant false
          scf.yield %380 : i1
        }
        cf.cond_br %374, ^bb69, ^bb70
        ^bb69:
          %381 = arith.constant 1 : i32
          %382 = llvm.mlir.constant(1 : i64) : i64
          %383 = llvm.alloca %382 x i32 : (i64) -> !llvm.ptr
          llvm.store %381, %383 : i32, !llvm.ptr
          %384 = arith.constant 0 : i1
          %385 = llvm.mlir.constant(1 : i64) : i64
          %386 = llvm.alloca %385 x i1 : (i64) -> !llvm.ptr
          llvm.store %384, %386 : i1, !llvm.ptr
          cf.br ^bb72
          ^bb72:
          %387 = llvm.load %383 : !llvm.ptr -> i32
          %388 = llvm.load %307 : !llvm.ptr -> i32
          %389 = arith.cmpi slt, %387, %388 : i32
          cf.cond_br %389, ^bb73, ^bb74
          ^bb73:
            %390 = llvm.load %369 : !llvm.ptr -> i64
            %391 = arith.extsi %390 : i64 to i128
            %392 = llvm.load %369 : !llvm.ptr -> i64
            %393 = arith.extsi %392 : i64 to i128
            %395 = arith.trunci %391 : i128 to i64
            %396 = arith.trunci %393 : i128 to i64
            %394 = arith.muli %395, %396 : i64
            %397 = arith.extsi %arg0 : i64 to i128
            %399 = arith.trunci %397 : i128 to i64
            %398 = arith.remsi %394, %399 : i64
            %400 = arith.extsi %398 : i64 to i128
            %401 = arith.trunci %400 : i128 to i64
            llvm.store %401, %369 : i64, !llvm.ptr
            %402 = llvm.load %369 : !llvm.ptr -> i64
            %403 = arith.constant 1 : i32
            %405 = arith.extsi %403 : i32 to i64
            %404 = arith.subi %arg0, %405 : i64
            %406 = arith.cmpi eq, %402, %404 : i64
            cf.cond_br %406, ^bb75, ^bb76
            ^bb75:
              %407 = arith.constant 1 : i1
              llvm.store %407, %386 : i1, !llvm.ptr
              cf.br ^bb74
            ^bb76:
              cf.br ^bb77
            ^bb77:
            %408 = llvm.load %383 : !llvm.ptr -> i32
            %409 = arith.constant 1 : i32
            %410 = arith.addi %408, %409 : i32
            llvm.store %410, %383 : i32, !llvm.ptr
            cf.br ^bb72
          ^bb74:
          %411 = llvm.load %386 : !llvm.ptr -> i1
          %413 = arith.constant 1 : i1
          %412 = arith.xori %411, %413 : i1
          cf.cond_br %412, ^bb78, ^bb79
          ^bb78:
            %415 = arith.constant 0 : i1
            func.return %415 : i1
          ^bb79:
            cf.br ^bb80
          ^bb80:
          cf.br ^bb71
        ^bb70:
          cf.br ^bb71
        ^bb71:
        cf.br ^bb68
      ^bb67:
        cf.br ^bb68
      ^bb68:
      %416 = llvm.load %282 : !llvm.ptr -> i32
      %417 = arith.constant 1 : i32
      %418 = arith.addi %416, %417 : i32
      llvm.store %418, %282 : i32, !llvm.ptr
      cf.br ^bb63
    ^bb65:
    %419 = arith.constant 1 : i1
    func.return %419 : i1
  }
  func.func @smallest_prime_factor(%arg0: i64) -> i64 {
    %420 = func.call @is_prime_mr(%arg0) : (i64) -> i1
    cf.cond_br %420, ^bb81, ^bb82
    ^bb81:
      func.return %arg0 : i64
    ^bb82:
      cf.br ^bb83
    ^bb83:
    %421 = arith.constant 3 : i32
    %423 = arith.extsi %421 : i32 to i64
    %422 = arith.remsi %arg0, %423 : i64
    %424 = arith.constant 0 : i32
    %426 = arith.extsi %424 : i32 to i64
    %425 = arith.cmpi eq, %422, %426 : i64
    cf.cond_br %425, ^bb84, ^bb85
    ^bb84:
      %427 = arith.constant 3 : i32
      %428 = arith.extsi %427 : i32 to i64
      func.return %428 : i64
    ^bb85:
      cf.br ^bb86
    ^bb86:
    %429 = arith.constant 5 : i32
    %430 = arith.extsi %429 : i32 to i64
    %431 = llvm.mlir.constant(1 : i64) : i64
    %432 = llvm.alloca %431 x i64 : (i64) -> !llvm.ptr
    llvm.store %430, %432 : i64, !llvm.ptr
    %433 = arith.constant 2 : i32
    %434 = arith.extsi %433 : i32 to i64
    %435 = llvm.mlir.constant(1 : i64) : i64
    %436 = llvm.alloca %435 x i64 : (i64) -> !llvm.ptr
    llvm.store %434, %436 : i64, !llvm.ptr
    cf.br ^bb87
    ^bb87:
    %437 = llvm.load %432 : !llvm.ptr -> i64
    %438 = llvm.load %432 : !llvm.ptr -> i64
    %439 = arith.muli %437, %438 : i64
    %440 = arith.cmpi sle, %439, %arg0 : i64
    cf.cond_br %440, ^bb88, ^bb89
    ^bb88:
      %441 = llvm.load %432 : !llvm.ptr -> i64
      %442 = arith.remsi %arg0, %441 : i64
      %443 = arith.constant 0 : i32
      %445 = arith.extsi %443 : i32 to i64
      %444 = arith.cmpi eq, %442, %445 : i64
      cf.cond_br %444, ^bb90, ^bb91
      ^bb90:
        %446 = llvm.load %432 : !llvm.ptr -> i64
        func.return %446 : i64
      ^bb91:
        cf.br ^bb92
      ^bb92:
      %447 = llvm.load %432 : !llvm.ptr -> i64
      %448 = llvm.load %436 : !llvm.ptr -> i64
      %449 = arith.addi %447, %448 : i64
      llvm.store %449, %432 : i64, !llvm.ptr
      %450 = arith.constant 6 : i32
      %451 = llvm.load %436 : !llvm.ptr -> i64
      %453 = arith.extsi %450 : i32 to i64
      %452 = arith.subi %453, %451 : i64
      llvm.store %452, %436 : i64, !llvm.ptr
      cf.br ^bb87
    ^bb89:
    func.return %arg0 : i64
  }
  func.func @main() -> i32 {
    %454 = arith.constant 999995705032704 : i32
    %455 = arith.extsi %454 : i32 to i64
    %456 = arith.constant 9 : i32
    %457 = arith.extsi %456 : i32 to i64
    %458 = llvm.mlir.constant(1 : i64) : i64
    %459 = llvm.alloca %458 x i64 : (i64) -> !llvm.ptr
    llvm.store %457, %459 : i64, !llvm.ptr
    %460 = arith.constant 0 : i32
    %461 = arith.extsi %460 : i32 to i64
    %462 = llvm.mlir.constant(1 : i64) : i64
    %463 = llvm.alloca %462 x i64 : (i64) -> !llvm.ptr
    llvm.store %461, %463 : i64, !llvm.ptr
    cf.br ^bb93
    ^bb93:
    %464 = arith.constant 1 : i1
    cf.cond_br %464, ^bb94, ^bb95
    ^bb94:
      %466 = arith.constant 2 : i32
      %467 = llvm.load %459 : !llvm.ptr -> i64
      %469 = arith.extsi %466 : i32 to i64
      %468 = arith.muli %469, %467 : i64
      %470 = arith.constant 1 : i32
      %472 = arith.extsi %470 : i32 to i64
      %471 = arith.subi %468, %472 : i64
      %465 = func.call @smallest_prime_factor(%471) : (i64) -> i64
      %473 = llvm.load %459 : !llvm.ptr -> i64
      %474 = arith.constant 1 : i32
      %476 = arith.extsi %474 : i32 to i64
      %475 = arith.subi %465, %476 : i64
      %477 = arith.constant 2 : i32
      %479 = arith.extsi %477 : i32 to i64
      %478 = arith.divsi %475, %479 : i64
      %480 = arith.addi %473, %478 : i64
      %481 = arith.cmpi sgt, %480, %455 : i64
      cf.cond_br %481, ^bb96, ^bb97
      ^bb96:
        %482 = arith.constant 2 : i32
        %483 = llvm.load %459 : !llvm.ptr -> i64
        %485 = arith.extsi %482 : i32 to i64
        %484 = arith.muli %485, %483 : i64
        %486 = arith.addi %455, %484 : i64
        llvm.store %486, %463 : i64, !llvm.ptr
        cf.br ^bb95
      ^bb97:
        cf.br ^bb98
      ^bb98:
      %487 = arith.cmpi eq, %480, %455 : i64
      cf.cond_br %487, ^bb99, ^bb100
      ^bb99:
        %488 = arith.constant 3 : i32
        %490 = arith.extsi %488 : i32 to i64
        %489 = arith.muli %490, %455 : i64
        llvm.store %489, %463 : i64, !llvm.ptr
        cf.br ^bb95
      ^bb100:
        cf.br ^bb101
      ^bb101:
      llvm.store %480, %459 : i64, !llvm.ptr
      cf.br ^bb93
    ^bb95:
    %491 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %492 = llvm.load %463 : !llvm.ptr -> i64
    %493 = llvm.call @printf(%491, %492) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    %494 = arith.constant 0 : i32
    func.return %494 : i32
  }
}