Problem 298

E[|L-R|] after 50 turns to 8 decimals.

Answer1.76882294
Output1.76882294
StatusPASS
Native helperno
Runtime0 ms
Peak memory1952 KB
Time complexityO(n^4) (estimated)
Space complexityO(n^2) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^4)?
Space complexityO(n^2)?
ApproachFlow solutionNot curated
VerdictUnknown

Flow source

# Project Euler 298
# E[|L-R|] after 50 turns to 8 decimals.

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

function read_i32_list(path: string, arr: ptr<i32>, n: i64) -> void {
    let f: ptr<void> = fopen(path, "r")
    let mut i: i64 = 0
    let mut c: i32 = fgetc(f)
    while i < n {
        while c == 32 || c == 10 || c == 13 || c == 9 {
            c = fgetc(f)
        }
        let mut sign: i32 = 1
        if c == 45 {
            sign = -1
            c = fgetc(f)
        }
        let mut v: i32 = 0
        while c >= 48 && c <= 57 {
            v = v * 10 + (c - 48)
            c = fgetc(f)
        }
        arr[i] = v * sign
        i = i + 1
    }
    fclose(f)
}

function main() -> i32 {
    let NS: i64 = 439
    let TURNS: i64 = 50
    let NT: i64 = 2886
    let NO: i64 = 440
    let offs: ptr<i32> = calloc(NO, 4)
    let tos: ptr<i32> = calloc(NT, 4)
    let deltas: ptr<i32> = calloc(NT, 4)
    let weights: ptr<i32> = calloc(NT, 4)
    read_i32_list("data/p298_offs.txt", offs, NO)
    read_i32_list("data/p298_tos.txt", tos, NT)
    read_i32_list("data/p298_deltas.txt", deltas, NT)
    read_i32_list("data/p298_weights.txt", weights, NT)

    let MAXLEN: i64 = 2 * TURNS + 1
    let cur: ptr<f64> = calloc(NS * MAXLEN, 8)
    let nxt: ptr<f64> = calloc(NS * MAXLEN, 8)
    let active: ptr<i8> = calloc(NS, 1)
    let nactive: ptr<i8> = calloc(NS, 1)
    cur[0 * MAXLEN + 0] = 1.0
    active[0] = 1
    let mut t: i64 = 0
    while t < TURNS {
        let new_len: i64 = 2 * (t + 1) + 1
        let old_len: i64 = 2 * t + 1
        let mut s: i64 = 0
        while s < NS {
            nactive[s] = 0
            let mut i: i64 = 0
            while i < new_len {
                nxt[s * MAXLEN + i] = 0.0
                i = i + 1
            }
            s = s + 1
        }
        s = 0
        while s < NS {
            if active[s] != 0 {
                let a: i64 = offs[s] as i64
                let b: i64 = offs[s + 1] as i64
                let mut e: i64 = a
                while e < b {
                    let ns: i64 = tos[e] as i64
                    let delta: i64 = deltas[e] as i64
                    let w: f64 = (weights[e] as f64) / 10.0
                    let shift: i64 = delta + 1
                    nactive[ns] = 1
                    let mut i: i64 = 0
                    while i < old_len {
                        let val: f64 = cur[s * MAXLEN + i]
                        if val != 0.0 {
                            nxt[ns * MAXLEN + i + shift] = nxt[ns * MAXLEN + i + shift] + val * w
                        }
                        i = i + 1
                    }
                    e = e + 1
                }
            }
            s = s + 1
        }
        s = 0
        while s < NS {
            active[s] = nactive[s]
            let mut i: i64 = 0
            while i < new_len {
                cur[s * MAXLEN + i] = nxt[s * MAXLEN + i]
                i = i + 1
            }
            s = s + 1
        }
        t = t + 1
    }
    let mut expected: f64 = 0.0
    let offset: i64 = TURNS
    let mut s: i64 = 0
    while s < NS {
        if active[s] != 0 {
            let mut i: i64 = 0
            while i < MAXLEN {
                let diff: i64 = i - offset
                let mut ad: f64 = diff as f64
                if ad < 0.0 { ad = 0.0 - ad }
                expected = expected + ad * cur[s * MAXLEN + i]
                i = i + 1
            }
        }
        s = s + 1
    }
    printf("%.8f\n", expected)
    free(offs); free(tos); free(deltas); free(weights); free(cur); free(nxt); free(active); free(nactive)
    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; }

void read_i32_list_string_ptr_i32_i64(char* path, int32_t* arr, int64_t n);
int32_t main(void);






