Problem 082

Minimal path sum: start any left cell, end any right cell; move up/down/right.

Answer260324
Output260324
StatusPASS
Native helperno
Runtime0 ms
Peak memory1200 KB
Time complexityO(n^2) (estimated)
Space complexityO(n) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^2)O(n^2)
Space complexityO(n)O(n^2)
ApproachFlow solutionBottom-up DP
VerdictOptimal

Flow source

# Project Euler 082
# Minimal path sum: start any left cell, end any right cell; move up/down/right.

extern {
    function fopen(path: string, mode: string) -> ptr<void>
    function fgetc(f: ptr<void>) -> i32
    function fclose(f: ptr<void>) -> i32
    function calloc(n: i64, size: i64) -> ptr<void>
    function free(p: ptr<void>) -> void
    function memcpy(dst: ptr<void>, src: ptr<void>, n: i64) -> ptr<void>
}

function read_int(f: ptr<void>) -> i32 {
    let mut c: i32 = fgetc(f)
    while c >= 0 && (c < 48 || c > 57) {
        c = fgetc(f)
    }
    if c < 0 { return -1 }
    let mut v: i32 = 0
    while c >= 48 && c <= 57 {
        v = v * 10 + (c - 48)
        c = fgetc(f)
    }
    return v
}

function min2(a: i64, b: i64) -> i64 {
    if a < b { return a }
    return b
}

