Problem 540

Counting Primitive Pythagorean Triples — P(3141592653589793).

Answer500000000002845
Output500000000002845
StatusPASS
Native helperno
Runtime570 ms
Peak memory4592 KB
Time complexityO(n^2) (estimated)
Space complexityO(n) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^2)O(n)
Space complexityO(n)O(1)
ApproachFlow solutionEuclid parametrisation
VerdictSuboptimal

Flow source

# Project Euler 540
# Counting Primitive Pythagorean Triples — P(3141592653589793).

import euler.nt { isqrt }

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

const N: i64 = 3141592653589793

function icbrt(n: i64) -> i64 {
    if n <= 1 { return n }
    let mut r: i64 = 1
    while r * r * r <= n {
        let r1: i64 = r + 1
        if r1 * r1 * r1 > n { break }
        r = r1
    }
    while r * r * r > n { r = r - 1 }
    return r
}

function odd_ge3_count_le(n: i64) -> i64 {
    if n < 3 { return 0 }
    return (n - 1) / 2
}

function raw_opposite_parity_count(limit: i64) -> i64 {
    if limit < 5 { return 0 }
    let mut full: i64 = (1 + isqrt(2 * limit - 1)) / 2
    while (full + 1) * (full + 1) + full * full <= limit { full = full + 1 }
    while full * full + (full - 1) * (full - 1) > limit { full = full - 1 }
    let k: i64 = full / 2
    let mut total: i64 = k * k
    let mut m: i64 = 2 * k + 1
    if m * m > limit { return total }
    let mut y: i64 = isqrt(limit - m * m)
    while m * m + 1 <= limit {
        let rem: i64 = limit - m * m
        while y * y > rem { y = y - 1 }
        let mut nmax: i64 = y
        if nmax >= m { nmax = m - 1 }
        if (m & 1) != 0 {
            total = total + nmax / 2
        } else {
            total = total + (nmax + 1) / 2
        }
        m = m + 1
    }
    return total
}

function build_small_table(cube: i64, small: ptr<i64>) -> void {
    let mut x: i64 = 1
    while x <= cube {
        let mut total: i64 = raw_opposite_parity_count(x)
        let max_d: i64 = isqrt(x)
        let split: i64 = icbrt(x)
        let mut d: i64 = 3
        while d <= max_d && d <= split {
            total = total - small[x / (d * d)]
            d = d + 2
        }
        if d <= max_d {
            let max_z: i64 = x / (d * d)
            let mut z: i64 = 1
            while z <= max_z {
                let hi: i64 = odd_ge3_count_le(isqrt(x / z))
                let lo: i64 = odd_ge3_count_le(isqrt(x / (z + 1)))
                total = total - (hi - lo) * small[z]
                z = z + 1
            }
        }
        small[x] = total
        x = x + 1
    }
}