void read_i32_list_string_ptr_i32_i64(char* path, int32_t* arr, int64_t n) {
    void* f = (void*)(fopen(path, "r"));
    int64_t i = 0;
    int32_t c = fgetc(f);
    while (i < n) {
        while ((((c == 32 || c == 10) || c == 13) || c == 9)) {
            c = fgetc(f);
        }
        int32_t sign = 1;
        if (c == 45) {
            sign = (-1);
            c = fgetc(f);
        }
        int32_t v = 0;
        while ((c >= 48 && c <= 57)) {
            v = ((v * 10) + (c - 48));
            c = fgetc(f);
        }
        arr[i] = (v * sign);
        i = (i + 1);
    }
    fclose(f);
}

int32_t main(void) {
    int64_t NS = 439;
    int64_t TURNS = 50;
    int64_t NT = 2886;
    int64_t NO = 440;
    int32_t* offs = (int32_t*)(calloc(NO, 4));
    int32_t* tos = (int32_t*)(calloc(NT, 4));
    int32_t* deltas = (int32_t*)(calloc(NT, 4));
    int32_t* weights = (int32_t*)(calloc(NT, 4));
    read_i32_list_string_ptr_i32_i64("data/p298_offs.txt", offs, NO);
    read_i32_list_string_ptr_i32_i64("data/p298_tos.txt", tos, NT);
    read_i32_list_string_ptr_i32_i64("data/p298_deltas.txt", deltas, NT);
    read_i32_list_string_ptr_i32_i64("data/p298_weights.txt", weights, NT);
    int64_t MAXLEN = ((2 * TURNS) + 1);
    double* cur = (double*)(calloc((NS * MAXLEN), 8));
    double* nxt = (double*)(calloc((NS * MAXLEN), 8));
    int8_t* active = (int8_t*)(calloc(NS, 1));
    int8_t* nactive = (int8_t*)(calloc(NS, 1));
    cur[((0 * MAXLEN) + 0)] = 1.0;
    active[0] = 1;
    int64_t t = 0;
    while (t < TURNS) {
        int64_t new_len = ((2 * (t + 1)) + 1);
        int64_t old_len = ((2 * t) + 1);
        int64_t s = 0;
        while (s < NS) {
            nactive[s] = 0;
            int64_t i = 0;
            while (i < new_len) {
                nxt[((s * MAXLEN) + i)] = 0.0;
                i = (i + 1);
            }
            s = (s + 1);
        }
        s = 0;
        while (s < NS) {
            if (active[s] != 0) {
                int64_t a = ((int64_t)(offs[s]));
                int64_t b = ((int64_t)(offs[(s + 1)]));
                int64_t e = a;
                while (e < b) {
                    int64_t ns = ((int64_t)(tos[e]));
                    int64_t delta = ((int64_t)(deltas[e]));
                    double w = (((double)(weights[e])) / 10.0);
                    int64_t shift = (delta + 1);
                    nactive[ns] = 1;
                    int64_t i = 0;
                    while (i < old_len) {
                        double val = cur[((s * MAXLEN) + i)];
                        if (val != 0.0) {
                            nxt[(((ns * MAXLEN) + i) + shift)] = (nxt[(((ns * MAXLEN) + i) + shift)] + (val * w));
                        }
                        i = (i + 1);
                    }
                    e = (e + 1);
                }
            }
            s = (s + 1);
        }
        s = 0;
        while (s < NS) {
            active[s] = nactive[s];
            int64_t i = 0;
            while (i < new_len) {
                cur[((s * MAXLEN) + i)] = nxt[((s * MAXLEN) + i)];
                i = (i + 1);
            }
            s = (s + 1);
        }
        t = (t + 1);
    }
    double expected = 0.0;
    int64_t offset = TURNS;
    int64_t s = 0;
    while (s < NS) {
        if (active[s] != 0) {
            int64_t i = 0;
            while (i < MAXLEN) {
                int64_t diff = (i - offset);
                double ad = ((double)(diff));
                if (ad < 0.0) {
                    ad = (0.0 - ad);
                }
                expected = (expected + (ad * cur[((s * MAXLEN) + i)]));
                i = (i + 1);
            }
        }
        s = (s + 1);
    }
    printf("%.8f\n", expected);
    free(offs);
    free(tos);
    free(deltas);
    free(weights);
    free(cur);
    free(nxt);
    free(active);
    free(nactive);
    return 0;
}

Generated MLIR

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