Problem 786

Billiard -- B(10^9). Uses floor_sum, Mertens function with Du Jiao sieve, and Mobius inversion.

Answer45594532839912702
Output45594532839912702
StatusPASS
Native helperno
Runtime160 ms
Peak memory70656 KB
Time complexityO(n) (estimated)
Space complexityO(n^2) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n)O(n log log n)
Space complexityO(n^2)O(n)
ApproachFlow solutionMobius sieve
VerdictOptimal

Flow source

# Project Euler 786
# Billiard -- B(10^9).
# Uses floor_sum, Mertens function with Du Jiao sieve, and Mobius inversion.

extern {
    function calloc(n: i64, size: i64) -> ptr<void>
    function free(p: ptr<void>) -> void
    function malloc(n: i64) -> ptr<void>
}

const HT_SIZE: i64 = 2097152
const HT_MASK: i64 = 2097151

let mut g_pref: ptr<i64> = null
let mut g_limit: i64 = 0
let mut g_ht_m_key: ptr<i64> = null
let mut g_ht_m_val: ptr<i64> = null
let mut g_ht_f_key: ptr<i64> = null
let mut g_ht_f_val: ptr<i64> = null

function floor_sum(n0: i64, m0: i64, a0: i64, b0: i64) -> i64 {
    let mut res: i64 = 0
    let mut n: i64 = n0
    let mut m: i64 = m0
    let mut a: i64 = a0
    let mut b: i64 = b0
    while true {
        if a >= m {
            res = res + (n - 1) * n * (a / m) / 2
            a = a % m
        }
        if b >= m {
            res = res + n * (b / m)
            b = b % m
        }
        let y_max: i64 = a * n + b
        if y_max < m { break }
        b = y_max % m
        n = y_max / m
        let tmp: i64 = m
        m = a
        a = tmp
    }
    return res
}

function icbrt(n: i64) -> i64 {
    if n <= 0 { return 0 }
    let mut bits: i64 = 0
    let mut t: i64 = n
    while t != 0 {
        bits = bits + 1
        t = t >> 1
    }
    let mut x: i64 = 1 << ((bits + 2) / 3)
    while true {
        let y: i64 = (2 * x + n / (x * x)) / 3
        if y >= x { break }
        x = y
    }
    while (x + 1) * (x + 1) * (x + 1) <= n {
        x = x + 1
    }
    while x * x * x > n {
        x = x - 1
    }
    return x
}

function ht_get(ht_key: ptr<i64>, ht_val: ptr<i64>, key: i64, out: ptr<i64>) -> i64 {
    let mut h: i64 = (key * 2654435761) & HT_MASK
    while ht_key[h] != 0 {
        if ht_key[h] == key {
            out[0] = ht_val[h]
            return 1
        }
        h = (h + 1) & HT_MASK
    }
    return 0
}

function ht_put(ht_key: ptr<i64>, ht_val: ptr<i64>, key: i64, val: i64) -> void {
    let mut h: i64 = (key * 2654435761) & HT_MASK
    while ht_key[h] != 0 {
        if ht_key[h] == key {
            ht_val[h] = val
            return
        }
        h = (h + 1) & HT_MASK
    }
    ht_key[h] = key
    ht_val[h] = val
}

function M_func(n: i64) -> i64 {
    if n <= 0 { return 0 }
    if n <= g_limit { return g_pref[n] }
    let out: ptr<i64> = malloc(8) as ptr<i64>
    if ht_get(g_ht_m_key, g_ht_m_val, n, out) == 1 {
        let v: i64 = out[0]
        free(out)
        return v
    }
    free(out)
    let mut res: i64 = 1
    let mut l: i64 = 2
    while l <= n {
        let q: i64 = n / l
        let r: i64 = n / q
        res = res - (r - l + 1) * M_func(q)
        l = r + 1
    }
    ht_put(g_ht_m_key, g_ht_m_val, n, res)
    return res
}

function F_func(n: i64) -> i64 {
    if n <= 0 { return 0 }
    let out: ptr<i64> = malloc(8) as ptr<i64>
    if ht_get(g_ht_f_key, g_ht_f_val, n, out) == 1 {
        let v: i64 = out[0]
        free(out)
        return v
    }
    free(out)
    let res: i64 = M_func(n) + F_func(n / 3)
    ht_put(g_ht_f_key, g_ht_f_val, n, res)
    return res
}

function count_points_nonprimitive(M: i64) -> i64 {
    if M < 28 { return 0 }
    let n: i64 = (M - 18) / 10
    let b: i64 = M - 10 * n
    let total: i64 = floor_sum(n, 18, 10, b)

    let n3: i64 = n / 3
    let b3: i64 = M - 30 * n3
    let total3: i64 = floor_sum(n3, 18, 30, b3)

    return total - total3
}

function count_points_primitive(M: i64) -> i64 {
    let max_d: i64 = M / 28
    if max_d <= 0 { return 0 }

    let limit: i64 = icbrt(max_d * max_d) + 64

    # Linear sieve for mu
    let mu: ptr<i64> = calloc(limit + 1, 8) as ptr<i64>
    let is_comp: ptr<i8> = calloc(limit + 1, 1) as ptr<i8>
    let primes: ptr<i64> = malloc((limit + 1) * 8) as ptr<i64>
    let mut pc: i64 = 0
    mu[1] = 1
    for i in 2..(limit + 1) {
        if is_comp[i] == 0 {
            primes[pc] = i
            pc = pc + 1
            mu[i] = -1
        }
        let mut j: i64 = 0
        while j < pc {
            let p: i64 = primes[j]
            let v: i64 = i * p
            if v > limit { break }
            is_comp[v] = 1
            if i % p == 0 {
                mu[v] = 0
                break
            }
            mu[v] = -mu[i]
            j = j + 1
        }
    }

    # Prefix sums of mu (Mertens function)
    let pref: ptr<i64> = calloc(limit + 1, 8) as ptr<i64>
    let mut s: i64 = 0
    for i in 1..(limit + 1) {
        s = s + mu[i]
        pref[i] = s
    }

    g_pref = pref
    g_limit = limit
    g_ht_m_key = calloc(HT_SIZE, 8) as ptr<i64>
    g_ht_m_val = calloc(HT_SIZE, 8) as ptr<i64>
    g_ht_f_key = calloc(HT_SIZE, 8) as ptr<i64>
    g_ht_f_val = calloc(HT_SIZE, 8) as ptr<i64>

    let mut ans: i64 = 0
    let mut l: i64 = 1
    while l <= max_d {
        let q: i64 = M / l
        let r: i64 = M / q
        let mut rr: i64 = r
        if rr > max_d { rr = max_d }
        let coef: i64 = F_func(rr) - F_func(l - 1)
        if coef != 0 {
            ans = ans + coef * count_points_nonprimitive(q)
        }
        l = rr + 1
    }

    free(mu)
    free(is_comp)
    free(primes)
    free(pref)
    free(g_ht_m_key)
    free(g_ht_m_val)
    free(g_ht_f_key)
    free(g_ht_f_val)
    return ans
}

