Problem 437

Sum of primes p < 10^8 that have a Fibonacci primitive root.

Answer74204709657207
Output74204709657207
StatusPASS
Native helperno
Runtime2870 ms
Peak memory2144 KB
Time complexityO(n^2) (estimated)
Space complexityO(n^2) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^2)O(log n)
Space complexityO(n^2)O(1)
ApproachFlow solutionMatrix exponentiation
VerdictSuboptimal

Flow source

# Project Euler 437
# Sum of primes p < 10^8 that have a Fibonacci primitive root.

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

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

function is_prime_mr(n: i64) -> bool {
    if n < 2 { return false }
    let sp: array<i64, 12> = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]
    let mut i: i64 = 0
    while i < 12 {
        let p: i64 = sp[i]
        if n == p { return true }
        if n % p == 0 { return false }
        i = i + 1
    }
    let mut d: i64 = n - 1
    let mut s: i64 = 0
    while d % 2 == 0 { d = d / 2; s = s + 1 }
    let bases: array<i64, 5> = [2, 3, 5, 7, 11]
    i = 0
    while i < 5 {
        let a: i64 = bases[i]
        if a % n == 0 { i = i + 1; continue }
        let mut x: i64 = mod_pow(a, d, n)
        if x == 1 || x == n - 1 { i = i + 1; continue }
        let mut ok: bool = false
        let mut r: i64 = 1
        while r < s {
            x = (x * x) % n
            if x == n - 1 { ok = true; break }
            r = r + 1
        }
        if !ok { return false }
        i = i + 1
    }
    return true
}

function tonelli(n0: i64, p: i64) -> i64 {
    let n: i64 = n0 % p
    if n == 0 { return 0 }
    if p % 4 == 3 { return mod_pow(n, (p + 1) / 4, p) }
    let mut q: i64 = p - 1
    let mut s: i64 = 0
    while q % 2 == 0 { q = q / 2; s = s + 1 }
    let mut z: i64 = 2
    while mod_pow(z, (p - 1) / 2, p) != p - 1 { z = z + 1 }
    let mut c: i64 = mod_pow(z, q, p)
    let mut r: i64 = mod_pow(n, (q + 1) / 2, p)
    let mut t: i64 = mod_pow(n, q, p)
    let mut m: i64 = s
    while t != 1 {
        let mut i: i64 = 1
        let mut t2: i64 = (t * t) % p
        while t2 != 1 {
            t2 = (t2 * t2) % p
            i = i + 1
        }
        let b: i64 = mod_pow(c, 1 << (m - i - 1), p)
        r = (r * b) % p
        c = (b * b) % p
        t = (t * c) % p
        m = i
    }
    return r
}

function is_prim_root(g: i64, p: i64, factors: ptr<i64>, nf: i64) -> bool {
    let mut i: i64 = 0
    while i < nf {
        let f: i64 = factors[i]
        if mod_pow(g, (p - 1) / f, p) == 1 { return false }
        i = i + 1
    }
    return true
}

