← All problems
Problem 737
Coins of radius 1 touch a vertical line, each resting on the one below, and the stack must stay balanced. Build the stack top-down: the centre of mass of the top m coins (mean of m unit vectors) must lie within distance 1 of the next coin's centre. Key identity: |G_m|^2 = H_m / m where H_m is the m-th harmonic number, so the whole problem reduces to a 1D rotation sum S(n) = alpha_n + sum_{m=2}^{n-1} beta_m where alpha_n = acos(r/2), beta_m = atan(sqrt(1-r^2/4)/(r*(t+1/2))) with t = m-1 and r = sqrt(H_t / t). Both depend only on harmonic numbers. The answer for k loops is the smallest n with S(n) > 2*pi*k. H_t and prefix sums of beta are precomputed exactly up to M; the tail is approximated with Euler-Maclaurin (integral via Gauss-Legendre in log space, plus endpoint correction). A binary search over n then finds the answer in O(log n) evaluations. Reproduces 31, 154, 6947 for 1, 2, 10.
View problem on Project Euler
Performance comparison
Metric Our solution Best known
Time complexity O(n)O(n * m)
Space complexity O(n^2)O(n)
Approach Flow solution Dynamic programming or generating function
Verdict Unknown
Flow source
# Project Euler 737: Coin Loops
# Coins of radius 1 touch a vertical line, each resting on the one below,
# and the stack must stay balanced. Build the stack top-down: the centre of
# mass of the top m coins (mean of m unit vectors) must lie within distance 1
# of the next coin's centre.
#
# Key identity: |G_m|^2 = H_m / m where H_m is the m-th harmonic number, so
# the whole problem reduces to a 1D rotation sum
# S(n) = alpha_n + sum_{m=2}^{n-1} beta_m
# where alpha_n = acos(r/2), beta_m = atan(sqrt(1-r^2/4)/(r*(t+1/2))) with
# t = m-1 and r = sqrt(H_t / t). Both depend only on harmonic numbers.
# The answer for k loops is the smallest n with S(n) > 2*pi*k.
#
# H_t and prefix sums of beta are precomputed exactly up to M; the tail is
# approximated with Euler-Maclaurin (integral via Gauss-Legendre in log
# space, plus endpoint correction). A binary search over n then finds the
# answer in O(log n) evaluations. Reproduces 31, 154, 6947 for 1, 2, 10.
extern {
function calloc(n: i64, size: i64) -> ptr<void>
function free(p: ptr<void>) -> void
function sqrt(x: f64) -> f64
function log(x: f64) -> f64
function atan(x: f64) -> f64
function acos(x: f64) -> f64
function exp(x: f64) -> f64
}
function harmonic_asymp(t: f64, gamma: f64) -> f64 {
let inv: f64 = 1.0 / t
let inv2: f64 = inv * inv
let inv4: f64 = inv2 * inv2
let inv6: f64 = inv4 * inv2
let inv8: f64 = inv4 * inv4
return log(t) + gamma + 0.5 * inv - (1.0 / 12.0) * inv2 + (1.0 / 120.0) * inv4 - (1.0 / 252.0) * inv6 + (1.0 / 240.0) * inv8
}
function beta_from_t(t: f64, Ht: f64) -> f64 {
let r: f64 = sqrt(Ht / t)
let q: f64 = sqrt(1.0 - 0.25 * r * r) / (r * (t + 0.5))
return atan(q)
}
function beta_real(m: f64, gamma: f64) -> f64 {
let t: f64 = m - 1.0
return beta_from_t(t, harmonic_asymp(t, gamma))
}
function alpha_from_t(t: f64, Ht: f64) -> f64 {
let r: f64 = sqrt(Ht / t)
return acos(0.5 * r)
}
function integral_beta_log(a: f64, b: f64, gl_x: ptr<f64>, gl_w: ptr<f64>, gamma: f64) -> f64 {
if b <= a { return 0.0 }
let ua: f64 = log(a)
let ub: f64 = log(b)
let seg_u: f64 = 0.5
let span: f64 = ub - ua
let mut steps: i64 = (span / seg_u) as i64
if (steps as f64) * seg_u < span { steps = steps + 1 }
if steps < 1 { steps = 1 }
let du: f64 = span / (steps as f64)
let mut total: f64 = 0.0
let mut i: i64 = 0
while i < steps {
let u0: f64 = ua + (i as f64) * du
let u1: f64 = ua + ((i + 1) as f64) * du
let mid: f64 = 0.5 * (u0 + u1)
let half: f64 = 0.5 * (u1 - u0)
let mut s: f64 = 0.0
let mut j: i64 = 0
while j < 16 {
let u: f64 = mid + half * gl_x[j]
let m: f64 = exp(u)
s = s + gl_w[j] * beta_real(m, gamma) * m
j = j + 1
}
total = total + s * half
i = i + 1
}
return total
}
function tail_sum_beta(a: f64, b: f64, gl_x: ptr<f64>, gl_w: ptr<f64>, gamma: f64) -> f64 {
if b < a { return 0.0 }
let integ: f64 = integral_beta_log(a, b, gl_x, gl_w, gamma)
let fa: f64 = beta_real(a, gamma)
let fb: f64 = beta_real(b, gamma)
return integ + 0.5 * (fa + fb)
}
function rotation_sum(n: i64, M: i64, H: ptr<f64>, pref_beta: ptr<f64>,
gl_x: ptr<f64>, gl_w: ptr<f64>, gamma: f64) -> f64 {
if n < 2 { return 0.0 }
let t: i64 = n - 1
let tf: f64 = (t as f64)
let Ht: f64 = 0.0
if t <= M {
Ht = H[t]
} else {
Ht = harmonic_asymp(tf, gamma)
}
let alpha: f64 = alpha_from_t(tf, Ht)
if t <= M {
return alpha + pref_beta[t]
}
return alpha + pref_beta[M] + tail_sum_beta(((M + 1) as f64), tf, gl_x, gl_w, gamma)
}
function coins_for_loops(loops: i64, M: i64, H: ptr<f64>, pref_beta: ptr<f64>,
gl_x: ptr<f64>, gl_w: ptr<f64>, gamma: f64) -> i64 {
let pi: f64 = 3.14159265358979323846
let target: f64 = 2.0 * pi * (loops as f64)
let mut lo: i64 = 1
let mut hi: i64 = 2
if loops * 5 > 2 { hi = loops * 5 } else { hi = 2 }
while rotation_sum(hi, M, H, pref_beta, gl_x, gl_w, gamma) <= target {
hi = hi * 2
}
while lo + 1 < hi {
let mid: i64 = (lo + hi) / 2
if rotation_sum(mid, M, H, pref_beta, gl_x, gl_w, gamma) > target {
hi = mid
} else {
lo = mid
}
}
return hi
}
function main() -> i32 {
let M: i64 = 500000
let gamma: f64 = 0.5772156649015329
let H: ptr<f64> = calloc(M + 2, 8)
let pref_beta: ptr<f64> = calloc(M + 2, 8)
let gl_x: ptr<f64> = calloc(16, 8)
let gl_w: ptr<f64> = calloc(16, 8)
if H == null || pref_beta == null || gl_x == null || gl_w == null { return 1 }
gl_x[0] = -0.9894009349916499
gl_x[1] = -0.9445750230732326
gl_x[2] = -0.8656312023878318
gl_x[3] = -0.755404408355003
gl_x[4] = -0.6178762444026438
gl_x[5] = -0.45801677765722737
gl_x[6] = -0.2816035507792589
gl_x[7] = -0.09501250983763744
gl_x[8] = 0.09501250983763744
gl_x[9] = 0.2816035507792589
gl_x[10] = 0.45801677765722737
gl_x[11] = 0.6178762444026438
gl_x[12] = 0.755404408355003
gl_x[13] = 0.8656312023878318
gl_x[14] = 0.9445750230732326
gl_x[15] = 0.9894009349916499
gl_w[0] = 0.027152459411754058
gl_w[1] = 0.062253523938647776
gl_w[2] = 0.0951585116824929
gl_w[3] = 0.12462897125553395
gl_w[4] = 0.14959598881657682
gl_w[5] = 0.16915651939500256
gl_w[6] = 0.1826034150449236
gl_w[7] = 0.18945061045506847
gl_w[8] = 0.18945061045506847
gl_w[9] = 0.1826034150449236
gl_w[10] = 0.16915651939500256
gl_w[11] = 0.14959598881657682
gl_w[12] = 0.12462897125553395
gl_w[13] = 0.0951585116824929
gl_w[14] = 0.062253523938647776
gl_w[15] = 0.027152459411754058
let mut Hval: f64 = 0.0
let mut t: i64 = 1
while t <= M {
Hval = Hval + 1.0 / (t as f64)
H[t] = Hval
t = t + 1
}
let mut s: f64 = 0.0
let mut m: i64 = 2
while m <= M {
let tt: i64 = m - 1
s = s + beta_from_t((tt as f64), H[tt])
pref_beta[m] = s
m = m + 1
}
let ans: i64 = coins_for_loops(2020, M, H, pref_beta, gl_x, gl_w, gamma)
printf("%lld\n", ans)
free(gl_w)
free(gl_x)
free(pref_beta)
free(H)
return 0
}
Generated C
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* Flow runtime helpers */
typedef struct flow_temp_node { struct flow_temp_node* next; } flow_temp_node;
static flow_temp_node* flow_temp_head = NULL;
static int flow_temp_atexit_set = 0;
__attribute__((unused)) static void flow_temp_free_all(void) {
while (flow_temp_head) {
flow_temp_node* n = flow_temp_head;
flow_temp_head = n->next;
free(n);
}
}
__attribute__((unused)) static void* flow_temp_alloc(size_t nbytes) {
flow_temp_node* node = (flow_temp_node*)malloc(sizeof(flow_temp_node) + nbytes);
if (!node) return NULL;
node->next = flow_temp_head;
flow_temp_head = node;
if (!flow_temp_atexit_set) {
flow_temp_atexit_set = 1;
atexit(flow_temp_free_all);
}
return (void*)(node + 1);
}
#ifndef FLOW_DIAG
#define FLOW_DIAG(msg) fprintf(stderr, "%s", (msg))
#endif
#ifndef FLOW_LOG
#define FLOW_LOG(fmt, ...) printf(fmt, __VA_ARGS__)
#endif
#ifndef FLOW_LOG_EMPTY
#define FLOW_LOG_EMPTY(fmt) printf(fmt)
#endif
static char* flow_strcat(const char* a, const char* b) {
size_t la = strlen(a ? a : ""), lb = strlen(b ? b : "");
char* r = (char*)flow_temp_alloc(la + lb + 1);
if (!r) return NULL;
if (la) memcpy(r, a, la);
if (lb) memcpy(r + la, b, lb);
r[la + lb] = '\0';
return r;
}
#define __flow_in_arr(arr, val) __extension__ ({ \
int _found = 0; \
size_t _n = sizeof(arr)/sizeof((arr)[0]); \
for (size_t _i = 0; _i < _n; _i++) { \
if ((arr)[_i] == (val)) { _found = 1; break; } \
} _found; })
/* Unified fault handler (MISRA #279) — override with -DFLOW_FAULT_HANDLER=fn */
#ifndef FLOW_FAULT_HANDLER
__attribute__((unused)) static inline void flow_fault_handler(const char* msg) {
fprintf(stderr, "flow: %s\n", msg ? msg : "fault");
abort();
#if defined(__GNUC__) || defined(__clang__)
__builtin_unreachable();
#endif
}
#else
#define flow_fault_handler FLOW_FAULT_HANDLER
#endif
#define flow_div_by_zero_handler() flow_fault_handler("division by zero")
#define flow_shift_ub_handler() flow_fault_handler("invalid shift (amount out of range or left-shift of negative)")
#ifndef FLOW_CHECKED_DIV
#define FLOW_CHECKED_DIV(L, R) (((R) != 0) ? ((L) / (R)) : (flow_div_by_zero_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_MOD
#define FLOW_CHECKED_MOD(L, R) (((R) != 0) ? ((L) % (R)) : (flow_div_by_zero_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_SHL
#define FLOW_CHECKED_SHL(L, R) ((((R) >= 0) && ((unsigned long long)(R) < (sizeof(L) * 8ull)) && ((L) >= 0)) ? ((L) << (R)) : (flow_shift_ub_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_SHR
#define FLOW_CHECKED_SHR(L, R) ((((R) >= 0) && ((unsigned long long)(R) < (sizeof(L) * 8ull))) ? ((L) >> (R)) : (flow_shift_ub_handler(), (L) * 0))
#endif
#include <math.h>
void* _ui_state = NULL;
static inline float i32_to_f32(int32_t v) { return (float)v; }
/* Host stub for @gpu kernels (device codegen replaces this). */
static inline int32_t gpu_thread_id(void) { return 0; }
double atan(double x);
double acos(double x);
double harmonic_asymp_f64_f64(double t, double gamma);
double beta_from_t_f64_f64(double t, double Ht);
double beta_real_f64_f64(double m, double gamma);
double alpha_from_t_f64_f64(double t, double Ht);
double integral_beta_log_f64_f64_ptr_f64_ptr_f64_f64(double a, double b, double* gl_x, double* gl_w, double gamma);
double tail_sum_beta_f64_f64_ptr_f64_ptr_f64_f64(double a, double b, double* gl_x, double* gl_w, double gamma);
double rotation_sum_i64_i64_ptr_f64_ptr_f64_ptr_f64_ptr_f64_f64(int64_t n, int64_t M, double* H, double* pref_beta, double* gl_x, double* gl_w, double gamma);
int64_t coins_for_loops_i64_i64_ptr_f64_ptr_f64_ptr_f64_ptr_f64_f64(int64_t loops, int64_t M, double* H, double* pref_beta, double* gl_x, double* gl_w, double gamma);
int32_t main(void);
double harmonic_asymp_f64_f64(double t, double gamma) {
double inv = (1.0 / t);
double inv2 = (inv * inv);
double inv4 = (inv2 * inv2);
double inv6 = (inv4 * inv2);
double inv8 = (inv4 * inv4);
return ((((((log(t) + gamma) + (0.5 * inv)) - ((1.0 / 12.0) * inv2)) + ((1.0 / 120.0) * inv4)) - ((1.0 / 252.0) * inv6)) + ((1.0 / 240.0) * inv8));
}
double beta_from_t_f64_f64(double t, double Ht) {
double r = sqrt((Ht / t));
double q = (sqrt((1.0 - ((0.25 * r) * r))) / (r * (t + 0.5)));
return atan(q);
}
double beta_real_f64_f64(double m, double gamma) {
double t = (m - 1.0);
return beta_from_t_f64_f64(t, harmonic_asymp_f64_f64(t, gamma));
}
double alpha_from_t_f64_f64(double t, double Ht) {
double r = sqrt((Ht / t));
return acos((0.5 * r));
}
double integral_beta_log_f64_f64_ptr_f64_ptr_f64_f64(double a, double b, double* gl_x, double* gl_w, double gamma) {
if (b <= a) {
return 0.0;
}
double ua = log(a);
double ub = log(b);
double seg_u = 0.5;
double span = (ub - ua);
int64_t steps = ((int64_t)((span / seg_u)));
if ((((double)(steps)) * seg_u) < span) {
steps = (steps + 1);
}
if (steps < 1) {
steps = 1;
}
double du = (span / ((double)(steps)));
double total = 0.0;
int64_t i = 0;
while (i < steps) {
double u0 = (ua + (((double)(i)) * du));
double u1 = (ua + (((double)((i + 1))) * du));
double mid = (0.5 * (u0 + u1));
double half = (0.5 * (u1 - u0));
double s = 0.0;
int64_t j = 0;
while (j < 16) {
double u = (mid + (half * gl_x[j]));
double m = exp(u);
s = (s + ((gl_w[j] * beta_real_f64_f64(m, gamma)) * m));
j = (j + 1);
}
total = (total + (s * half));
i = (i + 1);
}
return total;
}
double tail_sum_beta_f64_f64_ptr_f64_ptr_f64_f64(double a, double b, double* gl_x, double* gl_w, double gamma) {
if (b < a) {
return 0.0;
}
double integ = integral_beta_log_f64_f64_ptr_f64_ptr_f64_f64(a, b, gl_x, gl_w, gamma);
double fa = beta_real_f64_f64(a, gamma);
double fb = beta_real_f64_f64(b, gamma);
return (integ + (0.5 * (fa + fb)));
}
double rotation_sum_i64_i64_ptr_f64_ptr_f64_ptr_f64_ptr_f64_f64(int64_t n, int64_t M, double* H, double* pref_beta, double* gl_x, double* gl_w, double gamma) {
if (n < 2) {
return 0.0;
}
int64_t t = (n - 1);
double tf = ((double)(t));
double Ht = 0.0;
if (t <= M) {
Ht = H[t];
} else {
Ht = harmonic_asymp_f64_f64(tf, gamma);
}
double alpha = alpha_from_t_f64_f64(tf, Ht);
if (t <= M) {
return (alpha + pref_beta[t]);
}
return ((alpha + pref_beta[M]) + tail_sum_beta_f64_f64_ptr_f64_ptr_f64_f64(((double)((M + 1))), tf, gl_x, gl_w, gamma));
}
int64_t coins_for_loops_i64_i64_ptr_f64_ptr_f64_ptr_f64_ptr_f64_f64(int64_t loops, int64_t M, double* H, double* pref_beta, double* gl_x, double* gl_w, double gamma) {
double pi = 3.14159265358979323846;
double target = ((2.0 * pi) * ((double)(loops)));
int64_t lo = 1;
int64_t hi = 2;
if ((loops * 5) > 2) {
hi = (loops * 5);
} else {
hi = 2;
}
while (rotation_sum_i64_i64_ptr_f64_ptr_f64_ptr_f64_ptr_f64_f64(hi, M, H, pref_beta, gl_x, gl_w, gamma) <= target) {
hi = (hi * 2);
}
while ((lo + 1) < hi) {
int64_t mid = FLOW_CHECKED_DIV(((lo + hi)), (2));
if (rotation_sum_i64_i64_ptr_f64_ptr_f64_ptr_f64_ptr_f64_f64(mid, M, H, pref_beta, gl_x, gl_w, gamma) > target) {
hi = mid;
} else {
lo = mid;
}
}
return hi;
}
int32_t main(void) {
int64_t M = 500000;
double gamma = 0.5772156649015329;
double* H = (double*)(calloc((M + 2), 8));
double* pref_beta = (double*)(calloc((M + 2), 8));
double* gl_x = (double*)(calloc(16, 8));
double* gl_w = (double*)(calloc(16, 8));
if ((((H == NULL || pref_beta == NULL) || gl_x == NULL) || gl_w == NULL)) {
return 1;
}
gl_x[0] = (-0.9894009349916499);
gl_x[1] = (-0.9445750230732326);
gl_x[2] = (-0.8656312023878318);
gl_x[3] = (-0.755404408355003);
gl_x[4] = (-0.6178762444026438);
gl_x[5] = (-0.45801677765722737);
gl_x[6] = (-0.2816035507792589);
gl_x[7] = (-0.09501250983763744);
gl_x[8] = 0.09501250983763744;
gl_x[9] = 0.2816035507792589;
gl_x[10] = 0.45801677765722737;
gl_x[11] = 0.6178762444026438;
gl_x[12] = 0.755404408355003;
gl_x[13] = 0.8656312023878318;
gl_x[14] = 0.9445750230732326;
gl_x[15] = 0.9894009349916499;
gl_w[0] = 0.027152459411754058;
gl_w[1] = 0.062253523938647776;
gl_w[2] = 0.0951585116824929;
gl_w[3] = 0.12462897125553395;
gl_w[4] = 0.14959598881657682;
gl_w[5] = 0.16915651939500256;
gl_w[6] = 0.1826034150449236;
gl_w[7] = 0.18945061045506847;
gl_w[8] = 0.18945061045506847;
gl_w[9] = 0.1826034150449236;
gl_w[10] = 0.16915651939500256;
gl_w[11] = 0.14959598881657682;
gl_w[12] = 0.12462897125553395;
gl_w[13] = 0.0951585116824929;
gl_w[14] = 0.062253523938647776;
gl_w[15] = 0.027152459411754058;
double Hval = 0.0;
int64_t t = 1;
while (t <= M) {
Hval = (Hval + (1.0 / ((double)(t))));
H[t] = Hval;
t = (t + 1);
}
double s = 0.0;
int64_t m = 2;
while (m <= M) {
int64_t tt = (m - 1);
s = (s + beta_from_t_f64_f64(((double)(tt)), H[tt]));
pref_beta[m] = s;
m = (m + 1);
}
int64_t ans = coins_for_loops_i64_i64_ptr_f64_ptr_f64_ptr_f64_ptr_f64_f64(2020, M, H, pref_beta, gl_x, gl_w, gamma);
printf("%lld\n", ans);
free(gl_w);
free(gl_x);
free(pref_beta);
free(H);
return 0;
}
Generated MLIR
module {
llvm.func @printf(!llvm.ptr, ...) -> i32
llvm.mlir.global internal constant @str_0("%lld\n\00") {addr_space = 0 : i32} : !llvm.array<6 x i8>
func.func private @calloc(i64, i64) -> !llvm.ptr
func.func private @free(!llvm.ptr) -> ()
func.func private @sqrt(f64) -> f64
func.func private @log(f64) -> f64
func.func private @atan(f64) -> f64
func.func private @acos(f64) -> f64
func.func private @exp(f64) -> f64
func.func @harmonic_asymp(%arg0: f64, %arg1: f64) -> f64 {
%0 = arith.constant 1.0 : f32
%2 = arith.extf %0 : f32 to f64
%1 = arith.divf %2, %arg0 : f64
%3 = arith.mulf %1, %1 : f64
%4 = arith.mulf %3, %3 : f64
%5 = arith.mulf %4, %3 : f64
%6 = arith.mulf %4, %4 : f64
%7 = math.log %arg0 : f64
%8 = arith.addf %7, %arg1 : f64
%9 = arith.constant 0.5 : f32
%11 = arith.extf %9 : f32 to f64
%10 = arith.mulf %11, %1 : f64
%12 = arith.addf %8, %10 : f64
%13 = arith.constant 1.0 : f32
%14 = arith.constant 12.0 : f32
%15 = arith.divf %13, %14 : f32
%17 = arith.extf %15 : f32 to f64
%16 = arith.mulf %17, %3 : f64
%18 = arith.subf %12, %16 : f64
%19 = arith.constant 1.0 : f32
%20 = arith.constant 120.0 : f32
%21 = arith.divf %19, %20 : f32
%23 = arith.extf %21 : f32 to f64
%22 = arith.mulf %23, %4 : f64
%24 = arith.addf %18, %22 : f64
%25 = arith.constant 1.0 : f32
%26 = arith.constant 252.0 : f32
%27 = arith.divf %25, %26 : f32
%29 = arith.extf %27 : f32 to f64
%28 = arith.mulf %29, %5 : f64
%30 = arith.subf %24, %28 : f64
%31 = arith.constant 1.0 : f32
%32 = arith.constant 240.0 : f32
%33 = arith.divf %31, %32 : f32
%35 = arith.extf %33 : f32 to f64
%34 = arith.mulf %35, %6 : f64
%36 = arith.addf %30, %34 : f64
func.return %36 : f64
}
func.func @beta_from_t(%arg0: f64, %arg1: f64) -> f64 {
%37 = arith.divf %arg1, %arg0 : f64
%38 = math.sqrt %37 : f64
%39 = arith.constant 1.0 : f32
%40 = arith.constant 0.25 : f32
%42 = arith.extf %40 : f32 to f64
%41 = arith.mulf %42, %38 : f64
%43 = arith.mulf %41, %38 : f64
%45 = arith.extf %39 : f32 to f64
%44 = arith.subf %45, %43 : f64
%46 = math.sqrt %44 : f64
%47 = arith.constant 0.5 : f32
%49 = arith.extf %47 : f32 to f64
%48 = arith.addf %arg0, %49 : f64
%50 = arith.mulf %38, %48 : f64
%51 = arith.divf %46, %50 : f64
%52 = func.call @atan(%51) : (f64) -> f64
func.return %52 : f64
}
func.func @beta_real(%arg0: f64, %arg1: f64) -> f64 {
%53 = arith.constant 1.0 : f32
%55 = arith.extf %53 : f32 to f64
%54 = arith.subf %arg0, %55 : f64
%57 = func.call @harmonic_asymp(%54, %arg1) : (f64, f64) -> f64
%56 = func.call @beta_from_t(%54, %57) : (f64, f64) -> f64
func.return %56 : f64
}
func.func @alpha_from_t(%arg0: f64, %arg1: f64) -> f64 {
%58 = arith.divf %arg1, %arg0 : f64
%59 = math.sqrt %58 : f64
%61 = arith.constant 0.5 : f32
%63 = arith.extf %61 : f32 to f64
%62 = arith.mulf %63, %59 : f64
%60 = func.call @acos(%62) : (f64) -> f64
func.return %60 : f64
}
func.func @integral_beta_log(%arg0: f64, %arg1: f64, %arg2: !llvm.ptr, %arg3: !llvm.ptr, %arg4: f64) -> f64 {
%64 = arith.cmpf ole, %arg1, %arg0 : f64
cf.cond_br %64, ^bb0, ^bb1
^bb0:
%65 = arith.constant 0.0 : f32
%66 = arith.extf %65 : f32 to f64
func.return %66 : f64
^bb1:
cf.br ^bb2
^bb2:
%67 = math.log %arg0 : f64
%68 = math.log %arg1 : f64
%69 = arith.constant 0.5 : f32
%70 = arith.extf %69 : f32 to f64
%71 = arith.subf %68, %67 : f64
%72 = arith.divf %71, %70 : f64
%73 = arith.fptosi %72 : f64 to i64
%74 = llvm.mlir.constant(1 : i64) : i64
%75 = llvm.alloca %74 x i64 : (i64) -> !llvm.ptr
llvm.store %73, %75 : i64, !llvm.ptr
%76 = llvm.load %75 : !llvm.ptr -> i64
%77 = arith.sitofp %76 : i64 to f64
%78 = arith.mulf %77, %70 : f64
%79 = arith.cmpf olt, %78, %71 : f64
cf.cond_br %79, ^bb3, ^bb4
^bb3:
%80 = llvm.load %75 : !llvm.ptr -> i64
%81 = arith.constant 1 : i32
%83 = arith.extsi %81 : i32 to i64
%82 = arith.addi %80, %83 : i64
llvm.store %82, %75 : i64, !llvm.ptr
cf.br ^bb5
^bb4:
cf.br ^bb5
^bb5:
%84 = llvm.load %75 : !llvm.ptr -> i64
%85 = arith.constant 1 : i32
%87 = arith.extsi %85 : i32 to i64
%86 = arith.cmpi slt, %84, %87 : i64
cf.cond_br %86, ^bb6, ^bb7
^bb6:
%88 = arith.constant 1 : i32
%89 = arith.extsi %88 : i32 to i64
llvm.store %89, %75 : i64, !llvm.ptr
cf.br ^bb8
^bb7:
cf.br ^bb8
^bb8:
%90 = llvm.load %75 : !llvm.ptr -> i64
%91 = arith.sitofp %90 : i64 to f64
%92 = arith.divf %71, %91 : f64
%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 ^bb9
^bb9:
%101 = llvm.load %100 : !llvm.ptr -> i64
%102 = llvm.load %75 : !llvm.ptr -> i64
%103 = arith.cmpi slt, %101, %102 : i64
cf.cond_br %103, ^bb10, ^bb11
^bb10:
%104 = llvm.load %100 : !llvm.ptr -> i64
%105 = arith.sitofp %104 : i64 to f64
%106 = arith.mulf %105, %92 : f64
%107 = arith.addf %67, %106 : f64
%108 = llvm.load %100 : !llvm.ptr -> i64
%109 = arith.constant 1 : i32
%111 = arith.extsi %109 : i32 to i64
%110 = arith.addi %108, %111 : i64
%112 = arith.sitofp %110 : i64 to f64
%113 = arith.mulf %112, %92 : f64
%114 = arith.addf %67, %113 : f64
%115 = arith.constant 0.5 : f32
%116 = arith.addf %107, %114 : f64
%118 = arith.extf %115 : f32 to f64
%117 = arith.mulf %118, %116 : f64
%119 = arith.constant 0.5 : f32
%120 = arith.subf %114, %107 : f64
%122 = arith.extf %119 : f32 to f64
%121 = arith.mulf %122, %120 : f64
%123 = arith.constant 0.0 : f32
%124 = arith.extf %123 : f32 to f64
%125 = llvm.mlir.constant(1 : i64) : i64
%126 = llvm.alloca %125 x f64 : (i64) -> !llvm.ptr
llvm.store %124, %126 : f64, !llvm.ptr
%127 = arith.constant 0 : i32
%128 = arith.extsi %127 : i32 to i64
%129 = llvm.mlir.constant(1 : i64) : i64
%130 = llvm.alloca %129 x i64 : (i64) -> !llvm.ptr
llvm.store %128, %130 : i64, !llvm.ptr
cf.br ^bb12
^bb12:
%131 = llvm.load %130 : !llvm.ptr -> i64
%132 = arith.constant 16 : i32
%134 = arith.extsi %132 : i32 to i64
%133 = arith.cmpi slt, %131, %134 : i64
cf.cond_br %133, ^bb13, ^bb14
^bb13:
%136 = llvm.load %130 : !llvm.ptr -> i64
%137 = llvm.getelementptr %arg2[%136] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%135 = llvm.load %137 : !llvm.ptr -> f64
%138 = arith.mulf %121, %135 : f64
%139 = arith.addf %117, %138 : f64
%140 = math.exp %139 : f64
%141 = llvm.load %126 : !llvm.ptr -> f64
%143 = llvm.load %130 : !llvm.ptr -> i64
%144 = llvm.getelementptr %arg3[%143] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%142 = llvm.load %144 : !llvm.ptr -> f64
%145 = func.call @beta_real(%140, %arg4) : (f64, f64) -> f64
%146 = arith.mulf %142, %145 : f64
%147 = arith.mulf %146, %140 : f64
%148 = arith.addf %141, %147 : f64
llvm.store %148, %126 : f64, !llvm.ptr
%149 = llvm.load %130 : !llvm.ptr -> i64
%150 = arith.constant 1 : i32
%152 = arith.extsi %150 : i32 to i64
%151 = arith.addi %149, %152 : i64
llvm.store %151, %130 : i64, !llvm.ptr
cf.br ^bb12
^bb14:
%153 = llvm.load %96 : !llvm.ptr -> f64
%154 = llvm.load %126 : !llvm.ptr -> f64
%155 = arith.mulf %154, %121 : f64
%156 = arith.addf %153, %155 : f64
llvm.store %156, %96 : f64, !llvm.ptr
%157 = llvm.load %100 : !llvm.ptr -> i64
%158 = arith.constant 1 : i32
%160 = arith.extsi %158 : i32 to i64
%159 = arith.addi %157, %160 : i64
llvm.store %159, %100 : i64, !llvm.ptr
cf.br ^bb9
^bb11:
%161 = llvm.load %96 : !llvm.ptr -> f64
func.return %161 : f64
}
func.func @tail_sum_beta(%arg0: f64, %arg1: f64, %arg2: !llvm.ptr, %arg3: !llvm.ptr, %arg4: f64) -> f64 {
%162 = arith.cmpf olt, %arg1, %arg0 : f64
cf.cond_br %162, ^bb15, ^bb16
^bb15:
%163 = arith.constant 0.0 : f32
%164 = arith.extf %163 : f32 to f64
func.return %164 : f64
^bb16:
cf.br ^bb17
^bb17:
%165 = func.call @integral_beta_log(%arg0, %arg1, %arg2, %arg3, %arg4) : (f64, f64, !llvm.ptr, !llvm.ptr, f64) -> f64
%166 = func.call @beta_real(%arg0, %arg4) : (f64, f64) -> f64
%167 = func.call @beta_real(%arg1, %arg4) : (f64, f64) -> f64
%168 = arith.constant 0.5 : f32
%169 = arith.addf %166, %167 : f64
%171 = arith.extf %168 : f32 to f64
%170 = arith.mulf %171, %169 : f64
%172 = arith.addf %165, %170 : f64
func.return %172 : f64
}
func.func @rotation_sum(%arg0: i64, %arg1: i64, %arg2: !llvm.ptr, %arg3: !llvm.ptr, %arg4: !llvm.ptr, %arg5: !llvm.ptr, %arg6: f64) -> f64 {
%173 = arith.constant 2 : i32
%175 = arith.extsi %173 : i32 to i64
%174 = arith.cmpi slt, %arg0, %175 : i64
cf.cond_br %174, ^bb18, ^bb19
^bb18:
%176 = arith.constant 0.0 : f32
%177 = arith.extf %176 : f32 to f64
func.return %177 : f64
^bb19:
cf.br ^bb20
^bb20:
%178 = arith.constant 1 : i32
%180 = arith.extsi %178 : i32 to i64
%179 = arith.subi %arg0, %180 : i64
%181 = arith.sitofp %179 : i64 to f64
%182 = arith.constant 0.0 : f32
%183 = arith.extf %182 : f32 to f64
%184 = arith.cmpi sle, %179, %arg1 : i64
%185 = scf.if %184 -> (f64) {
%187 = llvm.getelementptr %arg2[%179] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%186 = llvm.load %187 : !llvm.ptr -> f64
scf.yield %186 : f64
} else {
%188 = func.call @harmonic_asymp(%181, %arg6) : (f64, f64) -> f64
scf.yield %188 : f64
}
%189 = func.call @alpha_from_t(%181, %185) : (f64, f64) -> f64
%190 = arith.cmpi sle, %179, %arg1 : i64
cf.cond_br %190, ^bb21, ^bb22
^bb21:
%192 = llvm.getelementptr %arg3[%179] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%191 = llvm.load %192 : !llvm.ptr -> f64
%193 = arith.addf %189, %191 : f64
func.return %193 : f64
^bb22:
cf.br ^bb23
^bb23:
%195 = llvm.getelementptr %arg3[%arg1] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%194 = llvm.load %195 : !llvm.ptr -> f64
%196 = arith.addf %189, %194 : f64
%198 = arith.constant 1 : i32
%200 = arith.extsi %198 : i32 to i64
%199 = arith.addi %arg1, %200 : i64
%201 = arith.sitofp %199 : i64 to f64
%197 = func.call @tail_sum_beta(%201, %181, %arg4, %arg5, %arg6) : (f64, f64, !llvm.ptr, !llvm.ptr, f64) -> f64
%202 = arith.addf %196, %197 : f64
func.return %202 : f64
}
func.func @coins_for_loops(%arg0: i64, %arg1: i64, %arg2: !llvm.ptr, %arg3: !llvm.ptr, %arg4: !llvm.ptr, %arg5: !llvm.ptr, %arg6: f64) -> i64 {
%203 = arith.constant 3.14159265358979323846 : f32
%204 = arith.extf %203 : f32 to f64
%205 = arith.constant 2.0 : f32
%207 = arith.extf %205 : f32 to f64
%206 = arith.mulf %207, %204 : f64
%208 = arith.sitofp %arg0 : i64 to f64
%209 = arith.mulf %206, %208 : f64
%210 = arith.constant 1 : i32
%211 = arith.extsi %210 : i32 to i64
%212 = llvm.mlir.constant(1 : i64) : i64
%213 = llvm.alloca %212 x i64 : (i64) -> !llvm.ptr
llvm.store %211, %213 : i64, !llvm.ptr
%214 = arith.constant 2 : i32
%215 = arith.extsi %214 : i32 to i64
%216 = llvm.mlir.constant(1 : i64) : i64
%217 = llvm.alloca %216 x i64 : (i64) -> !llvm.ptr
llvm.store %215, %217 : i64, !llvm.ptr
%218 = arith.constant 5 : i32
%220 = arith.extsi %218 : i32 to i64
%219 = arith.muli %arg0, %220 : i64
%221 = arith.constant 2 : i32
%223 = arith.extsi %221 : i32 to i64
%222 = arith.cmpi sgt, %219, %223 : i64
cf.cond_br %222, ^bb24, ^bb25
^bb24:
%224 = arith.constant 5 : i32
%226 = arith.extsi %224 : i32 to i64
%225 = arith.muli %arg0, %226 : i64
llvm.store %225, %217 : i64, !llvm.ptr
cf.br ^bb26
^bb25:
%227 = arith.constant 2 : i32
%228 = arith.extsi %227 : i32 to i64
llvm.store %228, %217 : i64, !llvm.ptr
cf.br ^bb26
^bb26:
cf.br ^bb27
^bb27:
%230 = llvm.load %217 : !llvm.ptr -> i64
%229 = func.call @rotation_sum(%230, %arg1, %arg2, %arg3, %arg4, %arg5, %arg6) : (i64, i64, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, f64) -> f64
%231 = arith.cmpf ole, %229, %209 : f64
cf.cond_br %231, ^bb28, ^bb29
^bb28:
%232 = llvm.load %217 : !llvm.ptr -> i64
%233 = arith.constant 2 : i32
%235 = arith.extsi %233 : i32 to i64
%234 = arith.muli %232, %235 : i64
llvm.store %234, %217 : i64, !llvm.ptr
cf.br ^bb27
^bb29:
cf.br ^bb30
^bb30:
%236 = llvm.load %213 : !llvm.ptr -> i64
%237 = arith.constant 1 : i32
%239 = arith.extsi %237 : i32 to i64
%238 = arith.addi %236, %239 : i64
%240 = llvm.load %217 : !llvm.ptr -> i64
%241 = arith.cmpi slt, %238, %240 : i64
cf.cond_br %241, ^bb31, ^bb32
^bb31:
%242 = llvm.load %213 : !llvm.ptr -> i64
%243 = llvm.load %217 : !llvm.ptr -> i64
%244 = arith.addi %242, %243 : i64
%245 = arith.constant 2 : i32
%247 = arith.extsi %245 : i32 to i64
%246 = arith.divsi %244, %247 : i64
%248 = func.call @rotation_sum(%246, %arg1, %arg2, %arg3, %arg4, %arg5, %arg6) : (i64, i64, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, f64) -> f64
%249 = arith.cmpf ogt, %248, %209 : f64
cf.cond_br %249, ^bb33, ^bb34
^bb33:
llvm.store %246, %217 : i64, !llvm.ptr
cf.br ^bb35
^bb34:
llvm.store %246, %213 : i64, !llvm.ptr
cf.br ^bb35
^bb35:
cf.br ^bb30
^bb32:
%250 = llvm.load %217 : !llvm.ptr -> i64
func.return %250 : i64
}
func.func @main() -> i32 {
%251 = arith.constant 500000 : i32
%252 = arith.extsi %251 : i32 to i64
%253 = arith.constant 0.5772156649015329 : f32
%254 = arith.extf %253 : f32 to f64
%256 = arith.constant 2 : i32
%258 = arith.extsi %256 : i32 to i64
%257 = arith.addi %252, %258 : i64
%259 = arith.constant 8 : i32
%260 = arith.extsi %259 : i32 to i64
%255 = func.call @calloc(%257, %260) : (i64, i64) -> !llvm.ptr
%262 = arith.constant 2 : i32
%264 = arith.extsi %262 : i32 to i64
%263 = arith.addi %252, %264 : i64
%265 = arith.constant 8 : i32
%266 = arith.extsi %265 : i32 to i64
%261 = func.call @calloc(%263, %266) : (i64, i64) -> !llvm.ptr
%268 = arith.constant 16 : i32
%269 = arith.constant 8 : i32
%270 = arith.extsi %268 : i32 to i64
%271 = arith.extsi %269 : i32 to i64
%267 = func.call @calloc(%270, %271) : (i64, i64) -> !llvm.ptr
%273 = arith.constant 16 : i32
%274 = arith.constant 8 : i32
%275 = arith.extsi %273 : i32 to i64
%276 = arith.extsi %274 : i32 to i64
%272 = func.call @calloc(%275, %276) : (i64, i64) -> !llvm.ptr
%277 = llvm.mlir.zero : !llvm.ptr
%278 = llvm.icmp "eq" %255, %277 : !llvm.ptr
%279 = scf.if %278 -> (i1) {
%280 = arith.constant true
scf.yield %280 : i1
} else {
%281 = llvm.mlir.zero : !llvm.ptr
%282 = llvm.icmp "eq" %261, %281 : !llvm.ptr
scf.yield %282 : i1
}
%283 = scf.if %279 -> (i1) {
%284 = arith.constant true
scf.yield %284 : i1
} else {
%285 = llvm.mlir.zero : !llvm.ptr
%286 = llvm.icmp "eq" %267, %285 : !llvm.ptr
scf.yield %286 : i1
}
%287 = scf.if %283 -> (i1) {
%288 = arith.constant true
scf.yield %288 : i1
} else {
%289 = llvm.mlir.zero : !llvm.ptr
%290 = llvm.icmp "eq" %272, %289 : !llvm.ptr
scf.yield %290 : i1
}
cf.cond_br %287, ^bb36, ^bb37
^bb36:
%291 = arith.constant 1 : i32
func.return %291 : i32
^bb37:
cf.br ^bb38
^bb38:
%292 = arith.constant 0.9894009349916499 : f32
%293 = arith.negf %292 : f32
%294 = arith.constant 0 : i32
%295 = arith.extf %293 : f32 to f64
%296 = arith.extsi %294 : i32 to i64
%297 = llvm.getelementptr %267[%296] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %295, %297 : f64, !llvm.ptr
%298 = arith.constant 0.9445750230732326 : f32
%299 = arith.negf %298 : f32
%300 = arith.constant 1 : i32
%301 = arith.extf %299 : f32 to f64
%302 = arith.extsi %300 : i32 to i64
%303 = llvm.getelementptr %267[%302] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %301, %303 : f64, !llvm.ptr
%304 = arith.constant 0.8656312023878318 : f32
%305 = arith.negf %304 : f32
%306 = arith.constant 2 : i32
%307 = arith.extf %305 : f32 to f64
%308 = arith.extsi %306 : i32 to i64
%309 = llvm.getelementptr %267[%308] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %307, %309 : f64, !llvm.ptr
%310 = arith.constant 0.755404408355003 : f32
%311 = arith.negf %310 : f32
%312 = arith.constant 3 : i32
%313 = arith.extf %311 : f32 to f64
%314 = arith.extsi %312 : i32 to i64
%315 = llvm.getelementptr %267[%314] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %313, %315 : f64, !llvm.ptr
%316 = arith.constant 0.6178762444026438 : f32
%317 = arith.negf %316 : f32
%318 = arith.constant 4 : i32
%319 = arith.extf %317 : f32 to f64
%320 = arith.extsi %318 : i32 to i64
%321 = llvm.getelementptr %267[%320] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %319, %321 : f64, !llvm.ptr
%322 = arith.constant 0.45801677765722737 : f32
%323 = arith.negf %322 : f32
%324 = arith.constant 5 : i32
%325 = arith.extf %323 : f32 to f64
%326 = arith.extsi %324 : i32 to i64
%327 = llvm.getelementptr %267[%326] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %325, %327 : f64, !llvm.ptr
%328 = arith.constant 0.2816035507792589 : f32
%329 = arith.negf %328 : f32
%330 = arith.constant 6 : i32
%331 = arith.extf %329 : f32 to f64
%332 = arith.extsi %330 : i32 to i64
%333 = llvm.getelementptr %267[%332] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %331, %333 : f64, !llvm.ptr
%334 = arith.constant 0.09501250983763744 : f32
%335 = arith.negf %334 : f32
%336 = arith.constant 7 : i32
%337 = arith.extf %335 : f32 to f64
%338 = arith.extsi %336 : i32 to i64
%339 = llvm.getelementptr %267[%338] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %337, %339 : f64, !llvm.ptr
%340 = arith.constant 0.09501250983763744 : f32
%341 = arith.constant 8 : i32
%342 = arith.extf %340 : f32 to f64
%343 = arith.extsi %341 : i32 to i64
%344 = llvm.getelementptr %267[%343] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %342, %344 : f64, !llvm.ptr
%345 = arith.constant 0.2816035507792589 : f32
%346 = arith.constant 9 : i32
%347 = arith.extf %345 : f32 to f64
%348 = arith.extsi %346 : i32 to i64
%349 = llvm.getelementptr %267[%348] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %347, %349 : f64, !llvm.ptr
%350 = arith.constant 0.45801677765722737 : f32
%351 = arith.constant 10 : i32
%352 = arith.extf %350 : f32 to f64
%353 = arith.extsi %351 : i32 to i64
%354 = llvm.getelementptr %267[%353] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %352, %354 : f64, !llvm.ptr
%355 = arith.constant 0.6178762444026438 : f32
%356 = arith.constant 11 : i32
%357 = arith.extf %355 : f32 to f64
%358 = arith.extsi %356 : i32 to i64
%359 = llvm.getelementptr %267[%358] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %357, %359 : f64, !llvm.ptr
%360 = arith.constant 0.755404408355003 : f32
%361 = arith.constant 12 : i32
%362 = arith.extf %360 : f32 to f64
%363 = arith.extsi %361 : i32 to i64
%364 = llvm.getelementptr %267[%363] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %362, %364 : f64, !llvm.ptr
%365 = arith.constant 0.8656312023878318 : f32
%366 = arith.constant 13 : i32
%367 = arith.extf %365 : f32 to f64
%368 = arith.extsi %366 : i32 to i64
%369 = llvm.getelementptr %267[%368] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %367, %369 : f64, !llvm.ptr
%370 = arith.constant 0.9445750230732326 : f32
%371 = arith.constant 14 : i32
%372 = arith.extf %370 : f32 to f64
%373 = arith.extsi %371 : i32 to i64
%374 = llvm.getelementptr %267[%373] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %372, %374 : f64, !llvm.ptr
%375 = arith.constant 0.9894009349916499 : f32
%376 = arith.constant 15 : i32
%377 = arith.extf %375 : f32 to f64
%378 = arith.extsi %376 : i32 to i64
%379 = llvm.getelementptr %267[%378] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %377, %379 : f64, !llvm.ptr
%380 = arith.constant 0.027152459411754058 : f32
%381 = arith.constant 0 : i32
%382 = arith.extf %380 : f32 to f64
%383 = arith.extsi %381 : i32 to i64
%384 = llvm.getelementptr %272[%383] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %382, %384 : f64, !llvm.ptr
%385 = arith.constant 0.062253523938647776 : f32
%386 = arith.constant 1 : i32
%387 = arith.extf %385 : f32 to f64
%388 = arith.extsi %386 : i32 to i64
%389 = llvm.getelementptr %272[%388] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %387, %389 : f64, !llvm.ptr
%390 = arith.constant 0.0951585116824929 : f32
%391 = arith.constant 2 : i32
%392 = arith.extf %390 : f32 to f64
%393 = arith.extsi %391 : i32 to i64
%394 = llvm.getelementptr %272[%393] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %392, %394 : f64, !llvm.ptr
%395 = arith.constant 0.12462897125553395 : f32
%396 = arith.constant 3 : i32
%397 = arith.extf %395 : f32 to f64
%398 = arith.extsi %396 : i32 to i64
%399 = llvm.getelementptr %272[%398] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %397, %399 : f64, !llvm.ptr
%400 = arith.constant 0.14959598881657682 : f32
%401 = arith.constant 4 : i32
%402 = arith.extf %400 : f32 to f64
%403 = arith.extsi %401 : i32 to i64
%404 = llvm.getelementptr %272[%403] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %402, %404 : f64, !llvm.ptr
%405 = arith.constant 0.16915651939500256 : f32
%406 = arith.constant 5 : i32
%407 = arith.extf %405 : f32 to f64
%408 = arith.extsi %406 : i32 to i64
%409 = llvm.getelementptr %272[%408] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %407, %409 : f64, !llvm.ptr
%410 = arith.constant 0.1826034150449236 : f32
%411 = arith.constant 6 : i32
%412 = arith.extf %410 : f32 to f64
%413 = arith.extsi %411 : i32 to i64
%414 = llvm.getelementptr %272[%413] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %412, %414 : f64, !llvm.ptr
%415 = arith.constant 0.18945061045506847 : f32
%416 = arith.constant 7 : i32
%417 = arith.extf %415 : f32 to f64
%418 = arith.extsi %416 : i32 to i64
%419 = llvm.getelementptr %272[%418] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %417, %419 : f64, !llvm.ptr
%420 = arith.constant 0.18945061045506847 : f32
%421 = arith.constant 8 : i32
%422 = arith.extf %420 : f32 to f64
%423 = arith.extsi %421 : i32 to i64
%424 = llvm.getelementptr %272[%423] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %422, %424 : f64, !llvm.ptr
%425 = arith.constant 0.1826034150449236 : f32
%426 = arith.constant 9 : i32
%427 = arith.extf %425 : f32 to f64
%428 = arith.extsi %426 : i32 to i64
%429 = llvm.getelementptr %272[%428] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %427, %429 : f64, !llvm.ptr
%430 = arith.constant 0.16915651939500256 : f32
%431 = arith.constant 10 : i32
%432 = arith.extf %430 : f32 to f64
%433 = arith.extsi %431 : i32 to i64
%434 = llvm.getelementptr %272[%433] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %432, %434 : f64, !llvm.ptr
%435 = arith.constant 0.14959598881657682 : f32
%436 = arith.constant 11 : i32
%437 = arith.extf %435 : f32 to f64
%438 = arith.extsi %436 : i32 to i64
%439 = llvm.getelementptr %272[%438] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %437, %439 : f64, !llvm.ptr
%440 = arith.constant 0.12462897125553395 : f32
%441 = arith.constant 12 : i32
%442 = arith.extf %440 : f32 to f64
%443 = arith.extsi %441 : i32 to i64
%444 = llvm.getelementptr %272[%443] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %442, %444 : f64, !llvm.ptr
%445 = arith.constant 0.0951585116824929 : f32
%446 = arith.constant 13 : i32
%447 = arith.extf %445 : f32 to f64
%448 = arith.extsi %446 : i32 to i64
%449 = llvm.getelementptr %272[%448] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %447, %449 : f64, !llvm.ptr
%450 = arith.constant 0.062253523938647776 : f32
%451 = arith.constant 14 : i32
%452 = arith.extf %450 : f32 to f64
%453 = arith.extsi %451 : i32 to i64
%454 = llvm.getelementptr %272[%453] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %452, %454 : f64, !llvm.ptr
%455 = arith.constant 0.027152459411754058 : f32
%456 = arith.constant 15 : i32
%457 = arith.extf %455 : f32 to f64
%458 = arith.extsi %456 : i32 to i64
%459 = llvm.getelementptr %272[%458] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %457, %459 : f64, !llvm.ptr
%460 = arith.constant 0.0 : f32
%461 = arith.extf %460 : f32 to f64
%462 = llvm.mlir.constant(1 : i64) : i64
%463 = llvm.alloca %462 x f64 : (i64) -> !llvm.ptr
llvm.store %461, %463 : f64, !llvm.ptr
%464 = arith.constant 1 : i32
%465 = arith.extsi %464 : i32 to i64
%466 = llvm.mlir.constant(1 : i64) : i64
%467 = llvm.alloca %466 x i64 : (i64) -> !llvm.ptr
llvm.store %465, %467 : i64, !llvm.ptr
cf.br ^bb39
^bb39:
%468 = llvm.load %467 : !llvm.ptr -> i64
%469 = arith.cmpi sle, %468, %252 : i64
cf.cond_br %469, ^bb40, ^bb41
^bb40:
%470 = llvm.load %463 : !llvm.ptr -> f64
%471 = arith.constant 1.0 : f32
%472 = llvm.load %467 : !llvm.ptr -> i64
%473 = arith.sitofp %472 : i64 to f64
%475 = arith.extf %471 : f32 to f64
%474 = arith.divf %475, %473 : f64
%476 = arith.addf %470, %474 : f64
llvm.store %476, %463 : f64, !llvm.ptr
%477 = llvm.load %463 : !llvm.ptr -> f64
%478 = llvm.load %467 : !llvm.ptr -> i64
%479 = llvm.getelementptr %255[%478] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %477, %479 : f64, !llvm.ptr
%480 = llvm.load %467 : !llvm.ptr -> i64
%481 = arith.constant 1 : i32
%483 = arith.extsi %481 : i32 to i64
%482 = arith.addi %480, %483 : i64
llvm.store %482, %467 : i64, !llvm.ptr
cf.br ^bb39
^bb41:
%484 = arith.constant 0.0 : f32
%485 = arith.extf %484 : f32 to f64
%486 = llvm.mlir.constant(1 : i64) : i64
%487 = llvm.alloca %486 x f64 : (i64) -> !llvm.ptr
llvm.store %485, %487 : f64, !llvm.ptr
%488 = arith.constant 2 : i32
%489 = arith.extsi %488 : i32 to i64
%490 = llvm.mlir.constant(1 : i64) : i64
%491 = llvm.alloca %490 x i64 : (i64) -> !llvm.ptr
llvm.store %489, %491 : i64, !llvm.ptr
cf.br ^bb42
^bb42:
%492 = llvm.load %491 : !llvm.ptr -> i64
%493 = arith.cmpi sle, %492, %252 : i64
cf.cond_br %493, ^bb43, ^bb44
^bb43:
%494 = llvm.load %491 : !llvm.ptr -> i64
%495 = arith.constant 1 : i32
%497 = arith.extsi %495 : i32 to i64
%496 = arith.subi %494, %497 : i64
%498 = llvm.load %487 : !llvm.ptr -> f64
%500 = arith.sitofp %496 : i64 to f64
%502 = llvm.getelementptr %255[%496] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%501 = llvm.load %502 : !llvm.ptr -> f64
%499 = func.call @beta_from_t(%500, %501) : (f64, f64) -> f64
%503 = arith.addf %498, %499 : f64
llvm.store %503, %487 : f64, !llvm.ptr
%504 = llvm.load %487 : !llvm.ptr -> f64
%505 = llvm.load %491 : !llvm.ptr -> i64
%506 = llvm.getelementptr %261[%505] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %504, %506 : f64, !llvm.ptr
%507 = llvm.load %491 : !llvm.ptr -> i64
%508 = arith.constant 1 : i32
%510 = arith.extsi %508 : i32 to i64
%509 = arith.addi %507, %510 : i64
llvm.store %509, %491 : i64, !llvm.ptr
cf.br ^bb42
^bb44:
%512 = arith.constant 2020 : i32
%513 = arith.extsi %512 : i32 to i64
%511 = func.call @coins_for_loops(%513, %252, %255, %261, %267, %272, %254) : (i64, i64, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, f64) -> i64
%514 = llvm.mlir.addressof @str_0 : !llvm.ptr
%515 = llvm.call @printf(%514, %511) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
func.call @free(%272) : (!llvm.ptr) -> ()
func.call @free(%267) : (!llvm.ptr) -> ()
func.call @free(%261) : (!llvm.ptr) -> ()
func.call @free(%255) : (!llvm.ptr) -> ()
%520 = arith.constant 0 : i32
func.return %520 : i32
}
}