Problem 972

Rational triangles on the unit sphere. Ported from native C to pure Flow.

Answer3575508
Output3575508
StatusPASS
Native helperno
Runtime2330 ms
Peak memory1472 KB
Time complexityO(n^2) (estimated)
Space complexityO(1) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^2)O(n^2)
Space complexityO(1)O(n^2)
ApproachFlow solutionBottom-up DP
VerdictOptimal

Flow source

# Project Euler 972
# Rational triangles on the unit sphere.
# Ported from native C to pure Flow.

import euler.nt { gcd }

extern {
    function calloc(n: i64, size: i64) -> ptr<void>
    function malloc(n: i64) -> ptr<void>
    function realloc(p: ptr<void>, n: i64) -> ptr<void>
    function free(p: ptr<void>)
    function printf(fmt: ptr<i8>, ...) -> i32
}

function gcd64(a0: i64, b0: i64) -> i64 {
    let mut a: i64 = if a0 < 0 { -a0 } else { a0 }
    let mut b: i64 = if b0 < 0 { -b0 } else { b0 }
    while b != 0 {
        let t: i64 = a % b
        a = b
        b = t
    }
    return a
}

function lcm64(a: i64, b: i64) -> i64 {
    return a / gcd64(a, b) * b
}

# Global state
let mut g_scale: i64 = 0
let mut g_coords: ptr<i64> = null
let mut g_ncoords: i32 = 0
let mut g_px: ptr<i64> = null
let mut g_py: ptr<i64> = null
let mut g_pz: ptr<i64> = null
let mut g_npoints: i32 = 0

# Heapsort for i64 array
function sift_down_i64(arr: ptr<i64>, start: i64, end: i64) -> void {
    let mut root: i64 = start
    while 2 * root + 1 <= end {
        let mut child: i64 = 2 * root + 1
        if child + 1 <= end && arr[child] < arr[child + 1] {
            child = child + 1
        }
        if arr[root] < arr[child] {
            let tmp: i64 = arr[root]
            arr[root] = arr[child]
            arr[child] = tmp
            root = child
        } else {
            break
        }
    }
}

function heapsort_i64(arr: ptr<i64>, n: i64) -> void {
    if n <= 1 { return }
    let mut start: i64 = n / 2 - 1
    while start >= 0 {
        sift_down_i64(arr, start, n - 1)
        start = start - 1
    }
    let mut end: i64 = n - 1
    while end > 0 {
        let tmp: i64 = arr[0]
        arr[0] = arr[end]
        arr[end] = tmp
        end = end - 1
        sift_down_i64(arr, 0, end)
    }
}

# Heapsort for key pairs (a, b) lexicographic
function sift_down_keys(ka: ptr<i64>, kb: ptr<i64>, start: i64, end: i64) -> void {
    let mut root: i64 = start
    while 2 * root + 1 <= end {
        let mut child: i64 = 2 * root + 1
        if child + 1 <= end {
            let ca: i64 = ka[child]
            let cb: i64 = kb[child]
            let cca: i64 = ka[child + 1]
            let ccb: i64 = kb[child + 1]
            if ca < cca || (ca == cca && cb < ccb) {
                child = child + 1
            }
        }
        let ra: i64 = ka[root]
        let rb: i64 = kb[root]
        let ca2: i64 = ka[child]
        let cb2: i64 = kb[child]
        if ra < ca2 || (ra == ca2 && rb < cb2) {
            let tmpa: i64 = ka[root]
            let tmpb: i64 = kb[root]
            ka[root] = ka[child]
            kb[root] = kb[child]
            ka[child] = tmpa
            kb[child] = tmpb
            root = child
        } else {
            break
        }
    }
}

function heapsort_keys(ka: ptr<i64>, kb: ptr<i64>, n: i64) -> void {
    if n <= 1 { return }
    let mut start: i64 = n / 2 - 1
    while start >= 0 {
        sift_down_keys(ka, kb, start, n - 1)
        start = start - 1
    }
    let mut end: i64 = n - 1
    while end > 0 {
        let tmpa: i64 = ka[0]
        let tmpb: i64 = kb[0]
        ka[0] = ka[end]
        kb[0] = kb[end]
        ka[end] = tmpa
        kb[end] = tmpb
        end = end - 1
        sift_down_keys(ka, kb, 0, end)
    }
}

function coordinate_values(n: i32) -> void {
    g_scale = 1
    let mut d: i32 = 1
    while d <= n {
        g_scale = lcm64(g_scale, d as i64)
        d = d + 1
    }

    let mut cap: i32 = 256
    g_coords = malloc((cap as i64) * 8) as ptr<i64>
    g_ncoords = 0
    g_coords[0] = 0
    g_ncoords = 1

    let mut d2: i32 = 2
    while d2 <= n {
        let step: i64 = g_scale / (d2 as i64)
        let mut a: i32 = 1
        while a < d2 {
            if gcd64(a as i64, d2 as i64) == 1 {
                let v: i64 = (a as i64) * step
                if g_ncoords + 2 > cap {
                    cap = cap * 2
                    g_coords = realloc(g_coords as ptr<void>, (cap as i64) * 8) as ptr<i64>
                }
                g_coords[g_ncoords] = v
                g_ncoords = g_ncoords + 1
                g_coords[g_ncoords] = -v
                g_ncoords = g_ncoords + 1
            }
            a = a + 1
        }
        d2 = d2 + 1
    }

    heapsort_i64(g_coords, g_ncoords as i64)

    let mut w: i32 = 0
    let mut i: i32 = 0
    while i < g_ncoords {
        if i == 0 || g_coords[i] != g_coords[i - 1] {
            g_coords[w] = g_coords[i]
            w = w + 1
        }
        i = i + 1
    }
    g_ncoords = w
}

function build_lifted_points(n: i32) -> void {
    coordinate_values(n)
    let scale2: i64 = g_scale * g_scale

    let sq: ptr<i64> = malloc((g_ncoords as i64) * 8) as ptr<i64>
    let mut i: i32 = 0
    while i < g_ncoords {
        sq[i] = g_coords[i] * g_coords[i]
        i = i + 1
    }

    let mut cap: i32 = 1 << 16
    g_px = malloc((cap as i64) * 8) as ptr<i64>
    g_py = malloc((cap as i64) * 8) as ptr<i64>
    g_pz = malloc((cap as i64) * 8) as ptr<i64>
    g_npoints = 0

    let mut xi: i32 = 0
    while xi < g_ncoords {
        let x: i64 = g_coords[xi]
        let x2: i64 = sq[xi]
        let mut yi: i32 = 0
        while yi < g_ncoords {
            let z0: i64 = x2 + sq[yi]
            if z0 < scale2 {
                if g_npoints >= cap {
                    cap = cap * 2
                    g_px = realloc(g_px as ptr<void>, (cap as i64) * 8) as ptr<i64>
                    g_py = realloc(g_py as ptr<void>, (cap as i64) * 8) as ptr<i64>
                    g_pz = realloc(g_pz as ptr<void>, (cap as i64) * 8) as ptr<i64>
                }
                g_px[g_npoints] = x
                g_py[g_npoints] = g_coords[yi]
                g_pz[g_npoints] = z0 + scale2
                g_npoints = g_npoints + 1
            }
            yi = yi + 1
        }
        xi = xi + 1
    }

    free(sq as ptr<void>)
}

function count_unordered_triples() -> i64 {
    let mut total: i64 = 0
    let m: i32 = g_npoints

    let ka: ptr<i64> = malloc((m as i64) * 8) as ptr<i64>
    let kb: ptr<i64> = malloc((m as i64) * 8) as ptr<i64>

    let mut i: i32 = 0
    while i < m - 2 {
        let px: i64 = g_px[i]
        let py: i64 = g_py[i]
        let pz: i64 = g_pz[i]
        let mut nk: i32 = 0

        if px != 0 {
            let mut j: i32 = i + 1
            while j < m {
                let qx: i64 = g_px[j]
                let qy: i64 = g_py[j]
                let qz: i64 = g_pz[j]
                let mut a: i64 = py * qx - px * qy
                let mut b: i64 = pz * qx - px * qz
                let g: i64 = gcd64(a, b)
                if g != 0 {
                    a = a / g
                    b = b / g
                }
                if a < 0 || (a == 0 && b < 0) {
                    a = -a
                    b = -b
                }
                ka[nk] = a
                kb[nk] = b
                nk = nk + 1
                j = j + 1
            }
        } else {
            let mut j: i32 = i + 1
            while j < m {
                let qx: i64 = g_px[j]
                let qy: i64 = g_py[j]
                let qz: i64 = g_pz[j]
                let mut a: i64 = qx
                let mut b: i64 = pz * qy - py * qz
                let g: i64 = gcd64(a, b)
                if g != 0 {
                    a = a / g
                    b = b / g
                }
                if a < 0 || (a == 0 && b < 0) {
                    a = -a
                    b = -b
                }
                ka[nk] = a
                kb[nk] = b
                nk = nk + 1
                j = j + 1
            }
        }

        heapsort_keys(ka, kb, nk as i64)

        let mut run_len: i64 = 1
        let mut prev_a: i64 = ka[0]
        let mut prev_b: i64 = kb[0]
        let mut k: i32 = 1
        while k < nk {
            if ka[k] == prev_a && kb[k] == prev_b {
                run_len = run_len + 1
            } else {
                if run_len >= 2 {
                    total = total + run_len * (run_len - 1) / 2
                }
                prev_a = ka[k]
                prev_b = kb[k]
                run_len = 1
            }
            k = k + 1
        }
        if run_len >= 2 {
            total = total + run_len * (run_len - 1) / 2
        }

        i = i + 1
    }

    free(ka as ptr<void>)
    free(kb as ptr<void>)
    return total
}

function compute_T(n: i32) -> i64 {
    build_lifted_points(n)
    let c: i64 = count_unordered_triples()
    let result: i64 = 6 * c
    free(g_coords as ptr<void>)
    free(g_px as ptr<void>)
    free(g_py as ptr<void>)
    free(g_pz as ptr<void>)
    return result
}

