Problem 411

sum_{k=1..30} S(k^5): longest nondecreasing path through modular stations.

Answer9936352
Output9936352
StatusPASS
Native helperno
Runtime19110 ms
Peak memory1021872 KB
Time complexityO(n^2) (estimated)
Space complexityO(n^2) (estimated)

Performance comparison

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

Flow source

# Project Euler 411
# sum_{k=1..30} S(k^5): longest nondecreasing path through modular stations.

import euler.nt { gcd }

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

function modpow(base0: i64, exp0: i64, mod: i64) -> i64 {
    let mut r: i64 = 1
    let mut b: i64 = base0 % mod
    let mut e: i64 = exp0
    while e > 0 {
        if e % 2 == 1 {
            r = ((r as i128) * (b as i128) % (mod as i128)) as i64
        }
        b = ((b as i128) * (b as i128) % (mod as i128)) as i64
        e = e / 2
    }
    return r
}

function phi_of(n0: i64) -> i64 {
    let mut n: i64 = n0
    let mut result: i64 = n0
    let mut p: i64 = 2
    while p * p <= n {
        if n % p == 0 {
            while n % p == 0 { n = n / p }
            result = result / p * (p - 1)
        }
        if p == 2 { p = 3 } else { p = p + 2 }
    }
    if n > 1 { result = result / n * (n - 1) }
    return result
}

function mult_order(a: i64, n: i64) -> i64 {
    if n == 1 { return 1 }
    let mut order: i64 = phi_of(n)
    let mut x: i64 = order
    let mut p: i64 = 2
    while p * p <= x {
        if x % p == 0 {
            while x % p == 0 { x = x / p }
            while order % p == 0 && modpow(a, order / p, n) == 1 {
                order = order / p
            }
        }
        if p == 2 { p = 3 } else { p = p + 2 }
    }
    if x > 1 {
        while order % x == 0 && modpow(a, order / x, n) == 1 {
            order = order / x
        }
    }
    return order
}

function lcm64(a: i64, b: i64) -> i64 {
    return a / gcd(a, b) * b
}

function compute_S(n: i64) -> i64 {
    let mut n2: i64 = n
    let mut v2: i64 = 0
    while n2 % 2 == 0 { n2 = n2 / 2; v2 = v2 + 1 }
    let mut n3: i64 = n
    let mut v3: i64 = 0
    while n3 % 3 == 0 { n3 = n3 / 3; v3 = v3 + 1 }
    let mut preperiod: i64 = v2
    if v3 > preperiod { preperiod = v3 }
    let ord2: i64 = 1
    if n2 > 1 { ord2 = mult_order(2, n2) }
    let ord3: i64 = 1
    if n3 > 1 { ord3 = mult_order(3, n3) }
    let period: i64 = lcm64(ord2, ord3)
    let total: i64 = preperiod + period

    let counts: ptr<i32> = calloc(n + 1, 4)
    if counts == null { return -1 }
    let mut x: i64 = 1 % n
    let mut t: i64 = 0
    while t < total {
        counts[x] = (counts[x] as i64 + 1) as i32
        x = (x * 2) % n
        t = t + 1
    }

    # prefix: counts[i] = start index, counts[i+1]-counts[i] = length
    let mut running: i64 = 0
    let mut i: i64 = 0
    while i < n {
        let c: i64 = counts[i] as i64
        counts[i] = running as i32
        running = running + c
        i = i + 1
    }
    counts[n] = running as i32

    let pos: ptr<i32> = calloc(n, 4)
    let ys: ptr<i32> = calloc(total, 4)
    if pos == null || ys == null { return -1 }
    i = 0
    while i < n {
        pos[i] = counts[i]
        i = i + 1
    }

    x = 1 % n
    let mut y: i64 = 1 % n
    t = 0
    while t < total {
        let idx: i64 = pos[x] as i64
        ys[idx] = y as i32
        pos[x] = (idx + 1) as i32
        x = (x * 2) % n
        y = (y * 3) % n
        t = t + 1
    }

    # For each x bucket, sort ys and run patience LIS across increasing x
    let tails: ptr<i32> = calloc(total + 1, 4)
    let mut len: i64 = 0
    let mut xx: i64 = 0
    while xx < n {
        let start: i64 = counts[xx] as i64
        let end: i64 = counts[xx + 1] as i64
        let segn: i64 = end - start
        if segn == 1 {
            let v: i64 = ys[start] as i64
            let mut lo: i64 = 0
            let mut hi: i64 = len
            while lo < hi {
                let mid: i64 = (lo + hi) / 2
                if (tails[mid] as i64) <= v { lo = mid + 1 } else { hi = mid }
            }
            tails[lo] = v as i32
            if lo == len { len = len + 1 }
        } elif segn > 1 {
            # insertion sort segment (usually small)
            let mut a: i64 = start + 1
            while a < end {
                let key: i32 = ys[a]
                let mut b: i64 = a
                while b > start && (ys[b - 1] as i64) > (key as i64) {
                    ys[b] = ys[b - 1]
                    b = b - 1
                }
                ys[b] = key
                a = a + 1
            }
            a = start
            while a < end {
                let v2: i64 = ys[a] as i64
                let mut lo2: i64 = 0
                let mut hi2: i64 = len
                while lo2 < hi2 {
                    let mid2: i64 = (lo2 + hi2) / 2
                    if (tails[mid2] as i64) <= v2 { lo2 = mid2 + 1 } else { hi2 = mid2 }
                }
                tails[lo2] = v2 as i32
                if lo2 == len { len = len + 1 }
                a = a + 1
            }
        }
        xx = xx + 1
    }

    free(tails)
    free(ys)
    free(pos)
    free(counts)
    return len
}

