Problem 729

Range of periodic sequences of a_{n+1} = a_n - 1/a_n (the Boole map). Periodic orbits correspond one-to-one with aperiodic binary sign itineraries: the inverse branches g+(y) = (y + sqrt(y*y+4))/2 and g-(y) = -1/g+(y) are contractions, so each binary necklace of length p (mask strictly minimal among its rotations, non-constant) yields one cycle of minimal period p via Newton iteration on the composed inverse map. Each cycle contributes p * (max - min); Kahan-sum S(25), 4dp.

Answer308896374.2502
Output308896374.2502
StatusPASS
Native helperno
Runtime4560 ms
Peak memory1152 KB
Time complexityO(n^3) (estimated)
Space complexityO(1) (estimated)

Performance comparison

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

Flow source

# Project Euler 729
# Range of periodic sequences of a_{n+1} = a_n - 1/a_n (the Boole map).
# Periodic orbits correspond one-to-one with aperiodic binary sign
# itineraries: the inverse branches g+(y) = (y + sqrt(y*y+4))/2 and
# g-(y) = -1/g+(y) are contractions, so each binary necklace of length p
# (mask strictly minimal among its rotations, non-constant) yields one
# cycle of minimal period p via Newton iteration on the composed inverse
# map. Each cycle contributes p * (max - min); Kahan-sum S(25), 4dp.

extern {
    function sqrt(x: f64) -> f64
}

function main() -> i32 {
    let big: i64 = 25
    let mut total: f64 = 0.0
    let mut comp: f64 = 0.0
    let mut p: i64 = 2
    while p <= big {
        let mut pow2p: i64 = 1
        let mut j: i64 = 0
        while j < p {
            pow2p = pow2p * 2
            j = j + 1
        }
        let mut m: i64 = 1
        while m < pow2p - 1 {
            # keep m only if strictly smaller than all its rotations
            let mut ok: i64 = 1
            let mut k: i64 = 1
            let mut pk: i64 = 2
            while k < p && ok == 1 {
                let rot: i64 = (m >> k) | ((m % pk) << (p - k))
                if rot <= m { ok = 0 }
                k = k + 1
                pk = pk * 2
            }
            if ok == 1 {
                # contraction warmup from x = 0
                let mut x: f64 = 0.0
                let mut sweep: i64 = 0
                while sweep < 2 {
                    let mut y: f64 = x
                    let mut i: i64 = p - 1
                    while i >= 0 {
                        let r: f64 = sqrt(y * y + 4.0)
                        let mut gp: f64 = 0.0
                        if y >= 0.0 { gp = (y + r) * 0.5 } else { gp = 2.0 / (r - y) }
                        if ((m >> i) & 1) == 1 { y = gp } else { y = -1.0 / gp }
                        i = i - 1
                    }
                    x = y
                    sweep = sweep + 1
                }
                # Newton on G(x) - x, G = composed inverse branches
                let mut it: i64 = 0
                let mut done: i64 = 0
                while done == 0 && it < 60 {
                    let mut y: f64 = x
                    let mut d: f64 = 1.0
                    let mut i: i64 = p - 1
                    while i >= 0 {
                        let r: f64 = sqrt(y * y + 4.0)
                        let mut gp: f64 = 0.0
                        let mut gpd: f64 = 0.0
                        if y >= 0.0 {
                            gp = (y + r) * 0.5
                            gpd = (r + y) / (2.0 * r)
                        } else {
                            gp = 2.0 / (r - y)
                            gpd = 2.0 / (r * (r - y))
                        }
                        if ((m >> i) & 1) == 1 {
                            y = gp
                            d = d * gpd
                        } else {
                            y = -1.0 / gp
                            d = d * gpd / (gp * gp)
                        }
                        i = i - 1
                    }
                    let nx: f64 = x + (y - x) / (1.0 - d)
                    let mut diff: f64 = nx - x
                    if diff < 0.0 { diff = -diff }
                    let mut ax: f64 = nx
                    if ax < 0.0 { ax = -ax }
                    x = nx
                    if diff <= 0.00000000000001 * (1.0 + ax) { done = 1 }
                    it = it + 1
                }
                # final backward pass collects the orbit points
                let mut y2: f64 = x
                let mut mn: f64 = x
                let mut mx: f64 = x
                let mut i2: i64 = p - 1
                while i2 >= 0 {
                    let r2: f64 = sqrt(y2 * y2 + 4.0)
                    let mut gp2: f64 = 0.0
                    if y2 >= 0.0 { gp2 = (y2 + r2) * 0.5 } else { gp2 = 2.0 / (r2 - y2) }
                    if ((m >> i2) & 1) == 1 { y2 = gp2 } else { y2 = -1.0 / gp2 }
                    if y2 < mn { mn = y2 }
                    if y2 > mx { mx = y2 }
                    i2 = i2 - 1
                }
                let contrib: f64 = (p as f64) * (mx - mn)
                # Kahan summation
                let t1: f64 = contrib - comp
                let t2: f64 = total + t1
                comp = (t2 - total) - t1
                total = t2
            }
            m = m + 1
        }
        p = p + 1
    }
    printf("%.4f\n", total)
    return 0
}

