Problem 264

Sum perimeters of lattice triangles with circumcenter O and orthocenter (5,0).

Answer2816417.1055
Output2816417.1055
StatusPASS
Native helperno
Runtime220 ms
Peak memory1120 KB
Time complexityO(n^3) (estimated)
Space complexityO(n) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^3)O(n^2)
Space complexityO(n)O(n^2)
ApproachFlow solutionCombinatorial or DP counting
VerdictSuboptimal

Flow source

# Project Euler 264
# Sum perimeters of lattice triangles with circumcenter O and orthocenter (5,0).

import euler.nt { isqrt }

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

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

function mod_inverse(a0: i64, m: i64) -> i64 {
    let mut a: i64 = a0 % m
    if a < 0 { a = a + m }
    let mut b: i64 = m
    let mut x0: i64 = 1
    let mut x1: i64 = 0
    while b != 0 {
        let q: i64 = a / b
        let t: i64 = a % b
        a = b
        b = t
        let tx: i64 = x0 - q * x1
        x0 = x1
        x1 = tx
    }
    if x0 < 0 { x0 = x0 + m }
    return x0
}

function hypot_f(ax: i64, ay: i64, bx: i64, by: i64) -> f64 {
    let dx: f64 = (ax - bx) as f64
    let dy: f64 = (ay - by) as f64
    return sqrt(dx * dx + dy * dy)
}

function tri_key(ax: i64, ay: i64, bx: i64, by: i64, cx: i64, cy: i64) -> i64 {
    # pack sorted coords into hash (simple dedup key)
    let mut a: i64 = ax * 1000003 + ay
    let mut b: i64 = bx * 1000003 + by
    let mut c: i64 = cx * 1000003 + cy
    if a > b { let t: i64 = a; a = b; b = t }
    if b > c { let t2: i64 = b; b = c; c = t2 }
    if a > b { let t3: i64 = a; a = b; b = t3 }
    return a * 1000000007 + b * 1000003 + c
}

