Problem 343

Sum f(n^3) for n=1..2e6; f(n)=LPF(n+1)-1 style via max LPF of factors of n^3+1.

Answer269533451410884183
Output269533451410884183
StatusPASS
Native helperno
Runtime80 ms
Peak memory43408 KB
Time complexityO(n^2) (estimated)
Space complexityO(n^2) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^2)?
Space complexityO(n^2)?
ApproachFlow solutionNot curated
VerdictUnknown

Flow source

# Project Euler 343
# Sum f(n^3) for n=1..2e6; f(n)=LPF(n+1)-1 style via max LPF of factors of n^3+1.

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

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

function tonelli(a0: i64, p: i64) -> i64 {
    let a: i64 = a0 % p
    if a == 0 { return 0 }
    if p % 4 == 3 {
        return modpow(a, (p + 1) / 4, p)
    }
    let mut q: i64 = p - 1
    let mut s: i64 = 0
    while q % 2 == 0 {
        q = q / 2
        s = s + 1
    }
    let mut z: i64 = 2
    while modpow(z, (p - 1) / 2, p) != p - 1 {
        z = z + 1
    }
    let mut m: i64 = s
    let mut c: i64 = modpow(z, q, p)
    let mut t: i64 = modpow(a, q, p)
    let mut r: i64 = modpow(a, (q + 1) / 2, p)
    while t != 1 {
        let mut i: i64 = 1
        let mut t2: i64 = (t * t) % p
        while t2 != 1 {
            t2 = (t2 * t2) % p
            i = i + 1
        }
        # b = c^(2^(m-i-1))
        let mut expb: i64 = 1
        let mut j: i64 = 0
        while j < m - i - 1 {
            expb = expb * 2
            j = j + 1
        }
        let b: i64 = modpow(c, expb, p)
        r = (r * b) % p
        t = (((t * b) % p) * b) % p
        c = (b * b) % p
        m = i
    }
    return r
}

function strip(p: i64, root: i64, limit: i64, rem: ptr<i64>, lpfq: ptr<i64>) -> i32 {
    let mut start: i64 = root
    if start == 0 { start = p }
    let mut k: i64 = start
    while k <= limit {
        let mut v: i64 = rem[k]
        if v % p == 0 {
            while v % p == 0 { v = v / p }
            rem[k] = v
            lpfq[k] = p
        }
        k = k + p
    }
    return 0
}

