Problem 706

3-Like Numbers — F(10^5) mod 10^9+7. Automaton with state (a,b,c,cur) tracking counts mod 3 of digit-sum classes 0,1,2 and the current running sum mod 3. Matrix exponentiation.

Answer884837055
Output884837055
StatusPASS
Native helperno
Runtime0 ms
Peak memory1424 KB
Time complexityO(n^5) (estimated)
Space complexityO(n^2) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^5)O(log n)
Space complexityO(n^2)O(n^2)
ApproachFlow solutionMatrix exponentiation
VerdictUnknown

Flow source

# Project Euler 706
# 3-Like Numbers — F(10^5) mod 10^9+7.
#
# Automaton with state (a,b,c,cur) tracking counts mod 3 of digit-sum
# classes 0,1,2 and the current running sum mod 3. Matrix exponentiation.

extern {
    function calloc(n: i64, size: i64) -> ptr<void>
    function free(p: ptr<void>) -> void
    function memset(p: ptr<void>, c: i32, n: i64) -> ptr<void>
    function memcpy(dst: ptr<void>, src: ptr<void>, n: i64) -> ptr<void>
}

const N: i64 = 81
const MOD: i64 = 1000000007

function idx(a: i32, b: i32, c: i32, cur: i32) -> i32 {
    return ((a * 3 + b) * 3 + c) * 3 + cur
}

function mat_mul(c: ptr<i64>, a: ptr<i64>, b: ptr<i64>) -> void {
    let t: ptr<i64> = calloc(N * N, 8)
    memset(t, 0, N * N * 8)
    let mut i: i32 = 0
    while i < 81 {
        let mut k: i32 = 0
        while k < 81 {
            if a[(i as i64) * N + (k as i64)] != 0 {
                let mut j: i32 = 0
                while j < 81 {
                    if b[(k as i64) * N + (j as i64)] != 0 {
                        let val: i64 = t[(i as i64) * N + (j as i64)] + a[(i as i64) * N + (k as i64)] * b[(k as i64) * N + (j as i64)]
                        t[(i as i64) * N + (j as i64)] = val % MOD
                    }
                    j = j + 1
                }
            }
            k = k + 1
        }
        i = i + 1
    }
    memcpy(c, t, N * N * 8)
    free(t)
}

function mat_pow(r: ptr<i64>, a0: ptr<i64>, e: i64) -> void {
    let a: ptr<i64> = calloc(N * N, 8)
    memcpy(a, a0, N * N * 8)
    memset(r, 0, N * N * 8)
    let mut i: i32 = 0
    while i < 81 {
        r[(i as i64) * N + (i as i64)] = 1
        i = i + 1
    }
    let mut e2: i64 = e
    while e2 > 0 {
        if (e2 & 1) == 1 {
            mat_mul(r, a, r)
        }
        e2 = e2 >> 1
        if e2 > 0 {
            mat_mul(a, a, a)
        }
    }
    free(a)
}

function mat_vec(out: ptr<i64>, m: ptr<i64>, v: ptr<i64>) -> void {
    let mut i: i32 = 0
    while i < 81 {
        let mut s: i64 = 0
        let mut j: i32 = 0
        while j < 81 {
            if m[(i as i64) * N + (j as i64)] != 0 {
                s = (s + m[(i as i64) * N + (j as i64)] * v[j]) % MOD
            }
            j = j + 1
        }
        out[i] = s
        i = i + 1
    }
}

function build(m: ptr<i64>, w0: i64, w1: i64, w2: i64) -> void {
    memset(m, 0, N * N * 8)
    let w: array<i64, 3> = [w0, w1, w2]
    let mut a: i32 = 0
    while a < 3 {
        let mut b: i32 = 0
        while b < 3 {
            let mut c: i32 = 0
            while c < 3 {
                let mut cur: i32 = 0
                while cur < 3 {
                    let frm: i32 = idx(a, b, c, cur)
                    let mut r: i32 = 0
                    while r < 3 {
                        let nxt: i32 = (cur + r) % 3
                        let mut a2: i32 = a
                        let mut b2: i32 = b
                        let mut c2: i32 = c
                        if nxt == 0 {
                            a2 = (a2 + 1) % 3
                        }
                        else {
                            if nxt == 1 {
                                b2 = (b2 + 1) % 3
                            }
                            else {
                                c2 = (c2 + 1) % 3
                            }
                        }
                        let to_idx: i32 = idx(a2, b2, c2, nxt)
                        m[(to_idx as i64) * N + (frm as i64)] = (m[(to_idx as i64) * N + (frm as i64)] + w[r]) % MOD
                        r = r + 1
                    }
                    cur = cur + 1
                }
                c = c + 1
            }
            b = b + 1
        }
        a = a + 1
    }
}

function main() -> i32 {
    let d: i64 = 100000

    let lead: ptr<i64> = calloc(N * N, 8)
    let step: ptr<i64> = calloc(N * N, 8)
    build(lead, 3, 3, 3)
    build(step, 4, 3, 3)

    let good: ptr<i8> = calloc(N, 1)
    let mut a: i32 = 0
    while a < 3 {
        let mut b: i32 = 0
        while b < 3 {
            let mut c: i32 = 0
            while c < 3 {
                let mut k: i32 = 0
                if a == 2 { k = k + 1 }
                if b == 2 { k = k + 1 }
                if c == 2 { k = k + 1 }
                if k % 3 == 0 {
                    let mut cur: i32 = 0
                    while cur < 3 {
                        good[idx(a, b, c, cur)] = 1
                        cur = cur + 1
                    }
                }
                c = c + 1
            }
            b = b + 1
        }
        a = a + 1
    }

    let v: ptr<i64> = calloc(N, 8)
    let v2: ptr<i64> = calloc(N, 8)
    v[idx(1, 0, 0, 0)] = 1

    mat_vec(v2, lead, v)
    memcpy(v, v2, N * 8)

    if d > 1 {
        let p: ptr<i64> = calloc(N * N, 8)
        mat_pow(p, step, d - 1)
        mat_vec(v2, p, v)
        memcpy(v, v2, N * 8)
        free(p)
    }

    let mut ans: i64 = 0
    let mut i: i32 = 0
    while i < 81 {
        if good[i] != 0 {
            ans = ans + v[i]
        }
        i = i + 1
    }

    printf("%lld\n", ans % MOD)

    free(lead)
    free(step)
    free(good)
    free(v)
    free(v2)
    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; }

int32_t idx_i32_i32_i32_i32(int32_t a, int32_t b, int32_t c, int32_t cur);
void mat_mul_ptr_i64_ptr_i64_ptr_i64(int64_t* c, int64_t* a, int64_t* b);
void mat_pow_ptr_i64_ptr_i64_i64(int64_t* r, int64_t* a0, int64_t e);
void mat_vec_ptr_i64_ptr_i64_ptr_i64(int64_t* out, int64_t* m, int64_t* v);
void build_ptr_i64_i64_i64_i64(int64_t* m, int64_t w0, int64_t w1, int64_t w2);
int32_t main(void);

static const int64_t N = 81;
static const int64_t MOD = 1000000007;





int32_t idx_i32_i32_i32_i32(int32_t a, int32_t b, int32_t c, int32_t cur) {
    return ((((((a * 3) + b) * 3) + c) * 3) + cur);
}

