Problem 897
Newton's method with tridiagonal solve for optimizing a piecewise function.
View problem on Project Euler
Performance comparison
| Metric | Our solution | Best known |
| Time complexity | O(n^2) | ? |
| Space complexity | O(n^2) | ? |
| Approach | Flow solution | Not curated |
| Verdict | Unknown |
Flow source
# Project Euler 897
# Newton's method with tridiagonal solve for optimizing a piecewise function.
extern {
function calloc(n: i64, size: i64) -> ptr<void>
function free(p: ptr<void>) -> void
function memset(p: ptr<void>, c: i32, n: i64) -> ptr<void>
function memcpy(dst: ptr<void>, src: ptr<void>, n: i64) -> ptr<void>
function fabs(x: f64) -> f64
function pow(base: f64, exp: f64) -> f64
}
const MAXN: i32 = 128
# Global arrays for Newton solve
let mut g_g: ptr<f64> = null
let mut g_diag: ptr<f64> = null
let mut g_lower: ptr<f64> = null
let mut g_upper: ptr<f64> = null
let mut g_rhs: ptr<f64> = null
let mut g_delta: ptr<f64> = null
let mut g_trial: ptr<f64> = null
let mut g_terms: ptr<f64> = null
# Tridiagonal temp arrays
let mut g_c: ptr<f64> = null
let mut g_d: ptr<f64> = null
let mut g_b: ptr<f64> = null
function tridiag_solve(lower: ptr<f64>, diag: ptr<f64>, upper: ptr<f64>, rhs: ptr<f64>, x: ptr<f64>, n: i32) -> void {
memcpy(g_c as ptr<void>, upper as ptr<void>, ((n - 1) as i64) * 8)
memcpy(g_d as ptr<void>, diag as ptr<void>, (n as i64) * 8)
memcpy(g_b as ptr<void>, rhs as ptr<void>, (n as i64) * 8)
let mut i: i32 = 0
while i < n - 1 {
let w: f64 = lower[i] / g_d[i]
g_d[i + 1] = g_d[i + 1] - w * g_c[i]
g_b[i + 1] = g_b[i + 1] - w * g_b[i]
i = i + 1
}
x[n - 1] = g_b[n - 1] / g_d[n - 1]
let mut i2: i32 = n - 2
while i2 >= 0 {
x[i2] = (g_b[i2] - g_c[i2] * x[i2 + 1]) / g_d[i2]
i2 = i2 - 1
}
}
function max_residual(xs: ptr<f64>, n: i32) -> f64 {
let mut mx: f64 = 0.0
let mut k: i32 = 1
while k < n - 1 {
let a: f64 = xs[k - 1]
let x: f64 = xs[k]
let b: f64 = xs[k + 1]
let a4: f64 = a * a * a * a
let b4: f64 = b * b * b * b
let x3: f64 = x * x * x
let g: f64 = a4 - b4 + 4.0 * x3 * (b - a)
let ag: f64 = fabs(g)
if ag > mx { mx = ag }
k = k + 1
}
return mx
}
function newton_solve(xs: ptr<f64>, n: i32) -> void {
let m: i32 = n - 2
let mut iter: i32 = 0
while iter < 200 {
memset(g_g as ptr<void>, 0, (m as i64) * 8)
memset(g_diag as ptr<void>, 0, (m as i64) * 8)
memset(g_lower as ptr<void>, 0, ((m - 1) as i64) * 8)
memset(g_upper as ptr<void>, 0, ((m - 1) as i64) * 8)
let mut k: i32 = 1
while k < n - 1 {
let a: f64 = xs[k - 1]
let x: f64 = xs[k]
let b: f64 = xs[k + 1]
let idx: i32 = k - 1
let a4: f64 = a * a * a * a
let b4: f64 = b * b * b * b
let x3: f64 = x * x * x
let x2: f64 = x * x
let a3: f64 = a * a * a
let b3: f64 = b * b * b
g_g[idx] = a4 - b4 + 4.0 * x3 * (b - a)
g_diag[idx] = 12.0 * x2 * (b - a)
if idx - 1 >= 0 {
g_lower[idx - 1] = 4.0 * a3 - 4.0 * x3
}
if idx + 1 < m {
g_upper[idx] = 4.0 * x3 - 4.0 * b3
}
k = k + 1
}
let mut maxg: f64 = 0.0
let mut i: i32 = 0
while i < m {
if fabs(g_g[i]) > maxg { maxg = fabs(g_g[i]) }
i = i + 1
}
if maxg < 1e-15 { break }
let mut i2: i32 = 0
while i2 < m {
g_rhs[i2] = -g_g[i2]
i2 = i2 + 1
}
tridiag_solve(g_lower, g_diag, g_upper, g_rhs, g_delta, m)
let mut alpha: f64 = 1.0
let mut found: i32 = 0
while alpha > 1e-14 {
memcpy(g_trial as ptr<void>, xs as ptr<void>, (n as i64) * 8)
let mut i3: i32 = 0
while i3 < m {
g_trial[i3 + 1] = xs[i3 + 1] + alpha * g_delta[i3]
i3 = i3 + 1
}
let mut ok: i32 = 1
let mut i4: i32 = 0
while i4 < n - 1 {
if !(g_trial[i4] < g_trial[i4 + 1]) {
ok = 0
break
}
i4 = i4 + 1
}
if ok != 0 {
if g_trial[1] > -1.0 && g_trial[1] < 1.0 && g_trial[n - 2] > -1.0 && g_trial[n - 2] < 1.0 {
if max_residual(g_trial, n) < maxg {
memcpy(xs as ptr<void>, g_trial as ptr<void>, (n as i64) * 8)
found = 1
break
}
}
}
alpha = alpha * 0.5
}
if found == 0 {
let mut i5: i32 = 0
while i5 < m {
xs[i5 + 1] = xs[i5 + 1] + 1e-16 * g_delta[i5]
i5 = i5 + 1
}
}
iter = iter + 1
}
}
function kahan_sum(values: ptr<f64>, n: i32) -> f64 {
let mut s: f64 = 0.0
let mut c: f64 = 0.0
let mut i: i32 = 0
while i < n {
let y: f64 = values[i] - c
let t: f64 = s + y
c = (t - s) - y
s = t
i = i + 1
}
return s
}
# Heapsort for doubles (ascending)
function dsort_sift_down(arr: ptr<f64>, n: i32, i: i32) -> void {
let mut root: i32 = i
while true {
let left: i32 = 2 * root + 1
let right: i32 = 2 * root + 2
let mut largest: i32 = root
if left < n {
if arr[left] > arr[largest] { largest = left }
}
if right < n {
if arr[right] > arr[largest] { largest = right }
}
if largest == root { return }
let tmp: f64 = arr[root]
arr[root] = arr[largest]
arr[largest] = tmp
root = largest
}
}
function dsort(arr: ptr<f64>, n: i32) -> void {
let mut i: i32 = n / 2 - 1
while i >= 0 {
dsort_sift_down(arr, n, i)
i = i - 1
}
let mut j: i32 = n - 1
while j > 0 {
let tmp: f64 = arr[0]
arr[0] = arr[j]
arr[j] = tmp
dsort_sift_down(arr, j, 0)
j = j - 1
}
}
function compute_area(xs: ptr<f64>, n: i32) -> f64 {
let mut i: i32 = 0
while i < n - 1 {
let a: f64 = xs[i]
let b: f64 = xs[i + 1]
let a4: f64 = a * a * a * a
let b4: f64 = b * b * b * b
g_terms[i] = (b - a) * (a4 + b4) * 0.5
i = i + 1
}
let bottom: f64 = kahan_sum(g_terms, n - 1)
return 2.0 - bottom
}
function main() -> i32 {
# Allocate global arrays
g_g = calloc(MAXN as i64, 8)
g_diag = calloc(MAXN as i64, 8)
g_lower = calloc(MAXN as i64, 8)
g_upper = calloc(MAXN as i64, 8)
g_rhs = calloc(MAXN as i64, 8)
g_delta = calloc(MAXN as i64, 8)
g_trial = calloc(MAXN as i64, 8)
g_terms = calloc(MAXN as i64, 8)
g_c = calloc(MAXN as i64, 8)
g_d = calloc(MAXN as i64, 8)
g_b = calloc(MAXN as i64, 8)
let n: i32 = 101
let m: i32 = (n - 1) / 2
let mut best_area: f64 = -1e18
let xs: ptr<f64> = calloc(MAXN as i64, 8)
let mut extra_left: i32 = 0
while extra_left <= 1 {
let mut left_internal: i32 = m
let mut right_internal: i32 = m - 1
if extra_left == 0 {
let tmp: i32 = left_internal
left_internal = right_internal
right_internal = tmp
}
let mut cnt: i32 = 0
xs[cnt] = -1.0
cnt = cnt + 1
let mut j: i32 = 1
while j <= left_internal {
let z: f64 = 1.0 - (j as f64) / ((left_internal + 1) as f64)
xs[cnt] = -pow(z, 3.0 / 5.0)
cnt = cnt + 1
j = j + 1
}
let mut j2: i32 = 1
while j2 <= right_internal {
let z2: f64 = (j2 as f64) / ((right_internal + 1) as f64)
xs[cnt] = pow(z2, 3.0 / 5.0)
cnt = cnt + 1
j2 = j2 + 1
}
xs[cnt] = 1.0
cnt = cnt + 1
dsort(xs, cnt)
newton_solve(xs, n)
let area: f64 = compute_area(xs, n)
if area > best_area { best_area = area }
extra_left = extra_left + 1
}
printf("%.9f\n", best_area)
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 tridiag_solve_ptr_f64_ptr_f64_ptr_f64_ptr_f64_ptr_f64_i32(double* lower, double* diag, double* upper, double* rhs, double* x, int32_t n);
double max_residual_ptr_f64_i32(double* xs, int32_t n);
void newton_solve_ptr_f64_i32(double* xs, int32_t n);
double kahan_sum_ptr_f64_i32(double* values, int32_t n);
void dsort_sift_down_ptr_f64_i32_i32(double* arr, int32_t n, int32_t i);
void dsort_ptr_f64_i32(double* arr, int32_t n);
double compute_area_ptr_f64_i32(double* xs, int32_t n);
int32_t main(void);
static const int32_t MAXN = 128;
/* Module statics */
static double* g_g = NULL;
static double* g_diag = NULL;
static double* g_lower = NULL;
static double* g_upper = NULL;
static double* g_rhs = NULL;
static double* g_delta = NULL;
static double* g_trial = NULL;
static double* g_terms = NULL;
static double* g_c = NULL;
static double* g_d = NULL;
static double* g_b = NULL;
void tridiag_solve_ptr_f64_ptr_f64_ptr_f64_ptr_f64_ptr_f64_i32(double* lower, double* diag, double* upper, double* rhs, double* x, int32_t n) {
memcpy(((void*)(g_c)), ((void*)(upper)), (((int64_t)((n - 1))) * 8));
memcpy(((void*)(g_d)), ((void*)(diag)), (((int64_t)(n)) * 8));
memcpy(((void*)(g_b)), ((void*)(rhs)), (((int64_t)(n)) * 8));
int32_t i = 0;
while (i < (n - 1)) {
double w = (lower[i] / g_d[i]);
g_d[(i + 1)] = (g_d[(i + 1)] - (w * g_c[i]));
g_b[(i + 1)] = (g_b[(i + 1)] - (w * g_b[i]));
i = (i + 1);
}
x[(n - 1)] = (g_b[(n - 1)] / g_d[(n - 1)]);
int32_t i2 = (n - 2);
while (i2 >= 0) {
x[i2] = ((g_b[i2] - (g_c[i2] * x[(i2 + 1)])) / g_d[i2]);
i2 = (i2 - 1);
}
}
double max_residual_ptr_f64_i32(double* xs, int32_t n) {
double mx = 0.0;
int32_t k = 1;
while (k < (n - 1)) {
double a = xs[(k - 1)];
double x = xs[k];
double b = xs[(k + 1)];
double a4 = (((a * a) * a) * a);
double b4 = (((b * b) * b) * b);
double x3 = ((x * x) * x);
double g = ((a4 - b4) + ((4.0 * x3) * (b - a)));
double ag = fabs(g);
if (ag > mx) {
mx = ag;
}
k = (k + 1);
}
return mx;
}
void newton_solve_ptr_f64_i32(double* xs, int32_t n) {
int32_t m = (n - 2);
int32_t iter = 0;
while (iter < 200) {
memset(((void*)(g_g)), 0, (((int64_t)(m)) * 8));
memset(((void*)(g_diag)), 0, (((int64_t)(m)) * 8));
memset(((void*)(g_lower)), 0, (((int64_t)((m - 1))) * 8));
memset(((void*)(g_upper)), 0, (((int64_t)((m - 1))) * 8));
int32_t k = 1;
while (k < (n - 1)) {
double a = xs[(k - 1)];
double x = xs[k];
double b = xs[(k + 1)];
int32_t idx = (k - 1);
double a4 = (((a * a) * a) * a);
double b4 = (((b * b) * b) * b);
double x3 = ((x * x) * x);
double x2 = (x * x);
double a3 = ((a * a) * a);
double b3 = ((b * b) * b);
g_g[idx] = ((a4 - b4) + ((4.0 * x3) * (b - a)));
g_diag[idx] = ((12.0 * x2) * (b - a));
if ((idx - 1) >= 0) {
g_lower[(idx - 1)] = ((4.0 * a3) - (4.0 * x3));
}
if ((idx + 1) < m) {
g_upper[idx] = ((4.0 * x3) - (4.0 * b3));
}
k = (k + 1);
}
double maxg = 0.0;
int32_t i = 0;
while (i < m) {
if (fabs(g_g[i]) > maxg) {
maxg = fabs(g_g[i]);
}
i = (i + 1);
}
if (maxg < 1e-15) {
break;
}
int32_t i2 = 0;
while (i2 < m) {
g_rhs[i2] = (-g_g[i2]);
i2 = (i2 + 1);
}
tridiag_solve_ptr_f64_ptr_f64_ptr_f64_ptr_f64_ptr_f64_i32(g_lower, g_diag, g_upper, g_rhs, g_delta, m);
double alpha = 1.0;
int32_t found = 0;
while (alpha > 1e-14) {
memcpy(((void*)(g_trial)), ((void*)(xs)), (((int64_t)(n)) * 8));
int32_t i3 = 0;
while (i3 < m) {
g_trial[(i3 + 1)] = (xs[(i3 + 1)] + (alpha * g_delta[i3]));
i3 = (i3 + 1);
}
int32_t ok = 1;
int32_t i4 = 0;
while (i4 < (n - 1)) {
if ((!(g_trial[i4] < g_trial[(i4 + 1)]))) {
ok = 0;
break;
}
i4 = (i4 + 1);
}
if (ok != 0) {
if ((((g_trial[1] > (-1.0) && g_trial[1] < 1.0) && g_trial[(n - 2)] > (-1.0)) && g_trial[(n - 2)] < 1.0)) {
if (max_residual_ptr_f64_i32(g_trial, n) < maxg) {
memcpy(((void*)(xs)), ((void*)(g_trial)), (((int64_t)(n)) * 8));
found = 1;
break;
}
}
}
alpha = (alpha * 0.5);
}
if (found == 0) {
int32_t i5 = 0;
while (i5 < m) {
xs[(i5 + 1)] = (xs[(i5 + 1)] + (1e-16 * g_delta[i5]));
i5 = (i5 + 1);
}
}
iter = (iter + 1);
}
}
double kahan_sum_ptr_f64_i32(double* values, int32_t n) {
double s = 0.0;
double c = 0.0;
int32_t i = 0;
while (i < n) {
double y = (values[i] - c);
double t = (s + y);
c = ((t - s) - y);
s = t;
i = (i + 1);
}
return s;
}
void dsort_sift_down_ptr_f64_i32_i32(double* arr, int32_t n, int32_t i) {
int32_t root = i;
while (1) {
int32_t left = ((2 * root) + 1);
int32_t right = ((2 * root) + 2);
int32_t largest = root;
if (left < n) {
if (arr[left] > arr[largest]) {
largest = left;
}
}
if (right < n) {
if (arr[right] > arr[largest]) {
largest = right;
}
}
if (largest == root) {
return;
}
double tmp = arr[root];
arr[root] = arr[largest];
arr[largest] = tmp;
root = largest;
}
}
void dsort_ptr_f64_i32(double* arr, int32_t n) {
int32_t i = (FLOW_CHECKED_DIV((n), (2)) - 1);
while (i >= 0) {
dsort_sift_down_ptr_f64_i32_i32(arr, n, i);
i = (i - 1);
}
int32_t j = (n - 1);
while (j > 0) {
double tmp = arr[0];
arr[0] = arr[j];
arr[j] = tmp;
dsort_sift_down_ptr_f64_i32_i32(arr, j, 0);
j = (j - 1);
}
}
double compute_area_ptr_f64_i32(double* xs, int32_t n) {
int32_t i = 0;
while (i < (n - 1)) {
double a = xs[i];
double b = xs[(i + 1)];
double a4 = (((a * a) * a) * a);
double b4 = (((b * b) * b) * b);
g_terms[i] = (((b - a) * (a4 + b4)) * 0.5);
i = (i + 1);
}
double bottom = kahan_sum_ptr_f64_i32(g_terms, (n - 1));
return (2.0 - bottom);
}
int32_t main(void) {
g_g = calloc(((int64_t)(MAXN)), 8);
g_diag = calloc(((int64_t)(MAXN)), 8);
g_lower = calloc(((int64_t)(MAXN)), 8);
g_upper = calloc(((int64_t)(MAXN)), 8);
g_rhs = calloc(((int64_t)(MAXN)), 8);
g_delta = calloc(((int64_t)(MAXN)), 8);
g_trial = calloc(((int64_t)(MAXN)), 8);
g_terms = calloc(((int64_t)(MAXN)), 8);
g_c = calloc(((int64_t)(MAXN)), 8);
g_d = calloc(((int64_t)(MAXN)), 8);
g_b = calloc(((int64_t)(MAXN)), 8);
int32_t n = 101;
int32_t m = FLOW_CHECKED_DIV(((n - 1)), (2));
double best_area = (-1e18);
double* xs = (double*)(calloc(((int64_t)(MAXN)), 8));
int32_t extra_left = 0;
while (extra_left <= 1) {
int32_t left_internal = m;
int32_t right_internal = (m - 1);
if (extra_left == 0) {
int32_t tmp = left_internal;
left_internal = right_internal;
right_internal = tmp;
}
int32_t cnt = 0;
xs[cnt] = (-1.0);
cnt = (cnt + 1);
int32_t j = 1;
while (j <= left_internal) {
double z = (1.0 - (((double)(j)) / ((double)((left_internal + 1)))));
xs[cnt] = (-pow(z, (3.0 / 5.0)));
cnt = (cnt + 1);
j = (j + 1);
}
int32_t j2 = 1;
while (j2 <= right_internal) {
double z2 = (((double)(j2)) / ((double)((right_internal + 1))));
xs[cnt] = pow(z2, (3.0 / 5.0));
cnt = (cnt + 1);
j2 = (j2 + 1);
}
xs[cnt] = 1.0;
cnt = (cnt + 1);
dsort_ptr_f64_i32(xs, cnt);
newton_solve_ptr_f64_i32(xs, n);
double area = compute_area_ptr_f64_i32(xs, n);
if (area > best_area) {
best_area = area;
}
extra_left = (extra_left + 1);
}
printf("%.9f\n", best_area);
return 0;
}
Generated MLIR
module {
llvm.func @printf(!llvm.ptr, ...) -> i32
llvm.mlir.global internal constant @str_0("%.9f\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 @memset(!llvm.ptr, i32, i64) -> !llvm.ptr
func.func private @memcpy(!llvm.ptr, !llvm.ptr, i64) -> !llvm.ptr
func.func private @fabs(f64) -> f64
func.func private @pow(f64, f64) -> f64
// Constant: MAXN
llvm.mlir.global internal constant @MAXN(128 : i32) : i32
// Module static: g_g
llvm.mlir.global internal @g_g() {addr_space = 0 : i32} : !llvm.ptr {
%0 = llvm.mlir.zero : !llvm.ptr
llvm.return %0 : !llvm.ptr
}
// Module static: g_diag
llvm.mlir.global internal @g_diag() {addr_space = 0 : i32} : !llvm.ptr {
%1 = llvm.mlir.zero : !llvm.ptr
llvm.return %1 : !llvm.ptr
}
// Module static: g_lower
llvm.mlir.global internal @g_lower() {addr_space = 0 : i32} : !llvm.ptr {
%2 = llvm.mlir.zero : !llvm.ptr
llvm.return %2 : !llvm.ptr
}
// Module static: g_upper
llvm.mlir.global internal @g_upper() {addr_space = 0 : i32} : !llvm.ptr {
%3 = llvm.mlir.zero : !llvm.ptr
llvm.return %3 : !llvm.ptr
}
// Module static: g_rhs
llvm.mlir.global internal @g_rhs() {addr_space = 0 : i32} : !llvm.ptr {
%4 = llvm.mlir.zero : !llvm.ptr
llvm.return %4 : !llvm.ptr
}
// Module static: g_delta
llvm.mlir.global internal @g_delta() {addr_space = 0 : i32} : !llvm.ptr {
%5 = llvm.mlir.zero : !llvm.ptr
llvm.return %5 : !llvm.ptr
}
// Module static: g_trial
llvm.mlir.global internal @g_trial() {addr_space = 0 : i32} : !llvm.ptr {
%6 = llvm.mlir.zero : !llvm.ptr
llvm.return %6 : !llvm.ptr
}
// Module static: g_terms
llvm.mlir.global internal @g_terms() {addr_space = 0 : i32} : !llvm.ptr {
%7 = llvm.mlir.zero : !llvm.ptr
llvm.return %7 : !llvm.ptr
}
// Module static: g_c
llvm.mlir.global internal @g_c() {addr_space = 0 : i32} : !llvm.ptr {
%8 = llvm.mlir.zero : !llvm.ptr
llvm.return %8 : !llvm.ptr
}
// Module static: g_d
llvm.mlir.global internal @g_d() {addr_space = 0 : i32} : !llvm.ptr {
%9 = llvm.mlir.zero : !llvm.ptr
llvm.return %9 : !llvm.ptr
}
// Module static: g_b
llvm.mlir.global internal @g_b() {addr_space = 0 : i32} : !llvm.ptr {
%10 = llvm.mlir.zero : !llvm.ptr
llvm.return %10 : !llvm.ptr
}
func.func @tridiag_solve(%arg0: !llvm.ptr, %arg1: !llvm.ptr, %arg2: !llvm.ptr, %arg3: !llvm.ptr, %arg4: !llvm.ptr, %arg5: i32) -> () {
%12 = llvm.mlir.addressof @g_c : !llvm.ptr
%13 = llvm.load %12 : !llvm.ptr -> !llvm.ptr
%14 = arith.constant 1 : i32
%15 = arith.subi %arg5, %14 : i32
%16 = arith.extsi %15 : i32 to i64
%17 = arith.constant 8 : i32
%19 = arith.extsi %17 : i32 to i64
%18 = arith.muli %16, %19 : i64
%11 = func.call @memcpy(%13, %arg2, %18) : (!llvm.ptr, !llvm.ptr, i64) -> !llvm.ptr
%21 = llvm.mlir.addressof @g_d : !llvm.ptr
%22 = llvm.load %21 : !llvm.ptr -> !llvm.ptr
%23 = arith.extsi %arg5 : i32 to i64
%24 = arith.constant 8 : i32
%26 = arith.extsi %24 : i32 to i64
%25 = arith.muli %23, %26 : i64
%20 = func.call @memcpy(%22, %arg1, %25) : (!llvm.ptr, !llvm.ptr, i64) -> !llvm.ptr
%28 = llvm.mlir.addressof @g_b : !llvm.ptr
%29 = llvm.load %28 : !llvm.ptr -> !llvm.ptr
%30 = arith.extsi %arg5 : i32 to i64
%31 = arith.constant 8 : i32
%33 = arith.extsi %31 : i32 to i64
%32 = arith.muli %30, %33 : i64
%27 = func.call @memcpy(%29, %arg3, %32) : (!llvm.ptr, !llvm.ptr, i64) -> !llvm.ptr
%34 = arith.constant 0 : i32
%35 = llvm.mlir.constant(1 : i64) : i64
%36 = llvm.alloca %35 x i32 : (i64) -> !llvm.ptr
llvm.store %34, %36 : i32, !llvm.ptr
cf.br ^bb0
^bb0:
%37 = llvm.load %36 : !llvm.ptr -> i32
%38 = arith.constant 1 : i32
%39 = arith.subi %arg5, %38 : i32
%40 = arith.cmpi slt, %37, %39 : i32
cf.cond_br %40, ^bb1, ^bb2
^bb1:
%42 = llvm.load %36 : !llvm.ptr -> i32
%43 = arith.extsi %42 : i32 to i64
%44 = llvm.getelementptr %arg0[%43] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%41 = llvm.load %44 : !llvm.ptr -> f64
%46 = llvm.mlir.addressof @g_d : !llvm.ptr
%47 = llvm.load %46 : !llvm.ptr -> !llvm.ptr
%48 = llvm.load %36 : !llvm.ptr -> i32
%49 = arith.extsi %48 : i32 to i64
%50 = llvm.getelementptr %47[%49] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%45 = llvm.load %50 : !llvm.ptr -> f64
%51 = arith.divf %41, %45 : f64
%53 = llvm.mlir.addressof @g_d : !llvm.ptr
%54 = llvm.load %53 : !llvm.ptr -> !llvm.ptr
%55 = llvm.load %36 : !llvm.ptr -> i32
%56 = arith.constant 1 : i32
%57 = arith.addi %55, %56 : i32
%58 = arith.extsi %57 : i32 to i64
%59 = llvm.getelementptr %54[%58] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%52 = llvm.load %59 : !llvm.ptr -> f64
%61 = llvm.mlir.addressof @g_c : !llvm.ptr
%62 = llvm.load %61 : !llvm.ptr -> !llvm.ptr
%63 = llvm.load %36 : !llvm.ptr -> i32
%64 = arith.extsi %63 : i32 to i64
%65 = llvm.getelementptr %62[%64] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%60 = llvm.load %65 : !llvm.ptr -> f64
%66 = arith.mulf %51, %60 : f64
%67 = arith.subf %52, %66 : f64
%68 = llvm.mlir.addressof @g_d : !llvm.ptr
%69 = llvm.load %68 : !llvm.ptr -> !llvm.ptr
%70 = llvm.load %36 : !llvm.ptr -> i32
%71 = arith.constant 1 : i32
%72 = arith.addi %70, %71 : i32
%73 = arith.extsi %72 : i32 to i64
%74 = llvm.getelementptr %69[%73] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %67, %74 : f64, !llvm.ptr
%76 = llvm.mlir.addressof @g_b : !llvm.ptr
%77 = llvm.load %76 : !llvm.ptr -> !llvm.ptr
%78 = llvm.load %36 : !llvm.ptr -> i32
%79 = arith.constant 1 : i32
%80 = arith.addi %78, %79 : i32
%81 = arith.extsi %80 : i32 to i64
%82 = llvm.getelementptr %77[%81] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%75 = llvm.load %82 : !llvm.ptr -> f64
%84 = llvm.mlir.addressof @g_b : !llvm.ptr
%85 = llvm.load %84 : !llvm.ptr -> !llvm.ptr
%86 = llvm.load %36 : !llvm.ptr -> i32
%87 = arith.extsi %86 : i32 to i64
%88 = llvm.getelementptr %85[%87] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%83 = llvm.load %88 : !llvm.ptr -> f64
%89 = arith.mulf %51, %83 : f64
%90 = arith.subf %75, %89 : f64
%91 = llvm.mlir.addressof @g_b : !llvm.ptr
%92 = llvm.load %91 : !llvm.ptr -> !llvm.ptr
%93 = llvm.load %36 : !llvm.ptr -> i32
%94 = arith.constant 1 : i32
%95 = arith.addi %93, %94 : i32
%96 = arith.extsi %95 : i32 to i64
%97 = llvm.getelementptr %92[%96] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %90, %97 : f64, !llvm.ptr
%98 = llvm.load %36 : !llvm.ptr -> i32
%99 = arith.constant 1 : i32
%100 = arith.addi %98, %99 : i32
llvm.store %100, %36 : i32, !llvm.ptr
cf.br ^bb0
^bb2:
%102 = llvm.mlir.addressof @g_b : !llvm.ptr
%103 = llvm.load %102 : !llvm.ptr -> !llvm.ptr
%104 = arith.constant 1 : i32
%105 = arith.subi %arg5, %104 : i32
%106 = arith.extsi %105 : i32 to i64
%107 = llvm.getelementptr %103[%106] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%101 = llvm.load %107 : !llvm.ptr -> f64
%109 = llvm.mlir.addressof @g_d : !llvm.ptr
%110 = llvm.load %109 : !llvm.ptr -> !llvm.ptr
%111 = arith.constant 1 : i32
%112 = arith.subi %arg5, %111 : i32
%113 = arith.extsi %112 : i32 to i64
%114 = llvm.getelementptr %110[%113] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%108 = llvm.load %114 : !llvm.ptr -> f64
%115 = arith.divf %101, %108 : f64
%116 = arith.constant 1 : i32
%117 = arith.subi %arg5, %116 : i32
%118 = arith.extsi %117 : i32 to i64
%119 = llvm.getelementptr %arg4[%118] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %115, %119 : f64, !llvm.ptr
%120 = arith.constant 2 : i32
%121 = arith.subi %arg5, %120 : i32
%122 = llvm.mlir.constant(1 : i64) : i64
%123 = llvm.alloca %122 x i32 : (i64) -> !llvm.ptr
llvm.store %121, %123 : i32, !llvm.ptr
cf.br ^bb3
^bb3:
%124 = llvm.load %123 : !llvm.ptr -> i32
%125 = arith.constant 0 : i32
%126 = arith.cmpi sge, %124, %125 : i32
cf.cond_br %126, ^bb4, ^bb5
^bb4:
%128 = llvm.mlir.addressof @g_b : !llvm.ptr
%129 = llvm.load %128 : !llvm.ptr -> !llvm.ptr
%130 = llvm.load %123 : !llvm.ptr -> i32
%131 = arith.extsi %130 : i32 to i64
%132 = llvm.getelementptr %129[%131] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%127 = llvm.load %132 : !llvm.ptr -> f64
%134 = llvm.mlir.addressof @g_c : !llvm.ptr
%135 = llvm.load %134 : !llvm.ptr -> !llvm.ptr
%136 = llvm.load %123 : !llvm.ptr -> i32
%137 = arith.extsi %136 : i32 to i64
%138 = llvm.getelementptr %135[%137] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%133 = llvm.load %138 : !llvm.ptr -> f64
%140 = llvm.load %123 : !llvm.ptr -> i32
%141 = arith.constant 1 : i32
%142 = arith.addi %140, %141 : i32
%143 = arith.extsi %142 : i32 to i64
%144 = llvm.getelementptr %arg4[%143] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%139 = llvm.load %144 : !llvm.ptr -> f64
%145 = arith.mulf %133, %139 : f64
%146 = arith.subf %127, %145 : f64
%148 = llvm.mlir.addressof @g_d : !llvm.ptr
%149 = llvm.load %148 : !llvm.ptr -> !llvm.ptr
%150 = llvm.load %123 : !llvm.ptr -> i32
%151 = arith.extsi %150 : i32 to i64
%152 = llvm.getelementptr %149[%151] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%147 = llvm.load %152 : !llvm.ptr -> f64
%153 = arith.divf %146, %147 : f64
%154 = llvm.load %123 : !llvm.ptr -> i32
%155 = arith.extsi %154 : i32 to i64
%156 = llvm.getelementptr %arg4[%155] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %153, %156 : f64, !llvm.ptr
%157 = llvm.load %123 : !llvm.ptr -> i32
%158 = arith.constant 1 : i32
%159 = arith.subi %157, %158 : i32
llvm.store %159, %123 : i32, !llvm.ptr
cf.br ^bb3
^bb5:
func.return
}
func.func @max_residual(%arg0: !llvm.ptr, %arg1: i32) -> f64 {
%160 = arith.constant 0.0 : f32
%161 = arith.extf %160 : f32 to f64
%162 = llvm.mlir.constant(1 : i64) : i64
%163 = llvm.alloca %162 x f64 : (i64) -> !llvm.ptr
llvm.store %161, %163 : f64, !llvm.ptr
%164 = arith.constant 1 : i32
%165 = llvm.mlir.constant(1 : i64) : i64
%166 = llvm.alloca %165 x i32 : (i64) -> !llvm.ptr
llvm.store %164, %166 : i32, !llvm.ptr
cf.br ^bb6
^bb6:
%167 = llvm.load %166 : !llvm.ptr -> i32
%168 = arith.constant 1 : i32
%169 = arith.subi %arg1, %168 : i32
%170 = arith.cmpi slt, %167, %169 : i32
cf.cond_br %170, ^bb7, ^bb8
^bb7:
%172 = llvm.load %166 : !llvm.ptr -> i32
%173 = arith.constant 1 : i32
%174 = arith.subi %172, %173 : i32
%175 = arith.extsi %174 : i32 to i64
%176 = llvm.getelementptr %arg0[%175] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%171 = llvm.load %176 : !llvm.ptr -> f64
%178 = llvm.load %166 : !llvm.ptr -> i32
%179 = arith.extsi %178 : i32 to i64
%180 = llvm.getelementptr %arg0[%179] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%177 = llvm.load %180 : !llvm.ptr -> f64
%182 = llvm.load %166 : !llvm.ptr -> i32
%183 = arith.constant 1 : i32
%184 = arith.addi %182, %183 : i32
%185 = arith.extsi %184 : i32 to i64
%186 = llvm.getelementptr %arg0[%185] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%181 = llvm.load %186 : !llvm.ptr -> f64
%187 = arith.mulf %171, %171 : f64
%188 = arith.mulf %187, %171 : f64
%189 = arith.mulf %188, %171 : f64
%190 = arith.mulf %181, %181 : f64
%191 = arith.mulf %190, %181 : f64
%192 = arith.mulf %191, %181 : f64
%193 = arith.mulf %177, %177 : f64
%194 = arith.mulf %193, %177 : f64
%195 = arith.subf %189, %192 : f64
%196 = arith.constant 4.0 : f32
%198 = arith.extf %196 : f32 to f64
%197 = arith.mulf %198, %194 : f64
%199 = arith.subf %181, %171 : f64
%200 = arith.mulf %197, %199 : f64
%201 = arith.addf %195, %200 : f64
%202 = math.absf %201 : f64
%203 = llvm.load %163 : !llvm.ptr -> f64
%204 = arith.cmpf ogt, %202, %203 : f64
cf.cond_br %204, ^bb9, ^bb10
^bb9:
llvm.store %202, %163 : f64, !llvm.ptr
cf.br ^bb11
^bb10:
cf.br ^bb11
^bb11:
%205 = llvm.load %166 : !llvm.ptr -> i32
%206 = arith.constant 1 : i32
%207 = arith.addi %205, %206 : i32
llvm.store %207, %166 : i32, !llvm.ptr
cf.br ^bb6
^bb8:
%208 = llvm.load %163 : !llvm.ptr -> f64
func.return %208 : f64
}
func.func @newton_solve(%arg0: !llvm.ptr, %arg1: i32) -> () {
%209 = arith.constant 2 : i32
%210 = arith.subi %arg1, %209 : i32
%211 = arith.constant 0 : i32
%212 = llvm.mlir.constant(1 : i64) : i64
%213 = llvm.alloca %212 x i32 : (i64) -> !llvm.ptr
llvm.store %211, %213 : i32, !llvm.ptr
cf.br ^bb12
^bb12:
%214 = llvm.load %213 : !llvm.ptr -> i32
%215 = arith.constant 200 : i32
%216 = arith.cmpi slt, %214, %215 : i32
cf.cond_br %216, ^bb13, ^bb14
^bb13:
%218 = llvm.mlir.addressof @g_g : !llvm.ptr
%219 = llvm.load %218 : !llvm.ptr -> !llvm.ptr
%220 = arith.constant 0 : i32
%221 = arith.extsi %210 : i32 to i64
%222 = arith.constant 8 : i32
%224 = arith.extsi %222 : i32 to i64
%223 = arith.muli %221, %224 : i64
%217 = func.call @memset(%219, %220, %223) : (!llvm.ptr, i32, i64) -> !llvm.ptr
%226 = llvm.mlir.addressof @g_diag : !llvm.ptr
%227 = llvm.load %226 : !llvm.ptr -> !llvm.ptr
%228 = arith.constant 0 : i32
%229 = arith.extsi %210 : i32 to i64
%230 = arith.constant 8 : i32
%232 = arith.extsi %230 : i32 to i64
%231 = arith.muli %229, %232 : i64
%225 = func.call @memset(%227, %228, %231) : (!llvm.ptr, i32, i64) -> !llvm.ptr
%234 = llvm.mlir.addressof @g_lower : !llvm.ptr
%235 = llvm.load %234 : !llvm.ptr -> !llvm.ptr
%236 = arith.constant 0 : i32
%237 = arith.constant 1 : i32
%238 = arith.subi %210, %237 : i32
%239 = arith.extsi %238 : i32 to i64
%240 = arith.constant 8 : i32
%242 = arith.extsi %240 : i32 to i64
%241 = arith.muli %239, %242 : i64
%233 = func.call @memset(%235, %236, %241) : (!llvm.ptr, i32, i64) -> !llvm.ptr
%244 = llvm.mlir.addressof @g_upper : !llvm.ptr
%245 = llvm.load %244 : !llvm.ptr -> !llvm.ptr
%246 = arith.constant 0 : i32
%247 = arith.constant 1 : i32
%248 = arith.subi %210, %247 : i32
%249 = arith.extsi %248 : i32 to i64
%250 = arith.constant 8 : i32
%252 = arith.extsi %250 : i32 to i64
%251 = arith.muli %249, %252 : i64
%243 = func.call @memset(%245, %246, %251) : (!llvm.ptr, i32, i64) -> !llvm.ptr
%253 = arith.constant 1 : i32
%254 = llvm.mlir.constant(1 : i64) : i64
%255 = llvm.alloca %254 x i32 : (i64) -> !llvm.ptr
llvm.store %253, %255 : i32, !llvm.ptr
cf.br ^bb15
^bb15:
%256 = llvm.load %255 : !llvm.ptr -> i32
%257 = arith.constant 1 : i32
%258 = arith.subi %arg1, %257 : i32
%259 = arith.cmpi slt, %256, %258 : i32
cf.cond_br %259, ^bb16, ^bb17
^bb16:
%261 = llvm.load %255 : !llvm.ptr -> i32
%262 = arith.constant 1 : i32
%263 = arith.subi %261, %262 : i32
%264 = arith.extsi %263 : i32 to i64
%265 = llvm.getelementptr %arg0[%264] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%260 = llvm.load %265 : !llvm.ptr -> f64
%267 = llvm.load %255 : !llvm.ptr -> i32
%268 = arith.extsi %267 : i32 to i64
%269 = llvm.getelementptr %arg0[%268] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%266 = llvm.load %269 : !llvm.ptr -> f64
%271 = llvm.load %255 : !llvm.ptr -> i32
%272 = arith.constant 1 : i32
%273 = arith.addi %271, %272 : i32
%274 = arith.extsi %273 : i32 to i64
%275 = llvm.getelementptr %arg0[%274] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%270 = llvm.load %275 : !llvm.ptr -> f64
%276 = llvm.load %255 : !llvm.ptr -> i32
%277 = arith.constant 1 : i32
%278 = arith.subi %276, %277 : i32
%279 = arith.mulf %260, %260 : f64
%280 = arith.mulf %279, %260 : f64
%281 = arith.mulf %280, %260 : f64
%282 = arith.mulf %270, %270 : f64
%283 = arith.mulf %282, %270 : f64
%284 = arith.mulf %283, %270 : f64
%285 = arith.mulf %266, %266 : f64
%286 = arith.mulf %285, %266 : f64
%287 = arith.mulf %266, %266 : f64
%288 = arith.mulf %260, %260 : f64
%289 = arith.mulf %288, %260 : f64
%290 = arith.mulf %270, %270 : f64
%291 = arith.mulf %290, %270 : f64
%292 = arith.subf %281, %284 : f64
%293 = arith.constant 4.0 : f32
%295 = arith.extf %293 : f32 to f64
%294 = arith.mulf %295, %286 : f64
%296 = arith.subf %270, %260 : f64
%297 = arith.mulf %294, %296 : f64
%298 = arith.addf %292, %297 : f64
%299 = llvm.mlir.addressof @g_g : !llvm.ptr
%300 = llvm.load %299 : !llvm.ptr -> !llvm.ptr
%301 = arith.extsi %278 : i32 to i64
%302 = llvm.getelementptr %300[%301] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %298, %302 : f64, !llvm.ptr
%303 = arith.constant 12.0 : f32
%305 = arith.extf %303 : f32 to f64
%304 = arith.mulf %305, %287 : f64
%306 = arith.subf %270, %260 : f64
%307 = arith.mulf %304, %306 : f64
%308 = llvm.mlir.addressof @g_diag : !llvm.ptr
%309 = llvm.load %308 : !llvm.ptr -> !llvm.ptr
%310 = arith.extsi %278 : i32 to i64
%311 = llvm.getelementptr %309[%310] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %307, %311 : f64, !llvm.ptr
%312 = arith.constant 1 : i32
%313 = arith.subi %278, %312 : i32
%314 = arith.constant 0 : i32
%315 = arith.cmpi sge, %313, %314 : i32
cf.cond_br %315, ^bb18, ^bb19
^bb18:
%316 = arith.constant 4.0 : f32
%318 = arith.extf %316 : f32 to f64
%317 = arith.mulf %318, %289 : f64
%319 = arith.constant 4.0 : f32
%321 = arith.extf %319 : f32 to f64
%320 = arith.mulf %321, %286 : f64
%322 = arith.subf %317, %320 : f64
%323 = llvm.mlir.addressof @g_lower : !llvm.ptr
%324 = llvm.load %323 : !llvm.ptr -> !llvm.ptr
%325 = arith.constant 1 : i32
%326 = arith.subi %278, %325 : i32
%327 = arith.extsi %326 : i32 to i64
%328 = llvm.getelementptr %324[%327] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %322, %328 : f64, !llvm.ptr
cf.br ^bb20
^bb19:
cf.br ^bb20
^bb20:
%329 = arith.constant 1 : i32
%330 = arith.addi %278, %329 : i32
%331 = arith.cmpi slt, %330, %210 : i32
cf.cond_br %331, ^bb21, ^bb22
^bb21:
%332 = arith.constant 4.0 : f32
%334 = arith.extf %332 : f32 to f64
%333 = arith.mulf %334, %286 : f64
%335 = arith.constant 4.0 : f32
%337 = arith.extf %335 : f32 to f64
%336 = arith.mulf %337, %291 : f64
%338 = arith.subf %333, %336 : f64
%339 = llvm.mlir.addressof @g_upper : !llvm.ptr
%340 = llvm.load %339 : !llvm.ptr -> !llvm.ptr
%341 = arith.extsi %278 : i32 to i64
%342 = llvm.getelementptr %340[%341] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %338, %342 : f64, !llvm.ptr
cf.br ^bb23
^bb22:
cf.br ^bb23
^bb23:
%343 = llvm.load %255 : !llvm.ptr -> i32
%344 = arith.constant 1 : i32
%345 = arith.addi %343, %344 : i32
llvm.store %345, %255 : i32, !llvm.ptr
cf.br ^bb15
^bb17:
%346 = arith.constant 0.0 : f32
%347 = arith.extf %346 : f32 to f64
%348 = llvm.mlir.constant(1 : i64) : i64
%349 = llvm.alloca %348 x f64 : (i64) -> !llvm.ptr
llvm.store %347, %349 : f64, !llvm.ptr
%350 = arith.constant 0 : i32
%351 = llvm.mlir.constant(1 : i64) : i64
%352 = llvm.alloca %351 x i32 : (i64) -> !llvm.ptr
llvm.store %350, %352 : i32, !llvm.ptr
cf.br ^bb24
^bb24:
%353 = llvm.load %352 : !llvm.ptr -> i32
%354 = arith.cmpi slt, %353, %210 : i32
cf.cond_br %354, ^bb25, ^bb26
^bb25:
%356 = llvm.mlir.addressof @g_g : !llvm.ptr
%357 = llvm.load %356 : !llvm.ptr -> !llvm.ptr
%358 = llvm.load %352 : !llvm.ptr -> i32
%359 = arith.extsi %358 : i32 to i64
%360 = llvm.getelementptr %357[%359] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%355 = llvm.load %360 : !llvm.ptr -> f64
%361 = math.absf %355 : f64
%362 = llvm.load %349 : !llvm.ptr -> f64
%363 = arith.cmpf ogt, %361, %362 : f64
cf.cond_br %363, ^bb27, ^bb28
^bb27:
%365 = llvm.mlir.addressof @g_g : !llvm.ptr
%366 = llvm.load %365 : !llvm.ptr -> !llvm.ptr
%367 = llvm.load %352 : !llvm.ptr -> i32
%368 = arith.extsi %367 : i32 to i64
%369 = llvm.getelementptr %366[%368] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%364 = llvm.load %369 : !llvm.ptr -> f64
%370 = math.absf %364 : f64
llvm.store %370, %349 : f64, !llvm.ptr
cf.br ^bb29
^bb28:
cf.br ^bb29
^bb29:
%371 = llvm.load %352 : !llvm.ptr -> i32
%372 = arith.constant 1 : i32
%373 = arith.addi %371, %372 : i32
llvm.store %373, %352 : i32, !llvm.ptr
cf.br ^bb24
^bb26:
%374 = llvm.load %349 : !llvm.ptr -> f64
%375 = arith.constant 0 : f32
%377 = arith.extf %375 : f32 to f64
%376 = arith.cmpf olt, %374, %377 : f64
cf.cond_br %376, ^bb30, ^bb31
^bb30:
cf.br ^bb14
^bb31:
cf.br ^bb32
^bb32:
%378 = arith.constant 0 : i32
%379 = llvm.mlir.constant(1 : i64) : i64
%380 = llvm.alloca %379 x i32 : (i64) -> !llvm.ptr
llvm.store %378, %380 : i32, !llvm.ptr
cf.br ^bb33
^bb33:
%381 = llvm.load %380 : !llvm.ptr -> i32
%382 = arith.cmpi slt, %381, %210 : i32
cf.cond_br %382, ^bb34, ^bb35
^bb34:
%384 = llvm.mlir.addressof @g_g : !llvm.ptr
%385 = llvm.load %384 : !llvm.ptr -> !llvm.ptr
%386 = llvm.load %380 : !llvm.ptr -> i32
%387 = arith.extsi %386 : i32 to i64
%388 = llvm.getelementptr %385[%387] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%383 = llvm.load %388 : !llvm.ptr -> f64
%389 = arith.negf %383 : f64
%390 = llvm.mlir.addressof @g_rhs : !llvm.ptr
%391 = llvm.load %390 : !llvm.ptr -> !llvm.ptr
%392 = llvm.load %380 : !llvm.ptr -> i32
%393 = arith.extsi %392 : i32 to i64
%394 = llvm.getelementptr %391[%393] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %389, %394 : f64, !llvm.ptr
%395 = llvm.load %380 : !llvm.ptr -> i32
%396 = arith.constant 1 : i32
%397 = arith.addi %395, %396 : i32
llvm.store %397, %380 : i32, !llvm.ptr
cf.br ^bb33
^bb35:
%399 = llvm.mlir.addressof @g_lower : !llvm.ptr
%400 = llvm.load %399 : !llvm.ptr -> !llvm.ptr
%401 = llvm.mlir.addressof @g_diag : !llvm.ptr
%402 = llvm.load %401 : !llvm.ptr -> !llvm.ptr
%403 = llvm.mlir.addressof @g_upper : !llvm.ptr
%404 = llvm.load %403 : !llvm.ptr -> !llvm.ptr
%405 = llvm.mlir.addressof @g_rhs : !llvm.ptr
%406 = llvm.load %405 : !llvm.ptr -> !llvm.ptr
%407 = llvm.mlir.addressof @g_delta : !llvm.ptr
%408 = llvm.load %407 : !llvm.ptr -> !llvm.ptr
func.call @tridiag_solve(%400, %402, %404, %406, %408, %210) : (!llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, i32) -> ()
%409 = arith.constant 1.0 : f32
%410 = arith.extf %409 : f32 to f64
%411 = llvm.mlir.constant(1 : i64) : i64
%412 = llvm.alloca %411 x f64 : (i64) -> !llvm.ptr
llvm.store %410, %412 : f64, !llvm.ptr
%413 = arith.constant 0 : i32
%414 = llvm.mlir.constant(1 : i64) : i64
%415 = llvm.alloca %414 x i32 : (i64) -> !llvm.ptr
llvm.store %413, %415 : i32, !llvm.ptr
cf.br ^bb36
^bb36:
%416 = llvm.load %412 : !llvm.ptr -> f64
%417 = arith.constant 0 : f32
%419 = arith.extf %417 : f32 to f64
%418 = arith.cmpf ogt, %416, %419 : f64
cf.cond_br %418, ^bb37, ^bb38
^bb37:
%421 = llvm.mlir.addressof @g_trial : !llvm.ptr
%422 = llvm.load %421 : !llvm.ptr -> !llvm.ptr
%423 = arith.extsi %arg1 : i32 to i64
%424 = arith.constant 8 : i32
%426 = arith.extsi %424 : i32 to i64
%425 = arith.muli %423, %426 : i64
%420 = func.call @memcpy(%422, %arg0, %425) : (!llvm.ptr, !llvm.ptr, i64) -> !llvm.ptr
%427 = arith.constant 0 : i32
%428 = llvm.mlir.constant(1 : i64) : i64
%429 = llvm.alloca %428 x i32 : (i64) -> !llvm.ptr
llvm.store %427, %429 : i32, !llvm.ptr
cf.br ^bb39
^bb39:
%430 = llvm.load %429 : !llvm.ptr -> i32
%431 = arith.cmpi slt, %430, %210 : i32
cf.cond_br %431, ^bb40, ^bb41
^bb40:
%433 = llvm.load %429 : !llvm.ptr -> i32
%434 = arith.constant 1 : i32
%435 = arith.addi %433, %434 : i32
%436 = arith.extsi %435 : i32 to i64
%437 = llvm.getelementptr %arg0[%436] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%432 = llvm.load %437 : !llvm.ptr -> f64
%438 = llvm.load %412 : !llvm.ptr -> f64
%440 = llvm.mlir.addressof @g_delta : !llvm.ptr
%441 = llvm.load %440 : !llvm.ptr -> !llvm.ptr
%442 = llvm.load %429 : !llvm.ptr -> i32
%443 = arith.extsi %442 : i32 to i64
%444 = llvm.getelementptr %441[%443] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%439 = llvm.load %444 : !llvm.ptr -> f64
%445 = arith.mulf %438, %439 : f64
%446 = arith.addf %432, %445 : f64
%447 = llvm.mlir.addressof @g_trial : !llvm.ptr
%448 = llvm.load %447 : !llvm.ptr -> !llvm.ptr
%449 = llvm.load %429 : !llvm.ptr -> i32
%450 = arith.constant 1 : i32
%451 = arith.addi %449, %450 : i32
%452 = arith.extsi %451 : i32 to i64
%453 = llvm.getelementptr %448[%452] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %446, %453 : f64, !llvm.ptr
%454 = llvm.load %429 : !llvm.ptr -> i32
%455 = arith.constant 1 : i32
%456 = arith.addi %454, %455 : i32
llvm.store %456, %429 : i32, !llvm.ptr
cf.br ^bb39
^bb41:
%457 = arith.constant 1 : i32
%458 = llvm.mlir.constant(1 : i64) : i64
%459 = llvm.alloca %458 x i32 : (i64) -> !llvm.ptr
llvm.store %457, %459 : i32, !llvm.ptr
%460 = arith.constant 0 : i32
%461 = llvm.mlir.constant(1 : i64) : i64
%462 = llvm.alloca %461 x i32 : (i64) -> !llvm.ptr
llvm.store %460, %462 : i32, !llvm.ptr
cf.br ^bb42
^bb42:
%463 = llvm.load %462 : !llvm.ptr -> i32
%464 = arith.constant 1 : i32
%465 = arith.subi %arg1, %464 : i32
%466 = arith.cmpi slt, %463, %465 : i32
cf.cond_br %466, ^bb43, ^bb44
^bb43:
%468 = llvm.mlir.addressof @g_trial : !llvm.ptr
%469 = llvm.load %468 : !llvm.ptr -> !llvm.ptr
%470 = llvm.load %462 : !llvm.ptr -> i32
%471 = arith.extsi %470 : i32 to i64
%472 = llvm.getelementptr %469[%471] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%467 = llvm.load %472 : !llvm.ptr -> f64
%474 = llvm.mlir.addressof @g_trial : !llvm.ptr
%475 = llvm.load %474 : !llvm.ptr -> !llvm.ptr
%476 = llvm.load %462 : !llvm.ptr -> i32
%477 = arith.constant 1 : i32
%478 = arith.addi %476, %477 : i32
%479 = arith.extsi %478 : i32 to i64
%480 = llvm.getelementptr %475[%479] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%473 = llvm.load %480 : !llvm.ptr -> f64
%481 = arith.cmpf olt, %467, %473 : f64
%483 = arith.constant 1 : i1
%482 = arith.xori %481, %483 : i1
cf.cond_br %482, ^bb45, ^bb46
^bb45:
%485 = arith.constant 0 : i32
llvm.store %485, %459 : i32, !llvm.ptr
cf.br ^bb44
^bb46:
cf.br ^bb47
^bb47:
%486 = llvm.load %462 : !llvm.ptr -> i32
%487 = arith.constant 1 : i32
%488 = arith.addi %486, %487 : i32
llvm.store %488, %462 : i32, !llvm.ptr
cf.br ^bb42
^bb44:
%489 = llvm.load %459 : !llvm.ptr -> i32
%490 = arith.constant 0 : i32
%491 = arith.cmpi ne, %489, %490 : i32
cf.cond_br %491, ^bb48, ^bb49
^bb48:
%493 = llvm.mlir.addressof @g_trial : !llvm.ptr
%494 = llvm.load %493 : !llvm.ptr -> !llvm.ptr
%495 = arith.constant 1 : i32
%496 = arith.extsi %495 : i32 to i64
%497 = llvm.getelementptr %494[%496] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%492 = llvm.load %497 : !llvm.ptr -> f64
%498 = arith.constant 1.0 : f32
%499 = arith.negf %498 : f32
%501 = arith.extf %499 : f32 to f64
%500 = arith.cmpf ogt, %492, %501 : f64
%502 = scf.if %500 -> (i1) {
%504 = llvm.mlir.addressof @g_trial : !llvm.ptr
%505 = llvm.load %504 : !llvm.ptr -> !llvm.ptr
%506 = arith.constant 1 : i32
%507 = arith.extsi %506 : i32 to i64
%508 = llvm.getelementptr %505[%507] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%503 = llvm.load %508 : !llvm.ptr -> f64
%509 = arith.constant 1.0 : f32
%511 = arith.extf %509 : f32 to f64
%510 = arith.cmpf olt, %503, %511 : f64
scf.yield %510 : i1
} else {
%512 = arith.constant false
scf.yield %512 : i1
}
%513 = scf.if %502 -> (i1) {
%515 = llvm.mlir.addressof @g_trial : !llvm.ptr
%516 = llvm.load %515 : !llvm.ptr -> !llvm.ptr
%517 = arith.constant 2 : i32
%518 = arith.subi %arg1, %517 : i32
%519 = arith.extsi %518 : i32 to i64
%520 = llvm.getelementptr %516[%519] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%514 = llvm.load %520 : !llvm.ptr -> f64
%521 = arith.constant 1.0 : f32
%522 = arith.negf %521 : f32
%524 = arith.extf %522 : f32 to f64
%523 = arith.cmpf ogt, %514, %524 : f64
scf.yield %523 : i1
} else {
%525 = arith.constant false
scf.yield %525 : i1
}
%526 = scf.if %513 -> (i1) {
%528 = llvm.mlir.addressof @g_trial : !llvm.ptr
%529 = llvm.load %528 : !llvm.ptr -> !llvm.ptr
%530 = arith.constant 2 : i32
%531 = arith.subi %arg1, %530 : i32
%532 = arith.extsi %531 : i32 to i64
%533 = llvm.getelementptr %529[%532] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%527 = llvm.load %533 : !llvm.ptr -> f64
%534 = arith.constant 1.0 : f32
%536 = arith.extf %534 : f32 to f64
%535 = arith.cmpf olt, %527, %536 : f64
scf.yield %535 : i1
} else {
%537 = arith.constant false
scf.yield %537 : i1
}
cf.cond_br %526, ^bb51, ^bb52
^bb51:
%539 = llvm.mlir.addressof @g_trial : !llvm.ptr
%540 = llvm.load %539 : !llvm.ptr -> !llvm.ptr
%538 = func.call @max_residual(%540, %arg1) : (!llvm.ptr, i32) -> f64
%541 = llvm.load %349 : !llvm.ptr -> f64
%542 = arith.cmpf olt, %538, %541 : f64
cf.cond_br %542, ^bb54, ^bb55
^bb54:
%544 = llvm.mlir.addressof @g_trial : !llvm.ptr
%545 = llvm.load %544 : !llvm.ptr -> !llvm.ptr
%546 = arith.extsi %arg1 : i32 to i64
%547 = arith.constant 8 : i32
%549 = arith.extsi %547 : i32 to i64
%548 = arith.muli %546, %549 : i64
%543 = func.call @memcpy(%arg0, %545, %548) : (!llvm.ptr, !llvm.ptr, i64) -> !llvm.ptr
%550 = arith.constant 1 : i32
llvm.store %550, %415 : i32, !llvm.ptr
cf.br ^bb38
^bb55:
cf.br ^bb56
^bb56:
cf.br ^bb53
^bb52:
cf.br ^bb53
^bb53:
cf.br ^bb50
^bb49:
cf.br ^bb50
^bb50:
%551 = llvm.load %412 : !llvm.ptr -> f64
%552 = arith.constant 0.5 : f32
%554 = arith.extf %552 : f32 to f64
%553 = arith.mulf %551, %554 : f64
llvm.store %553, %412 : f64, !llvm.ptr
cf.br ^bb36
^bb38:
%555 = llvm.load %415 : !llvm.ptr -> i32
%556 = arith.constant 0 : i32
%557 = arith.cmpi eq, %555, %556 : i32
cf.cond_br %557, ^bb57, ^bb58
^bb57:
%558 = arith.constant 0 : i32
%559 = llvm.mlir.constant(1 : i64) : i64
%560 = llvm.alloca %559 x i32 : (i64) -> !llvm.ptr
llvm.store %558, %560 : i32, !llvm.ptr
cf.br ^bb60
^bb60:
%561 = llvm.load %560 : !llvm.ptr -> i32
%562 = arith.cmpi slt, %561, %210 : i32
cf.cond_br %562, ^bb61, ^bb62
^bb61:
%564 = llvm.load %560 : !llvm.ptr -> i32
%565 = arith.constant 1 : i32
%566 = arith.addi %564, %565 : i32
%567 = arith.extsi %566 : i32 to i64
%568 = llvm.getelementptr %arg0[%567] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%563 = llvm.load %568 : !llvm.ptr -> f64
%569 = arith.constant 0 : f32
%571 = llvm.mlir.addressof @g_delta : !llvm.ptr
%572 = llvm.load %571 : !llvm.ptr -> !llvm.ptr
%573 = llvm.load %560 : !llvm.ptr -> i32
%574 = arith.extsi %573 : i32 to i64
%575 = llvm.getelementptr %572[%574] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%570 = llvm.load %575 : !llvm.ptr -> f64
%577 = arith.extf %569 : f32 to f64
%576 = arith.mulf %577, %570 : f64
%578 = arith.addf %563, %576 : f64
%579 = llvm.load %560 : !llvm.ptr -> i32
%580 = arith.constant 1 : i32
%581 = arith.addi %579, %580 : i32
%582 = arith.extsi %581 : i32 to i64
%583 = llvm.getelementptr %arg0[%582] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %578, %583 : f64, !llvm.ptr
%584 = llvm.load %560 : !llvm.ptr -> i32
%585 = arith.constant 1 : i32
%586 = arith.addi %584, %585 : i32
llvm.store %586, %560 : i32, !llvm.ptr
cf.br ^bb60
^bb62:
cf.br ^bb59
^bb58:
cf.br ^bb59
^bb59:
%587 = llvm.load %213 : !llvm.ptr -> i32
%588 = arith.constant 1 : i32
%589 = arith.addi %587, %588 : i32
llvm.store %589, %213 : i32, !llvm.ptr
cf.br ^bb12
^bb14:
func.return
}
func.func @kahan_sum(%arg0: !llvm.ptr, %arg1: i32) -> f64 {
%590 = arith.constant 0.0 : f32
%591 = arith.extf %590 : f32 to f64
%592 = llvm.mlir.constant(1 : i64) : i64
%593 = llvm.alloca %592 x f64 : (i64) -> !llvm.ptr
llvm.store %591, %593 : f64, !llvm.ptr
%594 = arith.constant 0.0 : f32
%595 = arith.extf %594 : f32 to f64
%596 = llvm.mlir.constant(1 : i64) : i64
%597 = llvm.alloca %596 x f64 : (i64) -> !llvm.ptr
llvm.store %595, %597 : f64, !llvm.ptr
%598 = arith.constant 0 : i32
%599 = llvm.mlir.constant(1 : i64) : i64
%600 = llvm.alloca %599 x i32 : (i64) -> !llvm.ptr
llvm.store %598, %600 : i32, !llvm.ptr
cf.br ^bb63
^bb63:
%601 = llvm.load %600 : !llvm.ptr -> i32
%602 = arith.cmpi slt, %601, %arg1 : i32
cf.cond_br %602, ^bb64, ^bb65
^bb64:
%604 = llvm.load %600 : !llvm.ptr -> i32
%605 = arith.extsi %604 : i32 to i64
%606 = llvm.getelementptr %arg0[%605] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%603 = llvm.load %606 : !llvm.ptr -> f64
%607 = llvm.load %597 : !llvm.ptr -> f64
%608 = arith.subf %603, %607 : f64
%609 = llvm.load %593 : !llvm.ptr -> f64
%610 = arith.addf %609, %608 : f64
%611 = llvm.load %593 : !llvm.ptr -> f64
%612 = arith.subf %610, %611 : f64
%613 = arith.subf %612, %608 : f64
llvm.store %613, %597 : f64, !llvm.ptr
llvm.store %610, %593 : f64, !llvm.ptr
%614 = llvm.load %600 : !llvm.ptr -> i32
%615 = arith.constant 1 : i32
%616 = arith.addi %614, %615 : i32
llvm.store %616, %600 : i32, !llvm.ptr
cf.br ^bb63
^bb65:
%617 = llvm.load %593 : !llvm.ptr -> f64
func.return %617 : f64
}
func.func @dsort_sift_down(%arg0: !llvm.ptr, %arg1: i32, %arg2: i32) -> () {
%618 = llvm.mlir.constant(1 : i64) : i64
%619 = llvm.alloca %618 x i32 : (i64) -> !llvm.ptr
llvm.store %arg2, %619 : i32, !llvm.ptr
cf.br ^bb66
^bb66:
%620 = arith.constant 1 : i1
cf.cond_br %620, ^bb67, ^bb68
^bb67:
%621 = arith.constant 2 : i32
%622 = llvm.load %619 : !llvm.ptr -> i32
%623 = arith.muli %621, %622 : i32
%624 = arith.constant 1 : i32
%625 = arith.addi %623, %624 : i32
%626 = arith.constant 2 : i32
%627 = llvm.load %619 : !llvm.ptr -> i32
%628 = arith.muli %626, %627 : i32
%629 = arith.constant 2 : i32
%630 = arith.addi %628, %629 : i32
%631 = llvm.load %619 : !llvm.ptr -> i32
%632 = llvm.mlir.constant(1 : i64) : i64
%633 = llvm.alloca %632 x i32 : (i64) -> !llvm.ptr
llvm.store %631, %633 : i32, !llvm.ptr
%634 = arith.cmpi slt, %625, %arg1 : i32
cf.cond_br %634, ^bb69, ^bb70
^bb69:
%636 = arith.extsi %625 : i32 to i64
%637 = llvm.getelementptr %arg0[%636] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%635 = llvm.load %637 : !llvm.ptr -> f64
%639 = llvm.load %633 : !llvm.ptr -> i32
%640 = arith.extsi %639 : i32 to i64
%641 = llvm.getelementptr %arg0[%640] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%638 = llvm.load %641 : !llvm.ptr -> f64
%642 = arith.cmpf ogt, %635, %638 : f64
cf.cond_br %642, ^bb72, ^bb73
^bb72:
llvm.store %625, %633 : i32, !llvm.ptr
cf.br ^bb74
^bb73:
cf.br ^bb74
^bb74:
cf.br ^bb71
^bb70:
cf.br ^bb71
^bb71:
%643 = arith.cmpi slt, %630, %arg1 : i32
cf.cond_br %643, ^bb75, ^bb76
^bb75:
%645 = arith.extsi %630 : i32 to i64
%646 = llvm.getelementptr %arg0[%645] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%644 = llvm.load %646 : !llvm.ptr -> f64
%648 = llvm.load %633 : !llvm.ptr -> i32
%649 = arith.extsi %648 : i32 to i64
%650 = llvm.getelementptr %arg0[%649] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%647 = llvm.load %650 : !llvm.ptr -> f64
%651 = arith.cmpf ogt, %644, %647 : f64
cf.cond_br %651, ^bb78, ^bb79
^bb78:
llvm.store %630, %633 : i32, !llvm.ptr
cf.br ^bb80
^bb79:
cf.br ^bb80
^bb80:
cf.br ^bb77
^bb76:
cf.br ^bb77
^bb77:
%652 = llvm.load %633 : !llvm.ptr -> i32
%653 = llvm.load %619 : !llvm.ptr -> i32
%654 = arith.cmpi eq, %652, %653 : i32
cf.cond_br %654, ^bb81, ^bb82
^bb81:
func.return
^bb82:
cf.br ^bb83
^bb83:
%656 = llvm.load %619 : !llvm.ptr -> i32
%657 = arith.extsi %656 : i32 to i64
%658 = llvm.getelementptr %arg0[%657] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%655 = llvm.load %658 : !llvm.ptr -> f64
%660 = llvm.load %633 : !llvm.ptr -> i32
%661 = arith.extsi %660 : i32 to i64
%662 = llvm.getelementptr %arg0[%661] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%659 = llvm.load %662 : !llvm.ptr -> f64
%663 = llvm.load %619 : !llvm.ptr -> i32
%664 = arith.extsi %663 : i32 to i64
%665 = llvm.getelementptr %arg0[%664] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %659, %665 : f64, !llvm.ptr
%666 = llvm.load %633 : !llvm.ptr -> i32
%667 = arith.extsi %666 : i32 to i64
%668 = llvm.getelementptr %arg0[%667] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %655, %668 : f64, !llvm.ptr
%669 = llvm.load %633 : !llvm.ptr -> i32
llvm.store %669, %619 : i32, !llvm.ptr
cf.br ^bb66
^bb68:
func.return
}
func.func @dsort(%arg0: !llvm.ptr, %arg1: i32) -> () {
%670 = arith.constant 2 : i32
%671 = arith.divsi %arg1, %670 : i32
%672 = arith.constant 1 : i32
%673 = arith.subi %671, %672 : i32
%674 = llvm.mlir.constant(1 : i64) : i64
%675 = llvm.alloca %674 x i32 : (i64) -> !llvm.ptr
llvm.store %673, %675 : i32, !llvm.ptr
cf.br ^bb84
^bb84:
%676 = llvm.load %675 : !llvm.ptr -> i32
%677 = arith.constant 0 : i32
%678 = arith.cmpi sge, %676, %677 : i32
cf.cond_br %678, ^bb85, ^bb86
^bb85:
%680 = llvm.load %675 : !llvm.ptr -> i32
func.call @dsort_sift_down(%arg0, %arg1, %680) : (!llvm.ptr, i32, i32) -> ()
%681 = llvm.load %675 : !llvm.ptr -> i32
%682 = arith.constant 1 : i32
%683 = arith.subi %681, %682 : i32
llvm.store %683, %675 : i32, !llvm.ptr
cf.br ^bb84
^bb86:
%684 = arith.constant 1 : i32
%685 = arith.subi %arg1, %684 : i32
%686 = llvm.mlir.constant(1 : i64) : i64
%687 = llvm.alloca %686 x i32 : (i64) -> !llvm.ptr
llvm.store %685, %687 : i32, !llvm.ptr
cf.br ^bb87
^bb87:
%688 = llvm.load %687 : !llvm.ptr -> i32
%689 = arith.constant 0 : i32
%690 = arith.cmpi sgt, %688, %689 : i32
cf.cond_br %690, ^bb88, ^bb89
^bb88:
%692 = arith.constant 0 : i32
%693 = arith.extsi %692 : i32 to i64
%694 = llvm.getelementptr %arg0[%693] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%691 = llvm.load %694 : !llvm.ptr -> f64
%696 = llvm.load %687 : !llvm.ptr -> i32
%697 = arith.extsi %696 : i32 to i64
%698 = llvm.getelementptr %arg0[%697] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%695 = llvm.load %698 : !llvm.ptr -> f64
%699 = arith.constant 0 : i32
%700 = arith.extsi %699 : i32 to i64
%701 = llvm.getelementptr %arg0[%700] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %695, %701 : f64, !llvm.ptr
%702 = llvm.load %687 : !llvm.ptr -> i32
%703 = arith.extsi %702 : i32 to i64
%704 = llvm.getelementptr %arg0[%703] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %691, %704 : f64, !llvm.ptr
%706 = llvm.load %687 : !llvm.ptr -> i32
%707 = arith.constant 0 : i32
func.call @dsort_sift_down(%arg0, %706, %707) : (!llvm.ptr, i32, i32) -> ()
%708 = llvm.load %687 : !llvm.ptr -> i32
%709 = arith.constant 1 : i32
%710 = arith.subi %708, %709 : i32
llvm.store %710, %687 : i32, !llvm.ptr
cf.br ^bb87
^bb89:
func.return
}
func.func @compute_area(%arg0: !llvm.ptr, %arg1: i32) -> f64 {
%711 = arith.constant 0 : i32
%712 = llvm.mlir.constant(1 : i64) : i64
%713 = llvm.alloca %712 x i32 : (i64) -> !llvm.ptr
llvm.store %711, %713 : i32, !llvm.ptr
cf.br ^bb90
^bb90:
%714 = llvm.load %713 : !llvm.ptr -> i32
%715 = arith.constant 1 : i32
%716 = arith.subi %arg1, %715 : i32
%717 = arith.cmpi slt, %714, %716 : i32
cf.cond_br %717, ^bb91, ^bb92
^bb91:
%719 = llvm.load %713 : !llvm.ptr -> i32
%720 = arith.extsi %719 : i32 to i64
%721 = llvm.getelementptr %arg0[%720] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%718 = llvm.load %721 : !llvm.ptr -> f64
%723 = llvm.load %713 : !llvm.ptr -> i32
%724 = arith.constant 1 : i32
%725 = arith.addi %723, %724 : i32
%726 = arith.extsi %725 : i32 to i64
%727 = llvm.getelementptr %arg0[%726] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%722 = llvm.load %727 : !llvm.ptr -> f64
%728 = arith.mulf %718, %718 : f64
%729 = arith.mulf %728, %718 : f64
%730 = arith.mulf %729, %718 : f64
%731 = arith.mulf %722, %722 : f64
%732 = arith.mulf %731, %722 : f64
%733 = arith.mulf %732, %722 : f64
%734 = arith.subf %722, %718 : f64
%735 = arith.addf %730, %733 : f64
%736 = arith.mulf %734, %735 : f64
%737 = arith.constant 0.5 : f32
%739 = arith.extf %737 : f32 to f64
%738 = arith.mulf %736, %739 : f64
%740 = llvm.mlir.addressof @g_terms : !llvm.ptr
%741 = llvm.load %740 : !llvm.ptr -> !llvm.ptr
%742 = llvm.load %713 : !llvm.ptr -> i32
%743 = arith.extsi %742 : i32 to i64
%744 = llvm.getelementptr %741[%743] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %738, %744 : f64, !llvm.ptr
%745 = llvm.load %713 : !llvm.ptr -> i32
%746 = arith.constant 1 : i32
%747 = arith.addi %745, %746 : i32
llvm.store %747, %713 : i32, !llvm.ptr
cf.br ^bb90
^bb92:
%749 = llvm.mlir.addressof @g_terms : !llvm.ptr
%750 = llvm.load %749 : !llvm.ptr -> !llvm.ptr
%751 = arith.constant 1 : i32
%752 = arith.subi %arg1, %751 : i32
%748 = func.call @kahan_sum(%750, %752) : (!llvm.ptr, i32) -> f64
%753 = arith.constant 2.0 : f32
%755 = arith.extf %753 : f32 to f64
%754 = arith.subf %755, %748 : f64
func.return %754 : f64
}
func.func @main() -> i32 {
%757 = llvm.mlir.addressof @MAXN : !llvm.ptr
%758 = llvm.load %757 : !llvm.ptr -> i32
%759 = arith.extsi %758 : i32 to i64
%760 = arith.constant 8 : i32
%761 = arith.extsi %760 : i32 to i64
%756 = func.call @calloc(%759, %761) : (i64, i64) -> !llvm.ptr
%762 = llvm.mlir.addressof @g_g : !llvm.ptr
llvm.store %756, %762 : !llvm.ptr, !llvm.ptr
%764 = llvm.mlir.addressof @MAXN : !llvm.ptr
%765 = llvm.load %764 : !llvm.ptr -> i32
%766 = arith.extsi %765 : i32 to i64
%767 = arith.constant 8 : i32
%768 = arith.extsi %767 : i32 to i64
%763 = func.call @calloc(%766, %768) : (i64, i64) -> !llvm.ptr
%769 = llvm.mlir.addressof @g_diag : !llvm.ptr
llvm.store %763, %769 : !llvm.ptr, !llvm.ptr
%771 = llvm.mlir.addressof @MAXN : !llvm.ptr
%772 = llvm.load %771 : !llvm.ptr -> i32
%773 = arith.extsi %772 : i32 to i64
%774 = arith.constant 8 : i32
%775 = arith.extsi %774 : i32 to i64
%770 = func.call @calloc(%773, %775) : (i64, i64) -> !llvm.ptr
%776 = llvm.mlir.addressof @g_lower : !llvm.ptr
llvm.store %770, %776 : !llvm.ptr, !llvm.ptr
%778 = llvm.mlir.addressof @MAXN : !llvm.ptr
%779 = llvm.load %778 : !llvm.ptr -> i32
%780 = arith.extsi %779 : i32 to i64
%781 = arith.constant 8 : i32
%782 = arith.extsi %781 : i32 to i64
%777 = func.call @calloc(%780, %782) : (i64, i64) -> !llvm.ptr
%783 = llvm.mlir.addressof @g_upper : !llvm.ptr
llvm.store %777, %783 : !llvm.ptr, !llvm.ptr
%785 = llvm.mlir.addressof @MAXN : !llvm.ptr
%786 = llvm.load %785 : !llvm.ptr -> i32
%787 = arith.extsi %786 : i32 to i64
%788 = arith.constant 8 : i32
%789 = arith.extsi %788 : i32 to i64
%784 = func.call @calloc(%787, %789) : (i64, i64) -> !llvm.ptr
%790 = llvm.mlir.addressof @g_rhs : !llvm.ptr
llvm.store %784, %790 : !llvm.ptr, !llvm.ptr
%792 = llvm.mlir.addressof @MAXN : !llvm.ptr
%793 = llvm.load %792 : !llvm.ptr -> i32
%794 = arith.extsi %793 : i32 to i64
%795 = arith.constant 8 : i32
%796 = arith.extsi %795 : i32 to i64
%791 = func.call @calloc(%794, %796) : (i64, i64) -> !llvm.ptr
%797 = llvm.mlir.addressof @g_delta : !llvm.ptr
llvm.store %791, %797 : !llvm.ptr, !llvm.ptr
%799 = llvm.mlir.addressof @MAXN : !llvm.ptr
%800 = llvm.load %799 : !llvm.ptr -> i32
%801 = arith.extsi %800 : i32 to i64
%802 = arith.constant 8 : i32
%803 = arith.extsi %802 : i32 to i64
%798 = func.call @calloc(%801, %803) : (i64, i64) -> !llvm.ptr
%804 = llvm.mlir.addressof @g_trial : !llvm.ptr
llvm.store %798, %804 : !llvm.ptr, !llvm.ptr
%806 = llvm.mlir.addressof @MAXN : !llvm.ptr
%807 = llvm.load %806 : !llvm.ptr -> i32
%808 = arith.extsi %807 : i32 to i64
%809 = arith.constant 8 : i32
%810 = arith.extsi %809 : i32 to i64
%805 = func.call @calloc(%808, %810) : (i64, i64) -> !llvm.ptr
%811 = llvm.mlir.addressof @g_terms : !llvm.ptr
llvm.store %805, %811 : !llvm.ptr, !llvm.ptr
%813 = llvm.mlir.addressof @MAXN : !llvm.ptr
%814 = llvm.load %813 : !llvm.ptr -> i32
%815 = arith.extsi %814 : i32 to i64
%816 = arith.constant 8 : i32
%817 = arith.extsi %816 : i32 to i64
%812 = func.call @calloc(%815, %817) : (i64, i64) -> !llvm.ptr
%818 = llvm.mlir.addressof @g_c : !llvm.ptr
llvm.store %812, %818 : !llvm.ptr, !llvm.ptr
%820 = llvm.mlir.addressof @MAXN : !llvm.ptr
%821 = llvm.load %820 : !llvm.ptr -> i32
%822 = arith.extsi %821 : i32 to i64
%823 = arith.constant 8 : i32
%824 = arith.extsi %823 : i32 to i64
%819 = func.call @calloc(%822, %824) : (i64, i64) -> !llvm.ptr
%825 = llvm.mlir.addressof @g_d : !llvm.ptr
llvm.store %819, %825 : !llvm.ptr, !llvm.ptr
%827 = llvm.mlir.addressof @MAXN : !llvm.ptr
%828 = llvm.load %827 : !llvm.ptr -> i32
%829 = arith.extsi %828 : i32 to i64
%830 = arith.constant 8 : i32
%831 = arith.extsi %830 : i32 to i64
%826 = func.call @calloc(%829, %831) : (i64, i64) -> !llvm.ptr
%832 = llvm.mlir.addressof @g_b : !llvm.ptr
llvm.store %826, %832 : !llvm.ptr, !llvm.ptr
%833 = arith.constant 101 : i32
%834 = arith.constant 1 : i32
%835 = arith.subi %833, %834 : i32
%836 = arith.constant 2 : i32
%837 = arith.divsi %835, %836 : i32
%838 = arith.constant 1000000000000000000 : f32
%839 = arith.negf %838 : f32
%840 = arith.extf %839 : f32 to f64
%841 = llvm.mlir.constant(1 : i64) : i64
%842 = llvm.alloca %841 x f64 : (i64) -> !llvm.ptr
llvm.store %840, %842 : f64, !llvm.ptr
%844 = llvm.mlir.addressof @MAXN : !llvm.ptr
%845 = llvm.load %844 : !llvm.ptr -> i32
%846 = arith.extsi %845 : i32 to i64
%847 = arith.constant 8 : i32
%848 = arith.extsi %847 : i32 to i64
%843 = func.call @calloc(%846, %848) : (i64, i64) -> !llvm.ptr
%849 = arith.constant 0 : i32
%850 = llvm.mlir.constant(1 : i64) : i64
%851 = llvm.alloca %850 x i32 : (i64) -> !llvm.ptr
llvm.store %849, %851 : i32, !llvm.ptr
cf.br ^bb93
^bb93:
%852 = llvm.load %851 : !llvm.ptr -> i32
%853 = arith.constant 1 : i32
%854 = arith.cmpi sle, %852, %853 : i32
cf.cond_br %854, ^bb94, ^bb95
^bb94:
%855 = llvm.mlir.constant(1 : i64) : i64
%856 = llvm.alloca %855 x i32 : (i64) -> !llvm.ptr
llvm.store %837, %856 : i32, !llvm.ptr
%857 = arith.constant 1 : i32
%858 = arith.subi %837, %857 : i32
%859 = llvm.mlir.constant(1 : i64) : i64
%860 = llvm.alloca %859 x i32 : (i64) -> !llvm.ptr
llvm.store %858, %860 : i32, !llvm.ptr
%861 = llvm.load %851 : !llvm.ptr -> i32
%862 = arith.constant 0 : i32
%863 = arith.cmpi eq, %861, %862 : i32
cf.cond_br %863, ^bb96, ^bb97
^bb96:
%864 = llvm.load %856 : !llvm.ptr -> i32
%865 = llvm.load %860 : !llvm.ptr -> i32
llvm.store %865, %856 : i32, !llvm.ptr
llvm.store %864, %860 : i32, !llvm.ptr
cf.br ^bb98
^bb97:
cf.br ^bb98
^bb98:
%866 = arith.constant 0 : i32
%867 = llvm.mlir.constant(1 : i64) : i64
%868 = llvm.alloca %867 x i32 : (i64) -> !llvm.ptr
llvm.store %866, %868 : i32, !llvm.ptr
%869 = arith.constant 1.0 : f32
%870 = arith.negf %869 : f32
%871 = llvm.load %868 : !llvm.ptr -> i32
%872 = arith.extf %870 : f32 to f64
%873 = arith.extsi %871 : i32 to i64
%874 = llvm.getelementptr %843[%873] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %872, %874 : f64, !llvm.ptr
%875 = llvm.load %868 : !llvm.ptr -> i32
%876 = arith.constant 1 : i32
%877 = arith.addi %875, %876 : i32
llvm.store %877, %868 : i32, !llvm.ptr
%878 = arith.constant 1 : i32
%879 = llvm.mlir.constant(1 : i64) : i64
%880 = llvm.alloca %879 x i32 : (i64) -> !llvm.ptr
llvm.store %878, %880 : i32, !llvm.ptr
cf.br ^bb99
^bb99:
%881 = llvm.load %880 : !llvm.ptr -> i32
%882 = llvm.load %856 : !llvm.ptr -> i32
%883 = arith.cmpi sle, %881, %882 : i32
cf.cond_br %883, ^bb100, ^bb101
^bb100:
%884 = arith.constant 1.0 : f32
%885 = llvm.load %880 : !llvm.ptr -> i32
%886 = arith.sitofp %885 : i32 to f64
%887 = llvm.load %856 : !llvm.ptr -> i32
%888 = arith.constant 1 : i32
%889 = arith.addi %887, %888 : i32
%890 = arith.sitofp %889 : i32 to f64
%891 = arith.divf %886, %890 : f64
%893 = arith.extf %884 : f32 to f64
%892 = arith.subf %893, %891 : f64
%895 = arith.constant 3.0 : f32
%896 = arith.constant 5.0 : f32
%897 = arith.divf %895, %896 : f32
%898 = arith.extf %897 : f32 to f64
%894 = func.call @pow(%892, %898) : (f64, f64) -> f64
%899 = arith.negf %894 : f64
%900 = llvm.load %868 : !llvm.ptr -> i32
%901 = arith.extsi %900 : i32 to i64
%902 = llvm.getelementptr %843[%901] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %899, %902 : f64, !llvm.ptr
%903 = llvm.load %868 : !llvm.ptr -> i32
%904 = arith.constant 1 : i32
%905 = arith.addi %903, %904 : i32
llvm.store %905, %868 : i32, !llvm.ptr
%906 = llvm.load %880 : !llvm.ptr -> i32
%907 = arith.constant 1 : i32
%908 = arith.addi %906, %907 : i32
llvm.store %908, %880 : i32, !llvm.ptr
cf.br ^bb99
^bb101:
%909 = arith.constant 1 : i32
%910 = llvm.mlir.constant(1 : i64) : i64
%911 = llvm.alloca %910 x i32 : (i64) -> !llvm.ptr
llvm.store %909, %911 : i32, !llvm.ptr
cf.br ^bb102
^bb102:
%912 = llvm.load %911 : !llvm.ptr -> i32
%913 = llvm.load %860 : !llvm.ptr -> i32
%914 = arith.cmpi sle, %912, %913 : i32
cf.cond_br %914, ^bb103, ^bb104
^bb103:
%915 = llvm.load %911 : !llvm.ptr -> i32
%916 = arith.sitofp %915 : i32 to f64
%917 = llvm.load %860 : !llvm.ptr -> i32
%918 = arith.constant 1 : i32
%919 = arith.addi %917, %918 : i32
%920 = arith.sitofp %919 : i32 to f64
%921 = arith.divf %916, %920 : f64
%923 = arith.constant 3.0 : f32
%924 = arith.constant 5.0 : f32
%925 = arith.divf %923, %924 : f32
%926 = arith.extf %925 : f32 to f64
%922 = func.call @pow(%921, %926) : (f64, f64) -> f64
%927 = llvm.load %868 : !llvm.ptr -> i32
%928 = arith.extsi %927 : i32 to i64
%929 = llvm.getelementptr %843[%928] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %922, %929 : f64, !llvm.ptr
%930 = llvm.load %868 : !llvm.ptr -> i32
%931 = arith.constant 1 : i32
%932 = arith.addi %930, %931 : i32
llvm.store %932, %868 : i32, !llvm.ptr
%933 = llvm.load %911 : !llvm.ptr -> i32
%934 = arith.constant 1 : i32
%935 = arith.addi %933, %934 : i32
llvm.store %935, %911 : i32, !llvm.ptr
cf.br ^bb102
^bb104:
%936 = arith.constant 1.0 : f32
%937 = llvm.load %868 : !llvm.ptr -> i32
%938 = arith.extf %936 : f32 to f64
%939 = arith.extsi %937 : i32 to i64
%940 = llvm.getelementptr %843[%939] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %938, %940 : f64, !llvm.ptr
%941 = llvm.load %868 : !llvm.ptr -> i32
%942 = arith.constant 1 : i32
%943 = arith.addi %941, %942 : i32
llvm.store %943, %868 : i32, !llvm.ptr
%945 = llvm.load %868 : !llvm.ptr -> i32
func.call @dsort(%843, %945) : (!llvm.ptr, i32) -> ()
func.call @newton_solve(%843, %833) : (!llvm.ptr, i32) -> ()
%947 = func.call @compute_area(%843, %833) : (!llvm.ptr, i32) -> f64
%948 = llvm.load %842 : !llvm.ptr -> f64
%949 = arith.cmpf ogt, %947, %948 : f64
cf.cond_br %949, ^bb105, ^bb106
^bb105:
llvm.store %947, %842 : f64, !llvm.ptr
cf.br ^bb107
^bb106:
cf.br ^bb107
^bb107:
%950 = llvm.load %851 : !llvm.ptr -> i32
%951 = arith.constant 1 : i32
%952 = arith.addi %950, %951 : i32
llvm.store %952, %851 : i32, !llvm.ptr
cf.br ^bb93
^bb95:
%953 = llvm.mlir.addressof @str_0 : !llvm.ptr
%954 = llvm.load %842 : !llvm.ptr -> f64
%955 = llvm.call @printf(%953, %954) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, f64) -> i32
%956 = arith.constant 0 : i32
func.return %956 : i32
}
}