Problem 699

T(N) = sum of n <= N where sigma(n)/n reduces to a/b with b = 3^k, k > 0. Uses seeds (2^a * 3^b * 5^c) and DFS with Pollard's rho factorization.

Answer37010438774467572
Output37010438774467572
StatusPASS
Native helperno
Runtime260 ms
Peak memory607408 KB
Time complexityO(n^2) (estimated)
Space complexityO(n^2) (estimated)

Performance comparison

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

Flow source

# Project Euler 699: Triffle Numbers
# T(N) = sum of n <= N where sigma(n)/n reduces to a/b with b = 3^k, k > 0.
# Uses seeds (2^a * 3^b * 5^c) and DFS with Pollard's rho factorization.

import euler.nt { gcd, is_prime, mod_pow, mulmod }

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

const N: i64 = 100000000000000  # 10^14

# ---- Pollard's rho ----
let mut g_rng_state: i64 = 42

function rng_next() -> i64 {
    g_rng_state = g_rng_state * 6364136223846793005 + 1442695040888963407
    return g_rng_state
}

function rng_range(lo: i64, hi: i64) -> i64 {
    let r: i64 = rng_next()
    if r < 0 { r = -r }
    return lo + (r % (hi - lo + 1))
}

function pollard_rho(n: i64) -> i64 {
    if n % 2 == 0 { return 2 }
    if n % 3 == 0 { return 3 }
    while true {
        let c: i64 = rng_range(1, n - 1)
        let mut x: i64 = rng_range(0, n - 1)
        let mut y: i64 = x
        let mut d: i64 = 1
        while d == 1 {
            x = (mulmod(x, x, n) + c) % n
            y = (mulmod(y, y, n) + c) % n
            y = (mulmod(y, y, n) + c) % n
            let diff: i64
            if x > y { diff = x - y } else { diff = y - x }
            d = gcd(diff, n)
        }
        if d != n { return d }
    }
    return 0
}

# Factorization into prime powers (stored in parallel arrays)
# Returns count of distinct prime factors
function factorize(n: i64, fps: ptr<i64>, fes: ptr<i64>) -> i64 {
    let mut nf: i64 = 0
    let mut x: i64 = n
    if x == 1 { return 0 }

    # Trial division by small primes
    let small_primes: ptr<i64> = calloc(12, 8)
    small_primes[0] = 2; small_primes[1] = 3; small_primes[2] = 5
    small_primes[3] = 7; small_primes[4] = 11; small_primes[5] = 13
    small_primes[6] = 17; small_primes[7] = 19; small_primes[8] = 23
    small_primes[9] = 29; small_primes[10] = 31; small_primes[11] = 37

    for i in 0..12 {
        let p: i64 = small_primes[i]
        if x % p == 0 {
            let mut cnt: i64 = 0
            while x % p == 0 { x = x / p; cnt = cnt + 1 }
            fps[nf] = p
            fes[nf] = cnt
            nf = nf + 1
            if x == 1 { free(small_primes); return nf }
        }
    }
    free(small_primes)

    if x == 1 { return nf }
    if is_prime(x) {
        fps[nf] = x
        fes[nf] = 1
        return nf + 1
    }

    # Pollard's rho recursion (iterative with stack)
    let stack: ptr<i64> = calloc(100, 8)
    let mut sp: i64 = 0
    stack[sp] = x; sp = sp + 1

    while sp > 0 {
        sp = sp - 1
        let m: i64 = stack[sp]
        if m == 1 { continue }
        if is_prime(m) {
            # Check if already in fps
            let mut found: i64 = -1
            for i in 0..nf {
                if fps[i] == m { found = i }
            }
            if found >= 0 {
                fes[found] = fes[found] + 1
            } else {
                fps[nf] = m
                fes[nf] = 1
                nf = nf + 1
            }
            continue
        }
        let d: i64 = pollard_rho(m)
        stack[sp] = d; sp = sp + 1
        stack[sp] = m / d; sp = sp + 1
    }
    free(stack)
    return nf
}

function is_power_of_3(n: i64) -> i64 {
    if n <= 0 { return -1 }
    let mut k: i64 = 0
    let mut x: i64 = n
    while x % 3 == 0 { x = x / 3; k = k + 1 }
    if x == 1 { return k } else { return -1 }
}

function sigma_prime_power(p: i64, e: i64) -> i64 {
    let mut s: i64 = 1
    let mut pp: i64 = 1
    for i in 0..e {
        pp = pp * p
        s = s + pp
    }
    return s
}

# ---- Hash set for visited ----
const VIS_HASH_SIZE: i64 = 20000003
let mut g_vis_keys: ptr<i64> = null

function vis_init() -> void {
    g_vis_keys = calloc(VIS_HASH_SIZE, 8)
}

function vis_check_or_add(n: i64) -> bool {
    let mut h: i64 = n % VIS_HASH_SIZE
    if h < 0 { h = h + VIS_HASH_SIZE }
    while g_vis_keys[h] != 0 {
        if g_vis_keys[h] == n { return false }
        h = h + 1
        if h >= VIS_HASH_SIZE { h = 0 }
    }
    g_vis_keys[h] = n
    return true
}

# ---- Factorization cache ----
const FAC_HASH_SIZE: i64 = 20000003
let mut g_fac_keys: ptr<i64> = null
let mut g_fac_data: ptr<i64> = null  # each entry: nf, then pairs (p, e)

function fac_cache_init() -> void {
    g_fac_keys = calloc(FAC_HASH_SIZE, 8)
    g_fac_data = calloc(FAC_HASH_SIZE * 22, 8)  # up to 20 prime factors + nf
}

function fac_cache_get(x: i64, out_fps: ptr<i64>, out_fes: ptr<i64>) -> i64 {
    let mut h: i64 = x % FAC_HASH_SIZE
    if h < 0 { h = h + FAC_HASH_SIZE }
    while g_fac_keys[h] != 0 {
        if g_fac_keys[h] == x {
            let base: i64 = h * 22
            let nf: i64 = g_fac_data[base]
            for i in 0..nf {
                out_fps[i] = g_fac_data[base + 1 + i * 2]
                out_fes[i] = g_fac_data[base + 2 + i * 2]
            }
            return nf
        }
        h = h + 1
        if h >= FAC_HASH_SIZE { h = 0 }
    }
    # Not found: factorize and store
    let nf: i64 = factorize(x, out_fps, out_fes)
    g_fac_keys[h] = x
    let base: i64 = h * 22
    g_fac_data[base] = nf
    for i in 0..nf {
        g_fac_data[base + 1 + i * 2] = out_fps[i]
        g_fac_data[base + 2 + i * 2] = out_fes[i]
    }
    return nf
}

# ---- DFS ----
let mut g_total: i64 = 0

function dfs(n: i64, num: i64, den: i64) -> void {
    if not vis_check_or_add(n) { return }

    let k: i64 = is_power_of_3(den)
    if k > 0 { g_total = g_total + n }

    if den == 1 { return }
    if den % 3 != 0 { return }
    if num == 1 { return }

    let fps: ptr<i64> = calloc(64, 8)
    let fes: ptr<i64> = calloc(64, 8)
    let nf: i64 = fac_cache_get(num, fps, fes)

    for i in 0..nf {
        let p: i64 = fps[i]
        if p <= 5 { continue }
        if n % p == 0 { continue }

        let mut pp: i64 = 1
        for e in 1..(fes[i] + 1) {
            if pp > N / p { break }
            pp = pp * p
            if n > N / pp { break }

            let sp: i64 = sigma_prime_power(p, e)
            let new_num: i64 = (num / pp) * sp
            let mut new_den: i64 = den

            let g: i64 = gcd(new_num, new_den)
            let nn: i64 = new_num / g
            let nd: i64 = new_den / g
            dfs(n * pp, nn, nd)
        }
    }

    free(fes)
    free(fps)
}

