Problem 809

f(22/7) mod 10^15 via Ackermann-Peter function and tetration. Pure Flow port of the native C solver. Uses i128 for CRT intermediates.

Answer75353432948733
Output75353432948733
StatusPASS
Native helperno
Runtime0 ms
Peak memory1072 KB
Time complexityO(n) (estimated)
Space complexityO(1) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n)O(log n)
Space complexityO(1)O(1)
ApproachFlow solutionModular exponentiation
VerdictSuboptimal

Flow source

# Project Euler 809: Rational Recurrence Relation
# f(22/7) mod 10^15 via Ackermann-Peter function and tetration.
# Pure Flow port of the native C solver. Uses i128 for CRT intermediates.

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

# Iterative extended GCD: returns g, sets x[0],y[0] with a*x + b*y = g.
function egcd(a0: i64, b0: i64, x: ptr<i64>, y: ptr<i64>) -> i64 {
    let mut old_r: i64 = a0
    let mut r: i64 = b0
    let mut old_s: i64 = 1
    let mut s: i64 = 0
    let mut old_t: i64 = 0
    let mut t: i64 = 1
    while r != 0 {
        let q: i64 = old_r / r
        let tr: i64 = old_r - q * r
        old_r = r
        r = tr
        let ts: i64 = old_s - q * s
        old_s = s
        s = ts
        let tt: i64 = old_t - q * t
        old_t = t
        t = tt
    }
    x[0] = old_s
    y[0] = old_t
    return old_r
}

function inv_mod(a: i64, m: i64) -> i64 {
    let xp: ptr<i64> = calloc(1, 8) as ptr<i64>
    let yp: ptr<i64> = calloc(1, 8) as ptr<i64>
    egcd(a % m, m, xp, yp)
    let mut x: i64 = xp[0]
    free(xp)
    free(yp)
    if x < 0 {
        x = x + m
    }
    return x % m
}

# CRT: x ≡ r1 (mod m1), x ≡ r2 (mod m2), m1,m2 coprime. Result < m1*m2.
function crt(r1: i64, m1: i64, r2: i64, m2: i64) -> i64 {
    let mut diff: i128 = ((r2 - r1) % m2) as i128
    if diff < 0 {
        diff = diff + (m2 as i128)
    }
    let k: i128 = diff * (inv_mod(m1 % m2, m2) as i128) % (m2 as i128)
    let result: i128 = (r1 as i128) + (m1 as i128) * k
    let prod: i128 = (m1 as i128) * (m2 as i128)
    return (result % prod) as i64
}

# phi of n = 2^a * 5^b (rem assumed 1).
function phi_2_5(n: i64) -> i64 {
    let mut x: i64 = n
    let mut a: i64 = 0
    while x % 2 == 0 {
        a = a + 1
        x = x / 2
    }
    let mut b: i64 = 0
    while x % 5 == 0 {
        b = b + 1
        x = x / 5
    }
    let mut res: i64 = n
    if a > 0 {
        res = res / 2
    }
    if b > 0 {
        res = (res / 5) * 4
    }
    return res
}

function totient_chain_len(n0: i64) -> i64 {
    let mut n: i64 = n0
    let mut steps: i64 = 0
    while n != 1 {
        n = phi_2_5(n)
        steps = steps + 1
    }
    return steps
}

# min(2 tetrated height times, cap) for base 2.
function tetration_cap(height: i64, cap: i64) -> i64 {
    if cap <= 0 {
        return 0
    }
    let v: i64 = 2
    if height <= 1 {
        if v < cap {
            return v
        }
        return cap
    }
    let mut i: i64 = 2
    let mut vv: i64 = v
    while i <= height {
        if vv >= 60 {
            return cap
        }
        vv = 1 << vv
        if vv >= cap {
            return cap
        }
        i = i + 1
    }
    return vv
}

# 2 tetrated height times (mod 2^a).
function tetration_mod_pow2(height: i64, a: i64) -> i64 {
    if a <= 0 {
        return 0
    }
    let modv: i64 = 1 << a
    if height == 1 {
        return 2 % modv
    }
    let exp: i64 = tetration_cap(height - 1, a)
    if exp >= a {
        return 0
    }
    return (1 << exp) % modv
}

function powmod_128(base: i64, exp0: i64, modv: i64) -> i64 {
    let mut r: i128 = 1 % (modv as i128)
    let mut b: i128 = base % (modv as i128)
    let mut exp: i64 = exp0
    while exp != 0 {
        if exp % 2 == 1 {
            r = r * b % (modv as i128)
        }
        b = b * b % (modv as i128)
        exp = exp / 2
    }
    return r as i64
}

# 2 tetrated height times (mod modv) for modv of the form 2^a * 5^b.
function tetration_mod(height: i64, modv: i64) -> i64 {
    if modv == 1 {
        return 0
    }
    let mut x: i64 = modv
    let mut a: i64 = 0
    while x % 2 == 0 {
        a = a + 1
        x = x / 2
    }
    let mut b: i64 = 0
    while x % 5 == 0 {
        b = b + 1
        x = x / 5
    }
    if b == 0 {
        return tetration_mod_pow2(height, a)
    }
    if a == 0 {
        if height == 1 {
            return 2 % modv
        }
        let exp: i64 = tetration_mod(height - 1, phi_2_5(modv))
        return powmod_128(2, exp, modv)
    }
    let m2: i64 = 1 << a
    let mut m5: i64 = 1
    let mut i: i64 = 0
    while i < b {
        m5 = m5 * 5
        i = i + 1
    }
    let r2: i64 = tetration_mod_pow2(height, a)
    let r5: i64 = tetration_mod(height, m5)
    return crt(r2, m2, r5, m5) % (m2 * m5)
}

function stable_tetration_mod(modv: i64) -> i64 {
    let height: i64 = totient_chain_len(modv) + 1
    return tetration_mod(height, modv)
}

