Problem 213

Expected empty squares after 50 flea jumps on 30x30.

Answer330.721154
Output330.721154
StatusPASS
Native helperno
Runtime10 ms
Peak memory1088 KB
Time complexityO(n^5) (estimated)
Space complexityO(n) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^5)O(n * s^2)
Space complexityO(n)O(s^2)
ApproachFlow solutionMarkov chain or DP over states
VerdictUnknown

Flow source

# Project Euler 213
# Expected empty squares after 50 flea jumps on 30x30.

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

function idx(x: i32, y: i32, h: i32) -> i64 {
    return (x as i64) * (h as i64) + (y as i64)
}

function main() -> i32 {
    let W: i32 = 30
    let H: i32 = 30
    let R: i32 = 50
    let N: i64 = (W as i64) * (H as i64)
    let empty: ptr<f64> = calloc(N, 8)
    let cur: ptr<f64> = calloc(N, 8)
    let nxt: ptr<f64> = calloc(N, 8)
    if empty == null || cur == null || nxt == null { return 1 }
    let mut i: i64 = 0
    while i < N {
        empty[i] = 1.0
        i = i + 1
    }

    let max_x: i32 = W / 2
    let max_y: i32 = H / 2
    let mut sx: i32 = 0
    while sx < max_x {
        let mut sy: i32 = 0
        while sy < max_y {
            i = 0
            while i < N {
                cur[i] = 0.0
                i = i + 1
            }
            cur[idx(sx, sy, H)] = 1.0

            let mut r: i32 = 0
            while r < R {
                i = 0
                while i < N {
                    nxt[i] = 0.0
                    i = i + 1
                }
                let mut x: i32 = 0
                while x < W {
                    let mut y: i32 = 0
                    while y < H {
                        let p: f64 = cur[idx(x, y, H)]
                        if p != 0.0 {
                            let mut dirs: i32 = 4
                            if x == 0 || x == W - 1 { dirs = dirs - 1 }
                            if y == 0 || y == H - 1 { dirs = dirs - 1 }
                            let prob: f64 = p / (dirs as f64)
                            if x > 0 { nxt[idx(x - 1, y, H)] = nxt[idx(x - 1, y, H)] + prob }
                            if x < W - 1 { nxt[idx(x + 1, y, H)] = nxt[idx(x + 1, y, H)] + prob }
                            if y > 0 { nxt[idx(x, y - 1, H)] = nxt[idx(x, y - 1, H)] + prob }
                            if y < H - 1 { nxt[idx(x, y + 1, H)] = nxt[idx(x, y + 1, H)] + prob }
                        }
                        y = y + 1
                    }
                    x = x + 1
                }
                i = 0
                while i < N {
                    cur[i] = nxt[i]
                    i = i + 1
                }
                r = r + 1
            }

            let mut x2: i32 = 0
            while x2 < W {
                let mut y2: i32 = 0
                while y2 < H {
                    let e: i64 = idx(x2, y2, H)
                    empty[e] = empty[e] * (1.0 - cur[e])
                    empty[e] = empty[e] * (1.0 - cur[idx(W - 1 - x2, y2, H)])
                    empty[e] = empty[e] * (1.0 - cur[idx(x2, H - 1 - y2, H)])
                    empty[e] = empty[e] * (1.0 - cur[idx(W - 1 - x2, H - 1 - y2, H)])
                    y2 = y2 + 1
                }
                x2 = x2 + 1
            }
            sy = sy + 1
        }
        sx = sx + 1
    }

    let mut result: f64 = 0.0
    i = 0
    while i < N {
        result = result + empty[i]
        i = i + 1
    }
    printf("%.6f\n", result)
    free(empty); free(cur); free(nxt)
    return 0
}

Generated C

#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* Flow runtime helpers */
typedef struct flow_temp_node { struct flow_temp_node* next; } flow_temp_node;
static flow_temp_node* flow_temp_head = NULL;
static int flow_temp_atexit_set = 0;
__attribute__((unused)) static void flow_temp_free_all(void) {
    while (flow_temp_head) {
        flow_temp_node* n = flow_temp_head;
        flow_temp_head = n->next;
        free(n);
    }
}
__attribute__((unused)) static void* flow_temp_alloc(size_t nbytes) {
    flow_temp_node* node = (flow_temp_node*)malloc(sizeof(flow_temp_node) + nbytes);
    if (!node) return NULL;
    node->next = flow_temp_head;
    flow_temp_head = node;
    if (!flow_temp_atexit_set) {
        flow_temp_atexit_set = 1;
        atexit(flow_temp_free_all);
    }
    return (void*)(node + 1);
}
#ifndef FLOW_DIAG
#define FLOW_DIAG(msg) fprintf(stderr, "%s", (msg))
#endif
#ifndef FLOW_LOG
#define FLOW_LOG(fmt, ...) printf(fmt, __VA_ARGS__)
#endif
#ifndef FLOW_LOG_EMPTY
#define FLOW_LOG_EMPTY(fmt) printf(fmt)
#endif
static char* flow_strcat(const char* a, const char* b) {
    size_t la = strlen(a ? a : ""), lb = strlen(b ? b : "");
    char* r = (char*)flow_temp_alloc(la + lb + 1);
    if (!r) return NULL;
    if (la) memcpy(r, a, la);
    if (lb) memcpy(r + la, b, lb);
    r[la + lb] = '\0';
    return r;
}