void mat_mul_ptr_i64_ptr_i64_ptr_i64(int64_t* c, int64_t* a, int64_t* b) {
    int64_t* t = (int64_t*)(calloc((N * N), 8));
    memset(t, 0, ((N * N) * 8));
    int32_t i = 0;
    while (i < 81) {
        int32_t k = 0;
        while (k < 81) {
            if (a[((((int64_t)(i)) * N) + ((int64_t)(k)))] != 0) {
                int32_t j = 0;
                while (j < 81) {
                    if (b[((((int64_t)(k)) * N) + ((int64_t)(j)))] != 0) {
                        int64_t val = (t[((((int64_t)(i)) * N) + ((int64_t)(j)))] + (a[((((int64_t)(i)) * N) + ((int64_t)(k)))] * b[((((int64_t)(k)) * N) + ((int64_t)(j)))]));
                        t[((((int64_t)(i)) * N) + ((int64_t)(j)))] = FLOW_CHECKED_MOD((val), (MOD));
                    }
                    j = (j + 1);
                }
            }
            k = (k + 1);
        }
        i = (i + 1);
    }
    memcpy(c, t, ((N * N) * 8));
    free(t);
}

void mat_pow_ptr_i64_ptr_i64_i64(int64_t* r, int64_t* a0, int64_t e) {
    int64_t* a = (int64_t*)(calloc((N * N), 8));
    memcpy(a, a0, ((N * N) * 8));
    memset(r, 0, ((N * N) * 8));
    int32_t i = 0;
    while (i < 81) {
        r[((((int64_t)(i)) * N) + ((int64_t)(i)))] = 1;
        i = (i + 1);
    }
    int64_t e2 = e;
    while (e2 > 0) {
        if ((e2 & 1) == 1) {
            mat_mul_ptr_i64_ptr_i64_ptr_i64(r, a, r);
        }
        e2 = FLOW_CHECKED_SHR((e2), (1));
        if (e2 > 0) {
            mat_mul_ptr_i64_ptr_i64_ptr_i64(a, a, a);
        }
    }
    free(a);
}

void mat_vec_ptr_i64_ptr_i64_ptr_i64(int64_t* out, int64_t* m, int64_t* v) {
    int32_t i = 0;
    while (i < 81) {
        int64_t s = 0;
        int32_t j = 0;
        while (j < 81) {
            if (m[((((int64_t)(i)) * N) + ((int64_t)(j)))] != 0) {
                s = FLOW_CHECKED_MOD(((s + (m[((((int64_t)(i)) * N) + ((int64_t)(j)))] * v[j]))), (MOD));
            }
            j = (j + 1);
        }
        out[i] = s;
        i = (i + 1);
    }
}

void build_ptr_i64_i64_i64_i64(int64_t* m, int64_t w0, int64_t w1, int64_t w2) {
    memset(m, 0, ((N * N) * 8));
    int64_t w[3] = { w0, w1, w2 };
    int32_t a = 0;
    while (a < 3) {
        int32_t b = 0;
        while (b < 3) {
            int32_t c = 0;
            while (c < 3) {
                int32_t cur = 0;
                while (cur < 3) {
                    int32_t frm = idx_i32_i32_i32_i32(a, b, c, cur);
                    int32_t r = 0;
                    while (r < 3) {
                        int32_t nxt = FLOW_CHECKED_MOD(((cur + r)), (3));
                        int32_t a2 = a;
                        int32_t b2 = b;
                        int32_t c2 = c;
                        if (nxt == 0) {
                            a2 = FLOW_CHECKED_MOD(((a2 + 1)), (3));
                        } else {
                            if (nxt == 1) {
                                b2 = FLOW_CHECKED_MOD(((b2 + 1)), (3));
                            } else {
                                c2 = FLOW_CHECKED_MOD(((c2 + 1)), (3));
                            }
                        }
                        int32_t to_idx = idx_i32_i32_i32_i32(a2, b2, c2, nxt);
                        m[((((int64_t)(to_idx)) * N) + ((int64_t)(frm)))] = FLOW_CHECKED_MOD(((m[((((int64_t)(to_idx)) * N) + ((int64_t)(frm)))] + (((unsigned)(r) < 3) ? w[r] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)(r), 3), flow_fault_handler("array index out of bounds"), w[0])))), (MOD));
                        r = (r + 1);
                    }
                    cur = (cur + 1);
                }
                c = (c + 1);
            }
            b = (b + 1);
        }
        a = (a + 1);
    }
}

