Problem 374

S(10^14) = sum f(n)*m(n) mod 982451653.

Answer334420941
Output334420941
StatusPASS
Native helperno
Runtime280 ms
Peak memory111584 KB
Time complexityO(n) (estimated)
Space complexityO(n) (estimated)

Performance comparison

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

Flow source

# Project Euler 374
# S(10^14) = sum f(n)*m(n) mod 982451653.

import euler.nt { isqrt }

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

function max_base_k(n: i64) -> i64 {
    let d: i64 = 1 + 8 * (n + 1)
    let s: i64 = isqrt(d)
    let mut k: i64 = (s - 1) / 2
    while k * (k + 1) / 2 - 1 > n {
        k = k - 1
    }
    while (k + 1) * (k + 2) / 2 - 1 <= n {
        k = k + 1
    }
    return k
}

function main() -> i32 {
    let p: i64 = 982451653
    let limit: i64 = 100000000000000
    let inv2: i64 = (p + 1) / 2

    let mut ans: i64 = 1
    let k_last: i64 = max_base_k(limit)
    let r_max: i64 = limit - (k_last * (k_last + 1) / 2 - 1)

    let inv_size: i64 = k_last + 1
    if inv_size < 3 { inv_size = 3 }
    let inv: ptr<i64> = calloc(inv_size, 8)
    if inv == null { return 1 }
    inv[1] = 1
    let mut i: i64 = 2
    while i < inv_size {
        inv[i] = p - (p / i) * inv[p % i] % p
        i = i + 1
    }

    let mut upto: i64 = 4
    if limit < 4 { upto = limit }
    if upto >= 2 {
        let cnt: i64 = upto - 1
        ans = ans + (2 + upto) * cnt / 2
    }
    ans = ans % p

    if k_last < 3 {
        printf("%lld\n", ans)
        free(inv)
        return 0
    }

    let mut fact: i64 = 2
    let mut sum_inv3: i64 = 0
    let mut prefix_Lm1: i64 = 0
    let mut need_prefix: i64 = 0
    if r_max >= 1 && r_max <= k_last - 2 { need_prefix = 1 }
    let capture_k: i64 = k_last - r_max
    let mut k: i64 = 3
    while k < k_last {
        fact = (fact * k) % p
        sum_inv3 = sum_inv3 + inv[k]
        if sum_inv3 >= p { sum_inv3 = sum_inv3 - p }

        let tmp: i64 = (1 + (k + 1) % p * (sum_inv3 % p) % p + (2 * k + 3) % p * inv2 % p) % p
        let sum_f_block: i64 = (fact * tmp) % p
        ans = (ans + (k - 1) % p * sum_f_block % p) % p
        if need_prefix == 1 && k == capture_k {
            prefix_Lm1 = sum_inv3
        }
        k = k + 1
    }

    k = k_last
    fact = (fact * k) % p
    sum_inv3 = sum_inv3 + inv[k]
    if sum_inv3 >= p { sum_inv3 = sum_inv3 - p }

    let mut sum_f: i64 = 0
    if r_max <= k - 2 {
        if r_max == 0 {
            sum_f = fact
        } else {
            let mut sum_inv_range: i64 = (sum_inv3 - prefix_Lm1) % p
            if sum_inv_range < 0 { sum_inv_range = sum_inv_range + p }
            let tmp2: i64 = (1 + (k + 1) * sum_inv_range) % p
            sum_f = (fact * tmp2) % p
        }
    } else {
        if r_max == k - 1 {
            let tmp3: i64 = (1 + (k + 1) * sum_inv3 + (k + 1) * inv2) % p
            sum_f = (fact * tmp3) % p
        } else {
            let tmp4: i64 = (1 + (k + 1) * sum_inv3 + (2 * k + 3) * inv2) % p
            sum_f = (fact * tmp4) % p
        }
    }

    ans = (ans + (k - 1) * sum_f) % p
    printf("%lld\n", ans)
    free(inv)
    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 max_base_k_i64(int64_t n);
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 max_base_k_i64(int64_t n) {
    int64_t d = (1 + (8 * (n + 1)));
    int64_t s = isqrt_i64(d);
    int64_t k = FLOW_CHECKED_DIV(((s - 1)), (2));
    while ((FLOW_CHECKED_DIV(((k * (k + 1))), (2)) - 1) > n) {
        k = (k - 1);
    }
    while ((FLOW_CHECKED_DIV((((k + 1) * (k + 2))), (2)) - 1) <= n) {
        k = (k + 1);
    }
    return k;
}

int32_t main(void) {
    int64_t p = 982451653;
    int64_t limit = 100000000000000;
    int64_t inv2 = FLOW_CHECKED_DIV(((p + 1)), (2));
    int64_t ans = 1;
    int64_t k_last = max_base_k_i64(limit);
    int64_t r_max = (limit - (FLOW_CHECKED_DIV(((k_last * (k_last + 1))), (2)) - 1));
    int64_t inv_size = (k_last + 1);
    if (inv_size < 3) {
        inv_size = 3;
    }
    int64_t* inv = (int64_t*)(calloc(inv_size, 8));
    if (inv == NULL) {
        return 1;
    }
    inv[1] = 1;
    int64_t i = 2;
    while (i < inv_size) {
        inv[i] = (p - FLOW_CHECKED_MOD(((FLOW_CHECKED_DIV((p), (i)) * inv[FLOW_CHECKED_MOD((p), (i))])), (p)));
        i = (i + 1);
    }
    int64_t upto = 4;
    if (limit < 4) {
        upto = limit;
    }
    if (upto >= 2) {
        int64_t cnt = (upto - 1);
        ans = (ans + FLOW_CHECKED_DIV((((2 + upto) * cnt)), (2)));
    }
    ans = FLOW_CHECKED_MOD((ans), (p));
    if (k_last < 3) {
        printf("%lld\n", ans);
        free(inv);
        return 0;
    }
    int64_t fact = 2;
    int64_t sum_inv3 = 0;
    int64_t prefix_Lm1 = 0;
    int64_t need_prefix = 0;
    if ((r_max >= 1 && r_max <= (k_last - 2))) {
        need_prefix = 1;
    }
    int64_t capture_k = (k_last - r_max);
    int64_t k = 3;
    while (k < k_last) {
        fact = FLOW_CHECKED_MOD(((fact * k)), (p));
        sum_inv3 = (sum_inv3 + inv[k]);
        if (sum_inv3 >= p) {
            sum_inv3 = (sum_inv3 - p);
        }
        int64_t tmp = FLOW_CHECKED_MOD((((1 + FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD(((k + 1)), (p)) * FLOW_CHECKED_MOD((sum_inv3), (p)))), (p))) + FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD((((2 * k) + 3)), (p)) * inv2)), (p)))), (p));
        int64_t sum_f_block = FLOW_CHECKED_MOD(((fact * tmp)), (p));
        ans = FLOW_CHECKED_MOD(((ans + FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD(((k - 1)), (p)) * sum_f_block)), (p)))), (p));
        if ((need_prefix == 1 && k == capture_k)) {
            prefix_Lm1 = sum_inv3;
        }
        k = (k + 1);
    }
    k = k_last;
    fact = FLOW_CHECKED_MOD(((fact * k)), (p));
    sum_inv3 = (sum_inv3 + inv[k]);
    if (sum_inv3 >= p) {
        sum_inv3 = (sum_inv3 - p);
    }
    int64_t sum_f = 0;
    if (r_max <= (k - 2)) {
        if (r_max == 0) {
            sum_f = fact;
        } else {
            int64_t sum_inv_range = FLOW_CHECKED_MOD(((sum_inv3 - prefix_Lm1)), (p));
            if (sum_inv_range < 0) {
                sum_inv_range = (sum_inv_range + p);
            }
            int64_t tmp2 = FLOW_CHECKED_MOD(((1 + ((k + 1) * sum_inv_range))), (p));
            sum_f = FLOW_CHECKED_MOD(((fact * tmp2)), (p));
        }
    } else {
        if (r_max == (k - 1)) {
            int64_t tmp3 = FLOW_CHECKED_MOD((((1 + ((k + 1) * sum_inv3)) + ((k + 1) * inv2))), (p));
            sum_f = FLOW_CHECKED_MOD(((fact * tmp3)), (p));
        } else {
            int64_t tmp4 = FLOW_CHECKED_MOD((((1 + ((k + 1) * sum_inv3)) + (((2 * k) + 3) * inv2))), (p));
            sum_f = FLOW_CHECKED_MOD(((fact * tmp4)), (p));
        }
    }
    ans = FLOW_CHECKED_MOD(((ans + ((k - 1) * sum_f))), (p));
    printf("%lld\n", ans);
    free(inv);
    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 @max_base_k(%arg0: i64) -> i64 {
    %175 = arith.constant 1 : i32
    %176 = arith.constant 8 : i32
    %177 = arith.constant 1 : i32
    %179 = arith.extsi %177 : i32 to i64
    %178 = arith.addi %arg0, %179 : i64
    %181 = arith.extsi %176 : i32 to i64
    %180 = arith.muli %181, %178 : i64
    %183 = arith.extsi %175 : i32 to i64
    %182 = arith.addi %183, %180 : i64
    %184 = func.call @isqrt(%182) : (i64) -> i64
    %185 = arith.constant 1 : i32
    %187 = arith.extsi %185 : i32 to i64
    %186 = arith.subi %184, %187 : i64
    %188 = arith.constant 2 : i32
    %190 = arith.extsi %188 : i32 to i64
    %189 = arith.divsi %186, %190 : i64
    %191 = llvm.mlir.constant(1 : i64) : i64
    %192 = llvm.alloca %191 x i64 : (i64) -> !llvm.ptr
    llvm.store %189, %192 : i64, !llvm.ptr
    cf.br ^bb42
    ^bb42:
    %193 = llvm.load %192 : !llvm.ptr -> i64
    %194 = llvm.load %192 : !llvm.ptr -> i64
    %195 = arith.constant 1 : i32
    %197 = arith.extsi %195 : i32 to i64
    %196 = arith.addi %194, %197 : i64
    %198 = arith.muli %193, %196 : i64
    %199 = arith.constant 2 : i32
    %201 = arith.extsi %199 : i32 to i64
    %200 = arith.divsi %198, %201 : i64
    %202 = arith.constant 1 : i32
    %204 = arith.extsi %202 : i32 to i64
    %203 = arith.subi %200, %204 : i64
    %205 = arith.cmpi sgt, %203, %arg0 : i64
    cf.cond_br %205, ^bb43, ^bb44
    ^bb43:
      %206 = llvm.load %192 : !llvm.ptr -> i64
      %207 = arith.constant 1 : i32
      %209 = arith.extsi %207 : i32 to i64
      %208 = arith.subi %206, %209 : i64
      llvm.store %208, %192 : i64, !llvm.ptr
      cf.br ^bb42
    ^bb44:
    cf.br ^bb45
    ^bb45:
    %210 = llvm.load %192 : !llvm.ptr -> i64
    %211 = arith.constant 1 : i32
    %213 = arith.extsi %211 : i32 to i64
    %212 = arith.addi %210, %213 : i64
    %214 = llvm.load %192 : !llvm.ptr -> i64
    %215 = arith.constant 2 : i32
    %217 = arith.extsi %215 : i32 to i64
    %216 = arith.addi %214, %217 : i64
    %218 = arith.muli %212, %216 : i64
    %219 = arith.constant 2 : i32
    %221 = arith.extsi %219 : i32 to i64
    %220 = arith.divsi %218, %221 : i64
    %222 = arith.constant 1 : i32
    %224 = arith.extsi %222 : i32 to i64
    %223 = arith.subi %220, %224 : i64
    %225 = arith.cmpi sle, %223, %arg0 : i64
    cf.cond_br %225, ^bb46, ^bb47
    ^bb46:
      %226 = llvm.load %192 : !llvm.ptr -> i64
      %227 = arith.constant 1 : i32
      %229 = arith.extsi %227 : i32 to i64
      %228 = arith.addi %226, %229 : i64
      llvm.store %228, %192 : i64, !llvm.ptr
      cf.br ^bb45
    ^bb47:
    %230 = llvm.load %192 : !llvm.ptr -> i64
    func.return %230 : i64
  }
  func.func @main() -> i32 {
    %231 = arith.constant 982451653 : i32
    %232 = arith.extsi %231 : i32 to i64
    %233 = arith.constant 99995705032704 : i32
    %234 = arith.extsi %233 : i32 to i64
    %235 = arith.constant 1 : i32
    %237 = arith.extsi %235 : i32 to i64
    %236 = arith.addi %232, %237 : i64
    %238 = arith.constant 2 : i32
    %240 = arith.extsi %238 : i32 to i64
    %239 = arith.divsi %236, %240 : i64
    %241 = arith.constant 1 : i32
    %242 = arith.extsi %241 : i32 to i64
    %243 = llvm.mlir.constant(1 : i64) : i64
    %244 = llvm.alloca %243 x i64 : (i64) -> !llvm.ptr
    llvm.store %242, %244 : i64, !llvm.ptr
    %245 = func.call @max_base_k(%234) : (i64) -> i64
    %246 = arith.constant 1 : i32
    %248 = arith.extsi %246 : i32 to i64
    %247 = arith.addi %245, %248 : i64
    %249 = arith.muli %245, %247 : i64
    %250 = arith.constant 2 : i32
    %252 = arith.extsi %250 : i32 to i64
    %251 = arith.divsi %249, %252 : i64
    %253 = arith.constant 1 : i32
    %255 = arith.extsi %253 : i32 to i64
    %254 = arith.subi %251, %255 : i64
    %256 = arith.subi %234, %254 : i64
    %257 = arith.constant 1 : i32
    %259 = arith.extsi %257 : i32 to i64
    %258 = arith.addi %245, %259 : i64
    %260 = arith.constant 3 : i32
    %262 = arith.extsi %260 : i32 to i64
    %261 = arith.cmpi slt, %258, %262 : i64
    %263 = scf.if %261 -> (i64) {
      %264 = arith.constant 3 : i32
      %265 = arith.extsi %264 : i32 to i64
      scf.yield %265 : i64
    } else {
      scf.yield %258 : i64
    }
    %267 = arith.constant 8 : i32
    %268 = arith.extsi %267 : i32 to i64
    %266 = func.call @calloc(%263, %268) : (i64, i64) -> !llvm.ptr
    %269 = llvm.mlir.zero : !llvm.ptr
    %270 = llvm.icmp "eq" %266, %269 : !llvm.ptr
    cf.cond_br %270, ^bb48, ^bb49
    ^bb48:
      %271 = arith.constant 1 : i32
      func.return %271 : i32
    ^bb49:
      cf.br ^bb50
    ^bb50:
    %272 = arith.constant 1 : i32
    %273 = arith.constant 1 : i32
    %274 = arith.extsi %272 : i32 to i64
    %275 = arith.extsi %273 : i32 to i64
    %276 = llvm.getelementptr %266[%275] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %274, %276 : i64, !llvm.ptr
    %277 = arith.constant 2 : i32
    %278 = arith.extsi %277 : i32 to i64
    %279 = llvm.mlir.constant(1 : i64) : i64
    %280 = llvm.alloca %279 x i64 : (i64) -> !llvm.ptr
    llvm.store %278, %280 : i64, !llvm.ptr
    cf.br ^bb51
    ^bb51:
    %281 = llvm.load %280 : !llvm.ptr -> i64
    %282 = arith.cmpi slt, %281, %263 : i64
    cf.cond_br %282, ^bb52, ^bb53
    ^bb52:
      %283 = llvm.load %280 : !llvm.ptr -> i64
      %284 = arith.divsi %232, %283 : i64
      %286 = llvm.load %280 : !llvm.ptr -> i64
      %287 = arith.remsi %232, %286 : i64
      %288 = llvm.getelementptr %266[%287] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %285 = llvm.load %288 : !llvm.ptr -> i64
      %289 = arith.muli %284, %285 : i64
      %290 = arith.remsi %289, %232 : i64
      %291 = arith.subi %232, %290 : i64
      %292 = llvm.load %280 : !llvm.ptr -> i64
      %293 = llvm.getelementptr %266[%292] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %291, %293 : i64, !llvm.ptr
      %294 = llvm.load %280 : !llvm.ptr -> i64
      %295 = arith.constant 1 : i32
      %297 = arith.extsi %295 : i32 to i64
      %296 = arith.addi %294, %297 : i64
      llvm.store %296, %280 : i64, !llvm.ptr
      cf.br ^bb51
    ^bb53:
    %298 = arith.constant 4 : i32
    %299 = arith.extsi %298 : i32 to i64
    %300 = llvm.mlir.constant(1 : i64) : i64
    %301 = llvm.alloca %300 x i64 : (i64) -> !llvm.ptr
    llvm.store %299, %301 : i64, !llvm.ptr
    %302 = arith.constant 4 : i32
    %304 = arith.extsi %302 : i32 to i64
    %303 = arith.cmpi slt, %234, %304 : i64
    cf.cond_br %303, ^bb54, ^bb55
    ^bb54:
      llvm.store %234, %301 : i64, !llvm.ptr
      cf.br ^bb56
    ^bb55:
      cf.br ^bb56
    ^bb56:
    %305 = llvm.load %301 : !llvm.ptr -> i64
    %306 = arith.constant 2 : i32
    %308 = arith.extsi %306 : i32 to i64
    %307 = arith.cmpi sge, %305, %308 : i64
    cf.cond_br %307, ^bb57, ^bb58
    ^bb57:
      %309 = llvm.load %301 : !llvm.ptr -> i64
      %310 = arith.constant 1 : i32
      %312 = arith.extsi %310 : i32 to i64
      %311 = arith.subi %309, %312 : i64
      %313 = llvm.load %244 : !llvm.ptr -> i64
      %314 = arith.constant 2 : i32
      %315 = llvm.load %301 : !llvm.ptr -> i64
      %317 = arith.extsi %314 : i32 to i64
      %316 = arith.addi %317, %315 : i64
      %318 = arith.muli %316, %311 : i64
      %319 = arith.constant 2 : i32
      %321 = arith.extsi %319 : i32 to i64
      %320 = arith.divsi %318, %321 : i64
      %322 = arith.addi %313, %320 : i64
      llvm.store %322, %244 : i64, !llvm.ptr
      cf.br ^bb59
    ^bb58:
      cf.br ^bb59
    ^bb59:
    %323 = llvm.load %244 : !llvm.ptr -> i64
    %324 = arith.remsi %323, %232 : i64
    llvm.store %324, %244 : i64, !llvm.ptr
    %325 = arith.constant 3 : i32
    %327 = arith.extsi %325 : i32 to i64
    %326 = arith.cmpi slt, %245, %327 : i64
    cf.cond_br %326, ^bb60, ^bb61
    ^bb60:
      %328 = llvm.mlir.addressof @str_0 : !llvm.ptr
      %329 = llvm.load %244 : !llvm.ptr -> i64
      %330 = llvm.call @printf(%328, %329) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
      func.call @free(%266) : (!llvm.ptr) -> ()
      %332 = arith.constant 0 : i32
      func.return %332 : i32
    ^bb61:
      cf.br ^bb62
    ^bb62:
    %333 = arith.constant 2 : i32
    %334 = arith.extsi %333 : i32 to i64
    %335 = llvm.mlir.constant(1 : i64) : i64
    %336 = llvm.alloca %335 x i64 : (i64) -> !llvm.ptr
    llvm.store %334, %336 : i64, !llvm.ptr
    %337 = arith.constant 0 : i32
    %338 = arith.extsi %337 : i32 to i64
    %339 = llvm.mlir.constant(1 : i64) : i64
    %340 = llvm.alloca %339 x i64 : (i64) -> !llvm.ptr
    llvm.store %338, %340 : i64, !llvm.ptr
    %341 = arith.constant 0 : i32
    %342 = arith.extsi %341 : i32 to i64
    %343 = llvm.mlir.constant(1 : i64) : i64
    %344 = llvm.alloca %343 x i64 : (i64) -> !llvm.ptr
    llvm.store %342, %344 : i64, !llvm.ptr
    %345 = arith.constant 0 : i32
    %346 = arith.extsi %345 : i32 to i64
    %347 = llvm.mlir.constant(1 : i64) : i64
    %348 = llvm.alloca %347 x i64 : (i64) -> !llvm.ptr
    llvm.store %346, %348 : i64, !llvm.ptr
    %349 = arith.constant 1 : i32
    %351 = arith.extsi %349 : i32 to i64
    %350 = arith.cmpi sge, %256, %351 : i64
    %352 = scf.if %350 -> (i1) {
      %353 = arith.constant 2 : i32
      %355 = arith.extsi %353 : i32 to i64
      %354 = arith.subi %245, %355 : i64
      %356 = arith.cmpi sle, %256, %354 : i64
      scf.yield %356 : i1
    } else {
      %357 = arith.constant false
      scf.yield %357 : i1
    }
    cf.cond_br %352, ^bb63, ^bb64
    ^bb63:
      %358 = arith.constant 1 : i32
      %359 = arith.extsi %358 : i32 to i64
      llvm.store %359, %348 : i64, !llvm.ptr
      cf.br ^bb65
    ^bb64:
      cf.br ^bb65
    ^bb65:
    %360 = arith.subi %245, %256 : i64
    %361 = arith.constant 3 : i32
    %362 = arith.extsi %361 : i32 to i64
    %363 = llvm.mlir.constant(1 : i64) : i64
    %364 = llvm.alloca %363 x i64 : (i64) -> !llvm.ptr
    llvm.store %362, %364 : i64, !llvm.ptr
    cf.br ^bb66
    ^bb66:
    %365 = llvm.load %364 : !llvm.ptr -> i64
    %366 = arith.cmpi slt, %365, %245 : i64
    cf.cond_br %366, ^bb67, ^bb68
    ^bb67:
      %367 = llvm.load %336 : !llvm.ptr -> i64
      %368 = llvm.load %364 : !llvm.ptr -> i64
      %369 = arith.muli %367, %368 : i64
      %370 = arith.remsi %369, %232 : i64
      llvm.store %370, %336 : i64, !llvm.ptr
      %371 = llvm.load %340 : !llvm.ptr -> i64
      %373 = llvm.load %364 : !llvm.ptr -> i64
      %374 = llvm.getelementptr %266[%373] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %372 = llvm.load %374 : !llvm.ptr -> i64
      %375 = arith.addi %371, %372 : i64
      llvm.store %375, %340 : i64, !llvm.ptr
      %376 = llvm.load %340 : !llvm.ptr -> i64
      %377 = arith.cmpi sge, %376, %232 : i64
      cf.cond_br %377, ^bb69, ^bb70
      ^bb69:
        %378 = llvm.load %340 : !llvm.ptr -> i64
        %379 = arith.subi %378, %232 : i64
        llvm.store %379, %340 : i64, !llvm.ptr
        cf.br ^bb71
      ^bb70:
        cf.br ^bb71
      ^bb71:
      %380 = arith.constant 1 : i32
      %381 = llvm.load %364 : !llvm.ptr -> i64
      %382 = arith.constant 1 : i32
      %384 = arith.extsi %382 : i32 to i64
      %383 = arith.addi %381, %384 : i64
      %385 = arith.remsi %383, %232 : i64
      %386 = llvm.load %340 : !llvm.ptr -> i64
      %387 = arith.remsi %386, %232 : i64
      %388 = arith.muli %385, %387 : i64
      %389 = arith.remsi %388, %232 : i64
      %391 = arith.extsi %380 : i32 to i64
      %390 = arith.addi %391, %389 : i64
      %392 = arith.constant 2 : i32
      %393 = llvm.load %364 : !llvm.ptr -> i64
      %395 = arith.extsi %392 : i32 to i64
      %394 = arith.muli %395, %393 : i64
      %396 = arith.constant 3 : i32
      %398 = arith.extsi %396 : i32 to i64
      %397 = arith.addi %394, %398 : i64
      %399 = arith.remsi %397, %232 : i64
      %400 = arith.muli %399, %239 : i64
      %401 = arith.remsi %400, %232 : i64
      %402 = arith.addi %390, %401 : i64
      %403 = arith.remsi %402, %232 : i64
      %404 = llvm.load %336 : !llvm.ptr -> i64
      %405 = arith.muli %404, %403 : i64
      %406 = arith.remsi %405, %232 : i64
      %407 = llvm.load %244 : !llvm.ptr -> i64
      %408 = llvm.load %364 : !llvm.ptr -> i64
      %409 = arith.constant 1 : i32
      %411 = arith.extsi %409 : i32 to i64
      %410 = arith.subi %408, %411 : i64
      %412 = arith.remsi %410, %232 : i64
      %413 = arith.muli %412, %406 : i64
      %414 = arith.remsi %413, %232 : i64
      %415 = arith.addi %407, %414 : i64
      %416 = arith.remsi %415, %232 : i64
      llvm.store %416, %244 : i64, !llvm.ptr
      %417 = llvm.load %348 : !llvm.ptr -> i64
      %418 = arith.constant 1 : i32
      %420 = arith.extsi %418 : i32 to i64
      %419 = arith.cmpi eq, %417, %420 : i64
      %421 = scf.if %419 -> (i1) {
        %422 = llvm.load %364 : !llvm.ptr -> i64
        %423 = arith.cmpi eq, %422, %360 : i64
        scf.yield %423 : i1
      } else {
        %424 = arith.constant false
        scf.yield %424 : i1
      }
      cf.cond_br %421, ^bb72, ^bb73
      ^bb72:
        %425 = llvm.load %340 : !llvm.ptr -> i64
        llvm.store %425, %344 : i64, !llvm.ptr
        cf.br ^bb74
      ^bb73:
        cf.br ^bb74
      ^bb74:
      %426 = llvm.load %364 : !llvm.ptr -> i64
      %427 = arith.constant 1 : i32
      %429 = arith.extsi %427 : i32 to i64
      %428 = arith.addi %426, %429 : i64
      llvm.store %428, %364 : i64, !llvm.ptr
      cf.br ^bb66
    ^bb68:
    llvm.store %245, %364 : i64, !llvm.ptr
    %430 = llvm.load %336 : !llvm.ptr -> i64
    %431 = llvm.load %364 : !llvm.ptr -> i64
    %432 = arith.muli %430, %431 : i64
    %433 = arith.remsi %432, %232 : i64
    llvm.store %433, %336 : i64, !llvm.ptr
    %434 = llvm.load %340 : !llvm.ptr -> i64
    %436 = llvm.load %364 : !llvm.ptr -> i64
    %437 = llvm.getelementptr %266[%436] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %435 = llvm.load %437 : !llvm.ptr -> i64
    %438 = arith.addi %434, %435 : i64
    llvm.store %438, %340 : i64, !llvm.ptr
    %439 = llvm.load %340 : !llvm.ptr -> i64
    %440 = arith.cmpi sge, %439, %232 : i64
    cf.cond_br %440, ^bb75, ^bb76
    ^bb75:
      %441 = llvm.load %340 : !llvm.ptr -> i64
      %442 = arith.subi %441, %232 : i64
      llvm.store %442, %340 : i64, !llvm.ptr
      cf.br ^bb77
    ^bb76:
      cf.br ^bb77
    ^bb77:
    %443 = arith.constant 0 : i32
    %444 = arith.extsi %443 : i32 to i64
    %445 = llvm.mlir.constant(1 : i64) : i64
    %446 = llvm.alloca %445 x i64 : (i64) -> !llvm.ptr
    llvm.store %444, %446 : i64, !llvm.ptr
    %447 = llvm.load %364 : !llvm.ptr -> i64
    %448 = arith.constant 2 : i32
    %450 = arith.extsi %448 : i32 to i64
    %449 = arith.subi %447, %450 : i64
    %451 = arith.cmpi sle, %256, %449 : i64
    cf.cond_br %451, ^bb78, ^bb79
    ^bb78:
      %452 = arith.constant 0 : i32
      %454 = arith.extsi %452 : i32 to i64
      %453 = arith.cmpi eq, %256, %454 : i64
      cf.cond_br %453, ^bb81, ^bb82
      ^bb81:
        %455 = llvm.load %336 : !llvm.ptr -> i64
        llvm.store %455, %446 : i64, !llvm.ptr
        cf.br ^bb83
      ^bb82:
        %456 = llvm.load %340 : !llvm.ptr -> i64
        %457 = llvm.load %344 : !llvm.ptr -> i64
        %458 = arith.subi %456, %457 : i64
        %459 = arith.remsi %458, %232 : i64
        %460 = llvm.mlir.constant(1 : i64) : i64
        %461 = llvm.alloca %460 x i64 : (i64) -> !llvm.ptr
        llvm.store %459, %461 : i64, !llvm.ptr
        %462 = llvm.load %461 : !llvm.ptr -> i64
        %463 = arith.constant 0 : i32
        %465 = arith.extsi %463 : i32 to i64
        %464 = arith.cmpi slt, %462, %465 : i64
        cf.cond_br %464, ^bb84, ^bb85
        ^bb84:
          %466 = llvm.load %461 : !llvm.ptr -> i64
          %467 = arith.addi %466, %232 : i64
          llvm.store %467, %461 : i64, !llvm.ptr
          cf.br ^bb86
        ^bb85:
          cf.br ^bb86
        ^bb86:
        %468 = arith.constant 1 : i32
        %469 = llvm.load %364 : !llvm.ptr -> i64
        %470 = arith.constant 1 : i32
        %472 = arith.extsi %470 : i32 to i64
        %471 = arith.addi %469, %472 : i64
        %473 = llvm.load %461 : !llvm.ptr -> i64
        %474 = arith.muli %471, %473 : i64
        %476 = arith.extsi %468 : i32 to i64
        %475 = arith.addi %476, %474 : i64
        %477 = arith.remsi %475, %232 : i64
        %478 = llvm.load %336 : !llvm.ptr -> i64
        %479 = arith.muli %478, %477 : i64
        %480 = arith.remsi %479, %232 : i64
        llvm.store %480, %446 : i64, !llvm.ptr
        cf.br ^bb83
      ^bb83:
      cf.br ^bb80
    ^bb79:
      %481 = llvm.load %364 : !llvm.ptr -> i64
      %482 = arith.constant 1 : i32
      %484 = arith.extsi %482 : i32 to i64
      %483 = arith.subi %481, %484 : i64
      %485 = arith.cmpi eq, %256, %483 : i64
      cf.cond_br %485, ^bb87, ^bb88
      ^bb87:
        %486 = arith.constant 1 : i32
        %487 = llvm.load %364 : !llvm.ptr -> i64
        %488 = arith.constant 1 : i32
        %490 = arith.extsi %488 : i32 to i64
        %489 = arith.addi %487, %490 : i64
        %491 = llvm.load %340 : !llvm.ptr -> i64
        %492 = arith.muli %489, %491 : i64
        %494 = arith.extsi %486 : i32 to i64
        %493 = arith.addi %494, %492 : i64
        %495 = llvm.load %364 : !llvm.ptr -> i64
        %496 = arith.constant 1 : i32
        %498 = arith.extsi %496 : i32 to i64
        %497 = arith.addi %495, %498 : i64
        %499 = arith.muli %497, %239 : i64
        %500 = arith.addi %493, %499 : i64
        %501 = arith.remsi %500, %232 : i64
        %502 = llvm.load %336 : !llvm.ptr -> i64
        %503 = arith.muli %502, %501 : i64
        %504 = arith.remsi %503, %232 : i64
        llvm.store %504, %446 : i64, !llvm.ptr
        cf.br ^bb89
      ^bb88:
        %505 = arith.constant 1 : i32
        %506 = llvm.load %364 : !llvm.ptr -> i64
        %507 = arith.constant 1 : i32
        %509 = arith.extsi %507 : i32 to i64
        %508 = arith.addi %506, %509 : i64
        %510 = llvm.load %340 : !llvm.ptr -> i64
        %511 = arith.muli %508, %510 : i64
        %513 = arith.extsi %505 : i32 to i64
        %512 = arith.addi %513, %511 : i64
        %514 = arith.constant 2 : i32
        %515 = llvm.load %364 : !llvm.ptr -> i64
        %517 = arith.extsi %514 : i32 to i64
        %516 = arith.muli %517, %515 : i64
        %518 = arith.constant 3 : i32
        %520 = arith.extsi %518 : i32 to i64
        %519 = arith.addi %516, %520 : i64
        %521 = arith.muli %519, %239 : i64
        %522 = arith.addi %512, %521 : i64
        %523 = arith.remsi %522, %232 : i64
        %524 = llvm.load %336 : !llvm.ptr -> i64
        %525 = arith.muli %524, %523 : i64
        %526 = arith.remsi %525, %232 : i64
        llvm.store %526, %446 : i64, !llvm.ptr
        cf.br ^bb89
      ^bb89:
      cf.br ^bb80
    ^bb80:
    %527 = llvm.load %244 : !llvm.ptr -> i64
    %528 = llvm.load %364 : !llvm.ptr -> i64
    %529 = arith.constant 1 : i32
    %531 = arith.extsi %529 : i32 to i64
    %530 = arith.subi %528, %531 : i64
    %532 = llvm.load %446 : !llvm.ptr -> i64
    %533 = arith.muli %530, %532 : i64
    %534 = arith.addi %527, %533 : i64
    %535 = arith.remsi %534, %232 : i64
    llvm.store %535, %244 : i64, !llvm.ptr
    %536 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %537 = llvm.load %244 : !llvm.ptr -> i64
    %538 = llvm.call @printf(%536, %537) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    func.call @free(%266) : (!llvm.ptr) -> ()
    %540 = arith.constant 0 : i32
    func.return %540 : i32
  }
}