Problem 372

R(2e6, 1e9): count pairs with floor((y/x)^2) odd.

Answer301450082318807027
Output301450082318807027
StatusPASS
Native helperno
Runtime4530 ms
Peak memory1072 KB
Time complexityO(n) (estimated)
Space complexityO(1) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n)?
Space complexityO(1)?
ApproachFlow solutionNot curated
VerdictUnknown

Flow source

# Project Euler 372
# R(2e6, 1e9): count pairs with floor((y/x)^2) odd.

import euler.nt { isqrt }

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

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

function 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 1 == 1 {
        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 }
        n = y_max / m
        b = y_max % m
        let tmp: i64 = a
        a = m
        m = tmp
    }
    return res
}

function isqrt128(n: i128) -> i64 {
    if n <= (0 as i128) { return 0 }
    if n < (2 as i128) { return n as i64 }
    let mut x: i128 = n
    let mut y: i128 = (x + (1 as i128)) / (2 as i128)
    while y < x {
        x = y
        y = (x + n / x) / (2 as i128)
    }
    return x as i64
}

function floor_surd(a: i64, b: i64, c: i64, k: i64) -> i64 {
    if b == 0 || k == 0 { return a / c }
    let mut bb: i64 = b
    if bb < 0 { bb = 0 - bb }
    let bbk: i128 = (bb as i128) * (bb as i128) * (k as i128)
    let s: i64 = isqrt128(bbk)
    if b > 0 {
        let t: i64 = (a + s) / c
        let u: i64 = (t + 1) * c - a
        if u <= 0 { return t + 1 }
        if (u as i128) * (u as i128) <= bbk { return t + 1 }
        return t
    }
    let t2: i64 = (a - s - 1) / c
    let d: i64 = a - (t2 + 1) * c
    if d >= 0 && (d as i128) * (d as i128) >= bbk { return t2 + 1 }
    return t2
}

function normalize(a0: i64, b0: i64, c0: i64, out_a: ptr<i64>, out_b: ptr<i64>, out_c: ptr<i64>) -> void {
    let mut a: i64 = a0
    let mut b: i64 = b0
    let mut c: i64 = c0
    if c < 0 {
        a = 0 - a
        b = 0 - b
        c = 0 - c
    }
    let g: i64 = igcd(igcd(a, b), c)
    if g > 1 {
        a = a / g
        b = b / g
        c = c / g
    }
    out_a[0] = a
    out_b[0] = b
    out_c[0] = c
}

function sum_floor_mul_surd(a0: i64, b0: i64, c0: i64, k: i64, n0: i64) -> i64 {
    if n0 <= 0 { return 0 }
    if b0 == 0 || k == 0 {
        let p: i64 = a0
        let q: i64 = c0
        if p >= 0 {
            return floor_sum(n0, q, p, p)
        }
        let pp: i64 = 0 - p
        return 0 - floor_sum(n0, q, pp, pp + q - 1)
    }

    let mut aa: i64 = a0
    let mut bb: i64 = b0
    let mut cc: i64 = c0
    let mut nn: i64 = n0
    let mut res: i64 = 0
    let mut sign: i64 = 1
    let box_a: array<i64, 1> = [0]
    let box_b: array<i64, 1> = [0]
    let box_c: array<i64, 1> = [0]

    while nn > 0 {
        let q_int: i64 = floor_surd(aa, bb, cc, k)
        if q_int != 0 {
            res = res + sign * q_int * nn * (nn + 1) / 2
            aa = aa - q_int * cc
        }
        if aa == 0 && bb == 0 { break }
        let m: i64 = floor_surd(aa * nn, bb * nn, cc, k)
        if m == 0 { break }
        res = res + sign * nn * m

        # reciprocal
        let mut A: i64 = cc * aa
        let mut B: i64 = 0 - cc * bb
        let mut C: i64 = aa * aa - bb * bb * k
        if C < 0 {
            A = 0 - A
            B = 0 - B
            C = 0 - C
        }
        normalize(A, B, C, box_a, box_b, box_c)
        aa = box_a[0]
        bb = box_b[0]
        cc = box_c[0]
        nn = m
        sign = 0 - sign
    }
    return res
}

function P_func(k: i64, L: i64, U: i64, len_side: i64, total_pairs: i64, U2m1: i64, Lm1: i64) -> i64 {
    if k == 1 {
        return len_side * (len_side - 1) / 2
    }
    let r: i64 = isqrt(k)
    if r * r == k {
        let s: i64 = r
        let mut b: i64 = U / s
        if b < L { return total_pairs }
        if b > U { b = U }
        let cnt: i64 = b - L + 1
        let sum_x: i64 = (L + b) * cnt / 2
        let partial: i64 = s * sum_x - L * cnt
        let full_cnt: i64 = U - b
        return partial + full_cnt * len_side
    }

    let mut b2: i64 = isqrt(U2m1 / k)
    if b2 < L { return total_pairs }
    if b2 > U { b2 = U }
    let cnt2: i64 = b2 - L + 1
    let sum_floor: i64 = sum_floor_mul_surd(0, 1, 1, k, b2) - sum_floor_mul_surd(0, 1, 1, k, Lm1)
    let partial2: i64 = sum_floor - (L - 1) * cnt2
    let full_cnt2: i64 = U - b2
    return partial2 + full_cnt2 * len_side
}

function solve(M: i64, N: i64) -> i64 {
    let L: i64 = M + 1
    let U: i64 = N
    if L > U { return 0 }
    let len_side: i64 = U - L + 1
    let total_pairs: i64 = len_side * len_side
    let k_max: i64 = (U * U) / (L * L)
    let mut last_odd: i64 = k_max
    if (k_max & 1) == 0 { last_odd = k_max - 1 }
    let U2m1: i64 = U * U - 1
    let Lm1: i64 = L - 1

    let mut ans: i64 = 0
    let mut n: i64 = 1
    while n <= last_odd {
        ans = ans + P_func(n + 1, L, U, len_side, total_pairs, U2m1, Lm1) - P_func(n, L, U, len_side, total_pairs, U2m1, Lm1)
        n = n + 2
    }
    return ans
}

function main() -> i32 {
    let ans: i64 = solve(2000000, 1000000000)
    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 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 igcd_i64_i64(int64_t a0, int64_t b0);
int64_t floor_sum_i64_i64_i64_i64(int64_t n0, int64_t m0, int64_t a0, int64_t b0);
int64_t isqrt128_i128(__int128 n);
int64_t floor_surd_i64_i64_i64_i64(int64_t a, int64_t b, int64_t c, int64_t k);
void normalize_i64_i64_i64_ptr_i64_ptr_i64_ptr_i64(int64_t a0, int64_t b0, int64_t c0, int64_t* out_a, int64_t* out_b, int64_t* out_c);
int64_t sum_floor_mul_surd_i64_i64_i64_i64_i64(int64_t a0, int64_t b0, int64_t c0, int64_t k, int64_t n0);
int64_t P_func_i64_i64_i64_i64_i64_i64_i64(int64_t k, int64_t L, int64_t U, int64_t len_side, int64_t total_pairs, int64_t U2m1, int64_t Lm1);
int64_t solve_i64_i64(int64_t M, int64_t N);
int32_t main(void);

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 igcd_i64_i64(int64_t a0, int64_t b0) {
    int64_t a = a0;
    int64_t b = b0;
    if (a < 0) {
        a = (0 - a);
    }
    if (b < 0) {
        b = (0 - b);
    }
    while (b != 0) {
        int64_t t = FLOW_CHECKED_MOD((a), (b));
        a = b;
        b = t;
    }
    return a;
}

int64_t 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 == 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;
        }
        n = FLOW_CHECKED_DIV((y_max), (m));
        b = FLOW_CHECKED_MOD((y_max), (m));
        int64_t tmp = a;
        a = m;
        m = tmp;
    }
    return res;
}

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

