Problem 332

Sum of minimal spherical triangle areas A(r) for r=1..50.

Answer2717.751525
Output2717.751525
StatusPASS
Native helperno
Runtime70 ms
Peak memory2000 KB
Time complexityO(n^3) (estimated)
Space complexityO(n^2) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^3)O(n^2)
Space complexityO(n^2)O(n^2)
ApproachFlow solutionBottom-up DP
VerdictSuboptimal

Flow source

# Project Euler 332
# Sum of minimal spherical triangle areas A(r) for r=1..50.

import euler.nt { isqrt }

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

function gcd_abs(a0: i64, b0: i64) -> i64 {
    let mut a: i64 = a0
    let mut b: i64 = b0
    if a < 0 { a = -a }
    if b < 0 { b = -b }
    while b != 0 {
        let t: i64 = a % b
        a = b
        b = t
    }
    return a
}

function min_area(r: i64) -> f64 {
    let rr: i64 = r * r
    let xs: ptr<i16> = calloc(30000, 2)
    let ys: ptr<i16> = calloc(30000, 2)
    let zs: ptr<i16> = calloc(30000, 2)
    let mut n: i64 = 0
    let mut x: i64 = -r
    while x <= r {
        let x2: i64 = x * x
        let mut y: i64 = -r
        while y <= r {
            let z2: i64 = rr - x2 - y * y
            if z2 >= 0 {
                let z: i64 = isqrt(z2)
                if z * z == z2 {
                    xs[n] = x as i16; ys[n] = y as i16; zs[n] = z as i16; n = n + 1
                    if z != 0 {
                        xs[n] = x as i16; ys[n] = y as i16; zs[n] = (-z) as i16; n = n + 1
                    }
                }
            }
            y = y + 1
        }
        x = x + 1
    }
    if n < 3 { free(xs); free(ys); free(zs); return 0.0 }

    let dots: ptr<i16> = calloc(n * n, 2)
    let mut i: i64 = 0
    while i < n {
        let xi: i64 = xs[i] as i64
        let yi: i64 = ys[i] as i64
        let zi: i64 = zs[i] as i64
        let mut j: i64 = i
        while j < n {
            let v: i64 = xi * (xs[j] as i64) + yi * (ys[j] as i64) + zi * (zs[j] as i64)
            dots[i * n + j] = v as i16
            dots[j * n + i] = v as i16
            j = j + 1
        }
        i = i + 1
    }

    let r2: f64 = (rr) as f64
    let r3: f64 = r2 * (r as f64)
    let inv_r2: f64 = 1.0 / r2
    let inv_r3: f64 = 1.0 / r3
    let mut best: f64 = 1.5707963267948966 * r2
    let mut best_unit: f64 = best / r2
    let mut D_max: i64 = floor(4.0 * r3 * tan(best_unit / 2.0) + 0.000000000001) as i64
    if D_max < 1 { D_max = 1 }

    i = 0
    while i < n - 2 {
        let xi: i64 = xs[i] as i64
        let yi: i64 = ys[i] as i64
        let zi: i64 = zs[i] as i64
        let mut j: i64 = i + 1
        while j < n - 1 {
            let xj: i64 = xs[j] as i64
            let yj: i64 = ys[j] as i64
            let zj: i64 = zs[j] as i64
            let cx: i64 = yi * zj - zi * yj
            let cy: i64 = zi * xj - xi * zj
            let cz: i64 = xi * yj - yi * xj
            if cx != 0 || cy != 0 || cz != 0 {
                let g: i64 = gcd_abs(cx, gcd_abs(cy, cz))
                if g != 0 && g <= D_max {
                    let dot_ij: i64 = dots[i * n + j] as i64
                    let mut k: i64 = j + 1
                    while k < n {
                        let mut det: i64 = cx * (xs[k] as i64) + cy * (ys[k] as i64) + cz * (zs[k] as i64)
                        if det != 0 {
                            if det < 0 { det = -det }
                            if det <= D_max {
                                let denom: f64 = 1.0 + ((dot_ij + (dots[j * n + k] as i64) + (dots[i * n + k] as i64)) as f64) * inv_r2
                                let area: f64 = 2.0 * atan2((det as f64) * inv_r3, denom) * r2
                                if area < best {
                                    best = area
                                    best_unit = best / r2
                                    D_max = floor(4.0 * r3 * tan(best_unit / 2.0) + 0.000000000001) as i64
                                    if D_max < 1 { D_max = 1 }
                                }
                            }
                        }
                        k = k + 1
                    }
                }
            }
            j = j + 1
        }
        i = i + 1
    }
    free(xs); free(ys); free(zs); free(dots)
    return best
}

function main() -> i32 {
    let mut sum: f64 = 0.0
    let mut r: i64 = 1
    while r <= 50 {
        sum = sum + min_area(r)
        r = r + 1
    }
    printf("%.6f\n", sum)
    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; }

int64_t gcd_i64_i64(int64_t a0, int64_t b0);
int64_t lcm_i64_i64(int64_t a, int64_t b);
int64_t isqrt_i64(int64_t n);
int64_t mulmod_i64_i64_i64(int64_t a0, int64_t b0, int64_t mod);
int64_t mod_pow_i64_i64_i64(int64_t base, int64_t exp, int64_t mod);
bool is_prime_i64(int64_t n);
double atan2(double y, double x);
int64_t gcd_abs_i64_i64(int64_t a0, int64_t b0);
double min_area_i64(int64_t r);
int32_t main(void);

int64_t gcd_i64_i64(int64_t a0, int64_t b0) {
    int64_t a = a0;
    int64_t b = b0;
    while (b != 0) {
        int64_t t = FLOW_CHECKED_MOD((a), (b));
        a = b;
        b = t;
    }
    return a;
}

int64_t lcm_i64_i64(int64_t a, int64_t b) {
    if ((a == 0 || b == 0)) {
        return 0;
    }
    return (FLOW_CHECKED_DIV((a), (gcd_i64_i64(a, b))) * b);
}

int64_t isqrt_i64(int64_t n) {
    if (n < 2) {
        return n;
    }
    int64_t x = n;
    int64_t y = FLOW_CHECKED_DIV(((x + 1)), (2));
    while (y < x) {
        x = y;
        y = FLOW_CHECKED_DIV(((x + FLOW_CHECKED_DIV((n), (x)))), (2));
    }
    return x;
}

int64_t mulmod_i64_i64_i64(int64_t a0, int64_t b0, int64_t mod) {
    int64_t a = FLOW_CHECKED_MOD((a0), (mod));
    int64_t b = FLOW_CHECKED_MOD((b0), (mod));
    int64_t result = 0;
    while (b > 0) {
        if (FLOW_CHECKED_MOD((b), (2)) == 1) {
            result = FLOW_CHECKED_MOD(((result + a)), (mod));
        }
        a = FLOW_CHECKED_MOD(((a * 2)), (mod));
        b = FLOW_CHECKED_DIV((b), (2));
    }
    return result;
}

int64_t mod_pow_i64_i64_i64(int64_t base, int64_t exp, int64_t mod) {
    if (mod == 1) {
        return 0;
    }
    int64_t result = 1;
    int64_t b = FLOW_CHECKED_MOD((base), (mod));
    int64_t e = exp;
    while (e > 0) {
        if (FLOW_CHECKED_MOD((e), (2)) == 1) {
            result = mulmod_i64_i64_i64(result, b, mod);
        }
        b = mulmod_i64_i64_i64(b, b, mod);
        e = FLOW_CHECKED_DIV((e), (2));
    }
    return result;
}

bool is_prime_i64(int64_t n) {
    if (n < 2) {
        return 0;
    }
    if (n < 4) {
        return 1;
    }
    if ((FLOW_CHECKED_MOD((n), (2)) == 0 || FLOW_CHECKED_MOD((n), (3)) == 0)) {
        return 0;
    }
    int64_t i = 5;
    while ((i * i) <= n) {
        if ((FLOW_CHECKED_MOD((n), (i)) == 0 || FLOW_CHECKED_MOD((n), ((i + 2))) == 0)) {
            return 0;
        }
        i = (i + 6);
    }
    return 1;
}