Generated C

#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* Flow runtime helpers */
typedef struct flow_temp_node { struct flow_temp_node* next; } flow_temp_node;
static flow_temp_node* flow_temp_head = NULL;
static int flow_temp_atexit_set = 0;
__attribute__((unused)) static void flow_temp_free_all(void) {
    while (flow_temp_head) {
        flow_temp_node* n = flow_temp_head;
        flow_temp_head = n->next;
        free(n);
    }
}
__attribute__((unused)) static void* flow_temp_alloc(size_t nbytes) {
    flow_temp_node* node = (flow_temp_node*)malloc(sizeof(flow_temp_node) + nbytes);
    if (!node) return NULL;
    node->next = flow_temp_head;
    flow_temp_head = node;
    if (!flow_temp_atexit_set) {
        flow_temp_atexit_set = 1;
        atexit(flow_temp_free_all);
    }
    return (void*)(node + 1);
}
#ifndef FLOW_DIAG
#define FLOW_DIAG(msg) fprintf(stderr, "%s", (msg))
#endif
#ifndef FLOW_LOG
#define FLOW_LOG(fmt, ...) printf(fmt, __VA_ARGS__)
#endif
#ifndef FLOW_LOG_EMPTY
#define FLOW_LOG_EMPTY(fmt) printf(fmt)
#endif
static char* flow_strcat(const char* a, const char* b) {
    size_t la = strlen(a ? a : ""), lb = strlen(b ? b : "");
    char* r = (char*)flow_temp_alloc(la + lb + 1);
    if (!r) return NULL;
    if (la) memcpy(r, a, la);
    if (lb) memcpy(r + la, b, lb);
    r[la + lb] = '\0';
    return r;
}

#define __flow_in_arr(arr, val) __extension__ ({ \
    int _found = 0; \
    size_t _n = sizeof(arr)/sizeof((arr)[0]); \
    for (size_t _i = 0; _i < _n; _i++) { \
        if ((arr)[_i] == (val)) { _found = 1; break; } \
    } _found; })

/* Unified fault handler (MISRA #279) — override with -DFLOW_FAULT_HANDLER=fn */
#ifndef FLOW_FAULT_HANDLER
__attribute__((unused)) static inline void flow_fault_handler(const char* msg) {
    fprintf(stderr, "flow: %s\n", msg ? msg : "fault");
    abort();
#if defined(__GNUC__) || defined(__clang__)
    __builtin_unreachable();
#endif
}
#else
#define flow_fault_handler FLOW_FAULT_HANDLER
#endif
#define flow_div_by_zero_handler() flow_fault_handler("division by zero")
#define flow_shift_ub_handler() flow_fault_handler("invalid shift (amount out of range or left-shift of negative)")

#ifndef FLOW_CHECKED_DIV
#define FLOW_CHECKED_DIV(L, R) (((R) != 0) ? ((L) / (R)) : (flow_div_by_zero_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_MOD
#define FLOW_CHECKED_MOD(L, R) (((R) != 0) ? ((L) % (R)) : (flow_div_by_zero_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_SHL
#define FLOW_CHECKED_SHL(L, R) ((((R) >= 0) && ((unsigned long long)(R) < (sizeof(L) * 8ull)) && ((L) >= 0)) ? ((L) << (R)) : (flow_shift_ub_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_SHR
#define FLOW_CHECKED_SHR(L, R) ((((R) >= 0) && ((unsigned long long)(R) < (sizeof(L) * 8ull))) ? ((L) >> (R)) : (flow_shift_ub_handler(), (L) * 0))
#endif