function ipow(a: i64, e: i64) -> i64 {
    let mut r: i64 = 1
    let mut i: i64 = 0
    while i < e { r = r * a; i = i + 1 }
    return r
}

function main() -> i32 {
    let mut total: i64 = 0
    let mut k: i64 = 1
    while k <= 30 {
        let n: i64 = ipow(k, 5)
        total = total + compute_S(n)
        k = k + 1
    }
    printf("%lld\n", total)
    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 modpow_i64_i64_i64(int64_t base0, int64_t exp0, int64_t mod);
int64_t phi_of_i64(int64_t n0);
int64_t mult_order_i64_i64(int64_t a, int64_t n);
int64_t lcm64_i64_i64(int64_t a, int64_t b);
int64_t compute_S_i64(int64_t n);
int64_t ipow_i64_i64(int64_t a, int64_t e);
int32_t main(void);

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 modpow_i64_i64_i64(int64_t base0, int64_t exp0, int64_t mod) {
    int64_t r = 1;
    int64_t b = FLOW_CHECKED_MOD((base0), (mod));
    int64_t e = exp0;
    while (e > 0) {
        if (FLOW_CHECKED_MOD((e), (2)) == 1) {
            r = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(r)) * ((__int128)(b)))), (((__int128)(mod))))));
        }
        b = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(b)) * ((__int128)(b)))), (((__int128)(mod))))));
        e = FLOW_CHECKED_DIV((e), (2));
    }
    return r;
}

int64_t phi_of_i64(int64_t n0) {
    int64_t n = n0;
    int64_t result = n0;
    int64_t p = 2;
    while ((p * p) <= n) {
        if (FLOW_CHECKED_MOD((n), (p)) == 0) {
            while (FLOW_CHECKED_MOD((n), (p)) == 0) {
                n = FLOW_CHECKED_DIV((n), (p));
            }
            result = (FLOW_CHECKED_DIV((result), (p)) * (p - 1));
        }
        if (p == 2) {
            p = 3;
        } else {
            p = (p + 2);
        }
    }
    if (n > 1) {
        result = (FLOW_CHECKED_DIV((result), (n)) * (n - 1));
    }
    return result;
}

int64_t mult_order_i64_i64(int64_t a, int64_t n) {
    if (n == 1) {
        return 1;
    }
    int64_t order = phi_of_i64(n);
    int64_t x = order;
    int64_t p = 2;
    while ((p * p) <= x) {
        if (FLOW_CHECKED_MOD((x), (p)) == 0) {
            while (FLOW_CHECKED_MOD((x), (p)) == 0) {
                x = FLOW_CHECKED_DIV((x), (p));
            }
            while ((FLOW_CHECKED_MOD((order), (p)) == 0 && modpow_i64_i64_i64(a, FLOW_CHECKED_DIV((order), (p)), n) == 1)) {
                order = FLOW_CHECKED_DIV((order), (p));
            }
        }
        if (p == 2) {
            p = 3;
        } else {
            p = (p + 2);
        }
    }
    if (x > 1) {
        while ((FLOW_CHECKED_MOD((order), (x)) == 0 && modpow_i64_i64_i64(a, FLOW_CHECKED_DIV((order), (x)), n) == 1)) {
            order = FLOW_CHECKED_DIV((order), (x));
        }
    }
    return order;
}

int64_t lcm64_i64_i64(int64_t a, int64_t b) {
    return (FLOW_CHECKED_DIV((a), (gcd_i64_i64(a, b))) * b);
}

