Problem 412

LC(10000, 5000) mod 76543217 (gnomon numbering count).

Answer38788800
Output38788800
StatusPASS
Native helperno
Runtime1460 ms
Peak memory1536 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 412
# LC(10000, 5000) mod 76543217 (gnomon numbering count).

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

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

function main() -> i32 {
    let M: i64 = 10000
    let N: i64 = 5000
    let MOD: i64 = 76543217
    let K: i64 = M - N
    let max_small: i64 = 2 * M - 1

    let fac: ptr<i64> = calloc(max_small + 1, 8)
    let invfac: ptr<i64> = calloc(max_small + 1, 8)
    if fac == null || invfac == null { return 1 }
    fac[0] = 1
    let mut i: i64 = 1
    while i <= max_small {
        fac[i] = ((fac[i - 1] as i128) * (i as i128) % (MOD as i128)) as i64
        i = i + 1
    }
    invfac[max_small] = modpow(fac[max_small], MOD - 2, MOD)
    i = max_small
    while i > 0 {
        invfac[i - 1] = ((invfac[i] as i128) * (i as i128) % (MOD as i128)) as i64
        i = i - 1
    }

    let mut v_a: i64 = 1
    i = 1
    while i < N {
        v_a = ((v_a as i128) * (fac[i] as i128) % (MOD as i128)) as i64
        i = i + 1
    }
    let mut v_b: i64 = 1
    i = 1
    while i < K {
        v_b = ((v_b as i128) * (fac[i] as i128) % (MOD as i128)) as i64
        i = i + 1
    }
    let mut v_ab: i64 = 1
    let mut t: i64 = 0
    while t < K {
        v_ab = ((v_ab as i128) * (fac[2 * N + t] as i128) % (MOD as i128)) as i64
        v_ab = ((v_ab as i128) * (invfac[N + t] as i128) % (MOD as i128)) as i64
        t = t + 1
    }
    let mut d_inv: i64 = 1
    let mut a: i64 = K
    while a < M {
        d_inv = ((d_inv as i128) * (invfac[a] as i128) % (MOD as i128)) as i64
        a = a + 1
    }
    let mut b: i64 = M + N
    while b < 2 * M {
        d_inv = ((d_inv as i128) * (invfac[b] as i128) % (MOD as i128)) as i64
        b = b + 1
    }

    let cells: i64 = M * M - N * N
    let mut total_fact: i64 = 1
    i = 2
    while i <= cells {
        total_fact = ((total_fact as i128) * (i as i128) % (MOD as i128)) as i64
        i = i + 1
    }

    let mut res: i64 = total_fact
    res = ((res as i128) * (v_a as i128) % (MOD as i128)) as i64
    res = ((res as i128) * (v_b as i128) % (MOD as i128)) as i64
    res = ((res as i128) * (v_ab as i128) % (MOD as i128)) as i64
    res = ((res as i128) * (d_inv as i128) % (MOD as i128)) as i64
    printf("%lld\n", res)
    free(invfac)
    free(fac)
    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 base0, int64_t exp0, int64_t mod);
int32_t main(void);



int64_t modpow_i64_i64_i64(int64_t base0, int64_t exp0, int64_t mod) {
    int64_t r = 1;
    int64_t b = FLOW_CHECKED_MOD((base0), (mod));
    int64_t e = exp0;
    while (e > 0) {
        if (FLOW_CHECKED_MOD((e), (2)) == 1) {
            __int128 t = FLOW_CHECKED_MOD(((((__int128)(r)) * ((__int128)(b)))), (((__int128)(mod))));
            r = ((int64_t)(t));
        }
        __int128 t2 = FLOW_CHECKED_MOD(((((__int128)(b)) * ((__int128)(b)))), (((__int128)(mod))));
        b = ((int64_t)(t2));
        e = FLOW_CHECKED_DIV((e), (2));
    }
    return r;
}

