Problem 392

Minimal red area for N=400 enmeshed unit circle grid, 10 decimals.

Answer3.1486734435
Output3.1486734435
StatusPASS
Native helperno
Runtime0 ms
Peak memory1072 KB
Time complexityO(n) (estimated)
Space complexityO(n) (estimated)

Performance comparison

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

Flow source

# Project Euler 392
# Minimal red area for N=400 enmeshed unit circle grid, 10 decimals.

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

function f(x: f64) -> f64 {
    let v: f64 = 1.0 - x * x
    if v < 0.0 { v = 0.0 }
    return sqrt(v)
}

function end_x(m: i32, x1: f64) -> f64 {
    if !(x1 > 0.0 && x1 < 1.0) { return 1.0e300 }
    let mut x_cur: f64 = x1
    let mut g_prev: f64 = 1.0
    let mut k: i32 = 1
    while k < m {
        if x_cur <= 0.0 { return 1.0e300 }
        if x_cur >= 1.0 { return x_cur }
        let g_cur: f64 = f(x_cur)
        let x_next: f64 = x_cur + (g_prev - g_cur) * g_cur / x_cur
        if !(x_cur < x_next) { return 1.0e300 }
        x_cur = x_next
        g_prev = g_cur
        k = k + 1
    }
    return x_cur
}

function solve_quadrant(m: i32) -> f64 {
    let mut lo: f64 = 0.000001
    while end_x(m, lo) >= 1.0 {
        lo = lo * 0.5
        if lo < 1.0e-20 { return 0.0 }
    }
    let mut hi: f64 = 0.9
    while end_x(m, hi) <= 1.0 {
        hi = (hi + 1.0) / 2.0
        if hi >= 1.0 - 1.0e-15 { return 0.0 }
    }
    let mut it: i32 = 0
    while it < 200 {
        let mid: f64 = (lo + hi) / 2.0
        if end_x(m, mid) > 1.0 { hi = mid } else { lo = mid }
        it = it + 1
    }
    let x1: f64 = (lo + hi) / 2.0
    let xs: ptr<f64> = calloc((m + 1) as i64, 8)
    if xs == null { return 0.0 }
    xs[0] = 0.0
    xs[1] = x1
    let mut g_prev: f64 = 1.0
    let mut k: i32 = 1
    while k < m {
        let xk: f64 = xs[k]
        let gk: f64 = f(xk)
        xs[k + 1] = xk + (g_prev - gk) * gk / xk
        g_prev = gk
        k = k + 1
    }
    let mut area_q: f64 = 0.0
    let mut i: i32 = 0
    while i < m {
        let xi: f64 = xs[i]
        area_q = area_q + (xs[i + 1] - xi) * f(xi)
        i = i + 1
    }
    free(xs)
    return area_q
}

