Problem 497

Drunken Tower of Hanoi — sum E(n,10^n,3^n,6^n,9^n) last 9 digits.

Answer684901360
Output684901360
StatusPASS
Native helperno
Runtime0 ms
Peak memory1104 KB
Time complexityO(n^4) (estimated)
Space complexityO(n) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^4)O(n)
Space complexityO(n)O(n)
ApproachFlow solutionBig-integer arithmetic
VerdictSuboptimal

Flow source

# Project Euler 497
# Drunken Tower of Hanoi — sum E(n,10^n,3^n,6^n,9^n) last 9 digits.

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

const MOD: i64 = 1000000000
const LIMIT: i64 = 10000

# Flattened dp[fr][dst][st][edge]
# Edges: (0,1),(0,2),(1,0),(1,2),(2,0),(2,1)

function edge_idx(u: i32, v: i32) -> i32 {
    if u == 0 {
        if v == 1 { return 0 }
        return 1
    }
    if u == 1 {
        if v == 0 { return 2 }
        return 3
    }
    if v == 0 { return 4 }
    return 5
}

function dp_idx(fr: i32, dst: i32, st: i32, e: i32) -> i64 {
    return ((((fr * 3 + dst) * 3 + st) * 6 + e) as i64)
}

function dist_lt(i: i64, j: i64) -> i64 {
    let mut a: i64 = (j - i) % MOD
    if a < 0 { a = a + MOD }
    let mut b: i64 = (j + i - 2) % MOD
    if b < 0 { b = b + MOD }
    return ((a as i128) * (b as i128) % (MOD as i128)) as i64
}

function dist_gt(i: i64, j: i64, k: i64) -> i64 {
    let mut a: i64 = (i - j) % MOD
    if a < 0 { a = a + MOD }
    let mut b: i64 = (2 * k - i - j) % MOD
    if b < 0 { b = b + MOD }
    return ((a as i128) * (b as i128) % (MOD as i128)) as i64
}

function init_counts(dp: ptr<i64>) -> void {
    let mut fr: i32 = 0
    while fr < 3 {
        let mut dst: i32 = 0
        while dst < 3 {
            if fr != dst {
                let mut st: i32 = 0
                while st < 3 {
                    let mut e: i32 = 0
                    while e < 6 {
                        dp[dp_idx(fr, dst, st, e)] = 0
                        e = e + 1
                    }
                    if st != fr {
                        let ei: i32 = edge_idx(st, fr)
                        dp[dp_idx(fr, dst, st, ei)] = dp[dp_idx(fr, dst, st, ei)] + 1
                    }
                    let ej: i32 = edge_idx(fr, dst)
                    dp[dp_idx(fr, dst, st, ej)] = dp[dp_idx(fr, dst, st, ej)] + 1
                    st = st + 1
                }
            }
            dst = dst + 1
        }
        fr = fr + 1
    }
}

function step_counts(dp: ptr<i64>, newdp: ptr<i64>) -> void {
    let mut fr: i32 = 0
    while fr < 3 {
        let mut dst: i32 = 0
        while dst < 3 {
            if fr != dst {
                let aux: i32 = 3 - fr - dst
                let mut st: i32 = 0
                while st < 3 {
                    let mut e: i32 = 0
                    while e < 6 {
                        let v1: i64 = dp[dp_idx(fr, aux, st, e)]
                        let v2: i64 = dp[dp_idx(aux, dst, dst, e)]
                        newdp[dp_idx(fr, dst, st, e)] = (v1 + v2) % MOD
                        e = e + 1
                    }
                    let e1: i32 = edge_idx(aux, fr)
                    let e2: i32 = edge_idx(fr, dst)
                    newdp[dp_idx(fr, dst, st, e1)] = (newdp[dp_idx(fr, dst, st, e1)] + 1) % MOD
                    newdp[dp_idx(fr, dst, st, e2)] = (newdp[dp_idx(fr, dst, st, e2)] + 1) % MOD
                    st = st + 1
                }
            }
            dst = dst + 1
        }
        fr = fr + 1
    }
}

