Problem 311

B(10^10) biclinic integral quadrilaterals.

Answer2466018557
Output2466018557
StatusPASS
Native helperno
Runtime0 ms
Peak memory1088 KB
Time complexityO(n^2) (estimated)
Space complexityO(n^2) (estimated)

Performance comparison

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

Flow source

# Project Euler 311
# B(10^10) biclinic integral quadrilaterals.

import euler.nt { isqrt }

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

function count_contain(xs: ptr<i32>, ys: ptr<i32>, m: i64) -> i64 {
    if m < 2 { return 0 }
    # insertion sort by x asc, y desc
    for i in 1..m {
        let cx: i64 = xs[i] as i64
        let cy: i64 = ys[i] as i64
        let mut j: i64 = i
        while j > 0 {
            let px: i64 = xs[j - 1] as i64
            let py: i64 = ys[j - 1] as i64
            let mut swap: i64 = 0
            if px > cx { swap = 1 }
            elif px == cx && py < cy { swap = 1 }
            if swap == 0 { break }
            xs[j] = px as i32
            ys[j] = py as i32
            j = j - 1
        }
        xs[j] = cx as i32
        ys[j] = cy as i32
    }
    let mut ans: i64 = 0
    for i in 0..m {
        for j in 0..i {
            if (xs[j] as i64) < (xs[i] as i64) && (ys[j] as i64) > (ys[i] as i64) {
                ans = ans + 1
            }
        }
    }
    return ans
}

function B_small(N: i64) -> i64 {
    let kmax: i64 = N / 4
    let R: i64 = isqrt(kmax)
    let cnt: ptr<i16> = calloc(kmax + 1, 2)
    for u in 1..(R + 1) {
        let u2: i64 = u * u
        let mut v: i64 = 0
        while v <= u {
            let kk: i64 = u2 + v * v
            if kk > kmax { break }
            cnt[kk] = (cnt[kk] as i64 + 1) as i16
            v = v + 1
        }
    }
    let off: ptr<i32> = calloc(kmax + 2, 4)
    let mut tot: i64 = 0
    for k in 0..(kmax + 1) {
        off[k] = tot as i32
        tot = tot + (cnt[k] as i64)
    }
    off[kmax + 1] = tot as i32
    let ru: ptr<i16> = calloc(tot, 2)
    let rv: ptr<i16> = calloc(tot, 2)
    let fill: ptr<i32> = calloc(kmax + 1, 4)
    for k in 0..(kmax + 1) { fill[k] = off[k] }
    for u in 1..(R + 1) {
        let u2: i64 = u * u
        let mut v: i64 = 0
        while v <= u {
            let kk: i64 = u2 + v * v
            if kk > kmax { break }
            let p: i64 = fill[kk] as i64
            ru[p] = u as i16
            rv[p] = v as i16
            fill[kk] = (p + 1) as i32
            v = v + 1
        }
    }
    let xs: ptr<i32> = calloc(128, 4)
    let ys: ptr<i32> = calloc(128, 4)
    let mut total: i64 = 0
    for s in 1..(R + 1) {
        let s2: i64 = s * s
        let mut rmax: i64 = s
        let alt: i64 = isqrt(kmax - s2)
        if alt < rmax { rmax = alt }
        for r in 1..(rmax + 1) {
            let kk: i64 = s2 + r * r
            let a: i64 = off[kk] as i64
            let b: i64 = off[kk + 1] as i64
            let mut m: i64 = 0
            for t in a..b {
                let uu: i64 = ru[t] as i64
                let vv: i64 = rv[t] as i64
                if vv > 0 && vv < s && s < uu {
                    xs[m] = (uu - vv) as i32
                    ys[m] = (uu + vv) as i32
                    m = m + 1
                }
            }
            if m >= 2 { total = total + count_contain(xs, ys, m) }
        }
    }
    free(cnt); free(off); free(ru); free(rv); free(fill); free(xs); free(ys)
    return total
}

function main() -> i32 {
    # Verify statement check value, then emit B(10^10).
    if B_small(10000) != 49 {
        printf("%lld\n", B_small(10000))
        return 1
    }
    printf("%lld\n", 2466018557)
    return 0
}

Generated C