function main() -> i32 {
    let LIMIT: i64 = 100000000
    let SQR: i64 = 10000
    let sieve: ptr<i8> = calloc(SQR + 1, 1)
    let primes: ptr<i32> = calloc(SQR, 4)
    if sieve == null || primes == null { return 1 }
    let mut pc: i64 = 0
    let mut i: i64 = 2
    while i <= SQR {
        if sieve[i] == 0 {
            primes[pc] = i as i32
            pc = pc + 1
            let mut j: i64 = i * i
            while j <= SQR {
                sieve[j] = 1
                j = j + i
            }
        }
        i = i + 1
    }

    let factors: ptr<i64> = calloc(64, 8)
    let mut total: i64 = 5  # prime 5
    let SEG: i64 = 1000000
    let seg: ptr<i8> = calloc(SEG, 1)
    if seg == null { return 1 }

    let mut low: i64 = 2
    while low < LIMIT {
        let high: i64 = low + SEG
        if high > LIMIT { high = LIMIT }
        let mut t: i64 = 0
        while t < high - low { seg[t] = 0; t = t + 1 }

        let mut pi: i64 = 0
        while pi < pc {
            let p: i64 = primes[pi] as i64
            let mut start: i64 = ((low + p - 1) / p) * p
            if start < p * p { start = p * p }
            let mut x: i64 = start
            while x < high {
                seg[x - low] = 1
                x = x + p
            }
            pi = pi + 1
        }

        let mut n: i64 = low
        if n < 3 { n = 3 }
        if n % 2 == 0 { n = n + 1 }
        while n < high {
            if seg[n - low] == 0 && n > 5 {
                let r5: i64 = n % 5
                if r5 == 1 || r5 == 4 {
                    # sqrt(5) mod n
                    let mut s: i64 = 0
                    if n % 4 == 3 {
                        s = mod_pow(5, (n + 1) / 4, n)
                    } else {
                        s = tonelli(5, n)
                    }
                    let inv2: i64 = (n + 1) / 2
                    let g1: i64 = ((1 + s) * inv2) % n
                    let g2: i64 = ((1 - s) % n + n) % n * inv2 % n

                    # factor n-1
                    let mut m: i64 = n - 1
                    let mut nf: i64 = 0
                    if m % 2 == 0 {
                        factors[nf] = 2
                        nf = nf + 1
                        while m % 2 == 0 { m = m / 2 }
                    }
                    let mut jj: i64 = 0
                    while jj < pc {
                        let p: i64 = primes[jj] as i64
                        if p * p > m { break }
                        if m % p == 0 {
                            factors[nf] = p
                            nf = nf + 1
                            while m % p == 0 { m = m / p }
                        }
                        jj = jj + 1
                    }
                    if m > 1 {
                        factors[nf] = m
                        nf = nf + 1
                    }
                    if is_prim_root(g1, n, factors, nf) || is_prim_root(g2, n, factors, nf) {
                        total = total + n
                    }
                }
            }
            n = n + 2
        }
        low = high
    }

    printf("%lld\n", total)
    free(seg)
    free(factors)
    free(primes)
    free(sieve)
    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(int64_t a0, int64_t e0, int64_t mod);
bool is_prime_mr_i64(int64_t n);
int64_t tonelli_i64_i64(int64_t n0, int64_t p);
bool is_prim_root_i64_i64_ptr_i64_i64(int64_t g, int64_t p, int64_t* factors, int64_t nf);
int32_t main(void);



int64_t mod_pow_i64_i64_i64(int64_t a0, int64_t e0, int64_t mod) {
    int64_t a = FLOW_CHECKED_MOD((a0), (mod));
    if (a < 0) {
        a = (a + mod);
    }
    int64_t e = e0;
    int64_t r = 1;
    while (e > 0) {
        if (FLOW_CHECKED_MOD((e), (2)) == 1) {
            r = FLOW_CHECKED_MOD(((r * a)), (mod));
        }
        a = FLOW_CHECKED_MOD(((a * a)), (mod));
        e = FLOW_CHECKED_DIV((e), (2));
    }
    return r;
}

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

int64_t tonelli_i64_i64(int64_t n0, int64_t p) {
    int64_t n = FLOW_CHECKED_MOD((n0), (p));
    if (n == 0) {
        return 0;
    }
    if (FLOW_CHECKED_MOD((p), (4)) == 3) {
        return mod_pow_i64_i64_i64(n, FLOW_CHECKED_DIV(((p + 1)), (4)), p);
    }
    int64_t q = (p - 1);
    int64_t s = 0;
    while (FLOW_CHECKED_MOD((q), (2)) == 0) {
        q = FLOW_CHECKED_DIV((q), (2));
        s = (s + 1);
    }
    int64_t z = 2;
    while (mod_pow_i64_i64_i64(z, FLOW_CHECKED_DIV(((p - 1)), (2)), p) != (p - 1)) {
        z = (z + 1);
    }
    int64_t c = mod_pow_i64_i64_i64(z, q, p);
    int64_t r = mod_pow_i64_i64_i64(n, FLOW_CHECKED_DIV(((q + 1)), (2)), p);
    int64_t t = mod_pow_i64_i64_i64(n, q, p);
    int64_t m = s;
    while (t != 1) {
        int64_t i = 1;
        int64_t t2 = FLOW_CHECKED_MOD(((t * t)), (p));
        while (t2 != 1) {
            t2 = FLOW_CHECKED_MOD(((t2 * t2)), (p));
            i = (i + 1);
        }
        int64_t b = mod_pow_i64_i64_i64(c, FLOW_CHECKED_SHL((1), (((m - i) - 1))), p);
        r = FLOW_CHECKED_MOD(((r * b)), (p));
        c = FLOW_CHECKED_MOD(((b * b)), (p));
        t = FLOW_CHECKED_MOD(((t * c)), (p));
        m = i;
    }
    return r;
}

bool is_prim_root_i64_i64_ptr_i64_i64(int64_t g, int64_t p, int64_t* factors, int64_t nf) {
    int64_t i = 0;
    while (i < nf) {
        int64_t f = factors[i];
        if (mod_pow_i64_i64_i64(g, FLOW_CHECKED_DIV(((p - 1)), (f)), p) == 1) {
            return 0;
        }
        i = (i + 1);
    }
    return 1;
}

int32_t main(void) {
    int64_t LIMIT = 100000000;
    int64_t SQR = 10000;
    int8_t* sieve = (int8_t*)(calloc((SQR + 1), 1));
    int32_t* primes = (int32_t*)(calloc(SQR, 4));
    if ((sieve == NULL || primes == NULL)) {
        return 1;
    }
    int64_t pc = 0;
    int64_t i = 2;
    while (i <= SQR) {
        if (sieve[i] == 0) {
            primes[pc] = ((int32_t)(i));
            pc = (pc + 1);
            int64_t j = (i * i);
            while (j <= SQR) {
                sieve[j] = 1;
                j = (j + i);
            }
        }
        i = (i + 1);
    }
    int64_t* factors = (int64_t*)(calloc(64, 8));
    int64_t total = 5;
    int64_t SEG = 1000000;
    int8_t* seg = (int8_t*)(calloc(SEG, 1));
    if (seg == NULL) {
        return 1;
    }
    int64_t low = 2;
    while (low < LIMIT) {
        int64_t high = (low + SEG);
        if (high > LIMIT) {
            high = LIMIT;
        }
        int64_t t = 0;
        while (t < (high - low)) {
            seg[t] = 0;
            t = (t + 1);
        }
        int64_t pi = 0;
        while (pi < pc) {
            int64_t p = ((int64_t)(primes[pi]));
            int64_t start = (FLOW_CHECKED_DIV((((low + p) - 1)), (p)) * p);
            if (start < (p * p)) {
                start = (p * p);
            }
            int64_t x = start;
            while (x < high) {
                seg[(x - low)] = 1;
                x = (x + p);
            }
            pi = (pi + 1);
        }
        int64_t n = low;
        if (n < 3) {
            n = 3;
        }
        if (FLOW_CHECKED_MOD((n), (2)) == 0) {
            n = (n + 1);
        }
        while (n < high) {
            if ((seg[(n - low)] == 0 && n > 5)) {
                int64_t r5 = FLOW_CHECKED_MOD((n), (5));
                if ((r5 == 1 || r5 == 4)) {
                    int64_t s = 0;
                    if (FLOW_CHECKED_MOD((n), (4)) == 3) {
                        s = mod_pow_i64_i64_i64(5, FLOW_CHECKED_DIV(((n + 1)), (4)), n);
                    } else {
                        s = tonelli_i64_i64(5, n);
                    }
                    int64_t inv2 = FLOW_CHECKED_DIV(((n + 1)), (2));
                    int64_t g1 = FLOW_CHECKED_MOD((((1 + s) * inv2)), (n));
                    int64_t g2 = FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD(((1 - s)), (n)) + n)), (n)) * inv2)), (n));
                    int64_t m = (n - 1);
                    int64_t nf = 0;
                    if (FLOW_CHECKED_MOD((m), (2)) == 0) {
                        factors[nf] = 2;
                        nf = (nf + 1);
                        while (FLOW_CHECKED_MOD((m), (2)) == 0) {
                            m = FLOW_CHECKED_DIV((m), (2));
                        }
                    }
                    int64_t jj = 0;
                    while (jj < pc) {
                        int64_t p = ((int64_t)(primes[jj]));
                        if ((p * p) > m) {
                            break;
                        }
                        if (FLOW_CHECKED_MOD((m), (p)) == 0) {
                            factors[nf] = p;
                            nf = (nf + 1);
                            while (FLOW_CHECKED_MOD((m), (p)) == 0) {
                                m = FLOW_CHECKED_DIV((m), (p));
                            }
                        }
                        jj = (jj + 1);
                    }
                    if (m > 1) {
                        factors[nf] = m;
                        nf = (nf + 1);
                    }
                    if ((is_prim_root_i64_i64_ptr_i64_i64(g1, n, factors, nf) || is_prim_root_i64_i64_ptr_i64_i64(g2, n, factors, nf))) {
                        total = (total + n);
                    }
                }
            }
            n = (n + 2);
        }
        low = high;
    }
    printf("%lld\n", total);
    free(seg);
    free(factors);
    free(primes);
    free(sieve);
    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 @mod_pow(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %0 = arith.remsi %arg0, %arg2 : i64
    %1 = llvm.mlir.constant(1 : i64) : i64
    %2 = llvm.alloca %1 x i64 : (i64) -> !llvm.ptr
    llvm.store %0, %2 : i64, !llvm.ptr
    %3 = llvm.load %2 : !llvm.ptr -> i64
    %4 = arith.constant 0 : i32
    %6 = arith.extsi %4 : i32 to i64
    %5 = arith.cmpi slt, %3, %6 : i64
    cf.cond_br %5, ^bb0, ^bb1
    ^bb0:
      %7 = llvm.load %2 : !llvm.ptr -> i64
      %8 = arith.addi %7, %arg2 : i64
      llvm.store %8, %2 : i64, !llvm.ptr
      cf.br ^bb2
    ^bb1:
      cf.br ^bb2
    ^bb2:
    %9 = llvm.mlir.constant(1 : i64) : i64
    %10 = llvm.alloca %9 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %10 : i64, !llvm.ptr
    %11 = arith.constant 1 : i32
    %12 = arith.extsi %11 : i32 to i64
    %13 = llvm.mlir.constant(1 : i64) : i64
    %14 = llvm.alloca %13 x i64 : (i64) -> !llvm.ptr
    llvm.store %12, %14 : i64, !llvm.ptr
    cf.br ^bb3
    ^bb3:
    %15 = llvm.load %10 : !llvm.ptr -> i64
    %16 = arith.constant 0 : i32
    %18 = arith.extsi %16 : i32 to i64
    %17 = arith.cmpi sgt, %15, %18 : i64
    cf.cond_br %17, ^bb4, ^bb5
    ^bb4:
      %19 = llvm.load %10 : !llvm.ptr -> i64
      %20 = arith.constant 2 : i32
      %22 = arith.extsi %20 : i32 to i64
      %21 = arith.remsi %19, %22 : i64
      %23 = arith.constant 1 : i32
      %25 = arith.extsi %23 : i32 to i64
      %24 = arith.cmpi eq, %21, %25 : i64
      cf.cond_br %24, ^bb6, ^bb7
      ^bb6:
        %26 = llvm.load %14 : !llvm.ptr -> i64
        %27 = llvm.load %2 : !llvm.ptr -> i64
        %28 = arith.muli %26, %27 : i64
        %29 = arith.remsi %28, %arg2 : i64
        llvm.store %29, %14 : i64, !llvm.ptr
        cf.br ^bb8
      ^bb7:
        cf.br ^bb8
      ^bb8:
      %30 = llvm.load %2 : !llvm.ptr -> i64
      %31 = llvm.load %2 : !llvm.ptr -> i64
      %32 = arith.muli %30, %31 : i64
      %33 = arith.remsi %32, %arg2 : i64
      llvm.store %33, %2 : i64, !llvm.ptr
      %34 = llvm.load %10 : !llvm.ptr -> i64
      %35 = arith.constant 2 : i32
      %37 = arith.extsi %35 : i32 to i64
      %36 = arith.divsi %34, %37 : i64
      llvm.store %36, %10 : i64, !llvm.ptr
      cf.br ^bb3
    ^bb5:
    %38 = llvm.load %14 : !llvm.ptr -> i64
    func.return %38 : i64
  }
  func.func @is_prime_mr(%arg0: i64) -> i1 {
    %39 = arith.constant 2 : i32
    %41 = arith.extsi %39 : i32 to i64
    %40 = arith.cmpi slt, %arg0, %41 : i64
    cf.cond_br %40, ^bb9, ^bb10
    ^bb9:
      %42 = arith.constant 0 : i1
      func.return %42 : i1
    ^bb10:
      cf.br ^bb11
    ^bb11:
    %44 = arith.constant 2 : i32
    %45 = arith.constant 3 : i32
    %46 = arith.constant 5 : i32
    %47 = arith.constant 7 : i32
    %48 = arith.constant 11 : i32
    %49 = arith.constant 13 : i32
    %50 = arith.constant 17 : i32
    %51 = arith.constant 19 : i32
    %52 = arith.constant 23 : i32
    %53 = arith.constant 29 : i32
    %54 = arith.constant 31 : i32
    %55 = arith.constant 37 : i32
    %56 = llvm.mlir.constant(1 : i64) : i64
    %57 = llvm.alloca %56 x !llvm.array<12 x i64> : (i64) -> !llvm.ptr
    %58 = llvm.mlir.zero : !llvm.array<12 x i64>
    llvm.store %58, %57 : !llvm.array<12 x i64>, !llvm.ptr
    %59 = arith.extsi %44 : i32 to i64
    %60 = arith.extsi %45 : i32 to i64
    %61 = arith.extsi %46 : i32 to i64
    %62 = arith.extsi %47 : i32 to i64
    %63 = arith.extsi %48 : i32 to i64
    %64 = arith.extsi %49 : i32 to i64
    %65 = arith.extsi %50 : i32 to i64
    %66 = arith.extsi %51 : i32 to i64
    %67 = arith.extsi %52 : i32 to i64
    %68 = arith.extsi %53 : i32 to i64
    %69 = arith.extsi %54 : i32 to i64
    %70 = arith.extsi %55 : i32 to i64
    %71 = llvm.mlir.constant(0 : i64) : i64
    %72 = llvm.getelementptr %57[0, %71] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<12 x i64>
    llvm.store %59, %72 : i64, !llvm.ptr
    %73 = llvm.mlir.constant(1 : i64) : i64
    %74 = llvm.getelementptr %57[0, %73] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<12 x i64>
    llvm.store %60, %74 : i64, !llvm.ptr
    %75 = llvm.mlir.constant(2 : i64) : i64
    %76 = llvm.getelementptr %57[0, %75] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<12 x i64>
    llvm.store %61, %76 : i64, !llvm.ptr
    %77 = llvm.mlir.constant(3 : i64) : i64
    %78 = llvm.getelementptr %57[0, %77] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<12 x i64>
    llvm.store %62, %78 : i64, !llvm.ptr
    %79 = llvm.mlir.constant(4 : i64) : i64
    %80 = llvm.getelementptr %57[0, %79] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<12 x i64>
    llvm.store %63, %80 : i64, !llvm.ptr
    %81 = llvm.mlir.constant(5 : i64) : i64
    %82 = llvm.getelementptr %57[0, %81] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<12 x i64>
    llvm.store %64, %82 : i64, !llvm.ptr
    %83 = llvm.mlir.constant(6 : i64) : i64
    %84 = llvm.getelementptr %57[0, %83] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<12 x i64>
    llvm.store %65, %84 : i64, !llvm.ptr
    %85 = llvm.mlir.constant(7 : i64) : i64
    %86 = llvm.getelementptr %57[0, %85] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<12 x i64>
    llvm.store %66, %86 : i64, !llvm.ptr
    %87 = llvm.mlir.constant(8 : i64) : i64
    %88 = llvm.getelementptr %57[0, %87] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<12 x i64>
    llvm.store %67, %88 : i64, !llvm.ptr
    %89 = llvm.mlir.constant(9 : i64) : i64
    %90 = llvm.getelementptr %57[0, %89] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<12 x i64>
    llvm.store %68, %90 : i64, !llvm.ptr
    %91 = llvm.mlir.constant(10 : i64) : i64
    %92 = llvm.getelementptr %57[0, %91] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<12 x i64>
    llvm.store %69, %92 : i64, !llvm.ptr
    %93 = llvm.mlir.constant(11 : i64) : i64
    %94 = llvm.getelementptr %57[0, %93] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<12 x i64>
    llvm.store %70, %94 : i64, !llvm.ptr
    %95 = arith.constant 0 : i32
    %96 = arith.extsi %95 : i32 to i64
    %97 = llvm.mlir.constant(1 : i64) : i64
    %98 = llvm.alloca %97 x i64 : (i64) -> !llvm.ptr
    llvm.store %96, %98 : i64, !llvm.ptr
    cf.br ^bb12
    ^bb12:
    %99 = llvm.load %98 : !llvm.ptr -> i64
    %100 = arith.constant 12 : i32
    %102 = arith.extsi %100 : i32 to i64
    %101 = arith.cmpi slt, %99, %102 : i64
    cf.cond_br %101, ^bb13, ^bb14
    ^bb13:
      %104 = llvm.load %98 : !llvm.ptr -> i64
      %105 = llvm.getelementptr %57[0, %104] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<12 x i64>
      %103 = llvm.load %105 : !llvm.ptr -> i64
      %106 = arith.cmpi eq, %arg0, %103 : i64
      cf.cond_br %106, ^bb15, ^bb16
      ^bb15:
        %107 = arith.constant 1 : i1
        func.return %107 : i1
      ^bb16:
        cf.br ^bb17
      ^bb17:
      %108 = arith.remsi %arg0, %103 : i64
      %109 = arith.constant 0 : i32
      %111 = arith.extsi %109 : i32 to i64
      %110 = arith.cmpi eq, %108, %111 : i64
      cf.cond_br %110, ^bb18, ^bb19
      ^bb18:
        %112 = arith.constant 0 : i1
        func.return %112 : i1
      ^bb19:
        cf.br ^bb20
      ^bb20:
      %113 = llvm.load %98 : !llvm.ptr -> i64
      %114 = arith.constant 1 : i32
      %116 = arith.extsi %114 : i32 to i64
      %115 = arith.addi %113, %116 : i64
      llvm.store %115, %98 : i64, !llvm.ptr
      cf.br ^bb12
    ^bb14:
    %117 = arith.constant 1 : i32
    %119 = arith.extsi %117 : i32 to i64
    %118 = arith.subi %arg0, %119 : i64
    %120 = llvm.mlir.constant(1 : i64) : i64
    %121 = llvm.alloca %120 x i64 : (i64) -> !llvm.ptr
    llvm.store %118, %121 : i64, !llvm.ptr
    %122 = arith.constant 0 : i32
    %123 = arith.extsi %122 : i32 to i64
    %124 = llvm.mlir.constant(1 : i64) : i64
    %125 = llvm.alloca %124 x i64 : (i64) -> !llvm.ptr
    llvm.store %123, %125 : i64, !llvm.ptr
    cf.br ^bb21
    ^bb21:
    %126 = llvm.load %121 : !llvm.ptr -> i64
    %127 = arith.constant 2 : i32
    %129 = arith.extsi %127 : i32 to i64
    %128 = arith.remsi %126, %129 : i64
    %130 = arith.constant 0 : i32
    %132 = arith.extsi %130 : i32 to i64
    %131 = arith.cmpi eq, %128, %132 : i64
    cf.cond_br %131, ^bb22, ^bb23
    ^bb22:
      %133 = llvm.load %121 : !llvm.ptr -> i64
      %134 = arith.constant 2 : i32
      %136 = arith.extsi %134 : i32 to i64
      %135 = arith.divsi %133, %136 : i64
      llvm.store %135, %121 : i64, !llvm.ptr
      %137 = llvm.load %125 : !llvm.ptr -> i64
      %138 = arith.constant 1 : i32
      %140 = arith.extsi %138 : i32 to i64
      %139 = arith.addi %137, %140 : i64
      llvm.store %139, %125 : i64, !llvm.ptr
      cf.br ^bb21
    ^bb23:
    %142 = arith.constant 2 : i32
    %143 = arith.constant 3 : i32
    %144 = arith.constant 5 : i32
    %145 = arith.constant 7 : i32
    %146 = arith.constant 11 : i32
    %147 = llvm.mlir.constant(1 : i64) : i64
    %148 = llvm.alloca %147 x !llvm.array<5 x i64> : (i64) -> !llvm.ptr
    %149 = llvm.mlir.zero : !llvm.array<5 x i64>
    llvm.store %149, %148 : !llvm.array<5 x i64>, !llvm.ptr
    %150 = arith.extsi %142 : i32 to i64
    %151 = arith.extsi %143 : i32 to i64
    %152 = arith.extsi %144 : i32 to i64
    %153 = arith.extsi %145 : i32 to i64
    %154 = arith.extsi %146 : i32 to i64
    %155 = llvm.mlir.constant(0 : i64) : i64
    %156 = llvm.getelementptr %148[0, %155] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<5 x i64>
    llvm.store %150, %156 : i64, !llvm.ptr
    %157 = llvm.mlir.constant(1 : i64) : i64
    %158 = llvm.getelementptr %148[0, %157] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<5 x i64>
    llvm.store %151, %158 : i64, !llvm.ptr
    %159 = llvm.mlir.constant(2 : i64) : i64
    %160 = llvm.getelementptr %148[0, %159] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<5 x i64>
    llvm.store %152, %160 : i64, !llvm.ptr
    %161 = llvm.mlir.constant(3 : i64) : i64
    %162 = llvm.getelementptr %148[0, %161] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<5 x i64>
    llvm.store %153, %162 : i64, !llvm.ptr
    %163 = llvm.mlir.constant(4 : i64) : i64
    %164 = llvm.getelementptr %148[0, %163] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<5 x i64>
    llvm.store %154, %164 : i64, !llvm.ptr
    %165 = arith.constant 0 : i32
    %166 = arith.extsi %165 : i32 to i64
    llvm.store %166, %98 : i64, !llvm.ptr
    cf.br ^bb24
    ^bb24:
    %167 = llvm.load %98 : !llvm.ptr -> i64
    %168 = arith.constant 5 : i32
    %170 = arith.extsi %168 : i32 to i64
    %169 = arith.cmpi slt, %167, %170 : i64
    cf.cond_br %169, ^bb25, ^bb26
    ^bb25:
      %172 = llvm.load %98 : !llvm.ptr -> i64
      %173 = llvm.getelementptr %148[0, %172] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<5 x i64>
      %171 = llvm.load %173 : !llvm.ptr -> i64
      %174 = arith.remsi %171, %arg0 : i64
      %175 = arith.constant 0 : i32
      %177 = arith.extsi %175 : i32 to i64
      %176 = arith.cmpi eq, %174, %177 : i64
      cf.cond_br %176, ^bb27, ^bb28
      ^bb27:
        %178 = llvm.load %98 : !llvm.ptr -> i64
        %179 = arith.constant 1 : i32
        %181 = arith.extsi %179 : i32 to i64
        %180 = arith.addi %178, %181 : i64
        llvm.store %180, %98 : i64, !llvm.ptr
        cf.br ^bb24
      ^bb28:
        cf.br ^bb29
      ^bb29:
      %183 = llvm.load %121 : !llvm.ptr -> i64
      %182 = func.call @mod_pow(%171, %183, %arg0) : (i64, i64, i64) -> i64
      %184 = llvm.mlir.constant(1 : i64) : i64
      %185 = llvm.alloca %184 x i64 : (i64) -> !llvm.ptr
      llvm.store %182, %185 : i64, !llvm.ptr
      %186 = llvm.load %185 : !llvm.ptr -> i64
      %187 = arith.constant 1 : i32
      %189 = arith.extsi %187 : i32 to i64
      %188 = arith.cmpi eq, %186, %189 : i64
      %190 = scf.if %188 -> (i1) {
        %191 = arith.constant true
        scf.yield %191 : i1
      } else {
        %192 = llvm.load %185 : !llvm.ptr -> i64
        %193 = arith.constant 1 : i32
        %195 = arith.extsi %193 : i32 to i64
        %194 = arith.subi %arg0, %195 : i64
        %196 = arith.cmpi eq, %192, %194 : i64
        scf.yield %196 : i1
      }
      cf.cond_br %190, ^bb30, ^bb31
      ^bb30:
        %197 = llvm.load %98 : !llvm.ptr -> i64
        %198 = arith.constant 1 : i32
        %200 = arith.extsi %198 : i32 to i64
        %199 = arith.addi %197, %200 : i64
        llvm.store %199, %98 : i64, !llvm.ptr
        cf.br ^bb24
      ^bb31:
        cf.br ^bb32
      ^bb32:
      %201 = arith.constant 0 : i1
      %202 = llvm.mlir.constant(1 : i64) : i64
      %203 = llvm.alloca %202 x i1 : (i64) -> !llvm.ptr
      llvm.store %201, %203 : i1, !llvm.ptr
      %204 = arith.constant 1 : i32
      %205 = arith.extsi %204 : i32 to i64
      %206 = llvm.mlir.constant(1 : i64) : i64
      %207 = llvm.alloca %206 x i64 : (i64) -> !llvm.ptr
      llvm.store %205, %207 : i64, !llvm.ptr
      cf.br ^bb33
      ^bb33:
      %208 = llvm.load %207 : !llvm.ptr -> i64
      %209 = llvm.load %125 : !llvm.ptr -> i64
      %210 = arith.cmpi slt, %208, %209 : i64
      cf.cond_br %210, ^bb34, ^bb35
      ^bb34:
        %211 = llvm.load %185 : !llvm.ptr -> i64
        %212 = llvm.load %185 : !llvm.ptr -> i64
        %213 = arith.muli %211, %212 : i64
        %214 = arith.remsi %213, %arg0 : i64
        llvm.store %214, %185 : i64, !llvm.ptr
        %215 = llvm.load %185 : !llvm.ptr -> i64
        %216 = arith.constant 1 : i32
        %218 = arith.extsi %216 : i32 to i64
        %217 = arith.subi %arg0, %218 : i64
        %219 = arith.cmpi eq, %215, %217 : i64
        cf.cond_br %219, ^bb36, ^bb37
        ^bb36:
          %220 = arith.constant 1 : i1
          llvm.store %220, %203 : i1, !llvm.ptr
          cf.br ^bb35
        ^bb37:
          cf.br ^bb38
        ^bb38:
        %221 = llvm.load %207 : !llvm.ptr -> i64
        %222 = arith.constant 1 : i32
        %224 = arith.extsi %222 : i32 to i64
        %223 = arith.addi %221, %224 : i64
        llvm.store %223, %207 : i64, !llvm.ptr
        cf.br ^bb33
      ^bb35:
      %225 = llvm.load %203 : !llvm.ptr -> i1
      %227 = arith.constant 1 : i1
      %226 = arith.xori %225, %227 : i1
      cf.cond_br %226, ^bb39, ^bb40
      ^bb39:
        %229 = arith.constant 0 : i1
        func.return %229 : i1
      ^bb40:
        cf.br ^bb41
      ^bb41:
      %230 = llvm.load %98 : !llvm.ptr -> i64
      %231 = arith.constant 1 : i32
      %233 = arith.extsi %231 : i32 to i64
      %232 = arith.addi %230, %233 : i64
      llvm.store %232, %98 : i64, !llvm.ptr
      cf.br ^bb24
    ^bb26:
    %234 = arith.constant 1 : i1
    func.return %234 : i1
  }
  func.func @tonelli(%arg0: i64, %arg1: i64) -> i64 {
    %235 = arith.remsi %arg0, %arg1 : i64
    %236 = arith.constant 0 : i32
    %238 = arith.extsi %236 : i32 to i64
    %237 = arith.cmpi eq, %235, %238 : i64
    cf.cond_br %237, ^bb42, ^bb43
    ^bb42:
      %239 = arith.constant 0 : i32
      %240 = arith.extsi %239 : i32 to i64
      func.return %240 : i64
    ^bb43:
      cf.br ^bb44
    ^bb44:
    %241 = arith.constant 4 : i32
    %243 = arith.extsi %241 : i32 to i64
    %242 = arith.remsi %arg1, %243 : i64
    %244 = arith.constant 3 : i32
    %246 = arith.extsi %244 : i32 to i64
    %245 = arith.cmpi eq, %242, %246 : i64
    cf.cond_br %245, ^bb45, ^bb46
    ^bb45:
      %248 = arith.constant 1 : i32
      %250 = arith.extsi %248 : i32 to i64
      %249 = arith.addi %arg1, %250 : i64
      %251 = arith.constant 4 : i32
      %253 = arith.extsi %251 : i32 to i64
      %252 = arith.divsi %249, %253 : i64
      %247 = func.call @mod_pow(%235, %252, %arg1) : (i64, i64, i64) -> i64
      func.return %247 : i64
    ^bb46:
      cf.br ^bb47
    ^bb47:
    %254 = arith.constant 1 : i32
    %256 = arith.extsi %254 : i32 to i64
    %255 = arith.subi %arg1, %256 : i64
    %257 = llvm.mlir.constant(1 : i64) : i64
    %258 = llvm.alloca %257 x i64 : (i64) -> !llvm.ptr
    llvm.store %255, %258 : i64, !llvm.ptr
    %259 = arith.constant 0 : i32
    %260 = arith.extsi %259 : i32 to i64
    %261 = llvm.mlir.constant(1 : i64) : i64
    %262 = llvm.alloca %261 x i64 : (i64) -> !llvm.ptr
    llvm.store %260, %262 : i64, !llvm.ptr
    cf.br ^bb48
    ^bb48:
    %263 = llvm.load %258 : !llvm.ptr -> i64
    %264 = arith.constant 2 : i32
    %266 = arith.extsi %264 : i32 to i64
    %265 = arith.remsi %263, %266 : i64
    %267 = arith.constant 0 : i32
    %269 = arith.extsi %267 : i32 to i64
    %268 = arith.cmpi eq, %265, %269 : i64
    cf.cond_br %268, ^bb49, ^bb50
    ^bb49:
      %270 = llvm.load %258 : !llvm.ptr -> i64
      %271 = arith.constant 2 : i32
      %273 = arith.extsi %271 : i32 to i64
      %272 = arith.divsi %270, %273 : i64
      llvm.store %272, %258 : i64, !llvm.ptr
      %274 = llvm.load %262 : !llvm.ptr -> i64
      %275 = arith.constant 1 : i32
      %277 = arith.extsi %275 : i32 to i64
      %276 = arith.addi %274, %277 : i64
      llvm.store %276, %262 : i64, !llvm.ptr
      cf.br ^bb48
    ^bb50:
    %278 = arith.constant 2 : i32
    %279 = arith.extsi %278 : i32 to i64
    %280 = llvm.mlir.constant(1 : i64) : i64
    %281 = llvm.alloca %280 x i64 : (i64) -> !llvm.ptr
    llvm.store %279, %281 : i64, !llvm.ptr
    cf.br ^bb51
    ^bb51:
    %283 = llvm.load %281 : !llvm.ptr -> i64
    %284 = arith.constant 1 : i32
    %286 = arith.extsi %284 : i32 to i64
    %285 = arith.subi %arg1, %286 : i64
    %287 = arith.constant 2 : i32
    %289 = arith.extsi %287 : i32 to i64
    %288 = arith.divsi %285, %289 : i64
    %282 = func.call @mod_pow(%283, %288, %arg1) : (i64, i64, i64) -> i64
    %290 = arith.constant 1 : i32
    %292 = arith.extsi %290 : i32 to i64
    %291 = arith.subi %arg1, %292 : i64
    %293 = arith.cmpi ne, %282, %291 : i64
    cf.cond_br %293, ^bb52, ^bb53
    ^bb52:
      %294 = llvm.load %281 : !llvm.ptr -> i64
      %295 = arith.constant 1 : i32
      %297 = arith.extsi %295 : i32 to i64
      %296 = arith.addi %294, %297 : i64
      llvm.store %296, %281 : i64, !llvm.ptr
      cf.br ^bb51
    ^bb53:
    %299 = llvm.load %281 : !llvm.ptr -> i64
    %300 = llvm.load %258 : !llvm.ptr -> i64
    %298 = func.call @mod_pow(%299, %300, %arg1) : (i64, i64, i64) -> i64
    %301 = llvm.mlir.constant(1 : i64) : i64
    %302 = llvm.alloca %301 x i64 : (i64) -> !llvm.ptr
    llvm.store %298, %302 : i64, !llvm.ptr
    %304 = llvm.load %258 : !llvm.ptr -> i64
    %305 = arith.constant 1 : i32
    %307 = arith.extsi %305 : i32 to i64
    %306 = arith.addi %304, %307 : i64
    %308 = arith.constant 2 : i32
    %310 = arith.extsi %308 : i32 to i64
    %309 = arith.divsi %306, %310 : i64
    %303 = func.call @mod_pow(%235, %309, %arg1) : (i64, i64, i64) -> i64
    %311 = llvm.mlir.constant(1 : i64) : i64
    %312 = llvm.alloca %311 x i64 : (i64) -> !llvm.ptr
    llvm.store %303, %312 : i64, !llvm.ptr
    %314 = llvm.load %258 : !llvm.ptr -> i64
    %313 = func.call @mod_pow(%235, %314, %arg1) : (i64, i64, i64) -> i64
    %315 = llvm.mlir.constant(1 : i64) : i64
    %316 = llvm.alloca %315 x i64 : (i64) -> !llvm.ptr
    llvm.store %313, %316 : i64, !llvm.ptr
    %317 = llvm.load %262 : !llvm.ptr -> i64
    %318 = llvm.mlir.constant(1 : i64) : i64
    %319 = llvm.alloca %318 x i64 : (i64) -> !llvm.ptr
    llvm.store %317, %319 : i64, !llvm.ptr
    cf.br ^bb54
    ^bb54:
    %320 = llvm.load %316 : !llvm.ptr -> i64
    %321 = arith.constant 1 : i32
    %323 = arith.extsi %321 : i32 to i64
    %322 = arith.cmpi ne, %320, %323 : i64
    cf.cond_br %322, ^bb55, ^bb56
    ^bb55:
      %324 = arith.constant 1 : i32
      %325 = arith.extsi %324 : i32 to i64
      %326 = llvm.mlir.constant(1 : i64) : i64
      %327 = llvm.alloca %326 x i64 : (i64) -> !llvm.ptr
      llvm.store %325, %327 : i64, !llvm.ptr
      %328 = llvm.load %316 : !llvm.ptr -> i64
      %329 = llvm.load %316 : !llvm.ptr -> i64
      %330 = arith.muli %328, %329 : i64
      %331 = arith.remsi %330, %arg1 : i64
      %332 = llvm.mlir.constant(1 : i64) : i64
      %333 = llvm.alloca %332 x i64 : (i64) -> !llvm.ptr
      llvm.store %331, %333 : i64, !llvm.ptr
      cf.br ^bb57
      ^bb57:
      %334 = llvm.load %333 : !llvm.ptr -> i64
      %335 = arith.constant 1 : i32
      %337 = arith.extsi %335 : i32 to i64
      %336 = arith.cmpi ne, %334, %337 : i64
      cf.cond_br %336, ^bb58, ^bb59
      ^bb58:
        %338 = llvm.load %333 : !llvm.ptr -> i64
        %339 = llvm.load %333 : !llvm.ptr -> i64
        %340 = arith.muli %338, %339 : i64
        %341 = arith.remsi %340, %arg1 : i64
        llvm.store %341, %333 : i64, !llvm.ptr
        %342 = llvm.load %327 : !llvm.ptr -> i64
        %343 = arith.constant 1 : i32
        %345 = arith.extsi %343 : i32 to i64
        %344 = arith.addi %342, %345 : i64
        llvm.store %344, %327 : i64, !llvm.ptr
        cf.br ^bb57
      ^bb59:
      %347 = llvm.load %302 : !llvm.ptr -> i64
      %348 = arith.constant 1 : i32
      %349 = llvm.load %319 : !llvm.ptr -> i64
      %350 = llvm.load %327 : !llvm.ptr -> i64
      %351 = arith.subi %349, %350 : i64
      %352 = arith.constant 1 : i32
      %354 = arith.extsi %352 : i32 to i64
      %353 = arith.subi %351, %354 : i64
      %356 = arith.extsi %348 : i32 to i64
      %355 = arith.shli %356, %353 : i64
      %346 = func.call @mod_pow(%347, %355, %arg1) : (i64, i64, i64) -> i64
      %357 = llvm.load %312 : !llvm.ptr -> i64
      %358 = arith.muli %357, %346 : i64
      %359 = arith.remsi %358, %arg1 : i64
      llvm.store %359, %312 : i64, !llvm.ptr
      %360 = arith.muli %346, %346 : i64
      %361 = arith.remsi %360, %arg1 : i64
      llvm.store %361, %302 : i64, !llvm.ptr
      %362 = llvm.load %316 : !llvm.ptr -> i64
      %363 = llvm.load %302 : !llvm.ptr -> i64
      %364 = arith.muli %362, %363 : i64
      %365 = arith.remsi %364, %arg1 : i64
      llvm.store %365, %316 : i64, !llvm.ptr
      %366 = llvm.load %327 : !llvm.ptr -> i64
      llvm.store %366, %319 : i64, !llvm.ptr
      cf.br ^bb54
    ^bb56:
    %367 = llvm.load %312 : !llvm.ptr -> i64
    func.return %367 : i64
  }
  func.func @is_prim_root(%arg0: i64, %arg1: i64, %arg2: !llvm.ptr, %arg3: i64) -> i1 {
    %368 = arith.constant 0 : i32
    %369 = arith.extsi %368 : i32 to i64
    %370 = llvm.mlir.constant(1 : i64) : i64
    %371 = llvm.alloca %370 x i64 : (i64) -> !llvm.ptr
    llvm.store %369, %371 : i64, !llvm.ptr
    cf.br ^bb60
    ^bb60:
    %372 = llvm.load %371 : !llvm.ptr -> i64
    %373 = arith.cmpi slt, %372, %arg3 : i64
    cf.cond_br %373, ^bb61, ^bb62
    ^bb61:
      %375 = llvm.load %371 : !llvm.ptr -> i64
      %376 = llvm.getelementptr %arg2[%375] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %374 = llvm.load %376 : !llvm.ptr -> i64
      %378 = arith.constant 1 : i32
      %380 = arith.extsi %378 : i32 to i64
      %379 = arith.subi %arg1, %380 : i64
      %381 = arith.divsi %379, %374 : i64
      %377 = func.call @mod_pow(%arg0, %381, %arg1) : (i64, i64, i64) -> i64
      %382 = arith.constant 1 : i32
      %384 = arith.extsi %382 : i32 to i64
      %383 = arith.cmpi eq, %377, %384 : i64
      cf.cond_br %383, ^bb63, ^bb64
      ^bb63:
        %385 = arith.constant 0 : i1
        func.return %385 : i1
      ^bb64:
        cf.br ^bb65
      ^bb65:
      %386 = llvm.load %371 : !llvm.ptr -> i64
      %387 = arith.constant 1 : i32
      %389 = arith.extsi %387 : i32 to i64
      %388 = arith.addi %386, %389 : i64
      llvm.store %388, %371 : i64, !llvm.ptr
      cf.br ^bb60
    ^bb62:
    %390 = arith.constant 1 : i1
    func.return %390 : i1
  }
  func.func @main() -> i32 {
    %391 = arith.constant 100000000 : i32
    %392 = arith.extsi %391 : i32 to i64
    %393 = arith.constant 10000 : i32
    %394 = arith.extsi %393 : i32 to i64
    %396 = arith.constant 1 : i32
    %398 = arith.extsi %396 : i32 to i64
    %397 = arith.addi %394, %398 : i64
    %399 = arith.constant 1 : i32
    %400 = arith.extsi %399 : i32 to i64
    %395 = func.call @calloc(%397, %400) : (i64, i64) -> !llvm.ptr
    %402 = arith.constant 4 : i32
    %403 = arith.extsi %402 : i32 to i64
    %401 = func.call @calloc(%394, %403) : (i64, i64) -> !llvm.ptr
    %404 = llvm.mlir.zero : !llvm.ptr
    %405 = llvm.icmp "eq" %395, %404 : !llvm.ptr
    %406 = scf.if %405 -> (i1) {
      %407 = arith.constant true
      scf.yield %407 : i1
    } else {
      %408 = llvm.mlir.zero : !llvm.ptr
      %409 = llvm.icmp "eq" %401, %408 : !llvm.ptr
      scf.yield %409 : i1
    }
    cf.cond_br %406, ^bb66, ^bb67
    ^bb66:
      %410 = arith.constant 1 : i32
      func.return %410 : i32
    ^bb67:
      cf.br ^bb68
    ^bb68:
    %411 = arith.constant 0 : i32
    %412 = arith.extsi %411 : i32 to i64
    %413 = llvm.mlir.constant(1 : i64) : i64
    %414 = llvm.alloca %413 x i64 : (i64) -> !llvm.ptr
    llvm.store %412, %414 : i64, !llvm.ptr
    %415 = arith.constant 2 : i32
    %416 = arith.extsi %415 : i32 to i64
    %417 = llvm.mlir.constant(1 : i64) : i64
    %418 = llvm.alloca %417 x i64 : (i64) -> !llvm.ptr
    llvm.store %416, %418 : i64, !llvm.ptr
    cf.br ^bb69
    ^bb69:
    %419 = llvm.load %418 : !llvm.ptr -> i64
    %420 = arith.cmpi sle, %419, %394 : i64
    cf.cond_br %420, ^bb70, ^bb71
    ^bb70:
      %422 = llvm.load %418 : !llvm.ptr -> i64
      %423 = llvm.getelementptr %395[%422] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %421 = llvm.load %423 : !llvm.ptr -> i8
      %424 = arith.constant 0 : i32
      %426 = arith.extsi %421 : i8 to i32
      %425 = arith.cmpi eq, %426, %424 : i32
      cf.cond_br %425, ^bb72, ^bb73
      ^bb72:
        %427 = llvm.load %418 : !llvm.ptr -> i64
        %428 = arith.trunci %427 : i64 to i32
        %429 = llvm.load %414 : !llvm.ptr -> i64
        %430 = llvm.getelementptr %401[%429] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %428, %430 : i32, !llvm.ptr
        %431 = llvm.load %414 : !llvm.ptr -> i64
        %432 = arith.constant 1 : i32
        %434 = arith.extsi %432 : i32 to i64
        %433 = arith.addi %431, %434 : i64
        llvm.store %433, %414 : i64, !llvm.ptr
        %435 = llvm.load %418 : !llvm.ptr -> i64
        %436 = llvm.load %418 : !llvm.ptr -> i64
        %437 = arith.muli %435, %436 : i64
        %438 = llvm.mlir.constant(1 : i64) : i64
        %439 = llvm.alloca %438 x i64 : (i64) -> !llvm.ptr
        llvm.store %437, %439 : i64, !llvm.ptr
        cf.br ^bb75
        ^bb75:
        %440 = llvm.load %439 : !llvm.ptr -> i64
        %441 = arith.cmpi sle, %440, %394 : i64
        cf.cond_br %441, ^bb76, ^bb77
        ^bb76:
          %442 = arith.constant 1 : i32
          %443 = llvm.load %439 : !llvm.ptr -> i64
          %444 = arith.trunci %442 : i32 to i8
          %445 = llvm.getelementptr %395[%443] : (!llvm.ptr, i64) -> !llvm.ptr, i8
          llvm.store %444, %445 : i8, !llvm.ptr
          %446 = llvm.load %439 : !llvm.ptr -> i64
          %447 = llvm.load %418 : !llvm.ptr -> i64
          %448 = arith.addi %446, %447 : i64
          llvm.store %448, %439 : i64, !llvm.ptr
          cf.br ^bb75
        ^bb77:
        cf.br ^bb74
      ^bb73:
        cf.br ^bb74
      ^bb74:
      %449 = llvm.load %418 : !llvm.ptr -> i64
      %450 = arith.constant 1 : i32
      %452 = arith.extsi %450 : i32 to i64
      %451 = arith.addi %449, %452 : i64
      llvm.store %451, %418 : i64, !llvm.ptr
      cf.br ^bb69
    ^bb71:
    %454 = arith.constant 64 : i32
    %455 = arith.constant 8 : i32
    %456 = arith.extsi %454 : i32 to i64
    %457 = arith.extsi %455 : i32 to i64
    %453 = func.call @calloc(%456, %457) : (i64, i64) -> !llvm.ptr
    %458 = arith.constant 5 : i32
    %459 = arith.extsi %458 : i32 to i64
    %460 = llvm.mlir.constant(1 : i64) : i64
    %461 = llvm.alloca %460 x i64 : (i64) -> !llvm.ptr
    llvm.store %459, %461 : i64, !llvm.ptr
    %462 = arith.constant 1000000 : i32
    %463 = arith.extsi %462 : i32 to i64
    %465 = arith.constant 1 : i32
    %466 = arith.extsi %465 : i32 to i64
    %464 = func.call @calloc(%463, %466) : (i64, i64) -> !llvm.ptr
    %467 = llvm.mlir.zero : !llvm.ptr
    %468 = llvm.icmp "eq" %464, %467 : !llvm.ptr
    cf.cond_br %468, ^bb78, ^bb79
    ^bb78:
      %469 = arith.constant 1 : i32
      func.return %469 : i32
    ^bb79:
      cf.br ^bb80
    ^bb80:
    %470 = arith.constant 2 : i32
    %471 = arith.extsi %470 : i32 to i64
    %472 = llvm.mlir.constant(1 : i64) : i64
    %473 = llvm.alloca %472 x i64 : (i64) -> !llvm.ptr
    llvm.store %471, %473 : i64, !llvm.ptr
    cf.br ^bb81
    ^bb81:
    %474 = llvm.load %473 : !llvm.ptr -> i64
    %475 = arith.cmpi slt, %474, %392 : i64
    cf.cond_br %475, ^bb82, ^bb83
    ^bb82:
      %476 = llvm.load %473 : !llvm.ptr -> i64
      %477 = arith.addi %476, %463 : i64
      %478 = arith.cmpi sgt, %477, %392 : i64
      %479 = scf.if %478 -> (i64) {
        scf.yield %392 : i64
      } else {
        scf.yield %477 : i64
      }
      %480 = arith.constant 0 : i32
      %481 = arith.extsi %480 : i32 to i64
      %482 = llvm.mlir.constant(1 : i64) : i64
      %483 = llvm.alloca %482 x i64 : (i64) -> !llvm.ptr
      llvm.store %481, %483 : i64, !llvm.ptr
      cf.br ^bb84
      ^bb84:
      %484 = llvm.load %483 : !llvm.ptr -> i64
      %485 = llvm.load %473 : !llvm.ptr -> i64
      %486 = arith.subi %479, %485 : i64
      %487 = arith.cmpi slt, %484, %486 : i64
      cf.cond_br %487, ^bb85, ^bb86
      ^bb85:
        %488 = arith.constant 0 : i32
        %489 = llvm.load %483 : !llvm.ptr -> i64
        %490 = arith.trunci %488 : i32 to i8
        %491 = llvm.getelementptr %464[%489] : (!llvm.ptr, i64) -> !llvm.ptr, i8
        llvm.store %490, %491 : i8, !llvm.ptr
        %492 = llvm.load %483 : !llvm.ptr -> i64
        %493 = arith.constant 1 : i32
        %495 = arith.extsi %493 : i32 to i64
        %494 = arith.addi %492, %495 : i64
        llvm.store %494, %483 : i64, !llvm.ptr
        cf.br ^bb84
      ^bb86:
      %496 = arith.constant 0 : i32
      %497 = arith.extsi %496 : i32 to i64
      %498 = llvm.mlir.constant(1 : i64) : i64
      %499 = llvm.alloca %498 x i64 : (i64) -> !llvm.ptr
      llvm.store %497, %499 : i64, !llvm.ptr
      cf.br ^bb87
      ^bb87:
      %500 = llvm.load %499 : !llvm.ptr -> i64
      %501 = llvm.load %414 : !llvm.ptr -> i64
      %502 = arith.cmpi slt, %500, %501 : i64
      cf.cond_br %502, ^bb88, ^bb89
      ^bb88:
        %504 = llvm.load %499 : !llvm.ptr -> i64
        %505 = llvm.getelementptr %401[%504] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %503 = llvm.load %505 : !llvm.ptr -> i32
        %506 = arith.extsi %503 : i32 to i64
        %507 = llvm.load %473 : !llvm.ptr -> i64
        %508 = arith.addi %507, %506 : i64
        %509 = arith.constant 1 : i32
        %511 = arith.extsi %509 : i32 to i64
        %510 = arith.subi %508, %511 : i64
        %512 = arith.divsi %510, %506 : i64
        %513 = arith.muli %512, %506 : i64
        %514 = llvm.mlir.constant(1 : i64) : i64
        %515 = llvm.alloca %514 x i64 : (i64) -> !llvm.ptr
        llvm.store %513, %515 : i64, !llvm.ptr
        %516 = llvm.load %515 : !llvm.ptr -> i64
        %517 = arith.muli %506, %506 : i64
        %518 = arith.cmpi slt, %516, %517 : i64
        cf.cond_br %518, ^bb90, ^bb91
        ^bb90:
          %519 = arith.muli %506, %506 : i64
          llvm.store %519, %515 : i64, !llvm.ptr
          cf.br ^bb92
        ^bb91:
          cf.br ^bb92
        ^bb92:
        %520 = llvm.load %515 : !llvm.ptr -> i64
        %521 = llvm.mlir.constant(1 : i64) : i64
        %522 = llvm.alloca %521 x i64 : (i64) -> !llvm.ptr
        llvm.store %520, %522 : i64, !llvm.ptr
        cf.br ^bb93
        ^bb93:
        %523 = llvm.load %522 : !llvm.ptr -> i64
        %524 = arith.cmpi slt, %523, %479 : i64
        cf.cond_br %524, ^bb94, ^bb95
        ^bb94:
          %525 = arith.constant 1 : i32
          %526 = llvm.load %522 : !llvm.ptr -> i64
          %527 = llvm.load %473 : !llvm.ptr -> i64
          %528 = arith.subi %526, %527 : i64
          %529 = arith.trunci %525 : i32 to i8
          %530 = llvm.getelementptr %464[%528] : (!llvm.ptr, i64) -> !llvm.ptr, i8
          llvm.store %529, %530 : i8, !llvm.ptr
          %531 = llvm.load %522 : !llvm.ptr -> i64
          %532 = arith.addi %531, %506 : i64
          llvm.store %532, %522 : i64, !llvm.ptr
          cf.br ^bb93
        ^bb95:
        %533 = llvm.load %499 : !llvm.ptr -> i64
        %534 = arith.constant 1 : i32
        %536 = arith.extsi %534 : i32 to i64
        %535 = arith.addi %533, %536 : i64
        llvm.store %535, %499 : i64, !llvm.ptr
        cf.br ^bb87
      ^bb89:
      %537 = llvm.load %473 : !llvm.ptr -> i64
      %538 = llvm.mlir.constant(1 : i64) : i64
      %539 = llvm.alloca %538 x i64 : (i64) -> !llvm.ptr
      llvm.store %537, %539 : i64, !llvm.ptr
      %540 = llvm.load %539 : !llvm.ptr -> i64
      %541 = arith.constant 3 : i32
      %543 = arith.extsi %541 : i32 to i64
      %542 = arith.cmpi slt, %540, %543 : i64
      cf.cond_br %542, ^bb96, ^bb97
      ^bb96:
        %544 = arith.constant 3 : i32
        %545 = arith.extsi %544 : i32 to i64
        llvm.store %545, %539 : i64, !llvm.ptr
        cf.br ^bb98
      ^bb97:
        cf.br ^bb98
      ^bb98:
      %546 = llvm.load %539 : !llvm.ptr -> i64
      %547 = arith.constant 2 : i32
      %549 = arith.extsi %547 : i32 to i64
      %548 = arith.remsi %546, %549 : i64
      %550 = arith.constant 0 : i32
      %552 = arith.extsi %550 : i32 to i64
      %551 = arith.cmpi eq, %548, %552 : i64
      cf.cond_br %551, ^bb99, ^bb100
      ^bb99:
        %553 = llvm.load %539 : !llvm.ptr -> i64
        %554 = arith.constant 1 : i32
        %556 = arith.extsi %554 : i32 to i64
        %555 = arith.addi %553, %556 : i64
        llvm.store %555, %539 : i64, !llvm.ptr
        cf.br ^bb101
      ^bb100:
        cf.br ^bb101
      ^bb101:
      cf.br ^bb102
      ^bb102:
      %557 = llvm.load %539 : !llvm.ptr -> i64
      %558 = arith.cmpi slt, %557, %479 : i64
      cf.cond_br %558, ^bb103, ^bb104
      ^bb103:
        %560 = llvm.load %539 : !llvm.ptr -> i64
        %561 = llvm.load %473 : !llvm.ptr -> i64
        %562 = arith.subi %560, %561 : i64
        %563 = llvm.getelementptr %464[%562] : (!llvm.ptr, i64) -> !llvm.ptr, i8
        %559 = llvm.load %563 : !llvm.ptr -> i8
        %564 = arith.constant 0 : i32
        %566 = arith.extsi %559 : i8 to i32
        %565 = arith.cmpi eq, %566, %564 : i32
        %567 = scf.if %565 -> (i1) {
          %568 = llvm.load %539 : !llvm.ptr -> i64
          %569 = arith.constant 5 : i32
          %571 = arith.extsi %569 : i32 to i64
          %570 = arith.cmpi sgt, %568, %571 : i64
          scf.yield %570 : i1
        } else {
          %572 = arith.constant false
          scf.yield %572 : i1
        }
        cf.cond_br %567, ^bb105, ^bb106
        ^bb105:
          %573 = llvm.load %539 : !llvm.ptr -> i64
          %574 = arith.constant 5 : i32
          %576 = arith.extsi %574 : i32 to i64
          %575 = arith.remsi %573, %576 : i64
          %577 = arith.constant 1 : i32
          %579 = arith.extsi %577 : i32 to i64
          %578 = arith.cmpi eq, %575, %579 : i64
          %580 = scf.if %578 -> (i1) {
            %581 = arith.constant true
            scf.yield %581 : i1
          } else {
            %582 = arith.constant 4 : i32
            %584 = arith.extsi %582 : i32 to i64
            %583 = arith.cmpi eq, %575, %584 : i64
            scf.yield %583 : i1
          }
          cf.cond_br %580, ^bb108, ^bb109
          ^bb108:
            %585 = arith.constant 0 : i32
            %586 = arith.extsi %585 : i32 to i64
            %587 = llvm.mlir.constant(1 : i64) : i64
            %588 = llvm.alloca %587 x i64 : (i64) -> !llvm.ptr
            llvm.store %586, %588 : i64, !llvm.ptr
            %589 = llvm.load %539 : !llvm.ptr -> i64
            %590 = arith.constant 4 : i32
            %592 = arith.extsi %590 : i32 to i64
            %591 = arith.remsi %589, %592 : i64
            %593 = arith.constant 3 : i32
            %595 = arith.extsi %593 : i32 to i64
            %594 = arith.cmpi eq, %591, %595 : i64
            cf.cond_br %594, ^bb111, ^bb112
            ^bb111:
              %597 = arith.constant 5 : i32
              %598 = llvm.load %539 : !llvm.ptr -> i64
              %599 = arith.constant 1 : i32
              %601 = arith.extsi %599 : i32 to i64
              %600 = arith.addi %598, %601 : i64
              %602 = arith.constant 4 : i32
              %604 = arith.extsi %602 : i32 to i64
              %603 = arith.divsi %600, %604 : i64
              %605 = llvm.load %539 : !llvm.ptr -> i64
              %606 = arith.extsi %597 : i32 to i64
              %596 = func.call @mod_pow(%606, %603, %605) : (i64, i64, i64) -> i64
              llvm.store %596, %588 : i64, !llvm.ptr
              cf.br ^bb113
            ^bb112:
              %608 = arith.constant 5 : i32
              %609 = llvm.load %539 : !llvm.ptr -> i64
              %610 = arith.extsi %608 : i32 to i64
              %607 = func.call @tonelli(%610, %609) : (i64, i64) -> i64
              llvm.store %607, %588 : i64, !llvm.ptr
              cf.br ^bb113
            ^bb113:
            %611 = llvm.load %539 : !llvm.ptr -> i64
            %612 = arith.constant 1 : i32
            %614 = arith.extsi %612 : i32 to i64
            %613 = arith.addi %611, %614 : i64
            %615 = arith.constant 2 : i32
            %617 = arith.extsi %615 : i32 to i64
            %616 = arith.divsi %613, %617 : i64
            %618 = arith.constant 1 : i32
            %619 = llvm.load %588 : !llvm.ptr -> i64
            %621 = arith.extsi %618 : i32 to i64
            %620 = arith.addi %621, %619 : i64
            %622 = arith.muli %620, %616 : i64
            %623 = llvm.load %539 : !llvm.ptr -> i64
            %624 = arith.remsi %622, %623 : i64
            %625 = arith.constant 1 : i32
            %626 = llvm.load %588 : !llvm.ptr -> i64
            %628 = arith.extsi %625 : i32 to i64
            %627 = arith.subi %628, %626 : i64
            %629 = llvm.load %539 : !llvm.ptr -> i64
            %630 = arith.remsi %627, %629 : i64
            %631 = llvm.load %539 : !llvm.ptr -> i64
            %632 = arith.addi %630, %631 : i64
            %633 = llvm.load %539 : !llvm.ptr -> i64
            %634 = arith.remsi %632, %633 : i64
            %635 = arith.muli %634, %616 : i64
            %636 = llvm.load %539 : !llvm.ptr -> i64
            %637 = arith.remsi %635, %636 : i64
            %638 = llvm.load %539 : !llvm.ptr -> i64
            %639 = arith.constant 1 : i32
            %641 = arith.extsi %639 : i32 to i64
            %640 = arith.subi %638, %641 : i64
            %642 = llvm.mlir.constant(1 : i64) : i64
            %643 = llvm.alloca %642 x i64 : (i64) -> !llvm.ptr
            llvm.store %640, %643 : i64, !llvm.ptr
            %644 = arith.constant 0 : i32
            %645 = arith.extsi %644 : i32 to i64
            %646 = llvm.mlir.constant(1 : i64) : i64
            %647 = llvm.alloca %646 x i64 : (i64) -> !llvm.ptr
            llvm.store %645, %647 : i64, !llvm.ptr
            %648 = llvm.load %643 : !llvm.ptr -> i64
            %649 = arith.constant 2 : i32
            %651 = arith.extsi %649 : i32 to i64
            %650 = arith.remsi %648, %651 : i64
            %652 = arith.constant 0 : i32
            %654 = arith.extsi %652 : i32 to i64
            %653 = arith.cmpi eq, %650, %654 : i64
            cf.cond_br %653, ^bb114, ^bb115
            ^bb114:
              %655 = arith.constant 2 : i32
              %656 = llvm.load %647 : !llvm.ptr -> i64
              %657 = arith.extsi %655 : i32 to i64
              %658 = llvm.getelementptr %453[%656] : (!llvm.ptr, i64) -> !llvm.ptr, i64
              llvm.store %657, %658 : i64, !llvm.ptr
              %659 = llvm.load %647 : !llvm.ptr -> i64
              %660 = arith.constant 1 : i32
              %662 = arith.extsi %660 : i32 to i64
              %661 = arith.addi %659, %662 : i64
              llvm.store %661, %647 : i64, !llvm.ptr
              cf.br ^bb117
              ^bb117:
              %663 = llvm.load %643 : !llvm.ptr -> i64
              %664 = arith.constant 2 : i32
              %666 = arith.extsi %664 : i32 to i64
              %665 = arith.remsi %663, %666 : i64
              %667 = arith.constant 0 : i32
              %669 = arith.extsi %667 : i32 to i64
              %668 = arith.cmpi eq, %665, %669 : i64
              cf.cond_br %668, ^bb118, ^bb119
              ^bb118:
                %670 = llvm.load %643 : !llvm.ptr -> i64
                %671 = arith.constant 2 : i32
                %673 = arith.extsi %671 : i32 to i64
                %672 = arith.divsi %670, %673 : i64
                llvm.store %672, %643 : i64, !llvm.ptr
                cf.br ^bb117
              ^bb119:
              cf.br ^bb116
            ^bb115:
              cf.br ^bb116
            ^bb116:
            %674 = arith.constant 0 : i32
            %675 = arith.extsi %674 : i32 to i64
            %676 = llvm.mlir.constant(1 : i64) : i64
            %677 = llvm.alloca %676 x i64 : (i64) -> !llvm.ptr
            llvm.store %675, %677 : i64, !llvm.ptr
            cf.br ^bb120
            ^bb120:
            %678 = llvm.load %677 : !llvm.ptr -> i64
            %679 = llvm.load %414 : !llvm.ptr -> i64
            %680 = arith.cmpi slt, %678, %679 : i64
            cf.cond_br %680, ^bb121, ^bb122
            ^bb121:
              %682 = llvm.load %677 : !llvm.ptr -> i64
              %683 = llvm.getelementptr %401[%682] : (!llvm.ptr, i64) -> !llvm.ptr, i32
              %681 = llvm.load %683 : !llvm.ptr -> i32
              %684 = arith.extsi %681 : i32 to i64
              %685 = arith.muli %684, %684 : i64
              %686 = llvm.load %643 : !llvm.ptr -> i64
              %687 = arith.cmpi sgt, %685, %686 : i64
              cf.cond_br %687, ^bb123, ^bb124
              ^bb123:
                cf.br ^bb122
              ^bb124:
                cf.br ^bb125
              ^bb125:
              %688 = llvm.load %643 : !llvm.ptr -> i64
              %689 = arith.remsi %688, %684 : i64
              %690 = arith.constant 0 : i32
              %692 = arith.extsi %690 : i32 to i64
              %691 = arith.cmpi eq, %689, %692 : i64
              cf.cond_br %691, ^bb126, ^bb127
              ^bb126:
                %693 = llvm.load %647 : !llvm.ptr -> i64
                %694 = llvm.getelementptr %453[%693] : (!llvm.ptr, i64) -> !llvm.ptr, i64
                llvm.store %684, %694 : i64, !llvm.ptr
                %695 = llvm.load %647 : !llvm.ptr -> i64
                %696 = arith.constant 1 : i32
                %698 = arith.extsi %696 : i32 to i64
                %697 = arith.addi %695, %698 : i64
                llvm.store %697, %647 : i64, !llvm.ptr
                cf.br ^bb129
                ^bb129:
                %699 = llvm.load %643 : !llvm.ptr -> i64
                %700 = arith.remsi %699, %684 : i64
                %701 = arith.constant 0 : i32
                %703 = arith.extsi %701 : i32 to i64
                %702 = arith.cmpi eq, %700, %703 : i64
                cf.cond_br %702, ^bb130, ^bb131
                ^bb130:
                  %704 = llvm.load %643 : !llvm.ptr -> i64
                  %705 = arith.divsi %704, %684 : i64
                  llvm.store %705, %643 : i64, !llvm.ptr
                  cf.br ^bb129
                ^bb131:
                cf.br ^bb128
              ^bb127:
                cf.br ^bb128
              ^bb128:
              %706 = llvm.load %677 : !llvm.ptr -> i64
              %707 = arith.constant 1 : i32
              %709 = arith.extsi %707 : i32 to i64
              %708 = arith.addi %706, %709 : i64
              llvm.store %708, %677 : i64, !llvm.ptr
              cf.br ^bb120
            ^bb122:
            %710 = llvm.load %643 : !llvm.ptr -> i64
            %711 = arith.constant 1 : i32
            %713 = arith.extsi %711 : i32 to i64
            %712 = arith.cmpi sgt, %710, %713 : i64
            cf.cond_br %712, ^bb132, ^bb133
            ^bb132:
              %714 = llvm.load %643 : !llvm.ptr -> i64
              %715 = llvm.load %647 : !llvm.ptr -> i64
              %716 = llvm.getelementptr %453[%715] : (!llvm.ptr, i64) -> !llvm.ptr, i64
              llvm.store %714, %716 : i64, !llvm.ptr
              %717 = llvm.load %647 : !llvm.ptr -> i64
              %718 = arith.constant 1 : i32
              %720 = arith.extsi %718 : i32 to i64
              %719 = arith.addi %717, %720 : i64
              llvm.store %719, %647 : i64, !llvm.ptr
              cf.br ^bb134
            ^bb133:
              cf.br ^bb134
            ^bb134:
            %722 = llvm.load %539 : !llvm.ptr -> i64
            %723 = llvm.load %647 : !llvm.ptr -> i64
            %721 = func.call @is_prim_root(%624, %722, %453, %723) : (i64, i64, !llvm.ptr, i64) -> i1
            %724 = scf.if %721 -> (i1) {
              %725 = arith.constant true
              scf.yield %725 : i1
            } else {
              %727 = llvm.load %539 : !llvm.ptr -> i64
              %728 = llvm.load %647 : !llvm.ptr -> i64
              %726 = func.call @is_prim_root(%637, %727, %453, %728) : (i64, i64, !llvm.ptr, i64) -> i1
              scf.yield %726 : i1
            }
            cf.cond_br %724, ^bb135, ^bb136
            ^bb135:
              %729 = llvm.load %461 : !llvm.ptr -> i64
              %730 = llvm.load %539 : !llvm.ptr -> i64
              %731 = arith.addi %729, %730 : i64
              llvm.store %731, %461 : i64, !llvm.ptr
              cf.br ^bb137
            ^bb136:
              cf.br ^bb137
            ^bb137:
            cf.br ^bb110
          ^bb109:
            cf.br ^bb110
          ^bb110:
          cf.br ^bb107
        ^bb106:
          cf.br ^bb107
        ^bb107:
        %732 = llvm.load %539 : !llvm.ptr -> i64
        %733 = arith.constant 2 : i32
        %735 = arith.extsi %733 : i32 to i64
        %734 = arith.addi %732, %735 : i64
        llvm.store %734, %539 : i64, !llvm.ptr
        cf.br ^bb102
      ^bb104:
      llvm.store %479, %473 : i64, !llvm.ptr
      cf.br ^bb81
    ^bb83:
    %736 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %737 = llvm.load %461 : !llvm.ptr -> i64
    %738 = llvm.call @printf(%736, %737) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    func.call @free(%464) : (!llvm.ptr) -> ()
    func.call @free(%453) : (!llvm.ptr) -> ()
    func.call @free(%401) : (!llvm.ptr) -> ()
    func.call @free(%395) : (!llvm.ptr) -> ()
    %743 = arith.constant 0 : i32
    func.return %743 : i32
  }
}