function main() -> i32 {
    let limit_p: i64 = 100000
    let HX: i64 = 5
    let HY: i64 = 0
    let d_max: f64 = (limit_p as f64) / 2.0
    let m_limit: i64 = (40.0 * d_max + 100.0) as i64
    let pq_limit: i64 = isqrt(m_limit) + 1
    let r_max: f64 = (limit_p as f64) / 4.0
    let r2_max: f64 = r_max * r_max

    let max_tri: i64 = 500000
    let seen: ptr<i64> = calloc(max_tri, 8)
    let seen_cnt: ptr<i64> = calloc(1, 8)
    let mut total: f64 = 0.0

    # d=0 special case: H=(5,0), b=-c on circle radius 5
    let n0: i64 = 25
    let mut x: i64 = -5
    while x <= 5 {
        let y2: i64 = n0 - x * x
        if y2 >= 0 {
            let y: i64 = isqrt(y2)
            if y * y == y2 {
                let mut yv: i64 = -y
                while yv <= y {
                    if yv != 0 {
                        let bx: i64 = x
                        let by: i64 = yv
                        let cx: i64 = -x
                        let cy: i64 = -yv
                        if !(bx == cx && by == cy) {
                            let per: f64 = hypot_f(HX, HY, bx, by) + hypot_f(bx, by, cx, cy) + hypot_f(cx, cy, HX, HY)
                            if per <= (limit_p as f64) + 0.000000001 {
                                let key: i64 = tri_key(HX, HY, bx, by, cx, cy)
                                let mut found: bool = false
                                let sc: i64 = seen_cnt[0]
                                let mut si: i64 = 0
                                while si < sc {
                                    if seen[si] == key { found = true; break }
                                    si = si + 1
                                }
                                if !found {
                                    seen[sc] = key
                                    seen_cnt[0] = sc + 1
                                    total = total + per
                                }
                            }
                        }
                    }
                    if yv == y { break }
                    if yv == -y { yv = y } else { yv = yv + 1 }
                }
            }
        }
        x = x + 1
    }

    let mut p: i64 = 0
    while p <= pq_limit {
        let p2: i64 = p * p
        if p2 > m_limit { break }
        let q_max: i64 = isqrt(m_limit - p2)
        let mut q: i64 = -q_max
        while q <= q_max {
            if p == 0 {
                if q != 1 { q = q + 1; continue }
            }
            if p == 0 && q == 0 { q = q + 1; continue }
            if gcd_abs(p, q) != 1 { q = q + 1; continue }
            let m: i64 = p2 + q * q
            if m == 0 || m > m_limit { q = q + 1; continue }

            let a40: i64 = (40 * p) % m
            let b100: i64 = 100 % m
            let d0: i64 = gcd_abs(a40, m)
            if b100 % d0 != 0 { q = q + 1; continue }
            let m1: i64 = m / d0
            let a1: i64 = a40 / d0
            let b1: i64 = b100 / d0
            let mut g0: i64 = 0
            if m1 > 1 {
                let inv: i64 = mod_inverse(a1 % m1, m1)
                g0 = (b1 * inv) % m1
            }

            let g_abs_max: i64 = (d_max / sqrt(m as f64)) as i64 + 2
            if g_abs_max <= 0 { q = q + 1; continue }

            let mut g_abs_min: i64 = 1
            if p > 0 {
                if m > 100 {
                    g_abs_min = (m - 100 + 40 * p - 1) / (40 * p)
                    if g_abs_min < 1 { g_abs_min = 1 }
                }
            }
            if g_abs_min > g_abs_max { q = q + 1; continue }

            let k_min: i64 = (-g_abs_max - g0 + m1 - 1) / m1
            let k_max: i64 = (g_abs_max - g0) / m1

            let mut k: i64 = k_min
            while k <= k_max {
                let g: i64 = g0 + k * m1
                if g != 0 {
                    let ag: i64 = g
                    if ag < 0 { ag = -ag }
                    if ag >= g_abs_min && ag <= g_abs_max {
                    let gg: i64 = g
                    let M: i64 = 3 * gg * gg * m - 40 * gg * p + 100
                    if M > 0 && M % m == 0 {
                        let t2: i64 = M / m
                        let t: i64 = isqrt(t2)
                        if t * t == t2 {
                            if ((g * p + t * q) & 1) == 0 && ((g * q - t * p) & 1) == 0 {
                                let ax: i64 = HX - g * p
                                let ay: i64 = HY - g * q
                                let bx: i64 = (g * p + t * q) / 2
                                let by: i64 = (g * q - t * p) / 2
                                let cx: i64 = (g * p - t * q) / 2
                                let cy: i64 = (g * q + t * p) / 2
                                if !((ax == bx && ay == by) || (ax == cx && ay == cy) || (bx == cx && by == cy)) {
                                    let n: i64 = ax * ax + ay * ay
                                    if (n as f64) <= r2_max + 0.000000001 {
                                        let per: f64 = hypot_f(ax, ay, bx, by) + hypot_f(bx, by, cx, cy) + hypot_f(cx, cy, ax, ay)
                                        if per <= (limit_p as f64) + 0.000000001 {
                                            let key: i64 = tri_key(ax, ay, bx, by, cx, cy)
                                            let mut found: bool = false
                                            let sc: i64 = seen_cnt[0]
                                            let mut si: i64 = 0
                                            while si < sc {
                                                if seen[si] == key { found = true; break }
                                                si = si + 1
                                            }
                                            if !found {
                                                seen[sc] = key
                                                seen_cnt[0] = sc + 1
                                                total = total + per
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    }
                }
                k = k + 1
            }
            q = q + 1
        }
        p = p + 1
    }

    free(seen); free(seen_cnt)
    printf("%.4f\n", total)
    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 gcd_abs_i64_i64(int64_t a0, int64_t b0);
int64_t mod_inverse_i64_i64(int64_t a0, int64_t m);
double hypot_f_i64_i64_i64_i64(int64_t ax, int64_t ay, int64_t bx, int64_t by);
int64_t tri_key_i64_i64_i64_i64_i64_i64(int64_t ax, int64_t ay, int64_t bx, int64_t by, int64_t cx, int64_t cy);
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 gcd_abs_i64_i64(int64_t a0, int64_t b0) {
    int64_t a = a0;
    int64_t b = b0;
    if (a < 0) {
        a = (-a);
    }
    if (b < 0) {
        b = (-b);
    }
    while (b != 0) {
        int64_t t = FLOW_CHECKED_MOD((a), (b));
        a = b;
        b = t;
    }
    return a;
}

int64_t mod_inverse_i64_i64(int64_t a0, int64_t m) {
    int64_t a = FLOW_CHECKED_MOD((a0), (m));
    if (a < 0) {
        a = (a + m);
    }
    int64_t b = m;
    int64_t x0 = 1;
    int64_t x1 = 0;
    while (b != 0) {
        int64_t q = FLOW_CHECKED_DIV((a), (b));
        int64_t t = FLOW_CHECKED_MOD((a), (b));
        a = b;
        b = t;
        int64_t tx = (x0 - (q * x1));
        x0 = x1;
        x1 = tx;
    }
    if (x0 < 0) {
        x0 = (x0 + m);
    }
    return x0;
}

double hypot_f_i64_i64_i64_i64(int64_t ax, int64_t ay, int64_t bx, int64_t by) {
    double dx = ((double)((ax - bx)));
    double dy = ((double)((ay - by)));
    return sqrt(((dx * dx) + (dy * dy)));
}

int64_t tri_key_i64_i64_i64_i64_i64_i64(int64_t ax, int64_t ay, int64_t bx, int64_t by, int64_t cx, int64_t cy) {
    int64_t a = ((ax * 1000003) + ay);
    int64_t b = ((bx * 1000003) + by);
    int64_t c = ((cx * 1000003) + cy);
    if (a > b) {
        int64_t t = a;
        a = b;
        b = t;
    }
    if (b > c) {
        int64_t t2 = b;
        b = c;
        c = t2;
    }
    if (a > b) {
        int64_t t3 = a;
        a = b;
        b = t3;
    }
    return (((a * 1000000007) + (b * 1000003)) + c);
}

int32_t main(void) {
    int64_t limit_p = 100000;
    int64_t HX = 5;
    int64_t HY = 0;
    double d_max = (((double)(limit_p)) / 2.0);
    int64_t m_limit = ((int64_t)(((40.0 * d_max) + 100.0)));
    int64_t pq_limit = (isqrt_i64(m_limit) + 1);
    double r_max = (((double)(limit_p)) / 4.0);
    double r2_max = (r_max * r_max);
    int64_t max_tri = 500000;
    int64_t* seen = (int64_t*)(calloc(max_tri, 8));
    int64_t* seen_cnt = (int64_t*)(calloc(1, 8));
    double total = 0.0;
    int64_t n0 = 25;
    int64_t x = (-5);
    while (x <= 5) {
        int64_t y2 = (n0 - (x * x));
        if (y2 >= 0) {
            int64_t y = isqrt_i64(y2);
            if ((y * y) == y2) {
                int64_t yv = (-y);
                while (yv <= y) {
                    if (yv != 0) {
                        int64_t bx = x;
                        int64_t by = yv;
                        int64_t cx = (-x);
                        int64_t cy = (-yv);
                        if ((!((bx == cx && by == cy)))) {
                            double per = ((hypot_f_i64_i64_i64_i64(HX, HY, bx, by) + hypot_f_i64_i64_i64_i64(bx, by, cx, cy)) + hypot_f_i64_i64_i64_i64(cx, cy, HX, HY));
                            if (per <= (((double)(limit_p)) + 0.000000001)) {
                                int64_t key = tri_key_i64_i64_i64_i64_i64_i64(HX, HY, bx, by, cx, cy);
                                bool found = 0;
                                int64_t sc = seen_cnt[0];
                                int64_t si = 0;
                                while (si < sc) {
                                    if (seen[si] == key) {
                                        found = 1;
                                        break;
                                    }
                                    si = (si + 1);
                                }
                                if ((!(found))) {
                                    seen[sc] = key;
                                    seen_cnt[0] = (sc + 1);
                                    total = (total + per);
                                }
                            }
                        }
                    }
                    if (yv == y) {
                        break;
                    }
                    if (yv == (-y)) {
                        yv = y;
                    } else {
                        yv = (yv + 1);
                    }
                }
            }
        }
        x = (x + 1);
    }
    int64_t p = 0;
    while (p <= pq_limit) {
        int64_t p2 = (p * p);
        if (p2 > m_limit) {
            break;
        }
        int64_t q_max = isqrt_i64((m_limit - p2));
        int64_t q = (-q_max);
        while (q <= q_max) {
            if (p == 0) {
                if (q != 1) {
                    q = (q + 1);
                    continue;
                }
            }
            if ((p == 0 && q == 0)) {
                q = (q + 1);
                continue;
            }
            if (gcd_abs_i64_i64(p, q) != 1) {
                q = (q + 1);
                continue;
            }
            int64_t m = (p2 + (q * q));
            if ((m == 0 || m > m_limit)) {
                q = (q + 1);
                continue;
            }
            int64_t a40 = FLOW_CHECKED_MOD(((40 * p)), (m));
            int64_t b100 = FLOW_CHECKED_MOD((100), (m));
            int64_t d0 = gcd_abs_i64_i64(a40, m);
            if (FLOW_CHECKED_MOD((b100), (d0)) != 0) {
                q = (q + 1);
                continue;
            }
            int64_t m1 = FLOW_CHECKED_DIV((m), (d0));
            int64_t a1 = FLOW_CHECKED_DIV((a40), (d0));
            int64_t b1 = FLOW_CHECKED_DIV((b100), (d0));
            int64_t g0 = 0;
            if (m1 > 1) {
                int64_t inv = mod_inverse_i64_i64(FLOW_CHECKED_MOD((a1), (m1)), m1);
                g0 = FLOW_CHECKED_MOD(((b1 * inv)), (m1));
            }
            int64_t g_abs_max = (((int64_t)((d_max / sqrt(((double)(m)))))) + 2);
            if (g_abs_max <= 0) {
                q = (q + 1);
                continue;
            }
            int64_t g_abs_min = 1;
            if (p > 0) {
                if (m > 100) {
                    g_abs_min = FLOW_CHECKED_DIV(((((m - 100) + (40 * p)) - 1)), ((40 * p)));
                    if (g_abs_min < 1) {
                        g_abs_min = 1;
                    }
                }
            }
            if (g_abs_min > g_abs_max) {
                q = (q + 1);
                continue;
            }
            int64_t k_min = FLOW_CHECKED_DIV((((((-g_abs_max) - g0) + m1) - 1)), (m1));
            int64_t k_max = FLOW_CHECKED_DIV(((g_abs_max - g0)), (m1));
            int64_t k = k_min;
            while (k <= k_max) {
                int64_t g = (g0 + (k * m1));
                if (g != 0) {
                    int64_t ag = g;
                    if (ag < 0) {
                        ag = (-ag);
                    }
                    if ((ag >= g_abs_min && ag <= g_abs_max)) {
                        int64_t gg = g;
                        int64_t M = (((((3 * gg) * gg) * m) - ((40 * gg) * p)) + 100);
                        if ((M > 0 && FLOW_CHECKED_MOD((M), (m)) == 0)) {
                            int64_t t2 = FLOW_CHECKED_DIV((M), (m));
                            int64_t t = isqrt_i64(t2);
                            if ((t * t) == t2) {
                                if (((((g * p) + (t * q)) & 1) == 0 && (((g * q) - (t * p)) & 1) == 0)) {
                                    int64_t ax = (HX - (g * p));
                                    int64_t ay = (HY - (g * q));
                                    int64_t bx = FLOW_CHECKED_DIV((((g * p) + (t * q))), (2));
                                    int64_t by = FLOW_CHECKED_DIV((((g * q) - (t * p))), (2));
                                    int64_t cx = FLOW_CHECKED_DIV((((g * p) - (t * q))), (2));
                                    int64_t cy = FLOW_CHECKED_DIV((((g * q) + (t * p))), (2));
                                    if ((!((((ax == bx && ay == by) || (ax == cx && ay == cy)) || (bx == cx && by == cy))))) {
                                        int64_t n = ((ax * ax) + (ay * ay));
                                        if (((double)(n)) <= (r2_max + 0.000000001)) {
                                            double per = ((hypot_f_i64_i64_i64_i64(ax, ay, bx, by) + hypot_f_i64_i64_i64_i64(bx, by, cx, cy)) + hypot_f_i64_i64_i64_i64(cx, cy, ax, ay));
                                            if (per <= (((double)(limit_p)) + 0.000000001)) {
                                                int64_t key = tri_key_i64_i64_i64_i64_i64_i64(ax, ay, bx, by, cx, cy);
                                                bool found = 0;
                                                int64_t sc = seen_cnt[0];
                                                int64_t si = 0;
                                                while (si < sc) {
                                                    if (seen[si] == key) {
                                                        found = 1;
                                                        break;
                                                    }
                                                    si = (si + 1);
                                                }
                                                if ((!(found))) {
                                                    seen[sc] = key;
                                                    seen_cnt[0] = (sc + 1);
                                                    total = (total + per);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                k = (k + 1);
            }
            q = (q + 1);
        }
        p = (p + 1);
    }
    free(seen);
    free(seen_cnt);
    printf("%.4f\n", total);
    return 0;
}

Generated MLIR

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