function main() -> i32 {
    let limit: i64 = 2000000
    let lpf: ptr<i32> = calloc(limit + 2, 4)
    if lpf == null { return 1 }
    # sieve for primes, then mark largest prime factor
    let sieve: ptr<i8> = calloc(limit + 2, 1)
    let mut i: i64 = 0
    while i <= limit + 1 {
        sieve[i] = 1
        i = i + 1
    }
    sieve[0] = 0; sieve[1] = 0
    i = 2
    while i * i <= limit + 1 {
        if sieve[i] == 1 {
            let mut j: i64 = i * i
            while j <= limit + 1 {
                sieve[j] = 0
                j = j + i
            }
        }
        i = i + 1
    }
    let mut pc: i64 = 0
    i = 2
    while i <= limit + 1 {
        if sieve[i] == 1 { pc = pc + 1 }
        i = i + 1
    }
    let primes: ptr<i64> = calloc(pc, 8)
    let mut idx: i64 = 0
    i = 2
    while i <= limit + 1 {
        if sieve[i] == 1 {
            primes[idx] = i
            idx = idx + 1
        }
        i = i + 1
    }
    # largest prime factor: overwrite with increasing primes
    i = 0
    while i <= limit + 1 {
        lpf[i] = 0
        i = i + 1
    }
    idx = 0
    while idx < pc {
        let p: i64 = primes[idx]
        let mut m: i64 = p
        while m <= limit + 1 {
            lpf[m] = p as i32
            m = m + p
        }
        idx = idx + 1
    }
    free(sieve)

    let rem: ptr<i64> = calloc(limit + 1, 8)
    let lpfq: ptr<i64> = calloc(limit + 1, 8)
    i = 1
    while i <= limit {
        rem[i] = i * i - i + 1
        lpfq[i] = 1
        i = i + 1
    }

    idx = 0
    while idx < pc {
        let p: i64 = primes[idx]
        if p == 2 {
            idx = idx + 1
            continue
        }
        if p == 3 {
            strip(3, 2, limit, rem, lpfq)
            idx = idx + 1
            continue
        }
        if p % 3 != 1 {
            idx = idx + 1
            continue
        }
        let sqrt_disc: i64 = tonelli(p - 3, p)
        let inv2: i64 = (p + 1) / 2
        let mut d1: i64 = (1 + sqrt_disc) % p
        if d1 < 0 { d1 = d1 + p }
        let mut root1: i64 = (d1 * inv2) % p
        if root1 < 0 { root1 = root1 + p }
        let mut d2: i64 = (1 - sqrt_disc) % p
        if d2 < 0 { d2 = d2 + p }
        let mut root2: i64 = (d2 * inv2) % p
        if root2 < 0 { root2 = root2 + p }
        # Verify roots; if broken, brute-force residues
        let chk1: i64 = (root1 * root1 - root1 + 1) % p
        let chk2: i64 = (root2 * root2 - root2 + 1) % p
        let c1: i64 = chk1
        if c1 < 0 { c1 = c1 + p }
        let c2: i64 = chk2
        if c2 < 0 { c2 = c2 + p }
        if c1 != 0 || c2 != 0 {
            root1 = -1
            root2 = -1
            let mut rr: i64 = 0
            while rr < p {
                let mut v: i64 = (rr * rr - rr + 1) % p
                if v < 0 { v = v + p }
                if v == 0 {
                    if root1 < 0 { root1 = rr }
                    elif root2 < 0 { root2 = rr; break }
                }
                rr = rr + 1
            }
        }
        if root1 >= 0 {
            strip(p, root1, limit, rem, lpfq)
        }
        if root2 >= 0 && root2 != root1 {
            strip(p, root2, limit, rem, lpfq)
        }
        idx = idx + 1
    }

    let mut total: i64 = 0
    let mut k: i64 = 1
    while k <= limit {
        if rem[k] > 1 { lpfq[k] = rem[k] }
        let a: i64 = lpf[k + 1] as i64
        let b: i64 = lpfq[k]
        let m: i64 = a
        if b > m { m = b }
        total = total + m - 1
        k = k + 1
    }
    printf("%lld\n", total)
    free(lpf); free(primes); free(rem); free(lpfq)
    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 modpow_i64_i64_i64(int64_t base, int64_t exp, int64_t mod);
int64_t tonelli_i64_i64(int64_t a0, int64_t p);
int32_t strip_i64_i64_i64_ptr_i64_ptr_i64(int64_t p, int64_t root, int64_t limit, int64_t* rem, int64_t* lpfq);
int32_t main(void);



int64_t modpow_i64_i64_i64(int64_t base, int64_t exp, int64_t mod) {
    int64_t r = 1;
    int64_t b = FLOW_CHECKED_MOD((base), (mod));
    int64_t e = exp;
    while (e > 0) {
        if (FLOW_CHECKED_MOD((e), (2)) == 1) {
            r = FLOW_CHECKED_MOD(((r * b)), (mod));
        }
        b = FLOW_CHECKED_MOD(((b * b)), (mod));
        e = FLOW_CHECKED_DIV((e), (2));
    }
    return r;
}

int64_t tonelli_i64_i64(int64_t a0, int64_t p) {
    int64_t a = FLOW_CHECKED_MOD((a0), (p));
    if (a == 0) {
        return 0;
    }
    if (FLOW_CHECKED_MOD((p), (4)) == 3) {
        return modpow_i64_i64_i64(a, FLOW_CHECKED_DIV(((p + 1)), (4)), p);
    }
    int64_t q = (p - 1);
    int64_t s = 0;
    while (FLOW_CHECKED_MOD((q), (2)) == 0) {
        q = FLOW_CHECKED_DIV((q), (2));
        s = (s + 1);
    }
    int64_t z = 2;
    while (modpow_i64_i64_i64(z, FLOW_CHECKED_DIV(((p - 1)), (2)), p) != (p - 1)) {
        z = (z + 1);
    }
    int64_t m = s;
    int64_t c = modpow_i64_i64_i64(z, q, p);
    int64_t t = modpow_i64_i64_i64(a, q, p);
    int64_t r = modpow_i64_i64_i64(a, FLOW_CHECKED_DIV(((q + 1)), (2)), p);
    while (t != 1) {
        int64_t i = 1;
        int64_t t2 = FLOW_CHECKED_MOD(((t * t)), (p));
        while (t2 != 1) {
            t2 = FLOW_CHECKED_MOD(((t2 * t2)), (p));
            i = (i + 1);
        }
        int64_t expb = 1;
        int64_t j = 0;
        while (j < ((m - i) - 1)) {
            expb = (expb * 2);
            j = (j + 1);
        }
        int64_t b = modpow_i64_i64_i64(c, expb, p);
        r = FLOW_CHECKED_MOD(((r * b)), (p));
        t = FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD(((t * b)), (p)) * b)), (p));
        c = FLOW_CHECKED_MOD(((b * b)), (p));
        m = i;
    }
    return r;
}

int32_t strip_i64_i64_i64_ptr_i64_ptr_i64(int64_t p, int64_t root, int64_t limit, int64_t* rem, int64_t* lpfq) {
    int64_t start = root;
    if (start == 0) {
        start = p;
    }
    int64_t k = start;
    while (k <= limit) {
        int64_t v = rem[k];
        if (FLOW_CHECKED_MOD((v), (p)) == 0) {
            while (FLOW_CHECKED_MOD((v), (p)) == 0) {
                v = FLOW_CHECKED_DIV((v), (p));
            }
            rem[k] = v;
            lpfq[k] = p;
        }
        k = (k + p);
    }
    return 0;
}

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