Problem 352
Blood tests: sum_{p=0.01..0.50} T(10000, p) to 6 decimals.
View problem on Project Euler
Performance comparison
| Metric | Our solution | Best known |
| Time complexity | O(n^2) | ? |
| Space complexity | O(n) | ? |
| Approach | Flow solution | Not curated |
| Verdict | Unknown |
Flow source
# Project Euler 352
# Blood tests: sum_{p=0.01..0.50} T(10000, p) to 6 decimals.
extern {
function calloc(n: i64, size: i64) -> ptr<void>
function free(p: ptr<void>) -> void
}
function T(s: i32, p: f64, kmax0: i32) -> f64 {
let mut kmax: i32 = kmax0
if kmax > s { kmax = s }
let a: f64 = 1.0 - p
let powa: ptr<f64> = calloc((kmax + 1) as i64, 8)
let U: ptr<f64> = calloc((s + 1) as i64, 8)
let P: ptr<f64> = calloc((kmax + 1) as i64, 8)
if powa == null || U == null || P == null { return 0.0 }
powa[0] = 1.0
let mut k: i32 = 1
while k <= kmax {
powa[k] = powa[k - 1] * a
k = k + 1
}
U[0] = 0.0
if s >= 1 { U[1] = 1.0 }
if kmax >= 1 { P[1] = 0.0 }
let nlimit: i32 = s
if nlimit > kmax { nlimit = kmax }
let mut n: i32 = 2
while n <= nlimit {
let denom: f64 = 1.0 - powa[n]
let mut bestP: f64 = 1.0e300
k = 1
while k < n {
let prob_pos: f64 = (1.0 - powa[k]) / denom
let cand: f64 = 1.0 + prob_pos * (P[k] + U[n - k]) + (1.0 - prob_pos) * P[n - k]
if cand < bestP { bestP = cand }
k = k + 1
}
P[n] = bestP
let mut bestU: f64 = 1.0e300
k = 1
while k <= n {
let cand2: f64 = 1.0 + U[n - k] + (1.0 - powa[k]) * P[k]
if cand2 < bestU { bestU = cand2 }
k = k + 1
}
U[n] = bestU
n = n + 1
}
n = nlimit + 1
while n <= s {
let mut bestU2: f64 = 1.0e300
k = 1
while k <= kmax {
let cand3: f64 = 1.0 + U[n - k] + (1.0 - powa[k]) * P[k]
if cand3 < bestU2 { bestU2 = cand3 }
k = k + 1
}
U[n] = bestU2
n = n + 1
}
let result: f64 = U[s]
free(P)
free(U)
free(powa)
return result
}
function main() -> i32 {
let mut total: f64 = 0.0
let mut i: i32 = 1
while i <= 50 {
let p: f64 = (i as f64) / 100.0
total = total + T(10000, p, 100)
i = i + 1
}
printf("%.6f\n", total)
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; }
double T_i32_f64_i32(int32_t s, double p, int32_t kmax0);
int32_t main(void);
double T_i32_f64_i32(int32_t s, double p, int32_t kmax0) {
int32_t kmax = kmax0;
if (kmax > s) {
kmax = s;
}
double a = (1.0 - p);
double* powa = (double*)(calloc(((int64_t)((kmax + 1))), 8));
double* U = (double*)(calloc(((int64_t)((s + 1))), 8));
double* P = (double*)(calloc(((int64_t)((kmax + 1))), 8));
if (((powa == NULL || U == NULL) || P == NULL)) {
return 0.0;
}
powa[0] = 1.0;
int32_t k = 1;
while (k <= kmax) {
powa[k] = (powa[(k - 1)] * a);
k = (k + 1);
}
U[0] = 0.0;
if (s >= 1) {
U[1] = 1.0;
}
if (kmax >= 1) {
P[1] = 0.0;
}
int32_t nlimit = s;
if (nlimit > kmax) {
nlimit = kmax;
}
int32_t n = 2;
while (n <= nlimit) {
double denom = (1.0 - powa[n]);
double bestP = 1.0e300;
k = 1;
while (k < n) {
double prob_pos = ((1.0 - powa[k]) / denom);
double cand = ((1.0 + (prob_pos * (P[k] + U[(n - k)]))) + ((1.0 - prob_pos) * P[(n - k)]));
if (cand < bestP) {
bestP = cand;
}
k = (k + 1);
}
P[n] = bestP;
double bestU = 1.0e300;
k = 1;
while (k <= n) {
double cand2 = ((1.0 + U[(n - k)]) + ((1.0 - powa[k]) * P[k]));
if (cand2 < bestU) {
bestU = cand2;
}
k = (k + 1);
}
U[n] = bestU;
n = (n + 1);
}
n = (nlimit + 1);
while (n <= s) {
double bestU2 = 1.0e300;
k = 1;
while (k <= kmax) {
double cand3 = ((1.0 + U[(n - k)]) + ((1.0 - powa[k]) * P[k]));
if (cand3 < bestU2) {
bestU2 = cand3;
}
k = (k + 1);
}
U[n] = bestU2;
n = (n + 1);
}
double result = U[s];
free(P);
free(U);
free(powa);
return result;
}
int32_t main(void) {
double total = 0.0;
int32_t i = 1;
while (i <= 50) {
double p = (((double)(i)) / 100.0);
total = (total + T_i32_f64_i32(10000, p, 100));
i = (i + 1);
}
printf("%.6f\n", total);
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 @T(%arg0: i32, %arg1: f64, %arg2: i32) -> f64 {
%0 = llvm.mlir.constant(1 : i64) : i64
%1 = llvm.alloca %0 x i32 : (i64) -> !llvm.ptr
llvm.store %arg2, %1 : i32, !llvm.ptr
%2 = llvm.load %1 : !llvm.ptr -> i32
%3 = arith.cmpi sgt, %2, %arg0 : i32
cf.cond_br %3, ^bb0, ^bb1
^bb0:
llvm.store %arg0, %1 : i32, !llvm.ptr
cf.br ^bb2
^bb1:
cf.br ^bb2
^bb2:
%4 = arith.constant 1.0 : f32
%6 = arith.extf %4 : f32 to f64
%5 = arith.subf %6, %arg1 : f64
%8 = llvm.load %1 : !llvm.ptr -> i32
%9 = arith.constant 1 : i32
%10 = arith.addi %8, %9 : i32
%11 = arith.extsi %10 : i32 to i64
%12 = arith.constant 8 : i32
%13 = arith.extsi %12 : i32 to i64
%7 = func.call @calloc(%11, %13) : (i64, i64) -> !llvm.ptr
%15 = arith.constant 1 : i32
%16 = arith.addi %arg0, %15 : i32
%17 = arith.extsi %16 : i32 to i64
%18 = arith.constant 8 : i32
%19 = arith.extsi %18 : i32 to i64
%14 = func.call @calloc(%17, %19) : (i64, i64) -> !llvm.ptr
%21 = llvm.load %1 : !llvm.ptr -> i32
%22 = arith.constant 1 : i32
%23 = arith.addi %21, %22 : i32
%24 = arith.extsi %23 : i32 to i64
%25 = arith.constant 8 : i32
%26 = arith.extsi %25 : i32 to i64
%20 = func.call @calloc(%24, %26) : (i64, i64) -> !llvm.ptr
%27 = llvm.mlir.zero : !llvm.ptr
%28 = llvm.icmp "eq" %7, %27 : !llvm.ptr
%29 = scf.if %28 -> (i1) {
%30 = arith.constant true
scf.yield %30 : i1
} else {
%31 = llvm.mlir.zero : !llvm.ptr
%32 = llvm.icmp "eq" %14, %31 : !llvm.ptr
scf.yield %32 : i1
}
%33 = scf.if %29 -> (i1) {
%34 = arith.constant true
scf.yield %34 : i1
} else {
%35 = llvm.mlir.zero : !llvm.ptr
%36 = llvm.icmp "eq" %20, %35 : !llvm.ptr
scf.yield %36 : i1
}
cf.cond_br %33, ^bb3, ^bb4
^bb3:
%37 = arith.constant 0.0 : f32
%38 = arith.extf %37 : f32 to f64
func.return %38 : f64
^bb4:
cf.br ^bb5
^bb5:
%39 = arith.constant 1.0 : f32
%40 = arith.constant 0 : i32
%41 = arith.extf %39 : f32 to f64
%42 = arith.extsi %40 : i32 to i64
%43 = llvm.getelementptr %7[%42] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %41, %43 : f64, !llvm.ptr
%44 = arith.constant 1 : i32
%45 = llvm.mlir.constant(1 : i64) : i64
%46 = llvm.alloca %45 x i32 : (i64) -> !llvm.ptr
llvm.store %44, %46 : i32, !llvm.ptr
cf.br ^bb6
^bb6:
%47 = llvm.load %46 : !llvm.ptr -> i32
%48 = llvm.load %1 : !llvm.ptr -> i32
%49 = arith.cmpi sle, %47, %48 : i32
cf.cond_br %49, ^bb7, ^bb8
^bb7:
%51 = llvm.load %46 : !llvm.ptr -> i32
%52 = arith.constant 1 : i32
%53 = arith.subi %51, %52 : i32
%54 = arith.extsi %53 : i32 to i64
%55 = llvm.getelementptr %7[%54] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%50 = llvm.load %55 : !llvm.ptr -> f64
%56 = arith.mulf %50, %5 : f64
%57 = llvm.load %46 : !llvm.ptr -> i32
%58 = arith.extsi %57 : i32 to i64
%59 = llvm.getelementptr %7[%58] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %56, %59 : f64, !llvm.ptr
%60 = llvm.load %46 : !llvm.ptr -> i32
%61 = arith.constant 1 : i32
%62 = arith.addi %60, %61 : i32
llvm.store %62, %46 : i32, !llvm.ptr
cf.br ^bb6
^bb8:
%63 = arith.constant 0.0 : f32
%64 = arith.constant 0 : i32
%65 = arith.extf %63 : f32 to f64
%66 = arith.extsi %64 : i32 to i64
%67 = llvm.getelementptr %14[%66] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %65, %67 : f64, !llvm.ptr
%68 = arith.constant 1 : i32
%69 = arith.cmpi sge, %arg0, %68 : i32
cf.cond_br %69, ^bb9, ^bb10
^bb9:
%70 = arith.constant 1.0 : f32
%71 = arith.constant 1 : i32
%72 = arith.extf %70 : f32 to f64
%73 = arith.extsi %71 : i32 to i64
%74 = llvm.getelementptr %14[%73] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %72, %74 : f64, !llvm.ptr
cf.br ^bb11
^bb10:
cf.br ^bb11
^bb11:
%75 = llvm.load %1 : !llvm.ptr -> i32
%76 = arith.constant 1 : i32
%77 = arith.cmpi sge, %75, %76 : i32
cf.cond_br %77, ^bb12, ^bb13
^bb12:
%78 = arith.constant 0.0 : f32
%79 = arith.constant 1 : i32
%80 = arith.extf %78 : f32 to f64
%81 = arith.extsi %79 : i32 to i64
%82 = llvm.getelementptr %20[%81] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %80, %82 : f64, !llvm.ptr
cf.br ^bb14
^bb13:
cf.br ^bb14
^bb14:
%83 = llvm.load %1 : !llvm.ptr -> i32
%84 = arith.cmpi sgt, %arg0, %83 : i32
%85 = scf.if %84 -> (i32) {
%86 = llvm.load %1 : !llvm.ptr -> i32
scf.yield %86 : i32
} else {
scf.yield %arg0 : i32
}
%87 = arith.constant 2 : i32
%88 = llvm.mlir.constant(1 : i64) : i64
%89 = llvm.alloca %88 x i32 : (i64) -> !llvm.ptr
llvm.store %87, %89 : i32, !llvm.ptr
cf.br ^bb15
^bb15:
%90 = llvm.load %89 : !llvm.ptr -> i32
%91 = arith.cmpi sle, %90, %85 : i32
cf.cond_br %91, ^bb16, ^bb17
^bb16:
%92 = arith.constant 1.0 : f32
%94 = llvm.load %89 : !llvm.ptr -> i32
%95 = arith.extsi %94 : i32 to i64
%96 = llvm.getelementptr %7[%95] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%93 = llvm.load %96 : !llvm.ptr -> f64
%98 = arith.extf %92 : f32 to f64
%97 = arith.subf %98, %93 : f64
%99 = arith.constant 1000000000000000052504760255204420248704468581108159154915854115511802457988908195786371375080447864043704443832883878176942523235360430575644792184786706982848387200926575803737830233794788090059368953234970799945081119038967640880074652742780142494579258788820056842838115669472196386865459400540160 : f32
%100 = arith.extf %99 : f32 to f64
%101 = llvm.mlir.constant(1 : i64) : i64
%102 = llvm.alloca %101 x f64 : (i64) -> !llvm.ptr
llvm.store %100, %102 : f64, !llvm.ptr
%103 = arith.constant 1 : i32
llvm.store %103, %46 : i32, !llvm.ptr
cf.br ^bb18
^bb18:
%104 = llvm.load %46 : !llvm.ptr -> i32
%105 = llvm.load %89 : !llvm.ptr -> i32
%106 = arith.cmpi slt, %104, %105 : i32
cf.cond_br %106, ^bb19, ^bb20
^bb19:
%107 = arith.constant 1.0 : f32
%109 = llvm.load %46 : !llvm.ptr -> i32
%110 = arith.extsi %109 : i32 to i64
%111 = llvm.getelementptr %7[%110] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%108 = llvm.load %111 : !llvm.ptr -> f64
%113 = arith.extf %107 : f32 to f64
%112 = arith.subf %113, %108 : f64
%114 = arith.divf %112, %97 : f64
%115 = arith.constant 1.0 : f32
%117 = llvm.load %46 : !llvm.ptr -> i32
%118 = arith.extsi %117 : i32 to i64
%119 = llvm.getelementptr %20[%118] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%116 = llvm.load %119 : !llvm.ptr -> f64
%121 = llvm.load %89 : !llvm.ptr -> i32
%122 = llvm.load %46 : !llvm.ptr -> i32
%123 = arith.subi %121, %122 : i32
%124 = arith.extsi %123 : i32 to i64
%125 = llvm.getelementptr %14[%124] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%120 = llvm.load %125 : !llvm.ptr -> f64
%126 = arith.addf %116, %120 : f64
%127 = arith.mulf %114, %126 : f64
%129 = arith.extf %115 : f32 to f64
%128 = arith.addf %129, %127 : f64
%130 = arith.constant 1.0 : f32
%132 = arith.extf %130 : f32 to f64
%131 = arith.subf %132, %114 : f64
%134 = llvm.load %89 : !llvm.ptr -> i32
%135 = llvm.load %46 : !llvm.ptr -> i32
%136 = arith.subi %134, %135 : i32
%137 = arith.extsi %136 : i32 to i64
%138 = llvm.getelementptr %20[%137] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%133 = llvm.load %138 : !llvm.ptr -> f64
%139 = arith.mulf %131, %133 : f64
%140 = arith.addf %128, %139 : f64
%141 = llvm.load %102 : !llvm.ptr -> f64
%142 = arith.cmpf olt, %140, %141 : f64
cf.cond_br %142, ^bb21, ^bb22
^bb21:
llvm.store %140, %102 : f64, !llvm.ptr
cf.br ^bb23
^bb22:
cf.br ^bb23
^bb23:
%143 = llvm.load %46 : !llvm.ptr -> i32
%144 = arith.constant 1 : i32
%145 = arith.addi %143, %144 : i32
llvm.store %145, %46 : i32, !llvm.ptr
cf.br ^bb18
^bb20:
%146 = llvm.load %102 : !llvm.ptr -> f64
%147 = llvm.load %89 : !llvm.ptr -> i32
%148 = arith.extsi %147 : i32 to i64
%149 = llvm.getelementptr %20[%148] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %146, %149 : f64, !llvm.ptr
%150 = arith.constant 1000000000000000052504760255204420248704468581108159154915854115511802457988908195786371375080447864043704443832883878176942523235360430575644792184786706982848387200926575803737830233794788090059368953234970799945081119038967640880074652742780142494579258788820056842838115669472196386865459400540160 : f32
%151 = arith.extf %150 : f32 to f64
%152 = llvm.mlir.constant(1 : i64) : i64
%153 = llvm.alloca %152 x f64 : (i64) -> !llvm.ptr
llvm.store %151, %153 : f64, !llvm.ptr
%154 = arith.constant 1 : i32
llvm.store %154, %46 : i32, !llvm.ptr
cf.br ^bb24
^bb24:
%155 = llvm.load %46 : !llvm.ptr -> i32
%156 = llvm.load %89 : !llvm.ptr -> i32
%157 = arith.cmpi sle, %155, %156 : i32
cf.cond_br %157, ^bb25, ^bb26
^bb25:
%158 = arith.constant 1.0 : f32
%160 = llvm.load %89 : !llvm.ptr -> i32
%161 = llvm.load %46 : !llvm.ptr -> i32
%162 = arith.subi %160, %161 : i32
%163 = arith.extsi %162 : i32 to i64
%164 = llvm.getelementptr %14[%163] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%159 = llvm.load %164 : !llvm.ptr -> f64
%166 = arith.extf %158 : f32 to f64
%165 = arith.addf %166, %159 : f64
%167 = arith.constant 1.0 : f32
%169 = llvm.load %46 : !llvm.ptr -> i32
%170 = arith.extsi %169 : i32 to i64
%171 = llvm.getelementptr %7[%170] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%168 = llvm.load %171 : !llvm.ptr -> f64
%173 = arith.extf %167 : f32 to f64
%172 = arith.subf %173, %168 : f64
%175 = llvm.load %46 : !llvm.ptr -> i32
%176 = arith.extsi %175 : i32 to i64
%177 = llvm.getelementptr %20[%176] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%174 = llvm.load %177 : !llvm.ptr -> f64
%178 = arith.mulf %172, %174 : f64
%179 = arith.addf %165, %178 : f64
%180 = llvm.load %153 : !llvm.ptr -> f64
%181 = arith.cmpf olt, %179, %180 : f64
cf.cond_br %181, ^bb27, ^bb28
^bb27:
llvm.store %179, %153 : f64, !llvm.ptr
cf.br ^bb29
^bb28:
cf.br ^bb29
^bb29:
%182 = llvm.load %46 : !llvm.ptr -> i32
%183 = arith.constant 1 : i32
%184 = arith.addi %182, %183 : i32
llvm.store %184, %46 : i32, !llvm.ptr
cf.br ^bb24
^bb26:
%185 = llvm.load %153 : !llvm.ptr -> f64
%186 = llvm.load %89 : !llvm.ptr -> i32
%187 = arith.extsi %186 : i32 to i64
%188 = llvm.getelementptr %14[%187] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %185, %188 : f64, !llvm.ptr
%189 = llvm.load %89 : !llvm.ptr -> i32
%190 = arith.constant 1 : i32
%191 = arith.addi %189, %190 : i32
llvm.store %191, %89 : i32, !llvm.ptr
cf.br ^bb15
^bb17:
%192 = arith.constant 1 : i32
%193 = arith.addi %85, %192 : i32
llvm.store %193, %89 : i32, !llvm.ptr
cf.br ^bb30
^bb30:
%194 = llvm.load %89 : !llvm.ptr -> i32
%195 = arith.cmpi sle, %194, %arg0 : i32
cf.cond_br %195, ^bb31, ^bb32
^bb31:
%196 = arith.constant 1000000000000000052504760255204420248704468581108159154915854115511802457988908195786371375080447864043704443832883878176942523235360430575644792184786706982848387200926575803737830233794788090059368953234970799945081119038967640880074652742780142494579258788820056842838115669472196386865459400540160 : f32
%197 = arith.extf %196 : f32 to f64
%198 = llvm.mlir.constant(1 : i64) : i64
%199 = llvm.alloca %198 x f64 : (i64) -> !llvm.ptr
llvm.store %197, %199 : f64, !llvm.ptr
%200 = arith.constant 1 : i32
llvm.store %200, %46 : i32, !llvm.ptr
cf.br ^bb33
^bb33:
%201 = llvm.load %46 : !llvm.ptr -> i32
%202 = llvm.load %1 : !llvm.ptr -> i32
%203 = arith.cmpi sle, %201, %202 : i32
cf.cond_br %203, ^bb34, ^bb35
^bb34:
%204 = arith.constant 1.0 : f32
%206 = llvm.load %89 : !llvm.ptr -> i32
%207 = llvm.load %46 : !llvm.ptr -> i32
%208 = arith.subi %206, %207 : i32
%209 = arith.extsi %208 : i32 to i64
%210 = llvm.getelementptr %14[%209] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%205 = llvm.load %210 : !llvm.ptr -> f64
%212 = arith.extf %204 : f32 to f64
%211 = arith.addf %212, %205 : f64
%213 = arith.constant 1.0 : f32
%215 = llvm.load %46 : !llvm.ptr -> i32
%216 = arith.extsi %215 : i32 to i64
%217 = llvm.getelementptr %7[%216] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%214 = llvm.load %217 : !llvm.ptr -> f64
%219 = arith.extf %213 : f32 to f64
%218 = arith.subf %219, %214 : f64
%221 = llvm.load %46 : !llvm.ptr -> i32
%222 = arith.extsi %221 : i32 to i64
%223 = llvm.getelementptr %20[%222] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%220 = llvm.load %223 : !llvm.ptr -> f64
%224 = arith.mulf %218, %220 : f64
%225 = arith.addf %211, %224 : f64
%226 = llvm.load %199 : !llvm.ptr -> f64
%227 = arith.cmpf olt, %225, %226 : f64
cf.cond_br %227, ^bb36, ^bb37
^bb36:
llvm.store %225, %199 : f64, !llvm.ptr
cf.br ^bb38
^bb37:
cf.br ^bb38
^bb38:
%228 = llvm.load %46 : !llvm.ptr -> i32
%229 = arith.constant 1 : i32
%230 = arith.addi %228, %229 : i32
llvm.store %230, %46 : i32, !llvm.ptr
cf.br ^bb33
^bb35:
%231 = llvm.load %199 : !llvm.ptr -> f64
%232 = llvm.load %89 : !llvm.ptr -> i32
%233 = arith.extsi %232 : i32 to i64
%234 = llvm.getelementptr %14[%233] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %231, %234 : f64, !llvm.ptr
%235 = llvm.load %89 : !llvm.ptr -> i32
%236 = arith.constant 1 : i32
%237 = arith.addi %235, %236 : i32
llvm.store %237, %89 : i32, !llvm.ptr
cf.br ^bb30
^bb32:
%239 = arith.extsi %arg0 : i32 to i64
%240 = llvm.getelementptr %14[%239] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%238 = llvm.load %240 : !llvm.ptr -> f64
func.call @free(%20) : (!llvm.ptr) -> ()
func.call @free(%14) : (!llvm.ptr) -> ()
func.call @free(%7) : (!llvm.ptr) -> ()
func.return %238 : f64
}
func.func @main() -> i32 {
%244 = arith.constant 0.0 : f32
%245 = arith.extf %244 : f32 to f64
%246 = llvm.mlir.constant(1 : i64) : i64
%247 = llvm.alloca %246 x f64 : (i64) -> !llvm.ptr
llvm.store %245, %247 : f64, !llvm.ptr
%248 = arith.constant 1 : i32
%249 = llvm.mlir.constant(1 : i64) : i64
%250 = llvm.alloca %249 x i32 : (i64) -> !llvm.ptr
llvm.store %248, %250 : i32, !llvm.ptr
cf.br ^bb39
^bb39:
%251 = llvm.load %250 : !llvm.ptr -> i32
%252 = arith.constant 50 : i32
%253 = arith.cmpi sle, %251, %252 : i32
cf.cond_br %253, ^bb40, ^bb41
^bb40:
%254 = llvm.load %250 : !llvm.ptr -> i32
%255 = arith.sitofp %254 : i32 to f64
%256 = arith.constant 100.0 : f32
%258 = arith.extf %256 : f32 to f64
%257 = arith.divf %255, %258 : f64
%259 = llvm.load %247 : !llvm.ptr -> f64
%261 = arith.constant 10000 : i32
%262 = arith.constant 100 : i32
%260 = func.call @T(%261, %257, %262) : (i32, f64, i32) -> f64
%263 = arith.addf %259, %260 : f64
llvm.store %263, %247 : f64, !llvm.ptr
%264 = llvm.load %250 : !llvm.ptr -> i32
%265 = arith.constant 1 : i32
%266 = arith.addi %264, %265 : i32
llvm.store %266, %250 : i32, !llvm.ptr
cf.br ^bb39
^bb41:
%267 = llvm.mlir.addressof @str_0 : !llvm.ptr
%268 = llvm.load %247 : !llvm.ptr -> f64
%269 = llvm.call @printf(%267, %268) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, f64) -> i32
%270 = arith.constant 0 : i32
func.return %270 : i32
}
}