Problem 791

Average and Variance: S(10^8) mod 433494437. Sum over quadruples (a,b,c,d) whose average equals twice their variance. Lattice enumeration with prefix sums.

Answer404890862
Output404890862
StatusPASS
Native helperno
Runtime700 ms
Peak memory1760 KB
Time complexityO(n^4) (estimated)
Space complexityO(n^2) (estimated)

Performance comparison

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

Flow source

# Project Euler 791
# Average and Variance: S(10^8) mod 433494437.
# Sum over quadruples (a,b,c,d) whose average equals twice their variance.
# Lattice enumeration with prefix sums.

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

const MOD: i64 = 433494437
const LIM: i64 = 1152921504606846976

function isqrt_i64(n: i64) -> i64 {
    if n <= 0 { return 0 }
    let mut r: i64 = sqrt(n as f64) as i64
    while r > 0 && r * r > n {
        r = r - 1
    }
    while (r + 1) * (r + 1) <= n {
        r = r + 1
    }
    return r
}

function main() -> i32 {
    let n: i64 = 100000000
    let N2: i64 = 2 * n
    let R: i64 = isqrt_i64(2 * n) + 2

    let s2: ptr<i64> = calloc(R + 1, 8)
    let ps2: ptr<i64> = calloc(R + 1, 8)
    let p1: ptr<i64> = calloc(R + 1, 8)
    let p2: ptr<i64> = calloc(R + 1, 8)
    let p3: ptr<i64> = calloc(R + 1, 8)

    for i in 1..(R + 1) {
        let ii: i64 = i * i
        s2[i] = s2[i - 1] + ii
        ps2[i] = ps2[i - 1] + s2[i]
        p1[i] = p1[i - 1] + i
        p2[i] = p2[i - 1] + ii
        p3[i] = p3[i - 1] + ii * i
    }

    let mut total: i64 = 0

    # Small U cases (U=0,1): brute force
    for U in 0..2 {
        for V in 0..(U + 1) {
            for W in 0..(V + 1) {
                let mut sgn: i32 = -1
                while sgn <= 1 {
                    if W == 0 && sgn == -1 {
                        sgn = sgn + 2
                    } else {
                        let u: i64 = -(U as i64)
                        let v: i64 = -(V as i64)
                        let w: i64 = (sgn as i64) * (W as i64)
                        let m: i64 = (U as i64) * (U as i64) + (V as i64) * (V as i64) + (W as i64) * (W as i64)
                        if m != 0 {
                            let a: i64 = (m + u + v + w) / 2
                            let b: i64 = (m + u - v - w) / 2
                            let c: i64 = (m - u + v - w) / 2
                            let d: i64 = (m - u - v + w) / 2
                            if 1 <= a && a <= b && b <= c && c <= d && d <= n {
                                let v_add: i64 = 2 * m
                                total = total + v_add % MOD
                                if total >= LIM { total = total % MOD }
                            }
                        }
                        sgn = sgn + 2
                    }
                }
            }
        }
    }

    # Main enumeration
    let mut U: i64 = 2
    while U <= R {
        let U2: i64 = U * U
        let rem: i64 = N2 - U2 - U
        if rem < 0 { break }

        let mut Wmax0: i64 = isqrt_i64(rem / 2)
        if Wmax0 > U { Wmax0 = U }

        let T: i64 = N2 - 2 * U2 - 2 * U

        let mut sgn: i32 = -1
        while sgn <= 1 {
            let startW: i64 = if sgn == 1 { 0 } else { 1 }
            if startW > Wmax0 {
                sgn = sgn + 2
                continue
            }

            let mut Wfull: i64
            if T < 0 {
                Wfull = -1
            } else {
                let rt: i64 = isqrt_i64(1 + 4 * T)
                if sgn == 1 {
                    Wfull = (rt - 1) / 2
                } else {
                    Wfull = (rt + 1) / 2
                }
                if Wfull > Wmax0 { Wfull = Wmax0 }
            }

            # Full segment: W in [startW..Wfull], V in [W..U]
            if Wfull >= startW {
                let A: i64 = startW
                let B: i64 = Wfull
                let num: i64 = B - A + 1

                let sumW: i64 = p1[B] - (if A > 0 { p1[A - 1] } else { 0 })
                let sumW2: i64 = p2[B] - (if A > 0 { p2[A - 1] } else { 0 })
                let sumW3: i64 = p3[B] - (if A > 0 { p3[A - 1] } else { 0 })

                let sumCnt: i64 = num * (U + 1) - sumW
                let sumCntW2: i64 = (U + 1) * sumW2 - sumW3

                let sumPrefix: i64
                if B == 0 {
                    sumPrefix = 0
                } else {
                    let mut lo: i64 = A - 1
                    let hi: i64 = B - 1
                    if lo < 0 { lo = 0 }
                    sumPrefix = ps2[hi] - (if lo > 0 { ps2[lo - 1] } else { 0 })
                }

                let sumSumV2: i64 = num * s2[U] - sumPrefix

                let contrib: i128 = (2 as i128) * (U2 as i128) * (sumCnt as i128) + (2 as i128) * (sumCntW2 as i128) + (2 as i128) * (sumSumV2 as i128)
                let mut cmod: i64 = (contrib % (MOD as i128)) as i64
                if cmod < 0 { cmod = cmod + MOD }
                total = total + cmod
                if total >= LIM { total = total % MOD }
            }

            # Tail segment
            let mut tail_start: i64 = Wfull + 1
            if tail_start < startW { tail_start = startW }
            if tail_start > Wmax0 {
                sgn = sgn + 2
                continue
            }

            let base_D: i64 = 4 * N2 + 1 - 4 * (U2 + U)

            let mut W: i64 = tail_start
            while W <= Wmax0 {
                let D: i64 = base_D - 4 * (W * W + (sgn as i64) * W)
                if D < 0 { break }

                let mut Vmax: i64 = (isqrt_i64(D) - 1) / 2
                if Vmax > U { Vmax = U }
                if Vmax < W {
                    W = W + 1
                    continue
                }

                let cnt: i64 = Vmax - W + 1
                let sumV2: i64 = s2[Vmax] - (if W > 0 { s2[W - 1] } else { 0 })

                let W2: i64 = W * W
                let contrib2: i128 = (cnt as i128) * (2 as i128) * ((U2 + W2) as i128) + (2 as i128) * (sumV2 as i128)
                let mut cmod2: i64 = (contrib2 % (MOD as i128)) as i64
                if cmod2 < 0 { cmod2 = cmod2 + MOD }
                total = total + cmod2
                if total >= LIM { total = total % MOD }
                W = W + 1
            }
            sgn = sgn + 2
        }
        U = U + 1
    }

    free(s2)
    free(ps2)
    free(p1)
    free(p2)
    free(p3)

    printf("%lld\n", total % MOD)
    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 isqrt_i64_i64(int64_t n);
int32_t main(void);

static const int64_t MOD = 433494437;
static const int64_t LIM = 1152921504606846976;




int64_t isqrt_i64_i64(int64_t n) {
    if (n <= 0) {
        return 0;
    }
    int64_t r = ((int64_t)(sqrt(((double)(n)))));
    while ((r > 0 && (r * r) > n)) {
        r = (r - 1);
    }
    while (((r + 1) * (r + 1)) <= n) {
        r = (r + 1);
    }
    return r;
}

int32_t main(void) {
    int64_t n = 100000000;
    int64_t N2 = (2 * n);
    int64_t R = (isqrt_i64_i64((2 * n)) + 2);
    int64_t* s2 = (int64_t*)(calloc((R + 1), 8));
    int64_t* ps2 = (int64_t*)(calloc((R + 1), 8));
    int64_t* p1 = (int64_t*)(calloc((R + 1), 8));
    int64_t* p2 = (int64_t*)(calloc((R + 1), 8));
    int64_t* p3 = (int64_t*)(calloc((R + 1), 8));
    int32_t __flow_step_1 = 1;
    for (int32_t i = 1; (1 <= (R + 1)) ? i < (R + 1) : i > (R + 1); i += (1 <= (R + 1)) ? 1 : -1) {
        int64_t ii = (i * i);
        s2[i] = (s2[(i - 1)] + ii);
        ps2[i] = (ps2[(i - 1)] + s2[i]);
        p1[i] = (p1[(i - 1)] + i);
        p2[i] = (p2[(i - 1)] + ii);
        p3[i] = (p3[(i - 1)] + (ii * i));
    }
    int64_t total = 0;
    int32_t __flow_step_2 = 1;
    for (int32_t U = 0; (0 <= 2) ? U < 2 : U > 2; U += (0 <= 2) ? 1 : -1) {
        int32_t __flow_step_3 = 1;
        for (int32_t V = 0; (0 <= (U + 1)) ? V < (U + 1) : V > (U + 1); V += (0 <= (U + 1)) ? 1 : -1) {
            int32_t __flow_step_4 = 1;
            for (int32_t W = 0; (0 <= (V + 1)) ? W < (V + 1) : W > (V + 1); W += (0 <= (V + 1)) ? 1 : -1) {
                int32_t sgn = (-1);
                while (sgn <= 1) {
                    if ((W == 0 && sgn == (-1))) {
                        sgn = (sgn + 2);
                    } else {
                        int64_t u = (-((int64_t)(U)));
                        int64_t v = (-((int64_t)(V)));
                        int64_t w = (((int64_t)(sgn)) * ((int64_t)(W)));
                        int64_t m = (((((int64_t)(U)) * ((int64_t)(U))) + (((int64_t)(V)) * ((int64_t)(V)))) + (((int64_t)(W)) * ((int64_t)(W))));
                        if (m != 0) {
                            int64_t a = FLOW_CHECKED_DIV(((((m + u) + v) + w)), (2));
                            int64_t b = FLOW_CHECKED_DIV(((((m + u) - v) - w)), (2));
                            int64_t c = FLOW_CHECKED_DIV(((((m - u) + v) - w)), (2));
                            int64_t d = FLOW_CHECKED_DIV(((((m - u) - v) + w)), (2));
                            if (((((1 <= a && a <= b) && b <= c) && c <= d) && d <= n)) {
                                int64_t v_add = (2 * m);
                                total = (total + FLOW_CHECKED_MOD((v_add), (MOD)));
                                if (total >= LIM) {
                                    total = FLOW_CHECKED_MOD((total), (MOD));
                                }
                            }
                        }
                        sgn = (sgn + 2);
                    }
                }
            }
        }
    }
    int64_t U = 2;
    while (U <= R) {
        int64_t U2 = (U * U);
        int64_t rem = ((N2 - U2) - U);
        if (rem < 0) {
            break;
        }
        int64_t Wmax0 = isqrt_i64_i64(FLOW_CHECKED_DIV((rem), (2)));
        if (Wmax0 > U) {
            Wmax0 = U;
        }
        int64_t T = ((N2 - (2 * U2)) - (2 * U));
        int32_t sgn = (-1);
        while (sgn <= 1) {
            int64_t startW = ((sgn == 1) ? (0) : (1));
            if (startW > Wmax0) {
                sgn = (sgn + 2);
                continue;
            }
            int64_t Wfull;
            if (T < 0) {
                Wfull = (-1);
            } else {
                int64_t rt = isqrt_i64_i64((1 + (4 * T)));
                if (sgn == 1) {
                    Wfull = FLOW_CHECKED_DIV(((rt - 1)), (2));
                } else {
                    Wfull = FLOW_CHECKED_DIV(((rt + 1)), (2));
                }
                if (Wfull > Wmax0) {
                    Wfull = Wmax0;
                }
            }
            if (Wfull >= startW) {
                int64_t A = startW;
                int64_t B = Wfull;
                int64_t num = ((B - A) + 1);
                int64_t sumW = (p1[B] - ((A > 0) ? (p1[(A - 1)]) : (0)));
                int64_t sumW2 = (p2[B] - ((A > 0) ? (p2[(A - 1)]) : (0)));
                int64_t sumW3 = (p3[B] - ((A > 0) ? (p3[(A - 1)]) : (0)));
                int64_t sumCnt = ((num * (U + 1)) - sumW);
                int64_t sumCntW2 = (((U + 1) * sumW2) - sumW3);
                int64_t sumPrefix;
                if (B == 0) {
                    sumPrefix = 0;
                } else {
                    int64_t lo = (A - 1);
                    int64_t hi = (B - 1);
                    if (lo < 0) {
                        lo = 0;
                    }
                    sumPrefix = (ps2[hi] - ((lo > 0) ? (ps2[(lo - 1)]) : (0)));
                }
                int64_t sumSumV2 = ((num * s2[U]) - sumPrefix);
                __int128 contrib = ((((((__int128)(2)) * ((__int128)(U2))) * ((__int128)(sumCnt))) + (((__int128)(2)) * ((__int128)(sumCntW2)))) + (((__int128)(2)) * ((__int128)(sumSumV2))));
                int64_t cmod = ((int64_t)(FLOW_CHECKED_MOD((contrib), (((__int128)(MOD))))));
                if (cmod < 0) {
                    cmod = (cmod + MOD);
                }
                total = (total + cmod);
                if (total >= LIM) {
                    total = FLOW_CHECKED_MOD((total), (MOD));
                }
            }
            int64_t tail_start = (Wfull + 1);
            if (tail_start < startW) {
                tail_start = startW;
            }
            if (tail_start > Wmax0) {
                sgn = (sgn + 2);
                continue;
            }
            int64_t base_D = (((4 * N2) + 1) - (4 * (U2 + U)));
            int64_t W = tail_start;
            while (W <= Wmax0) {
                int64_t D = (base_D - (4 * ((W * W) + (((int64_t)(sgn)) * W))));
                if (D < 0) {
                    break;
                }
                int64_t Vmax = FLOW_CHECKED_DIV(((isqrt_i64_i64(D) - 1)), (2));
                if (Vmax > U) {
                    Vmax = U;
                }
                if (Vmax < W) {
                    W = (W + 1);
                    continue;
                }
                int64_t cnt = ((Vmax - W) + 1);
                int64_t sumV2 = (s2[Vmax] - ((W > 0) ? (s2[(W - 1)]) : (0)));
                int64_t W2 = (W * W);
                __int128 contrib2 = (((((__int128)(cnt)) * ((__int128)(2))) * ((__int128)((U2 + W2)))) + (((__int128)(2)) * ((__int128)(sumV2))));
                int64_t cmod2 = ((int64_t)(FLOW_CHECKED_MOD((contrib2), (((__int128)(MOD))))));
                if (cmod2 < 0) {
                    cmod2 = (cmod2 + MOD);
                }
                total = (total + cmod2);
                if (total >= LIM) {
                    total = FLOW_CHECKED_MOD((total), (MOD));
                }
                W = (W + 1);
            }
            sgn = (sgn + 2);
        }
        U = (U + 1);
    }
    free(s2);
    free(ps2);
    free(p1);
    free(p2);
    free(p3);
    printf("%lld\n", FLOW_CHECKED_MOD((total), (MOD)));
    return 0;
}

Generated MLIR

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