Problem 953

DFS over products of distinct odd primes with XOR constraint.

Answer176907658
Output176907658
StatusPASS
Native helperno
Runtime9470 ms
Peak memory41808 KB
Time complexityO(n^2) (estimated)
Space complexityO(1) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^2)O(n!)
Space complexityO(1)O(n^2)
ApproachFlow solutionBacktracking search
VerdictOptimal

Flow source

# Project Euler 953
# DFS over products of distinct odd primes with XOR constraint.

import euler.nt { isqrt }

extern {
    function calloc(n: i64, size: i64) -> ptr<void>
    function free(p: ptr<void>) -> void
    function malloc(n: i64) -> ptr<void>
    function memset(p: ptr<void>, c: i32, n: i64) -> ptr<void>
    function sqrt(x: f64) -> f64
}

const MOD: i64 = 1000000007

let mut INV6: i64 = 0

function my_mod_pow(base0: i64, exp0: i64, mod: i64) -> i64 {
    let mut result: i64 = 1
    let mut base: i64 = base0 % mod
    let mut exp: i64 = exp0
    while exp > 0 {
        if (exp & 1) == 1 {
            result = result * base % mod
        }
        base = base * base % mod
        exp = exp >> 1
    }
    return result
}

function isqrt_ll(n: i64) -> i64 {
    if n <= 0 { return 0 }
    let mut x: i64 = isqrt(n)
    while x * x > n { x = x - 1 }
    while (x + 1) * (x + 1) <= n { x = x + 1 }
    return x
}

function sum_sq(n0: i64) -> i64 {
    let n: i64 = n0 % MOD
    return n * (n + 1) % MOD * (2 * n + 1) % MOD * INV6 % MOD
}

function contribution(kernel: i64, bound: i64, multiplier: i64) -> i64 {
    let t: i64 = isqrt_ll(bound / kernel)
    return multiplier * (kernel % MOD) % MOD * sum_sq(t) % MOD
}

# Global state
let mut g_flags: ptr<i8> = null
let mut g_odd_primes: ptr<i32> = null
let mut g_odd_prime_count: i64 = 0
let mut g_limit: i64 = 0

# Stack-based DFS. State: prod, next_idx, xor_val, last, odd_count
# We use parallel arrays for the stack.
let mut st_prod: ptr<i64> = null
let mut st_next_idx: ptr<i32> = null
let mut st_xor_val: ptr<i32> = null
let mut st_last: ptr<i32> = null
let mut st_odd_count: ptr<i32> = null

function branch_sum(bound: i64, target: i64, multiplier: i64) -> i64 {
    if bound <= 0 { return 0 }

    let mut total: i64 = 0
    if target == 0 {
        total = contribution(1, bound, multiplier)
    }

    let plen: i64 = g_odd_prime_count

    let mut stack_cap: i64 = 1 << 21
    st_prod = malloc(stack_cap * 8)
    st_next_idx = malloc(stack_cap * 4)
    st_xor_val = malloc(stack_cap * 4)
    st_last = malloc(stack_cap * 4)
    st_odd_count = malloc(stack_cap * 4)
    let mut sp: i64 = 0

    let mut idx: i64 = 0
    while idx < plen {
        let p: i64 = g_odd_primes[idx] as i64
        if p > bound / (p + 2) { break }
        st_prod[sp] = p
        st_next_idx[sp] = (idx + 1) as i32
        st_xor_val[sp] = p as i32
        st_last[sp] = p as i32
        st_odd_count[sp] = 1
        sp = sp + 1
        idx = idx + 1
    }

    while sp > 0 {
        sp = sp - 1
        let next_idx: i64 = st_next_idx[sp] as i64
        let prod: i64 = st_prod[sp]
        let xor_val: i64 = st_xor_val[sp] as i64
        let last: i64 = st_last[sp] as i64
        let odd_count: i64 = st_odd_count[sp] as i64

        if odd_count != 0 {
            let cand: i64 = target ^ xor_val
            if cand > last && cand <= g_limit && g_flags[cand] != 0 {
                if prod <= bound / cand {
                    total = (total + contribution(prod * cand, bound, multiplier)) % MOD
                }
            }
        }

        let next_odd_count: i64 = odd_count ^ 1
        let mut j: i64 = next_idx
        while j < plen {
            let q: i64 = g_odd_primes[j] as i64
            if prod > bound / q { break }
            let new_prod: i64 = prod * q
            let first: i64 = q + 2
            if new_prod > bound / first { break }
            if next_odd_count == 0 {
                let temp: i64 = new_prod * first
                if temp > bound / (first + 2) { break }
            }
            st_prod[sp] = new_prod
            st_next_idx[sp] = (j + 1) as i32
            st_xor_val[sp] = (xor_val ^ q) as i32
            st_last[sp] = q as i32
            st_odd_count[sp] = next_odd_count as i32
            sp = sp + 1
            j = j + 1
        }
    }

    free(st_prod)
    free(st_next_idx)
    free(st_xor_val)
    free(st_last)
    free(st_odd_count)
    return total % MOD
}

function prime_sieve(limit: i64) -> void {
    let flags: ptr<i8> = malloc(limit + 1)
    memset(flags, 1, limit + 1)
    flags[0] = 0
    flags[1] = 0
    let mut p: i64 = 2
    while p * p <= limit {
        if flags[p] != 0 {
            let mut j: i64 = p * p
            while j <= limit {
                flags[j] = 0
                j = j + p
            }
        }
        p = p + 1
    }
    let mut count: i64 = 0
    let mut pp: i64 = 3
    while pp <= limit {
        if flags[pp] != 0 { count = count + 1 }
        pp = pp + 2
    }
    let odd_primes: ptr<i32> = malloc(count * 4)
    let mut ii: i64 = 0
    let mut pp2: i64 = 3
    while pp2 <= limit {
        if flags[pp2] != 0 {
            odd_primes[ii] = pp2 as i32
            ii = ii + 1
        }
        pp2 = pp2 + 2
    }
    g_flags = flags
    g_odd_primes = odd_primes
    g_odd_prime_count = count
}

