← All problems
Problem 456
Triangles Containing Origin II — C(2_000_000).
View problem on Project Euler
Performance comparison
Metric Our solution Best known
Time complexity O(n^2)O(n^2)
Space complexity O(n^2)O(n^2)
Approach Flow solution Bottom-up DP
Verdict Optimal
Flow source
# Project Euler 456
# Triangles Containing Origin II — C(2_000_000).
extern {
function calloc(n: i64, size: i64) -> ptr<void>
function free(p: ptr<void>) -> void
}
function gcd_abs(a0: i64, b0: i64) -> i64 {
let mut a: i64 = a0
let mut b: i64 = b0
if a < 0 { a = 0 - a }
if b < 0 { b = 0 - b }
while b != 0 {
let t: i64 = a % b
a = b
b = t
}
return a
}
function comb3(n: i64) -> i64 {
if n < 3 { return 0 }
return n * (n - 1) * (n - 2) / 6
}
function half(x: i64, y: i64) -> i32 {
if y > 0 { return 0 }
if y == 0 {
if x > 0 { return 0 }
}
return 1
}
# True if polar angle of a is strictly less than polar angle of b.
function angle_less(ax: i64, ay: i64, bx: i64, by: i64) -> bool {
let ha: i32 = half(ax, ay)
let hb: i32 = half(bx, by)
if ha != hb { return ha < hb }
let cross: i64 = ax * by - ay * bx
if cross != 0 { return cross > 0 }
let da: i64 = ax * ax + ay * ay
let db: i64 = bx * bx + by * by
return da < db
}
# Open angle from a to b is in (0, pi).
function open_lt_pi(ax: i64, ay: i64, bx: i64, by: i64) -> bool {
let cross: i64 = ax * by - ay * bx
if cross > 0 { return true }
if cross < 0 { return false }
let dot: i64 = ax * bx + ay * by
return dot > 0
}
function sort_points(xs: ptr<i64>, ys: ptr<i64>, n: i64) -> void {
let lo: ptr<i64> = calloc(64, 8)
let hi: ptr<i64> = calloc(64, 8)
let mut sp: i32 = 0
lo[0] = 0
hi[0] = n - 1
sp = 1
while sp > 0 {
sp = sp - 1
let l: i64 = lo[sp]
let h: i64 = hi[sp]
if l >= h { continue }
let mid: i64 = (l + h) / 2
let px: i64 = xs[mid]
let py: i64 = ys[mid]
let mut i: i64 = l
let mut j: i64 = h
while i <= j {
while angle_less(xs[i], ys[i], px, py) { i = i + 1 }
while angle_less(px, py, xs[j], ys[j]) { j = j - 1 }
if i <= j {
let tx: i64 = xs[i]
xs[i] = xs[j]
xs[j] = tx
let ty: i64 = ys[i]
ys[i] = ys[j]
ys[j] = ty
i = i + 1
j = j - 1
}
}
if l < j {
lo[sp] = l
hi[sp] = j
sp = sp + 1
}
if i < h {
lo[sp] = i
hi[sp] = h
sp = sp + 1
}
}
free(lo)
free(hi)
}
function main() -> i32 {
let n: i64 = 2000000
let xs: ptr<i64> = calloc(n, 8)
let ys: ptr<i64> = calloc(n, 8)
if xs == null || ys == null { return 1 }
let SHIFT: i64 = 21
let MASK: i64 = (1 << SHIFT) - 1
let HS: i64 = 1 << 22
let hdx: ptr<i64> = calloc(HS, 8)
let hdy: ptr<i64> = calloc(HS, 8)
let hpack: ptr<i64> = calloc(HS, 8)
let hused: ptr<i8> = calloc(HS, 1)
if hdx == null || hdy == null || hpack == null || hused == null { return 1 }
let modx: i64 = 32323
let mody: i64 = 30103
let ax: i64 = 1248
let ay: i64 = 8421
let mut x: i64 = 1
let mut y: i64 = 1
let mut m: i64 = 0
let mut t: i64 = 0
while t < n {
x = (x * ax) % modx
y = (y * ay) % mody
let px: i64 = x - 16161
let py: i64 = y - 15051
if !(px == 0 && py == 0) {
xs[m] = px
ys[m] = py
m = m + 1
let g: i64 = gcd_abs(px, py)
let mut dx: i64 = px / g
let mut dy: i64 = py / g
let mut side0: bool = true
if dx > 0 {
side0 = true
} else {
if dx == 0 {
if dy > 0 {
side0 = true
} else {
side0 = false
dx = 0 - dx
dy = 0 - dy
}
} else {
side0 = false
dx = 0 - dx
dy = 0 - dy
}
}
let mut h: i64 = (dx * 1315423911 + dy * 2654435761) % HS
if h < 0 { h = h + HS }
while hused[h] == 1 {
if hdx[h] == dx {
if hdy[h] == dy { break }
}
h = h + 1
if h >= HS { h = 0 }
}
if hused[h] == 0 {
hused[h] = 1
hdx[h] = dx
hdy[h] = dy
hpack[h] = 0
}
if side0 {
hpack[h] = hpack[h] + 1
} else {
hpack[h] = hpack[h] + (1 << SHIFT)
}
}
t = t + 1
}
if m < 3 {
printf("%lld\n", 0 as i64)
return 0
}
sort_points(xs, ys, m)
let mut open_semi: i64 = 0
let mut j: i64 = 1
let mut i: i64 = 0
while i < m {
if j < i + 1 { j = i + 1 }
let xi: i64 = xs[i]
let yi: i64 = ys[i]
while j < i + m {
let xj: i64 = xs[j % m]
let yj: i64 = ys[j % m]
if open_lt_pi(xi, yi, xj, yj) {
j = j + 1
} else {
break
}
}
let k: i64 = j - i - 1
open_semi = open_semi + k * (k - 1) / 2
i = i + 1
}
let mut antipodal: i64 = 0
let mut hi: i64 = 0
while hi < HS {
if hused[hi] == 1 {
let packed: i64 = hpack[hi]
let a: i64 = packed & MASK
let b: i64 = packed >> SHIFT
if a > 0 {
if b > 0 {
let tt: i64 = a + b
antipodal = antipodal + a * b * (m - tt)
antipodal = antipodal + comb3(tt) - comb3(a) - comb3(b)
}
}
}
hi = hi + 1
}
let total: i64 = comb3(m)
printf("%lld\n", total - open_semi - antipodal)
free(xs)
free(ys)
free(hdx)
free(hdy)
free(hpack)
free(hused)
return 0
}
Generated C
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* Flow runtime helpers */
typedef struct flow_temp_node { struct flow_temp_node* next; } flow_temp_node;
static flow_temp_node* flow_temp_head = NULL;
static int flow_temp_atexit_set = 0;
__attribute__((unused)) static void flow_temp_free_all(void) {
while (flow_temp_head) {
flow_temp_node* n = flow_temp_head;
flow_temp_head = n->next;
free(n);
}
}
__attribute__((unused)) static void* flow_temp_alloc(size_t nbytes) {
flow_temp_node* node = (flow_temp_node*)malloc(sizeof(flow_temp_node) + nbytes);
if (!node) return NULL;
node->next = flow_temp_head;
flow_temp_head = node;
if (!flow_temp_atexit_set) {
flow_temp_atexit_set = 1;
atexit(flow_temp_free_all);
}
return (void*)(node + 1);
}
#ifndef FLOW_DIAG
#define FLOW_DIAG(msg) fprintf(stderr, "%s", (msg))
#endif
#ifndef FLOW_LOG
#define FLOW_LOG(fmt, ...) printf(fmt, __VA_ARGS__)
#endif
#ifndef FLOW_LOG_EMPTY
#define FLOW_LOG_EMPTY(fmt) printf(fmt)
#endif
static char* flow_strcat(const char* a, const char* b) {
size_t la = strlen(a ? a : ""), lb = strlen(b ? b : "");
char* r = (char*)flow_temp_alloc(la + lb + 1);
if (!r) return NULL;
if (la) memcpy(r, a, la);
if (lb) memcpy(r + la, b, lb);
r[la + lb] = '\0';
return r;
}
#define __flow_in_arr(arr, val) __extension__ ({ \
int _found = 0; \
size_t _n = sizeof(arr)/sizeof((arr)[0]); \
for (size_t _i = 0; _i < _n; _i++) { \
if ((arr)[_i] == (val)) { _found = 1; break; } \
} _found; })
/* Unified fault handler (MISRA #279) — override with -DFLOW_FAULT_HANDLER=fn */
#ifndef FLOW_FAULT_HANDLER
__attribute__((unused)) static inline void flow_fault_handler(const char* msg) {
fprintf(stderr, "flow: %s\n", msg ? msg : "fault");
abort();
#if defined(__GNUC__) || defined(__clang__)
__builtin_unreachable();
#endif
}
#else
#define flow_fault_handler FLOW_FAULT_HANDLER
#endif
#define flow_div_by_zero_handler() flow_fault_handler("division by zero")
#define flow_shift_ub_handler() flow_fault_handler("invalid shift (amount out of range or left-shift of negative)")
#ifndef FLOW_CHECKED_DIV
#define FLOW_CHECKED_DIV(L, R) (((R) != 0) ? ((L) / (R)) : (flow_div_by_zero_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_MOD
#define FLOW_CHECKED_MOD(L, R) (((R) != 0) ? ((L) % (R)) : (flow_div_by_zero_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_SHL
#define FLOW_CHECKED_SHL(L, R) ((((R) >= 0) && ((unsigned long long)(R) < (sizeof(L) * 8ull)) && ((L) >= 0)) ? ((L) << (R)) : (flow_shift_ub_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_SHR
#define FLOW_CHECKED_SHR(L, R) ((((R) >= 0) && ((unsigned long long)(R) < (sizeof(L) * 8ull))) ? ((L) >> (R)) : (flow_shift_ub_handler(), (L) * 0))
#endif
#include <math.h>
void* _ui_state = NULL;
static inline float i32_to_f32(int32_t v) { return (float)v; }
/* Host stub for @gpu kernels (device codegen replaces this). */
static inline int32_t gpu_thread_id(void) { return 0; }
int64_t gcd_abs_i64_i64(int64_t a0, int64_t b0);
int64_t comb3_i64(int64_t n);
int32_t half_i64_i64(int64_t x, int64_t y);
bool angle_less_i64_i64_i64_i64(int64_t ax, int64_t ay, int64_t bx, int64_t by);
bool open_lt_pi_i64_i64_i64_i64(int64_t ax, int64_t ay, int64_t bx, int64_t by);
void sort_points_ptr_i64_ptr_i64_i64(int64_t* xs, int64_t* ys, int64_t n);
int32_t main(void);
int64_t gcd_abs_i64_i64(int64_t a0, int64_t b0) {
int64_t a = a0;
int64_t b = b0;
if (a < 0) {
a = (0 - a);
}
if (b < 0) {
b = (0 - b);
}
while (b != 0) {
int64_t t = FLOW_CHECKED_MOD((a), (b));
a = b;
b = t;
}
return a;
}
int64_t comb3_i64(int64_t n) {
if (n < 3) {
return 0;
}
return FLOW_CHECKED_DIV((((n * (n - 1)) * (n - 2))), (6));
}
int32_t half_i64_i64(int64_t x, int64_t y) {
if (y > 0) {
return 0;
}
if (y == 0) {
if (x > 0) {
return 0;
}
}
return 1;
}
bool angle_less_i64_i64_i64_i64(int64_t ax, int64_t ay, int64_t bx, int64_t by) {
int32_t ha = half_i64_i64(ax, ay);
int32_t hb = half_i64_i64(bx, by);
if (ha != hb) {
return ha < hb;
}
int64_t cross = ((ax * by) - (ay * bx));
if (cross != 0) {
return cross > 0;
}
int64_t da = ((ax * ax) + (ay * ay));
int64_t db = ((bx * bx) + (by * by));
return da < db;
}
bool open_lt_pi_i64_i64_i64_i64(int64_t ax, int64_t ay, int64_t bx, int64_t by) {
int64_t cross = ((ax * by) - (ay * bx));
if (cross > 0) {
return 1;
}
if (cross < 0) {
return 0;
}
int64_t dot = ((ax * bx) + (ay * by));
return dot > 0;
}
void sort_points_ptr_i64_ptr_i64_i64(int64_t* xs, int64_t* ys, int64_t n) {
int64_t* lo = (int64_t*)(calloc(64, 8));
int64_t* hi = (int64_t*)(calloc(64, 8));
int32_t sp = 0;
lo[0] = 0;
hi[0] = (n - 1);
sp = 1;
while (sp > 0) {
sp = (sp - 1);
int64_t l = lo[sp];
int64_t h = hi[sp];
if (l >= h) {
continue;
}
int64_t mid = FLOW_CHECKED_DIV(((l + h)), (2));
int64_t px = xs[mid];
int64_t py = ys[mid];
int64_t i = l;
int64_t j = h;
while (i <= j) {
while (angle_less_i64_i64_i64_i64(xs[i], ys[i], px, py)) {
i = (i + 1);
}
while (angle_less_i64_i64_i64_i64(px, py, xs[j], ys[j])) {
j = (j - 1);
}
if (i <= j) {
int64_t tx = xs[i];
xs[i] = xs[j];
xs[j] = tx;
int64_t ty = ys[i];
ys[i] = ys[j];
ys[j] = ty;
i = (i + 1);
j = (j - 1);
}
}
if (l < j) {
lo[sp] = l;
hi[sp] = j;
sp = (sp + 1);
}
if (i < h) {
lo[sp] = i;
hi[sp] = h;
sp = (sp + 1);
}
}
free(lo);
free(hi);
}
int32_t main(void) {
int64_t n = 2000000;
int64_t* xs = (int64_t*)(calloc(n, 8));
int64_t* ys = (int64_t*)(calloc(n, 8));
if ((xs == NULL || ys == NULL)) {
return 1;
}
int64_t SHIFT = 21;
int64_t MASK = (FLOW_CHECKED_SHL((1), (SHIFT)) - 1);
int64_t HS = FLOW_CHECKED_SHL((1), (22));
int64_t* hdx = (int64_t*)(calloc(HS, 8));
int64_t* hdy = (int64_t*)(calloc(HS, 8));
int64_t* hpack = (int64_t*)(calloc(HS, 8));
int8_t* hused = (int8_t*)(calloc(HS, 1));
if ((((hdx == NULL || hdy == NULL) || hpack == NULL) || hused == NULL)) {
return 1;
}
int64_t modx = 32323;
int64_t mody = 30103;
int64_t ax = 1248;
int64_t ay = 8421;
int64_t x = 1;
int64_t y = 1;
int64_t m = 0;
int64_t t = 0;
while (t < n) {
x = FLOW_CHECKED_MOD(((x * ax)), (modx));
y = FLOW_CHECKED_MOD(((y * ay)), (mody));
int64_t px = (x - 16161);
int64_t py = (y - 15051);
if ((!((px == 0 && py == 0)))) {
xs[m] = px;
ys[m] = py;
m = (m + 1);
int64_t g = gcd_abs_i64_i64(px, py);
int64_t dx = FLOW_CHECKED_DIV((px), (g));
int64_t dy = FLOW_CHECKED_DIV((py), (g));
bool side0 = 1;
if (dx > 0) {
side0 = 1;
} else {
if (dx == 0) {
if (dy > 0) {
side0 = 1;
} else {
side0 = 0;
dx = (0 - dx);
dy = (0 - dy);
}
} else {
side0 = 0;
dx = (0 - dx);
dy = (0 - dy);
}
}
int64_t h = FLOW_CHECKED_MOD((((dx * 1315423911) + (dy * 2654435761))), (HS));
if (h < 0) {
h = (h + HS);
}
while (hused[h] == 1) {
if (hdx[h] == dx) {
if (hdy[h] == dy) {
break;
}
}
h = (h + 1);
if (h >= HS) {
h = 0;
}
}
if (hused[h] == 0) {
hused[h] = 1;
hdx[h] = dx;
hdy[h] = dy;
hpack[h] = 0;
}
if (side0) {
hpack[h] = (hpack[h] + 1);
} else {
hpack[h] = (hpack[h] + FLOW_CHECKED_SHL((1), (SHIFT)));
}
}
t = (t + 1);
}
if (m < 3) {
printf("%lld\n", ((int64_t)(0)));
return 0;
}
sort_points_ptr_i64_ptr_i64_i64(xs, ys, m);
int64_t open_semi = 0;
int64_t j = 1;
int64_t i = 0;
while (i < m) {
if (j < (i + 1)) {
j = (i + 1);
}
int64_t xi = xs[i];
int64_t yi = ys[i];
while (j < (i + m)) {
int64_t xj = xs[FLOW_CHECKED_MOD((j), (m))];
int64_t yj = ys[FLOW_CHECKED_MOD((j), (m))];
if (open_lt_pi_i64_i64_i64_i64(xi, yi, xj, yj)) {
j = (j + 1);
} else {
break;
}
}
int64_t k = ((j - i) - 1);
open_semi = (open_semi + FLOW_CHECKED_DIV(((k * (k - 1))), (2)));
i = (i + 1);
}
int64_t antipodal = 0;
int64_t hi = 0;
while (hi < HS) {
if (hused[hi] == 1) {
int64_t packed = hpack[hi];
int64_t a = (packed & MASK);
int64_t b = FLOW_CHECKED_SHR((packed), (SHIFT));
if (a > 0) {
if (b > 0) {
int64_t tt = (a + b);
antipodal = (antipodal + ((a * b) * (m - tt)));
antipodal = (((antipodal + comb3_i64(tt)) - comb3_i64(a)) - comb3_i64(b));
}
}
}
hi = (hi + 1);
}
int64_t total = comb3_i64(m);
printf("%lld\n", ((total - open_semi) - antipodal));
free(xs);
free(ys);
free(hdx);
free(hdy);
free(hpack);
free(hused);
return 0;
}
Generated MLIR
module {
llvm.func @printf(!llvm.ptr, ...) -> i32
llvm.mlir.global internal constant @str_0("%lld\n\00") {addr_space = 0 : i32} : !llvm.array<6 x i8>
func.func private @calloc(i64, i64) -> !llvm.ptr
func.func private @free(!llvm.ptr) -> ()
func.func @gcd_abs(%arg0: i64, %arg1: i64) -> i64 {
%0 = llvm.mlir.constant(1 : i64) : i64
%1 = llvm.alloca %0 x i64 : (i64) -> !llvm.ptr
llvm.store %arg0, %1 : i64, !llvm.ptr
%2 = llvm.mlir.constant(1 : i64) : i64
%3 = llvm.alloca %2 x i64 : (i64) -> !llvm.ptr
llvm.store %arg1, %3 : i64, !llvm.ptr
%4 = llvm.load %1 : !llvm.ptr -> i64
%5 = arith.constant 0 : i32
%7 = arith.extsi %5 : i32 to i64
%6 = arith.cmpi slt, %4, %7 : i64
cf.cond_br %6, ^bb0, ^bb1
^bb0:
%8 = arith.constant 0 : i32
%9 = llvm.load %1 : !llvm.ptr -> i64
%11 = arith.extsi %8 : i32 to i64
%10 = arith.subi %11, %9 : i64
llvm.store %10, %1 : i64, !llvm.ptr
cf.br ^bb2
^bb1:
cf.br ^bb2
^bb2:
%12 = llvm.load %3 : !llvm.ptr -> i64
%13 = arith.constant 0 : i32
%15 = arith.extsi %13 : i32 to i64
%14 = arith.cmpi slt, %12, %15 : i64
cf.cond_br %14, ^bb3, ^bb4
^bb3:
%16 = arith.constant 0 : i32
%17 = llvm.load %3 : !llvm.ptr -> i64
%19 = arith.extsi %16 : i32 to i64
%18 = arith.subi %19, %17 : i64
llvm.store %18, %3 : i64, !llvm.ptr
cf.br ^bb5
^bb4:
cf.br ^bb5
^bb5:
cf.br ^bb6
^bb6:
%20 = llvm.load %3 : !llvm.ptr -> i64
%21 = arith.constant 0 : i32
%23 = arith.extsi %21 : i32 to i64
%22 = arith.cmpi ne, %20, %23 : i64
cf.cond_br %22, ^bb7, ^bb8
^bb7:
%24 = llvm.load %1 : !llvm.ptr -> i64
%25 = llvm.load %3 : !llvm.ptr -> i64
%26 = arith.remsi %24, %25 : i64
%27 = llvm.load %3 : !llvm.ptr -> i64
llvm.store %27, %1 : i64, !llvm.ptr
llvm.store %26, %3 : i64, !llvm.ptr
cf.br ^bb6
^bb8:
%28 = llvm.load %1 : !llvm.ptr -> i64
func.return %28 : i64
}
func.func @comb3(%arg0: i64) -> i64 {
%29 = arith.constant 3 : i32
%31 = arith.extsi %29 : i32 to i64
%30 = arith.cmpi slt, %arg0, %31 : i64
cf.cond_br %30, ^bb9, ^bb10
^bb9:
%32 = arith.constant 0 : i32
%33 = arith.extsi %32 : i32 to i64
func.return %33 : i64
^bb10:
cf.br ^bb11
^bb11:
%34 = arith.constant 1 : i32
%36 = arith.extsi %34 : i32 to i64
%35 = arith.subi %arg0, %36 : i64
%37 = arith.muli %arg0, %35 : i64
%38 = arith.constant 2 : i32
%40 = arith.extsi %38 : i32 to i64
%39 = arith.subi %arg0, %40 : i64
%41 = arith.muli %37, %39 : i64
%42 = arith.constant 6 : i32
%44 = arith.extsi %42 : i32 to i64
%43 = arith.divsi %41, %44 : i64
func.return %43 : i64
}
func.func @half(%arg0: i64, %arg1: i64) -> i32 {
%45 = arith.constant 0 : i32
%47 = arith.extsi %45 : i32 to i64
%46 = arith.cmpi sgt, %arg1, %47 : i64
cf.cond_br %46, ^bb12, ^bb13
^bb12:
%48 = arith.constant 0 : i32
func.return %48 : i32
^bb13:
cf.br ^bb14
^bb14:
%49 = arith.constant 0 : i32
%51 = arith.extsi %49 : i32 to i64
%50 = arith.cmpi eq, %arg1, %51 : i64
cf.cond_br %50, ^bb15, ^bb16
^bb15:
%52 = arith.constant 0 : i32
%54 = arith.extsi %52 : i32 to i64
%53 = arith.cmpi sgt, %arg0, %54 : i64
cf.cond_br %53, ^bb18, ^bb19
^bb18:
%55 = arith.constant 0 : i32
func.return %55 : i32
^bb19:
cf.br ^bb20
^bb20:
cf.br ^bb17
^bb16:
cf.br ^bb17
^bb17:
%56 = arith.constant 1 : i32
func.return %56 : i32
}
func.func @angle_less(%arg0: i64, %arg1: i64, %arg2: i64, %arg3: i64) -> i1 {
%57 = func.call @half(%arg0, %arg1) : (i64, i64) -> i32
%58 = func.call @half(%arg2, %arg3) : (i64, i64) -> i32
%59 = arith.cmpi ne, %57, %58 : i32
cf.cond_br %59, ^bb21, ^bb22
^bb21:
%60 = arith.cmpi slt, %57, %58 : i32
func.return %60 : i1
^bb22:
cf.br ^bb23
^bb23:
%61 = arith.muli %arg0, %arg3 : i64
%62 = arith.muli %arg1, %arg2 : i64
%63 = arith.subi %61, %62 : i64
%64 = arith.constant 0 : i32
%66 = arith.extsi %64 : i32 to i64
%65 = arith.cmpi ne, %63, %66 : i64
cf.cond_br %65, ^bb24, ^bb25
^bb24:
%67 = arith.constant 0 : i32
%69 = arith.extsi %67 : i32 to i64
%68 = arith.cmpi sgt, %63, %69 : i64
func.return %68 : i1
^bb25:
cf.br ^bb26
^bb26:
%70 = arith.muli %arg0, %arg0 : i64
%71 = arith.muli %arg1, %arg1 : i64
%72 = arith.addi %70, %71 : i64
%73 = arith.muli %arg2, %arg2 : i64
%74 = arith.muli %arg3, %arg3 : i64
%75 = arith.addi %73, %74 : i64
%76 = arith.cmpi slt, %72, %75 : i64
func.return %76 : i1
}
func.func @open_lt_pi(%arg0: i64, %arg1: i64, %arg2: i64, %arg3: i64) -> i1 {
%77 = arith.muli %arg0, %arg3 : i64
%78 = arith.muli %arg1, %arg2 : i64
%79 = arith.subi %77, %78 : i64
%80 = arith.constant 0 : i32
%82 = arith.extsi %80 : i32 to i64
%81 = arith.cmpi sgt, %79, %82 : i64
cf.cond_br %81, ^bb27, ^bb28
^bb27:
%83 = arith.constant 1 : i1
func.return %83 : i1
^bb28:
cf.br ^bb29
^bb29:
%84 = arith.constant 0 : i32
%86 = arith.extsi %84 : i32 to i64
%85 = arith.cmpi slt, %79, %86 : i64
cf.cond_br %85, ^bb30, ^bb31
^bb30:
%87 = arith.constant 0 : i1
func.return %87 : i1
^bb31:
cf.br ^bb32
^bb32:
%88 = arith.muli %arg0, %arg2 : i64
%89 = arith.muli %arg1, %arg3 : i64
%90 = arith.addi %88, %89 : i64
%91 = arith.constant 0 : i32
%93 = arith.extsi %91 : i32 to i64
%92 = arith.cmpi sgt, %90, %93 : i64
func.return %92 : i1
}
func.func @sort_points(%arg0: !llvm.ptr, %arg1: !llvm.ptr, %arg2: i64) -> () {
%95 = arith.constant 64 : i32
%96 = arith.constant 8 : i32
%97 = arith.extsi %95 : i32 to i64
%98 = arith.extsi %96 : i32 to i64
%94 = func.call @calloc(%97, %98) : (i64, i64) -> !llvm.ptr
%100 = arith.constant 64 : i32
%101 = arith.constant 8 : i32
%102 = arith.extsi %100 : i32 to i64
%103 = arith.extsi %101 : i32 to i64
%99 = func.call @calloc(%102, %103) : (i64, i64) -> !llvm.ptr
%104 = arith.constant 0 : i32
%105 = llvm.mlir.constant(1 : i64) : i64
%106 = llvm.alloca %105 x i32 : (i64) -> !llvm.ptr
llvm.store %104, %106 : i32, !llvm.ptr
%107 = arith.constant 0 : i32
%108 = arith.constant 0 : i32
%109 = arith.extsi %107 : i32 to i64
%110 = arith.extsi %108 : i32 to i64
%111 = llvm.getelementptr %94[%110] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %109, %111 : i64, !llvm.ptr
%112 = arith.constant 1 : i32
%114 = arith.extsi %112 : i32 to i64
%113 = arith.subi %arg2, %114 : i64
%115 = arith.constant 0 : i32
%116 = arith.extsi %115 : i32 to i64
%117 = llvm.getelementptr %99[%116] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %113, %117 : i64, !llvm.ptr
%118 = arith.constant 1 : i32
llvm.store %118, %106 : i32, !llvm.ptr
cf.br ^bb33
^bb33:
%119 = llvm.load %106 : !llvm.ptr -> i32
%120 = arith.constant 0 : i32
%121 = arith.cmpi sgt, %119, %120 : i32
cf.cond_br %121, ^bb34, ^bb35
^bb34:
%122 = llvm.load %106 : !llvm.ptr -> i32
%123 = arith.constant 1 : i32
%124 = arith.subi %122, %123 : i32
llvm.store %124, %106 : i32, !llvm.ptr
%126 = llvm.load %106 : !llvm.ptr -> i32
%127 = arith.extsi %126 : i32 to i64
%128 = llvm.getelementptr %94[%127] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%125 = llvm.load %128 : !llvm.ptr -> i64
%130 = llvm.load %106 : !llvm.ptr -> i32
%131 = arith.extsi %130 : i32 to i64
%132 = llvm.getelementptr %99[%131] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%129 = llvm.load %132 : !llvm.ptr -> i64
%133 = arith.cmpi sge, %125, %129 : i64
cf.cond_br %133, ^bb36, ^bb37
^bb36:
cf.br ^bb33
^bb37:
cf.br ^bb38
^bb38:
%134 = arith.addi %125, %129 : i64
%135 = arith.constant 2 : i32
%137 = arith.extsi %135 : i32 to i64
%136 = arith.divsi %134, %137 : i64
%139 = llvm.getelementptr %arg0[%136] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%138 = llvm.load %139 : !llvm.ptr -> i64
%141 = llvm.getelementptr %arg1[%136] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%140 = llvm.load %141 : !llvm.ptr -> i64
%142 = llvm.mlir.constant(1 : i64) : i64
%143 = llvm.alloca %142 x i64 : (i64) -> !llvm.ptr
llvm.store %125, %143 : i64, !llvm.ptr
%144 = llvm.mlir.constant(1 : i64) : i64
%145 = llvm.alloca %144 x i64 : (i64) -> !llvm.ptr
llvm.store %129, %145 : i64, !llvm.ptr
cf.br ^bb39
^bb39:
%146 = llvm.load %143 : !llvm.ptr -> i64
%147 = llvm.load %145 : !llvm.ptr -> i64
%148 = arith.cmpi sle, %146, %147 : i64
cf.cond_br %148, ^bb40, ^bb41
^bb40:
cf.br ^bb42
^bb42:
%151 = llvm.load %143 : !llvm.ptr -> i64
%152 = llvm.getelementptr %arg0[%151] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%150 = llvm.load %152 : !llvm.ptr -> i64
%154 = llvm.load %143 : !llvm.ptr -> i64
%155 = llvm.getelementptr %arg1[%154] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%153 = llvm.load %155 : !llvm.ptr -> i64
%149 = func.call @angle_less(%150, %153, %138, %140) : (i64, i64, i64, i64) -> i1
cf.cond_br %149, ^bb43, ^bb44
^bb43:
%156 = llvm.load %143 : !llvm.ptr -> i64
%157 = arith.constant 1 : i32
%159 = arith.extsi %157 : i32 to i64
%158 = arith.addi %156, %159 : i64
llvm.store %158, %143 : i64, !llvm.ptr
cf.br ^bb42
^bb44:
cf.br ^bb45
^bb45:
%162 = llvm.load %145 : !llvm.ptr -> i64
%163 = llvm.getelementptr %arg0[%162] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%161 = llvm.load %163 : !llvm.ptr -> i64
%165 = llvm.load %145 : !llvm.ptr -> i64
%166 = llvm.getelementptr %arg1[%165] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%164 = llvm.load %166 : !llvm.ptr -> i64
%160 = func.call @angle_less(%138, %140, %161, %164) : (i64, i64, i64, i64) -> i1
cf.cond_br %160, ^bb46, ^bb47
^bb46:
%167 = llvm.load %145 : !llvm.ptr -> i64
%168 = arith.constant 1 : i32
%170 = arith.extsi %168 : i32 to i64
%169 = arith.subi %167, %170 : i64
llvm.store %169, %145 : i64, !llvm.ptr
cf.br ^bb45
^bb47:
%171 = llvm.load %143 : !llvm.ptr -> i64
%172 = llvm.load %145 : !llvm.ptr -> i64
%173 = arith.cmpi sle, %171, %172 : i64
cf.cond_br %173, ^bb48, ^bb49
^bb48:
%175 = llvm.load %143 : !llvm.ptr -> i64
%176 = llvm.getelementptr %arg0[%175] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%174 = llvm.load %176 : !llvm.ptr -> i64
%178 = llvm.load %145 : !llvm.ptr -> i64
%179 = llvm.getelementptr %arg0[%178] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%177 = llvm.load %179 : !llvm.ptr -> i64
%180 = llvm.load %143 : !llvm.ptr -> i64
%181 = llvm.getelementptr %arg0[%180] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %177, %181 : i64, !llvm.ptr
%182 = llvm.load %145 : !llvm.ptr -> i64
%183 = llvm.getelementptr %arg0[%182] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %174, %183 : i64, !llvm.ptr
%185 = llvm.load %143 : !llvm.ptr -> i64
%186 = llvm.getelementptr %arg1[%185] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%184 = llvm.load %186 : !llvm.ptr -> i64
%188 = llvm.load %145 : !llvm.ptr -> i64
%189 = llvm.getelementptr %arg1[%188] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%187 = llvm.load %189 : !llvm.ptr -> i64
%190 = llvm.load %143 : !llvm.ptr -> i64
%191 = llvm.getelementptr %arg1[%190] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %187, %191 : i64, !llvm.ptr
%192 = llvm.load %145 : !llvm.ptr -> i64
%193 = llvm.getelementptr %arg1[%192] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %184, %193 : i64, !llvm.ptr
%194 = llvm.load %143 : !llvm.ptr -> i64
%195 = arith.constant 1 : i32
%197 = arith.extsi %195 : i32 to i64
%196 = arith.addi %194, %197 : i64
llvm.store %196, %143 : i64, !llvm.ptr
%198 = llvm.load %145 : !llvm.ptr -> i64
%199 = arith.constant 1 : i32
%201 = arith.extsi %199 : i32 to i64
%200 = arith.subi %198, %201 : i64
llvm.store %200, %145 : i64, !llvm.ptr
cf.br ^bb50
^bb49:
cf.br ^bb50
^bb50:
cf.br ^bb39
^bb41:
%202 = llvm.load %145 : !llvm.ptr -> i64
%203 = arith.cmpi slt, %125, %202 : i64
cf.cond_br %203, ^bb51, ^bb52
^bb51:
%204 = llvm.load %106 : !llvm.ptr -> i32
%205 = arith.extsi %204 : i32 to i64
%206 = llvm.getelementptr %94[%205] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %125, %206 : i64, !llvm.ptr
%207 = llvm.load %145 : !llvm.ptr -> i64
%208 = llvm.load %106 : !llvm.ptr -> i32
%209 = arith.extsi %208 : i32 to i64
%210 = llvm.getelementptr %99[%209] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %207, %210 : i64, !llvm.ptr
%211 = llvm.load %106 : !llvm.ptr -> i32
%212 = arith.constant 1 : i32
%213 = arith.addi %211, %212 : i32
llvm.store %213, %106 : i32, !llvm.ptr
cf.br ^bb53
^bb52:
cf.br ^bb53
^bb53:
%214 = llvm.load %143 : !llvm.ptr -> i64
%215 = arith.cmpi slt, %214, %129 : i64
cf.cond_br %215, ^bb54, ^bb55
^bb54:
%216 = llvm.load %143 : !llvm.ptr -> i64
%217 = llvm.load %106 : !llvm.ptr -> i32
%218 = arith.extsi %217 : i32 to i64
%219 = llvm.getelementptr %94[%218] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %216, %219 : i64, !llvm.ptr
%220 = llvm.load %106 : !llvm.ptr -> i32
%221 = arith.extsi %220 : i32 to i64
%222 = llvm.getelementptr %99[%221] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %129, %222 : i64, !llvm.ptr
%223 = llvm.load %106 : !llvm.ptr -> i32
%224 = arith.constant 1 : i32
%225 = arith.addi %223, %224 : i32
llvm.store %225, %106 : i32, !llvm.ptr
cf.br ^bb56
^bb55:
cf.br ^bb56
^bb56:
cf.br ^bb33
^bb35:
func.call @free(%94) : (!llvm.ptr) -> ()
func.call @free(%99) : (!llvm.ptr) -> ()
func.return
}
func.func @main() -> i32 {
%228 = arith.constant 2000000 : i32
%229 = arith.extsi %228 : i32 to i64
%231 = arith.constant 8 : i32
%232 = arith.extsi %231 : i32 to i64
%230 = func.call @calloc(%229, %232) : (i64, i64) -> !llvm.ptr
%234 = arith.constant 8 : i32
%235 = arith.extsi %234 : i32 to i64
%233 = func.call @calloc(%229, %235) : (i64, i64) -> !llvm.ptr
%236 = llvm.mlir.zero : !llvm.ptr
%237 = llvm.icmp "eq" %230, %236 : !llvm.ptr
%238 = scf.if %237 -> (i1) {
%239 = arith.constant true
scf.yield %239 : i1
} else {
%240 = llvm.mlir.zero : !llvm.ptr
%241 = llvm.icmp "eq" %233, %240 : !llvm.ptr
scf.yield %241 : i1
}
cf.cond_br %238, ^bb57, ^bb58
^bb57:
%242 = arith.constant 1 : i32
func.return %242 : i32
^bb58:
cf.br ^bb59
^bb59:
%243 = arith.constant 21 : i32
%244 = arith.extsi %243 : i32 to i64
%245 = arith.constant 1 : i32
%247 = arith.extsi %245 : i32 to i64
%246 = arith.shli %247, %244 : i64
%248 = arith.constant 1 : i32
%250 = arith.extsi %248 : i32 to i64
%249 = arith.subi %246, %250 : i64
%251 = arith.constant 1 : i32
%252 = arith.constant 22 : i32
%253 = arith.shli %251, %252 : i32
%254 = arith.extsi %253 : i32 to i64
%256 = arith.constant 8 : i32
%257 = arith.extsi %256 : i32 to i64
%255 = func.call @calloc(%254, %257) : (i64, i64) -> !llvm.ptr
%259 = arith.constant 8 : i32
%260 = arith.extsi %259 : i32 to i64
%258 = func.call @calloc(%254, %260) : (i64, i64) -> !llvm.ptr
%262 = arith.constant 8 : i32
%263 = arith.extsi %262 : i32 to i64
%261 = func.call @calloc(%254, %263) : (i64, i64) -> !llvm.ptr
%265 = arith.constant 1 : i32
%266 = arith.extsi %265 : i32 to i64
%264 = func.call @calloc(%254, %266) : (i64, i64) -> !llvm.ptr
%267 = llvm.mlir.zero : !llvm.ptr
%268 = llvm.icmp "eq" %255, %267 : !llvm.ptr
%269 = scf.if %268 -> (i1) {
%270 = arith.constant true
scf.yield %270 : i1
} else {
%271 = llvm.mlir.zero : !llvm.ptr
%272 = llvm.icmp "eq" %258, %271 : !llvm.ptr
scf.yield %272 : i1
}
%273 = scf.if %269 -> (i1) {
%274 = arith.constant true
scf.yield %274 : i1
} else {
%275 = llvm.mlir.zero : !llvm.ptr
%276 = llvm.icmp "eq" %261, %275 : !llvm.ptr
scf.yield %276 : i1
}
%277 = scf.if %273 -> (i1) {
%278 = arith.constant true
scf.yield %278 : i1
} else {
%279 = llvm.mlir.zero : !llvm.ptr
%280 = llvm.icmp "eq" %264, %279 : !llvm.ptr
scf.yield %280 : i1
}
cf.cond_br %277, ^bb60, ^bb61
^bb60:
%281 = arith.constant 1 : i32
func.return %281 : i32
^bb61:
cf.br ^bb62
^bb62:
%282 = arith.constant 32323 : i32
%283 = arith.extsi %282 : i32 to i64
%284 = arith.constant 30103 : i32
%285 = arith.extsi %284 : i32 to i64
%286 = arith.constant 1248 : i32
%287 = arith.extsi %286 : i32 to i64
%288 = arith.constant 8421 : i32
%289 = arith.extsi %288 : i32 to i64
%290 = arith.constant 1 : i32
%291 = arith.extsi %290 : i32 to i64
%292 = llvm.mlir.constant(1 : i64) : i64
%293 = llvm.alloca %292 x i64 : (i64) -> !llvm.ptr
llvm.store %291, %293 : i64, !llvm.ptr
%294 = arith.constant 1 : i32
%295 = arith.extsi %294 : i32 to i64
%296 = llvm.mlir.constant(1 : i64) : i64
%297 = llvm.alloca %296 x i64 : (i64) -> !llvm.ptr
llvm.store %295, %297 : i64, !llvm.ptr
%298 = arith.constant 0 : i32
%299 = arith.extsi %298 : i32 to i64
%300 = llvm.mlir.constant(1 : i64) : i64
%301 = llvm.alloca %300 x i64 : (i64) -> !llvm.ptr
llvm.store %299, %301 : i64, !llvm.ptr
%302 = arith.constant 0 : i32
%303 = arith.extsi %302 : i32 to i64
%304 = llvm.mlir.constant(1 : i64) : i64
%305 = llvm.alloca %304 x i64 : (i64) -> !llvm.ptr
llvm.store %303, %305 : i64, !llvm.ptr
cf.br ^bb63
^bb63:
%306 = llvm.load %305 : !llvm.ptr -> i64
%307 = arith.cmpi slt, %306, %229 : i64
cf.cond_br %307, ^bb64, ^bb65
^bb64:
%308 = llvm.load %293 : !llvm.ptr -> i64
%309 = arith.muli %308, %287 : i64
%310 = arith.remsi %309, %283 : i64
llvm.store %310, %293 : i64, !llvm.ptr
%311 = llvm.load %297 : !llvm.ptr -> i64
%312 = arith.muli %311, %289 : i64
%313 = arith.remsi %312, %285 : i64
llvm.store %313, %297 : i64, !llvm.ptr
%314 = llvm.load %293 : !llvm.ptr -> i64
%315 = arith.constant 16161 : i32
%317 = arith.extsi %315 : i32 to i64
%316 = arith.subi %314, %317 : i64
%318 = llvm.load %297 : !llvm.ptr -> i64
%319 = arith.constant 15051 : i32
%321 = arith.extsi %319 : i32 to i64
%320 = arith.subi %318, %321 : i64
%322 = arith.constant 0 : i32
%324 = arith.extsi %322 : i32 to i64
%323 = arith.cmpi eq, %316, %324 : i64
%325 = scf.if %323 -> (i1) {
%326 = arith.constant 0 : i32
%328 = arith.extsi %326 : i32 to i64
%327 = arith.cmpi eq, %320, %328 : i64
scf.yield %327 : i1
} else {
%329 = arith.constant false
scf.yield %329 : i1
}
%331 = arith.constant 1 : i1
%330 = arith.xori %325, %331 : i1
cf.cond_br %330, ^bb66, ^bb67
^bb66:
%333 = llvm.load %301 : !llvm.ptr -> i64
%334 = llvm.getelementptr %230[%333] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %316, %334 : i64, !llvm.ptr
%335 = llvm.load %301 : !llvm.ptr -> i64
%336 = llvm.getelementptr %233[%335] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %320, %336 : i64, !llvm.ptr
%337 = llvm.load %301 : !llvm.ptr -> i64
%338 = arith.constant 1 : i32
%340 = arith.extsi %338 : i32 to i64
%339 = arith.addi %337, %340 : i64
llvm.store %339, %301 : i64, !llvm.ptr
%341 = func.call @gcd_abs(%316, %320) : (i64, i64) -> i64
%342 = arith.divsi %316, %341 : i64
%343 = llvm.mlir.constant(1 : i64) : i64
%344 = llvm.alloca %343 x i64 : (i64) -> !llvm.ptr
llvm.store %342, %344 : i64, !llvm.ptr
%345 = arith.divsi %320, %341 : i64
%346 = llvm.mlir.constant(1 : i64) : i64
%347 = llvm.alloca %346 x i64 : (i64) -> !llvm.ptr
llvm.store %345, %347 : i64, !llvm.ptr
%348 = arith.constant 1 : i1
%349 = llvm.mlir.constant(1 : i64) : i64
%350 = llvm.alloca %349 x i1 : (i64) -> !llvm.ptr
llvm.store %348, %350 : i1, !llvm.ptr
%351 = llvm.load %344 : !llvm.ptr -> i64
%352 = arith.constant 0 : i32
%354 = arith.extsi %352 : i32 to i64
%353 = arith.cmpi sgt, %351, %354 : i64
cf.cond_br %353, ^bb69, ^bb70
^bb69:
%355 = arith.constant 1 : i1
llvm.store %355, %350 : i1, !llvm.ptr
cf.br ^bb71
^bb70:
%356 = llvm.load %344 : !llvm.ptr -> i64
%357 = arith.constant 0 : i32
%359 = arith.extsi %357 : i32 to i64
%358 = arith.cmpi eq, %356, %359 : i64
cf.cond_br %358, ^bb72, ^bb73
^bb72:
%360 = llvm.load %347 : !llvm.ptr -> i64
%361 = arith.constant 0 : i32
%363 = arith.extsi %361 : i32 to i64
%362 = arith.cmpi sgt, %360, %363 : i64
cf.cond_br %362, ^bb75, ^bb76
^bb75:
%364 = arith.constant 1 : i1
llvm.store %364, %350 : i1, !llvm.ptr
cf.br ^bb77
^bb76:
%365 = arith.constant 0 : i1
llvm.store %365, %350 : i1, !llvm.ptr
%366 = arith.constant 0 : i32
%367 = llvm.load %344 : !llvm.ptr -> i64
%369 = arith.extsi %366 : i32 to i64
%368 = arith.subi %369, %367 : i64
llvm.store %368, %344 : i64, !llvm.ptr
%370 = arith.constant 0 : i32
%371 = llvm.load %347 : !llvm.ptr -> i64
%373 = arith.extsi %370 : i32 to i64
%372 = arith.subi %373, %371 : i64
llvm.store %372, %347 : i64, !llvm.ptr
cf.br ^bb77
^bb77:
cf.br ^bb74
^bb73:
%374 = arith.constant 0 : i1
llvm.store %374, %350 : i1, !llvm.ptr
%375 = arith.constant 0 : i32
%376 = llvm.load %344 : !llvm.ptr -> i64
%378 = arith.extsi %375 : i32 to i64
%377 = arith.subi %378, %376 : i64
llvm.store %377, %344 : i64, !llvm.ptr
%379 = arith.constant 0 : i32
%380 = llvm.load %347 : !llvm.ptr -> i64
%382 = arith.extsi %379 : i32 to i64
%381 = arith.subi %382, %380 : i64
llvm.store %381, %347 : i64, !llvm.ptr
cf.br ^bb74
^bb74:
cf.br ^bb71
^bb71:
%383 = llvm.load %344 : !llvm.ptr -> i64
%384 = arith.constant 1315423911 : i32
%386 = arith.extsi %384 : i32 to i64
%385 = arith.muli %383, %386 : i64
%387 = llvm.load %347 : !llvm.ptr -> i64
%388 = arith.constant -1640531535 : i32
%390 = arith.extsi %388 : i32 to i64
%389 = arith.muli %387, %390 : i64
%391 = arith.addi %385, %389 : i64
%392 = arith.remsi %391, %254 : i64
%393 = llvm.mlir.constant(1 : i64) : i64
%394 = llvm.alloca %393 x i64 : (i64) -> !llvm.ptr
llvm.store %392, %394 : i64, !llvm.ptr
%395 = llvm.load %394 : !llvm.ptr -> i64
%396 = arith.constant 0 : i32
%398 = arith.extsi %396 : i32 to i64
%397 = arith.cmpi slt, %395, %398 : i64
cf.cond_br %397, ^bb78, ^bb79
^bb78:
%399 = llvm.load %394 : !llvm.ptr -> i64
%400 = arith.addi %399, %254 : i64
llvm.store %400, %394 : i64, !llvm.ptr
cf.br ^bb80
^bb79:
cf.br ^bb80
^bb80:
cf.br ^bb81
^bb81:
%402 = llvm.load %394 : !llvm.ptr -> i64
%403 = llvm.getelementptr %264[%402] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%401 = llvm.load %403 : !llvm.ptr -> i8
%404 = arith.constant 1 : i32
%406 = arith.extsi %401 : i8 to i32
%405 = arith.cmpi eq, %406, %404 : i32
cf.cond_br %405, ^bb82, ^bb83
^bb82:
%408 = llvm.load %394 : !llvm.ptr -> i64
%409 = llvm.getelementptr %255[%408] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%407 = llvm.load %409 : !llvm.ptr -> i64
%410 = llvm.load %344 : !llvm.ptr -> i64
%411 = arith.cmpi eq, %407, %410 : i64
cf.cond_br %411, ^bb84, ^bb85
^bb84:
%413 = llvm.load %394 : !llvm.ptr -> i64
%414 = llvm.getelementptr %258[%413] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%412 = llvm.load %414 : !llvm.ptr -> i64
%415 = llvm.load %347 : !llvm.ptr -> i64
%416 = arith.cmpi eq, %412, %415 : i64
cf.cond_br %416, ^bb87, ^bb88
^bb87:
cf.br ^bb83
^bb88:
cf.br ^bb89
^bb89:
cf.br ^bb86
^bb85:
cf.br ^bb86
^bb86:
%417 = llvm.load %394 : !llvm.ptr -> i64
%418 = arith.constant 1 : i32
%420 = arith.extsi %418 : i32 to i64
%419 = arith.addi %417, %420 : i64
llvm.store %419, %394 : i64, !llvm.ptr
%421 = llvm.load %394 : !llvm.ptr -> i64
%422 = arith.cmpi sge, %421, %254 : i64
cf.cond_br %422, ^bb90, ^bb91
^bb90:
%423 = arith.constant 0 : i32
%424 = arith.extsi %423 : i32 to i64
llvm.store %424, %394 : i64, !llvm.ptr
cf.br ^bb92
^bb91:
cf.br ^bb92
^bb92:
cf.br ^bb81
^bb83:
%426 = llvm.load %394 : !llvm.ptr -> i64
%427 = llvm.getelementptr %264[%426] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%425 = llvm.load %427 : !llvm.ptr -> i8
%428 = arith.constant 0 : i32
%430 = arith.extsi %425 : i8 to i32
%429 = arith.cmpi eq, %430, %428 : i32
cf.cond_br %429, ^bb93, ^bb94
^bb93:
%431 = arith.constant 1 : i32
%432 = llvm.load %394 : !llvm.ptr -> i64
%433 = arith.trunci %431 : i32 to i8
%434 = llvm.getelementptr %264[%432] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %433, %434 : i8, !llvm.ptr
%435 = llvm.load %344 : !llvm.ptr -> i64
%436 = llvm.load %394 : !llvm.ptr -> i64
%437 = llvm.getelementptr %255[%436] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %435, %437 : i64, !llvm.ptr
%438 = llvm.load %347 : !llvm.ptr -> i64
%439 = llvm.load %394 : !llvm.ptr -> i64
%440 = llvm.getelementptr %258[%439] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %438, %440 : i64, !llvm.ptr
%441 = arith.constant 0 : i32
%442 = llvm.load %394 : !llvm.ptr -> i64
%443 = arith.extsi %441 : i32 to i64
%444 = llvm.getelementptr %261[%442] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %443, %444 : i64, !llvm.ptr
cf.br ^bb95
^bb94:
cf.br ^bb95
^bb95:
%445 = llvm.load %350 : !llvm.ptr -> i1
cf.cond_br %445, ^bb96, ^bb97
^bb96:
%447 = llvm.load %394 : !llvm.ptr -> i64
%448 = llvm.getelementptr %261[%447] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%446 = llvm.load %448 : !llvm.ptr -> i64
%449 = arith.constant 1 : i32
%451 = arith.extsi %449 : i32 to i64
%450 = arith.addi %446, %451 : i64
%452 = llvm.load %394 : !llvm.ptr -> i64
%453 = llvm.getelementptr %261[%452] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %450, %453 : i64, !llvm.ptr
cf.br ^bb98
^bb97:
%455 = llvm.load %394 : !llvm.ptr -> i64
%456 = llvm.getelementptr %261[%455] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%454 = llvm.load %456 : !llvm.ptr -> i64
%457 = arith.constant 1 : i32
%459 = arith.extsi %457 : i32 to i64
%458 = arith.shli %459, %244 : i64
%460 = arith.addi %454, %458 : i64
%461 = llvm.load %394 : !llvm.ptr -> i64
%462 = llvm.getelementptr %261[%461] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %460, %462 : i64, !llvm.ptr
cf.br ^bb98
^bb98:
cf.br ^bb68
^bb67:
cf.br ^bb68
^bb68:
%463 = llvm.load %305 : !llvm.ptr -> i64
%464 = arith.constant 1 : i32
%466 = arith.extsi %464 : i32 to i64
%465 = arith.addi %463, %466 : i64
llvm.store %465, %305 : i64, !llvm.ptr
cf.br ^bb63
^bb65:
%467 = llvm.load %301 : !llvm.ptr -> i64
%468 = arith.constant 3 : i32
%470 = arith.extsi %468 : i32 to i64
%469 = arith.cmpi slt, %467, %470 : i64
cf.cond_br %469, ^bb99, ^bb100
^bb99:
%471 = llvm.mlir.addressof @str_0 : !llvm.ptr
%472 = arith.constant 0 : i32
%473 = arith.extsi %472 : i32 to i64
%474 = llvm.call @printf(%471, %473) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
%475 = arith.constant 0 : i32
func.return %475 : i32
^bb100:
cf.br ^bb101
^bb101:
%477 = llvm.load %301 : !llvm.ptr -> i64
func.call @sort_points(%230, %233, %477) : (!llvm.ptr, !llvm.ptr, i64) -> ()
%478 = arith.constant 0 : i32
%479 = arith.extsi %478 : i32 to i64
%480 = llvm.mlir.constant(1 : i64) : i64
%481 = llvm.alloca %480 x i64 : (i64) -> !llvm.ptr
llvm.store %479, %481 : i64, !llvm.ptr
%482 = arith.constant 1 : i32
%483 = arith.extsi %482 : i32 to i64
%484 = llvm.mlir.constant(1 : i64) : i64
%485 = llvm.alloca %484 x i64 : (i64) -> !llvm.ptr
llvm.store %483, %485 : i64, !llvm.ptr
%486 = arith.constant 0 : i32
%487 = arith.extsi %486 : i32 to i64
%488 = llvm.mlir.constant(1 : i64) : i64
%489 = llvm.alloca %488 x i64 : (i64) -> !llvm.ptr
llvm.store %487, %489 : i64, !llvm.ptr
cf.br ^bb102
^bb102:
%490 = llvm.load %489 : !llvm.ptr -> i64
%491 = llvm.load %301 : !llvm.ptr -> i64
%492 = arith.cmpi slt, %490, %491 : i64
cf.cond_br %492, ^bb103, ^bb104
^bb103:
%493 = llvm.load %485 : !llvm.ptr -> i64
%494 = llvm.load %489 : !llvm.ptr -> i64
%495 = arith.constant 1 : i32
%497 = arith.extsi %495 : i32 to i64
%496 = arith.addi %494, %497 : i64
%498 = arith.cmpi slt, %493, %496 : i64
cf.cond_br %498, ^bb105, ^bb106
^bb105:
%499 = llvm.load %489 : !llvm.ptr -> i64
%500 = arith.constant 1 : i32
%502 = arith.extsi %500 : i32 to i64
%501 = arith.addi %499, %502 : i64
llvm.store %501, %485 : i64, !llvm.ptr
cf.br ^bb107
^bb106:
cf.br ^bb107
^bb107:
%504 = llvm.load %489 : !llvm.ptr -> i64
%505 = llvm.getelementptr %230[%504] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%503 = llvm.load %505 : !llvm.ptr -> i64
%507 = llvm.load %489 : !llvm.ptr -> i64
%508 = llvm.getelementptr %233[%507] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%506 = llvm.load %508 : !llvm.ptr -> i64
cf.br ^bb108
^bb108:
%509 = llvm.load %485 : !llvm.ptr -> i64
%510 = llvm.load %489 : !llvm.ptr -> i64
%511 = llvm.load %301 : !llvm.ptr -> i64
%512 = arith.addi %510, %511 : i64
%513 = arith.cmpi slt, %509, %512 : i64
cf.cond_br %513, ^bb109, ^bb110
^bb109:
%515 = llvm.load %485 : !llvm.ptr -> i64
%516 = llvm.load %301 : !llvm.ptr -> i64
%517 = arith.remsi %515, %516 : i64
%518 = llvm.getelementptr %230[%517] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%514 = llvm.load %518 : !llvm.ptr -> i64
%520 = llvm.load %485 : !llvm.ptr -> i64
%521 = llvm.load %301 : !llvm.ptr -> i64
%522 = arith.remsi %520, %521 : i64
%523 = llvm.getelementptr %233[%522] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%519 = llvm.load %523 : !llvm.ptr -> i64
%524 = func.call @open_lt_pi(%503, %506, %514, %519) : (i64, i64, i64, i64) -> i1
cf.cond_br %524, ^bb111, ^bb112
^bb111:
%525 = llvm.load %485 : !llvm.ptr -> i64
%526 = arith.constant 1 : i32
%528 = arith.extsi %526 : i32 to i64
%527 = arith.addi %525, %528 : i64
llvm.store %527, %485 : i64, !llvm.ptr
cf.br ^bb113
^bb112:
cf.br ^bb110
^bb113:
cf.br ^bb108
^bb110:
%529 = llvm.load %485 : !llvm.ptr -> i64
%530 = llvm.load %489 : !llvm.ptr -> i64
%531 = arith.subi %529, %530 : i64
%532 = arith.constant 1 : i32
%534 = arith.extsi %532 : i32 to i64
%533 = arith.subi %531, %534 : i64
%535 = llvm.load %481 : !llvm.ptr -> i64
%536 = arith.constant 1 : i32
%538 = arith.extsi %536 : i32 to i64
%537 = arith.subi %533, %538 : i64
%539 = arith.muli %533, %537 : i64
%540 = arith.constant 2 : i32
%542 = arith.extsi %540 : i32 to i64
%541 = arith.divsi %539, %542 : i64
%543 = arith.addi %535, %541 : i64
llvm.store %543, %481 : i64, !llvm.ptr
%544 = llvm.load %489 : !llvm.ptr -> i64
%545 = arith.constant 1 : i32
%547 = arith.extsi %545 : i32 to i64
%546 = arith.addi %544, %547 : i64
llvm.store %546, %489 : i64, !llvm.ptr
cf.br ^bb102
^bb104:
%548 = arith.constant 0 : i32
%549 = arith.extsi %548 : i32 to i64
%550 = llvm.mlir.constant(1 : i64) : i64
%551 = llvm.alloca %550 x i64 : (i64) -> !llvm.ptr
llvm.store %549, %551 : i64, !llvm.ptr
%552 = arith.constant 0 : i32
%553 = arith.extsi %552 : i32 to i64
%554 = llvm.mlir.constant(1 : i64) : i64
%555 = llvm.alloca %554 x i64 : (i64) -> !llvm.ptr
llvm.store %553, %555 : i64, !llvm.ptr
cf.br ^bb114
^bb114:
%556 = llvm.load %555 : !llvm.ptr -> i64
%557 = arith.cmpi slt, %556, %254 : i64
cf.cond_br %557, ^bb115, ^bb116
^bb115:
%559 = llvm.load %555 : !llvm.ptr -> i64
%560 = llvm.getelementptr %264[%559] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%558 = llvm.load %560 : !llvm.ptr -> i8
%561 = arith.constant 1 : i32
%563 = arith.extsi %558 : i8 to i32
%562 = arith.cmpi eq, %563, %561 : i32
cf.cond_br %562, ^bb117, ^bb118
^bb117:
%565 = llvm.load %555 : !llvm.ptr -> i64
%566 = llvm.getelementptr %261[%565] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%564 = llvm.load %566 : !llvm.ptr -> i64
%567 = arith.andi %564, %249 : i64
%568 = arith.shrsi %564, %244 : i64
%569 = arith.constant 0 : i32
%571 = arith.extsi %569 : i32 to i64
%570 = arith.cmpi sgt, %567, %571 : i64
cf.cond_br %570, ^bb120, ^bb121
^bb120:
%572 = arith.constant 0 : i32
%574 = arith.extsi %572 : i32 to i64
%573 = arith.cmpi sgt, %568, %574 : i64
cf.cond_br %573, ^bb123, ^bb124
^bb123:
%575 = arith.addi %567, %568 : i64
%576 = llvm.load %551 : !llvm.ptr -> i64
%577 = arith.muli %567, %568 : i64
%578 = llvm.load %301 : !llvm.ptr -> i64
%579 = arith.subi %578, %575 : i64
%580 = arith.muli %577, %579 : i64
%581 = arith.addi %576, %580 : i64
llvm.store %581, %551 : i64, !llvm.ptr
%582 = llvm.load %551 : !llvm.ptr -> i64
%583 = func.call @comb3(%575) : (i64) -> i64
%584 = arith.addi %582, %583 : i64
%585 = func.call @comb3(%567) : (i64) -> i64
%586 = arith.subi %584, %585 : i64
%587 = func.call @comb3(%568) : (i64) -> i64
%588 = arith.subi %586, %587 : i64
llvm.store %588, %551 : i64, !llvm.ptr
cf.br ^bb125
^bb124:
cf.br ^bb125
^bb125:
cf.br ^bb122
^bb121:
cf.br ^bb122
^bb122:
cf.br ^bb119
^bb118:
cf.br ^bb119
^bb119:
%589 = llvm.load %555 : !llvm.ptr -> i64
%590 = arith.constant 1 : i32
%592 = arith.extsi %590 : i32 to i64
%591 = arith.addi %589, %592 : i64
llvm.store %591, %555 : i64, !llvm.ptr
cf.br ^bb114
^bb116:
%594 = llvm.load %301 : !llvm.ptr -> i64
%593 = func.call @comb3(%594) : (i64) -> i64
%595 = llvm.mlir.addressof @str_0 : !llvm.ptr
%596 = llvm.load %481 : !llvm.ptr -> i64
%597 = arith.subi %593, %596 : i64
%598 = llvm.load %551 : !llvm.ptr -> i64
%599 = arith.subi %597, %598 : i64
%600 = llvm.call @printf(%595, %599) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
func.call @free(%230) : (!llvm.ptr) -> ()
func.call @free(%233) : (!llvm.ptr) -> ()
func.call @free(%255) : (!llvm.ptr) -> ()
func.call @free(%258) : (!llvm.ptr) -> ()
func.call @free(%261) : (!llvm.ptr) -> ()
func.call @free(%264) : (!llvm.ptr) -> ()
%607 = arith.constant 0 : i32
func.return %607 : i32
}
}