function main() -> i32 {
    let mod2: i64 = 1 << 15
    let mut mod5: i64 = 1
    let mut i: i64 = 0
    while i < 15 {
        mod5 = mod5 * 5
        i = i + 1
    }

    let mut r2: i64 = (-3) % mod2
    if r2 < 0 {
        r2 = r2 + mod2
    }

    let tower_mod5: i64 = stable_tetration_mod(mod5)
    let mut r5: i64 = (tower_mod5 - 3) % mod5
    if r5 < 0 {
        r5 = r5 + mod5
    }

    let result: i64 = crt(r2, mod2, r5, mod5)
    let mod10_15: i64 = mod2 * mod5
    printf("%lld\n", result % mod10_15)
    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 egcd_i64_i64_ptr_i64_ptr_i64(int64_t a0, int64_t b0, int64_t* x, int64_t* y);
int64_t inv_mod_i64_i64(int64_t a, int64_t m);
int64_t crt_i64_i64_i64_i64(int64_t r1, int64_t m1, int64_t r2, int64_t m2);
int64_t phi_2_5_i64(int64_t n);
int64_t totient_chain_len_i64(int64_t n0);
int64_t tetration_cap_i64_i64(int64_t height, int64_t cap);
int64_t tetration_mod_pow2_i64_i64(int64_t height, int64_t a);
int64_t powmod_128_i64_i64_i64(int64_t base, int64_t exp0, int64_t modv);
int64_t tetration_mod_i64_i64(int64_t height, int64_t modv);
int64_t stable_tetration_mod_i64(int64_t modv);
int32_t main(void);



int64_t egcd_i64_i64_ptr_i64_ptr_i64(int64_t a0, int64_t b0, int64_t* x, int64_t* y) {
    int64_t old_r = a0;
    int64_t r = b0;
    int64_t old_s = 1;
    int64_t s = 0;
    int64_t old_t = 0;
    int64_t t = 1;
    while (r != 0) {
        int64_t q = FLOW_CHECKED_DIV((old_r), (r));
        int64_t tr = (old_r - (q * r));
        old_r = r;
        r = tr;
        int64_t ts = (old_s - (q * s));
        old_s = s;
        s = ts;
        int64_t tt = (old_t - (q * t));
        old_t = t;
        t = tt;
    }
    x[0] = old_s;
    y[0] = old_t;
    return old_r;
}

int64_t inv_mod_i64_i64(int64_t a, int64_t m) {
    int64_t* xp = (int64_t*)(((int64_t*)(calloc(1, 8))));
    int64_t* yp = (int64_t*)(((int64_t*)(calloc(1, 8))));
    egcd_i64_i64_ptr_i64_ptr_i64(FLOW_CHECKED_MOD((a), (m)), m, xp, yp);
    int64_t x = xp[0];
    free(xp);
    free(yp);
    if (x < 0) {
        x = (x + m);
    }
    return FLOW_CHECKED_MOD((x), (m));
}

int64_t crt_i64_i64_i64_i64(int64_t r1, int64_t m1, int64_t r2, int64_t m2) {
    __int128 diff = ((__int128)(FLOW_CHECKED_MOD(((r2 - r1)), (m2))));
    if (diff < 0) {
        diff = (diff + ((__int128)(m2)));
    }
    __int128 k = FLOW_CHECKED_MOD(((diff * ((__int128)(inv_mod_i64_i64(FLOW_CHECKED_MOD((m1), (m2)), m2))))), (((__int128)(m2))));
    __int128 result = (((__int128)(r1)) + (((__int128)(m1)) * k));
    __int128 prod = (((__int128)(m1)) * ((__int128)(m2)));
    return ((int64_t)(FLOW_CHECKED_MOD((result), (prod))));
}

int64_t phi_2_5_i64(int64_t n) {
    int64_t x = n;
    int64_t a = 0;
    while (FLOW_CHECKED_MOD((x), (2)) == 0) {
        a = (a + 1);
        x = FLOW_CHECKED_DIV((x), (2));
    }
    int64_t b = 0;
    while (FLOW_CHECKED_MOD((x), (5)) == 0) {
        b = (b + 1);
        x = FLOW_CHECKED_DIV((x), (5));
    }
    int64_t res = n;
    if (a > 0) {
        res = FLOW_CHECKED_DIV((res), (2));
    }
    if (b > 0) {
        res = (FLOW_CHECKED_DIV((res), (5)) * 4);
    }
    return res;
}

int64_t totient_chain_len_i64(int64_t n0) {
    int64_t n = n0;
    int64_t steps = 0;
    while (n != 1) {
        n = phi_2_5_i64(n);
        steps = (steps + 1);
    }
    return steps;
}

int64_t tetration_cap_i64_i64(int64_t height, int64_t cap) {
    if (cap <= 0) {
        return 0;
    }
    int64_t v = 2;
    if (height <= 1) {
        if (v < cap) {
            return v;
        }
        return cap;
    }
    int64_t i = 2;
    int64_t vv = v;
    while (i <= height) {
        if (vv >= 60) {
            return cap;
        }
        vv = FLOW_CHECKED_SHL((1), (vv));
        if (vv >= cap) {
            return cap;
        }
        i = (i + 1);
    }
    return vv;
}

int64_t tetration_mod_pow2_i64_i64(int64_t height, int64_t a) {
    if (a <= 0) {
        return 0;
    }
    int64_t modv = FLOW_CHECKED_SHL((1), (a));
    if (height == 1) {
        return FLOW_CHECKED_MOD((2), (modv));
    }
    int64_t exp = tetration_cap_i64_i64((height - 1), a);
    if (exp >= a) {
        return 0;
    }
    return FLOW_CHECKED_MOD((FLOW_CHECKED_SHL((1), (exp))), (modv));
}

int64_t powmod_128_i64_i64_i64(int64_t base, int64_t exp0, int64_t modv) {
    __int128 r = FLOW_CHECKED_MOD((1), (((__int128)(modv))));
    __int128 b = FLOW_CHECKED_MOD((base), (((__int128)(modv))));
    int64_t exp = exp0;
    while (exp != 0) {
        if (FLOW_CHECKED_MOD((exp), (2)) == 1) {
            r = FLOW_CHECKED_MOD(((r * b)), (((__int128)(modv))));
        }
        b = FLOW_CHECKED_MOD(((b * b)), (((__int128)(modv))));
        exp = FLOW_CHECKED_DIV((exp), (2));
    }
    return ((int64_t)(r));
}

int64_t tetration_mod_i64_i64(int64_t height, int64_t modv) {
    if (modv == 1) {
        return 0;
    }
    int64_t x = modv;
    int64_t a = 0;
    while (FLOW_CHECKED_MOD((x), (2)) == 0) {
        a = (a + 1);
        x = FLOW_CHECKED_DIV((x), (2));
    }
    int64_t b = 0;
    while (FLOW_CHECKED_MOD((x), (5)) == 0) {
        b = (b + 1);
        x = FLOW_CHECKED_DIV((x), (5));
    }
    if (b == 0) {
        return tetration_mod_pow2_i64_i64(height, a);
    }
    if (a == 0) {
        if (height == 1) {
            return FLOW_CHECKED_MOD((2), (modv));
        }
        int64_t exp = tetration_mod_i64_i64((height - 1), phi_2_5_i64(modv));
        return powmod_128_i64_i64_i64(2, exp, modv);
    }
    int64_t m2 = FLOW_CHECKED_SHL((1), (a));
    int64_t m5 = 1;
    int64_t i = 0;
    while (i < b) {
        m5 = (m5 * 5);
        i = (i + 1);
    }
    int64_t r2 = tetration_mod_pow2_i64_i64(height, a);
    int64_t r5 = tetration_mod_i64_i64(height, m5);
    return FLOW_CHECKED_MOD((crt_i64_i64_i64_i64(r2, m2, r5, m5)), ((m2 * m5)));
}

int64_t stable_tetration_mod_i64(int64_t modv) {
    int64_t height = (totient_chain_len_i64(modv) + 1);
    return tetration_mod_i64_i64(height, modv);
}

int32_t main(void) {
    int64_t mod2 = FLOW_CHECKED_SHL((1), (15));
    int64_t mod5 = 1;
    int64_t i = 0;
    while (i < 15) {
        mod5 = (mod5 * 5);
        i = (i + 1);
    }
    int64_t r2 = FLOW_CHECKED_MOD(((-3)), (mod2));
    if (r2 < 0) {
        r2 = (r2 + mod2);
    }
    int64_t tower_mod5 = stable_tetration_mod_i64(mod5);
    int64_t r5 = FLOW_CHECKED_MOD(((tower_mod5 - 3)), (mod5));
    if (r5 < 0) {
        r5 = (r5 + mod5);
    }
    int64_t result = crt_i64_i64_i64_i64(r2, mod2, r5, mod5);
    int64_t mod10_15 = (mod2 * mod5);
    printf("%lld\n", FLOW_CHECKED_MOD((result), (mod10_15)));
    return 0;
}

Generated MLIR

module {
  llvm.func @printf(!llvm.ptr, ...) -> i32
  llvm.mlir.global internal constant @str_0("%lld\n\00") {addr_space = 0 : i32} : !llvm.array<6 x i8>
  func.func private @calloc(i64, i64) -> !llvm.ptr
  func.func private @free(!llvm.ptr) -> ()
  func.func @egcd(%arg0: i64, %arg1: i64, %arg2: !llvm.ptr, %arg3: !llvm.ptr) -> 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
    %4 = arith.constant 1 : i32
    %5 = arith.extsi %4 : i32 to i64
    %6 = llvm.mlir.constant(1 : i64) : i64
    %7 = llvm.alloca %6 x i64 : (i64) -> !llvm.ptr
    llvm.store %5, %7 : i64, !llvm.ptr
    %8 = arith.constant 0 : i32
    %9 = arith.extsi %8 : i32 to i64
    %10 = llvm.mlir.constant(1 : i64) : i64
    %11 = llvm.alloca %10 x i64 : (i64) -> !llvm.ptr
    llvm.store %9, %11 : i64, !llvm.ptr
    %12 = arith.constant 0 : i32
    %13 = arith.extsi %12 : i32 to i64
    %14 = llvm.mlir.constant(1 : i64) : i64
    %15 = llvm.alloca %14 x i64 : (i64) -> !llvm.ptr
    llvm.store %13, %15 : i64, !llvm.ptr
    %16 = arith.constant 1 : i32
    %17 = arith.extsi %16 : i32 to i64
    %18 = llvm.mlir.constant(1 : i64) : i64
    %19 = llvm.alloca %18 x i64 : (i64) -> !llvm.ptr
    llvm.store %17, %19 : i64, !llvm.ptr
    cf.br ^bb0
    ^bb0:
    %20 = llvm.load %3 : !llvm.ptr -> i64
    %21 = arith.constant 0 : i32
    %23 = arith.extsi %21 : i32 to i64
    %22 = arith.cmpi ne, %20, %23 : i64
    cf.cond_br %22, ^bb1, ^bb2
    ^bb1:
      %24 = llvm.load %1 : !llvm.ptr -> i64
      %25 = llvm.load %3 : !llvm.ptr -> i64
      %26 = arith.divsi %24, %25 : i64
      %27 = llvm.load %1 : !llvm.ptr -> i64
      %28 = llvm.load %3 : !llvm.ptr -> i64
      %29 = arith.muli %26, %28 : i64
      %30 = arith.subi %27, %29 : i64
      %31 = llvm.load %3 : !llvm.ptr -> i64
      llvm.store %31, %1 : i64, !llvm.ptr
      llvm.store %30, %3 : i64, !llvm.ptr
      %32 = llvm.load %7 : !llvm.ptr -> i64
      %33 = llvm.load %11 : !llvm.ptr -> i64
      %34 = arith.muli %26, %33 : i64
      %35 = arith.subi %32, %34 : i64
      %36 = llvm.load %11 : !llvm.ptr -> i64
      llvm.store %36, %7 : i64, !llvm.ptr
      llvm.store %35, %11 : i64, !llvm.ptr
      %37 = llvm.load %15 : !llvm.ptr -> i64
      %38 = llvm.load %19 : !llvm.ptr -> i64
      %39 = arith.muli %26, %38 : i64
      %40 = arith.subi %37, %39 : i64
      %41 = llvm.load %19 : !llvm.ptr -> i64
      llvm.store %41, %15 : i64, !llvm.ptr
      llvm.store %40, %19 : i64, !llvm.ptr
      cf.br ^bb0
    ^bb2:
    %42 = llvm.load %7 : !llvm.ptr -> i64
    %43 = arith.constant 0 : i32
    %44 = arith.extsi %43 : i32 to i64
    %45 = llvm.getelementptr %arg2[%44] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %42, %45 : i64, !llvm.ptr
    %46 = llvm.load %15 : !llvm.ptr -> i64
    %47 = arith.constant 0 : i32
    %48 = arith.extsi %47 : i32 to i64
    %49 = llvm.getelementptr %arg3[%48] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %46, %49 : i64, !llvm.ptr
    %50 = llvm.load %1 : !llvm.ptr -> i64
    func.return %50 : i64
  }
  func.func @inv_mod(%arg0: i64, %arg1: i64) -> i64 {
    %52 = arith.constant 1 : i32
    %53 = arith.constant 8 : i32
    %54 = arith.extsi %52 : i32 to i64
    %55 = arith.extsi %53 : i32 to i64
    %51 = func.call @calloc(%54, %55) : (i64, i64) -> !llvm.ptr
    %57 = arith.constant 1 : i32
    %58 = arith.constant 8 : i32
    %59 = arith.extsi %57 : i32 to i64
    %60 = arith.extsi %58 : i32 to i64
    %56 = func.call @calloc(%59, %60) : (i64, i64) -> !llvm.ptr
    %62 = arith.remsi %arg0, %arg1 : i64
    %61 = func.call @egcd(%62, %arg1, %51, %56) : (i64, i64, !llvm.ptr, !llvm.ptr) -> i64
    %64 = arith.constant 0 : i32
    %65 = arith.extsi %64 : i32 to i64
    %66 = llvm.getelementptr %51[%65] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %63 = llvm.load %66 : !llvm.ptr -> i64
    %67 = llvm.mlir.constant(1 : i64) : i64
    %68 = llvm.alloca %67 x i64 : (i64) -> !llvm.ptr
    llvm.store %63, %68 : i64, !llvm.ptr
    func.call @free(%51) : (!llvm.ptr) -> ()
    func.call @free(%56) : (!llvm.ptr) -> ()
    %71 = llvm.load %68 : !llvm.ptr -> i64
    %72 = arith.constant 0 : i32
    %74 = arith.extsi %72 : i32 to i64
    %73 = arith.cmpi slt, %71, %74 : i64
    cf.cond_br %73, ^bb3, ^bb4
    ^bb3:
      %75 = llvm.load %68 : !llvm.ptr -> i64
      %76 = arith.addi %75, %arg1 : i64
      llvm.store %76, %68 : i64, !llvm.ptr
      cf.br ^bb5
    ^bb4:
      cf.br ^bb5
    ^bb5:
    %77 = llvm.load %68 : !llvm.ptr -> i64
    %78 = arith.remsi %77, %arg1 : i64
    func.return %78 : i64
  }
  func.func @crt(%arg0: i64, %arg1: i64, %arg2: i64, %arg3: i64) -> i64 {
    %79 = arith.subi %arg2, %arg0 : i64
    %80 = arith.remsi %79, %arg3 : i64
    %81 = arith.extsi %80 : i64 to i128
    %82 = llvm.mlir.constant(1 : i64) : i64
    %83 = llvm.alloca %82 x i128 : (i64) -> !llvm.ptr
    llvm.store %81, %83 : i128, !llvm.ptr
    %84 = llvm.load %83 : !llvm.ptr -> i128
    %85 = arith.constant 0 : i32
    %87 = arith.trunci %84 : i128 to i64
    %88 = arith.extsi %85 : i32 to i64
    %86 = arith.cmpi slt, %87, %88 : i64
    cf.cond_br %86, ^bb6, ^bb7
    ^bb6:
      %89 = llvm.load %83 : !llvm.ptr -> i128
      %90 = arith.extsi %arg3 : i64 to i128
      %92 = arith.trunci %89 : i128 to i64
      %93 = arith.trunci %90 : i128 to i64
      %91 = arith.addi %92, %93 : i64
      %94 = arith.extsi %91 : i64 to i128
      llvm.store %94, %83 : i128, !llvm.ptr
      cf.br ^bb8
    ^bb7:
      cf.br ^bb8
    ^bb8:
    %95 = llvm.load %83 : !llvm.ptr -> i128
    %97 = arith.remsi %arg1, %arg3 : i64
    %96 = func.call @inv_mod(%97, %arg3) : (i64, i64) -> i64
    %98 = arith.extsi %96 : i64 to i128
    %100 = arith.trunci %95 : i128 to i64
    %101 = arith.trunci %98 : i128 to i64
    %99 = arith.muli %100, %101 : i64
    %102 = arith.extsi %arg3 : i64 to i128
    %104 = arith.trunci %102 : i128 to i64
    %103 = arith.remsi %99, %104 : i64
    %105 = arith.extsi %103 : i64 to i128
    %106 = arith.extsi %arg0 : i64 to i128
    %107 = arith.extsi %arg1 : i64 to i128
    %109 = arith.trunci %107 : i128 to i64
    %110 = arith.trunci %105 : i128 to i64
    %108 = arith.muli %109, %110 : i64
    %112 = arith.trunci %106 : i128 to i64
    %111 = arith.addi %112, %108 : i64
    %113 = arith.extsi %111 : i64 to i128
    %114 = arith.extsi %arg1 : i64 to i128
    %115 = arith.extsi %arg3 : i64 to i128
    %117 = arith.trunci %114 : i128 to i64
    %118 = arith.trunci %115 : i128 to i64
    %116 = arith.muli %117, %118 : i64
    %119 = arith.extsi %116 : i64 to i128
    %121 = arith.trunci %113 : i128 to i64
    %122 = arith.trunci %119 : i128 to i64
    %120 = arith.remsi %121, %122 : i64
    func.return %120 : i64
  }
  func.func @phi_2_5(%arg0: i64) -> i64 {
    %123 = llvm.mlir.constant(1 : i64) : i64
    %124 = llvm.alloca %123 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %124 : i64, !llvm.ptr
    %125 = arith.constant 0 : i32
    %126 = arith.extsi %125 : i32 to i64
    %127 = llvm.mlir.constant(1 : i64) : i64
    %128 = llvm.alloca %127 x i64 : (i64) -> !llvm.ptr
    llvm.store %126, %128 : i64, !llvm.ptr
    cf.br ^bb9
    ^bb9:
    %129 = llvm.load %124 : !llvm.ptr -> i64
    %130 = arith.constant 2 : i32
    %132 = arith.extsi %130 : i32 to i64
    %131 = arith.remsi %129, %132 : i64
    %133 = arith.constant 0 : i32
    %135 = arith.extsi %133 : i32 to i64
    %134 = arith.cmpi eq, %131, %135 : i64
    cf.cond_br %134, ^bb10, ^bb11
    ^bb10:
      %136 = llvm.load %128 : !llvm.ptr -> i64
      %137 = arith.constant 1 : i32
      %139 = arith.extsi %137 : i32 to i64
      %138 = arith.addi %136, %139 : i64
      llvm.store %138, %128 : i64, !llvm.ptr
      %140 = llvm.load %124 : !llvm.ptr -> i64
      %141 = arith.constant 2 : i32
      %143 = arith.extsi %141 : i32 to i64
      %142 = arith.divsi %140, %143 : i64
      llvm.store %142, %124 : i64, !llvm.ptr
      cf.br ^bb9
    ^bb11:
    %144 = arith.constant 0 : i32
    %145 = arith.extsi %144 : i32 to i64
    %146 = llvm.mlir.constant(1 : i64) : i64
    %147 = llvm.alloca %146 x i64 : (i64) -> !llvm.ptr
    llvm.store %145, %147 : i64, !llvm.ptr
    cf.br ^bb12
    ^bb12:
    %148 = llvm.load %124 : !llvm.ptr -> i64
    %149 = arith.constant 5 : i32
    %151 = arith.extsi %149 : i32 to i64
    %150 = arith.remsi %148, %151 : i64
    %152 = arith.constant 0 : i32
    %154 = arith.extsi %152 : i32 to i64
    %153 = arith.cmpi eq, %150, %154 : i64
    cf.cond_br %153, ^bb13, ^bb14
    ^bb13:
      %155 = llvm.load %147 : !llvm.ptr -> i64
      %156 = arith.constant 1 : i32
      %158 = arith.extsi %156 : i32 to i64
      %157 = arith.addi %155, %158 : i64
      llvm.store %157, %147 : i64, !llvm.ptr
      %159 = llvm.load %124 : !llvm.ptr -> i64
      %160 = arith.constant 5 : i32
      %162 = arith.extsi %160 : i32 to i64
      %161 = arith.divsi %159, %162 : i64
      llvm.store %161, %124 : i64, !llvm.ptr
      cf.br ^bb12
    ^bb14:
    %163 = llvm.mlir.constant(1 : i64) : i64
    %164 = llvm.alloca %163 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %164 : i64, !llvm.ptr
    %165 = llvm.load %128 : !llvm.ptr -> i64
    %166 = arith.constant 0 : i32
    %168 = arith.extsi %166 : i32 to i64
    %167 = arith.cmpi sgt, %165, %168 : i64
    cf.cond_br %167, ^bb15, ^bb16
    ^bb15:
      %169 = llvm.load %164 : !llvm.ptr -> i64
      %170 = arith.constant 2 : i32
      %172 = arith.extsi %170 : i32 to i64
      %171 = arith.divsi %169, %172 : i64
      llvm.store %171, %164 : i64, !llvm.ptr
      cf.br ^bb17
    ^bb16:
      cf.br ^bb17
    ^bb17:
    %173 = llvm.load %147 : !llvm.ptr -> i64
    %174 = arith.constant 0 : i32
    %176 = arith.extsi %174 : i32 to i64
    %175 = arith.cmpi sgt, %173, %176 : i64
    cf.cond_br %175, ^bb18, ^bb19
    ^bb18:
      %177 = llvm.load %164 : !llvm.ptr -> i64
      %178 = arith.constant 5 : i32
      %180 = arith.extsi %178 : i32 to i64
      %179 = arith.divsi %177, %180 : i64
      %181 = arith.constant 4 : i32
      %183 = arith.extsi %181 : i32 to i64
      %182 = arith.muli %179, %183 : i64
      llvm.store %182, %164 : i64, !llvm.ptr
      cf.br ^bb20
    ^bb19:
      cf.br ^bb20
    ^bb20:
    %184 = llvm.load %164 : !llvm.ptr -> i64
    func.return %184 : i64
  }
  func.func @totient_chain_len(%arg0: i64) -> i64 {
    %185 = llvm.mlir.constant(1 : i64) : i64
    %186 = llvm.alloca %185 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %186 : i64, !llvm.ptr
    %187 = arith.constant 0 : i32
    %188 = arith.extsi %187 : i32 to i64
    %189 = llvm.mlir.constant(1 : i64) : i64
    %190 = llvm.alloca %189 x i64 : (i64) -> !llvm.ptr
    llvm.store %188, %190 : i64, !llvm.ptr
    cf.br ^bb21
    ^bb21:
    %191 = llvm.load %186 : !llvm.ptr -> i64
    %192 = arith.constant 1 : i32
    %194 = arith.extsi %192 : i32 to i64
    %193 = arith.cmpi ne, %191, %194 : i64
    cf.cond_br %193, ^bb22, ^bb23
    ^bb22:
      %196 = llvm.load %186 : !llvm.ptr -> i64
      %195 = func.call @phi_2_5(%196) : (i64) -> i64
      llvm.store %195, %186 : i64, !llvm.ptr
      %197 = llvm.load %190 : !llvm.ptr -> i64
      %198 = arith.constant 1 : i32
      %200 = arith.extsi %198 : i32 to i64
      %199 = arith.addi %197, %200 : i64
      llvm.store %199, %190 : i64, !llvm.ptr
      cf.br ^bb21
    ^bb23:
    %201 = llvm.load %190 : !llvm.ptr -> i64
    func.return %201 : i64
  }
  func.func @tetration_cap(%arg0: i64, %arg1: i64) -> i64 {
    %202 = arith.constant 0 : i32
    %204 = arith.extsi %202 : i32 to i64
    %203 = arith.cmpi sle, %arg1, %204 : i64
    cf.cond_br %203, ^bb24, ^bb25
    ^bb24:
      %205 = arith.constant 0 : i32
      %206 = arith.extsi %205 : i32 to i64
      func.return %206 : i64
    ^bb25:
      cf.br ^bb26
    ^bb26:
    %207 = arith.constant 2 : i32
    %208 = arith.extsi %207 : i32 to i64
    %209 = arith.constant 1 : i32
    %211 = arith.extsi %209 : i32 to i64
    %210 = arith.cmpi sle, %arg0, %211 : i64
    cf.cond_br %210, ^bb27, ^bb28
    ^bb27:
      %212 = arith.cmpi slt, %208, %arg1 : i64
      cf.cond_br %212, ^bb30, ^bb31
      ^bb30:
        func.return %208 : i64
      ^bb31:
        cf.br ^bb32
      ^bb32:
      func.return %arg1 : i64
    ^bb28:
      cf.br ^bb29
    ^bb29:
    %213 = arith.constant 2 : i32
    %214 = arith.extsi %213 : i32 to i64
    %215 = llvm.mlir.constant(1 : i64) : i64
    %216 = llvm.alloca %215 x i64 : (i64) -> !llvm.ptr
    llvm.store %214, %216 : i64, !llvm.ptr
    %217 = llvm.mlir.constant(1 : i64) : i64
    %218 = llvm.alloca %217 x i64 : (i64) -> !llvm.ptr
    llvm.store %208, %218 : i64, !llvm.ptr
    cf.br ^bb33
    ^bb33:
    %219 = llvm.load %216 : !llvm.ptr -> i64
    %220 = arith.cmpi sle, %219, %arg0 : i64
    cf.cond_br %220, ^bb34, ^bb35
    ^bb34:
      %221 = llvm.load %218 : !llvm.ptr -> i64
      %222 = arith.constant 60 : i32
      %224 = arith.extsi %222 : i32 to i64
      %223 = arith.cmpi sge, %221, %224 : i64
      cf.cond_br %223, ^bb36, ^bb37
      ^bb36:
        func.return %arg1 : i64
      ^bb37:
        cf.br ^bb38
      ^bb38:
      %225 = arith.constant 1 : i32
      %226 = llvm.load %218 : !llvm.ptr -> i64
      %228 = arith.extsi %225 : i32 to i64
      %227 = arith.shli %228, %226 : i64
      llvm.store %227, %218 : i64, !llvm.ptr
      %229 = llvm.load %218 : !llvm.ptr -> i64
      %230 = arith.cmpi sge, %229, %arg1 : i64
      cf.cond_br %230, ^bb39, ^bb40
      ^bb39:
        func.return %arg1 : i64
      ^bb40:
        cf.br ^bb41
      ^bb41:
      %231 = llvm.load %216 : !llvm.ptr -> i64
      %232 = arith.constant 1 : i32
      %234 = arith.extsi %232 : i32 to i64
      %233 = arith.addi %231, %234 : i64
      llvm.store %233, %216 : i64, !llvm.ptr
      cf.br ^bb33
    ^bb35:
    %235 = llvm.load %218 : !llvm.ptr -> i64
    func.return %235 : i64
  }
  func.func @tetration_mod_pow2(%arg0: i64, %arg1: i64) -> i64 {
    %236 = arith.constant 0 : i32
    %238 = arith.extsi %236 : i32 to i64
    %237 = arith.cmpi sle, %arg1, %238 : i64
    cf.cond_br %237, ^bb42, ^bb43
    ^bb42:
      %239 = arith.constant 0 : i32
      %240 = arith.extsi %239 : i32 to i64
      func.return %240 : i64
    ^bb43:
      cf.br ^bb44
    ^bb44:
    %241 = arith.constant 1 : i32
    %243 = arith.extsi %241 : i32 to i64
    %242 = arith.shli %243, %arg1 : i64
    %244 = arith.constant 1 : i32
    %246 = arith.extsi %244 : i32 to i64
    %245 = arith.cmpi eq, %arg0, %246 : i64
    cf.cond_br %245, ^bb45, ^bb46
    ^bb45:
      %247 = arith.constant 2 : i32
      %249 = arith.extsi %247 : i32 to i64
      %248 = arith.remsi %249, %242 : i64
      func.return %248 : i64
    ^bb46:
      cf.br ^bb47
    ^bb47:
    %251 = arith.constant 1 : i32
    %253 = arith.extsi %251 : i32 to i64
    %252 = arith.subi %arg0, %253 : i64
    %250 = func.call @tetration_cap(%252, %arg1) : (i64, i64) -> i64
    %254 = arith.cmpi sge, %250, %arg1 : i64
    cf.cond_br %254, ^bb48, ^bb49
    ^bb48:
      %255 = arith.constant 0 : i32
      %256 = arith.extsi %255 : i32 to i64
      func.return %256 : i64
    ^bb49:
      cf.br ^bb50
    ^bb50:
    %257 = arith.constant 1 : i32
    %259 = arith.extsi %257 : i32 to i64
    %258 = arith.shli %259, %250 : i64
    %260 = arith.remsi %258, %242 : i64
    func.return %260 : i64
  }
  func.func @powmod_128(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %261 = arith.constant 1 : i32
    %262 = arith.extsi %arg2 : i64 to i128
    %264 = arith.extsi %261 : i32 to i64
    %265 = arith.trunci %262 : i128 to i64
    %263 = arith.remsi %264, %265 : i64
    %266 = arith.extsi %263 : i64 to i128
    %267 = llvm.mlir.constant(1 : i64) : i64
    %268 = llvm.alloca %267 x i128 : (i64) -> !llvm.ptr
    llvm.store %266, %268 : i128, !llvm.ptr
    %269 = arith.extsi %arg2 : i64 to i128
    %271 = arith.trunci %269 : i128 to i64
    %270 = arith.remsi %arg0, %271 : i64
    %272 = arith.extsi %270 : i64 to i128
    %273 = llvm.mlir.constant(1 : i64) : i64
    %274 = llvm.alloca %273 x i128 : (i64) -> !llvm.ptr
    llvm.store %272, %274 : i128, !llvm.ptr
    %275 = llvm.mlir.constant(1 : i64) : i64
    %276 = llvm.alloca %275 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %276 : i64, !llvm.ptr
    cf.br ^bb51
    ^bb51:
    %277 = llvm.load %276 : !llvm.ptr -> i64
    %278 = arith.constant 0 : i32
    %280 = arith.extsi %278 : i32 to i64
    %279 = arith.cmpi ne, %277, %280 : i64
    cf.cond_br %279, ^bb52, ^bb53
    ^bb52:
      %281 = llvm.load %276 : !llvm.ptr -> i64
      %282 = arith.constant 2 : i32
      %284 = arith.extsi %282 : i32 to i64
      %283 = arith.remsi %281, %284 : i64
      %285 = arith.constant 1 : i32
      %287 = arith.extsi %285 : i32 to i64
      %286 = arith.cmpi eq, %283, %287 : i64
      cf.cond_br %286, ^bb54, ^bb55
      ^bb54:
        %288 = llvm.load %268 : !llvm.ptr -> i128
        %289 = llvm.load %274 : !llvm.ptr -> i128
        %291 = arith.trunci %288 : i128 to i64
        %292 = arith.trunci %289 : i128 to i64
        %290 = arith.muli %291, %292 : i64
        %293 = arith.extsi %arg2 : i64 to i128
        %295 = arith.trunci %293 : i128 to i64
        %294 = arith.remsi %290, %295 : i64
        %296 = arith.extsi %294 : i64 to i128
        llvm.store %296, %268 : i128, !llvm.ptr
        cf.br ^bb56
      ^bb55:
        cf.br ^bb56
      ^bb56:
      %297 = llvm.load %274 : !llvm.ptr -> i128
      %298 = llvm.load %274 : !llvm.ptr -> i128
      %300 = arith.trunci %297 : i128 to i64
      %301 = arith.trunci %298 : i128 to i64
      %299 = arith.muli %300, %301 : i64
      %302 = arith.extsi %arg2 : i64 to i128
      %304 = arith.trunci %302 : i128 to i64
      %303 = arith.remsi %299, %304 : i64
      %305 = arith.extsi %303 : i64 to i128
      llvm.store %305, %274 : i128, !llvm.ptr
      %306 = llvm.load %276 : !llvm.ptr -> i64
      %307 = arith.constant 2 : i32
      %309 = arith.extsi %307 : i32 to i64
      %308 = arith.divsi %306, %309 : i64
      llvm.store %308, %276 : i64, !llvm.ptr
      cf.br ^bb51
    ^bb53:
    %310 = llvm.load %268 : !llvm.ptr -> i128
    %311 = arith.trunci %310 : i128 to i64
    func.return %311 : i64
  }
  func.func @tetration_mod(%arg0: i64, %arg1: i64) -> i64 {
    %312 = arith.constant 1 : i32
    %314 = arith.extsi %312 : i32 to i64
    %313 = arith.cmpi eq, %arg1, %314 : i64
    cf.cond_br %313, ^bb57, ^bb58
    ^bb57:
      %315 = arith.constant 0 : i32
      %316 = arith.extsi %315 : i32 to i64
      func.return %316 : i64
    ^bb58:
      cf.br ^bb59
    ^bb59:
    %317 = llvm.mlir.constant(1 : i64) : i64
    %318 = llvm.alloca %317 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %318 : i64, !llvm.ptr
    %319 = arith.constant 0 : i32
    %320 = arith.extsi %319 : i32 to i64
    %321 = llvm.mlir.constant(1 : i64) : i64
    %322 = llvm.alloca %321 x i64 : (i64) -> !llvm.ptr
    llvm.store %320, %322 : i64, !llvm.ptr
    cf.br ^bb60
    ^bb60:
    %323 = llvm.load %318 : !llvm.ptr -> i64
    %324 = arith.constant 2 : i32
    %326 = arith.extsi %324 : i32 to i64
    %325 = arith.remsi %323, %326 : i64
    %327 = arith.constant 0 : i32
    %329 = arith.extsi %327 : i32 to i64
    %328 = arith.cmpi eq, %325, %329 : i64
    cf.cond_br %328, ^bb61, ^bb62
    ^bb61:
      %330 = llvm.load %322 : !llvm.ptr -> i64
      %331 = arith.constant 1 : i32
      %333 = arith.extsi %331 : i32 to i64
      %332 = arith.addi %330, %333 : i64
      llvm.store %332, %322 : i64, !llvm.ptr
      %334 = llvm.load %318 : !llvm.ptr -> i64
      %335 = arith.constant 2 : i32
      %337 = arith.extsi %335 : i32 to i64
      %336 = arith.divsi %334, %337 : i64
      llvm.store %336, %318 : i64, !llvm.ptr
      cf.br ^bb60
    ^bb62:
    %338 = arith.constant 0 : i32
    %339 = arith.extsi %338 : i32 to i64
    %340 = llvm.mlir.constant(1 : i64) : i64
    %341 = llvm.alloca %340 x i64 : (i64) -> !llvm.ptr
    llvm.store %339, %341 : i64, !llvm.ptr
    cf.br ^bb63
    ^bb63:
    %342 = llvm.load %318 : !llvm.ptr -> i64
    %343 = arith.constant 5 : i32
    %345 = arith.extsi %343 : i32 to i64
    %344 = arith.remsi %342, %345 : i64
    %346 = arith.constant 0 : i32
    %348 = arith.extsi %346 : i32 to i64
    %347 = arith.cmpi eq, %344, %348 : i64
    cf.cond_br %347, ^bb64, ^bb65
    ^bb64:
      %349 = llvm.load %341 : !llvm.ptr -> i64
      %350 = arith.constant 1 : i32
      %352 = arith.extsi %350 : i32 to i64
      %351 = arith.addi %349, %352 : i64
      llvm.store %351, %341 : i64, !llvm.ptr
      %353 = llvm.load %318 : !llvm.ptr -> i64
      %354 = arith.constant 5 : i32
      %356 = arith.extsi %354 : i32 to i64
      %355 = arith.divsi %353, %356 : i64
      llvm.store %355, %318 : i64, !llvm.ptr
      cf.br ^bb63
    ^bb65:
    %357 = llvm.load %341 : !llvm.ptr -> i64
    %358 = arith.constant 0 : i32
    %360 = arith.extsi %358 : i32 to i64
    %359 = arith.cmpi eq, %357, %360 : i64
    cf.cond_br %359, ^bb66, ^bb67
    ^bb66:
      %362 = llvm.load %322 : !llvm.ptr -> i64
      %361 = func.call @tetration_mod_pow2(%arg0, %362) : (i64, i64) -> i64
      func.return %361 : i64
    ^bb67:
      cf.br ^bb68
    ^bb68:
    %363 = llvm.load %322 : !llvm.ptr -> i64
    %364 = arith.constant 0 : i32
    %366 = arith.extsi %364 : i32 to i64
    %365 = arith.cmpi eq, %363, %366 : i64
    cf.cond_br %365, ^bb69, ^bb70
    ^bb69:
      %367 = arith.constant 1 : i32
      %369 = arith.extsi %367 : i32 to i64
      %368 = arith.cmpi eq, %arg0, %369 : i64
      cf.cond_br %368, ^bb72, ^bb73
      ^bb72:
        %370 = arith.constant 2 : i32
        %372 = arith.extsi %370 : i32 to i64
        %371 = arith.remsi %372, %arg1 : i64
        func.return %371 : i64
      ^bb73:
        cf.br ^bb74
      ^bb74:
      %374 = arith.constant 1 : i32
      %376 = arith.extsi %374 : i32 to i64
      %375 = arith.subi %arg0, %376 : i64
      %377 = func.call @phi_2_5(%arg1) : (i64) -> i64
      %373 = func.call @tetration_mod(%375, %377) : (i64, i64) -> i64
      %379 = arith.constant 2 : i32
      %380 = arith.extsi %379 : i32 to i64
      %378 = func.call @powmod_128(%380, %373, %arg1) : (i64, i64, i64) -> i64
      func.return %378 : i64
    ^bb70:
      cf.br ^bb71
    ^bb71:
    %381 = arith.constant 1 : i32
    %382 = llvm.load %322 : !llvm.ptr -> i64
    %384 = arith.extsi %381 : i32 to i64
    %383 = arith.shli %384, %382 : i64
    %385 = arith.constant 1 : i32
    %386 = arith.extsi %385 : i32 to i64
    %387 = llvm.mlir.constant(1 : i64) : i64
    %388 = llvm.alloca %387 x i64 : (i64) -> !llvm.ptr
    llvm.store %386, %388 : i64, !llvm.ptr
    %389 = arith.constant 0 : i32
    %390 = arith.extsi %389 : i32 to i64
    %391 = llvm.mlir.constant(1 : i64) : i64
    %392 = llvm.alloca %391 x i64 : (i64) -> !llvm.ptr
    llvm.store %390, %392 : i64, !llvm.ptr
    cf.br ^bb75
    ^bb75:
    %393 = llvm.load %392 : !llvm.ptr -> i64
    %394 = llvm.load %341 : !llvm.ptr -> i64
    %395 = arith.cmpi slt, %393, %394 : i64
    cf.cond_br %395, ^bb76, ^bb77
    ^bb76:
      %396 = llvm.load %388 : !llvm.ptr -> i64
      %397 = arith.constant 5 : i32
      %399 = arith.extsi %397 : i32 to i64
      %398 = arith.muli %396, %399 : i64
      llvm.store %398, %388 : i64, !llvm.ptr
      %400 = llvm.load %392 : !llvm.ptr -> i64
      %401 = arith.constant 1 : i32
      %403 = arith.extsi %401 : i32 to i64
      %402 = arith.addi %400, %403 : i64
      llvm.store %402, %392 : i64, !llvm.ptr
      cf.br ^bb75
    ^bb77:
    %405 = llvm.load %322 : !llvm.ptr -> i64
    %404 = func.call @tetration_mod_pow2(%arg0, %405) : (i64, i64) -> i64
    %407 = llvm.load %388 : !llvm.ptr -> i64
    %406 = func.call @tetration_mod(%arg0, %407) : (i64, i64) -> i64
    %409 = llvm.load %388 : !llvm.ptr -> i64
    %408 = func.call @crt(%404, %383, %406, %409) : (i64, i64, i64, i64) -> i64
    %410 = llvm.load %388 : !llvm.ptr -> i64
    %411 = arith.muli %383, %410 : i64
    %412 = arith.remsi %408, %411 : i64
    func.return %412 : i64
  }
  func.func @stable_tetration_mod(%arg0: i64) -> i64 {
    %413 = func.call @totient_chain_len(%arg0) : (i64) -> i64
    %414 = arith.constant 1 : i32
    %416 = arith.extsi %414 : i32 to i64
    %415 = arith.addi %413, %416 : i64
    %417 = func.call @tetration_mod(%415, %arg0) : (i64, i64) -> i64
    func.return %417 : i64
  }
  func.func @main() -> i32 {
    %418 = arith.constant 1 : i32
    %419 = arith.constant 15 : i32
    %420 = arith.shli %418, %419 : i32
    %421 = arith.extsi %420 : i32 to i64
    %422 = arith.constant 1 : i32
    %423 = arith.extsi %422 : i32 to i64
    %424 = llvm.mlir.constant(1 : i64) : i64
    %425 = llvm.alloca %424 x i64 : (i64) -> !llvm.ptr
    llvm.store %423, %425 : i64, !llvm.ptr
    %426 = arith.constant 0 : i32
    %427 = arith.extsi %426 : i32 to i64
    %428 = llvm.mlir.constant(1 : i64) : i64
    %429 = llvm.alloca %428 x i64 : (i64) -> !llvm.ptr
    llvm.store %427, %429 : i64, !llvm.ptr
    cf.br ^bb78
    ^bb78:
    %430 = llvm.load %429 : !llvm.ptr -> i64
    %431 = arith.constant 15 : i32
    %433 = arith.extsi %431 : i32 to i64
    %432 = arith.cmpi slt, %430, %433 : i64
    cf.cond_br %432, ^bb79, ^bb80
    ^bb79:
      %434 = llvm.load %425 : !llvm.ptr -> i64
      %435 = arith.constant 5 : i32
      %437 = arith.extsi %435 : i32 to i64
      %436 = arith.muli %434, %437 : i64
      llvm.store %436, %425 : i64, !llvm.ptr
      %438 = llvm.load %429 : !llvm.ptr -> i64
      %439 = arith.constant 1 : i32
      %441 = arith.extsi %439 : i32 to i64
      %440 = arith.addi %438, %441 : i64
      llvm.store %440, %429 : i64, !llvm.ptr
      cf.br ^bb78
    ^bb80:
    %442 = arith.constant 3 : i32
    %444 = arith.constant 0 : i32
    %443 = arith.subi %444, %442 : i32
    %446 = arith.extsi %443 : i32 to i64
    %445 = arith.remsi %446, %421 : i64
    %447 = llvm.mlir.constant(1 : i64) : i64
    %448 = llvm.alloca %447 x i64 : (i64) -> !llvm.ptr
    llvm.store %445, %448 : i64, !llvm.ptr
    %449 = llvm.load %448 : !llvm.ptr -> i64
    %450 = arith.constant 0 : i32
    %452 = arith.extsi %450 : i32 to i64
    %451 = arith.cmpi slt, %449, %452 : i64
    cf.cond_br %451, ^bb81, ^bb82
    ^bb81:
      %453 = llvm.load %448 : !llvm.ptr -> i64
      %454 = arith.addi %453, %421 : i64
      llvm.store %454, %448 : i64, !llvm.ptr
      cf.br ^bb83
    ^bb82:
      cf.br ^bb83
    ^bb83:
    %456 = llvm.load %425 : !llvm.ptr -> i64
    %455 = func.call @stable_tetration_mod(%456) : (i64) -> i64
    %457 = arith.constant 3 : i32
    %459 = arith.extsi %457 : i32 to i64
    %458 = arith.subi %455, %459 : i64
    %460 = llvm.load %425 : !llvm.ptr -> i64
    %461 = arith.remsi %458, %460 : i64
    %462 = llvm.mlir.constant(1 : i64) : i64
    %463 = llvm.alloca %462 x i64 : (i64) -> !llvm.ptr
    llvm.store %461, %463 : i64, !llvm.ptr
    %464 = llvm.load %463 : !llvm.ptr -> i64
    %465 = arith.constant 0 : i32
    %467 = arith.extsi %465 : i32 to i64
    %466 = arith.cmpi slt, %464, %467 : i64
    cf.cond_br %466, ^bb84, ^bb85
    ^bb84:
      %468 = llvm.load %463 : !llvm.ptr -> i64
      %469 = llvm.load %425 : !llvm.ptr -> i64
      %470 = arith.addi %468, %469 : i64
      llvm.store %470, %463 : i64, !llvm.ptr
      cf.br ^bb86
    ^bb85:
      cf.br ^bb86
    ^bb86:
    %472 = llvm.load %448 : !llvm.ptr -> i64
    %473 = llvm.load %463 : !llvm.ptr -> i64
    %474 = llvm.load %425 : !llvm.ptr -> i64
    %471 = func.call @crt(%472, %421, %473, %474) : (i64, i64, i64, i64) -> i64
    %475 = llvm.load %425 : !llvm.ptr -> i64
    %476 = arith.muli %421, %475 : i64
    %477 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %478 = arith.remsi %471, %476 : i64
    %479 = llvm.call @printf(%477, %478) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    %480 = arith.constant 0 : i32
    func.return %480 : i32
  }
}