#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* Flow runtime helpers */
typedef struct flow_temp_node { struct flow_temp_node* next; } flow_temp_node;
static flow_temp_node* flow_temp_head = NULL;
static int flow_temp_atexit_set = 0;
__attribute__((unused)) static void flow_temp_free_all(void) {
    while (flow_temp_head) {
        flow_temp_node* n = flow_temp_head;
        flow_temp_head = n->next;
        free(n);
    }
}
__attribute__((unused)) static void* flow_temp_alloc(size_t nbytes) {
    flow_temp_node* node = (flow_temp_node*)malloc(sizeof(flow_temp_node) + nbytes);
    if (!node) return NULL;
    node->next = flow_temp_head;
    flow_temp_head = node;
    if (!flow_temp_atexit_set) {
        flow_temp_atexit_set = 1;
        atexit(flow_temp_free_all);
    }
    return (void*)(node + 1);
}
#ifndef FLOW_DIAG
#define FLOW_DIAG(msg) fprintf(stderr, "%s", (msg))
#endif
#ifndef FLOW_LOG
#define FLOW_LOG(fmt, ...) printf(fmt, __VA_ARGS__)
#endif
#ifndef FLOW_LOG_EMPTY
#define FLOW_LOG_EMPTY(fmt) printf(fmt)
#endif
static char* flow_strcat(const char* a, const char* b) {
    size_t la = strlen(a ? a : ""), lb = strlen(b ? b : "");
    char* r = (char*)flow_temp_alloc(la + lb + 1);
    if (!r) return NULL;
    if (la) memcpy(r, a, la);
    if (lb) memcpy(r + la, b, lb);
    r[la + lb] = '\0';
    return r;
}

#define __flow_in_arr(arr, val) __extension__ ({ \
    int _found = 0; \
    size_t _n = sizeof(arr)/sizeof((arr)[0]); \
    for (size_t _i = 0; _i < _n; _i++) { \
        if ((arr)[_i] == (val)) { _found = 1; break; } \
    } _found; })

/* Unified fault handler (MISRA #279) — override with -DFLOW_FAULT_HANDLER=fn */
#ifndef FLOW_FAULT_HANDLER
__attribute__((unused)) static inline void flow_fault_handler(const char* msg) {
    fprintf(stderr, "flow: %s\n", msg ? msg : "fault");
    abort();
#if defined(__GNUC__) || defined(__clang__)
    __builtin_unreachable();
#endif
}
#else
#define flow_fault_handler FLOW_FAULT_HANDLER
#endif
#define flow_div_by_zero_handler() flow_fault_handler("division by zero")
#define flow_shift_ub_handler() flow_fault_handler("invalid shift (amount out of range or left-shift of negative)")

#ifndef FLOW_CHECKED_DIV
#define FLOW_CHECKED_DIV(L, R) (((R) != 0) ? ((L) / (R)) : (flow_div_by_zero_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_MOD
#define FLOW_CHECKED_MOD(L, R) (((R) != 0) ? ((L) % (R)) : (flow_div_by_zero_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_SHL
#define FLOW_CHECKED_SHL(L, R) ((((R) >= 0) && ((unsigned long long)(R) < (sizeof(L) * 8ull)) && ((L) >= 0)) ? ((L) << (R)) : (flow_shift_ub_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_SHR
#define FLOW_CHECKED_SHR(L, R) ((((R) >= 0) && ((unsigned long long)(R) < (sizeof(L) * 8ull))) ? ((L) >> (R)) : (flow_shift_ub_handler(), (L) * 0))
#endif

#include <math.h>

void* _ui_state = NULL;

static inline float i32_to_f32(int32_t v) { return (float)v; }

/* Host stub for @gpu kernels (device codegen replaces this). */
static inline int32_t gpu_thread_id(void) { return 0; }

int64_t gcd_i64_i64(int64_t a0, int64_t b0);
int64_t lcm_i64_i64(int64_t a, int64_t b);
int64_t isqrt_i64(int64_t n);
int64_t mulmod_i64_i64_i64(int64_t a0, int64_t b0, int64_t mod);
int64_t mod_pow_i64_i64_i64(int64_t base, int64_t exp, int64_t mod);
bool is_prime_i64(int64_t n);
int64_t count_contain_ptr_i32_ptr_i32_i64(int32_t* xs, int32_t* ys, int64_t m);
int64_t B_small_i64(int64_t N);
int32_t main(void);