function main() -> i32 {
    let N: i32 = 400
    let m: i32 = N / 2 + 1
    let ans: f64 = 4.0 * solve_quadrant(m)
    printf("%.10f\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 f_f64(double x);
double end_x_i32_f64(int32_t m, double x1);
double solve_quadrant_i32(int32_t m);
int32_t main(void);




double f_f64(double x) {
    double v = (1.0 - (x * x));
    if (v < 0.0) {
        v = 0.0;
    }
    return sqrt(v);
}

double end_x_i32_f64(int32_t m, double x1) {
    if ((!((x1 > 0.0 && x1 < 1.0)))) {
        return 1.0e300;
    }
    double x_cur = x1;
    double g_prev = 1.0;
    int32_t k = 1;
    while (k < m) {
        if (x_cur <= 0.0) {
            return 1.0e300;
        }
        if (x_cur >= 1.0) {
            return x_cur;
        }
        double g_cur = f_f64(x_cur);
        double x_next = (x_cur + (((g_prev - g_cur) * g_cur) / x_cur));
        if ((!(x_cur < x_next))) {
            return 1.0e300;
        }
        x_cur = x_next;
        g_prev = g_cur;
        k = (k + 1);
    }
    return x_cur;
}

double solve_quadrant_i32(int32_t m) {
    double lo = 0.000001;
    while (end_x_i32_f64(m, lo) >= 1.0) {
        lo = (lo * 0.5);
        if (lo < 1.0e-20) {
            return 0.0;
        }
    }
    double hi = 0.9;
    while (end_x_i32_f64(m, hi) <= 1.0) {
        hi = ((hi + 1.0) / 2.0);
        if (hi >= (1.0 - 1.0e-15)) {
            return 0.0;
        }
    }
    int32_t it = 0;
    while (it < 200) {
        double mid = ((lo + hi) / 2.0);
        if (end_x_i32_f64(m, mid) > 1.0) {
            hi = mid;
        } else {
            lo = mid;
        }
        it = (it + 1);
    }
    double x1 = ((lo + hi) / 2.0);
    double* xs = (double*)(calloc(((int64_t)((m + 1))), 8));
    if (xs == NULL) {
        return 0.0;
    }
    xs[0] = 0.0;
    xs[1] = x1;
    double g_prev = 1.0;
    int32_t k = 1;
    while (k < m) {
        double xk = xs[k];
        double gk = f_f64(xk);
        xs[(k + 1)] = (xk + (((g_prev - gk) * gk) / xk));
        g_prev = gk;
        k = (k + 1);
    }
    double area_q = 0.0;
    int32_t i = 0;
    while (i < m) {
        double xi = xs[i];
        area_q = (area_q + ((xs[(i + 1)] - xi) * f_f64(xi)));
        i = (i + 1);
    }
    free(xs);
    return area_q;
}

int32_t main(void) {
    int32_t N = 400;
    int32_t m = (FLOW_CHECKED_DIV((N), (2)) + 1);
    double ans = (4.0 * solve_quadrant_i32(m));
    printf("%.10f\n", ans);
    return 0;
}

Generated MLIR

module {
  llvm.func @printf(!llvm.ptr, ...) -> i32
  llvm.mlir.global internal constant @str_0("%.10f\n\00") {addr_space = 0 : i32} : !llvm.array<7 x i8>
  func.func private @sqrt(f64) -> f64
  func.func private @calloc(i64, i64) -> !llvm.ptr
  func.func private @free(!llvm.ptr) -> ()
  func.func @f(%arg0: f64) -> f64 {
    %0 = arith.constant 1.0 : f32
    %1 = arith.mulf %arg0, %arg0 : f64
    %3 = arith.extf %0 : f32 to f64
    %2 = arith.subf %3, %1 : f64
    %4 = arith.constant 0.0 : f32
    %6 = arith.extf %4 : f32 to f64
    %5 = arith.cmpf olt, %2, %6 : f64
    %7 = scf.if %5 -> (f64) {
      %8 = arith.constant 0.0 : f32
      %9 = arith.extf %8 : f32 to f64
      scf.yield %9 : f64
    } else {
      scf.yield %2 : f64
    }
    %10 = math.sqrt %7 : f64
    func.return %10 : f64
  }
  func.func @end_x(%arg0: i32, %arg1: f64) -> f64 {
    %11 = arith.constant 0.0 : f32
    %13 = arith.extf %11 : f32 to f64
    %12 = arith.cmpf ogt, %arg1, %13 : f64
    %14 = scf.if %12 -> (i1) {
      %15 = arith.constant 1.0 : f32
      %17 = arith.extf %15 : f32 to f64
      %16 = arith.cmpf olt, %arg1, %17 : f64
      scf.yield %16 : i1
    } else {
      %18 = arith.constant false
      scf.yield %18 : i1
    }
    %20 = arith.constant 1 : i1
    %19 = arith.xori %14, %20 : i1
    cf.cond_br %19, ^bb0, ^bb1
    ^bb0:
      %22 = arith.constant 1000000000000000052504760255204420248704468581108159154915854115511802457988908195786371375080447864043704443832883878176942523235360430575644792184786706982848387200926575803737830233794788090059368953234970799945081119038967640880074652742780142494579258788820056842838115669472196386865459400540160 : f32
      %23 = arith.extf %22 : f32 to f64
      func.return %23 : f64
    ^bb1:
      cf.br ^bb2
    ^bb2:
    %24 = llvm.mlir.constant(1 : i64) : i64
    %25 = llvm.alloca %24 x f64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %25 : f64, !llvm.ptr
    %26 = arith.constant 1.0 : f32
    %27 = arith.extf %26 : f32 to f64
    %28 = llvm.mlir.constant(1 : i64) : i64
    %29 = llvm.alloca %28 x f64 : (i64) -> !llvm.ptr
    llvm.store %27, %29 : f64, !llvm.ptr
    %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
    cf.br ^bb3
    ^bb3:
    %33 = llvm.load %32 : !llvm.ptr -> i32
    %34 = arith.cmpi slt, %33, %arg0 : i32
    cf.cond_br %34, ^bb4, ^bb5
    ^bb4:
      %35 = llvm.load %25 : !llvm.ptr -> f64
      %36 = arith.constant 0.0 : f32
      %38 = arith.extf %36 : f32 to f64
      %37 = arith.cmpf ole, %35, %38 : f64
      cf.cond_br %37, ^bb6, ^bb7
      ^bb6:
        %39 = arith.constant 1000000000000000052504760255204420248704468581108159154915854115511802457988908195786371375080447864043704443832883878176942523235360430575644792184786706982848387200926575803737830233794788090059368953234970799945081119038967640880074652742780142494579258788820056842838115669472196386865459400540160 : f32
        %40 = arith.extf %39 : f32 to f64
        func.return %40 : f64
      ^bb7:
        cf.br ^bb8
      ^bb8:
      %41 = llvm.load %25 : !llvm.ptr -> f64
      %42 = arith.constant 1.0 : f32
      %44 = arith.extf %42 : f32 to f64
      %43 = arith.cmpf oge, %41, %44 : f64
      cf.cond_br %43, ^bb9, ^bb10
      ^bb9:
        %45 = llvm.load %25 : !llvm.ptr -> f64
        func.return %45 : f64
      ^bb10:
        cf.br ^bb11
      ^bb11:
      %47 = llvm.load %25 : !llvm.ptr -> f64
      %46 = func.call @f(%47) : (f64) -> f64
      %48 = llvm.load %25 : !llvm.ptr -> f64
      %49 = llvm.load %29 : !llvm.ptr -> f64
      %50 = arith.subf %49, %46 : f64
      %51 = arith.mulf %50, %46 : f64
      %52 = llvm.load %25 : !llvm.ptr -> f64
      %53 = arith.divf %51, %52 : f64
      %54 = arith.addf %48, %53 : f64
      %55 = llvm.load %25 : !llvm.ptr -> f64
      %56 = arith.cmpf olt, %55, %54 : f64
      %58 = arith.constant 1 : i1
      %57 = arith.xori %56, %58 : i1
      cf.cond_br %57, ^bb12, ^bb13
      ^bb12:
        %60 = arith.constant 1000000000000000052504760255204420248704468581108159154915854115511802457988908195786371375080447864043704443832883878176942523235360430575644792184786706982848387200926575803737830233794788090059368953234970799945081119038967640880074652742780142494579258788820056842838115669472196386865459400540160 : f32
        %61 = arith.extf %60 : f32 to f64
        func.return %61 : f64
      ^bb13:
        cf.br ^bb14
      ^bb14:
      llvm.store %54, %25 : f64, !llvm.ptr
      llvm.store %46, %29 : f64, !llvm.ptr
      %62 = llvm.load %32 : !llvm.ptr -> i32
      %63 = arith.constant 1 : i32
      %64 = arith.addi %62, %63 : i32
      llvm.store %64, %32 : i32, !llvm.ptr
      cf.br ^bb3
    ^bb5:
    %65 = llvm.load %25 : !llvm.ptr -> f64
    func.return %65 : f64
  }
  func.func @solve_quadrant(%arg0: i32) -> f64 {
    %66 = arith.constant 0.000001 : f32
    %67 = arith.extf %66 : f32 to f64
    %68 = llvm.mlir.constant(1 : i64) : i64
    %69 = llvm.alloca %68 x f64 : (i64) -> !llvm.ptr
    llvm.store %67, %69 : f64, !llvm.ptr
    cf.br ^bb15
    ^bb15:
    %71 = llvm.load %69 : !llvm.ptr -> f64
    %70 = func.call @end_x(%arg0, %71) : (i32, f64) -> f64
    %72 = arith.constant 1.0 : f32
    %74 = arith.extf %72 : f32 to f64
    %73 = arith.cmpf oge, %70, %74 : f64
    cf.cond_br %73, ^bb16, ^bb17
    ^bb16:
      %75 = llvm.load %69 : !llvm.ptr -> f64
      %76 = arith.constant 0.5 : f32
      %78 = arith.extf %76 : f32 to f64
      %77 = arith.mulf %75, %78 : f64
      llvm.store %77, %69 : f64, !llvm.ptr
      %79 = llvm.load %69 : !llvm.ptr -> f64
      %80 = arith.constant 0 : f32
      %82 = arith.extf %80 : f32 to f64
      %81 = arith.cmpf olt, %79, %82 : f64
      cf.cond_br %81, ^bb18, ^bb19
      ^bb18:
        %83 = arith.constant 0.0 : f32
        %84 = arith.extf %83 : f32 to f64
        func.return %84 : f64
      ^bb19:
        cf.br ^bb20
      ^bb20:
      cf.br ^bb15
    ^bb17:
    %85 = arith.constant 0.9 : f32
    %86 = arith.extf %85 : f32 to f64
    %87 = llvm.mlir.constant(1 : i64) : i64
    %88 = llvm.alloca %87 x f64 : (i64) -> !llvm.ptr
    llvm.store %86, %88 : f64, !llvm.ptr
    cf.br ^bb21
    ^bb21:
    %90 = llvm.load %88 : !llvm.ptr -> f64
    %89 = func.call @end_x(%arg0, %90) : (i32, f64) -> f64
    %91 = arith.constant 1.0 : f32
    %93 = arith.extf %91 : f32 to f64
    %92 = arith.cmpf ole, %89, %93 : f64
    cf.cond_br %92, ^bb22, ^bb23
    ^bb22:
      %94 = llvm.load %88 : !llvm.ptr -> f64
      %95 = arith.constant 1.0 : f32
      %97 = arith.extf %95 : f32 to f64
      %96 = arith.addf %94, %97 : f64
      %98 = arith.constant 2.0 : f32
      %100 = arith.extf %98 : f32 to f64
      %99 = arith.divf %96, %100 : f64
      llvm.store %99, %88 : f64, !llvm.ptr
      %101 = llvm.load %88 : !llvm.ptr -> f64
      %102 = arith.constant 1.0 : f32
      %103 = arith.constant 0 : f32
      %104 = arith.subf %102, %103 : f32
      %106 = arith.extf %104 : f32 to f64
      %105 = arith.cmpf oge, %101, %106 : f64
      cf.cond_br %105, ^bb24, ^bb25
      ^bb24:
        %107 = arith.constant 0.0 : f32
        %108 = arith.extf %107 : f32 to f64
        func.return %108 : f64
      ^bb25:
        cf.br ^bb26
      ^bb26:
      cf.br ^bb21
    ^bb23:
    %109 = arith.constant 0 : i32
    %110 = llvm.mlir.constant(1 : i64) : i64
    %111 = llvm.alloca %110 x i32 : (i64) -> !llvm.ptr
    llvm.store %109, %111 : i32, !llvm.ptr
    cf.br ^bb27
    ^bb27:
    %112 = llvm.load %111 : !llvm.ptr -> i32
    %113 = arith.constant 200 : i32
    %114 = arith.cmpi slt, %112, %113 : i32
    cf.cond_br %114, ^bb28, ^bb29
    ^bb28:
      %115 = llvm.load %69 : !llvm.ptr -> f64
      %116 = llvm.load %88 : !llvm.ptr -> f64
      %117 = arith.addf %115, %116 : f64
      %118 = arith.constant 2.0 : f32
      %120 = arith.extf %118 : f32 to f64
      %119 = arith.divf %117, %120 : f64
      %121 = func.call @end_x(%arg0, %119) : (i32, f64) -> f64
      %122 = arith.constant 1.0 : f32
      %124 = arith.extf %122 : f32 to f64
      %123 = arith.cmpf ogt, %121, %124 : f64
      cf.cond_br %123, ^bb30, ^bb31
      ^bb30:
        llvm.store %119, %88 : f64, !llvm.ptr
        cf.br ^bb32
      ^bb31:
        llvm.store %119, %69 : f64, !llvm.ptr
        cf.br ^bb32
      ^bb32:
      %125 = llvm.load %111 : !llvm.ptr -> i32
      %126 = arith.constant 1 : i32
      %127 = arith.addi %125, %126 : i32
      llvm.store %127, %111 : i32, !llvm.ptr
      cf.br ^bb27
    ^bb29:
    %128 = llvm.load %69 : !llvm.ptr -> f64
    %129 = llvm.load %88 : !llvm.ptr -> f64
    %130 = arith.addf %128, %129 : f64
    %131 = arith.constant 2.0 : f32
    %133 = arith.extf %131 : f32 to f64
    %132 = arith.divf %130, %133 : f64
    %135 = arith.constant 1 : i32
    %136 = arith.addi %arg0, %135 : i32
    %137 = arith.extsi %136 : i32 to i64
    %138 = arith.constant 8 : i32
    %139 = arith.extsi %138 : i32 to i64
    %134 = func.call @calloc(%137, %139) : (i64, i64) -> !llvm.ptr
    %140 = llvm.mlir.zero : !llvm.ptr
    %141 = llvm.icmp "eq" %134, %140 : !llvm.ptr
    cf.cond_br %141, ^bb33, ^bb34
    ^bb33:
      %142 = arith.constant 0.0 : f32
      %143 = arith.extf %142 : f32 to f64
      func.return %143 : f64
    ^bb34:
      cf.br ^bb35
    ^bb35:
    %144 = arith.constant 0.0 : f32
    %145 = arith.constant 0 : i32
    %146 = arith.extf %144 : f32 to f64
    %147 = arith.extsi %145 : i32 to i64
    %148 = llvm.getelementptr %134[%147] : (!llvm.ptr, i64) -> !llvm.ptr, f64
    llvm.store %146, %148 : f64, !llvm.ptr
    %149 = arith.constant 1 : i32
    %150 = arith.extsi %149 : i32 to i64
    %151 = llvm.getelementptr %134[%150] : (!llvm.ptr, i64) -> !llvm.ptr, f64
    llvm.store %132, %151 : f64, !llvm.ptr
    %152 = arith.constant 1.0 : f32
    %153 = arith.extf %152 : f32 to f64
    %154 = llvm.mlir.constant(1 : i64) : i64
    %155 = llvm.alloca %154 x f64 : (i64) -> !llvm.ptr
    llvm.store %153, %155 : f64, !llvm.ptr
    %156 = arith.constant 1 : i32
    %157 = llvm.mlir.constant(1 : i64) : i64
    %158 = llvm.alloca %157 x i32 : (i64) -> !llvm.ptr
    llvm.store %156, %158 : i32, !llvm.ptr
    cf.br ^bb36
    ^bb36:
    %159 = llvm.load %158 : !llvm.ptr -> i32
    %160 = arith.cmpi slt, %159, %arg0 : i32
    cf.cond_br %160, ^bb37, ^bb38
    ^bb37:
      %162 = llvm.load %158 : !llvm.ptr -> i32
      %163 = arith.extsi %162 : i32 to i64
      %164 = llvm.getelementptr %134[%163] : (!llvm.ptr, i64) -> !llvm.ptr, f64
      %161 = llvm.load %164 : !llvm.ptr -> f64
      %165 = func.call @f(%161) : (f64) -> f64
      %166 = llvm.load %155 : !llvm.ptr -> f64
      %167 = arith.subf %166, %165 : f64
      %168 = arith.mulf %167, %165 : f64
      %169 = arith.divf %168, %161 : f64
      %170 = arith.addf %161, %169 : f64
      %171 = llvm.load %158 : !llvm.ptr -> i32
      %172 = arith.constant 1 : i32
      %173 = arith.addi %171, %172 : i32
      %174 = arith.extsi %173 : i32 to i64
      %175 = llvm.getelementptr %134[%174] : (!llvm.ptr, i64) -> !llvm.ptr, f64
      llvm.store %170, %175 : f64, !llvm.ptr
      llvm.store %165, %155 : f64, !llvm.ptr
      %176 = llvm.load %158 : !llvm.ptr -> i32
      %177 = arith.constant 1 : i32
      %178 = arith.addi %176, %177 : i32
      llvm.store %178, %158 : i32, !llvm.ptr
      cf.br ^bb36
    ^bb38:
    %179 = arith.constant 0.0 : f32
    %180 = arith.extf %179 : f32 to f64
    %181 = llvm.mlir.constant(1 : i64) : i64
    %182 = llvm.alloca %181 x f64 : (i64) -> !llvm.ptr
    llvm.store %180, %182 : f64, !llvm.ptr
    %183 = arith.constant 0 : i32
    %184 = llvm.mlir.constant(1 : i64) : i64
    %185 = llvm.alloca %184 x i32 : (i64) -> !llvm.ptr
    llvm.store %183, %185 : i32, !llvm.ptr
    cf.br ^bb39
    ^bb39:
    %186 = llvm.load %185 : !llvm.ptr -> i32
    %187 = arith.cmpi slt, %186, %arg0 : i32
    cf.cond_br %187, ^bb40, ^bb41
    ^bb40:
      %189 = llvm.load %185 : !llvm.ptr -> i32
      %190 = arith.extsi %189 : i32 to i64
      %191 = llvm.getelementptr %134[%190] : (!llvm.ptr, i64) -> !llvm.ptr, f64
      %188 = llvm.load %191 : !llvm.ptr -> f64
      %192 = llvm.load %182 : !llvm.ptr -> f64
      %194 = llvm.load %185 : !llvm.ptr -> i32
      %195 = arith.constant 1 : i32
      %196 = arith.addi %194, %195 : i32
      %197 = arith.extsi %196 : i32 to i64
      %198 = llvm.getelementptr %134[%197] : (!llvm.ptr, i64) -> !llvm.ptr, f64
      %193 = llvm.load %198 : !llvm.ptr -> f64
      %199 = arith.subf %193, %188 : f64
      %200 = func.call @f(%188) : (f64) -> f64
      %201 = arith.mulf %199, %200 : f64
      %202 = arith.addf %192, %201 : f64
      llvm.store %202, %182 : f64, !llvm.ptr
      %203 = llvm.load %185 : !llvm.ptr -> i32
      %204 = arith.constant 1 : i32
      %205 = arith.addi %203, %204 : i32
      llvm.store %205, %185 : i32, !llvm.ptr
      cf.br ^bb39
    ^bb41:
    func.call @free(%134) : (!llvm.ptr) -> ()
    %207 = llvm.load %182 : !llvm.ptr -> f64
    func.return %207 : f64
  }
  func.func @main() -> i32 {
    %208 = arith.constant 400 : i32
    %209 = arith.constant 2 : i32
    %210 = arith.divsi %208, %209 : i32
    %211 = arith.constant 1 : i32
    %212 = arith.addi %210, %211 : i32
    %213 = arith.constant 4.0 : f32
    %214 = func.call @solve_quadrant(%212) : (i32) -> f64
    %216 = arith.extf %213 : f32 to f64
    %215 = arith.mulf %216, %214 : f64
    %217 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %218 = llvm.call @printf(%217, %215) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, f64) -> i32
    %219 = arith.constant 0 : i32
    func.return %219 : i32
  }
}