function main() -> i32 {
    let cube: i64 = icbrt(N)
    let small: ptr<i64> = calloc(cube + 1, 8)
    let tail: ptr<i64> = calloc(cube + 1, 8)
    let transformed: ptr<i64> = calloc(cube + 1, 8)
    if small == null || tail == null || transformed == null { return 1 }
    build_small_table(cube, small)
    let s_max: i64 = isqrt(N / 5)
    let mut t: i64 = 1
    while t <= cube {
        let mut s: i64 = (cube / t + 1) * t
        if (s & 1) == 0 { s = s + t }
        let mut acc: i64 = 0
        let step: i64 = 2 * t
        while s <= s_max {
            acc = acc + small[N / (s * s)]
            s = s + step
        }
        tail[t] = acc
        t = t + 2
    }
    let mut start: i64 = cube
    if (start & 1) == 0 { start = start - 1 }
    t = start
    while t > 0 {
        let x: i64 = N / (t * t)
        let mut total: i64 = raw_opposite_parity_count(x)
        let mut s: i64 = 3 * t
        let step: i64 = 2 * t
        while s <= cube {
            total = total - transformed[s]
            s = s + step
        }
        total = total - tail[t]
        transformed[t] = total
        t = t - 2
    }
    printf("%lld\n", transformed[1])
    free(small); free(tail); free(transformed)
    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 icbrt_i64(int64_t n);
int64_t odd_ge3_count_le_i64(int64_t n);
int64_t raw_opposite_parity_count_i64(int64_t limit);
void build_small_table_i64_ptr_i64(int64_t cube, int64_t* small);
int32_t main(void);

static const int64_t N = 3141592653589793;

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 icbrt_i64(int64_t n) {
    if (n <= 1) {
        return n;
    }
    int64_t r = 1;
    while (((r * r) * r) <= n) {
        int64_t r1 = (r + 1);
        if (((r1 * r1) * r1) > n) {
            break;
        }
        r = r1;
    }
    while (((r * r) * r) > n) {
        r = (r - 1);
    }
    return r;
}

int64_t odd_ge3_count_le_i64(int64_t n) {
    if (n < 3) {
        return 0;
    }
    return FLOW_CHECKED_DIV(((n - 1)), (2));
}

int64_t raw_opposite_parity_count_i64(int64_t limit) {
    if (limit < 5) {
        return 0;
    }
    int64_t full = FLOW_CHECKED_DIV(((1 + isqrt_i64(((2 * limit) - 1)))), (2));
    while ((((full + 1) * (full + 1)) + (full * full)) <= limit) {
        full = (full + 1);
    }
    while (((full * full) + ((full - 1) * (full - 1))) > limit) {
        full = (full - 1);
    }
    int64_t k = FLOW_CHECKED_DIV((full), (2));
    int64_t total = (k * k);
    int64_t m = ((2 * k) + 1);
    if ((m * m) > limit) {
        return total;
    }
    int64_t y = isqrt_i64((limit - (m * m)));
    while (((m * m) + 1) <= limit) {
        int64_t rem = (limit - (m * m));
        while ((y * y) > rem) {
            y = (y - 1);
        }
        int64_t nmax = y;
        if (nmax >= m) {
            nmax = (m - 1);
        }
        if ((m & 1) != 0) {
            total = (total + FLOW_CHECKED_DIV((nmax), (2)));
        } else {
            total = (total + FLOW_CHECKED_DIV(((nmax + 1)), (2)));
        }
        m = (m + 1);
    }
    return total;
}

void build_small_table_i64_ptr_i64(int64_t cube, int64_t* small) {
    int64_t x = 1;
    while (x <= cube) {
        int64_t total = raw_opposite_parity_count_i64(x);
        int64_t max_d = isqrt_i64(x);
        int64_t split = icbrt_i64(x);
        int64_t d = 3;
        while ((d <= max_d && d <= split)) {
            total = (total - small[FLOW_CHECKED_DIV((x), ((d * d)))]);
            d = (d + 2);
        }
        if (d <= max_d) {
            int64_t max_z = FLOW_CHECKED_DIV((x), ((d * d)));
            int64_t z = 1;
            while (z <= max_z) {
                int64_t hi = odd_ge3_count_le_i64(isqrt_i64(FLOW_CHECKED_DIV((x), (z))));
                int64_t lo = odd_ge3_count_le_i64(isqrt_i64(FLOW_CHECKED_DIV((x), ((z + 1)))));
                total = (total - ((hi - lo) * small[z]));
                z = (z + 1);
            }
        }
        small[x] = total;
        x = (x + 1);
    }
}

int32_t main(void) {
    int64_t cube = icbrt_i64(N);
    int64_t* small = (int64_t*)(calloc((cube + 1), 8));
    int64_t* tail = (int64_t*)(calloc((cube + 1), 8));
    int64_t* transformed = (int64_t*)(calloc((cube + 1), 8));
    if (((small == NULL || tail == NULL) || transformed == NULL)) {
        return 1;
    }
    build_small_table_i64_ptr_i64(cube, small);
    int64_t s_max = isqrt_i64(FLOW_CHECKED_DIV((N), (5)));
    int64_t t = 1;
    while (t <= cube) {
        int64_t s = ((FLOW_CHECKED_DIV((cube), (t)) + 1) * t);
        if ((s & 1) == 0) {
            s = (s + t);
        }
        int64_t acc = 0;
        int64_t step = (2 * t);
        while (s <= s_max) {
            acc = (acc + small[FLOW_CHECKED_DIV((N), ((s * s)))]);
            s = (s + step);
        }
        tail[t] = acc;
        t = (t + 2);
    }
    int64_t start = cube;
    if ((start & 1) == 0) {
        start = (start - 1);
    }
    t = start;
    while (t > 0) {
        int64_t x = FLOW_CHECKED_DIV((N), ((t * t)));
        int64_t total = raw_opposite_parity_count_i64(x);
        int64_t s = (3 * t);
        int64_t step = (2 * t);
        while (s <= cube) {
            total = (total - transformed[s]);
            s = (s + step);
        }
        total = (total - tail[t]);
        transformed[t] = total;
        t = (t - 2);
    }
    printf("%lld\n", transformed[1]);
    free(small);
    free(tail);
    free(transformed);
    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 @free(!llvm.ptr) -> ()
  // Constant: N
  llvm.mlir.global internal constant @N(3141592653589793 : i64) : i64
  func.func @icbrt(%arg0: i64) -> i64 {
    %175 = arith.constant 1 : i32
    %177 = arith.extsi %175 : i32 to i64
    %176 = arith.cmpi sle, %arg0, %177 : i64
    cf.cond_br %176, ^bb42, ^bb43
    ^bb42:
      func.return %arg0 : i64
    ^bb43:
      cf.br ^bb44
    ^bb44:
    %178 = arith.constant 1 : i32
    %179 = arith.extsi %178 : i32 to i64
    %180 = llvm.mlir.constant(1 : i64) : i64
    %181 = llvm.alloca %180 x i64 : (i64) -> !llvm.ptr
    llvm.store %179, %181 : i64, !llvm.ptr
    cf.br ^bb45
    ^bb45:
    %182 = llvm.load %181 : !llvm.ptr -> i64
    %183 = llvm.load %181 : !llvm.ptr -> i64
    %184 = arith.muli %182, %183 : i64
    %185 = llvm.load %181 : !llvm.ptr -> i64
    %186 = arith.muli %184, %185 : i64
    %187 = arith.cmpi sle, %186, %arg0 : i64
    cf.cond_br %187, ^bb46, ^bb47
    ^bb46:
      %188 = llvm.load %181 : !llvm.ptr -> i64
      %189 = arith.constant 1 : i32
      %191 = arith.extsi %189 : i32 to i64
      %190 = arith.addi %188, %191 : i64
      %192 = arith.muli %190, %190 : i64
      %193 = arith.muli %192, %190 : i64
      %194 = arith.cmpi sgt, %193, %arg0 : i64
      cf.cond_br %194, ^bb48, ^bb49
      ^bb48:
        cf.br ^bb47
      ^bb49:
        cf.br ^bb50
      ^bb50:
      llvm.store %190, %181 : i64, !llvm.ptr
      cf.br ^bb45
    ^bb47:
    cf.br ^bb51
    ^bb51:
    %195 = llvm.load %181 : !llvm.ptr -> i64
    %196 = llvm.load %181 : !llvm.ptr -> i64
    %197 = arith.muli %195, %196 : i64
    %198 = llvm.load %181 : !llvm.ptr -> i64
    %199 = arith.muli %197, %198 : i64
    %200 = arith.cmpi sgt, %199, %arg0 : i64
    cf.cond_br %200, ^bb52, ^bb53
    ^bb52:
      %201 = llvm.load %181 : !llvm.ptr -> i64
      %202 = arith.constant 1 : i32
      %204 = arith.extsi %202 : i32 to i64
      %203 = arith.subi %201, %204 : i64
      llvm.store %203, %181 : i64, !llvm.ptr
      cf.br ^bb51
    ^bb53:
    %205 = llvm.load %181 : !llvm.ptr -> i64
    func.return %205 : i64
  }
  func.func @odd_ge3_count_le(%arg0: i64) -> i64 {
    %206 = arith.constant 3 : i32
    %208 = arith.extsi %206 : i32 to i64
    %207 = arith.cmpi slt, %arg0, %208 : i64
    cf.cond_br %207, ^bb54, ^bb55
    ^bb54:
      %209 = arith.constant 0 : i32
      %210 = arith.extsi %209 : i32 to i64
      func.return %210 : i64
    ^bb55:
      cf.br ^bb56
    ^bb56:
    %211 = arith.constant 1 : i32
    %213 = arith.extsi %211 : i32 to i64
    %212 = arith.subi %arg0, %213 : i64
    %214 = arith.constant 2 : i32
    %216 = arith.extsi %214 : i32 to i64
    %215 = arith.divsi %212, %216 : i64
    func.return %215 : i64
  }
  func.func @raw_opposite_parity_count(%arg0: i64) -> i64 {
    %217 = arith.constant 5 : i32
    %219 = arith.extsi %217 : i32 to i64
    %218 = arith.cmpi slt, %arg0, %219 : i64
    cf.cond_br %218, ^bb57, ^bb58
    ^bb57:
      %220 = arith.constant 0 : i32
      %221 = arith.extsi %220 : i32 to i64
      func.return %221 : i64
    ^bb58:
      cf.br ^bb59
    ^bb59:
    %222 = arith.constant 1 : i32
    %224 = arith.constant 2 : i32
    %226 = arith.extsi %224 : i32 to i64
    %225 = arith.muli %226, %arg0 : i64
    %227 = arith.constant 1 : i32
    %229 = arith.extsi %227 : i32 to i64
    %228 = arith.subi %225, %229 : i64
    %223 = func.call @isqrt(%228) : (i64) -> i64
    %231 = arith.extsi %222 : i32 to i64
    %230 = arith.addi %231, %223 : i64
    %232 = arith.constant 2 : i32
    %234 = arith.extsi %232 : i32 to i64
    %233 = arith.divsi %230, %234 : i64
    %235 = llvm.mlir.constant(1 : i64) : i64
    %236 = llvm.alloca %235 x i64 : (i64) -> !llvm.ptr
    llvm.store %233, %236 : i64, !llvm.ptr
    cf.br ^bb60
    ^bb60:
    %237 = llvm.load %236 : !llvm.ptr -> i64
    %238 = arith.constant 1 : i32
    %240 = arith.extsi %238 : i32 to i64
    %239 = arith.addi %237, %240 : i64
    %241 = llvm.load %236 : !llvm.ptr -> i64
    %242 = arith.constant 1 : i32
    %244 = arith.extsi %242 : i32 to i64
    %243 = arith.addi %241, %244 : i64
    %245 = arith.muli %239, %243 : i64
    %246 = llvm.load %236 : !llvm.ptr -> i64
    %247 = llvm.load %236 : !llvm.ptr -> i64
    %248 = arith.muli %246, %247 : i64
    %249 = arith.addi %245, %248 : i64
    %250 = arith.cmpi sle, %249, %arg0 : i64
    cf.cond_br %250, ^bb61, ^bb62
    ^bb61:
      %251 = llvm.load %236 : !llvm.ptr -> i64
      %252 = arith.constant 1 : i32
      %254 = arith.extsi %252 : i32 to i64
      %253 = arith.addi %251, %254 : i64
      llvm.store %253, %236 : i64, !llvm.ptr
      cf.br ^bb60
    ^bb62:
    cf.br ^bb63
    ^bb63:
    %255 = llvm.load %236 : !llvm.ptr -> i64
    %256 = llvm.load %236 : !llvm.ptr -> i64
    %257 = arith.muli %255, %256 : i64
    %258 = llvm.load %236 : !llvm.ptr -> i64
    %259 = arith.constant 1 : i32
    %261 = arith.extsi %259 : i32 to i64
    %260 = arith.subi %258, %261 : i64
    %262 = llvm.load %236 : !llvm.ptr -> i64
    %263 = arith.constant 1 : i32
    %265 = arith.extsi %263 : i32 to i64
    %264 = arith.subi %262, %265 : i64
    %266 = arith.muli %260, %264 : i64
    %267 = arith.addi %257, %266 : i64
    %268 = arith.cmpi sgt, %267, %arg0 : i64
    cf.cond_br %268, ^bb64, ^bb65
    ^bb64:
      %269 = llvm.load %236 : !llvm.ptr -> i64
      %270 = arith.constant 1 : i32
      %272 = arith.extsi %270 : i32 to i64
      %271 = arith.subi %269, %272 : i64
      llvm.store %271, %236 : i64, !llvm.ptr
      cf.br ^bb63
    ^bb65:
    %273 = llvm.load %236 : !llvm.ptr -> i64
    %274 = arith.constant 2 : i32
    %276 = arith.extsi %274 : i32 to i64
    %275 = arith.divsi %273, %276 : i64
    %277 = arith.muli %275, %275 : i64
    %278 = llvm.mlir.constant(1 : i64) : i64
    %279 = llvm.alloca %278 x i64 : (i64) -> !llvm.ptr
    llvm.store %277, %279 : i64, !llvm.ptr
    %280 = arith.constant 2 : i32
    %282 = arith.extsi %280 : i32 to i64
    %281 = arith.muli %282, %275 : i64
    %283 = arith.constant 1 : i32
    %285 = arith.extsi %283 : i32 to i64
    %284 = arith.addi %281, %285 : i64
    %286 = llvm.mlir.constant(1 : i64) : i64
    %287 = llvm.alloca %286 x i64 : (i64) -> !llvm.ptr
    llvm.store %284, %287 : i64, !llvm.ptr
    %288 = llvm.load %287 : !llvm.ptr -> i64
    %289 = llvm.load %287 : !llvm.ptr -> i64
    %290 = arith.muli %288, %289 : i64
    %291 = arith.cmpi sgt, %290, %arg0 : i64
    cf.cond_br %291, ^bb66, ^bb67
    ^bb66:
      %292 = llvm.load %279 : !llvm.ptr -> i64
      func.return %292 : i64
    ^bb67:
      cf.br ^bb68
    ^bb68:
    %294 = llvm.load %287 : !llvm.ptr -> i64
    %295 = llvm.load %287 : !llvm.ptr -> i64
    %296 = arith.muli %294, %295 : i64
    %297 = arith.subi %arg0, %296 : i64
    %293 = func.call @isqrt(%297) : (i64) -> i64
    %298 = llvm.mlir.constant(1 : i64) : i64
    %299 = llvm.alloca %298 x i64 : (i64) -> !llvm.ptr
    llvm.store %293, %299 : i64, !llvm.ptr
    cf.br ^bb69
    ^bb69:
    %300 = llvm.load %287 : !llvm.ptr -> i64
    %301 = llvm.load %287 : !llvm.ptr -> i64
    %302 = arith.muli %300, %301 : i64
    %303 = arith.constant 1 : i32
    %305 = arith.extsi %303 : i32 to i64
    %304 = arith.addi %302, %305 : i64
    %306 = arith.cmpi sle, %304, %arg0 : i64
    cf.cond_br %306, ^bb70, ^bb71
    ^bb70:
      %307 = llvm.load %287 : !llvm.ptr -> i64
      %308 = llvm.load %287 : !llvm.ptr -> i64
      %309 = arith.muli %307, %308 : i64
      %310 = arith.subi %arg0, %309 : i64
      cf.br ^bb72
      ^bb72:
      %311 = llvm.load %299 : !llvm.ptr -> i64
      %312 = llvm.load %299 : !llvm.ptr -> i64
      %313 = arith.muli %311, %312 : i64
      %314 = arith.cmpi sgt, %313, %310 : i64
      cf.cond_br %314, ^bb73, ^bb74
      ^bb73:
        %315 = llvm.load %299 : !llvm.ptr -> i64
        %316 = arith.constant 1 : i32
        %318 = arith.extsi %316 : i32 to i64
        %317 = arith.subi %315, %318 : i64
        llvm.store %317, %299 : i64, !llvm.ptr
        cf.br ^bb72
      ^bb74:
      %319 = llvm.load %299 : !llvm.ptr -> i64
      %320 = llvm.mlir.constant(1 : i64) : i64
      %321 = llvm.alloca %320 x i64 : (i64) -> !llvm.ptr
      llvm.store %319, %321 : i64, !llvm.ptr
      %322 = llvm.load %321 : !llvm.ptr -> i64
      %323 = llvm.load %287 : !llvm.ptr -> i64
      %324 = arith.cmpi sge, %322, %323 : i64
      cf.cond_br %324, ^bb75, ^bb76
      ^bb75:
        %325 = llvm.load %287 : !llvm.ptr -> i64
        %326 = arith.constant 1 : i32
        %328 = arith.extsi %326 : i32 to i64
        %327 = arith.subi %325, %328 : i64
        llvm.store %327, %321 : i64, !llvm.ptr
        cf.br ^bb77
      ^bb76:
        cf.br ^bb77
      ^bb77:
      %329 = llvm.load %287 : !llvm.ptr -> i64
      %330 = arith.constant 1 : i32
      %332 = arith.extsi %330 : i32 to i64
      %331 = arith.andi %329, %332 : i64
      %333 = arith.constant 0 : i32
      %335 = arith.extsi %333 : i32 to i64
      %334 = arith.cmpi ne, %331, %335 : i64
      cf.cond_br %334, ^bb78, ^bb79
      ^bb78:
        %336 = llvm.load %279 : !llvm.ptr -> i64
        %337 = llvm.load %321 : !llvm.ptr -> i64
        %338 = arith.constant 2 : i32
        %340 = arith.extsi %338 : i32 to i64
        %339 = arith.divsi %337, %340 : i64
        %341 = arith.addi %336, %339 : i64
        llvm.store %341, %279 : i64, !llvm.ptr
        cf.br ^bb80
      ^bb79:
        %342 = llvm.load %279 : !llvm.ptr -> i64
        %343 = llvm.load %321 : !llvm.ptr -> i64
        %344 = arith.constant 1 : i32
        %346 = arith.extsi %344 : i32 to i64
        %345 = arith.addi %343, %346 : i64
        %347 = arith.constant 2 : i32
        %349 = arith.extsi %347 : i32 to i64
        %348 = arith.divsi %345, %349 : i64
        %350 = arith.addi %342, %348 : i64
        llvm.store %350, %279 : i64, !llvm.ptr
        cf.br ^bb80
      ^bb80:
      %351 = llvm.load %287 : !llvm.ptr -> i64
      %352 = arith.constant 1 : i32
      %354 = arith.extsi %352 : i32 to i64
      %353 = arith.addi %351, %354 : i64
      llvm.store %353, %287 : i64, !llvm.ptr
      cf.br ^bb69
    ^bb71:
    %355 = llvm.load %279 : !llvm.ptr -> i64
    func.return %355 : i64
  }
  func.func @build_small_table(%arg0: i64, %arg1: !llvm.ptr) -> () {
    %356 = arith.constant 1 : i32
    %357 = arith.extsi %356 : i32 to i64
    %358 = llvm.mlir.constant(1 : i64) : i64
    %359 = llvm.alloca %358 x i64 : (i64) -> !llvm.ptr
    llvm.store %357, %359 : i64, !llvm.ptr
    cf.br ^bb81
    ^bb81:
    %360 = llvm.load %359 : !llvm.ptr -> i64
    %361 = arith.cmpi sle, %360, %arg0 : i64
    cf.cond_br %361, ^bb82, ^bb83
    ^bb82:
      %363 = llvm.load %359 : !llvm.ptr -> i64
      %362 = func.call @raw_opposite_parity_count(%363) : (i64) -> i64
      %364 = llvm.mlir.constant(1 : i64) : i64
      %365 = llvm.alloca %364 x i64 : (i64) -> !llvm.ptr
      llvm.store %362, %365 : i64, !llvm.ptr
      %367 = llvm.load %359 : !llvm.ptr -> i64
      %366 = func.call @isqrt(%367) : (i64) -> i64
      %369 = llvm.load %359 : !llvm.ptr -> i64
      %368 = func.call @icbrt(%369) : (i64) -> i64
      %370 = arith.constant 3 : i32
      %371 = arith.extsi %370 : i32 to i64
      %372 = llvm.mlir.constant(1 : i64) : i64
      %373 = llvm.alloca %372 x i64 : (i64) -> !llvm.ptr
      llvm.store %371, %373 : i64, !llvm.ptr
      cf.br ^bb84
      ^bb84:
      %374 = llvm.load %373 : !llvm.ptr -> i64
      %375 = arith.cmpi sle, %374, %366 : i64
      %376 = scf.if %375 -> (i1) {
        %377 = llvm.load %373 : !llvm.ptr -> i64
        %378 = arith.cmpi sle, %377, %368 : i64
        scf.yield %378 : i1
      } else {
        %379 = arith.constant false
        scf.yield %379 : i1
      }
      cf.cond_br %376, ^bb85, ^bb86
      ^bb85:
        %380 = llvm.load %365 : !llvm.ptr -> i64
        %382 = llvm.load %359 : !llvm.ptr -> i64
        %383 = llvm.load %373 : !llvm.ptr -> i64
        %384 = llvm.load %373 : !llvm.ptr -> i64
        %385 = arith.muli %383, %384 : i64
        %386 = arith.divsi %382, %385 : i64
        %387 = llvm.getelementptr %arg1[%386] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %381 = llvm.load %387 : !llvm.ptr -> i64
        %388 = arith.subi %380, %381 : i64
        llvm.store %388, %365 : i64, !llvm.ptr
        %389 = llvm.load %373 : !llvm.ptr -> i64
        %390 = arith.constant 2 : i32
        %392 = arith.extsi %390 : i32 to i64
        %391 = arith.addi %389, %392 : i64
        llvm.store %391, %373 : i64, !llvm.ptr
        cf.br ^bb84
      ^bb86:
      %393 = llvm.load %373 : !llvm.ptr -> i64
      %394 = arith.cmpi sle, %393, %366 : i64
      cf.cond_br %394, ^bb87, ^bb88
      ^bb87:
        %395 = llvm.load %359 : !llvm.ptr -> i64
        %396 = llvm.load %373 : !llvm.ptr -> i64
        %397 = llvm.load %373 : !llvm.ptr -> i64
        %398 = arith.muli %396, %397 : i64
        %399 = arith.divsi %395, %398 : i64
        %400 = arith.constant 1 : i32
        %401 = arith.extsi %400 : i32 to i64
        %402 = llvm.mlir.constant(1 : i64) : i64
        %403 = llvm.alloca %402 x i64 : (i64) -> !llvm.ptr
        llvm.store %401, %403 : i64, !llvm.ptr
        cf.br ^bb90
        ^bb90:
        %404 = llvm.load %403 : !llvm.ptr -> i64
        %405 = arith.cmpi sle, %404, %399 : i64
        cf.cond_br %405, ^bb91, ^bb92
        ^bb91:
          %408 = llvm.load %359 : !llvm.ptr -> i64
          %409 = llvm.load %403 : !llvm.ptr -> i64
          %410 = arith.divsi %408, %409 : i64
          %407 = func.call @isqrt(%410) : (i64) -> i64
          %406 = func.call @odd_ge3_count_le(%407) : (i64) -> i64
          %413 = llvm.load %359 : !llvm.ptr -> i64
          %414 = llvm.load %403 : !llvm.ptr -> i64
          %415 = arith.constant 1 : i32
          %417 = arith.extsi %415 : i32 to i64
          %416 = arith.addi %414, %417 : i64
          %418 = arith.divsi %413, %416 : i64
          %412 = func.call @isqrt(%418) : (i64) -> i64
          %411 = func.call @odd_ge3_count_le(%412) : (i64) -> i64
          %419 = llvm.load %365 : !llvm.ptr -> i64
          %420 = arith.subi %406, %411 : i64
          %422 = llvm.load %403 : !llvm.ptr -> i64
          %423 = llvm.getelementptr %arg1[%422] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %421 = llvm.load %423 : !llvm.ptr -> i64
          %424 = arith.muli %420, %421 : i64
          %425 = arith.subi %419, %424 : i64
          llvm.store %425, %365 : i64, !llvm.ptr
          %426 = llvm.load %403 : !llvm.ptr -> i64
          %427 = arith.constant 1 : i32
          %429 = arith.extsi %427 : i32 to i64
          %428 = arith.addi %426, %429 : i64
          llvm.store %428, %403 : i64, !llvm.ptr
          cf.br ^bb90
        ^bb92:
        cf.br ^bb89
      ^bb88:
        cf.br ^bb89
      ^bb89:
      %430 = llvm.load %365 : !llvm.ptr -> i64
      %431 = llvm.load %359 : !llvm.ptr -> i64
      %432 = llvm.getelementptr %arg1[%431] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %430, %432 : i64, !llvm.ptr
      %433 = llvm.load %359 : !llvm.ptr -> i64
      %434 = arith.constant 1 : i32
      %436 = arith.extsi %434 : i32 to i64
      %435 = arith.addi %433, %436 : i64
      llvm.store %435, %359 : i64, !llvm.ptr
      cf.br ^bb81
    ^bb83:
    func.return
  }
  func.func @main() -> i32 {
    %438 = llvm.mlir.addressof @N : !llvm.ptr
    %439 = llvm.load %438 : !llvm.ptr -> i64
    %437 = func.call @icbrt(%439) : (i64) -> i64
    %441 = arith.constant 1 : i32
    %443 = arith.extsi %441 : i32 to i64
    %442 = arith.addi %437, %443 : i64
    %444 = arith.constant 8 : i32
    %445 = arith.extsi %444 : i32 to i64
    %440 = func.call @calloc(%442, %445) : (i64, i64) -> !llvm.ptr
    %447 = arith.constant 1 : i32
    %449 = arith.extsi %447 : i32 to i64
    %448 = arith.addi %437, %449 : i64
    %450 = arith.constant 8 : i32
    %451 = arith.extsi %450 : i32 to i64
    %446 = func.call @calloc(%448, %451) : (i64, i64) -> !llvm.ptr
    %453 = arith.constant 1 : i32
    %455 = arith.extsi %453 : i32 to i64
    %454 = arith.addi %437, %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 = llvm.mlir.zero : !llvm.ptr
    %459 = llvm.icmp "eq" %440, %458 : !llvm.ptr
    %460 = scf.if %459 -> (i1) {
      %461 = arith.constant true
      scf.yield %461 : i1
    } else {
      %462 = llvm.mlir.zero : !llvm.ptr
      %463 = llvm.icmp "eq" %446, %462 : !llvm.ptr
      scf.yield %463 : i1
    }
    %464 = scf.if %460 -> (i1) {
      %465 = arith.constant true
      scf.yield %465 : i1
    } else {
      %466 = llvm.mlir.zero : !llvm.ptr
      %467 = llvm.icmp "eq" %452, %466 : !llvm.ptr
      scf.yield %467 : i1
    }
    cf.cond_br %464, ^bb93, ^bb94
    ^bb93:
      %468 = arith.constant 1 : i32
      func.return %468 : i32
    ^bb94:
      cf.br ^bb95
    ^bb95:
    func.call @build_small_table(%437, %440) : (i64, !llvm.ptr) -> ()
    %471 = llvm.mlir.addressof @N : !llvm.ptr
    %472 = llvm.load %471 : !llvm.ptr -> i64
    %473 = arith.constant 5 : i32
    %475 = arith.extsi %473 : i32 to i64
    %474 = arith.divsi %472, %475 : i64
    %470 = func.call @isqrt(%474) : (i64) -> i64
    %476 = arith.constant 1 : i32
    %477 = arith.extsi %476 : i32 to i64
    %478 = llvm.mlir.constant(1 : i64) : i64
    %479 = llvm.alloca %478 x i64 : (i64) -> !llvm.ptr
    llvm.store %477, %479 : i64, !llvm.ptr
    cf.br ^bb96
    ^bb96:
    %480 = llvm.load %479 : !llvm.ptr -> i64
    %481 = arith.cmpi sle, %480, %437 : i64
    cf.cond_br %481, ^bb97, ^bb98
    ^bb97:
      %482 = llvm.load %479 : !llvm.ptr -> i64
      %483 = arith.divsi %437, %482 : i64
      %484 = arith.constant 1 : i32
      %486 = arith.extsi %484 : i32 to i64
      %485 = arith.addi %483, %486 : i64
      %487 = llvm.load %479 : !llvm.ptr -> i64
      %488 = arith.muli %485, %487 : i64
      %489 = llvm.mlir.constant(1 : i64) : i64
      %490 = llvm.alloca %489 x i64 : (i64) -> !llvm.ptr
      llvm.store %488, %490 : i64, !llvm.ptr
      %491 = llvm.load %490 : !llvm.ptr -> i64
      %492 = arith.constant 1 : i32
      %494 = arith.extsi %492 : i32 to i64
      %493 = arith.andi %491, %494 : i64
      %495 = arith.constant 0 : i32
      %497 = arith.extsi %495 : i32 to i64
      %496 = arith.cmpi eq, %493, %497 : i64
      cf.cond_br %496, ^bb99, ^bb100
      ^bb99:
        %498 = llvm.load %490 : !llvm.ptr -> i64
        %499 = llvm.load %479 : !llvm.ptr -> i64
        %500 = arith.addi %498, %499 : i64
        llvm.store %500, %490 : i64, !llvm.ptr
        cf.br ^bb101
      ^bb100:
        cf.br ^bb101
      ^bb101:
      %501 = arith.constant 0 : i32
      %502 = arith.extsi %501 : i32 to i64
      %503 = llvm.mlir.constant(1 : i64) : i64
      %504 = llvm.alloca %503 x i64 : (i64) -> !llvm.ptr
      llvm.store %502, %504 : i64, !llvm.ptr
      %505 = arith.constant 2 : i32
      %506 = llvm.load %479 : !llvm.ptr -> i64
      %508 = arith.extsi %505 : i32 to i64
      %507 = arith.muli %508, %506 : i64
      cf.br ^bb102
      ^bb102:
      %509 = llvm.load %490 : !llvm.ptr -> i64
      %510 = arith.cmpi sle, %509, %470 : i64
      cf.cond_br %510, ^bb103, ^bb104
      ^bb103:
        %511 = llvm.load %504 : !llvm.ptr -> i64
        %513 = llvm.mlir.addressof @N : !llvm.ptr
        %514 = llvm.load %513 : !llvm.ptr -> i64
        %515 = llvm.load %490 : !llvm.ptr -> i64
        %516 = llvm.load %490 : !llvm.ptr -> i64
        %517 = arith.muli %515, %516 : i64
        %518 = arith.divsi %514, %517 : i64
        %519 = llvm.getelementptr %440[%518] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %512 = llvm.load %519 : !llvm.ptr -> i64
        %520 = arith.addi %511, %512 : i64
        llvm.store %520, %504 : i64, !llvm.ptr
        %521 = llvm.load %490 : !llvm.ptr -> i64
        %522 = arith.addi %521, %507 : i64
        llvm.store %522, %490 : i64, !llvm.ptr
        cf.br ^bb102
      ^bb104:
      %523 = llvm.load %504 : !llvm.ptr -> i64
      %524 = llvm.load %479 : !llvm.ptr -> i64
      %525 = llvm.getelementptr %446[%524] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %523, %525 : i64, !llvm.ptr
      %526 = llvm.load %479 : !llvm.ptr -> i64
      %527 = arith.constant 2 : i32
      %529 = arith.extsi %527 : i32 to i64
      %528 = arith.addi %526, %529 : i64
      llvm.store %528, %479 : i64, !llvm.ptr
      cf.br ^bb96
    ^bb98:
    %530 = llvm.mlir.constant(1 : i64) : i64
    %531 = llvm.alloca %530 x i64 : (i64) -> !llvm.ptr
    llvm.store %437, %531 : i64, !llvm.ptr
    %532 = llvm.load %531 : !llvm.ptr -> i64
    %533 = arith.constant 1 : i32
    %535 = arith.extsi %533 : i32 to i64
    %534 = arith.andi %532, %535 : i64
    %536 = arith.constant 0 : i32
    %538 = arith.extsi %536 : i32 to i64
    %537 = arith.cmpi eq, %534, %538 : i64
    cf.cond_br %537, ^bb105, ^bb106
    ^bb105:
      %539 = llvm.load %531 : !llvm.ptr -> i64
      %540 = arith.constant 1 : i32
      %542 = arith.extsi %540 : i32 to i64
      %541 = arith.subi %539, %542 : i64
      llvm.store %541, %531 : i64, !llvm.ptr
      cf.br ^bb107
    ^bb106:
      cf.br ^bb107
    ^bb107:
    %543 = llvm.load %531 : !llvm.ptr -> i64
    llvm.store %543, %479 : i64, !llvm.ptr
    cf.br ^bb108
    ^bb108:
    %544 = llvm.load %479 : !llvm.ptr -> i64
    %545 = arith.constant 0 : i32
    %547 = arith.extsi %545 : i32 to i64
    %546 = arith.cmpi sgt, %544, %547 : i64
    cf.cond_br %546, ^bb109, ^bb110
    ^bb109:
      %548 = llvm.mlir.addressof @N : !llvm.ptr
      %549 = llvm.load %548 : !llvm.ptr -> i64
      %550 = llvm.load %479 : !llvm.ptr -> i64
      %551 = llvm.load %479 : !llvm.ptr -> i64
      %552 = arith.muli %550, %551 : i64
      %553 = arith.divsi %549, %552 : i64
      %554 = func.call @raw_opposite_parity_count(%553) : (i64) -> i64
      %555 = llvm.mlir.constant(1 : i64) : i64
      %556 = llvm.alloca %555 x i64 : (i64) -> !llvm.ptr
      llvm.store %554, %556 : i64, !llvm.ptr
      %557 = arith.constant 3 : i32
      %558 = llvm.load %479 : !llvm.ptr -> i64
      %560 = arith.extsi %557 : i32 to i64
      %559 = arith.muli %560, %558 : i64
      %561 = llvm.mlir.constant(1 : i64) : i64
      %562 = llvm.alloca %561 x i64 : (i64) -> !llvm.ptr
      llvm.store %559, %562 : i64, !llvm.ptr
      %563 = arith.constant 2 : i32
      %564 = llvm.load %479 : !llvm.ptr -> i64
      %566 = arith.extsi %563 : i32 to i64
      %565 = arith.muli %566, %564 : i64
      cf.br ^bb111
      ^bb111:
      %567 = llvm.load %562 : !llvm.ptr -> i64
      %568 = arith.cmpi sle, %567, %437 : i64
      cf.cond_br %568, ^bb112, ^bb113
      ^bb112:
        %569 = llvm.load %556 : !llvm.ptr -> i64
        %571 = llvm.load %562 : !llvm.ptr -> i64
        %572 = llvm.getelementptr %452[%571] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %570 = llvm.load %572 : !llvm.ptr -> i64
        %573 = arith.subi %569, %570 : i64
        llvm.store %573, %556 : i64, !llvm.ptr
        %574 = llvm.load %562 : !llvm.ptr -> i64
        %575 = arith.addi %574, %565 : i64
        llvm.store %575, %562 : i64, !llvm.ptr
        cf.br ^bb111
      ^bb113:
      %576 = llvm.load %556 : !llvm.ptr -> i64
      %578 = llvm.load %479 : !llvm.ptr -> i64
      %579 = llvm.getelementptr %446[%578] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %577 = llvm.load %579 : !llvm.ptr -> i64
      %580 = arith.subi %576, %577 : i64
      llvm.store %580, %556 : i64, !llvm.ptr
      %581 = llvm.load %556 : !llvm.ptr -> i64
      %582 = llvm.load %479 : !llvm.ptr -> i64
      %583 = llvm.getelementptr %452[%582] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %581, %583 : i64, !llvm.ptr
      %584 = llvm.load %479 : !llvm.ptr -> i64
      %585 = arith.constant 2 : i32
      %587 = arith.extsi %585 : i32 to i64
      %586 = arith.subi %584, %587 : i64
      llvm.store %586, %479 : i64, !llvm.ptr
      cf.br ^bb108
    ^bb110:
    %588 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %590 = arith.constant 1 : i32
    %591 = arith.extsi %590 : i32 to i64
    %592 = llvm.getelementptr %452[%591] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %589 = llvm.load %592 : !llvm.ptr -> i64
    %593 = llvm.call @printf(%588, %589) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    func.call @free(%440) : (!llvm.ptr) -> ()
    func.call @free(%446) : (!llvm.ptr) -> ()
    func.call @free(%452) : (!llvm.ptr) -> ()
    %597 = arith.constant 0 : i32
    func.return %597 : i32
  }
}