int32_t main(void) {
    int64_t d = 100000;
    int64_t* lead = (int64_t*)(calloc((N * N), 8));
    int64_t* step = (int64_t*)(calloc((N * N), 8));
    build_ptr_i64_i64_i64_i64(lead, 3, 3, 3);
    build_ptr_i64_i64_i64_i64(step, 4, 3, 3);
    int8_t* good = (int8_t*)(calloc(N, 1));
    int32_t a = 0;
    while (a < 3) {
        int32_t b = 0;
        while (b < 3) {
            int32_t c = 0;
            while (c < 3) {
                int32_t k = 0;
                if (a == 2) {
                    k = (k + 1);
                }
                if (b == 2) {
                    k = (k + 1);
                }
                if (c == 2) {
                    k = (k + 1);
                }
                if (FLOW_CHECKED_MOD((k), (3)) == 0) {
                    int32_t cur = 0;
                    while (cur < 3) {
                        good[idx_i32_i32_i32_i32(a, b, c, cur)] = 1;
                        cur = (cur + 1);
                    }
                }
                c = (c + 1);
            }
            b = (b + 1);
        }
        a = (a + 1);
    }
    int64_t* v = (int64_t*)(calloc(N, 8));
    int64_t* v2 = (int64_t*)(calloc(N, 8));
    v[idx_i32_i32_i32_i32(1, 0, 0, 0)] = 1;
    mat_vec_ptr_i64_ptr_i64_ptr_i64(v2, lead, v);
    memcpy(v, v2, (N * 8));
    if (d > 1) {
        int64_t* p = (int64_t*)(calloc((N * N), 8));
        mat_pow_ptr_i64_ptr_i64_i64(p, step, (d - 1));
        mat_vec_ptr_i64_ptr_i64_ptr_i64(v2, p, v);
        memcpy(v, v2, (N * 8));
        free(p);
    }
    int64_t ans = 0;
    int32_t i = 0;
    while (i < 81) {
        if (good[i] != 0) {
            ans = (ans + v[i]);
        }
        i = (i + 1);
    }
    printf("%lld\n", FLOW_CHECKED_MOD((ans), (MOD)));
    free(lead);
    free(step);
    free(good);
    free(v);
    free(v2);
    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 private @memset(!llvm.ptr, i32, i64) -> !llvm.ptr
  func.func private @memcpy(!llvm.ptr, !llvm.ptr, i64) -> !llvm.ptr
  // Constant: N
  llvm.mlir.global internal constant @N(81 : i64) : i64
  // Constant: MOD
  llvm.mlir.global internal constant @MOD(1000000007 : i64) : i64
  func.func @idx(%arg0: i32, %arg1: i32, %arg2: i32, %arg3: i32) -> i32 {
    %0 = arith.constant 3 : i32
    %1 = arith.muli %arg0, %0 : i32
    %2 = arith.addi %1, %arg1 : i32
    %3 = arith.constant 3 : i32
    %4 = arith.muli %2, %3 : i32
    %5 = arith.addi %4, %arg2 : i32
    %6 = arith.constant 3 : i32
    %7 = arith.muli %5, %6 : i32
    %8 = arith.addi %7, %arg3 : i32
    func.return %8 : i32
  }
  func.func @mat_mul(%arg0: !llvm.ptr, %arg1: !llvm.ptr, %arg2: !llvm.ptr) -> () {
    %10 = llvm.mlir.addressof @N : !llvm.ptr
    %11 = llvm.load %10 : !llvm.ptr -> i64
    %12 = llvm.mlir.addressof @N : !llvm.ptr
    %13 = llvm.load %12 : !llvm.ptr -> i64
    %14 = arith.muli %11, %13 : i64
    %15 = arith.constant 8 : i32
    %16 = arith.extsi %15 : i32 to i64
    %9 = func.call @calloc(%14, %16) : (i64, i64) -> !llvm.ptr
    %18 = arith.constant 0 : i32
    %19 = llvm.mlir.addressof @N : !llvm.ptr
    %20 = llvm.load %19 : !llvm.ptr -> i64
    %21 = llvm.mlir.addressof @N : !llvm.ptr
    %22 = llvm.load %21 : !llvm.ptr -> i64
    %23 = arith.muli %20, %22 : i64
    %24 = arith.constant 8 : i32
    %26 = arith.extsi %24 : i32 to i64
    %25 = arith.muli %23, %26 : i64
    %17 = func.call @memset(%9, %18, %25) : (!llvm.ptr, i32, i64) -> !llvm.ptr
    %27 = arith.constant 0 : i32
    %28 = llvm.mlir.constant(1 : i64) : i64
    %29 = llvm.alloca %28 x i32 : (i64) -> !llvm.ptr
    llvm.store %27, %29 : i32, !llvm.ptr
    cf.br ^bb0
    ^bb0:
    %30 = llvm.load %29 : !llvm.ptr -> i32
    %31 = arith.constant 81 : i32
    %32 = arith.cmpi slt, %30, %31 : i32
    cf.cond_br %32, ^bb1, ^bb2
    ^bb1:
      %33 = arith.constant 0 : i32
      %34 = llvm.mlir.constant(1 : i64) : i64
      %35 = llvm.alloca %34 x i32 : (i64) -> !llvm.ptr
      llvm.store %33, %35 : i32, !llvm.ptr
      cf.br ^bb3
      ^bb3:
      %36 = llvm.load %35 : !llvm.ptr -> i32
      %37 = arith.constant 81 : i32
      %38 = arith.cmpi slt, %36, %37 : i32
      cf.cond_br %38, ^bb4, ^bb5
      ^bb4:
        %40 = llvm.load %29 : !llvm.ptr -> i32
        %41 = arith.extsi %40 : i32 to i64
        %42 = llvm.mlir.addressof @N : !llvm.ptr
        %43 = llvm.load %42 : !llvm.ptr -> i64
        %44 = arith.muli %41, %43 : i64
        %45 = llvm.load %35 : !llvm.ptr -> i32
        %46 = arith.extsi %45 : i32 to i64
        %47 = arith.addi %44, %46 : i64
        %48 = llvm.getelementptr %arg1[%47] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %39 = llvm.load %48 : !llvm.ptr -> i64
        %49 = arith.constant 0 : i32
        %51 = arith.extsi %49 : i32 to i64
        %50 = arith.cmpi ne, %39, %51 : i64
        cf.cond_br %50, ^bb6, ^bb7
        ^bb6:
          %52 = arith.constant 0 : i32
          %53 = llvm.mlir.constant(1 : i64) : i64
          %54 = llvm.alloca %53 x i32 : (i64) -> !llvm.ptr
          llvm.store %52, %54 : i32, !llvm.ptr
          cf.br ^bb9
          ^bb9:
          %55 = llvm.load %54 : !llvm.ptr -> i32
          %56 = arith.constant 81 : i32
          %57 = arith.cmpi slt, %55, %56 : i32
          cf.cond_br %57, ^bb10, ^bb11
          ^bb10:
            %59 = llvm.load %35 : !llvm.ptr -> i32
            %60 = arith.extsi %59 : i32 to i64
            %61 = llvm.mlir.addressof @N : !llvm.ptr
            %62 = llvm.load %61 : !llvm.ptr -> i64
            %63 = arith.muli %60, %62 : i64
            %64 = llvm.load %54 : !llvm.ptr -> i32
            %65 = arith.extsi %64 : i32 to i64
            %66 = arith.addi %63, %65 : i64
            %67 = llvm.getelementptr %arg2[%66] : (!llvm.ptr, i64) -> !llvm.ptr, i64
            %58 = llvm.load %67 : !llvm.ptr -> i64
            %68 = arith.constant 0 : i32
            %70 = arith.extsi %68 : i32 to i64
            %69 = arith.cmpi ne, %58, %70 : i64
            cf.cond_br %69, ^bb12, ^bb13
            ^bb12:
              %72 = llvm.load %29 : !llvm.ptr -> i32
              %73 = arith.extsi %72 : i32 to i64
              %74 = llvm.mlir.addressof @N : !llvm.ptr
              %75 = llvm.load %74 : !llvm.ptr -> i64
              %76 = arith.muli %73, %75 : i64
              %77 = llvm.load %54 : !llvm.ptr -> i32
              %78 = arith.extsi %77 : i32 to i64
              %79 = arith.addi %76, %78 : i64
              %80 = llvm.getelementptr %9[%79] : (!llvm.ptr, i64) -> !llvm.ptr, i64
              %71 = llvm.load %80 : !llvm.ptr -> i64
              %82 = llvm.load %29 : !llvm.ptr -> i32
              %83 = arith.extsi %82 : i32 to i64
              %84 = llvm.mlir.addressof @N : !llvm.ptr
              %85 = llvm.load %84 : !llvm.ptr -> i64
              %86 = arith.muli %83, %85 : i64
              %87 = llvm.load %35 : !llvm.ptr -> i32
              %88 = arith.extsi %87 : i32 to i64
              %89 = arith.addi %86, %88 : i64
              %90 = llvm.getelementptr %arg1[%89] : (!llvm.ptr, i64) -> !llvm.ptr, i64
              %81 = llvm.load %90 : !llvm.ptr -> i64
              %92 = llvm.load %35 : !llvm.ptr -> i32
              %93 = arith.extsi %92 : i32 to i64
              %94 = llvm.mlir.addressof @N : !llvm.ptr
              %95 = llvm.load %94 : !llvm.ptr -> i64
              %96 = arith.muli %93, %95 : i64
              %97 = llvm.load %54 : !llvm.ptr -> i32
              %98 = arith.extsi %97 : i32 to i64
              %99 = arith.addi %96, %98 : i64
              %100 = llvm.getelementptr %arg2[%99] : (!llvm.ptr, i64) -> !llvm.ptr, i64
              %91 = llvm.load %100 : !llvm.ptr -> i64
              %101 = arith.muli %81, %91 : i64
              %102 = arith.addi %71, %101 : i64
              %103 = llvm.mlir.addressof @MOD : !llvm.ptr
              %104 = llvm.load %103 : !llvm.ptr -> i64
              %105 = arith.remsi %102, %104 : i64
              %106 = llvm.load %29 : !llvm.ptr -> i32
              %107 = arith.extsi %106 : i32 to i64
              %108 = llvm.mlir.addressof @N : !llvm.ptr
              %109 = llvm.load %108 : !llvm.ptr -> i64
              %110 = arith.muli %107, %109 : i64
              %111 = llvm.load %54 : !llvm.ptr -> i32
              %112 = arith.extsi %111 : i32 to i64
              %113 = arith.addi %110, %112 : i64
              %114 = llvm.getelementptr %9[%113] : (!llvm.ptr, i64) -> !llvm.ptr, i64
              llvm.store %105, %114 : i64, !llvm.ptr
              cf.br ^bb14
            ^bb13:
              cf.br ^bb14
            ^bb14:
            %115 = llvm.load %54 : !llvm.ptr -> i32
            %116 = arith.constant 1 : i32
            %117 = arith.addi %115, %116 : i32
            llvm.store %117, %54 : i32, !llvm.ptr
            cf.br ^bb9
          ^bb11:
          cf.br ^bb8
        ^bb7:
          cf.br ^bb8
        ^bb8:
        %118 = llvm.load %35 : !llvm.ptr -> i32
        %119 = arith.constant 1 : i32
        %120 = arith.addi %118, %119 : i32
        llvm.store %120, %35 : i32, !llvm.ptr
        cf.br ^bb3
      ^bb5:
      %121 = llvm.load %29 : !llvm.ptr -> i32
      %122 = arith.constant 1 : i32
      %123 = arith.addi %121, %122 : i32
      llvm.store %123, %29 : i32, !llvm.ptr
      cf.br ^bb0
    ^bb2:
    %125 = llvm.mlir.addressof @N : !llvm.ptr
    %126 = llvm.load %125 : !llvm.ptr -> i64
    %127 = llvm.mlir.addressof @N : !llvm.ptr
    %128 = llvm.load %127 : !llvm.ptr -> i64
    %129 = arith.muli %126, %128 : i64
    %130 = arith.constant 8 : i32
    %132 = arith.extsi %130 : i32 to i64
    %131 = arith.muli %129, %132 : i64
    %124 = func.call @memcpy(%arg0, %9, %131) : (!llvm.ptr, !llvm.ptr, i64) -> !llvm.ptr
    func.call @free(%9) : (!llvm.ptr) -> ()
    func.return
  }
  func.func @mat_pow(%arg0: !llvm.ptr, %arg1: !llvm.ptr, %arg2: i64) -> () {
    %135 = llvm.mlir.addressof @N : !llvm.ptr
    %136 = llvm.load %135 : !llvm.ptr -> i64
    %137 = llvm.mlir.addressof @N : !llvm.ptr
    %138 = llvm.load %137 : !llvm.ptr -> i64
    %139 = arith.muli %136, %138 : i64
    %140 = arith.constant 8 : i32
    %141 = arith.extsi %140 : i32 to i64
    %134 = func.call @calloc(%139, %141) : (i64, i64) -> !llvm.ptr
    %143 = llvm.mlir.addressof @N : !llvm.ptr
    %144 = llvm.load %143 : !llvm.ptr -> i64
    %145 = llvm.mlir.addressof @N : !llvm.ptr
    %146 = llvm.load %145 : !llvm.ptr -> i64
    %147 = arith.muli %144, %146 : i64
    %148 = arith.constant 8 : i32
    %150 = arith.extsi %148 : i32 to i64
    %149 = arith.muli %147, %150 : i64
    %142 = func.call @memcpy(%134, %arg1, %149) : (!llvm.ptr, !llvm.ptr, i64) -> !llvm.ptr
    %152 = arith.constant 0 : i32
    %153 = llvm.mlir.addressof @N : !llvm.ptr
    %154 = llvm.load %153 : !llvm.ptr -> i64
    %155 = llvm.mlir.addressof @N : !llvm.ptr
    %156 = llvm.load %155 : !llvm.ptr -> i64
    %157 = arith.muli %154, %156 : i64
    %158 = arith.constant 8 : i32
    %160 = arith.extsi %158 : i32 to i64
    %159 = arith.muli %157, %160 : i64
    %151 = func.call @memset(%arg0, %152, %159) : (!llvm.ptr, i32, i64) -> !llvm.ptr
    %161 = arith.constant 0 : i32
    %162 = llvm.mlir.constant(1 : i64) : i64
    %163 = llvm.alloca %162 x i32 : (i64) -> !llvm.ptr
    llvm.store %161, %163 : i32, !llvm.ptr
    cf.br ^bb15
    ^bb15:
    %164 = llvm.load %163 : !llvm.ptr -> i32
    %165 = arith.constant 81 : i32
    %166 = arith.cmpi slt, %164, %165 : i32
    cf.cond_br %166, ^bb16, ^bb17
    ^bb16:
      %167 = arith.constant 1 : i32
      %168 = llvm.load %163 : !llvm.ptr -> i32
      %169 = arith.extsi %168 : i32 to i64
      %170 = llvm.mlir.addressof @N : !llvm.ptr
      %171 = llvm.load %170 : !llvm.ptr -> i64
      %172 = arith.muli %169, %171 : i64
      %173 = llvm.load %163 : !llvm.ptr -> i32
      %174 = arith.extsi %173 : i32 to i64
      %175 = arith.addi %172, %174 : i64
      %176 = arith.extsi %167 : i32 to i64
      %177 = llvm.getelementptr %arg0[%175] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %176, %177 : i64, !llvm.ptr
      %178 = llvm.load %163 : !llvm.ptr -> i32
      %179 = arith.constant 1 : i32
      %180 = arith.addi %178, %179 : i32
      llvm.store %180, %163 : i32, !llvm.ptr
      cf.br ^bb15
    ^bb17:
    %181 = llvm.mlir.constant(1 : i64) : i64
    %182 = llvm.alloca %181 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg2, %182 : i64, !llvm.ptr
    cf.br ^bb18
    ^bb18:
    %183 = llvm.load %182 : !llvm.ptr -> i64
    %184 = arith.constant 0 : i32
    %186 = arith.extsi %184 : i32 to i64
    %185 = arith.cmpi sgt, %183, %186 : i64
    cf.cond_br %185, ^bb19, ^bb20
    ^bb19:
      %187 = llvm.load %182 : !llvm.ptr -> i64
      %188 = arith.constant 1 : i32
      %190 = arith.extsi %188 : i32 to i64
      %189 = arith.andi %187, %190 : i64
      %191 = arith.constant 1 : i32
      %193 = arith.extsi %191 : i32 to i64
      %192 = arith.cmpi eq, %189, %193 : i64
      cf.cond_br %192, ^bb21, ^bb22
      ^bb21:
        func.call @mat_mul(%arg0, %134, %arg0) : (!llvm.ptr, !llvm.ptr, !llvm.ptr) -> ()
        cf.br ^bb23
      ^bb22:
        cf.br ^bb23
      ^bb23:
      %195 = llvm.load %182 : !llvm.ptr -> i64
      %196 = arith.constant 1 : i32
      %198 = arith.extsi %196 : i32 to i64
      %197 = arith.shrsi %195, %198 : i64
      llvm.store %197, %182 : i64, !llvm.ptr
      %199 = llvm.load %182 : !llvm.ptr -> i64
      %200 = arith.constant 0 : i32
      %202 = arith.extsi %200 : i32 to i64
      %201 = arith.cmpi sgt, %199, %202 : i64
      cf.cond_br %201, ^bb24, ^bb25
      ^bb24:
        func.call @mat_mul(%134, %134, %134) : (!llvm.ptr, !llvm.ptr, !llvm.ptr) -> ()
        cf.br ^bb26
      ^bb25:
        cf.br ^bb26
      ^bb26:
      cf.br ^bb18
    ^bb20:
    func.call @free(%134) : (!llvm.ptr) -> ()
    func.return
  }
  func.func @mat_vec(%arg0: !llvm.ptr, %arg1: !llvm.ptr, %arg2: !llvm.ptr) -> () {
    %205 = arith.constant 0 : i32
    %206 = llvm.mlir.constant(1 : i64) : i64
    %207 = llvm.alloca %206 x i32 : (i64) -> !llvm.ptr
    llvm.store %205, %207 : i32, !llvm.ptr
    cf.br ^bb27
    ^bb27:
    %208 = llvm.load %207 : !llvm.ptr -> i32
    %209 = arith.constant 81 : i32
    %210 = arith.cmpi slt, %208, %209 : i32
    cf.cond_br %210, ^bb28, ^bb29
    ^bb28:
      %211 = arith.constant 0 : i32
      %212 = arith.extsi %211 : i32 to i64
      %213 = llvm.mlir.constant(1 : i64) : i64
      %214 = llvm.alloca %213 x i64 : (i64) -> !llvm.ptr
      llvm.store %212, %214 : i64, !llvm.ptr
      %215 = arith.constant 0 : i32
      %216 = llvm.mlir.constant(1 : i64) : i64
      %217 = llvm.alloca %216 x i32 : (i64) -> !llvm.ptr
      llvm.store %215, %217 : i32, !llvm.ptr
      cf.br ^bb30
      ^bb30:
      %218 = llvm.load %217 : !llvm.ptr -> i32
      %219 = arith.constant 81 : i32
      %220 = arith.cmpi slt, %218, %219 : i32
      cf.cond_br %220, ^bb31, ^bb32
      ^bb31:
        %222 = llvm.load %207 : !llvm.ptr -> i32
        %223 = arith.extsi %222 : i32 to i64
        %224 = llvm.mlir.addressof @N : !llvm.ptr
        %225 = llvm.load %224 : !llvm.ptr -> i64
        %226 = arith.muli %223, %225 : i64
        %227 = llvm.load %217 : !llvm.ptr -> i32
        %228 = arith.extsi %227 : i32 to i64
        %229 = arith.addi %226, %228 : i64
        %230 = llvm.getelementptr %arg1[%229] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %221 = llvm.load %230 : !llvm.ptr -> i64
        %231 = arith.constant 0 : i32
        %233 = arith.extsi %231 : i32 to i64
        %232 = arith.cmpi ne, %221, %233 : i64
        cf.cond_br %232, ^bb33, ^bb34
        ^bb33:
          %234 = llvm.load %214 : !llvm.ptr -> i64
          %236 = llvm.load %207 : !llvm.ptr -> i32
          %237 = arith.extsi %236 : i32 to i64
          %238 = llvm.mlir.addressof @N : !llvm.ptr
          %239 = llvm.load %238 : !llvm.ptr -> i64
          %240 = arith.muli %237, %239 : i64
          %241 = llvm.load %217 : !llvm.ptr -> i32
          %242 = arith.extsi %241 : i32 to i64
          %243 = arith.addi %240, %242 : i64
          %244 = llvm.getelementptr %arg1[%243] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %235 = llvm.load %244 : !llvm.ptr -> i64
          %246 = llvm.load %217 : !llvm.ptr -> i32
          %247 = arith.extsi %246 : i32 to i64
          %248 = llvm.getelementptr %arg2[%247] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %245 = llvm.load %248 : !llvm.ptr -> i64
          %249 = arith.muli %235, %245 : i64
          %250 = arith.addi %234, %249 : i64
          %251 = llvm.mlir.addressof @MOD : !llvm.ptr
          %252 = llvm.load %251 : !llvm.ptr -> i64
          %253 = arith.remsi %250, %252 : i64
          llvm.store %253, %214 : i64, !llvm.ptr
          cf.br ^bb35
        ^bb34:
          cf.br ^bb35
        ^bb35:
        %254 = llvm.load %217 : !llvm.ptr -> i32
        %255 = arith.constant 1 : i32
        %256 = arith.addi %254, %255 : i32
        llvm.store %256, %217 : i32, !llvm.ptr
        cf.br ^bb30
      ^bb32:
      %257 = llvm.load %214 : !llvm.ptr -> i64
      %258 = llvm.load %207 : !llvm.ptr -> i32
      %259 = arith.extsi %258 : i32 to i64
      %260 = llvm.getelementptr %arg0[%259] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %257, %260 : i64, !llvm.ptr
      %261 = llvm.load %207 : !llvm.ptr -> i32
      %262 = arith.constant 1 : i32
      %263 = arith.addi %261, %262 : i32
      llvm.store %263, %207 : i32, !llvm.ptr
      cf.br ^bb27
    ^bb29:
    func.return
  }
  func.func @build(%arg0: !llvm.ptr, %arg1: i64, %arg2: i64, %arg3: i64) -> () {
    %265 = arith.constant 0 : i32
    %266 = llvm.mlir.addressof @N : !llvm.ptr
    %267 = llvm.load %266 : !llvm.ptr -> i64
    %268 = llvm.mlir.addressof @N : !llvm.ptr
    %269 = llvm.load %268 : !llvm.ptr -> i64
    %270 = arith.muli %267, %269 : i64
    %271 = arith.constant 8 : i32
    %273 = arith.extsi %271 : i32 to i64
    %272 = arith.muli %270, %273 : i64
    %264 = func.call @memset(%arg0, %265, %272) : (!llvm.ptr, i32, i64) -> !llvm.ptr
    %275 = llvm.mlir.constant(1 : i64) : i64
    %276 = llvm.alloca %275 x !llvm.array<3 x i64> : (i64) -> !llvm.ptr
    %277 = llvm.mlir.zero : !llvm.array<3 x i64>
    llvm.store %277, %276 : !llvm.array<3 x i64>, !llvm.ptr
    %278 = llvm.mlir.constant(0 : i64) : i64
    %279 = llvm.getelementptr %276[0, %278] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<3 x i64>
    llvm.store %arg1, %279 : i64, !llvm.ptr
    %280 = llvm.mlir.constant(1 : i64) : i64
    %281 = llvm.getelementptr %276[0, %280] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<3 x i64>
    llvm.store %arg2, %281 : i64, !llvm.ptr
    %282 = llvm.mlir.constant(2 : i64) : i64
    %283 = llvm.getelementptr %276[0, %282] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<3 x i64>
    llvm.store %arg3, %283 : i64, !llvm.ptr
    %284 = arith.constant 0 : i32
    %285 = llvm.mlir.constant(1 : i64) : i64
    %286 = llvm.alloca %285 x i32 : (i64) -> !llvm.ptr
    llvm.store %284, %286 : i32, !llvm.ptr
    cf.br ^bb36
    ^bb36:
    %287 = llvm.load %286 : !llvm.ptr -> i32
    %288 = arith.constant 3 : i32
    %289 = arith.cmpi slt, %287, %288 : i32
    cf.cond_br %289, ^bb37, ^bb38
    ^bb37:
      %290 = arith.constant 0 : i32
      %291 = llvm.mlir.constant(1 : i64) : i64
      %292 = llvm.alloca %291 x i32 : (i64) -> !llvm.ptr
      llvm.store %290, %292 : i32, !llvm.ptr
      cf.br ^bb39
      ^bb39:
      %293 = llvm.load %292 : !llvm.ptr -> i32
      %294 = arith.constant 3 : i32
      %295 = arith.cmpi slt, %293, %294 : i32
      cf.cond_br %295, ^bb40, ^bb41
      ^bb40:
        %296 = arith.constant 0 : i32
        %297 = llvm.mlir.constant(1 : i64) : i64
        %298 = llvm.alloca %297 x i32 : (i64) -> !llvm.ptr
        llvm.store %296, %298 : i32, !llvm.ptr
        cf.br ^bb42
        ^bb42:
        %299 = llvm.load %298 : !llvm.ptr -> i32
        %300 = arith.constant 3 : i32
        %301 = arith.cmpi slt, %299, %300 : i32
        cf.cond_br %301, ^bb43, ^bb44
        ^bb43:
          %302 = arith.constant 0 : i32
          %303 = llvm.mlir.constant(1 : i64) : i64
          %304 = llvm.alloca %303 x i32 : (i64) -> !llvm.ptr
          llvm.store %302, %304 : i32, !llvm.ptr
          cf.br ^bb45
          ^bb45:
          %305 = llvm.load %304 : !llvm.ptr -> i32
          %306 = arith.constant 3 : i32
          %307 = arith.cmpi slt, %305, %306 : i32
          cf.cond_br %307, ^bb46, ^bb47
          ^bb46:
            %309 = llvm.load %286 : !llvm.ptr -> i32
            %310 = llvm.load %292 : !llvm.ptr -> i32
            %311 = llvm.load %298 : !llvm.ptr -> i32
            %312 = llvm.load %304 : !llvm.ptr -> i32
            %308 = func.call @idx(%309, %310, %311, %312) : (i32, i32, i32, i32) -> i32
            %313 = arith.constant 0 : i32
            %314 = llvm.mlir.constant(1 : i64) : i64
            %315 = llvm.alloca %314 x i32 : (i64) -> !llvm.ptr
            llvm.store %313, %315 : i32, !llvm.ptr
            cf.br ^bb48
            ^bb48:
            %316 = llvm.load %315 : !llvm.ptr -> i32
            %317 = arith.constant 3 : i32
            %318 = arith.cmpi slt, %316, %317 : i32
            cf.cond_br %318, ^bb49, ^bb50
            ^bb49:
              %319 = llvm.load %304 : !llvm.ptr -> i32
              %320 = llvm.load %315 : !llvm.ptr -> i32
              %321 = arith.addi %319, %320 : i32
              %322 = arith.constant 3 : i32
              %323 = arith.remsi %321, %322 : i32
              %324 = llvm.load %286 : !llvm.ptr -> i32
              %325 = llvm.mlir.constant(1 : i64) : i64
              %326 = llvm.alloca %325 x i32 : (i64) -> !llvm.ptr
              llvm.store %324, %326 : i32, !llvm.ptr
              %327 = llvm.load %292 : !llvm.ptr -> i32
              %328 = llvm.mlir.constant(1 : i64) : i64
              %329 = llvm.alloca %328 x i32 : (i64) -> !llvm.ptr
              llvm.store %327, %329 : i32, !llvm.ptr
              %330 = llvm.load %298 : !llvm.ptr -> i32
              %331 = llvm.mlir.constant(1 : i64) : i64
              %332 = llvm.alloca %331 x i32 : (i64) -> !llvm.ptr
              llvm.store %330, %332 : i32, !llvm.ptr
              %333 = arith.constant 0 : i32
              %334 = arith.cmpi eq, %323, %333 : i32
              cf.cond_br %334, ^bb51, ^bb52
              ^bb51:
                %335 = llvm.load %326 : !llvm.ptr -> i32
                %336 = arith.constant 1 : i32
                %337 = arith.addi %335, %336 : i32
                %338 = arith.constant 3 : i32
                %339 = arith.remsi %337, %338 : i32
                llvm.store %339, %326 : i32, !llvm.ptr
                cf.br ^bb53
              ^bb52:
                %340 = arith.constant 1 : i32
                %341 = arith.cmpi eq, %323, %340 : i32
                cf.cond_br %341, ^bb54, ^bb55
                ^bb54:
                  %342 = llvm.load %329 : !llvm.ptr -> i32
                  %343 = arith.constant 1 : i32
                  %344 = arith.addi %342, %343 : i32
                  %345 = arith.constant 3 : i32
                  %346 = arith.remsi %344, %345 : i32
                  llvm.store %346, %329 : i32, !llvm.ptr
                  cf.br ^bb56
                ^bb55:
                  %347 = llvm.load %332 : !llvm.ptr -> i32
                  %348 = arith.constant 1 : i32
                  %349 = arith.addi %347, %348 : i32
                  %350 = arith.constant 3 : i32
                  %351 = arith.remsi %349, %350 : i32
                  llvm.store %351, %332 : i32, !llvm.ptr
                  cf.br ^bb56
                ^bb56:
                cf.br ^bb53
              ^bb53:
              %353 = llvm.load %326 : !llvm.ptr -> i32
              %354 = llvm.load %329 : !llvm.ptr -> i32
              %355 = llvm.load %332 : !llvm.ptr -> i32
              %352 = func.call @idx(%353, %354, %355, %323) : (i32, i32, i32, i32) -> i32
              %357 = arith.extsi %352 : i32 to i64
              %358 = llvm.mlir.addressof @N : !llvm.ptr
              %359 = llvm.load %358 : !llvm.ptr -> i64
              %360 = arith.muli %357, %359 : i64
              %361 = arith.extsi %308 : i32 to i64
              %362 = arith.addi %360, %361 : i64
              %363 = llvm.getelementptr %arg0[%362] : (!llvm.ptr, i64) -> !llvm.ptr, i64
              %356 = llvm.load %363 : !llvm.ptr -> i64
              %365 = llvm.load %315 : !llvm.ptr -> i32
              %366 = arith.extsi %365 : i32 to i64
              %367 = llvm.getelementptr %276[0, %366] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<3 x i64>
              %364 = llvm.load %367 : !llvm.ptr -> i64
              %368 = arith.addi %356, %364 : i64
              %369 = llvm.mlir.addressof @MOD : !llvm.ptr
              %370 = llvm.load %369 : !llvm.ptr -> i64
              %371 = arith.remsi %368, %370 : i64
              %372 = arith.extsi %352 : i32 to i64
              %373 = llvm.mlir.addressof @N : !llvm.ptr
              %374 = llvm.load %373 : !llvm.ptr -> i64
              %375 = arith.muli %372, %374 : i64
              %376 = arith.extsi %308 : i32 to i64
              %377 = arith.addi %375, %376 : i64
              %378 = llvm.getelementptr %arg0[%377] : (!llvm.ptr, i64) -> !llvm.ptr, i64
              llvm.store %371, %378 : i64, !llvm.ptr
              %379 = llvm.load %315 : !llvm.ptr -> i32
              %380 = arith.constant 1 : i32
              %381 = arith.addi %379, %380 : i32
              llvm.store %381, %315 : i32, !llvm.ptr
              cf.br ^bb48
            ^bb50:
            %382 = llvm.load %304 : !llvm.ptr -> i32
            %383 = arith.constant 1 : i32
            %384 = arith.addi %382, %383 : i32
            llvm.store %384, %304 : i32, !llvm.ptr
            cf.br ^bb45
          ^bb47:
          %385 = llvm.load %298 : !llvm.ptr -> i32
          %386 = arith.constant 1 : i32
          %387 = arith.addi %385, %386 : i32
          llvm.store %387, %298 : i32, !llvm.ptr
          cf.br ^bb42
        ^bb44:
        %388 = llvm.load %292 : !llvm.ptr -> i32
        %389 = arith.constant 1 : i32
        %390 = arith.addi %388, %389 : i32
        llvm.store %390, %292 : i32, !llvm.ptr
        cf.br ^bb39
      ^bb41:
      %391 = llvm.load %286 : !llvm.ptr -> i32
      %392 = arith.constant 1 : i32
      %393 = arith.addi %391, %392 : i32
      llvm.store %393, %286 : i32, !llvm.ptr
      cf.br ^bb36
    ^bb38:
    func.return
  }
  func.func @main() -> i32 {
    %394 = arith.constant 100000 : i32
    %395 = arith.extsi %394 : i32 to i64
    %397 = llvm.mlir.addressof @N : !llvm.ptr
    %398 = llvm.load %397 : !llvm.ptr -> i64
    %399 = llvm.mlir.addressof @N : !llvm.ptr
    %400 = llvm.load %399 : !llvm.ptr -> i64
    %401 = arith.muli %398, %400 : i64
    %402 = arith.constant 8 : i32
    %403 = arith.extsi %402 : i32 to i64
    %396 = func.call @calloc(%401, %403) : (i64, i64) -> !llvm.ptr
    %405 = llvm.mlir.addressof @N : !llvm.ptr
    %406 = llvm.load %405 : !llvm.ptr -> i64
    %407 = llvm.mlir.addressof @N : !llvm.ptr
    %408 = llvm.load %407 : !llvm.ptr -> i64
    %409 = arith.muli %406, %408 : i64
    %410 = arith.constant 8 : i32
    %411 = arith.extsi %410 : i32 to i64
    %404 = func.call @calloc(%409, %411) : (i64, i64) -> !llvm.ptr
    %413 = arith.constant 3 : i32
    %414 = arith.constant 3 : i32
    %415 = arith.constant 3 : i32
    %416 = arith.extsi %413 : i32 to i64
    %417 = arith.extsi %414 : i32 to i64
    %418 = arith.extsi %415 : i32 to i64
    func.call @build(%396, %416, %417, %418) : (!llvm.ptr, i64, i64, i64) -> ()
    %420 = arith.constant 4 : i32
    %421 = arith.constant 3 : i32
    %422 = arith.constant 3 : i32
    %423 = arith.extsi %420 : i32 to i64
    %424 = arith.extsi %421 : i32 to i64
    %425 = arith.extsi %422 : i32 to i64
    func.call @build(%404, %423, %424, %425) : (!llvm.ptr, i64, i64, i64) -> ()
    %427 = llvm.mlir.addressof @N : !llvm.ptr
    %428 = llvm.load %427 : !llvm.ptr -> i64
    %429 = arith.constant 1 : i32
    %430 = arith.extsi %429 : i32 to i64
    %426 = func.call @calloc(%428, %430) : (i64, i64) -> !llvm.ptr
    %431 = arith.constant 0 : i32
    %432 = llvm.mlir.constant(1 : i64) : i64
    %433 = llvm.alloca %432 x i32 : (i64) -> !llvm.ptr
    llvm.store %431, %433 : i32, !llvm.ptr
    cf.br ^bb57
    ^bb57:
    %434 = llvm.load %433 : !llvm.ptr -> i32
    %435 = arith.constant 3 : i32
    %436 = arith.cmpi slt, %434, %435 : i32
    cf.cond_br %436, ^bb58, ^bb59
    ^bb58:
      %437 = arith.constant 0 : i32
      %438 = llvm.mlir.constant(1 : i64) : i64
      %439 = llvm.alloca %438 x i32 : (i64) -> !llvm.ptr
      llvm.store %437, %439 : i32, !llvm.ptr
      cf.br ^bb60
      ^bb60:
      %440 = llvm.load %439 : !llvm.ptr -> i32
      %441 = arith.constant 3 : i32
      %442 = arith.cmpi slt, %440, %441 : i32
      cf.cond_br %442, ^bb61, ^bb62
      ^bb61:
        %443 = arith.constant 0 : i32
        %444 = llvm.mlir.constant(1 : i64) : i64
        %445 = llvm.alloca %444 x i32 : (i64) -> !llvm.ptr
        llvm.store %443, %445 : i32, !llvm.ptr
        cf.br ^bb63
        ^bb63:
        %446 = llvm.load %445 : !llvm.ptr -> i32
        %447 = arith.constant 3 : i32
        %448 = arith.cmpi slt, %446, %447 : i32
        cf.cond_br %448, ^bb64, ^bb65
        ^bb64:
          %449 = arith.constant 0 : i32
          %450 = llvm.mlir.constant(1 : i64) : i64
          %451 = llvm.alloca %450 x i32 : (i64) -> !llvm.ptr
          llvm.store %449, %451 : i32, !llvm.ptr
          %452 = llvm.load %433 : !llvm.ptr -> i32
          %453 = arith.constant 2 : i32
          %454 = arith.cmpi eq, %452, %453 : i32
          cf.cond_br %454, ^bb66, ^bb67
          ^bb66:
            %455 = llvm.load %451 : !llvm.ptr -> i32
            %456 = arith.constant 1 : i32
            %457 = arith.addi %455, %456 : i32
            llvm.store %457, %451 : i32, !llvm.ptr
            cf.br ^bb68
          ^bb67:
            cf.br ^bb68
          ^bb68:
          %458 = llvm.load %439 : !llvm.ptr -> i32
          %459 = arith.constant 2 : i32
          %460 = arith.cmpi eq, %458, %459 : i32
          cf.cond_br %460, ^bb69, ^bb70
          ^bb69:
            %461 = llvm.load %451 : !llvm.ptr -> i32
            %462 = arith.constant 1 : i32
            %463 = arith.addi %461, %462 : i32
            llvm.store %463, %451 : i32, !llvm.ptr
            cf.br ^bb71
          ^bb70:
            cf.br ^bb71
          ^bb71:
          %464 = llvm.load %445 : !llvm.ptr -> i32
          %465 = arith.constant 2 : i32
          %466 = arith.cmpi eq, %464, %465 : i32
          cf.cond_br %466, ^bb72, ^bb73
          ^bb72:
            %467 = llvm.load %451 : !llvm.ptr -> i32
            %468 = arith.constant 1 : i32
            %469 = arith.addi %467, %468 : i32
            llvm.store %469, %451 : i32, !llvm.ptr
            cf.br ^bb74
          ^bb73:
            cf.br ^bb74
          ^bb74:
          %470 = llvm.load %451 : !llvm.ptr -> i32
          %471 = arith.constant 3 : i32
          %472 = arith.remsi %470, %471 : i32
          %473 = arith.constant 0 : i32
          %474 = arith.cmpi eq, %472, %473 : i32
          cf.cond_br %474, ^bb75, ^bb76
          ^bb75:
            %475 = arith.constant 0 : i32
            %476 = llvm.mlir.constant(1 : i64) : i64
            %477 = llvm.alloca %476 x i32 : (i64) -> !llvm.ptr
            llvm.store %475, %477 : i32, !llvm.ptr
            cf.br ^bb78
            ^bb78:
            %478 = llvm.load %477 : !llvm.ptr -> i32
            %479 = arith.constant 3 : i32
            %480 = arith.cmpi slt, %478, %479 : i32
            cf.cond_br %480, ^bb79, ^bb80
            ^bb79:
              %481 = arith.constant 1 : i32
              %483 = llvm.load %433 : !llvm.ptr -> i32
              %484 = llvm.load %439 : !llvm.ptr -> i32
              %485 = llvm.load %445 : !llvm.ptr -> i32
              %486 = llvm.load %477 : !llvm.ptr -> i32
              %482 = func.call @idx(%483, %484, %485, %486) : (i32, i32, i32, i32) -> i32
              %487 = arith.trunci %481 : i32 to i8
              %488 = arith.extsi %482 : i32 to i64
              %489 = llvm.getelementptr %426[%488] : (!llvm.ptr, i64) -> !llvm.ptr, i8
              llvm.store %487, %489 : i8, !llvm.ptr
              %490 = llvm.load %477 : !llvm.ptr -> i32
              %491 = arith.constant 1 : i32
              %492 = arith.addi %490, %491 : i32
              llvm.store %492, %477 : i32, !llvm.ptr
              cf.br ^bb78
            ^bb80:
            cf.br ^bb77
          ^bb76:
            cf.br ^bb77
          ^bb77:
          %493 = llvm.load %445 : !llvm.ptr -> i32
          %494 = arith.constant 1 : i32
          %495 = arith.addi %493, %494 : i32
          llvm.store %495, %445 : i32, !llvm.ptr
          cf.br ^bb63
        ^bb65:
        %496 = llvm.load %439 : !llvm.ptr -> i32
        %497 = arith.constant 1 : i32
        %498 = arith.addi %496, %497 : i32
        llvm.store %498, %439 : i32, !llvm.ptr
        cf.br ^bb60
      ^bb62:
      %499 = llvm.load %433 : !llvm.ptr -> i32
      %500 = arith.constant 1 : i32
      %501 = arith.addi %499, %500 : i32
      llvm.store %501, %433 : i32, !llvm.ptr
      cf.br ^bb57
    ^bb59:
    %503 = llvm.mlir.addressof @N : !llvm.ptr
    %504 = llvm.load %503 : !llvm.ptr -> i64
    %505 = arith.constant 8 : i32
    %506 = arith.extsi %505 : i32 to i64
    %502 = func.call @calloc(%504, %506) : (i64, i64) -> !llvm.ptr
    %508 = llvm.mlir.addressof @N : !llvm.ptr
    %509 = llvm.load %508 : !llvm.ptr -> i64
    %510 = arith.constant 8 : i32
    %511 = arith.extsi %510 : i32 to i64
    %507 = func.call @calloc(%509, %511) : (i64, i64) -> !llvm.ptr
    %512 = arith.constant 1 : i32
    %514 = arith.constant 1 : i32
    %515 = arith.constant 0 : i32
    %516 = arith.constant 0 : i32
    %517 = arith.constant 0 : i32
    %513 = func.call @idx(%514, %515, %516, %517) : (i32, i32, i32, i32) -> i32
    %518 = arith.extsi %512 : i32 to i64
    %519 = arith.extsi %513 : i32 to i64
    %520 = llvm.getelementptr %502[%519] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %518, %520 : i64, !llvm.ptr
    func.call @mat_vec(%507, %396, %502) : (!llvm.ptr, !llvm.ptr, !llvm.ptr) -> ()
    %523 = llvm.mlir.addressof @N : !llvm.ptr
    %524 = llvm.load %523 : !llvm.ptr -> i64
    %525 = arith.constant 8 : i32
    %527 = arith.extsi %525 : i32 to i64
    %526 = arith.muli %524, %527 : i64
    %522 = func.call @memcpy(%502, %507, %526) : (!llvm.ptr, !llvm.ptr, i64) -> !llvm.ptr
    %528 = arith.constant 1 : i32
    %530 = arith.extsi %528 : i32 to i64
    %529 = arith.cmpi sgt, %395, %530 : i64
    cf.cond_br %529, ^bb81, ^bb82
    ^bb81:
      %532 = llvm.mlir.addressof @N : !llvm.ptr
      %533 = llvm.load %532 : !llvm.ptr -> i64
      %534 = llvm.mlir.addressof @N : !llvm.ptr
      %535 = llvm.load %534 : !llvm.ptr -> i64
      %536 = arith.muli %533, %535 : i64
      %537 = arith.constant 8 : i32
      %538 = arith.extsi %537 : i32 to i64
      %531 = func.call @calloc(%536, %538) : (i64, i64) -> !llvm.ptr
      %540 = arith.constant 1 : i32
      %542 = arith.extsi %540 : i32 to i64
      %541 = arith.subi %395, %542 : i64
      func.call @mat_pow(%531, %404, %541) : (!llvm.ptr, !llvm.ptr, i64) -> ()
      func.call @mat_vec(%507, %531, %502) : (!llvm.ptr, !llvm.ptr, !llvm.ptr) -> ()
      %545 = llvm.mlir.addressof @N : !llvm.ptr
      %546 = llvm.load %545 : !llvm.ptr -> i64
      %547 = arith.constant 8 : i32
      %549 = arith.extsi %547 : i32 to i64
      %548 = arith.muli %546, %549 : i64
      %544 = func.call @memcpy(%502, %507, %548) : (!llvm.ptr, !llvm.ptr, i64) -> !llvm.ptr
      func.call @free(%531) : (!llvm.ptr) -> ()
      cf.br ^bb83
    ^bb82:
      cf.br ^bb83
    ^bb83:
    %551 = arith.constant 0 : i32
    %552 = arith.extsi %551 : i32 to i64
    %553 = llvm.mlir.constant(1 : i64) : i64
    %554 = llvm.alloca %553 x i64 : (i64) -> !llvm.ptr
    llvm.store %552, %554 : i64, !llvm.ptr
    %555 = arith.constant 0 : i32
    %556 = llvm.mlir.constant(1 : i64) : i64
    %557 = llvm.alloca %556 x i32 : (i64) -> !llvm.ptr
    llvm.store %555, %557 : i32, !llvm.ptr
    cf.br ^bb84
    ^bb84:
    %558 = llvm.load %557 : !llvm.ptr -> i32
    %559 = arith.constant 81 : i32
    %560 = arith.cmpi slt, %558, %559 : i32
    cf.cond_br %560, ^bb85, ^bb86
    ^bb85:
      %562 = llvm.load %557 : !llvm.ptr -> i32
      %563 = arith.extsi %562 : i32 to i64
      %564 = llvm.getelementptr %426[%563] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %561 = llvm.load %564 : !llvm.ptr -> i8
      %565 = arith.constant 0 : i32
      %567 = arith.extsi %561 : i8 to i32
      %566 = arith.cmpi ne, %567, %565 : i32
      cf.cond_br %566, ^bb87, ^bb88
      ^bb87:
        %568 = llvm.load %554 : !llvm.ptr -> i64
        %570 = llvm.load %557 : !llvm.ptr -> i32
        %571 = arith.extsi %570 : i32 to i64
        %572 = llvm.getelementptr %502[%571] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %569 = llvm.load %572 : !llvm.ptr -> i64
        %573 = arith.addi %568, %569 : i64
        llvm.store %573, %554 : i64, !llvm.ptr
        cf.br ^bb89
      ^bb88:
        cf.br ^bb89
      ^bb89:
      %574 = llvm.load %557 : !llvm.ptr -> i32
      %575 = arith.constant 1 : i32
      %576 = arith.addi %574, %575 : i32
      llvm.store %576, %557 : i32, !llvm.ptr
      cf.br ^bb84
    ^bb86:
    %577 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %578 = llvm.load %554 : !llvm.ptr -> i64
    %579 = llvm.mlir.addressof @MOD : !llvm.ptr
    %580 = llvm.load %579 : !llvm.ptr -> i64
    %581 = arith.remsi %578, %580 : i64
    %582 = llvm.call @printf(%577, %581) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    func.call @free(%396) : (!llvm.ptr) -> ()
    func.call @free(%404) : (!llvm.ptr) -> ()
    func.call @free(%426) : (!llvm.ptr) -> ()
    func.call @free(%502) : (!llvm.ptr) -> ()
    func.call @free(%507) : (!llvm.ptr) -> ()
    %588 = arith.constant 0 : i32
    func.return %588 : i32
  }
}