Problem 678

Fermat-like Equations: count (a,b,c,e,f) with 0 < a < b, e >= 2, f >= 3 and a^e + b^e = c^f <= 10^18. Split by e: e = 2: for every perfect power m = c^f, count a < b with a^2 + b^2 = m from the factorisation of c (r2 divisor formula; square / half-square corrections read off the exponents, no big sqrt). e = 3: f = 3 is impossible (Fermat); for f >= 4 use a^3 + b^3 = (a+b)(a^2-ab+b^2): a+b = d runs over divisors of c^f with m <= d^3 <= 4m, then ab and the discriminant decide. e >= 4: few enough pairs (a, b) to enumerate directly; each sum is looked up in a hash table mapping c^f -> number of (c, f) pairs.

Answer1986065
Output1986065
StatusPASS
Native helperno
Runtime24610 ms
Peak memory71472 KB
Time complexityO(n^4) (estimated)
Space complexityO(n^2) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^4)O(sqrt(n))
Space complexityO(n^2)O(1)
ApproachFlow solutionTrial division or Pollard rho
VerdictSuboptimal

Flow source

# Project Euler 678
# Fermat-like Equations: count (a,b,c,e,f) with 0 < a < b, e >= 2, f >= 3
# and a^e + b^e = c^f <= 10^18.
#
# Split by e:
#   e = 2:  for every perfect power m = c^f, count a < b with a^2 + b^2 = m
#           from the factorisation of c (r2 divisor formula; square /
#           half-square corrections read off the exponents, no big sqrt).
#   e = 3:  f = 3 is impossible (Fermat); for f >= 4 use
#           a^3 + b^3 = (a+b)(a^2-ab+b^2): a+b = d runs over divisors of
#           c^f with m <= d^3 <= 4m, then ab and the discriminant decide.
#   e >= 4: few enough pairs (a, b) to enumerate directly; each sum is
#           looked up in a hash table mapping c^f -> number of (c, f) pairs.

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

const N: i64 = 1000000000000000000
const HB: i64 = 4194304          # hash slots (2^22), ~1.03M keys
const HMASK: i64 = 4194303

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

# a^e, or N+1 if it exceeds N (overflow-safe)
function ipow_capped(a: i64, e: i64) -> i64 {
    let mut cur: i64 = 1
    let mut i: i64 = 0
    while i < e {
        if cur > N / a {
            return N + 1
        }
        cur = cur * a
        i = i + 1
    }
    return cur
}

function hash_slot(keys: ptr<i64>, s: i64) -> i64 {
    let mut h: i64 = s % HB
    while keys[h] != 0 && keys[h] != s {
        h = (h + 1) & HMASK
    }
    return h
}