int64_t compute_S_i64(int64_t n) {
    int64_t n2 = n;
    int64_t v2 = 0;
    while (FLOW_CHECKED_MOD((n2), (2)) == 0) {
        n2 = FLOW_CHECKED_DIV((n2), (2));
        v2 = (v2 + 1);
    }
    int64_t n3 = n;
    int64_t v3 = 0;
    while (FLOW_CHECKED_MOD((n3), (3)) == 0) {
        n3 = FLOW_CHECKED_DIV((n3), (3));
        v3 = (v3 + 1);
    }
    int64_t preperiod = v2;
    if (v3 > preperiod) {
        preperiod = v3;
    }
    int64_t ord2 = 1;
    if (n2 > 1) {
        ord2 = mult_order_i64_i64(2, n2);
    }
    int64_t ord3 = 1;
    if (n3 > 1) {
        ord3 = mult_order_i64_i64(3, n3);
    }
    int64_t period = lcm64_i64_i64(ord2, ord3);
    int64_t total = (preperiod + period);
    int32_t* counts = (int32_t*)(calloc((n + 1), 4));
    if (counts == NULL) {
        return (-1);
    }
    int64_t x = FLOW_CHECKED_MOD((1), (n));
    int64_t t = 0;
    while (t < total) {
        counts[x] = ((int32_t)((((int64_t)(counts[x])) + 1)));
        x = FLOW_CHECKED_MOD(((x * 2)), (n));
        t = (t + 1);
    }
    int64_t running = 0;
    int64_t i = 0;
    while (i < n) {
        int64_t c = ((int64_t)(counts[i]));
        counts[i] = ((int32_t)(running));
        running = (running + c);
        i = (i + 1);
    }
    counts[n] = ((int32_t)(running));
    int32_t* pos = (int32_t*)(calloc(n, 4));
    int32_t* ys = (int32_t*)(calloc(total, 4));
    if ((pos == NULL || ys == NULL)) {
        return (-1);
    }
    i = 0;
    while (i < n) {
        pos[i] = counts[i];
        i = (i + 1);
    }
    x = FLOW_CHECKED_MOD((1), (n));
    int64_t y = FLOW_CHECKED_MOD((1), (n));
    t = 0;
    while (t < total) {
        int64_t idx = ((int64_t)(pos[x]));
        ys[idx] = ((int32_t)(y));
        pos[x] = ((int32_t)((idx + 1)));
        x = FLOW_CHECKED_MOD(((x * 2)), (n));
        y = FLOW_CHECKED_MOD(((y * 3)), (n));
        t = (t + 1);
    }
    int32_t* tails = (int32_t*)(calloc((total + 1), 4));
    int64_t len = 0;
    int64_t xx = 0;
    while (xx < n) {
        int64_t start = ((int64_t)(counts[xx]));
        int64_t end = ((int64_t)(counts[(xx + 1)]));
        int64_t segn = (end - start);
        if (segn == 1) {
            int64_t v = ((int64_t)(ys[start]));
            int64_t lo = 0;
            int64_t hi = len;
            while (lo < hi) {
                int64_t mid = FLOW_CHECKED_DIV(((lo + hi)), (2));
                if (((int64_t)(tails[mid])) <= v) {
                    lo = (mid + 1);
                } else {
                    hi = mid;
                }
            }
            tails[lo] = ((int32_t)(v));
            if (lo == len) {
                len = (len + 1);
            }
        } else if (segn > 1) {
            int64_t a = (start + 1);
            while (a < end) {
                int32_t key = ys[a];
                int64_t b = a;
                while ((b > start && ((int64_t)(ys[(b - 1)])) > ((int64_t)(key)))) {
                    ys[b] = ys[(b - 1)];
                    b = (b - 1);
                }
                ys[b] = key;
                a = (a + 1);
            }
            a = start;
            while (a < end) {
                int64_t v2 = ((int64_t)(ys[a]));
                int64_t lo2 = 0;
                int64_t hi2 = len;
                while (lo2 < hi2) {
                    int64_t mid2 = FLOW_CHECKED_DIV(((lo2 + hi2)), (2));
                    if (((int64_t)(tails[mid2])) <= v2) {
                        lo2 = (mid2 + 1);
                    } else {
                        hi2 = mid2;
                    }
                }
                tails[lo2] = ((int32_t)(v2));
                if (lo2 == len) {
                    len = (len + 1);
                }
                a = (a + 1);
            }
        }
        xx = (xx + 1);
    }
    free(tails);
    free(ys);
    free(pos);
    free(counts);
    return len;
}

int64_t ipow_i64_i64(int64_t a, int64_t e) {
    int64_t r = 1;
    int64_t i = 0;
    while (i < e) {
        r = (r * a);
        i = (i + 1);
    }
    return r;
}

int32_t main(void) {
    int64_t total = 0;
    int64_t k = 1;
    while (k <= 30) {
        int64_t n = ipow_i64_i64(k, 5);
        total = (total + compute_S_i64(n));
        k = (k + 1);
    }
    printf("%lld\n", total);
    return 0;
}

Generated MLIR

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