function main() -> i32 {
    INV6 = my_mod_pow(6, MOD - 2, MOD)

    let n: i64 = 100000000000000
    let prime_limit: i64 = isqrt_ll(2 * n) + 10

    prime_sieve(prime_limit)
    g_limit = prime_limit

    let result: i64 = (branch_sum(n, 0, 1) + branch_sum(n / 2, 2, 2)) % MOD

    printf("%lld\n", result)
    free(g_flags)
    free(g_odd_primes)
    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 my_mod_pow_i64_i64_i64(int64_t base0, int64_t exp0, int64_t mod);
int64_t isqrt_ll_i64(int64_t n);
int64_t sum_sq_i64(int64_t n0);
int64_t contribution_i64_i64_i64(int64_t kernel, int64_t bound, int64_t multiplier);
int64_t branch_sum_i64_i64_i64(int64_t bound, int64_t target, int64_t multiplier);
void prime_sieve_i64(int64_t limit);
int32_t main(void);

static const int64_t MOD = 1000000007;

/* Module statics */
static int64_t INV6 = 0;
static int8_t* g_flags = NULL;
static int32_t* g_odd_primes = NULL;
static int64_t g_odd_prime_count = 0;
static int64_t g_limit = 0;
static int64_t* st_prod = NULL;
static int32_t* st_next_idx = NULL;
static int32_t* st_xor_val = NULL;
static int32_t* st_last = NULL;
static int32_t* st_odd_count = 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 my_mod_pow_i64_i64_i64(int64_t base0, int64_t exp0, int64_t mod) {
    int64_t result = 1;
    int64_t base = FLOW_CHECKED_MOD((base0), (mod));
    int64_t exp = exp0;
    while (exp > 0) {
        if ((exp & 1) == 1) {
            result = FLOW_CHECKED_MOD(((result * base)), (mod));
        }
        base = FLOW_CHECKED_MOD(((base * base)), (mod));
        exp = FLOW_CHECKED_SHR((exp), (1));
    }
    return result;
}

int64_t isqrt_ll_i64(int64_t n) {
    if (n <= 0) {
        return 0;
    }
    int64_t x = isqrt_i64(n);
    while ((x * x) > n) {
        x = (x - 1);
    }
    while (((x + 1) * (x + 1)) <= n) {
        x = (x + 1);
    }
    return x;
}

int64_t sum_sq_i64(int64_t n0) {
    int64_t n = FLOW_CHECKED_MOD((n0), (MOD));
    return FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD(((n * (n + 1))), (MOD)) * ((2 * n) + 1))), (MOD)) * INV6)), (MOD));
}

int64_t contribution_i64_i64_i64(int64_t kernel, int64_t bound, int64_t multiplier) {
    int64_t t = isqrt_ll_i64(FLOW_CHECKED_DIV((bound), (kernel)));
    return FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD(((multiplier * FLOW_CHECKED_MOD((kernel), (MOD)))), (MOD)) * sum_sq_i64(t))), (MOD));
}

int64_t branch_sum_i64_i64_i64(int64_t bound, int64_t target, int64_t multiplier) {
    if (bound <= 0) {
        return 0;
    }
    int64_t total = 0;
    if (target == 0) {
        total = contribution_i64_i64_i64(1, bound, multiplier);
    }
    int64_t plen = g_odd_prime_count;
    int64_t stack_cap = FLOW_CHECKED_SHL((1), (21));
    st_prod = malloc((stack_cap * 8));
    st_next_idx = malloc((stack_cap * 4));
    st_xor_val = malloc((stack_cap * 4));
    st_last = malloc((stack_cap * 4));
    st_odd_count = malloc((stack_cap * 4));
    int64_t sp = 0;
    int64_t idx = 0;
    while (idx < plen) {
        int64_t p = ((int64_t)(g_odd_primes[idx]));
        if (p > FLOW_CHECKED_DIV((bound), ((p + 2)))) {
            break;
        }
        st_prod[sp] = p;
        st_next_idx[sp] = ((int32_t)((idx + 1)));
        st_xor_val[sp] = ((int32_t)(p));
        st_last[sp] = ((int32_t)(p));
        st_odd_count[sp] = 1;
        sp = (sp + 1);
        idx = (idx + 1);
    }
    while (sp > 0) {
        sp = (sp - 1);
        int64_t next_idx = ((int64_t)(st_next_idx[sp]));
        int64_t prod = st_prod[sp];
        int64_t xor_val = ((int64_t)(st_xor_val[sp]));
        int64_t last = ((int64_t)(st_last[sp]));
        int64_t odd_count = ((int64_t)(st_odd_count[sp]));
        if (odd_count != 0) {
            int64_t cand = (target ^ xor_val);
            if (((cand > last && cand <= g_limit) && g_flags[cand] != 0)) {
                if (prod <= FLOW_CHECKED_DIV((bound), (cand))) {
                    total = FLOW_CHECKED_MOD(((total + contribution_i64_i64_i64((prod * cand), bound, multiplier))), (MOD));
                }
            }
        }
        int64_t next_odd_count = (odd_count ^ 1);
        int64_t j = next_idx;
        while (j < plen) {
            int64_t q = ((int64_t)(g_odd_primes[j]));
            if (prod > FLOW_CHECKED_DIV((bound), (q))) {
                break;
            }
            int64_t new_prod = (prod * q);
            int64_t first = (q + 2);
            if (new_prod > FLOW_CHECKED_DIV((bound), (first))) {
                break;
            }
            if (next_odd_count == 0) {
                int64_t temp = (new_prod * first);
                if (temp > FLOW_CHECKED_DIV((bound), ((first + 2)))) {
                    break;
                }
            }
            st_prod[sp] = new_prod;
            st_next_idx[sp] = ((int32_t)((j + 1)));
            st_xor_val[sp] = ((int32_t)((xor_val ^ q)));
            st_last[sp] = ((int32_t)(q));
            st_odd_count[sp] = ((int32_t)(next_odd_count));
            sp = (sp + 1);
            j = (j + 1);
        }
    }
    free(st_prod);
    free(st_next_idx);
    free(st_xor_val);
    free(st_last);
    free(st_odd_count);
    return FLOW_CHECKED_MOD((total), (MOD));
}

void prime_sieve_i64(int64_t limit) {
    int8_t* flags = (int8_t*)(malloc((limit + 1)));
    memset(flags, 1, (limit + 1));
    flags[0] = 0;
    flags[1] = 0;
    int64_t p = 2;
    while ((p * p) <= limit) {
        if (flags[p] != 0) {
            int64_t j = (p * p);
            while (j <= limit) {
                flags[j] = 0;
                j = (j + p);
            }
        }
        p = (p + 1);
    }
    int64_t count = 0;
    int64_t pp = 3;
    while (pp <= limit) {
        if (flags[pp] != 0) {
            count = (count + 1);
        }
        pp = (pp + 2);
    }
    int32_t* odd_primes = (int32_t*)(malloc((count * 4)));
    int64_t ii = 0;
    int64_t pp2 = 3;
    while (pp2 <= limit) {
        if (flags[pp2] != 0) {
            odd_primes[ii] = ((int32_t)(pp2));
            ii = (ii + 1);
        }
        pp2 = (pp2 + 2);
    }
    g_flags = flags;
    g_odd_primes = odd_primes;
    g_odd_prime_count = count;
}