int64_t gcd_abs_i64_i64(int64_t a0, int64_t b0) {
    int64_t a = a0;
    int64_t b = b0;
    if (a < 0) {
        a = (-a);
    }
    if (b < 0) {
        b = (-b);
    }
    while (b != 0) {
        int64_t t = FLOW_CHECKED_MOD((a), (b));
        a = b;
        b = t;
    }
    return a;
}

double min_area_i64(int64_t r) {
    int64_t rr = (r * r);
    int16_t* xs = (int16_t*)(calloc(30000, 2));
    int16_t* ys = (int16_t*)(calloc(30000, 2));
    int16_t* zs = (int16_t*)(calloc(30000, 2));
    int64_t n = 0;
    int64_t x = (-r);
    while (x <= r) {
        int64_t x2 = (x * x);
        int64_t y = (-r);
        while (y <= r) {
            int64_t z2 = ((rr - x2) - (y * y));
            if (z2 >= 0) {
                int64_t z = isqrt_i64(z2);
                if ((z * z) == z2) {
                    xs[n] = ((int16_t)(x));
                    ys[n] = ((int16_t)(y));
                    zs[n] = ((int16_t)(z));
                    n = (n + 1);
                    if (z != 0) {
                        xs[n] = ((int16_t)(x));
                        ys[n] = ((int16_t)(y));
                        zs[n] = ((int16_t)((-z)));
                        n = (n + 1);
                    }
                }
            }
            y = (y + 1);
        }
        x = (x + 1);
    }
    if (n < 3) {
        free(xs);
        free(ys);
        free(zs);
        return 0.0;
    }
    int16_t* dots = (int16_t*)(calloc((n * n), 2));
    int64_t i = 0;
    while (i < n) {
        int64_t xi = ((int64_t)(xs[i]));
        int64_t yi = ((int64_t)(ys[i]));
        int64_t zi = ((int64_t)(zs[i]));
        int64_t j = i;
        while (j < n) {
            int64_t v = (((xi * ((int64_t)(xs[j]))) + (yi * ((int64_t)(ys[j])))) + (zi * ((int64_t)(zs[j]))));
            dots[((i * n) + j)] = ((int16_t)(v));
            dots[((j * n) + i)] = ((int16_t)(v));
            j = (j + 1);
        }
        i = (i + 1);
    }
    double r2 = ((double)(rr));
    double r3 = (r2 * ((double)(r)));
    double inv_r2 = (1.0 / r2);
    double inv_r3 = (1.0 / r3);
    double best = (1.5707963267948966 * r2);
    double best_unit = (best / r2);
    int64_t D_max = ((int64_t)(floor((((4.0 * r3) * tan((best_unit / 2.0))) + 0.000000000001))));
    if (D_max < 1) {
        D_max = 1;
    }
    i = 0;
    while (i < (n - 2)) {
        int64_t xi = ((int64_t)(xs[i]));
        int64_t yi = ((int64_t)(ys[i]));
        int64_t zi = ((int64_t)(zs[i]));
        int64_t j = (i + 1);
        while (j < (n - 1)) {
            int64_t xj = ((int64_t)(xs[j]));
            int64_t yj = ((int64_t)(ys[j]));
            int64_t zj = ((int64_t)(zs[j]));
            int64_t cx = ((yi * zj) - (zi * yj));
            int64_t cy = ((zi * xj) - (xi * zj));
            int64_t cz = ((xi * yj) - (yi * xj));
            if (((cx != 0 || cy != 0) || cz != 0)) {
                int64_t g = gcd_abs_i64_i64(cx, gcd_abs_i64_i64(cy, cz));
                if ((g != 0 && g <= D_max)) {
                    int64_t dot_ij = ((int64_t)(dots[((i * n) + j)]));
                    int64_t k = (j + 1);
                    while (k < n) {
                        int64_t det = (((cx * ((int64_t)(xs[k]))) + (cy * ((int64_t)(ys[k])))) + (cz * ((int64_t)(zs[k]))));
                        if (det != 0) {
                            if (det < 0) {
                                det = (-det);
                            }
                            if (det <= D_max) {
                                double denom = (1.0 + (((double)(((dot_ij + ((int64_t)(dots[((j * n) + k)]))) + ((int64_t)(dots[((i * n) + k)]))))) * inv_r2));
                                double area = ((2.0 * atan2((((double)(det)) * inv_r3), denom)) * r2);
                                if (area < best) {
                                    best = area;
                                    best_unit = (best / r2);
                                    D_max = ((int64_t)(floor((((4.0 * r3) * tan((best_unit / 2.0))) + 0.000000000001))));
                                    if (D_max < 1) {
                                        D_max = 1;
                                    }
                                }
                            }
                        }
                        k = (k + 1);
                    }
                }
            }
            j = (j + 1);
        }
        i = (i + 1);
    }
    free(xs);
    free(ys);
    free(zs);
    free(dots);
    return best;
}