function main() -> i32 {
    vis_init()
    fac_cache_init()

    # Build seeds: n = 2^a * 3^b * 5^c, b >= 1, n <= N
    let pow2: ptr<i64> = calloc(50, 8)
    let pow3: ptr<i64> = calloc(30, 8)
    let pow5: ptr<i64> = calloc(30, 8)

    pow2[0] = 1
    let mut n2: i64 = 1
    let mut a_max: i64 = 0
    while pow2[a_max] * 2 <= N {
        a_max = a_max + 1
        pow2[a_max] = pow2[a_max - 1] * 2
    }

    pow3[0] = 1
    let mut n3: i64 = 1
    let mut b_max: i64 = 0
    while pow3[b_max] * 3 <= N {
        b_max = b_max + 1
        pow3[b_max] = pow3[b_max - 1] * 3
    }

    pow5[0] = 1
    let mut c_max: i64 = 0
    while pow5[c_max] * 5 <= N {
        c_max = c_max + 1
        pow5[c_max] = pow5[c_max - 1] * 5
    }

    let tmp_fps: ptr<i64> = calloc(64, 8)
    let tmp_fes: ptr<i64> = calloc(64, 8)

    for a in 0..(a_max + 1) {
        let pa: i64 = pow2[a]
        let sig2: i64
        if a > 0 { sig2 = pa * 2 - 1 } else { sig2 = 1 }

        for b in 1..(b_max + 1) {
            let pb: i64 = pow3[b]
            if pa * pb > N { break }
            let sig3: i64 = (pb * 3 - 1) / 2

            for c in 0..(c_max + 1) {
                let pc: i64 = pow5[c]
                let n: i64 = pa * pb * pc
                if n > N { break }
                let sig5: i64
                if c > 0 { sig5 = (pc * 5 - 1) / 4 } else { sig5 = 1 }
                let sig: i64 = sig2 * sig3 * sig5

                let g: i64 = gcd(n, sig)
                let num: i64 = sig / g
                let den: i64 = n / g

                if den % 3 != 0 { continue }
                if den == 1 { continue }

                dfs(n, num, den)
            }
        }
    }

    printf("%lld\n", g_total)

    free(tmp_fes)
    free(tmp_fps)
    free(pow5)
    free(pow3)
    free(pow2)
    free(g_fac_data)
    free(g_fac_keys)
    free(g_vis_keys)
    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 rng_next(void);
int64_t rng_range_i64_i64(int64_t lo, int64_t hi);
int64_t pollard_rho_i64(int64_t n);
int64_t factorize_i64_ptr_i64_ptr_i64(int64_t n, int64_t* fps, int64_t* fes);
int64_t is_power_of_3_i64(int64_t n);
int64_t sigma_prime_power_i64_i64(int64_t p, int64_t e);
void vis_init(void);
bool vis_check_or_add_i64(int64_t n);
void fac_cache_init(void);
int64_t fac_cache_get_i64_ptr_i64_ptr_i64(int64_t x, int64_t* out_fps, int64_t* out_fes);
void dfs_i64_i64_i64(int64_t n, int64_t num, int64_t den);
int32_t main(void);

static const int64_t N = 100000000000000;
static const int64_t VIS_HASH_SIZE = 20000003;
static const int64_t FAC_HASH_SIZE = 20000003;

/* Module statics */
static int64_t g_rng_state = 42;
static int64_t* g_vis_keys = NULL;
static int64_t* g_fac_keys = NULL;
static int64_t* g_fac_data = NULL;
static int64_t g_total = 0;

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 rng_next(void) {
    g_rng_state = ((g_rng_state * 6364136223846793005) + 1442695040888963407);
    return g_rng_state;
}

int64_t rng_range_i64_i64(int64_t lo, int64_t hi) {
    int64_t r = rng_next();
    if (r < 0) {
        r = (-r);
    }
    return (lo + FLOW_CHECKED_MOD((r), (((hi - lo) + 1))));
}

int64_t pollard_rho_i64(int64_t n) {
    if (FLOW_CHECKED_MOD((n), (2)) == 0) {
        return 2;
    }
    if (FLOW_CHECKED_MOD((n), (3)) == 0) {
        return 3;
    }
    while (1) {
        int64_t c = rng_range_i64_i64(1, (n - 1));
        int64_t x = rng_range_i64_i64(0, (n - 1));
        int64_t y = x;
        int64_t d = 1;
        while (d == 1) {
            x = FLOW_CHECKED_MOD(((mulmod_i64_i64_i64(x, x, n) + c)), (n));
            y = FLOW_CHECKED_MOD(((mulmod_i64_i64_i64(y, y, n) + c)), (n));
            y = FLOW_CHECKED_MOD(((mulmod_i64_i64_i64(y, y, n) + c)), (n));
            int64_t diff;
            if (x > y) {
                diff = (x - y);
            } else {
                diff = (y - x);
            }
            d = gcd_i64_i64(diff, n);
        }
        if (d != n) {
            return d;
        }
    }
    return 0;
}

int64_t factorize_i64_ptr_i64_ptr_i64(int64_t n, int64_t* fps, int64_t* fes) {
    int64_t nf = 0;
    int64_t x = n;
    if (x == 1) {
        return 0;
    }
    int64_t* small_primes = (int64_t*)(calloc(12, 8));
    small_primes[0] = 2;
    small_primes[1] = 3;
    small_primes[2] = 5;
    small_primes[3] = 7;
    small_primes[4] = 11;
    small_primes[5] = 13;
    small_primes[6] = 17;
    small_primes[7] = 19;
    small_primes[8] = 23;
    small_primes[9] = 29;
    small_primes[10] = 31;
    small_primes[11] = 37;
    int32_t __flow_step_1 = 1;
    for (int32_t i = 0; (0 <= 12) ? i < 12 : i > 12; i += (0 <= 12) ? 1 : -1) {
        int64_t p = small_primes[i];
        if (FLOW_CHECKED_MOD((x), (p)) == 0) {
            int64_t cnt = 0;
            while (FLOW_CHECKED_MOD((x), (p)) == 0) {
                x = FLOW_CHECKED_DIV((x), (p));
                cnt = (cnt + 1);
            }
            fps[nf] = p;
            fes[nf] = cnt;
            nf = (nf + 1);
            if (x == 1) {
                free(small_primes);
                return nf;
            }
        }
    }
    free(small_primes);
    if (x == 1) {
        return nf;
    }
    if (is_prime_i64(x)) {
        fps[nf] = x;
        fes[nf] = 1;
        return (nf + 1);
    }
    int64_t* stack = (int64_t*)(calloc(100, 8));
    int64_t sp = 0;
    stack[sp] = x;
    sp = (sp + 1);
    while (sp > 0) {
        sp = (sp - 1);
        int64_t m = stack[sp];
        if (m == 1) {
            continue;
        }
        if (is_prime_i64(m)) {
            int64_t found = (-1);
            int32_t __flow_step_2 = 1;
            for (int32_t i = 0; (0 <= nf) ? i < nf : i > nf; i += (0 <= nf) ? 1 : -1) {
                if (fps[i] == m) {
                    found = i;
                }
            }
            if (found >= 0) {
                fes[found] = (fes[found] + 1);
            } else {
                fps[nf] = m;
                fes[nf] = 1;
                nf = (nf + 1);
            }
            continue;
        }
        int64_t d = pollard_rho_i64(m);
        stack[sp] = d;
        sp = (sp + 1);
        stack[sp] = FLOW_CHECKED_DIV((m), (d));
        sp = (sp + 1);
    }
    free(stack);
    return nf;
}

int64_t is_power_of_3_i64(int64_t n) {
    if (n <= 0) {
        return (-1);
    }
    int64_t k = 0;
    int64_t x = n;
    while (FLOW_CHECKED_MOD((x), (3)) == 0) {
        x = FLOW_CHECKED_DIV((x), (3));
        k = (k + 1);
    }
    if (x == 1) {
        return k;
    } else {
        return (-1);
    }
}

int64_t sigma_prime_power_i64_i64(int64_t p, int64_t e) {
    int64_t s = 1;
    int64_t pp = 1;
    int32_t __flow_step_3 = 1;
    for (int32_t i = 0; (0 <= e) ? i < e : i > e; i += (0 <= e) ? 1 : -1) {
        pp = (pp * p);
        s = (s + pp);
    }
    return s;
}

void vis_init(void) {
    g_vis_keys = calloc(VIS_HASH_SIZE, 8);
}

bool vis_check_or_add_i64(int64_t n) {
    int64_t h = FLOW_CHECKED_MOD((n), (VIS_HASH_SIZE));
    if (h < 0) {
        h = (h + VIS_HASH_SIZE);
    }
    while (g_vis_keys[h] != 0) {
        if (g_vis_keys[h] == n) {
            return 0;
        }
        h = (h + 1);
        if (h >= VIS_HASH_SIZE) {
            h = 0;
        }
    }
    g_vis_keys[h] = n;
    return 1;
}

void fac_cache_init(void) {
    g_fac_keys = calloc(FAC_HASH_SIZE, 8);
    g_fac_data = calloc((FAC_HASH_SIZE * 22), 8);
}

int64_t fac_cache_get_i64_ptr_i64_ptr_i64(int64_t x, int64_t* out_fps, int64_t* out_fes) {
    int64_t h = FLOW_CHECKED_MOD((x), (FAC_HASH_SIZE));
    if (h < 0) {
        h = (h + FAC_HASH_SIZE);
    }
    while (g_fac_keys[h] != 0) {
        if (g_fac_keys[h] == x) {
            int64_t base = (h * 22);
            int64_t nf = g_fac_data[base];
            int32_t __flow_step_4 = 1;
            for (int32_t i = 0; (0 <= nf) ? i < nf : i > nf; i += (0 <= nf) ? 1 : -1) {
                out_fps[i] = g_fac_data[((base + 1) + (i * 2))];
                out_fes[i] = g_fac_data[((base + 2) + (i * 2))];
            }
            return nf;
        }
        h = (h + 1);
        if (h >= FAC_HASH_SIZE) {
            h = 0;
        }
    }
    int64_t nf = factorize_i64_ptr_i64_ptr_i64(x, out_fps, out_fes);
    g_fac_keys[h] = x;
    int64_t base = (h * 22);
    g_fac_data[base] = nf;
    int32_t __flow_step_5 = 1;
    for (int32_t i = 0; (0 <= nf) ? i < nf : i > nf; i += (0 <= nf) ? 1 : -1) {
        g_fac_data[((base + 1) + (i * 2))] = out_fps[i];
        g_fac_data[((base + 2) + (i * 2))] = out_fes[i];
    }
    return nf;
}

void dfs_i64_i64_i64(int64_t n, int64_t num, int64_t den) {
    if ((!(vis_check_or_add_i64(n)))) {
        return;
    }
    int64_t k = is_power_of_3_i64(den);
    if (k > 0) {
        g_total = (g_total + n);
    }
    if (den == 1) {
        return;
    }
    if (FLOW_CHECKED_MOD((den), (3)) != 0) {
        return;
    }
    if (num == 1) {
        return;
    }
    int64_t* fps = (int64_t*)(calloc(64, 8));
    int64_t* fes = (int64_t*)(calloc(64, 8));
    int64_t nf = fac_cache_get_i64_ptr_i64_ptr_i64(num, fps, fes);
    int32_t __flow_step_6 = 1;
    for (int32_t i = 0; (0 <= nf) ? i < nf : i > nf; i += (0 <= nf) ? 1 : -1) {
        int64_t p = fps[i];
        if (p <= 5) {
            continue;
        }
        if (FLOW_CHECKED_MOD((n), (p)) == 0) {
            continue;
        }
        int64_t pp = 1;
        int32_t __flow_step_7 = 1;
        for (int32_t e = 1; (1 <= (fes[i] + 1)) ? e < (fes[i] + 1) : e > (fes[i] + 1); e += (1 <= (fes[i] + 1)) ? 1 : -1) {
            if (pp > FLOW_CHECKED_DIV((N), (p))) {
                break;
            }
            pp = (pp * p);
            if (n > FLOW_CHECKED_DIV((N), (pp))) {
                break;
            }
            int64_t sp = sigma_prime_power_i64_i64(p, e);
            int64_t new_num = (FLOW_CHECKED_DIV((num), (pp)) * sp);
            int64_t new_den = den;
            int64_t g = gcd_i64_i64(new_num, new_den);
            int64_t nn = FLOW_CHECKED_DIV((new_num), (g));
            int64_t nd = FLOW_CHECKED_DIV((new_den), (g));
            dfs_i64_i64_i64((n * pp), nn, nd);
        }
    }
    free(fes);
    free(fps);
}

int32_t main(void) {
    vis_init();
    fac_cache_init();
    int64_t* pow2 = (int64_t*)(calloc(50, 8));
    int64_t* pow3 = (int64_t*)(calloc(30, 8));
    int64_t* pow5 = (int64_t*)(calloc(30, 8));
    pow2[0] = 1;
    int64_t n2 = 1;
    int64_t a_max = 0;
    while ((pow2[a_max] * 2) <= N) {
        a_max = (a_max + 1);
        pow2[a_max] = (pow2[(a_max - 1)] * 2);
    }
    pow3[0] = 1;
    int64_t n3 = 1;
    int64_t b_max = 0;
    while ((pow3[b_max] * 3) <= N) {
        b_max = (b_max + 1);
        pow3[b_max] = (pow3[(b_max - 1)] * 3);
    }
    pow5[0] = 1;
    int64_t c_max = 0;
    while ((pow5[c_max] * 5) <= N) {
        c_max = (c_max + 1);
        pow5[c_max] = (pow5[(c_max - 1)] * 5);
    }
    int64_t* tmp_fps = (int64_t*)(calloc(64, 8));
    int64_t* tmp_fes = (int64_t*)(calloc(64, 8));
    int32_t __flow_step_8 = 1;
    for (int32_t a = 0; (0 <= (a_max + 1)) ? a < (a_max + 1) : a > (a_max + 1); a += (0 <= (a_max + 1)) ? 1 : -1) {
        int64_t pa = pow2[a];
        int64_t sig2;
        if (a > 0) {
            sig2 = ((pa * 2) - 1);
        } else {
            sig2 = 1;
        }
        int32_t __flow_step_9 = 1;
        for (int32_t b = 1; (1 <= (b_max + 1)) ? b < (b_max + 1) : b > (b_max + 1); b += (1 <= (b_max + 1)) ? 1 : -1) {
            int64_t pb = pow3[b];
            if ((pa * pb) > N) {
                break;
            }
            int64_t sig3 = FLOW_CHECKED_DIV((((pb * 3) - 1)), (2));
            int32_t __flow_step_10 = 1;
            for (int32_t c = 0; (0 <= (c_max + 1)) ? c < (c_max + 1) : c > (c_max + 1); c += (0 <= (c_max + 1)) ? 1 : -1) {
                int64_t pc = pow5[c];
                int64_t n = ((pa * pb) * pc);
                if (n > N) {
                    break;
                }
                int64_t sig5;
                if (c > 0) {
                    sig5 = FLOW_CHECKED_DIV((((pc * 5) - 1)), (4));
                } else {
                    sig5 = 1;
                }
                int64_t sig = ((sig2 * sig3) * sig5);
                int64_t g = gcd_i64_i64(n, sig);
                int64_t num = FLOW_CHECKED_DIV((sig), (g));
                int64_t den = FLOW_CHECKED_DIV((n), (g));
                if (FLOW_CHECKED_MOD((den), (3)) != 0) {
                    continue;
                }
                if (den == 1) {
                    continue;
                }
                dfs_i64_i64_i64(n, num, den);
            }
        }
    }
    printf("%lld\n", g_total);
    free(tmp_fes);
    free(tmp_fps);
    free(pow5);
    free(pow3);
    free(pow2);
    free(g_fac_data);
    free(g_fac_keys);
    free(g_vis_keys);
    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 @memset(!llvm.ptr, i64, i64) -> !llvm.ptr
  // Constant: N
  llvm.mlir.global internal constant @N(100000000000000 : i64) : i64
  // Module static: g_rng_state
  llvm.mlir.global internal @g_rng_state(42 : i64) : i64
  func.func @rng_next() -> i64 {
    %175 = llvm.mlir.addressof @g_rng_state : !llvm.ptr
    %176 = llvm.load %175 : !llvm.ptr -> i64
    %177 = arith.constant 6364136219551825709 : i32
    %179 = arith.extsi %177 : i32 to i64
    %178 = arith.muli %176, %179 : i64
    %180 = arith.constant 1442695036593996111 : i32
    %182 = arith.extsi %180 : i32 to i64
    %181 = arith.addi %178, %182 : i64
    %183 = llvm.mlir.addressof @g_rng_state : !llvm.ptr
    llvm.store %181, %183 : i64, !llvm.ptr
    %184 = llvm.mlir.addressof @g_rng_state : !llvm.ptr
    %185 = llvm.load %184 : !llvm.ptr -> i64
    func.return %185 : i64
  }
  func.func @rng_range(%arg0: i64, %arg1: i64) -> i64 {
    %186 = func.call @rng_next() : () -> i64
    %187 = arith.constant 0 : i32
    %189 = arith.extsi %187 : i32 to i64
    %188 = arith.cmpi slt, %186, %189 : i64
    %190 = scf.if %188 -> (i64) {
      %192 = arith.constant 0 : i64
      %191 = arith.subi %192, %186 : i64
      scf.yield %191 : i64
    } else {
      scf.yield %186 : i64
    }
    %193 = arith.subi %arg1, %arg0 : i64
    %194 = arith.constant 1 : i32
    %196 = arith.extsi %194 : i32 to i64
    %195 = arith.addi %193, %196 : i64
    %197 = arith.remsi %190, %195 : i64
    %198 = arith.addi %arg0, %197 : i64
    func.return %198 : i64
  }
  func.func @pollard_rho(%arg0: i64) -> i64 {
    %199 = arith.constant 2 : i32
    %201 = arith.extsi %199 : i32 to i64
    %200 = arith.remsi %arg0, %201 : i64
    %202 = arith.constant 0 : i32
    %204 = arith.extsi %202 : i32 to i64
    %203 = arith.cmpi eq, %200, %204 : i64
    cf.cond_br %203, ^bb42, ^bb43
    ^bb42:
      %205 = arith.constant 2 : i32
      %206 = arith.extsi %205 : i32 to i64
      func.return %206 : i64
    ^bb43:
      cf.br ^bb44
    ^bb44:
    %207 = arith.constant 3 : i32
    %209 = arith.extsi %207 : i32 to i64
    %208 = arith.remsi %arg0, %209 : i64
    %210 = arith.constant 0 : i32
    %212 = arith.extsi %210 : i32 to i64
    %211 = arith.cmpi eq, %208, %212 : i64
    cf.cond_br %211, ^bb45, ^bb46
    ^bb45:
      %213 = arith.constant 3 : i32
      %214 = arith.extsi %213 : i32 to i64
      func.return %214 : i64
    ^bb46:
      cf.br ^bb47
    ^bb47:
    cf.br ^bb48
    ^bb48:
    %215 = arith.constant 1 : i1
    cf.cond_br %215, ^bb49, ^bb50
    ^bb49:
      %217 = arith.constant 1 : i32
      %218 = arith.constant 1 : i32
      %220 = arith.extsi %218 : i32 to i64
      %219 = arith.subi %arg0, %220 : i64
      %221 = arith.extsi %217 : i32 to i64
      %216 = func.call @rng_range(%221, %219) : (i64, i64) -> i64
      %223 = arith.constant 0 : i32
      %224 = arith.constant 1 : i32
      %226 = arith.extsi %224 : i32 to i64
      %225 = arith.subi %arg0, %226 : i64
      %227 = arith.extsi %223 : i32 to i64
      %222 = func.call @rng_range(%227, %225) : (i64, i64) -> i64
      %228 = llvm.mlir.constant(1 : i64) : i64
      %229 = llvm.alloca %228 x i64 : (i64) -> !llvm.ptr
      llvm.store %222, %229 : i64, !llvm.ptr
      %230 = llvm.load %229 : !llvm.ptr -> i64
      %231 = llvm.mlir.constant(1 : i64) : i64
      %232 = llvm.alloca %231 x i64 : (i64) -> !llvm.ptr
      llvm.store %230, %232 : i64, !llvm.ptr
      %233 = arith.constant 1 : i32
      %234 = arith.extsi %233 : i32 to i64
      %235 = llvm.mlir.constant(1 : i64) : i64
      %236 = llvm.alloca %235 x i64 : (i64) -> !llvm.ptr
      llvm.store %234, %236 : i64, !llvm.ptr
      cf.br ^bb51
      ^bb51:
      %237 = llvm.load %236 : !llvm.ptr -> i64
      %238 = arith.constant 1 : i32
      %240 = arith.extsi %238 : i32 to i64
      %239 = arith.cmpi eq, %237, %240 : i64
      cf.cond_br %239, ^bb52, ^bb53
      ^bb52:
        %242 = llvm.load %229 : !llvm.ptr -> i64
        %243 = llvm.load %229 : !llvm.ptr -> i64
        %241 = func.call @mulmod(%242, %243, %arg0) : (i64, i64, i64) -> i64
        %244 = arith.addi %241, %216 : i64
        %245 = arith.remsi %244, %arg0 : i64
        llvm.store %245, %229 : i64, !llvm.ptr
        %247 = llvm.load %232 : !llvm.ptr -> i64
        %248 = llvm.load %232 : !llvm.ptr -> i64
        %246 = func.call @mulmod(%247, %248, %arg0) : (i64, i64, i64) -> i64
        %249 = arith.addi %246, %216 : i64
        %250 = arith.remsi %249, %arg0 : i64
        llvm.store %250, %232 : i64, !llvm.ptr
        %252 = llvm.load %232 : !llvm.ptr -> i64
        %253 = llvm.load %232 : !llvm.ptr -> i64
        %251 = func.call @mulmod(%252, %253, %arg0) : (i64, i64, i64) -> i64
        %254 = arith.addi %251, %216 : i64
        %255 = arith.remsi %254, %arg0 : i64
        llvm.store %255, %232 : i64, !llvm.ptr
        %256 = llvm.mlir.undef : i64
        %257 = llvm.load %229 : !llvm.ptr -> i64
        %258 = llvm.load %232 : !llvm.ptr -> i64
        %259 = arith.cmpi sgt, %257, %258 : i64
        %260 = scf.if %259 -> (i64) {
          %261 = llvm.load %229 : !llvm.ptr -> i64
          %262 = llvm.load %232 : !llvm.ptr -> i64
          %263 = arith.subi %261, %262 : i64
          scf.yield %263 : i64
        } else {
          %264 = llvm.load %232 : !llvm.ptr -> i64
          %265 = llvm.load %229 : !llvm.ptr -> i64
          %266 = arith.subi %264, %265 : i64
          scf.yield %266 : i64
        }
        %267 = func.call @gcd(%260, %arg0) : (i64, i64) -> i64
        llvm.store %267, %236 : i64, !llvm.ptr
        cf.br ^bb51
      ^bb53:
      %268 = llvm.load %236 : !llvm.ptr -> i64
      %269 = arith.cmpi ne, %268, %arg0 : i64
      cf.cond_br %269, ^bb54, ^bb55
      ^bb54:
        %270 = llvm.load %236 : !llvm.ptr -> i64
        func.return %270 : i64
      ^bb55:
        cf.br ^bb56
      ^bb56:
      cf.br ^bb48
    ^bb50:
    %271 = arith.constant 0 : i32
    %272 = arith.extsi %271 : i32 to i64
    func.return %272 : i64
  }
  func.func @factorize(%arg0: i64, %arg1: !llvm.ptr, %arg2: !llvm.ptr) -> i64 {
    %273 = arith.constant 0 : i32
    %274 = arith.extsi %273 : i32 to i64
    %275 = llvm.mlir.constant(1 : i64) : i64
    %276 = llvm.alloca %275 x i64 : (i64) -> !llvm.ptr
    llvm.store %274, %276 : i64, !llvm.ptr
    %277 = llvm.mlir.constant(1 : i64) : i64
    %278 = llvm.alloca %277 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %278 : i64, !llvm.ptr
    %279 = llvm.load %278 : !llvm.ptr -> i64
    %280 = arith.constant 1 : i32
    %282 = arith.extsi %280 : i32 to i64
    %281 = arith.cmpi eq, %279, %282 : i64
    cf.cond_br %281, ^bb57, ^bb58
    ^bb57:
      %283 = arith.constant 0 : i32
      %284 = arith.extsi %283 : i32 to i64
      func.return %284 : i64
    ^bb58:
      cf.br ^bb59
    ^bb59:
    %286 = arith.constant 12 : i32
    %287 = arith.constant 8 : i32
    %288 = arith.extsi %286 : i32 to i64
    %289 = arith.extsi %287 : i32 to i64
    %285 = func.call @calloc(%288, %289) : (i64, i64) -> !llvm.ptr
    %290 = arith.constant 2 : i32
    %291 = arith.constant 0 : i32
    %292 = arith.extsi %290 : i32 to i64
    %293 = arith.extsi %291 : i32 to i64
    %294 = llvm.getelementptr %285[%293] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %292, %294 : i64, !llvm.ptr
    %295 = arith.constant 3 : i32
    %296 = arith.constant 1 : i32
    %297 = arith.extsi %295 : i32 to i64
    %298 = arith.extsi %296 : i32 to i64
    %299 = llvm.getelementptr %285[%298] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %297, %299 : i64, !llvm.ptr
    %300 = arith.constant 5 : i32
    %301 = arith.constant 2 : i32
    %302 = arith.extsi %300 : i32 to i64
    %303 = arith.extsi %301 : i32 to i64
    %304 = llvm.getelementptr %285[%303] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %302, %304 : i64, !llvm.ptr
    %305 = arith.constant 7 : i32
    %306 = arith.constant 3 : i32
    %307 = arith.extsi %305 : i32 to i64
    %308 = arith.extsi %306 : i32 to i64
    %309 = llvm.getelementptr %285[%308] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %307, %309 : i64, !llvm.ptr
    %310 = arith.constant 11 : i32
    %311 = arith.constant 4 : i32
    %312 = arith.extsi %310 : i32 to i64
    %313 = arith.extsi %311 : i32 to i64
    %314 = llvm.getelementptr %285[%313] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %312, %314 : i64, !llvm.ptr
    %315 = arith.constant 13 : i32
    %316 = arith.constant 5 : i32
    %317 = arith.extsi %315 : i32 to i64
    %318 = arith.extsi %316 : i32 to i64
    %319 = llvm.getelementptr %285[%318] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %317, %319 : i64, !llvm.ptr
    %320 = arith.constant 17 : i32
    %321 = arith.constant 6 : i32
    %322 = arith.extsi %320 : i32 to i64
    %323 = arith.extsi %321 : i32 to i64
    %324 = llvm.getelementptr %285[%323] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %322, %324 : i64, !llvm.ptr
    %325 = arith.constant 19 : i32
    %326 = arith.constant 7 : i32
    %327 = arith.extsi %325 : i32 to i64
    %328 = arith.extsi %326 : i32 to i64
    %329 = llvm.getelementptr %285[%328] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %327, %329 : i64, !llvm.ptr
    %330 = arith.constant 23 : i32
    %331 = arith.constant 8 : i32
    %332 = arith.extsi %330 : i32 to i64
    %333 = arith.extsi %331 : i32 to i64
    %334 = llvm.getelementptr %285[%333] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %332, %334 : i64, !llvm.ptr
    %335 = arith.constant 29 : i32
    %336 = arith.constant 9 : i32
    %337 = arith.extsi %335 : i32 to i64
    %338 = arith.extsi %336 : i32 to i64
    %339 = llvm.getelementptr %285[%338] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %337, %339 : i64, !llvm.ptr
    %340 = arith.constant 31 : i32
    %341 = arith.constant 10 : i32
    %342 = arith.extsi %340 : i32 to i64
    %343 = arith.extsi %341 : i32 to i64
    %344 = llvm.getelementptr %285[%343] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %342, %344 : i64, !llvm.ptr
    %345 = arith.constant 37 : i32
    %346 = arith.constant 11 : i32
    %347 = arith.extsi %345 : i32 to i64
    %348 = arith.extsi %346 : i32 to i64
    %349 = llvm.getelementptr %285[%348] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %347, %349 : i64, !llvm.ptr
    %350 = arith.constant 0 : i32
    %351 = arith.constant 12 : i32
    %352 = arith.index_cast %350 : i32 to index
    %353 = arith.index_cast %351 : i32 to index
    %355 = arith.constant 1 : index
    %356 = arith.constant -1 : index
    %357 = arith.cmpi sle, %352, %353 : index
    %354 = arith.select %357, %355, %356 : index
    cf.br ^bb60(%352 : index)
    ^bb60(%358: index):
    %359 = arith.cmpi slt, %358, %353 : index
    %360 = arith.cmpi sgt, %358, %353 : index
    %361 = arith.select %357, %359, %360 : i1
    cf.cond_br %361, ^bb61(%358 : index), ^bb62(%358 : index)
    ^bb61(%362: index):
      %364 = arith.index_cast %362 : index to i64
      %365 = llvm.getelementptr %285[%364] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %363 = llvm.load %365 : !llvm.ptr -> i64
      %366 = llvm.load %278 : !llvm.ptr -> i64
      %367 = arith.remsi %366, %363 : i64
      %368 = arith.constant 0 : i32
      %370 = arith.extsi %368 : i32 to i64
      %369 = arith.cmpi eq, %367, %370 : i64
      cf.cond_br %369, ^bb63, ^bb64
      ^bb63:
        %371 = arith.constant 0 : i32
        %372 = arith.extsi %371 : i32 to i64
        %373 = llvm.mlir.constant(1 : i64) : i64
        %374 = llvm.alloca %373 x i64 : (i64) -> !llvm.ptr
        llvm.store %372, %374 : i64, !llvm.ptr
        cf.br ^bb66
        ^bb66:
        %375 = llvm.load %278 : !llvm.ptr -> i64
        %376 = arith.remsi %375, %363 : i64
        %377 = arith.constant 0 : i32
        %379 = arith.extsi %377 : i32 to i64
        %378 = arith.cmpi eq, %376, %379 : i64
        cf.cond_br %378, ^bb67, ^bb68
        ^bb67:
          %380 = llvm.load %278 : !llvm.ptr -> i64
          %381 = arith.divsi %380, %363 : i64
          llvm.store %381, %278 : i64, !llvm.ptr
          %382 = llvm.load %374 : !llvm.ptr -> i64
          %383 = arith.constant 1 : i32
          %385 = arith.extsi %383 : i32 to i64
          %384 = arith.addi %382, %385 : i64
          llvm.store %384, %374 : i64, !llvm.ptr
          cf.br ^bb66
        ^bb68:
        %386 = llvm.load %276 : !llvm.ptr -> i64
        %387 = llvm.getelementptr %arg1[%386] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %363, %387 : i64, !llvm.ptr
        %388 = llvm.load %374 : !llvm.ptr -> i64
        %389 = llvm.load %276 : !llvm.ptr -> i64
        %390 = llvm.getelementptr %arg2[%389] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %388, %390 : i64, !llvm.ptr
        %391 = llvm.load %276 : !llvm.ptr -> i64
        %392 = arith.constant 1 : i32
        %394 = arith.extsi %392 : i32 to i64
        %393 = arith.addi %391, %394 : i64
        llvm.store %393, %276 : i64, !llvm.ptr
        %395 = llvm.load %278 : !llvm.ptr -> i64
        %396 = arith.constant 1 : i32
        %398 = arith.extsi %396 : i32 to i64
        %397 = arith.cmpi eq, %395, %398 : i64
        cf.cond_br %397, ^bb69, ^bb70
        ^bb69:
          func.call @free(%285) : (!llvm.ptr) -> ()
          %400 = llvm.load %276 : !llvm.ptr -> i64
          func.return %400 : i64
        ^bb70:
          cf.br ^bb71
        ^bb71:
        cf.br ^bb65
      ^bb64:
        cf.br ^bb65
      ^bb65:
      %401 = arith.addi %362, %354 : index
      cf.br ^bb60(%401 : index)
    ^bb62(%402: index):
    func.call @free(%285) : (!llvm.ptr) -> ()
    %404 = llvm.load %278 : !llvm.ptr -> i64
    %405 = arith.constant 1 : i32
    %407 = arith.extsi %405 : i32 to i64
    %406 = arith.cmpi eq, %404, %407 : i64
    cf.cond_br %406, ^bb72, ^bb73
    ^bb72:
      %408 = llvm.load %276 : !llvm.ptr -> i64
      func.return %408 : i64
    ^bb73:
      cf.br ^bb74
    ^bb74:
    %410 = llvm.load %278 : !llvm.ptr -> i64
    %409 = func.call @is_prime(%410) : (i64) -> i1
    cf.cond_br %409, ^bb75, ^bb76
    ^bb75:
      %411 = llvm.load %278 : !llvm.ptr -> i64
      %412 = llvm.load %276 : !llvm.ptr -> i64
      %413 = llvm.getelementptr %arg1[%412] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %411, %413 : i64, !llvm.ptr
      %414 = arith.constant 1 : i32
      %415 = llvm.load %276 : !llvm.ptr -> i64
      %416 = arith.extsi %414 : i32 to i64
      %417 = llvm.getelementptr %arg2[%415] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %416, %417 : i64, !llvm.ptr
      %418 = llvm.load %276 : !llvm.ptr -> i64
      %419 = arith.constant 1 : i32
      %421 = arith.extsi %419 : i32 to i64
      %420 = arith.addi %418, %421 : i64
      func.return %420 : i64
    ^bb76:
      cf.br ^bb77
    ^bb77:
    %423 = arith.constant 100 : i32
    %424 = arith.constant 8 : i32
    %425 = arith.extsi %423 : i32 to i64
    %426 = arith.extsi %424 : i32 to i64
    %422 = func.call @calloc(%425, %426) : (i64, i64) -> !llvm.ptr
    %427 = arith.constant 0 : i32
    %428 = arith.extsi %427 : i32 to i64
    %429 = llvm.mlir.constant(1 : i64) : i64
    %430 = llvm.alloca %429 x i64 : (i64) -> !llvm.ptr
    llvm.store %428, %430 : i64, !llvm.ptr
    %431 = llvm.load %278 : !llvm.ptr -> i64
    %432 = llvm.load %430 : !llvm.ptr -> i64
    %433 = llvm.getelementptr %422[%432] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %431, %433 : i64, !llvm.ptr
    %434 = llvm.load %430 : !llvm.ptr -> i64
    %435 = arith.constant 1 : i32
    %437 = arith.extsi %435 : i32 to i64
    %436 = arith.addi %434, %437 : i64
    llvm.store %436, %430 : i64, !llvm.ptr
    cf.br ^bb78
    ^bb78:
    %438 = llvm.load %430 : !llvm.ptr -> i64
    %439 = arith.constant 0 : i32
    %441 = arith.extsi %439 : i32 to i64
    %440 = arith.cmpi sgt, %438, %441 : i64
    cf.cond_br %440, ^bb79, ^bb80
    ^bb79:
      %442 = llvm.load %430 : !llvm.ptr -> i64
      %443 = arith.constant 1 : i32
      %445 = arith.extsi %443 : i32 to i64
      %444 = arith.subi %442, %445 : i64
      llvm.store %444, %430 : i64, !llvm.ptr
      %447 = llvm.load %430 : !llvm.ptr -> i64
      %448 = llvm.getelementptr %422[%447] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %446 = llvm.load %448 : !llvm.ptr -> i64
      %449 = arith.constant 1 : i32
      %451 = arith.extsi %449 : i32 to i64
      %450 = arith.cmpi eq, %446, %451 : i64
      cf.cond_br %450, ^bb81, ^bb82
      ^bb81:
        cf.br ^bb78
      ^bb82:
        cf.br ^bb83
      ^bb83:
      %452 = func.call @is_prime(%446) : (i64) -> i1
      cf.cond_br %452, ^bb84, ^bb85
      ^bb84:
        %453 = arith.constant 1 : i32
        %455 = arith.constant 0 : i32
        %454 = arith.subi %455, %453 : i32
        %456 = arith.extsi %454 : i32 to i64
        %457 = llvm.mlir.constant(1 : i64) : i64
        %458 = llvm.alloca %457 x i64 : (i64) -> !llvm.ptr
        llvm.store %456, %458 : i64, !llvm.ptr
        %459 = arith.constant 0 : i32
        %460 = llvm.load %276 : !llvm.ptr -> i64
        %461 = arith.index_cast %459 : i32 to index
        %462 = arith.index_cast %460 : i32 to index
        %464 = arith.constant 1 : index
        %465 = arith.constant -1 : index
        %466 = arith.cmpi sle, %461, %462 : index
        %463 = arith.select %466, %464, %465 : index
        cf.br ^bb87(%461 : index)
        ^bb87(%467: index):
        %468 = arith.cmpi slt, %467, %462 : index
        %469 = arith.cmpi sgt, %467, %462 : index
        %470 = arith.select %466, %468, %469 : i1
        cf.cond_br %470, ^bb88(%467 : index), ^bb89(%467 : index)
        ^bb88(%471: index):
          %473 = arith.index_cast %471 : index to i64
          %474 = llvm.getelementptr %arg1[%473] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %472 = llvm.load %474 : !llvm.ptr -> i64
          %475 = arith.cmpi eq, %472, %446 : i64
          cf.cond_br %475, ^bb90, ^bb91
          ^bb90:
            %476 = arith.index_cast %471 : index to i64
            llvm.store %476, %458 : i64, !llvm.ptr
            cf.br ^bb92
          ^bb91:
            cf.br ^bb92
          ^bb92:
          %477 = arith.addi %471, %463 : index
          cf.br ^bb87(%477 : index)
        ^bb89(%478: index):
        %479 = llvm.load %458 : !llvm.ptr -> i64
        %480 = arith.constant 0 : i32
        %482 = arith.extsi %480 : i32 to i64
        %481 = arith.cmpi sge, %479, %482 : i64
        cf.cond_br %481, ^bb93, ^bb94
        ^bb93:
          %484 = llvm.load %458 : !llvm.ptr -> i64
          %485 = llvm.getelementptr %arg2[%484] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %483 = llvm.load %485 : !llvm.ptr -> i64
          %486 = arith.constant 1 : i32
          %488 = arith.extsi %486 : i32 to i64
          %487 = arith.addi %483, %488 : i64
          %489 = llvm.load %458 : !llvm.ptr -> i64
          %490 = llvm.getelementptr %arg2[%489] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          llvm.store %487, %490 : i64, !llvm.ptr
          cf.br ^bb95
        ^bb94:
          %491 = llvm.load %276 : !llvm.ptr -> i64
          %492 = llvm.getelementptr %arg1[%491] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          llvm.store %446, %492 : i64, !llvm.ptr
          %493 = arith.constant 1 : i32
          %494 = llvm.load %276 : !llvm.ptr -> i64
          %495 = arith.extsi %493 : i32 to i64
          %496 = llvm.getelementptr %arg2[%494] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          llvm.store %495, %496 : i64, !llvm.ptr
          %497 = llvm.load %276 : !llvm.ptr -> i64
          %498 = arith.constant 1 : i32
          %500 = arith.extsi %498 : i32 to i64
          %499 = arith.addi %497, %500 : i64
          llvm.store %499, %276 : i64, !llvm.ptr
          cf.br ^bb95
        ^bb95:
        cf.br ^bb78
      ^bb85:
        cf.br ^bb86
      ^bb86:
      %501 = func.call @pollard_rho(%446) : (i64) -> i64
      %502 = llvm.load %430 : !llvm.ptr -> i64
      %503 = llvm.getelementptr %422[%502] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %501, %503 : i64, !llvm.ptr
      %504 = llvm.load %430 : !llvm.ptr -> i64
      %505 = arith.constant 1 : i32
      %507 = arith.extsi %505 : i32 to i64
      %506 = arith.addi %504, %507 : i64
      llvm.store %506, %430 : i64, !llvm.ptr
      %508 = arith.divsi %446, %501 : i64
      %509 = llvm.load %430 : !llvm.ptr -> i64
      %510 = llvm.getelementptr %422[%509] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %508, %510 : i64, !llvm.ptr
      %511 = llvm.load %430 : !llvm.ptr -> i64
      %512 = arith.constant 1 : i32
      %514 = arith.extsi %512 : i32 to i64
      %513 = arith.addi %511, %514 : i64
      llvm.store %513, %430 : i64, !llvm.ptr
      cf.br ^bb78
    ^bb80:
    func.call @free(%422) : (!llvm.ptr) -> ()
    %516 = llvm.load %276 : !llvm.ptr -> i64
    func.return %516 : i64
  }
  func.func @is_power_of_3(%arg0: i64) -> i64 {
    %517 = arith.constant 0 : i32
    %519 = arith.extsi %517 : i32 to i64
    %518 = arith.cmpi sle, %arg0, %519 : i64
    cf.cond_br %518, ^bb96, ^bb97
    ^bb96:
      %520 = arith.constant 1 : i32
      %522 = arith.constant 0 : i32
      %521 = arith.subi %522, %520 : i32
      %523 = arith.extsi %521 : i32 to i64
      func.return %523 : i64
    ^bb97:
      cf.br ^bb98
    ^bb98:
    %524 = arith.constant 0 : i32
    %525 = arith.extsi %524 : i32 to i64
    %526 = llvm.mlir.constant(1 : i64) : i64
    %527 = llvm.alloca %526 x i64 : (i64) -> !llvm.ptr
    llvm.store %525, %527 : i64, !llvm.ptr
    %528 = llvm.mlir.constant(1 : i64) : i64
    %529 = llvm.alloca %528 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %529 : i64, !llvm.ptr
    cf.br ^bb99
    ^bb99:
    %530 = llvm.load %529 : !llvm.ptr -> i64
    %531 = arith.constant 3 : i32
    %533 = arith.extsi %531 : i32 to i64
    %532 = arith.remsi %530, %533 : i64
    %534 = arith.constant 0 : i32
    %536 = arith.extsi %534 : i32 to i64
    %535 = arith.cmpi eq, %532, %536 : i64
    cf.cond_br %535, ^bb100, ^bb101
    ^bb100:
      %537 = llvm.load %529 : !llvm.ptr -> i64
      %538 = arith.constant 3 : i32
      %540 = arith.extsi %538 : i32 to i64
      %539 = arith.divsi %537, %540 : i64
      llvm.store %539, %529 : i64, !llvm.ptr
      %541 = llvm.load %527 : !llvm.ptr -> i64
      %542 = arith.constant 1 : i32
      %544 = arith.extsi %542 : i32 to i64
      %543 = arith.addi %541, %544 : i64
      llvm.store %543, %527 : i64, !llvm.ptr
      cf.br ^bb99
    ^bb101:
    %545 = llvm.load %529 : !llvm.ptr -> i64
    %546 = arith.constant 1 : i32
    %548 = arith.extsi %546 : i32 to i64
    %547 = arith.cmpi eq, %545, %548 : i64
    cf.cond_br %547, ^bb102, ^bb103
    ^bb102:
      %549 = llvm.load %527 : !llvm.ptr -> i64
      func.return %549 : i64
    ^bb103:
      %550 = arith.constant 1 : i32
      %552 = arith.constant 0 : i32
      %551 = arith.subi %552, %550 : i32
      %553 = arith.extsi %551 : i32 to i64
      func.return %553 : i64
  }
  func.func @sigma_prime_power(%arg0: i64, %arg1: i64) -> i64 {
    %554 = arith.constant 1 : i32
    %555 = arith.extsi %554 : i32 to i64
    %556 = llvm.mlir.constant(1 : i64) : i64
    %557 = llvm.alloca %556 x i64 : (i64) -> !llvm.ptr
    llvm.store %555, %557 : i64, !llvm.ptr
    %558 = arith.constant 1 : i32
    %559 = arith.extsi %558 : i32 to i64
    %560 = llvm.mlir.constant(1 : i64) : i64
    %561 = llvm.alloca %560 x i64 : (i64) -> !llvm.ptr
    llvm.store %559, %561 : i64, !llvm.ptr
    %562 = arith.constant 0 : i32
    %563 = arith.index_cast %562 : i32 to index
    %564 = arith.index_cast %arg1 : i32 to index
    %566 = arith.constant 1 : index
    %567 = arith.constant -1 : index
    %568 = arith.cmpi sle, %563, %564 : index
    %565 = arith.select %568, %566, %567 : index
    cf.br ^bb105(%563 : index)
    ^bb105(%569: index):
    %570 = arith.cmpi slt, %569, %564 : index
    %571 = arith.cmpi sgt, %569, %564 : index
    %572 = arith.select %568, %570, %571 : i1
    cf.cond_br %572, ^bb106(%569 : index), ^bb107(%569 : index)
    ^bb106(%573: index):
      %574 = llvm.load %561 : !llvm.ptr -> i64
      %575 = arith.muli %574, %arg0 : i64
      llvm.store %575, %561 : i64, !llvm.ptr
      %576 = llvm.load %557 : !llvm.ptr -> i64
      %577 = llvm.load %561 : !llvm.ptr -> i64
      %578 = arith.addi %576, %577 : i64
      llvm.store %578, %557 : i64, !llvm.ptr
      %579 = arith.addi %573, %565 : index
      cf.br ^bb105(%579 : index)
    ^bb107(%580: index):
    %581 = llvm.load %557 : !llvm.ptr -> i64
    func.return %581 : i64
  }
  // Constant: VIS_HASH_SIZE
  llvm.mlir.global internal constant @VIS_HASH_SIZE(20000003 : i64) : i64
  // Module static: g_vis_keys
  llvm.mlir.global internal @g_vis_keys() {addr_space = 0 : i32} : !llvm.ptr {
    %582 = llvm.mlir.zero : !llvm.ptr
    llvm.return %582 : !llvm.ptr
  }
  func.func @vis_init() -> () {
    %584 = llvm.mlir.addressof @VIS_HASH_SIZE : !llvm.ptr
    %585 = llvm.load %584 : !llvm.ptr -> i64
    %586 = arith.constant 8 : i32
    %587 = arith.extsi %586 : i32 to i64
    %583 = func.call @calloc(%585, %587) : (i64, i64) -> !llvm.ptr
    %588 = llvm.mlir.addressof @g_vis_keys : !llvm.ptr
    llvm.store %583, %588 : !llvm.ptr, !llvm.ptr
    func.return
  }
  func.func @vis_check_or_add(%arg0: i64) -> i1 {
    %589 = llvm.mlir.addressof @VIS_HASH_SIZE : !llvm.ptr
    %590 = llvm.load %589 : !llvm.ptr -> i64
    %591 = arith.remsi %arg0, %590 : i64
    %592 = llvm.mlir.constant(1 : i64) : i64
    %593 = llvm.alloca %592 x i64 : (i64) -> !llvm.ptr
    llvm.store %591, %593 : i64, !llvm.ptr
    %594 = llvm.load %593 : !llvm.ptr -> i64
    %595 = arith.constant 0 : i32
    %597 = arith.extsi %595 : i32 to i64
    %596 = arith.cmpi slt, %594, %597 : i64
    cf.cond_br %596, ^bb108, ^bb109
    ^bb108:
      %598 = llvm.load %593 : !llvm.ptr -> i64
      %599 = llvm.mlir.addressof @VIS_HASH_SIZE : !llvm.ptr
      %600 = llvm.load %599 : !llvm.ptr -> i64
      %601 = arith.addi %598, %600 : i64
      llvm.store %601, %593 : i64, !llvm.ptr
      cf.br ^bb110
    ^bb109:
      cf.br ^bb110
    ^bb110:
    cf.br ^bb111
    ^bb111:
    %603 = llvm.mlir.addressof @g_vis_keys : !llvm.ptr
    %604 = llvm.load %603 : !llvm.ptr -> !llvm.ptr
    %605 = llvm.load %593 : !llvm.ptr -> i64
    %606 = llvm.getelementptr %604[%605] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %602 = llvm.load %606 : !llvm.ptr -> i64
    %607 = arith.constant 0 : i32
    %609 = arith.extsi %607 : i32 to i64
    %608 = arith.cmpi ne, %602, %609 : i64
    cf.cond_br %608, ^bb112, ^bb113
    ^bb112:
      %611 = llvm.mlir.addressof @g_vis_keys : !llvm.ptr
      %612 = llvm.load %611 : !llvm.ptr -> !llvm.ptr
      %613 = llvm.load %593 : !llvm.ptr -> i64
      %614 = llvm.getelementptr %612[%613] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %610 = llvm.load %614 : !llvm.ptr -> i64
      %615 = arith.cmpi eq, %610, %arg0 : i64
      cf.cond_br %615, ^bb114, ^bb115
      ^bb114:
        %616 = arith.constant 0 : i1
        func.return %616 : i1
      ^bb115:
        cf.br ^bb116
      ^bb116:
      %617 = llvm.load %593 : !llvm.ptr -> i64
      %618 = arith.constant 1 : i32
      %620 = arith.extsi %618 : i32 to i64
      %619 = arith.addi %617, %620 : i64
      llvm.store %619, %593 : i64, !llvm.ptr
      %621 = llvm.load %593 : !llvm.ptr -> i64
      %622 = llvm.mlir.addressof @VIS_HASH_SIZE : !llvm.ptr
      %623 = llvm.load %622 : !llvm.ptr -> i64
      %624 = arith.cmpi sge, %621, %623 : i64
      cf.cond_br %624, ^bb117, ^bb118
      ^bb117:
        %625 = arith.constant 0 : i32
        %626 = arith.extsi %625 : i32 to i64
        llvm.store %626, %593 : i64, !llvm.ptr
        cf.br ^bb119
      ^bb118:
        cf.br ^bb119
      ^bb119:
      cf.br ^bb111
    ^bb113:
    %627 = llvm.mlir.addressof @g_vis_keys : !llvm.ptr
    %628 = llvm.load %627 : !llvm.ptr -> !llvm.ptr
    %629 = llvm.load %593 : !llvm.ptr -> i64
    %630 = llvm.getelementptr %628[%629] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %arg0, %630 : i64, !llvm.ptr
    %631 = arith.constant 1 : i1
    func.return %631 : i1
  }
  // Constant: FAC_HASH_SIZE
  llvm.mlir.global internal constant @FAC_HASH_SIZE(20000003 : i64) : i64
  // Module static: g_fac_keys
  llvm.mlir.global internal @g_fac_keys() {addr_space = 0 : i32} : !llvm.ptr {
    %632 = llvm.mlir.zero : !llvm.ptr
    llvm.return %632 : !llvm.ptr
  }
  // Module static: g_fac_data
  llvm.mlir.global internal @g_fac_data() {addr_space = 0 : i32} : !llvm.ptr {
    %633 = llvm.mlir.zero : !llvm.ptr
    llvm.return %633 : !llvm.ptr
  }
  func.func @fac_cache_init() -> () {
    %635 = llvm.mlir.addressof @FAC_HASH_SIZE : !llvm.ptr
    %636 = llvm.load %635 : !llvm.ptr -> i64
    %637 = arith.constant 8 : i32
    %638 = arith.extsi %637 : i32 to i64
    %634 = func.call @calloc(%636, %638) : (i64, i64) -> !llvm.ptr
    %639 = llvm.mlir.addressof @g_fac_keys : !llvm.ptr
    llvm.store %634, %639 : !llvm.ptr, !llvm.ptr
    %641 = llvm.mlir.addressof @FAC_HASH_SIZE : !llvm.ptr
    %642 = llvm.load %641 : !llvm.ptr -> i64
    %643 = arith.constant 22 : i32
    %645 = arith.extsi %643 : i32 to i64
    %644 = arith.muli %642, %645 : i64
    %646 = arith.constant 8 : i32
    %647 = arith.extsi %646 : i32 to i64
    %640 = func.call @calloc(%644, %647) : (i64, i64) -> !llvm.ptr
    %648 = llvm.mlir.addressof @g_fac_data : !llvm.ptr
    llvm.store %640, %648 : !llvm.ptr, !llvm.ptr
    func.return
  }
  func.func @fac_cache_get(%arg0: i64, %arg1: !llvm.ptr, %arg2: !llvm.ptr) -> i64 {
    %649 = llvm.mlir.addressof @FAC_HASH_SIZE : !llvm.ptr
    %650 = llvm.load %649 : !llvm.ptr -> i64
    %651 = arith.remsi %arg0, %650 : i64
    %652 = llvm.mlir.constant(1 : i64) : i64
    %653 = llvm.alloca %652 x i64 : (i64) -> !llvm.ptr
    llvm.store %651, %653 : i64, !llvm.ptr
    %654 = llvm.load %653 : !llvm.ptr -> i64
    %655 = arith.constant 0 : i32
    %657 = arith.extsi %655 : i32 to i64
    %656 = arith.cmpi slt, %654, %657 : i64
    cf.cond_br %656, ^bb120, ^bb121
    ^bb120:
      %658 = llvm.load %653 : !llvm.ptr -> i64
      %659 = llvm.mlir.addressof @FAC_HASH_SIZE : !llvm.ptr
      %660 = llvm.load %659 : !llvm.ptr -> i64
      %661 = arith.addi %658, %660 : i64
      llvm.store %661, %653 : i64, !llvm.ptr
      cf.br ^bb122
    ^bb121:
      cf.br ^bb122
    ^bb122:
    cf.br ^bb123
    ^bb123:
    %663 = llvm.mlir.addressof @g_fac_keys : !llvm.ptr
    %664 = llvm.load %663 : !llvm.ptr -> !llvm.ptr
    %665 = llvm.load %653 : !llvm.ptr -> i64
    %666 = llvm.getelementptr %664[%665] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %662 = llvm.load %666 : !llvm.ptr -> i64
    %667 = arith.constant 0 : i32
    %669 = arith.extsi %667 : i32 to i64
    %668 = arith.cmpi ne, %662, %669 : i64
    cf.cond_br %668, ^bb124, ^bb125
    ^bb124:
      %671 = llvm.mlir.addressof @g_fac_keys : !llvm.ptr
      %672 = llvm.load %671 : !llvm.ptr -> !llvm.ptr
      %673 = llvm.load %653 : !llvm.ptr -> i64
      %674 = llvm.getelementptr %672[%673] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %670 = llvm.load %674 : !llvm.ptr -> i64
      %675 = arith.cmpi eq, %670, %arg0 : i64
      cf.cond_br %675, ^bb126, ^bb127
      ^bb126:
        %676 = llvm.load %653 : !llvm.ptr -> i64
        %677 = arith.constant 22 : i32
        %679 = arith.extsi %677 : i32 to i64
        %678 = arith.muli %676, %679 : i64
        %681 = llvm.mlir.addressof @g_fac_data : !llvm.ptr
        %682 = llvm.load %681 : !llvm.ptr -> !llvm.ptr
        %683 = llvm.getelementptr %682[%678] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %680 = llvm.load %683 : !llvm.ptr -> i64
        %684 = arith.constant 0 : i32
        %685 = arith.index_cast %684 : i32 to index
        %686 = arith.index_cast %680 : i32 to index
        %688 = arith.constant 1 : index
        %689 = arith.constant -1 : index
        %690 = arith.cmpi sle, %685, %686 : index
        %687 = arith.select %690, %688, %689 : index
        cf.br ^bb129(%685 : index)
        ^bb129(%691: index):
        %692 = arith.cmpi slt, %691, %686 : index
        %693 = arith.cmpi sgt, %691, %686 : index
        %694 = arith.select %690, %692, %693 : i1
        cf.cond_br %694, ^bb130(%691 : index), ^bb131(%691 : index)
        ^bb130(%695: index):
          %697 = llvm.mlir.addressof @g_fac_data : !llvm.ptr
          %698 = llvm.load %697 : !llvm.ptr -> !llvm.ptr
          %699 = arith.constant 1 : i32
          %701 = arith.extsi %699 : i32 to i64
          %700 = arith.addi %678, %701 : i64
          %702 = arith.constant 2 : i32
          %704 = arith.index_cast %695 : index to i32
          %703 = arith.muli %704, %702 : i32
          %706 = arith.extsi %703 : i32 to i64
          %705 = arith.addi %700, %706 : i64
          %707 = llvm.getelementptr %698[%705] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %696 = llvm.load %707 : !llvm.ptr -> i64
          %708 = arith.index_cast %695 : index to i64
          %709 = llvm.getelementptr %arg1[%708] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          llvm.store %696, %709 : i64, !llvm.ptr
          %711 = llvm.mlir.addressof @g_fac_data : !llvm.ptr
          %712 = llvm.load %711 : !llvm.ptr -> !llvm.ptr
          %713 = arith.constant 2 : i32
          %715 = arith.extsi %713 : i32 to i64
          %714 = arith.addi %678, %715 : i64
          %716 = arith.constant 2 : i32
          %718 = arith.index_cast %695 : index to i32
          %717 = arith.muli %718, %716 : i32
          %720 = arith.extsi %717 : i32 to i64
          %719 = arith.addi %714, %720 : i64
          %721 = llvm.getelementptr %712[%719] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %710 = llvm.load %721 : !llvm.ptr -> i64
          %722 = arith.index_cast %695 : index to i64
          %723 = llvm.getelementptr %arg2[%722] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          llvm.store %710, %723 : i64, !llvm.ptr
          %724 = arith.addi %695, %687 : index
          cf.br ^bb129(%724 : index)
        ^bb131(%725: index):
        func.return %680 : i64
      ^bb127:
        cf.br ^bb128
      ^bb128:
      %726 = llvm.load %653 : !llvm.ptr -> i64
      %727 = arith.constant 1 : i32
      %729 = arith.extsi %727 : i32 to i64
      %728 = arith.addi %726, %729 : i64
      llvm.store %728, %653 : i64, !llvm.ptr
      %730 = llvm.load %653 : !llvm.ptr -> i64
      %731 = llvm.mlir.addressof @FAC_HASH_SIZE : !llvm.ptr
      %732 = llvm.load %731 : !llvm.ptr -> i64
      %733 = arith.cmpi sge, %730, %732 : i64
      cf.cond_br %733, ^bb132, ^bb133
      ^bb132:
        %734 = arith.constant 0 : i32
        %735 = arith.extsi %734 : i32 to i64
        llvm.store %735, %653 : i64, !llvm.ptr
        cf.br ^bb134
      ^bb133:
        cf.br ^bb134
      ^bb134:
      cf.br ^bb123
    ^bb125:
    %736 = func.call @factorize(%arg0, %arg1, %arg2) : (i64, !llvm.ptr, !llvm.ptr) -> i64
    %737 = llvm.mlir.addressof @g_fac_keys : !llvm.ptr
    %738 = llvm.load %737 : !llvm.ptr -> !llvm.ptr
    %739 = llvm.load %653 : !llvm.ptr -> i64
    %740 = llvm.getelementptr %738[%739] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %arg0, %740 : i64, !llvm.ptr
    %741 = llvm.load %653 : !llvm.ptr -> i64
    %742 = arith.constant 22 : i32
    %744 = arith.extsi %742 : i32 to i64
    %743 = arith.muli %741, %744 : i64
    %745 = llvm.mlir.addressof @g_fac_data : !llvm.ptr
    %746 = llvm.load %745 : !llvm.ptr -> !llvm.ptr
    %747 = llvm.getelementptr %746[%743] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %736, %747 : i64, !llvm.ptr
    %748 = arith.constant 0 : i32
    %749 = arith.index_cast %748 : i32 to index
    %750 = arith.index_cast %736 : i32 to index
    %752 = arith.constant 1 : index
    %753 = arith.constant -1 : index
    %754 = arith.cmpi sle, %749, %750 : index
    %751 = arith.select %754, %752, %753 : index
    cf.br ^bb135(%749 : index)
    ^bb135(%755: index):
    %756 = arith.cmpi slt, %755, %750 : index
    %757 = arith.cmpi sgt, %755, %750 : index
    %758 = arith.select %754, %756, %757 : i1
    cf.cond_br %758, ^bb136(%755 : index), ^bb137(%755 : index)
    ^bb136(%759: index):
      %761 = arith.index_cast %759 : index to i64
      %762 = llvm.getelementptr %arg1[%761] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %760 = llvm.load %762 : !llvm.ptr -> i64
      %763 = llvm.mlir.addressof @g_fac_data : !llvm.ptr
      %764 = llvm.load %763 : !llvm.ptr -> !llvm.ptr
      %765 = arith.constant 1 : i32
      %767 = arith.extsi %765 : i32 to i64
      %766 = arith.addi %743, %767 : i64
      %768 = arith.constant 2 : i32
      %770 = arith.index_cast %759 : index to i32
      %769 = arith.muli %770, %768 : i32
      %772 = arith.extsi %769 : i32 to i64
      %771 = arith.addi %766, %772 : i64
      %773 = llvm.getelementptr %764[%771] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %760, %773 : i64, !llvm.ptr
      %775 = arith.index_cast %759 : index to i64
      %776 = llvm.getelementptr %arg2[%775] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %774 = llvm.load %776 : !llvm.ptr -> i64
      %777 = llvm.mlir.addressof @g_fac_data : !llvm.ptr
      %778 = llvm.load %777 : !llvm.ptr -> !llvm.ptr
      %779 = arith.constant 2 : i32
      %781 = arith.extsi %779 : i32 to i64
      %780 = arith.addi %743, %781 : i64
      %782 = arith.constant 2 : i32
      %784 = arith.index_cast %759 : index to i32
      %783 = arith.muli %784, %782 : i32
      %786 = arith.extsi %783 : i32 to i64
      %785 = arith.addi %780, %786 : i64
      %787 = llvm.getelementptr %778[%785] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %774, %787 : i64, !llvm.ptr
      %788 = arith.addi %759, %751 : index
      cf.br ^bb135(%788 : index)
    ^bb137(%789: index):
    func.return %736 : i64
  }
  // Module static: g_total
  llvm.mlir.global internal @g_total(0 : i64) : i64
  func.func @dfs(%arg0: i64, %arg1: i64, %arg2: i64) -> () {
    %790 = func.call @vis_check_or_add(%arg0) : (i64) -> i1
    %792 = arith.constant 1 : i1
    %791 = arith.xori %790, %792 : i1
    cf.cond_br %791, ^bb138, ^bb139
    ^bb138:
      func.return
    ^bb139:
      cf.br ^bb140
    ^bb140:
    %794 = func.call @is_power_of_3(%arg2) : (i64) -> i64
    %795 = arith.constant 0 : i32
    %797 = arith.extsi %795 : i32 to i64
    %796 = arith.cmpi sgt, %794, %797 : i64
    cf.cond_br %796, ^bb141, ^bb142
    ^bb141:
      %798 = llvm.mlir.addressof @g_total : !llvm.ptr
      %799 = llvm.load %798 : !llvm.ptr -> i64
      %800 = arith.addi %799, %arg0 : i64
      %801 = llvm.mlir.addressof @g_total : !llvm.ptr
      llvm.store %800, %801 : i64, !llvm.ptr
      cf.br ^bb143
    ^bb142:
      cf.br ^bb143
    ^bb143:
    %802 = arith.constant 1 : i32
    %804 = arith.extsi %802 : i32 to i64
    %803 = arith.cmpi eq, %arg2, %804 : i64
    cf.cond_br %803, ^bb144, ^bb145
    ^bb144:
      func.return
    ^bb145:
      cf.br ^bb146
    ^bb146:
    %805 = arith.constant 3 : i32
    %807 = arith.extsi %805 : i32 to i64
    %806 = arith.remsi %arg2, %807 : i64
    %808 = arith.constant 0 : i32
    %810 = arith.extsi %808 : i32 to i64
    %809 = arith.cmpi ne, %806, %810 : i64
    cf.cond_br %809, ^bb147, ^bb148
    ^bb147:
      func.return
    ^bb148:
      cf.br ^bb149
    ^bb149:
    %811 = arith.constant 1 : i32
    %813 = arith.extsi %811 : i32 to i64
    %812 = arith.cmpi eq, %arg1, %813 : i64
    cf.cond_br %812, ^bb150, ^bb151
    ^bb150:
      func.return
    ^bb151:
      cf.br ^bb152
    ^bb152:
    %815 = arith.constant 64 : i32
    %816 = arith.constant 8 : i32
    %817 = arith.extsi %815 : i32 to i64
    %818 = arith.extsi %816 : i32 to i64
    %814 = func.call @calloc(%817, %818) : (i64, i64) -> !llvm.ptr
    %820 = arith.constant 64 : i32
    %821 = arith.constant 8 : i32
    %822 = arith.extsi %820 : i32 to i64
    %823 = arith.extsi %821 : i32 to i64
    %819 = func.call @calloc(%822, %823) : (i64, i64) -> !llvm.ptr
    %824 = func.call @fac_cache_get(%arg1, %814, %819) : (i64, !llvm.ptr, !llvm.ptr) -> i64
    %825 = arith.constant 0 : i32
    %826 = arith.index_cast %825 : i32 to index
    %827 = arith.index_cast %824 : i32 to index
    %829 = arith.constant 1 : index
    %830 = arith.constant -1 : index
    %831 = arith.cmpi sle, %826, %827 : index
    %828 = arith.select %831, %829, %830 : index
    cf.br ^bb153(%826 : index)
    ^bb153(%832: index):
    %833 = arith.cmpi slt, %832, %827 : index
    %834 = arith.cmpi sgt, %832, %827 : index
    %835 = arith.select %831, %833, %834 : i1
    cf.cond_br %835, ^bb154(%832 : index), ^bb155(%832 : index)
    ^bb154(%836: index):
      %838 = arith.index_cast %836 : index to i64
      %839 = llvm.getelementptr %814[%838] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %837 = llvm.load %839 : !llvm.ptr -> i64
      %840 = arith.constant 5 : i32
      %842 = arith.extsi %840 : i32 to i64
      %841 = arith.cmpi sle, %837, %842 : i64
      cf.cond_br %841, ^bb156, ^bb157
      ^bb156:
        %843 = arith.addi %836, %828 : index
        cf.br ^bb153(%843 : index)
      ^bb157:
        cf.br ^bb158
      ^bb158:
      %844 = arith.remsi %arg0, %837 : i64
      %845 = arith.constant 0 : i32
      %847 = arith.extsi %845 : i32 to i64
      %846 = arith.cmpi eq, %844, %847 : i64
      cf.cond_br %846, ^bb159, ^bb160
      ^bb159:
        %848 = arith.addi %836, %828 : index
        cf.br ^bb153(%848 : index)
      ^bb160:
        cf.br ^bb161
      ^bb161:
      %849 = arith.constant 1 : i32
      %850 = arith.extsi %849 : i32 to i64
      %851 = llvm.mlir.constant(1 : i64) : i64
      %852 = llvm.alloca %851 x i64 : (i64) -> !llvm.ptr
      llvm.store %850, %852 : i64, !llvm.ptr
      %853 = arith.constant 1 : i32
      %855 = arith.index_cast %836 : index to i64
      %856 = llvm.getelementptr %819[%855] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %854 = llvm.load %856 : !llvm.ptr -> i64
      %857 = arith.constant 1 : i32
      %859 = arith.extsi %857 : i32 to i64
      %858 = arith.addi %854, %859 : i64
      %860 = arith.index_cast %853 : i32 to index
      %861 = arith.index_cast %858 : i32 to index
      %863 = arith.constant 1 : index
      %864 = arith.constant -1 : index
      %865 = arith.cmpi sle, %860, %861 : index
      %862 = arith.select %865, %863, %864 : index
      cf.br ^bb162(%860 : index)
      ^bb162(%866: index):
      %867 = arith.cmpi slt, %866, %861 : index
      %868 = arith.cmpi sgt, %866, %861 : index
      %869 = arith.select %865, %867, %868 : i1
      cf.cond_br %869, ^bb163(%866 : index), ^bb164(%866 : index)
      ^bb163(%870: index):
        %871 = llvm.load %852 : !llvm.ptr -> i64
        %872 = llvm.mlir.addressof @N : !llvm.ptr
        %873 = llvm.load %872 : !llvm.ptr -> i64
        %874 = arith.divsi %873, %837 : i64
        %875 = arith.cmpi sgt, %871, %874 : i64
        cf.cond_br %875, ^bb165, ^bb166
        ^bb165:
          cf.br ^bb164(%870 : index)
        ^bb166:
          cf.br ^bb167
        ^bb167:
        %876 = llvm.load %852 : !llvm.ptr -> i64
        %877 = arith.muli %876, %837 : i64
        llvm.store %877, %852 : i64, !llvm.ptr
        %878 = llvm.mlir.addressof @N : !llvm.ptr
        %879 = llvm.load %878 : !llvm.ptr -> i64
        %880 = llvm.load %852 : !llvm.ptr -> i64
        %881 = arith.divsi %879, %880 : i64
        %882 = arith.cmpi sgt, %arg0, %881 : i64
        cf.cond_br %882, ^bb168, ^bb169
        ^bb168:
          cf.br ^bb164(%870 : index)
        ^bb169:
          cf.br ^bb170
        ^bb170:
        %884 = arith.index_cast %870 : index to i64
        %883 = func.call @sigma_prime_power(%837, %884) : (i64, i64) -> i64
        %885 = llvm.load %852 : !llvm.ptr -> i64
        %886 = arith.divsi %arg1, %885 : i64
        %887 = arith.muli %886, %883 : i64
        %888 = llvm.mlir.constant(1 : i64) : i64
        %889 = llvm.alloca %888 x i64 : (i64) -> !llvm.ptr
        llvm.store %arg2, %889 : i64, !llvm.ptr
        %891 = llvm.load %889 : !llvm.ptr -> i64
        %890 = func.call @gcd(%887, %891) : (i64, i64) -> i64
        %892 = arith.divsi %887, %890 : i64
        %893 = llvm.load %889 : !llvm.ptr -> i64
        %894 = arith.divsi %893, %890 : i64
        %896 = llvm.load %852 : !llvm.ptr -> i64
        %897 = arith.muli %arg0, %896 : i64
        func.call @dfs(%897, %892, %894) : (i64, i64, i64) -> ()
        %898 = arith.addi %870, %862 : index
        cf.br ^bb162(%898 : index)
      ^bb164(%899: index):
      %900 = arith.addi %836, %828 : index
      cf.br ^bb153(%900 : index)
    ^bb155(%901: index):
    func.call @free(%819) : (!llvm.ptr) -> ()
    func.call @free(%814) : (!llvm.ptr) -> ()
    func.return
  }
  func.func @main() -> i32 {
    func.call @vis_init() : () -> ()
    func.call @fac_cache_init() : () -> ()
    %907 = arith.constant 50 : i32
    %908 = arith.constant 8 : i32
    %909 = arith.extsi %907 : i32 to i64
    %910 = arith.extsi %908 : i32 to i64
    %906 = func.call @calloc(%909, %910) : (i64, i64) -> !llvm.ptr
    %912 = arith.constant 30 : i32
    %913 = arith.constant 8 : i32
    %914 = arith.extsi %912 : i32 to i64
    %915 = arith.extsi %913 : i32 to i64
    %911 = func.call @calloc(%914, %915) : (i64, i64) -> !llvm.ptr
    %917 = arith.constant 30 : i32
    %918 = arith.constant 8 : i32
    %919 = arith.extsi %917 : i32 to i64
    %920 = arith.extsi %918 : i32 to i64
    %916 = func.call @calloc(%919, %920) : (i64, i64) -> !llvm.ptr
    %921 = arith.constant 1 : i32
    %922 = arith.constant 0 : i32
    %923 = arith.extsi %921 : i32 to i64
    %924 = arith.extsi %922 : i32 to i64
    %925 = llvm.getelementptr %906[%924] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %923, %925 : i64, !llvm.ptr
    %926 = arith.constant 1 : i32
    %927 = arith.extsi %926 : i32 to i64
    %928 = llvm.mlir.constant(1 : i64) : i64
    %929 = llvm.alloca %928 x i64 : (i64) -> !llvm.ptr
    llvm.store %927, %929 : i64, !llvm.ptr
    %930 = arith.constant 0 : i32
    %931 = arith.extsi %930 : i32 to i64
    %932 = llvm.mlir.constant(1 : i64) : i64
    %933 = llvm.alloca %932 x i64 : (i64) -> !llvm.ptr
    llvm.store %931, %933 : i64, !llvm.ptr
    cf.br ^bb171
    ^bb171:
    %935 = llvm.load %933 : !llvm.ptr -> i64
    %936 = llvm.getelementptr %906[%935] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %934 = llvm.load %936 : !llvm.ptr -> i64
    %937 = arith.constant 2 : i32
    %939 = arith.extsi %937 : i32 to i64
    %938 = arith.muli %934, %939 : i64
    %940 = llvm.mlir.addressof @N : !llvm.ptr
    %941 = llvm.load %940 : !llvm.ptr -> i64
    %942 = arith.cmpi sle, %938, %941 : i64
    cf.cond_br %942, ^bb172, ^bb173
    ^bb172:
      %943 = llvm.load %933 : !llvm.ptr -> i64
      %944 = arith.constant 1 : i32
      %946 = arith.extsi %944 : i32 to i64
      %945 = arith.addi %943, %946 : i64
      llvm.store %945, %933 : i64, !llvm.ptr
      %948 = llvm.load %933 : !llvm.ptr -> i64
      %949 = arith.constant 1 : i32
      %951 = arith.extsi %949 : i32 to i64
      %950 = arith.subi %948, %951 : i64
      %952 = llvm.getelementptr %906[%950] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %947 = llvm.load %952 : !llvm.ptr -> i64
      %953 = arith.constant 2 : i32
      %955 = arith.extsi %953 : i32 to i64
      %954 = arith.muli %947, %955 : i64
      %956 = llvm.load %933 : !llvm.ptr -> i64
      %957 = llvm.getelementptr %906[%956] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %954, %957 : i64, !llvm.ptr
      cf.br ^bb171
    ^bb173:
    %958 = arith.constant 1 : i32
    %959 = arith.constant 0 : i32
    %960 = arith.extsi %958 : i32 to i64
    %961 = arith.extsi %959 : i32 to i64
    %962 = llvm.getelementptr %911[%961] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %960, %962 : i64, !llvm.ptr
    %963 = arith.constant 1 : i32
    %964 = arith.extsi %963 : i32 to i64
    %965 = llvm.mlir.constant(1 : i64) : i64
    %966 = llvm.alloca %965 x i64 : (i64) -> !llvm.ptr
    llvm.store %964, %966 : i64, !llvm.ptr
    %967 = arith.constant 0 : i32
    %968 = arith.extsi %967 : i32 to i64
    %969 = llvm.mlir.constant(1 : i64) : i64
    %970 = llvm.alloca %969 x i64 : (i64) -> !llvm.ptr
    llvm.store %968, %970 : i64, !llvm.ptr
    cf.br ^bb174
    ^bb174:
    %972 = llvm.load %970 : !llvm.ptr -> i64
    %973 = llvm.getelementptr %911[%972] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %971 = llvm.load %973 : !llvm.ptr -> i64
    %974 = arith.constant 3 : i32
    %976 = arith.extsi %974 : i32 to i64
    %975 = arith.muli %971, %976 : i64
    %977 = llvm.mlir.addressof @N : !llvm.ptr
    %978 = llvm.load %977 : !llvm.ptr -> i64
    %979 = arith.cmpi sle, %975, %978 : i64
    cf.cond_br %979, ^bb175, ^bb176
    ^bb175:
      %980 = llvm.load %970 : !llvm.ptr -> i64
      %981 = arith.constant 1 : i32
      %983 = arith.extsi %981 : i32 to i64
      %982 = arith.addi %980, %983 : i64
      llvm.store %982, %970 : i64, !llvm.ptr
      %985 = llvm.load %970 : !llvm.ptr -> i64
      %986 = arith.constant 1 : i32
      %988 = arith.extsi %986 : i32 to i64
      %987 = arith.subi %985, %988 : i64
      %989 = llvm.getelementptr %911[%987] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %984 = llvm.load %989 : !llvm.ptr -> i64
      %990 = arith.constant 3 : i32
      %992 = arith.extsi %990 : i32 to i64
      %991 = arith.muli %984, %992 : i64
      %993 = llvm.load %970 : !llvm.ptr -> i64
      %994 = llvm.getelementptr %911[%993] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %991, %994 : i64, !llvm.ptr
      cf.br ^bb174
    ^bb176:
    %995 = arith.constant 1 : i32
    %996 = arith.constant 0 : i32
    %997 = arith.extsi %995 : i32 to i64
    %998 = arith.extsi %996 : i32 to i64
    %999 = llvm.getelementptr %916[%998] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %997, %999 : i64, !llvm.ptr
    %1000 = arith.constant 0 : i32
    %1001 = arith.extsi %1000 : i32 to i64
    %1002 = llvm.mlir.constant(1 : i64) : i64
    %1003 = llvm.alloca %1002 x i64 : (i64) -> !llvm.ptr
    llvm.store %1001, %1003 : i64, !llvm.ptr
    cf.br ^bb177
    ^bb177:
    %1005 = llvm.load %1003 : !llvm.ptr -> i64
    %1006 = llvm.getelementptr %916[%1005] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %1004 = llvm.load %1006 : !llvm.ptr -> i64
    %1007 = arith.constant 5 : i32
    %1009 = arith.extsi %1007 : i32 to i64
    %1008 = arith.muli %1004, %1009 : i64
    %1010 = llvm.mlir.addressof @N : !llvm.ptr
    %1011 = llvm.load %1010 : !llvm.ptr -> i64
    %1012 = arith.cmpi sle, %1008, %1011 : i64
    cf.cond_br %1012, ^bb178, ^bb179
    ^bb178:
      %1013 = llvm.load %1003 : !llvm.ptr -> i64
      %1014 = arith.constant 1 : i32
      %1016 = arith.extsi %1014 : i32 to i64
      %1015 = arith.addi %1013, %1016 : i64
      llvm.store %1015, %1003 : i64, !llvm.ptr
      %1018 = llvm.load %1003 : !llvm.ptr -> i64
      %1019 = arith.constant 1 : i32
      %1021 = arith.extsi %1019 : i32 to i64
      %1020 = arith.subi %1018, %1021 : i64
      %1022 = llvm.getelementptr %916[%1020] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %1017 = llvm.load %1022 : !llvm.ptr -> i64
      %1023 = arith.constant 5 : i32
      %1025 = arith.extsi %1023 : i32 to i64
      %1024 = arith.muli %1017, %1025 : i64
      %1026 = llvm.load %1003 : !llvm.ptr -> i64
      %1027 = llvm.getelementptr %916[%1026] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %1024, %1027 : i64, !llvm.ptr
      cf.br ^bb177
    ^bb179:
    %1029 = arith.constant 64 : i32
    %1030 = arith.constant 8 : i32
    %1031 = arith.extsi %1029 : i32 to i64
    %1032 = arith.extsi %1030 : i32 to i64
    %1028 = func.call @calloc(%1031, %1032) : (i64, i64) -> !llvm.ptr
    %1034 = arith.constant 64 : i32
    %1035 = arith.constant 8 : i32
    %1036 = arith.extsi %1034 : i32 to i64
    %1037 = arith.extsi %1035 : i32 to i64
    %1033 = func.call @calloc(%1036, %1037) : (i64, i64) -> !llvm.ptr
    %1038 = arith.constant 0 : i32
    %1039 = llvm.load %933 : !llvm.ptr -> i64
    %1040 = arith.constant 1 : i32
    %1042 = arith.extsi %1040 : i32 to i64
    %1041 = arith.addi %1039, %1042 : i64
    %1043 = arith.index_cast %1038 : i32 to index
    %1044 = arith.index_cast %1041 : i32 to index
    %1046 = arith.constant 1 : index
    %1047 = arith.constant -1 : index
    %1048 = arith.cmpi sle, %1043, %1044 : index
    %1045 = arith.select %1048, %1046, %1047 : index
    cf.br ^bb180(%1043 : index)
    ^bb180(%1049: index):
    %1050 = arith.cmpi slt, %1049, %1044 : index
    %1051 = arith.cmpi sgt, %1049, %1044 : index
    %1052 = arith.select %1048, %1050, %1051 : i1
    cf.cond_br %1052, ^bb181(%1049 : index), ^bb182(%1049 : index)
    ^bb181(%1053: index):
      %1055 = arith.index_cast %1053 : index to i64
      %1056 = llvm.getelementptr %906[%1055] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %1054 = llvm.load %1056 : !llvm.ptr -> i64
      %1057 = llvm.mlir.undef : i64
      %1058 = arith.constant 0 : i32
      %1060 = arith.index_cast %1053 : index to i32
      %1059 = arith.cmpi sgt, %1060, %1058 : i32
      %1061 = scf.if %1059 -> (i64) {
        %1062 = arith.constant 2 : i32
        %1064 = arith.extsi %1062 : i32 to i64
        %1063 = arith.muli %1054, %1064 : i64
        %1065 = arith.constant 1 : i32
        %1067 = arith.extsi %1065 : i32 to i64
        %1066 = arith.subi %1063, %1067 : i64
        scf.yield %1066 : i64
      } else {
        %1068 = arith.constant 1 : i32
        %1069 = arith.extsi %1068 : i32 to i64
        scf.yield %1069 : i64
      }
      %1070 = arith.constant 1 : i32
      %1071 = llvm.load %970 : !llvm.ptr -> i64
      %1072 = arith.constant 1 : i32
      %1074 = arith.extsi %1072 : i32 to i64
      %1073 = arith.addi %1071, %1074 : i64
      %1075 = arith.index_cast %1070 : i32 to index
      %1076 = arith.index_cast %1073 : i32 to index
      %1078 = arith.constant 1 : index
      %1079 = arith.constant -1 : index
      %1080 = arith.cmpi sle, %1075, %1076 : index
      %1077 = arith.select %1080, %1078, %1079 : index
      cf.br ^bb183(%1075 : index)
      ^bb183(%1081: index):
      %1082 = arith.cmpi slt, %1081, %1076 : index
      %1083 = arith.cmpi sgt, %1081, %1076 : index
      %1084 = arith.select %1080, %1082, %1083 : i1
      cf.cond_br %1084, ^bb184(%1081 : index), ^bb185(%1081 : index)
      ^bb184(%1085: index):
        %1087 = arith.index_cast %1085 : index to i64
        %1088 = llvm.getelementptr %911[%1087] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %1086 = llvm.load %1088 : !llvm.ptr -> i64
        %1089 = arith.muli %1054, %1086 : i64
        %1090 = llvm.mlir.addressof @N : !llvm.ptr
        %1091 = llvm.load %1090 : !llvm.ptr -> i64
        %1092 = arith.cmpi sgt, %1089, %1091 : i64
        cf.cond_br %1092, ^bb186, ^bb187
        ^bb186:
          cf.br ^bb185(%1085 : index)
        ^bb187:
          cf.br ^bb188
        ^bb188:
        %1093 = arith.constant 3 : i32
        %1095 = arith.extsi %1093 : i32 to i64
        %1094 = arith.muli %1086, %1095 : i64
        %1096 = arith.constant 1 : i32
        %1098 = arith.extsi %1096 : i32 to i64
        %1097 = arith.subi %1094, %1098 : i64
        %1099 = arith.constant 2 : i32
        %1101 = arith.extsi %1099 : i32 to i64
        %1100 = arith.divsi %1097, %1101 : i64
        %1102 = arith.constant 0 : i32
        %1103 = llvm.load %1003 : !llvm.ptr -> i64
        %1104 = arith.constant 1 : i32
        %1106 = arith.extsi %1104 : i32 to i64
        %1105 = arith.addi %1103, %1106 : i64
        %1107 = arith.index_cast %1102 : i32 to index
        %1108 = arith.index_cast %1105 : i32 to index
        %1110 = arith.constant 1 : index
        %1111 = arith.constant -1 : index
        %1112 = arith.cmpi sle, %1107, %1108 : index
        %1109 = arith.select %1112, %1110, %1111 : index
        cf.br ^bb189(%1107 : index)
        ^bb189(%1113: index):
        %1114 = arith.cmpi slt, %1113, %1108 : index
        %1115 = arith.cmpi sgt, %1113, %1108 : index
        %1116 = arith.select %1112, %1114, %1115 : i1
        cf.cond_br %1116, ^bb190(%1113 : index), ^bb191(%1113 : index)
        ^bb190(%1117: index):
          %1119 = arith.index_cast %1117 : index to i64
          %1120 = llvm.getelementptr %916[%1119] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %1118 = llvm.load %1120 : !llvm.ptr -> i64
          %1121 = arith.muli %1054, %1086 : i64
          %1122 = arith.muli %1121, %1118 : i64
          %1123 = llvm.mlir.addressof @N : !llvm.ptr
          %1124 = llvm.load %1123 : !llvm.ptr -> i64
          %1125 = arith.cmpi sgt, %1122, %1124 : i64
          cf.cond_br %1125, ^bb192, ^bb193
          ^bb192:
            cf.br ^bb191(%1117 : index)
          ^bb193:
            cf.br ^bb194
          ^bb194:
          %1126 = llvm.mlir.undef : i64
          %1127 = arith.constant 0 : i32
          %1129 = arith.index_cast %1117 : index to i32
          %1128 = arith.cmpi sgt, %1129, %1127 : i32
          %1130 = scf.if %1128 -> (i64) {
            %1131 = arith.constant 5 : i32
            %1133 = arith.extsi %1131 : i32 to i64
            %1132 = arith.muli %1118, %1133 : i64
            %1134 = arith.constant 1 : i32
            %1136 = arith.extsi %1134 : i32 to i64
            %1135 = arith.subi %1132, %1136 : i64
            %1137 = arith.constant 4 : i32
            %1139 = arith.extsi %1137 : i32 to i64
            %1138 = arith.divsi %1135, %1139 : i64
            scf.yield %1138 : i64
          } else {
            %1140 = arith.constant 1 : i32
            %1141 = arith.extsi %1140 : i32 to i64
            scf.yield %1141 : i64
          }
          %1142 = arith.muli %1061, %1100 : i64
          %1143 = arith.muli %1142, %1130 : i64
          %1144 = func.call @gcd(%1122, %1143) : (i64, i64) -> i64
          %1145 = arith.divsi %1143, %1144 : i64
          %1146 = arith.divsi %1122, %1144 : i64
          %1147 = arith.constant 3 : i32
          %1149 = arith.extsi %1147 : i32 to i64
          %1148 = arith.remsi %1146, %1149 : i64
          %1150 = arith.constant 0 : i32
          %1152 = arith.extsi %1150 : i32 to i64
          %1151 = arith.cmpi ne, %1148, %1152 : i64
          cf.cond_br %1151, ^bb195, ^bb196
          ^bb195:
            %1153 = arith.addi %1117, %1109 : index
            cf.br ^bb189(%1153 : index)
          ^bb196:
            cf.br ^bb197
          ^bb197:
          %1154 = arith.constant 1 : i32
          %1156 = arith.extsi %1154 : i32 to i64
          %1155 = arith.cmpi eq, %1146, %1156 : i64
          cf.cond_br %1155, ^bb198, ^bb199
          ^bb198:
            %1157 = arith.addi %1117, %1109 : index
            cf.br ^bb189(%1157 : index)
          ^bb199:
            cf.br ^bb200
          ^bb200:
          func.call @dfs(%1122, %1145, %1146) : (i64, i64, i64) -> ()
          %1159 = arith.addi %1117, %1109 : index
          cf.br ^bb189(%1159 : index)
        ^bb191(%1160: index):
        %1161 = arith.addi %1085, %1077 : index
        cf.br ^bb183(%1161 : index)
      ^bb185(%1162: index):
      %1163 = arith.addi %1053, %1045 : index
      cf.br ^bb180(%1163 : index)
    ^bb182(%1164: index):
    %1165 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %1166 = llvm.mlir.addressof @g_total : !llvm.ptr
    %1167 = llvm.load %1166 : !llvm.ptr -> i64
    %1168 = llvm.call @printf(%1165, %1167) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    func.call @free(%1033) : (!llvm.ptr) -> ()
    func.call @free(%1028) : (!llvm.ptr) -> ()
    func.call @free(%916) : (!llvm.ptr) -> ()
    func.call @free(%911) : (!llvm.ptr) -> ()
    func.call @free(%906) : (!llvm.ptr) -> ()
    %1175 = llvm.mlir.addressof @g_fac_data : !llvm.ptr
    %1176 = llvm.load %1175 : !llvm.ptr -> !llvm.ptr
    func.call @free(%1176) : (!llvm.ptr) -> ()
    %1178 = llvm.mlir.addressof @g_fac_keys : !llvm.ptr
    %1179 = llvm.load %1178 : !llvm.ptr -> !llvm.ptr
    func.call @free(%1179) : (!llvm.ptr) -> ()
    %1181 = llvm.mlir.addressof @g_vis_keys : !llvm.ptr
    %1182 = llvm.load %1181 : !llvm.ptr -> !llvm.ptr
    func.call @free(%1182) : (!llvm.ptr) -> ()
    %1183 = arith.constant 0 : i32
    func.return %1183 : i32
  }
}