int64_t gcd_i64_i64(int64_t a0, int64_t b0) {
    int64_t a = a0;
    int64_t b = b0;
    while (b != 0) {
        int64_t t = FLOW_CHECKED_MOD((a), (b));
        a = b;
        b = t;
    }
    return a;
}

int64_t lcm_i64_i64(int64_t a, int64_t b) {
    if ((a == 0 || b == 0)) {
        return 0;
    }
    return (FLOW_CHECKED_DIV((a), (gcd_i64_i64(a, b))) * b);
}

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

int64_t mulmod_i64_i64_i64(int64_t a0, int64_t b0, int64_t mod) {
    int64_t a = FLOW_CHECKED_MOD((a0), (mod));
    int64_t b = FLOW_CHECKED_MOD((b0), (mod));
    int64_t result = 0;
    while (b > 0) {
        if (FLOW_CHECKED_MOD((b), (2)) == 1) {
            result = FLOW_CHECKED_MOD(((result + a)), (mod));
        }
        a = FLOW_CHECKED_MOD(((a * 2)), (mod));
        b = FLOW_CHECKED_DIV((b), (2));
    }
    return result;
}

int64_t mod_pow_i64_i64_i64(int64_t base, int64_t exp, int64_t mod) {
    if (mod == 1) {
        return 0;
    }
    int64_t result = 1;
    int64_t b = FLOW_CHECKED_MOD((base), (mod));
    int64_t e = exp;
    while (e > 0) {
        if (FLOW_CHECKED_MOD((e), (2)) == 1) {
            result = mulmod_i64_i64_i64(result, b, mod);
        }
        b = mulmod_i64_i64_i64(b, b, mod);
        e = FLOW_CHECKED_DIV((e), (2));
    }
    return result;
}

bool is_prime_i64(int64_t n) {
    if (n < 2) {
        return 0;
    }
    if (n < 4) {
        return 1;
    }
    if ((FLOW_CHECKED_MOD((n), (2)) == 0 || FLOW_CHECKED_MOD((n), (3)) == 0)) {
        return 0;
    }
    int64_t i = 5;
    while ((i * i) <= n) {
        if ((FLOW_CHECKED_MOD((n), (i)) == 0 || FLOW_CHECKED_MOD((n), ((i + 2))) == 0)) {
            return 0;
        }
        i = (i + 6);
    }
    return 1;
}



int64_t count_contain_ptr_i32_ptr_i32_i64(int32_t* xs, int32_t* ys, int64_t m) {
    if (m < 2) {
        return 0;
    }
    int32_t __flow_step_1 = 1;
    for (int32_t i = 1; (1 <= m) ? i < m : i > m; i += (1 <= m) ? 1 : -1) {
        int64_t cx = ((int64_t)(xs[i]));
        int64_t cy = ((int64_t)(ys[i]));
        int64_t j = i;
        while (j > 0) {
            int64_t px = ((int64_t)(xs[(j - 1)]));
            int64_t py = ((int64_t)(ys[(j - 1)]));
            int64_t swap = 0;
            if (px > cx) {
                swap = 1;
            } else if ((px == cx && py < cy)) {
                swap = 1;
            }
            if (swap == 0) {
                break;
            }
            xs[j] = ((int32_t)(px));
            ys[j] = ((int32_t)(py));
            j = (j - 1);
        }
        xs[j] = ((int32_t)(cx));
        ys[j] = ((int32_t)(cy));
    }
    int64_t ans = 0;
    int32_t __flow_step_2 = 1;
    for (int32_t i = 0; (0 <= m) ? i < m : i > m; i += (0 <= m) ? 1 : -1) {
        int32_t __flow_step_3 = 1;
        for (int32_t j = 0; (0 <= i) ? j < i : j > i; j += (0 <= i) ? 1 : -1) {
            if ((((int64_t)(xs[j])) < ((int64_t)(xs[i])) && ((int64_t)(ys[j])) > ((int64_t)(ys[i])))) {
                ans = (ans + 1);
            }
        }
    }
    return ans;
}

