Problem 525
Rolling Ellipse — C(1,4)+C(3,4) via adaptive Simpson.
View problem on Project Euler
Performance comparison
| Metric | Our solution | Best known |
| Time complexity | O(n) | ? |
| Space complexity | O(n) | ? |
| Approach | Flow solution | Not curated |
| Verdict | Unknown |
Flow source
# Project Euler 525
# Rolling Ellipse — C(1,4)+C(3,4) via adaptive Simpson.
extern {
function sin(x: f64) -> f64
function cos(x: f64) -> f64
function atan2(y: f64, x: f64) -> f64
function sqrt(x: f64) -> f64
function hypot(x: f64, y: f64) -> f64
function fabs(x: f64) -> f64
function calloc(n: i64, size: i64) -> ptr<void>
function free(p: ptr<void>) -> void
}
const PI: f64 = 3.14159265358979323846
function speed(t: f64, a: f64, b: f64) -> f64 {
let s: f64 = sin(t)
let c: f64 = cos(t)
let denom: f64 = a * a * s * s + b * b * c * c
let d: f64 = sqrt(denom)
let theta: f64 = atan2(b * c, a * s) - PI
let thetap: f64 = -a * b / denom
let px: f64 = a * c
let py: f64 = b * s
let jx: f64 = -py
let jy: f64 = px
let ppx: f64 = -a * s
let ppy: f64 = b * c
let wx: f64 = thetap * jx + ppx
let wy: f64 = thetap * jy + ppy
let ct: f64 = cos(theta)
let st: f64 = sin(theta)
let rwx: f64 = wx * ct - wy * st
let rwy: f64 = wx * st + wy * ct
let dx: f64 = d - rwx
let dy: f64 = -rwy
return hypot(dx, dy)
}
function simpson(a0: f64, b0: f64, fa: f64, fm: f64, fb: f64) -> f64 {
return (b0 - a0) * (fa + 4.0 * fm + fb) / 6.0
}
function adaptive_simpson(a: f64, b: f64, ea: f64, eb: f64, eps: f64) -> f64 {
# iterative stack: a,b,fa,fm,fb,s,eps (7 doubles per frame)
let stack: ptr<f64> = calloc(7 * 10000, 8)
if stack == null { return 0.0 }
let fa: f64 = speed(a, ea, eb)
let fb: f64 = speed(b, ea, eb)
let m: f64 = (a + b) / 2.0
let fm: f64 = speed(m, ea, eb)
let whole: f64 = simpson(a, b, fa, fm, fb)
let mut sp: i64 = 0
stack[0] = a; stack[1] = b; stack[2] = fa; stack[3] = fm
stack[4] = fb; stack[5] = whole; stack[6] = eps
sp = 1
let mut total: f64 = 0.0
while sp > 0 {
sp = sp - 1
let base: i64 = sp * 7
let a1: f64 = stack[base]
let b1: f64 = stack[base + 1]
let fa1: f64 = stack[base + 2]
let fm1: f64 = stack[base + 3]
let fb1: f64 = stack[base + 4]
let s1: f64 = stack[base + 5]
let eps1: f64 = stack[base + 6]
let m1: f64 = (a1 + b1) / 2.0
let lm: f64 = (a1 + m1) / 2.0
let rm: f64 = (m1 + b1) / 2.0
let flm: f64 = speed(lm, ea, eb)
let frm: f64 = speed(rm, ea, eb)
let left: f64 = simpson(a1, m1, fa1, flm, fm1)
let right: f64 = simpson(m1, b1, fm1, frm, fb1)
if fabs((left + right) - s1) <= 15.0 * eps1 {
total = total + left + right + ((left + right) - s1) / 15.0
} else {
let e2: f64 = eps1 / 2.0
let b2: i64 = sp * 7
stack[b2] = m1; stack[b2 + 1] = b1; stack[b2 + 2] = fm1
stack[b2 + 3] = frm; stack[b2 + 4] = fb1; stack[b2 + 5] = right; stack[b2 + 6] = e2
sp = sp + 1
let b3: i64 = sp * 7
stack[b3] = a1; stack[b3 + 1] = m1; stack[b3 + 2] = fa1
stack[b3 + 3] = flm; stack[b3 + 4] = fm1; stack[b3 + 5] = left; stack[b3 + 6] = e2
sp = sp + 1
}
}
free(stack)
return total
}
function center_curve_length(a: f64, b: f64) -> f64 {
let t0: f64 = -PI / 2.0
let t1: f64 = t0 + 2.0 * PI
return adaptive_simpson(t0, t1, a, b, 1.0e-12)
}
function main() -> i32 {
let ans: f64 = center_curve_length(1.0, 4.0) + center_curve_length(3.0, 4.0)
printf("%.8f\n", ans)
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 atan2(double y, double x);
double hypot(double x, double y);
double speed_f64_f64_f64(double t, double a, double b);
double simpson_f64_f64_f64_f64_f64(double a0, double b0, double fa, double fm, double fb);
double adaptive_simpson_f64_f64_f64_f64_f64(double a, double b, double ea, double eb, double eps);
double center_curve_length_f64_f64(double a, double b);
int32_t main(void);
static const double PI = 3.14159265358979323846;
double speed_f64_f64_f64(double t, double a, double b) {
double s = sin(t);
double c = cos(t);
double denom = ((((a * a) * s) * s) + (((b * b) * c) * c));
double d = sqrt(denom);
double theta = (atan2((b * c), (a * s)) - PI);
double thetap = (((-a) * b) / denom);
double px = (a * c);
double py = (b * s);
double jx = (-py);
double jy = px;
double ppx = ((-a) * s);
double ppy = (b * c);
double wx = ((thetap * jx) + ppx);
double wy = ((thetap * jy) + ppy);
double ct = cos(theta);
double st = sin(theta);
double rwx = ((wx * ct) - (wy * st));
double rwy = ((wx * st) + (wy * ct));
double dx = (d - rwx);
double dy = (-rwy);
return hypot(dx, dy);
}
double simpson_f64_f64_f64_f64_f64(double a0, double b0, double fa, double fm, double fb) {
return (((b0 - a0) * ((fa + (4.0 * fm)) + fb)) / 6.0);
}
double adaptive_simpson_f64_f64_f64_f64_f64(double a, double b, double ea, double eb, double eps) {
double* stack = (double*)(calloc((7 * 10000), 8));
if (stack == NULL) {
return 0.0;
}
double fa = speed_f64_f64_f64(a, ea, eb);
double fb = speed_f64_f64_f64(b, ea, eb);
double m = ((a + b) / 2.0);
double fm = speed_f64_f64_f64(m, ea, eb);
double whole = simpson_f64_f64_f64_f64_f64(a, b, fa, fm, fb);
int64_t sp = 0;
stack[0] = a;
stack[1] = b;
stack[2] = fa;
stack[3] = fm;
stack[4] = fb;
stack[5] = whole;
stack[6] = eps;
sp = 1;
double total = 0.0;
while (sp > 0) {
sp = (sp - 1);
int64_t base = (sp * 7);
double a1 = stack[base];
double b1 = stack[(base + 1)];
double fa1 = stack[(base + 2)];
double fm1 = stack[(base + 3)];
double fb1 = stack[(base + 4)];
double s1 = stack[(base + 5)];
double eps1 = stack[(base + 6)];
double m1 = ((a1 + b1) / 2.0);
double lm = ((a1 + m1) / 2.0);
double rm = ((m1 + b1) / 2.0);
double flm = speed_f64_f64_f64(lm, ea, eb);
double frm = speed_f64_f64_f64(rm, ea, eb);
double left = simpson_f64_f64_f64_f64_f64(a1, m1, fa1, flm, fm1);
double right = simpson_f64_f64_f64_f64_f64(m1, b1, fm1, frm, fb1);
if (fabs(((left + right) - s1)) <= (15.0 * eps1)) {
total = (((total + left) + right) + (((left + right) - s1) / 15.0));
} else {
double e2 = (eps1 / 2.0);
int64_t b2 = (sp * 7);
stack[b2] = m1;
stack[(b2 + 1)] = b1;
stack[(b2 + 2)] = fm1;
stack[(b2 + 3)] = frm;
stack[(b2 + 4)] = fb1;
stack[(b2 + 5)] = right;
stack[(b2 + 6)] = e2;
sp = (sp + 1);
int64_t b3 = (sp * 7);
stack[b3] = a1;
stack[(b3 + 1)] = m1;
stack[(b3 + 2)] = fa1;
stack[(b3 + 3)] = flm;
stack[(b3 + 4)] = fm1;
stack[(b3 + 5)] = left;
stack[(b3 + 6)] = e2;
sp = (sp + 1);
}
}
free(stack);
return total;
}
double center_curve_length_f64_f64(double a, double b) {
double t0 = ((-PI) / 2.0);
double t1 = (t0 + (2.0 * PI));
return adaptive_simpson_f64_f64_f64_f64_f64(t0, t1, a, b, 1.0e-12);
}
int32_t main(void) {
double ans = (center_curve_length_f64_f64(1.0, 4.0) + center_curve_length_f64_f64(3.0, 4.0));
printf("%.8f\n", ans);
return 0;
}
Generated MLIR
module {
llvm.func @printf(!llvm.ptr, ...) -> i32
llvm.mlir.global internal constant @str_0("%.8f\n\00") {addr_space = 0 : i32} : !llvm.array<6 x i8>
func.func private @sin(f64) -> f64
func.func private @cos(f64) -> f64
func.func private @atan2(f64, f64) -> f64
func.func private @sqrt(f64) -> f64
func.func private @hypot(f64, f64) -> f64
func.func private @fabs(f64) -> f64
func.func private @calloc(i64, i64) -> !llvm.ptr
func.func private @free(!llvm.ptr) -> ()
// Constant: PI
llvm.mlir.global internal constant @PI(3.14159265358979323846 : f64) : f64
func.func @speed(%arg0: f64, %arg1: f64, %arg2: f64) -> f64 {
%0 = math.sin %arg0 : f64
%1 = math.cos %arg0 : f64
%2 = arith.mulf %arg1, %arg1 : f64
%3 = arith.mulf %2, %0 : f64
%4 = arith.mulf %3, %0 : f64
%5 = arith.mulf %arg2, %arg2 : f64
%6 = arith.mulf %5, %1 : f64
%7 = arith.mulf %6, %1 : f64
%8 = arith.addf %4, %7 : f64
%9 = math.sqrt %8 : f64
%11 = arith.mulf %arg2, %1 : f64
%12 = arith.mulf %arg1, %0 : f64
%10 = func.call @atan2(%11, %12) : (f64, f64) -> f64
%13 = llvm.mlir.addressof @PI : !llvm.ptr
%14 = llvm.load %13 : !llvm.ptr -> f64
%15 = arith.subf %10, %14 : f64
%16 = arith.negf %arg1 : f64
%17 = arith.mulf %16, %arg2 : f64
%18 = arith.divf %17, %8 : f64
%19 = arith.mulf %arg1, %1 : f64
%20 = arith.mulf %arg2, %0 : f64
%21 = arith.negf %20 : f64
%22 = arith.negf %arg1 : f64
%23 = arith.mulf %22, %0 : f64
%24 = arith.mulf %arg2, %1 : f64
%25 = arith.mulf %18, %21 : f64
%26 = arith.addf %25, %23 : f64
%27 = arith.mulf %18, %19 : f64
%28 = arith.addf %27, %24 : f64
%29 = math.cos %15 : f64
%30 = math.sin %15 : f64
%31 = arith.mulf %26, %29 : f64
%32 = arith.mulf %28, %30 : f64
%33 = arith.subf %31, %32 : f64
%34 = arith.mulf %26, %30 : f64
%35 = arith.mulf %28, %29 : f64
%36 = arith.addf %34, %35 : f64
%37 = arith.subf %9, %33 : f64
%38 = arith.negf %36 : f64
%39 = func.call @hypot(%37, %38) : (f64, f64) -> f64
func.return %39 : f64
}
func.func @simpson(%arg0: f64, %arg1: f64, %arg2: f64, %arg3: f64, %arg4: f64) -> f64 {
%40 = arith.subf %arg1, %arg0 : f64
%41 = arith.constant 4.0 : f32
%43 = arith.extf %41 : f32 to f64
%42 = arith.mulf %43, %arg3 : f64
%44 = arith.addf %arg2, %42 : f64
%45 = arith.addf %44, %arg4 : f64
%46 = arith.mulf %40, %45 : f64
%47 = arith.constant 6.0 : f32
%49 = arith.extf %47 : f32 to f64
%48 = arith.divf %46, %49 : f64
func.return %48 : f64
}
func.func @adaptive_simpson(%arg0: f64, %arg1: f64, %arg2: f64, %arg3: f64, %arg4: f64) -> f64 {
%51 = arith.constant 7 : i32
%52 = arith.constant 10000 : i32
%53 = arith.muli %51, %52 : i32
%54 = arith.constant 8 : i32
%55 = arith.extsi %53 : i32 to i64
%56 = arith.extsi %54 : i32 to i64
%50 = func.call @calloc(%55, %56) : (i64, i64) -> !llvm.ptr
%57 = llvm.mlir.zero : !llvm.ptr
%58 = llvm.icmp "eq" %50, %57 : !llvm.ptr
cf.cond_br %58, ^bb0, ^bb1
^bb0:
%59 = arith.constant 0.0 : f32
%60 = arith.extf %59 : f32 to f64
func.return %60 : f64
^bb1:
cf.br ^bb2
^bb2:
%61 = func.call @speed(%arg0, %arg2, %arg3) : (f64, f64, f64) -> f64
%62 = func.call @speed(%arg1, %arg2, %arg3) : (f64, f64, f64) -> f64
%63 = arith.addf %arg0, %arg1 : f64
%64 = arith.constant 2.0 : f32
%66 = arith.extf %64 : f32 to f64
%65 = arith.divf %63, %66 : f64
%67 = func.call @speed(%65, %arg2, %arg3) : (f64, f64, f64) -> f64
%68 = func.call @simpson(%arg0, %arg1, %61, %67, %62) : (f64, f64, f64, f64, f64) -> f64
%69 = arith.constant 0 : i32
%70 = arith.extsi %69 : i32 to i64
%71 = llvm.mlir.constant(1 : i64) : i64
%72 = llvm.alloca %71 x i64 : (i64) -> !llvm.ptr
llvm.store %70, %72 : i64, !llvm.ptr
%73 = arith.constant 0 : i32
%74 = arith.extsi %73 : i32 to i64
%75 = llvm.getelementptr %50[%74] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %arg0, %75 : f64, !llvm.ptr
%76 = arith.constant 1 : i32
%77 = arith.extsi %76 : i32 to i64
%78 = llvm.getelementptr %50[%77] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %arg1, %78 : f64, !llvm.ptr
%79 = arith.constant 2 : i32
%80 = arith.extsi %79 : i32 to i64
%81 = llvm.getelementptr %50[%80] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %61, %81 : f64, !llvm.ptr
%82 = arith.constant 3 : i32
%83 = arith.extsi %82 : i32 to i64
%84 = llvm.getelementptr %50[%83] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %67, %84 : f64, !llvm.ptr
%85 = arith.constant 4 : i32
%86 = arith.extsi %85 : i32 to i64
%87 = llvm.getelementptr %50[%86] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %62, %87 : f64, !llvm.ptr
%88 = arith.constant 5 : i32
%89 = arith.extsi %88 : i32 to i64
%90 = llvm.getelementptr %50[%89] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %68, %90 : f64, !llvm.ptr
%91 = arith.constant 6 : i32
%92 = arith.extsi %91 : i32 to i64
%93 = llvm.getelementptr %50[%92] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %arg4, %93 : f64, !llvm.ptr
%94 = arith.constant 1 : i32
%95 = arith.extsi %94 : i32 to i64
llvm.store %95, %72 : i64, !llvm.ptr
%96 = arith.constant 0.0 : f32
%97 = arith.extf %96 : f32 to f64
%98 = llvm.mlir.constant(1 : i64) : i64
%99 = llvm.alloca %98 x f64 : (i64) -> !llvm.ptr
llvm.store %97, %99 : f64, !llvm.ptr
cf.br ^bb3
^bb3:
%100 = llvm.load %72 : !llvm.ptr -> i64
%101 = arith.constant 0 : i32
%103 = arith.extsi %101 : i32 to i64
%102 = arith.cmpi sgt, %100, %103 : i64
cf.cond_br %102, ^bb4, ^bb5
^bb4:
%104 = llvm.load %72 : !llvm.ptr -> i64
%105 = arith.constant 1 : i32
%107 = arith.extsi %105 : i32 to i64
%106 = arith.subi %104, %107 : i64
llvm.store %106, %72 : i64, !llvm.ptr
%108 = llvm.load %72 : !llvm.ptr -> i64
%109 = arith.constant 7 : i32
%111 = arith.extsi %109 : i32 to i64
%110 = arith.muli %108, %111 : i64
%113 = llvm.getelementptr %50[%110] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%112 = llvm.load %113 : !llvm.ptr -> f64
%115 = arith.constant 1 : i32
%117 = arith.extsi %115 : i32 to i64
%116 = arith.addi %110, %117 : i64
%118 = llvm.getelementptr %50[%116] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%114 = llvm.load %118 : !llvm.ptr -> f64
%120 = arith.constant 2 : i32
%122 = arith.extsi %120 : i32 to i64
%121 = arith.addi %110, %122 : i64
%123 = llvm.getelementptr %50[%121] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%119 = llvm.load %123 : !llvm.ptr -> f64
%125 = arith.constant 3 : i32
%127 = arith.extsi %125 : i32 to i64
%126 = arith.addi %110, %127 : i64
%128 = llvm.getelementptr %50[%126] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%124 = llvm.load %128 : !llvm.ptr -> f64
%130 = arith.constant 4 : i32
%132 = arith.extsi %130 : i32 to i64
%131 = arith.addi %110, %132 : i64
%133 = llvm.getelementptr %50[%131] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%129 = llvm.load %133 : !llvm.ptr -> f64
%135 = arith.constant 5 : i32
%137 = arith.extsi %135 : i32 to i64
%136 = arith.addi %110, %137 : i64
%138 = llvm.getelementptr %50[%136] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%134 = llvm.load %138 : !llvm.ptr -> f64
%140 = arith.constant 6 : i32
%142 = arith.extsi %140 : i32 to i64
%141 = arith.addi %110, %142 : i64
%143 = llvm.getelementptr %50[%141] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%139 = llvm.load %143 : !llvm.ptr -> f64
%144 = arith.addf %112, %114 : f64
%145 = arith.constant 2.0 : f32
%147 = arith.extf %145 : f32 to f64
%146 = arith.divf %144, %147 : f64
%148 = arith.addf %112, %146 : f64
%149 = arith.constant 2.0 : f32
%151 = arith.extf %149 : f32 to f64
%150 = arith.divf %148, %151 : f64
%152 = arith.addf %146, %114 : f64
%153 = arith.constant 2.0 : f32
%155 = arith.extf %153 : f32 to f64
%154 = arith.divf %152, %155 : f64
%156 = func.call @speed(%150, %arg2, %arg3) : (f64, f64, f64) -> f64
%157 = func.call @speed(%154, %arg2, %arg3) : (f64, f64, f64) -> f64
%158 = func.call @simpson(%112, %146, %119, %156, %124) : (f64, f64, f64, f64, f64) -> f64
%159 = func.call @simpson(%146, %114, %124, %157, %129) : (f64, f64, f64, f64, f64) -> f64
%160 = arith.addf %158, %159 : f64
%161 = arith.subf %160, %134 : f64
%162 = math.absf %161 : f64
%163 = arith.constant 15.0 : f32
%165 = arith.extf %163 : f32 to f64
%164 = arith.mulf %165, %139 : f64
%166 = arith.cmpf ole, %162, %164 : f64
cf.cond_br %166, ^bb6, ^bb7
^bb6:
%167 = llvm.load %99 : !llvm.ptr -> f64
%168 = arith.addf %167, %158 : f64
%169 = arith.addf %168, %159 : f64
%170 = arith.addf %158, %159 : f64
%171 = arith.subf %170, %134 : f64
%172 = arith.constant 15.0 : f32
%174 = arith.extf %172 : f32 to f64
%173 = arith.divf %171, %174 : f64
%175 = arith.addf %169, %173 : f64
llvm.store %175, %99 : f64, !llvm.ptr
cf.br ^bb8
^bb7:
%176 = arith.constant 2.0 : f32
%178 = arith.extf %176 : f32 to f64
%177 = arith.divf %139, %178 : f64
%179 = llvm.load %72 : !llvm.ptr -> i64
%180 = arith.constant 7 : i32
%182 = arith.extsi %180 : i32 to i64
%181 = arith.muli %179, %182 : i64
%183 = llvm.getelementptr %50[%181] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %146, %183 : f64, !llvm.ptr
%184 = arith.constant 1 : i32
%186 = arith.extsi %184 : i32 to i64
%185 = arith.addi %181, %186 : i64
%187 = llvm.getelementptr %50[%185] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %114, %187 : f64, !llvm.ptr
%188 = arith.constant 2 : i32
%190 = arith.extsi %188 : i32 to i64
%189 = arith.addi %181, %190 : i64
%191 = llvm.getelementptr %50[%189] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %124, %191 : f64, !llvm.ptr
%192 = arith.constant 3 : i32
%194 = arith.extsi %192 : i32 to i64
%193 = arith.addi %181, %194 : i64
%195 = llvm.getelementptr %50[%193] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %157, %195 : f64, !llvm.ptr
%196 = arith.constant 4 : i32
%198 = arith.extsi %196 : i32 to i64
%197 = arith.addi %181, %198 : i64
%199 = llvm.getelementptr %50[%197] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %129, %199 : f64, !llvm.ptr
%200 = arith.constant 5 : i32
%202 = arith.extsi %200 : i32 to i64
%201 = arith.addi %181, %202 : i64
%203 = llvm.getelementptr %50[%201] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %159, %203 : f64, !llvm.ptr
%204 = arith.constant 6 : i32
%206 = arith.extsi %204 : i32 to i64
%205 = arith.addi %181, %206 : i64
%207 = llvm.getelementptr %50[%205] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %177, %207 : f64, !llvm.ptr
%208 = llvm.load %72 : !llvm.ptr -> i64
%209 = arith.constant 1 : i32
%211 = arith.extsi %209 : i32 to i64
%210 = arith.addi %208, %211 : i64
llvm.store %210, %72 : i64, !llvm.ptr
%212 = llvm.load %72 : !llvm.ptr -> i64
%213 = arith.constant 7 : i32
%215 = arith.extsi %213 : i32 to i64
%214 = arith.muli %212, %215 : i64
%216 = llvm.getelementptr %50[%214] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %112, %216 : f64, !llvm.ptr
%217 = arith.constant 1 : i32
%219 = arith.extsi %217 : i32 to i64
%218 = arith.addi %214, %219 : i64
%220 = llvm.getelementptr %50[%218] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %146, %220 : f64, !llvm.ptr
%221 = arith.constant 2 : i32
%223 = arith.extsi %221 : i32 to i64
%222 = arith.addi %214, %223 : i64
%224 = llvm.getelementptr %50[%222] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %119, %224 : f64, !llvm.ptr
%225 = arith.constant 3 : i32
%227 = arith.extsi %225 : i32 to i64
%226 = arith.addi %214, %227 : i64
%228 = llvm.getelementptr %50[%226] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %156, %228 : f64, !llvm.ptr
%229 = arith.constant 4 : i32
%231 = arith.extsi %229 : i32 to i64
%230 = arith.addi %214, %231 : i64
%232 = llvm.getelementptr %50[%230] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %124, %232 : f64, !llvm.ptr
%233 = arith.constant 5 : i32
%235 = arith.extsi %233 : i32 to i64
%234 = arith.addi %214, %235 : i64
%236 = llvm.getelementptr %50[%234] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %158, %236 : f64, !llvm.ptr
%237 = arith.constant 6 : i32
%239 = arith.extsi %237 : i32 to i64
%238 = arith.addi %214, %239 : i64
%240 = llvm.getelementptr %50[%238] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %177, %240 : f64, !llvm.ptr
%241 = llvm.load %72 : !llvm.ptr -> i64
%242 = arith.constant 1 : i32
%244 = arith.extsi %242 : i32 to i64
%243 = arith.addi %241, %244 : i64
llvm.store %243, %72 : i64, !llvm.ptr
cf.br ^bb8
^bb8:
cf.br ^bb3
^bb5:
func.call @free(%50) : (!llvm.ptr) -> ()
%246 = llvm.load %99 : !llvm.ptr -> f64
func.return %246 : f64
}
func.func @center_curve_length(%arg0: f64, %arg1: f64) -> f64 {
%247 = llvm.mlir.addressof @PI : !llvm.ptr
%248 = llvm.load %247 : !llvm.ptr -> f64
%249 = arith.negf %248 : f64
%250 = arith.constant 2.0 : f32
%252 = arith.extf %250 : f32 to f64
%251 = arith.divf %249, %252 : f64
%253 = arith.constant 2.0 : f32
%254 = llvm.mlir.addressof @PI : !llvm.ptr
%255 = llvm.load %254 : !llvm.ptr -> f64
%257 = arith.extf %253 : f32 to f64
%256 = arith.mulf %257, %255 : f64
%258 = arith.addf %251, %256 : f64
%260 = arith.constant 0 : f32
%261 = arith.extf %260 : f32 to f64
%259 = func.call @adaptive_simpson(%251, %258, %arg0, %arg1, %261) : (f64, f64, f64, f64, f64) -> f64
func.return %259 : f64
}
func.func @main() -> i32 {
%263 = arith.constant 1.0 : f32
%264 = arith.constant 4.0 : f32
%265 = arith.extf %263 : f32 to f64
%266 = arith.extf %264 : f32 to f64
%262 = func.call @center_curve_length(%265, %266) : (f64, f64) -> f64
%268 = arith.constant 3.0 : f32
%269 = arith.constant 4.0 : f32
%270 = arith.extf %268 : f32 to f64
%271 = arith.extf %269 : f32 to f64
%267 = func.call @center_curve_length(%270, %271) : (f64, f64) -> f64
%272 = arith.addf %262, %267 : f64
%273 = llvm.mlir.addressof @str_0 : !llvm.ptr
%274 = llvm.call @printf(%273, %272) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, f64) -> i32
%275 = arith.constant 0 : i32
func.return %275 : i32
}
}