int32_t main(void) {
    INV6 = my_mod_pow_i64_i64_i64(6, (MOD - 2), MOD);
    int64_t n = 100000000000000;
    int64_t prime_limit = (isqrt_ll_i64((2 * n)) + 10);
    prime_sieve_i64(prime_limit);
    g_limit = prime_limit;
    int64_t result = FLOW_CHECKED_MOD(((branch_sum_i64_i64_i64(n, 0, 1) + branch_sum_i64_i64_i64(FLOW_CHECKED_DIV((n), (2)), 2, 2))), (MOD));
    printf("%lld\n", result);
    free(g_flags);
    free(g_odd_primes);
    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 private @malloc(i64) -> !llvm.ptr
  func.func private @memset(!llvm.ptr, i32, i64) -> !llvm.ptr
  func.func private @sqrt(f64) -> f64
  // Constant: MOD
  llvm.mlir.global internal constant @MOD(1000000007 : i64) : i64
  // Module static: INV6
  llvm.mlir.global internal @INV6(0 : i64) : i64
  func.func @my_mod_pow(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %175 = arith.constant 1 : i32
    %176 = arith.extsi %175 : i32 to i64
    %177 = llvm.mlir.constant(1 : i64) : i64
    %178 = llvm.alloca %177 x i64 : (i64) -> !llvm.ptr
    llvm.store %176, %178 : i64, !llvm.ptr
    %179 = arith.remsi %arg0, %arg2 : i64
    %180 = llvm.mlir.constant(1 : i64) : i64
    %181 = llvm.alloca %180 x i64 : (i64) -> !llvm.ptr
    llvm.store %179, %181 : i64, !llvm.ptr
    %182 = llvm.mlir.constant(1 : i64) : i64
    %183 = llvm.alloca %182 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %183 : i64, !llvm.ptr
    cf.br ^bb42
    ^bb42:
    %184 = llvm.load %183 : !llvm.ptr -> i64
    %185 = arith.constant 0 : i32
    %187 = arith.extsi %185 : i32 to i64
    %186 = arith.cmpi sgt, %184, %187 : i64
    cf.cond_br %186, ^bb43, ^bb44
    ^bb43:
      %188 = llvm.load %183 : !llvm.ptr -> i64
      %189 = arith.constant 1 : i32
      %191 = arith.extsi %189 : i32 to i64
      %190 = arith.andi %188, %191 : i64
      %192 = arith.constant 1 : i32
      %194 = arith.extsi %192 : i32 to i64
      %193 = arith.cmpi eq, %190, %194 : i64
      cf.cond_br %193, ^bb45, ^bb46
      ^bb45:
        %195 = llvm.load %178 : !llvm.ptr -> i64
        %196 = llvm.load %181 : !llvm.ptr -> i64
        %197 = arith.muli %195, %196 : i64
        %198 = arith.remsi %197, %arg2 : i64
        llvm.store %198, %178 : i64, !llvm.ptr
        cf.br ^bb47
      ^bb46:
        cf.br ^bb47
      ^bb47:
      %199 = llvm.load %181 : !llvm.ptr -> i64
      %200 = llvm.load %181 : !llvm.ptr -> i64
      %201 = arith.muli %199, %200 : i64
      %202 = arith.remsi %201, %arg2 : i64
      llvm.store %202, %181 : i64, !llvm.ptr
      %203 = llvm.load %183 : !llvm.ptr -> i64
      %204 = arith.constant 1 : i32
      %206 = arith.extsi %204 : i32 to i64
      %205 = arith.shrsi %203, %206 : i64
      llvm.store %205, %183 : i64, !llvm.ptr
      cf.br ^bb42
    ^bb44:
    %207 = llvm.load %178 : !llvm.ptr -> i64
    func.return %207 : i64
  }
  func.func @isqrt_ll(%arg0: i64) -> i64 {
    %208 = arith.constant 0 : i32
    %210 = arith.extsi %208 : i32 to i64
    %209 = arith.cmpi sle, %arg0, %210 : i64
    cf.cond_br %209, ^bb48, ^bb49
    ^bb48:
      %211 = arith.constant 0 : i32
      %212 = arith.extsi %211 : i32 to i64
      func.return %212 : i64
    ^bb49:
      cf.br ^bb50
    ^bb50:
    %213 = func.call @isqrt(%arg0) : (i64) -> i64
    %214 = llvm.mlir.constant(1 : i64) : i64
    %215 = llvm.alloca %214 x i64 : (i64) -> !llvm.ptr
    llvm.store %213, %215 : i64, !llvm.ptr
    cf.br ^bb51
    ^bb51:
    %216 = llvm.load %215 : !llvm.ptr -> i64
    %217 = llvm.load %215 : !llvm.ptr -> i64
    %218 = arith.muli %216, %217 : i64
    %219 = arith.cmpi sgt, %218, %arg0 : i64
    cf.cond_br %219, ^bb52, ^bb53
    ^bb52:
      %220 = llvm.load %215 : !llvm.ptr -> i64
      %221 = arith.constant 1 : i32
      %223 = arith.extsi %221 : i32 to i64
      %222 = arith.subi %220, %223 : i64
      llvm.store %222, %215 : i64, !llvm.ptr
      cf.br ^bb51
    ^bb53:
    cf.br ^bb54
    ^bb54:
    %224 = llvm.load %215 : !llvm.ptr -> i64
    %225 = arith.constant 1 : i32
    %227 = arith.extsi %225 : i32 to i64
    %226 = arith.addi %224, %227 : i64
    %228 = llvm.load %215 : !llvm.ptr -> i64
    %229 = arith.constant 1 : i32
    %231 = arith.extsi %229 : i32 to i64
    %230 = arith.addi %228, %231 : i64
    %232 = arith.muli %226, %230 : i64
    %233 = arith.cmpi sle, %232, %arg0 : i64
    cf.cond_br %233, ^bb55, ^bb56
    ^bb55:
      %234 = llvm.load %215 : !llvm.ptr -> i64
      %235 = arith.constant 1 : i32
      %237 = arith.extsi %235 : i32 to i64
      %236 = arith.addi %234, %237 : i64
      llvm.store %236, %215 : i64, !llvm.ptr
      cf.br ^bb54
    ^bb56:
    %238 = llvm.load %215 : !llvm.ptr -> i64
    func.return %238 : i64
  }
  func.func @sum_sq(%arg0: i64) -> i64 {
    %239 = llvm.mlir.addressof @MOD : !llvm.ptr
    %240 = llvm.load %239 : !llvm.ptr -> i64
    %241 = arith.remsi %arg0, %240 : i64
    %242 = arith.constant 1 : i32
    %244 = arith.extsi %242 : i32 to i64
    %243 = arith.addi %241, %244 : i64
    %245 = arith.muli %241, %243 : i64
    %246 = llvm.mlir.addressof @MOD : !llvm.ptr
    %247 = llvm.load %246 : !llvm.ptr -> i64
    %248 = arith.remsi %245, %247 : i64
    %249 = arith.constant 2 : i32
    %251 = arith.extsi %249 : i32 to i64
    %250 = arith.muli %251, %241 : i64
    %252 = arith.constant 1 : i32
    %254 = arith.extsi %252 : i32 to i64
    %253 = arith.addi %250, %254 : i64
    %255 = arith.muli %248, %253 : i64
    %256 = llvm.mlir.addressof @MOD : !llvm.ptr
    %257 = llvm.load %256 : !llvm.ptr -> i64
    %258 = arith.remsi %255, %257 : i64
    %259 = llvm.mlir.addressof @INV6 : !llvm.ptr
    %260 = llvm.load %259 : !llvm.ptr -> i64
    %261 = arith.muli %258, %260 : i64
    %262 = llvm.mlir.addressof @MOD : !llvm.ptr
    %263 = llvm.load %262 : !llvm.ptr -> i64
    %264 = arith.remsi %261, %263 : i64
    func.return %264 : i64
  }
  func.func @contribution(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %266 = arith.divsi %arg1, %arg0 : i64
    %265 = func.call @isqrt_ll(%266) : (i64) -> i64
    %267 = llvm.mlir.addressof @MOD : !llvm.ptr
    %268 = llvm.load %267 : !llvm.ptr -> i64
    %269 = arith.remsi %arg0, %268 : i64
    %270 = arith.muli %arg2, %269 : i64
    %271 = llvm.mlir.addressof @MOD : !llvm.ptr
    %272 = llvm.load %271 : !llvm.ptr -> i64
    %273 = arith.remsi %270, %272 : i64
    %274 = func.call @sum_sq(%265) : (i64) -> i64
    %275 = arith.muli %273, %274 : i64
    %276 = llvm.mlir.addressof @MOD : !llvm.ptr
    %277 = llvm.load %276 : !llvm.ptr -> i64
    %278 = arith.remsi %275, %277 : i64
    func.return %278 : i64
  }
  // Module static: g_flags
  llvm.mlir.global internal @g_flags() {addr_space = 0 : i32} : !llvm.ptr {
    %279 = llvm.mlir.zero : !llvm.ptr
    llvm.return %279 : !llvm.ptr
  }
  // Module static: g_odd_primes
  llvm.mlir.global internal @g_odd_primes() {addr_space = 0 : i32} : !llvm.ptr {
    %280 = llvm.mlir.zero : !llvm.ptr
    llvm.return %280 : !llvm.ptr
  }
  // Module static: g_odd_prime_count
  llvm.mlir.global internal @g_odd_prime_count(0 : i64) : i64
  // Module static: g_limit
  llvm.mlir.global internal @g_limit(0 : i64) : i64
  // Module static: st_prod
  llvm.mlir.global internal @st_prod() {addr_space = 0 : i32} : !llvm.ptr {
    %281 = llvm.mlir.zero : !llvm.ptr
    llvm.return %281 : !llvm.ptr
  }
  // Module static: st_next_idx
  llvm.mlir.global internal @st_next_idx() {addr_space = 0 : i32} : !llvm.ptr {
    %282 = llvm.mlir.zero : !llvm.ptr
    llvm.return %282 : !llvm.ptr
  }
  // Module static: st_xor_val
  llvm.mlir.global internal @st_xor_val() {addr_space = 0 : i32} : !llvm.ptr {
    %283 = llvm.mlir.zero : !llvm.ptr
    llvm.return %283 : !llvm.ptr
  }
  // Module static: st_last
  llvm.mlir.global internal @st_last() {addr_space = 0 : i32} : !llvm.ptr {
    %284 = llvm.mlir.zero : !llvm.ptr
    llvm.return %284 : !llvm.ptr
  }
  // Module static: st_odd_count
  llvm.mlir.global internal @st_odd_count() {addr_space = 0 : i32} : !llvm.ptr {
    %285 = llvm.mlir.zero : !llvm.ptr
    llvm.return %285 : !llvm.ptr
  }
  func.func @branch_sum(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %286 = arith.constant 0 : i32
    %288 = arith.extsi %286 : i32 to i64
    %287 = arith.cmpi sle, %arg0, %288 : i64
    cf.cond_br %287, ^bb57, ^bb58
    ^bb57:
      %289 = arith.constant 0 : i32
      %290 = arith.extsi %289 : i32 to i64
      func.return %290 : i64
    ^bb58:
      cf.br ^bb59
    ^bb59:
    %291 = arith.constant 0 : i32
    %292 = arith.extsi %291 : i32 to i64
    %293 = llvm.mlir.constant(1 : i64) : i64
    %294 = llvm.alloca %293 x i64 : (i64) -> !llvm.ptr
    llvm.store %292, %294 : i64, !llvm.ptr
    %295 = arith.constant 0 : i32
    %297 = arith.extsi %295 : i32 to i64
    %296 = arith.cmpi eq, %arg1, %297 : i64
    cf.cond_br %296, ^bb60, ^bb61
    ^bb60:
      %299 = arith.constant 1 : i32
      %300 = arith.extsi %299 : i32 to i64
      %298 = func.call @contribution(%300, %arg0, %arg2) : (i64, i64, i64) -> i64
      llvm.store %298, %294 : i64, !llvm.ptr
      cf.br ^bb62
    ^bb61:
      cf.br ^bb62
    ^bb62:
    %301 = llvm.mlir.addressof @g_odd_prime_count : !llvm.ptr
    %302 = llvm.load %301 : !llvm.ptr -> i64
    %303 = arith.constant 1 : i32
    %304 = arith.constant 21 : i32
    %305 = arith.shli %303, %304 : i32
    %306 = arith.extsi %305 : i32 to i64
    %307 = llvm.mlir.constant(1 : i64) : i64
    %308 = llvm.alloca %307 x i64 : (i64) -> !llvm.ptr
    llvm.store %306, %308 : i64, !llvm.ptr
    %310 = llvm.load %308 : !llvm.ptr -> i64
    %311 = arith.constant 8 : i32
    %313 = arith.extsi %311 : i32 to i64
    %312 = arith.muli %310, %313 : i64
    %309 = func.call @malloc(%312) : (i64) -> !llvm.ptr
    %314 = llvm.mlir.addressof @st_prod : !llvm.ptr
    llvm.store %309, %314 : !llvm.ptr, !llvm.ptr
    %316 = llvm.load %308 : !llvm.ptr -> i64
    %317 = arith.constant 4 : i32
    %319 = arith.extsi %317 : i32 to i64
    %318 = arith.muli %316, %319 : i64
    %315 = func.call @malloc(%318) : (i64) -> !llvm.ptr
    %320 = llvm.mlir.addressof @st_next_idx : !llvm.ptr
    llvm.store %315, %320 : !llvm.ptr, !llvm.ptr
    %322 = llvm.load %308 : !llvm.ptr -> i64
    %323 = arith.constant 4 : i32
    %325 = arith.extsi %323 : i32 to i64
    %324 = arith.muli %322, %325 : i64
    %321 = func.call @malloc(%324) : (i64) -> !llvm.ptr
    %326 = llvm.mlir.addressof @st_xor_val : !llvm.ptr
    llvm.store %321, %326 : !llvm.ptr, !llvm.ptr
    %328 = llvm.load %308 : !llvm.ptr -> i64
    %329 = arith.constant 4 : i32
    %331 = arith.extsi %329 : i32 to i64
    %330 = arith.muli %328, %331 : i64
    %327 = func.call @malloc(%330) : (i64) -> !llvm.ptr
    %332 = llvm.mlir.addressof @st_last : !llvm.ptr
    llvm.store %327, %332 : !llvm.ptr, !llvm.ptr
    %334 = llvm.load %308 : !llvm.ptr -> i64
    %335 = arith.constant 4 : i32
    %337 = arith.extsi %335 : i32 to i64
    %336 = arith.muli %334, %337 : i64
    %333 = func.call @malloc(%336) : (i64) -> !llvm.ptr
    %338 = llvm.mlir.addressof @st_odd_count : !llvm.ptr
    llvm.store %333, %338 : !llvm.ptr, !llvm.ptr
    %339 = arith.constant 0 : i32
    %340 = arith.extsi %339 : i32 to i64
    %341 = llvm.mlir.constant(1 : i64) : i64
    %342 = llvm.alloca %341 x i64 : (i64) -> !llvm.ptr
    llvm.store %340, %342 : i64, !llvm.ptr
    %343 = arith.constant 0 : i32
    %344 = arith.extsi %343 : i32 to i64
    %345 = llvm.mlir.constant(1 : i64) : i64
    %346 = llvm.alloca %345 x i64 : (i64) -> !llvm.ptr
    llvm.store %344, %346 : i64, !llvm.ptr
    cf.br ^bb63
    ^bb63:
    %347 = llvm.load %346 : !llvm.ptr -> i64
    %348 = arith.cmpi slt, %347, %302 : i64
    cf.cond_br %348, ^bb64, ^bb65
    ^bb64:
      %350 = llvm.mlir.addressof @g_odd_primes : !llvm.ptr
      %351 = llvm.load %350 : !llvm.ptr -> !llvm.ptr
      %352 = llvm.load %346 : !llvm.ptr -> i64
      %353 = llvm.getelementptr %351[%352] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %349 = llvm.load %353 : !llvm.ptr -> i32
      %354 = arith.extsi %349 : i32 to i64
      %355 = arith.constant 2 : i32
      %357 = arith.extsi %355 : i32 to i64
      %356 = arith.addi %354, %357 : i64
      %358 = arith.divsi %arg0, %356 : i64
      %359 = arith.cmpi sgt, %354, %358 : i64
      cf.cond_br %359, ^bb66, ^bb67
      ^bb66:
        cf.br ^bb65
      ^bb67:
        cf.br ^bb68
      ^bb68:
      %360 = llvm.mlir.addressof @st_prod : !llvm.ptr
      %361 = llvm.load %360 : !llvm.ptr -> !llvm.ptr
      %362 = llvm.load %342 : !llvm.ptr -> i64
      %363 = llvm.getelementptr %361[%362] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %354, %363 : i64, !llvm.ptr
      %364 = llvm.load %346 : !llvm.ptr -> i64
      %365 = arith.constant 1 : i32
      %367 = arith.extsi %365 : i32 to i64
      %366 = arith.addi %364, %367 : i64
      %368 = arith.trunci %366 : i64 to i32
      %369 = llvm.mlir.addressof @st_next_idx : !llvm.ptr
      %370 = llvm.load %369 : !llvm.ptr -> !llvm.ptr
      %371 = llvm.load %342 : !llvm.ptr -> i64
      %372 = llvm.getelementptr %370[%371] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      llvm.store %368, %372 : i32, !llvm.ptr
      %373 = arith.trunci %354 : i64 to i32
      %374 = llvm.mlir.addressof @st_xor_val : !llvm.ptr
      %375 = llvm.load %374 : !llvm.ptr -> !llvm.ptr
      %376 = llvm.load %342 : !llvm.ptr -> i64
      %377 = llvm.getelementptr %375[%376] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      llvm.store %373, %377 : i32, !llvm.ptr
      %378 = arith.trunci %354 : i64 to i32
      %379 = llvm.mlir.addressof @st_last : !llvm.ptr
      %380 = llvm.load %379 : !llvm.ptr -> !llvm.ptr
      %381 = llvm.load %342 : !llvm.ptr -> i64
      %382 = llvm.getelementptr %380[%381] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      llvm.store %378, %382 : i32, !llvm.ptr
      %383 = arith.constant 1 : i32
      %384 = llvm.mlir.addressof @st_odd_count : !llvm.ptr
      %385 = llvm.load %384 : !llvm.ptr -> !llvm.ptr
      %386 = llvm.load %342 : !llvm.ptr -> i64
      %387 = llvm.getelementptr %385[%386] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      llvm.store %383, %387 : i32, !llvm.ptr
      %388 = llvm.load %342 : !llvm.ptr -> i64
      %389 = arith.constant 1 : i32
      %391 = arith.extsi %389 : i32 to i64
      %390 = arith.addi %388, %391 : i64
      llvm.store %390, %342 : i64, !llvm.ptr
      %392 = llvm.load %346 : !llvm.ptr -> i64
      %393 = arith.constant 1 : i32
      %395 = arith.extsi %393 : i32 to i64
      %394 = arith.addi %392, %395 : i64
      llvm.store %394, %346 : i64, !llvm.ptr
      cf.br ^bb63
    ^bb65:
    cf.br ^bb69
    ^bb69:
    %396 = llvm.load %342 : !llvm.ptr -> i64
    %397 = arith.constant 0 : i32
    %399 = arith.extsi %397 : i32 to i64
    %398 = arith.cmpi sgt, %396, %399 : i64
    cf.cond_br %398, ^bb70, ^bb71
    ^bb70:
      %400 = llvm.load %342 : !llvm.ptr -> i64
      %401 = arith.constant 1 : i32
      %403 = arith.extsi %401 : i32 to i64
      %402 = arith.subi %400, %403 : i64
      llvm.store %402, %342 : i64, !llvm.ptr
      %405 = llvm.mlir.addressof @st_next_idx : !llvm.ptr
      %406 = llvm.load %405 : !llvm.ptr -> !llvm.ptr
      %407 = llvm.load %342 : !llvm.ptr -> i64
      %408 = llvm.getelementptr %406[%407] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %404 = llvm.load %408 : !llvm.ptr -> i32
      %409 = arith.extsi %404 : i32 to i64
      %411 = llvm.mlir.addressof @st_prod : !llvm.ptr
      %412 = llvm.load %411 : !llvm.ptr -> !llvm.ptr
      %413 = llvm.load %342 : !llvm.ptr -> i64
      %414 = llvm.getelementptr %412[%413] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %410 = llvm.load %414 : !llvm.ptr -> i64
      %416 = llvm.mlir.addressof @st_xor_val : !llvm.ptr
      %417 = llvm.load %416 : !llvm.ptr -> !llvm.ptr
      %418 = llvm.load %342 : !llvm.ptr -> i64
      %419 = llvm.getelementptr %417[%418] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %415 = llvm.load %419 : !llvm.ptr -> i32
      %420 = arith.extsi %415 : i32 to i64
      %422 = llvm.mlir.addressof @st_last : !llvm.ptr
      %423 = llvm.load %422 : !llvm.ptr -> !llvm.ptr
      %424 = llvm.load %342 : !llvm.ptr -> i64
      %425 = llvm.getelementptr %423[%424] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %421 = llvm.load %425 : !llvm.ptr -> i32
      %426 = arith.extsi %421 : i32 to i64
      %428 = llvm.mlir.addressof @st_odd_count : !llvm.ptr
      %429 = llvm.load %428 : !llvm.ptr -> !llvm.ptr
      %430 = llvm.load %342 : !llvm.ptr -> i64
      %431 = llvm.getelementptr %429[%430] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %427 = llvm.load %431 : !llvm.ptr -> i32
      %432 = arith.extsi %427 : i32 to i64
      %433 = arith.constant 0 : i32
      %435 = arith.extsi %433 : i32 to i64
      %434 = arith.cmpi ne, %432, %435 : i64
      cf.cond_br %434, ^bb72, ^bb73
      ^bb72:
        %436 = arith.xori %arg1, %420 : i64
        %437 = arith.cmpi sgt, %436, %426 : i64
        %438 = scf.if %437 -> (i1) {
          %439 = llvm.mlir.addressof @g_limit : !llvm.ptr
          %440 = llvm.load %439 : !llvm.ptr -> i64
          %441 = arith.cmpi sle, %436, %440 : i64
          scf.yield %441 : i1
        } else {
          %442 = arith.constant false
          scf.yield %442 : i1
        }
        %443 = scf.if %438 -> (i1) {
          %445 = llvm.mlir.addressof @g_flags : !llvm.ptr
          %446 = llvm.load %445 : !llvm.ptr -> !llvm.ptr
          %447 = llvm.getelementptr %446[%436] : (!llvm.ptr, i64) -> !llvm.ptr, i8
          %444 = llvm.load %447 : !llvm.ptr -> i8
          %448 = arith.constant 0 : i32
          %450 = arith.extsi %444 : i8 to i32
          %449 = arith.cmpi ne, %450, %448 : i32
          scf.yield %449 : i1
        } else {
          %451 = arith.constant false
          scf.yield %451 : i1
        }
        cf.cond_br %443, ^bb75, ^bb76
        ^bb75:
          %452 = arith.divsi %arg0, %436 : i64
          %453 = arith.cmpi sle, %410, %452 : i64
          cf.cond_br %453, ^bb78, ^bb79
          ^bb78:
            %454 = llvm.load %294 : !llvm.ptr -> i64
            %456 = arith.muli %410, %436 : i64
            %455 = func.call @contribution(%456, %arg0, %arg2) : (i64, i64, i64) -> i64
            %457 = arith.addi %454, %455 : i64
            %458 = llvm.mlir.addressof @MOD : !llvm.ptr
            %459 = llvm.load %458 : !llvm.ptr -> i64
            %460 = arith.remsi %457, %459 : i64
            llvm.store %460, %294 : i64, !llvm.ptr
            cf.br ^bb80
          ^bb79:
            cf.br ^bb80
          ^bb80:
          cf.br ^bb77
        ^bb76:
          cf.br ^bb77
        ^bb77:
        cf.br ^bb74
      ^bb73:
        cf.br ^bb74
      ^bb74:
      %461 = arith.constant 1 : i32
      %463 = arith.extsi %461 : i32 to i64
      %462 = arith.xori %432, %463 : i64
      %464 = llvm.mlir.constant(1 : i64) : i64
      %465 = llvm.alloca %464 x i64 : (i64) -> !llvm.ptr
      llvm.store %409, %465 : i64, !llvm.ptr
      cf.br ^bb81
      ^bb81:
      %466 = llvm.load %465 : !llvm.ptr -> i64
      %467 = arith.cmpi slt, %466, %302 : i64
      cf.cond_br %467, ^bb82, ^bb83
      ^bb82:
        %469 = llvm.mlir.addressof @g_odd_primes : !llvm.ptr
        %470 = llvm.load %469 : !llvm.ptr -> !llvm.ptr
        %471 = llvm.load %465 : !llvm.ptr -> i64
        %472 = llvm.getelementptr %470[%471] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %468 = llvm.load %472 : !llvm.ptr -> i32
        %473 = arith.extsi %468 : i32 to i64
        %474 = arith.divsi %arg0, %473 : i64
        %475 = arith.cmpi sgt, %410, %474 : i64
        cf.cond_br %475, ^bb84, ^bb85
        ^bb84:
          cf.br ^bb83
        ^bb85:
          cf.br ^bb86
        ^bb86:
        %476 = arith.muli %410, %473 : i64
        %477 = arith.constant 2 : i32
        %479 = arith.extsi %477 : i32 to i64
        %478 = arith.addi %473, %479 : i64
        %480 = arith.divsi %arg0, %478 : i64
        %481 = arith.cmpi sgt, %476, %480 : i64
        cf.cond_br %481, ^bb87, ^bb88
        ^bb87:
          cf.br ^bb83
        ^bb88:
          cf.br ^bb89
        ^bb89:
        %482 = arith.constant 0 : i32
        %484 = arith.extsi %482 : i32 to i64
        %483 = arith.cmpi eq, %462, %484 : i64
        cf.cond_br %483, ^bb90, ^bb91
        ^bb90:
          %485 = arith.muli %476, %478 : i64
          %486 = arith.constant 2 : i32
          %488 = arith.extsi %486 : i32 to i64
          %487 = arith.addi %478, %488 : i64
          %489 = arith.divsi %arg0, %487 : i64
          %490 = arith.cmpi sgt, %485, %489 : i64
          cf.cond_br %490, ^bb93, ^bb94
          ^bb93:
            cf.br ^bb83
          ^bb94:
            cf.br ^bb95
          ^bb95:
          cf.br ^bb92
        ^bb91:
          cf.br ^bb92
        ^bb92:
        %491 = llvm.mlir.addressof @st_prod : !llvm.ptr
        %492 = llvm.load %491 : !llvm.ptr -> !llvm.ptr
        %493 = llvm.load %342 : !llvm.ptr -> i64
        %494 = llvm.getelementptr %492[%493] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %476, %494 : i64, !llvm.ptr
        %495 = llvm.load %465 : !llvm.ptr -> i64
        %496 = arith.constant 1 : i32
        %498 = arith.extsi %496 : i32 to i64
        %497 = arith.addi %495, %498 : i64
        %499 = arith.trunci %497 : i64 to i32
        %500 = llvm.mlir.addressof @st_next_idx : !llvm.ptr
        %501 = llvm.load %500 : !llvm.ptr -> !llvm.ptr
        %502 = llvm.load %342 : !llvm.ptr -> i64
        %503 = llvm.getelementptr %501[%502] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %499, %503 : i32, !llvm.ptr
        %504 = arith.xori %420, %473 : i64
        %505 = arith.trunci %504 : i64 to i32
        %506 = llvm.mlir.addressof @st_xor_val : !llvm.ptr
        %507 = llvm.load %506 : !llvm.ptr -> !llvm.ptr
        %508 = llvm.load %342 : !llvm.ptr -> i64
        %509 = llvm.getelementptr %507[%508] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %505, %509 : i32, !llvm.ptr
        %510 = arith.trunci %473 : i64 to i32
        %511 = llvm.mlir.addressof @st_last : !llvm.ptr
        %512 = llvm.load %511 : !llvm.ptr -> !llvm.ptr
        %513 = llvm.load %342 : !llvm.ptr -> i64
        %514 = llvm.getelementptr %512[%513] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %510, %514 : i32, !llvm.ptr
        %515 = arith.trunci %462 : i64 to i32
        %516 = llvm.mlir.addressof @st_odd_count : !llvm.ptr
        %517 = llvm.load %516 : !llvm.ptr -> !llvm.ptr
        %518 = llvm.load %342 : !llvm.ptr -> i64
        %519 = llvm.getelementptr %517[%518] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %515, %519 : i32, !llvm.ptr
        %520 = llvm.load %342 : !llvm.ptr -> i64
        %521 = arith.constant 1 : i32
        %523 = arith.extsi %521 : i32 to i64
        %522 = arith.addi %520, %523 : i64
        llvm.store %522, %342 : i64, !llvm.ptr
        %524 = llvm.load %465 : !llvm.ptr -> i64
        %525 = arith.constant 1 : i32
        %527 = arith.extsi %525 : i32 to i64
        %526 = arith.addi %524, %527 : i64
        llvm.store %526, %465 : i64, !llvm.ptr
        cf.br ^bb81
      ^bb83:
      cf.br ^bb69
    ^bb71:
    %529 = llvm.mlir.addressof @st_prod : !llvm.ptr
    %530 = llvm.load %529 : !llvm.ptr -> !llvm.ptr
    func.call @free(%530) : (!llvm.ptr) -> ()
    %532 = llvm.mlir.addressof @st_next_idx : !llvm.ptr
    %533 = llvm.load %532 : !llvm.ptr -> !llvm.ptr
    func.call @free(%533) : (!llvm.ptr) -> ()
    %535 = llvm.mlir.addressof @st_xor_val : !llvm.ptr
    %536 = llvm.load %535 : !llvm.ptr -> !llvm.ptr
    func.call @free(%536) : (!llvm.ptr) -> ()
    %538 = llvm.mlir.addressof @st_last : !llvm.ptr
    %539 = llvm.load %538 : !llvm.ptr -> !llvm.ptr
    func.call @free(%539) : (!llvm.ptr) -> ()
    %541 = llvm.mlir.addressof @st_odd_count : !llvm.ptr
    %542 = llvm.load %541 : !llvm.ptr -> !llvm.ptr
    func.call @free(%542) : (!llvm.ptr) -> ()
    %543 = llvm.load %294 : !llvm.ptr -> i64
    %544 = llvm.mlir.addressof @MOD : !llvm.ptr
    %545 = llvm.load %544 : !llvm.ptr -> i64
    %546 = arith.remsi %543, %545 : i64
    func.return %546 : i64
  }
  func.func @prime_sieve(%arg0: i64) -> () {
    %548 = arith.constant 1 : i32
    %550 = arith.extsi %548 : i32 to i64
    %549 = arith.addi %arg0, %550 : i64
    %547 = func.call @malloc(%549) : (i64) -> !llvm.ptr
    %552 = arith.constant 1 : i32
    %553 = arith.constant 1 : i32
    %555 = arith.extsi %553 : i32 to i64
    %554 = arith.addi %arg0, %555 : i64
    %551 = func.call @memset(%547, %552, %554) : (!llvm.ptr, i32, i64) -> !llvm.ptr
    %556 = arith.constant 0 : i32
    %557 = arith.constant 0 : i32
    %558 = arith.trunci %556 : i32 to i8
    %559 = arith.extsi %557 : i32 to i64
    %560 = llvm.getelementptr %547[%559] : (!llvm.ptr, i64) -> !llvm.ptr, i8
    llvm.store %558, %560 : i8, !llvm.ptr
    %561 = arith.constant 0 : i32
    %562 = arith.constant 1 : i32
    %563 = arith.trunci %561 : i32 to i8
    %564 = arith.extsi %562 : i32 to i64
    %565 = llvm.getelementptr %547[%564] : (!llvm.ptr, i64) -> !llvm.ptr, i8
    llvm.store %563, %565 : i8, !llvm.ptr
    %566 = arith.constant 2 : i32
    %567 = arith.extsi %566 : i32 to i64
    %568 = llvm.mlir.constant(1 : i64) : i64
    %569 = llvm.alloca %568 x i64 : (i64) -> !llvm.ptr
    llvm.store %567, %569 : i64, !llvm.ptr
    cf.br ^bb96
    ^bb96:
    %570 = llvm.load %569 : !llvm.ptr -> i64
    %571 = llvm.load %569 : !llvm.ptr -> i64
    %572 = arith.muli %570, %571 : i64
    %573 = arith.cmpi sle, %572, %arg0 : i64
    cf.cond_br %573, ^bb97, ^bb98
    ^bb97:
      %575 = llvm.load %569 : !llvm.ptr -> i64
      %576 = llvm.getelementptr %547[%575] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %574 = llvm.load %576 : !llvm.ptr -> i8
      %577 = arith.constant 0 : i32
      %579 = arith.extsi %574 : i8 to i32
      %578 = arith.cmpi ne, %579, %577 : i32
      cf.cond_br %578, ^bb99, ^bb100
      ^bb99:
        %580 = llvm.load %569 : !llvm.ptr -> i64
        %581 = llvm.load %569 : !llvm.ptr -> i64
        %582 = arith.muli %580, %581 : i64
        %583 = llvm.mlir.constant(1 : i64) : i64
        %584 = llvm.alloca %583 x i64 : (i64) -> !llvm.ptr
        llvm.store %582, %584 : i64, !llvm.ptr
        cf.br ^bb102
        ^bb102:
        %585 = llvm.load %584 : !llvm.ptr -> i64
        %586 = arith.cmpi sle, %585, %arg0 : i64
        cf.cond_br %586, ^bb103, ^bb104
        ^bb103:
          %587 = arith.constant 0 : i32
          %588 = llvm.load %584 : !llvm.ptr -> i64
          %589 = arith.trunci %587 : i32 to i8
          %590 = llvm.getelementptr %547[%588] : (!llvm.ptr, i64) -> !llvm.ptr, i8
          llvm.store %589, %590 : i8, !llvm.ptr
          %591 = llvm.load %584 : !llvm.ptr -> i64
          %592 = llvm.load %569 : !llvm.ptr -> i64
          %593 = arith.addi %591, %592 : i64
          llvm.store %593, %584 : i64, !llvm.ptr
          cf.br ^bb102
        ^bb104:
        cf.br ^bb101
      ^bb100:
        cf.br ^bb101
      ^bb101:
      %594 = llvm.load %569 : !llvm.ptr -> i64
      %595 = arith.constant 1 : i32
      %597 = arith.extsi %595 : i32 to i64
      %596 = arith.addi %594, %597 : i64
      llvm.store %596, %569 : i64, !llvm.ptr
      cf.br ^bb96
    ^bb98:
    %598 = arith.constant 0 : i32
    %599 = arith.extsi %598 : i32 to i64
    %600 = llvm.mlir.constant(1 : i64) : i64
    %601 = llvm.alloca %600 x i64 : (i64) -> !llvm.ptr
    llvm.store %599, %601 : i64, !llvm.ptr
    %602 = arith.constant 3 : i32
    %603 = arith.extsi %602 : i32 to i64
    %604 = llvm.mlir.constant(1 : i64) : i64
    %605 = llvm.alloca %604 x i64 : (i64) -> !llvm.ptr
    llvm.store %603, %605 : i64, !llvm.ptr
    cf.br ^bb105
    ^bb105:
    %606 = llvm.load %605 : !llvm.ptr -> i64
    %607 = arith.cmpi sle, %606, %arg0 : i64
    cf.cond_br %607, ^bb106, ^bb107
    ^bb106:
      %609 = llvm.load %605 : !llvm.ptr -> i64
      %610 = llvm.getelementptr %547[%609] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %608 = llvm.load %610 : !llvm.ptr -> i8
      %611 = arith.constant 0 : i32
      %613 = arith.extsi %608 : i8 to i32
      %612 = arith.cmpi ne, %613, %611 : i32
      cf.cond_br %612, ^bb108, ^bb109
      ^bb108:
        %614 = llvm.load %601 : !llvm.ptr -> i64
        %615 = arith.constant 1 : i32
        %617 = arith.extsi %615 : i32 to i64
        %616 = arith.addi %614, %617 : i64
        llvm.store %616, %601 : i64, !llvm.ptr
        cf.br ^bb110
      ^bb109:
        cf.br ^bb110
      ^bb110:
      %618 = llvm.load %605 : !llvm.ptr -> i64
      %619 = arith.constant 2 : i32
      %621 = arith.extsi %619 : i32 to i64
      %620 = arith.addi %618, %621 : i64
      llvm.store %620, %605 : i64, !llvm.ptr
      cf.br ^bb105
    ^bb107:
    %623 = llvm.load %601 : !llvm.ptr -> i64
    %624 = arith.constant 4 : i32
    %626 = arith.extsi %624 : i32 to i64
    %625 = arith.muli %623, %626 : i64
    %622 = func.call @malloc(%625) : (i64) -> !llvm.ptr
    %627 = arith.constant 0 : i32
    %628 = arith.extsi %627 : i32 to i64
    %629 = llvm.mlir.constant(1 : i64) : i64
    %630 = llvm.alloca %629 x i64 : (i64) -> !llvm.ptr
    llvm.store %628, %630 : i64, !llvm.ptr
    %631 = arith.constant 3 : i32
    %632 = arith.extsi %631 : i32 to i64
    %633 = llvm.mlir.constant(1 : i64) : i64
    %634 = llvm.alloca %633 x i64 : (i64) -> !llvm.ptr
    llvm.store %632, %634 : i64, !llvm.ptr
    cf.br ^bb111
    ^bb111:
    %635 = llvm.load %634 : !llvm.ptr -> i64
    %636 = arith.cmpi sle, %635, %arg0 : i64
    cf.cond_br %636, ^bb112, ^bb113
    ^bb112:
      %638 = llvm.load %634 : !llvm.ptr -> i64
      %639 = llvm.getelementptr %547[%638] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %637 = llvm.load %639 : !llvm.ptr -> i8
      %640 = arith.constant 0 : i32
      %642 = arith.extsi %637 : i8 to i32
      %641 = arith.cmpi ne, %642, %640 : i32
      cf.cond_br %641, ^bb114, ^bb115
      ^bb114:
        %643 = llvm.load %634 : !llvm.ptr -> i64
        %644 = arith.trunci %643 : i64 to i32
        %645 = llvm.load %630 : !llvm.ptr -> i64
        %646 = llvm.getelementptr %622[%645] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %644, %646 : i32, !llvm.ptr
        %647 = llvm.load %630 : !llvm.ptr -> i64
        %648 = arith.constant 1 : i32
        %650 = arith.extsi %648 : i32 to i64
        %649 = arith.addi %647, %650 : i64
        llvm.store %649, %630 : i64, !llvm.ptr
        cf.br ^bb116
      ^bb115:
        cf.br ^bb116
      ^bb116:
      %651 = llvm.load %634 : !llvm.ptr -> i64
      %652 = arith.constant 2 : i32
      %654 = arith.extsi %652 : i32 to i64
      %653 = arith.addi %651, %654 : i64
      llvm.store %653, %634 : i64, !llvm.ptr
      cf.br ^bb111
    ^bb113:
    %655 = llvm.mlir.addressof @g_flags : !llvm.ptr
    llvm.store %547, %655 : !llvm.ptr, !llvm.ptr
    %656 = llvm.mlir.addressof @g_odd_primes : !llvm.ptr
    llvm.store %622, %656 : !llvm.ptr, !llvm.ptr
    %657 = llvm.load %601 : !llvm.ptr -> i64
    %658 = llvm.mlir.addressof @g_odd_prime_count : !llvm.ptr
    llvm.store %657, %658 : i64, !llvm.ptr
    func.return
  }
  func.func @main() -> i32 {
    %660 = arith.constant 6 : i32
    %661 = llvm.mlir.addressof @MOD : !llvm.ptr
    %662 = llvm.load %661 : !llvm.ptr -> i64
    %663 = arith.constant 2 : i32
    %665 = arith.extsi %663 : i32 to i64
    %664 = arith.subi %662, %665 : i64
    %666 = llvm.mlir.addressof @MOD : !llvm.ptr
    %667 = llvm.load %666 : !llvm.ptr -> i64
    %668 = arith.extsi %660 : i32 to i64
    %659 = func.call @my_mod_pow(%668, %664, %667) : (i64, i64, i64) -> i64
    %669 = llvm.mlir.addressof @INV6 : !llvm.ptr
    llvm.store %659, %669 : i64, !llvm.ptr
    %670 = arith.constant 99995705032704 : i32
    %671 = arith.extsi %670 : i32 to i64
    %673 = arith.constant 2 : i32
    %675 = arith.extsi %673 : i32 to i64
    %674 = arith.muli %675, %671 : i64
    %672 = func.call @isqrt_ll(%674) : (i64) -> i64
    %676 = arith.constant 10 : i32
    %678 = arith.extsi %676 : i32 to i64
    %677 = arith.addi %672, %678 : i64
    func.call @prime_sieve(%677) : (i64) -> ()
    %680 = llvm.mlir.addressof @g_limit : !llvm.ptr
    llvm.store %677, %680 : i64, !llvm.ptr
    %682 = arith.constant 0 : i32
    %683 = arith.constant 1 : i32
    %684 = arith.extsi %682 : i32 to i64
    %685 = arith.extsi %683 : i32 to i64
    %681 = func.call @branch_sum(%671, %684, %685) : (i64, i64, i64) -> i64
    %687 = arith.constant 2 : i32
    %689 = arith.extsi %687 : i32 to i64
    %688 = arith.divsi %671, %689 : i64
    %690 = arith.constant 2 : i32
    %691 = arith.constant 2 : i32
    %692 = arith.extsi %690 : i32 to i64
    %693 = arith.extsi %691 : i32 to i64
    %686 = func.call @branch_sum(%688, %692, %693) : (i64, i64, i64) -> i64
    %694 = arith.addi %681, %686 : i64
    %695 = llvm.mlir.addressof @MOD : !llvm.ptr
    %696 = llvm.load %695 : !llvm.ptr -> i64
    %697 = arith.remsi %694, %696 : i64
    %698 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %699 = llvm.call @printf(%698, %697) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    %701 = llvm.mlir.addressof @g_flags : !llvm.ptr
    %702 = llvm.load %701 : !llvm.ptr -> !llvm.ptr
    func.call @free(%702) : (!llvm.ptr) -> ()
    %704 = llvm.mlir.addressof @g_odd_primes : !llvm.ptr
    %705 = llvm.load %704 : !llvm.ptr -> !llvm.ptr
    func.call @free(%705) : (!llvm.ptr) -> ()
    %706 = arith.constant 0 : i32
    func.return %706 : i32
  }
}