Problem 227

Expected turns for The Chase with 100 players.

Answer3780.618622
Output3780.618622
StatusPASS
Native helperno
Runtime0 ms
Peak memory1184 KB
Time complexityO(n^2) (estimated)
Space complexityO(n) (estimated)

Performance comparison

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

Flow source

# Project Euler 227
# Expected turns for The Chase with 100 players.

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

function main() -> i32 {
    let N: i32 = 100
    let n: i32 = N - 1
    let mut i: i32 = 0
    let A: ptr<f64> = calloc((n as i64) * (n as i64), 8)
    let b: ptr<f64> = calloc(n as i64, 8)
    if A == null || b == null { return 1 }
    let p_m2: f64 = 1.0 / 36.0
    let p_m1: f64 = 2.0 / 9.0
    let p_0: f64 = 0.5
    let p_p1: f64 = 2.0 / 9.0
    let p_p2: f64 = 1.0 / 36.0
    let mut d: i32 = 1
    while d < N {
        let r: i32 = d - 1
        A[(r as i64) * (n as i64) + (r as i64)] = 1.0
        b[r] = 1.0
        let mut k: i32 = 0
        while k < 5 {
            let mut delta: i32 = 0
            let mut p: f64 = 0.0
            match k {
                0 => { delta = 0 - 2; p = p_m2 }
                1 => { delta = 0 - 1; p = p_m1 }
                2 => { delta = 0; p = p_0 }
                3 => { delta = 1; p = p_p1 }
                _ => { delta = 2; p = p_p2 }
            }
            let mut d2: i32 = (d + delta) % N
            if d2 < 0 { d2 = d2 + N }
            if d2 != 0 {
                let c: i32 = d2 - 1
                let idx: i64 = (r as i64) * (n as i64) + (c as i64)
                A[idx] = A[idx] - p
            }
            k = k + 1
        }
        d = d + 1
    }
    let mut col: i32 = 0
    while col < n {
        let mut piv: i32 = col
        let mut best: f64 = fabs(A[(col as i64) * (n as i64) + (col as i64)])
        i = col + 1
        while i < n {
            let v: f64 = fabs(A[(i as i64) * (n as i64) + (col as i64)])
            if v > best { best = v; piv = i }
            i = i + 1
        }
        if piv != col {
            let mut j: i32 = 0
            while j < n {
                let tmp: f64 = A[(col as i64) * (n as i64) + (j as i64)]
                A[(col as i64) * (n as i64) + (j as i64)] = A[(piv as i64) * (n as i64) + (j as i64)]
                A[(piv as i64) * (n as i64) + (j as i64)] = tmp
                j = j + 1
            }
            let tb: f64 = b[col]
            b[col] = b[piv]
            b[piv] = tb
        }
        let diag: f64 = A[(col as i64) * (n as i64) + (col as i64)]
        i = col + 1
        while i < n {
            let f: f64 = A[(i as i64) * (n as i64) + (col as i64)] / diag
            let mut j: i32 = col
            while j < n {
                let ij: i64 = (i as i64) * (n as i64) + (j as i64)
                let cj: i64 = (col as i64) * (n as i64) + (j as i64)
                A[ij] = A[ij] - f * A[cj]
                j = j + 1
            }
            b[i] = b[i] - f * b[col]
            i = i + 1
        }
        col = col + 1
    }
    let x: ptr<f64> = calloc(n as i64, 8)
    i = n - 1
    while i >= 0 {
        let mut s: f64 = b[i]
        let mut j: i32 = i + 1
        while j < n {
            s = s - A[(i as i64) * (n as i64) + (j as i64)] * x[j]
            j = j + 1
        }
        x[i] = s / A[(i as i64) * (n as i64) + (i as i64)]
        i = i - 1
    }
    printf("%.6f\n", x[N / 2 - 1])
    free(A); free(b); free(x)
    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 main(void);




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