int32_t main(void) {
    int64_t M = 10000;
    int64_t N = 5000;
    int64_t MOD = 76543217;
    int64_t K = (M - N);
    int64_t max_small = ((2 * M) - 1);
    int64_t* fac = (int64_t*)(calloc((max_small + 1), 8));
    int64_t* invfac = (int64_t*)(calloc((max_small + 1), 8));
    if ((fac == NULL || invfac == NULL)) {
        return 1;
    }
    fac[0] = 1;
    int64_t i = 1;
    while (i <= max_small) {
        fac[i] = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(fac[(i - 1)])) * ((__int128)(i)))), (((__int128)(MOD))))));
        i = (i + 1);
    }
    invfac[max_small] = modpow_i64_i64_i64(fac[max_small], (MOD - 2), MOD);
    i = max_small;
    while (i > 0) {
        invfac[(i - 1)] = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(invfac[i])) * ((__int128)(i)))), (((__int128)(MOD))))));
        i = (i - 1);
    }
    int64_t v_a = 1;
    i = 1;
    while (i < N) {
        v_a = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(v_a)) * ((__int128)(fac[i])))), (((__int128)(MOD))))));
        i = (i + 1);
    }
    int64_t v_b = 1;
    i = 1;
    while (i < K) {
        v_b = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(v_b)) * ((__int128)(fac[i])))), (((__int128)(MOD))))));
        i = (i + 1);
    }
    int64_t v_ab = 1;
    int64_t t = 0;
    while (t < K) {
        v_ab = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(v_ab)) * ((__int128)(fac[((2 * N) + t)])))), (((__int128)(MOD))))));
        v_ab = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(v_ab)) * ((__int128)(invfac[(N + t)])))), (((__int128)(MOD))))));
        t = (t + 1);
    }
    int64_t d_inv = 1;
    int64_t a = K;
    while (a < M) {
        d_inv = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(d_inv)) * ((__int128)(invfac[a])))), (((__int128)(MOD))))));
        a = (a + 1);
    }
    int64_t b = (M + N);
    while (b < (2 * M)) {
        d_inv = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(d_inv)) * ((__int128)(invfac[b])))), (((__int128)(MOD))))));
        b = (b + 1);
    }
    int64_t cells = ((M * M) - (N * N));
    int64_t total_fact = 1;
    i = 2;
    while (i <= cells) {
        total_fact = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(total_fact)) * ((__int128)(i)))), (((__int128)(MOD))))));
        i = (i + 1);
    }
    int64_t res = total_fact;
    res = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(res)) * ((__int128)(v_a)))), (((__int128)(MOD))))));
    res = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(res)) * ((__int128)(v_b)))), (((__int128)(MOD))))));
    res = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(res)) * ((__int128)(v_ab)))), (((__int128)(MOD))))));
    res = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(res)) * ((__int128)(d_inv)))), (((__int128)(MOD))))));
    printf("%lld\n", res);
    free(invfac);
    free(fac);
    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 = arith.extsi %20 : i64 to i128
        %22 = llvm.load %6 : !llvm.ptr -> i64
        %23 = arith.extsi %22 : i64 to i128
        %25 = arith.trunci %21 : i128 to i64
        %26 = arith.trunci %23 : i128 to i64
        %24 = arith.muli %25, %26 : i64
        %27 = arith.extsi %arg2 : i64 to i128
        %29 = arith.trunci %27 : i128 to i64
        %28 = arith.remsi %24, %29 : i64
        %30 = arith.extsi %28 : i64 to i128
        %31 = arith.trunci %30 : i128 to i64
        llvm.store %31, %3 : i64, !llvm.ptr
        cf.br ^bb5
      ^bb4:
        cf.br ^bb5
      ^bb5:
      %32 = llvm.load %6 : !llvm.ptr -> i64
      %33 = arith.extsi %32 : i64 to i128
      %34 = llvm.load %6 : !llvm.ptr -> i64
      %35 = arith.extsi %34 : i64 to i128
      %37 = arith.trunci %33 : i128 to i64
      %38 = arith.trunci %35 : i128 to i64
      %36 = arith.muli %37, %38 : i64
      %39 = arith.extsi %arg2 : i64 to i128
      %41 = arith.trunci %39 : i128 to i64
      %40 = arith.remsi %36, %41 : i64
      %42 = arith.extsi %40 : i64 to i128
      %43 = arith.trunci %42 : i128 to i64
      llvm.store %43, %6 : i64, !llvm.ptr
      %44 = llvm.load %8 : !llvm.ptr -> i64
      %45 = arith.constant 2 : i32
      %47 = arith.extsi %45 : i32 to i64
      %46 = arith.divsi %44, %47 : i64
      llvm.store %46, %8 : i64, !llvm.ptr
      cf.br ^bb0
    ^bb2:
    %48 = llvm.load %3 : !llvm.ptr -> i64
    func.return %48 : i64
  }
  func.func @main() -> i32 {
    %49 = arith.constant 10000 : i32
    %50 = arith.extsi %49 : i32 to i64
    %51 = arith.constant 5000 : i32
    %52 = arith.extsi %51 : i32 to i64
    %53 = arith.constant 76543217 : i32
    %54 = arith.extsi %53 : i32 to i64
    %55 = arith.subi %50, %52 : i64
    %56 = arith.constant 2 : i32
    %58 = arith.extsi %56 : i32 to i64
    %57 = arith.muli %58, %50 : i64
    %59 = arith.constant 1 : i32
    %61 = arith.extsi %59 : i32 to i64
    %60 = arith.subi %57, %61 : i64
    %63 = arith.constant 1 : i32
    %65 = arith.extsi %63 : i32 to i64
    %64 = arith.addi %60, %65 : i64
    %66 = arith.constant 8 : i32
    %67 = arith.extsi %66 : i32 to i64
    %62 = func.call @calloc(%64, %67) : (i64, i64) -> !llvm.ptr
    %69 = arith.constant 1 : i32
    %71 = arith.extsi %69 : i32 to i64
    %70 = arith.addi %60, %71 : i64
    %72 = arith.constant 8 : i32
    %73 = arith.extsi %72 : i32 to i64
    %68 = func.call @calloc(%70, %73) : (i64, i64) -> !llvm.ptr
    %74 = llvm.mlir.zero : !llvm.ptr
    %75 = llvm.icmp "eq" %62, %74 : !llvm.ptr
    %76 = scf.if %75 -> (i1) {
      %77 = arith.constant true
      scf.yield %77 : i1
    } else {
      %78 = llvm.mlir.zero : !llvm.ptr
      %79 = llvm.icmp "eq" %68, %78 : !llvm.ptr
      scf.yield %79 : i1
    }
    cf.cond_br %76, ^bb6, ^bb7
    ^bb6:
      %80 = arith.constant 1 : i32
      func.return %80 : i32
    ^bb7:
      cf.br ^bb8
    ^bb8:
    %81 = arith.constant 1 : i32
    %82 = arith.constant 0 : i32
    %83 = arith.extsi %81 : i32 to i64
    %84 = arith.extsi %82 : i32 to i64
    %85 = llvm.getelementptr %62[%84] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %83, %85 : i64, !llvm.ptr
    %86 = arith.constant 1 : i32
    %87 = arith.extsi %86 : i32 to i64
    %88 = llvm.mlir.constant(1 : i64) : i64
    %89 = llvm.alloca %88 x i64 : (i64) -> !llvm.ptr
    llvm.store %87, %89 : i64, !llvm.ptr
    cf.br ^bb9
    ^bb9:
    %90 = llvm.load %89 : !llvm.ptr -> i64
    %91 = arith.cmpi sle, %90, %60 : i64
    cf.cond_br %91, ^bb10, ^bb11
    ^bb10:
      %93 = llvm.load %89 : !llvm.ptr -> i64
      %94 = arith.constant 1 : i32
      %96 = arith.extsi %94 : i32 to i64
      %95 = arith.subi %93, %96 : i64
      %97 = llvm.getelementptr %62[%95] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %92 = llvm.load %97 : !llvm.ptr -> i64
      %98 = arith.extsi %92 : i64 to i128
      %99 = llvm.load %89 : !llvm.ptr -> i64
      %100 = arith.extsi %99 : i64 to i128
      %102 = arith.trunci %98 : i128 to i64
      %103 = arith.trunci %100 : i128 to i64
      %101 = arith.muli %102, %103 : i64
      %104 = arith.extsi %54 : i64 to i128
      %106 = arith.trunci %104 : i128 to i64
      %105 = arith.remsi %101, %106 : i64
      %107 = llvm.load %89 : !llvm.ptr -> i64
      %108 = llvm.getelementptr %62[%107] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %105, %108 : i64, !llvm.ptr
      %109 = llvm.load %89 : !llvm.ptr -> i64
      %110 = arith.constant 1 : i32
      %112 = arith.extsi %110 : i32 to i64
      %111 = arith.addi %109, %112 : i64
      llvm.store %111, %89 : i64, !llvm.ptr
      cf.br ^bb9
    ^bb11:
    %115 = llvm.getelementptr %62[%60] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %114 = llvm.load %115 : !llvm.ptr -> i64
    %116 = arith.constant 2 : i32
    %118 = arith.extsi %116 : i32 to i64
    %117 = arith.subi %54, %118 : i64
    %113 = func.call @modpow(%114, %117, %54) : (i64, i64, i64) -> i64
    %119 = llvm.getelementptr %68[%60] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %113, %119 : i64, !llvm.ptr
    llvm.store %60, %89 : i64, !llvm.ptr
    cf.br ^bb12
    ^bb12:
    %120 = llvm.load %89 : !llvm.ptr -> i64
    %121 = arith.constant 0 : i32
    %123 = arith.extsi %121 : i32 to i64
    %122 = arith.cmpi sgt, %120, %123 : i64
    cf.cond_br %122, ^bb13, ^bb14
    ^bb13:
      %125 = llvm.load %89 : !llvm.ptr -> i64
      %126 = llvm.getelementptr %68[%125] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %124 = llvm.load %126 : !llvm.ptr -> i64
      %127 = arith.extsi %124 : i64 to i128
      %128 = llvm.load %89 : !llvm.ptr -> i64
      %129 = arith.extsi %128 : i64 to i128
      %131 = arith.trunci %127 : i128 to i64
      %132 = arith.trunci %129 : i128 to i64
      %130 = arith.muli %131, %132 : i64
      %133 = arith.extsi %54 : i64 to i128
      %135 = arith.trunci %133 : i128 to i64
      %134 = arith.remsi %130, %135 : i64
      %136 = llvm.load %89 : !llvm.ptr -> i64
      %137 = arith.constant 1 : i32
      %139 = arith.extsi %137 : i32 to i64
      %138 = arith.subi %136, %139 : i64
      %140 = llvm.getelementptr %68[%138] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %134, %140 : i64, !llvm.ptr
      %141 = llvm.load %89 : !llvm.ptr -> i64
      %142 = arith.constant 1 : i32
      %144 = arith.extsi %142 : i32 to i64
      %143 = arith.subi %141, %144 : i64
      llvm.store %143, %89 : i64, !llvm.ptr
      cf.br ^bb12
    ^bb14:
    %145 = arith.constant 1 : i32
    %146 = arith.extsi %145 : i32 to i64
    %147 = llvm.mlir.constant(1 : i64) : i64
    %148 = llvm.alloca %147 x i64 : (i64) -> !llvm.ptr
    llvm.store %146, %148 : i64, !llvm.ptr
    %149 = arith.constant 1 : i32
    %150 = arith.extsi %149 : i32 to i64
    llvm.store %150, %89 : i64, !llvm.ptr
    cf.br ^bb15
    ^bb15:
    %151 = llvm.load %89 : !llvm.ptr -> i64
    %152 = arith.cmpi slt, %151, %52 : i64
    cf.cond_br %152, ^bb16, ^bb17
    ^bb16:
      %153 = llvm.load %148 : !llvm.ptr -> i64
      %154 = arith.extsi %153 : i64 to i128
      %156 = llvm.load %89 : !llvm.ptr -> i64
      %157 = llvm.getelementptr %62[%156] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %155 = llvm.load %157 : !llvm.ptr -> i64
      %158 = arith.extsi %155 : i64 to i128
      %160 = arith.trunci %154 : i128 to i64
      %161 = arith.trunci %158 : i128 to i64
      %159 = arith.muli %160, %161 : i64
      %162 = arith.extsi %54 : i64 to i128
      %164 = arith.trunci %162 : i128 to i64
      %163 = arith.remsi %159, %164 : i64
      llvm.store %163, %148 : i64, !llvm.ptr
      %165 = llvm.load %89 : !llvm.ptr -> i64
      %166 = arith.constant 1 : i32
      %168 = arith.extsi %166 : i32 to i64
      %167 = arith.addi %165, %168 : i64
      llvm.store %167, %89 : i64, !llvm.ptr
      cf.br ^bb15
    ^bb17:
    %169 = arith.constant 1 : i32
    %170 = arith.extsi %169 : i32 to i64
    %171 = llvm.mlir.constant(1 : i64) : i64
    %172 = llvm.alloca %171 x i64 : (i64) -> !llvm.ptr
    llvm.store %170, %172 : i64, !llvm.ptr
    %173 = arith.constant 1 : i32
    %174 = arith.extsi %173 : i32 to i64
    llvm.store %174, %89 : i64, !llvm.ptr
    cf.br ^bb18
    ^bb18:
    %175 = llvm.load %89 : !llvm.ptr -> i64
    %176 = arith.cmpi slt, %175, %55 : i64
    cf.cond_br %176, ^bb19, ^bb20
    ^bb19:
      %177 = llvm.load %172 : !llvm.ptr -> i64
      %178 = arith.extsi %177 : i64 to i128
      %180 = llvm.load %89 : !llvm.ptr -> i64
      %181 = llvm.getelementptr %62[%180] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %179 = llvm.load %181 : !llvm.ptr -> i64
      %182 = arith.extsi %179 : i64 to i128
      %184 = arith.trunci %178 : i128 to i64
      %185 = arith.trunci %182 : i128 to i64
      %183 = arith.muli %184, %185 : i64
      %186 = arith.extsi %54 : i64 to i128
      %188 = arith.trunci %186 : i128 to i64
      %187 = arith.remsi %183, %188 : i64
      llvm.store %187, %172 : i64, !llvm.ptr
      %189 = llvm.load %89 : !llvm.ptr -> i64
      %190 = arith.constant 1 : i32
      %192 = arith.extsi %190 : i32 to i64
      %191 = arith.addi %189, %192 : i64
      llvm.store %191, %89 : i64, !llvm.ptr
      cf.br ^bb18
    ^bb20:
    %193 = arith.constant 1 : i32
    %194 = arith.extsi %193 : i32 to i64
    %195 = llvm.mlir.constant(1 : i64) : i64
    %196 = llvm.alloca %195 x i64 : (i64) -> !llvm.ptr
    llvm.store %194, %196 : i64, !llvm.ptr
    %197 = arith.constant 0 : i32
    %198 = arith.extsi %197 : i32 to i64
    %199 = llvm.mlir.constant(1 : i64) : i64
    %200 = llvm.alloca %199 x i64 : (i64) -> !llvm.ptr
    llvm.store %198, %200 : i64, !llvm.ptr
    cf.br ^bb21
    ^bb21:
    %201 = llvm.load %200 : !llvm.ptr -> i64
    %202 = arith.cmpi slt, %201, %55 : i64
    cf.cond_br %202, ^bb22, ^bb23
    ^bb22:
      %203 = llvm.load %196 : !llvm.ptr -> i64
      %204 = arith.extsi %203 : i64 to i128
      %206 = arith.constant 2 : i32
      %208 = arith.extsi %206 : i32 to i64
      %207 = arith.muli %208, %52 : i64
      %209 = llvm.load %200 : !llvm.ptr -> i64
      %210 = arith.addi %207, %209 : i64
      %211 = llvm.getelementptr %62[%210] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %205 = llvm.load %211 : !llvm.ptr -> i64
      %212 = arith.extsi %205 : i64 to i128
      %214 = arith.trunci %204 : i128 to i64
      %215 = arith.trunci %212 : i128 to i64
      %213 = arith.muli %214, %215 : i64
      %216 = arith.extsi %54 : i64 to i128
      %218 = arith.trunci %216 : i128 to i64
      %217 = arith.remsi %213, %218 : i64
      llvm.store %217, %196 : i64, !llvm.ptr
      %219 = llvm.load %196 : !llvm.ptr -> i64
      %220 = arith.extsi %219 : i64 to i128
      %222 = llvm.load %200 : !llvm.ptr -> i64
      %223 = arith.addi %52, %222 : i64
      %224 = llvm.getelementptr %68[%223] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %221 = llvm.load %224 : !llvm.ptr -> i64
      %225 = arith.extsi %221 : i64 to i128
      %227 = arith.trunci %220 : i128 to i64
      %228 = arith.trunci %225 : i128 to i64
      %226 = arith.muli %227, %228 : i64
      %229 = arith.extsi %54 : i64 to i128
      %231 = arith.trunci %229 : i128 to i64
      %230 = arith.remsi %226, %231 : i64
      llvm.store %230, %196 : i64, !llvm.ptr
      %232 = llvm.load %200 : !llvm.ptr -> i64
      %233 = arith.constant 1 : i32
      %235 = arith.extsi %233 : i32 to i64
      %234 = arith.addi %232, %235 : i64
      llvm.store %234, %200 : i64, !llvm.ptr
      cf.br ^bb21
    ^bb23:
    %236 = arith.constant 1 : 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
    %240 = llvm.mlir.constant(1 : i64) : i64
    %241 = llvm.alloca %240 x i64 : (i64) -> !llvm.ptr
    llvm.store %55, %241 : i64, !llvm.ptr
    cf.br ^bb24
    ^bb24:
    %242 = llvm.load %241 : !llvm.ptr -> i64
    %243 = arith.cmpi slt, %242, %50 : i64
    cf.cond_br %243, ^bb25, ^bb26
    ^bb25:
      %244 = llvm.load %239 : !llvm.ptr -> i64
      %245 = arith.extsi %244 : i64 to i128
      %247 = llvm.load %241 : !llvm.ptr -> i64
      %248 = llvm.getelementptr %68[%247] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %246 = llvm.load %248 : !llvm.ptr -> i64
      %249 = arith.extsi %246 : i64 to i128
      %251 = arith.trunci %245 : i128 to i64
      %252 = arith.trunci %249 : i128 to i64
      %250 = arith.muli %251, %252 : i64
      %253 = arith.extsi %54 : i64 to i128
      %255 = arith.trunci %253 : i128 to i64
      %254 = arith.remsi %250, %255 : i64
      llvm.store %254, %239 : i64, !llvm.ptr
      %256 = llvm.load %241 : !llvm.ptr -> i64
      %257 = arith.constant 1 : i32
      %259 = arith.extsi %257 : i32 to i64
      %258 = arith.addi %256, %259 : i64
      llvm.store %258, %241 : i64, !llvm.ptr
      cf.br ^bb24
    ^bb26:
    %260 = arith.addi %50, %52 : i64
    %261 = llvm.mlir.constant(1 : i64) : i64
    %262 = llvm.alloca %261 x i64 : (i64) -> !llvm.ptr
    llvm.store %260, %262 : i64, !llvm.ptr
    cf.br ^bb27
    ^bb27:
    %263 = llvm.load %262 : !llvm.ptr -> i64
    %264 = arith.constant 2 : i32
    %266 = arith.extsi %264 : i32 to i64
    %265 = arith.muli %266, %50 : i64
    %267 = arith.cmpi slt, %263, %265 : i64
    cf.cond_br %267, ^bb28, ^bb29
    ^bb28:
      %268 = llvm.load %239 : !llvm.ptr -> i64
      %269 = arith.extsi %268 : i64 to i128
      %271 = llvm.load %262 : !llvm.ptr -> i64
      %272 = llvm.getelementptr %68[%271] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %270 = llvm.load %272 : !llvm.ptr -> i64
      %273 = arith.extsi %270 : i64 to i128
      %275 = arith.trunci %269 : i128 to i64
      %276 = arith.trunci %273 : i128 to i64
      %274 = arith.muli %275, %276 : i64
      %277 = arith.extsi %54 : i64 to i128
      %279 = arith.trunci %277 : i128 to i64
      %278 = arith.remsi %274, %279 : i64
      llvm.store %278, %239 : i64, !llvm.ptr
      %280 = llvm.load %262 : !llvm.ptr -> i64
      %281 = arith.constant 1 : i32
      %283 = arith.extsi %281 : i32 to i64
      %282 = arith.addi %280, %283 : i64
      llvm.store %282, %262 : i64, !llvm.ptr
      cf.br ^bb27
    ^bb29:
    %284 = arith.muli %50, %50 : i64
    %285 = arith.muli %52, %52 : i64
    %286 = arith.subi %284, %285 : i64
    %287 = arith.constant 1 : i32
    %288 = arith.extsi %287 : i32 to i64
    %289 = llvm.mlir.constant(1 : i64) : i64
    %290 = llvm.alloca %289 x i64 : (i64) -> !llvm.ptr
    llvm.store %288, %290 : i64, !llvm.ptr
    %291 = arith.constant 2 : i32
    %292 = arith.extsi %291 : i32 to i64
    llvm.store %292, %89 : i64, !llvm.ptr
    cf.br ^bb30
    ^bb30:
    %293 = llvm.load %89 : !llvm.ptr -> i64
    %294 = arith.cmpi sle, %293, %286 : i64
    cf.cond_br %294, ^bb31, ^bb32
    ^bb31:
      %295 = llvm.load %290 : !llvm.ptr -> i64
      %296 = arith.extsi %295 : i64 to i128
      %297 = llvm.load %89 : !llvm.ptr -> i64
      %298 = arith.extsi %297 : i64 to i128
      %300 = arith.trunci %296 : i128 to i64
      %301 = arith.trunci %298 : i128 to i64
      %299 = arith.muli %300, %301 : i64
      %302 = arith.extsi %54 : i64 to i128
      %304 = arith.trunci %302 : i128 to i64
      %303 = arith.remsi %299, %304 : i64
      llvm.store %303, %290 : i64, !llvm.ptr
      %305 = llvm.load %89 : !llvm.ptr -> i64
      %306 = arith.constant 1 : i32
      %308 = arith.extsi %306 : i32 to i64
      %307 = arith.addi %305, %308 : i64
      llvm.store %307, %89 : i64, !llvm.ptr
      cf.br ^bb30
    ^bb32:
    %309 = llvm.load %290 : !llvm.ptr -> i64
    %310 = llvm.mlir.constant(1 : i64) : i64
    %311 = llvm.alloca %310 x i64 : (i64) -> !llvm.ptr
    llvm.store %309, %311 : i64, !llvm.ptr
    %312 = llvm.load %311 : !llvm.ptr -> i64
    %313 = arith.extsi %312 : i64 to i128
    %314 = llvm.load %148 : !llvm.ptr -> i64
    %315 = arith.extsi %314 : i64 to i128
    %317 = arith.trunci %313 : i128 to i64
    %318 = arith.trunci %315 : i128 to i64
    %316 = arith.muli %317, %318 : i64
    %319 = arith.extsi %54 : i64 to i128
    %321 = arith.trunci %319 : i128 to i64
    %320 = arith.remsi %316, %321 : i64
    llvm.store %320, %311 : i64, !llvm.ptr
    %322 = llvm.load %311 : !llvm.ptr -> i64
    %323 = arith.extsi %322 : i64 to i128
    %324 = llvm.load %172 : !llvm.ptr -> i64
    %325 = arith.extsi %324 : i64 to i128
    %327 = arith.trunci %323 : i128 to i64
    %328 = arith.trunci %325 : i128 to i64
    %326 = arith.muli %327, %328 : i64
    %329 = arith.extsi %54 : i64 to i128
    %331 = arith.trunci %329 : i128 to i64
    %330 = arith.remsi %326, %331 : i64
    llvm.store %330, %311 : i64, !llvm.ptr
    %332 = llvm.load %311 : !llvm.ptr -> i64
    %333 = arith.extsi %332 : i64 to i128
    %334 = llvm.load %196 : !llvm.ptr -> i64
    %335 = arith.extsi %334 : i64 to i128
    %337 = arith.trunci %333 : i128 to i64
    %338 = arith.trunci %335 : i128 to i64
    %336 = arith.muli %337, %338 : i64
    %339 = arith.extsi %54 : i64 to i128
    %341 = arith.trunci %339 : i128 to i64
    %340 = arith.remsi %336, %341 : i64
    llvm.store %340, %311 : i64, !llvm.ptr
    %342 = llvm.load %311 : !llvm.ptr -> i64
    %343 = arith.extsi %342 : i64 to i128
    %344 = llvm.load %239 : !llvm.ptr -> i64
    %345 = arith.extsi %344 : i64 to i128
    %347 = arith.trunci %343 : i128 to i64
    %348 = arith.trunci %345 : i128 to i64
    %346 = arith.muli %347, %348 : i64
    %349 = arith.extsi %54 : i64 to i128
    %351 = arith.trunci %349 : i128 to i64
    %350 = arith.remsi %346, %351 : i64
    llvm.store %350, %311 : i64, !llvm.ptr
    %352 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %353 = llvm.load %311 : !llvm.ptr -> i64
    %354 = llvm.call @printf(%352, %353) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    func.call @free(%68) : (!llvm.ptr) -> ()
    func.call @free(%62) : (!llvm.ptr) -> ()
    %357 = arith.constant 0 : i32
    func.return %357 : i32
  }
}