function main() -> i32 {
    printf("%lld\n", compute_T(12))
    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_i64_i64(int64_t a0, int64_t b0);
int64_t lcm_i64_i64(int64_t a, int64_t b);
int64_t isqrt_i64(int64_t n);
int64_t mulmod_i64_i64_i64(int64_t a0, int64_t b0, int64_t mod);
int64_t mod_pow_i64_i64_i64(int64_t base, int64_t exp, int64_t mod);
bool is_prime_i64(int64_t n);
int64_t gcd64_i64_i64(int64_t a0, int64_t b0);
int64_t lcm64_i64_i64(int64_t a, int64_t b);
void sift_down_i64_ptr_i64_i64_i64(int64_t* arr, int64_t start, int64_t end);
void heapsort_i64_ptr_i64_i64(int64_t* arr, int64_t n);
void sift_down_keys_ptr_i64_ptr_i64_i64_i64(int64_t* ka, int64_t* kb, int64_t start, int64_t end);
void heapsort_keys_ptr_i64_ptr_i64_i64(int64_t* ka, int64_t* kb, int64_t n);
void coordinate_values_i32(int32_t n);
void build_lifted_points_i32(int32_t n);
int64_t count_unordered_triples(void);
int64_t compute_T_i32(int32_t n);
int32_t main(void);

/* Module statics */
static int64_t g_scale = 0;
static int64_t* g_coords = NULL;
static int32_t g_ncoords = 0;
static int64_t* g_px = NULL;
static int64_t* g_py = NULL;
static int64_t* g_pz = NULL;
static int32_t g_npoints = 0;

int64_t gcd_i64_i64(int64_t a0, int64_t b0) {
    int64_t a = a0;
    int64_t b = b0;
    while (b != 0) {
        int64_t t = FLOW_CHECKED_MOD((a), (b));
        a = b;
        b = t;
    }
    return a;
}

int64_t lcm_i64_i64(int64_t a, int64_t b) {
    if ((a == 0 || b == 0)) {
        return 0;
    }
    return (FLOW_CHECKED_DIV((a), (gcd_i64_i64(a, b))) * b);
}

int64_t isqrt_i64(int64_t n) {
    if (n < 2) {
        return n;
    }
    int64_t x = n;
    int64_t y = FLOW_CHECKED_DIV(((x + 1)), (2));
    while (y < x) {
        x = y;
        y = FLOW_CHECKED_DIV(((x + FLOW_CHECKED_DIV((n), (x)))), (2));
    }
    return x;
}

int64_t mulmod_i64_i64_i64(int64_t a0, int64_t b0, int64_t mod) {
    int64_t a = FLOW_CHECKED_MOD((a0), (mod));
    int64_t b = FLOW_CHECKED_MOD((b0), (mod));
    int64_t result = 0;
    while (b > 0) {
        if (FLOW_CHECKED_MOD((b), (2)) == 1) {
            result = FLOW_CHECKED_MOD(((result + a)), (mod));
        }
        a = FLOW_CHECKED_MOD(((a * 2)), (mod));
        b = FLOW_CHECKED_DIV((b), (2));
    }
    return result;
}

int64_t mod_pow_i64_i64_i64(int64_t base, int64_t exp, int64_t mod) {
    if (mod == 1) {
        return 0;
    }
    int64_t result = 1;
    int64_t b = FLOW_CHECKED_MOD((base), (mod));
    int64_t e = exp;
    while (e > 0) {
        if (FLOW_CHECKED_MOD((e), (2)) == 1) {
            result = mulmod_i64_i64_i64(result, b, mod);
        }
        b = mulmod_i64_i64_i64(b, b, mod);
        e = FLOW_CHECKED_DIV((e), (2));
    }
    return result;
}

bool is_prime_i64(int64_t n) {
    if (n < 2) {
        return 0;
    }
    if (n < 4) {
        return 1;
    }
    if ((FLOW_CHECKED_MOD((n), (2)) == 0 || FLOW_CHECKED_MOD((n), (3)) == 0)) {
        return 0;
    }
    int64_t i = 5;
    while ((i * i) <= n) {
        if ((FLOW_CHECKED_MOD((n), (i)) == 0 || FLOW_CHECKED_MOD((n), ((i + 2))) == 0)) {
            return 0;
        }
        i = (i + 6);
    }
    return 1;
}






int64_t gcd64_i64_i64(int64_t a0, int64_t b0) {
    int64_t a = ((a0 < 0) ? ((-a0)) : (a0));
    int64_t b = ((b0 < 0) ? ((-b0)) : (b0));
    while (b != 0) {
        int64_t t = FLOW_CHECKED_MOD((a), (b));
        a = b;
        b = t;
    }
    return a;
}

int64_t lcm64_i64_i64(int64_t a, int64_t b) {
    return (FLOW_CHECKED_DIV((a), (gcd64_i64_i64(a, b))) * b);
}

void sift_down_i64_ptr_i64_i64_i64(int64_t* arr, int64_t start, int64_t end) {
    int64_t root = start;
    while (((2 * root) + 1) <= end) {
        int64_t child = ((2 * root) + 1);
        if (((child + 1) <= end && arr[child] < arr[(child + 1)])) {
            child = (child + 1);
        }
        if (arr[root] < arr[child]) {
            int64_t tmp = arr[root];
            arr[root] = arr[child];
            arr[child] = tmp;
            root = child;
        } else {
            break;
        }
    }
}

void heapsort_i64_ptr_i64_i64(int64_t* arr, int64_t n) {
    if (n <= 1) {
        return;
    }
    int64_t start = (FLOW_CHECKED_DIV((n), (2)) - 1);
    while (start >= 0) {
        sift_down_i64_ptr_i64_i64_i64(arr, start, (n - 1));
        start = (start - 1);
    }
    int64_t end = (n - 1);
    while (end > 0) {
        int64_t tmp = arr[0];
        arr[0] = arr[end];
        arr[end] = tmp;
        end = (end - 1);
        sift_down_i64_ptr_i64_i64_i64(arr, 0, end);
    }
}

void sift_down_keys_ptr_i64_ptr_i64_i64_i64(int64_t* ka, int64_t* kb, int64_t start, int64_t end) {
    int64_t root = start;
    while (((2 * root) + 1) <= end) {
        int64_t child = ((2 * root) + 1);
        if ((child + 1) <= end) {
            int64_t ca = ka[child];
            int64_t cb = kb[child];
            int64_t cca = ka[(child + 1)];
            int64_t ccb = kb[(child + 1)];
            if ((ca < cca || (ca == cca && cb < ccb))) {
                child = (child + 1);
            }
        }
        int64_t ra = ka[root];
        int64_t rb = kb[root];
        int64_t ca2 = ka[child];
        int64_t cb2 = kb[child];
        if ((ra < ca2 || (ra == ca2 && rb < cb2))) {
            int64_t tmpa = ka[root];
            int64_t tmpb = kb[root];
            ka[root] = ka[child];
            kb[root] = kb[child];
            ka[child] = tmpa;
            kb[child] = tmpb;
            root = child;
        } else {
            break;
        }
    }
}

void heapsort_keys_ptr_i64_ptr_i64_i64(int64_t* ka, int64_t* kb, int64_t n) {
    if (n <= 1) {
        return;
    }
    int64_t start = (FLOW_CHECKED_DIV((n), (2)) - 1);
    while (start >= 0) {
        sift_down_keys_ptr_i64_ptr_i64_i64_i64(ka, kb, start, (n - 1));
        start = (start - 1);
    }
    int64_t end = (n - 1);
    while (end > 0) {
        int64_t tmpa = ka[0];
        int64_t tmpb = kb[0];
        ka[0] = ka[end];
        kb[0] = kb[end];
        ka[end] = tmpa;
        kb[end] = tmpb;
        end = (end - 1);
        sift_down_keys_ptr_i64_ptr_i64_i64_i64(ka, kb, 0, end);
    }
}

void coordinate_values_i32(int32_t n) {
    g_scale = 1;
    int32_t d = 1;
    while (d <= n) {
        g_scale = lcm64_i64_i64(g_scale, ((int64_t)(d)));
        d = (d + 1);
    }
    int32_t cap = 256;
    g_coords = ((int64_t*)(malloc((((int64_t)(cap)) * 8))));
    g_ncoords = 0;
    g_coords[0] = 0;
    g_ncoords = 1;
    int32_t d2 = 2;
    while (d2 <= n) {
        int64_t step = FLOW_CHECKED_DIV((g_scale), (((int64_t)(d2))));
        int32_t a = 1;
        while (a < d2) {
            if (gcd64_i64_i64(((int64_t)(a)), ((int64_t)(d2))) == 1) {
                int64_t v = (((int64_t)(a)) * step);
                if ((g_ncoords + 2) > cap) {
                    cap = (cap * 2);
                    g_coords = ((int64_t*)(realloc(((void*)(g_coords)), (((int64_t)(cap)) * 8))));
                }
                g_coords[g_ncoords] = v;
                g_ncoords = (g_ncoords + 1);
                g_coords[g_ncoords] = (-v);
                g_ncoords = (g_ncoords + 1);
            }
            a = (a + 1);
        }
        d2 = (d2 + 1);
    }
    heapsort_i64_ptr_i64_i64(g_coords, ((int64_t)(g_ncoords)));
    int32_t w = 0;
    int32_t i = 0;
    while (i < g_ncoords) {
        if ((i == 0 || g_coords[i] != g_coords[(i - 1)])) {
            g_coords[w] = g_coords[i];
            w = (w + 1);
        }
        i = (i + 1);
    }
    g_ncoords = w;
}

void build_lifted_points_i32(int32_t n) {
    coordinate_values_i32(n);
    int64_t scale2 = (g_scale * g_scale);
    int64_t* sq = (int64_t*)(((int64_t*)(malloc((((int64_t)(g_ncoords)) * 8)))));
    int32_t i = 0;
    while (i < g_ncoords) {
        sq[i] = (g_coords[i] * g_coords[i]);
        i = (i + 1);
    }
    int32_t cap = FLOW_CHECKED_SHL((1), (16));
    g_px = ((int64_t*)(malloc((((int64_t)(cap)) * 8))));
    g_py = ((int64_t*)(malloc((((int64_t)(cap)) * 8))));
    g_pz = ((int64_t*)(malloc((((int64_t)(cap)) * 8))));
    g_npoints = 0;
    int32_t xi = 0;
    while (xi < g_ncoords) {
        int64_t x = g_coords[xi];
        int64_t x2 = sq[xi];
        int32_t yi = 0;
        while (yi < g_ncoords) {
            int64_t z0 = (x2 + sq[yi]);
            if (z0 < scale2) {
                if (g_npoints >= cap) {
                    cap = (cap * 2);
                    g_px = ((int64_t*)(realloc(((void*)(g_px)), (((int64_t)(cap)) * 8))));
                    g_py = ((int64_t*)(realloc(((void*)(g_py)), (((int64_t)(cap)) * 8))));
                    g_pz = ((int64_t*)(realloc(((void*)(g_pz)), (((int64_t)(cap)) * 8))));
                }
                g_px[g_npoints] = x;
                g_py[g_npoints] = g_coords[yi];
                g_pz[g_npoints] = (z0 + scale2);
                g_npoints = (g_npoints + 1);
            }
            yi = (yi + 1);
        }
        xi = (xi + 1);
    }
    free(((void*)(sq)));
}

int64_t count_unordered_triples(void) {
    int64_t total = 0;
    int32_t m = g_npoints;
    int64_t* ka = (int64_t*)(((int64_t*)(malloc((((int64_t)(m)) * 8)))));
    int64_t* kb = (int64_t*)(((int64_t*)(malloc((((int64_t)(m)) * 8)))));
    int32_t i = 0;
    while (i < (m - 2)) {
        int64_t px = g_px[i];
        int64_t py = g_py[i];
        int64_t pz = g_pz[i];
        int32_t nk = 0;
        if (px != 0) {
            int32_t j = (i + 1);
            while (j < m) {
                int64_t qx = g_px[j];
                int64_t qy = g_py[j];
                int64_t qz = g_pz[j];
                int64_t a = ((py * qx) - (px * qy));
                int64_t b = ((pz * qx) - (px * qz));
                int64_t g = gcd64_i64_i64(a, b);
                if (g != 0) {
                    a = FLOW_CHECKED_DIV((a), (g));
                    b = FLOW_CHECKED_DIV((b), (g));
                }
                if ((a < 0 || (a == 0 && b < 0))) {
                    a = (-a);
                    b = (-b);
                }
                ka[nk] = a;
                kb[nk] = b;
                nk = (nk + 1);
                j = (j + 1);
            }
        } else {
            int32_t j = (i + 1);
            while (j < m) {
                int64_t qx = g_px[j];
                int64_t qy = g_py[j];
                int64_t qz = g_pz[j];
                int64_t a = qx;
                int64_t b = ((pz * qy) - (py * qz));
                int64_t g = gcd64_i64_i64(a, b);
                if (g != 0) {
                    a = FLOW_CHECKED_DIV((a), (g));
                    b = FLOW_CHECKED_DIV((b), (g));
                }
                if ((a < 0 || (a == 0 && b < 0))) {
                    a = (-a);
                    b = (-b);
                }
                ka[nk] = a;
                kb[nk] = b;
                nk = (nk + 1);
                j = (j + 1);
            }
        }
        heapsort_keys_ptr_i64_ptr_i64_i64(ka, kb, ((int64_t)(nk)));
        int64_t run_len = 1;
        int64_t prev_a = ka[0];
        int64_t prev_b = kb[0];
        int32_t k = 1;
        while (k < nk) {
            if ((ka[k] == prev_a && kb[k] == prev_b)) {
                run_len = (run_len + 1);
            } else {
                if (run_len >= 2) {
                    total = (total + FLOW_CHECKED_DIV(((run_len * (run_len - 1))), (2)));
                }
                prev_a = ka[k];
                prev_b = kb[k];
                run_len = 1;
            }
            k = (k + 1);
        }
        if (run_len >= 2) {
            total = (total + FLOW_CHECKED_DIV(((run_len * (run_len - 1))), (2)));
        }
        i = (i + 1);
    }
    free(((void*)(ka)));
    free(((void*)(kb)));
    return total;
}

int64_t compute_T_i32(int32_t n) {
    build_lifted_points_i32(n);
    int64_t c = count_unordered_triples();
    int64_t result = (6 * c);
    free(((void*)(g_coords)));
    free(((void*)(g_px)));
    free(((void*)(g_py)));
    free(((void*)(g_pz)));
    return result;
}

int32_t main(void) {
    printf("%lld\n", compute_T_i32(12));
    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 @gcd(%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
    cf.br ^bb0
    ^bb0:
    %4 = llvm.load %3 : !llvm.ptr -> i64
    %5 = arith.constant 0 : i32
    %7 = arith.extsi %5 : i32 to i64
    %6 = arith.cmpi ne, %4, %7 : i64
    cf.cond_br %6, ^bb1, ^bb2
    ^bb1:
      %8 = llvm.load %1 : !llvm.ptr -> i64
      %9 = llvm.load %3 : !llvm.ptr -> i64
      %10 = arith.remsi %8, %9 : i64
      %11 = llvm.load %3 : !llvm.ptr -> i64
      llvm.store %11, %1 : i64, !llvm.ptr
      llvm.store %10, %3 : i64, !llvm.ptr
      cf.br ^bb0
    ^bb2:
    %12 = llvm.load %1 : !llvm.ptr -> i64
    func.return %12 : i64
  }
  func.func @lcm(%arg0: i64, %arg1: i64) -> i64 {
    %13 = arith.constant 0 : i32
    %15 = arith.extsi %13 : i32 to i64
    %14 = arith.cmpi eq, %arg0, %15 : i64
    %16 = scf.if %14 -> (i1) {
      %17 = arith.constant true
      scf.yield %17 : i1
    } else {
      %18 = arith.constant 0 : i32
      %20 = arith.extsi %18 : i32 to i64
      %19 = arith.cmpi eq, %arg1, %20 : i64
      scf.yield %19 : i1
    }
    cf.cond_br %16, ^bb3, ^bb4
    ^bb3:
      %21 = arith.constant 0 : i32
      %22 = arith.extsi %21 : i32 to i64
      func.return %22 : i64
    ^bb4:
      cf.br ^bb5
    ^bb5:
    %23 = func.call @gcd(%arg0, %arg1) : (i64, i64) -> i64
    %24 = arith.divsi %arg0, %23 : i64
    %25 = arith.muli %24, %arg1 : i64
    func.return %25 : i64
  }
  func.func @isqrt(%arg0: i64) -> i64 {
    %26 = arith.constant 2 : i32
    %28 = arith.extsi %26 : i32 to i64
    %27 = arith.cmpi slt, %arg0, %28 : i64
    cf.cond_br %27, ^bb6, ^bb7
    ^bb6:
      func.return %arg0 : i64
    ^bb7:
      cf.br ^bb8
    ^bb8:
    %29 = llvm.mlir.constant(1 : i64) : i64
    %30 = llvm.alloca %29 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %30 : i64, !llvm.ptr
    %31 = llvm.load %30 : !llvm.ptr -> i64
    %32 = arith.constant 1 : i32
    %34 = arith.extsi %32 : i32 to i64
    %33 = arith.addi %31, %34 : i64
    %35 = arith.constant 2 : i32
    %37 = arith.extsi %35 : i32 to i64
    %36 = arith.divsi %33, %37 : i64
    %38 = llvm.mlir.constant(1 : i64) : i64
    %39 = llvm.alloca %38 x i64 : (i64) -> !llvm.ptr
    llvm.store %36, %39 : i64, !llvm.ptr
    cf.br ^bb9
    ^bb9:
    %40 = llvm.load %39 : !llvm.ptr -> i64
    %41 = llvm.load %30 : !llvm.ptr -> i64
    %42 = arith.cmpi slt, %40, %41 : i64
    cf.cond_br %42, ^bb10, ^bb11
    ^bb10:
      %43 = llvm.load %39 : !llvm.ptr -> i64
      llvm.store %43, %30 : i64, !llvm.ptr
      %44 = llvm.load %30 : !llvm.ptr -> i64
      %45 = llvm.load %30 : !llvm.ptr -> i64
      %46 = arith.divsi %arg0, %45 : i64
      %47 = arith.addi %44, %46 : i64
      %48 = arith.constant 2 : i32
      %50 = arith.extsi %48 : i32 to i64
      %49 = arith.divsi %47, %50 : i64
      llvm.store %49, %39 : i64, !llvm.ptr
      cf.br ^bb9
    ^bb11:
    %51 = llvm.load %30 : !llvm.ptr -> i64
    func.return %51 : i64
  }
  func.func @mulmod(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %52 = arith.remsi %arg0, %arg2 : i64
    %53 = llvm.mlir.constant(1 : i64) : i64
    %54 = llvm.alloca %53 x i64 : (i64) -> !llvm.ptr
    llvm.store %52, %54 : i64, !llvm.ptr
    %55 = arith.remsi %arg1, %arg2 : i64
    %56 = llvm.mlir.constant(1 : i64) : i64
    %57 = llvm.alloca %56 x i64 : (i64) -> !llvm.ptr
    llvm.store %55, %57 : i64, !llvm.ptr
    %58 = arith.constant 0 : i32
    %59 = arith.extsi %58 : i32 to i64
    %60 = llvm.mlir.constant(1 : i64) : i64
    %61 = llvm.alloca %60 x i64 : (i64) -> !llvm.ptr
    llvm.store %59, %61 : i64, !llvm.ptr
    cf.br ^bb12
    ^bb12:
    %62 = llvm.load %57 : !llvm.ptr -> i64
    %63 = arith.constant 0 : i32
    %65 = arith.extsi %63 : i32 to i64
    %64 = arith.cmpi sgt, %62, %65 : i64
    cf.cond_br %64, ^bb13, ^bb14
    ^bb13:
      %66 = llvm.load %57 : !llvm.ptr -> i64
      %67 = arith.constant 2 : i32
      %69 = arith.extsi %67 : i32 to i64
      %68 = arith.remsi %66, %69 : i64
      %70 = arith.constant 1 : i32
      %72 = arith.extsi %70 : i32 to i64
      %71 = arith.cmpi eq, %68, %72 : i64
      cf.cond_br %71, ^bb15, ^bb16
      ^bb15:
        %73 = llvm.load %61 : !llvm.ptr -> i64
        %74 = llvm.load %54 : !llvm.ptr -> i64
        %75 = arith.addi %73, %74 : i64
        %76 = arith.remsi %75, %arg2 : i64
        llvm.store %76, %61 : i64, !llvm.ptr
        cf.br ^bb17
      ^bb16:
        cf.br ^bb17
      ^bb17:
      %77 = llvm.load %54 : !llvm.ptr -> i64
      %78 = arith.constant 2 : i32
      %80 = arith.extsi %78 : i32 to i64
      %79 = arith.muli %77, %80 : i64
      %81 = arith.remsi %79, %arg2 : i64
      llvm.store %81, %54 : i64, !llvm.ptr
      %82 = llvm.load %57 : !llvm.ptr -> i64
      %83 = arith.constant 2 : i32
      %85 = arith.extsi %83 : i32 to i64
      %84 = arith.divsi %82, %85 : i64
      llvm.store %84, %57 : i64, !llvm.ptr
      cf.br ^bb12
    ^bb14:
    %86 = llvm.load %61 : !llvm.ptr -> i64
    func.return %86 : i64
  }
  func.func @mod_pow(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %87 = arith.constant 1 : i32
    %89 = arith.extsi %87 : i32 to i64
    %88 = arith.cmpi eq, %arg2, %89 : i64
    cf.cond_br %88, ^bb18, ^bb19
    ^bb18:
      %90 = arith.constant 0 : i32
      %91 = arith.extsi %90 : i32 to i64
      func.return %91 : i64
    ^bb19:
      cf.br ^bb20
    ^bb20:
    %92 = arith.constant 1 : i32
    %93 = arith.extsi %92 : i32 to i64
    %94 = llvm.mlir.constant(1 : i64) : i64
    %95 = llvm.alloca %94 x i64 : (i64) -> !llvm.ptr
    llvm.store %93, %95 : i64, !llvm.ptr
    %96 = arith.remsi %arg0, %arg2 : i64
    %97 = llvm.mlir.constant(1 : i64) : i64
    %98 = llvm.alloca %97 x i64 : (i64) -> !llvm.ptr
    llvm.store %96, %98 : i64, !llvm.ptr
    %99 = llvm.mlir.constant(1 : i64) : i64
    %100 = llvm.alloca %99 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %100 : i64, !llvm.ptr
    cf.br ^bb21
    ^bb21:
    %101 = llvm.load %100 : !llvm.ptr -> i64
    %102 = arith.constant 0 : i32
    %104 = arith.extsi %102 : i32 to i64
    %103 = arith.cmpi sgt, %101, %104 : i64
    cf.cond_br %103, ^bb22, ^bb23
    ^bb22:
      %105 = llvm.load %100 : !llvm.ptr -> i64
      %106 = arith.constant 2 : i32
      %108 = arith.extsi %106 : i32 to i64
      %107 = arith.remsi %105, %108 : i64
      %109 = arith.constant 1 : i32
      %111 = arith.extsi %109 : i32 to i64
      %110 = arith.cmpi eq, %107, %111 : i64
      cf.cond_br %110, ^bb24, ^bb25
      ^bb24:
        %113 = llvm.load %95 : !llvm.ptr -> i64
        %114 = llvm.load %98 : !llvm.ptr -> i64
        %112 = func.call @mulmod(%113, %114, %arg2) : (i64, i64, i64) -> i64
        llvm.store %112, %95 : i64, !llvm.ptr
        cf.br ^bb26
      ^bb25:
        cf.br ^bb26
      ^bb26:
      %116 = llvm.load %98 : !llvm.ptr -> i64
      %117 = llvm.load %98 : !llvm.ptr -> i64
      %115 = func.call @mulmod(%116, %117, %arg2) : (i64, i64, i64) -> i64
      llvm.store %115, %98 : i64, !llvm.ptr
      %118 = llvm.load %100 : !llvm.ptr -> i64
      %119 = arith.constant 2 : i32
      %121 = arith.extsi %119 : i32 to i64
      %120 = arith.divsi %118, %121 : i64
      llvm.store %120, %100 : i64, !llvm.ptr
      cf.br ^bb21
    ^bb23:
    %122 = llvm.load %95 : !llvm.ptr -> i64
    func.return %122 : i64
  }
  func.func @is_prime(%arg0: i64) -> i1 {
    %123 = arith.constant 2 : i32
    %125 = arith.extsi %123 : i32 to i64
    %124 = arith.cmpi slt, %arg0, %125 : i64
    cf.cond_br %124, ^bb27, ^bb28
    ^bb27:
      %126 = arith.constant 0 : i1
      func.return %126 : i1
    ^bb28:
      cf.br ^bb29
    ^bb29:
    %127 = arith.constant 4 : i32
    %129 = arith.extsi %127 : i32 to i64
    %128 = arith.cmpi slt, %arg0, %129 : i64
    cf.cond_br %128, ^bb30, ^bb31
    ^bb30:
      %130 = arith.constant 1 : i1
      func.return %130 : i1
    ^bb31:
      cf.br ^bb32
    ^bb32:
    %131 = arith.constant 2 : i32
    %133 = arith.extsi %131 : i32 to i64
    %132 = arith.remsi %arg0, %133 : i64
    %134 = arith.constant 0 : i32
    %136 = arith.extsi %134 : i32 to i64
    %135 = arith.cmpi eq, %132, %136 : i64
    %137 = scf.if %135 -> (i1) {
      %138 = arith.constant true
      scf.yield %138 : i1
    } else {
      %139 = arith.constant 3 : i32
      %141 = arith.extsi %139 : i32 to i64
      %140 = arith.remsi %arg0, %141 : i64
      %142 = arith.constant 0 : i32
      %144 = arith.extsi %142 : i32 to i64
      %143 = arith.cmpi eq, %140, %144 : i64
      scf.yield %143 : i1
    }
    cf.cond_br %137, ^bb33, ^bb34
    ^bb33:
      %145 = arith.constant 0 : i1
      func.return %145 : i1
    ^bb34:
      cf.br ^bb35
    ^bb35:
    %146 = arith.constant 5 : i32
    %147 = arith.extsi %146 : i32 to i64
    %148 = llvm.mlir.constant(1 : i64) : i64
    %149 = llvm.alloca %148 x i64 : (i64) -> !llvm.ptr
    llvm.store %147, %149 : i64, !llvm.ptr
    cf.br ^bb36
    ^bb36:
    %150 = llvm.load %149 : !llvm.ptr -> i64
    %151 = llvm.load %149 : !llvm.ptr -> i64
    %152 = arith.muli %150, %151 : i64
    %153 = arith.cmpi sle, %152, %arg0 : i64
    cf.cond_br %153, ^bb37, ^bb38
    ^bb37:
      %154 = llvm.load %149 : !llvm.ptr -> i64
      %155 = arith.remsi %arg0, %154 : i64
      %156 = arith.constant 0 : i32
      %158 = arith.extsi %156 : i32 to i64
      %157 = arith.cmpi eq, %155, %158 : i64
      %159 = scf.if %157 -> (i1) {
        %160 = arith.constant true
        scf.yield %160 : i1
      } else {
        %161 = llvm.load %149 : !llvm.ptr -> i64
        %162 = arith.constant 2 : i32
        %164 = arith.extsi %162 : i32 to i64
        %163 = arith.addi %161, %164 : i64
        %165 = arith.remsi %arg0, %163 : i64
        %166 = arith.constant 0 : i32
        %168 = arith.extsi %166 : i32 to i64
        %167 = arith.cmpi eq, %165, %168 : i64
        scf.yield %167 : i1
      }
      cf.cond_br %159, ^bb39, ^bb40
      ^bb39:
        %169 = arith.constant 0 : i1
        func.return %169 : i1
      ^bb40:
        cf.br ^bb41
      ^bb41:
      %170 = llvm.load %149 : !llvm.ptr -> i64
      %171 = arith.constant 6 : i32
      %173 = arith.extsi %171 : i32 to i64
      %172 = arith.addi %170, %173 : i64
      llvm.store %172, %149 : i64, !llvm.ptr
      cf.br ^bb36
    ^bb38:
    %174 = arith.constant 1 : i1
    func.return %174 : i1
  }
  func.func private @calloc(i64, i64) -> !llvm.ptr
  func.func private @malloc(i64) -> !llvm.ptr
  func.func private @realloc(!llvm.ptr, i64) -> !llvm.ptr
  func.func private @free(!llvm.ptr) -> ()

  func.func @gcd64(%arg0: i64, %arg1: i64) -> i64 {
    %175 = arith.constant 0 : i32
    %177 = arith.extsi %175 : i32 to i64
    %176 = arith.cmpi slt, %arg0, %177 : i64
    %178 = scf.if %176 -> (i64) {
      %180 = arith.constant 0 : i64
      %179 = arith.subi %180, %arg0 : i64
      scf.yield %179 : i64
    } else {
      scf.yield %arg0 : i64
    }
    %181 = llvm.mlir.constant(1 : i64) : i64
    %182 = llvm.alloca %181 x i64 : (i64) -> !llvm.ptr
    llvm.store %178, %182 : i64, !llvm.ptr
    %183 = arith.constant 0 : i32
    %185 = arith.extsi %183 : i32 to i64
    %184 = arith.cmpi slt, %arg1, %185 : i64
    %186 = scf.if %184 -> (i64) {
      %188 = arith.constant 0 : i64
      %187 = arith.subi %188, %arg1 : i64
      scf.yield %187 : i64
    } else {
      scf.yield %arg1 : i64
    }
    %189 = llvm.mlir.constant(1 : i64) : i64
    %190 = llvm.alloca %189 x i64 : (i64) -> !llvm.ptr
    llvm.store %186, %190 : i64, !llvm.ptr
    cf.br ^bb42
    ^bb42:
    %191 = llvm.load %190 : !llvm.ptr -> i64
    %192 = arith.constant 0 : i32
    %194 = arith.extsi %192 : i32 to i64
    %193 = arith.cmpi ne, %191, %194 : i64
    cf.cond_br %193, ^bb43, ^bb44
    ^bb43:
      %195 = llvm.load %182 : !llvm.ptr -> i64
      %196 = llvm.load %190 : !llvm.ptr -> i64
      %197 = arith.remsi %195, %196 : i64
      %198 = llvm.load %190 : !llvm.ptr -> i64
      llvm.store %198, %182 : i64, !llvm.ptr
      llvm.store %197, %190 : i64, !llvm.ptr
      cf.br ^bb42
    ^bb44:
    %199 = llvm.load %182 : !llvm.ptr -> i64
    func.return %199 : i64
  }
  func.func @lcm64(%arg0: i64, %arg1: i64) -> i64 {
    %200 = func.call @gcd64(%arg0, %arg1) : (i64, i64) -> i64
    %201 = arith.divsi %arg0, %200 : i64
    %202 = arith.muli %201, %arg1 : i64
    func.return %202 : i64
  }
  // Module static: g_scale
  llvm.mlir.global internal @g_scale(0 : i64) : i64
  // Module static: g_coords
  llvm.mlir.global internal @g_coords() {addr_space = 0 : i32} : !llvm.ptr {
    %203 = llvm.mlir.zero : !llvm.ptr
    llvm.return %203 : !llvm.ptr
  }
  // Module static: g_ncoords
  llvm.mlir.global internal @g_ncoords(0 : i32) : i32
  // Module static: g_px
  llvm.mlir.global internal @g_px() {addr_space = 0 : i32} : !llvm.ptr {
    %204 = llvm.mlir.zero : !llvm.ptr
    llvm.return %204 : !llvm.ptr
  }
  // Module static: g_py
  llvm.mlir.global internal @g_py() {addr_space = 0 : i32} : !llvm.ptr {
    %205 = llvm.mlir.zero : !llvm.ptr
    llvm.return %205 : !llvm.ptr
  }
  // Module static: g_pz
  llvm.mlir.global internal @g_pz() {addr_space = 0 : i32} : !llvm.ptr {
    %206 = llvm.mlir.zero : !llvm.ptr
    llvm.return %206 : !llvm.ptr
  }
  // Module static: g_npoints
  llvm.mlir.global internal @g_npoints(0 : i32) : i32
  func.func @sift_down_i64(%arg0: !llvm.ptr, %arg1: i64, %arg2: i64) -> () {
    %207 = llvm.mlir.constant(1 : i64) : i64
    %208 = llvm.alloca %207 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %208 : i64, !llvm.ptr
    cf.br ^bb45
    ^bb45:
    %209 = arith.constant 2 : i32
    %210 = llvm.load %208 : !llvm.ptr -> i64
    %212 = arith.extsi %209 : i32 to i64
    %211 = arith.muli %212, %210 : i64
    %213 = arith.constant 1 : i32
    %215 = arith.extsi %213 : i32 to i64
    %214 = arith.addi %211, %215 : i64
    %216 = arith.cmpi sle, %214, %arg2 : i64
    cf.cond_br %216, ^bb46, ^bb47
    ^bb46:
      %217 = arith.constant 2 : i32
      %218 = llvm.load %208 : !llvm.ptr -> i64
      %220 = arith.extsi %217 : i32 to i64
      %219 = arith.muli %220, %218 : i64
      %221 = arith.constant 1 : i32
      %223 = arith.extsi %221 : i32 to i64
      %222 = arith.addi %219, %223 : i64
      %224 = llvm.mlir.constant(1 : i64) : i64
      %225 = llvm.alloca %224 x i64 : (i64) -> !llvm.ptr
      llvm.store %222, %225 : i64, !llvm.ptr
      %226 = llvm.load %225 : !llvm.ptr -> i64
      %227 = arith.constant 1 : i32
      %229 = arith.extsi %227 : i32 to i64
      %228 = arith.addi %226, %229 : i64
      %230 = arith.cmpi sle, %228, %arg2 : i64
      %231 = scf.if %230 -> (i1) {
        %233 = llvm.load %225 : !llvm.ptr -> i64
        %234 = llvm.getelementptr %arg0[%233] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %232 = llvm.load %234 : !llvm.ptr -> i64
        %236 = llvm.load %225 : !llvm.ptr -> i64
        %237 = arith.constant 1 : i32
        %239 = arith.extsi %237 : i32 to i64
        %238 = arith.addi %236, %239 : i64
        %240 = llvm.getelementptr %arg0[%238] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %235 = llvm.load %240 : !llvm.ptr -> i64
        %241 = arith.cmpi slt, %232, %235 : i64
        scf.yield %241 : i1
      } else {
        %242 = arith.constant false
        scf.yield %242 : i1
      }
      cf.cond_br %231, ^bb48, ^bb49
      ^bb48:
        %243 = llvm.load %225 : !llvm.ptr -> i64
        %244 = arith.constant 1 : i32
        %246 = arith.extsi %244 : i32 to i64
        %245 = arith.addi %243, %246 : i64
        llvm.store %245, %225 : i64, !llvm.ptr
        cf.br ^bb50
      ^bb49:
        cf.br ^bb50
      ^bb50:
      %248 = llvm.load %208 : !llvm.ptr -> i64
      %249 = llvm.getelementptr %arg0[%248] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %247 = llvm.load %249 : !llvm.ptr -> i64
      %251 = llvm.load %225 : !llvm.ptr -> i64
      %252 = llvm.getelementptr %arg0[%251] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %250 = llvm.load %252 : !llvm.ptr -> i64
      %253 = arith.cmpi slt, %247, %250 : i64
      cf.cond_br %253, ^bb51, ^bb52
      ^bb51:
        %255 = llvm.load %208 : !llvm.ptr -> i64
        %256 = llvm.getelementptr %arg0[%255] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %254 = llvm.load %256 : !llvm.ptr -> i64
        %258 = llvm.load %225 : !llvm.ptr -> i64
        %259 = llvm.getelementptr %arg0[%258] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %257 = llvm.load %259 : !llvm.ptr -> i64
        %260 = llvm.load %208 : !llvm.ptr -> i64
        %261 = llvm.getelementptr %arg0[%260] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %257, %261 : i64, !llvm.ptr
        %262 = llvm.load %225 : !llvm.ptr -> i64
        %263 = llvm.getelementptr %arg0[%262] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %254, %263 : i64, !llvm.ptr
        %264 = llvm.load %225 : !llvm.ptr -> i64
        llvm.store %264, %208 : i64, !llvm.ptr
        cf.br ^bb53
      ^bb52:
        cf.br ^bb47
      ^bb53:
      cf.br ^bb45
    ^bb47:
    func.return
  }
  func.func @heapsort_i64(%arg0: !llvm.ptr, %arg1: i64) -> () {
    %265 = arith.constant 1 : i32
    %267 = arith.extsi %265 : i32 to i64
    %266 = arith.cmpi sle, %arg1, %267 : i64
    cf.cond_br %266, ^bb54, ^bb55
    ^bb54:
      func.return
    ^bb55:
      cf.br ^bb56
    ^bb56:
    %268 = arith.constant 2 : i32
    %270 = arith.extsi %268 : i32 to i64
    %269 = arith.divsi %arg1, %270 : i64
    %271 = arith.constant 1 : i32
    %273 = arith.extsi %271 : i32 to i64
    %272 = arith.subi %269, %273 : i64
    %274 = llvm.mlir.constant(1 : i64) : i64
    %275 = llvm.alloca %274 x i64 : (i64) -> !llvm.ptr
    llvm.store %272, %275 : i64, !llvm.ptr
    cf.br ^bb57
    ^bb57:
    %276 = llvm.load %275 : !llvm.ptr -> i64
    %277 = arith.constant 0 : i32
    %279 = arith.extsi %277 : i32 to i64
    %278 = arith.cmpi sge, %276, %279 : i64
    cf.cond_br %278, ^bb58, ^bb59
    ^bb58:
      %281 = llvm.load %275 : !llvm.ptr -> i64
      %282 = arith.constant 1 : i32
      %284 = arith.extsi %282 : i32 to i64
      %283 = arith.subi %arg1, %284 : i64
      func.call @sift_down_i64(%arg0, %281, %283) : (!llvm.ptr, i64, i64) -> ()
      %285 = llvm.load %275 : !llvm.ptr -> i64
      %286 = arith.constant 1 : i32
      %288 = arith.extsi %286 : i32 to i64
      %287 = arith.subi %285, %288 : i64
      llvm.store %287, %275 : i64, !llvm.ptr
      cf.br ^bb57
    ^bb59:
    %289 = arith.constant 1 : i32
    %291 = arith.extsi %289 : i32 to i64
    %290 = arith.subi %arg1, %291 : i64
    %292 = llvm.mlir.constant(1 : i64) : i64
    %293 = llvm.alloca %292 x i64 : (i64) -> !llvm.ptr
    llvm.store %290, %293 : i64, !llvm.ptr
    cf.br ^bb60
    ^bb60:
    %294 = llvm.load %293 : !llvm.ptr -> i64
    %295 = arith.constant 0 : i32
    %297 = arith.extsi %295 : i32 to i64
    %296 = arith.cmpi sgt, %294, %297 : i64
    cf.cond_br %296, ^bb61, ^bb62
    ^bb61:
      %299 = arith.constant 0 : i32
      %300 = arith.extsi %299 : i32 to i64
      %301 = llvm.getelementptr %arg0[%300] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %298 = llvm.load %301 : !llvm.ptr -> i64
      %303 = llvm.load %293 : !llvm.ptr -> i64
      %304 = llvm.getelementptr %arg0[%303] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %302 = llvm.load %304 : !llvm.ptr -> i64
      %305 = arith.constant 0 : i32
      %306 = arith.extsi %305 : i32 to i64
      %307 = llvm.getelementptr %arg0[%306] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %302, %307 : i64, !llvm.ptr
      %308 = llvm.load %293 : !llvm.ptr -> i64
      %309 = llvm.getelementptr %arg0[%308] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %298, %309 : i64, !llvm.ptr
      %310 = llvm.load %293 : !llvm.ptr -> i64
      %311 = arith.constant 1 : i32
      %313 = arith.extsi %311 : i32 to i64
      %312 = arith.subi %310, %313 : i64
      llvm.store %312, %293 : i64, !llvm.ptr
      %315 = arith.constant 0 : i32
      %316 = llvm.load %293 : !llvm.ptr -> i64
      %317 = arith.extsi %315 : i32 to i64
      func.call @sift_down_i64(%arg0, %317, %316) : (!llvm.ptr, i64, i64) -> ()
      cf.br ^bb60
    ^bb62:
    func.return
  }
  func.func @sift_down_keys(%arg0: !llvm.ptr, %arg1: !llvm.ptr, %arg2: i64, %arg3: i64) -> () {
    %318 = llvm.mlir.constant(1 : i64) : i64
    %319 = llvm.alloca %318 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg2, %319 : i64, !llvm.ptr
    cf.br ^bb63
    ^bb63:
    %320 = arith.constant 2 : i32
    %321 = llvm.load %319 : !llvm.ptr -> i64
    %323 = arith.extsi %320 : i32 to i64
    %322 = arith.muli %323, %321 : i64
    %324 = arith.constant 1 : i32
    %326 = arith.extsi %324 : i32 to i64
    %325 = arith.addi %322, %326 : i64
    %327 = arith.cmpi sle, %325, %arg3 : i64
    cf.cond_br %327, ^bb64, ^bb65
    ^bb64:
      %328 = arith.constant 2 : i32
      %329 = llvm.load %319 : !llvm.ptr -> i64
      %331 = arith.extsi %328 : i32 to i64
      %330 = arith.muli %331, %329 : i64
      %332 = arith.constant 1 : i32
      %334 = arith.extsi %332 : i32 to i64
      %333 = arith.addi %330, %334 : i64
      %335 = llvm.mlir.constant(1 : i64) : i64
      %336 = llvm.alloca %335 x i64 : (i64) -> !llvm.ptr
      llvm.store %333, %336 : i64, !llvm.ptr
      %337 = llvm.load %336 : !llvm.ptr -> i64
      %338 = arith.constant 1 : i32
      %340 = arith.extsi %338 : i32 to i64
      %339 = arith.addi %337, %340 : i64
      %341 = arith.cmpi sle, %339, %arg3 : i64
      cf.cond_br %341, ^bb66, ^bb67
      ^bb66:
        %343 = llvm.load %336 : !llvm.ptr -> i64
        %344 = llvm.getelementptr %arg0[%343] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %342 = llvm.load %344 : !llvm.ptr -> i64
        %346 = llvm.load %336 : !llvm.ptr -> i64
        %347 = llvm.getelementptr %arg1[%346] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %345 = llvm.load %347 : !llvm.ptr -> i64
        %349 = llvm.load %336 : !llvm.ptr -> i64
        %350 = arith.constant 1 : i32
        %352 = arith.extsi %350 : i32 to i64
        %351 = arith.addi %349, %352 : i64
        %353 = llvm.getelementptr %arg0[%351] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %348 = llvm.load %353 : !llvm.ptr -> i64
        %355 = llvm.load %336 : !llvm.ptr -> i64
        %356 = arith.constant 1 : i32
        %358 = arith.extsi %356 : i32 to i64
        %357 = arith.addi %355, %358 : i64
        %359 = llvm.getelementptr %arg1[%357] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %354 = llvm.load %359 : !llvm.ptr -> i64
        %360 = arith.cmpi slt, %342, %348 : i64
        %361 = scf.if %360 -> (i1) {
          %362 = arith.constant true
          scf.yield %362 : i1
        } else {
          %363 = arith.cmpi eq, %342, %348 : i64
          %364 = scf.if %363 -> (i1) {
            %365 = arith.cmpi slt, %345, %354 : i64
            scf.yield %365 : i1
          } else {
            %366 = arith.constant false
            scf.yield %366 : i1
          }
          scf.yield %364 : i1
        }
        cf.cond_br %361, ^bb69, ^bb70
        ^bb69:
          %367 = llvm.load %336 : !llvm.ptr -> i64
          %368 = arith.constant 1 : i32
          %370 = arith.extsi %368 : i32 to i64
          %369 = arith.addi %367, %370 : i64
          llvm.store %369, %336 : i64, !llvm.ptr
          cf.br ^bb71
        ^bb70:
          cf.br ^bb71
        ^bb71:
        cf.br ^bb68
      ^bb67:
        cf.br ^bb68
      ^bb68:
      %372 = llvm.load %319 : !llvm.ptr -> i64
      %373 = llvm.getelementptr %arg0[%372] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %371 = llvm.load %373 : !llvm.ptr -> i64
      %375 = llvm.load %319 : !llvm.ptr -> i64
      %376 = llvm.getelementptr %arg1[%375] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %374 = llvm.load %376 : !llvm.ptr -> i64
      %378 = llvm.load %336 : !llvm.ptr -> i64
      %379 = llvm.getelementptr %arg0[%378] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %377 = llvm.load %379 : !llvm.ptr -> i64
      %381 = llvm.load %336 : !llvm.ptr -> i64
      %382 = llvm.getelementptr %arg1[%381] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %380 = llvm.load %382 : !llvm.ptr -> i64
      %383 = arith.cmpi slt, %371, %377 : i64
      %384 = scf.if %383 -> (i1) {
        %385 = arith.constant true
        scf.yield %385 : i1
      } else {
        %386 = arith.cmpi eq, %371, %377 : i64
        %387 = scf.if %386 -> (i1) {
          %388 = arith.cmpi slt, %374, %380 : i64
          scf.yield %388 : i1
        } else {
          %389 = arith.constant false
          scf.yield %389 : i1
        }
        scf.yield %387 : i1
      }
      cf.cond_br %384, ^bb72, ^bb73
      ^bb72:
        %391 = llvm.load %319 : !llvm.ptr -> i64
        %392 = llvm.getelementptr %arg0[%391] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %390 = llvm.load %392 : !llvm.ptr -> i64
        %394 = llvm.load %319 : !llvm.ptr -> i64
        %395 = llvm.getelementptr %arg1[%394] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %393 = llvm.load %395 : !llvm.ptr -> i64
        %397 = llvm.load %336 : !llvm.ptr -> i64
        %398 = llvm.getelementptr %arg0[%397] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %396 = llvm.load %398 : !llvm.ptr -> i64
        %399 = llvm.load %319 : !llvm.ptr -> i64
        %400 = llvm.getelementptr %arg0[%399] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %396, %400 : i64, !llvm.ptr
        %402 = llvm.load %336 : !llvm.ptr -> i64
        %403 = llvm.getelementptr %arg1[%402] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %401 = llvm.load %403 : !llvm.ptr -> i64
        %404 = llvm.load %319 : !llvm.ptr -> i64
        %405 = llvm.getelementptr %arg1[%404] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %401, %405 : i64, !llvm.ptr
        %406 = llvm.load %336 : !llvm.ptr -> i64
        %407 = llvm.getelementptr %arg0[%406] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %390, %407 : i64, !llvm.ptr
        %408 = llvm.load %336 : !llvm.ptr -> i64
        %409 = llvm.getelementptr %arg1[%408] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %393, %409 : i64, !llvm.ptr
        %410 = llvm.load %336 : !llvm.ptr -> i64
        llvm.store %410, %319 : i64, !llvm.ptr
        cf.br ^bb74
      ^bb73:
        cf.br ^bb65
      ^bb74:
      cf.br ^bb63
    ^bb65:
    func.return
  }
  func.func @heapsort_keys(%arg0: !llvm.ptr, %arg1: !llvm.ptr, %arg2: i64) -> () {
    %411 = arith.constant 1 : i32
    %413 = arith.extsi %411 : i32 to i64
    %412 = arith.cmpi sle, %arg2, %413 : i64
    cf.cond_br %412, ^bb75, ^bb76
    ^bb75:
      func.return
    ^bb76:
      cf.br ^bb77
    ^bb77:
    %414 = arith.constant 2 : i32
    %416 = arith.extsi %414 : i32 to i64
    %415 = arith.divsi %arg2, %416 : i64
    %417 = arith.constant 1 : i32
    %419 = arith.extsi %417 : i32 to i64
    %418 = arith.subi %415, %419 : i64
    %420 = llvm.mlir.constant(1 : i64) : i64
    %421 = llvm.alloca %420 x i64 : (i64) -> !llvm.ptr
    llvm.store %418, %421 : i64, !llvm.ptr
    cf.br ^bb78
    ^bb78:
    %422 = llvm.load %421 : !llvm.ptr -> i64
    %423 = arith.constant 0 : i32
    %425 = arith.extsi %423 : i32 to i64
    %424 = arith.cmpi sge, %422, %425 : i64
    cf.cond_br %424, ^bb79, ^bb80
    ^bb79:
      %427 = llvm.load %421 : !llvm.ptr -> i64
      %428 = arith.constant 1 : i32
      %430 = arith.extsi %428 : i32 to i64
      %429 = arith.subi %arg2, %430 : i64
      func.call @sift_down_keys(%arg0, %arg1, %427, %429) : (!llvm.ptr, !llvm.ptr, i64, i64) -> ()
      %431 = llvm.load %421 : !llvm.ptr -> i64
      %432 = arith.constant 1 : i32
      %434 = arith.extsi %432 : i32 to i64
      %433 = arith.subi %431, %434 : i64
      llvm.store %433, %421 : i64, !llvm.ptr
      cf.br ^bb78
    ^bb80:
    %435 = arith.constant 1 : i32
    %437 = arith.extsi %435 : i32 to i64
    %436 = arith.subi %arg2, %437 : i64
    %438 = llvm.mlir.constant(1 : i64) : i64
    %439 = llvm.alloca %438 x i64 : (i64) -> !llvm.ptr
    llvm.store %436, %439 : i64, !llvm.ptr
    cf.br ^bb81
    ^bb81:
    %440 = llvm.load %439 : !llvm.ptr -> i64
    %441 = arith.constant 0 : i32
    %443 = arith.extsi %441 : i32 to i64
    %442 = arith.cmpi sgt, %440, %443 : i64
    cf.cond_br %442, ^bb82, ^bb83
    ^bb82:
      %445 = arith.constant 0 : i32
      %446 = arith.extsi %445 : i32 to i64
      %447 = llvm.getelementptr %arg0[%446] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %444 = llvm.load %447 : !llvm.ptr -> i64
      %449 = arith.constant 0 : i32
      %450 = arith.extsi %449 : i32 to i64
      %451 = llvm.getelementptr %arg1[%450] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %448 = llvm.load %451 : !llvm.ptr -> i64
      %453 = llvm.load %439 : !llvm.ptr -> i64
      %454 = llvm.getelementptr %arg0[%453] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %452 = llvm.load %454 : !llvm.ptr -> i64
      %455 = arith.constant 0 : i32
      %456 = arith.extsi %455 : i32 to i64
      %457 = llvm.getelementptr %arg0[%456] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %452, %457 : i64, !llvm.ptr
      %459 = llvm.load %439 : !llvm.ptr -> i64
      %460 = llvm.getelementptr %arg1[%459] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %458 = llvm.load %460 : !llvm.ptr -> i64
      %461 = arith.constant 0 : i32
      %462 = arith.extsi %461 : i32 to i64
      %463 = llvm.getelementptr %arg1[%462] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %458, %463 : i64, !llvm.ptr
      %464 = llvm.load %439 : !llvm.ptr -> i64
      %465 = llvm.getelementptr %arg0[%464] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %444, %465 : i64, !llvm.ptr
      %466 = llvm.load %439 : !llvm.ptr -> i64
      %467 = llvm.getelementptr %arg1[%466] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %448, %467 : i64, !llvm.ptr
      %468 = llvm.load %439 : !llvm.ptr -> i64
      %469 = arith.constant 1 : i32
      %471 = arith.extsi %469 : i32 to i64
      %470 = arith.subi %468, %471 : i64
      llvm.store %470, %439 : i64, !llvm.ptr
      %473 = arith.constant 0 : i32
      %474 = llvm.load %439 : !llvm.ptr -> i64
      %475 = arith.extsi %473 : i32 to i64
      func.call @sift_down_keys(%arg0, %arg1, %475, %474) : (!llvm.ptr, !llvm.ptr, i64, i64) -> ()
      cf.br ^bb81
    ^bb83:
    func.return
  }
  func.func @coordinate_values(%arg0: i32) -> () {
    %476 = arith.constant 1 : i32
    %477 = arith.extsi %476 : i32 to i64
    %478 = llvm.mlir.addressof @g_scale : !llvm.ptr
    llvm.store %477, %478 : i64, !llvm.ptr
    %479 = arith.constant 1 : i32
    %480 = llvm.mlir.constant(1 : i64) : i64
    %481 = llvm.alloca %480 x i32 : (i64) -> !llvm.ptr
    llvm.store %479, %481 : i32, !llvm.ptr
    cf.br ^bb84
    ^bb84:
    %482 = llvm.load %481 : !llvm.ptr -> i32
    %483 = arith.cmpi sle, %482, %arg0 : i32
    cf.cond_br %483, ^bb85, ^bb86
    ^bb85:
      %485 = llvm.mlir.addressof @g_scale : !llvm.ptr
      %486 = llvm.load %485 : !llvm.ptr -> i64
      %487 = llvm.load %481 : !llvm.ptr -> i32
      %488 = arith.extsi %487 : i32 to i64
      %484 = func.call @lcm64(%486, %488) : (i64, i64) -> i64
      %489 = llvm.mlir.addressof @g_scale : !llvm.ptr
      llvm.store %484, %489 : i64, !llvm.ptr
      %490 = llvm.load %481 : !llvm.ptr -> i32
      %491 = arith.constant 1 : i32
      %492 = arith.addi %490, %491 : i32
      llvm.store %492, %481 : i32, !llvm.ptr
      cf.br ^bb84
    ^bb86:
    %493 = arith.constant 256 : i32
    %494 = llvm.mlir.constant(1 : i64) : i64
    %495 = llvm.alloca %494 x i32 : (i64) -> !llvm.ptr
    llvm.store %493, %495 : i32, !llvm.ptr
    %497 = llvm.load %495 : !llvm.ptr -> i32
    %498 = arith.extsi %497 : i32 to i64
    %499 = arith.constant 8 : i32
    %501 = arith.extsi %499 : i32 to i64
    %500 = arith.muli %498, %501 : i64
    %496 = func.call @malloc(%500) : (i64) -> !llvm.ptr
    %502 = llvm.mlir.addressof @g_coords : !llvm.ptr
    llvm.store %496, %502 : !llvm.ptr, !llvm.ptr
    %503 = arith.constant 0 : i32
    %504 = llvm.mlir.addressof @g_ncoords : !llvm.ptr
    llvm.store %503, %504 : i32, !llvm.ptr
    %505 = arith.constant 0 : i32
    %506 = llvm.mlir.addressof @g_coords : !llvm.ptr
    %507 = llvm.load %506 : !llvm.ptr -> !llvm.ptr
    %508 = arith.constant 0 : i32
    %509 = arith.extsi %505 : i32 to i64
    %510 = arith.extsi %508 : i32 to i64
    %511 = llvm.getelementptr %507[%510] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %509, %511 : i64, !llvm.ptr
    %512 = arith.constant 1 : i32
    %513 = llvm.mlir.addressof @g_ncoords : !llvm.ptr
    llvm.store %512, %513 : i32, !llvm.ptr
    %514 = arith.constant 2 : i32
    %515 = llvm.mlir.constant(1 : i64) : i64
    %516 = llvm.alloca %515 x i32 : (i64) -> !llvm.ptr
    llvm.store %514, %516 : i32, !llvm.ptr
    cf.br ^bb87
    ^bb87:
    %517 = llvm.load %516 : !llvm.ptr -> i32
    %518 = arith.cmpi sle, %517, %arg0 : i32
    cf.cond_br %518, ^bb88, ^bb89
    ^bb88:
      %519 = llvm.mlir.addressof @g_scale : !llvm.ptr
      %520 = llvm.load %519 : !llvm.ptr -> i64
      %521 = llvm.load %516 : !llvm.ptr -> i32
      %522 = arith.extsi %521 : i32 to i64
      %523 = arith.divsi %520, %522 : i64
      %524 = arith.constant 1 : i32
      %525 = llvm.mlir.constant(1 : i64) : i64
      %526 = llvm.alloca %525 x i32 : (i64) -> !llvm.ptr
      llvm.store %524, %526 : i32, !llvm.ptr
      cf.br ^bb90
      ^bb90:
      %527 = llvm.load %526 : !llvm.ptr -> i32
      %528 = llvm.load %516 : !llvm.ptr -> i32
      %529 = arith.cmpi slt, %527, %528 : i32
      cf.cond_br %529, ^bb91, ^bb92
      ^bb91:
        %531 = llvm.load %526 : !llvm.ptr -> i32
        %532 = arith.extsi %531 : i32 to i64
        %533 = llvm.load %516 : !llvm.ptr -> i32
        %534 = arith.extsi %533 : i32 to i64
        %530 = func.call @gcd64(%532, %534) : (i64, i64) -> i64
        %535 = arith.constant 1 : i32
        %537 = arith.extsi %535 : i32 to i64
        %536 = arith.cmpi eq, %530, %537 : i64
        cf.cond_br %536, ^bb93, ^bb94
        ^bb93:
          %538 = llvm.load %526 : !llvm.ptr -> i32
          %539 = arith.extsi %538 : i32 to i64
          %540 = arith.muli %539, %523 : i64
          %541 = llvm.mlir.addressof @g_ncoords : !llvm.ptr
          %542 = llvm.load %541 : !llvm.ptr -> i32
          %543 = arith.constant 2 : i32
          %544 = arith.addi %542, %543 : i32
          %545 = llvm.load %495 : !llvm.ptr -> i32
          %546 = arith.cmpi sgt, %544, %545 : i32
          cf.cond_br %546, ^bb96, ^bb97
          ^bb96:
            %547 = llvm.load %495 : !llvm.ptr -> i32
            %548 = arith.constant 2 : i32
            %549 = arith.muli %547, %548 : i32
            llvm.store %549, %495 : i32, !llvm.ptr
            %551 = llvm.mlir.addressof @g_coords : !llvm.ptr
            %552 = llvm.load %551 : !llvm.ptr -> !llvm.ptr
            %553 = llvm.load %495 : !llvm.ptr -> i32
            %554 = arith.extsi %553 : i32 to i64
            %555 = arith.constant 8 : i32
            %557 = arith.extsi %555 : i32 to i64
            %556 = arith.muli %554, %557 : i64
            %550 = func.call @realloc(%552, %556) : (!llvm.ptr, i64) -> !llvm.ptr
            %558 = llvm.mlir.addressof @g_coords : !llvm.ptr
            llvm.store %550, %558 : !llvm.ptr, !llvm.ptr
            cf.br ^bb98
          ^bb97:
            cf.br ^bb98
          ^bb98:
          %559 = llvm.mlir.addressof @g_coords : !llvm.ptr
          %560 = llvm.load %559 : !llvm.ptr -> !llvm.ptr
          %561 = llvm.mlir.addressof @g_ncoords : !llvm.ptr
          %562 = llvm.load %561 : !llvm.ptr -> i32
          %563 = arith.extsi %562 : i32 to i64
          %564 = llvm.getelementptr %560[%563] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          llvm.store %540, %564 : i64, !llvm.ptr
          %565 = llvm.mlir.addressof @g_ncoords : !llvm.ptr
          %566 = llvm.load %565 : !llvm.ptr -> i32
          %567 = arith.constant 1 : i32
          %568 = arith.addi %566, %567 : i32
          %569 = llvm.mlir.addressof @g_ncoords : !llvm.ptr
          llvm.store %568, %569 : i32, !llvm.ptr
          %571 = arith.constant 0 : i64
          %570 = arith.subi %571, %540 : i64
          %572 = llvm.mlir.addressof @g_coords : !llvm.ptr
          %573 = llvm.load %572 : !llvm.ptr -> !llvm.ptr
          %574 = llvm.mlir.addressof @g_ncoords : !llvm.ptr
          %575 = llvm.load %574 : !llvm.ptr -> i32
          %576 = arith.extsi %575 : i32 to i64
          %577 = llvm.getelementptr %573[%576] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          llvm.store %570, %577 : i64, !llvm.ptr
          %578 = llvm.mlir.addressof @g_ncoords : !llvm.ptr
          %579 = llvm.load %578 : !llvm.ptr -> i32
          %580 = arith.constant 1 : i32
          %581 = arith.addi %579, %580 : i32
          %582 = llvm.mlir.addressof @g_ncoords : !llvm.ptr
          llvm.store %581, %582 : i32, !llvm.ptr
          cf.br ^bb95
        ^bb94:
          cf.br ^bb95
        ^bb95:
        %583 = llvm.load %526 : !llvm.ptr -> i32
        %584 = arith.constant 1 : i32
        %585 = arith.addi %583, %584 : i32
        llvm.store %585, %526 : i32, !llvm.ptr
        cf.br ^bb90
      ^bb92:
      %586 = llvm.load %516 : !llvm.ptr -> i32
      %587 = arith.constant 1 : i32
      %588 = arith.addi %586, %587 : i32
      llvm.store %588, %516 : i32, !llvm.ptr
      cf.br ^bb87
    ^bb89:
    %590 = llvm.mlir.addressof @g_coords : !llvm.ptr
    %591 = llvm.load %590 : !llvm.ptr -> !llvm.ptr
    %592 = llvm.mlir.addressof @g_ncoords : !llvm.ptr
    %593 = llvm.load %592 : !llvm.ptr -> i32
    %594 = arith.extsi %593 : i32 to i64
    func.call @heapsort_i64(%591, %594) : (!llvm.ptr, i64) -> ()
    %595 = arith.constant 0 : i32
    %596 = llvm.mlir.constant(1 : i64) : i64
    %597 = llvm.alloca %596 x i32 : (i64) -> !llvm.ptr
    llvm.store %595, %597 : i32, !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 ^bb99
    ^bb99:
    %601 = llvm.load %600 : !llvm.ptr -> i32
    %602 = llvm.mlir.addressof @g_ncoords : !llvm.ptr
    %603 = llvm.load %602 : !llvm.ptr -> i32
    %604 = arith.cmpi slt, %601, %603 : i32
    cf.cond_br %604, ^bb100, ^bb101
    ^bb100:
      %605 = llvm.load %600 : !llvm.ptr -> i32
      %606 = arith.constant 0 : i32
      %607 = arith.cmpi eq, %605, %606 : i32
      %608 = scf.if %607 -> (i1) {
        %609 = arith.constant true
        scf.yield %609 : i1
      } else {
        %611 = llvm.mlir.addressof @g_coords : !llvm.ptr
        %612 = llvm.load %611 : !llvm.ptr -> !llvm.ptr
        %613 = llvm.load %600 : !llvm.ptr -> i32
        %614 = arith.extsi %613 : i32 to i64
        %615 = llvm.getelementptr %612[%614] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %610 = llvm.load %615 : !llvm.ptr -> i64
        %617 = llvm.mlir.addressof @g_coords : !llvm.ptr
        %618 = llvm.load %617 : !llvm.ptr -> !llvm.ptr
        %619 = llvm.load %600 : !llvm.ptr -> i32
        %620 = arith.constant 1 : i32
        %621 = arith.subi %619, %620 : i32
        %622 = arith.extsi %621 : i32 to i64
        %623 = llvm.getelementptr %618[%622] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %616 = llvm.load %623 : !llvm.ptr -> i64
        %624 = arith.cmpi ne, %610, %616 : i64
        scf.yield %624 : i1
      }
      cf.cond_br %608, ^bb102, ^bb103
      ^bb102:
        %626 = llvm.mlir.addressof @g_coords : !llvm.ptr
        %627 = llvm.load %626 : !llvm.ptr -> !llvm.ptr
        %628 = llvm.load %600 : !llvm.ptr -> i32
        %629 = arith.extsi %628 : i32 to i64
        %630 = llvm.getelementptr %627[%629] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %625 = llvm.load %630 : !llvm.ptr -> i64
        %631 = llvm.mlir.addressof @g_coords : !llvm.ptr
        %632 = llvm.load %631 : !llvm.ptr -> !llvm.ptr
        %633 = llvm.load %597 : !llvm.ptr -> i32
        %634 = arith.extsi %633 : i32 to i64
        %635 = llvm.getelementptr %632[%634] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %625, %635 : i64, !llvm.ptr
        %636 = llvm.load %597 : !llvm.ptr -> i32
        %637 = arith.constant 1 : i32
        %638 = arith.addi %636, %637 : i32
        llvm.store %638, %597 : i32, !llvm.ptr
        cf.br ^bb104
      ^bb103:
        cf.br ^bb104
      ^bb104:
      %639 = llvm.load %600 : !llvm.ptr -> i32
      %640 = arith.constant 1 : i32
      %641 = arith.addi %639, %640 : i32
      llvm.store %641, %600 : i32, !llvm.ptr
      cf.br ^bb99
    ^bb101:
    %642 = llvm.load %597 : !llvm.ptr -> i32
    %643 = llvm.mlir.addressof @g_ncoords : !llvm.ptr
    llvm.store %642, %643 : i32, !llvm.ptr
    func.return
  }
  func.func @build_lifted_points(%arg0: i32) -> () {
    func.call @coordinate_values(%arg0) : (i32) -> ()
    %645 = llvm.mlir.addressof @g_scale : !llvm.ptr
    %646 = llvm.load %645 : !llvm.ptr -> i64
    %647 = llvm.mlir.addressof @g_scale : !llvm.ptr
    %648 = llvm.load %647 : !llvm.ptr -> i64
    %649 = arith.muli %646, %648 : i64
    %651 = llvm.mlir.addressof @g_ncoords : !llvm.ptr
    %652 = llvm.load %651 : !llvm.ptr -> i32
    %653 = arith.extsi %652 : i32 to i64
    %654 = arith.constant 8 : i32
    %656 = arith.extsi %654 : i32 to i64
    %655 = arith.muli %653, %656 : i64
    %650 = func.call @malloc(%655) : (i64) -> !llvm.ptr
    %657 = arith.constant 0 : i32
    %658 = llvm.mlir.constant(1 : i64) : i64
    %659 = llvm.alloca %658 x i32 : (i64) -> !llvm.ptr
    llvm.store %657, %659 : i32, !llvm.ptr
    cf.br ^bb105
    ^bb105:
    %660 = llvm.load %659 : !llvm.ptr -> i32
    %661 = llvm.mlir.addressof @g_ncoords : !llvm.ptr
    %662 = llvm.load %661 : !llvm.ptr -> i32
    %663 = arith.cmpi slt, %660, %662 : i32
    cf.cond_br %663, ^bb106, ^bb107
    ^bb106:
      %665 = llvm.mlir.addressof @g_coords : !llvm.ptr
      %666 = llvm.load %665 : !llvm.ptr -> !llvm.ptr
      %667 = llvm.load %659 : !llvm.ptr -> i32
      %668 = arith.extsi %667 : i32 to i64
      %669 = llvm.getelementptr %666[%668] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %664 = llvm.load %669 : !llvm.ptr -> i64
      %671 = llvm.mlir.addressof @g_coords : !llvm.ptr
      %672 = llvm.load %671 : !llvm.ptr -> !llvm.ptr
      %673 = llvm.load %659 : !llvm.ptr -> i32
      %674 = arith.extsi %673 : i32 to i64
      %675 = llvm.getelementptr %672[%674] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %670 = llvm.load %675 : !llvm.ptr -> i64
      %676 = arith.muli %664, %670 : i64
      %677 = llvm.load %659 : !llvm.ptr -> i32
      %678 = arith.extsi %677 : i32 to i64
      %679 = llvm.getelementptr %650[%678] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %676, %679 : i64, !llvm.ptr
      %680 = llvm.load %659 : !llvm.ptr -> i32
      %681 = arith.constant 1 : i32
      %682 = arith.addi %680, %681 : i32
      llvm.store %682, %659 : i32, !llvm.ptr
      cf.br ^bb105
    ^bb107:
    %683 = arith.constant 1 : i32
    %684 = arith.constant 16 : i32
    %685 = arith.shli %683, %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
    %689 = llvm.load %687 : !llvm.ptr -> i32
    %690 = arith.extsi %689 : i32 to i64
    %691 = arith.constant 8 : i32
    %693 = arith.extsi %691 : i32 to i64
    %692 = arith.muli %690, %693 : i64
    %688 = func.call @malloc(%692) : (i64) -> !llvm.ptr
    %694 = llvm.mlir.addressof @g_px : !llvm.ptr
    llvm.store %688, %694 : !llvm.ptr, !llvm.ptr
    %696 = llvm.load %687 : !llvm.ptr -> i32
    %697 = arith.extsi %696 : i32 to i64
    %698 = arith.constant 8 : i32
    %700 = arith.extsi %698 : i32 to i64
    %699 = arith.muli %697, %700 : i64
    %695 = func.call @malloc(%699) : (i64) -> !llvm.ptr
    %701 = llvm.mlir.addressof @g_py : !llvm.ptr
    llvm.store %695, %701 : !llvm.ptr, !llvm.ptr
    %703 = llvm.load %687 : !llvm.ptr -> i32
    %704 = arith.extsi %703 : i32 to i64
    %705 = arith.constant 8 : i32
    %707 = arith.extsi %705 : i32 to i64
    %706 = arith.muli %704, %707 : i64
    %702 = func.call @malloc(%706) : (i64) -> !llvm.ptr
    %708 = llvm.mlir.addressof @g_pz : !llvm.ptr
    llvm.store %702, %708 : !llvm.ptr, !llvm.ptr
    %709 = arith.constant 0 : i32
    %710 = llvm.mlir.addressof @g_npoints : !llvm.ptr
    llvm.store %709, %710 : i32, !llvm.ptr
    %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 ^bb108
    ^bb108:
    %714 = llvm.load %713 : !llvm.ptr -> i32
    %715 = llvm.mlir.addressof @g_ncoords : !llvm.ptr
    %716 = llvm.load %715 : !llvm.ptr -> i32
    %717 = arith.cmpi slt, %714, %716 : i32
    cf.cond_br %717, ^bb109, ^bb110
    ^bb109:
      %719 = llvm.mlir.addressof @g_coords : !llvm.ptr
      %720 = llvm.load %719 : !llvm.ptr -> !llvm.ptr
      %721 = llvm.load %713 : !llvm.ptr -> i32
      %722 = arith.extsi %721 : i32 to i64
      %723 = llvm.getelementptr %720[%722] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %718 = llvm.load %723 : !llvm.ptr -> i64
      %725 = llvm.load %713 : !llvm.ptr -> i32
      %726 = arith.extsi %725 : i32 to i64
      %727 = llvm.getelementptr %650[%726] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %724 = llvm.load %727 : !llvm.ptr -> i64
      %728 = arith.constant 0 : i32
      %729 = llvm.mlir.constant(1 : i64) : i64
      %730 = llvm.alloca %729 x i32 : (i64) -> !llvm.ptr
      llvm.store %728, %730 : i32, !llvm.ptr
      cf.br ^bb111
      ^bb111:
      %731 = llvm.load %730 : !llvm.ptr -> i32
      %732 = llvm.mlir.addressof @g_ncoords : !llvm.ptr
      %733 = llvm.load %732 : !llvm.ptr -> i32
      %734 = arith.cmpi slt, %731, %733 : i32
      cf.cond_br %734, ^bb112, ^bb113
      ^bb112:
        %736 = llvm.load %730 : !llvm.ptr -> i32
        %737 = arith.extsi %736 : i32 to i64
        %738 = llvm.getelementptr %650[%737] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %735 = llvm.load %738 : !llvm.ptr -> i64
        %739 = arith.addi %724, %735 : i64
        %740 = arith.cmpi slt, %739, %649 : i64
        cf.cond_br %740, ^bb114, ^bb115
        ^bb114:
          %741 = llvm.mlir.addressof @g_npoints : !llvm.ptr
          %742 = llvm.load %741 : !llvm.ptr -> i32
          %743 = llvm.load %687 : !llvm.ptr -> i32
          %744 = arith.cmpi sge, %742, %743 : i32
          cf.cond_br %744, ^bb117, ^bb118
          ^bb117:
            %745 = llvm.load %687 : !llvm.ptr -> i32
            %746 = arith.constant 2 : i32
            %747 = arith.muli %745, %746 : i32
            llvm.store %747, %687 : i32, !llvm.ptr
            %749 = llvm.mlir.addressof @g_px : !llvm.ptr
            %750 = llvm.load %749 : !llvm.ptr -> !llvm.ptr
            %751 = llvm.load %687 : !llvm.ptr -> i32
            %752 = arith.extsi %751 : i32 to i64
            %753 = arith.constant 8 : i32
            %755 = arith.extsi %753 : i32 to i64
            %754 = arith.muli %752, %755 : i64
            %748 = func.call @realloc(%750, %754) : (!llvm.ptr, i64) -> !llvm.ptr
            %756 = llvm.mlir.addressof @g_px : !llvm.ptr
            llvm.store %748, %756 : !llvm.ptr, !llvm.ptr
            %758 = llvm.mlir.addressof @g_py : !llvm.ptr
            %759 = llvm.load %758 : !llvm.ptr -> !llvm.ptr
            %760 = llvm.load %687 : !llvm.ptr -> i32
            %761 = arith.extsi %760 : i32 to i64
            %762 = arith.constant 8 : i32
            %764 = arith.extsi %762 : i32 to i64
            %763 = arith.muli %761, %764 : i64
            %757 = func.call @realloc(%759, %763) : (!llvm.ptr, i64) -> !llvm.ptr
            %765 = llvm.mlir.addressof @g_py : !llvm.ptr
            llvm.store %757, %765 : !llvm.ptr, !llvm.ptr
            %767 = llvm.mlir.addressof @g_pz : !llvm.ptr
            %768 = llvm.load %767 : !llvm.ptr -> !llvm.ptr
            %769 = llvm.load %687 : !llvm.ptr -> i32
            %770 = arith.extsi %769 : i32 to i64
            %771 = arith.constant 8 : i32
            %773 = arith.extsi %771 : i32 to i64
            %772 = arith.muli %770, %773 : i64
            %766 = func.call @realloc(%768, %772) : (!llvm.ptr, i64) -> !llvm.ptr
            %774 = llvm.mlir.addressof @g_pz : !llvm.ptr
            llvm.store %766, %774 : !llvm.ptr, !llvm.ptr
            cf.br ^bb119
          ^bb118:
            cf.br ^bb119
          ^bb119:
          %775 = llvm.mlir.addressof @g_px : !llvm.ptr
          %776 = llvm.load %775 : !llvm.ptr -> !llvm.ptr
          %777 = llvm.mlir.addressof @g_npoints : !llvm.ptr
          %778 = llvm.load %777 : !llvm.ptr -> i32
          %779 = arith.extsi %778 : i32 to i64
          %780 = llvm.getelementptr %776[%779] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          llvm.store %718, %780 : i64, !llvm.ptr
          %782 = llvm.mlir.addressof @g_coords : !llvm.ptr
          %783 = llvm.load %782 : !llvm.ptr -> !llvm.ptr
          %784 = llvm.load %730 : !llvm.ptr -> i32
          %785 = arith.extsi %784 : i32 to i64
          %786 = llvm.getelementptr %783[%785] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %781 = llvm.load %786 : !llvm.ptr -> i64
          %787 = llvm.mlir.addressof @g_py : !llvm.ptr
          %788 = llvm.load %787 : !llvm.ptr -> !llvm.ptr
          %789 = llvm.mlir.addressof @g_npoints : !llvm.ptr
          %790 = llvm.load %789 : !llvm.ptr -> i32
          %791 = arith.extsi %790 : i32 to i64
          %792 = llvm.getelementptr %788[%791] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          llvm.store %781, %792 : i64, !llvm.ptr
          %793 = arith.addi %739, %649 : i64
          %794 = llvm.mlir.addressof @g_pz : !llvm.ptr
          %795 = llvm.load %794 : !llvm.ptr -> !llvm.ptr
          %796 = llvm.mlir.addressof @g_npoints : !llvm.ptr
          %797 = llvm.load %796 : !llvm.ptr -> i32
          %798 = arith.extsi %797 : i32 to i64
          %799 = llvm.getelementptr %795[%798] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          llvm.store %793, %799 : i64, !llvm.ptr
          %800 = llvm.mlir.addressof @g_npoints : !llvm.ptr
          %801 = llvm.load %800 : !llvm.ptr -> i32
          %802 = arith.constant 1 : i32
          %803 = arith.addi %801, %802 : i32
          %804 = llvm.mlir.addressof @g_npoints : !llvm.ptr
          llvm.store %803, %804 : i32, !llvm.ptr
          cf.br ^bb116
        ^bb115:
          cf.br ^bb116
        ^bb116:
        %805 = llvm.load %730 : !llvm.ptr -> i32
        %806 = arith.constant 1 : i32
        %807 = arith.addi %805, %806 : i32
        llvm.store %807, %730 : i32, !llvm.ptr
        cf.br ^bb111
      ^bb113:
      %808 = llvm.load %713 : !llvm.ptr -> i32
      %809 = arith.constant 1 : i32
      %810 = arith.addi %808, %809 : i32
      llvm.store %810, %713 : i32, !llvm.ptr
      cf.br ^bb108
    ^bb110:
    func.call @free(%650) : (!llvm.ptr) -> ()
    func.return
  }
  func.func @count_unordered_triples() -> i64 {
    %812 = arith.constant 0 : i32
    %813 = arith.extsi %812 : i32 to i64
    %814 = llvm.mlir.constant(1 : i64) : i64
    %815 = llvm.alloca %814 x i64 : (i64) -> !llvm.ptr
    llvm.store %813, %815 : i64, !llvm.ptr
    %816 = llvm.mlir.addressof @g_npoints : !llvm.ptr
    %817 = llvm.load %816 : !llvm.ptr -> i32
    %819 = arith.extsi %817 : i32 to i64
    %820 = arith.constant 8 : i32
    %822 = arith.extsi %820 : i32 to i64
    %821 = arith.muli %819, %822 : i64
    %818 = func.call @malloc(%821) : (i64) -> !llvm.ptr
    %824 = arith.extsi %817 : i32 to i64
    %825 = arith.constant 8 : i32
    %827 = arith.extsi %825 : i32 to i64
    %826 = arith.muli %824, %827 : i64
    %823 = func.call @malloc(%826) : (i64) -> !llvm.ptr
    %828 = arith.constant 0 : i32
    %829 = llvm.mlir.constant(1 : i64) : i64
    %830 = llvm.alloca %829 x i32 : (i64) -> !llvm.ptr
    llvm.store %828, %830 : i32, !llvm.ptr
    cf.br ^bb120
    ^bb120:
    %831 = llvm.load %830 : !llvm.ptr -> i32
    %832 = arith.constant 2 : i32
    %833 = arith.subi %817, %832 : i32
    %834 = arith.cmpi slt, %831, %833 : i32
    cf.cond_br %834, ^bb121, ^bb122
    ^bb121:
      %836 = llvm.mlir.addressof @g_px : !llvm.ptr
      %837 = llvm.load %836 : !llvm.ptr -> !llvm.ptr
      %838 = llvm.load %830 : !llvm.ptr -> i32
      %839 = arith.extsi %838 : i32 to i64
      %840 = llvm.getelementptr %837[%839] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %835 = llvm.load %840 : !llvm.ptr -> i64
      %842 = llvm.mlir.addressof @g_py : !llvm.ptr
      %843 = llvm.load %842 : !llvm.ptr -> !llvm.ptr
      %844 = llvm.load %830 : !llvm.ptr -> i32
      %845 = arith.extsi %844 : i32 to i64
      %846 = llvm.getelementptr %843[%845] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %841 = llvm.load %846 : !llvm.ptr -> i64
      %848 = llvm.mlir.addressof @g_pz : !llvm.ptr
      %849 = llvm.load %848 : !llvm.ptr -> !llvm.ptr
      %850 = llvm.load %830 : !llvm.ptr -> i32
      %851 = arith.extsi %850 : i32 to i64
      %852 = llvm.getelementptr %849[%851] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %847 = llvm.load %852 : !llvm.ptr -> i64
      %853 = arith.constant 0 : i32
      %854 = llvm.mlir.constant(1 : i64) : i64
      %855 = llvm.alloca %854 x i32 : (i64) -> !llvm.ptr
      llvm.store %853, %855 : i32, !llvm.ptr
      %856 = arith.constant 0 : i32
      %858 = arith.extsi %856 : i32 to i64
      %857 = arith.cmpi ne, %835, %858 : i64
      cf.cond_br %857, ^bb123, ^bb124
      ^bb123:
        %859 = llvm.load %830 : !llvm.ptr -> i32
        %860 = arith.constant 1 : i32
        %861 = arith.addi %859, %860 : i32
        %862 = llvm.mlir.constant(1 : i64) : i64
        %863 = llvm.alloca %862 x i32 : (i64) -> !llvm.ptr
        llvm.store %861, %863 : i32, !llvm.ptr
        cf.br ^bb126
        ^bb126:
        %864 = llvm.load %863 : !llvm.ptr -> i32
        %865 = arith.cmpi slt, %864, %817 : i32
        cf.cond_br %865, ^bb127, ^bb128
        ^bb127:
          %867 = llvm.mlir.addressof @g_px : !llvm.ptr
          %868 = llvm.load %867 : !llvm.ptr -> !llvm.ptr
          %869 = llvm.load %863 : !llvm.ptr -> i32
          %870 = arith.extsi %869 : i32 to i64
          %871 = llvm.getelementptr %868[%870] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %866 = llvm.load %871 : !llvm.ptr -> i64
          %873 = llvm.mlir.addressof @g_py : !llvm.ptr
          %874 = llvm.load %873 : !llvm.ptr -> !llvm.ptr
          %875 = llvm.load %863 : !llvm.ptr -> i32
          %876 = arith.extsi %875 : i32 to i64
          %877 = llvm.getelementptr %874[%876] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %872 = llvm.load %877 : !llvm.ptr -> i64
          %879 = llvm.mlir.addressof @g_pz : !llvm.ptr
          %880 = llvm.load %879 : !llvm.ptr -> !llvm.ptr
          %881 = llvm.load %863 : !llvm.ptr -> i32
          %882 = arith.extsi %881 : i32 to i64
          %883 = llvm.getelementptr %880[%882] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %878 = llvm.load %883 : !llvm.ptr -> i64
          %884 = arith.muli %841, %866 : i64
          %885 = arith.muli %835, %872 : i64
          %886 = arith.subi %884, %885 : i64
          %887 = llvm.mlir.constant(1 : i64) : i64
          %888 = llvm.alloca %887 x i64 : (i64) -> !llvm.ptr
          llvm.store %886, %888 : i64, !llvm.ptr
          %889 = arith.muli %847, %866 : i64
          %890 = arith.muli %835, %878 : i64
          %891 = arith.subi %889, %890 : i64
          %892 = llvm.mlir.constant(1 : i64) : i64
          %893 = llvm.alloca %892 x i64 : (i64) -> !llvm.ptr
          llvm.store %891, %893 : i64, !llvm.ptr
          %895 = llvm.load %888 : !llvm.ptr -> i64
          %896 = llvm.load %893 : !llvm.ptr -> i64
          %894 = func.call @gcd64(%895, %896) : (i64, i64) -> i64
          %897 = arith.constant 0 : i32
          %899 = arith.extsi %897 : i32 to i64
          %898 = arith.cmpi ne, %894, %899 : i64
          cf.cond_br %898, ^bb129, ^bb130
          ^bb129:
            %900 = llvm.load %888 : !llvm.ptr -> i64
            %901 = arith.divsi %900, %894 : i64
            llvm.store %901, %888 : i64, !llvm.ptr
            %902 = llvm.load %893 : !llvm.ptr -> i64
            %903 = arith.divsi %902, %894 : i64
            llvm.store %903, %893 : i64, !llvm.ptr
            cf.br ^bb131
          ^bb130:
            cf.br ^bb131
          ^bb131:
          %904 = llvm.load %888 : !llvm.ptr -> i64
          %905 = arith.constant 0 : i32
          %907 = arith.extsi %905 : i32 to i64
          %906 = arith.cmpi slt, %904, %907 : i64
          %908 = scf.if %906 -> (i1) {
            %909 = arith.constant true
            scf.yield %909 : i1
          } else {
            %910 = llvm.load %888 : !llvm.ptr -> i64
            %911 = arith.constant 0 : i32
            %913 = arith.extsi %911 : i32 to i64
            %912 = arith.cmpi eq, %910, %913 : i64
            %914 = scf.if %912 -> (i1) {
              %915 = llvm.load %893 : !llvm.ptr -> i64
              %916 = arith.constant 0 : i32
              %918 = arith.extsi %916 : i32 to i64
              %917 = arith.cmpi slt, %915, %918 : i64
              scf.yield %917 : i1
            } else {
              %919 = arith.constant false
              scf.yield %919 : i1
            }
            scf.yield %914 : i1
          }
          cf.cond_br %908, ^bb132, ^bb133
          ^bb132:
            %920 = llvm.load %888 : !llvm.ptr -> i64
            %922 = arith.constant 0 : i64
            %921 = arith.subi %922, %920 : i64
            llvm.store %921, %888 : i64, !llvm.ptr
            %923 = llvm.load %893 : !llvm.ptr -> i64
            %925 = arith.constant 0 : i64
            %924 = arith.subi %925, %923 : i64
            llvm.store %924, %893 : i64, !llvm.ptr
            cf.br ^bb134
          ^bb133:
            cf.br ^bb134
          ^bb134:
          %926 = llvm.load %888 : !llvm.ptr -> i64
          %927 = llvm.load %855 : !llvm.ptr -> i32
          %928 = arith.extsi %927 : i32 to i64
          %929 = llvm.getelementptr %818[%928] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          llvm.store %926, %929 : i64, !llvm.ptr
          %930 = llvm.load %893 : !llvm.ptr -> i64
          %931 = llvm.load %855 : !llvm.ptr -> i32
          %932 = arith.extsi %931 : i32 to i64
          %933 = llvm.getelementptr %823[%932] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          llvm.store %930, %933 : i64, !llvm.ptr
          %934 = llvm.load %855 : !llvm.ptr -> i32
          %935 = arith.constant 1 : i32
          %936 = arith.addi %934, %935 : i32
          llvm.store %936, %855 : i32, !llvm.ptr
          %937 = llvm.load %863 : !llvm.ptr -> i32
          %938 = arith.constant 1 : i32
          %939 = arith.addi %937, %938 : i32
          llvm.store %939, %863 : i32, !llvm.ptr
          cf.br ^bb126
        ^bb128:
        cf.br ^bb125
      ^bb124:
        %940 = llvm.load %830 : !llvm.ptr -> i32
        %941 = arith.constant 1 : i32
        %942 = arith.addi %940, %941 : i32
        %943 = llvm.mlir.constant(1 : i64) : i64
        %944 = llvm.alloca %943 x i32 : (i64) -> !llvm.ptr
        llvm.store %942, %944 : i32, !llvm.ptr
        cf.br ^bb135
        ^bb135:
        %945 = llvm.load %944 : !llvm.ptr -> i32
        %946 = arith.cmpi slt, %945, %817 : i32
        cf.cond_br %946, ^bb136, ^bb137
        ^bb136:
          %948 = llvm.mlir.addressof @g_px : !llvm.ptr
          %949 = llvm.load %948 : !llvm.ptr -> !llvm.ptr
          %950 = llvm.load %944 : !llvm.ptr -> i32
          %951 = arith.extsi %950 : i32 to i64
          %952 = llvm.getelementptr %949[%951] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %947 = llvm.load %952 : !llvm.ptr -> i64
          %954 = llvm.mlir.addressof @g_py : !llvm.ptr
          %955 = llvm.load %954 : !llvm.ptr -> !llvm.ptr
          %956 = llvm.load %944 : !llvm.ptr -> i32
          %957 = arith.extsi %956 : i32 to i64
          %958 = llvm.getelementptr %955[%957] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %953 = llvm.load %958 : !llvm.ptr -> i64
          %960 = llvm.mlir.addressof @g_pz : !llvm.ptr
          %961 = llvm.load %960 : !llvm.ptr -> !llvm.ptr
          %962 = llvm.load %944 : !llvm.ptr -> i32
          %963 = arith.extsi %962 : i32 to i64
          %964 = llvm.getelementptr %961[%963] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %959 = llvm.load %964 : !llvm.ptr -> i64
          %965 = llvm.mlir.constant(1 : i64) : i64
          %966 = llvm.alloca %965 x i64 : (i64) -> !llvm.ptr
          llvm.store %947, %966 : i64, !llvm.ptr
          %967 = arith.muli %847, %953 : i64
          %968 = arith.muli %841, %959 : i64
          %969 = arith.subi %967, %968 : i64
          %970 = llvm.mlir.constant(1 : i64) : i64
          %971 = llvm.alloca %970 x i64 : (i64) -> !llvm.ptr
          llvm.store %969, %971 : i64, !llvm.ptr
          %973 = llvm.load %966 : !llvm.ptr -> i64
          %974 = llvm.load %971 : !llvm.ptr -> i64
          %972 = func.call @gcd64(%973, %974) : (i64, i64) -> i64
          %975 = arith.constant 0 : i32
          %977 = arith.extsi %975 : i32 to i64
          %976 = arith.cmpi ne, %972, %977 : i64
          cf.cond_br %976, ^bb138, ^bb139
          ^bb138:
            %978 = llvm.load %966 : !llvm.ptr -> i64
            %979 = arith.divsi %978, %972 : i64
            llvm.store %979, %966 : i64, !llvm.ptr
            %980 = llvm.load %971 : !llvm.ptr -> i64
            %981 = arith.divsi %980, %972 : i64
            llvm.store %981, %971 : i64, !llvm.ptr
            cf.br ^bb140
          ^bb139:
            cf.br ^bb140
          ^bb140:
          %982 = llvm.load %966 : !llvm.ptr -> i64
          %983 = arith.constant 0 : i32
          %985 = arith.extsi %983 : i32 to i64
          %984 = arith.cmpi slt, %982, %985 : i64
          %986 = scf.if %984 -> (i1) {
            %987 = arith.constant true
            scf.yield %987 : i1
          } else {
            %988 = llvm.load %966 : !llvm.ptr -> i64
            %989 = arith.constant 0 : i32
            %991 = arith.extsi %989 : i32 to i64
            %990 = arith.cmpi eq, %988, %991 : i64
            %992 = scf.if %990 -> (i1) {
              %993 = llvm.load %971 : !llvm.ptr -> i64
              %994 = arith.constant 0 : i32
              %996 = arith.extsi %994 : i32 to i64
              %995 = arith.cmpi slt, %993, %996 : i64
              scf.yield %995 : i1
            } else {
              %997 = arith.constant false
              scf.yield %997 : i1
            }
            scf.yield %992 : i1
          }
          cf.cond_br %986, ^bb141, ^bb142
          ^bb141:
            %998 = llvm.load %966 : !llvm.ptr -> i64
            %1000 = arith.constant 0 : i64
            %999 = arith.subi %1000, %998 : i64
            llvm.store %999, %966 : i64, !llvm.ptr
            %1001 = llvm.load %971 : !llvm.ptr -> i64
            %1003 = arith.constant 0 : i64
            %1002 = arith.subi %1003, %1001 : i64
            llvm.store %1002, %971 : i64, !llvm.ptr
            cf.br ^bb143
          ^bb142:
            cf.br ^bb143
          ^bb143:
          %1004 = llvm.load %966 : !llvm.ptr -> i64
          %1005 = llvm.load %855 : !llvm.ptr -> i32
          %1006 = arith.extsi %1005 : i32 to i64
          %1007 = llvm.getelementptr %818[%1006] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          llvm.store %1004, %1007 : i64, !llvm.ptr
          %1008 = llvm.load %971 : !llvm.ptr -> i64
          %1009 = llvm.load %855 : !llvm.ptr -> i32
          %1010 = arith.extsi %1009 : i32 to i64
          %1011 = llvm.getelementptr %823[%1010] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          llvm.store %1008, %1011 : i64, !llvm.ptr
          %1012 = llvm.load %855 : !llvm.ptr -> i32
          %1013 = arith.constant 1 : i32
          %1014 = arith.addi %1012, %1013 : i32
          llvm.store %1014, %855 : i32, !llvm.ptr
          %1015 = llvm.load %944 : !llvm.ptr -> i32
          %1016 = arith.constant 1 : i32
          %1017 = arith.addi %1015, %1016 : i32
          llvm.store %1017, %944 : i32, !llvm.ptr
          cf.br ^bb135
        ^bb137:
        cf.br ^bb125
      ^bb125:
      %1019 = llvm.load %855 : !llvm.ptr -> i32
      %1020 = arith.extsi %1019 : i32 to i64
      func.call @heapsort_keys(%818, %823, %1020) : (!llvm.ptr, !llvm.ptr, i64) -> ()
      %1021 = arith.constant 1 : i32
      %1022 = arith.extsi %1021 : i32 to i64
      %1023 = llvm.mlir.constant(1 : i64) : i64
      %1024 = llvm.alloca %1023 x i64 : (i64) -> !llvm.ptr
      llvm.store %1022, %1024 : i64, !llvm.ptr
      %1026 = arith.constant 0 : i32
      %1027 = arith.extsi %1026 : i32 to i64
      %1028 = llvm.getelementptr %818[%1027] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %1025 = llvm.load %1028 : !llvm.ptr -> i64
      %1029 = llvm.mlir.constant(1 : i64) : i64
      %1030 = llvm.alloca %1029 x i64 : (i64) -> !llvm.ptr
      llvm.store %1025, %1030 : i64, !llvm.ptr
      %1032 = arith.constant 0 : i32
      %1033 = arith.extsi %1032 : i32 to i64
      %1034 = llvm.getelementptr %823[%1033] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %1031 = llvm.load %1034 : !llvm.ptr -> i64
      %1035 = llvm.mlir.constant(1 : i64) : i64
      %1036 = llvm.alloca %1035 x i64 : (i64) -> !llvm.ptr
      llvm.store %1031, %1036 : i64, !llvm.ptr
      %1037 = arith.constant 1 : i32
      %1038 = llvm.mlir.constant(1 : i64) : i64
      %1039 = llvm.alloca %1038 x i32 : (i64) -> !llvm.ptr
      llvm.store %1037, %1039 : i32, !llvm.ptr
      cf.br ^bb144
      ^bb144:
      %1040 = llvm.load %1039 : !llvm.ptr -> i32
      %1041 = llvm.load %855 : !llvm.ptr -> i32
      %1042 = arith.cmpi slt, %1040, %1041 : i32
      cf.cond_br %1042, ^bb145, ^bb146
      ^bb145:
        %1044 = llvm.load %1039 : !llvm.ptr -> i32
        %1045 = arith.extsi %1044 : i32 to i64
        %1046 = llvm.getelementptr %818[%1045] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %1043 = llvm.load %1046 : !llvm.ptr -> i64
        %1047 = llvm.load %1030 : !llvm.ptr -> i64
        %1048 = arith.cmpi eq, %1043, %1047 : i64
        %1049 = scf.if %1048 -> (i1) {
          %1051 = llvm.load %1039 : !llvm.ptr -> i32
          %1052 = arith.extsi %1051 : i32 to i64
          %1053 = llvm.getelementptr %823[%1052] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %1050 = llvm.load %1053 : !llvm.ptr -> i64
          %1054 = llvm.load %1036 : !llvm.ptr -> i64
          %1055 = arith.cmpi eq, %1050, %1054 : i64
          scf.yield %1055 : i1
        } else {
          %1056 = arith.constant false
          scf.yield %1056 : i1
        }
        cf.cond_br %1049, ^bb147, ^bb148
        ^bb147:
          %1057 = llvm.load %1024 : !llvm.ptr -> i64
          %1058 = arith.constant 1 : i32
          %1060 = arith.extsi %1058 : i32 to i64
          %1059 = arith.addi %1057, %1060 : i64
          llvm.store %1059, %1024 : i64, !llvm.ptr
          cf.br ^bb149
        ^bb148:
          %1061 = llvm.load %1024 : !llvm.ptr -> i64
          %1062 = arith.constant 2 : i32
          %1064 = arith.extsi %1062 : i32 to i64
          %1063 = arith.cmpi sge, %1061, %1064 : i64
          cf.cond_br %1063, ^bb150, ^bb151
          ^bb150:
            %1065 = llvm.load %815 : !llvm.ptr -> i64
            %1066 = llvm.load %1024 : !llvm.ptr -> i64
            %1067 = llvm.load %1024 : !llvm.ptr -> i64
            %1068 = arith.constant 1 : i32
            %1070 = arith.extsi %1068 : i32 to i64
            %1069 = arith.subi %1067, %1070 : i64
            %1071 = arith.muli %1066, %1069 : i64
            %1072 = arith.constant 2 : i32
            %1074 = arith.extsi %1072 : i32 to i64
            %1073 = arith.divsi %1071, %1074 : i64
            %1075 = arith.addi %1065, %1073 : i64
            llvm.store %1075, %815 : i64, !llvm.ptr
            cf.br ^bb152
          ^bb151:
            cf.br ^bb152
          ^bb152:
          %1077 = llvm.load %1039 : !llvm.ptr -> i32
          %1078 = arith.extsi %1077 : i32 to i64
          %1079 = llvm.getelementptr %818[%1078] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %1076 = llvm.load %1079 : !llvm.ptr -> i64
          llvm.store %1076, %1030 : i64, !llvm.ptr
          %1081 = llvm.load %1039 : !llvm.ptr -> i32
          %1082 = arith.extsi %1081 : i32 to i64
          %1083 = llvm.getelementptr %823[%1082] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %1080 = llvm.load %1083 : !llvm.ptr -> i64
          llvm.store %1080, %1036 : i64, !llvm.ptr
          %1084 = arith.constant 1 : i32
          %1085 = arith.extsi %1084 : i32 to i64
          llvm.store %1085, %1024 : i64, !llvm.ptr
          cf.br ^bb149
        ^bb149:
        %1086 = llvm.load %1039 : !llvm.ptr -> i32
        %1087 = arith.constant 1 : i32
        %1088 = arith.addi %1086, %1087 : i32
        llvm.store %1088, %1039 : i32, !llvm.ptr
        cf.br ^bb144
      ^bb146:
      %1089 = llvm.load %1024 : !llvm.ptr -> i64
      %1090 = arith.constant 2 : i32
      %1092 = arith.extsi %1090 : i32 to i64
      %1091 = arith.cmpi sge, %1089, %1092 : i64
      cf.cond_br %1091, ^bb153, ^bb154
      ^bb153:
        %1093 = llvm.load %815 : !llvm.ptr -> i64
        %1094 = llvm.load %1024 : !llvm.ptr -> i64
        %1095 = llvm.load %1024 : !llvm.ptr -> i64
        %1096 = arith.constant 1 : i32
        %1098 = arith.extsi %1096 : i32 to i64
        %1097 = arith.subi %1095, %1098 : i64
        %1099 = arith.muli %1094, %1097 : i64
        %1100 = arith.constant 2 : i32
        %1102 = arith.extsi %1100 : i32 to i64
        %1101 = arith.divsi %1099, %1102 : i64
        %1103 = arith.addi %1093, %1101 : i64
        llvm.store %1103, %815 : i64, !llvm.ptr
        cf.br ^bb155
      ^bb154:
        cf.br ^bb155
      ^bb155:
      %1104 = llvm.load %830 : !llvm.ptr -> i32
      %1105 = arith.constant 1 : i32
      %1106 = arith.addi %1104, %1105 : i32
      llvm.store %1106, %830 : i32, !llvm.ptr
      cf.br ^bb120
    ^bb122:
    func.call @free(%818) : (!llvm.ptr) -> ()
    func.call @free(%823) : (!llvm.ptr) -> ()
    %1109 = llvm.load %815 : !llvm.ptr -> i64
    func.return %1109 : i64
  }
  func.func @compute_T(%arg0: i32) -> i64 {
    func.call @build_lifted_points(%arg0) : (i32) -> ()
    %1111 = func.call @count_unordered_triples() : () -> i64
    %1112 = arith.constant 6 : i32
    %1114 = arith.extsi %1112 : i32 to i64
    %1113 = arith.muli %1114, %1111 : i64
    %1116 = llvm.mlir.addressof @g_coords : !llvm.ptr
    %1117 = llvm.load %1116 : !llvm.ptr -> !llvm.ptr
    func.call @free(%1117) : (!llvm.ptr) -> ()
    %1119 = llvm.mlir.addressof @g_px : !llvm.ptr
    %1120 = llvm.load %1119 : !llvm.ptr -> !llvm.ptr
    func.call @free(%1120) : (!llvm.ptr) -> ()
    %1122 = llvm.mlir.addressof @g_py : !llvm.ptr
    %1123 = llvm.load %1122 : !llvm.ptr -> !llvm.ptr
    func.call @free(%1123) : (!llvm.ptr) -> ()
    %1125 = llvm.mlir.addressof @g_pz : !llvm.ptr
    %1126 = llvm.load %1125 : !llvm.ptr -> !llvm.ptr
    func.call @free(%1126) : (!llvm.ptr) -> ()
    func.return %1113 : i64
  }
  func.func @main() -> i32 {
    %1127 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %1129 = arith.constant 12 : i32
    %1128 = func.call @compute_T(%1129) : (i32) -> i64
    %1130 = llvm.call @printf(%1127, %1128) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    %1131 = arith.constant 0 : i32
    func.return %1131 : i32
  }
}