Problem 971

Sum of C_p = 1 + n*t over primes p <= 10^8 with p % 5 == 1. Ported from native C to pure Flow.

Answer33626723890930
Output(timeout)
StatusSKIP
Native helperno
Runtimen/a
Peak memoryn/a
Time complexityO(n^2) (estimated)
Space complexityO(n) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^2)O(n log log n)
Space complexityO(n)O(n)
ApproachFlow solutionSieve or enumeration
VerdictSuboptimal

Flow source

# Project Euler 971
# Sum of C_p = 1 + n*t over primes p <= 10^8 with p % 5 == 1.
# Ported from native C to pure Flow.

import euler.nt { isqrt }

extern {
    function calloc(n: i64, size: i64) -> ptr<void>
    function free(p: ptr<void>)
    function printf(fmt: ptr<i8>, ...) -> i32
}

# mulmod for u64 values where a, b < m <= 10^8: a*b fits in i64
function mulmod971(a0: i64, b0: i64, m: i64) -> i64 {
    let mut a: i64 = a0 % m
    let mut b: i64 = b0 % m
    let mut result: i64 = 0
    while b > 0 {
        if (b & 1) != 0 {
            result = (result + a) % m
        }
        a = (a * 2) % m
        b = b >> 1
    }
    return result
}

function powmod(a0: i64, e: i64, m: i64) -> i64 {
    let mut r: i64 = 1 % m
    let mut a: i64 = a0 % m
    let mut ee: i64 = e
    while ee > 0 {
        if (ee & 1) != 0 {
            r = mulmod971(r, a, m)
        }
        a = mulmod971(a, a, m)
        ee = ee >> 1
    }
    return r
}

# Odd-only sieve up to n. Returns array of primes and count.
let mut g_primes: ptr<i64> = null

function sieve_primes(n: i64) -> i64 {
    if n < 2 { return 0 }
    let half: i64 = n / 2 + 1
    let sv: ptr<i8> = calloc(half, 1) as ptr<i8>
    let limit: i64 = isqrt(n)
    let mut i: i64 = 1
    while i <= limit / 2 {
        if sv[i] == 0 {
            let p: i64 = 2 * i + 1
            let start: i64 = (p * p - 1) / 2
            let mut j: i64 = start
            while j < half {
                sv[j] = 1
                j = j + p
            }
        }
        i = i + 1
    }
    # count
    let mut cnt: i64 = 1
    i = 1
    while i < half {
        let v: i64 = 2 * i + 1
        if v <= n && sv[i] == 0 {
            cnt = cnt + 1
        }
        i = i + 1
    }
    g_primes = calloc(cnt, 8) as ptr<i64>
    let mut k: i64 = 0
    g_primes[k] = 2
    k = k + 1
    i = 1
    while i < half {
        let v: i64 = 2 * i + 1
        if v <= n && sv[i] == 0 {
            g_primes[k] = v
            k = k + 1
        }
        i = i + 1
    }
    free(sv as ptr<void>)
    return k
}

# For prime p with p % 5 == 1, count elements of mu5 on a cycle of phi.
function count_periodic_in_mu5(p: i64) -> i64 {
    let n: i64 = (p - 1) / 5
    # find a generator of mu5: a with a^n != 1 mod p
    let mut a: i64 = 2
    let mut zeta: i64 = powmod(a, n, p)
    while zeta == 1 {
        a = a + 1
        zeta = powmod(a, n, p)
    }
    # build mu5: {1, zeta, zeta^2, zeta^3, zeta^4}
    let mu5: array<i64, 5> = [0, 0, 0, 0, 0]
    mu5[0] = 1 % p
    let mut cur: i64 = 1
    let mut i: i64 = 1
    while i < 5 {
        cur = mulmod971(cur, zeta, p)
        mu5[i] = cur
        i = i + 1
    }
    # phi(s) = s * (1+s)^n mod p
    let phi: array<i64, 5> = [0, 0, 0, 0, 0]
    i = 0
    while i < 5 {
        let s: i64 = mu5[i]
        let one_plus: i64 = (1 + s) % p
        let pv: i64 = powmod(one_plus, n, p)
        phi[i] = mulmod971(s, pv, p)
        i = i + 1
    }
    # functional graph traversal on the 5 nodes
    let visited: array<i64, 5> = [0, 0, 0, 0, 0]
    let in_cycle: array<i64, 5> = [0, 0, 0, 0, 0]
    let path: array<i64, 8> = [0, 0, 0, 0, 0, 0, 0, 0]

    let mut start: i64 = 0
    while start < 5 {
        if visited[start] != 0 {
            start = start + 1
            continue
        }
        let mut pathlen: i64 = 0
        let mut ci: i64 = start
        while true {
            if visited[ci] == 0 {
                visited[ci] = 1
                path[pathlen] = ci
                pathlen = pathlen + 1
                # compute next: phi[ci]; find its index
                let v: i64 = phi[ci]
                let mut next: i64 = -1
                let mut j: i64 = 0
                while j < 5 {
                    if mu5[j] == v {
                        next = j
                        break
                    }
                    j = j + 1
                }
                if next < 0 {
                    # maps outside mu5: no cycle on this path
                    let mut x: i64 = 0
                    while x < pathlen {
                        visited[path[x]] = 2
                        x = x + 1
                    }
                    break
                }
                ci = next
            } else {
                if visited[ci] == 1 {
                    # found a cycle: from first occurrence of ci in path
                    let mut idx: i64 = 0
                    let mut x: i64 = 0
                    while x < pathlen {
                        if path[x] == ci {
                            idx = x
                            break
                        }
                        x = x + 1
                    }
                    x = idx
                    while x < pathlen {
                        in_cycle[path[x]] = 1
                        x = x + 1
                    }
                    x = 0
                    while x < pathlen {
                        visited[path[x]] = 2
                        x = x + 1
                    }
                    break
                } else {
                    # visited == 2: leads to processed region
                    let mut x: i64 = 0
                    while x < pathlen {
                        visited[path[x]] = 2
                        x = x + 1
                    }
                    break
                }
            }
        }
        start = start + 1
    }
    let mut t: i64 = 0
    let mut i2: i64 = 0
    while i2 < 5 {
        t = t + in_cycle[i2]
        i2 = i2 + 1
    }
    return t
}

function main() -> i32 {
    let limit: i64 = 100000000
    let np: i64 = sieve_primes(limit)
    let mut total: i128 = 0
    let mut i: i64 = 0
    while i < np {
        let p: i64 = g_primes[i]
        if p < 5 {
            if p == 2 || p == 3 {
                i = i + 1
                continue
            }
        }
        if p % 5 != 1 {
            i = i + 1
            continue
        }
        let n: i64 = (p - 1) / 5
        let t: i64 = count_periodic_in_mu5(p)
        let C_p: i64 = 1 + n * t
        total = total + (C_p as i128)
        i = i + 1
    }
    free(g_primes as ptr<void>)
    printf("%lld\n", total as i64)
    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 mulmod971_i64_i64_i64(int64_t a0, int64_t b0, int64_t m);
int64_t powmod_i64_i64_i64(int64_t a0, int64_t e, int64_t m);
int64_t sieve_primes_i64(int64_t n);
int64_t count_periodic_in_mu5_i64(int64_t p);
int32_t main(void);

/* Module statics */
static int64_t* g_primes = NULL;

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 mulmod971_i64_i64_i64(int64_t a0, int64_t b0, int64_t m) {
    int64_t a = FLOW_CHECKED_MOD((a0), (m));
    int64_t b = FLOW_CHECKED_MOD((b0), (m));
    int64_t result = 0;
    while (b > 0) {
        if ((b & 1) != 0) {
            result = FLOW_CHECKED_MOD(((result + a)), (m));
        }
        a = FLOW_CHECKED_MOD(((a * 2)), (m));
        b = FLOW_CHECKED_SHR((b), (1));
    }
    return result;
}

int64_t powmod_i64_i64_i64(int64_t a0, int64_t e, int64_t m) {
    int64_t r = FLOW_CHECKED_MOD((1), (m));
    int64_t a = FLOW_CHECKED_MOD((a0), (m));
    int64_t ee = e;
    while (ee > 0) {
        if ((ee & 1) != 0) {
            r = mulmod971_i64_i64_i64(r, a, m);
        }
        a = mulmod971_i64_i64_i64(a, a, m);
        ee = FLOW_CHECKED_SHR((ee), (1));
    }
    return r;
}

int64_t sieve_primes_i64(int64_t n) {
    if (n < 2) {
        return 0;
    }
    int64_t half = (FLOW_CHECKED_DIV((n), (2)) + 1);
    int8_t* sv = (int8_t*)(((int8_t*)(calloc(half, 1))));
    int64_t limit = isqrt_i64(n);
    int64_t i = 1;
    while (i <= FLOW_CHECKED_DIV((limit), (2))) {
        if (sv[i] == 0) {
            int64_t p = ((2 * i) + 1);
            int64_t start = FLOW_CHECKED_DIV((((p * p) - 1)), (2));
            int64_t j = start;
            while (j < half) {
                sv[j] = 1;
                j = (j + p);
            }
        }
        i = (i + 1);
    }
    int64_t cnt = 1;
    i = 1;
    while (i < half) {
        int64_t v = ((2 * i) + 1);
        if ((v <= n && sv[i] == 0)) {
            cnt = (cnt + 1);
        }
        i = (i + 1);
    }
    g_primes = ((int64_t*)(calloc(cnt, 8)));
    int64_t k = 0;
    g_primes[k] = 2;
    k = (k + 1);
    i = 1;
    while (i < half) {
        int64_t v = ((2 * i) + 1);
        if ((v <= n && sv[i] == 0)) {
            g_primes[k] = v;
            k = (k + 1);
        }
        i = (i + 1);
    }
    free(((void*)(sv)));
    return k;
}

int64_t count_periodic_in_mu5_i64(int64_t p) {
    int64_t n = FLOW_CHECKED_DIV(((p - 1)), (5));
    int64_t a = 2;
    int64_t zeta = powmod_i64_i64_i64(a, n, p);
    while (zeta == 1) {
        a = (a + 1);
        zeta = powmod_i64_i64_i64(a, n, p);
    }
    int64_t mu5[5] = { 0, 0, 0, 0, 0 };
    mu5[0] = FLOW_CHECKED_MOD((1), (p));
    int64_t cur = 1;
    int64_t i = 1;
    while (i < 5) {
        cur = mulmod971_i64_i64_i64(cur, zeta, p);
        mu5[i] = cur;
        i = (i + 1);
    }
    int64_t phi[5] = { 0, 0, 0, 0, 0 };
    i = 0;
    while (i < 5) {
        int64_t s = (((unsigned)(i) < 5) ? mu5[i] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)(i), 5), flow_fault_handler("array index out of bounds"), mu5[0]));
        int64_t one_plus = FLOW_CHECKED_MOD(((1 + s)), (p));
        int64_t pv = powmod_i64_i64_i64(one_plus, n, p);
        phi[i] = mulmod971_i64_i64_i64(s, pv, p);
        i = (i + 1);
    }
    int64_t visited[5] = { 0, 0, 0, 0, 0 };
    int64_t in_cycle[5] = { 0, 0, 0, 0, 0 };
    int64_t path[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
    int64_t start = 0;
    while (start < 5) {
        if ((((unsigned)(start) < 5) ? visited[start] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)(start), 5), flow_fault_handler("array index out of bounds"), visited[0])) != 0) {
            start = (start + 1);
            continue;
        }
        int64_t pathlen = 0;
        int64_t ci = start;
        while (1) {
            if ((((unsigned)(ci) < 5) ? visited[ci] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)(ci), 5), flow_fault_handler("array index out of bounds"), visited[0])) == 0) {
                visited[ci] = 1;
                path[pathlen] = ci;
                pathlen = (pathlen + 1);
                int64_t v = (((unsigned)(ci) < 5) ? phi[ci] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)(ci), 5), flow_fault_handler("array index out of bounds"), phi[0]));
                int64_t next = (-1);
                int64_t j = 0;
                while (j < 5) {
                    if ((((unsigned)(j) < 5) ? mu5[j] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)(j), 5), flow_fault_handler("array index out of bounds"), mu5[0])) == v) {
                        next = j;
                        break;
                    }
                    j = (j + 1);
                }
                if (next < 0) {
                    int64_t x = 0;
                    while (x < pathlen) {
                        visited[(((unsigned)(x) < 8) ? path[x] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)(x), 8), flow_fault_handler("array index out of bounds"), path[0]))] = 2;
                        x = (x + 1);
                    }
                    break;
                }
                ci = next;
            } else {
                if ((((unsigned)(ci) < 5) ? visited[ci] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)(ci), 5), flow_fault_handler("array index out of bounds"), visited[0])) == 1) {
                    int64_t idx = 0;
                    int64_t x = 0;
                    while (x < pathlen) {
                        if ((((unsigned)(x) < 8) ? path[x] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)(x), 8), flow_fault_handler("array index out of bounds"), path[0])) == ci) {
                            idx = x;
                            break;
                        }
                        x = (x + 1);
                    }
                    x = idx;
                    while (x < pathlen) {
                        in_cycle[(((unsigned)(x) < 8) ? path[x] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)(x), 8), flow_fault_handler("array index out of bounds"), path[0]))] = 1;
                        x = (x + 1);
                    }
                    x = 0;
                    while (x < pathlen) {
                        visited[(((unsigned)(x) < 8) ? path[x] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)(x), 8), flow_fault_handler("array index out of bounds"), path[0]))] = 2;
                        x = (x + 1);
                    }
                    break;
                } else {
                    int64_t x = 0;
                    while (x < pathlen) {
                        visited[(((unsigned)(x) < 8) ? path[x] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)(x), 8), flow_fault_handler("array index out of bounds"), path[0]))] = 2;
                        x = (x + 1);
                    }
                    break;
                }
            }
        }
        start = (start + 1);
    }
    int64_t t = 0;
    int64_t i2 = 0;
    while (i2 < 5) {
        t = (t + (((unsigned)(i2) < 5) ? in_cycle[i2] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)(i2), 5), flow_fault_handler("array index out of bounds"), in_cycle[0])));
        i2 = (i2 + 1);
    }
    return t;
}