int64_t floor_surd_i64_i64_i64_i64(int64_t a, int64_t b, int64_t c, int64_t k) {
    if ((b == 0 || k == 0)) {
        return FLOW_CHECKED_DIV((a), (c));
    }
    int64_t bb = b;
    if (bb < 0) {
        bb = (0 - bb);
    }
    __int128 bbk = ((((__int128)(bb)) * ((__int128)(bb))) * ((__int128)(k)));
    int64_t s = isqrt128_i128(bbk);
    if (b > 0) {
        int64_t t = FLOW_CHECKED_DIV(((a + s)), (c));
        int64_t u = (((t + 1) * c) - a);
        if (u <= 0) {
            return (t + 1);
        }
        if ((((__int128)(u)) * ((__int128)(u))) <= bbk) {
            return (t + 1);
        }
        return t;
    }
    int64_t t2 = FLOW_CHECKED_DIV((((a - s) - 1)), (c));
    int64_t d = (a - ((t2 + 1) * c));
    if ((d >= 0 && (((__int128)(d)) * ((__int128)(d))) >= bbk)) {
        return (t2 + 1);
    }
    return t2;
}

void normalize_i64_i64_i64_ptr_i64_ptr_i64_ptr_i64(int64_t a0, int64_t b0, int64_t c0, int64_t* out_a, int64_t* out_b, int64_t* out_c) {
    int64_t a = a0;
    int64_t b = b0;
    int64_t c = c0;
    if (c < 0) {
        a = (0 - a);
        b = (0 - b);
        c = (0 - c);
    }
    int64_t g = igcd_i64_i64(igcd_i64_i64(a, b), c);
    if (g > 1) {
        a = FLOW_CHECKED_DIV((a), (g));
        b = FLOW_CHECKED_DIV((b), (g));
        c = FLOW_CHECKED_DIV((c), (g));
    }
    out_a[0] = a;
    out_b[0] = b;
    out_c[0] = c;
}

int64_t sum_floor_mul_surd_i64_i64_i64_i64_i64(int64_t a0, int64_t b0, int64_t c0, int64_t k, int64_t n0) {
    if (n0 <= 0) {
        return 0;
    }
    if ((b0 == 0 || k == 0)) {
        int64_t p = a0;
        int64_t q = c0;
        if (p >= 0) {
            return floor_sum_i64_i64_i64_i64(n0, q, p, p);
        }
        int64_t pp = (0 - p);
        return (0 - floor_sum_i64_i64_i64_i64(n0, q, pp, ((pp + q) - 1)));
    }
    int64_t aa = a0;
    int64_t bb = b0;
    int64_t cc = c0;
    int64_t nn = n0;
    int64_t res = 0;
    int64_t sign = 1;
    int64_t box_a[1] = { 0 };
    int64_t box_b[1] = { 0 };
    int64_t box_c[1] = { 0 };
    while (nn > 0) {
        int64_t q_int = floor_surd_i64_i64_i64_i64(aa, bb, cc, k);
        if (q_int != 0) {
            res = (res + FLOW_CHECKED_DIV(((((sign * q_int) * nn) * (nn + 1))), (2)));
            aa = (aa - (q_int * cc));
        }
        if ((aa == 0 && bb == 0)) {
            break;
        }
        int64_t m = floor_surd_i64_i64_i64_i64((aa * nn), (bb * nn), cc, k);
        if (m == 0) {
            break;
        }
        res = (res + ((sign * nn) * m));
        int64_t A = (cc * aa);
        int64_t B = (0 - (cc * bb));
        int64_t C = ((aa * aa) - ((bb * bb) * k));
        if (C < 0) {
            A = (0 - A);
            B = (0 - B);
            C = (0 - C);
        }
        normalize_i64_i64_i64_ptr_i64_ptr_i64_ptr_i64(A, B, C, box_a, box_b, box_c);
        aa = (((unsigned)(0) < 1) ? box_a[0] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)(0), 1), flow_fault_handler("array index out of bounds"), box_a[0]));
        bb = (((unsigned)(0) < 1) ? box_b[0] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)(0), 1), flow_fault_handler("array index out of bounds"), box_b[0]));
        cc = (((unsigned)(0) < 1) ? box_c[0] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)(0), 1), flow_fault_handler("array index out of bounds"), box_c[0]));
        nn = m;
        sign = (0 - sign);
    }
    return res;
}

int64_t P_func_i64_i64_i64_i64_i64_i64_i64(int64_t k, int64_t L, int64_t U, int64_t len_side, int64_t total_pairs, int64_t U2m1, int64_t Lm1) {
    if (k == 1) {
        return FLOW_CHECKED_DIV(((len_side * (len_side - 1))), (2));
    }
    int64_t r = isqrt_i64(k);
    if ((r * r) == k) {
        int64_t s = r;
        int64_t b = FLOW_CHECKED_DIV((U), (s));
        if (b < L) {
            return total_pairs;
        }
        if (b > U) {
            b = U;
        }
        int64_t cnt = ((b - L) + 1);
        int64_t sum_x = FLOW_CHECKED_DIV((((L + b) * cnt)), (2));
        int64_t partial = ((s * sum_x) - (L * cnt));
        int64_t full_cnt = (U - b);
        return (partial + (full_cnt * len_side));
    }
    int64_t b2 = isqrt_i64(FLOW_CHECKED_DIV((U2m1), (k)));
    if (b2 < L) {
        return total_pairs;
    }
    if (b2 > U) {
        b2 = U;
    }
    int64_t cnt2 = ((b2 - L) + 1);
    int64_t sum_floor = (sum_floor_mul_surd_i64_i64_i64_i64_i64(0, 1, 1, k, b2) - sum_floor_mul_surd_i64_i64_i64_i64_i64(0, 1, 1, k, Lm1));
    int64_t partial2 = (sum_floor - ((L - 1) * cnt2));
    int64_t full_cnt2 = (U - b2);
    return (partial2 + (full_cnt2 * len_side));
}

int64_t solve_i64_i64(int64_t M, int64_t N) {
    int64_t L = (M + 1);
    int64_t U = N;
    if (L > U) {
        return 0;
    }
    int64_t len_side = ((U - L) + 1);
    int64_t total_pairs = (len_side * len_side);
    int64_t k_max = FLOW_CHECKED_DIV(((U * U)), ((L * L)));
    int64_t last_odd = k_max;
    if ((k_max & 1) == 0) {
        last_odd = (k_max - 1);
    }
    int64_t U2m1 = ((U * U) - 1);
    int64_t Lm1 = (L - 1);
    int64_t ans = 0;
    int64_t n = 1;
    while (n <= last_odd) {
        ans = ((ans + P_func_i64_i64_i64_i64_i64_i64_i64((n + 1), L, U, len_side, total_pairs, U2m1, Lm1)) - P_func_i64_i64_i64_i64_i64_i64_i64(n, L, U, len_side, total_pairs, U2m1, Lm1));
        n = (n + 2);
    }
    return ans;
}