function main() -> i32 {
    let n: i32 = 80
    let a: ptr<i64> = calloc((n * n) as i64, 8)
    let col: ptr<i64> = calloc(n as i64, 8)
    let prev: ptr<i64> = calloc(n as i64, 8)
    if a == null || col == null || prev == null { return 1 }

    let f: ptr<void> = fopen("data/p082.txt", "r")
    if f == null {
        printf("failed to read data/p082.txt\n")
        return 1
    }
    let mut i: i32 = 0
    while i < n * n {
        a[i] = read_int(f) as i64
        i = i + 1
    }
    fclose(f)

    # prev[r] = min cost to reach (r,0) from left column start = a[r][0]
    let mut r: i32 = 0
    while r < n {
        prev[r] = a[r * n]
        r = r + 1
    }

    let mut c: i32 = 1
    while c < n {
        # downward pass
        col[0] = prev[0] + a[0 * n + c]
        r = 1
        while r < n {
            col[r] = a[r * n + c] + min2(prev[r], col[r - 1])
            r = r + 1
        }
        # upward pass
        r = n - 2
        while r >= 0 {
            col[r] = min2(col[r], col[r + 1] + a[r * n + c])
            r = r - 1
        }
        memcpy(prev, col, (n as i64) * 8)
        c = c + 1
    }

    let mut best: i64 = prev[0]
    r = 1
    while r < n {
        best = min2(best, prev[r])
        r = r + 1
    }
    printf("%lld\n", best)
    free(a)
    free(col)
    free(prev)
    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 read_int_ptr_void(void* f);
int64_t min2_i64_i64(int64_t a, int64_t b);
int32_t main(void);







int32_t read_int_ptr_void(void* f) {
    int32_t c = fgetc(f);
    while ((c >= 0 && (c < 48 || c > 57))) {
        c = fgetc(f);
    }
    if (c < 0) {
        return (-1);
    }
    int32_t v = 0;
    while ((c >= 48 && c <= 57)) {
        v = ((v * 10) + (c - 48));
        c = fgetc(f);
    }
    return v;
}

int64_t min2_i64_i64(int64_t a, int64_t b) {
    if (a < b) {
        return a;
    }
    return b;
}

int32_t main(void) {
    int32_t n = 80;
    int64_t* a = (int64_t*)(calloc(((int64_t)((n * n))), 8));
    int64_t* col = (int64_t*)(calloc(((int64_t)(n)), 8));
    int64_t* prev = (int64_t*)(calloc(((int64_t)(n)), 8));
    if (((a == NULL || col == NULL) || prev == NULL)) {
        return 1;
    }
    void* f = (void*)(fopen("data/p082.txt", "r"));
    if (f == NULL) {
        printf("failed to read data/p082.txt\n");
        return 1;
    }
    int32_t i = 0;
    while (i < (n * n)) {
        a[i] = ((int64_t)(read_int_ptr_void(f)));
        i = (i + 1);
    }
    fclose(f);
    int32_t r = 0;
    while (r < n) {
        prev[r] = a[(r * n)];
        r = (r + 1);
    }
    int32_t c = 1;
    while (c < n) {
        col[0] = (prev[0] + a[((0 * n) + c)]);
        r = 1;
        while (r < n) {
            col[r] = (a[((r * n) + c)] + min2_i64_i64(prev[r], col[(r - 1)]));
            r = (r + 1);
        }
        r = (n - 2);
        while (r >= 0) {
            col[r] = min2_i64_i64(col[r], (col[(r + 1)] + a[((r * n) + c)]));
            r = (r - 1);
        }
        memcpy(prev, col, (((int64_t)(n)) * 8));
        c = (c + 1);
    }
    int64_t best = prev[0];
    r = 1;
    while (r < n) {
        best = min2_i64_i64(best, prev[r]);
        r = (r + 1);
    }
    printf("%lld\n", best);
    free(a);
    free(col);
    free(prev);
    return 0;
}

Generated MLIR

module {
  llvm.func @printf(!llvm.ptr, ...) -> i32
  llvm.mlir.global internal constant @str_0("data/p082.txt\00") {addr_space = 0 : i32} : !llvm.array<14 x i8>
  llvm.mlir.global internal constant @str_1("r\00") {addr_space = 0 : i32} : !llvm.array<2 x i8>
  llvm.mlir.global internal constant @str_2("failed to read data/p082.txt\n\00") {addr_space = 0 : i32} : !llvm.array<30 x i8>
  llvm.mlir.global internal constant @str_3("%lld\n\00") {addr_space = 0 : i32} : !llvm.array<6 x i8>
  func.func private @fopen(!llvm.ptr, !llvm.ptr) -> !llvm.ptr
  func.func private @fgetc(!llvm.ptr) -> i32
  func.func private @fclose(!llvm.ptr) -> i32
  func.func private @calloc(i64, i64) -> !llvm.ptr
  func.func private @free(!llvm.ptr) -> ()
  func.func private @memcpy(!llvm.ptr, !llvm.ptr, i64) -> !llvm.ptr
  func.func @read_int(%arg0: !llvm.ptr) -> i32 {
    %0 = func.call @fgetc(%arg0) : (!llvm.ptr) -> i32
    %1 = llvm.mlir.constant(1 : i64) : i64
    %2 = llvm.alloca %1 x i32 : (i64) -> !llvm.ptr
    llvm.store %0, %2 : i32, !llvm.ptr
    cf.br ^bb0
    ^bb0:
    %3 = llvm.load %2 : !llvm.ptr -> i32
    %4 = arith.constant 0 : i32
    %5 = arith.cmpi sge, %3, %4 : i32
    %6 = scf.if %5 -> (i1) {
      %7 = llvm.load %2 : !llvm.ptr -> i32
      %8 = arith.constant 48 : i32
      %9 = arith.cmpi slt, %7, %8 : i32
      %10 = scf.if %9 -> (i1) {
        %11 = arith.constant true
        scf.yield %11 : i1
      } else {
        %12 = llvm.load %2 : !llvm.ptr -> i32
        %13 = arith.constant 57 : i32
        %14 = arith.cmpi sgt, %12, %13 : i32
        scf.yield %14 : i1
      }
      scf.yield %10 : i1
    } else {
      %15 = arith.constant false
      scf.yield %15 : i1
    }
    cf.cond_br %6, ^bb1, ^bb2
    ^bb1:
      %16 = func.call @fgetc(%arg0) : (!llvm.ptr) -> i32
      llvm.store %16, %2 : i32, !llvm.ptr
      cf.br ^bb0
    ^bb2:
    %17 = llvm.load %2 : !llvm.ptr -> i32
    %18 = arith.constant 0 : i32
    %19 = arith.cmpi slt, %17, %18 : i32
    cf.cond_br %19, ^bb3, ^bb4
    ^bb3:
      %20 = arith.constant 1 : i32
      %22 = arith.constant 0 : i32
      %21 = arith.subi %22, %20 : i32
      func.return %21 : i32
    ^bb4:
      cf.br ^bb5
    ^bb5:
    %23 = arith.constant 0 : i32
    %24 = llvm.mlir.constant(1 : i64) : i64
    %25 = llvm.alloca %24 x i32 : (i64) -> !llvm.ptr
    llvm.store %23, %25 : i32, !llvm.ptr
    cf.br ^bb6
    ^bb6:
    %26 = llvm.load %2 : !llvm.ptr -> i32
    %27 = arith.constant 48 : i32
    %28 = arith.cmpi sge, %26, %27 : i32
    %29 = scf.if %28 -> (i1) {
      %30 = llvm.load %2 : !llvm.ptr -> i32
      %31 = arith.constant 57 : i32
      %32 = arith.cmpi sle, %30, %31 : i32
      scf.yield %32 : i1
    } else {
      %33 = arith.constant false
      scf.yield %33 : i1
    }
    cf.cond_br %29, ^bb7, ^bb8
    ^bb7:
      %34 = llvm.load %25 : !llvm.ptr -> i32
      %35 = arith.constant 10 : i32
      %36 = arith.muli %34, %35 : i32
      %37 = llvm.load %2 : !llvm.ptr -> i32
      %38 = arith.constant 48 : i32
      %39 = arith.subi %37, %38 : i32
      %40 = arith.addi %36, %39 : i32
      llvm.store %40, %25 : i32, !llvm.ptr
      %41 = func.call @fgetc(%arg0) : (!llvm.ptr) -> i32
      llvm.store %41, %2 : i32, !llvm.ptr
      cf.br ^bb6
    ^bb8:
    %42 = llvm.load %25 : !llvm.ptr -> i32
    func.return %42 : i32
  }
  func.func @min2(%arg0: i64, %arg1: i64) -> i64 {
    %43 = arith.cmpi slt, %arg0, %arg1 : i64
    cf.cond_br %43, ^bb9, ^bb10
    ^bb9:
      func.return %arg0 : i64
    ^bb10:
      cf.br ^bb11
    ^bb11:
    func.return %arg1 : i64
  }
  func.func @main() -> i32 {
    %44 = arith.constant 80 : i32
    %46 = arith.muli %44, %44 : i32
    %47 = arith.extsi %46 : i32 to i64
    %48 = arith.constant 8 : i32
    %49 = arith.extsi %48 : i32 to i64
    %45 = func.call @calloc(%47, %49) : (i64, i64) -> !llvm.ptr
    %51 = arith.extsi %44 : i32 to i64
    %52 = arith.constant 8 : i32
    %53 = arith.extsi %52 : i32 to i64
    %50 = func.call @calloc(%51, %53) : (i64, i64) -> !llvm.ptr
    %55 = arith.extsi %44 : i32 to i64
    %56 = arith.constant 8 : i32
    %57 = arith.extsi %56 : i32 to i64
    %54 = func.call @calloc(%55, %57) : (i64, i64) -> !llvm.ptr
    %58 = llvm.mlir.zero : !llvm.ptr
    %59 = llvm.icmp "eq" %45, %58 : !llvm.ptr
    %60 = scf.if %59 -> (i1) {
      %61 = arith.constant true
      scf.yield %61 : i1
    } else {
      %62 = llvm.mlir.zero : !llvm.ptr
      %63 = llvm.icmp "eq" %50, %62 : !llvm.ptr
      scf.yield %63 : i1
    }
    %64 = scf.if %60 -> (i1) {
      %65 = arith.constant true
      scf.yield %65 : i1
    } else {
      %66 = llvm.mlir.zero : !llvm.ptr
      %67 = llvm.icmp "eq" %54, %66 : !llvm.ptr
      scf.yield %67 : i1
    }
    cf.cond_br %64, ^bb12, ^bb13
    ^bb12:
      %68 = arith.constant 1 : i32
      func.return %68 : i32
    ^bb13:
      cf.br ^bb14
    ^bb14:
    %70 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %71 = llvm.mlir.addressof @str_1 : !llvm.ptr
    %69 = func.call @fopen(%70, %71) : (!llvm.ptr, !llvm.ptr) -> !llvm.ptr
    %72 = llvm.mlir.zero : !llvm.ptr
    %73 = llvm.icmp "eq" %69, %72 : !llvm.ptr
    cf.cond_br %73, ^bb15, ^bb16
    ^bb15:
      %74 = llvm.mlir.addressof @str_2 : !llvm.ptr
      %75 = llvm.call @printf(%74) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr) -> i32
      %76 = arith.constant 1 : i32
      func.return %76 : i32
    ^bb16:
      cf.br ^bb17
    ^bb17:
    %77 = arith.constant 0 : i32
    %78 = llvm.mlir.constant(1 : i64) : i64
    %79 = llvm.alloca %78 x i32 : (i64) -> !llvm.ptr
    llvm.store %77, %79 : i32, !llvm.ptr
    cf.br ^bb18
    ^bb18:
    %80 = llvm.load %79 : !llvm.ptr -> i32
    %81 = arith.muli %44, %44 : i32
    %82 = arith.cmpi slt, %80, %81 : i32
    cf.cond_br %82, ^bb19, ^bb20
    ^bb19:
      %83 = func.call @read_int(%69) : (!llvm.ptr) -> i32
      %84 = arith.extsi %83 : i32 to i64
      %85 = llvm.load %79 : !llvm.ptr -> i32
      %86 = arith.extsi %85 : i32 to i64
      %87 = llvm.getelementptr %45[%86] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %84, %87 : i64, !llvm.ptr
      %88 = llvm.load %79 : !llvm.ptr -> i32
      %89 = arith.constant 1 : i32
      %90 = arith.addi %88, %89 : i32
      llvm.store %90, %79 : i32, !llvm.ptr
      cf.br ^bb18
    ^bb20:
    %91 = func.call @fclose(%69) : (!llvm.ptr) -> i32
    %92 = arith.constant 0 : i32
    %93 = llvm.mlir.constant(1 : i64) : i64
    %94 = llvm.alloca %93 x i32 : (i64) -> !llvm.ptr
    llvm.store %92, %94 : i32, !llvm.ptr
    cf.br ^bb21
    ^bb21:
    %95 = llvm.load %94 : !llvm.ptr -> i32
    %96 = arith.cmpi slt, %95, %44 : i32
    cf.cond_br %96, ^bb22, ^bb23
    ^bb22:
      %98 = llvm.load %94 : !llvm.ptr -> i32
      %99 = arith.muli %98, %44 : i32
      %100 = arith.extsi %99 : i32 to i64
      %101 = llvm.getelementptr %45[%100] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %97 = llvm.load %101 : !llvm.ptr -> i64
      %102 = llvm.load %94 : !llvm.ptr -> i32
      %103 = arith.extsi %102 : i32 to i64
      %104 = llvm.getelementptr %54[%103] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %97, %104 : i64, !llvm.ptr
      %105 = llvm.load %94 : !llvm.ptr -> i32
      %106 = arith.constant 1 : i32
      %107 = arith.addi %105, %106 : i32
      llvm.store %107, %94 : i32, !llvm.ptr
      cf.br ^bb21
    ^bb23:
    %108 = arith.constant 1 : i32
    %109 = llvm.mlir.constant(1 : i64) : i64
    %110 = llvm.alloca %109 x i32 : (i64) -> !llvm.ptr
    llvm.store %108, %110 : i32, !llvm.ptr
    cf.br ^bb24
    ^bb24:
    %111 = llvm.load %110 : !llvm.ptr -> i32
    %112 = arith.cmpi slt, %111, %44 : i32
    cf.cond_br %112, ^bb25, ^bb26
    ^bb25:
      %114 = arith.constant 0 : i32
      %115 = arith.extsi %114 : i32 to i64
      %116 = llvm.getelementptr %54[%115] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %113 = llvm.load %116 : !llvm.ptr -> i64
      %118 = arith.constant 0 : i32
      %119 = arith.muli %118, %44 : i32
      %120 = llvm.load %110 : !llvm.ptr -> i32
      %121 = arith.addi %119, %120 : i32
      %122 = arith.extsi %121 : i32 to i64
      %123 = llvm.getelementptr %45[%122] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %117 = llvm.load %123 : !llvm.ptr -> i64
      %124 = arith.addi %113, %117 : i64
      %125 = arith.constant 0 : i32
      %126 = arith.extsi %125 : i32 to i64
      %127 = llvm.getelementptr %50[%126] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %124, %127 : i64, !llvm.ptr
      %128 = arith.constant 1 : i32
      llvm.store %128, %94 : i32, !llvm.ptr
      cf.br ^bb27
      ^bb27:
      %129 = llvm.load %94 : !llvm.ptr -> i32
      %130 = arith.cmpi slt, %129, %44 : i32
      cf.cond_br %130, ^bb28, ^bb29
      ^bb28:
        %132 = llvm.load %94 : !llvm.ptr -> i32
        %133 = arith.muli %132, %44 : i32
        %134 = llvm.load %110 : !llvm.ptr -> i32
        %135 = arith.addi %133, %134 : i32
        %136 = arith.extsi %135 : i32 to i64
        %137 = llvm.getelementptr %45[%136] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %131 = llvm.load %137 : !llvm.ptr -> i64
        %140 = llvm.load %94 : !llvm.ptr -> i32
        %141 = arith.extsi %140 : i32 to i64
        %142 = llvm.getelementptr %54[%141] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %139 = llvm.load %142 : !llvm.ptr -> i64
        %144 = llvm.load %94 : !llvm.ptr -> i32
        %145 = arith.constant 1 : i32
        %146 = arith.subi %144, %145 : i32
        %147 = arith.extsi %146 : i32 to i64
        %148 = llvm.getelementptr %50[%147] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %143 = llvm.load %148 : !llvm.ptr -> i64
        %138 = func.call @min2(%139, %143) : (i64, i64) -> i64
        %149 = arith.addi %131, %138 : i64
        %150 = llvm.load %94 : !llvm.ptr -> i32
        %151 = arith.extsi %150 : i32 to i64
        %152 = llvm.getelementptr %50[%151] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %149, %152 : i64, !llvm.ptr
        %153 = llvm.load %94 : !llvm.ptr -> i32
        %154 = arith.constant 1 : i32
        %155 = arith.addi %153, %154 : i32
        llvm.store %155, %94 : i32, !llvm.ptr
        cf.br ^bb27
      ^bb29:
      %156 = arith.constant 2 : i32
      %157 = arith.subi %44, %156 : i32
      llvm.store %157, %94 : i32, !llvm.ptr
      cf.br ^bb30
      ^bb30:
      %158 = llvm.load %94 : !llvm.ptr -> i32
      %159 = arith.constant 0 : i32
      %160 = arith.cmpi sge, %158, %159 : i32
      cf.cond_br %160, ^bb31, ^bb32
      ^bb31:
        %163 = llvm.load %94 : !llvm.ptr -> i32
        %164 = arith.extsi %163 : i32 to i64
        %165 = llvm.getelementptr %50[%164] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %162 = llvm.load %165 : !llvm.ptr -> i64
        %167 = llvm.load %94 : !llvm.ptr -> i32
        %168 = arith.constant 1 : i32
        %169 = arith.addi %167, %168 : i32
        %170 = arith.extsi %169 : i32 to i64
        %171 = llvm.getelementptr %50[%170] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %166 = llvm.load %171 : !llvm.ptr -> i64
        %173 = llvm.load %94 : !llvm.ptr -> i32
        %174 = arith.muli %173, %44 : i32
        %175 = llvm.load %110 : !llvm.ptr -> i32
        %176 = arith.addi %174, %175 : i32
        %177 = arith.extsi %176 : i32 to i64
        %178 = llvm.getelementptr %45[%177] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %172 = llvm.load %178 : !llvm.ptr -> i64
        %179 = arith.addi %166, %172 : i64
        %161 = func.call @min2(%162, %179) : (i64, i64) -> i64
        %180 = llvm.load %94 : !llvm.ptr -> i32
        %181 = arith.extsi %180 : i32 to i64
        %182 = llvm.getelementptr %50[%181] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %161, %182 : i64, !llvm.ptr
        %183 = llvm.load %94 : !llvm.ptr -> i32
        %184 = arith.constant 1 : i32
        %185 = arith.subi %183, %184 : i32
        llvm.store %185, %94 : i32, !llvm.ptr
        cf.br ^bb30
      ^bb32:
      %187 = arith.extsi %44 : i32 to i64
      %188 = arith.constant 8 : i32
      %190 = arith.extsi %188 : i32 to i64
      %189 = arith.muli %187, %190 : i64
      %186 = func.call @memcpy(%54, %50, %189) : (!llvm.ptr, !llvm.ptr, i64) -> !llvm.ptr
      %191 = llvm.load %110 : !llvm.ptr -> i32
      %192 = arith.constant 1 : i32
      %193 = arith.addi %191, %192 : i32
      llvm.store %193, %110 : i32, !llvm.ptr
      cf.br ^bb24
    ^bb26:
    %195 = arith.constant 0 : i32
    %196 = arith.extsi %195 : i32 to i64
    %197 = llvm.getelementptr %54[%196] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %194 = llvm.load %197 : !llvm.ptr -> i64
    %198 = llvm.mlir.constant(1 : i64) : i64
    %199 = llvm.alloca %198 x i64 : (i64) -> !llvm.ptr
    llvm.store %194, %199 : i64, !llvm.ptr
    %200 = arith.constant 1 : i32
    llvm.store %200, %94 : i32, !llvm.ptr
    cf.br ^bb33
    ^bb33:
    %201 = llvm.load %94 : !llvm.ptr -> i32
    %202 = arith.cmpi slt, %201, %44 : i32
    cf.cond_br %202, ^bb34, ^bb35
    ^bb34:
      %204 = llvm.load %199 : !llvm.ptr -> i64
      %206 = llvm.load %94 : !llvm.ptr -> i32
      %207 = arith.extsi %206 : i32 to i64
      %208 = llvm.getelementptr %54[%207] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %205 = llvm.load %208 : !llvm.ptr -> i64
      %203 = func.call @min2(%204, %205) : (i64, i64) -> i64
      llvm.store %203, %199 : i64, !llvm.ptr
      %209 = llvm.load %94 : !llvm.ptr -> i32
      %210 = arith.constant 1 : i32
      %211 = arith.addi %209, %210 : i32
      llvm.store %211, %94 : i32, !llvm.ptr
      cf.br ^bb33
    ^bb35:
    %212 = llvm.mlir.addressof @str_3 : !llvm.ptr
    %213 = llvm.load %199 : !llvm.ptr -> i64
    %214 = llvm.call @printf(%212, %213) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    func.call @free(%45) : (!llvm.ptr) -> ()
    func.call @free(%50) : (!llvm.ptr) -> ()
    func.call @free(%54) : (!llvm.ptr) -> ()
    %218 = arith.constant 0 : i32
    func.return %218 : i32
  }
}