int32_t main(void) {
    int64_t limit = 100000000;
    int64_t np = sieve_primes_i64(limit);
    __int128 total = 0;
    int64_t i = 0;
    while (i < np) {
        int64_t p = g_primes[i];
        if (p < 5) {
            if ((p == 2 || p == 3)) {
                i = (i + 1);
                continue;
            }
        }
        if (FLOW_CHECKED_MOD((p), (5)) != 1) {
            i = (i + 1);
            continue;
        }
        int64_t n = FLOW_CHECKED_DIV(((p - 1)), (5));
        int64_t t = count_periodic_in_mu5_i64(p);
        int64_t C_p = (1 + (n * t));
        total = (total + ((__int128)(C_p)));
        i = (i + 1);
    }
    free(((void*)(g_primes)));
    printf("%lld\n", ((int64_t)(total)));
    return 0;
}

Generated MLIR

module {
  llvm.func @printf(!llvm.ptr, ...) -> i32
  llvm.mlir.global internal constant @str_0("%lld\n\00") {addr_space = 0 : i32} : !llvm.array<6 x i8>
  func.func @gcd(%arg0: i64, %arg1: i64) -> i64 {
    %0 = llvm.mlir.constant(1 : i64) : i64
    %1 = llvm.alloca %0 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %1 : i64, !llvm.ptr
    %2 = llvm.mlir.constant(1 : i64) : i64
    %3 = llvm.alloca %2 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %3 : i64, !llvm.ptr
    cf.br ^bb0
    ^bb0:
    %4 = llvm.load %3 : !llvm.ptr -> i64
    %5 = arith.constant 0 : i32
    %7 = arith.extsi %5 : i32 to i64
    %6 = arith.cmpi ne, %4, %7 : i64
    cf.cond_br %6, ^bb1, ^bb2
    ^bb1:
      %8 = llvm.load %1 : !llvm.ptr -> i64
      %9 = llvm.load %3 : !llvm.ptr -> i64
      %10 = arith.remsi %8, %9 : i64
      %11 = llvm.load %3 : !llvm.ptr -> i64
      llvm.store %11, %1 : i64, !llvm.ptr
      llvm.store %10, %3 : i64, !llvm.ptr
      cf.br ^bb0
    ^bb2:
    %12 = llvm.load %1 : !llvm.ptr -> i64
    func.return %12 : i64
  }
  func.func @lcm(%arg0: i64, %arg1: i64) -> i64 {
    %13 = arith.constant 0 : i32
    %15 = arith.extsi %13 : i32 to i64
    %14 = arith.cmpi eq, %arg0, %15 : i64
    %16 = scf.if %14 -> (i1) {
      %17 = arith.constant true
      scf.yield %17 : i1
    } else {
      %18 = arith.constant 0 : i32
      %20 = arith.extsi %18 : i32 to i64
      %19 = arith.cmpi eq, %arg1, %20 : i64
      scf.yield %19 : i1
    }
    cf.cond_br %16, ^bb3, ^bb4
    ^bb3:
      %21 = arith.constant 0 : i32
      %22 = arith.extsi %21 : i32 to i64
      func.return %22 : i64
    ^bb4:
      cf.br ^bb5
    ^bb5:
    %23 = func.call @gcd(%arg0, %arg1) : (i64, i64) -> i64
    %24 = arith.divsi %arg0, %23 : i64
    %25 = arith.muli %24, %arg1 : i64
    func.return %25 : i64
  }
  func.func @isqrt(%arg0: i64) -> i64 {
    %26 = arith.constant 2 : i32
    %28 = arith.extsi %26 : i32 to i64
    %27 = arith.cmpi slt, %arg0, %28 : i64
    cf.cond_br %27, ^bb6, ^bb7
    ^bb6:
      func.return %arg0 : i64
    ^bb7:
      cf.br ^bb8
    ^bb8:
    %29 = llvm.mlir.constant(1 : i64) : i64
    %30 = llvm.alloca %29 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %30 : i64, !llvm.ptr
    %31 = llvm.load %30 : !llvm.ptr -> i64
    %32 = arith.constant 1 : i32
    %34 = arith.extsi %32 : i32 to i64
    %33 = arith.addi %31, %34 : i64
    %35 = arith.constant 2 : i32
    %37 = arith.extsi %35 : i32 to i64
    %36 = arith.divsi %33, %37 : i64
    %38 = llvm.mlir.constant(1 : i64) : i64
    %39 = llvm.alloca %38 x i64 : (i64) -> !llvm.ptr
    llvm.store %36, %39 : i64, !llvm.ptr
    cf.br ^bb9
    ^bb9:
    %40 = llvm.load %39 : !llvm.ptr -> i64
    %41 = llvm.load %30 : !llvm.ptr -> i64
    %42 = arith.cmpi slt, %40, %41 : i64
    cf.cond_br %42, ^bb10, ^bb11
    ^bb10:
      %43 = llvm.load %39 : !llvm.ptr -> i64
      llvm.store %43, %30 : i64, !llvm.ptr
      %44 = llvm.load %30 : !llvm.ptr -> i64
      %45 = llvm.load %30 : !llvm.ptr -> i64
      %46 = arith.divsi %arg0, %45 : i64
      %47 = arith.addi %44, %46 : i64
      %48 = arith.constant 2 : i32
      %50 = arith.extsi %48 : i32 to i64
      %49 = arith.divsi %47, %50 : i64
      llvm.store %49, %39 : i64, !llvm.ptr
      cf.br ^bb9
    ^bb11:
    %51 = llvm.load %30 : !llvm.ptr -> i64
    func.return %51 : i64
  }
  func.func @mulmod(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %52 = arith.remsi %arg0, %arg2 : i64
    %53 = llvm.mlir.constant(1 : i64) : i64
    %54 = llvm.alloca %53 x i64 : (i64) -> !llvm.ptr
    llvm.store %52, %54 : i64, !llvm.ptr
    %55 = arith.remsi %arg1, %arg2 : i64
    %56 = llvm.mlir.constant(1 : i64) : i64
    %57 = llvm.alloca %56 x i64 : (i64) -> !llvm.ptr
    llvm.store %55, %57 : i64, !llvm.ptr
    %58 = arith.constant 0 : i32
    %59 = arith.extsi %58 : i32 to i64
    %60 = llvm.mlir.constant(1 : i64) : i64
    %61 = llvm.alloca %60 x i64 : (i64) -> !llvm.ptr
    llvm.store %59, %61 : i64, !llvm.ptr
    cf.br ^bb12
    ^bb12:
    %62 = llvm.load %57 : !llvm.ptr -> i64
    %63 = arith.constant 0 : i32
    %65 = arith.extsi %63 : i32 to i64
    %64 = arith.cmpi sgt, %62, %65 : i64
    cf.cond_br %64, ^bb13, ^bb14
    ^bb13:
      %66 = llvm.load %57 : !llvm.ptr -> i64
      %67 = arith.constant 2 : i32
      %69 = arith.extsi %67 : i32 to i64
      %68 = arith.remsi %66, %69 : i64
      %70 = arith.constant 1 : i32
      %72 = arith.extsi %70 : i32 to i64
      %71 = arith.cmpi eq, %68, %72 : i64
      cf.cond_br %71, ^bb15, ^bb16
      ^bb15:
        %73 = llvm.load %61 : !llvm.ptr -> i64
        %74 = llvm.load %54 : !llvm.ptr -> i64
        %75 = arith.addi %73, %74 : i64
        %76 = arith.remsi %75, %arg2 : i64
        llvm.store %76, %61 : i64, !llvm.ptr
        cf.br ^bb17
      ^bb16:
        cf.br ^bb17
      ^bb17:
      %77 = llvm.load %54 : !llvm.ptr -> i64
      %78 = arith.constant 2 : i32
      %80 = arith.extsi %78 : i32 to i64
      %79 = arith.muli %77, %80 : i64
      %81 = arith.remsi %79, %arg2 : i64
      llvm.store %81, %54 : i64, !llvm.ptr
      %82 = llvm.load %57 : !llvm.ptr -> i64
      %83 = arith.constant 2 : i32
      %85 = arith.extsi %83 : i32 to i64
      %84 = arith.divsi %82, %85 : i64
      llvm.store %84, %57 : i64, !llvm.ptr
      cf.br ^bb12
    ^bb14:
    %86 = llvm.load %61 : !llvm.ptr -> i64
    func.return %86 : i64
  }
  func.func @mod_pow(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %87 = arith.constant 1 : i32
    %89 = arith.extsi %87 : i32 to i64
    %88 = arith.cmpi eq, %arg2, %89 : i64
    cf.cond_br %88, ^bb18, ^bb19
    ^bb18:
      %90 = arith.constant 0 : i32
      %91 = arith.extsi %90 : i32 to i64
      func.return %91 : i64
    ^bb19:
      cf.br ^bb20
    ^bb20:
    %92 = arith.constant 1 : i32
    %93 = arith.extsi %92 : i32 to i64
    %94 = llvm.mlir.constant(1 : i64) : i64
    %95 = llvm.alloca %94 x i64 : (i64) -> !llvm.ptr
    llvm.store %93, %95 : i64, !llvm.ptr
    %96 = arith.remsi %arg0, %arg2 : i64
    %97 = llvm.mlir.constant(1 : i64) : i64
    %98 = llvm.alloca %97 x i64 : (i64) -> !llvm.ptr
    llvm.store %96, %98 : i64, !llvm.ptr
    %99 = llvm.mlir.constant(1 : i64) : i64
    %100 = llvm.alloca %99 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %100 : i64, !llvm.ptr
    cf.br ^bb21
    ^bb21:
    %101 = llvm.load %100 : !llvm.ptr -> i64
    %102 = arith.constant 0 : i32
    %104 = arith.extsi %102 : i32 to i64
    %103 = arith.cmpi sgt, %101, %104 : i64
    cf.cond_br %103, ^bb22, ^bb23
    ^bb22:
      %105 = llvm.load %100 : !llvm.ptr -> i64
      %106 = arith.constant 2 : i32
      %108 = arith.extsi %106 : i32 to i64
      %107 = arith.remsi %105, %108 : i64
      %109 = arith.constant 1 : i32
      %111 = arith.extsi %109 : i32 to i64
      %110 = arith.cmpi eq, %107, %111 : i64
      cf.cond_br %110, ^bb24, ^bb25
      ^bb24:
        %113 = llvm.load %95 : !llvm.ptr -> i64
        %114 = llvm.load %98 : !llvm.ptr -> i64
        %112 = func.call @mulmod(%113, %114, %arg2) : (i64, i64, i64) -> i64
        llvm.store %112, %95 : i64, !llvm.ptr
        cf.br ^bb26
      ^bb25:
        cf.br ^bb26
      ^bb26:
      %116 = llvm.load %98 : !llvm.ptr -> i64
      %117 = llvm.load %98 : !llvm.ptr -> i64
      %115 = func.call @mulmod(%116, %117, %arg2) : (i64, i64, i64) -> i64
      llvm.store %115, %98 : i64, !llvm.ptr
      %118 = llvm.load %100 : !llvm.ptr -> i64
      %119 = arith.constant 2 : i32
      %121 = arith.extsi %119 : i32 to i64
      %120 = arith.divsi %118, %121 : i64
      llvm.store %120, %100 : i64, !llvm.ptr
      cf.br ^bb21
    ^bb23:
    %122 = llvm.load %95 : !llvm.ptr -> i64
    func.return %122 : i64
  }
  func.func @is_prime(%arg0: i64) -> i1 {
    %123 = arith.constant 2 : i32
    %125 = arith.extsi %123 : i32 to i64
    %124 = arith.cmpi slt, %arg0, %125 : i64
    cf.cond_br %124, ^bb27, ^bb28
    ^bb27:
      %126 = arith.constant 0 : i1
      func.return %126 : i1
    ^bb28:
      cf.br ^bb29
    ^bb29:
    %127 = arith.constant 4 : i32
    %129 = arith.extsi %127 : i32 to i64
    %128 = arith.cmpi slt, %arg0, %129 : i64
    cf.cond_br %128, ^bb30, ^bb31
    ^bb30:
      %130 = arith.constant 1 : i1
      func.return %130 : i1
    ^bb31:
      cf.br ^bb32
    ^bb32:
    %131 = arith.constant 2 : i32
    %133 = arith.extsi %131 : i32 to i64
    %132 = arith.remsi %arg0, %133 : i64
    %134 = arith.constant 0 : i32
    %136 = arith.extsi %134 : i32 to i64
    %135 = arith.cmpi eq, %132, %136 : i64
    %137 = scf.if %135 -> (i1) {
      %138 = arith.constant true
      scf.yield %138 : i1
    } else {
      %139 = arith.constant 3 : i32
      %141 = arith.extsi %139 : i32 to i64
      %140 = arith.remsi %arg0, %141 : i64
      %142 = arith.constant 0 : i32
      %144 = arith.extsi %142 : i32 to i64
      %143 = arith.cmpi eq, %140, %144 : i64
      scf.yield %143 : i1
    }
    cf.cond_br %137, ^bb33, ^bb34
    ^bb33:
      %145 = arith.constant 0 : i1
      func.return %145 : i1
    ^bb34:
      cf.br ^bb35
    ^bb35:
    %146 = arith.constant 5 : i32
    %147 = arith.extsi %146 : i32 to i64
    %148 = llvm.mlir.constant(1 : i64) : i64
    %149 = llvm.alloca %148 x i64 : (i64) -> !llvm.ptr
    llvm.store %147, %149 : i64, !llvm.ptr
    cf.br ^bb36
    ^bb36:
    %150 = llvm.load %149 : !llvm.ptr -> i64
    %151 = llvm.load %149 : !llvm.ptr -> i64
    %152 = arith.muli %150, %151 : i64
    %153 = arith.cmpi sle, %152, %arg0 : i64
    cf.cond_br %153, ^bb37, ^bb38
    ^bb37:
      %154 = llvm.load %149 : !llvm.ptr -> i64
      %155 = arith.remsi %arg0, %154 : i64
      %156 = arith.constant 0 : i32
      %158 = arith.extsi %156 : i32 to i64
      %157 = arith.cmpi eq, %155, %158 : i64
      %159 = scf.if %157 -> (i1) {
        %160 = arith.constant true
        scf.yield %160 : i1
      } else {
        %161 = llvm.load %149 : !llvm.ptr -> i64
        %162 = arith.constant 2 : i32
        %164 = arith.extsi %162 : i32 to i64
        %163 = arith.addi %161, %164 : i64
        %165 = arith.remsi %arg0, %163 : i64
        %166 = arith.constant 0 : i32
        %168 = arith.extsi %166 : i32 to i64
        %167 = arith.cmpi eq, %165, %168 : i64
        scf.yield %167 : i1
      }
      cf.cond_br %159, ^bb39, ^bb40
      ^bb39:
        %169 = arith.constant 0 : i1
        func.return %169 : i1
      ^bb40:
        cf.br ^bb41
      ^bb41:
      %170 = llvm.load %149 : !llvm.ptr -> i64
      %171 = arith.constant 6 : i32
      %173 = arith.extsi %171 : i32 to i64
      %172 = arith.addi %170, %173 : i64
      llvm.store %172, %149 : i64, !llvm.ptr
      cf.br ^bb36
    ^bb38:
    %174 = arith.constant 1 : i1
    func.return %174 : i1
  }
  func.func private @calloc(i64, i64) -> !llvm.ptr
  func.func private @free(!llvm.ptr) -> ()

  func.func @mulmod971(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %175 = arith.remsi %arg0, %arg2 : i64
    %176 = llvm.mlir.constant(1 : i64) : i64
    %177 = llvm.alloca %176 x i64 : (i64) -> !llvm.ptr
    llvm.store %175, %177 : i64, !llvm.ptr
    %178 = arith.remsi %arg1, %arg2 : i64
    %179 = llvm.mlir.constant(1 : i64) : i64
    %180 = llvm.alloca %179 x i64 : (i64) -> !llvm.ptr
    llvm.store %178, %180 : i64, !llvm.ptr
    %181 = arith.constant 0 : i32
    %182 = arith.extsi %181 : i32 to i64
    %183 = llvm.mlir.constant(1 : i64) : i64
    %184 = llvm.alloca %183 x i64 : (i64) -> !llvm.ptr
    llvm.store %182, %184 : i64, !llvm.ptr
    cf.br ^bb42
    ^bb42:
    %185 = llvm.load %180 : !llvm.ptr -> i64
    %186 = arith.constant 0 : i32
    %188 = arith.extsi %186 : i32 to i64
    %187 = arith.cmpi sgt, %185, %188 : i64
    cf.cond_br %187, ^bb43, ^bb44
    ^bb43:
      %189 = llvm.load %180 : !llvm.ptr -> i64
      %190 = arith.constant 1 : i32
      %192 = arith.extsi %190 : i32 to i64
      %191 = arith.andi %189, %192 : i64
      %193 = arith.constant 0 : i32
      %195 = arith.extsi %193 : i32 to i64
      %194 = arith.cmpi ne, %191, %195 : i64
      cf.cond_br %194, ^bb45, ^bb46
      ^bb45:
        %196 = llvm.load %184 : !llvm.ptr -> i64
        %197 = llvm.load %177 : !llvm.ptr -> i64
        %198 = arith.addi %196, %197 : i64
        %199 = arith.remsi %198, %arg2 : i64
        llvm.store %199, %184 : i64, !llvm.ptr
        cf.br ^bb47
      ^bb46:
        cf.br ^bb47
      ^bb47:
      %200 = llvm.load %177 : !llvm.ptr -> i64
      %201 = arith.constant 2 : i32
      %203 = arith.extsi %201 : i32 to i64
      %202 = arith.muli %200, %203 : i64
      %204 = arith.remsi %202, %arg2 : i64
      llvm.store %204, %177 : i64, !llvm.ptr
      %205 = llvm.load %180 : !llvm.ptr -> i64
      %206 = arith.constant 1 : i32
      %208 = arith.extsi %206 : i32 to i64
      %207 = arith.shrsi %205, %208 : i64
      llvm.store %207, %180 : i64, !llvm.ptr
      cf.br ^bb42
    ^bb44:
    %209 = llvm.load %184 : !llvm.ptr -> i64
    func.return %209 : i64
  }
  func.func @powmod(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %210 = arith.constant 1 : i32
    %212 = arith.extsi %210 : i32 to i64
    %211 = arith.remsi %212, %arg2 : i64
    %213 = llvm.mlir.constant(1 : i64) : i64
    %214 = llvm.alloca %213 x i64 : (i64) -> !llvm.ptr
    llvm.store %211, %214 : i64, !llvm.ptr
    %215 = arith.remsi %arg0, %arg2 : i64
    %216 = llvm.mlir.constant(1 : i64) : i64
    %217 = llvm.alloca %216 x i64 : (i64) -> !llvm.ptr
    llvm.store %215, %217 : i64, !llvm.ptr
    %218 = llvm.mlir.constant(1 : i64) : i64
    %219 = llvm.alloca %218 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %219 : i64, !llvm.ptr
    cf.br ^bb48
    ^bb48:
    %220 = llvm.load %219 : !llvm.ptr -> i64
    %221 = arith.constant 0 : i32
    %223 = arith.extsi %221 : i32 to i64
    %222 = arith.cmpi sgt, %220, %223 : i64
    cf.cond_br %222, ^bb49, ^bb50
    ^bb49:
      %224 = llvm.load %219 : !llvm.ptr -> i64
      %225 = arith.constant 1 : i32
      %227 = arith.extsi %225 : i32 to i64
      %226 = arith.andi %224, %227 : i64
      %228 = arith.constant 0 : i32
      %230 = arith.extsi %228 : i32 to i64
      %229 = arith.cmpi ne, %226, %230 : i64
      cf.cond_br %229, ^bb51, ^bb52
      ^bb51:
        %232 = llvm.load %214 : !llvm.ptr -> i64
        %233 = llvm.load %217 : !llvm.ptr -> i64
        %231 = func.call @mulmod971(%232, %233, %arg2) : (i64, i64, i64) -> i64
        llvm.store %231, %214 : i64, !llvm.ptr
        cf.br ^bb53
      ^bb52:
        cf.br ^bb53
      ^bb53:
      %235 = llvm.load %217 : !llvm.ptr -> i64
      %236 = llvm.load %217 : !llvm.ptr -> i64
      %234 = func.call @mulmod971(%235, %236, %arg2) : (i64, i64, i64) -> i64
      llvm.store %234, %217 : i64, !llvm.ptr
      %237 = llvm.load %219 : !llvm.ptr -> i64
      %238 = arith.constant 1 : i32
      %240 = arith.extsi %238 : i32 to i64
      %239 = arith.shrsi %237, %240 : i64
      llvm.store %239, %219 : i64, !llvm.ptr
      cf.br ^bb48
    ^bb50:
    %241 = llvm.load %214 : !llvm.ptr -> i64
    func.return %241 : i64
  }
  // Module static: g_primes
  llvm.mlir.global internal @g_primes() {addr_space = 0 : i32} : !llvm.ptr {
    %242 = llvm.mlir.zero : !llvm.ptr
    llvm.return %242 : !llvm.ptr
  }
  func.func @sieve_primes(%arg0: i64) -> i64 {
    %243 = arith.constant 2 : i32
    %245 = arith.extsi %243 : i32 to i64
    %244 = arith.cmpi slt, %arg0, %245 : i64
    cf.cond_br %244, ^bb54, ^bb55
    ^bb54:
      %246 = arith.constant 0 : i32
      %247 = arith.extsi %246 : i32 to i64
      func.return %247 : i64
    ^bb55:
      cf.br ^bb56
    ^bb56:
    %248 = arith.constant 2 : i32
    %250 = arith.extsi %248 : i32 to i64
    %249 = arith.divsi %arg0, %250 : i64
    %251 = arith.constant 1 : i32
    %253 = arith.extsi %251 : i32 to i64
    %252 = arith.addi %249, %253 : i64
    %255 = arith.constant 1 : i32
    %256 = arith.extsi %255 : i32 to i64
    %254 = func.call @calloc(%252, %256) : (i64, i64) -> !llvm.ptr
    %257 = func.call @isqrt(%arg0) : (i64) -> i64
    %258 = arith.constant 1 : i32
    %259 = arith.extsi %258 : i32 to i64
    %260 = llvm.mlir.constant(1 : i64) : i64
    %261 = llvm.alloca %260 x i64 : (i64) -> !llvm.ptr
    llvm.store %259, %261 : i64, !llvm.ptr
    cf.br ^bb57
    ^bb57:
    %262 = llvm.load %261 : !llvm.ptr -> i64
    %263 = arith.constant 2 : i32
    %265 = arith.extsi %263 : i32 to i64
    %264 = arith.divsi %257, %265 : i64
    %266 = arith.cmpi sle, %262, %264 : i64
    cf.cond_br %266, ^bb58, ^bb59
    ^bb58:
      %268 = llvm.load %261 : !llvm.ptr -> i64
      %269 = llvm.getelementptr %254[%268] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %267 = llvm.load %269 : !llvm.ptr -> i8
      %270 = arith.constant 0 : i32
      %272 = arith.extsi %267 : i8 to i32
      %271 = arith.cmpi eq, %272, %270 : i32
      cf.cond_br %271, ^bb60, ^bb61
      ^bb60:
        %273 = arith.constant 2 : i32
        %274 = llvm.load %261 : !llvm.ptr -> i64
        %276 = arith.extsi %273 : i32 to i64
        %275 = arith.muli %276, %274 : i64
        %277 = arith.constant 1 : i32
        %279 = arith.extsi %277 : i32 to i64
        %278 = arith.addi %275, %279 : i64
        %280 = arith.muli %278, %278 : i64
        %281 = arith.constant 1 : i32
        %283 = arith.extsi %281 : i32 to i64
        %282 = arith.subi %280, %283 : i64
        %284 = arith.constant 2 : i32
        %286 = arith.extsi %284 : i32 to i64
        %285 = arith.divsi %282, %286 : i64
        %287 = llvm.mlir.constant(1 : i64) : i64
        %288 = llvm.alloca %287 x i64 : (i64) -> !llvm.ptr
        llvm.store %285, %288 : i64, !llvm.ptr
        cf.br ^bb63
        ^bb63:
        %289 = llvm.load %288 : !llvm.ptr -> i64
        %290 = arith.cmpi slt, %289, %252 : i64
        cf.cond_br %290, ^bb64, ^bb65
        ^bb64:
          %291 = arith.constant 1 : i32
          %292 = llvm.load %288 : !llvm.ptr -> i64
          %293 = arith.trunci %291 : i32 to i8
          %294 = llvm.getelementptr %254[%292] : (!llvm.ptr, i64) -> !llvm.ptr, i8
          llvm.store %293, %294 : i8, !llvm.ptr
          %295 = llvm.load %288 : !llvm.ptr -> i64
          %296 = arith.addi %295, %278 : i64
          llvm.store %296, %288 : i64, !llvm.ptr
          cf.br ^bb63
        ^bb65:
        cf.br ^bb62
      ^bb61:
        cf.br ^bb62
      ^bb62:
      %297 = llvm.load %261 : !llvm.ptr -> i64
      %298 = arith.constant 1 : i32
      %300 = arith.extsi %298 : i32 to i64
      %299 = arith.addi %297, %300 : i64
      llvm.store %299, %261 : i64, !llvm.ptr
      cf.br ^bb57
    ^bb59:
    %301 = arith.constant 1 : i32
    %302 = arith.extsi %301 : i32 to i64
    %303 = llvm.mlir.constant(1 : i64) : i64
    %304 = llvm.alloca %303 x i64 : (i64) -> !llvm.ptr
    llvm.store %302, %304 : i64, !llvm.ptr
    %305 = arith.constant 1 : i32
    %306 = arith.extsi %305 : i32 to i64
    llvm.store %306, %261 : i64, !llvm.ptr
    cf.br ^bb66
    ^bb66:
    %307 = llvm.load %261 : !llvm.ptr -> i64
    %308 = arith.cmpi slt, %307, %252 : i64
    cf.cond_br %308, ^bb67, ^bb68
    ^bb67:
      %309 = arith.constant 2 : i32
      %310 = llvm.load %261 : !llvm.ptr -> i64
      %312 = arith.extsi %309 : i32 to i64
      %311 = arith.muli %312, %310 : i64
      %313 = arith.constant 1 : i32
      %315 = arith.extsi %313 : i32 to i64
      %314 = arith.addi %311, %315 : i64
      %316 = arith.cmpi sle, %314, %arg0 : i64
      %317 = scf.if %316 -> (i1) {
        %319 = llvm.load %261 : !llvm.ptr -> i64
        %320 = llvm.getelementptr %254[%319] : (!llvm.ptr, i64) -> !llvm.ptr, i8
        %318 = llvm.load %320 : !llvm.ptr -> i8
        %321 = arith.constant 0 : i32
        %323 = arith.extsi %318 : i8 to i32
        %322 = arith.cmpi eq, %323, %321 : i32
        scf.yield %322 : i1
      } else {
        %324 = arith.constant false
        scf.yield %324 : i1
      }
      cf.cond_br %317, ^bb69, ^bb70
      ^bb69:
        %325 = llvm.load %304 : !llvm.ptr -> i64
        %326 = arith.constant 1 : i32
        %328 = arith.extsi %326 : i32 to i64
        %327 = arith.addi %325, %328 : i64
        llvm.store %327, %304 : i64, !llvm.ptr
        cf.br ^bb71
      ^bb70:
        cf.br ^bb71
      ^bb71:
      %329 = llvm.load %261 : !llvm.ptr -> i64
      %330 = arith.constant 1 : i32
      %332 = arith.extsi %330 : i32 to i64
      %331 = arith.addi %329, %332 : i64
      llvm.store %331, %261 : i64, !llvm.ptr
      cf.br ^bb66
    ^bb68:
    %334 = llvm.load %304 : !llvm.ptr -> i64
    %335 = arith.constant 8 : i32
    %336 = arith.extsi %335 : i32 to i64
    %333 = func.call @calloc(%334, %336) : (i64, i64) -> !llvm.ptr
    %337 = llvm.mlir.addressof @g_primes : !llvm.ptr
    llvm.store %333, %337 : !llvm.ptr, !llvm.ptr
    %338 = arith.constant 0 : i32
    %339 = arith.extsi %338 : i32 to i64
    %340 = llvm.mlir.constant(1 : i64) : i64
    %341 = llvm.alloca %340 x i64 : (i64) -> !llvm.ptr
    llvm.store %339, %341 : i64, !llvm.ptr
    %342 = arith.constant 2 : i32
    %343 = llvm.mlir.addressof @g_primes : !llvm.ptr
    %344 = llvm.load %343 : !llvm.ptr -> !llvm.ptr
    %345 = llvm.load %341 : !llvm.ptr -> i64
    %346 = arith.extsi %342 : i32 to i64
    %347 = llvm.getelementptr %344[%345] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %346, %347 : i64, !llvm.ptr
    %348 = llvm.load %341 : !llvm.ptr -> i64
    %349 = arith.constant 1 : i32
    %351 = arith.extsi %349 : i32 to i64
    %350 = arith.addi %348, %351 : i64
    llvm.store %350, %341 : i64, !llvm.ptr
    %352 = arith.constant 1 : i32
    %353 = arith.extsi %352 : i32 to i64
    llvm.store %353, %261 : i64, !llvm.ptr
    cf.br ^bb72
    ^bb72:
    %354 = llvm.load %261 : !llvm.ptr -> i64
    %355 = arith.cmpi slt, %354, %252 : i64
    cf.cond_br %355, ^bb73, ^bb74
    ^bb73:
      %356 = arith.constant 2 : i32
      %357 = llvm.load %261 : !llvm.ptr -> i64
      %359 = arith.extsi %356 : i32 to i64
      %358 = arith.muli %359, %357 : i64
      %360 = arith.constant 1 : i32
      %362 = arith.extsi %360 : i32 to i64
      %361 = arith.addi %358, %362 : i64
      %363 = arith.cmpi sle, %361, %arg0 : i64
      %364 = scf.if %363 -> (i1) {
        %366 = llvm.load %261 : !llvm.ptr -> i64
        %367 = llvm.getelementptr %254[%366] : (!llvm.ptr, i64) -> !llvm.ptr, i8
        %365 = llvm.load %367 : !llvm.ptr -> i8
        %368 = arith.constant 0 : i32
        %370 = arith.extsi %365 : i8 to i32
        %369 = arith.cmpi eq, %370, %368 : i32
        scf.yield %369 : i1
      } else {
        %371 = arith.constant false
        scf.yield %371 : i1
      }
      cf.cond_br %364, ^bb75, ^bb76
      ^bb75:
        %372 = llvm.mlir.addressof @g_primes : !llvm.ptr
        %373 = llvm.load %372 : !llvm.ptr -> !llvm.ptr
        %374 = llvm.load %341 : !llvm.ptr -> i64
        %375 = llvm.getelementptr %373[%374] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %361, %375 : i64, !llvm.ptr
        %376 = llvm.load %341 : !llvm.ptr -> i64
        %377 = arith.constant 1 : i32
        %379 = arith.extsi %377 : i32 to i64
        %378 = arith.addi %376, %379 : i64
        llvm.store %378, %341 : i64, !llvm.ptr
        cf.br ^bb77
      ^bb76:
        cf.br ^bb77
      ^bb77:
      %380 = llvm.load %261 : !llvm.ptr -> i64
      %381 = arith.constant 1 : i32
      %383 = arith.extsi %381 : i32 to i64
      %382 = arith.addi %380, %383 : i64
      llvm.store %382, %261 : i64, !llvm.ptr
      cf.br ^bb72
    ^bb74:
    func.call @free(%254) : (!llvm.ptr) -> ()
    %385 = llvm.load %341 : !llvm.ptr -> i64
    func.return %385 : i64
  }
  func.func @count_periodic_in_mu5(%arg0: i64) -> i64 {
    %386 = arith.constant 1 : i32
    %388 = arith.extsi %386 : i32 to i64
    %387 = arith.subi %arg0, %388 : i64
    %389 = arith.constant 5 : i32
    %391 = arith.extsi %389 : i32 to i64
    %390 = arith.divsi %387, %391 : i64
    %392 = arith.constant 2 : i32
    %393 = arith.extsi %392 : i32 to i64
    %394 = llvm.mlir.constant(1 : i64) : i64
    %395 = llvm.alloca %394 x i64 : (i64) -> !llvm.ptr
    llvm.store %393, %395 : i64, !llvm.ptr
    %397 = llvm.load %395 : !llvm.ptr -> i64
    %396 = func.call @powmod(%397, %390, %arg0) : (i64, i64, i64) -> i64
    %398 = llvm.mlir.constant(1 : i64) : i64
    %399 = llvm.alloca %398 x i64 : (i64) -> !llvm.ptr
    llvm.store %396, %399 : i64, !llvm.ptr
    cf.br ^bb78
    ^bb78:
    %400 = llvm.load %399 : !llvm.ptr -> i64
    %401 = arith.constant 1 : i32
    %403 = arith.extsi %401 : i32 to i64
    %402 = arith.cmpi eq, %400, %403 : i64
    cf.cond_br %402, ^bb79, ^bb80
    ^bb79:
      %404 = llvm.load %395 : !llvm.ptr -> i64
      %405 = arith.constant 1 : i32
      %407 = arith.extsi %405 : i32 to i64
      %406 = arith.addi %404, %407 : i64
      llvm.store %406, %395 : i64, !llvm.ptr
      %409 = llvm.load %395 : !llvm.ptr -> i64
      %408 = func.call @powmod(%409, %390, %arg0) : (i64, i64, i64) -> i64
      llvm.store %408, %399 : i64, !llvm.ptr
      cf.br ^bb78
    ^bb80:
    %411 = arith.constant 0 : i32
    %412 = arith.constant 0 : i32
    %413 = arith.constant 0 : i32
    %414 = arith.constant 0 : i32
    %415 = arith.constant 0 : i32
    %416 = llvm.mlir.constant(1 : i64) : i64
    %417 = llvm.alloca %416 x !llvm.array<5 x i64> : (i64) -> !llvm.ptr
    %418 = llvm.mlir.zero : !llvm.array<5 x i64>
    llvm.store %418, %417 : !llvm.array<5 x i64>, !llvm.ptr
    %419 = arith.extsi %411 : i32 to i64
    %420 = arith.extsi %412 : i32 to i64
    %421 = arith.extsi %413 : i32 to i64
    %422 = arith.extsi %414 : i32 to i64
    %423 = arith.extsi %415 : i32 to i64
    %424 = llvm.mlir.constant(0 : i64) : i64
    %425 = llvm.getelementptr %417[0, %424] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<5 x i64>
    llvm.store %419, %425 : i64, !llvm.ptr
    %426 = llvm.mlir.constant(1 : i64) : i64
    %427 = llvm.getelementptr %417[0, %426] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<5 x i64>
    llvm.store %420, %427 : i64, !llvm.ptr
    %428 = llvm.mlir.constant(2 : i64) : i64
    %429 = llvm.getelementptr %417[0, %428] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<5 x i64>
    llvm.store %421, %429 : i64, !llvm.ptr
    %430 = llvm.mlir.constant(3 : i64) : i64
    %431 = llvm.getelementptr %417[0, %430] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<5 x i64>
    llvm.store %422, %431 : i64, !llvm.ptr
    %432 = llvm.mlir.constant(4 : i64) : i64
    %433 = llvm.getelementptr %417[0, %432] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<5 x i64>
    llvm.store %423, %433 : i64, !llvm.ptr
    %434 = arith.constant 1 : i32
    %436 = arith.extsi %434 : i32 to i64
    %435 = arith.remsi %436, %arg0 : i64
    %437 = arith.constant 0 : i32
    %438 = arith.extsi %437 : i32 to i64
    %439 = llvm.getelementptr %417[0, %438] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<5 x i64>
    llvm.store %435, %439 : i64, !llvm.ptr
    %440 = arith.constant 1 : i32
    %441 = arith.extsi %440 : i32 to i64
    %442 = llvm.mlir.constant(1 : i64) : i64
    %443 = llvm.alloca %442 x i64 : (i64) -> !llvm.ptr
    llvm.store %441, %443 : i64, !llvm.ptr
    %444 = arith.constant 1 : i32
    %445 = arith.extsi %444 : i32 to i64
    %446 = llvm.mlir.constant(1 : i64) : i64
    %447 = llvm.alloca %446 x i64 : (i64) -> !llvm.ptr
    llvm.store %445, %447 : i64, !llvm.ptr
    cf.br ^bb81
    ^bb81:
    %448 = llvm.load %447 : !llvm.ptr -> i64
    %449 = arith.constant 5 : i32
    %451 = arith.extsi %449 : i32 to i64
    %450 = arith.cmpi slt, %448, %451 : i64
    cf.cond_br %450, ^bb82, ^bb83
    ^bb82:
      %453 = llvm.load %443 : !llvm.ptr -> i64
      %454 = llvm.load %399 : !llvm.ptr -> i64
      %452 = func.call @mulmod971(%453, %454, %arg0) : (i64, i64, i64) -> i64
      llvm.store %452, %443 : i64, !llvm.ptr
      %455 = llvm.load %443 : !llvm.ptr -> i64
      %456 = llvm.load %447 : !llvm.ptr -> i64
      %457 = llvm.getelementptr %417[0, %456] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<5 x i64>
      llvm.store %455, %457 : i64, !llvm.ptr
      %458 = llvm.load %447 : !llvm.ptr -> i64
      %459 = arith.constant 1 : i32
      %461 = arith.extsi %459 : i32 to i64
      %460 = arith.addi %458, %461 : i64
      llvm.store %460, %447 : i64, !llvm.ptr
      cf.br ^bb81
    ^bb83:
    %463 = arith.constant 0 : i32
    %464 = arith.constant 0 : i32
    %465 = arith.constant 0 : i32
    %466 = arith.constant 0 : i32
    %467 = arith.constant 0 : i32
    %468 = llvm.mlir.constant(1 : i64) : i64
    %469 = llvm.alloca %468 x !llvm.array<5 x i64> : (i64) -> !llvm.ptr
    %470 = llvm.mlir.zero : !llvm.array<5 x i64>
    llvm.store %470, %469 : !llvm.array<5 x i64>, !llvm.ptr
    %471 = arith.extsi %463 : i32 to i64
    %472 = arith.extsi %464 : i32 to i64
    %473 = arith.extsi %465 : i32 to i64
    %474 = arith.extsi %466 : i32 to i64
    %475 = arith.extsi %467 : i32 to i64
    %476 = llvm.mlir.constant(0 : i64) : i64
    %477 = llvm.getelementptr %469[0, %476] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<5 x i64>
    llvm.store %471, %477 : i64, !llvm.ptr
    %478 = llvm.mlir.constant(1 : i64) : i64
    %479 = llvm.getelementptr %469[0, %478] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<5 x i64>
    llvm.store %472, %479 : i64, !llvm.ptr
    %480 = llvm.mlir.constant(2 : i64) : i64
    %481 = llvm.getelementptr %469[0, %480] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<5 x i64>
    llvm.store %473, %481 : i64, !llvm.ptr
    %482 = llvm.mlir.constant(3 : i64) : i64
    %483 = llvm.getelementptr %469[0, %482] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<5 x i64>
    llvm.store %474, %483 : i64, !llvm.ptr
    %484 = llvm.mlir.constant(4 : i64) : i64
    %485 = llvm.getelementptr %469[0, %484] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<5 x i64>
    llvm.store %475, %485 : i64, !llvm.ptr
    %486 = arith.constant 0 : i32
    %487 = arith.extsi %486 : i32 to i64
    llvm.store %487, %447 : i64, !llvm.ptr
    cf.br ^bb84
    ^bb84:
    %488 = llvm.load %447 : !llvm.ptr -> i64
    %489 = arith.constant 5 : i32
    %491 = arith.extsi %489 : i32 to i64
    %490 = arith.cmpi slt, %488, %491 : i64
    cf.cond_br %490, ^bb85, ^bb86
    ^bb85:
      %493 = llvm.load %447 : !llvm.ptr -> i64
      %494 = llvm.getelementptr %417[0, %493] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<5 x i64>
      %492 = llvm.load %494 : !llvm.ptr -> i64
      %495 = arith.constant 1 : i32
      %497 = arith.extsi %495 : i32 to i64
      %496 = arith.addi %497, %492 : i64
      %498 = arith.remsi %496, %arg0 : i64
      %499 = func.call @powmod(%498, %390, %arg0) : (i64, i64, i64) -> i64
      %500 = func.call @mulmod971(%492, %499, %arg0) : (i64, i64, i64) -> i64
      %501 = llvm.load %447 : !llvm.ptr -> i64
      %502 = llvm.getelementptr %469[0, %501] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<5 x i64>
      llvm.store %500, %502 : i64, !llvm.ptr
      %503 = llvm.load %447 : !llvm.ptr -> i64
      %504 = arith.constant 1 : i32
      %506 = arith.extsi %504 : i32 to i64
      %505 = arith.addi %503, %506 : i64
      llvm.store %505, %447 : i64, !llvm.ptr
      cf.br ^bb84
    ^bb86:
    %508 = arith.constant 0 : i32
    %509 = arith.constant 0 : i32
    %510 = arith.constant 0 : i32
    %511 = arith.constant 0 : i32
    %512 = arith.constant 0 : i32
    %513 = llvm.mlir.constant(1 : i64) : i64
    %514 = llvm.alloca %513 x !llvm.array<5 x i64> : (i64) -> !llvm.ptr
    %515 = llvm.mlir.zero : !llvm.array<5 x i64>
    llvm.store %515, %514 : !llvm.array<5 x i64>, !llvm.ptr
    %516 = arith.extsi %508 : i32 to i64
    %517 = arith.extsi %509 : i32 to i64
    %518 = arith.extsi %510 : i32 to i64
    %519 = arith.extsi %511 : i32 to i64
    %520 = arith.extsi %512 : i32 to i64
    %521 = llvm.mlir.constant(0 : i64) : i64
    %522 = llvm.getelementptr %514[0, %521] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<5 x i64>
    llvm.store %516, %522 : i64, !llvm.ptr
    %523 = llvm.mlir.constant(1 : i64) : i64
    %524 = llvm.getelementptr %514[0, %523] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<5 x i64>
    llvm.store %517, %524 : i64, !llvm.ptr
    %525 = llvm.mlir.constant(2 : i64) : i64
    %526 = llvm.getelementptr %514[0, %525] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<5 x i64>
    llvm.store %518, %526 : i64, !llvm.ptr
    %527 = llvm.mlir.constant(3 : i64) : i64
    %528 = llvm.getelementptr %514[0, %527] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<5 x i64>
    llvm.store %519, %528 : i64, !llvm.ptr
    %529 = llvm.mlir.constant(4 : i64) : i64
    %530 = llvm.getelementptr %514[0, %529] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<5 x i64>
    llvm.store %520, %530 : i64, !llvm.ptr
    %532 = arith.constant 0 : i32
    %533 = arith.constant 0 : i32
    %534 = arith.constant 0 : i32
    %535 = arith.constant 0 : i32
    %536 = arith.constant 0 : i32
    %537 = llvm.mlir.constant(1 : i64) : i64
    %538 = llvm.alloca %537 x !llvm.array<5 x i64> : (i64) -> !llvm.ptr
    %539 = llvm.mlir.zero : !llvm.array<5 x i64>
    llvm.store %539, %538 : !llvm.array<5 x i64>, !llvm.ptr
    %540 = arith.extsi %532 : i32 to i64
    %541 = arith.extsi %533 : i32 to i64
    %542 = arith.extsi %534 : i32 to i64
    %543 = arith.extsi %535 : i32 to i64
    %544 = arith.extsi %536 : i32 to i64
    %545 = llvm.mlir.constant(0 : i64) : i64
    %546 = llvm.getelementptr %538[0, %545] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<5 x i64>
    llvm.store %540, %546 : i64, !llvm.ptr
    %547 = llvm.mlir.constant(1 : i64) : i64
    %548 = llvm.getelementptr %538[0, %547] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<5 x i64>
    llvm.store %541, %548 : i64, !llvm.ptr
    %549 = llvm.mlir.constant(2 : i64) : i64
    %550 = llvm.getelementptr %538[0, %549] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<5 x i64>
    llvm.store %542, %550 : i64, !llvm.ptr
    %551 = llvm.mlir.constant(3 : i64) : i64
    %552 = llvm.getelementptr %538[0, %551] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<5 x i64>
    llvm.store %543, %552 : i64, !llvm.ptr
    %553 = llvm.mlir.constant(4 : i64) : i64
    %554 = llvm.getelementptr %538[0, %553] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<5 x i64>
    llvm.store %544, %554 : i64, !llvm.ptr
    %556 = arith.constant 0 : i32
    %557 = arith.constant 0 : i32
    %558 = arith.constant 0 : i32
    %559 = arith.constant 0 : i32
    %560 = arith.constant 0 : i32
    %561 = arith.constant 0 : i32
    %562 = arith.constant 0 : i32
    %563 = arith.constant 0 : i32
    %564 = llvm.mlir.constant(1 : i64) : i64
    %565 = llvm.alloca %564 x !llvm.array<8 x i64> : (i64) -> !llvm.ptr
    %566 = llvm.mlir.zero : !llvm.array<8 x i64>
    llvm.store %566, %565 : !llvm.array<8 x i64>, !llvm.ptr
    %567 = arith.extsi %556 : i32 to i64
    %568 = arith.extsi %557 : i32 to i64
    %569 = arith.extsi %558 : i32 to i64
    %570 = arith.extsi %559 : i32 to i64
    %571 = arith.extsi %560 : i32 to i64
    %572 = arith.extsi %561 : i32 to i64
    %573 = arith.extsi %562 : i32 to i64
    %574 = arith.extsi %563 : i32 to i64
    %575 = llvm.mlir.constant(0 : i64) : i64
    %576 = llvm.getelementptr %565[0, %575] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<8 x i64>
    llvm.store %567, %576 : i64, !llvm.ptr
    %577 = llvm.mlir.constant(1 : i64) : i64
    %578 = llvm.getelementptr %565[0, %577] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<8 x i64>
    llvm.store %568, %578 : i64, !llvm.ptr
    %579 = llvm.mlir.constant(2 : i64) : i64
    %580 = llvm.getelementptr %565[0, %579] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<8 x i64>
    llvm.store %569, %580 : i64, !llvm.ptr
    %581 = llvm.mlir.constant(3 : i64) : i64
    %582 = llvm.getelementptr %565[0, %581] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<8 x i64>
    llvm.store %570, %582 : i64, !llvm.ptr
    %583 = llvm.mlir.constant(4 : i64) : i64
    %584 = llvm.getelementptr %565[0, %583] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<8 x i64>
    llvm.store %571, %584 : i64, !llvm.ptr
    %585 = llvm.mlir.constant(5 : i64) : i64
    %586 = llvm.getelementptr %565[0, %585] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<8 x i64>
    llvm.store %572, %586 : i64, !llvm.ptr
    %587 = llvm.mlir.constant(6 : i64) : i64
    %588 = llvm.getelementptr %565[0, %587] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<8 x i64>
    llvm.store %573, %588 : i64, !llvm.ptr
    %589 = llvm.mlir.constant(7 : i64) : i64
    %590 = llvm.getelementptr %565[0, %589] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<8 x i64>
    llvm.store %574, %590 : i64, !llvm.ptr
    %591 = arith.constant 0 : i32
    %592 = arith.extsi %591 : i32 to i64
    %593 = llvm.mlir.constant(1 : i64) : i64
    %594 = llvm.alloca %593 x i64 : (i64) -> !llvm.ptr
    llvm.store %592, %594 : i64, !llvm.ptr
    cf.br ^bb87
    ^bb87:
    %595 = llvm.load %594 : !llvm.ptr -> i64
    %596 = arith.constant 5 : i32
    %598 = arith.extsi %596 : i32 to i64
    %597 = arith.cmpi slt, %595, %598 : i64
    cf.cond_br %597, ^bb88, ^bb89
    ^bb88:
      %600 = llvm.load %594 : !llvm.ptr -> i64
      %601 = llvm.getelementptr %514[0, %600] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<5 x i64>
      %599 = llvm.load %601 : !llvm.ptr -> i64
      %602 = arith.constant 0 : i32
      %604 = arith.extsi %602 : i32 to i64
      %603 = arith.cmpi ne, %599, %604 : i64
      cf.cond_br %603, ^bb90, ^bb91
      ^bb90:
        %605 = llvm.load %594 : !llvm.ptr -> i64
        %606 = arith.constant 1 : i32
        %608 = arith.extsi %606 : i32 to i64
        %607 = arith.addi %605, %608 : i64
        llvm.store %607, %594 : i64, !llvm.ptr
        cf.br ^bb87
      ^bb91:
        cf.br ^bb92
      ^bb92:
      %609 = arith.constant 0 : i32
      %610 = arith.extsi %609 : i32 to i64
      %611 = llvm.mlir.constant(1 : i64) : i64
      %612 = llvm.alloca %611 x i64 : (i64) -> !llvm.ptr
      llvm.store %610, %612 : i64, !llvm.ptr
      %613 = llvm.load %594 : !llvm.ptr -> i64
      %614 = llvm.mlir.constant(1 : i64) : i64
      %615 = llvm.alloca %614 x i64 : (i64) -> !llvm.ptr
      llvm.store %613, %615 : i64, !llvm.ptr
      cf.br ^bb93
      ^bb93:
      %616 = arith.constant 1 : i1
      cf.cond_br %616, ^bb94, ^bb95
      ^bb94:
        %618 = llvm.load %615 : !llvm.ptr -> i64
        %619 = llvm.getelementptr %514[0, %618] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<5 x i64>
        %617 = llvm.load %619 : !llvm.ptr -> i64
        %620 = arith.constant 0 : i32
        %622 = arith.extsi %620 : i32 to i64
        %621 = arith.cmpi eq, %617, %622 : i64
        cf.cond_br %621, ^bb96, ^bb97
        ^bb96:
          %623 = arith.constant 1 : i32
          %624 = llvm.load %615 : !llvm.ptr -> i64
          %625 = arith.extsi %623 : i32 to i64
          %626 = llvm.getelementptr %514[0, %624] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<5 x i64>
          llvm.store %625, %626 : i64, !llvm.ptr
          %627 = llvm.load %615 : !llvm.ptr -> i64
          %628 = llvm.load %612 : !llvm.ptr -> i64
          %629 = llvm.getelementptr %565[0, %628] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<8 x i64>
          llvm.store %627, %629 : i64, !llvm.ptr
          %630 = llvm.load %612 : !llvm.ptr -> i64
          %631 = arith.constant 1 : i32
          %633 = arith.extsi %631 : i32 to i64
          %632 = arith.addi %630, %633 : i64
          llvm.store %632, %612 : i64, !llvm.ptr
          %635 = llvm.load %615 : !llvm.ptr -> i64
          %636 = llvm.getelementptr %469[0, %635] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<5 x i64>
          %634 = llvm.load %636 : !llvm.ptr -> i64
          %637 = arith.constant 1 : i32
          %639 = arith.constant 0 : i32
          %638 = arith.subi %639, %637 : i32
          %640 = arith.extsi %638 : i32 to i64
          %641 = llvm.mlir.constant(1 : i64) : i64
          %642 = llvm.alloca %641 x i64 : (i64) -> !llvm.ptr
          llvm.store %640, %642 : i64, !llvm.ptr
          %643 = arith.constant 0 : i32
          %644 = arith.extsi %643 : i32 to i64
          %645 = llvm.mlir.constant(1 : i64) : i64
          %646 = llvm.alloca %645 x i64 : (i64) -> !llvm.ptr
          llvm.store %644, %646 : i64, !llvm.ptr
          cf.br ^bb99
          ^bb99:
          %647 = llvm.load %646 : !llvm.ptr -> i64
          %648 = arith.constant 5 : i32
          %650 = arith.extsi %648 : i32 to i64
          %649 = arith.cmpi slt, %647, %650 : i64
          cf.cond_br %649, ^bb100, ^bb101
          ^bb100:
            %652 = llvm.load %646 : !llvm.ptr -> i64
            %653 = llvm.getelementptr %417[0, %652] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<5 x i64>
            %651 = llvm.load %653 : !llvm.ptr -> i64
            %654 = arith.cmpi eq, %651, %634 : i64
            cf.cond_br %654, ^bb102, ^bb103
            ^bb102:
              %655 = llvm.load %646 : !llvm.ptr -> i64
              llvm.store %655, %642 : i64, !llvm.ptr
              cf.br ^bb101
            ^bb103:
              cf.br ^bb104
            ^bb104:
            %656 = llvm.load %646 : !llvm.ptr -> i64
            %657 = arith.constant 1 : i32
            %659 = arith.extsi %657 : i32 to i64
            %658 = arith.addi %656, %659 : i64
            llvm.store %658, %646 : i64, !llvm.ptr
            cf.br ^bb99
          ^bb101:
          %660 = llvm.load %642 : !llvm.ptr -> i64
          %661 = arith.constant 0 : i32
          %663 = arith.extsi %661 : i32 to i64
          %662 = arith.cmpi slt, %660, %663 : i64
          cf.cond_br %662, ^bb105, ^bb106
          ^bb105:
            %664 = arith.constant 0 : i32
            %665 = arith.extsi %664 : i32 to i64
            %666 = llvm.mlir.constant(1 : i64) : i64
            %667 = llvm.alloca %666 x i64 : (i64) -> !llvm.ptr
            llvm.store %665, %667 : i64, !llvm.ptr
            cf.br ^bb108
            ^bb108:
            %668 = llvm.load %667 : !llvm.ptr -> i64
            %669 = llvm.load %612 : !llvm.ptr -> i64
            %670 = arith.cmpi slt, %668, %669 : i64
            cf.cond_br %670, ^bb109, ^bb110
            ^bb109:
              %671 = arith.constant 2 : i32
              %673 = llvm.load %667 : !llvm.ptr -> i64
              %674 = llvm.getelementptr %565[0, %673] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<8 x i64>
              %672 = llvm.load %674 : !llvm.ptr -> i64
              %675 = arith.extsi %671 : i32 to i64
              %676 = llvm.getelementptr %514[0, %672] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<5 x i64>
              llvm.store %675, %676 : i64, !llvm.ptr
              %677 = llvm.load %667 : !llvm.ptr -> i64
              %678 = arith.constant 1 : i32
              %680 = arith.extsi %678 : i32 to i64
              %679 = arith.addi %677, %680 : i64
              llvm.store %679, %667 : i64, !llvm.ptr
              cf.br ^bb108
            ^bb110:
            cf.br ^bb95
          ^bb106:
            cf.br ^bb107
          ^bb107:
          %681 = llvm.load %642 : !llvm.ptr -> i64
          llvm.store %681, %615 : i64, !llvm.ptr
          cf.br ^bb98
        ^bb97:
          %683 = llvm.load %615 : !llvm.ptr -> i64
          %684 = llvm.getelementptr %514[0, %683] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<5 x i64>
          %682 = llvm.load %684 : !llvm.ptr -> i64
          %685 = arith.constant 1 : i32
          %687 = arith.extsi %685 : i32 to i64
          %686 = arith.cmpi eq, %682, %687 : i64
          cf.cond_br %686, ^bb111, ^bb112
          ^bb111:
            %688 = arith.constant 0 : i32
            %689 = arith.extsi %688 : i32 to i64
            %690 = llvm.mlir.constant(1 : i64) : i64
            %691 = llvm.alloca %690 x i64 : (i64) -> !llvm.ptr
            llvm.store %689, %691 : i64, !llvm.ptr
            %692 = arith.constant 0 : i32
            %693 = arith.extsi %692 : i32 to i64
            %694 = llvm.mlir.constant(1 : i64) : i64
            %695 = llvm.alloca %694 x i64 : (i64) -> !llvm.ptr
            llvm.store %693, %695 : i64, !llvm.ptr
            cf.br ^bb114
            ^bb114:
            %696 = llvm.load %695 : !llvm.ptr -> i64
            %697 = llvm.load %612 : !llvm.ptr -> i64
            %698 = arith.cmpi slt, %696, %697 : i64
            cf.cond_br %698, ^bb115, ^bb116
            ^bb115:
              %700 = llvm.load %695 : !llvm.ptr -> i64
              %701 = llvm.getelementptr %565[0, %700] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<8 x i64>
              %699 = llvm.load %701 : !llvm.ptr -> i64
              %702 = llvm.load %615 : !llvm.ptr -> i64
              %703 = arith.cmpi eq, %699, %702 : i64
              cf.cond_br %703, ^bb117, ^bb118
              ^bb117:
                %704 = llvm.load %695 : !llvm.ptr -> i64
                llvm.store %704, %691 : i64, !llvm.ptr
                cf.br ^bb116
              ^bb118:
                cf.br ^bb119
              ^bb119:
              %705 = llvm.load %695 : !llvm.ptr -> i64
              %706 = arith.constant 1 : i32
              %708 = arith.extsi %706 : i32 to i64
              %707 = arith.addi %705, %708 : i64
              llvm.store %707, %695 : i64, !llvm.ptr
              cf.br ^bb114
            ^bb116:
            %709 = llvm.load %691 : !llvm.ptr -> i64
            llvm.store %709, %695 : i64, !llvm.ptr
            cf.br ^bb120
            ^bb120:
            %710 = llvm.load %695 : !llvm.ptr -> i64
            %711 = llvm.load %612 : !llvm.ptr -> i64
            %712 = arith.cmpi slt, %710, %711 : i64
            cf.cond_br %712, ^bb121, ^bb122
            ^bb121:
              %713 = arith.constant 1 : i32
              %715 = llvm.load %695 : !llvm.ptr -> i64
              %716 = llvm.getelementptr %565[0, %715] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<8 x i64>
              %714 = llvm.load %716 : !llvm.ptr -> i64
              %717 = arith.extsi %713 : i32 to i64
              %718 = llvm.getelementptr %538[0, %714] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<5 x i64>
              llvm.store %717, %718 : i64, !llvm.ptr
              %719 = llvm.load %695 : !llvm.ptr -> i64
              %720 = arith.constant 1 : i32
              %722 = arith.extsi %720 : i32 to i64
              %721 = arith.addi %719, %722 : i64
              llvm.store %721, %695 : i64, !llvm.ptr
              cf.br ^bb120
            ^bb122:
            %723 = arith.constant 0 : i32
            %724 = arith.extsi %723 : i32 to i64
            llvm.store %724, %695 : i64, !llvm.ptr
            cf.br ^bb123
            ^bb123:
            %725 = llvm.load %695 : !llvm.ptr -> i64
            %726 = llvm.load %612 : !llvm.ptr -> i64
            %727 = arith.cmpi slt, %725, %726 : i64
            cf.cond_br %727, ^bb124, ^bb125
            ^bb124:
              %728 = arith.constant 2 : i32
              %730 = llvm.load %695 : !llvm.ptr -> i64
              %731 = llvm.getelementptr %565[0, %730] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<8 x i64>
              %729 = llvm.load %731 : !llvm.ptr -> i64
              %732 = arith.extsi %728 : i32 to i64
              %733 = llvm.getelementptr %514[0, %729] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<5 x i64>
              llvm.store %732, %733 : i64, !llvm.ptr
              %734 = llvm.load %695 : !llvm.ptr -> i64
              %735 = arith.constant 1 : i32
              %737 = arith.extsi %735 : i32 to i64
              %736 = arith.addi %734, %737 : i64
              llvm.store %736, %695 : i64, !llvm.ptr
              cf.br ^bb123
            ^bb125:
            cf.br ^bb95
          ^bb112:
            %738 = arith.constant 0 : i32
            %739 = arith.extsi %738 : i32 to i64
            %740 = llvm.mlir.constant(1 : i64) : i64
            %741 = llvm.alloca %740 x i64 : (i64) -> !llvm.ptr
            llvm.store %739, %741 : i64, !llvm.ptr
            cf.br ^bb126
            ^bb126:
            %742 = llvm.load %741 : !llvm.ptr -> i64
            %743 = llvm.load %612 : !llvm.ptr -> i64
            %744 = arith.cmpi slt, %742, %743 : i64
            cf.cond_br %744, ^bb127, ^bb128
            ^bb127:
              %745 = arith.constant 2 : i32
              %747 = llvm.load %741 : !llvm.ptr -> i64
              %748 = llvm.getelementptr %565[0, %747] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<8 x i64>
              %746 = llvm.load %748 : !llvm.ptr -> i64
              %749 = arith.extsi %745 : i32 to i64
              %750 = llvm.getelementptr %514[0, %746] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<5 x i64>
              llvm.store %749, %750 : i64, !llvm.ptr
              %751 = llvm.load %741 : !llvm.ptr -> i64
              %752 = arith.constant 1 : i32
              %754 = arith.extsi %752 : i32 to i64
              %753 = arith.addi %751, %754 : i64
              llvm.store %753, %741 : i64, !llvm.ptr
              cf.br ^bb126
            ^bb128:
            cf.br ^bb95
        ^bb98:
        cf.br ^bb93
      ^bb95:
      %755 = llvm.load %594 : !llvm.ptr -> i64
      %756 = arith.constant 1 : i32
      %758 = arith.extsi %756 : i32 to i64
      %757 = arith.addi %755, %758 : i64
      llvm.store %757, %594 : i64, !llvm.ptr
      cf.br ^bb87
    ^bb89:
    %759 = arith.constant 0 : i32
    %760 = arith.extsi %759 : i32 to i64
    %761 = llvm.mlir.constant(1 : i64) : i64
    %762 = llvm.alloca %761 x i64 : (i64) -> !llvm.ptr
    llvm.store %760, %762 : i64, !llvm.ptr
    %763 = arith.constant 0 : i32
    %764 = arith.extsi %763 : i32 to i64
    %765 = llvm.mlir.constant(1 : i64) : i64
    %766 = llvm.alloca %765 x i64 : (i64) -> !llvm.ptr
    llvm.store %764, %766 : i64, !llvm.ptr
    cf.br ^bb129
    ^bb129:
    %767 = llvm.load %766 : !llvm.ptr -> i64
    %768 = arith.constant 5 : i32
    %770 = arith.extsi %768 : i32 to i64
    %769 = arith.cmpi slt, %767, %770 : i64
    cf.cond_br %769, ^bb130, ^bb131
    ^bb130:
      %771 = llvm.load %762 : !llvm.ptr -> i64
      %773 = llvm.load %766 : !llvm.ptr -> i64
      %774 = llvm.getelementptr %538[0, %773] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<5 x i64>
      %772 = llvm.load %774 : !llvm.ptr -> i64
      %775 = arith.addi %771, %772 : i64
      llvm.store %775, %762 : i64, !llvm.ptr
      %776 = llvm.load %766 : !llvm.ptr -> i64
      %777 = arith.constant 1 : i32
      %779 = arith.extsi %777 : i32 to i64
      %778 = arith.addi %776, %779 : i64
      llvm.store %778, %766 : i64, !llvm.ptr
      cf.br ^bb129
    ^bb131:
    %780 = llvm.load %762 : !llvm.ptr -> i64
    func.return %780 : i64
  }
  func.func @main() -> i32 {
    %781 = arith.constant 100000000 : i32
    %782 = arith.extsi %781 : i32 to i64
    %783 = func.call @sieve_primes(%782) : (i64) -> i64
    %784 = arith.constant 0 : i32
    %785 = arith.extsi %784 : i32 to i128
    %786 = llvm.mlir.constant(1 : i64) : i64
    %787 = llvm.alloca %786 x i128 : (i64) -> !llvm.ptr
    llvm.store %785, %787 : i128, !llvm.ptr
    %788 = arith.constant 0 : i32
    %789 = arith.extsi %788 : i32 to i64
    %790 = llvm.mlir.constant(1 : i64) : i64
    %791 = llvm.alloca %790 x i64 : (i64) -> !llvm.ptr
    llvm.store %789, %791 : i64, !llvm.ptr
    cf.br ^bb132
    ^bb132:
    %792 = llvm.load %791 : !llvm.ptr -> i64
    %793 = arith.cmpi slt, %792, %783 : i64
    cf.cond_br %793, ^bb133, ^bb134
    ^bb133:
      %795 = llvm.mlir.addressof @g_primes : !llvm.ptr
      %796 = llvm.load %795 : !llvm.ptr -> !llvm.ptr
      %797 = llvm.load %791 : !llvm.ptr -> i64
      %798 = llvm.getelementptr %796[%797] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %794 = llvm.load %798 : !llvm.ptr -> i64
      %799 = arith.constant 5 : i32
      %801 = arith.extsi %799 : i32 to i64
      %800 = arith.cmpi slt, %794, %801 : i64
      cf.cond_br %800, ^bb135, ^bb136
      ^bb135:
        %802 = arith.constant 2 : i32
        %804 = arith.extsi %802 : i32 to i64
        %803 = arith.cmpi eq, %794, %804 : i64
        %805 = scf.if %803 -> (i1) {
          %806 = arith.constant true
          scf.yield %806 : i1
        } else {
          %807 = arith.constant 3 : i32
          %809 = arith.extsi %807 : i32 to i64
          %808 = arith.cmpi eq, %794, %809 : i64
          scf.yield %808 : i1
        }
        cf.cond_br %805, ^bb138, ^bb139
        ^bb138:
          %810 = llvm.load %791 : !llvm.ptr -> i64
          %811 = arith.constant 1 : i32
          %813 = arith.extsi %811 : i32 to i64
          %812 = arith.addi %810, %813 : i64
          llvm.store %812, %791 : i64, !llvm.ptr
          cf.br ^bb132
        ^bb139:
          cf.br ^bb140
        ^bb140:
        cf.br ^bb137
      ^bb136:
        cf.br ^bb137
      ^bb137:
      %814 = arith.constant 5 : i32
      %816 = arith.extsi %814 : i32 to i64
      %815 = arith.remsi %794, %816 : i64
      %817 = arith.constant 1 : i32
      %819 = arith.extsi %817 : i32 to i64
      %818 = arith.cmpi ne, %815, %819 : i64
      cf.cond_br %818, ^bb141, ^bb142
      ^bb141:
        %820 = llvm.load %791 : !llvm.ptr -> i64
        %821 = arith.constant 1 : i32
        %823 = arith.extsi %821 : i32 to i64
        %822 = arith.addi %820, %823 : i64
        llvm.store %822, %791 : i64, !llvm.ptr
        cf.br ^bb132
      ^bb142:
        cf.br ^bb143
      ^bb143:
      %824 = arith.constant 1 : i32
      %826 = arith.extsi %824 : i32 to i64
      %825 = arith.subi %794, %826 : i64
      %827 = arith.constant 5 : i32
      %829 = arith.extsi %827 : i32 to i64
      %828 = arith.divsi %825, %829 : i64
      %830 = func.call @count_periodic_in_mu5(%794) : (i64) -> i64
      %831 = arith.constant 1 : i32
      %832 = arith.muli %828, %830 : i64
      %834 = arith.extsi %831 : i32 to i64
      %833 = arith.addi %834, %832 : i64
      %835 = llvm.load %787 : !llvm.ptr -> i128
      %836 = arith.extsi %833 : i64 to i128
      %838 = arith.trunci %835 : i128 to i64
      %839 = arith.trunci %836 : i128 to i64
      %837 = arith.addi %838, %839 : i64
      %840 = arith.extsi %837 : i64 to i128
      llvm.store %840, %787 : i128, !llvm.ptr
      %841 = llvm.load %791 : !llvm.ptr -> i64
      %842 = arith.constant 1 : i32
      %844 = arith.extsi %842 : i32 to i64
      %843 = arith.addi %841, %844 : i64
      llvm.store %843, %791 : i64, !llvm.ptr
      cf.br ^bb132
    ^bb134:
    %846 = llvm.mlir.addressof @g_primes : !llvm.ptr
    %847 = llvm.load %846 : !llvm.ptr -> !llvm.ptr
    func.call @free(%847) : (!llvm.ptr) -> ()
    %848 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %849 = llvm.load %787 : !llvm.ptr -> i128
    %850 = arith.trunci %849 : i128 to i64
    %851 = llvm.call @printf(%848, %850) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    %852 = arith.constant 0 : i32
    func.return %852 : i32
  }
}