int32_t main(void) {
    double sum = 0.0;
    int64_t r = 1;
    while (r <= 50) {
        sum = (sum + min_area_i64(r));
        r = (r + 1);
    }
    printf("%.6f\n", sum);
    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 @gcd(%arg0: i64, %arg1: i64) -> i64 {
    %0 = llvm.mlir.constant(1 : i64) : i64
    %1 = llvm.alloca %0 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %1 : i64, !llvm.ptr
    %2 = llvm.mlir.constant(1 : i64) : i64
    %3 = llvm.alloca %2 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %3 : i64, !llvm.ptr
    cf.br ^bb0
    ^bb0:
    %4 = llvm.load %3 : !llvm.ptr -> i64
    %5 = arith.constant 0 : i32
    %7 = arith.extsi %5 : i32 to i64
    %6 = arith.cmpi ne, %4, %7 : i64
    cf.cond_br %6, ^bb1, ^bb2
    ^bb1:
      %8 = llvm.load %1 : !llvm.ptr -> i64
      %9 = llvm.load %3 : !llvm.ptr -> i64
      %10 = arith.remsi %8, %9 : i64
      %11 = llvm.load %3 : !llvm.ptr -> i64
      llvm.store %11, %1 : i64, !llvm.ptr
      llvm.store %10, %3 : i64, !llvm.ptr
      cf.br ^bb0
    ^bb2:
    %12 = llvm.load %1 : !llvm.ptr -> i64
    func.return %12 : i64
  }
  func.func @lcm(%arg0: i64, %arg1: i64) -> i64 {
    %13 = arith.constant 0 : i32
    %15 = arith.extsi %13 : i32 to i64
    %14 = arith.cmpi eq, %arg0, %15 : i64
    %16 = scf.if %14 -> (i1) {
      %17 = arith.constant true
      scf.yield %17 : i1
    } else {
      %18 = arith.constant 0 : i32
      %20 = arith.extsi %18 : i32 to i64
      %19 = arith.cmpi eq, %arg1, %20 : i64
      scf.yield %19 : i1
    }
    cf.cond_br %16, ^bb3, ^bb4
    ^bb3:
      %21 = arith.constant 0 : i32
      %22 = arith.extsi %21 : i32 to i64
      func.return %22 : i64
    ^bb4:
      cf.br ^bb5
    ^bb5:
    %23 = func.call @gcd(%arg0, %arg1) : (i64, i64) -> i64
    %24 = arith.divsi %arg0, %23 : i64
    %25 = arith.muli %24, %arg1 : i64
    func.return %25 : i64
  }
  func.func @isqrt(%arg0: i64) -> i64 {
    %26 = arith.constant 2 : i32
    %28 = arith.extsi %26 : i32 to i64
    %27 = arith.cmpi slt, %arg0, %28 : i64
    cf.cond_br %27, ^bb6, ^bb7
    ^bb6:
      func.return %arg0 : i64
    ^bb7:
      cf.br ^bb8
    ^bb8:
    %29 = llvm.mlir.constant(1 : i64) : i64
    %30 = llvm.alloca %29 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %30 : i64, !llvm.ptr
    %31 = llvm.load %30 : !llvm.ptr -> i64
    %32 = arith.constant 1 : i32
    %34 = arith.extsi %32 : i32 to i64
    %33 = arith.addi %31, %34 : i64
    %35 = arith.constant 2 : i32
    %37 = arith.extsi %35 : i32 to i64
    %36 = arith.divsi %33, %37 : i64
    %38 = llvm.mlir.constant(1 : i64) : i64
    %39 = llvm.alloca %38 x i64 : (i64) -> !llvm.ptr
    llvm.store %36, %39 : i64, !llvm.ptr
    cf.br ^bb9
    ^bb9:
    %40 = llvm.load %39 : !llvm.ptr -> i64
    %41 = llvm.load %30 : !llvm.ptr -> i64
    %42 = arith.cmpi slt, %40, %41 : i64
    cf.cond_br %42, ^bb10, ^bb11
    ^bb10:
      %43 = llvm.load %39 : !llvm.ptr -> i64
      llvm.store %43, %30 : i64, !llvm.ptr
      %44 = llvm.load %30 : !llvm.ptr -> i64
      %45 = llvm.load %30 : !llvm.ptr -> i64
      %46 = arith.divsi %arg0, %45 : i64
      %47 = arith.addi %44, %46 : i64
      %48 = arith.constant 2 : i32
      %50 = arith.extsi %48 : i32 to i64
      %49 = arith.divsi %47, %50 : i64
      llvm.store %49, %39 : i64, !llvm.ptr
      cf.br ^bb9
    ^bb11:
    %51 = llvm.load %30 : !llvm.ptr -> i64
    func.return %51 : i64
  }
  func.func @mulmod(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %52 = arith.remsi %arg0, %arg2 : i64
    %53 = llvm.mlir.constant(1 : i64) : i64
    %54 = llvm.alloca %53 x i64 : (i64) -> !llvm.ptr
    llvm.store %52, %54 : i64, !llvm.ptr
    %55 = arith.remsi %arg1, %arg2 : i64
    %56 = llvm.mlir.constant(1 : i64) : i64
    %57 = llvm.alloca %56 x i64 : (i64) -> !llvm.ptr
    llvm.store %55, %57 : i64, !llvm.ptr
    %58 = arith.constant 0 : i32
    %59 = arith.extsi %58 : i32 to i64
    %60 = llvm.mlir.constant(1 : i64) : i64
    %61 = llvm.alloca %60 x i64 : (i64) -> !llvm.ptr
    llvm.store %59, %61 : i64, !llvm.ptr
    cf.br ^bb12
    ^bb12:
    %62 = llvm.load %57 : !llvm.ptr -> i64
    %63 = arith.constant 0 : i32
    %65 = arith.extsi %63 : i32 to i64
    %64 = arith.cmpi sgt, %62, %65 : i64
    cf.cond_br %64, ^bb13, ^bb14
    ^bb13:
      %66 = llvm.load %57 : !llvm.ptr -> i64
      %67 = arith.constant 2 : i32
      %69 = arith.extsi %67 : i32 to i64
      %68 = arith.remsi %66, %69 : i64
      %70 = arith.constant 1 : i32
      %72 = arith.extsi %70 : i32 to i64
      %71 = arith.cmpi eq, %68, %72 : i64
      cf.cond_br %71, ^bb15, ^bb16
      ^bb15:
        %73 = llvm.load %61 : !llvm.ptr -> i64
        %74 = llvm.load %54 : !llvm.ptr -> i64
        %75 = arith.addi %73, %74 : i64
        %76 = arith.remsi %75, %arg2 : i64
        llvm.store %76, %61 : i64, !llvm.ptr
        cf.br ^bb17
      ^bb16:
        cf.br ^bb17
      ^bb17:
      %77 = llvm.load %54 : !llvm.ptr -> i64
      %78 = arith.constant 2 : i32
      %80 = arith.extsi %78 : i32 to i64
      %79 = arith.muli %77, %80 : i64
      %81 = arith.remsi %79, %arg2 : i64
      llvm.store %81, %54 : i64, !llvm.ptr
      %82 = llvm.load %57 : !llvm.ptr -> i64
      %83 = arith.constant 2 : i32
      %85 = arith.extsi %83 : i32 to i64
      %84 = arith.divsi %82, %85 : i64
      llvm.store %84, %57 : i64, !llvm.ptr
      cf.br ^bb12
    ^bb14:
    %86 = llvm.load %61 : !llvm.ptr -> i64
    func.return %86 : i64
  }
  func.func @mod_pow(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %87 = arith.constant 1 : i32
    %89 = arith.extsi %87 : i32 to i64
    %88 = arith.cmpi eq, %arg2, %89 : i64
    cf.cond_br %88, ^bb18, ^bb19
    ^bb18:
      %90 = arith.constant 0 : i32
      %91 = arith.extsi %90 : i32 to i64
      func.return %91 : i64
    ^bb19:
      cf.br ^bb20
    ^bb20:
    %92 = arith.constant 1 : i32
    %93 = arith.extsi %92 : i32 to i64
    %94 = llvm.mlir.constant(1 : i64) : i64
    %95 = llvm.alloca %94 x i64 : (i64) -> !llvm.ptr
    llvm.store %93, %95 : i64, !llvm.ptr
    %96 = arith.remsi %arg0, %arg2 : i64
    %97 = llvm.mlir.constant(1 : i64) : i64
    %98 = llvm.alloca %97 x i64 : (i64) -> !llvm.ptr
    llvm.store %96, %98 : i64, !llvm.ptr
    %99 = llvm.mlir.constant(1 : i64) : i64
    %100 = llvm.alloca %99 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %100 : i64, !llvm.ptr
    cf.br ^bb21
    ^bb21:
    %101 = llvm.load %100 : !llvm.ptr -> i64
    %102 = arith.constant 0 : i32
    %104 = arith.extsi %102 : i32 to i64
    %103 = arith.cmpi sgt, %101, %104 : i64
    cf.cond_br %103, ^bb22, ^bb23
    ^bb22:
      %105 = llvm.load %100 : !llvm.ptr -> i64
      %106 = arith.constant 2 : i32
      %108 = arith.extsi %106 : i32 to i64
      %107 = arith.remsi %105, %108 : i64
      %109 = arith.constant 1 : i32
      %111 = arith.extsi %109 : i32 to i64
      %110 = arith.cmpi eq, %107, %111 : i64
      cf.cond_br %110, ^bb24, ^bb25
      ^bb24:
        %113 = llvm.load %95 : !llvm.ptr -> i64
        %114 = llvm.load %98 : !llvm.ptr -> i64
        %112 = func.call @mulmod(%113, %114, %arg2) : (i64, i64, i64) -> i64
        llvm.store %112, %95 : i64, !llvm.ptr
        cf.br ^bb26
      ^bb25:
        cf.br ^bb26
      ^bb26:
      %116 = llvm.load %98 : !llvm.ptr -> i64
      %117 = llvm.load %98 : !llvm.ptr -> i64
      %115 = func.call @mulmod(%116, %117, %arg2) : (i64, i64, i64) -> i64
      llvm.store %115, %98 : i64, !llvm.ptr
      %118 = llvm.load %100 : !llvm.ptr -> i64
      %119 = arith.constant 2 : i32
      %121 = arith.extsi %119 : i32 to i64
      %120 = arith.divsi %118, %121 : i64
      llvm.store %120, %100 : i64, !llvm.ptr
      cf.br ^bb21
    ^bb23:
    %122 = llvm.load %95 : !llvm.ptr -> i64
    func.return %122 : i64
  }
  func.func @is_prime(%arg0: i64) -> i1 {
    %123 = arith.constant 2 : i32
    %125 = arith.extsi %123 : i32 to i64
    %124 = arith.cmpi slt, %arg0, %125 : i64
    cf.cond_br %124, ^bb27, ^bb28
    ^bb27:
      %126 = arith.constant 0 : i1
      func.return %126 : i1
    ^bb28:
      cf.br ^bb29
    ^bb29:
    %127 = arith.constant 4 : i32
    %129 = arith.extsi %127 : i32 to i64
    %128 = arith.cmpi slt, %arg0, %129 : i64
    cf.cond_br %128, ^bb30, ^bb31
    ^bb30:
      %130 = arith.constant 1 : i1
      func.return %130 : i1
    ^bb31:
      cf.br ^bb32
    ^bb32:
    %131 = arith.constant 2 : i32
    %133 = arith.extsi %131 : i32 to i64
    %132 = arith.remsi %arg0, %133 : i64
    %134 = arith.constant 0 : i32
    %136 = arith.extsi %134 : i32 to i64
    %135 = arith.cmpi eq, %132, %136 : i64
    %137 = scf.if %135 -> (i1) {
      %138 = arith.constant true
      scf.yield %138 : i1
    } else {
      %139 = arith.constant 3 : i32
      %141 = arith.extsi %139 : i32 to i64
      %140 = arith.remsi %arg0, %141 : i64
      %142 = arith.constant 0 : i32
      %144 = arith.extsi %142 : i32 to i64
      %143 = arith.cmpi eq, %140, %144 : i64
      scf.yield %143 : i1
    }
    cf.cond_br %137, ^bb33, ^bb34
    ^bb33:
      %145 = arith.constant 0 : i1
      func.return %145 : i1
    ^bb34:
      cf.br ^bb35
    ^bb35:
    %146 = arith.constant 5 : i32
    %147 = arith.extsi %146 : i32 to i64
    %148 = llvm.mlir.constant(1 : i64) : i64
    %149 = llvm.alloca %148 x i64 : (i64) -> !llvm.ptr
    llvm.store %147, %149 : i64, !llvm.ptr
    cf.br ^bb36
    ^bb36:
    %150 = llvm.load %149 : !llvm.ptr -> i64
    %151 = llvm.load %149 : !llvm.ptr -> i64
    %152 = arith.muli %150, %151 : i64
    %153 = arith.cmpi sle, %152, %arg0 : i64
    cf.cond_br %153, ^bb37, ^bb38
    ^bb37:
      %154 = llvm.load %149 : !llvm.ptr -> i64
      %155 = arith.remsi %arg0, %154 : i64
      %156 = arith.constant 0 : i32
      %158 = arith.extsi %156 : i32 to i64
      %157 = arith.cmpi eq, %155, %158 : i64
      %159 = scf.if %157 -> (i1) {
        %160 = arith.constant true
        scf.yield %160 : i1
      } else {
        %161 = llvm.load %149 : !llvm.ptr -> i64
        %162 = arith.constant 2 : i32
        %164 = arith.extsi %162 : i32 to i64
        %163 = arith.addi %161, %164 : i64
        %165 = arith.remsi %arg0, %163 : i64
        %166 = arith.constant 0 : i32
        %168 = arith.extsi %166 : i32 to i64
        %167 = arith.cmpi eq, %165, %168 : i64
        scf.yield %167 : i1
      }
      cf.cond_br %159, ^bb39, ^bb40
      ^bb39:
        %169 = arith.constant 0 : i1
        func.return %169 : i1
      ^bb40:
        cf.br ^bb41
      ^bb41:
      %170 = llvm.load %149 : !llvm.ptr -> i64
      %171 = arith.constant 6 : i32
      %173 = arith.extsi %171 : i32 to i64
      %172 = arith.addi %170, %173 : i64
      llvm.store %172, %149 : i64, !llvm.ptr
      cf.br ^bb36
    ^bb38:
    %174 = arith.constant 1 : i1
    func.return %174 : i1
  }
  func.func private @calloc(i64, i64) -> !llvm.ptr
  func.func private @free(!llvm.ptr) -> ()
  func.func private @atan2(f64, f64) -> f64
  func.func private @tan(f64) -> f64
  func.func private @floor(f64) -> f64
  func.func @gcd_abs(%arg0: i64, %arg1: i64) -> i64 {
    %175 = llvm.mlir.constant(1 : i64) : i64
    %176 = llvm.alloca %175 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %176 : i64, !llvm.ptr
    %177 = llvm.mlir.constant(1 : i64) : i64
    %178 = llvm.alloca %177 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %178 : i64, !llvm.ptr
    %179 = llvm.load %176 : !llvm.ptr -> i64
    %180 = arith.constant 0 : i32
    %182 = arith.extsi %180 : i32 to i64
    %181 = arith.cmpi slt, %179, %182 : i64
    cf.cond_br %181, ^bb42, ^bb43
    ^bb42:
      %183 = llvm.load %176 : !llvm.ptr -> i64
      %185 = arith.constant 0 : i64
      %184 = arith.subi %185, %183 : i64
      llvm.store %184, %176 : i64, !llvm.ptr
      cf.br ^bb44
    ^bb43:
      cf.br ^bb44
    ^bb44:
    %186 = llvm.load %178 : !llvm.ptr -> i64
    %187 = arith.constant 0 : i32
    %189 = arith.extsi %187 : i32 to i64
    %188 = arith.cmpi slt, %186, %189 : i64
    cf.cond_br %188, ^bb45, ^bb46
    ^bb45:
      %190 = llvm.load %178 : !llvm.ptr -> i64
      %192 = arith.constant 0 : i64
      %191 = arith.subi %192, %190 : i64
      llvm.store %191, %178 : i64, !llvm.ptr
      cf.br ^bb47
    ^bb46:
      cf.br ^bb47
    ^bb47:
    cf.br ^bb48
    ^bb48:
    %193 = llvm.load %178 : !llvm.ptr -> i64
    %194 = arith.constant 0 : i32
    %196 = arith.extsi %194 : i32 to i64
    %195 = arith.cmpi ne, %193, %196 : i64
    cf.cond_br %195, ^bb49, ^bb50
    ^bb49:
      %197 = llvm.load %176 : !llvm.ptr -> i64
      %198 = llvm.load %178 : !llvm.ptr -> i64
      %199 = arith.remsi %197, %198 : i64
      %200 = llvm.load %178 : !llvm.ptr -> i64
      llvm.store %200, %176 : i64, !llvm.ptr
      llvm.store %199, %178 : i64, !llvm.ptr
      cf.br ^bb48
    ^bb50:
    %201 = llvm.load %176 : !llvm.ptr -> i64
    func.return %201 : i64
  }
  func.func @min_area(%arg0: i64) -> f64 {
    %202 = arith.muli %arg0, %arg0 : i64
    %204 = arith.constant 30000 : i32
    %205 = arith.constant 2 : i32
    %206 = arith.extsi %204 : i32 to i64
    %207 = arith.extsi %205 : i32 to i64
    %203 = func.call @calloc(%206, %207) : (i64, i64) -> !llvm.ptr
    %209 = arith.constant 30000 : i32
    %210 = arith.constant 2 : i32
    %211 = arith.extsi %209 : i32 to i64
    %212 = arith.extsi %210 : i32 to i64
    %208 = func.call @calloc(%211, %212) : (i64, i64) -> !llvm.ptr
    %214 = arith.constant 30000 : i32
    %215 = arith.constant 2 : i32
    %216 = arith.extsi %214 : i32 to i64
    %217 = arith.extsi %215 : i32 to i64
    %213 = func.call @calloc(%216, %217) : (i64, i64) -> !llvm.ptr
    %218 = arith.constant 0 : i32
    %219 = arith.extsi %218 : i32 to i64
    %220 = llvm.mlir.constant(1 : i64) : i64
    %221 = llvm.alloca %220 x i64 : (i64) -> !llvm.ptr
    llvm.store %219, %221 : i64, !llvm.ptr
    %223 = arith.constant 0 : i64
    %222 = arith.subi %223, %arg0 : i64
    %224 = llvm.mlir.constant(1 : i64) : i64
    %225 = llvm.alloca %224 x i64 : (i64) -> !llvm.ptr
    llvm.store %222, %225 : i64, !llvm.ptr
    cf.br ^bb51
    ^bb51:
    %226 = llvm.load %225 : !llvm.ptr -> i64
    %227 = arith.cmpi sle, %226, %arg0 : i64
    cf.cond_br %227, ^bb52, ^bb53
    ^bb52:
      %228 = llvm.load %225 : !llvm.ptr -> i64
      %229 = llvm.load %225 : !llvm.ptr -> i64
      %230 = arith.muli %228, %229 : i64
      %232 = arith.constant 0 : i64
      %231 = arith.subi %232, %arg0 : i64
      %233 = llvm.mlir.constant(1 : i64) : i64
      %234 = llvm.alloca %233 x i64 : (i64) -> !llvm.ptr
      llvm.store %231, %234 : i64, !llvm.ptr
      cf.br ^bb54
      ^bb54:
      %235 = llvm.load %234 : !llvm.ptr -> i64
      %236 = arith.cmpi sle, %235, %arg0 : i64
      cf.cond_br %236, ^bb55, ^bb56
      ^bb55:
        %237 = arith.subi %202, %230 : i64
        %238 = llvm.load %234 : !llvm.ptr -> i64
        %239 = llvm.load %234 : !llvm.ptr -> i64
        %240 = arith.muli %238, %239 : i64
        %241 = arith.subi %237, %240 : i64
        %242 = arith.constant 0 : i32
        %244 = arith.extsi %242 : i32 to i64
        %243 = arith.cmpi sge, %241, %244 : i64
        cf.cond_br %243, ^bb57, ^bb58
        ^bb57:
          %245 = func.call @isqrt(%241) : (i64) -> i64
          %246 = arith.muli %245, %245 : i64
          %247 = arith.cmpi eq, %246, %241 : i64
          cf.cond_br %247, ^bb60, ^bb61
          ^bb60:
            %248 = llvm.load %225 : !llvm.ptr -> i64
            %249 = arith.trunci %248 : i64 to i16
            %250 = llvm.load %221 : !llvm.ptr -> i64
            %251 = llvm.getelementptr %203[%250] : (!llvm.ptr, i64) -> !llvm.ptr, i16
            llvm.store %249, %251 : i16, !llvm.ptr
            %252 = llvm.load %234 : !llvm.ptr -> i64
            %253 = arith.trunci %252 : i64 to i16
            %254 = llvm.load %221 : !llvm.ptr -> i64
            %255 = llvm.getelementptr %208[%254] : (!llvm.ptr, i64) -> !llvm.ptr, i16
            llvm.store %253, %255 : i16, !llvm.ptr
            %256 = arith.trunci %245 : i64 to i16
            %257 = llvm.load %221 : !llvm.ptr -> i64
            %258 = llvm.getelementptr %213[%257] : (!llvm.ptr, i64) -> !llvm.ptr, i16
            llvm.store %256, %258 : i16, !llvm.ptr
            %259 = llvm.load %221 : !llvm.ptr -> i64
            %260 = arith.constant 1 : i32
            %262 = arith.extsi %260 : i32 to i64
            %261 = arith.addi %259, %262 : i64
            llvm.store %261, %221 : i64, !llvm.ptr
            %263 = arith.constant 0 : i32
            %265 = arith.extsi %263 : i32 to i64
            %264 = arith.cmpi ne, %245, %265 : i64
            cf.cond_br %264, ^bb63, ^bb64
            ^bb63:
              %266 = llvm.load %225 : !llvm.ptr -> i64
              %267 = arith.trunci %266 : i64 to i16
              %268 = llvm.load %221 : !llvm.ptr -> i64
              %269 = llvm.getelementptr %203[%268] : (!llvm.ptr, i64) -> !llvm.ptr, i16
              llvm.store %267, %269 : i16, !llvm.ptr
              %270 = llvm.load %234 : !llvm.ptr -> i64
              %271 = arith.trunci %270 : i64 to i16
              %272 = llvm.load %221 : !llvm.ptr -> i64
              %273 = llvm.getelementptr %208[%272] : (!llvm.ptr, i64) -> !llvm.ptr, i16
              llvm.store %271, %273 : i16, !llvm.ptr
              %275 = arith.constant 0 : i64
              %274 = arith.subi %275, %245 : i64
              %276 = arith.trunci %274 : i64 to i16
              %277 = llvm.load %221 : !llvm.ptr -> i64
              %278 = llvm.getelementptr %213[%277] : (!llvm.ptr, i64) -> !llvm.ptr, i16
              llvm.store %276, %278 : i16, !llvm.ptr
              %279 = llvm.load %221 : !llvm.ptr -> i64
              %280 = arith.constant 1 : i32
              %282 = arith.extsi %280 : i32 to i64
              %281 = arith.addi %279, %282 : i64
              llvm.store %281, %221 : i64, !llvm.ptr
              cf.br ^bb65
            ^bb64:
              cf.br ^bb65
            ^bb65:
            cf.br ^bb62
          ^bb61:
            cf.br ^bb62
          ^bb62:
          cf.br ^bb59
        ^bb58:
          cf.br ^bb59
        ^bb59:
        %283 = llvm.load %234 : !llvm.ptr -> i64
        %284 = arith.constant 1 : i32
        %286 = arith.extsi %284 : i32 to i64
        %285 = arith.addi %283, %286 : i64
        llvm.store %285, %234 : i64, !llvm.ptr
        cf.br ^bb54
      ^bb56:
      %287 = llvm.load %225 : !llvm.ptr -> i64
      %288 = arith.constant 1 : i32
      %290 = arith.extsi %288 : i32 to i64
      %289 = arith.addi %287, %290 : i64
      llvm.store %289, %225 : i64, !llvm.ptr
      cf.br ^bb51
    ^bb53:
    %291 = llvm.load %221 : !llvm.ptr -> i64
    %292 = arith.constant 3 : i32
    %294 = arith.extsi %292 : i32 to i64
    %293 = arith.cmpi slt, %291, %294 : i64
    cf.cond_br %293, ^bb66, ^bb67
    ^bb66:
      func.call @free(%203) : (!llvm.ptr) -> ()
      func.call @free(%208) : (!llvm.ptr) -> ()
      func.call @free(%213) : (!llvm.ptr) -> ()
      %298 = arith.constant 0.0 : f32
      %299 = arith.extf %298 : f32 to f64
      func.return %299 : f64
    ^bb67:
      cf.br ^bb68
    ^bb68:
    %301 = llvm.load %221 : !llvm.ptr -> i64
    %302 = llvm.load %221 : !llvm.ptr -> i64
    %303 = arith.muli %301, %302 : i64
    %304 = arith.constant 2 : i32
    %305 = arith.extsi %304 : i32 to i64
    %300 = func.call @calloc(%303, %305) : (i64, i64) -> !llvm.ptr
    %306 = arith.constant 0 : i32
    %307 = arith.extsi %306 : i32 to i64
    %308 = llvm.mlir.constant(1 : i64) : i64
    %309 = llvm.alloca %308 x i64 : (i64) -> !llvm.ptr
    llvm.store %307, %309 : i64, !llvm.ptr
    cf.br ^bb69
    ^bb69:
    %310 = llvm.load %309 : !llvm.ptr -> i64
    %311 = llvm.load %221 : !llvm.ptr -> i64
    %312 = arith.cmpi slt, %310, %311 : i64
    cf.cond_br %312, ^bb70, ^bb71
    ^bb70:
      %314 = llvm.load %309 : !llvm.ptr -> i64
      %315 = llvm.getelementptr %203[%314] : (!llvm.ptr, i64) -> !llvm.ptr, i16
      %313 = llvm.load %315 : !llvm.ptr -> i16
      %316 = arith.extsi %313 : i16 to i64
      %318 = llvm.load %309 : !llvm.ptr -> i64
      %319 = llvm.getelementptr %208[%318] : (!llvm.ptr, i64) -> !llvm.ptr, i16
      %317 = llvm.load %319 : !llvm.ptr -> i16
      %320 = arith.extsi %317 : i16 to i64
      %322 = llvm.load %309 : !llvm.ptr -> i64
      %323 = llvm.getelementptr %213[%322] : (!llvm.ptr, i64) -> !llvm.ptr, i16
      %321 = llvm.load %323 : !llvm.ptr -> i16
      %324 = arith.extsi %321 : i16 to i64
      %325 = llvm.load %309 : !llvm.ptr -> i64
      %326 = llvm.mlir.constant(1 : i64) : i64
      %327 = llvm.alloca %326 x i64 : (i64) -> !llvm.ptr
      llvm.store %325, %327 : i64, !llvm.ptr
      cf.br ^bb72
      ^bb72:
      %328 = llvm.load %327 : !llvm.ptr -> i64
      %329 = llvm.load %221 : !llvm.ptr -> i64
      %330 = arith.cmpi slt, %328, %329 : i64
      cf.cond_br %330, ^bb73, ^bb74
      ^bb73:
        %332 = llvm.load %327 : !llvm.ptr -> i64
        %333 = llvm.getelementptr %203[%332] : (!llvm.ptr, i64) -> !llvm.ptr, i16
        %331 = llvm.load %333 : !llvm.ptr -> i16
        %334 = arith.extsi %331 : i16 to i64
        %335 = arith.muli %316, %334 : i64
        %337 = llvm.load %327 : !llvm.ptr -> i64
        %338 = llvm.getelementptr %208[%337] : (!llvm.ptr, i64) -> !llvm.ptr, i16
        %336 = llvm.load %338 : !llvm.ptr -> i16
        %339 = arith.extsi %336 : i16 to i64
        %340 = arith.muli %320, %339 : i64
        %341 = arith.addi %335, %340 : i64
        %343 = llvm.load %327 : !llvm.ptr -> i64
        %344 = llvm.getelementptr %213[%343] : (!llvm.ptr, i64) -> !llvm.ptr, i16
        %342 = llvm.load %344 : !llvm.ptr -> i16
        %345 = arith.extsi %342 : i16 to i64
        %346 = arith.muli %324, %345 : i64
        %347 = arith.addi %341, %346 : i64
        %348 = arith.trunci %347 : i64 to i16
        %349 = llvm.load %309 : !llvm.ptr -> i64
        %350 = llvm.load %221 : !llvm.ptr -> i64
        %351 = arith.muli %349, %350 : i64
        %352 = llvm.load %327 : !llvm.ptr -> i64
        %353 = arith.addi %351, %352 : i64
        %354 = llvm.getelementptr %300[%353] : (!llvm.ptr, i64) -> !llvm.ptr, i16
        llvm.store %348, %354 : i16, !llvm.ptr
        %355 = arith.trunci %347 : i64 to i16
        %356 = llvm.load %327 : !llvm.ptr -> i64
        %357 = llvm.load %221 : !llvm.ptr -> i64
        %358 = arith.muli %356, %357 : i64
        %359 = llvm.load %309 : !llvm.ptr -> i64
        %360 = arith.addi %358, %359 : i64
        %361 = llvm.getelementptr %300[%360] : (!llvm.ptr, i64) -> !llvm.ptr, i16
        llvm.store %355, %361 : i16, !llvm.ptr
        %362 = llvm.load %327 : !llvm.ptr -> i64
        %363 = arith.constant 1 : i32
        %365 = arith.extsi %363 : i32 to i64
        %364 = arith.addi %362, %365 : i64
        llvm.store %364, %327 : i64, !llvm.ptr
        cf.br ^bb72
      ^bb74:
      %366 = llvm.load %309 : !llvm.ptr -> i64
      %367 = arith.constant 1 : i32
      %369 = arith.extsi %367 : i32 to i64
      %368 = arith.addi %366, %369 : i64
      llvm.store %368, %309 : i64, !llvm.ptr
      cf.br ^bb69
    ^bb71:
    %370 = arith.sitofp %202 : i64 to f64
    %371 = arith.sitofp %arg0 : i64 to f64
    %372 = arith.mulf %370, %371 : f64
    %373 = arith.constant 1.0 : f32
    %375 = arith.extf %373 : f32 to f64
    %374 = arith.divf %375, %370 : f64
    %376 = arith.constant 1.0 : f32
    %378 = arith.extf %376 : f32 to f64
    %377 = arith.divf %378, %372 : f64
    %379 = arith.constant 1.5707963267948966 : f32
    %381 = arith.extf %379 : f32 to f64
    %380 = arith.mulf %381, %370 : f64
    %382 = llvm.mlir.constant(1 : i64) : i64
    %383 = llvm.alloca %382 x f64 : (i64) -> !llvm.ptr
    llvm.store %380, %383 : f64, !llvm.ptr
    %384 = llvm.load %383 : !llvm.ptr -> f64
    %385 = arith.divf %384, %370 : f64
    %386 = llvm.mlir.constant(1 : i64) : i64
    %387 = llvm.alloca %386 x f64 : (i64) -> !llvm.ptr
    llvm.store %385, %387 : f64, !llvm.ptr
    %389 = arith.constant 4.0 : f32
    %391 = arith.extf %389 : f32 to f64
    %390 = arith.mulf %391, %372 : f64
    %392 = llvm.load %387 : !llvm.ptr -> f64
    %393 = arith.constant 2.0 : f32
    %395 = arith.extf %393 : f32 to f64
    %394 = arith.divf %392, %395 : f64
    %396 = math.tan %394 : f64
    %397 = arith.mulf %390, %396 : f64
    %398 = arith.constant 0.000000000001 : f32
    %400 = arith.extf %398 : f32 to f64
    %399 = arith.addf %397, %400 : f64
    %388 = func.call @floor(%399) : (f64) -> f64
    %401 = arith.fptosi %388 : f64 to i64
    %402 = llvm.mlir.constant(1 : i64) : i64
    %403 = llvm.alloca %402 x i64 : (i64) -> !llvm.ptr
    llvm.store %401, %403 : i64, !llvm.ptr
    %404 = llvm.load %403 : !llvm.ptr -> i64
    %405 = arith.constant 1 : i32
    %407 = arith.extsi %405 : i32 to i64
    %406 = arith.cmpi slt, %404, %407 : i64
    cf.cond_br %406, ^bb75, ^bb76
    ^bb75:
      %408 = arith.constant 1 : i32
      %409 = arith.extsi %408 : i32 to i64
      llvm.store %409, %403 : i64, !llvm.ptr
      cf.br ^bb77
    ^bb76:
      cf.br ^bb77
    ^bb77:
    %410 = arith.constant 0 : i32
    %411 = arith.extsi %410 : i32 to i64
    llvm.store %411, %309 : i64, !llvm.ptr
    cf.br ^bb78
    ^bb78:
    %412 = llvm.load %309 : !llvm.ptr -> i64
    %413 = llvm.load %221 : !llvm.ptr -> i64
    %414 = arith.constant 2 : i32
    %416 = arith.extsi %414 : i32 to i64
    %415 = arith.subi %413, %416 : i64
    %417 = arith.cmpi slt, %412, %415 : i64
    cf.cond_br %417, ^bb79, ^bb80
    ^bb79:
      %419 = llvm.load %309 : !llvm.ptr -> i64
      %420 = llvm.getelementptr %203[%419] : (!llvm.ptr, i64) -> !llvm.ptr, i16
      %418 = llvm.load %420 : !llvm.ptr -> i16
      %421 = arith.extsi %418 : i16 to i64
      %423 = llvm.load %309 : !llvm.ptr -> i64
      %424 = llvm.getelementptr %208[%423] : (!llvm.ptr, i64) -> !llvm.ptr, i16
      %422 = llvm.load %424 : !llvm.ptr -> i16
      %425 = arith.extsi %422 : i16 to i64
      %427 = llvm.load %309 : !llvm.ptr -> i64
      %428 = llvm.getelementptr %213[%427] : (!llvm.ptr, i64) -> !llvm.ptr, i16
      %426 = llvm.load %428 : !llvm.ptr -> i16
      %429 = arith.extsi %426 : i16 to i64
      %430 = llvm.load %309 : !llvm.ptr -> i64
      %431 = arith.constant 1 : i32
      %433 = arith.extsi %431 : i32 to i64
      %432 = arith.addi %430, %433 : i64
      %434 = llvm.mlir.constant(1 : i64) : i64
      %435 = llvm.alloca %434 x i64 : (i64) -> !llvm.ptr
      llvm.store %432, %435 : i64, !llvm.ptr
      cf.br ^bb81
      ^bb81:
      %436 = llvm.load %435 : !llvm.ptr -> i64
      %437 = llvm.load %221 : !llvm.ptr -> i64
      %438 = arith.constant 1 : i32
      %440 = arith.extsi %438 : i32 to i64
      %439 = arith.subi %437, %440 : i64
      %441 = arith.cmpi slt, %436, %439 : i64
      cf.cond_br %441, ^bb82, ^bb83
      ^bb82:
        %443 = llvm.load %435 : !llvm.ptr -> i64
        %444 = llvm.getelementptr %203[%443] : (!llvm.ptr, i64) -> !llvm.ptr, i16
        %442 = llvm.load %444 : !llvm.ptr -> i16
        %445 = arith.extsi %442 : i16 to i64
        %447 = llvm.load %435 : !llvm.ptr -> i64
        %448 = llvm.getelementptr %208[%447] : (!llvm.ptr, i64) -> !llvm.ptr, i16
        %446 = llvm.load %448 : !llvm.ptr -> i16
        %449 = arith.extsi %446 : i16 to i64
        %451 = llvm.load %435 : !llvm.ptr -> i64
        %452 = llvm.getelementptr %213[%451] : (!llvm.ptr, i64) -> !llvm.ptr, i16
        %450 = llvm.load %452 : !llvm.ptr -> i16
        %453 = arith.extsi %450 : i16 to i64
        %454 = arith.muli %425, %453 : i64
        %455 = arith.muli %429, %449 : i64
        %456 = arith.subi %454, %455 : i64
        %457 = arith.muli %429, %445 : i64
        %458 = arith.muli %421, %453 : i64
        %459 = arith.subi %457, %458 : i64
        %460 = arith.muli %421, %449 : i64
        %461 = arith.muli %425, %445 : i64
        %462 = arith.subi %460, %461 : i64
        %463 = arith.constant 0 : i32
        %465 = arith.extsi %463 : i32 to i64
        %464 = arith.cmpi ne, %456, %465 : i64
        %466 = scf.if %464 -> (i1) {
          %467 = arith.constant true
          scf.yield %467 : i1
        } else {
          %468 = arith.constant 0 : i32
          %470 = arith.extsi %468 : i32 to i64
          %469 = arith.cmpi ne, %459, %470 : i64
          scf.yield %469 : i1
        }
        %471 = scf.if %466 -> (i1) {
          %472 = arith.constant true
          scf.yield %472 : i1
        } else {
          %473 = arith.constant 0 : i32
          %475 = arith.extsi %473 : i32 to i64
          %474 = arith.cmpi ne, %462, %475 : i64
          scf.yield %474 : i1
        }
        cf.cond_br %471, ^bb84, ^bb85
        ^bb84:
          %477 = func.call @gcd_abs(%459, %462) : (i64, i64) -> i64
          %476 = func.call @gcd_abs(%456, %477) : (i64, i64) -> i64
          %478 = arith.constant 0 : i32
          %480 = arith.extsi %478 : i32 to i64
          %479 = arith.cmpi ne, %476, %480 : i64
          %481 = scf.if %479 -> (i1) {
            %482 = llvm.load %403 : !llvm.ptr -> i64
            %483 = arith.cmpi sle, %476, %482 : i64
            scf.yield %483 : i1
          } else {
            %484 = arith.constant false
            scf.yield %484 : i1
          }
          cf.cond_br %481, ^bb87, ^bb88
          ^bb87:
            %486 = llvm.load %309 : !llvm.ptr -> i64
            %487 = llvm.load %221 : !llvm.ptr -> i64
            %488 = arith.muli %486, %487 : i64
            %489 = llvm.load %435 : !llvm.ptr -> i64
            %490 = arith.addi %488, %489 : i64
            %491 = llvm.getelementptr %300[%490] : (!llvm.ptr, i64) -> !llvm.ptr, i16
            %485 = llvm.load %491 : !llvm.ptr -> i16
            %492 = arith.extsi %485 : i16 to i64
            %493 = llvm.load %435 : !llvm.ptr -> i64
            %494 = arith.constant 1 : i32
            %496 = arith.extsi %494 : i32 to i64
            %495 = arith.addi %493, %496 : i64
            %497 = llvm.mlir.constant(1 : i64) : i64
            %498 = llvm.alloca %497 x i64 : (i64) -> !llvm.ptr
            llvm.store %495, %498 : i64, !llvm.ptr
            cf.br ^bb90
            ^bb90:
            %499 = llvm.load %498 : !llvm.ptr -> i64
            %500 = llvm.load %221 : !llvm.ptr -> i64
            %501 = arith.cmpi slt, %499, %500 : i64
            cf.cond_br %501, ^bb91, ^bb92
            ^bb91:
              %503 = llvm.load %498 : !llvm.ptr -> i64
              %504 = llvm.getelementptr %203[%503] : (!llvm.ptr, i64) -> !llvm.ptr, i16
              %502 = llvm.load %504 : !llvm.ptr -> i16
              %505 = arith.extsi %502 : i16 to i64
              %506 = arith.muli %456, %505 : i64
              %508 = llvm.load %498 : !llvm.ptr -> i64
              %509 = llvm.getelementptr %208[%508] : (!llvm.ptr, i64) -> !llvm.ptr, i16
              %507 = llvm.load %509 : !llvm.ptr -> i16
              %510 = arith.extsi %507 : i16 to i64
              %511 = arith.muli %459, %510 : i64
              %512 = arith.addi %506, %511 : i64
              %514 = llvm.load %498 : !llvm.ptr -> i64
              %515 = llvm.getelementptr %213[%514] : (!llvm.ptr, i64) -> !llvm.ptr, i16
              %513 = llvm.load %515 : !llvm.ptr -> i16
              %516 = arith.extsi %513 : i16 to i64
              %517 = arith.muli %462, %516 : i64
              %518 = arith.addi %512, %517 : i64
              %519 = llvm.mlir.constant(1 : i64) : i64
              %520 = llvm.alloca %519 x i64 : (i64) -> !llvm.ptr
              llvm.store %518, %520 : i64, !llvm.ptr
              %521 = llvm.load %520 : !llvm.ptr -> i64
              %522 = arith.constant 0 : i32
              %524 = arith.extsi %522 : i32 to i64
              %523 = arith.cmpi ne, %521, %524 : i64
              cf.cond_br %523, ^bb93, ^bb94
              ^bb93:
                %525 = llvm.load %520 : !llvm.ptr -> i64
                %526 = arith.constant 0 : i32
                %528 = arith.extsi %526 : i32 to i64
                %527 = arith.cmpi slt, %525, %528 : i64
                cf.cond_br %527, ^bb96, ^bb97
                ^bb96:
                  %529 = llvm.load %520 : !llvm.ptr -> i64
                  %531 = arith.constant 0 : i64
                  %530 = arith.subi %531, %529 : i64
                  llvm.store %530, %520 : i64, !llvm.ptr
                  cf.br ^bb98
                ^bb97:
                  cf.br ^bb98
                ^bb98:
                %532 = llvm.load %520 : !llvm.ptr -> i64
                %533 = llvm.load %403 : !llvm.ptr -> i64
                %534 = arith.cmpi sle, %532, %533 : i64
                cf.cond_br %534, ^bb99, ^bb100
                ^bb99:
                  %535 = arith.constant 1.0 : f32
                  %537 = llvm.load %435 : !llvm.ptr -> i64
                  %538 = llvm.load %221 : !llvm.ptr -> i64
                  %539 = arith.muli %537, %538 : i64
                  %540 = llvm.load %498 : !llvm.ptr -> i64
                  %541 = arith.addi %539, %540 : i64
                  %542 = llvm.getelementptr %300[%541] : (!llvm.ptr, i64) -> !llvm.ptr, i16
                  %536 = llvm.load %542 : !llvm.ptr -> i16
                  %543 = arith.extsi %536 : i16 to i64
                  %544 = arith.addi %492, %543 : i64
                  %546 = llvm.load %309 : !llvm.ptr -> i64
                  %547 = llvm.load %221 : !llvm.ptr -> i64
                  %548 = arith.muli %546, %547 : i64
                  %549 = llvm.load %498 : !llvm.ptr -> i64
                  %550 = arith.addi %548, %549 : i64
                  %551 = llvm.getelementptr %300[%550] : (!llvm.ptr, i64) -> !llvm.ptr, i16
                  %545 = llvm.load %551 : !llvm.ptr -> i16
                  %552 = arith.extsi %545 : i16 to i64
                  %553 = arith.addi %544, %552 : i64
                  %554 = arith.sitofp %553 : i64 to f64
                  %555 = arith.mulf %554, %374 : f64
                  %557 = arith.extf %535 : f32 to f64
                  %556 = arith.addf %557, %555 : f64
                  %558 = arith.constant 2.0 : f32
                  %560 = llvm.load %520 : !llvm.ptr -> i64
                  %561 = arith.sitofp %560 : i64 to f64
                  %562 = arith.mulf %561, %377 : f64
                  %559 = func.call @atan2(%562, %556) : (f64, f64) -> f64
                  %564 = arith.extf %558 : f32 to f64
                  %563 = arith.mulf %564, %559 : f64
                  %565 = arith.mulf %563, %370 : f64
                  %566 = llvm.load %383 : !llvm.ptr -> f64
                  %567 = arith.cmpf olt, %565, %566 : f64
                  cf.cond_br %567, ^bb102, ^bb103
                  ^bb102:
                    llvm.store %565, %383 : f64, !llvm.ptr
                    %568 = llvm.load %383 : !llvm.ptr -> f64
                    %569 = arith.divf %568, %370 : f64
                    llvm.store %569, %387 : f64, !llvm.ptr
                    %571 = arith.constant 4.0 : f32
                    %573 = arith.extf %571 : f32 to f64
                    %572 = arith.mulf %573, %372 : f64
                    %574 = llvm.load %387 : !llvm.ptr -> f64
                    %575 = arith.constant 2.0 : f32
                    %577 = arith.extf %575 : f32 to f64
                    %576 = arith.divf %574, %577 : f64
                    %578 = math.tan %576 : f64
                    %579 = arith.mulf %572, %578 : f64
                    %580 = arith.constant 0.000000000001 : f32
                    %582 = arith.extf %580 : f32 to f64
                    %581 = arith.addf %579, %582 : f64
                    %570 = func.call @floor(%581) : (f64) -> f64
                    %583 = arith.fptosi %570 : f64 to i64
                    llvm.store %583, %403 : i64, !llvm.ptr
                    %584 = llvm.load %403 : !llvm.ptr -> i64
                    %585 = arith.constant 1 : i32
                    %587 = arith.extsi %585 : i32 to i64
                    %586 = arith.cmpi slt, %584, %587 : i64
                    cf.cond_br %586, ^bb105, ^bb106
                    ^bb105:
                      %588 = arith.constant 1 : i32
                      %589 = arith.extsi %588 : i32 to i64
                      llvm.store %589, %403 : i64, !llvm.ptr
                      cf.br ^bb107
                    ^bb106:
                      cf.br ^bb107
                    ^bb107:
                    cf.br ^bb104
                  ^bb103:
                    cf.br ^bb104
                  ^bb104:
                  cf.br ^bb101
                ^bb100:
                  cf.br ^bb101
                ^bb101:
                cf.br ^bb95
              ^bb94:
                cf.br ^bb95
              ^bb95:
              %590 = llvm.load %498 : !llvm.ptr -> i64
              %591 = arith.constant 1 : i32
              %593 = arith.extsi %591 : i32 to i64
              %592 = arith.addi %590, %593 : i64
              llvm.store %592, %498 : i64, !llvm.ptr
              cf.br ^bb90
            ^bb92:
            cf.br ^bb89
          ^bb88:
            cf.br ^bb89
          ^bb89:
          cf.br ^bb86
        ^bb85:
          cf.br ^bb86
        ^bb86:
        %594 = llvm.load %435 : !llvm.ptr -> i64
        %595 = arith.constant 1 : i32
        %597 = arith.extsi %595 : i32 to i64
        %596 = arith.addi %594, %597 : i64
        llvm.store %596, %435 : i64, !llvm.ptr
        cf.br ^bb81
      ^bb83:
      %598 = llvm.load %309 : !llvm.ptr -> i64
      %599 = arith.constant 1 : i32
      %601 = arith.extsi %599 : i32 to i64
      %600 = arith.addi %598, %601 : i64
      llvm.store %600, %309 : i64, !llvm.ptr
      cf.br ^bb78
    ^bb80:
    func.call @free(%203) : (!llvm.ptr) -> ()
    func.call @free(%208) : (!llvm.ptr) -> ()
    func.call @free(%213) : (!llvm.ptr) -> ()
    func.call @free(%300) : (!llvm.ptr) -> ()
    %606 = llvm.load %383 : !llvm.ptr -> f64
    func.return %606 : f64
  }
  func.func @main() -> i32 {
    %607 = arith.constant 0.0 : f32
    %608 = arith.extf %607 : f32 to f64
    %609 = llvm.mlir.constant(1 : i64) : i64
    %610 = llvm.alloca %609 x f64 : (i64) -> !llvm.ptr
    llvm.store %608, %610 : f64, !llvm.ptr
    %611 = arith.constant 1 : i32
    %612 = arith.extsi %611 : i32 to i64
    %613 = llvm.mlir.constant(1 : i64) : i64
    %614 = llvm.alloca %613 x i64 : (i64) -> !llvm.ptr
    llvm.store %612, %614 : i64, !llvm.ptr
    cf.br ^bb108
    ^bb108:
    %615 = llvm.load %614 : !llvm.ptr -> i64
    %616 = arith.constant 50 : i32
    %618 = arith.extsi %616 : i32 to i64
    %617 = arith.cmpi sle, %615, %618 : i64
    cf.cond_br %617, ^bb109, ^bb110
    ^bb109:
      %619 = llvm.load %610 : !llvm.ptr -> f64
      %621 = llvm.load %614 : !llvm.ptr -> i64
      %620 = func.call @min_area(%621) : (i64) -> f64
      %622 = arith.addf %619, %620 : f64
      llvm.store %622, %610 : f64, !llvm.ptr
      %623 = llvm.load %614 : !llvm.ptr -> i64
      %624 = arith.constant 1 : i32
      %626 = arith.extsi %624 : i32 to i64
      %625 = arith.addi %623, %626 : i64
      llvm.store %625, %614 : i64, !llvm.ptr
      cf.br ^bb108
    ^bb110:
    %627 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %628 = llvm.load %610 : !llvm.ptr -> f64
    %629 = llvm.call @printf(%627, %628) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, f64) -> i32
    %630 = arith.constant 0 : i32
    func.return %630 : i32
  }
}