Problem 644
Computes f(200, 500) for the random first move game. Ported from C. Uses f64 math with preallocated arrays.
View problem on Project Euler
Performance comparison
| Metric | Our solution | Best known |
| Time complexity | O(n^3) | ? |
| Space complexity | O(n^2) | ? |
| Approach | Flow solution | Not curated |
| Verdict | Unknown |
Flow source
# Project Euler 644: Squares on the Line.
# Computes f(200, 500) for the random first move game.
# Ported from C. Uses f64 math with preallocated arrays.
extern {
function calloc(n: i64, size: i64) -> ptr<void>
function free(p: ptr<void>)
function printf(fmt: ptr<i8>, ...) -> i32
function fabs(x: f64) -> f64
}
const SQRT2: f64 = 1.4142135623730950488016887242096980785696718753769
const EPS: f64 = 1e-12
const MAX_VALS: i32 = 200000
const MAX_EVENTS: i32 = 2000000
function dmerge_sort(arr: ptr<f64>, lo: i32, hi: i32, tmp: ptr<f64>) -> void {
if hi - lo <= 1 { return }
let mid: i32 = (lo + hi) / 2
dmerge_sort(arr, lo, mid, tmp)
dmerge_sort(arr, mid, hi, tmp)
let mut i: i32 = lo
let mut j: i32 = mid
let mut k: i32 = lo
while i < mid && j < hi {
if arr[i] <= arr[j] { tmp[k] = arr[i]; i = i + 1 }
else { tmp[k] = arr[j]; j = j + 1 }
k = k + 1
}
while i < mid { tmp[k] = arr[i]; i = i + 1; k = k + 1 }
while j < hi { tmp[k] = arr[j]; j = j + 1; k = k + 1 }
let mut x: i32 = lo
while x < hi { arr[x] = tmp[x]; x = x + 1 }
}
function dsort(arr: ptr<f64>, len: i32) -> void {
let tmp: ptr<f64> = calloc(len as i64, 8)
dmerge_sort(arr, 0, len, tmp)
free(tmp as ptr<void>)
}
function dedup_double(arr: ptr<f64>, len: i32) -> i32 {
if len <= 1 { return len }
let mut j: i32 = 0
let mut i: i32 = 1
while i < len {
if arr[i] != arr[j] {
j = j + 1
arr[j] = arr[i]
}
i = i + 1
}
return j + 1
}
function upper_index(arr: ptr<f64>, len: i32, x: f64) -> i32 {
let mut lo: i32 = 0
let mut hi: i32 = len
while lo < hi {
let mid: i32 = (lo + hi) / 2
if arr[mid] <= x { lo = mid + 1 }
else { hi = mid }
}
return lo
}
function generate_ring(max_l: f64, vals: ptr<f64>) -> i32 {
let mut len: i32 = 0
vals[len] = 0.0
len = len + 1
let max_b: i32 = (max_l / SQRT2) as i32 + 1
let mut b: i32 = 0
while b <= max_b {
let base: f64 = (b as f64) * SQRT2
let max_a: i32 = (max_l - base + 1e-12) as i32
let mut a: i32 = 0
while a <= max_a {
vals[len] = (a as f64) + base
len = len + 1
a = a + 1
}
b = b + 1
}
dsort(vals, len)
len = dedup_double(vals, len)
return len
}
function compute_grundy_intervals(max_l: f64, starts: ptr<f64>, ends: ptr<f64>, grundy: ptr<i32>) -> i32 {
let vals: ptr<f64> = calloc(MAX_VALS as i64, 8)
let n: i32 = generate_ring(max_l, vals) - 1
let mut s_len: i32 = 0
let mut e_len: i32 = 0
let mut g_len: i32 = 0
let moves_cap: i32 = 256
let moves: ptr<i8> = calloc(moves_cap as i64, 1)
let mut max_g: i32 = 0
let mut idx: i32 = 0
while idx < n {
let a: f64 = vals[idx]
let b: f64 = vals[idx + 1]
let L: f64 = (a + b) * 0.5
let mut i: i32 = 0
while i <= max_g {
moves[i] = 0
i = i + 1
}
let mut xi: i32 = 0
while xi < 2 {
let x: f64 = if xi == 0 { 1.0 } else { SQRT2 }
let skip: i32 = if L < x { 1 } else { if s_len == 0 { 1 } else { 0 } }
if skip == 0 {
let S: f64 = L - x
let mut u_idx: i32 = upper_index(starts, s_len, S) - 1
let mut t_idx: i32 = 0
let done: ptr<i32> = calloc(1, 4)
while t_idx <= u_idx && done[0] == 0 {
let t_start: f64 = starts[t_idx]
if t_start >= S { done[0] = 1 }
if done[0] == 0 {
let mut t_end: f64 = ends[t_idx]
if t_end > S { t_end = S }
let mut u_end: f64 = ends[u_idx]
if u_end > S { u_end = S }
let u_start: f64 = starts[u_idx]
let mut left: f64 = S - u_end
if t_start > left { left = t_start }
let mut right: f64 = S - u_start
if t_end < right { right = t_end }
if left < right {
let g: i32 = grundy[t_idx] ^ grundy[u_idx]
if g < moves_cap { moves[g] = 1 }
if g > max_g { max_g = g }
}
if t_end < S - u_start { t_idx = t_idx + 1 }
else { u_idx = u_idx - 1 }
}
}
free(done as ptr<void>)
}
xi = xi + 1
}
let mut g: i32 = 0
while g < moves_cap && moves[g] == 1 { g = g + 1 }
if g_len > 0 && grundy[g_len - 1] == g && fabs(ends[e_len - 1] - a) < EPS {
ends[e_len - 1] = b
} else {
starts[s_len] = a
s_len = s_len + 1
ends[e_len] = b
e_len = e_len + 1
grundy[g_len] = g
g_len = g_len + 1
}
idx = idx + 1
}
free(moves as ptr<void>)
free(vals as ptr<void>)
return g_len
}
function ev_merge_sort(idx: ptr<i32>, lo: i32, hi: i32, pos: ptr<f64>, tmp: ptr<i32>) -> void {
if hi - lo <= 1 { return }
let mid: i32 = (lo + hi) / 2
ev_merge_sort(idx, lo, mid, pos, tmp)
ev_merge_sort(idx, mid, hi, pos, tmp)
let mut i: i32 = lo
let mut j: i32 = mid
let mut k: i32 = lo
while i < mid && j < hi {
if pos[idx[i]] <= pos[idx[j]] {
tmp[k] = idx[i]
i = i + 1
} else {
tmp[k] = idx[j]
j = j + 1
}
k = k + 1
}
while i < mid { tmp[k] = idx[i]; i = i + 1; k = k + 1 }
while j < hi { tmp[k] = idx[j]; j = j + 1; k = k + 1 }
let mut x: i32 = lo
while x < hi { idx[x] = tmp[x]; x = x + 1 }
}
function build_w_segments(starts: ptr<f64>, ends: ptr<f64>, grundy: ptr<i32>, g_len: i32, max_s: f64,
seg_starts: ptr<f64>, seg_ends: ptr<f64>, seg_slopes: ptr<f64>, seg_vals: ptr<f64>) -> i32 {
let mut max_g: i32 = 0
let mut i: i32 = 0
while i < g_len {
if grundy[i] > max_g { max_g = grundy[i] }
i = i + 1
}
let gsz: ptr<i32> = calloc((max_g + 1) as i64, 4)
let mut i2: i32 = 0
while i2 < g_len { gsz[grundy[i2]] = gsz[grundy[i2]] + 1; i2 = i2 + 1 }
# Flat arrays with offsets per grundy group
let goff: ptr<i32> = calloc((max_g + 2) as i64, 4)
let mut g3: i32 = 0
while g3 <= max_g {
goff[g3 + 1] = goff[g3] + gsz[g3]
g3 = g3 + 1
}
let total: i32 = goff[max_g + 1]
let ga: ptr<f64> = calloc(total as i64, 8)
let gb: ptr<f64> = calloc(total as i64, 8)
let gidx: ptr<i32> = calloc((max_g + 1) as i64, 4)
let mut i3: i32 = 0
while i3 < g_len {
let gg: i32 = grundy[i3]
let off: i32 = goff[gg] + gidx[gg]
ga[off] = starts[i3]
gb[off] = ends[i3]
gidx[gg] = gidx[gg] + 1
i3 = i3 + 1
}
let ev_pos: ptr<f64> = calloc(MAX_EVENTS as i64, 8)
let ev_delta: ptr<i32> = calloc(MAX_EVENTS as i64, 4)
let mut ev_count: i32 = 0
let mut g2: i32 = 0
while g2 <= max_g {
let m: i32 = gsz[g2]
let off2: i32 = goff[g2]
let mut i4: i32 = 0
while i4 < m {
let a1: f64 = ga[off2 + i4]
let b1: f64 = gb[off2 + i4]
let mut j: i32 = i4
while j < m {
let a2: f64 = ga[off2 + j]
let b2: f64 = gb[off2 + j]
let w: i32 = if i4 == j { 1 } else { 2 }
let p0: f64 = a1 + a2
let p1: f64 = a1 + b2
let p2: f64 = b1 + a2
let p3: f64 = b1 + b2
if p0 > max_s + EPS { break }
let skip: i32 = if p3 < 0.0 { 1 } else { 0 }
if skip == 0 {
let mut pp0: f64 = p0
let mut pp3: f64 = p3
if pp0 < 0.0 { pp0 = 0.0 }
if pp3 > max_s { pp3 = max_s }
let q1: f64 = if p1 < p2 { p1 } else { p2 }
let q2: f64 = if p1 < p2 { p2 } else { p1 }
ev_pos[ev_count] = pp0; ev_delta[ev_count] = w; ev_count = ev_count + 1
ev_pos[ev_count] = q1; ev_delta[ev_count] = -w; ev_count = ev_count + 1
ev_pos[ev_count] = q2; ev_delta[ev_count] = -w; ev_count = ev_count + 1
ev_pos[ev_count] = pp3; ev_delta[ev_count] = w; ev_count = ev_count + 1
}
j = j + 1
}
i4 = i4 + 1
}
g2 = g2 + 1
}
let ev_idx: ptr<i32> = calloc(MAX_EVENTS as i64, 4)
let ev_tmp: ptr<i32> = calloc(MAX_EVENTS as i64, 4)
let mut ei: i32 = 0
while ei < ev_count { ev_idx[ei] = ei; ei = ei + 1 }
ev_merge_sort(ev_idx, 0, ev_count, ev_pos, ev_tmp)
let m_pos: ptr<f64> = calloc(MAX_EVENTS as i64, 8)
let m_delta: ptr<i32> = calloc(MAX_EVENTS as i64, 4)
let mut m_count: i32 = 0
if ev_count > 0 {
let mut cur_pos: f64 = ev_pos[ev_idx[0]]
let mut cur_delta: i32 = ev_delta[ev_idx[0]]
let mut i5: i32 = 1
while i5 < ev_count {
let ip: i32 = ev_idx[i5]
if fabs(ev_pos[ip] - cur_pos) < EPS {
cur_delta = cur_delta + ev_delta[ip]
} else {
m_pos[m_count] = cur_pos
m_delta[m_count] = cur_delta
m_count = m_count + 1
cur_pos = ev_pos[ip]
cur_delta = ev_delta[ip]
}
i5 = i5 + 1
}
m_pos[m_count] = cur_pos
m_delta[m_count] = cur_delta
m_count = m_count + 1
}
let mut seg_count: i32 = 0
let mut slope: f64 = 0.0
let mut val: f64 = 0.0
let mut prev: f64 = 0.0
let mut i6: i32 = 0
while i6 < m_count {
let pos: f64 = m_pos[i6]
let delta: i32 = m_delta[i6]
if pos > max_s { break }
if pos > prev {
seg_starts[seg_count] = prev
seg_ends[seg_count] = pos
seg_slopes[seg_count] = slope
seg_vals[seg_count] = val
seg_count = seg_count + 1
val = val + slope * (pos - prev)
prev = pos
}
slope = slope + (delta as f64)
i6 = i6 + 1
}
if prev < max_s {
seg_starts[seg_count] = prev
seg_ends[seg_count] = max_s
seg_slopes[seg_count] = slope
seg_vals[seg_count] = val
seg_count = seg_count + 1
}
free(ga as ptr<void>)
free(gb as ptr<void>)
free(gsz as ptr<void>)
free(goff as ptr<void>)
free(gidx as ptr<void>)
free(ev_pos as ptr<void>)
free(ev_delta as ptr<void>)
free(ev_idx as ptr<void>)
free(ev_tmp as ptr<void>)
free(m_pos as ptr<void>)
free(m_delta as ptr<void>)
return seg_count
}
function w_value(seg_starts: ptr<f64>, seg_ends: ptr<f64>, seg_slopes: ptr<f64>, seg_vals: ptr<f64>, seg_count: i32, x: f64, out_val: ptr<f64>, out_slope: ptr<f64>) -> void {
let mut lo: i32 = 0
let mut hi: i32 = seg_count
while lo < hi {
let mid: i32 = (lo + hi) / 2
if seg_ends[mid] <= x { lo = mid + 1 }
else { hi = mid }
}
if lo >= seg_count {
out_val[0] = 0.0
out_slope[0] = 0.0
return
}
let start: f64 = seg_starts[lo]
let slope: f64 = seg_slopes[lo]
let val: f64 = seg_vals[lo] + slope * (x - start)
out_val[0] = val
out_slope[0] = slope
}
function term_deriv(m: f64, b0: f64, c: f64, L: f64) -> f64 {
return (m * L * L - 2.0 * m * c * L - b0 * c) / ((L - c) * (L - c))
}
function e_local_func(L: f64, m1: f64, b1: f64, m2: f64, b2: f64) -> f64 {
return 0.5 * L * ((m1 * L + b1) / (L - 1.0) + (m2 * L + b2) / (L - SQRT2))
}
function de_local_func(L: f64, m1: f64, b1: f64, m2: f64, b2: f64) -> f64 {
return 0.5 * (term_deriv(m1, b1, 1.0, L) + term_deriv(m2, b2, SQRT2, L))
}
function bisect_func(lo: f64, hi: f64, dlo: f64, m1: f64, b1: f64, m2: f64, b2: f64) -> f64 {
let mut lo2: f64 = lo
let mut hi2: f64 = hi
let mut dlo2: f64 = dlo
let mut iter: i32 = 0
while iter < 60 {
let m: f64 = (lo2 + hi2) * 0.5
let dm: f64 = de_local_func(m, m1, b1, m2, b2)
if dm == 0.0 { return m }
if dm * dlo2 > 0.0 { lo2 = m; dlo2 = dm }
else { hi2 = m }
iter = iter + 1
}
return (lo2 + hi2) * 0.5
}
function f_value(a: f64, b: f64, seg_starts: ptr<f64>, seg_ends: ptr<f64>, seg_slopes: ptr<f64>, seg_vals: ptr<f64>, seg_count: i32) -> f64 {
let points: ptr<f64> = calloc(MAX_VALS as i64, 8)
let mut p_len: i32 = 0
points[p_len] = a; p_len = p_len + 1
points[p_len] = b; p_len = p_len + 1
let mut i: i32 = 0
while i < seg_count {
let p: f64 = seg_starts[i]
let v1: f64 = p + 1.0
if a < v1 && v1 < b { points[p_len] = v1; p_len = p_len + 1 }
let v2: f64 = p + SQRT2
if a < v2 && v2 < b { points[p_len] = v2; p_len = p_len + 1 }
i = i + 1
}
let mut i2: i32 = 0
while i2 < seg_count {
let p: f64 = seg_ends[i2]
let v1: f64 = p + 1.0
if a < v1 && v1 < b { points[p_len] = v1; p_len = p_len + 1 }
let v2: f64 = p + SQRT2
if a < v2 && v2 < b { points[p_len] = v2; p_len = p_len + 1 }
i2 = i2 + 1
}
dsort(points, p_len)
p_len = dedup_double(points, p_len)
let mut best: f64 = -1.0
let mut i3: i32 = 0
while i3 < p_len - 1 {
let L0: f64 = points[i3]
let L1: f64 = points[i3 + 1]
if L1 - L0 >= 1e-12 {
let mid: f64 = (L0 + L1) * 0.5
let w1p: ptr<f64> = calloc(1, 8)
let m1p: ptr<f64> = calloc(1, 8)
let w2p: ptr<f64> = calloc(1, 8)
let m2p: ptr<f64> = calloc(1, 8)
w_value(seg_starts, seg_ends, seg_slopes, seg_vals, seg_count, mid - 1.0, w1p, m1p)
w_value(seg_starts, seg_ends, seg_slopes, seg_vals, seg_count, mid - SQRT2, w2p, m2p)
let w1: f64 = w1p[0]
let m1: f64 = m1p[0]
let w2: f64 = w2p[0]
let m2: f64 = m2p[0]
let b1: f64 = w1 - m1 * mid
let b2: f64 = w2 - m2 * mid
free(w1p as ptr<void>)
free(m1p as ptr<void>)
free(w2p as ptr<void>)
free(m2p as ptr<void>)
let val0: f64 = e_local_func(L0, m1, b1, m2, b2)
if val0 > best { best = val0 }
let val1: f64 = e_local_func(mid, m1, b1, m2, b2)
if val1 > best { best = val1 }
let val2: f64 = e_local_func(L1, m1, b1, m2, b2)
if val2 > best { best = val2 }
let left: f64 = L0 + 1e-10
let right: f64 = L1 - 1e-10
if left < right {
let dl: f64 = de_local_func(left, m1, b1, m2, b2)
let dm: f64 = de_local_func(mid, m1, b1, m2, b2)
let dr: f64 = de_local_func(right, m1, b1, m2, b2)
if dl * dm < 0.0 {
let root: f64 = bisect_func(left, mid, dl, m1, b1, m2, b2)
let val: f64 = e_local_func(root, m1, b1, m2, b2)
if val > best { best = val }
}
if dm * dr < 0.0 {
let root: f64 = bisect_func(mid, right, dm, m1, b1, m2, b2)
let val: f64 = e_local_func(root, m1, b1, m2, b2)
if val > best { best = val }
}
}
}
i3 = i3 + 1
}
free(points as ptr<void>)
return best
}
function main() -> i32 {
let max_l: f64 = 500.0
let starts: ptr<f64> = calloc(MAX_VALS as i64, 8)
let ends: ptr<f64> = calloc(MAX_VALS as i64, 8)
let grundy: ptr<i32> = calloc(MAX_VALS as i64, 4)
let g_len: i32 = compute_grundy_intervals(max_l, starts, ends, grundy)
let seg_starts: ptr<f64> = calloc(MAX_VALS as i64, 8)
let seg_ends: ptr<f64> = calloc(MAX_VALS as i64, 8)
let seg_slopes: ptr<f64> = calloc(MAX_VALS as i64, 8)
let seg_vals: ptr<f64> = calloc(MAX_VALS as i64, 8)
let seg_count: i32 = build_w_segments(starts, ends, grundy, g_len, max_l, seg_starts, seg_ends, seg_slopes, seg_vals)
let answer: f64 = f_value(200.0, 500.0, seg_starts, seg_ends, seg_slopes, seg_vals, seg_count)
printf("%.8f\n", answer)
free(starts as ptr<void>)
free(ends as ptr<void>)
free(grundy as ptr<void>)
free(seg_starts as ptr<void>)
free(seg_ends as ptr<void>)
free(seg_slopes as ptr<void>)
free(seg_vals as ptr<void>)
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; }
void dmerge_sort_ptr_f64_i32_i32_ptr_f64(double* arr, int32_t lo, int32_t hi, double* tmp);
void dsort_ptr_f64_i32(double* arr, int32_t len);
int32_t dedup_double_ptr_f64_i32(double* arr, int32_t len);
int32_t upper_index_ptr_f64_i32_f64(double* arr, int32_t len, double x);
int32_t generate_ring_f64_ptr_f64(double max_l, double* vals);
int32_t compute_grundy_intervals_f64_ptr_f64_ptr_f64_ptr_i32(double max_l, double* starts, double* ends, int32_t* grundy);
void ev_merge_sort_ptr_i32_i32_i32_ptr_f64_ptr_i32(int32_t* idx, int32_t lo, int32_t hi, double* pos, int32_t* tmp);
int32_t build_w_segments_ptr_f64_ptr_f64_ptr_i32_i32_f64_ptr_f64_ptr_f64_ptr_f64_ptr_f64(double* starts, double* ends, int32_t* grundy, int32_t g_len, double max_s, double* seg_starts, double* seg_ends, double* seg_slopes, double* seg_vals);
void w_value_ptr_f64_ptr_f64_ptr_f64_ptr_f64_i32_f64_ptr_f64_ptr_f64(double* seg_starts, double* seg_ends, double* seg_slopes, double* seg_vals, int32_t seg_count, double x, double* out_val, double* out_slope);
double term_deriv_f64_f64_f64_f64(double m, double b0, double c, double L);
double e_local_func_f64_f64_f64_f64_f64(double L, double m1, double b1, double m2, double b2);
double de_local_func_f64_f64_f64_f64_f64(double L, double m1, double b1, double m2, double b2);
double bisect_func_f64_f64_f64_f64_f64_f64_f64(double lo, double hi, double dlo, double m1, double b1, double m2, double b2);
double f_value_f64_f64_ptr_f64_ptr_f64_ptr_f64_ptr_f64_i32(double a, double b, double* seg_starts, double* seg_ends, double* seg_slopes, double* seg_vals, int32_t seg_count);
int32_t main(void);
static const double SQRT2 = 1.4142135623730950488016887242096980785696718753769;
static const double EPS = 1e-12;
static const int32_t MAX_VALS = 200000;
static const int32_t MAX_EVENTS = 2000000;
void dmerge_sort_ptr_f64_i32_i32_ptr_f64(double* arr, int32_t lo, int32_t hi, double* tmp) {
if ((hi - lo) <= 1) {
return;
}
int32_t mid = FLOW_CHECKED_DIV(((lo + hi)), (2));
dmerge_sort_ptr_f64_i32_i32_ptr_f64(arr, lo, mid, tmp);
dmerge_sort_ptr_f64_i32_i32_ptr_f64(arr, mid, hi, tmp);
int32_t i = lo;
int32_t j = mid;
int32_t k = lo;
while ((i < mid && j < hi)) {
if (arr[i] <= arr[j]) {
tmp[k] = arr[i];
i = (i + 1);
} else {
tmp[k] = arr[j];
j = (j + 1);
}
k = (k + 1);
}
while (i < mid) {
tmp[k] = arr[i];
i = (i + 1);
k = (k + 1);
}
while (j < hi) {
tmp[k] = arr[j];
j = (j + 1);
k = (k + 1);
}
int32_t x = lo;
while (x < hi) {
arr[x] = tmp[x];
x = (x + 1);
}
}
void dsort_ptr_f64_i32(double* arr, int32_t len) {
double* tmp = (double*)(calloc(((int64_t)(len)), 8));
dmerge_sort_ptr_f64_i32_i32_ptr_f64(arr, 0, len, tmp);
free(((void*)(tmp)));
}
int32_t dedup_double_ptr_f64_i32(double* arr, int32_t len) {
if (len <= 1) {
return len;
}
int32_t j = 0;
int32_t i = 1;
while (i < len) {
if (arr[i] != arr[j]) {
j = (j + 1);
arr[j] = arr[i];
}
i = (i + 1);
}
return (j + 1);
}
int32_t upper_index_ptr_f64_i32_f64(double* arr, int32_t len, double x) {
int32_t lo = 0;
int32_t hi = len;
while (lo < hi) {
int32_t mid = FLOW_CHECKED_DIV(((lo + hi)), (2));
if (arr[mid] <= x) {
lo = (mid + 1);
} else {
hi = mid;
}
}
return lo;
}
int32_t generate_ring_f64_ptr_f64(double max_l, double* vals) {
int32_t len = 0;
vals[len] = 0.0;
len = (len + 1);
int32_t max_b = (((int32_t)((max_l / SQRT2))) + 1);
int32_t b = 0;
while (b <= max_b) {
double base = (((double)(b)) * SQRT2);
int32_t max_a = ((int32_t)(((max_l - base) + 1e-12)));
int32_t a = 0;
while (a <= max_a) {
vals[len] = (((double)(a)) + base);
len = (len + 1);
a = (a + 1);
}
b = (b + 1);
}
dsort_ptr_f64_i32(vals, len);
len = dedup_double_ptr_f64_i32(vals, len);
return len;
}
int32_t compute_grundy_intervals_f64_ptr_f64_ptr_f64_ptr_i32(double max_l, double* starts, double* ends, int32_t* grundy) {
double* vals = (double*)(calloc(((int64_t)(MAX_VALS)), 8));
int32_t n = (generate_ring_f64_ptr_f64(max_l, vals) - 1);
int32_t s_len = 0;
int32_t e_len = 0;
int32_t g_len = 0;
int32_t moves_cap = 256;
int8_t* moves = (int8_t*)(calloc(((int64_t)(moves_cap)), 1));
int32_t max_g = 0;
int32_t idx = 0;
while (idx < n) {
double a = vals[idx];
double b = vals[(idx + 1)];
double L = ((a + b) * 0.5);
int32_t i = 0;
while (i <= max_g) {
moves[i] = 0;
i = (i + 1);
}
int32_t xi = 0;
while (xi < 2) {
double x = ((xi == 0) ? (1.0) : (SQRT2));
int32_t skip = ((L < x) ? (1) : (((s_len == 0) ? (1) : (0))));
if (skip == 0) {
double S = (L - x);
int32_t u_idx = (upper_index_ptr_f64_i32_f64(starts, s_len, S) - 1);
int32_t t_idx = 0;
int32_t* done = (int32_t*)(calloc(1, 4));
while ((t_idx <= u_idx && done[0] == 0)) {
double t_start = starts[t_idx];
if (t_start >= S) {
done[0] = 1;
}
if (done[0] == 0) {
double t_end = ends[t_idx];
if (t_end > S) {
t_end = S;
}
double u_end = ends[u_idx];
if (u_end > S) {
u_end = S;
}
double u_start = starts[u_idx];
double left = (S - u_end);
if (t_start > left) {
left = t_start;
}
double right = (S - u_start);
if (t_end < right) {
right = t_end;
}
if (left < right) {
int32_t g = (grundy[t_idx] ^ grundy[u_idx]);
if (g < moves_cap) {
moves[g] = 1;
}
if (g > max_g) {
max_g = g;
}
}
if (t_end < (S - u_start)) {
t_idx = (t_idx + 1);
} else {
u_idx = (u_idx - 1);
}
}
}
free(((void*)(done)));
}
xi = (xi + 1);
}
int32_t g = 0;
while ((g < moves_cap && moves[g] == 1)) {
g = (g + 1);
}
if (((g_len > 0 && grundy[(g_len - 1)] == g) && fabs((ends[(e_len - 1)] - a)) < EPS)) {
ends[(e_len - 1)] = b;
} else {
starts[s_len] = a;
s_len = (s_len + 1);
ends[e_len] = b;
e_len = (e_len + 1);
grundy[g_len] = g;
g_len = (g_len + 1);
}
idx = (idx + 1);
}
free(((void*)(moves)));
free(((void*)(vals)));
return g_len;
}
void ev_merge_sort_ptr_i32_i32_i32_ptr_f64_ptr_i32(int32_t* idx, int32_t lo, int32_t hi, double* pos, int32_t* tmp) {
if ((hi - lo) <= 1) {
return;
}
int32_t mid = FLOW_CHECKED_DIV(((lo + hi)), (2));
ev_merge_sort_ptr_i32_i32_i32_ptr_f64_ptr_i32(idx, lo, mid, pos, tmp);
ev_merge_sort_ptr_i32_i32_i32_ptr_f64_ptr_i32(idx, mid, hi, pos, tmp);
int32_t i = lo;
int32_t j = mid;
int32_t k = lo;
while ((i < mid && j < hi)) {
if (pos[idx[i]] <= pos[idx[j]]) {
tmp[k] = idx[i];
i = (i + 1);
} else {
tmp[k] = idx[j];
j = (j + 1);
}
k = (k + 1);
}
while (i < mid) {
tmp[k] = idx[i];
i = (i + 1);
k = (k + 1);
}
while (j < hi) {
tmp[k] = idx[j];
j = (j + 1);
k = (k + 1);
}
int32_t x = lo;
while (x < hi) {
idx[x] = tmp[x];
x = (x + 1);
}
}
int32_t build_w_segments_ptr_f64_ptr_f64_ptr_i32_i32_f64_ptr_f64_ptr_f64_ptr_f64_ptr_f64(double* starts, double* ends, int32_t* grundy, int32_t g_len, double max_s, double* seg_starts, double* seg_ends, double* seg_slopes, double* seg_vals) {
int32_t max_g = 0;
int32_t i = 0;
while (i < g_len) {
if (grundy[i] > max_g) {
max_g = grundy[i];
}
i = (i + 1);
}
int32_t* gsz = (int32_t*)(calloc(((int64_t)((max_g + 1))), 4));
int32_t i2 = 0;
while (i2 < g_len) {
gsz[grundy[i2]] = (gsz[grundy[i2]] + 1);
i2 = (i2 + 1);
}
int32_t* goff = (int32_t*)(calloc(((int64_t)((max_g + 2))), 4));
int32_t g3 = 0;
while (g3 <= max_g) {
goff[(g3 + 1)] = (goff[g3] + gsz[g3]);
g3 = (g3 + 1);
}
int32_t total = goff[(max_g + 1)];
double* ga = (double*)(calloc(((int64_t)(total)), 8));
double* gb = (double*)(calloc(((int64_t)(total)), 8));
int32_t* gidx = (int32_t*)(calloc(((int64_t)((max_g + 1))), 4));
int32_t i3 = 0;
while (i3 < g_len) {
int32_t gg = grundy[i3];
int32_t off = (goff[gg] + gidx[gg]);
ga[off] = starts[i3];
gb[off] = ends[i3];
gidx[gg] = (gidx[gg] + 1);
i3 = (i3 + 1);
}
double* ev_pos = (double*)(calloc(((int64_t)(MAX_EVENTS)), 8));
int32_t* ev_delta = (int32_t*)(calloc(((int64_t)(MAX_EVENTS)), 4));
int32_t ev_count = 0;
int32_t g2 = 0;
while (g2 <= max_g) {
int32_t m = gsz[g2];
int32_t off2 = goff[g2];
int32_t i4 = 0;
while (i4 < m) {
double a1 = ga[(off2 + i4)];
double b1 = gb[(off2 + i4)];
int32_t j = i4;
while (j < m) {
double a2 = ga[(off2 + j)];
double b2 = gb[(off2 + j)];
int32_t w = ((i4 == j) ? (1) : (2));
double p0 = (a1 + a2);
double p1 = (a1 + b2);
double p2 = (b1 + a2);
double p3 = (b1 + b2);
if (p0 > (max_s + EPS)) {
break;
}
int32_t skip = ((p3 < 0.0) ? (1) : (0));
if (skip == 0) {
double pp0 = p0;
double pp3 = p3;
if (pp0 < 0.0) {
pp0 = 0.0;
}
if (pp3 > max_s) {
pp3 = max_s;
}
double q1 = ((p1 < p2) ? (p1) : (p2));
double q2 = ((p1 < p2) ? (p2) : (p1));
ev_pos[ev_count] = pp0;
ev_delta[ev_count] = w;
ev_count = (ev_count + 1);
ev_pos[ev_count] = q1;
ev_delta[ev_count] = (-w);
ev_count = (ev_count + 1);
ev_pos[ev_count] = q2;
ev_delta[ev_count] = (-w);
ev_count = (ev_count + 1);
ev_pos[ev_count] = pp3;
ev_delta[ev_count] = w;
ev_count = (ev_count + 1);
}
j = (j + 1);
}
i4 = (i4 + 1);
}
g2 = (g2 + 1);
}
int32_t* ev_idx = (int32_t*)(calloc(((int64_t)(MAX_EVENTS)), 4));
int32_t* ev_tmp = (int32_t*)(calloc(((int64_t)(MAX_EVENTS)), 4));
int32_t ei = 0;
while (ei < ev_count) {
ev_idx[ei] = ei;
ei = (ei + 1);
}
ev_merge_sort_ptr_i32_i32_i32_ptr_f64_ptr_i32(ev_idx, 0, ev_count, ev_pos, ev_tmp);
double* m_pos = (double*)(calloc(((int64_t)(MAX_EVENTS)), 8));
int32_t* m_delta = (int32_t*)(calloc(((int64_t)(MAX_EVENTS)), 4));
int32_t m_count = 0;
if (ev_count > 0) {
double cur_pos = ev_pos[ev_idx[0]];
int32_t cur_delta = ev_delta[ev_idx[0]];
int32_t i5 = 1;
while (i5 < ev_count) {
int32_t ip = ev_idx[i5];
if (fabs((ev_pos[ip] - cur_pos)) < EPS) {
cur_delta = (cur_delta + ev_delta[ip]);
} else {
m_pos[m_count] = cur_pos;
m_delta[m_count] = cur_delta;
m_count = (m_count + 1);
cur_pos = ev_pos[ip];
cur_delta = ev_delta[ip];
}
i5 = (i5 + 1);
}
m_pos[m_count] = cur_pos;
m_delta[m_count] = cur_delta;
m_count = (m_count + 1);
}
int32_t seg_count = 0;
double slope = 0.0;
double val = 0.0;
double prev = 0.0;
int32_t i6 = 0;
while (i6 < m_count) {
double pos = m_pos[i6];
int32_t delta = m_delta[i6];
if (pos > max_s) {
break;
}
if (pos > prev) {
seg_starts[seg_count] = prev;
seg_ends[seg_count] = pos;
seg_slopes[seg_count] = slope;
seg_vals[seg_count] = val;
seg_count = (seg_count + 1);
val = (val + (slope * (pos - prev)));
prev = pos;
}
slope = (slope + ((double)(delta)));
i6 = (i6 + 1);
}
if (prev < max_s) {
seg_starts[seg_count] = prev;
seg_ends[seg_count] = max_s;
seg_slopes[seg_count] = slope;
seg_vals[seg_count] = val;
seg_count = (seg_count + 1);
}
free(((void*)(ga)));
free(((void*)(gb)));
free(((void*)(gsz)));
free(((void*)(goff)));
free(((void*)(gidx)));
free(((void*)(ev_pos)));
free(((void*)(ev_delta)));
free(((void*)(ev_idx)));
free(((void*)(ev_tmp)));
free(((void*)(m_pos)));
free(((void*)(m_delta)));
return seg_count;
}
void w_value_ptr_f64_ptr_f64_ptr_f64_ptr_f64_i32_f64_ptr_f64_ptr_f64(double* seg_starts, double* seg_ends, double* seg_slopes, double* seg_vals, int32_t seg_count, double x, double* out_val, double* out_slope) {
int32_t lo = 0;
int32_t hi = seg_count;
while (lo < hi) {
int32_t mid = FLOW_CHECKED_DIV(((lo + hi)), (2));
if (seg_ends[mid] <= x) {
lo = (mid + 1);
} else {
hi = mid;
}
}
if (lo >= seg_count) {
out_val[0] = 0.0;
out_slope[0] = 0.0;
return;
}
double start = seg_starts[lo];
double slope = seg_slopes[lo];
double val = (seg_vals[lo] + (slope * (x - start)));
out_val[0] = val;
out_slope[0] = slope;
}
double term_deriv_f64_f64_f64_f64(double m, double b0, double c, double L) {
return (((((m * L) * L) - (((2.0 * m) * c) * L)) - (b0 * c)) / ((L - c) * (L - c)));
}
double e_local_func_f64_f64_f64_f64_f64(double L, double m1, double b1, double m2, double b2) {
return ((0.5 * L) * ((((m1 * L) + b1) / (L - 1.0)) + (((m2 * L) + b2) / (L - SQRT2))));
}
double de_local_func_f64_f64_f64_f64_f64(double L, double m1, double b1, double m2, double b2) {
return (0.5 * (term_deriv_f64_f64_f64_f64(m1, b1, 1.0, L) + term_deriv_f64_f64_f64_f64(m2, b2, SQRT2, L)));
}
double bisect_func_f64_f64_f64_f64_f64_f64_f64(double lo, double hi, double dlo, double m1, double b1, double m2, double b2) {
double lo2 = lo;
double hi2 = hi;
double dlo2 = dlo;
int32_t iter = 0;
while (iter < 60) {
double m = ((lo2 + hi2) * 0.5);
double dm = de_local_func_f64_f64_f64_f64_f64(m, m1, b1, m2, b2);
if (dm == 0.0) {
return m;
}
if ((dm * dlo2) > 0.0) {
lo2 = m;
dlo2 = dm;
} else {
hi2 = m;
}
iter = (iter + 1);
}
return ((lo2 + hi2) * 0.5);
}
double f_value_f64_f64_ptr_f64_ptr_f64_ptr_f64_ptr_f64_i32(double a, double b, double* seg_starts, double* seg_ends, double* seg_slopes, double* seg_vals, int32_t seg_count) {
double* points = (double*)(calloc(((int64_t)(MAX_VALS)), 8));
int32_t p_len = 0;
points[p_len] = a;
p_len = (p_len + 1);
points[p_len] = b;
p_len = (p_len + 1);
int32_t i = 0;
while (i < seg_count) {
double p = seg_starts[i];
double v1 = (p + 1.0);
if ((a < v1 && v1 < b)) {
points[p_len] = v1;
p_len = (p_len + 1);
}
double v2 = (p + SQRT2);
if ((a < v2 && v2 < b)) {
points[p_len] = v2;
p_len = (p_len + 1);
}
i = (i + 1);
}
int32_t i2 = 0;
while (i2 < seg_count) {
double p = seg_ends[i2];
double v1 = (p + 1.0);
if ((a < v1 && v1 < b)) {
points[p_len] = v1;
p_len = (p_len + 1);
}
double v2 = (p + SQRT2);
if ((a < v2 && v2 < b)) {
points[p_len] = v2;
p_len = (p_len + 1);
}
i2 = (i2 + 1);
}
dsort_ptr_f64_i32(points, p_len);
p_len = dedup_double_ptr_f64_i32(points, p_len);
double best = (-1.0);
int32_t i3 = 0;
while (i3 < (p_len - 1)) {
double L0 = points[i3];
double L1 = points[(i3 + 1)];
if ((L1 - L0) >= 1e-12) {
double mid = ((L0 + L1) * 0.5);
double* w1p = (double*)(calloc(1, 8));
double* m1p = (double*)(calloc(1, 8));
double* w2p = (double*)(calloc(1, 8));
double* m2p = (double*)(calloc(1, 8));
w_value_ptr_f64_ptr_f64_ptr_f64_ptr_f64_i32_f64_ptr_f64_ptr_f64(seg_starts, seg_ends, seg_slopes, seg_vals, seg_count, (mid - 1.0), w1p, m1p);
w_value_ptr_f64_ptr_f64_ptr_f64_ptr_f64_i32_f64_ptr_f64_ptr_f64(seg_starts, seg_ends, seg_slopes, seg_vals, seg_count, (mid - SQRT2), w2p, m2p);
double w1 = w1p[0];
double m1 = m1p[0];
double w2 = w2p[0];
double m2 = m2p[0];
double b1 = (w1 - (m1 * mid));
double b2 = (w2 - (m2 * mid));
free(((void*)(w1p)));
free(((void*)(m1p)));
free(((void*)(w2p)));
free(((void*)(m2p)));
double val0 = e_local_func_f64_f64_f64_f64_f64(L0, m1, b1, m2, b2);
if (val0 > best) {
best = val0;
}
double val1 = e_local_func_f64_f64_f64_f64_f64(mid, m1, b1, m2, b2);
if (val1 > best) {
best = val1;
}
double val2 = e_local_func_f64_f64_f64_f64_f64(L1, m1, b1, m2, b2);
if (val2 > best) {
best = val2;
}
double left = (L0 + 1e-10);
double right = (L1 - 1e-10);
if (left < right) {
double dl = de_local_func_f64_f64_f64_f64_f64(left, m1, b1, m2, b2);
double dm = de_local_func_f64_f64_f64_f64_f64(mid, m1, b1, m2, b2);
double dr = de_local_func_f64_f64_f64_f64_f64(right, m1, b1, m2, b2);
if ((dl * dm) < 0.0) {
double root = bisect_func_f64_f64_f64_f64_f64_f64_f64(left, mid, dl, m1, b1, m2, b2);
double val = e_local_func_f64_f64_f64_f64_f64(root, m1, b1, m2, b2);
if (val > best) {
best = val;
}
}
if ((dm * dr) < 0.0) {
double root = bisect_func_f64_f64_f64_f64_f64_f64_f64(mid, right, dm, m1, b1, m2, b2);
double val = e_local_func_f64_f64_f64_f64_f64(root, m1, b1, m2, b2);
if (val > best) {
best = val;
}
}
}
}
i3 = (i3 + 1);
}
free(((void*)(points)));
return best;
}
int32_t main(void) {
double max_l = 500.0;
double* starts = (double*)(calloc(((int64_t)(MAX_VALS)), 8));
double* ends = (double*)(calloc(((int64_t)(MAX_VALS)), 8));
int32_t* grundy = (int32_t*)(calloc(((int64_t)(MAX_VALS)), 4));
int32_t g_len = compute_grundy_intervals_f64_ptr_f64_ptr_f64_ptr_i32(max_l, starts, ends, grundy);
double* seg_starts = (double*)(calloc(((int64_t)(MAX_VALS)), 8));
double* seg_ends = (double*)(calloc(((int64_t)(MAX_VALS)), 8));
double* seg_slopes = (double*)(calloc(((int64_t)(MAX_VALS)), 8));
double* seg_vals = (double*)(calloc(((int64_t)(MAX_VALS)), 8));
int32_t seg_count = build_w_segments_ptr_f64_ptr_f64_ptr_i32_i32_f64_ptr_f64_ptr_f64_ptr_f64_ptr_f64(starts, ends, grundy, g_len, max_l, seg_starts, seg_ends, seg_slopes, seg_vals);
double answer = f_value_f64_f64_ptr_f64_ptr_f64_ptr_f64_ptr_f64_i32(200.0, 500.0, seg_starts, seg_ends, seg_slopes, seg_vals, seg_count);
printf("%.8f\n", answer);
free(((void*)(starts)));
free(((void*)(ends)));
free(((void*)(grundy)));
free(((void*)(seg_starts)));
free(((void*)(seg_ends)));
free(((void*)(seg_slopes)));
free(((void*)(seg_vals)));
return 0;
}
Generated MLIR
module {
llvm.func @printf(!llvm.ptr, ...) -> i32
llvm.mlir.global internal constant @str_0("%.8f\n\00") {addr_space = 0 : i32} : !llvm.array<6 x i8>
func.func private @calloc(i64, i64) -> !llvm.ptr
func.func private @free(!llvm.ptr) -> ()
func.func private @fabs(f64) -> f64
// Constant: SQRT2
llvm.mlir.global internal constant @SQRT2(1.4142135623730950488016887242096980785696718753769 : f64) : f64
// Constant: EPS
llvm.mlir.global internal constant @EPS(0.000000000001 : f64) : f64
// Constant: MAX_VALS
llvm.mlir.global internal constant @MAX_VALS(200000 : i32) : i32
// Constant: MAX_EVENTS
llvm.mlir.global internal constant @MAX_EVENTS(2000000 : i32) : i32
func.func @dmerge_sort(%arg0: !llvm.ptr, %arg1: i32, %arg2: i32, %arg3: !llvm.ptr) -> () {
%0 = arith.subi %arg2, %arg1 : i32
%1 = arith.constant 1 : i32
%2 = arith.cmpi sle, %0, %1 : i32
cf.cond_br %2, ^bb0, ^bb1
^bb0:
func.return
^bb1:
cf.br ^bb2
^bb2:
%3 = arith.addi %arg1, %arg2 : i32
%4 = arith.constant 2 : i32
%5 = arith.divsi %3, %4 : i32
func.call @dmerge_sort(%arg0, %arg1, %5, %arg3) : (!llvm.ptr, i32, i32, !llvm.ptr) -> ()
func.call @dmerge_sort(%arg0, %5, %arg2, %arg3) : (!llvm.ptr, i32, i32, !llvm.ptr) -> ()
%8 = llvm.mlir.constant(1 : i64) : i64
%9 = llvm.alloca %8 x i32 : (i64) -> !llvm.ptr
llvm.store %arg1, %9 : i32, !llvm.ptr
%10 = llvm.mlir.constant(1 : i64) : i64
%11 = llvm.alloca %10 x i32 : (i64) -> !llvm.ptr
llvm.store %5, %11 : i32, !llvm.ptr
%12 = llvm.mlir.constant(1 : i64) : i64
%13 = llvm.alloca %12 x i32 : (i64) -> !llvm.ptr
llvm.store %arg1, %13 : i32, !llvm.ptr
cf.br ^bb3
^bb3:
%14 = llvm.load %9 : !llvm.ptr -> i32
%15 = arith.cmpi slt, %14, %5 : i32
%16 = scf.if %15 -> (i1) {
%17 = llvm.load %11 : !llvm.ptr -> i32
%18 = arith.cmpi slt, %17, %arg2 : i32
scf.yield %18 : i1
} else {
%19 = arith.constant false
scf.yield %19 : i1
}
cf.cond_br %16, ^bb4, ^bb5
^bb4:
%21 = llvm.load %9 : !llvm.ptr -> i32
%22 = arith.extsi %21 : i32 to i64
%23 = llvm.getelementptr %arg0[%22] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%20 = llvm.load %23 : !llvm.ptr -> f64
%25 = llvm.load %11 : !llvm.ptr -> i32
%26 = arith.extsi %25 : i32 to i64
%27 = llvm.getelementptr %arg0[%26] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%24 = llvm.load %27 : !llvm.ptr -> f64
%28 = arith.cmpf ole, %20, %24 : f64
cf.cond_br %28, ^bb6, ^bb7
^bb6:
%30 = llvm.load %9 : !llvm.ptr -> i32
%31 = arith.extsi %30 : i32 to i64
%32 = llvm.getelementptr %arg0[%31] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%29 = llvm.load %32 : !llvm.ptr -> f64
%33 = llvm.load %13 : !llvm.ptr -> i32
%34 = arith.extsi %33 : i32 to i64
%35 = llvm.getelementptr %arg3[%34] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %29, %35 : f64, !llvm.ptr
%36 = llvm.load %9 : !llvm.ptr -> i32
%37 = arith.constant 1 : i32
%38 = arith.addi %36, %37 : i32
llvm.store %38, %9 : i32, !llvm.ptr
cf.br ^bb8
^bb7:
%40 = llvm.load %11 : !llvm.ptr -> i32
%41 = arith.extsi %40 : i32 to i64
%42 = llvm.getelementptr %arg0[%41] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%39 = llvm.load %42 : !llvm.ptr -> f64
%43 = llvm.load %13 : !llvm.ptr -> i32
%44 = arith.extsi %43 : i32 to i64
%45 = llvm.getelementptr %arg3[%44] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %39, %45 : f64, !llvm.ptr
%46 = llvm.load %11 : !llvm.ptr -> i32
%47 = arith.constant 1 : i32
%48 = arith.addi %46, %47 : i32
llvm.store %48, %11 : i32, !llvm.ptr
cf.br ^bb8
^bb8:
%49 = llvm.load %13 : !llvm.ptr -> i32
%50 = arith.constant 1 : i32
%51 = arith.addi %49, %50 : i32
llvm.store %51, %13 : i32, !llvm.ptr
cf.br ^bb3
^bb5:
cf.br ^bb9
^bb9:
%52 = llvm.load %9 : !llvm.ptr -> i32
%53 = arith.cmpi slt, %52, %5 : i32
cf.cond_br %53, ^bb10, ^bb11
^bb10:
%55 = llvm.load %9 : !llvm.ptr -> i32
%56 = arith.extsi %55 : i32 to i64
%57 = llvm.getelementptr %arg0[%56] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%54 = llvm.load %57 : !llvm.ptr -> f64
%58 = llvm.load %13 : !llvm.ptr -> i32
%59 = arith.extsi %58 : i32 to i64
%60 = llvm.getelementptr %arg3[%59] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %54, %60 : f64, !llvm.ptr
%61 = llvm.load %9 : !llvm.ptr -> i32
%62 = arith.constant 1 : i32
%63 = arith.addi %61, %62 : i32
llvm.store %63, %9 : i32, !llvm.ptr
%64 = llvm.load %13 : !llvm.ptr -> i32
%65 = arith.constant 1 : i32
%66 = arith.addi %64, %65 : i32
llvm.store %66, %13 : i32, !llvm.ptr
cf.br ^bb9
^bb11:
cf.br ^bb12
^bb12:
%67 = llvm.load %11 : !llvm.ptr -> i32
%68 = arith.cmpi slt, %67, %arg2 : i32
cf.cond_br %68, ^bb13, ^bb14
^bb13:
%70 = llvm.load %11 : !llvm.ptr -> i32
%71 = arith.extsi %70 : i32 to i64
%72 = llvm.getelementptr %arg0[%71] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%69 = llvm.load %72 : !llvm.ptr -> f64
%73 = llvm.load %13 : !llvm.ptr -> i32
%74 = arith.extsi %73 : i32 to i64
%75 = llvm.getelementptr %arg3[%74] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %69, %75 : f64, !llvm.ptr
%76 = llvm.load %11 : !llvm.ptr -> i32
%77 = arith.constant 1 : i32
%78 = arith.addi %76, %77 : i32
llvm.store %78, %11 : i32, !llvm.ptr
%79 = llvm.load %13 : !llvm.ptr -> i32
%80 = arith.constant 1 : i32
%81 = arith.addi %79, %80 : i32
llvm.store %81, %13 : i32, !llvm.ptr
cf.br ^bb12
^bb14:
%82 = llvm.mlir.constant(1 : i64) : i64
%83 = llvm.alloca %82 x i32 : (i64) -> !llvm.ptr
llvm.store %arg1, %83 : i32, !llvm.ptr
cf.br ^bb15
^bb15:
%84 = llvm.load %83 : !llvm.ptr -> i32
%85 = arith.cmpi slt, %84, %arg2 : i32
cf.cond_br %85, ^bb16, ^bb17
^bb16:
%87 = llvm.load %83 : !llvm.ptr -> i32
%88 = arith.extsi %87 : i32 to i64
%89 = llvm.getelementptr %arg3[%88] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%86 = llvm.load %89 : !llvm.ptr -> f64
%90 = llvm.load %83 : !llvm.ptr -> i32
%91 = arith.extsi %90 : i32 to i64
%92 = llvm.getelementptr %arg0[%91] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %86, %92 : f64, !llvm.ptr
%93 = llvm.load %83 : !llvm.ptr -> i32
%94 = arith.constant 1 : i32
%95 = arith.addi %93, %94 : i32
llvm.store %95, %83 : i32, !llvm.ptr
cf.br ^bb15
^bb17:
func.return
}
func.func @dsort(%arg0: !llvm.ptr, %arg1: i32) -> () {
%97 = arith.extsi %arg1 : i32 to i64
%98 = arith.constant 8 : i32
%99 = arith.extsi %98 : i32 to i64
%96 = func.call @calloc(%97, %99) : (i64, i64) -> !llvm.ptr
%101 = arith.constant 0 : i32
func.call @dmerge_sort(%arg0, %101, %arg1, %96) : (!llvm.ptr, i32, i32, !llvm.ptr) -> ()
func.call @free(%96) : (!llvm.ptr) -> ()
func.return
}
func.func @dedup_double(%arg0: !llvm.ptr, %arg1: i32) -> i32 {
%103 = arith.constant 1 : i32
%104 = arith.cmpi sle, %arg1, %103 : i32
cf.cond_br %104, ^bb18, ^bb19
^bb18:
func.return %arg1 : i32
^bb19:
cf.br ^bb20
^bb20:
%105 = arith.constant 0 : i32
%106 = llvm.mlir.constant(1 : i64) : i64
%107 = llvm.alloca %106 x i32 : (i64) -> !llvm.ptr
llvm.store %105, %107 : i32, !llvm.ptr
%108 = arith.constant 1 : i32
%109 = llvm.mlir.constant(1 : i64) : i64
%110 = llvm.alloca %109 x i32 : (i64) -> !llvm.ptr
llvm.store %108, %110 : i32, !llvm.ptr
cf.br ^bb21
^bb21:
%111 = llvm.load %110 : !llvm.ptr -> i32
%112 = arith.cmpi slt, %111, %arg1 : i32
cf.cond_br %112, ^bb22, ^bb23
^bb22:
%114 = llvm.load %110 : !llvm.ptr -> i32
%115 = arith.extsi %114 : i32 to i64
%116 = llvm.getelementptr %arg0[%115] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%113 = llvm.load %116 : !llvm.ptr -> f64
%118 = llvm.load %107 : !llvm.ptr -> i32
%119 = arith.extsi %118 : i32 to i64
%120 = llvm.getelementptr %arg0[%119] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%117 = llvm.load %120 : !llvm.ptr -> f64
%121 = arith.cmpf one, %113, %117 : f64
cf.cond_br %121, ^bb24, ^bb25
^bb24:
%122 = llvm.load %107 : !llvm.ptr -> i32
%123 = arith.constant 1 : i32
%124 = arith.addi %122, %123 : i32
llvm.store %124, %107 : i32, !llvm.ptr
%126 = llvm.load %110 : !llvm.ptr -> i32
%127 = arith.extsi %126 : i32 to i64
%128 = llvm.getelementptr %arg0[%127] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%125 = llvm.load %128 : !llvm.ptr -> f64
%129 = llvm.load %107 : !llvm.ptr -> i32
%130 = arith.extsi %129 : i32 to i64
%131 = llvm.getelementptr %arg0[%130] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %125, %131 : f64, !llvm.ptr
cf.br ^bb26
^bb25:
cf.br ^bb26
^bb26:
%132 = llvm.load %110 : !llvm.ptr -> i32
%133 = arith.constant 1 : i32
%134 = arith.addi %132, %133 : i32
llvm.store %134, %110 : i32, !llvm.ptr
cf.br ^bb21
^bb23:
%135 = llvm.load %107 : !llvm.ptr -> i32
%136 = arith.constant 1 : i32
%137 = arith.addi %135, %136 : i32
func.return %137 : i32
}
func.func @upper_index(%arg0: !llvm.ptr, %arg1: i32, %arg2: f64) -> i32 {
%138 = arith.constant 0 : i32
%139 = llvm.mlir.constant(1 : i64) : i64
%140 = llvm.alloca %139 x i32 : (i64) -> !llvm.ptr
llvm.store %138, %140 : i32, !llvm.ptr
%141 = llvm.mlir.constant(1 : i64) : i64
%142 = llvm.alloca %141 x i32 : (i64) -> !llvm.ptr
llvm.store %arg1, %142 : i32, !llvm.ptr
cf.br ^bb27
^bb27:
%143 = llvm.load %140 : !llvm.ptr -> i32
%144 = llvm.load %142 : !llvm.ptr -> i32
%145 = arith.cmpi slt, %143, %144 : i32
cf.cond_br %145, ^bb28, ^bb29
^bb28:
%146 = llvm.load %140 : !llvm.ptr -> i32
%147 = llvm.load %142 : !llvm.ptr -> i32
%148 = arith.addi %146, %147 : i32
%149 = arith.constant 2 : i32
%150 = arith.divsi %148, %149 : i32
%152 = arith.extsi %150 : i32 to i64
%153 = llvm.getelementptr %arg0[%152] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%151 = llvm.load %153 : !llvm.ptr -> f64
%154 = arith.cmpf ole, %151, %arg2 : f64
cf.cond_br %154, ^bb30, ^bb31
^bb30:
%155 = arith.constant 1 : i32
%156 = arith.addi %150, %155 : i32
llvm.store %156, %140 : i32, !llvm.ptr
cf.br ^bb32
^bb31:
llvm.store %150, %142 : i32, !llvm.ptr
cf.br ^bb32
^bb32:
cf.br ^bb27
^bb29:
%157 = llvm.load %140 : !llvm.ptr -> i32
func.return %157 : i32
}
func.func @generate_ring(%arg0: f64, %arg1: !llvm.ptr) -> i32 {
%158 = arith.constant 0 : i32
%159 = llvm.mlir.constant(1 : i64) : i64
%160 = llvm.alloca %159 x i32 : (i64) -> !llvm.ptr
llvm.store %158, %160 : i32, !llvm.ptr
%161 = arith.constant 0.0 : f32
%162 = llvm.load %160 : !llvm.ptr -> i32
%163 = arith.extf %161 : f32 to f64
%164 = arith.extsi %162 : i32 to i64
%165 = llvm.getelementptr %arg1[%164] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %163, %165 : f64, !llvm.ptr
%166 = llvm.load %160 : !llvm.ptr -> i32
%167 = arith.constant 1 : i32
%168 = arith.addi %166, %167 : i32
llvm.store %168, %160 : i32, !llvm.ptr
%169 = llvm.mlir.addressof @SQRT2 : !llvm.ptr
%170 = llvm.load %169 : !llvm.ptr -> f64
%171 = arith.divf %arg0, %170 : f64
%172 = arith.fptosi %171 : f64 to i32
%173 = arith.constant 1 : i32
%174 = arith.addi %172, %173 : i32
%175 = arith.constant 0 : i32
%176 = llvm.mlir.constant(1 : i64) : i64
%177 = llvm.alloca %176 x i32 : (i64) -> !llvm.ptr
llvm.store %175, %177 : i32, !llvm.ptr
cf.br ^bb33
^bb33:
%178 = llvm.load %177 : !llvm.ptr -> i32
%179 = arith.cmpi sle, %178, %174 : i32
cf.cond_br %179, ^bb34, ^bb35
^bb34:
%180 = llvm.load %177 : !llvm.ptr -> i32
%181 = arith.sitofp %180 : i32 to f64
%182 = llvm.mlir.addressof @SQRT2 : !llvm.ptr
%183 = llvm.load %182 : !llvm.ptr -> f64
%184 = arith.mulf %181, %183 : f64
%185 = arith.subf %arg0, %184 : f64
%186 = arith.constant 0 : f32
%188 = arith.extf %186 : f32 to f64
%187 = arith.addf %185, %188 : f64
%189 = arith.fptosi %187 : f64 to i32
%190 = arith.constant 0 : i32
%191 = llvm.mlir.constant(1 : i64) : i64
%192 = llvm.alloca %191 x i32 : (i64) -> !llvm.ptr
llvm.store %190, %192 : i32, !llvm.ptr
cf.br ^bb36
^bb36:
%193 = llvm.load %192 : !llvm.ptr -> i32
%194 = arith.cmpi sle, %193, %189 : i32
cf.cond_br %194, ^bb37, ^bb38
^bb37:
%195 = llvm.load %192 : !llvm.ptr -> i32
%196 = arith.sitofp %195 : i32 to f64
%197 = arith.addf %196, %184 : f64
%198 = llvm.load %160 : !llvm.ptr -> i32
%199 = arith.extsi %198 : i32 to i64
%200 = llvm.getelementptr %arg1[%199] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %197, %200 : f64, !llvm.ptr
%201 = llvm.load %160 : !llvm.ptr -> i32
%202 = arith.constant 1 : i32
%203 = arith.addi %201, %202 : i32
llvm.store %203, %160 : i32, !llvm.ptr
%204 = llvm.load %192 : !llvm.ptr -> i32
%205 = arith.constant 1 : i32
%206 = arith.addi %204, %205 : i32
llvm.store %206, %192 : i32, !llvm.ptr
cf.br ^bb36
^bb38:
%207 = llvm.load %177 : !llvm.ptr -> i32
%208 = arith.constant 1 : i32
%209 = arith.addi %207, %208 : i32
llvm.store %209, %177 : i32, !llvm.ptr
cf.br ^bb33
^bb35:
%211 = llvm.load %160 : !llvm.ptr -> i32
func.call @dsort(%arg1, %211) : (!llvm.ptr, i32) -> ()
%213 = llvm.load %160 : !llvm.ptr -> i32
%212 = func.call @dedup_double(%arg1, %213) : (!llvm.ptr, i32) -> i32
llvm.store %212, %160 : i32, !llvm.ptr
%214 = llvm.load %160 : !llvm.ptr -> i32
func.return %214 : i32
}
func.func @compute_grundy_intervals(%arg0: f64, %arg1: !llvm.ptr, %arg2: !llvm.ptr, %arg3: !llvm.ptr) -> i32 {
%216 = llvm.mlir.addressof @MAX_VALS : !llvm.ptr
%217 = llvm.load %216 : !llvm.ptr -> i32
%218 = arith.extsi %217 : i32 to i64
%219 = arith.constant 8 : i32
%220 = arith.extsi %219 : i32 to i64
%215 = func.call @calloc(%218, %220) : (i64, i64) -> !llvm.ptr
%221 = func.call @generate_ring(%arg0, %215) : (f64, !llvm.ptr) -> i32
%222 = arith.constant 1 : i32
%223 = arith.subi %221, %222 : i32
%224 = arith.constant 0 : i32
%225 = llvm.mlir.constant(1 : i64) : i64
%226 = llvm.alloca %225 x i32 : (i64) -> !llvm.ptr
llvm.store %224, %226 : i32, !llvm.ptr
%227 = arith.constant 0 : i32
%228 = llvm.mlir.constant(1 : i64) : i64
%229 = llvm.alloca %228 x i32 : (i64) -> !llvm.ptr
llvm.store %227, %229 : i32, !llvm.ptr
%230 = arith.constant 0 : i32
%231 = llvm.mlir.constant(1 : i64) : i64
%232 = llvm.alloca %231 x i32 : (i64) -> !llvm.ptr
llvm.store %230, %232 : i32, !llvm.ptr
%233 = arith.constant 256 : i32
%235 = arith.extsi %233 : i32 to i64
%236 = arith.constant 1 : i32
%237 = arith.extsi %236 : i32 to i64
%234 = func.call @calloc(%235, %237) : (i64, i64) -> !llvm.ptr
%238 = arith.constant 0 : i32
%239 = llvm.mlir.constant(1 : i64) : i64
%240 = llvm.alloca %239 x i32 : (i64) -> !llvm.ptr
llvm.store %238, %240 : i32, !llvm.ptr
%241 = arith.constant 0 : i32
%242 = llvm.mlir.constant(1 : i64) : i64
%243 = llvm.alloca %242 x i32 : (i64) -> !llvm.ptr
llvm.store %241, %243 : i32, !llvm.ptr
cf.br ^bb39
^bb39:
%244 = llvm.load %243 : !llvm.ptr -> i32
%245 = arith.cmpi slt, %244, %223 : i32
cf.cond_br %245, ^bb40, ^bb41
^bb40:
%247 = llvm.load %243 : !llvm.ptr -> i32
%248 = arith.extsi %247 : i32 to i64
%249 = llvm.getelementptr %215[%248] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%246 = llvm.load %249 : !llvm.ptr -> f64
%251 = llvm.load %243 : !llvm.ptr -> i32
%252 = arith.constant 1 : i32
%253 = arith.addi %251, %252 : i32
%254 = arith.extsi %253 : i32 to i64
%255 = llvm.getelementptr %215[%254] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%250 = llvm.load %255 : !llvm.ptr -> f64
%256 = arith.addf %246, %250 : f64
%257 = arith.constant 0.5 : f32
%259 = arith.extf %257 : f32 to f64
%258 = arith.mulf %256, %259 : f64
%260 = arith.constant 0 : i32
%261 = llvm.mlir.constant(1 : i64) : i64
%262 = llvm.alloca %261 x i32 : (i64) -> !llvm.ptr
llvm.store %260, %262 : i32, !llvm.ptr
cf.br ^bb42
^bb42:
%263 = llvm.load %262 : !llvm.ptr -> i32
%264 = llvm.load %240 : !llvm.ptr -> i32
%265 = arith.cmpi sle, %263, %264 : i32
cf.cond_br %265, ^bb43, ^bb44
^bb43:
%266 = arith.constant 0 : i32
%267 = llvm.load %262 : !llvm.ptr -> i32
%268 = arith.trunci %266 : i32 to i8
%269 = arith.extsi %267 : i32 to i64
%270 = llvm.getelementptr %234[%269] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %268, %270 : i8, !llvm.ptr
%271 = llvm.load %262 : !llvm.ptr -> i32
%272 = arith.constant 1 : i32
%273 = arith.addi %271, %272 : i32
llvm.store %273, %262 : i32, !llvm.ptr
cf.br ^bb42
^bb44:
%274 = arith.constant 0 : i32
%275 = llvm.mlir.constant(1 : i64) : i64
%276 = llvm.alloca %275 x i32 : (i64) -> !llvm.ptr
llvm.store %274, %276 : i32, !llvm.ptr
cf.br ^bb45
^bb45:
%277 = llvm.load %276 : !llvm.ptr -> i32
%278 = arith.constant 2 : i32
%279 = arith.cmpi slt, %277, %278 : i32
cf.cond_br %279, ^bb46, ^bb47
^bb46:
%280 = llvm.load %276 : !llvm.ptr -> i32
%281 = arith.constant 0 : i32
%282 = arith.cmpi eq, %280, %281 : i32
%283 = scf.if %282 -> (f32) {
%284 = arith.constant 1.0 : f32
scf.yield %284 : f32
} else {
%285 = llvm.mlir.addressof @SQRT2 : !llvm.ptr
%286 = llvm.load %285 : !llvm.ptr -> f64
scf.yield %286 : f64
}
%287 = arith.extf %283 : f32 to f64
%288 = arith.cmpf olt, %258, %287 : f64
%289 = scf.if %288 -> (i32) {
%290 = arith.constant 1 : i32
scf.yield %290 : i32
} else {
%291 = llvm.load %226 : !llvm.ptr -> i32
%292 = arith.constant 0 : i32
%293 = arith.cmpi eq, %291, %292 : i32
%294 = scf.if %293 -> (i32) {
%295 = arith.constant 1 : i32
scf.yield %295 : i32
} else {
%296 = arith.constant 0 : i32
scf.yield %296 : i32
}
scf.yield %294 : i32
}
%297 = arith.constant 0 : i32
%298 = arith.cmpi eq, %289, %297 : i32
cf.cond_br %298, ^bb48, ^bb49
^bb48:
%299 = arith.subf %258, %287 : f64
%301 = llvm.load %226 : !llvm.ptr -> i32
%300 = func.call @upper_index(%arg1, %301, %299) : (!llvm.ptr, i32, f64) -> i32
%302 = arith.constant 1 : i32
%303 = arith.subi %300, %302 : i32
%304 = llvm.mlir.constant(1 : i64) : i64
%305 = llvm.alloca %304 x i32 : (i64) -> !llvm.ptr
llvm.store %303, %305 : i32, !llvm.ptr
%306 = arith.constant 0 : i32
%307 = llvm.mlir.constant(1 : i64) : i64
%308 = llvm.alloca %307 x i32 : (i64) -> !llvm.ptr
llvm.store %306, %308 : i32, !llvm.ptr
%310 = arith.constant 1 : i32
%311 = arith.constant 4 : i32
%312 = arith.extsi %310 : i32 to i64
%313 = arith.extsi %311 : i32 to i64
%309 = func.call @calloc(%312, %313) : (i64, i64) -> !llvm.ptr
cf.br ^bb51
^bb51:
%314 = llvm.load %308 : !llvm.ptr -> i32
%315 = llvm.load %305 : !llvm.ptr -> i32
%316 = arith.cmpi sle, %314, %315 : i32
%317 = scf.if %316 -> (i1) {
%319 = arith.constant 0 : i32
%320 = arith.extsi %319 : i32 to i64
%321 = llvm.getelementptr %309[%320] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%318 = llvm.load %321 : !llvm.ptr -> i32
%322 = arith.constant 0 : i32
%323 = arith.cmpi eq, %318, %322 : i32
scf.yield %323 : i1
} else {
%324 = arith.constant false
scf.yield %324 : i1
}
cf.cond_br %317, ^bb52, ^bb53
^bb52:
%326 = llvm.load %308 : !llvm.ptr -> i32
%327 = arith.extsi %326 : i32 to i64
%328 = llvm.getelementptr %arg1[%327] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%325 = llvm.load %328 : !llvm.ptr -> f64
%329 = arith.cmpf oge, %325, %299 : f64
cf.cond_br %329, ^bb54, ^bb55
^bb54:
%330 = arith.constant 1 : i32
%331 = arith.constant 0 : i32
%332 = arith.extsi %331 : i32 to i64
%333 = llvm.getelementptr %309[%332] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %330, %333 : i32, !llvm.ptr
cf.br ^bb56
^bb55:
cf.br ^bb56
^bb56:
%335 = arith.constant 0 : i32
%336 = arith.extsi %335 : i32 to i64
%337 = llvm.getelementptr %309[%336] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%334 = llvm.load %337 : !llvm.ptr -> i32
%338 = arith.constant 0 : i32
%339 = arith.cmpi eq, %334, %338 : i32
cf.cond_br %339, ^bb57, ^bb58
^bb57:
%341 = llvm.load %308 : !llvm.ptr -> i32
%342 = arith.extsi %341 : i32 to i64
%343 = llvm.getelementptr %arg2[%342] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%340 = llvm.load %343 : !llvm.ptr -> f64
%344 = llvm.mlir.constant(1 : i64) : i64
%345 = llvm.alloca %344 x f64 : (i64) -> !llvm.ptr
llvm.store %340, %345 : f64, !llvm.ptr
%346 = llvm.load %345 : !llvm.ptr -> f64
%347 = arith.cmpf ogt, %346, %299 : f64
cf.cond_br %347, ^bb60, ^bb61
^bb60:
llvm.store %299, %345 : f64, !llvm.ptr
cf.br ^bb62
^bb61:
cf.br ^bb62
^bb62:
%349 = llvm.load %305 : !llvm.ptr -> i32
%350 = arith.extsi %349 : i32 to i64
%351 = llvm.getelementptr %arg2[%350] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%348 = llvm.load %351 : !llvm.ptr -> f64
%352 = llvm.mlir.constant(1 : i64) : i64
%353 = llvm.alloca %352 x f64 : (i64) -> !llvm.ptr
llvm.store %348, %353 : f64, !llvm.ptr
%354 = llvm.load %353 : !llvm.ptr -> f64
%355 = arith.cmpf ogt, %354, %299 : f64
cf.cond_br %355, ^bb63, ^bb64
^bb63:
llvm.store %299, %353 : f64, !llvm.ptr
cf.br ^bb65
^bb64:
cf.br ^bb65
^bb65:
%357 = llvm.load %305 : !llvm.ptr -> i32
%358 = arith.extsi %357 : i32 to i64
%359 = llvm.getelementptr %arg1[%358] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%356 = llvm.load %359 : !llvm.ptr -> f64
%360 = llvm.load %353 : !llvm.ptr -> f64
%361 = arith.subf %299, %360 : f64
%362 = llvm.mlir.constant(1 : i64) : i64
%363 = llvm.alloca %362 x f64 : (i64) -> !llvm.ptr
llvm.store %361, %363 : f64, !llvm.ptr
%364 = llvm.load %363 : !llvm.ptr -> f64
%365 = arith.cmpf ogt, %325, %364 : f64
cf.cond_br %365, ^bb66, ^bb67
^bb66:
llvm.store %325, %363 : f64, !llvm.ptr
cf.br ^bb68
^bb67:
cf.br ^bb68
^bb68:
%366 = arith.subf %299, %356 : f64
%367 = llvm.mlir.constant(1 : i64) : i64
%368 = llvm.alloca %367 x f64 : (i64) -> !llvm.ptr
llvm.store %366, %368 : f64, !llvm.ptr
%369 = llvm.load %345 : !llvm.ptr -> f64
%370 = llvm.load %368 : !llvm.ptr -> f64
%371 = arith.cmpf olt, %369, %370 : f64
cf.cond_br %371, ^bb69, ^bb70
^bb69:
%372 = llvm.load %345 : !llvm.ptr -> f64
llvm.store %372, %368 : f64, !llvm.ptr
cf.br ^bb71
^bb70:
cf.br ^bb71
^bb71:
%373 = llvm.load %363 : !llvm.ptr -> f64
%374 = llvm.load %368 : !llvm.ptr -> f64
%375 = arith.cmpf olt, %373, %374 : f64
cf.cond_br %375, ^bb72, ^bb73
^bb72:
%377 = llvm.load %308 : !llvm.ptr -> i32
%378 = arith.extsi %377 : i32 to i64
%379 = llvm.getelementptr %arg3[%378] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%376 = llvm.load %379 : !llvm.ptr -> i32
%381 = llvm.load %305 : !llvm.ptr -> i32
%382 = arith.extsi %381 : i32 to i64
%383 = llvm.getelementptr %arg3[%382] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%380 = llvm.load %383 : !llvm.ptr -> i32
%384 = arith.xori %376, %380 : i32
%385 = arith.cmpi slt, %384, %233 : i32
cf.cond_br %385, ^bb75, ^bb76
^bb75:
%386 = arith.constant 1 : i32
%387 = arith.trunci %386 : i32 to i8
%388 = arith.extsi %384 : i32 to i64
%389 = llvm.getelementptr %234[%388] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %387, %389 : i8, !llvm.ptr
cf.br ^bb77
^bb76:
cf.br ^bb77
^bb77:
%390 = llvm.load %240 : !llvm.ptr -> i32
%391 = arith.cmpi sgt, %384, %390 : i32
cf.cond_br %391, ^bb78, ^bb79
^bb78:
llvm.store %384, %240 : i32, !llvm.ptr
cf.br ^bb80
^bb79:
cf.br ^bb80
^bb80:
cf.br ^bb74
^bb73:
cf.br ^bb74
^bb74:
%392 = llvm.load %345 : !llvm.ptr -> f64
%393 = arith.subf %299, %356 : f64
%394 = arith.cmpf olt, %392, %393 : f64
cf.cond_br %394, ^bb81, ^bb82
^bb81:
%395 = llvm.load %308 : !llvm.ptr -> i32
%396 = arith.constant 1 : i32
%397 = arith.addi %395, %396 : i32
llvm.store %397, %308 : i32, !llvm.ptr
cf.br ^bb83
^bb82:
%398 = llvm.load %305 : !llvm.ptr -> i32
%399 = arith.constant 1 : i32
%400 = arith.subi %398, %399 : i32
llvm.store %400, %305 : i32, !llvm.ptr
cf.br ^bb83
^bb83:
cf.br ^bb59
^bb58:
cf.br ^bb59
^bb59:
cf.br ^bb51
^bb53:
func.call @free(%309) : (!llvm.ptr) -> ()
cf.br ^bb50
^bb49:
cf.br ^bb50
^bb50:
%402 = llvm.load %276 : !llvm.ptr -> i32
%403 = arith.constant 1 : i32
%404 = arith.addi %402, %403 : i32
llvm.store %404, %276 : i32, !llvm.ptr
cf.br ^bb45
^bb47:
%405 = arith.constant 0 : i32
%406 = llvm.mlir.constant(1 : i64) : i64
%407 = llvm.alloca %406 x i32 : (i64) -> !llvm.ptr
llvm.store %405, %407 : i32, !llvm.ptr
cf.br ^bb84
^bb84:
%408 = llvm.load %407 : !llvm.ptr -> i32
%409 = arith.cmpi slt, %408, %233 : i32
%410 = scf.if %409 -> (i1) {
%412 = llvm.load %407 : !llvm.ptr -> i32
%413 = arith.extsi %412 : i32 to i64
%414 = llvm.getelementptr %234[%413] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%411 = llvm.load %414 : !llvm.ptr -> i8
%415 = arith.constant 1 : i32
%417 = arith.extsi %411 : i8 to i32
%416 = arith.cmpi eq, %417, %415 : i32
scf.yield %416 : i1
} else {
%418 = arith.constant false
scf.yield %418 : i1
}
cf.cond_br %410, ^bb85, ^bb86
^bb85:
%419 = llvm.load %407 : !llvm.ptr -> i32
%420 = arith.constant 1 : i32
%421 = arith.addi %419, %420 : i32
llvm.store %421, %407 : i32, !llvm.ptr
cf.br ^bb84
^bb86:
%422 = llvm.load %232 : !llvm.ptr -> i32
%423 = arith.constant 0 : i32
%424 = arith.cmpi sgt, %422, %423 : i32
%425 = scf.if %424 -> (i1) {
%427 = llvm.load %232 : !llvm.ptr -> i32
%428 = arith.constant 1 : i32
%429 = arith.subi %427, %428 : i32
%430 = arith.extsi %429 : i32 to i64
%431 = llvm.getelementptr %arg3[%430] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%426 = llvm.load %431 : !llvm.ptr -> i32
%432 = llvm.load %407 : !llvm.ptr -> i32
%433 = arith.cmpi eq, %426, %432 : i32
scf.yield %433 : i1
} else {
%434 = arith.constant false
scf.yield %434 : i1
}
%435 = scf.if %425 -> (i1) {
%437 = llvm.load %229 : !llvm.ptr -> i32
%438 = arith.constant 1 : i32
%439 = arith.subi %437, %438 : i32
%440 = arith.extsi %439 : i32 to i64
%441 = llvm.getelementptr %arg2[%440] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%436 = llvm.load %441 : !llvm.ptr -> f64
%442 = arith.subf %436, %246 : f64
%443 = math.absf %442 : f64
%444 = llvm.mlir.addressof @EPS : !llvm.ptr
%445 = llvm.load %444 : !llvm.ptr -> f64
%446 = arith.cmpf olt, %443, %445 : f64
scf.yield %446 : i1
} else {
%447 = arith.constant false
scf.yield %447 : i1
}
cf.cond_br %435, ^bb87, ^bb88
^bb87:
%448 = llvm.load %229 : !llvm.ptr -> i32
%449 = arith.constant 1 : i32
%450 = arith.subi %448, %449 : i32
%451 = arith.extsi %450 : i32 to i64
%452 = llvm.getelementptr %arg2[%451] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %250, %452 : f64, !llvm.ptr
cf.br ^bb89
^bb88:
%453 = llvm.load %226 : !llvm.ptr -> i32
%454 = arith.extsi %453 : i32 to i64
%455 = llvm.getelementptr %arg1[%454] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %246, %455 : f64, !llvm.ptr
%456 = llvm.load %226 : !llvm.ptr -> i32
%457 = arith.constant 1 : i32
%458 = arith.addi %456, %457 : i32
llvm.store %458, %226 : i32, !llvm.ptr
%459 = llvm.load %229 : !llvm.ptr -> i32
%460 = arith.extsi %459 : i32 to i64
%461 = llvm.getelementptr %arg2[%460] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %250, %461 : f64, !llvm.ptr
%462 = llvm.load %229 : !llvm.ptr -> i32
%463 = arith.constant 1 : i32
%464 = arith.addi %462, %463 : i32
llvm.store %464, %229 : i32, !llvm.ptr
%465 = llvm.load %407 : !llvm.ptr -> i32
%466 = llvm.load %232 : !llvm.ptr -> i32
%467 = arith.extsi %466 : i32 to i64
%468 = llvm.getelementptr %arg3[%467] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %465, %468 : i32, !llvm.ptr
%469 = llvm.load %232 : !llvm.ptr -> i32
%470 = arith.constant 1 : i32
%471 = arith.addi %469, %470 : i32
llvm.store %471, %232 : i32, !llvm.ptr
cf.br ^bb89
^bb89:
%472 = llvm.load %243 : !llvm.ptr -> i32
%473 = arith.constant 1 : i32
%474 = arith.addi %472, %473 : i32
llvm.store %474, %243 : i32, !llvm.ptr
cf.br ^bb39
^bb41:
func.call @free(%234) : (!llvm.ptr) -> ()
func.call @free(%215) : (!llvm.ptr) -> ()
%477 = llvm.load %232 : !llvm.ptr -> i32
func.return %477 : i32
}
func.func @ev_merge_sort(%arg0: !llvm.ptr, %arg1: i32, %arg2: i32, %arg3: !llvm.ptr, %arg4: !llvm.ptr) -> () {
%478 = arith.subi %arg2, %arg1 : i32
%479 = arith.constant 1 : i32
%480 = arith.cmpi sle, %478, %479 : i32
cf.cond_br %480, ^bb90, ^bb91
^bb90:
func.return
^bb91:
cf.br ^bb92
^bb92:
%481 = arith.addi %arg1, %arg2 : i32
%482 = arith.constant 2 : i32
%483 = arith.divsi %481, %482 : i32
func.call @ev_merge_sort(%arg0, %arg1, %483, %arg3, %arg4) : (!llvm.ptr, i32, i32, !llvm.ptr, !llvm.ptr) -> ()
func.call @ev_merge_sort(%arg0, %483, %arg2, %arg3, %arg4) : (!llvm.ptr, i32, i32, !llvm.ptr, !llvm.ptr) -> ()
%486 = llvm.mlir.constant(1 : i64) : i64
%487 = llvm.alloca %486 x i32 : (i64) -> !llvm.ptr
llvm.store %arg1, %487 : i32, !llvm.ptr
%488 = llvm.mlir.constant(1 : i64) : i64
%489 = llvm.alloca %488 x i32 : (i64) -> !llvm.ptr
llvm.store %483, %489 : i32, !llvm.ptr
%490 = llvm.mlir.constant(1 : i64) : i64
%491 = llvm.alloca %490 x i32 : (i64) -> !llvm.ptr
llvm.store %arg1, %491 : i32, !llvm.ptr
cf.br ^bb93
^bb93:
%492 = llvm.load %487 : !llvm.ptr -> i32
%493 = arith.cmpi slt, %492, %483 : i32
%494 = scf.if %493 -> (i1) {
%495 = llvm.load %489 : !llvm.ptr -> i32
%496 = arith.cmpi slt, %495, %arg2 : i32
scf.yield %496 : i1
} else {
%497 = arith.constant false
scf.yield %497 : i1
}
cf.cond_br %494, ^bb94, ^bb95
^bb94:
%500 = llvm.load %487 : !llvm.ptr -> i32
%501 = arith.extsi %500 : i32 to i64
%502 = llvm.getelementptr %arg0[%501] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%499 = llvm.load %502 : !llvm.ptr -> i32
%503 = arith.extsi %499 : i32 to i64
%504 = llvm.getelementptr %arg3[%503] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%498 = llvm.load %504 : !llvm.ptr -> f64
%507 = llvm.load %489 : !llvm.ptr -> i32
%508 = arith.extsi %507 : i32 to i64
%509 = llvm.getelementptr %arg0[%508] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%506 = llvm.load %509 : !llvm.ptr -> i32
%510 = arith.extsi %506 : i32 to i64
%511 = llvm.getelementptr %arg3[%510] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%505 = llvm.load %511 : !llvm.ptr -> f64
%512 = arith.cmpf ole, %498, %505 : f64
cf.cond_br %512, ^bb96, ^bb97
^bb96:
%514 = llvm.load %487 : !llvm.ptr -> i32
%515 = arith.extsi %514 : i32 to i64
%516 = llvm.getelementptr %arg0[%515] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%513 = llvm.load %516 : !llvm.ptr -> i32
%517 = llvm.load %491 : !llvm.ptr -> i32
%518 = arith.extsi %517 : i32 to i64
%519 = llvm.getelementptr %arg4[%518] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %513, %519 : i32, !llvm.ptr
%520 = llvm.load %487 : !llvm.ptr -> i32
%521 = arith.constant 1 : i32
%522 = arith.addi %520, %521 : i32
llvm.store %522, %487 : i32, !llvm.ptr
cf.br ^bb98
^bb97:
%524 = llvm.load %489 : !llvm.ptr -> i32
%525 = arith.extsi %524 : i32 to i64
%526 = llvm.getelementptr %arg0[%525] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%523 = llvm.load %526 : !llvm.ptr -> i32
%527 = llvm.load %491 : !llvm.ptr -> i32
%528 = arith.extsi %527 : i32 to i64
%529 = llvm.getelementptr %arg4[%528] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %523, %529 : i32, !llvm.ptr
%530 = llvm.load %489 : !llvm.ptr -> i32
%531 = arith.constant 1 : i32
%532 = arith.addi %530, %531 : i32
llvm.store %532, %489 : i32, !llvm.ptr
cf.br ^bb98
^bb98:
%533 = llvm.load %491 : !llvm.ptr -> i32
%534 = arith.constant 1 : i32
%535 = arith.addi %533, %534 : i32
llvm.store %535, %491 : i32, !llvm.ptr
cf.br ^bb93
^bb95:
cf.br ^bb99
^bb99:
%536 = llvm.load %487 : !llvm.ptr -> i32
%537 = arith.cmpi slt, %536, %483 : i32
cf.cond_br %537, ^bb100, ^bb101
^bb100:
%539 = llvm.load %487 : !llvm.ptr -> i32
%540 = arith.extsi %539 : i32 to i64
%541 = llvm.getelementptr %arg0[%540] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%538 = llvm.load %541 : !llvm.ptr -> i32
%542 = llvm.load %491 : !llvm.ptr -> i32
%543 = arith.extsi %542 : i32 to i64
%544 = llvm.getelementptr %arg4[%543] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %538, %544 : i32, !llvm.ptr
%545 = llvm.load %487 : !llvm.ptr -> i32
%546 = arith.constant 1 : i32
%547 = arith.addi %545, %546 : i32
llvm.store %547, %487 : i32, !llvm.ptr
%548 = llvm.load %491 : !llvm.ptr -> i32
%549 = arith.constant 1 : i32
%550 = arith.addi %548, %549 : i32
llvm.store %550, %491 : i32, !llvm.ptr
cf.br ^bb99
^bb101:
cf.br ^bb102
^bb102:
%551 = llvm.load %489 : !llvm.ptr -> i32
%552 = arith.cmpi slt, %551, %arg2 : i32
cf.cond_br %552, ^bb103, ^bb104
^bb103:
%554 = llvm.load %489 : !llvm.ptr -> i32
%555 = arith.extsi %554 : i32 to i64
%556 = llvm.getelementptr %arg0[%555] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%553 = llvm.load %556 : !llvm.ptr -> i32
%557 = llvm.load %491 : !llvm.ptr -> i32
%558 = arith.extsi %557 : i32 to i64
%559 = llvm.getelementptr %arg4[%558] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %553, %559 : i32, !llvm.ptr
%560 = llvm.load %489 : !llvm.ptr -> i32
%561 = arith.constant 1 : i32
%562 = arith.addi %560, %561 : i32
llvm.store %562, %489 : i32, !llvm.ptr
%563 = llvm.load %491 : !llvm.ptr -> i32
%564 = arith.constant 1 : i32
%565 = arith.addi %563, %564 : i32
llvm.store %565, %491 : i32, !llvm.ptr
cf.br ^bb102
^bb104:
%566 = llvm.mlir.constant(1 : i64) : i64
%567 = llvm.alloca %566 x i32 : (i64) -> !llvm.ptr
llvm.store %arg1, %567 : i32, !llvm.ptr
cf.br ^bb105
^bb105:
%568 = llvm.load %567 : !llvm.ptr -> i32
%569 = arith.cmpi slt, %568, %arg2 : i32
cf.cond_br %569, ^bb106, ^bb107
^bb106:
%571 = llvm.load %567 : !llvm.ptr -> i32
%572 = arith.extsi %571 : i32 to i64
%573 = llvm.getelementptr %arg4[%572] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%570 = llvm.load %573 : !llvm.ptr -> i32
%574 = llvm.load %567 : !llvm.ptr -> i32
%575 = arith.extsi %574 : i32 to i64
%576 = llvm.getelementptr %arg0[%575] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %570, %576 : i32, !llvm.ptr
%577 = llvm.load %567 : !llvm.ptr -> i32
%578 = arith.constant 1 : i32
%579 = arith.addi %577, %578 : i32
llvm.store %579, %567 : i32, !llvm.ptr
cf.br ^bb105
^bb107:
func.return
}
func.func @build_w_segments(%arg0: !llvm.ptr, %arg1: !llvm.ptr, %arg2: !llvm.ptr, %arg3: i32, %arg4: f64, %arg5: !llvm.ptr, %arg6: !llvm.ptr, %arg7: !llvm.ptr, %arg8: !llvm.ptr) -> i32 {
%580 = arith.constant 0 : i32
%581 = llvm.mlir.constant(1 : i64) : i64
%582 = llvm.alloca %581 x i32 : (i64) -> !llvm.ptr
llvm.store %580, %582 : i32, !llvm.ptr
%583 = arith.constant 0 : i32
%584 = llvm.mlir.constant(1 : i64) : i64
%585 = llvm.alloca %584 x i32 : (i64) -> !llvm.ptr
llvm.store %583, %585 : i32, !llvm.ptr
cf.br ^bb108
^bb108:
%586 = llvm.load %585 : !llvm.ptr -> i32
%587 = arith.cmpi slt, %586, %arg3 : i32
cf.cond_br %587, ^bb109, ^bb110
^bb109:
%589 = llvm.load %585 : !llvm.ptr -> i32
%590 = arith.extsi %589 : i32 to i64
%591 = llvm.getelementptr %arg2[%590] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%588 = llvm.load %591 : !llvm.ptr -> i32
%592 = llvm.load %582 : !llvm.ptr -> i32
%593 = arith.cmpi sgt, %588, %592 : i32
cf.cond_br %593, ^bb111, ^bb112
^bb111:
%595 = llvm.load %585 : !llvm.ptr -> i32
%596 = arith.extsi %595 : i32 to i64
%597 = llvm.getelementptr %arg2[%596] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%594 = llvm.load %597 : !llvm.ptr -> i32
llvm.store %594, %582 : i32, !llvm.ptr
cf.br ^bb113
^bb112:
cf.br ^bb113
^bb113:
%598 = llvm.load %585 : !llvm.ptr -> i32
%599 = arith.constant 1 : i32
%600 = arith.addi %598, %599 : i32
llvm.store %600, %585 : i32, !llvm.ptr
cf.br ^bb108
^bb110:
%602 = llvm.load %582 : !llvm.ptr -> i32
%603 = arith.constant 1 : i32
%604 = arith.addi %602, %603 : i32
%605 = arith.extsi %604 : i32 to i64
%606 = arith.constant 4 : i32
%607 = arith.extsi %606 : i32 to i64
%601 = func.call @calloc(%605, %607) : (i64, i64) -> !llvm.ptr
%608 = arith.constant 0 : i32
%609 = llvm.mlir.constant(1 : i64) : i64
%610 = llvm.alloca %609 x i32 : (i64) -> !llvm.ptr
llvm.store %608, %610 : i32, !llvm.ptr
cf.br ^bb114
^bb114:
%611 = llvm.load %610 : !llvm.ptr -> i32
%612 = arith.cmpi slt, %611, %arg3 : i32
cf.cond_br %612, ^bb115, ^bb116
^bb115:
%615 = llvm.load %610 : !llvm.ptr -> i32
%616 = arith.extsi %615 : i32 to i64
%617 = llvm.getelementptr %arg2[%616] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%614 = llvm.load %617 : !llvm.ptr -> i32
%618 = arith.extsi %614 : i32 to i64
%619 = llvm.getelementptr %601[%618] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%613 = llvm.load %619 : !llvm.ptr -> i32
%620 = arith.constant 1 : i32
%621 = arith.addi %613, %620 : i32
%623 = llvm.load %610 : !llvm.ptr -> i32
%624 = arith.extsi %623 : i32 to i64
%625 = llvm.getelementptr %arg2[%624] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%622 = llvm.load %625 : !llvm.ptr -> i32
%626 = arith.extsi %622 : i32 to i64
%627 = llvm.getelementptr %601[%626] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %621, %627 : i32, !llvm.ptr
%628 = llvm.load %610 : !llvm.ptr -> i32
%629 = arith.constant 1 : i32
%630 = arith.addi %628, %629 : i32
llvm.store %630, %610 : i32, !llvm.ptr
cf.br ^bb114
^bb116:
%632 = llvm.load %582 : !llvm.ptr -> i32
%633 = arith.constant 2 : i32
%634 = arith.addi %632, %633 : i32
%635 = arith.extsi %634 : i32 to i64
%636 = arith.constant 4 : i32
%637 = arith.extsi %636 : i32 to i64
%631 = func.call @calloc(%635, %637) : (i64, i64) -> !llvm.ptr
%638 = arith.constant 0 : i32
%639 = llvm.mlir.constant(1 : i64) : i64
%640 = llvm.alloca %639 x i32 : (i64) -> !llvm.ptr
llvm.store %638, %640 : i32, !llvm.ptr
cf.br ^bb117
^bb117:
%641 = llvm.load %640 : !llvm.ptr -> i32
%642 = llvm.load %582 : !llvm.ptr -> i32
%643 = arith.cmpi sle, %641, %642 : i32
cf.cond_br %643, ^bb118, ^bb119
^bb118:
%645 = llvm.load %640 : !llvm.ptr -> i32
%646 = arith.extsi %645 : i32 to i64
%647 = llvm.getelementptr %631[%646] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%644 = llvm.load %647 : !llvm.ptr -> i32
%649 = llvm.load %640 : !llvm.ptr -> i32
%650 = arith.extsi %649 : i32 to i64
%651 = llvm.getelementptr %601[%650] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%648 = llvm.load %651 : !llvm.ptr -> i32
%652 = arith.addi %644, %648 : i32
%653 = llvm.load %640 : !llvm.ptr -> i32
%654 = arith.constant 1 : i32
%655 = arith.addi %653, %654 : i32
%656 = arith.extsi %655 : i32 to i64
%657 = llvm.getelementptr %631[%656] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %652, %657 : i32, !llvm.ptr
%658 = llvm.load %640 : !llvm.ptr -> i32
%659 = arith.constant 1 : i32
%660 = arith.addi %658, %659 : i32
llvm.store %660, %640 : i32, !llvm.ptr
cf.br ^bb117
^bb119:
%662 = llvm.load %582 : !llvm.ptr -> i32
%663 = arith.constant 1 : i32
%664 = arith.addi %662, %663 : i32
%665 = arith.extsi %664 : i32 to i64
%666 = llvm.getelementptr %631[%665] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%661 = llvm.load %666 : !llvm.ptr -> i32
%668 = arith.extsi %661 : i32 to i64
%669 = arith.constant 8 : i32
%670 = arith.extsi %669 : i32 to i64
%667 = func.call @calloc(%668, %670) : (i64, i64) -> !llvm.ptr
%672 = arith.extsi %661 : i32 to i64
%673 = arith.constant 8 : i32
%674 = arith.extsi %673 : i32 to i64
%671 = func.call @calloc(%672, %674) : (i64, i64) -> !llvm.ptr
%676 = llvm.load %582 : !llvm.ptr -> i32
%677 = arith.constant 1 : i32
%678 = arith.addi %676, %677 : i32
%679 = arith.extsi %678 : i32 to i64
%680 = arith.constant 4 : i32
%681 = arith.extsi %680 : i32 to i64
%675 = func.call @calloc(%679, %681) : (i64, i64) -> !llvm.ptr
%682 = arith.constant 0 : i32
%683 = llvm.mlir.constant(1 : i64) : i64
%684 = llvm.alloca %683 x i32 : (i64) -> !llvm.ptr
llvm.store %682, %684 : i32, !llvm.ptr
cf.br ^bb120
^bb120:
%685 = llvm.load %684 : !llvm.ptr -> i32
%686 = arith.cmpi slt, %685, %arg3 : i32
cf.cond_br %686, ^bb121, ^bb122
^bb121:
%688 = llvm.load %684 : !llvm.ptr -> i32
%689 = arith.extsi %688 : i32 to i64
%690 = llvm.getelementptr %arg2[%689] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%687 = llvm.load %690 : !llvm.ptr -> i32
%692 = arith.extsi %687 : i32 to i64
%693 = llvm.getelementptr %631[%692] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%691 = llvm.load %693 : !llvm.ptr -> i32
%695 = arith.extsi %687 : i32 to i64
%696 = llvm.getelementptr %675[%695] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%694 = llvm.load %696 : !llvm.ptr -> i32
%697 = arith.addi %691, %694 : i32
%699 = llvm.load %684 : !llvm.ptr -> i32
%700 = arith.extsi %699 : i32 to i64
%701 = llvm.getelementptr %arg0[%700] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%698 = llvm.load %701 : !llvm.ptr -> f64
%702 = arith.extsi %697 : i32 to i64
%703 = llvm.getelementptr %667[%702] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %698, %703 : f64, !llvm.ptr
%705 = llvm.load %684 : !llvm.ptr -> i32
%706 = arith.extsi %705 : i32 to i64
%707 = llvm.getelementptr %arg1[%706] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%704 = llvm.load %707 : !llvm.ptr -> f64
%708 = arith.extsi %697 : i32 to i64
%709 = llvm.getelementptr %671[%708] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %704, %709 : f64, !llvm.ptr
%711 = arith.extsi %687 : i32 to i64
%712 = llvm.getelementptr %675[%711] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%710 = llvm.load %712 : !llvm.ptr -> i32
%713 = arith.constant 1 : i32
%714 = arith.addi %710, %713 : i32
%715 = arith.extsi %687 : i32 to i64
%716 = llvm.getelementptr %675[%715] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %714, %716 : i32, !llvm.ptr
%717 = llvm.load %684 : !llvm.ptr -> i32
%718 = arith.constant 1 : i32
%719 = arith.addi %717, %718 : i32
llvm.store %719, %684 : i32, !llvm.ptr
cf.br ^bb120
^bb122:
%721 = llvm.mlir.addressof @MAX_EVENTS : !llvm.ptr
%722 = llvm.load %721 : !llvm.ptr -> i32
%723 = arith.extsi %722 : i32 to i64
%724 = arith.constant 8 : i32
%725 = arith.extsi %724 : i32 to i64
%720 = func.call @calloc(%723, %725) : (i64, i64) -> !llvm.ptr
%727 = llvm.mlir.addressof @MAX_EVENTS : !llvm.ptr
%728 = llvm.load %727 : !llvm.ptr -> i32
%729 = arith.extsi %728 : i32 to i64
%730 = arith.constant 4 : i32
%731 = arith.extsi %730 : i32 to i64
%726 = func.call @calloc(%729, %731) : (i64, i64) -> !llvm.ptr
%732 = arith.constant 0 : i32
%733 = llvm.mlir.constant(1 : i64) : i64
%734 = llvm.alloca %733 x i32 : (i64) -> !llvm.ptr
llvm.store %732, %734 : i32, !llvm.ptr
%735 = arith.constant 0 : i32
%736 = llvm.mlir.constant(1 : i64) : i64
%737 = llvm.alloca %736 x i32 : (i64) -> !llvm.ptr
llvm.store %735, %737 : i32, !llvm.ptr
cf.br ^bb123
^bb123:
%738 = llvm.load %737 : !llvm.ptr -> i32
%739 = llvm.load %582 : !llvm.ptr -> i32
%740 = arith.cmpi sle, %738, %739 : i32
cf.cond_br %740, ^bb124, ^bb125
^bb124:
%742 = llvm.load %737 : !llvm.ptr -> i32
%743 = arith.extsi %742 : i32 to i64
%744 = llvm.getelementptr %601[%743] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%741 = llvm.load %744 : !llvm.ptr -> i32
%746 = llvm.load %737 : !llvm.ptr -> i32
%747 = arith.extsi %746 : i32 to i64
%748 = llvm.getelementptr %631[%747] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%745 = llvm.load %748 : !llvm.ptr -> i32
%749 = arith.constant 0 : i32
%750 = llvm.mlir.constant(1 : i64) : i64
%751 = llvm.alloca %750 x i32 : (i64) -> !llvm.ptr
llvm.store %749, %751 : i32, !llvm.ptr
cf.br ^bb126
^bb126:
%752 = llvm.load %751 : !llvm.ptr -> i32
%753 = arith.cmpi slt, %752, %741 : i32
cf.cond_br %753, ^bb127, ^bb128
^bb127:
%755 = llvm.load %751 : !llvm.ptr -> i32
%756 = arith.addi %745, %755 : i32
%757 = arith.extsi %756 : i32 to i64
%758 = llvm.getelementptr %667[%757] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%754 = llvm.load %758 : !llvm.ptr -> f64
%760 = llvm.load %751 : !llvm.ptr -> i32
%761 = arith.addi %745, %760 : i32
%762 = arith.extsi %761 : i32 to i64
%763 = llvm.getelementptr %671[%762] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%759 = llvm.load %763 : !llvm.ptr -> f64
%764 = llvm.load %751 : !llvm.ptr -> i32
%765 = llvm.mlir.constant(1 : i64) : i64
%766 = llvm.alloca %765 x i32 : (i64) -> !llvm.ptr
llvm.store %764, %766 : i32, !llvm.ptr
cf.br ^bb129
^bb129:
%767 = llvm.load %766 : !llvm.ptr -> i32
%768 = arith.cmpi slt, %767, %741 : i32
cf.cond_br %768, ^bb130, ^bb131
^bb130:
%770 = llvm.load %766 : !llvm.ptr -> i32
%771 = arith.addi %745, %770 : i32
%772 = arith.extsi %771 : i32 to i64
%773 = llvm.getelementptr %667[%772] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%769 = llvm.load %773 : !llvm.ptr -> f64
%775 = llvm.load %766 : !llvm.ptr -> i32
%776 = arith.addi %745, %775 : i32
%777 = arith.extsi %776 : i32 to i64
%778 = llvm.getelementptr %671[%777] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%774 = llvm.load %778 : !llvm.ptr -> f64
%779 = llvm.load %751 : !llvm.ptr -> i32
%780 = llvm.load %766 : !llvm.ptr -> i32
%781 = arith.cmpi eq, %779, %780 : i32
%782 = scf.if %781 -> (i32) {
%783 = arith.constant 1 : i32
scf.yield %783 : i32
} else {
%784 = arith.constant 2 : i32
scf.yield %784 : i32
}
%785 = arith.addf %754, %769 : f64
%786 = arith.addf %754, %774 : f64
%787 = arith.addf %759, %769 : f64
%788 = arith.addf %759, %774 : f64
%789 = llvm.mlir.addressof @EPS : !llvm.ptr
%790 = llvm.load %789 : !llvm.ptr -> f64
%791 = arith.addf %arg4, %790 : f64
%792 = arith.cmpf ogt, %785, %791 : f64
cf.cond_br %792, ^bb132, ^bb133
^bb132:
cf.br ^bb131
^bb133:
cf.br ^bb134
^bb134:
%793 = arith.constant 0.0 : f32
%795 = arith.extf %793 : f32 to f64
%794 = arith.cmpf olt, %788, %795 : f64
%796 = scf.if %794 -> (i32) {
%797 = arith.constant 1 : i32
scf.yield %797 : i32
} else {
%798 = arith.constant 0 : i32
scf.yield %798 : i32
}
%799 = arith.constant 0 : i32
%800 = arith.cmpi eq, %796, %799 : i32
cf.cond_br %800, ^bb135, ^bb136
^bb135:
%801 = llvm.mlir.constant(1 : i64) : i64
%802 = llvm.alloca %801 x f64 : (i64) -> !llvm.ptr
llvm.store %785, %802 : f64, !llvm.ptr
%803 = llvm.mlir.constant(1 : i64) : i64
%804 = llvm.alloca %803 x f64 : (i64) -> !llvm.ptr
llvm.store %788, %804 : f64, !llvm.ptr
%805 = llvm.load %802 : !llvm.ptr -> f64
%806 = arith.constant 0.0 : f32
%808 = arith.extf %806 : f32 to f64
%807 = arith.cmpf olt, %805, %808 : f64
cf.cond_br %807, ^bb138, ^bb139
^bb138:
%809 = arith.constant 0.0 : f32
%810 = arith.extf %809 : f32 to f64
llvm.store %810, %802 : f64, !llvm.ptr
cf.br ^bb140
^bb139:
cf.br ^bb140
^bb140:
%811 = llvm.load %804 : !llvm.ptr -> f64
%812 = arith.cmpf ogt, %811, %arg4 : f64
cf.cond_br %812, ^bb141, ^bb142
^bb141:
llvm.store %arg4, %804 : f64, !llvm.ptr
cf.br ^bb143
^bb142:
cf.br ^bb143
^bb143:
%813 = arith.cmpf olt, %786, %787 : f64
%814 = scf.if %813 -> (f64) {
scf.yield %786 : f64
} else {
scf.yield %787 : f64
}
%815 = arith.cmpf olt, %786, %787 : f64
%816 = scf.if %815 -> (f64) {
scf.yield %787 : f64
} else {
scf.yield %786 : f64
}
%817 = llvm.load %802 : !llvm.ptr -> f64
%818 = llvm.load %734 : !llvm.ptr -> i32
%819 = arith.extsi %818 : i32 to i64
%820 = llvm.getelementptr %720[%819] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %817, %820 : f64, !llvm.ptr
%821 = llvm.load %734 : !llvm.ptr -> i32
%822 = arith.extsi %821 : i32 to i64
%823 = llvm.getelementptr %726[%822] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %782, %823 : i32, !llvm.ptr
%824 = llvm.load %734 : !llvm.ptr -> i32
%825 = arith.constant 1 : i32
%826 = arith.addi %824, %825 : i32
llvm.store %826, %734 : i32, !llvm.ptr
%827 = llvm.load %734 : !llvm.ptr -> i32
%828 = arith.extsi %827 : i32 to i64
%829 = llvm.getelementptr %720[%828] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %814, %829 : f64, !llvm.ptr
%831 = arith.constant 0 : i32
%830 = arith.subi %831, %782 : i32
%832 = llvm.load %734 : !llvm.ptr -> i32
%833 = arith.extsi %832 : i32 to i64
%834 = llvm.getelementptr %726[%833] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %830, %834 : i32, !llvm.ptr
%835 = llvm.load %734 : !llvm.ptr -> i32
%836 = arith.constant 1 : i32
%837 = arith.addi %835, %836 : i32
llvm.store %837, %734 : i32, !llvm.ptr
%838 = llvm.load %734 : !llvm.ptr -> i32
%839 = arith.extsi %838 : i32 to i64
%840 = llvm.getelementptr %720[%839] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %816, %840 : f64, !llvm.ptr
%842 = arith.constant 0 : i32
%841 = arith.subi %842, %782 : i32
%843 = llvm.load %734 : !llvm.ptr -> i32
%844 = arith.extsi %843 : i32 to i64
%845 = llvm.getelementptr %726[%844] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %841, %845 : i32, !llvm.ptr
%846 = llvm.load %734 : !llvm.ptr -> i32
%847 = arith.constant 1 : i32
%848 = arith.addi %846, %847 : i32
llvm.store %848, %734 : i32, !llvm.ptr
%849 = llvm.load %804 : !llvm.ptr -> f64
%850 = llvm.load %734 : !llvm.ptr -> i32
%851 = arith.extsi %850 : i32 to i64
%852 = llvm.getelementptr %720[%851] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %849, %852 : f64, !llvm.ptr
%853 = llvm.load %734 : !llvm.ptr -> i32
%854 = arith.extsi %853 : i32 to i64
%855 = llvm.getelementptr %726[%854] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %782, %855 : i32, !llvm.ptr
%856 = llvm.load %734 : !llvm.ptr -> i32
%857 = arith.constant 1 : i32
%858 = arith.addi %856, %857 : i32
llvm.store %858, %734 : i32, !llvm.ptr
cf.br ^bb137
^bb136:
cf.br ^bb137
^bb137:
%859 = llvm.load %766 : !llvm.ptr -> i32
%860 = arith.constant 1 : i32
%861 = arith.addi %859, %860 : i32
llvm.store %861, %766 : i32, !llvm.ptr
cf.br ^bb129
^bb131:
%862 = llvm.load %751 : !llvm.ptr -> i32
%863 = arith.constant 1 : i32
%864 = arith.addi %862, %863 : i32
llvm.store %864, %751 : i32, !llvm.ptr
cf.br ^bb126
^bb128:
%865 = llvm.load %737 : !llvm.ptr -> i32
%866 = arith.constant 1 : i32
%867 = arith.addi %865, %866 : i32
llvm.store %867, %737 : i32, !llvm.ptr
cf.br ^bb123
^bb125:
%869 = llvm.mlir.addressof @MAX_EVENTS : !llvm.ptr
%870 = llvm.load %869 : !llvm.ptr -> i32
%871 = arith.extsi %870 : i32 to i64
%872 = arith.constant 4 : i32
%873 = arith.extsi %872 : i32 to i64
%868 = func.call @calloc(%871, %873) : (i64, i64) -> !llvm.ptr
%875 = llvm.mlir.addressof @MAX_EVENTS : !llvm.ptr
%876 = llvm.load %875 : !llvm.ptr -> i32
%877 = arith.extsi %876 : i32 to i64
%878 = arith.constant 4 : i32
%879 = arith.extsi %878 : i32 to i64
%874 = func.call @calloc(%877, %879) : (i64, i64) -> !llvm.ptr
%880 = arith.constant 0 : i32
%881 = llvm.mlir.constant(1 : i64) : i64
%882 = llvm.alloca %881 x i32 : (i64) -> !llvm.ptr
llvm.store %880, %882 : i32, !llvm.ptr
cf.br ^bb144
^bb144:
%883 = llvm.load %882 : !llvm.ptr -> i32
%884 = llvm.load %734 : !llvm.ptr -> i32
%885 = arith.cmpi slt, %883, %884 : i32
cf.cond_br %885, ^bb145, ^bb146
^bb145:
%886 = llvm.load %882 : !llvm.ptr -> i32
%887 = llvm.load %882 : !llvm.ptr -> i32
%888 = arith.extsi %887 : i32 to i64
%889 = llvm.getelementptr %868[%888] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %886, %889 : i32, !llvm.ptr
%890 = llvm.load %882 : !llvm.ptr -> i32
%891 = arith.constant 1 : i32
%892 = arith.addi %890, %891 : i32
llvm.store %892, %882 : i32, !llvm.ptr
cf.br ^bb144
^bb146:
%894 = arith.constant 0 : i32
%895 = llvm.load %734 : !llvm.ptr -> i32
func.call @ev_merge_sort(%868, %894, %895, %720, %874) : (!llvm.ptr, i32, i32, !llvm.ptr, !llvm.ptr) -> ()
%897 = llvm.mlir.addressof @MAX_EVENTS : !llvm.ptr
%898 = llvm.load %897 : !llvm.ptr -> i32
%899 = arith.extsi %898 : i32 to i64
%900 = arith.constant 8 : i32
%901 = arith.extsi %900 : i32 to i64
%896 = func.call @calloc(%899, %901) : (i64, i64) -> !llvm.ptr
%903 = llvm.mlir.addressof @MAX_EVENTS : !llvm.ptr
%904 = llvm.load %903 : !llvm.ptr -> i32
%905 = arith.extsi %904 : i32 to i64
%906 = arith.constant 4 : i32
%907 = arith.extsi %906 : i32 to i64
%902 = func.call @calloc(%905, %907) : (i64, i64) -> !llvm.ptr
%908 = arith.constant 0 : i32
%909 = llvm.mlir.constant(1 : i64) : i64
%910 = llvm.alloca %909 x i32 : (i64) -> !llvm.ptr
llvm.store %908, %910 : i32, !llvm.ptr
%911 = llvm.load %734 : !llvm.ptr -> i32
%912 = arith.constant 0 : i32
%913 = arith.cmpi sgt, %911, %912 : i32
cf.cond_br %913, ^bb147, ^bb148
^bb147:
%916 = arith.constant 0 : i32
%917 = arith.extsi %916 : i32 to i64
%918 = llvm.getelementptr %868[%917] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%915 = llvm.load %918 : !llvm.ptr -> i32
%919 = arith.extsi %915 : i32 to i64
%920 = llvm.getelementptr %720[%919] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%914 = llvm.load %920 : !llvm.ptr -> f64
%921 = llvm.mlir.constant(1 : i64) : i64
%922 = llvm.alloca %921 x f64 : (i64) -> !llvm.ptr
llvm.store %914, %922 : f64, !llvm.ptr
%925 = arith.constant 0 : i32
%926 = arith.extsi %925 : i32 to i64
%927 = llvm.getelementptr %868[%926] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%924 = llvm.load %927 : !llvm.ptr -> i32
%928 = arith.extsi %924 : i32 to i64
%929 = llvm.getelementptr %726[%928] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%923 = llvm.load %929 : !llvm.ptr -> i32
%930 = llvm.mlir.constant(1 : i64) : i64
%931 = llvm.alloca %930 x i32 : (i64) -> !llvm.ptr
llvm.store %923, %931 : i32, !llvm.ptr
%932 = arith.constant 1 : i32
%933 = llvm.mlir.constant(1 : i64) : i64
%934 = llvm.alloca %933 x i32 : (i64) -> !llvm.ptr
llvm.store %932, %934 : i32, !llvm.ptr
cf.br ^bb150
^bb150:
%935 = llvm.load %934 : !llvm.ptr -> i32
%936 = llvm.load %734 : !llvm.ptr -> i32
%937 = arith.cmpi slt, %935, %936 : i32
cf.cond_br %937, ^bb151, ^bb152
^bb151:
%939 = llvm.load %934 : !llvm.ptr -> i32
%940 = arith.extsi %939 : i32 to i64
%941 = llvm.getelementptr %868[%940] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%938 = llvm.load %941 : !llvm.ptr -> i32
%943 = arith.extsi %938 : i32 to i64
%944 = llvm.getelementptr %720[%943] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%942 = llvm.load %944 : !llvm.ptr -> f64
%945 = llvm.load %922 : !llvm.ptr -> f64
%946 = arith.subf %942, %945 : f64
%947 = math.absf %946 : f64
%948 = llvm.mlir.addressof @EPS : !llvm.ptr
%949 = llvm.load %948 : !llvm.ptr -> f64
%950 = arith.cmpf olt, %947, %949 : f64
cf.cond_br %950, ^bb153, ^bb154
^bb153:
%951 = llvm.load %931 : !llvm.ptr -> i32
%953 = arith.extsi %938 : i32 to i64
%954 = llvm.getelementptr %726[%953] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%952 = llvm.load %954 : !llvm.ptr -> i32
%955 = arith.addi %951, %952 : i32
llvm.store %955, %931 : i32, !llvm.ptr
cf.br ^bb155
^bb154:
%956 = llvm.load %922 : !llvm.ptr -> f64
%957 = llvm.load %910 : !llvm.ptr -> i32
%958 = arith.extsi %957 : i32 to i64
%959 = llvm.getelementptr %896[%958] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %956, %959 : f64, !llvm.ptr
%960 = llvm.load %931 : !llvm.ptr -> i32
%961 = llvm.load %910 : !llvm.ptr -> i32
%962 = arith.extsi %961 : i32 to i64
%963 = llvm.getelementptr %902[%962] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %960, %963 : i32, !llvm.ptr
%964 = llvm.load %910 : !llvm.ptr -> i32
%965 = arith.constant 1 : i32
%966 = arith.addi %964, %965 : i32
llvm.store %966, %910 : i32, !llvm.ptr
%968 = arith.extsi %938 : i32 to i64
%969 = llvm.getelementptr %720[%968] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%967 = llvm.load %969 : !llvm.ptr -> f64
llvm.store %967, %922 : f64, !llvm.ptr
%971 = arith.extsi %938 : i32 to i64
%972 = llvm.getelementptr %726[%971] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%970 = llvm.load %972 : !llvm.ptr -> i32
llvm.store %970, %931 : i32, !llvm.ptr
cf.br ^bb155
^bb155:
%973 = llvm.load %934 : !llvm.ptr -> i32
%974 = arith.constant 1 : i32
%975 = arith.addi %973, %974 : i32
llvm.store %975, %934 : i32, !llvm.ptr
cf.br ^bb150
^bb152:
%976 = llvm.load %922 : !llvm.ptr -> f64
%977 = llvm.load %910 : !llvm.ptr -> i32
%978 = arith.extsi %977 : i32 to i64
%979 = llvm.getelementptr %896[%978] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %976, %979 : f64, !llvm.ptr
%980 = llvm.load %931 : !llvm.ptr -> i32
%981 = llvm.load %910 : !llvm.ptr -> i32
%982 = arith.extsi %981 : i32 to i64
%983 = llvm.getelementptr %902[%982] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %980, %983 : i32, !llvm.ptr
%984 = llvm.load %910 : !llvm.ptr -> i32
%985 = arith.constant 1 : i32
%986 = arith.addi %984, %985 : i32
llvm.store %986, %910 : i32, !llvm.ptr
cf.br ^bb149
^bb148:
cf.br ^bb149
^bb149:
%987 = arith.constant 0 : i32
%988 = llvm.mlir.constant(1 : i64) : i64
%989 = llvm.alloca %988 x i32 : (i64) -> !llvm.ptr
llvm.store %987, %989 : i32, !llvm.ptr
%990 = arith.constant 0.0 : f32
%991 = arith.extf %990 : f32 to f64
%992 = llvm.mlir.constant(1 : i64) : i64
%993 = llvm.alloca %992 x f64 : (i64) -> !llvm.ptr
llvm.store %991, %993 : f64, !llvm.ptr
%994 = arith.constant 0.0 : f32
%995 = arith.extf %994 : f32 to f64
%996 = llvm.mlir.constant(1 : i64) : i64
%997 = llvm.alloca %996 x f64 : (i64) -> !llvm.ptr
llvm.store %995, %997 : f64, !llvm.ptr
%998 = arith.constant 0.0 : f32
%999 = arith.extf %998 : f32 to f64
%1000 = llvm.mlir.constant(1 : i64) : i64
%1001 = llvm.alloca %1000 x f64 : (i64) -> !llvm.ptr
llvm.store %999, %1001 : f64, !llvm.ptr
%1002 = arith.constant 0 : i32
%1003 = llvm.mlir.constant(1 : i64) : i64
%1004 = llvm.alloca %1003 x i32 : (i64) -> !llvm.ptr
llvm.store %1002, %1004 : i32, !llvm.ptr
cf.br ^bb156
^bb156:
%1005 = llvm.load %1004 : !llvm.ptr -> i32
%1006 = llvm.load %910 : !llvm.ptr -> i32
%1007 = arith.cmpi slt, %1005, %1006 : i32
cf.cond_br %1007, ^bb157, ^bb158
^bb157:
%1009 = llvm.load %1004 : !llvm.ptr -> i32
%1010 = arith.extsi %1009 : i32 to i64
%1011 = llvm.getelementptr %896[%1010] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%1008 = llvm.load %1011 : !llvm.ptr -> f64
%1013 = llvm.load %1004 : !llvm.ptr -> i32
%1014 = arith.extsi %1013 : i32 to i64
%1015 = llvm.getelementptr %902[%1014] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%1012 = llvm.load %1015 : !llvm.ptr -> i32
%1016 = arith.cmpf ogt, %1008, %arg4 : f64
cf.cond_br %1016, ^bb159, ^bb160
^bb159:
cf.br ^bb158
^bb160:
cf.br ^bb161
^bb161:
%1017 = llvm.load %1001 : !llvm.ptr -> f64
%1018 = arith.cmpf ogt, %1008, %1017 : f64
cf.cond_br %1018, ^bb162, ^bb163
^bb162:
%1019 = llvm.load %1001 : !llvm.ptr -> f64
%1020 = llvm.load %989 : !llvm.ptr -> i32
%1021 = arith.extsi %1020 : i32 to i64
%1022 = llvm.getelementptr %arg5[%1021] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %1019, %1022 : f64, !llvm.ptr
%1023 = llvm.load %989 : !llvm.ptr -> i32
%1024 = arith.extsi %1023 : i32 to i64
%1025 = llvm.getelementptr %arg6[%1024] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %1008, %1025 : f64, !llvm.ptr
%1026 = llvm.load %993 : !llvm.ptr -> f64
%1027 = llvm.load %989 : !llvm.ptr -> i32
%1028 = arith.extsi %1027 : i32 to i64
%1029 = llvm.getelementptr %arg7[%1028] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %1026, %1029 : f64, !llvm.ptr
%1030 = llvm.load %997 : !llvm.ptr -> f64
%1031 = llvm.load %989 : !llvm.ptr -> i32
%1032 = arith.extsi %1031 : i32 to i64
%1033 = llvm.getelementptr %arg8[%1032] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %1030, %1033 : f64, !llvm.ptr
%1034 = llvm.load %989 : !llvm.ptr -> i32
%1035 = arith.constant 1 : i32
%1036 = arith.addi %1034, %1035 : i32
llvm.store %1036, %989 : i32, !llvm.ptr
%1037 = llvm.load %997 : !llvm.ptr -> f64
%1038 = llvm.load %993 : !llvm.ptr -> f64
%1039 = llvm.load %1001 : !llvm.ptr -> f64
%1040 = arith.subf %1008, %1039 : f64
%1041 = arith.mulf %1038, %1040 : f64
%1042 = arith.addf %1037, %1041 : f64
llvm.store %1042, %997 : f64, !llvm.ptr
llvm.store %1008, %1001 : f64, !llvm.ptr
cf.br ^bb164
^bb163:
cf.br ^bb164
^bb164:
%1043 = llvm.load %993 : !llvm.ptr -> f64
%1044 = arith.sitofp %1012 : i32 to f64
%1045 = arith.addf %1043, %1044 : f64
llvm.store %1045, %993 : f64, !llvm.ptr
%1046 = llvm.load %1004 : !llvm.ptr -> i32
%1047 = arith.constant 1 : i32
%1048 = arith.addi %1046, %1047 : i32
llvm.store %1048, %1004 : i32, !llvm.ptr
cf.br ^bb156
^bb158:
%1049 = llvm.load %1001 : !llvm.ptr -> f64
%1050 = arith.cmpf olt, %1049, %arg4 : f64
cf.cond_br %1050, ^bb165, ^bb166
^bb165:
%1051 = llvm.load %1001 : !llvm.ptr -> f64
%1052 = llvm.load %989 : !llvm.ptr -> i32
%1053 = arith.extsi %1052 : i32 to i64
%1054 = llvm.getelementptr %arg5[%1053] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %1051, %1054 : f64, !llvm.ptr
%1055 = llvm.load %989 : !llvm.ptr -> i32
%1056 = arith.extsi %1055 : i32 to i64
%1057 = llvm.getelementptr %arg6[%1056] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %arg4, %1057 : f64, !llvm.ptr
%1058 = llvm.load %993 : !llvm.ptr -> f64
%1059 = llvm.load %989 : !llvm.ptr -> i32
%1060 = arith.extsi %1059 : i32 to i64
%1061 = llvm.getelementptr %arg7[%1060] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %1058, %1061 : f64, !llvm.ptr
%1062 = llvm.load %997 : !llvm.ptr -> f64
%1063 = llvm.load %989 : !llvm.ptr -> i32
%1064 = arith.extsi %1063 : i32 to i64
%1065 = llvm.getelementptr %arg8[%1064] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %1062, %1065 : f64, !llvm.ptr
%1066 = llvm.load %989 : !llvm.ptr -> i32
%1067 = arith.constant 1 : i32
%1068 = arith.addi %1066, %1067 : i32
llvm.store %1068, %989 : i32, !llvm.ptr
cf.br ^bb167
^bb166:
cf.br ^bb167
^bb167:
func.call @free(%667) : (!llvm.ptr) -> ()
func.call @free(%671) : (!llvm.ptr) -> ()
func.call @free(%601) : (!llvm.ptr) -> ()
func.call @free(%631) : (!llvm.ptr) -> ()
func.call @free(%675) : (!llvm.ptr) -> ()
func.call @free(%720) : (!llvm.ptr) -> ()
func.call @free(%726) : (!llvm.ptr) -> ()
func.call @free(%868) : (!llvm.ptr) -> ()
func.call @free(%874) : (!llvm.ptr) -> ()
func.call @free(%896) : (!llvm.ptr) -> ()
func.call @free(%902) : (!llvm.ptr) -> ()
%1080 = llvm.load %989 : !llvm.ptr -> i32
func.return %1080 : i32
}
func.func @w_value(%arg0: !llvm.ptr, %arg1: !llvm.ptr, %arg2: !llvm.ptr, %arg3: !llvm.ptr, %arg4: i32, %arg5: f64, %arg6: !llvm.ptr, %arg7: !llvm.ptr) -> () {
%1081 = arith.constant 0 : i32
%1082 = llvm.mlir.constant(1 : i64) : i64
%1083 = llvm.alloca %1082 x i32 : (i64) -> !llvm.ptr
llvm.store %1081, %1083 : i32, !llvm.ptr
%1084 = llvm.mlir.constant(1 : i64) : i64
%1085 = llvm.alloca %1084 x i32 : (i64) -> !llvm.ptr
llvm.store %arg4, %1085 : i32, !llvm.ptr
cf.br ^bb168
^bb168:
%1086 = llvm.load %1083 : !llvm.ptr -> i32
%1087 = llvm.load %1085 : !llvm.ptr -> i32
%1088 = arith.cmpi slt, %1086, %1087 : i32
cf.cond_br %1088, ^bb169, ^bb170
^bb169:
%1089 = llvm.load %1083 : !llvm.ptr -> i32
%1090 = llvm.load %1085 : !llvm.ptr -> i32
%1091 = arith.addi %1089, %1090 : i32
%1092 = arith.constant 2 : i32
%1093 = arith.divsi %1091, %1092 : i32
%1095 = arith.extsi %1093 : i32 to i64
%1096 = llvm.getelementptr %arg1[%1095] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%1094 = llvm.load %1096 : !llvm.ptr -> f64
%1097 = arith.cmpf ole, %1094, %arg5 : f64
cf.cond_br %1097, ^bb171, ^bb172
^bb171:
%1098 = arith.constant 1 : i32
%1099 = arith.addi %1093, %1098 : i32
llvm.store %1099, %1083 : i32, !llvm.ptr
cf.br ^bb173
^bb172:
llvm.store %1093, %1085 : i32, !llvm.ptr
cf.br ^bb173
^bb173:
cf.br ^bb168
^bb170:
%1100 = llvm.load %1083 : !llvm.ptr -> i32
%1101 = arith.cmpi sge, %1100, %arg4 : i32
cf.cond_br %1101, ^bb174, ^bb175
^bb174:
%1102 = arith.constant 0.0 : f32
%1103 = arith.constant 0 : i32
%1104 = arith.extf %1102 : f32 to f64
%1105 = arith.extsi %1103 : i32 to i64
%1106 = llvm.getelementptr %arg6[%1105] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %1104, %1106 : f64, !llvm.ptr
%1107 = arith.constant 0.0 : f32
%1108 = arith.constant 0 : i32
%1109 = arith.extf %1107 : f32 to f64
%1110 = arith.extsi %1108 : i32 to i64
%1111 = llvm.getelementptr %arg7[%1110] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %1109, %1111 : f64, !llvm.ptr
func.return
^bb175:
cf.br ^bb176
^bb176:
%1113 = llvm.load %1083 : !llvm.ptr -> i32
%1114 = arith.extsi %1113 : i32 to i64
%1115 = llvm.getelementptr %arg0[%1114] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%1112 = llvm.load %1115 : !llvm.ptr -> f64
%1117 = llvm.load %1083 : !llvm.ptr -> i32
%1118 = arith.extsi %1117 : i32 to i64
%1119 = llvm.getelementptr %arg2[%1118] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%1116 = llvm.load %1119 : !llvm.ptr -> f64
%1121 = llvm.load %1083 : !llvm.ptr -> i32
%1122 = arith.extsi %1121 : i32 to i64
%1123 = llvm.getelementptr %arg3[%1122] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%1120 = llvm.load %1123 : !llvm.ptr -> f64
%1124 = arith.subf %arg5, %1112 : f64
%1125 = arith.mulf %1116, %1124 : f64
%1126 = arith.addf %1120, %1125 : f64
%1127 = arith.constant 0 : i32
%1128 = arith.extsi %1127 : i32 to i64
%1129 = llvm.getelementptr %arg6[%1128] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %1126, %1129 : f64, !llvm.ptr
%1130 = arith.constant 0 : i32
%1131 = arith.extsi %1130 : i32 to i64
%1132 = llvm.getelementptr %arg7[%1131] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %1116, %1132 : f64, !llvm.ptr
func.return
}
func.func @term_deriv(%arg0: f64, %arg1: f64, %arg2: f64, %arg3: f64) -> f64 {
%1133 = arith.mulf %arg0, %arg3 : f64
%1134 = arith.mulf %1133, %arg3 : f64
%1135 = arith.constant 2.0 : f32
%1137 = arith.extf %1135 : f32 to f64
%1136 = arith.mulf %1137, %arg0 : f64
%1138 = arith.mulf %1136, %arg2 : f64
%1139 = arith.mulf %1138, %arg3 : f64
%1140 = arith.subf %1134, %1139 : f64
%1141 = arith.mulf %arg1, %arg2 : f64
%1142 = arith.subf %1140, %1141 : f64
%1143 = arith.subf %arg3, %arg2 : f64
%1144 = arith.subf %arg3, %arg2 : f64
%1145 = arith.mulf %1143, %1144 : f64
%1146 = arith.divf %1142, %1145 : f64
func.return %1146 : f64
}
func.func @e_local_func(%arg0: f64, %arg1: f64, %arg2: f64, %arg3: f64, %arg4: f64) -> f64 {
%1147 = arith.constant 0.5 : f32
%1149 = arith.extf %1147 : f32 to f64
%1148 = arith.mulf %1149, %arg0 : f64
%1150 = arith.mulf %arg1, %arg0 : f64
%1151 = arith.addf %1150, %arg2 : f64
%1152 = arith.constant 1.0 : f32
%1154 = arith.extf %1152 : f32 to f64
%1153 = arith.subf %arg0, %1154 : f64
%1155 = arith.divf %1151, %1153 : f64
%1156 = arith.mulf %arg3, %arg0 : f64
%1157 = arith.addf %1156, %arg4 : f64
%1158 = llvm.mlir.addressof @SQRT2 : !llvm.ptr
%1159 = llvm.load %1158 : !llvm.ptr -> f64
%1160 = arith.subf %arg0, %1159 : f64
%1161 = arith.divf %1157, %1160 : f64
%1162 = arith.addf %1155, %1161 : f64
%1163 = arith.mulf %1148, %1162 : f64
func.return %1163 : f64
}
func.func @de_local_func(%arg0: f64, %arg1: f64, %arg2: f64, %arg3: f64, %arg4: f64) -> f64 {
%1164 = arith.constant 0.5 : f32
%1166 = arith.constant 1.0 : f32
%1167 = arith.extf %1166 : f32 to f64
%1165 = func.call @term_deriv(%arg1, %arg2, %1167, %arg0) : (f64, f64, f64, f64) -> f64
%1169 = llvm.mlir.addressof @SQRT2 : !llvm.ptr
%1170 = llvm.load %1169 : !llvm.ptr -> f64
%1168 = func.call @term_deriv(%arg3, %arg4, %1170, %arg0) : (f64, f64, f64, f64) -> f64
%1171 = arith.addf %1165, %1168 : f64
%1173 = arith.extf %1164 : f32 to f64
%1172 = arith.mulf %1173, %1171 : f64
func.return %1172 : f64
}
func.func @bisect_func(%arg0: f64, %arg1: f64, %arg2: f64, %arg3: f64, %arg4: f64, %arg5: f64, %arg6: f64) -> f64 {
%1174 = llvm.mlir.constant(1 : i64) : i64
%1175 = llvm.alloca %1174 x f64 : (i64) -> !llvm.ptr
llvm.store %arg0, %1175 : f64, !llvm.ptr
%1176 = llvm.mlir.constant(1 : i64) : i64
%1177 = llvm.alloca %1176 x f64 : (i64) -> !llvm.ptr
llvm.store %arg1, %1177 : f64, !llvm.ptr
%1178 = llvm.mlir.constant(1 : i64) : i64
%1179 = llvm.alloca %1178 x f64 : (i64) -> !llvm.ptr
llvm.store %arg2, %1179 : f64, !llvm.ptr
%1180 = arith.constant 0 : i32
%1181 = llvm.mlir.constant(1 : i64) : i64
%1182 = llvm.alloca %1181 x i32 : (i64) -> !llvm.ptr
llvm.store %1180, %1182 : i32, !llvm.ptr
cf.br ^bb177
^bb177:
%1183 = llvm.load %1182 : !llvm.ptr -> i32
%1184 = arith.constant 60 : i32
%1185 = arith.cmpi slt, %1183, %1184 : i32
cf.cond_br %1185, ^bb178, ^bb179
^bb178:
%1186 = llvm.load %1175 : !llvm.ptr -> f64
%1187 = llvm.load %1177 : !llvm.ptr -> f64
%1188 = arith.addf %1186, %1187 : f64
%1189 = arith.constant 0.5 : f32
%1191 = arith.extf %1189 : f32 to f64
%1190 = arith.mulf %1188, %1191 : f64
%1192 = func.call @de_local_func(%1190, %arg3, %arg4, %arg5, %arg6) : (f64, f64, f64, f64, f64) -> f64
%1193 = arith.constant 0.0 : f32
%1195 = arith.extf %1193 : f32 to f64
%1194 = arith.cmpf oeq, %1192, %1195 : f64
cf.cond_br %1194, ^bb180, ^bb181
^bb180:
func.return %1190 : f64
^bb181:
cf.br ^bb182
^bb182:
%1196 = llvm.load %1179 : !llvm.ptr -> f64
%1197 = arith.mulf %1192, %1196 : f64
%1198 = arith.constant 0.0 : f32
%1200 = arith.extf %1198 : f32 to f64
%1199 = arith.cmpf ogt, %1197, %1200 : f64
cf.cond_br %1199, ^bb183, ^bb184
^bb183:
llvm.store %1190, %1175 : f64, !llvm.ptr
llvm.store %1192, %1179 : f64, !llvm.ptr
cf.br ^bb185
^bb184:
llvm.store %1190, %1177 : f64, !llvm.ptr
cf.br ^bb185
^bb185:
%1201 = llvm.load %1182 : !llvm.ptr -> i32
%1202 = arith.constant 1 : i32
%1203 = arith.addi %1201, %1202 : i32
llvm.store %1203, %1182 : i32, !llvm.ptr
cf.br ^bb177
^bb179:
%1204 = llvm.load %1175 : !llvm.ptr -> f64
%1205 = llvm.load %1177 : !llvm.ptr -> f64
%1206 = arith.addf %1204, %1205 : f64
%1207 = arith.constant 0.5 : f32
%1209 = arith.extf %1207 : f32 to f64
%1208 = arith.mulf %1206, %1209 : f64
func.return %1208 : f64
}
func.func @f_value(%arg0: f64, %arg1: f64, %arg2: !llvm.ptr, %arg3: !llvm.ptr, %arg4: !llvm.ptr, %arg5: !llvm.ptr, %arg6: i32) -> f64 {
%1211 = llvm.mlir.addressof @MAX_VALS : !llvm.ptr
%1212 = llvm.load %1211 : !llvm.ptr -> i32
%1213 = arith.extsi %1212 : i32 to i64
%1214 = arith.constant 8 : i32
%1215 = arith.extsi %1214 : i32 to i64
%1210 = func.call @calloc(%1213, %1215) : (i64, i64) -> !llvm.ptr
%1216 = arith.constant 0 : i32
%1217 = llvm.mlir.constant(1 : i64) : i64
%1218 = llvm.alloca %1217 x i32 : (i64) -> !llvm.ptr
llvm.store %1216, %1218 : i32, !llvm.ptr
%1219 = llvm.load %1218 : !llvm.ptr -> i32
%1220 = arith.extsi %1219 : i32 to i64
%1221 = llvm.getelementptr %1210[%1220] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %arg0, %1221 : f64, !llvm.ptr
%1222 = llvm.load %1218 : !llvm.ptr -> i32
%1223 = arith.constant 1 : i32
%1224 = arith.addi %1222, %1223 : i32
llvm.store %1224, %1218 : i32, !llvm.ptr
%1225 = llvm.load %1218 : !llvm.ptr -> i32
%1226 = arith.extsi %1225 : i32 to i64
%1227 = llvm.getelementptr %1210[%1226] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %arg1, %1227 : f64, !llvm.ptr
%1228 = llvm.load %1218 : !llvm.ptr -> i32
%1229 = arith.constant 1 : i32
%1230 = arith.addi %1228, %1229 : i32
llvm.store %1230, %1218 : i32, !llvm.ptr
%1231 = arith.constant 0 : i32
%1232 = llvm.mlir.constant(1 : i64) : i64
%1233 = llvm.alloca %1232 x i32 : (i64) -> !llvm.ptr
llvm.store %1231, %1233 : i32, !llvm.ptr
cf.br ^bb186
^bb186:
%1234 = llvm.load %1233 : !llvm.ptr -> i32
%1235 = arith.cmpi slt, %1234, %arg6 : i32
cf.cond_br %1235, ^bb187, ^bb188
^bb187:
%1237 = llvm.load %1233 : !llvm.ptr -> i32
%1238 = arith.extsi %1237 : i32 to i64
%1239 = llvm.getelementptr %arg2[%1238] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%1236 = llvm.load %1239 : !llvm.ptr -> f64
%1240 = arith.constant 1.0 : f32
%1242 = arith.extf %1240 : f32 to f64
%1241 = arith.addf %1236, %1242 : f64
%1243 = arith.cmpf olt, %arg0, %1241 : f64
%1244 = scf.if %1243 -> (i1) {
%1245 = arith.cmpf olt, %1241, %arg1 : f64
scf.yield %1245 : i1
} else {
%1246 = arith.constant false
scf.yield %1246 : i1
}
cf.cond_br %1244, ^bb189, ^bb190
^bb189:
%1247 = llvm.load %1218 : !llvm.ptr -> i32
%1248 = arith.extsi %1247 : i32 to i64
%1249 = llvm.getelementptr %1210[%1248] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %1241, %1249 : f64, !llvm.ptr
%1250 = llvm.load %1218 : !llvm.ptr -> i32
%1251 = arith.constant 1 : i32
%1252 = arith.addi %1250, %1251 : i32
llvm.store %1252, %1218 : i32, !llvm.ptr
cf.br ^bb191
^bb190:
cf.br ^bb191
^bb191:
%1253 = llvm.mlir.addressof @SQRT2 : !llvm.ptr
%1254 = llvm.load %1253 : !llvm.ptr -> f64
%1255 = arith.addf %1236, %1254 : f64
%1256 = arith.cmpf olt, %arg0, %1255 : f64
%1257 = scf.if %1256 -> (i1) {
%1258 = arith.cmpf olt, %1255, %arg1 : f64
scf.yield %1258 : i1
} else {
%1259 = arith.constant false
scf.yield %1259 : i1
}
cf.cond_br %1257, ^bb192, ^bb193
^bb192:
%1260 = llvm.load %1218 : !llvm.ptr -> i32
%1261 = arith.extsi %1260 : i32 to i64
%1262 = llvm.getelementptr %1210[%1261] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %1255, %1262 : f64, !llvm.ptr
%1263 = llvm.load %1218 : !llvm.ptr -> i32
%1264 = arith.constant 1 : i32
%1265 = arith.addi %1263, %1264 : i32
llvm.store %1265, %1218 : i32, !llvm.ptr
cf.br ^bb194
^bb193:
cf.br ^bb194
^bb194:
%1266 = llvm.load %1233 : !llvm.ptr -> i32
%1267 = arith.constant 1 : i32
%1268 = arith.addi %1266, %1267 : i32
llvm.store %1268, %1233 : i32, !llvm.ptr
cf.br ^bb186
^bb188:
%1269 = arith.constant 0 : i32
%1270 = llvm.mlir.constant(1 : i64) : i64
%1271 = llvm.alloca %1270 x i32 : (i64) -> !llvm.ptr
llvm.store %1269, %1271 : i32, !llvm.ptr
cf.br ^bb195
^bb195:
%1272 = llvm.load %1271 : !llvm.ptr -> i32
%1273 = arith.cmpi slt, %1272, %arg6 : i32
cf.cond_br %1273, ^bb196, ^bb197
^bb196:
%1275 = llvm.load %1271 : !llvm.ptr -> i32
%1276 = arith.extsi %1275 : i32 to i64
%1277 = llvm.getelementptr %arg3[%1276] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%1274 = llvm.load %1277 : !llvm.ptr -> f64
%1278 = arith.constant 1.0 : f32
%1280 = arith.extf %1278 : f32 to f64
%1279 = arith.addf %1274, %1280 : f64
%1281 = arith.cmpf olt, %arg0, %1279 : f64
%1282 = scf.if %1281 -> (i1) {
%1283 = arith.cmpf olt, %1279, %arg1 : f64
scf.yield %1283 : i1
} else {
%1284 = arith.constant false
scf.yield %1284 : i1
}
cf.cond_br %1282, ^bb198, ^bb199
^bb198:
%1285 = llvm.load %1218 : !llvm.ptr -> i32
%1286 = arith.extsi %1285 : i32 to i64
%1287 = llvm.getelementptr %1210[%1286] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %1279, %1287 : f64, !llvm.ptr
%1288 = llvm.load %1218 : !llvm.ptr -> i32
%1289 = arith.constant 1 : i32
%1290 = arith.addi %1288, %1289 : i32
llvm.store %1290, %1218 : i32, !llvm.ptr
cf.br ^bb200
^bb199:
cf.br ^bb200
^bb200:
%1291 = llvm.mlir.addressof @SQRT2 : !llvm.ptr
%1292 = llvm.load %1291 : !llvm.ptr -> f64
%1293 = arith.addf %1274, %1292 : f64
%1294 = arith.cmpf olt, %arg0, %1293 : f64
%1295 = scf.if %1294 -> (i1) {
%1296 = arith.cmpf olt, %1293, %arg1 : f64
scf.yield %1296 : i1
} else {
%1297 = arith.constant false
scf.yield %1297 : i1
}
cf.cond_br %1295, ^bb201, ^bb202
^bb201:
%1298 = llvm.load %1218 : !llvm.ptr -> i32
%1299 = arith.extsi %1298 : i32 to i64
%1300 = llvm.getelementptr %1210[%1299] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %1293, %1300 : f64, !llvm.ptr
%1301 = llvm.load %1218 : !llvm.ptr -> i32
%1302 = arith.constant 1 : i32
%1303 = arith.addi %1301, %1302 : i32
llvm.store %1303, %1218 : i32, !llvm.ptr
cf.br ^bb203
^bb202:
cf.br ^bb203
^bb203:
%1304 = llvm.load %1271 : !llvm.ptr -> i32
%1305 = arith.constant 1 : i32
%1306 = arith.addi %1304, %1305 : i32
llvm.store %1306, %1271 : i32, !llvm.ptr
cf.br ^bb195
^bb197:
%1308 = llvm.load %1218 : !llvm.ptr -> i32
func.call @dsort(%1210, %1308) : (!llvm.ptr, i32) -> ()
%1310 = llvm.load %1218 : !llvm.ptr -> i32
%1309 = func.call @dedup_double(%1210, %1310) : (!llvm.ptr, i32) -> i32
llvm.store %1309, %1218 : i32, !llvm.ptr
%1311 = arith.constant 1.0 : f32
%1312 = arith.negf %1311 : f32
%1313 = arith.extf %1312 : f32 to f64
%1314 = llvm.mlir.constant(1 : i64) : i64
%1315 = llvm.alloca %1314 x f64 : (i64) -> !llvm.ptr
llvm.store %1313, %1315 : f64, !llvm.ptr
%1316 = arith.constant 0 : i32
%1317 = llvm.mlir.constant(1 : i64) : i64
%1318 = llvm.alloca %1317 x i32 : (i64) -> !llvm.ptr
llvm.store %1316, %1318 : i32, !llvm.ptr
cf.br ^bb204
^bb204:
%1319 = llvm.load %1318 : !llvm.ptr -> i32
%1320 = llvm.load %1218 : !llvm.ptr -> i32
%1321 = arith.constant 1 : i32
%1322 = arith.subi %1320, %1321 : i32
%1323 = arith.cmpi slt, %1319, %1322 : i32
cf.cond_br %1323, ^bb205, ^bb206
^bb205:
%1325 = llvm.load %1318 : !llvm.ptr -> i32
%1326 = arith.extsi %1325 : i32 to i64
%1327 = llvm.getelementptr %1210[%1326] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%1324 = llvm.load %1327 : !llvm.ptr -> f64
%1329 = llvm.load %1318 : !llvm.ptr -> i32
%1330 = arith.constant 1 : i32
%1331 = arith.addi %1329, %1330 : i32
%1332 = arith.extsi %1331 : i32 to i64
%1333 = llvm.getelementptr %1210[%1332] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%1328 = llvm.load %1333 : !llvm.ptr -> f64
%1334 = arith.subf %1328, %1324 : f64
%1335 = arith.constant 0 : f32
%1337 = arith.extf %1335 : f32 to f64
%1336 = arith.cmpf oge, %1334, %1337 : f64
cf.cond_br %1336, ^bb207, ^bb208
^bb207:
%1338 = arith.addf %1324, %1328 : f64
%1339 = arith.constant 0.5 : f32
%1341 = arith.extf %1339 : f32 to f64
%1340 = arith.mulf %1338, %1341 : f64
%1343 = arith.constant 1 : i32
%1344 = arith.constant 8 : i32
%1345 = arith.extsi %1343 : i32 to i64
%1346 = arith.extsi %1344 : i32 to i64
%1342 = func.call @calloc(%1345, %1346) : (i64, i64) -> !llvm.ptr
%1348 = arith.constant 1 : i32
%1349 = arith.constant 8 : i32
%1350 = arith.extsi %1348 : i32 to i64
%1351 = arith.extsi %1349 : i32 to i64
%1347 = func.call @calloc(%1350, %1351) : (i64, i64) -> !llvm.ptr
%1353 = arith.constant 1 : i32
%1354 = arith.constant 8 : i32
%1355 = arith.extsi %1353 : i32 to i64
%1356 = arith.extsi %1354 : i32 to i64
%1352 = func.call @calloc(%1355, %1356) : (i64, i64) -> !llvm.ptr
%1358 = arith.constant 1 : i32
%1359 = arith.constant 8 : i32
%1360 = arith.extsi %1358 : i32 to i64
%1361 = arith.extsi %1359 : i32 to i64
%1357 = func.call @calloc(%1360, %1361) : (i64, i64) -> !llvm.ptr
%1363 = arith.constant 1.0 : f32
%1365 = arith.extf %1363 : f32 to f64
%1364 = arith.subf %1340, %1365 : f64
func.call @w_value(%arg2, %arg3, %arg4, %arg5, %arg6, %1364, %1342, %1347) : (!llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, i32, f64, !llvm.ptr, !llvm.ptr) -> ()
%1367 = llvm.mlir.addressof @SQRT2 : !llvm.ptr
%1368 = llvm.load %1367 : !llvm.ptr -> f64
%1369 = arith.subf %1340, %1368 : f64
func.call @w_value(%arg2, %arg3, %arg4, %arg5, %arg6, %1369, %1352, %1357) : (!llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, i32, f64, !llvm.ptr, !llvm.ptr) -> ()
%1371 = arith.constant 0 : i32
%1372 = arith.extsi %1371 : i32 to i64
%1373 = llvm.getelementptr %1342[%1372] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%1370 = llvm.load %1373 : !llvm.ptr -> f64
%1375 = arith.constant 0 : i32
%1376 = arith.extsi %1375 : i32 to i64
%1377 = llvm.getelementptr %1347[%1376] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%1374 = llvm.load %1377 : !llvm.ptr -> f64
%1379 = arith.constant 0 : i32
%1380 = arith.extsi %1379 : i32 to i64
%1381 = llvm.getelementptr %1352[%1380] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%1378 = llvm.load %1381 : !llvm.ptr -> f64
%1383 = arith.constant 0 : i32
%1384 = arith.extsi %1383 : i32 to i64
%1385 = llvm.getelementptr %1357[%1384] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%1382 = llvm.load %1385 : !llvm.ptr -> f64
%1386 = arith.mulf %1374, %1340 : f64
%1387 = arith.subf %1370, %1386 : f64
%1388 = arith.mulf %1382, %1340 : f64
%1389 = arith.subf %1378, %1388 : f64
func.call @free(%1342) : (!llvm.ptr) -> ()
func.call @free(%1347) : (!llvm.ptr) -> ()
func.call @free(%1352) : (!llvm.ptr) -> ()
func.call @free(%1357) : (!llvm.ptr) -> ()
%1394 = func.call @e_local_func(%1324, %1374, %1387, %1382, %1389) : (f64, f64, f64, f64, f64) -> f64
%1395 = llvm.load %1315 : !llvm.ptr -> f64
%1396 = arith.cmpf ogt, %1394, %1395 : f64
cf.cond_br %1396, ^bb210, ^bb211
^bb210:
llvm.store %1394, %1315 : f64, !llvm.ptr
cf.br ^bb212
^bb211:
cf.br ^bb212
^bb212:
%1397 = func.call @e_local_func(%1340, %1374, %1387, %1382, %1389) : (f64, f64, f64, f64, f64) -> f64
%1398 = llvm.load %1315 : !llvm.ptr -> f64
%1399 = arith.cmpf ogt, %1397, %1398 : f64
cf.cond_br %1399, ^bb213, ^bb214
^bb213:
llvm.store %1397, %1315 : f64, !llvm.ptr
cf.br ^bb215
^bb214:
cf.br ^bb215
^bb215:
%1400 = func.call @e_local_func(%1328, %1374, %1387, %1382, %1389) : (f64, f64, f64, f64, f64) -> f64
%1401 = llvm.load %1315 : !llvm.ptr -> f64
%1402 = arith.cmpf ogt, %1400, %1401 : f64
cf.cond_br %1402, ^bb216, ^bb217
^bb216:
llvm.store %1400, %1315 : f64, !llvm.ptr
cf.br ^bb218
^bb217:
cf.br ^bb218
^bb218:
%1403 = arith.constant 0.0000000001 : f32
%1405 = arith.extf %1403 : f32 to f64
%1404 = arith.addf %1324, %1405 : f64
%1406 = arith.constant 0.0000000001 : f32
%1408 = arith.extf %1406 : f32 to f64
%1407 = arith.subf %1328, %1408 : f64
%1409 = arith.cmpf olt, %1404, %1407 : f64
cf.cond_br %1409, ^bb219, ^bb220
^bb219:
%1410 = func.call @de_local_func(%1404, %1374, %1387, %1382, %1389) : (f64, f64, f64, f64, f64) -> f64
%1411 = func.call @de_local_func(%1340, %1374, %1387, %1382, %1389) : (f64, f64, f64, f64, f64) -> f64
%1412 = func.call @de_local_func(%1407, %1374, %1387, %1382, %1389) : (f64, f64, f64, f64, f64) -> f64
%1413 = arith.mulf %1410, %1411 : f64
%1414 = arith.constant 0.0 : f32
%1416 = arith.extf %1414 : f32 to f64
%1415 = arith.cmpf olt, %1413, %1416 : f64
cf.cond_br %1415, ^bb222, ^bb223
^bb222:
%1417 = func.call @bisect_func(%1404, %1340, %1410, %1374, %1387, %1382, %1389) : (f64, f64, f64, f64, f64, f64, f64) -> f64
%1418 = func.call @e_local_func(%1417, %1374, %1387, %1382, %1389) : (f64, f64, f64, f64, f64) -> f64
%1419 = llvm.load %1315 : !llvm.ptr -> f64
%1420 = arith.cmpf ogt, %1418, %1419 : f64
cf.cond_br %1420, ^bb225, ^bb226
^bb225:
llvm.store %1418, %1315 : f64, !llvm.ptr
cf.br ^bb227
^bb226:
cf.br ^bb227
^bb227:
cf.br ^bb224
^bb223:
cf.br ^bb224
^bb224:
%1421 = arith.mulf %1411, %1412 : f64
%1422 = arith.constant 0.0 : f32
%1424 = arith.extf %1422 : f32 to f64
%1423 = arith.cmpf olt, %1421, %1424 : f64
cf.cond_br %1423, ^bb228, ^bb229
^bb228:
%1425 = func.call @bisect_func(%1340, %1407, %1411, %1374, %1387, %1382, %1389) : (f64, f64, f64, f64, f64, f64, f64) -> f64
%1426 = func.call @e_local_func(%1425, %1374, %1387, %1382, %1389) : (f64, f64, f64, f64, f64) -> f64
%1427 = llvm.load %1315 : !llvm.ptr -> f64
%1428 = arith.cmpf ogt, %1426, %1427 : f64
cf.cond_br %1428, ^bb231, ^bb232
^bb231:
llvm.store %1426, %1315 : f64, !llvm.ptr
cf.br ^bb233
^bb232:
cf.br ^bb233
^bb233:
cf.br ^bb230
^bb229:
cf.br ^bb230
^bb230:
cf.br ^bb221
^bb220:
cf.br ^bb221
^bb221:
cf.br ^bb209
^bb208:
cf.br ^bb209
^bb209:
%1429 = llvm.load %1318 : !llvm.ptr -> i32
%1430 = arith.constant 1 : i32
%1431 = arith.addi %1429, %1430 : i32
llvm.store %1431, %1318 : i32, !llvm.ptr
cf.br ^bb204
^bb206:
func.call @free(%1210) : (!llvm.ptr) -> ()
%1433 = llvm.load %1315 : !llvm.ptr -> f64
func.return %1433 : f64
}
func.func @main() -> i32 {
%1434 = arith.constant 500.0 : f32
%1435 = arith.extf %1434 : f32 to f64
%1437 = llvm.mlir.addressof @MAX_VALS : !llvm.ptr
%1438 = llvm.load %1437 : !llvm.ptr -> i32
%1439 = arith.extsi %1438 : i32 to i64
%1440 = arith.constant 8 : i32
%1441 = arith.extsi %1440 : i32 to i64
%1436 = func.call @calloc(%1439, %1441) : (i64, i64) -> !llvm.ptr
%1443 = llvm.mlir.addressof @MAX_VALS : !llvm.ptr
%1444 = llvm.load %1443 : !llvm.ptr -> i32
%1445 = arith.extsi %1444 : i32 to i64
%1446 = arith.constant 8 : i32
%1447 = arith.extsi %1446 : i32 to i64
%1442 = func.call @calloc(%1445, %1447) : (i64, i64) -> !llvm.ptr
%1449 = llvm.mlir.addressof @MAX_VALS : !llvm.ptr
%1450 = llvm.load %1449 : !llvm.ptr -> i32
%1451 = arith.extsi %1450 : i32 to i64
%1452 = arith.constant 4 : i32
%1453 = arith.extsi %1452 : i32 to i64
%1448 = func.call @calloc(%1451, %1453) : (i64, i64) -> !llvm.ptr
%1454 = func.call @compute_grundy_intervals(%1435, %1436, %1442, %1448) : (f64, !llvm.ptr, !llvm.ptr, !llvm.ptr) -> i32
%1456 = llvm.mlir.addressof @MAX_VALS : !llvm.ptr
%1457 = llvm.load %1456 : !llvm.ptr -> i32
%1458 = arith.extsi %1457 : i32 to i64
%1459 = arith.constant 8 : i32
%1460 = arith.extsi %1459 : i32 to i64
%1455 = func.call @calloc(%1458, %1460) : (i64, i64) -> !llvm.ptr
%1462 = llvm.mlir.addressof @MAX_VALS : !llvm.ptr
%1463 = llvm.load %1462 : !llvm.ptr -> i32
%1464 = arith.extsi %1463 : i32 to i64
%1465 = arith.constant 8 : i32
%1466 = arith.extsi %1465 : i32 to i64
%1461 = func.call @calloc(%1464, %1466) : (i64, i64) -> !llvm.ptr
%1468 = llvm.mlir.addressof @MAX_VALS : !llvm.ptr
%1469 = llvm.load %1468 : !llvm.ptr -> i32
%1470 = arith.extsi %1469 : i32 to i64
%1471 = arith.constant 8 : i32
%1472 = arith.extsi %1471 : i32 to i64
%1467 = func.call @calloc(%1470, %1472) : (i64, i64) -> !llvm.ptr
%1474 = llvm.mlir.addressof @MAX_VALS : !llvm.ptr
%1475 = llvm.load %1474 : !llvm.ptr -> i32
%1476 = arith.extsi %1475 : i32 to i64
%1477 = arith.constant 8 : i32
%1478 = arith.extsi %1477 : i32 to i64
%1473 = func.call @calloc(%1476, %1478) : (i64, i64) -> !llvm.ptr
%1479 = func.call @build_w_segments(%1436, %1442, %1448, %1454, %1435, %1455, %1461, %1467, %1473) : (!llvm.ptr, !llvm.ptr, !llvm.ptr, i32, f64, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr) -> i32
%1481 = arith.constant 200.0 : f32
%1482 = arith.constant 500.0 : f32
%1483 = arith.extf %1481 : f32 to f64
%1484 = arith.extf %1482 : f32 to f64
%1480 = func.call @f_value(%1483, %1484, %1455, %1461, %1467, %1473, %1479) : (f64, f64, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, i32) -> f64
%1485 = llvm.mlir.addressof @str_0 : !llvm.ptr
%1486 = llvm.call @printf(%1485, %1480) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, f64) -> i32
func.call @free(%1436) : (!llvm.ptr) -> ()
func.call @free(%1442) : (!llvm.ptr) -> ()
func.call @free(%1448) : (!llvm.ptr) -> ()
func.call @free(%1455) : (!llvm.ptr) -> ()
func.call @free(%1461) : (!llvm.ptr) -> ()
func.call @free(%1467) : (!llvm.ptr) -> ()
func.call @free(%1473) : (!llvm.ptr) -> ()
%1494 = arith.constant 0 : i32
func.return %1494 : i32
}
}