Problem 379

g(10^12) = number of pairs x<=y with lcm(x,y)<=N via Lucy / un-Lucy.

Answer132314136838185
Output132314136838185
StatusPASS
Native helperno
Runtime2410 ms
Peak memory38128 KB
Time complexityO(n^3) (estimated)
Space complexityO(n^2) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^3)O(n log log n)
Space complexityO(n^2)O(n)
ApproachFlow solutionSieve or enumeration
VerdictSuboptimal

Flow source

# Project Euler 379
# g(10^12) = number of pairs x<=y with lcm(x,y)<=N via Lucy / un-Lucy.

import euler.nt { isqrt }

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

function lower_bound(arr: ptr<i64>, n: i64, key: i64) -> i64 {
    let mut lo: i64 = 0
    let mut hi: i64 = n
    while lo < hi {
        let mid: i64 = (lo + hi) / 2
        if arr[mid] < key {
            lo = mid + 1
        } else {
            hi = mid
        }
    }
    return lo
}

function main() -> i32 {
    let N: i64 = 1000000000000
    let m: i64 = isqrt(N)

    # Build key values V = distinct floor(N/i), ascending
    let Vtmp: ptr<i64> = calloc(2 * m + 10, 8)
    let mut vc: i64 = 0
    let mut i: i64 = 1
    while i <= N {
        let q: i64 = N / i
        Vtmp[vc] = q
        vc = vc + 1
        i = N / q + 1
    }
    # reverse to ascending
    let V: ptr<i64> = calloc(vc, 8)
    let mut j: i64 = 0
    while j < vc {
        V[j] = Vtmp[vc - 1 - j]
        j = j + 1
    }
    free(Vtmp)
    let L: i64 = vc

    let id2: ptr<i32> = calloc(m + 1, 4)
    j = 0
    while j <= m {
        id2[j] = -1
        j = j + 1
    }
    j = 0
    while j < L {
        let v: i64 = V[j]
        if v > m {
            id2[N / v] = j as i32
        }
        j = j + 1
    }

    let S: ptr<i64> = calloc(L, 8)
    j = 0
    while j < L {
        S[j] = V[j] - 1
        j = j + 1
    }

    # primes <= m
    let sieve: ptr<i8> = calloc(m + 1, 1)
    let primes: ptr<i32> = calloc(m / 5 + 10, 4)
    let mut pc: i64 = 0
    sieve[0] = 1
    sieve[1] = 1
    i = 2
    while i <= m {
        if sieve[i] == 0 {
            primes[pc] = i as i32
            pc = pc + 1
            let mut t: i64 = i * i
            while t <= m {
                sieve[t] = 1
                t = t + i
            }
        }
        i = i + 1
    }

    # Lucy sieve for pi
    let mut pi: i64 = 0
    while pi < pc {
        let p: i64 = primes[pi] as i64
        let p2: i64 = p * p
        if p2 > N { break }
        let sp: i64 = S[p - 2]
        let start: i64 = lower_bound(V, L, p2)
        j = L - 1
        while j >= start {
            let v: i64 = V[j]
            let u: i64 = v / p
            let mut Sj: i64 = 0
            if u <= m {
                Sj = S[u - 1]
            } else {
                Sj = S[id2[N / u] as i64]
            }
            S[j] = S[j] - (Sj - sp)
            j = j - 1
        }
        pi = pi + 1
    }

    j = 0
    while j < L {
        S[j] = S[j] * 3
        j = j + 1
    }

    # Un-Lucy
    pi = pc - 1
    while pi >= 0 {
        let p: i64 = primes[pi] as i64
        let p2: i64 = p * p
        if p2 <= N {
            let sp: i64 = S[p - 1]
            let start: i64 = lower_bound(V, L, p2)
            j = L - 1
            while j >= start {
                let v: i64 = V[j]
                let mut u: i64 = v / p
                let mut e: i64 = 1
                while u >= p {
                    let mut Sj: i64 = 0
                    if u <= m {
                        Sj = S[u - 1]
                    } else {
                        Sj = S[id2[N / u] as i64]
                    }
                    S[j] = S[j] + (2 * e + 1) * (Sj - sp) + (2 * (e + 1) + 1)
                    e = e + 1
                    u = u / p
                }
                j = j - 1
            }
        }
        pi = pi - 1
    }

    let Lsum: i64 = S[L - 1] + 1
    let g: i64 = (Lsum + N) / 2
    printf("%lld\n", g)
    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 lower_bound_ptr_i64_i64_i64(int64_t* arr, int64_t n, int64_t key);
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 lower_bound_ptr_i64_i64_i64(int64_t* arr, int64_t n, int64_t key) {
    int64_t lo = 0;
    int64_t hi = n;
    while (lo < hi) {
        int64_t mid = FLOW_CHECKED_DIV(((lo + hi)), (2));
        if (arr[mid] < key) {
            lo = (mid + 1);
        } else {
            hi = mid;
        }
    }
    return lo;
}

int32_t main(void) {
    int64_t N = 1000000000000;
    int64_t m = isqrt_i64(N);
    int64_t* Vtmp = (int64_t*)(calloc(((2 * m) + 10), 8));
    int64_t vc = 0;
    int64_t i = 1;
    while (i <= N) {
        int64_t q = FLOW_CHECKED_DIV((N), (i));
        Vtmp[vc] = q;
        vc = (vc + 1);
        i = (FLOW_CHECKED_DIV((N), (q)) + 1);
    }
    int64_t* V = (int64_t*)(calloc(vc, 8));
    int64_t j = 0;
    while (j < vc) {
        V[j] = Vtmp[((vc - 1) - j)];
        j = (j + 1);
    }
    free(Vtmp);
    int64_t L = vc;
    int32_t* id2 = (int32_t*)(calloc((m + 1), 4));
    j = 0;
    while (j <= m) {
        id2[j] = (-1);
        j = (j + 1);
    }
    j = 0;
    while (j < L) {
        int64_t v = V[j];
        if (v > m) {
            id2[FLOW_CHECKED_DIV((N), (v))] = ((int32_t)(j));
        }
        j = (j + 1);
    }
    int64_t* S = (int64_t*)(calloc(L, 8));
    j = 0;
    while (j < L) {
        S[j] = (V[j] - 1);
        j = (j + 1);
    }
    int8_t* sieve = (int8_t*)(calloc((m + 1), 1));
    int32_t* primes = (int32_t*)(calloc((FLOW_CHECKED_DIV((m), (5)) + 10), 4));
    int64_t pc = 0;
    sieve[0] = 1;
    sieve[1] = 1;
    i = 2;
    while (i <= m) {
        if (sieve[i] == 0) {
            primes[pc] = ((int32_t)(i));
            pc = (pc + 1);
            int64_t t = (i * i);
            while (t <= m) {
                sieve[t] = 1;
                t = (t + i);
            }
        }
        i = (i + 1);
    }
    int64_t pi = 0;
    while (pi < pc) {
        int64_t p = ((int64_t)(primes[pi]));
        int64_t p2 = (p * p);
        if (p2 > N) {
            break;
        }
        int64_t sp = S[(p - 2)];
        int64_t start = lower_bound_ptr_i64_i64_i64(V, L, p2);
        j = (L - 1);
        while (j >= start) {
            int64_t v = V[j];
            int64_t u = FLOW_CHECKED_DIV((v), (p));
            int64_t Sj = 0;
            if (u <= m) {
                Sj = S[(u - 1)];
            } else {
                Sj = S[((int64_t)(id2[FLOW_CHECKED_DIV((N), (u))]))];
            }
            S[j] = (S[j] - (Sj - sp));
            j = (j - 1);
        }
        pi = (pi + 1);
    }
    j = 0;
    while (j < L) {
        S[j] = (S[j] * 3);
        j = (j + 1);
    }
    pi = (pc - 1);
    while (pi >= 0) {
        int64_t p = ((int64_t)(primes[pi]));
        int64_t p2 = (p * p);
        if (p2 <= N) {
            int64_t sp = S[(p - 1)];
            int64_t start = lower_bound_ptr_i64_i64_i64(V, L, p2);
            j = (L - 1);
            while (j >= start) {
                int64_t v = V[j];
                int64_t u = FLOW_CHECKED_DIV((v), (p));
                int64_t e = 1;
                while (u >= p) {
                    int64_t Sj = 0;
                    if (u <= m) {
                        Sj = S[(u - 1)];
                    } else {
                        Sj = S[((int64_t)(id2[FLOW_CHECKED_DIV((N), (u))]))];
                    }
                    S[j] = ((S[j] + (((2 * e) + 1) * (Sj - sp))) + ((2 * (e + 1)) + 1));
                    e = (e + 1);
                    u = FLOW_CHECKED_DIV((u), (p));
                }
                j = (j - 1);
            }
        }
        pi = (pi - 1);
    }
    int64_t Lsum = (S[(L - 1)] + 1);
    int64_t g = FLOW_CHECKED_DIV(((Lsum + N)), (2));
    printf("%lld\n", g);
    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 @lower_bound(%arg0: !llvm.ptr, %arg1: i64, %arg2: i64) -> i64 {
    %175 = arith.constant 0 : i32
    %176 = arith.extsi %175 : i32 to i64
    %177 = llvm.mlir.constant(1 : i64) : i64
    %178 = llvm.alloca %177 x i64 : (i64) -> !llvm.ptr
    llvm.store %176, %178 : i64, !llvm.ptr
    %179 = llvm.mlir.constant(1 : i64) : i64
    %180 = llvm.alloca %179 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %180 : i64, !llvm.ptr
    cf.br ^bb42
    ^bb42:
    %181 = llvm.load %178 : !llvm.ptr -> i64
    %182 = llvm.load %180 : !llvm.ptr -> i64
    %183 = arith.cmpi slt, %181, %182 : i64
    cf.cond_br %183, ^bb43, ^bb44
    ^bb43:
      %184 = llvm.load %178 : !llvm.ptr -> i64
      %185 = llvm.load %180 : !llvm.ptr -> i64
      %186 = arith.addi %184, %185 : i64
      %187 = arith.constant 2 : i32
      %189 = arith.extsi %187 : i32 to i64
      %188 = arith.divsi %186, %189 : i64
      %191 = llvm.getelementptr %arg0[%188] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %190 = llvm.load %191 : !llvm.ptr -> i64
      %192 = arith.cmpi slt, %190, %arg2 : i64
      cf.cond_br %192, ^bb45, ^bb46
      ^bb45:
        %193 = arith.constant 1 : i32
        %195 = arith.extsi %193 : i32 to i64
        %194 = arith.addi %188, %195 : i64
        llvm.store %194, %178 : i64, !llvm.ptr
        cf.br ^bb47
      ^bb46:
        llvm.store %188, %180 : i64, !llvm.ptr
        cf.br ^bb47
      ^bb47:
      cf.br ^bb42
    ^bb44:
    %196 = llvm.load %178 : !llvm.ptr -> i64
    func.return %196 : i64
  }
  func.func @main() -> i32 {
    %197 = arith.constant 995705032704 : i32
    %198 = arith.extsi %197 : i32 to i64
    %199 = func.call @isqrt(%198) : (i64) -> i64
    %201 = arith.constant 2 : i32
    %203 = arith.extsi %201 : i32 to i64
    %202 = arith.muli %203, %199 : i64
    %204 = arith.constant 10 : i32
    %206 = arith.extsi %204 : i32 to i64
    %205 = arith.addi %202, %206 : i64
    %207 = arith.constant 8 : i32
    %208 = arith.extsi %207 : i32 to i64
    %200 = func.call @calloc(%205, %208) : (i64, i64) -> !llvm.ptr
    %209 = arith.constant 0 : i32
    %210 = arith.extsi %209 : i32 to i64
    %211 = llvm.mlir.constant(1 : i64) : i64
    %212 = llvm.alloca %211 x i64 : (i64) -> !llvm.ptr
    llvm.store %210, %212 : i64, !llvm.ptr
    %213 = arith.constant 1 : i32
    %214 = arith.extsi %213 : i32 to i64
    %215 = llvm.mlir.constant(1 : i64) : i64
    %216 = llvm.alloca %215 x i64 : (i64) -> !llvm.ptr
    llvm.store %214, %216 : i64, !llvm.ptr
    cf.br ^bb48
    ^bb48:
    %217 = llvm.load %216 : !llvm.ptr -> i64
    %218 = arith.cmpi sle, %217, %198 : i64
    cf.cond_br %218, ^bb49, ^bb50
    ^bb49:
      %219 = llvm.load %216 : !llvm.ptr -> i64
      %220 = arith.divsi %198, %219 : i64
      %221 = llvm.load %212 : !llvm.ptr -> i64
      %222 = llvm.getelementptr %200[%221] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %220, %222 : i64, !llvm.ptr
      %223 = llvm.load %212 : !llvm.ptr -> i64
      %224 = arith.constant 1 : i32
      %226 = arith.extsi %224 : i32 to i64
      %225 = arith.addi %223, %226 : i64
      llvm.store %225, %212 : i64, !llvm.ptr
      %227 = arith.divsi %198, %220 : i64
      %228 = arith.constant 1 : i32
      %230 = arith.extsi %228 : i32 to i64
      %229 = arith.addi %227, %230 : i64
      llvm.store %229, %216 : i64, !llvm.ptr
      cf.br ^bb48
    ^bb50:
    %232 = llvm.load %212 : !llvm.ptr -> i64
    %233 = arith.constant 8 : i32
    %234 = arith.extsi %233 : i32 to i64
    %231 = func.call @calloc(%232, %234) : (i64, i64) -> !llvm.ptr
    %235 = arith.constant 0 : i32
    %236 = arith.extsi %235 : i32 to i64
    %237 = llvm.mlir.constant(1 : i64) : i64
    %238 = llvm.alloca %237 x i64 : (i64) -> !llvm.ptr
    llvm.store %236, %238 : i64, !llvm.ptr
    cf.br ^bb51
    ^bb51:
    %239 = llvm.load %238 : !llvm.ptr -> i64
    %240 = llvm.load %212 : !llvm.ptr -> i64
    %241 = arith.cmpi slt, %239, %240 : i64
    cf.cond_br %241, ^bb52, ^bb53
    ^bb52:
      %243 = llvm.load %212 : !llvm.ptr -> i64
      %244 = arith.constant 1 : i32
      %246 = arith.extsi %244 : i32 to i64
      %245 = arith.subi %243, %246 : i64
      %247 = llvm.load %238 : !llvm.ptr -> i64
      %248 = arith.subi %245, %247 : i64
      %249 = llvm.getelementptr %200[%248] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %242 = llvm.load %249 : !llvm.ptr -> i64
      %250 = llvm.load %238 : !llvm.ptr -> i64
      %251 = llvm.getelementptr %231[%250] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %242, %251 : i64, !llvm.ptr
      %252 = llvm.load %238 : !llvm.ptr -> i64
      %253 = arith.constant 1 : i32
      %255 = arith.extsi %253 : i32 to i64
      %254 = arith.addi %252, %255 : i64
      llvm.store %254, %238 : i64, !llvm.ptr
      cf.br ^bb51
    ^bb53:
    func.call @free(%200) : (!llvm.ptr) -> ()
    %257 = llvm.load %212 : !llvm.ptr -> i64
    %259 = arith.constant 1 : i32
    %261 = arith.extsi %259 : i32 to i64
    %260 = arith.addi %199, %261 : i64
    %262 = arith.constant 4 : i32
    %263 = arith.extsi %262 : i32 to i64
    %258 = func.call @calloc(%260, %263) : (i64, i64) -> !llvm.ptr
    %264 = arith.constant 0 : i32
    %265 = arith.extsi %264 : i32 to i64
    llvm.store %265, %238 : i64, !llvm.ptr
    cf.br ^bb54
    ^bb54:
    %266 = llvm.load %238 : !llvm.ptr -> i64
    %267 = arith.cmpi sle, %266, %199 : i64
    cf.cond_br %267, ^bb55, ^bb56
    ^bb55:
      %268 = arith.constant 1 : i32
      %270 = arith.constant 0 : i32
      %269 = arith.subi %270, %268 : i32
      %271 = llvm.load %238 : !llvm.ptr -> i64
      %272 = llvm.getelementptr %258[%271] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      llvm.store %269, %272 : i32, !llvm.ptr
      %273 = llvm.load %238 : !llvm.ptr -> i64
      %274 = arith.constant 1 : i32
      %276 = arith.extsi %274 : i32 to i64
      %275 = arith.addi %273, %276 : i64
      llvm.store %275, %238 : i64, !llvm.ptr
      cf.br ^bb54
    ^bb56:
    %277 = arith.constant 0 : i32
    %278 = arith.extsi %277 : i32 to i64
    llvm.store %278, %238 : i64, !llvm.ptr
    cf.br ^bb57
    ^bb57:
    %279 = llvm.load %238 : !llvm.ptr -> i64
    %280 = arith.cmpi slt, %279, %257 : i64
    cf.cond_br %280, ^bb58, ^bb59
    ^bb58:
      %282 = llvm.load %238 : !llvm.ptr -> i64
      %283 = llvm.getelementptr %231[%282] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %281 = llvm.load %283 : !llvm.ptr -> i64
      %284 = arith.cmpi sgt, %281, %199 : i64
      cf.cond_br %284, ^bb60, ^bb61
      ^bb60:
        %285 = llvm.load %238 : !llvm.ptr -> i64
        %286 = arith.trunci %285 : i64 to i32
        %287 = arith.divsi %198, %281 : i64
        %288 = llvm.getelementptr %258[%287] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %286, %288 : i32, !llvm.ptr
        cf.br ^bb62
      ^bb61:
        cf.br ^bb62
      ^bb62:
      %289 = llvm.load %238 : !llvm.ptr -> i64
      %290 = arith.constant 1 : i32
      %292 = arith.extsi %290 : i32 to i64
      %291 = arith.addi %289, %292 : i64
      llvm.store %291, %238 : i64, !llvm.ptr
      cf.br ^bb57
    ^bb59:
    %294 = arith.constant 8 : i32
    %295 = arith.extsi %294 : i32 to i64
    %293 = func.call @calloc(%257, %295) : (i64, i64) -> !llvm.ptr
    %296 = arith.constant 0 : i32
    %297 = arith.extsi %296 : i32 to i64
    llvm.store %297, %238 : i64, !llvm.ptr
    cf.br ^bb63
    ^bb63:
    %298 = llvm.load %238 : !llvm.ptr -> i64
    %299 = arith.cmpi slt, %298, %257 : i64
    cf.cond_br %299, ^bb64, ^bb65
    ^bb64:
      %301 = llvm.load %238 : !llvm.ptr -> i64
      %302 = llvm.getelementptr %231[%301] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %300 = llvm.load %302 : !llvm.ptr -> i64
      %303 = arith.constant 1 : i32
      %305 = arith.extsi %303 : i32 to i64
      %304 = arith.subi %300, %305 : i64
      %306 = llvm.load %238 : !llvm.ptr -> i64
      %307 = llvm.getelementptr %293[%306] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %304, %307 : i64, !llvm.ptr
      %308 = llvm.load %238 : !llvm.ptr -> i64
      %309 = arith.constant 1 : i32
      %311 = arith.extsi %309 : i32 to i64
      %310 = arith.addi %308, %311 : i64
      llvm.store %310, %238 : i64, !llvm.ptr
      cf.br ^bb63
    ^bb65:
    %313 = arith.constant 1 : i32
    %315 = arith.extsi %313 : i32 to i64
    %314 = arith.addi %199, %315 : i64
    %316 = arith.constant 1 : i32
    %317 = arith.extsi %316 : i32 to i64
    %312 = func.call @calloc(%314, %317) : (i64, i64) -> !llvm.ptr
    %319 = arith.constant 5 : i32
    %321 = arith.extsi %319 : i32 to i64
    %320 = arith.divsi %199, %321 : i64
    %322 = arith.constant 10 : i32
    %324 = arith.extsi %322 : i32 to i64
    %323 = arith.addi %320, %324 : i64
    %325 = arith.constant 4 : i32
    %326 = arith.extsi %325 : i32 to i64
    %318 = func.call @calloc(%323, %326) : (i64, i64) -> !llvm.ptr
    %327 = arith.constant 0 : i32
    %328 = arith.extsi %327 : i32 to i64
    %329 = llvm.mlir.constant(1 : i64) : i64
    %330 = llvm.alloca %329 x i64 : (i64) -> !llvm.ptr
    llvm.store %328, %330 : i64, !llvm.ptr
    %331 = arith.constant 1 : i32
    %332 = arith.constant 0 : i32
    %333 = arith.trunci %331 : i32 to i8
    %334 = arith.extsi %332 : i32 to i64
    %335 = llvm.getelementptr %312[%334] : (!llvm.ptr, i64) -> !llvm.ptr, i8
    llvm.store %333, %335 : i8, !llvm.ptr
    %336 = arith.constant 1 : i32
    %337 = arith.constant 1 : i32
    %338 = arith.trunci %336 : i32 to i8
    %339 = arith.extsi %337 : i32 to i64
    %340 = llvm.getelementptr %312[%339] : (!llvm.ptr, i64) -> !llvm.ptr, i8
    llvm.store %338, %340 : i8, !llvm.ptr
    %341 = arith.constant 2 : i32
    %342 = arith.extsi %341 : i32 to i64
    llvm.store %342, %216 : i64, !llvm.ptr
    cf.br ^bb66
    ^bb66:
    %343 = llvm.load %216 : !llvm.ptr -> i64
    %344 = arith.cmpi sle, %343, %199 : i64
    cf.cond_br %344, ^bb67, ^bb68
    ^bb67:
      %346 = llvm.load %216 : !llvm.ptr -> i64
      %347 = llvm.getelementptr %312[%346] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %345 = llvm.load %347 : !llvm.ptr -> i8
      %348 = arith.constant 0 : i32
      %350 = arith.extsi %345 : i8 to i32
      %349 = arith.cmpi eq, %350, %348 : i32
      cf.cond_br %349, ^bb69, ^bb70
      ^bb69:
        %351 = llvm.load %216 : !llvm.ptr -> i64
        %352 = arith.trunci %351 : i64 to i32
        %353 = llvm.load %330 : !llvm.ptr -> i64
        %354 = llvm.getelementptr %318[%353] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %352, %354 : i32, !llvm.ptr
        %355 = llvm.load %330 : !llvm.ptr -> i64
        %356 = arith.constant 1 : i32
        %358 = arith.extsi %356 : i32 to i64
        %357 = arith.addi %355, %358 : i64
        llvm.store %357, %330 : i64, !llvm.ptr
        %359 = llvm.load %216 : !llvm.ptr -> i64
        %360 = llvm.load %216 : !llvm.ptr -> i64
        %361 = arith.muli %359, %360 : i64
        %362 = llvm.mlir.constant(1 : i64) : i64
        %363 = llvm.alloca %362 x i64 : (i64) -> !llvm.ptr
        llvm.store %361, %363 : i64, !llvm.ptr
        cf.br ^bb72
        ^bb72:
        %364 = llvm.load %363 : !llvm.ptr -> i64
        %365 = arith.cmpi sle, %364, %199 : i64
        cf.cond_br %365, ^bb73, ^bb74
        ^bb73:
          %366 = arith.constant 1 : i32
          %367 = llvm.load %363 : !llvm.ptr -> i64
          %368 = arith.trunci %366 : i32 to i8
          %369 = llvm.getelementptr %312[%367] : (!llvm.ptr, i64) -> !llvm.ptr, i8
          llvm.store %368, %369 : i8, !llvm.ptr
          %370 = llvm.load %363 : !llvm.ptr -> i64
          %371 = llvm.load %216 : !llvm.ptr -> i64
          %372 = arith.addi %370, %371 : i64
          llvm.store %372, %363 : i64, !llvm.ptr
          cf.br ^bb72
        ^bb74:
        cf.br ^bb71
      ^bb70:
        cf.br ^bb71
      ^bb71:
      %373 = llvm.load %216 : !llvm.ptr -> i64
      %374 = arith.constant 1 : i32
      %376 = arith.extsi %374 : i32 to i64
      %375 = arith.addi %373, %376 : i64
      llvm.store %375, %216 : i64, !llvm.ptr
      cf.br ^bb66
    ^bb68:
    %377 = arith.constant 0 : i32
    %378 = arith.extsi %377 : i32 to i64
    %379 = llvm.mlir.constant(1 : i64) : i64
    %380 = llvm.alloca %379 x i64 : (i64) -> !llvm.ptr
    llvm.store %378, %380 : i64, !llvm.ptr
    cf.br ^bb75
    ^bb75:
    %381 = llvm.load %380 : !llvm.ptr -> i64
    %382 = llvm.load %330 : !llvm.ptr -> i64
    %383 = arith.cmpi slt, %381, %382 : i64
    cf.cond_br %383, ^bb76, ^bb77
    ^bb76:
      %385 = llvm.load %380 : !llvm.ptr -> i64
      %386 = llvm.getelementptr %318[%385] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %384 = llvm.load %386 : !llvm.ptr -> i32
      %387 = arith.extsi %384 : i32 to i64
      %388 = arith.muli %387, %387 : i64
      %389 = arith.cmpi sgt, %388, %198 : i64
      cf.cond_br %389, ^bb78, ^bb79
      ^bb78:
        cf.br ^bb77
      ^bb79:
        cf.br ^bb80
      ^bb80:
      %391 = arith.constant 2 : i32
      %393 = arith.extsi %391 : i32 to i64
      %392 = arith.subi %387, %393 : i64
      %394 = llvm.getelementptr %293[%392] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %390 = llvm.load %394 : !llvm.ptr -> i64
      %395 = func.call @lower_bound(%231, %257, %388) : (!llvm.ptr, i64, i64) -> i64
      %396 = arith.constant 1 : i32
      %398 = arith.extsi %396 : i32 to i64
      %397 = arith.subi %257, %398 : i64
      llvm.store %397, %238 : i64, !llvm.ptr
      cf.br ^bb81
      ^bb81:
      %399 = llvm.load %238 : !llvm.ptr -> i64
      %400 = arith.cmpi sge, %399, %395 : i64
      cf.cond_br %400, ^bb82, ^bb83
      ^bb82:
        %402 = llvm.load %238 : !llvm.ptr -> i64
        %403 = llvm.getelementptr %231[%402] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %401 = llvm.load %403 : !llvm.ptr -> i64
        %404 = arith.divsi %401, %387 : i64
        %405 = arith.constant 0 : i32
        %406 = arith.extsi %405 : i32 to i64
        %407 = llvm.mlir.constant(1 : i64) : i64
        %408 = llvm.alloca %407 x i64 : (i64) -> !llvm.ptr
        llvm.store %406, %408 : i64, !llvm.ptr
        %409 = arith.cmpi sle, %404, %199 : i64
        cf.cond_br %409, ^bb84, ^bb85
        ^bb84:
          %411 = arith.constant 1 : i32
          %413 = arith.extsi %411 : i32 to i64
          %412 = arith.subi %404, %413 : i64
          %414 = llvm.getelementptr %293[%412] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %410 = llvm.load %414 : !llvm.ptr -> i64
          llvm.store %410, %408 : i64, !llvm.ptr
          cf.br ^bb86
        ^bb85:
          %417 = arith.divsi %198, %404 : i64
          %418 = llvm.getelementptr %258[%417] : (!llvm.ptr, i64) -> !llvm.ptr, i32
          %416 = llvm.load %418 : !llvm.ptr -> i32
          %419 = arith.extsi %416 : i32 to i64
          %420 = llvm.getelementptr %293[%419] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %415 = llvm.load %420 : !llvm.ptr -> i64
          llvm.store %415, %408 : i64, !llvm.ptr
          cf.br ^bb86
        ^bb86:
        %422 = llvm.load %238 : !llvm.ptr -> i64
        %423 = llvm.getelementptr %293[%422] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %421 = llvm.load %423 : !llvm.ptr -> i64
        %424 = llvm.load %408 : !llvm.ptr -> i64
        %425 = arith.subi %424, %390 : i64
        %426 = arith.subi %421, %425 : i64
        %427 = llvm.load %238 : !llvm.ptr -> i64
        %428 = llvm.getelementptr %293[%427] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %426, %428 : i64, !llvm.ptr
        %429 = llvm.load %238 : !llvm.ptr -> i64
        %430 = arith.constant 1 : i32
        %432 = arith.extsi %430 : i32 to i64
        %431 = arith.subi %429, %432 : i64
        llvm.store %431, %238 : i64, !llvm.ptr
        cf.br ^bb81
      ^bb83:
      %433 = llvm.load %380 : !llvm.ptr -> i64
      %434 = arith.constant 1 : i32
      %436 = arith.extsi %434 : i32 to i64
      %435 = arith.addi %433, %436 : i64
      llvm.store %435, %380 : i64, !llvm.ptr
      cf.br ^bb75
    ^bb77:
    %437 = arith.constant 0 : i32
    %438 = arith.extsi %437 : i32 to i64
    llvm.store %438, %238 : i64, !llvm.ptr
    cf.br ^bb87
    ^bb87:
    %439 = llvm.load %238 : !llvm.ptr -> i64
    %440 = arith.cmpi slt, %439, %257 : i64
    cf.cond_br %440, ^bb88, ^bb89
    ^bb88:
      %442 = llvm.load %238 : !llvm.ptr -> i64
      %443 = llvm.getelementptr %293[%442] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %441 = llvm.load %443 : !llvm.ptr -> i64
      %444 = arith.constant 3 : i32
      %446 = arith.extsi %444 : i32 to i64
      %445 = arith.muli %441, %446 : i64
      %447 = llvm.load %238 : !llvm.ptr -> i64
      %448 = llvm.getelementptr %293[%447] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %445, %448 : i64, !llvm.ptr
      %449 = llvm.load %238 : !llvm.ptr -> i64
      %450 = arith.constant 1 : i32
      %452 = arith.extsi %450 : i32 to i64
      %451 = arith.addi %449, %452 : i64
      llvm.store %451, %238 : i64, !llvm.ptr
      cf.br ^bb87
    ^bb89:
    %453 = llvm.load %330 : !llvm.ptr -> i64
    %454 = arith.constant 1 : i32
    %456 = arith.extsi %454 : i32 to i64
    %455 = arith.subi %453, %456 : i64
    llvm.store %455, %380 : i64, !llvm.ptr
    cf.br ^bb90
    ^bb90:
    %457 = llvm.load %380 : !llvm.ptr -> i64
    %458 = arith.constant 0 : i32
    %460 = arith.extsi %458 : i32 to i64
    %459 = arith.cmpi sge, %457, %460 : i64
    cf.cond_br %459, ^bb91, ^bb92
    ^bb91:
      %462 = llvm.load %380 : !llvm.ptr -> i64
      %463 = llvm.getelementptr %318[%462] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %461 = llvm.load %463 : !llvm.ptr -> i32
      %464 = arith.extsi %461 : i32 to i64
      %465 = arith.muli %464, %464 : i64
      %466 = arith.cmpi sle, %465, %198 : i64
      cf.cond_br %466, ^bb93, ^bb94
      ^bb93:
        %468 = arith.constant 1 : i32
        %470 = arith.extsi %468 : i32 to i64
        %469 = arith.subi %464, %470 : i64
        %471 = llvm.getelementptr %293[%469] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %467 = llvm.load %471 : !llvm.ptr -> i64
        %472 = func.call @lower_bound(%231, %257, %465) : (!llvm.ptr, i64, i64) -> i64
        %473 = arith.constant 1 : i32
        %475 = arith.extsi %473 : i32 to i64
        %474 = arith.subi %257, %475 : i64
        llvm.store %474, %238 : i64, !llvm.ptr
        cf.br ^bb96
        ^bb96:
        %476 = llvm.load %238 : !llvm.ptr -> i64
        %477 = arith.cmpi sge, %476, %472 : i64
        cf.cond_br %477, ^bb97, ^bb98
        ^bb97:
          %479 = llvm.load %238 : !llvm.ptr -> i64
          %480 = llvm.getelementptr %231[%479] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %478 = llvm.load %480 : !llvm.ptr -> i64
          %481 = arith.divsi %478, %464 : i64
          %482 = llvm.mlir.constant(1 : i64) : i64
          %483 = llvm.alloca %482 x i64 : (i64) -> !llvm.ptr
          llvm.store %481, %483 : i64, !llvm.ptr
          %484 = arith.constant 1 : i32
          %485 = arith.extsi %484 : i32 to i64
          %486 = llvm.mlir.constant(1 : i64) : i64
          %487 = llvm.alloca %486 x i64 : (i64) -> !llvm.ptr
          llvm.store %485, %487 : i64, !llvm.ptr
          cf.br ^bb99
          ^bb99:
          %488 = llvm.load %483 : !llvm.ptr -> i64
          %489 = arith.cmpi sge, %488, %464 : i64
          cf.cond_br %489, ^bb100, ^bb101
          ^bb100:
            %490 = arith.constant 0 : i32
            %491 = arith.extsi %490 : i32 to i64
            %492 = llvm.mlir.constant(1 : i64) : i64
            %493 = llvm.alloca %492 x i64 : (i64) -> !llvm.ptr
            llvm.store %491, %493 : i64, !llvm.ptr
            %494 = llvm.load %483 : !llvm.ptr -> i64
            %495 = arith.cmpi sle, %494, %199 : i64
            cf.cond_br %495, ^bb102, ^bb103
            ^bb102:
              %497 = llvm.load %483 : !llvm.ptr -> i64
              %498 = arith.constant 1 : i32
              %500 = arith.extsi %498 : i32 to i64
              %499 = arith.subi %497, %500 : i64
              %501 = llvm.getelementptr %293[%499] : (!llvm.ptr, i64) -> !llvm.ptr, i64
              %496 = llvm.load %501 : !llvm.ptr -> i64
              llvm.store %496, %493 : i64, !llvm.ptr
              cf.br ^bb104
            ^bb103:
              %504 = llvm.load %483 : !llvm.ptr -> i64
              %505 = arith.divsi %198, %504 : i64
              %506 = llvm.getelementptr %258[%505] : (!llvm.ptr, i64) -> !llvm.ptr, i32
              %503 = llvm.load %506 : !llvm.ptr -> i32
              %507 = arith.extsi %503 : i32 to i64
              %508 = llvm.getelementptr %293[%507] : (!llvm.ptr, i64) -> !llvm.ptr, i64
              %502 = llvm.load %508 : !llvm.ptr -> i64
              llvm.store %502, %493 : i64, !llvm.ptr
              cf.br ^bb104
            ^bb104:
            %510 = llvm.load %238 : !llvm.ptr -> i64
            %511 = llvm.getelementptr %293[%510] : (!llvm.ptr, i64) -> !llvm.ptr, i64
            %509 = llvm.load %511 : !llvm.ptr -> i64
            %512 = arith.constant 2 : i32
            %513 = llvm.load %487 : !llvm.ptr -> i64
            %515 = arith.extsi %512 : i32 to i64
            %514 = arith.muli %515, %513 : i64
            %516 = arith.constant 1 : i32
            %518 = arith.extsi %516 : i32 to i64
            %517 = arith.addi %514, %518 : i64
            %519 = llvm.load %493 : !llvm.ptr -> i64
            %520 = arith.subi %519, %467 : i64
            %521 = arith.muli %517, %520 : i64
            %522 = arith.addi %509, %521 : i64
            %523 = arith.constant 2 : i32
            %524 = llvm.load %487 : !llvm.ptr -> i64
            %525 = arith.constant 1 : i32
            %527 = arith.extsi %525 : i32 to i64
            %526 = arith.addi %524, %527 : i64
            %529 = arith.extsi %523 : i32 to i64
            %528 = arith.muli %529, %526 : i64
            %530 = arith.constant 1 : i32
            %532 = arith.extsi %530 : i32 to i64
            %531 = arith.addi %528, %532 : i64
            %533 = arith.addi %522, %531 : i64
            %534 = llvm.load %238 : !llvm.ptr -> i64
            %535 = llvm.getelementptr %293[%534] : (!llvm.ptr, i64) -> !llvm.ptr, i64
            llvm.store %533, %535 : i64, !llvm.ptr
            %536 = llvm.load %487 : !llvm.ptr -> i64
            %537 = arith.constant 1 : i32
            %539 = arith.extsi %537 : i32 to i64
            %538 = arith.addi %536, %539 : i64
            llvm.store %538, %487 : i64, !llvm.ptr
            %540 = llvm.load %483 : !llvm.ptr -> i64
            %541 = arith.divsi %540, %464 : i64
            llvm.store %541, %483 : i64, !llvm.ptr
            cf.br ^bb99
          ^bb101:
          %542 = llvm.load %238 : !llvm.ptr -> i64
          %543 = arith.constant 1 : i32
          %545 = arith.extsi %543 : i32 to i64
          %544 = arith.subi %542, %545 : i64
          llvm.store %544, %238 : i64, !llvm.ptr
          cf.br ^bb96
        ^bb98:
        cf.br ^bb95
      ^bb94:
        cf.br ^bb95
      ^bb95:
      %546 = llvm.load %380 : !llvm.ptr -> i64
      %547 = arith.constant 1 : i32
      %549 = arith.extsi %547 : i32 to i64
      %548 = arith.subi %546, %549 : i64
      llvm.store %548, %380 : i64, !llvm.ptr
      cf.br ^bb90
    ^bb92:
    %551 = arith.constant 1 : i32
    %553 = arith.extsi %551 : i32 to i64
    %552 = arith.subi %257, %553 : i64
    %554 = llvm.getelementptr %293[%552] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %550 = llvm.load %554 : !llvm.ptr -> i64
    %555 = arith.constant 1 : i32
    %557 = arith.extsi %555 : i32 to i64
    %556 = arith.addi %550, %557 : i64
    %558 = arith.addi %556, %198 : i64
    %559 = arith.constant 2 : i32
    %561 = arith.extsi %559 : i32 to i64
    %560 = arith.divsi %558, %561 : i64
    %562 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %563 = llvm.call @printf(%562, %560) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    %564 = arith.constant 0 : i32
    func.return %564 : i32
  }
}