function main() -> i32 {
    let sz: i64 = 3 * 3 * 3 * 6
    let dp: ptr<i64> = calloc(sz, 8)
    let newdp: ptr<i64> = calloc(sz, 8)
    if dp == null || newdp == null { return 1 }
    init_counts(dp)

    let mut a: i64 = 1
    let mut b: i64 = 1
    let mut c: i64 = 1
    let mut k: i64 = 1
    let mut total: i64 = 0
    let mut n: i64 = 1
    while n <= LIMIT {
        a = (a * 3) % MOD
        b = (b * 6) % MOD
        c = (c * 9) % MOD
        k = (k * 10) % MOD

        if n > 1 {
            step_counts(dp, newdp)
            let mut i: i64 = 0
            while i < sz {
                dp[i] = newdp[i]
                i = i + 1
            }
        }

        let d01: i64 = dist_lt(a, b)
        let d02: i64 = dist_lt(a, c)
        let d10: i64 = dist_gt(b, a, k)
        let d12: i64 = dist_lt(b, c)
        let d20: i64 = dist_gt(c, a, k)
        let d21: i64 = dist_gt(c, b, k)

        let mut e: i128 = 0
        e = e + (dp[dp_idx(0, 2, 1, 0)] as i128) * (d01 as i128)
        e = e + (dp[dp_idx(0, 2, 1, 1)] as i128) * (d02 as i128)
        e = e + (dp[dp_idx(0, 2, 1, 2)] as i128) * (d10 as i128)
        e = e + (dp[dp_idx(0, 2, 1, 3)] as i128) * (d12 as i128)
        e = e + (dp[dp_idx(0, 2, 1, 4)] as i128) * (d20 as i128)
        e = e + (dp[dp_idx(0, 2, 1, 5)] as i128) * (d21 as i128)
        total = ((total as i128 + e) % (MOD as i128)) as i64
        n = n + 1
    }

    printf("%lld\n", total)
    free(newdp)
    free(dp)
    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 edge_idx_i32_i32(int32_t u, int32_t v);
int64_t dp_idx_i32_i32_i32_i32(int32_t fr, int32_t dst, int32_t st, int32_t e);
int64_t dist_lt_i64_i64(int64_t i, int64_t j);
int64_t dist_gt_i64_i64_i64(int64_t i, int64_t j, int64_t k);
void init_counts_ptr_i64(int64_t* dp);
void step_counts_ptr_i64_ptr_i64(int64_t* dp, int64_t* newdp);
int32_t main(void);

static const int64_t MOD = 1000000000;
static const int64_t LIMIT = 10000;



int32_t edge_idx_i32_i32(int32_t u, int32_t v) {
    if (u == 0) {
        if (v == 1) {
            return 0;
        }
        return 1;
    }
    if (u == 1) {
        if (v == 0) {
            return 2;
        }
        return 3;
    }
    if (v == 0) {
        return 4;
    }
    return 5;
}

int64_t dp_idx_i32_i32_i32_i32(int32_t fr, int32_t dst, int32_t st, int32_t e) {
    return ((int64_t)(((((((fr * 3) + dst) * 3) + st) * 6) + e)));
}

int64_t dist_lt_i64_i64(int64_t i, int64_t j) {
    int64_t a = FLOW_CHECKED_MOD(((j - i)), (MOD));
    if (a < 0) {
        a = (a + MOD);
    }
    int64_t b = FLOW_CHECKED_MOD((((j + i) - 2)), (MOD));
    if (b < 0) {
        b = (b + MOD);
    }
    return ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(a)) * ((__int128)(b)))), (((__int128)(MOD))))));
}

int64_t dist_gt_i64_i64_i64(int64_t i, int64_t j, int64_t k) {
    int64_t a = FLOW_CHECKED_MOD(((i - j)), (MOD));
    if (a < 0) {
        a = (a + MOD);
    }
    int64_t b = FLOW_CHECKED_MOD(((((2 * k) - i) - j)), (MOD));
    if (b < 0) {
        b = (b + MOD);
    }
    return ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(a)) * ((__int128)(b)))), (((__int128)(MOD))))));
}

void init_counts_ptr_i64(int64_t* dp) {
    int32_t fr = 0;
    while (fr < 3) {
        int32_t dst = 0;
        while (dst < 3) {
            if (fr != dst) {
                int32_t st = 0;
                while (st < 3) {
                    int32_t e = 0;
                    while (e < 6) {
                        dp[dp_idx_i32_i32_i32_i32(fr, dst, st, e)] = 0;
                        e = (e + 1);
                    }
                    if (st != fr) {
                        int32_t ei = edge_idx_i32_i32(st, fr);
                        dp[dp_idx_i32_i32_i32_i32(fr, dst, st, ei)] = (dp[dp_idx_i32_i32_i32_i32(fr, dst, st, ei)] + 1);
                    }
                    int32_t ej = edge_idx_i32_i32(fr, dst);
                    dp[dp_idx_i32_i32_i32_i32(fr, dst, st, ej)] = (dp[dp_idx_i32_i32_i32_i32(fr, dst, st, ej)] + 1);
                    st = (st + 1);
                }
            }
            dst = (dst + 1);
        }
        fr = (fr + 1);
    }
}

void step_counts_ptr_i64_ptr_i64(int64_t* dp, int64_t* newdp) {
    int32_t fr = 0;
    while (fr < 3) {
        int32_t dst = 0;
        while (dst < 3) {
            if (fr != dst) {
                int32_t aux = ((3 - fr) - dst);
                int32_t st = 0;
                while (st < 3) {
                    int32_t e = 0;
                    while (e < 6) {
                        int64_t v1 = dp[dp_idx_i32_i32_i32_i32(fr, aux, st, e)];
                        int64_t v2 = dp[dp_idx_i32_i32_i32_i32(aux, dst, dst, e)];
                        newdp[dp_idx_i32_i32_i32_i32(fr, dst, st, e)] = FLOW_CHECKED_MOD(((v1 + v2)), (MOD));
                        e = (e + 1);
                    }
                    int32_t e1 = edge_idx_i32_i32(aux, fr);
                    int32_t e2 = edge_idx_i32_i32(fr, dst);
                    newdp[dp_idx_i32_i32_i32_i32(fr, dst, st, e1)] = FLOW_CHECKED_MOD(((newdp[dp_idx_i32_i32_i32_i32(fr, dst, st, e1)] + 1)), (MOD));
                    newdp[dp_idx_i32_i32_i32_i32(fr, dst, st, e2)] = FLOW_CHECKED_MOD(((newdp[dp_idx_i32_i32_i32_i32(fr, dst, st, e2)] + 1)), (MOD));
                    st = (st + 1);
                }
            }
            dst = (dst + 1);
        }
        fr = (fr + 1);
    }
}

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