#define __flow_in_arr(arr, val) __extension__ ({ \
    int _found = 0; \
    size_t _n = sizeof(arr)/sizeof((arr)[0]); \
    for (size_t _i = 0; _i < _n; _i++) { \
        if ((arr)[_i] == (val)) { _found = 1; break; } \
    } _found; })

/* Unified fault handler (MISRA #279) — override with -DFLOW_FAULT_HANDLER=fn */
#ifndef FLOW_FAULT_HANDLER
__attribute__((unused)) static inline void flow_fault_handler(const char* msg) {
    fprintf(stderr, "flow: %s\n", msg ? msg : "fault");
    abort();
#if defined(__GNUC__) || defined(__clang__)
    __builtin_unreachable();
#endif
}
#else
#define flow_fault_handler FLOW_FAULT_HANDLER
#endif
#define flow_div_by_zero_handler() flow_fault_handler("division by zero")
#define flow_shift_ub_handler() flow_fault_handler("invalid shift (amount out of range or left-shift of negative)")

#ifndef FLOW_CHECKED_DIV
#define FLOW_CHECKED_DIV(L, R) (((R) != 0) ? ((L) / (R)) : (flow_div_by_zero_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_MOD
#define FLOW_CHECKED_MOD(L, R) (((R) != 0) ? ((L) % (R)) : (flow_div_by_zero_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_SHL
#define FLOW_CHECKED_SHL(L, R) ((((R) >= 0) && ((unsigned long long)(R) < (sizeof(L) * 8ull)) && ((L) >= 0)) ? ((L) << (R)) : (flow_shift_ub_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_SHR
#define FLOW_CHECKED_SHR(L, R) ((((R) >= 0) && ((unsigned long long)(R) < (sizeof(L) * 8ull))) ? ((L) >> (R)) : (flow_shift_ub_handler(), (L) * 0))
#endif

#include <math.h>

void* _ui_state = NULL;

static inline float i32_to_f32(int32_t v) { return (float)v; }

/* Host stub for @gpu kernels (device codegen replaces this). */
static inline int32_t gpu_thread_id(void) { return 0; }

int64_t idx_i32_i32_i32(int32_t x, int32_t y, int32_t h);
int32_t main(void);



int64_t idx_i32_i32_i32(int32_t x, int32_t y, int32_t h) {
    return ((((int64_t)(x)) * ((int64_t)(h))) + ((int64_t)(y)));
}

int32_t main(void) {
    int32_t W = 30;
    int32_t H = 30;
    int32_t R = 50;
    int64_t N = (((int64_t)(W)) * ((int64_t)(H)));
    double* empty = (double*)(calloc(N, 8));
    double* cur = (double*)(calloc(N, 8));
    double* nxt = (double*)(calloc(N, 8));
    if (((empty == NULL || cur == NULL) || nxt == NULL)) {
        return 1;
    }
    int64_t i = 0;
    while (i < N) {
        empty[i] = 1.0;
        i = (i + 1);
    }
    int32_t max_x = FLOW_CHECKED_DIV((W), (2));
    int32_t max_y = FLOW_CHECKED_DIV((H), (2));
    int32_t sx = 0;
    while (sx < max_x) {
        int32_t sy = 0;
        while (sy < max_y) {
            i = 0;
            while (i < N) {
                cur[i] = 0.0;
                i = (i + 1);
            }
            cur[idx_i32_i32_i32(sx, sy, H)] = 1.0;
            int32_t r = 0;
            while (r < R) {
                i = 0;
                while (i < N) {
                    nxt[i] = 0.0;
                    i = (i + 1);
                }
                int32_t x = 0;
                while (x < W) {
                    int32_t y = 0;
                    while (y < H) {
                        double p = cur[idx_i32_i32_i32(x, y, H)];
                        if (p != 0.0) {
                            int32_t dirs = 4;
                            if ((x == 0 || x == (W - 1))) {
                                dirs = (dirs - 1);
                            }
                            if ((y == 0 || y == (H - 1))) {
                                dirs = (dirs - 1);
                            }
                            double prob = (p / ((double)(dirs)));
                            if (x > 0) {
                                nxt[idx_i32_i32_i32((x - 1), y, H)] = (nxt[idx_i32_i32_i32((x - 1), y, H)] + prob);
                            }
                            if (x < (W - 1)) {
                                nxt[idx_i32_i32_i32((x + 1), y, H)] = (nxt[idx_i32_i32_i32((x + 1), y, H)] + prob);
                            }
                            if (y > 0) {
                                nxt[idx_i32_i32_i32(x, (y - 1), H)] = (nxt[idx_i32_i32_i32(x, (y - 1), H)] + prob);
                            }
                            if (y < (H - 1)) {
                                nxt[idx_i32_i32_i32(x, (y + 1), H)] = (nxt[idx_i32_i32_i32(x, (y + 1), H)] + prob);
                            }
                        }
                        y = (y + 1);
                    }
                    x = (x + 1);
                }
                i = 0;
                while (i < N) {
                    cur[i] = nxt[i];
                    i = (i + 1);
                }
                r = (r + 1);
            }
            int32_t x2 = 0;
            while (x2 < W) {
                int32_t y2 = 0;
                while (y2 < H) {
                    int64_t e = idx_i32_i32_i32(x2, y2, H);
                    empty[e] = (empty[e] * (1.0 - cur[e]));
                    empty[e] = (empty[e] * (1.0 - cur[idx_i32_i32_i32(((W - 1) - x2), y2, H)]));
                    empty[e] = (empty[e] * (1.0 - cur[idx_i32_i32_i32(x2, ((H - 1) - y2), H)]));
                    empty[e] = (empty[e] * (1.0 - cur[idx_i32_i32_i32(((W - 1) - x2), ((H - 1) - y2), H)]));
                    y2 = (y2 + 1);
                }
                x2 = (x2 + 1);
            }
            sy = (sy + 1);
        }
        sx = (sx + 1);
    }
    double result = 0.0;
    i = 0;
    while (i < N) {
        result = (result + empty[i]);
        i = (i + 1);
    }
    printf("%.6f\n", result);
    free(empty);
    free(cur);
    free(nxt);
    return 0;
}