#include <math.h>

void* _ui_state = NULL;

static inline float i32_to_f32(int32_t v) { return (float)v; }

/* Host stub for @gpu kernels (device codegen replaces this). */
static inline int32_t gpu_thread_id(void) { return 0; }

int32_t main(void);


int32_t main(void) {
    int64_t big = 25;
    double total = 0.0;
    double comp = 0.0;
    int64_t p = 2;
    while (p <= big) {
        int64_t pow2p = 1;
        int64_t j = 0;
        while (j < p) {
            pow2p = (pow2p * 2);
            j = (j + 1);
        }
        int64_t m = 1;
        while (m < (pow2p - 1)) {
            int64_t ok = 1;
            int64_t k = 1;
            int64_t pk = 2;
            while ((k < p && ok == 1)) {
                int64_t rot = (FLOW_CHECKED_SHR((m), (k)) | FLOW_CHECKED_SHL((FLOW_CHECKED_MOD((m), (pk))), ((p - k))));
                if (rot <= m) {
                    ok = 0;
                }
                k = (k + 1);
                pk = (pk * 2);
            }
            if (ok == 1) {
                double x = 0.0;
                int64_t sweep = 0;
                while (sweep < 2) {
                    double y = x;
                    int64_t i = (p - 1);
                    while (i >= 0) {
                        double r = sqrt(((y * y) + 4.0));
                        double gp = 0.0;
                        if (y >= 0.0) {
                            gp = ((y + r) * 0.5);
                        } else {
                            gp = (2.0 / (r - y));
                        }
                        if ((FLOW_CHECKED_SHR((m), (i)) & 1) == 1) {
                            y = gp;
                        } else {
                            y = ((-1.0) / gp);
                        }
                        i = (i - 1);
                    }
                    x = y;
                    sweep = (sweep + 1);
                }
                int64_t it = 0;
                int64_t done = 0;
                while ((done == 0 && it < 60)) {
                    double y = x;
                    double d = 1.0;
                    int64_t i = (p - 1);
                    while (i >= 0) {
                        double r = sqrt(((y * y) + 4.0));
                        double gp = 0.0;
                        double gpd = 0.0;
                        if (y >= 0.0) {
                            gp = ((y + r) * 0.5);
                            gpd = ((r + y) / (2.0 * r));
                        } else {
                            gp = (2.0 / (r - y));
                            gpd = (2.0 / (r * (r - y)));
                        }
                        if ((FLOW_CHECKED_SHR((m), (i)) & 1) == 1) {
                            y = gp;
                            d = (d * gpd);
                        } else {
                            y = ((-1.0) / gp);
                            d = ((d * gpd) / (gp * gp));
                        }
                        i = (i - 1);
                    }
                    double nx = (x + ((y - x) / (1.0 - d)));
                    double diff = (nx - x);
                    if (diff < 0.0) {
                        diff = (-diff);
                    }
                    double ax = nx;
                    if (ax < 0.0) {
                        ax = (-ax);
                    }
                    x = nx;
                    if (diff <= (0.00000000000001 * (1.0 + ax))) {
                        done = 1;
                    }
                    it = (it + 1);
                }
                double y2 = x;
                double mn = x;
                double mx = x;
                int64_t i2 = (p - 1);
                while (i2 >= 0) {
                    double r2 = sqrt(((y2 * y2) + 4.0));
                    double gp2 = 0.0;
                    if (y2 >= 0.0) {
                        gp2 = ((y2 + r2) * 0.5);
                    } else {
                        gp2 = (2.0 / (r2 - y2));
                    }
                    if ((FLOW_CHECKED_SHR((m), (i2)) & 1) == 1) {
                        y2 = gp2;
                    } else {
                        y2 = ((-1.0) / gp2);
                    }
                    if (y2 < mn) {
                        mn = y2;
                    }
                    if (y2 > mx) {
                        mx = y2;
                    }
                    i2 = (i2 - 1);
                }
                double contrib = (((double)(p)) * (mx - mn));
                double t1 = (contrib - comp);
                double t2 = (total + t1);
                comp = ((t2 - total) - t1);
                total = t2;
            }
            m = (m + 1);
        }
        p = (p + 1);
    }
    printf("%.4f\n", total);
    return 0;
}

Generated MLIR

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