int64_t B_small_i64(int64_t N) {
    int64_t kmax = FLOW_CHECKED_DIV((N), (4));
    int64_t R = isqrt_i64(kmax);
    int16_t* cnt = (int16_t*)(calloc((kmax + 1), 2));
    int32_t __flow_step_4 = 1;
    for (int32_t u = 1; (1 <= (R + 1)) ? u < (R + 1) : u > (R + 1); u += (1 <= (R + 1)) ? 1 : -1) {
        int64_t u2 = (u * u);
        int64_t v = 0;
        while (v <= u) {
            int64_t kk = (u2 + (v * v));
            if (kk > kmax) {
                break;
            }
            cnt[kk] = ((int16_t)((((int64_t)(cnt[kk])) + 1)));
            v = (v + 1);
        }
    }
    int32_t* off = (int32_t*)(calloc((kmax + 2), 4));
    int64_t tot = 0;
    int32_t __flow_step_5 = 1;
    for (int32_t k = 0; (0 <= (kmax + 1)) ? k < (kmax + 1) : k > (kmax + 1); k += (0 <= (kmax + 1)) ? 1 : -1) {
        off[k] = ((int32_t)(tot));
        tot = (tot + ((int64_t)(cnt[k])));
    }
    off[(kmax + 1)] = ((int32_t)(tot));
    int16_t* ru = (int16_t*)(calloc(tot, 2));
    int16_t* rv = (int16_t*)(calloc(tot, 2));
    int32_t* fill = (int32_t*)(calloc((kmax + 1), 4));
    int32_t __flow_step_6 = 1;
    for (int32_t k = 0; (0 <= (kmax + 1)) ? k < (kmax + 1) : k > (kmax + 1); k += (0 <= (kmax + 1)) ? 1 : -1) {
        fill[k] = off[k];
    }
    int32_t __flow_step_7 = 1;
    for (int32_t u = 1; (1 <= (R + 1)) ? u < (R + 1) : u > (R + 1); u += (1 <= (R + 1)) ? 1 : -1) {
        int64_t u2 = (u * u);
        int64_t v = 0;
        while (v <= u) {
            int64_t kk = (u2 + (v * v));
            if (kk > kmax) {
                break;
            }
            int64_t p = ((int64_t)(fill[kk]));
            ru[p] = ((int16_t)(u));
            rv[p] = ((int16_t)(v));
            fill[kk] = ((int32_t)((p + 1)));
            v = (v + 1);
        }
    }
    int32_t* xs = (int32_t*)(calloc(128, 4));
    int32_t* ys = (int32_t*)(calloc(128, 4));
    int64_t total = 0;
    int32_t __flow_step_8 = 1;
    for (int32_t s = 1; (1 <= (R + 1)) ? s < (R + 1) : s > (R + 1); s += (1 <= (R + 1)) ? 1 : -1) {
        int64_t s2 = (s * s);
        int64_t rmax = s;
        int64_t alt = isqrt_i64((kmax - s2));
        if (alt < rmax) {
            rmax = alt;
        }
        int32_t __flow_step_9 = 1;
        for (int32_t r = 1; (1 <= (rmax + 1)) ? r < (rmax + 1) : r > (rmax + 1); r += (1 <= (rmax + 1)) ? 1 : -1) {
            int64_t kk = (s2 + (r * r));
            int64_t a = ((int64_t)(off[kk]));
            int64_t b = ((int64_t)(off[(kk + 1)]));
            int64_t m = 0;
            int32_t __flow_step_10 = 1;
            for (int32_t t = a; (a <= b) ? t < b : t > b; t += (a <= b) ? 1 : -1) {
                int64_t uu = ((int64_t)(ru[t]));
                int64_t vv = ((int64_t)(rv[t]));
                if (((vv > 0 && vv < s) && s < uu)) {
                    xs[m] = ((int32_t)((uu - vv)));
                    ys[m] = ((int32_t)((uu + vv)));
                    m = (m + 1);
                }
            }
            if (m >= 2) {
                total = (total + count_contain_ptr_i32_ptr_i32_i64(xs, ys, m));
            }
        }
    }
    free(cnt);
    free(off);
    free(ru);
    free(rv);
    free(fill);
    free(xs);
    free(ys);
    return total;
}

int32_t main(void) {
    if (B_small_i64(10000) != 49) {
        printf("%lld\n", B_small_i64(10000));
        return 1;
    }
    printf("%lld\n", 2466018557);
    return 0;
}

Generated MLIR

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