function main() -> i32 {
    # smallest-prime-factor sieve up to 10^6 (c <= N^(1/3))
    let CM: i64 = 1000000
    let spf: ptr<i32> = calloc(CM + 1, 4)
    let mut i: i64 = 2
    while i <= CM {
        if spf[i] == 0 {
            let mut j: i64 = i
            while j <= CM {
                if spf[j] == 0 {
                    spf[j] = i as i32
                }
                j = j + i
            }
        }
        i = i + 1
    }

    let hkey: ptr<i64> = calloc(HB, 8)
    let hcnt: ptr<i64> = calloc(HB, 8)

    let pf: ptr<i64> = calloc(64, 8)    # prime factors of c
    let px: ptr<i64> = calloc(64, 8)    # exponents
    let divs: ptr<i64> = calloc(70000, 8)

    let mut total: i64 = 0

    # ---- enumerate (c, f) pairs: e=2 formula, e=3 divisors, hash fill ----
    let mut f: i64 = 3
    while ipow_capped(2, f) <= N {
        let mut c: i64 = 2
        let mut m: i64 = ipow_capped(c, f)
        while m <= N {
            # register in hash for the e >= 4 loop
            let hs: i64 = hash_slot(hkey, m)
            hkey[hs] = m
            hcnt[hs] = hcnt[hs] + 1

            # factor c
            let mut np: i64 = 0
            let mut cc: i64 = c
            while cc > 1 {
                let p: i64 = spf[cc] as i64
                let mut x: i64 = 0
                while cc % p == 0 {
                    cc = cc / p
                    x = x + 1
                }
                pf[np] = p
                px[np] = x
                np = np + 1
            }

            # e = 2: B = prod (x*f + 1) over p = 1 mod 4; need q = 3 mod 4
            # exponents even; square / half-square from exponents alone
            let mut B: i64 = 1
            let mut ok: i64 = 1
            let mut allev: i64 = 1        # all exponents of m even?
            let mut oddev: i64 = 1        # all odd-prime exponents even?
            let mut s2: i64 = 0           # exponent of 2 in m
            i = 0
            while i < np {
                let xf: i64 = px[i] * f
                if pf[i] == 2 {
                    s2 = xf
                } else {
                    if xf % 2 == 1 {
                        oddev = 0
                    }
                    if pf[i] % 4 == 1 {
                        B = B * (xf + 1)
                    } else {
                        if xf % 2 == 1 {
                            ok = 0
                        }
                    }
                }
                if xf % 2 == 1 {
                    allev = 0
                }
                i = i + 1
            }
            if ok == 1 {
                let mut sq: i64 = 0
                if allev == 1 {
                    sq = 1
                }
                let mut hsq: i64 = 0
                if s2 >= 1 && (s2 - 1) % 2 == 0 && oddev == 1 {
                    hsq = 1
                }
                total = total + (B - sq - hsq) / 2
            }

            # e = 3, f >= 4: d = a+b over divisors of m, m <= d^3 <= 4m
            if f >= 4 {
                divs[0] = 1
                let mut nd: i64 = 1
                i = 0
                while i < np {
                    let xf: i64 = px[i] * f
                    let mut nnd: i64 = nd
                    let mut pe: i64 = 1
                    let mut t: i64 = 1
                    while t <= xf {
                        # cap: only extend divisors while pe*p stays <= dmax bound
                        pe = pe * pf[i]
                        let mut u: i64 = 0
                        while u < nd {
                            let dv: i64 = divs[u]
                            # keep divisors up to 2e6 (d^3 <= 4m <= 4e18)
                            if dv <= 2000000 / pe {
                                divs[nnd] = dv * pe
                                nnd = nnd + 1
                            }
                            u = u + 1
                        }
                        t = t + 1
                    }
                    nd = nnd
                    i = i + 1
                }
                let mut u: i64 = 0
                while u < nd {
                    let d: i64 = divs[u]
                    if m % d == 0 {
                        let d3: i64 = d * d * d
                        if d3 >= m && d3 <= 4 * m {
                            let q: i64 = m / d
                            let t2: i64 = d * d - q
                            if t2 > 0 && t2 % 3 == 0 {
                                let ab: i64 = t2 / 3
                                let disc: i64 = d * d - 4 * ab
                                if disc > 0 {
                                    let rr: i64 = isqrt64(disc)
                                    if rr * rr == disc && (d - rr) % 2 == 0 {
                                        let aa: i64 = (d - rr) / 2
                                        let bbv: i64 = (d + rr) / 2
                                        if aa >= 1 && aa < bbv {
                                            if aa * aa * aa + bbv * bbv * bbv == m {
                                                total = total + 1
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    u = u + 1
                }
            }

            c = c + 1
            m = ipow_capped(c, f)
        }
        f = f + 1
    }

    # ---- e >= 4: enumerate pairs, look sums up in the hash ----
    let P: ptr<i64> = calloc(40000, 8)
    let mut e: i64 = 4
    while ipow_capped(2, e) < N {
        let mut amax: i64 = 0
        let mut a: i64 = 1
        let mut pa: i64 = ipow_capped(a, e)
        while pa <= N {
            P[a] = pa
            amax = a
            a = a + 1
            pa = ipow_capped(a, e)
        }
        a = 1
        while a < amax {
            let ae: i64 = P[a]
            if ae + P[a + 1] > N {
                a = amax
            } else {
                let mut b: i64 = a + 1
                while b <= amax && ae + P[b] <= N {
                    let s: i64 = ae + P[b]
                    let hs2: i64 = hash_slot(hkey, s)
                    if hkey[hs2] == s {
                        total = total + hcnt[hs2]
                    }
                    b = b + 1
                }
                a = a + 1
            }
        }
        e = e + 1
    }

    printf("%lld\n", total)

    free(spf)
    free(hkey)
    free(hcnt)
    free(pf)
    free(px)
    free(divs)
    free(P)
    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 isqrt64_i64(int64_t n);
int64_t ipow_capped_i64_i64(int64_t a, int64_t e);
int64_t hash_slot_ptr_i64_i64(int64_t* keys, int64_t s);
int32_t main(void);

static const int64_t N = 1000000000000000000;
static const int64_t HB = 4194304;
static const int64_t HMASK = 4194303;



int64_t isqrt64_i64(int64_t n) {
    if (n <= 0) {
        return 0;
    }
    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 ipow_capped_i64_i64(int64_t a, int64_t e) {
    int64_t cur = 1;
    int64_t i = 0;
    while (i < e) {
        if (cur > FLOW_CHECKED_DIV((N), (a))) {
            return (N + 1);
        }
        cur = (cur * a);
        i = (i + 1);
    }
    return cur;
}

int64_t hash_slot_ptr_i64_i64(int64_t* keys, int64_t s) {
    int64_t h = FLOW_CHECKED_MOD((s), (HB));
    while ((keys[h] != 0 && keys[h] != s)) {
        h = ((h + 1) & HMASK);
    }
    return h;
}

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