int32_t main(void) {
    int64_t ans = solve_i64_i64(2000000, 1000000000);
    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 @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) -> ()
  func.func @igcd(%arg0: i64, %arg1: i64) -> i64 {
    %175 = llvm.mlir.constant(1 : i64) : i64
    %176 = llvm.alloca %175 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %176 : i64, !llvm.ptr
    %177 = llvm.mlir.constant(1 : i64) : i64
    %178 = llvm.alloca %177 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %178 : i64, !llvm.ptr
    %179 = llvm.load %176 : !llvm.ptr -> i64
    %180 = arith.constant 0 : i32
    %182 = arith.extsi %180 : i32 to i64
    %181 = arith.cmpi slt, %179, %182 : i64
    cf.cond_br %181, ^bb42, ^bb43
    ^bb42:
      %183 = arith.constant 0 : i32
      %184 = llvm.load %176 : !llvm.ptr -> i64
      %186 = arith.extsi %183 : i32 to i64
      %185 = arith.subi %186, %184 : i64
      llvm.store %185, %176 : i64, !llvm.ptr
      cf.br ^bb44
    ^bb43:
      cf.br ^bb44
    ^bb44:
    %187 = llvm.load %178 : !llvm.ptr -> i64
    %188 = arith.constant 0 : i32
    %190 = arith.extsi %188 : i32 to i64
    %189 = arith.cmpi slt, %187, %190 : i64
    cf.cond_br %189, ^bb45, ^bb46
    ^bb45:
      %191 = arith.constant 0 : i32
      %192 = llvm.load %178 : !llvm.ptr -> i64
      %194 = arith.extsi %191 : i32 to i64
      %193 = arith.subi %194, %192 : i64
      llvm.store %193, %178 : i64, !llvm.ptr
      cf.br ^bb47
    ^bb46:
      cf.br ^bb47
    ^bb47:
    cf.br ^bb48
    ^bb48:
    %195 = llvm.load %178 : !llvm.ptr -> i64
    %196 = arith.constant 0 : i32
    %198 = arith.extsi %196 : i32 to i64
    %197 = arith.cmpi ne, %195, %198 : i64
    cf.cond_br %197, ^bb49, ^bb50
    ^bb49:
      %199 = llvm.load %176 : !llvm.ptr -> i64
      %200 = llvm.load %178 : !llvm.ptr -> i64
      %201 = arith.remsi %199, %200 : i64
      %202 = llvm.load %178 : !llvm.ptr -> i64
      llvm.store %202, %176 : i64, !llvm.ptr
      llvm.store %201, %178 : i64, !llvm.ptr
      cf.br ^bb48
    ^bb50:
    %203 = llvm.load %176 : !llvm.ptr -> i64
    func.return %203 : i64
  }
  func.func @floor_sum(%arg0: i64, %arg1: i64, %arg2: i64, %arg3: i64) -> i64 {
    %204 = arith.constant 0 : i32
    %205 = arith.extsi %204 : i32 to i64
    %206 = llvm.mlir.constant(1 : i64) : i64
    %207 = llvm.alloca %206 x i64 : (i64) -> !llvm.ptr
    llvm.store %205, %207 : i64, !llvm.ptr
    %208 = llvm.mlir.constant(1 : i64) : i64
    %209 = llvm.alloca %208 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %209 : i64, !llvm.ptr
    %210 = llvm.mlir.constant(1 : i64) : i64
    %211 = llvm.alloca %210 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %211 : i64, !llvm.ptr
    %212 = llvm.mlir.constant(1 : i64) : i64
    %213 = llvm.alloca %212 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg2, %213 : i64, !llvm.ptr
    %214 = llvm.mlir.constant(1 : i64) : i64
    %215 = llvm.alloca %214 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg3, %215 : i64, !llvm.ptr
    cf.br ^bb51
    ^bb51:
    %216 = arith.constant 1 : i32
    %217 = arith.constant 1 : i32
    %218 = arith.cmpi eq, %216, %217 : i32
    cf.cond_br %218, ^bb52, ^bb53
    ^bb52:
      %219 = llvm.load %213 : !llvm.ptr -> i64
      %220 = llvm.load %211 : !llvm.ptr -> i64
      %221 = arith.cmpi sge, %219, %220 : i64
      cf.cond_br %221, ^bb54, ^bb55
      ^bb54:
        %222 = llvm.load %207 : !llvm.ptr -> i64
        %223 = llvm.load %209 : !llvm.ptr -> i64
        %224 = arith.constant 1 : i32
        %226 = arith.extsi %224 : i32 to i64
        %225 = arith.subi %223, %226 : i64
        %227 = llvm.load %209 : !llvm.ptr -> i64
        %228 = arith.muli %225, %227 : i64
        %229 = llvm.load %213 : !llvm.ptr -> i64
        %230 = llvm.load %211 : !llvm.ptr -> i64
        %231 = arith.divsi %229, %230 : i64
        %232 = arith.muli %228, %231 : i64
        %233 = arith.constant 2 : i32
        %235 = arith.extsi %233 : i32 to i64
        %234 = arith.divsi %232, %235 : i64
        %236 = arith.addi %222, %234 : i64
        llvm.store %236, %207 : i64, !llvm.ptr
        %237 = llvm.load %213 : !llvm.ptr -> i64
        %238 = llvm.load %211 : !llvm.ptr -> i64
        %239 = arith.remsi %237, %238 : i64
        llvm.store %239, %213 : i64, !llvm.ptr
        cf.br ^bb56
      ^bb55:
        cf.br ^bb56
      ^bb56:
      %240 = llvm.load %215 : !llvm.ptr -> i64
      %241 = llvm.load %211 : !llvm.ptr -> i64
      %242 = arith.cmpi sge, %240, %241 : i64
      cf.cond_br %242, ^bb57, ^bb58
      ^bb57:
        %243 = llvm.load %207 : !llvm.ptr -> i64
        %244 = llvm.load %209 : !llvm.ptr -> i64
        %245 = llvm.load %215 : !llvm.ptr -> i64
        %246 = llvm.load %211 : !llvm.ptr -> i64
        %247 = arith.divsi %245, %246 : i64
        %248 = arith.muli %244, %247 : i64
        %249 = arith.addi %243, %248 : i64
        llvm.store %249, %207 : i64, !llvm.ptr
        %250 = llvm.load %215 : !llvm.ptr -> i64
        %251 = llvm.load %211 : !llvm.ptr -> i64
        %252 = arith.remsi %250, %251 : i64
        llvm.store %252, %215 : i64, !llvm.ptr
        cf.br ^bb59
      ^bb58:
        cf.br ^bb59
      ^bb59:
      %253 = llvm.load %213 : !llvm.ptr -> i64
      %254 = llvm.load %209 : !llvm.ptr -> i64
      %255 = arith.muli %253, %254 : i64
      %256 = llvm.load %215 : !llvm.ptr -> i64
      %257 = arith.addi %255, %256 : i64
      %258 = llvm.load %211 : !llvm.ptr -> i64
      %259 = arith.cmpi slt, %257, %258 : i64
      cf.cond_br %259, ^bb60, ^bb61
      ^bb60:
        cf.br ^bb53
      ^bb61:
        cf.br ^bb62
      ^bb62:
      %260 = llvm.load %211 : !llvm.ptr -> i64
      %261 = arith.divsi %257, %260 : i64
      llvm.store %261, %209 : i64, !llvm.ptr
      %262 = llvm.load %211 : !llvm.ptr -> i64
      %263 = arith.remsi %257, %262 : i64
      llvm.store %263, %215 : i64, !llvm.ptr
      %264 = llvm.load %213 : !llvm.ptr -> i64
      %265 = llvm.load %211 : !llvm.ptr -> i64
      llvm.store %265, %213 : i64, !llvm.ptr
      llvm.store %264, %211 : i64, !llvm.ptr
      cf.br ^bb51
    ^bb53:
    %266 = llvm.load %207 : !llvm.ptr -> i64
    func.return %266 : i64
  }
  func.func @isqrt128(%arg0: i128) -> i64 {
    %267 = arith.constant 0 : i32
    %268 = arith.extsi %267 : i32 to i128
    %270 = arith.trunci %arg0 : i128 to i64
    %271 = arith.trunci %268 : i128 to i64
    %269 = arith.cmpi sle, %270, %271 : i64
    cf.cond_br %269, ^bb63, ^bb64
    ^bb63:
      %272 = arith.constant 0 : i32
      %273 = arith.extsi %272 : i32 to i64
      func.return %273 : i64
    ^bb64:
      cf.br ^bb65
    ^bb65:
    %274 = arith.constant 2 : i32
    %275 = arith.extsi %274 : i32 to i128
    %277 = arith.trunci %arg0 : i128 to i64
    %278 = arith.trunci %275 : i128 to i64
    %276 = arith.cmpi slt, %277, %278 : i64
    cf.cond_br %276, ^bb66, ^bb67
    ^bb66:
      %279 = arith.trunci %arg0 : i128 to i64
      func.return %279 : i64
    ^bb67:
      cf.br ^bb68
    ^bb68:
    %280 = llvm.mlir.constant(1 : i64) : i64
    %281 = llvm.alloca %280 x i128 : (i64) -> !llvm.ptr
    llvm.store %arg0, %281 : i128, !llvm.ptr
    %282 = llvm.load %281 : !llvm.ptr -> i128
    %283 = arith.constant 1 : i32
    %284 = arith.extsi %283 : i32 to i128
    %286 = arith.trunci %282 : i128 to i64
    %287 = arith.trunci %284 : i128 to i64
    %285 = arith.addi %286, %287 : i64
    %288 = arith.constant 2 : i32
    %289 = arith.extsi %288 : i32 to i128
    %291 = arith.trunci %289 : i128 to i64
    %290 = arith.divsi %285, %291 : i64
    %292 = arith.extsi %290 : i64 to i128
    %293 = llvm.mlir.constant(1 : i64) : i64
    %294 = llvm.alloca %293 x i128 : (i64) -> !llvm.ptr
    llvm.store %292, %294 : i128, !llvm.ptr
    cf.br ^bb69
    ^bb69:
    %295 = llvm.load %294 : !llvm.ptr -> i128
    %296 = llvm.load %281 : !llvm.ptr -> i128
    %298 = arith.trunci %295 : i128 to i64
    %299 = arith.trunci %296 : i128 to i64
    %297 = arith.cmpi slt, %298, %299 : i64
    cf.cond_br %297, ^bb70, ^bb71
    ^bb70:
      %300 = llvm.load %294 : !llvm.ptr -> i128
      llvm.store %300, %281 : i128, !llvm.ptr
      %301 = llvm.load %281 : !llvm.ptr -> i128
      %302 = llvm.load %281 : !llvm.ptr -> i128
      %304 = arith.trunci %arg0 : i128 to i64
      %305 = arith.trunci %302 : i128 to i64
      %303 = arith.divsi %304, %305 : i64
      %307 = arith.trunci %301 : i128 to i64
      %306 = arith.addi %307, %303 : i64
      %308 = arith.constant 2 : i32
      %309 = arith.extsi %308 : i32 to i128
      %311 = arith.trunci %309 : i128 to i64
      %310 = arith.divsi %306, %311 : i64
      %312 = arith.extsi %310 : i64 to i128
      llvm.store %312, %294 : i128, !llvm.ptr
      cf.br ^bb69
    ^bb71:
    %313 = llvm.load %281 : !llvm.ptr -> i128
    %314 = arith.trunci %313 : i128 to i64
    func.return %314 : i64
  }
  func.func @floor_surd(%arg0: i64, %arg1: i64, %arg2: i64, %arg3: i64) -> i64 {
    %315 = arith.constant 0 : i32
    %317 = arith.extsi %315 : i32 to i64
    %316 = arith.cmpi eq, %arg1, %317 : i64
    %318 = scf.if %316 -> (i1) {
      %319 = arith.constant true
      scf.yield %319 : i1
    } else {
      %320 = arith.constant 0 : i32
      %322 = arith.extsi %320 : i32 to i64
      %321 = arith.cmpi eq, %arg3, %322 : i64
      scf.yield %321 : i1
    }
    cf.cond_br %318, ^bb72, ^bb73
    ^bb72:
      %323 = arith.divsi %arg0, %arg2 : i64
      func.return %323 : i64
    ^bb73:
      cf.br ^bb74
    ^bb74:
    %324 = llvm.mlir.constant(1 : i64) : i64
    %325 = llvm.alloca %324 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %325 : i64, !llvm.ptr
    %326 = llvm.load %325 : !llvm.ptr -> i64
    %327 = arith.constant 0 : i32
    %329 = arith.extsi %327 : i32 to i64
    %328 = arith.cmpi slt, %326, %329 : i64
    cf.cond_br %328, ^bb75, ^bb76
    ^bb75:
      %330 = arith.constant 0 : i32
      %331 = llvm.load %325 : !llvm.ptr -> i64
      %333 = arith.extsi %330 : i32 to i64
      %332 = arith.subi %333, %331 : i64
      llvm.store %332, %325 : i64, !llvm.ptr
      cf.br ^bb77
    ^bb76:
      cf.br ^bb77
    ^bb77:
    %334 = llvm.load %325 : !llvm.ptr -> i64
    %335 = arith.extsi %334 : i64 to i128
    %336 = llvm.load %325 : !llvm.ptr -> i64
    %337 = arith.extsi %336 : i64 to i128
    %339 = arith.trunci %335 : i128 to i64
    %340 = arith.trunci %337 : i128 to i64
    %338 = arith.muli %339, %340 : i64
    %341 = arith.extsi %arg3 : i64 to i128
    %343 = arith.trunci %341 : i128 to i64
    %342 = arith.muli %338, %343 : i64
    %344 = arith.extsi %342 : i64 to i128
    %345 = func.call @isqrt128(%344) : (i128) -> i64
    %346 = arith.constant 0 : i32
    %348 = arith.extsi %346 : i32 to i64
    %347 = arith.cmpi sgt, %arg1, %348 : i64
    cf.cond_br %347, ^bb78, ^bb79
    ^bb78:
      %349 = arith.addi %arg0, %345 : i64
      %350 = arith.divsi %349, %arg2 : i64
      %351 = arith.constant 1 : i32
      %353 = arith.extsi %351 : i32 to i64
      %352 = arith.addi %350, %353 : i64
      %354 = arith.muli %352, %arg2 : i64
      %355 = arith.subi %354, %arg0 : i64
      %356 = arith.constant 0 : i32
      %358 = arith.extsi %356 : i32 to i64
      %357 = arith.cmpi sle, %355, %358 : i64
      cf.cond_br %357, ^bb81, ^bb82
      ^bb81:
        %359 = arith.constant 1 : i32
        %361 = arith.extsi %359 : i32 to i64
        %360 = arith.addi %350, %361 : i64
        func.return %360 : i64
      ^bb82:
        cf.br ^bb83
      ^bb83:
      %362 = arith.extsi %355 : i64 to i128
      %363 = arith.extsi %355 : i64 to i128
      %365 = arith.trunci %362 : i128 to i64
      %366 = arith.trunci %363 : i128 to i64
      %364 = arith.muli %365, %366 : i64
      %368 = arith.trunci %344 : i128 to i64
      %367 = arith.cmpi sle, %364, %368 : i64
      cf.cond_br %367, ^bb84, ^bb85
      ^bb84:
        %369 = arith.constant 1 : i32
        %371 = arith.extsi %369 : i32 to i64
        %370 = arith.addi %350, %371 : i64
        func.return %370 : i64
      ^bb85:
        cf.br ^bb86
      ^bb86:
      func.return %350 : i64
    ^bb79:
      cf.br ^bb80
    ^bb80:
    %372 = arith.subi %arg0, %345 : i64
    %373 = arith.constant 1 : i32
    %375 = arith.extsi %373 : i32 to i64
    %374 = arith.subi %372, %375 : i64
    %376 = arith.divsi %374, %arg2 : i64
    %377 = arith.constant 1 : i32
    %379 = arith.extsi %377 : i32 to i64
    %378 = arith.addi %376, %379 : i64
    %380 = arith.muli %378, %arg2 : i64
    %381 = arith.subi %arg0, %380 : i64
    %382 = arith.constant 0 : i32
    %384 = arith.extsi %382 : i32 to i64
    %383 = arith.cmpi sge, %381, %384 : i64
    %385 = scf.if %383 -> (i1) {
      %386 = arith.extsi %381 : i64 to i128
      %387 = arith.extsi %381 : i64 to i128
      %389 = arith.trunci %386 : i128 to i64
      %390 = arith.trunci %387 : i128 to i64
      %388 = arith.muli %389, %390 : i64
      %392 = arith.trunci %344 : i128 to i64
      %391 = arith.cmpi sge, %388, %392 : i64
      scf.yield %391 : i1
    } else {
      %393 = arith.constant false
      scf.yield %393 : i1
    }
    cf.cond_br %385, ^bb87, ^bb88
    ^bb87:
      %394 = arith.constant 1 : i32
      %396 = arith.extsi %394 : i32 to i64
      %395 = arith.addi %376, %396 : i64
      func.return %395 : i64
    ^bb88:
      cf.br ^bb89
    ^bb89:
    func.return %376 : i64
  }
  func.func @normalize(%arg0: i64, %arg1: i64, %arg2: i64, %arg3: !llvm.ptr, %arg4: !llvm.ptr, %arg5: !llvm.ptr) -> () {
    %397 = llvm.mlir.constant(1 : i64) : i64
    %398 = llvm.alloca %397 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %398 : i64, !llvm.ptr
    %399 = llvm.mlir.constant(1 : i64) : i64
    %400 = llvm.alloca %399 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %400 : i64, !llvm.ptr
    %401 = llvm.mlir.constant(1 : i64) : i64
    %402 = llvm.alloca %401 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg2, %402 : i64, !llvm.ptr
    %403 = llvm.load %402 : !llvm.ptr -> i64
    %404 = arith.constant 0 : i32
    %406 = arith.extsi %404 : i32 to i64
    %405 = arith.cmpi slt, %403, %406 : i64
    cf.cond_br %405, ^bb90, ^bb91
    ^bb90:
      %407 = arith.constant 0 : i32
      %408 = llvm.load %398 : !llvm.ptr -> i64
      %410 = arith.extsi %407 : i32 to i64
      %409 = arith.subi %410, %408 : i64
      llvm.store %409, %398 : i64, !llvm.ptr
      %411 = arith.constant 0 : i32
      %412 = llvm.load %400 : !llvm.ptr -> i64
      %414 = arith.extsi %411 : i32 to i64
      %413 = arith.subi %414, %412 : i64
      llvm.store %413, %400 : i64, !llvm.ptr
      %415 = arith.constant 0 : i32
      %416 = llvm.load %402 : !llvm.ptr -> i64
      %418 = arith.extsi %415 : i32 to i64
      %417 = arith.subi %418, %416 : i64
      llvm.store %417, %402 : i64, !llvm.ptr
      cf.br ^bb92
    ^bb91:
      cf.br ^bb92
    ^bb92:
    %421 = llvm.load %398 : !llvm.ptr -> i64
    %422 = llvm.load %400 : !llvm.ptr -> i64
    %420 = func.call @igcd(%421, %422) : (i64, i64) -> i64
    %423 = llvm.load %402 : !llvm.ptr -> i64
    %419 = func.call @igcd(%420, %423) : (i64, i64) -> i64
    %424 = arith.constant 1 : i32
    %426 = arith.extsi %424 : i32 to i64
    %425 = arith.cmpi sgt, %419, %426 : i64
    cf.cond_br %425, ^bb93, ^bb94
    ^bb93:
      %427 = llvm.load %398 : !llvm.ptr -> i64
      %428 = arith.divsi %427, %419 : i64
      llvm.store %428, %398 : i64, !llvm.ptr
      %429 = llvm.load %400 : !llvm.ptr -> i64
      %430 = arith.divsi %429, %419 : i64
      llvm.store %430, %400 : i64, !llvm.ptr
      %431 = llvm.load %402 : !llvm.ptr -> i64
      %432 = arith.divsi %431, %419 : i64
      llvm.store %432, %402 : i64, !llvm.ptr
      cf.br ^bb95
    ^bb94:
      cf.br ^bb95
    ^bb95:
    %433 = llvm.load %398 : !llvm.ptr -> i64
    %434 = arith.constant 0 : i32
    %435 = arith.extsi %434 : i32 to i64
    %436 = llvm.getelementptr %arg3[%435] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %433, %436 : i64, !llvm.ptr
    %437 = llvm.load %400 : !llvm.ptr -> i64
    %438 = arith.constant 0 : i32
    %439 = arith.extsi %438 : i32 to i64
    %440 = llvm.getelementptr %arg4[%439] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %437, %440 : i64, !llvm.ptr
    %441 = llvm.load %402 : !llvm.ptr -> i64
    %442 = arith.constant 0 : i32
    %443 = arith.extsi %442 : i32 to i64
    %444 = llvm.getelementptr %arg5[%443] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %441, %444 : i64, !llvm.ptr
    func.return
  }
  func.func @sum_floor_mul_surd(%arg0: i64, %arg1: i64, %arg2: i64, %arg3: i64, %arg4: i64) -> i64 {
    %445 = arith.constant 0 : i32
    %447 = arith.extsi %445 : i32 to i64
    %446 = arith.cmpi sle, %arg4, %447 : i64
    cf.cond_br %446, ^bb96, ^bb97
    ^bb96:
      %448 = arith.constant 0 : i32
      %449 = arith.extsi %448 : i32 to i64
      func.return %449 : i64
    ^bb97:
      cf.br ^bb98
    ^bb98:
    %450 = arith.constant 0 : i32
    %452 = arith.extsi %450 : i32 to i64
    %451 = arith.cmpi eq, %arg1, %452 : i64
    %453 = scf.if %451 -> (i1) {
      %454 = arith.constant true
      scf.yield %454 : i1
    } else {
      %455 = arith.constant 0 : i32
      %457 = arith.extsi %455 : i32 to i64
      %456 = arith.cmpi eq, %arg3, %457 : i64
      scf.yield %456 : i1
    }
    cf.cond_br %453, ^bb99, ^bb100
    ^bb99:
      %458 = arith.constant 0 : i32
      %460 = arith.extsi %458 : i32 to i64
      %459 = arith.cmpi sge, %arg0, %460 : i64
      cf.cond_br %459, ^bb102, ^bb103
      ^bb102:
        %461 = func.call @floor_sum(%arg4, %arg2, %arg0, %arg0) : (i64, i64, i64, i64) -> i64
        func.return %461 : i64
      ^bb103:
        cf.br ^bb104
      ^bb104:
      %462 = arith.constant 0 : i32
      %464 = arith.extsi %462 : i32 to i64
      %463 = arith.subi %464, %arg0 : i64
      %465 = arith.constant 0 : i32
      %467 = arith.addi %463, %arg2 : i64
      %468 = arith.constant 1 : i32
      %470 = arith.extsi %468 : i32 to i64
      %469 = arith.subi %467, %470 : i64
      %466 = func.call @floor_sum(%arg4, %arg2, %463, %469) : (i64, i64, i64, i64) -> i64
      %472 = arith.extsi %465 : i32 to i64
      %471 = arith.subi %472, %466 : i64
      func.return %471 : i64
    ^bb100:
      cf.br ^bb101
    ^bb101:
    %473 = llvm.mlir.constant(1 : i64) : i64
    %474 = llvm.alloca %473 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %474 : i64, !llvm.ptr
    %475 = llvm.mlir.constant(1 : i64) : i64
    %476 = llvm.alloca %475 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %476 : i64, !llvm.ptr
    %477 = llvm.mlir.constant(1 : i64) : i64
    %478 = llvm.alloca %477 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg2, %478 : i64, !llvm.ptr
    %479 = llvm.mlir.constant(1 : i64) : i64
    %480 = llvm.alloca %479 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg4, %480 : i64, !llvm.ptr
    %481 = arith.constant 0 : i32
    %482 = arith.extsi %481 : i32 to i64
    %483 = llvm.mlir.constant(1 : i64) : i64
    %484 = llvm.alloca %483 x i64 : (i64) -> !llvm.ptr
    llvm.store %482, %484 : i64, !llvm.ptr
    %485 = arith.constant 1 : i32
    %486 = arith.extsi %485 : i32 to i64
    %487 = llvm.mlir.constant(1 : i64) : i64
    %488 = llvm.alloca %487 x i64 : (i64) -> !llvm.ptr
    llvm.store %486, %488 : i64, !llvm.ptr
    %490 = arith.constant 0 : i32
    %491 = llvm.mlir.constant(1 : i64) : i64
    %492 = llvm.alloca %491 x !llvm.array<1 x i64> : (i64) -> !llvm.ptr
    %493 = llvm.mlir.zero : !llvm.array<1 x i64>
    llvm.store %493, %492 : !llvm.array<1 x i64>, !llvm.ptr
    %494 = arith.extsi %490 : i32 to i64
    %495 = llvm.mlir.constant(0 : i64) : i64
    %496 = llvm.getelementptr %492[0, %495] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<1 x i64>
    llvm.store %494, %496 : i64, !llvm.ptr
    %498 = arith.constant 0 : i32
    %499 = llvm.mlir.constant(1 : i64) : i64
    %500 = llvm.alloca %499 x !llvm.array<1 x i64> : (i64) -> !llvm.ptr
    %501 = llvm.mlir.zero : !llvm.array<1 x i64>
    llvm.store %501, %500 : !llvm.array<1 x i64>, !llvm.ptr
    %502 = arith.extsi %498 : i32 to i64
    %503 = llvm.mlir.constant(0 : i64) : i64
    %504 = llvm.getelementptr %500[0, %503] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<1 x i64>
    llvm.store %502, %504 : i64, !llvm.ptr
    %506 = arith.constant 0 : i32
    %507 = llvm.mlir.constant(1 : i64) : i64
    %508 = llvm.alloca %507 x !llvm.array<1 x i64> : (i64) -> !llvm.ptr
    %509 = llvm.mlir.zero : !llvm.array<1 x i64>
    llvm.store %509, %508 : !llvm.array<1 x i64>, !llvm.ptr
    %510 = arith.extsi %506 : i32 to i64
    %511 = llvm.mlir.constant(0 : i64) : i64
    %512 = llvm.getelementptr %508[0, %511] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<1 x i64>
    llvm.store %510, %512 : i64, !llvm.ptr
    cf.br ^bb105
    ^bb105:
    %513 = llvm.load %480 : !llvm.ptr -> i64
    %514 = arith.constant 0 : i32
    %516 = arith.extsi %514 : i32 to i64
    %515 = arith.cmpi sgt, %513, %516 : i64
    cf.cond_br %515, ^bb106, ^bb107
    ^bb106:
      %518 = llvm.load %474 : !llvm.ptr -> i64
      %519 = llvm.load %476 : !llvm.ptr -> i64
      %520 = llvm.load %478 : !llvm.ptr -> i64
      %517 = func.call @floor_surd(%518, %519, %520, %arg3) : (i64, i64, i64, i64) -> i64
      %521 = arith.constant 0 : i32
      %523 = arith.extsi %521 : i32 to i64
      %522 = arith.cmpi ne, %517, %523 : i64
      cf.cond_br %522, ^bb108, ^bb109
      ^bb108:
        %524 = llvm.load %484 : !llvm.ptr -> i64
        %525 = llvm.load %488 : !llvm.ptr -> i64
        %526 = arith.muli %525, %517 : i64
        %527 = llvm.load %480 : !llvm.ptr -> i64
        %528 = arith.muli %526, %527 : i64
        %529 = llvm.load %480 : !llvm.ptr -> i64
        %530 = arith.constant 1 : i32
        %532 = arith.extsi %530 : i32 to i64
        %531 = arith.addi %529, %532 : i64
        %533 = arith.muli %528, %531 : i64
        %534 = arith.constant 2 : i32
        %536 = arith.extsi %534 : i32 to i64
        %535 = arith.divsi %533, %536 : i64
        %537 = arith.addi %524, %535 : i64
        llvm.store %537, %484 : i64, !llvm.ptr
        %538 = llvm.load %474 : !llvm.ptr -> i64
        %539 = llvm.load %478 : !llvm.ptr -> i64
        %540 = arith.muli %517, %539 : i64
        %541 = arith.subi %538, %540 : i64
        llvm.store %541, %474 : i64, !llvm.ptr
        cf.br ^bb110
      ^bb109:
        cf.br ^bb110
      ^bb110:
      %542 = llvm.load %474 : !llvm.ptr -> i64
      %543 = arith.constant 0 : i32
      %545 = arith.extsi %543 : i32 to i64
      %544 = arith.cmpi eq, %542, %545 : i64
      %546 = scf.if %544 -> (i1) {
        %547 = llvm.load %476 : !llvm.ptr -> i64
        %548 = arith.constant 0 : i32
        %550 = arith.extsi %548 : i32 to i64
        %549 = arith.cmpi eq, %547, %550 : i64
        scf.yield %549 : i1
      } else {
        %551 = arith.constant false
        scf.yield %551 : i1
      }
      cf.cond_br %546, ^bb111, ^bb112
      ^bb111:
        cf.br ^bb107
      ^bb112:
        cf.br ^bb113
      ^bb113:
      %553 = llvm.load %474 : !llvm.ptr -> i64
      %554 = llvm.load %480 : !llvm.ptr -> i64
      %555 = arith.muli %553, %554 : i64
      %556 = llvm.load %476 : !llvm.ptr -> i64
      %557 = llvm.load %480 : !llvm.ptr -> i64
      %558 = arith.muli %556, %557 : i64
      %559 = llvm.load %478 : !llvm.ptr -> i64
      %552 = func.call @floor_surd(%555, %558, %559, %arg3) : (i64, i64, i64, i64) -> i64
      %560 = arith.constant 0 : i32
      %562 = arith.extsi %560 : i32 to i64
      %561 = arith.cmpi eq, %552, %562 : i64
      cf.cond_br %561, ^bb114, ^bb115
      ^bb114:
        cf.br ^bb107
      ^bb115:
        cf.br ^bb116
      ^bb116:
      %563 = llvm.load %484 : !llvm.ptr -> i64
      %564 = llvm.load %488 : !llvm.ptr -> i64
      %565 = llvm.load %480 : !llvm.ptr -> i64
      %566 = arith.muli %564, %565 : i64
      %567 = arith.muli %566, %552 : i64
      %568 = arith.addi %563, %567 : i64
      llvm.store %568, %484 : i64, !llvm.ptr
      %569 = llvm.load %478 : !llvm.ptr -> i64
      %570 = llvm.load %474 : !llvm.ptr -> i64
      %571 = arith.muli %569, %570 : i64
      %572 = llvm.mlir.constant(1 : i64) : i64
      %573 = llvm.alloca %572 x i64 : (i64) -> !llvm.ptr
      llvm.store %571, %573 : i64, !llvm.ptr
      %574 = arith.constant 0 : i32
      %575 = llvm.load %478 : !llvm.ptr -> i64
      %576 = llvm.load %476 : !llvm.ptr -> i64
      %577 = arith.muli %575, %576 : i64
      %579 = arith.extsi %574 : i32 to i64
      %578 = arith.subi %579, %577 : i64
      %580 = llvm.mlir.constant(1 : i64) : i64
      %581 = llvm.alloca %580 x i64 : (i64) -> !llvm.ptr
      llvm.store %578, %581 : i64, !llvm.ptr
      %582 = llvm.load %474 : !llvm.ptr -> i64
      %583 = llvm.load %474 : !llvm.ptr -> i64
      %584 = arith.muli %582, %583 : i64
      %585 = llvm.load %476 : !llvm.ptr -> i64
      %586 = llvm.load %476 : !llvm.ptr -> i64
      %587 = arith.muli %585, %586 : i64
      %588 = arith.muli %587, %arg3 : i64
      %589 = arith.subi %584, %588 : i64
      %590 = llvm.mlir.constant(1 : i64) : i64
      %591 = llvm.alloca %590 x i64 : (i64) -> !llvm.ptr
      llvm.store %589, %591 : i64, !llvm.ptr
      %592 = llvm.load %591 : !llvm.ptr -> i64
      %593 = arith.constant 0 : i32
      %595 = arith.extsi %593 : i32 to i64
      %594 = arith.cmpi slt, %592, %595 : i64
      cf.cond_br %594, ^bb117, ^bb118
      ^bb117:
        %596 = arith.constant 0 : i32
        %597 = llvm.load %573 : !llvm.ptr -> i64
        %599 = arith.extsi %596 : i32 to i64
        %598 = arith.subi %599, %597 : i64
        llvm.store %598, %573 : i64, !llvm.ptr
        %600 = arith.constant 0 : i32
        %601 = llvm.load %581 : !llvm.ptr -> i64
        %603 = arith.extsi %600 : i32 to i64
        %602 = arith.subi %603, %601 : i64
        llvm.store %602, %581 : i64, !llvm.ptr
        %604 = arith.constant 0 : i32
        %605 = llvm.load %591 : !llvm.ptr -> i64
        %607 = arith.extsi %604 : i32 to i64
        %606 = arith.subi %607, %605 : i64
        llvm.store %606, %591 : i64, !llvm.ptr
        cf.br ^bb119
      ^bb118:
        cf.br ^bb119
      ^bb119:
      %609 = llvm.load %573 : !llvm.ptr -> i64
      %610 = llvm.load %581 : !llvm.ptr -> i64
      %611 = llvm.load %591 : !llvm.ptr -> i64
      func.call @normalize(%609, %610, %611, %492, %500, %508) : (i64, i64, i64, !llvm.ptr, !llvm.ptr, !llvm.ptr) -> ()
      %613 = arith.constant 0 : i32
      %614 = arith.extsi %613 : i32 to i64
      %615 = llvm.getelementptr %492[0, %614] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<1 x i64>
      %612 = llvm.load %615 : !llvm.ptr -> i64
      llvm.store %612, %474 : i64, !llvm.ptr
      %617 = arith.constant 0 : i32
      %618 = arith.extsi %617 : i32 to i64
      %619 = llvm.getelementptr %500[0, %618] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<1 x i64>
      %616 = llvm.load %619 : !llvm.ptr -> i64
      llvm.store %616, %476 : i64, !llvm.ptr
      %621 = arith.constant 0 : i32
      %622 = arith.extsi %621 : i32 to i64
      %623 = llvm.getelementptr %508[0, %622] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<1 x i64>
      %620 = llvm.load %623 : !llvm.ptr -> i64
      llvm.store %620, %478 : i64, !llvm.ptr
      llvm.store %552, %480 : i64, !llvm.ptr
      %624 = arith.constant 0 : i32
      %625 = llvm.load %488 : !llvm.ptr -> i64
      %627 = arith.extsi %624 : i32 to i64
      %626 = arith.subi %627, %625 : i64
      llvm.store %626, %488 : i64, !llvm.ptr
      cf.br ^bb105
    ^bb107:
    %628 = llvm.load %484 : !llvm.ptr -> i64
    func.return %628 : i64
  }
  func.func @P_func(%arg0: i64, %arg1: i64, %arg2: i64, %arg3: i64, %arg4: i64, %arg5: i64, %arg6: i64) -> i64 {
    %629 = arith.constant 1 : i32
    %631 = arith.extsi %629 : i32 to i64
    %630 = arith.cmpi eq, %arg0, %631 : i64
    cf.cond_br %630, ^bb120, ^bb121
    ^bb120:
      %632 = arith.constant 1 : i32
      %634 = arith.extsi %632 : i32 to i64
      %633 = arith.subi %arg3, %634 : i64
      %635 = arith.muli %arg3, %633 : i64
      %636 = arith.constant 2 : i32
      %638 = arith.extsi %636 : i32 to i64
      %637 = arith.divsi %635, %638 : i64
      func.return %637 : i64
    ^bb121:
      cf.br ^bb122
    ^bb122:
    %639 = func.call @isqrt(%arg0) : (i64) -> i64
    %640 = arith.muli %639, %639 : i64
    %641 = arith.cmpi eq, %640, %arg0 : i64
    cf.cond_br %641, ^bb123, ^bb124
    ^bb123:
      %642 = arith.divsi %arg2, %639 : i64
      %643 = llvm.mlir.constant(1 : i64) : i64
      %644 = llvm.alloca %643 x i64 : (i64) -> !llvm.ptr
      llvm.store %642, %644 : i64, !llvm.ptr
      %645 = llvm.load %644 : !llvm.ptr -> i64
      %646 = arith.cmpi slt, %645, %arg1 : i64
      cf.cond_br %646, ^bb126, ^bb127
      ^bb126:
        func.return %arg4 : i64
      ^bb127:
        cf.br ^bb128
      ^bb128:
      %647 = llvm.load %644 : !llvm.ptr -> i64
      %648 = arith.cmpi sgt, %647, %arg2 : i64
      cf.cond_br %648, ^bb129, ^bb130
      ^bb129:
        llvm.store %arg2, %644 : i64, !llvm.ptr
        cf.br ^bb131
      ^bb130:
        cf.br ^bb131
      ^bb131:
      %649 = llvm.load %644 : !llvm.ptr -> i64
      %650 = arith.subi %649, %arg1 : i64
      %651 = arith.constant 1 : i32
      %653 = arith.extsi %651 : i32 to i64
      %652 = arith.addi %650, %653 : i64
      %654 = llvm.load %644 : !llvm.ptr -> i64
      %655 = arith.addi %arg1, %654 : i64
      %656 = arith.muli %655, %652 : i64
      %657 = arith.constant 2 : i32
      %659 = arith.extsi %657 : i32 to i64
      %658 = arith.divsi %656, %659 : i64
      %660 = arith.muli %639, %658 : i64
      %661 = arith.muli %arg1, %652 : i64
      %662 = arith.subi %660, %661 : i64
      %663 = llvm.load %644 : !llvm.ptr -> i64
      %664 = arith.subi %arg2, %663 : i64
      %665 = arith.muli %664, %arg3 : i64
      %666 = arith.addi %662, %665 : i64
      func.return %666 : i64
    ^bb124:
      cf.br ^bb125
    ^bb125:
    %668 = arith.divsi %arg5, %arg0 : i64
    %667 = func.call @isqrt(%668) : (i64) -> i64
    %669 = llvm.mlir.constant(1 : i64) : i64
    %670 = llvm.alloca %669 x i64 : (i64) -> !llvm.ptr
    llvm.store %667, %670 : i64, !llvm.ptr
    %671 = llvm.load %670 : !llvm.ptr -> i64
    %672 = arith.cmpi slt, %671, %arg1 : i64
    cf.cond_br %672, ^bb132, ^bb133
    ^bb132:
      func.return %arg4 : i64
    ^bb133:
      cf.br ^bb134
    ^bb134:
    %673 = llvm.load %670 : !llvm.ptr -> i64
    %674 = arith.cmpi sgt, %673, %arg2 : i64
    cf.cond_br %674, ^bb135, ^bb136
    ^bb135:
      llvm.store %arg2, %670 : i64, !llvm.ptr
      cf.br ^bb137
    ^bb136:
      cf.br ^bb137
    ^bb137:
    %675 = llvm.load %670 : !llvm.ptr -> i64
    %676 = arith.subi %675, %arg1 : i64
    %677 = arith.constant 1 : i32
    %679 = arith.extsi %677 : i32 to i64
    %678 = arith.addi %676, %679 : i64
    %681 = arith.constant 0 : i32
    %682 = arith.constant 1 : i32
    %683 = arith.constant 1 : i32
    %684 = llvm.load %670 : !llvm.ptr -> i64
    %685 = arith.extsi %681 : i32 to i64
    %686 = arith.extsi %682 : i32 to i64
    %687 = arith.extsi %683 : i32 to i64
    %680 = func.call @sum_floor_mul_surd(%685, %686, %687, %arg0, %684) : (i64, i64, i64, i64, i64) -> i64
    %689 = arith.constant 0 : i32
    %690 = arith.constant 1 : i32
    %691 = arith.constant 1 : i32
    %692 = arith.extsi %689 : i32 to i64
    %693 = arith.extsi %690 : i32 to i64
    %694 = arith.extsi %691 : i32 to i64
    %688 = func.call @sum_floor_mul_surd(%692, %693, %694, %arg0, %arg6) : (i64, i64, i64, i64, i64) -> i64
    %695 = arith.subi %680, %688 : i64
    %696 = arith.constant 1 : i32
    %698 = arith.extsi %696 : i32 to i64
    %697 = arith.subi %arg1, %698 : i64
    %699 = arith.muli %697, %678 : i64
    %700 = arith.subi %695, %699 : i64
    %701 = llvm.load %670 : !llvm.ptr -> i64
    %702 = arith.subi %arg2, %701 : i64
    %703 = arith.muli %702, %arg3 : i64
    %704 = arith.addi %700, %703 : i64
    func.return %704 : i64
  }
  func.func @solve(%arg0: i64, %arg1: i64) -> i64 {
    %705 = arith.constant 1 : i32
    %707 = arith.extsi %705 : i32 to i64
    %706 = arith.addi %arg0, %707 : i64
    %708 = arith.cmpi sgt, %706, %arg1 : i64
    cf.cond_br %708, ^bb138, ^bb139
    ^bb138:
      %709 = arith.constant 0 : i32
      %710 = arith.extsi %709 : i32 to i64
      func.return %710 : i64
    ^bb139:
      cf.br ^bb140
    ^bb140:
    %711 = arith.subi %arg1, %706 : i64
    %712 = arith.constant 1 : i32
    %714 = arith.extsi %712 : i32 to i64
    %713 = arith.addi %711, %714 : i64
    %715 = arith.muli %713, %713 : i64
    %716 = arith.muli %arg1, %arg1 : i64
    %717 = arith.muli %706, %706 : i64
    %718 = arith.divsi %716, %717 : i64
    %719 = llvm.mlir.constant(1 : i64) : i64
    %720 = llvm.alloca %719 x i64 : (i64) -> !llvm.ptr
    llvm.store %718, %720 : i64, !llvm.ptr
    %721 = arith.constant 1 : i32
    %723 = arith.extsi %721 : i32 to i64
    %722 = arith.andi %718, %723 : i64
    %724 = arith.constant 0 : i32
    %726 = arith.extsi %724 : i32 to i64
    %725 = arith.cmpi eq, %722, %726 : i64
    cf.cond_br %725, ^bb141, ^bb142
    ^bb141:
      %727 = arith.constant 1 : i32
      %729 = arith.extsi %727 : i32 to i64
      %728 = arith.subi %718, %729 : i64
      llvm.store %728, %720 : i64, !llvm.ptr
      cf.br ^bb143
    ^bb142:
      cf.br ^bb143
    ^bb143:
    %730 = arith.muli %arg1, %arg1 : i64
    %731 = arith.constant 1 : i32
    %733 = arith.extsi %731 : i32 to i64
    %732 = arith.subi %730, %733 : i64
    %734 = arith.constant 1 : i32
    %736 = arith.extsi %734 : i32 to i64
    %735 = arith.subi %706, %736 : i64
    %737 = arith.constant 0 : i32
    %738 = arith.extsi %737 : i32 to i64
    %739 = llvm.mlir.constant(1 : i64) : i64
    %740 = llvm.alloca %739 x i64 : (i64) -> !llvm.ptr
    llvm.store %738, %740 : i64, !llvm.ptr
    %741 = arith.constant 1 : i32
    %742 = arith.extsi %741 : i32 to i64
    %743 = llvm.mlir.constant(1 : i64) : i64
    %744 = llvm.alloca %743 x i64 : (i64) -> !llvm.ptr
    llvm.store %742, %744 : i64, !llvm.ptr
    cf.br ^bb144
    ^bb144:
    %745 = llvm.load %744 : !llvm.ptr -> i64
    %746 = llvm.load %720 : !llvm.ptr -> i64
    %747 = arith.cmpi sle, %745, %746 : i64
    cf.cond_br %747, ^bb145, ^bb146
    ^bb145:
      %748 = llvm.load %740 : !llvm.ptr -> i64
      %750 = llvm.load %744 : !llvm.ptr -> i64
      %751 = arith.constant 1 : i32
      %753 = arith.extsi %751 : i32 to i64
      %752 = arith.addi %750, %753 : i64
      %749 = func.call @P_func(%752, %706, %arg1, %713, %715, %732, %735) : (i64, i64, i64, i64, i64, i64, i64) -> i64
      %754 = arith.addi %748, %749 : i64
      %756 = llvm.load %744 : !llvm.ptr -> i64
      %755 = func.call @P_func(%756, %706, %arg1, %713, %715, %732, %735) : (i64, i64, i64, i64, i64, i64, i64) -> i64
      %757 = arith.subi %754, %755 : i64
      llvm.store %757, %740 : i64, !llvm.ptr
      %758 = llvm.load %744 : !llvm.ptr -> i64
      %759 = arith.constant 2 : i32
      %761 = arith.extsi %759 : i32 to i64
      %760 = arith.addi %758, %761 : i64
      llvm.store %760, %744 : i64, !llvm.ptr
      cf.br ^bb144
    ^bb146:
    %762 = llvm.load %740 : !llvm.ptr -> i64
    func.return %762 : i64
  }
  func.func @main() -> i32 {
    %764 = arith.constant 2000000 : i32
    %765 = arith.constant 1000000000 : i32
    %766 = arith.extsi %764 : i32 to i64
    %767 = arith.extsi %765 : i32 to i64
    %763 = func.call @solve(%766, %767) : (i64, i64) -> i64
    %768 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %769 = llvm.call @printf(%768, %763) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    %770 = arith.constant 0 : i32
    func.return %770 : i32
  }
}