Generated MLIR

module {
  llvm.func @printf(!llvm.ptr, ...) -> i32
  llvm.mlir.global internal constant @str_0("%.6f\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 @idx(%arg0: i32, %arg1: i32, %arg2: i32) -> i64 {
    %0 = arith.extsi %arg0 : i32 to i64
    %1 = arith.extsi %arg2 : i32 to i64
    %2 = arith.muli %0, %1 : i64
    %3 = arith.extsi %arg1 : i32 to i64
    %4 = arith.addi %2, %3 : i64
    func.return %4 : i64
  }
  func.func @main() -> i32 {
    %5 = arith.constant 30 : i32
    %6 = arith.constant 30 : i32
    %7 = arith.constant 50 : i32
    %8 = arith.extsi %5 : i32 to i64
    %9 = arith.extsi %6 : i32 to i64
    %10 = arith.muli %8, %9 : i64
    %12 = arith.constant 8 : i32
    %13 = arith.extsi %12 : i32 to i64
    %11 = func.call @calloc(%10, %13) : (i64, i64) -> !llvm.ptr
    %15 = arith.constant 8 : i32
    %16 = arith.extsi %15 : i32 to i64
    %14 = func.call @calloc(%10, %16) : (i64, i64) -> !llvm.ptr
    %18 = arith.constant 8 : i32
    %19 = arith.extsi %18 : i32 to i64
    %17 = func.call @calloc(%10, %19) : (i64, i64) -> !llvm.ptr
    %20 = llvm.mlir.zero : !llvm.ptr
    %21 = llvm.icmp "eq" %11, %20 : !llvm.ptr
    %22 = scf.if %21 -> (i1) {
      %23 = arith.constant true
      scf.yield %23 : i1
    } else {
      %24 = llvm.mlir.zero : !llvm.ptr
      %25 = llvm.icmp "eq" %14, %24 : !llvm.ptr
      scf.yield %25 : i1
    }
    %26 = scf.if %22 -> (i1) {
      %27 = arith.constant true
      scf.yield %27 : i1
    } else {
      %28 = llvm.mlir.zero : !llvm.ptr
      %29 = llvm.icmp "eq" %17, %28 : !llvm.ptr
      scf.yield %29 : i1
    }
    cf.cond_br %26, ^bb0, ^bb1
    ^bb0:
      %30 = arith.constant 1 : i32
      func.return %30 : i32
    ^bb1:
      cf.br ^bb2
    ^bb2:
    %31 = arith.constant 0 : i32
    %32 = arith.extsi %31 : i32 to i64
    %33 = llvm.mlir.constant(1 : i64) : i64
    %34 = llvm.alloca %33 x i64 : (i64) -> !llvm.ptr
    llvm.store %32, %34 : i64, !llvm.ptr
    cf.br ^bb3
    ^bb3:
    %35 = llvm.load %34 : !llvm.ptr -> i64
    %36 = arith.cmpi slt, %35, %10 : i64
    cf.cond_br %36, ^bb4, ^bb5
    ^bb4:
      %37 = arith.constant 1.0 : f32
      %38 = llvm.load %34 : !llvm.ptr -> i64
      %39 = arith.extf %37 : f32 to f64
      %40 = llvm.getelementptr %11[%38] : (!llvm.ptr, i64) -> !llvm.ptr, f64
      llvm.store %39, %40 : f64, !llvm.ptr
      %41 = llvm.load %34 : !llvm.ptr -> i64
      %42 = arith.constant 1 : i32
      %44 = arith.extsi %42 : i32 to i64
      %43 = arith.addi %41, %44 : i64
      llvm.store %43, %34 : i64, !llvm.ptr
      cf.br ^bb3
    ^bb5:
    %45 = arith.constant 2 : i32
    %46 = arith.divsi %5, %45 : i32
    %47 = arith.constant 2 : i32
    %48 = arith.divsi %6, %47 : i32
    %49 = arith.constant 0 : i32
    %50 = llvm.mlir.constant(1 : i64) : i64
    %51 = llvm.alloca %50 x i32 : (i64) -> !llvm.ptr
    llvm.store %49, %51 : i32, !llvm.ptr
    cf.br ^bb6
    ^bb6:
    %52 = llvm.load %51 : !llvm.ptr -> i32
    %53 = arith.cmpi slt, %52, %46 : i32
    cf.cond_br %53, ^bb7, ^bb8
    ^bb7:
      %54 = arith.constant 0 : i32
      %55 = llvm.mlir.constant(1 : i64) : i64
      %56 = llvm.alloca %55 x i32 : (i64) -> !llvm.ptr
      llvm.store %54, %56 : i32, !llvm.ptr
      cf.br ^bb9
      ^bb9:
      %57 = llvm.load %56 : !llvm.ptr -> i32
      %58 = arith.cmpi slt, %57, %48 : i32
      cf.cond_br %58, ^bb10, ^bb11
      ^bb10:
        %59 = arith.constant 0 : i32
        %60 = arith.extsi %59 : i32 to i64
        llvm.store %60, %34 : i64, !llvm.ptr
        cf.br ^bb12
        ^bb12:
        %61 = llvm.load %34 : !llvm.ptr -> i64
        %62 = arith.cmpi slt, %61, %10 : i64
        cf.cond_br %62, ^bb13, ^bb14
        ^bb13:
          %63 = arith.constant 0.0 : f32
          %64 = llvm.load %34 : !llvm.ptr -> i64
          %65 = arith.extf %63 : f32 to f64
          %66 = llvm.getelementptr %14[%64] : (!llvm.ptr, i64) -> !llvm.ptr, f64
          llvm.store %65, %66 : f64, !llvm.ptr
          %67 = llvm.load %34 : !llvm.ptr -> i64
          %68 = arith.constant 1 : i32
          %70 = arith.extsi %68 : i32 to i64
          %69 = arith.addi %67, %70 : i64
          llvm.store %69, %34 : i64, !llvm.ptr
          cf.br ^bb12
        ^bb14:
        %71 = arith.constant 1.0 : f32
        %73 = llvm.load %51 : !llvm.ptr -> i32
        %74 = llvm.load %56 : !llvm.ptr -> i32
        %72 = func.call @idx(%73, %74, %6) : (i32, i32, i32) -> i64
        %75 = arith.extf %71 : f32 to f64
        %76 = llvm.getelementptr %14[%72] : (!llvm.ptr, i64) -> !llvm.ptr, f64
        llvm.store %75, %76 : f64, !llvm.ptr
        %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 ^bb15
        ^bb15:
        %80 = llvm.load %79 : !llvm.ptr -> i32
        %81 = arith.cmpi slt, %80, %7 : i32
        cf.cond_br %81, ^bb16, ^bb17
        ^bb16:
          %82 = arith.constant 0 : i32
          %83 = arith.extsi %82 : i32 to i64
          llvm.store %83, %34 : i64, !llvm.ptr
          cf.br ^bb18
          ^bb18:
          %84 = llvm.load %34 : !llvm.ptr -> i64
          %85 = arith.cmpi slt, %84, %10 : i64
          cf.cond_br %85, ^bb19, ^bb20
          ^bb19:
            %86 = arith.constant 0.0 : f32
            %87 = llvm.load %34 : !llvm.ptr -> i64
            %88 = arith.extf %86 : f32 to f64
            %89 = llvm.getelementptr %17[%87] : (!llvm.ptr, i64) -> !llvm.ptr, f64
            llvm.store %88, %89 : f64, !llvm.ptr
            %90 = llvm.load %34 : !llvm.ptr -> i64
            %91 = arith.constant 1 : i32
            %93 = arith.extsi %91 : i32 to i64
            %92 = arith.addi %90, %93 : i64
            llvm.store %92, %34 : i64, !llvm.ptr
            cf.br ^bb18
          ^bb20:
          %94 = arith.constant 0 : i32
          %95 = llvm.mlir.constant(1 : i64) : i64
          %96 = llvm.alloca %95 x i32 : (i64) -> !llvm.ptr
          llvm.store %94, %96 : i32, !llvm.ptr
          cf.br ^bb21
          ^bb21:
          %97 = llvm.load %96 : !llvm.ptr -> i32
          %98 = arith.cmpi slt, %97, %5 : i32
          cf.cond_br %98, ^bb22, ^bb23
          ^bb22:
            %99 = arith.constant 0 : i32
            %100 = llvm.mlir.constant(1 : i64) : i64
            %101 = llvm.alloca %100 x i32 : (i64) -> !llvm.ptr
            llvm.store %99, %101 : i32, !llvm.ptr
            cf.br ^bb24
            ^bb24:
            %102 = llvm.load %101 : !llvm.ptr -> i32
            %103 = arith.cmpi slt, %102, %6 : i32
            cf.cond_br %103, ^bb25, ^bb26
            ^bb25:
              %106 = llvm.load %96 : !llvm.ptr -> i32
              %107 = llvm.load %101 : !llvm.ptr -> i32
              %105 = func.call @idx(%106, %107, %6) : (i32, i32, i32) -> i64
              %108 = llvm.getelementptr %14[%105] : (!llvm.ptr, i64) -> !llvm.ptr, f64
              %104 = llvm.load %108 : !llvm.ptr -> f64
              %109 = arith.constant 0.0 : f32
              %111 = arith.extf %109 : f32 to f64
              %110 = arith.cmpf one, %104, %111 : f64
              cf.cond_br %110, ^bb27, ^bb28
              ^bb27:
                %112 = arith.constant 4 : i32
                %113 = llvm.mlir.constant(1 : i64) : i64
                %114 = llvm.alloca %113 x i32 : (i64) -> !llvm.ptr
                llvm.store %112, %114 : i32, !llvm.ptr
                %115 = llvm.load %96 : !llvm.ptr -> i32
                %116 = arith.constant 0 : i32
                %117 = arith.cmpi eq, %115, %116 : i32
                %118 = scf.if %117 -> (i1) {
                  %119 = arith.constant true
                  scf.yield %119 : i1
                } else {
                  %120 = llvm.load %96 : !llvm.ptr -> i32
                  %121 = arith.constant 1 : i32
                  %122 = arith.subi %5, %121 : i32
                  %123 = arith.cmpi eq, %120, %122 : i32
                  scf.yield %123 : i1
                }
                cf.cond_br %118, ^bb30, ^bb31
                ^bb30:
                  %124 = llvm.load %114 : !llvm.ptr -> i32
                  %125 = arith.constant 1 : i32
                  %126 = arith.subi %124, %125 : i32
                  llvm.store %126, %114 : i32, !llvm.ptr
                  cf.br ^bb32
                ^bb31:
                  cf.br ^bb32
                ^bb32:
                %127 = llvm.load %101 : !llvm.ptr -> i32
                %128 = arith.constant 0 : i32
                %129 = arith.cmpi eq, %127, %128 : i32
                %130 = scf.if %129 -> (i1) {
                  %131 = arith.constant true
                  scf.yield %131 : i1
                } else {
                  %132 = llvm.load %101 : !llvm.ptr -> i32
                  %133 = arith.constant 1 : i32
                  %134 = arith.subi %6, %133 : i32
                  %135 = arith.cmpi eq, %132, %134 : i32
                  scf.yield %135 : i1
                }
                cf.cond_br %130, ^bb33, ^bb34
                ^bb33:
                  %136 = llvm.load %114 : !llvm.ptr -> i32
                  %137 = arith.constant 1 : i32
                  %138 = arith.subi %136, %137 : i32
                  llvm.store %138, %114 : i32, !llvm.ptr
                  cf.br ^bb35
                ^bb34:
                  cf.br ^bb35
                ^bb35:
                %139 = llvm.load %114 : !llvm.ptr -> i32
                %140 = arith.sitofp %139 : i32 to f64
                %141 = arith.divf %104, %140 : f64
                %142 = llvm.load %96 : !llvm.ptr -> i32
                %143 = arith.constant 0 : i32
                %144 = arith.cmpi sgt, %142, %143 : i32
                cf.cond_br %144, ^bb36, ^bb37
                ^bb36:
                  %147 = llvm.load %96 : !llvm.ptr -> i32
                  %148 = arith.constant 1 : i32
                  %149 = arith.subi %147, %148 : i32
                  %150 = llvm.load %101 : !llvm.ptr -> i32
                  %146 = func.call @idx(%149, %150, %6) : (i32, i32, i32) -> i64
                  %151 = llvm.getelementptr %17[%146] : (!llvm.ptr, i64) -> !llvm.ptr, f64
                  %145 = llvm.load %151 : !llvm.ptr -> f64
                  %152 = arith.addf %145, %141 : f64
                  %154 = llvm.load %96 : !llvm.ptr -> i32
                  %155 = arith.constant 1 : i32
                  %156 = arith.subi %154, %155 : i32
                  %157 = llvm.load %101 : !llvm.ptr -> i32
                  %153 = func.call @idx(%156, %157, %6) : (i32, i32, i32) -> i64
                  %158 = llvm.getelementptr %17[%153] : (!llvm.ptr, i64) -> !llvm.ptr, f64
                  llvm.store %152, %158 : f64, !llvm.ptr
                  cf.br ^bb38
                ^bb37:
                  cf.br ^bb38
                ^bb38:
                %159 = llvm.load %96 : !llvm.ptr -> i32
                %160 = arith.constant 1 : i32
                %161 = arith.subi %5, %160 : i32
                %162 = arith.cmpi slt, %159, %161 : i32
                cf.cond_br %162, ^bb39, ^bb40
                ^bb39:
                  %165 = llvm.load %96 : !llvm.ptr -> i32
                  %166 = arith.constant 1 : i32
                  %167 = arith.addi %165, %166 : i32
                  %168 = llvm.load %101 : !llvm.ptr -> i32
                  %164 = func.call @idx(%167, %168, %6) : (i32, i32, i32) -> i64
                  %169 = llvm.getelementptr %17[%164] : (!llvm.ptr, i64) -> !llvm.ptr, f64
                  %163 = llvm.load %169 : !llvm.ptr -> f64
                  %170 = arith.addf %163, %141 : f64
                  %172 = llvm.load %96 : !llvm.ptr -> i32
                  %173 = arith.constant 1 : i32
                  %174 = arith.addi %172, %173 : i32
                  %175 = llvm.load %101 : !llvm.ptr -> i32
                  %171 = func.call @idx(%174, %175, %6) : (i32, i32, i32) -> i64
                  %176 = llvm.getelementptr %17[%171] : (!llvm.ptr, i64) -> !llvm.ptr, f64
                  llvm.store %170, %176 : f64, !llvm.ptr
                  cf.br ^bb41
                ^bb40:
                  cf.br ^bb41
                ^bb41:
                %177 = llvm.load %101 : !llvm.ptr -> i32
                %178 = arith.constant 0 : i32
                %179 = arith.cmpi sgt, %177, %178 : i32
                cf.cond_br %179, ^bb42, ^bb43
                ^bb42:
                  %182 = llvm.load %96 : !llvm.ptr -> i32
                  %183 = llvm.load %101 : !llvm.ptr -> i32
                  %184 = arith.constant 1 : i32
                  %185 = arith.subi %183, %184 : i32
                  %181 = func.call @idx(%182, %185, %6) : (i32, i32, i32) -> i64
                  %186 = llvm.getelementptr %17[%181] : (!llvm.ptr, i64) -> !llvm.ptr, f64
                  %180 = llvm.load %186 : !llvm.ptr -> f64
                  %187 = arith.addf %180, %141 : f64
                  %189 = llvm.load %96 : !llvm.ptr -> i32
                  %190 = llvm.load %101 : !llvm.ptr -> i32
                  %191 = arith.constant 1 : i32
                  %192 = arith.subi %190, %191 : i32
                  %188 = func.call @idx(%189, %192, %6) : (i32, i32, i32) -> i64
                  %193 = llvm.getelementptr %17[%188] : (!llvm.ptr, i64) -> !llvm.ptr, f64
                  llvm.store %187, %193 : f64, !llvm.ptr
                  cf.br ^bb44
                ^bb43:
                  cf.br ^bb44
                ^bb44:
                %194 = llvm.load %101 : !llvm.ptr -> i32
                %195 = arith.constant 1 : i32
                %196 = arith.subi %6, %195 : i32
                %197 = arith.cmpi slt, %194, %196 : i32
                cf.cond_br %197, ^bb45, ^bb46
                ^bb45:
                  %200 = llvm.load %96 : !llvm.ptr -> i32
                  %201 = llvm.load %101 : !llvm.ptr -> i32
                  %202 = arith.constant 1 : i32
                  %203 = arith.addi %201, %202 : i32
                  %199 = func.call @idx(%200, %203, %6) : (i32, i32, i32) -> i64
                  %204 = llvm.getelementptr %17[%199] : (!llvm.ptr, i64) -> !llvm.ptr, f64
                  %198 = llvm.load %204 : !llvm.ptr -> f64
                  %205 = arith.addf %198, %141 : f64
                  %207 = llvm.load %96 : !llvm.ptr -> i32
                  %208 = llvm.load %101 : !llvm.ptr -> i32
                  %209 = arith.constant 1 : i32
                  %210 = arith.addi %208, %209 : i32
                  %206 = func.call @idx(%207, %210, %6) : (i32, i32, i32) -> i64
                  %211 = llvm.getelementptr %17[%206] : (!llvm.ptr, i64) -> !llvm.ptr, f64
                  llvm.store %205, %211 : f64, !llvm.ptr
                  cf.br ^bb47
                ^bb46:
                  cf.br ^bb47
                ^bb47:
                cf.br ^bb29
              ^bb28:
                cf.br ^bb29
              ^bb29:
              %212 = llvm.load %101 : !llvm.ptr -> i32
              %213 = arith.constant 1 : i32
              %214 = arith.addi %212, %213 : i32
              llvm.store %214, %101 : i32, !llvm.ptr
              cf.br ^bb24
            ^bb26:
            %215 = llvm.load %96 : !llvm.ptr -> i32
            %216 = arith.constant 1 : i32
            %217 = arith.addi %215, %216 : i32
            llvm.store %217, %96 : i32, !llvm.ptr
            cf.br ^bb21
          ^bb23:
          %218 = arith.constant 0 : i32
          %219 = arith.extsi %218 : i32 to i64
          llvm.store %219, %34 : i64, !llvm.ptr
          cf.br ^bb48
          ^bb48:
          %220 = llvm.load %34 : !llvm.ptr -> i64
          %221 = arith.cmpi slt, %220, %10 : i64
          cf.cond_br %221, ^bb49, ^bb50
          ^bb49:
            %223 = llvm.load %34 : !llvm.ptr -> i64
            %224 = llvm.getelementptr %17[%223] : (!llvm.ptr, i64) -> !llvm.ptr, f64
            %222 = llvm.load %224 : !llvm.ptr -> f64
            %225 = llvm.load %34 : !llvm.ptr -> i64
            %226 = llvm.getelementptr %14[%225] : (!llvm.ptr, i64) -> !llvm.ptr, f64
            llvm.store %222, %226 : f64, !llvm.ptr
            %227 = llvm.load %34 : !llvm.ptr -> i64
            %228 = arith.constant 1 : i32
            %230 = arith.extsi %228 : i32 to i64
            %229 = arith.addi %227, %230 : i64
            llvm.store %229, %34 : i64, !llvm.ptr
            cf.br ^bb48
          ^bb50:
          %231 = llvm.load %79 : !llvm.ptr -> i32
          %232 = arith.constant 1 : i32
          %233 = arith.addi %231, %232 : i32
          llvm.store %233, %79 : i32, !llvm.ptr
          cf.br ^bb15
        ^bb17:
        %234 = arith.constant 0 : i32
        %235 = llvm.mlir.constant(1 : i64) : i64
        %236 = llvm.alloca %235 x i32 : (i64) -> !llvm.ptr
        llvm.store %234, %236 : i32, !llvm.ptr
        cf.br ^bb51
        ^bb51:
        %237 = llvm.load %236 : !llvm.ptr -> i32
        %238 = arith.cmpi slt, %237, %5 : i32
        cf.cond_br %238, ^bb52, ^bb53
        ^bb52:
          %239 = arith.constant 0 : i32
          %240 = llvm.mlir.constant(1 : i64) : i64
          %241 = llvm.alloca %240 x i32 : (i64) -> !llvm.ptr
          llvm.store %239, %241 : i32, !llvm.ptr
          cf.br ^bb54
          ^bb54:
          %242 = llvm.load %241 : !llvm.ptr -> i32
          %243 = arith.cmpi slt, %242, %6 : i32
          cf.cond_br %243, ^bb55, ^bb56
          ^bb55:
            %245 = llvm.load %236 : !llvm.ptr -> i32
            %246 = llvm.load %241 : !llvm.ptr -> i32
            %244 = func.call @idx(%245, %246, %6) : (i32, i32, i32) -> i64
            %248 = llvm.getelementptr %11[%244] : (!llvm.ptr, i64) -> !llvm.ptr, f64
            %247 = llvm.load %248 : !llvm.ptr -> f64
            %249 = arith.constant 1.0 : f32
            %251 = llvm.getelementptr %14[%244] : (!llvm.ptr, i64) -> !llvm.ptr, f64
            %250 = llvm.load %251 : !llvm.ptr -> f64
            %253 = arith.extf %249 : f32 to f64
            %252 = arith.subf %253, %250 : f64
            %254 = arith.mulf %247, %252 : f64
            %255 = llvm.getelementptr %11[%244] : (!llvm.ptr, i64) -> !llvm.ptr, f64
            llvm.store %254, %255 : f64, !llvm.ptr
            %257 = llvm.getelementptr %11[%244] : (!llvm.ptr, i64) -> !llvm.ptr, f64
            %256 = llvm.load %257 : !llvm.ptr -> f64
            %258 = arith.constant 1.0 : f32
            %261 = arith.constant 1 : i32
            %262 = arith.subi %5, %261 : i32
            %263 = llvm.load %236 : !llvm.ptr -> i32
            %264 = arith.subi %262, %263 : i32
            %265 = llvm.load %241 : !llvm.ptr -> i32
            %260 = func.call @idx(%264, %265, %6) : (i32, i32, i32) -> i64
            %266 = llvm.getelementptr %14[%260] : (!llvm.ptr, i64) -> !llvm.ptr, f64
            %259 = llvm.load %266 : !llvm.ptr -> f64
            %268 = arith.extf %258 : f32 to f64
            %267 = arith.subf %268, %259 : f64
            %269 = arith.mulf %256, %267 : f64
            %270 = llvm.getelementptr %11[%244] : (!llvm.ptr, i64) -> !llvm.ptr, f64
            llvm.store %269, %270 : f64, !llvm.ptr
            %272 = llvm.getelementptr %11[%244] : (!llvm.ptr, i64) -> !llvm.ptr, f64
            %271 = llvm.load %272 : !llvm.ptr -> f64
            %273 = arith.constant 1.0 : f32
            %276 = llvm.load %236 : !llvm.ptr -> i32
            %277 = arith.constant 1 : i32
            %278 = arith.subi %6, %277 : i32
            %279 = llvm.load %241 : !llvm.ptr -> i32
            %280 = arith.subi %278, %279 : i32
            %275 = func.call @idx(%276, %280, %6) : (i32, i32, i32) -> i64
            %281 = llvm.getelementptr %14[%275] : (!llvm.ptr, i64) -> !llvm.ptr, f64
            %274 = llvm.load %281 : !llvm.ptr -> f64
            %283 = arith.extf %273 : f32 to f64
            %282 = arith.subf %283, %274 : f64
            %284 = arith.mulf %271, %282 : f64
            %285 = llvm.getelementptr %11[%244] : (!llvm.ptr, i64) -> !llvm.ptr, f64
            llvm.store %284, %285 : f64, !llvm.ptr
            %287 = llvm.getelementptr %11[%244] : (!llvm.ptr, i64) -> !llvm.ptr, f64
            %286 = llvm.load %287 : !llvm.ptr -> f64
            %288 = arith.constant 1.0 : f32
            %291 = arith.constant 1 : i32
            %292 = arith.subi %5, %291 : i32
            %293 = llvm.load %236 : !llvm.ptr -> i32
            %294 = arith.subi %292, %293 : i32
            %295 = arith.constant 1 : i32
            %296 = arith.subi %6, %295 : i32
            %297 = llvm.load %241 : !llvm.ptr -> i32
            %298 = arith.subi %296, %297 : i32
            %290 = func.call @idx(%294, %298, %6) : (i32, i32, i32) -> i64
            %299 = llvm.getelementptr %14[%290] : (!llvm.ptr, i64) -> !llvm.ptr, f64
            %289 = llvm.load %299 : !llvm.ptr -> f64
            %301 = arith.extf %288 : f32 to f64
            %300 = arith.subf %301, %289 : f64
            %302 = arith.mulf %286, %300 : f64
            %303 = llvm.getelementptr %11[%244] : (!llvm.ptr, i64) -> !llvm.ptr, f64
            llvm.store %302, %303 : f64, !llvm.ptr
            %304 = llvm.load %241 : !llvm.ptr -> i32
            %305 = arith.constant 1 : i32
            %306 = arith.addi %304, %305 : i32
            llvm.store %306, %241 : i32, !llvm.ptr
            cf.br ^bb54
          ^bb56:
          %307 = llvm.load %236 : !llvm.ptr -> i32
          %308 = arith.constant 1 : i32
          %309 = arith.addi %307, %308 : i32
          llvm.store %309, %236 : i32, !llvm.ptr
          cf.br ^bb51
        ^bb53:
        %310 = llvm.load %56 : !llvm.ptr -> i32
        %311 = arith.constant 1 : i32
        %312 = arith.addi %310, %311 : i32
        llvm.store %312, %56 : i32, !llvm.ptr
        cf.br ^bb9
      ^bb11:
      %313 = llvm.load %51 : !llvm.ptr -> i32
      %314 = arith.constant 1 : i32
      %315 = arith.addi %313, %314 : i32
      llvm.store %315, %51 : i32, !llvm.ptr
      cf.br ^bb6
    ^bb8:
    %316 = arith.constant 0.0 : f32
    %317 = arith.extf %316 : f32 to f64
    %318 = llvm.mlir.constant(1 : i64) : i64
    %319 = llvm.alloca %318 x f64 : (i64) -> !llvm.ptr
    llvm.store %317, %319 : f64, !llvm.ptr
    %320 = arith.constant 0 : i32
    %321 = arith.extsi %320 : i32 to i64
    llvm.store %321, %34 : i64, !llvm.ptr
    cf.br ^bb57
    ^bb57:
    %322 = llvm.load %34 : !llvm.ptr -> i64
    %323 = arith.cmpi slt, %322, %10 : i64
    cf.cond_br %323, ^bb58, ^bb59
    ^bb58:
      %324 = llvm.load %319 : !llvm.ptr -> f64
      %326 = llvm.load %34 : !llvm.ptr -> i64
      %327 = llvm.getelementptr %11[%326] : (!llvm.ptr, i64) -> !llvm.ptr, f64
      %325 = llvm.load %327 : !llvm.ptr -> f64
      %328 = arith.addf %324, %325 : f64
      llvm.store %328, %319 : f64, !llvm.ptr
      %329 = llvm.load %34 : !llvm.ptr -> i64
      %330 = arith.constant 1 : i32
      %332 = arith.extsi %330 : i32 to i64
      %331 = arith.addi %329, %332 : i64
      llvm.store %331, %34 : i64, !llvm.ptr
      cf.br ^bb57
    ^bb59:
    %333 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %334 = llvm.load %319 : !llvm.ptr -> f64
    %335 = llvm.call @printf(%333, %334) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, f64) -> i32
    func.call @free(%11) : (!llvm.ptr) -> ()
    func.call @free(%14) : (!llvm.ptr) -> ()
    func.call @free(%17) : (!llvm.ptr) -> ()
    %339 = arith.constant 0 : i32
    func.return %339 : i32
  }
}