function main() -> i32 {
    let N: i64 = 1000000000
    let M: i64 = 3 * N + 6
    let ans: i64 = 2 + 4 * count_points_primitive(M)
    printf("%lld\n", ans)
    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 floor_sum_i64_i64_i64_i64(int64_t n0, int64_t m0, int64_t a0, int64_t b0);
int64_t icbrt_i64(int64_t n);
int64_t ht_get_ptr_i64_ptr_i64_i64_ptr_i64(int64_t* ht_key, int64_t* ht_val, int64_t key, int64_t* out);
void ht_put_ptr_i64_ptr_i64_i64_i64(int64_t* ht_key, int64_t* ht_val, int64_t key, int64_t val);
int64_t M_func_i64(int64_t n);
int64_t F_func_i64(int64_t n);
int64_t count_points_nonprimitive_i64(int64_t M);
int64_t count_points_primitive_i64(int64_t M);
int32_t main(void);

static const int64_t HT_SIZE = 2097152;
static const int64_t HT_MASK = 2097151;

/* Module statics */
static int64_t* g_pref = NULL;
static int64_t g_limit = 0;
static int64_t* g_ht_m_key = NULL;
static int64_t* g_ht_m_val = NULL;
static int64_t* g_ht_f_key = NULL;
static int64_t* g_ht_f_val = NULL;




int64_t floor_sum_i64_i64_i64_i64(int64_t n0, int64_t m0, int64_t a0, int64_t b0) {
    int64_t res = 0;
    int64_t n = n0;
    int64_t m = m0;
    int64_t a = a0;
    int64_t b = b0;
    while (1) {
        if (a >= m) {
            res = (res + FLOW_CHECKED_DIV(((((n - 1) * n) * FLOW_CHECKED_DIV((a), (m)))), (2)));
            a = FLOW_CHECKED_MOD((a), (m));
        }
        if (b >= m) {
            res = (res + (n * FLOW_CHECKED_DIV((b), (m))));
            b = FLOW_CHECKED_MOD((b), (m));
        }
        int64_t y_max = ((a * n) + b);
        if (y_max < m) {
            break;
        }
        b = FLOW_CHECKED_MOD((y_max), (m));
        n = FLOW_CHECKED_DIV((y_max), (m));
        int64_t tmp = m;
        m = a;
        a = tmp;
    }
    return res;
}

int64_t icbrt_i64(int64_t n) {
    if (n <= 0) {
        return 0;
    }
    int64_t bits = 0;
    int64_t t = n;
    while (t != 0) {
        bits = (bits + 1);
        t = FLOW_CHECKED_SHR((t), (1));
    }
    int64_t x = FLOW_CHECKED_SHL((1), (FLOW_CHECKED_DIV(((bits + 2)), (3))));
    while (1) {
        int64_t y = FLOW_CHECKED_DIV((((2 * x) + FLOW_CHECKED_DIV((n), ((x * x))))), (3));
        if (y >= x) {
            break;
        }
        x = y;
    }
    while ((((x + 1) * (x + 1)) * (x + 1)) <= n) {
        x = (x + 1);
    }
    while (((x * x) * x) > n) {
        x = (x - 1);
    }
    return x;
}

int64_t ht_get_ptr_i64_ptr_i64_i64_ptr_i64(int64_t* ht_key, int64_t* ht_val, int64_t key, int64_t* out) {
    int64_t h = ((key * 2654435761) & HT_MASK);
    while (ht_key[h] != 0) {
        if (ht_key[h] == key) {
            out[0] = ht_val[h];
            return 1;
        }
        h = ((h + 1) & HT_MASK);
    }
    return 0;
}

void ht_put_ptr_i64_ptr_i64_i64_i64(int64_t* ht_key, int64_t* ht_val, int64_t key, int64_t val) {
    int64_t h = ((key * 2654435761) & HT_MASK);
    while (ht_key[h] != 0) {
        if (ht_key[h] == key) {
            ht_val[h] = val;
            return;
        }
        h = ((h + 1) & HT_MASK);
    }
    ht_key[h] = key;
    ht_val[h] = val;
}

int64_t M_func_i64(int64_t n) {
    if (n <= 0) {
        return 0;
    }
    if (n <= g_limit) {
        return g_pref[n];
    }
    int64_t* out = (int64_t*)(((int64_t*)(malloc(8))));
    if (ht_get_ptr_i64_ptr_i64_i64_ptr_i64(g_ht_m_key, g_ht_m_val, n, out) == 1) {
        int64_t v = out[0];
        free(out);
        return v;
    }
    free(out);
    int64_t res = 1;
    int64_t l = 2;
    while (l <= n) {
        int64_t q = FLOW_CHECKED_DIV((n), (l));
        int64_t r = FLOW_CHECKED_DIV((n), (q));
        res = (res - (((r - l) + 1) * M_func_i64(q)));
        l = (r + 1);
    }
    ht_put_ptr_i64_ptr_i64_i64_i64(g_ht_m_key, g_ht_m_val, n, res);
    return res;
}

int64_t F_func_i64(int64_t n) {
    if (n <= 0) {
        return 0;
    }
    int64_t* out = (int64_t*)(((int64_t*)(malloc(8))));
    if (ht_get_ptr_i64_ptr_i64_i64_ptr_i64(g_ht_f_key, g_ht_f_val, n, out) == 1) {
        int64_t v = out[0];
        free(out);
        return v;
    }
    free(out);
    int64_t res = (M_func_i64(n) + F_func_i64(FLOW_CHECKED_DIV((n), (3))));
    ht_put_ptr_i64_ptr_i64_i64_i64(g_ht_f_key, g_ht_f_val, n, res);
    return res;
}

int64_t count_points_nonprimitive_i64(int64_t M) {
    if (M < 28) {
        return 0;
    }
    int64_t n = FLOW_CHECKED_DIV(((M - 18)), (10));
    int64_t b = (M - (10 * n));
    int64_t total = floor_sum_i64_i64_i64_i64(n, 18, 10, b);
    int64_t n3 = FLOW_CHECKED_DIV((n), (3));
    int64_t b3 = (M - (30 * n3));
    int64_t total3 = floor_sum_i64_i64_i64_i64(n3, 18, 30, b3);
    return (total - total3);
}

int64_t count_points_primitive_i64(int64_t M) {
    int64_t max_d = FLOW_CHECKED_DIV((M), (28));
    if (max_d <= 0) {
        return 0;
    }
    int64_t limit = (icbrt_i64((max_d * max_d)) + 64);
    int64_t* mu = (int64_t*)(((int64_t*)(calloc((limit + 1), 8))));
    int8_t* is_comp = (int8_t*)(((int8_t*)(calloc((limit + 1), 1))));
    int64_t* primes = (int64_t*)(((int64_t*)(malloc(((limit + 1) * 8)))));
    int64_t pc = 0;
    mu[1] = 1;
    int32_t __flow_step_1 = 1;
    for (int32_t i = 2; (2 <= (limit + 1)) ? i < (limit + 1) : i > (limit + 1); i += (2 <= (limit + 1)) ? 1 : -1) {
        if (is_comp[i] == 0) {
            primes[pc] = i;
            pc = (pc + 1);
            mu[i] = (-1);
        }
        int64_t j = 0;
        while (j < pc) {
            int64_t p = primes[j];
            int64_t v = (i * p);
            if (v > limit) {
                break;
            }
            is_comp[v] = 1;
            if (FLOW_CHECKED_MOD((i), (p)) == 0) {
                mu[v] = 0;
                break;
            }
            mu[v] = (-mu[i]);
            j = (j + 1);
        }
    }
    int64_t* pref = (int64_t*)(((int64_t*)(calloc((limit + 1), 8))));
    int64_t s = 0;
    int32_t __flow_step_2 = 1;
    for (int32_t i = 1; (1 <= (limit + 1)) ? i < (limit + 1) : i > (limit + 1); i += (1 <= (limit + 1)) ? 1 : -1) {
        s = (s + mu[i]);
        pref[i] = s;
    }
    g_pref = pref;
    g_limit = limit;
    g_ht_m_key = ((int64_t*)(calloc(HT_SIZE, 8)));
    g_ht_m_val = ((int64_t*)(calloc(HT_SIZE, 8)));
    g_ht_f_key = ((int64_t*)(calloc(HT_SIZE, 8)));
    g_ht_f_val = ((int64_t*)(calloc(HT_SIZE, 8)));
    int64_t ans = 0;
    int64_t l = 1;
    while (l <= max_d) {
        int64_t q = FLOW_CHECKED_DIV((M), (l));
        int64_t r = FLOW_CHECKED_DIV((M), (q));
        int64_t rr = r;
        if (rr > max_d) {
            rr = max_d;
        }
        int64_t coef = (F_func_i64(rr) - F_func_i64((l - 1)));
        if (coef != 0) {
            ans = (ans + (coef * count_points_nonprimitive_i64(q)));
        }
        l = (rr + 1);
    }
    free(mu);
    free(is_comp);
    free(primes);
    free(pref);
    free(g_ht_m_key);
    free(g_ht_m_val);
    free(g_ht_f_key);
    free(g_ht_f_val);
    return ans;
}

int32_t main(void) {
    int64_t N = 1000000000;
    int64_t M = ((3 * N) + 6);
    int64_t ans = (2 + (4 * count_points_primitive_i64(M)));
    printf("%lld\n", ans);
    return 0;
}

Generated MLIR

module {
  llvm.func @printf(!llvm.ptr, ...) -> i32
  llvm.mlir.global internal constant @str_0("%lld\n\00") {addr_space = 0 : i32} : !llvm.array<6 x i8>
  func.func private @calloc(i64, i64) -> !llvm.ptr
  func.func private @free(!llvm.ptr) -> ()
  func.func private @malloc(i64) -> !llvm.ptr
  // Constant: HT_SIZE
  llvm.mlir.global internal constant @HT_SIZE(2097152 : i64) : i64
  // Constant: HT_MASK
  llvm.mlir.global internal constant @HT_MASK(2097151 : i64) : i64
  // Module static: g_pref
  llvm.mlir.global internal @g_pref() {addr_space = 0 : i32} : !llvm.ptr {
    %0 = llvm.mlir.zero : !llvm.ptr
    llvm.return %0 : !llvm.ptr
  }
  // Module static: g_limit
  llvm.mlir.global internal @g_limit(0 : i64) : i64
  // Module static: g_ht_m_key
  llvm.mlir.global internal @g_ht_m_key() {addr_space = 0 : i32} : !llvm.ptr {
    %1 = llvm.mlir.zero : !llvm.ptr
    llvm.return %1 : !llvm.ptr
  }
  // Module static: g_ht_m_val
  llvm.mlir.global internal @g_ht_m_val() {addr_space = 0 : i32} : !llvm.ptr {
    %2 = llvm.mlir.zero : !llvm.ptr
    llvm.return %2 : !llvm.ptr
  }
  // Module static: g_ht_f_key
  llvm.mlir.global internal @g_ht_f_key() {addr_space = 0 : i32} : !llvm.ptr {
    %3 = llvm.mlir.zero : !llvm.ptr
    llvm.return %3 : !llvm.ptr
  }
  // Module static: g_ht_f_val
  llvm.mlir.global internal @g_ht_f_val() {addr_space = 0 : i32} : !llvm.ptr {
    %4 = llvm.mlir.zero : !llvm.ptr
    llvm.return %4 : !llvm.ptr
  }
  func.func @floor_sum(%arg0: i64, %arg1: i64, %arg2: i64, %arg3: i64) -> i64 {
    %5 = arith.constant 0 : i32
    %6 = arith.extsi %5 : i32 to i64
    %7 = llvm.mlir.constant(1 : i64) : i64
    %8 = llvm.alloca %7 x i64 : (i64) -> !llvm.ptr
    llvm.store %6, %8 : i64, !llvm.ptr
    %9 = llvm.mlir.constant(1 : i64) : i64
    %10 = llvm.alloca %9 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %10 : i64, !llvm.ptr
    %11 = llvm.mlir.constant(1 : i64) : i64
    %12 = llvm.alloca %11 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %12 : i64, !llvm.ptr
    %13 = llvm.mlir.constant(1 : i64) : i64
    %14 = llvm.alloca %13 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg2, %14 : i64, !llvm.ptr
    %15 = llvm.mlir.constant(1 : i64) : i64
    %16 = llvm.alloca %15 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg3, %16 : i64, !llvm.ptr
    cf.br ^bb0
    ^bb0:
    %17 = arith.constant 1 : i1
    cf.cond_br %17, ^bb1, ^bb2
    ^bb1:
      %18 = llvm.load %14 : !llvm.ptr -> i64
      %19 = llvm.load %12 : !llvm.ptr -> i64
      %20 = arith.cmpi sge, %18, %19 : i64
      cf.cond_br %20, ^bb3, ^bb4
      ^bb3:
        %21 = llvm.load %8 : !llvm.ptr -> i64
        %22 = llvm.load %10 : !llvm.ptr -> i64
        %23 = arith.constant 1 : i32
        %25 = arith.extsi %23 : i32 to i64
        %24 = arith.subi %22, %25 : i64
        %26 = llvm.load %10 : !llvm.ptr -> i64
        %27 = arith.muli %24, %26 : i64
        %28 = llvm.load %14 : !llvm.ptr -> i64
        %29 = llvm.load %12 : !llvm.ptr -> i64
        %30 = arith.divsi %28, %29 : i64
        %31 = arith.muli %27, %30 : i64
        %32 = arith.constant 2 : i32
        %34 = arith.extsi %32 : i32 to i64
        %33 = arith.divsi %31, %34 : i64
        %35 = arith.addi %21, %33 : i64
        llvm.store %35, %8 : i64, !llvm.ptr
        %36 = llvm.load %14 : !llvm.ptr -> i64
        %37 = llvm.load %12 : !llvm.ptr -> i64
        %38 = arith.remsi %36, %37 : i64
        llvm.store %38, %14 : i64, !llvm.ptr
        cf.br ^bb5
      ^bb4:
        cf.br ^bb5
      ^bb5:
      %39 = llvm.load %16 : !llvm.ptr -> i64
      %40 = llvm.load %12 : !llvm.ptr -> i64
      %41 = arith.cmpi sge, %39, %40 : i64
      cf.cond_br %41, ^bb6, ^bb7
      ^bb6:
        %42 = llvm.load %8 : !llvm.ptr -> i64
        %43 = llvm.load %10 : !llvm.ptr -> i64
        %44 = llvm.load %16 : !llvm.ptr -> i64
        %45 = llvm.load %12 : !llvm.ptr -> i64
        %46 = arith.divsi %44, %45 : i64
        %47 = arith.muli %43, %46 : i64
        %48 = arith.addi %42, %47 : i64
        llvm.store %48, %8 : i64, !llvm.ptr
        %49 = llvm.load %16 : !llvm.ptr -> i64
        %50 = llvm.load %12 : !llvm.ptr -> i64
        %51 = arith.remsi %49, %50 : i64
        llvm.store %51, %16 : i64, !llvm.ptr
        cf.br ^bb8
      ^bb7:
        cf.br ^bb8
      ^bb8:
      %52 = llvm.load %14 : !llvm.ptr -> i64
      %53 = llvm.load %10 : !llvm.ptr -> i64
      %54 = arith.muli %52, %53 : i64
      %55 = llvm.load %16 : !llvm.ptr -> i64
      %56 = arith.addi %54, %55 : i64
      %57 = llvm.load %12 : !llvm.ptr -> i64
      %58 = arith.cmpi slt, %56, %57 : i64
      cf.cond_br %58, ^bb9, ^bb10
      ^bb9:
        cf.br ^bb2
      ^bb10:
        cf.br ^bb11
      ^bb11:
      %59 = llvm.load %12 : !llvm.ptr -> i64
      %60 = arith.remsi %56, %59 : i64
      llvm.store %60, %16 : i64, !llvm.ptr
      %61 = llvm.load %12 : !llvm.ptr -> i64
      %62 = arith.divsi %56, %61 : i64
      llvm.store %62, %10 : i64, !llvm.ptr
      %63 = llvm.load %12 : !llvm.ptr -> i64
      %64 = llvm.load %14 : !llvm.ptr -> i64
      llvm.store %64, %12 : i64, !llvm.ptr
      llvm.store %63, %14 : i64, !llvm.ptr
      cf.br ^bb0
    ^bb2:
    %65 = llvm.load %8 : !llvm.ptr -> i64
    func.return %65 : i64
  }
  func.func @icbrt(%arg0: i64) -> i64 {
    %66 = arith.constant 0 : i32
    %68 = arith.extsi %66 : i32 to i64
    %67 = arith.cmpi sle, %arg0, %68 : i64
    cf.cond_br %67, ^bb12, ^bb13
    ^bb12:
      %69 = arith.constant 0 : i32
      %70 = arith.extsi %69 : i32 to i64
      func.return %70 : i64
    ^bb13:
      cf.br ^bb14
    ^bb14:
    %71 = arith.constant 0 : i32
    %72 = arith.extsi %71 : i32 to i64
    %73 = llvm.mlir.constant(1 : i64) : i64
    %74 = llvm.alloca %73 x i64 : (i64) -> !llvm.ptr
    llvm.store %72, %74 : i64, !llvm.ptr
    %75 = llvm.mlir.constant(1 : i64) : i64
    %76 = llvm.alloca %75 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %76 : i64, !llvm.ptr
    cf.br ^bb15
    ^bb15:
    %77 = llvm.load %76 : !llvm.ptr -> i64
    %78 = arith.constant 0 : i32
    %80 = arith.extsi %78 : i32 to i64
    %79 = arith.cmpi ne, %77, %80 : i64
    cf.cond_br %79, ^bb16, ^bb17
    ^bb16:
      %81 = llvm.load %74 : !llvm.ptr -> i64
      %82 = arith.constant 1 : i32
      %84 = arith.extsi %82 : i32 to i64
      %83 = arith.addi %81, %84 : i64
      llvm.store %83, %74 : i64, !llvm.ptr
      %85 = llvm.load %76 : !llvm.ptr -> i64
      %86 = arith.constant 1 : i32
      %88 = arith.extsi %86 : i32 to i64
      %87 = arith.shrsi %85, %88 : i64
      llvm.store %87, %76 : i64, !llvm.ptr
      cf.br ^bb15
    ^bb17:
    %89 = arith.constant 1 : i32
    %90 = llvm.load %74 : !llvm.ptr -> i64
    %91 = arith.constant 2 : i32
    %93 = arith.extsi %91 : i32 to i64
    %92 = arith.addi %90, %93 : i64
    %94 = arith.constant 3 : i32
    %96 = arith.extsi %94 : i32 to i64
    %95 = arith.divsi %92, %96 : i64
    %98 = arith.extsi %89 : i32 to i64
    %97 = arith.shli %98, %95 : i64
    %99 = llvm.mlir.constant(1 : i64) : i64
    %100 = llvm.alloca %99 x i64 : (i64) -> !llvm.ptr
    llvm.store %97, %100 : i64, !llvm.ptr
    cf.br ^bb18
    ^bb18:
    %101 = arith.constant 1 : i1
    cf.cond_br %101, ^bb19, ^bb20
    ^bb19:
      %102 = arith.constant 2 : i32
      %103 = llvm.load %100 : !llvm.ptr -> i64
      %105 = arith.extsi %102 : i32 to i64
      %104 = arith.muli %105, %103 : i64
      %106 = llvm.load %100 : !llvm.ptr -> i64
      %107 = llvm.load %100 : !llvm.ptr -> i64
      %108 = arith.muli %106, %107 : i64
      %109 = arith.divsi %arg0, %108 : i64
      %110 = arith.addi %104, %109 : i64
      %111 = arith.constant 3 : i32
      %113 = arith.extsi %111 : i32 to i64
      %112 = arith.divsi %110, %113 : i64
      %114 = llvm.load %100 : !llvm.ptr -> i64
      %115 = arith.cmpi sge, %112, %114 : i64
      cf.cond_br %115, ^bb21, ^bb22
      ^bb21:
        cf.br ^bb20
      ^bb22:
        cf.br ^bb23
      ^bb23:
      llvm.store %112, %100 : i64, !llvm.ptr
      cf.br ^bb18
    ^bb20:
    cf.br ^bb24
    ^bb24:
    %116 = llvm.load %100 : !llvm.ptr -> i64
    %117 = arith.constant 1 : i32
    %119 = arith.extsi %117 : i32 to i64
    %118 = arith.addi %116, %119 : i64
    %120 = llvm.load %100 : !llvm.ptr -> i64
    %121 = arith.constant 1 : i32
    %123 = arith.extsi %121 : i32 to i64
    %122 = arith.addi %120, %123 : i64
    %124 = arith.muli %118, %122 : i64
    %125 = llvm.load %100 : !llvm.ptr -> i64
    %126 = arith.constant 1 : i32
    %128 = arith.extsi %126 : i32 to i64
    %127 = arith.addi %125, %128 : i64
    %129 = arith.muli %124, %127 : i64
    %130 = arith.cmpi sle, %129, %arg0 : i64
    cf.cond_br %130, ^bb25, ^bb26
    ^bb25:
      %131 = llvm.load %100 : !llvm.ptr -> i64
      %132 = arith.constant 1 : i32
      %134 = arith.extsi %132 : i32 to i64
      %133 = arith.addi %131, %134 : i64
      llvm.store %133, %100 : i64, !llvm.ptr
      cf.br ^bb24
    ^bb26:
    cf.br ^bb27
    ^bb27:
    %135 = llvm.load %100 : !llvm.ptr -> i64
    %136 = llvm.load %100 : !llvm.ptr -> i64
    %137 = arith.muli %135, %136 : i64
    %138 = llvm.load %100 : !llvm.ptr -> i64
    %139 = arith.muli %137, %138 : i64
    %140 = arith.cmpi sgt, %139, %arg0 : i64
    cf.cond_br %140, ^bb28, ^bb29
    ^bb28:
      %141 = llvm.load %100 : !llvm.ptr -> i64
      %142 = arith.constant 1 : i32
      %144 = arith.extsi %142 : i32 to i64
      %143 = arith.subi %141, %144 : i64
      llvm.store %143, %100 : i64, !llvm.ptr
      cf.br ^bb27
    ^bb29:
    %145 = llvm.load %100 : !llvm.ptr -> i64
    func.return %145 : i64
  }
  func.func @ht_get(%arg0: !llvm.ptr, %arg1: !llvm.ptr, %arg2: i64, %arg3: !llvm.ptr) -> i64 {
    %146 = arith.constant -1640531535 : i32
    %148 = arith.extsi %146 : i32 to i64
    %147 = arith.muli %arg2, %148 : i64
    %149 = llvm.mlir.addressof @HT_MASK : !llvm.ptr
    %150 = llvm.load %149 : !llvm.ptr -> i64
    %151 = arith.andi %147, %150 : i64
    %152 = llvm.mlir.constant(1 : i64) : i64
    %153 = llvm.alloca %152 x i64 : (i64) -> !llvm.ptr
    llvm.store %151, %153 : i64, !llvm.ptr
    cf.br ^bb30
    ^bb30:
    %155 = llvm.load %153 : !llvm.ptr -> i64
    %156 = llvm.getelementptr %arg0[%155] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %154 = llvm.load %156 : !llvm.ptr -> i64
    %157 = arith.constant 0 : i32
    %159 = arith.extsi %157 : i32 to i64
    %158 = arith.cmpi ne, %154, %159 : i64
    cf.cond_br %158, ^bb31, ^bb32
    ^bb31:
      %161 = llvm.load %153 : !llvm.ptr -> i64
      %162 = llvm.getelementptr %arg0[%161] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %160 = llvm.load %162 : !llvm.ptr -> i64
      %163 = arith.cmpi eq, %160, %arg2 : i64
      cf.cond_br %163, ^bb33, ^bb34
      ^bb33:
        %165 = llvm.load %153 : !llvm.ptr -> i64
        %166 = llvm.getelementptr %arg1[%165] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %164 = llvm.load %166 : !llvm.ptr -> i64
        %167 = arith.constant 0 : i32
        %168 = arith.extsi %167 : i32 to i64
        %169 = llvm.getelementptr %arg3[%168] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %164, %169 : i64, !llvm.ptr
        %170 = arith.constant 1 : i32
        %171 = arith.extsi %170 : i32 to i64
        func.return %171 : i64
      ^bb34:
        cf.br ^bb35
      ^bb35:
      %172 = llvm.load %153 : !llvm.ptr -> i64
      %173 = arith.constant 1 : i32
      %175 = arith.extsi %173 : i32 to i64
      %174 = arith.addi %172, %175 : i64
      %176 = llvm.mlir.addressof @HT_MASK : !llvm.ptr
      %177 = llvm.load %176 : !llvm.ptr -> i64
      %178 = arith.andi %174, %177 : i64
      llvm.store %178, %153 : i64, !llvm.ptr
      cf.br ^bb30
    ^bb32:
    %179 = arith.constant 0 : i32
    %180 = arith.extsi %179 : i32 to i64
    func.return %180 : i64
  }
  func.func @ht_put(%arg0: !llvm.ptr, %arg1: !llvm.ptr, %arg2: i64, %arg3: i64) -> () {
    %181 = arith.constant -1640531535 : i32
    %183 = arith.extsi %181 : i32 to i64
    %182 = arith.muli %arg2, %183 : i64
    %184 = llvm.mlir.addressof @HT_MASK : !llvm.ptr
    %185 = llvm.load %184 : !llvm.ptr -> i64
    %186 = arith.andi %182, %185 : i64
    %187 = llvm.mlir.constant(1 : i64) : i64
    %188 = llvm.alloca %187 x i64 : (i64) -> !llvm.ptr
    llvm.store %186, %188 : i64, !llvm.ptr
    cf.br ^bb36
    ^bb36:
    %190 = llvm.load %188 : !llvm.ptr -> i64
    %191 = llvm.getelementptr %arg0[%190] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %189 = llvm.load %191 : !llvm.ptr -> i64
    %192 = arith.constant 0 : i32
    %194 = arith.extsi %192 : i32 to i64
    %193 = arith.cmpi ne, %189, %194 : i64
    cf.cond_br %193, ^bb37, ^bb38
    ^bb37:
      %196 = llvm.load %188 : !llvm.ptr -> i64
      %197 = llvm.getelementptr %arg0[%196] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %195 = llvm.load %197 : !llvm.ptr -> i64
      %198 = arith.cmpi eq, %195, %arg2 : i64
      cf.cond_br %198, ^bb39, ^bb40
      ^bb39:
        %199 = llvm.load %188 : !llvm.ptr -> i64
        %200 = llvm.getelementptr %arg1[%199] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %arg3, %200 : i64, !llvm.ptr
        func.return
      ^bb40:
        cf.br ^bb41
      ^bb41:
      %201 = llvm.load %188 : !llvm.ptr -> i64
      %202 = arith.constant 1 : i32
      %204 = arith.extsi %202 : i32 to i64
      %203 = arith.addi %201, %204 : i64
      %205 = llvm.mlir.addressof @HT_MASK : !llvm.ptr
      %206 = llvm.load %205 : !llvm.ptr -> i64
      %207 = arith.andi %203, %206 : i64
      llvm.store %207, %188 : i64, !llvm.ptr
      cf.br ^bb36
    ^bb38:
    %208 = llvm.load %188 : !llvm.ptr -> i64
    %209 = llvm.getelementptr %arg0[%208] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %arg2, %209 : i64, !llvm.ptr
    %210 = llvm.load %188 : !llvm.ptr -> i64
    %211 = llvm.getelementptr %arg1[%210] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %arg3, %211 : i64, !llvm.ptr
    func.return
  }
  func.func @M_func(%arg0: i64) -> i64 {
    %212 = arith.constant 0 : i32
    %214 = arith.extsi %212 : i32 to i64
    %213 = arith.cmpi sle, %arg0, %214 : i64
    cf.cond_br %213, ^bb42, ^bb43
    ^bb42:
      %215 = arith.constant 0 : i32
      %216 = arith.extsi %215 : i32 to i64
      func.return %216 : i64
    ^bb43:
      cf.br ^bb44
    ^bb44:
    %217 = llvm.mlir.addressof @g_limit : !llvm.ptr
    %218 = llvm.load %217 : !llvm.ptr -> i64
    %219 = arith.cmpi sle, %arg0, %218 : i64
    cf.cond_br %219, ^bb45, ^bb46
    ^bb45:
      %221 = llvm.mlir.addressof @g_pref : !llvm.ptr
      %222 = llvm.load %221 : !llvm.ptr -> !llvm.ptr
      %223 = llvm.getelementptr %222[%arg0] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %220 = llvm.load %223 : !llvm.ptr -> i64
      func.return %220 : i64
    ^bb46:
      cf.br ^bb47
    ^bb47:
    %225 = arith.constant 8 : i32
    %226 = arith.extsi %225 : i32 to i64
    %224 = func.call @malloc(%226) : (i64) -> !llvm.ptr
    %228 = llvm.mlir.addressof @g_ht_m_key : !llvm.ptr
    %229 = llvm.load %228 : !llvm.ptr -> !llvm.ptr
    %230 = llvm.mlir.addressof @g_ht_m_val : !llvm.ptr
    %231 = llvm.load %230 : !llvm.ptr -> !llvm.ptr
    %227 = func.call @ht_get(%229, %231, %arg0, %224) : (!llvm.ptr, !llvm.ptr, i64, !llvm.ptr) -> i64
    %232 = arith.constant 1 : i32
    %234 = arith.extsi %232 : i32 to i64
    %233 = arith.cmpi eq, %227, %234 : i64
    cf.cond_br %233, ^bb48, ^bb49
    ^bb48:
      %236 = arith.constant 0 : i32
      %237 = arith.extsi %236 : i32 to i64
      %238 = llvm.getelementptr %224[%237] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %235 = llvm.load %238 : !llvm.ptr -> i64
      func.call @free(%224) : (!llvm.ptr) -> ()
      func.return %235 : i64
    ^bb49:
      cf.br ^bb50
    ^bb50:
    func.call @free(%224) : (!llvm.ptr) -> ()
    %241 = arith.constant 1 : i32
    %242 = arith.extsi %241 : i32 to i64
    %243 = llvm.mlir.constant(1 : i64) : i64
    %244 = llvm.alloca %243 x i64 : (i64) -> !llvm.ptr
    llvm.store %242, %244 : i64, !llvm.ptr
    %245 = arith.constant 2 : i32
    %246 = arith.extsi %245 : i32 to i64
    %247 = llvm.mlir.constant(1 : i64) : i64
    %248 = llvm.alloca %247 x i64 : (i64) -> !llvm.ptr
    llvm.store %246, %248 : i64, !llvm.ptr
    cf.br ^bb51
    ^bb51:
    %249 = llvm.load %248 : !llvm.ptr -> i64
    %250 = arith.cmpi sle, %249, %arg0 : i64
    cf.cond_br %250, ^bb52, ^bb53
    ^bb52:
      %251 = llvm.load %248 : !llvm.ptr -> i64
      %252 = arith.divsi %arg0, %251 : i64
      %253 = arith.divsi %arg0, %252 : i64
      %254 = llvm.load %244 : !llvm.ptr -> i64
      %255 = llvm.load %248 : !llvm.ptr -> i64
      %256 = arith.subi %253, %255 : i64
      %257 = arith.constant 1 : i32
      %259 = arith.extsi %257 : i32 to i64
      %258 = arith.addi %256, %259 : i64
      %260 = func.call @M_func(%252) : (i64) -> i64
      %261 = arith.muli %258, %260 : i64
      %262 = arith.subi %254, %261 : i64
      llvm.store %262, %244 : i64, !llvm.ptr
      %263 = arith.constant 1 : i32
      %265 = arith.extsi %263 : i32 to i64
      %264 = arith.addi %253, %265 : i64
      llvm.store %264, %248 : i64, !llvm.ptr
      cf.br ^bb51
    ^bb53:
    %267 = llvm.mlir.addressof @g_ht_m_key : !llvm.ptr
    %268 = llvm.load %267 : !llvm.ptr -> !llvm.ptr
    %269 = llvm.mlir.addressof @g_ht_m_val : !llvm.ptr
    %270 = llvm.load %269 : !llvm.ptr -> !llvm.ptr
    %271 = llvm.load %244 : !llvm.ptr -> i64
    func.call @ht_put(%268, %270, %arg0, %271) : (!llvm.ptr, !llvm.ptr, i64, i64) -> ()
    %272 = llvm.load %244 : !llvm.ptr -> i64
    func.return %272 : i64
  }
  func.func @F_func(%arg0: i64) -> i64 {
    %273 = arith.constant 0 : i32
    %275 = arith.extsi %273 : i32 to i64
    %274 = arith.cmpi sle, %arg0, %275 : i64
    cf.cond_br %274, ^bb54, ^bb55
    ^bb54:
      %276 = arith.constant 0 : i32
      %277 = arith.extsi %276 : i32 to i64
      func.return %277 : i64
    ^bb55:
      cf.br ^bb56
    ^bb56:
    %279 = arith.constant 8 : i32
    %280 = arith.extsi %279 : i32 to i64
    %278 = func.call @malloc(%280) : (i64) -> !llvm.ptr
    %282 = llvm.mlir.addressof @g_ht_f_key : !llvm.ptr
    %283 = llvm.load %282 : !llvm.ptr -> !llvm.ptr
    %284 = llvm.mlir.addressof @g_ht_f_val : !llvm.ptr
    %285 = llvm.load %284 : !llvm.ptr -> !llvm.ptr
    %281 = func.call @ht_get(%283, %285, %arg0, %278) : (!llvm.ptr, !llvm.ptr, i64, !llvm.ptr) -> i64
    %286 = arith.constant 1 : i32
    %288 = arith.extsi %286 : i32 to i64
    %287 = arith.cmpi eq, %281, %288 : i64
    cf.cond_br %287, ^bb57, ^bb58
    ^bb57:
      %290 = arith.constant 0 : i32
      %291 = arith.extsi %290 : i32 to i64
      %292 = llvm.getelementptr %278[%291] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %289 = llvm.load %292 : !llvm.ptr -> i64
      func.call @free(%278) : (!llvm.ptr) -> ()
      func.return %289 : i64
    ^bb58:
      cf.br ^bb59
    ^bb59:
    func.call @free(%278) : (!llvm.ptr) -> ()
    %295 = func.call @M_func(%arg0) : (i64) -> i64
    %297 = arith.constant 3 : i32
    %299 = arith.extsi %297 : i32 to i64
    %298 = arith.divsi %arg0, %299 : i64
    %296 = func.call @F_func(%298) : (i64) -> i64
    %300 = arith.addi %295, %296 : i64
    %302 = llvm.mlir.addressof @g_ht_f_key : !llvm.ptr
    %303 = llvm.load %302 : !llvm.ptr -> !llvm.ptr
    %304 = llvm.mlir.addressof @g_ht_f_val : !llvm.ptr
    %305 = llvm.load %304 : !llvm.ptr -> !llvm.ptr
    func.call @ht_put(%303, %305, %arg0, %300) : (!llvm.ptr, !llvm.ptr, i64, i64) -> ()
    func.return %300 : i64
  }
  func.func @count_points_nonprimitive(%arg0: i64) -> i64 {
    %306 = arith.constant 28 : i32
    %308 = arith.extsi %306 : i32 to i64
    %307 = arith.cmpi slt, %arg0, %308 : i64
    cf.cond_br %307, ^bb60, ^bb61
    ^bb60:
      %309 = arith.constant 0 : i32
      %310 = arith.extsi %309 : i32 to i64
      func.return %310 : i64
    ^bb61:
      cf.br ^bb62
    ^bb62:
    %311 = arith.constant 18 : i32
    %313 = arith.extsi %311 : i32 to i64
    %312 = arith.subi %arg0, %313 : i64
    %314 = arith.constant 10 : i32
    %316 = arith.extsi %314 : i32 to i64
    %315 = arith.divsi %312, %316 : i64
    %317 = arith.constant 10 : i32
    %319 = arith.extsi %317 : i32 to i64
    %318 = arith.muli %319, %315 : i64
    %320 = arith.subi %arg0, %318 : i64
    %322 = arith.constant 18 : i32
    %323 = arith.constant 10 : i32
    %324 = arith.extsi %322 : i32 to i64
    %325 = arith.extsi %323 : i32 to i64
    %321 = func.call @floor_sum(%315, %324, %325, %320) : (i64, i64, i64, i64) -> i64
    %326 = arith.constant 3 : i32
    %328 = arith.extsi %326 : i32 to i64
    %327 = arith.divsi %315, %328 : i64
    %329 = arith.constant 30 : i32
    %331 = arith.extsi %329 : i32 to i64
    %330 = arith.muli %331, %327 : i64
    %332 = arith.subi %arg0, %330 : i64
    %334 = arith.constant 18 : i32
    %335 = arith.constant 30 : i32
    %336 = arith.extsi %334 : i32 to i64
    %337 = arith.extsi %335 : i32 to i64
    %333 = func.call @floor_sum(%327, %336, %337, %332) : (i64, i64, i64, i64) -> i64
    %338 = arith.subi %321, %333 : i64
    func.return %338 : i64
  }
  func.func @count_points_primitive(%arg0: i64) -> i64 {
    %339 = arith.constant 28 : i32
    %341 = arith.extsi %339 : i32 to i64
    %340 = arith.divsi %arg0, %341 : i64
    %342 = arith.constant 0 : i32
    %344 = arith.extsi %342 : i32 to i64
    %343 = arith.cmpi sle, %340, %344 : i64
    cf.cond_br %343, ^bb63, ^bb64
    ^bb63:
      %345 = arith.constant 0 : i32
      %346 = arith.extsi %345 : i32 to i64
      func.return %346 : i64
    ^bb64:
      cf.br ^bb65
    ^bb65:
    %348 = arith.muli %340, %340 : i64
    %347 = func.call @icbrt(%348) : (i64) -> i64
    %349 = arith.constant 64 : i32
    %351 = arith.extsi %349 : i32 to i64
    %350 = arith.addi %347, %351 : i64
    %353 = arith.constant 1 : i32
    %355 = arith.extsi %353 : i32 to i64
    %354 = arith.addi %350, %355 : i64
    %356 = arith.constant 8 : i32
    %357 = arith.extsi %356 : i32 to i64
    %352 = func.call @calloc(%354, %357) : (i64, i64) -> !llvm.ptr
    %359 = arith.constant 1 : i32
    %361 = arith.extsi %359 : i32 to i64
    %360 = arith.addi %350, %361 : i64
    %362 = arith.constant 1 : i32
    %363 = arith.extsi %362 : i32 to i64
    %358 = func.call @calloc(%360, %363) : (i64, i64) -> !llvm.ptr
    %365 = arith.constant 1 : i32
    %367 = arith.extsi %365 : i32 to i64
    %366 = arith.addi %350, %367 : i64
    %368 = arith.constant 8 : i32
    %370 = arith.extsi %368 : i32 to i64
    %369 = arith.muli %366, %370 : i64
    %364 = func.call @malloc(%369) : (i64) -> !llvm.ptr
    %371 = arith.constant 0 : i32
    %372 = arith.extsi %371 : i32 to i64
    %373 = llvm.mlir.constant(1 : i64) : i64
    %374 = llvm.alloca %373 x i64 : (i64) -> !llvm.ptr
    llvm.store %372, %374 : i64, !llvm.ptr
    %375 = arith.constant 1 : i32
    %376 = arith.constant 1 : i32
    %377 = arith.extsi %375 : i32 to i64
    %378 = arith.extsi %376 : i32 to i64
    %379 = llvm.getelementptr %352[%378] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %377, %379 : i64, !llvm.ptr
    %380 = arith.constant 2 : i32
    %381 = arith.constant 1 : i32
    %383 = arith.extsi %381 : i32 to i64
    %382 = arith.addi %350, %383 : i64
    %384 = arith.index_cast %380 : i32 to index
    %385 = arith.index_cast %382 : i32 to index
    %387 = arith.constant 1 : index
    %388 = arith.constant -1 : index
    %389 = arith.cmpi sle, %384, %385 : index
    %386 = arith.select %389, %387, %388 : index
    cf.br ^bb66(%384 : index)
    ^bb66(%390: index):
    %391 = arith.cmpi slt, %390, %385 : index
    %392 = arith.cmpi sgt, %390, %385 : index
    %393 = arith.select %389, %391, %392 : i1
    cf.cond_br %393, ^bb67(%390 : index), ^bb68(%390 : index)
    ^bb67(%394: index):
      %396 = arith.index_cast %394 : index to i64
      %397 = llvm.getelementptr %358[%396] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %395 = llvm.load %397 : !llvm.ptr -> i8
      %398 = arith.constant 0 : i32
      %400 = arith.extsi %395 : i8 to i32
      %399 = arith.cmpi eq, %400, %398 : i32
      cf.cond_br %399, ^bb69, ^bb70
      ^bb69:
        %401 = llvm.load %374 : !llvm.ptr -> i64
        %402 = arith.index_cast %394 : index to i64
        %403 = llvm.getelementptr %364[%401] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %402, %403 : i64, !llvm.ptr
        %404 = llvm.load %374 : !llvm.ptr -> i64
        %405 = arith.constant 1 : i32
        %407 = arith.extsi %405 : i32 to i64
        %406 = arith.addi %404, %407 : i64
        llvm.store %406, %374 : i64, !llvm.ptr
        %408 = arith.constant 1 : i32
        %410 = arith.constant 0 : i32
        %409 = arith.subi %410, %408 : i32
        %411 = arith.extsi %409 : i32 to i64
        %412 = arith.index_cast %394 : index to i64
        %413 = llvm.getelementptr %352[%412] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %411, %413 : i64, !llvm.ptr
        cf.br ^bb71
      ^bb70:
        cf.br ^bb71
      ^bb71:
      %414 = arith.constant 0 : i32
      %415 = arith.extsi %414 : i32 to i64
      %416 = llvm.mlir.constant(1 : i64) : i64
      %417 = llvm.alloca %416 x i64 : (i64) -> !llvm.ptr
      llvm.store %415, %417 : i64, !llvm.ptr
      cf.br ^bb72
      ^bb72:
      %418 = llvm.load %417 : !llvm.ptr -> i64
      %419 = llvm.load %374 : !llvm.ptr -> i64
      %420 = arith.cmpi slt, %418, %419 : i64
      cf.cond_br %420, ^bb73, ^bb74
      ^bb73:
        %422 = llvm.load %417 : !llvm.ptr -> i64
        %423 = llvm.getelementptr %364[%422] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %421 = llvm.load %423 : !llvm.ptr -> i64
        %425 = arith.index_cast %394 : index to i32
        %426 = arith.trunci %421 : i64 to i32
        %424 = arith.muli %425, %426 : i32
        %427 = arith.extsi %424 : i32 to i64
        %428 = arith.cmpi sgt, %427, %350 : i64
        cf.cond_br %428, ^bb75, ^bb76
        ^bb75:
          cf.br ^bb74
        ^bb76:
          cf.br ^bb77
        ^bb77:
        %429 = arith.constant 1 : i32
        %430 = arith.trunci %429 : i32 to i8
        %431 = llvm.getelementptr %358[%427] : (!llvm.ptr, i64) -> !llvm.ptr, i8
        llvm.store %430, %431 : i8, !llvm.ptr
        %433 = arith.index_cast %394 : index to i32
        %434 = arith.trunci %421 : i64 to i32
        %432 = arith.remsi %433, %434 : i32
        %435 = arith.constant 0 : i32
        %436 = arith.cmpi eq, %432, %435 : i32
        cf.cond_br %436, ^bb78, ^bb79
        ^bb78:
          %437 = arith.constant 0 : i32
          %438 = arith.extsi %437 : i32 to i64
          %439 = llvm.getelementptr %352[%427] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          llvm.store %438, %439 : i64, !llvm.ptr
          cf.br ^bb74
        ^bb79:
          cf.br ^bb80
        ^bb80:
        %441 = arith.index_cast %394 : index to i64
        %442 = llvm.getelementptr %352[%441] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %440 = llvm.load %442 : !llvm.ptr -> i64
        %444 = arith.constant 0 : i64
        %443 = arith.subi %444, %440 : i64
        %445 = llvm.getelementptr %352[%427] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %443, %445 : i64, !llvm.ptr
        %446 = llvm.load %417 : !llvm.ptr -> i64
        %447 = arith.constant 1 : i32
        %449 = arith.extsi %447 : i32 to i64
        %448 = arith.addi %446, %449 : i64
        llvm.store %448, %417 : i64, !llvm.ptr
        cf.br ^bb72
      ^bb74:
      %450 = arith.addi %394, %386 : index
      cf.br ^bb66(%450 : index)
    ^bb68(%451: index):
    %453 = arith.constant 1 : i32
    %455 = arith.extsi %453 : i32 to i64
    %454 = arith.addi %350, %455 : i64
    %456 = arith.constant 8 : i32
    %457 = arith.extsi %456 : i32 to i64
    %452 = func.call @calloc(%454, %457) : (i64, i64) -> !llvm.ptr
    %458 = arith.constant 0 : i32
    %459 = arith.extsi %458 : i32 to i64
    %460 = llvm.mlir.constant(1 : i64) : i64
    %461 = llvm.alloca %460 x i64 : (i64) -> !llvm.ptr
    llvm.store %459, %461 : i64, !llvm.ptr
    %462 = arith.constant 1 : i32
    %463 = arith.constant 1 : i32
    %465 = arith.extsi %463 : i32 to i64
    %464 = arith.addi %350, %465 : i64
    %466 = arith.index_cast %462 : i32 to index
    %467 = arith.index_cast %464 : i32 to index
    %469 = arith.constant 1 : index
    %470 = arith.constant -1 : index
    %471 = arith.cmpi sle, %466, %467 : index
    %468 = arith.select %471, %469, %470 : index
    cf.br ^bb81(%466 : index)
    ^bb81(%472: index):
    %473 = arith.cmpi slt, %472, %467 : index
    %474 = arith.cmpi sgt, %472, %467 : index
    %475 = arith.select %471, %473, %474 : i1
    cf.cond_br %475, ^bb82(%472 : index), ^bb83(%472 : index)
    ^bb82(%476: index):
      %477 = llvm.load %461 : !llvm.ptr -> i64
      %479 = arith.index_cast %476 : index to i64
      %480 = llvm.getelementptr %352[%479] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %478 = llvm.load %480 : !llvm.ptr -> i64
      %481 = arith.addi %477, %478 : i64
      llvm.store %481, %461 : i64, !llvm.ptr
      %482 = llvm.load %461 : !llvm.ptr -> i64
      %483 = arith.index_cast %476 : index to i64
      %484 = llvm.getelementptr %452[%483] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %482, %484 : i64, !llvm.ptr
      %485 = arith.addi %476, %468 : index
      cf.br ^bb81(%485 : index)
    ^bb83(%486: index):
    %487 = llvm.mlir.addressof @g_pref : !llvm.ptr
    llvm.store %452, %487 : !llvm.ptr, !llvm.ptr
    %488 = llvm.mlir.addressof @g_limit : !llvm.ptr
    llvm.store %350, %488 : i64, !llvm.ptr
    %490 = llvm.mlir.addressof @HT_SIZE : !llvm.ptr
    %491 = llvm.load %490 : !llvm.ptr -> i64
    %492 = arith.constant 8 : i32
    %493 = arith.extsi %492 : i32 to i64
    %489 = func.call @calloc(%491, %493) : (i64, i64) -> !llvm.ptr
    %494 = llvm.mlir.addressof @g_ht_m_key : !llvm.ptr
    llvm.store %489, %494 : !llvm.ptr, !llvm.ptr
    %496 = llvm.mlir.addressof @HT_SIZE : !llvm.ptr
    %497 = llvm.load %496 : !llvm.ptr -> i64
    %498 = arith.constant 8 : i32
    %499 = arith.extsi %498 : i32 to i64
    %495 = func.call @calloc(%497, %499) : (i64, i64) -> !llvm.ptr
    %500 = llvm.mlir.addressof @g_ht_m_val : !llvm.ptr
    llvm.store %495, %500 : !llvm.ptr, !llvm.ptr
    %502 = llvm.mlir.addressof @HT_SIZE : !llvm.ptr
    %503 = llvm.load %502 : !llvm.ptr -> i64
    %504 = arith.constant 8 : i32
    %505 = arith.extsi %504 : i32 to i64
    %501 = func.call @calloc(%503, %505) : (i64, i64) -> !llvm.ptr
    %506 = llvm.mlir.addressof @g_ht_f_key : !llvm.ptr
    llvm.store %501, %506 : !llvm.ptr, !llvm.ptr
    %508 = llvm.mlir.addressof @HT_SIZE : !llvm.ptr
    %509 = llvm.load %508 : !llvm.ptr -> i64
    %510 = arith.constant 8 : i32
    %511 = arith.extsi %510 : i32 to i64
    %507 = func.call @calloc(%509, %511) : (i64, i64) -> !llvm.ptr
    %512 = llvm.mlir.addressof @g_ht_f_val : !llvm.ptr
    llvm.store %507, %512 : !llvm.ptr, !llvm.ptr
    %513 = arith.constant 0 : i32
    %514 = arith.extsi %513 : i32 to i64
    %515 = llvm.mlir.constant(1 : i64) : i64
    %516 = llvm.alloca %515 x i64 : (i64) -> !llvm.ptr
    llvm.store %514, %516 : i64, !llvm.ptr
    %517 = arith.constant 1 : i32
    %518 = arith.extsi %517 : i32 to i64
    %519 = llvm.mlir.constant(1 : i64) : i64
    %520 = llvm.alloca %519 x i64 : (i64) -> !llvm.ptr
    llvm.store %518, %520 : i64, !llvm.ptr
    cf.br ^bb84
    ^bb84:
    %521 = llvm.load %520 : !llvm.ptr -> i64
    %522 = arith.cmpi sle, %521, %340 : i64
    cf.cond_br %522, ^bb85, ^bb86
    ^bb85:
      %523 = llvm.load %520 : !llvm.ptr -> i64
      %524 = arith.divsi %arg0, %523 : i64
      %525 = arith.divsi %arg0, %524 : i64
      %526 = llvm.mlir.constant(1 : i64) : i64
      %527 = llvm.alloca %526 x i64 : (i64) -> !llvm.ptr
      llvm.store %525, %527 : i64, !llvm.ptr
      %528 = llvm.load %527 : !llvm.ptr -> i64
      %529 = arith.cmpi sgt, %528, %340 : i64
      cf.cond_br %529, ^bb87, ^bb88
      ^bb87:
        llvm.store %340, %527 : i64, !llvm.ptr
        cf.br ^bb89
      ^bb88:
        cf.br ^bb89
      ^bb89:
      %531 = llvm.load %527 : !llvm.ptr -> i64
      %530 = func.call @F_func(%531) : (i64) -> i64
      %533 = llvm.load %520 : !llvm.ptr -> i64
      %534 = arith.constant 1 : i32
      %536 = arith.extsi %534 : i32 to i64
      %535 = arith.subi %533, %536 : i64
      %532 = func.call @F_func(%535) : (i64) -> i64
      %537 = arith.subi %530, %532 : i64
      %538 = arith.constant 0 : i32
      %540 = arith.extsi %538 : i32 to i64
      %539 = arith.cmpi ne, %537, %540 : i64
      cf.cond_br %539, ^bb90, ^bb91
      ^bb90:
        %541 = llvm.load %516 : !llvm.ptr -> i64
        %542 = func.call @count_points_nonprimitive(%524) : (i64) -> i64
        %543 = arith.muli %537, %542 : i64
        %544 = arith.addi %541, %543 : i64
        llvm.store %544, %516 : i64, !llvm.ptr
        cf.br ^bb92
      ^bb91:
        cf.br ^bb92
      ^bb92:
      %545 = llvm.load %527 : !llvm.ptr -> i64
      %546 = arith.constant 1 : i32
      %548 = arith.extsi %546 : i32 to i64
      %547 = arith.addi %545, %548 : i64
      llvm.store %547, %520 : i64, !llvm.ptr
      cf.br ^bb84
    ^bb86:
    func.call @free(%352) : (!llvm.ptr) -> ()
    func.call @free(%358) : (!llvm.ptr) -> ()
    func.call @free(%364) : (!llvm.ptr) -> ()
    func.call @free(%452) : (!llvm.ptr) -> ()
    %554 = llvm.mlir.addressof @g_ht_m_key : !llvm.ptr
    %555 = llvm.load %554 : !llvm.ptr -> !llvm.ptr
    func.call @free(%555) : (!llvm.ptr) -> ()
    %557 = llvm.mlir.addressof @g_ht_m_val : !llvm.ptr
    %558 = llvm.load %557 : !llvm.ptr -> !llvm.ptr
    func.call @free(%558) : (!llvm.ptr) -> ()
    %560 = llvm.mlir.addressof @g_ht_f_key : !llvm.ptr
    %561 = llvm.load %560 : !llvm.ptr -> !llvm.ptr
    func.call @free(%561) : (!llvm.ptr) -> ()
    %563 = llvm.mlir.addressof @g_ht_f_val : !llvm.ptr
    %564 = llvm.load %563 : !llvm.ptr -> !llvm.ptr
    func.call @free(%564) : (!llvm.ptr) -> ()
    %565 = llvm.load %516 : !llvm.ptr -> i64
    func.return %565 : i64
  }
  func.func @main() -> i32 {
    %566 = arith.constant 1000000000 : i32
    %567 = arith.extsi %566 : i32 to i64
    %568 = arith.constant 3 : i32
    %570 = arith.extsi %568 : i32 to i64
    %569 = arith.muli %570, %567 : i64
    %571 = arith.constant 6 : i32
    %573 = arith.extsi %571 : i32 to i64
    %572 = arith.addi %569, %573 : i64
    %574 = arith.constant 2 : i32
    %575 = arith.constant 4 : i32
    %576 = func.call @count_points_primitive(%572) : (i64) -> i64
    %578 = arith.extsi %575 : i32 to i64
    %577 = arith.muli %578, %576 : i64
    %580 = arith.extsi %574 : i32 to i64
    %579 = arith.addi %580, %577 : i64
    %581 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %582 = llvm.call @printf(%581, %579) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    %583 = arith.constant 0 : i32
    func.return %583 : i32
  }
}