Problem 616

Creative numbers <= 1e12: perfect powers minus p^q minus 16.

Answer310884668312456458
Output310884668312456458
StatusPASS
Native helperno
Runtime160 ms
Peak memory12432 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 616
# Creative numbers <= 1e12: perfect powers minus p^q minus 16.

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

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

function ipow(base: i64, exp: i64) -> i64 {
    let mut r: i64 = 1
    let mut b: i64 = base
    let mut e: i64 = exp
    while e > 0 {
        if (e & 1) == 1 {
            if r > 1000000000000 / b { return -1 }
            r = r * b
        }
        e = e / 2
        if e > 0 {
            if b > 1000000000000 / b { return -1 }
            b = b * b
        }
    }
    return r
}

function iroot(limit: i64, exp: i64) -> i64 {
    # largest a with a^exp <= limit
    let mut lo: i64 = 1
    let mut hi: i64 = limit
    if exp >= 2 {
        hi = isqrt(limit) + 2
        if hi > limit { hi = limit }
    }
    while lo < hi {
        let mid: i64 = (lo + hi + 1) / 2
        let p: i64 = ipow(mid, exp)
        if p < 0 || p > limit { hi = mid - 1 } else { lo = mid }
    }
    return lo
}

function heapify(a: ptr<i64>, n: i64, i0: i64) -> void {
    let mut i: i64 = i0
    while true {
        let mut largest: i64 = i
        let l: i64 = 2 * i + 1
        let r: i64 = 2 * i + 2
        if l < n && a[l] > a[largest] { largest = l }
        if r < n && a[r] > a[largest] { largest = r }
        if largest == i { break }
        let t: i64 = a[i]
        a[i] = a[largest]
        a[largest] = t
        i = largest
    }
}

function heapsort(a: ptr<i64>, n: i64) -> void {
    let mut i: i64 = n / 2 - 1
    while i >= 0 {
        heapify(a, n, i)
        i = i - 1
    }
    i = n - 1
    while i > 0 {
        let t: i64 = a[0]
        a[0] = a[i]
        a[i] = t
        heapify(a, i, 0)
        i = i - 1
    }
}

function main() -> i32 {
    let LIMIT: i64 = 1000000000000
    # Collect perfect powers
    let arr: ptr<i64> = calloc(2000000, 8)
    if arr == null { return 1 }
    let mut n: i64 = 0
    let mut exp: i64 = 2
    while exp <= 40 {
        let base: i64 = iroot(LIMIT, exp)
        let mut a: i64 = 2
        while a <= base {
            let p: i64 = ipow(a, exp)
            if p > 0 && p <= LIMIT {
                arr[n] = p
                n = n + 1
            }
            a = a + 1
        }
        exp = exp + 1
    }
    heapsort(arr, n)
    let mut sum_pp: i64 = 0
    let mut i: i64 = 0
    while i < n {
        if i == 0 || arr[i] != arr[i - 1] {
            sum_pp = sum_pp + arr[i]
        }
        i = i + 1
    }
    # primes <= 1e6
    let M: i64 = 1000000
    let sieve: ptr<i8> = calloc(M + 1, 1)
    let primes: ptr<i32> = calloc(M / 5 + 10, 4)
    if sieve == null || primes == null { return 1 }
    i = 2
    while i <= M {
        sieve[i] = 1
        i = i + 1
    }
    let mut p: i64 = 2
    while p * p <= M {
        if sieve[p] != 0 {
            let mut q: i64 = p * p
            while q <= M {
                sieve[q] = 0
                q = q + p
            }
        }
        p = p + 1
    }
    let mut pn: i64 = 0
    i = 2
    while i <= M {
        if sieve[i] != 0 {
            primes[pn] = i as i32
            pn = pn + 1
        }
        i = i + 1
    }
    let exps: ptr<i64> = calloc(12, 8)
    exps[0] = 2; exps[1] = 3; exps[2] = 5; exps[3] = 7
    exps[4] = 11; exps[5] = 13; exps[6] = 17; exps[7] = 19
    exps[8] = 23; exps[9] = 29; exps[10] = 31; exps[11] = 37
    let pp: ptr<i64> = calloc(200000, 8)
    let mut m: i64 = 0
    let mut ei: i64 = 0
    while ei < 12 {
        let qe: i64 = exps[ei]
        let maxb: i64 = iroot(LIMIT, qe)
        let mut j: i64 = 0
        while j < pn {
            let pr: i64 = primes[j] as i64
            if pr > maxb { break }
            let val: i64 = ipow(pr, qe)
            if val > 0 && val <= LIMIT {
                pp[m] = val
                m = m + 1
            }
            j = j + 1
        }
        ei = ei + 1
    }
    heapsort(pp, m)
    let mut sum_pq: i64 = 0
    i = 0
    while i < m {
        if i == 0 || pp[i] != pp[i - 1] {
            sum_pq = sum_pq + pp[i]
        }
        i = i + 1
    }
    let ans: i64 = sum_pp - sum_pq - 16
    printf("%lld\n", ans)
    free(arr)
    free(sieve)
    free(primes)
    free(exps)
    free(pp)
    return 0
}

Generated C

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

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

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

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

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

#include <math.h>

void* _ui_state = NULL;

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

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

int64_t isqrt_i64(int64_t n);
int64_t ipow_i64_i64(int64_t base, int64_t exp);
int64_t iroot_i64_i64(int64_t limit, int64_t exp);
void heapify_ptr_i64_i64_i64(int64_t* a, int64_t n, int64_t i0);
void heapsort_ptr_i64_i64(int64_t* a, int64_t n);
int32_t main(void);



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

int64_t ipow_i64_i64(int64_t base, int64_t exp) {
    int64_t r = 1;
    int64_t b = base;
    int64_t e = exp;
    while (e > 0) {
        if ((e & 1) == 1) {
            if (r > FLOW_CHECKED_DIV((1000000000000), (b))) {
                return (-1);
            }
            r = (r * b);
        }
        e = FLOW_CHECKED_DIV((e), (2));
        if (e > 0) {
            if (b > FLOW_CHECKED_DIV((1000000000000), (b))) {
                return (-1);
            }
            b = (b * b);
        }
    }
    return r;
}

int64_t iroot_i64_i64(int64_t limit, int64_t exp) {
    int64_t lo = 1;
    int64_t hi = limit;
    if (exp >= 2) {
        hi = (isqrt_i64(limit) + 2);
        if (hi > limit) {
            hi = limit;
        }
    }
    while (lo < hi) {
        int64_t mid = FLOW_CHECKED_DIV((((lo + hi) + 1)), (2));
        int64_t p = ipow_i64_i64(mid, exp);
        if ((p < 0 || p > limit)) {
            hi = (mid - 1);
        } else {
            lo = mid;
        }
    }
    return lo;
}

void heapify_ptr_i64_i64_i64(int64_t* a, int64_t n, int64_t i0) {
    int64_t i = i0;
    while (1) {
        int64_t largest = i;
        int64_t l = ((2 * i) + 1);
        int64_t r = ((2 * i) + 2);
        if ((l < n && a[l] > a[largest])) {
            largest = l;
        }
        if ((r < n && a[r] > a[largest])) {
            largest = r;
        }
        if (largest == i) {
            break;
        }
        int64_t t = a[i];
        a[i] = a[largest];
        a[largest] = t;
        i = largest;
    }
}

void heapsort_ptr_i64_i64(int64_t* a, int64_t n) {
    int64_t i = (FLOW_CHECKED_DIV((n), (2)) - 1);
    while (i >= 0) {
        heapify_ptr_i64_i64_i64(a, n, i);
        i = (i - 1);
    }
    i = (n - 1);
    while (i > 0) {
        int64_t t = a[0];
        a[0] = a[i];
        a[i] = t;
        heapify_ptr_i64_i64_i64(a, i, 0);
        i = (i - 1);
    }
}

int32_t main(void) {
    int64_t LIMIT = 1000000000000;
    int64_t* arr = (int64_t*)(calloc(2000000, 8));
    if (arr == NULL) {
        return 1;
    }
    int64_t n = 0;
    int64_t exp = 2;
    while (exp <= 40) {
        int64_t base = iroot_i64_i64(LIMIT, exp);
        int64_t a = 2;
        while (a <= base) {
            int64_t p = ipow_i64_i64(a, exp);
            if ((p > 0 && p <= LIMIT)) {
                arr[n] = p;
                n = (n + 1);
            }
            a = (a + 1);
        }
        exp = (exp + 1);
    }
    heapsort_ptr_i64_i64(arr, n);
    int64_t sum_pp = 0;
    int64_t i = 0;
    while (i < n) {
        if ((i == 0 || arr[i] != arr[(i - 1)])) {
            sum_pp = (sum_pp + arr[i]);
        }
        i = (i + 1);
    }
    int64_t M = 1000000;
    int8_t* sieve = (int8_t*)(calloc((M + 1), 1));
    int32_t* primes = (int32_t*)(calloc((FLOW_CHECKED_DIV((M), (5)) + 10), 4));
    if ((sieve == NULL || primes == NULL)) {
        return 1;
    }
    i = 2;
    while (i <= M) {
        sieve[i] = 1;
        i = (i + 1);
    }
    int64_t p = 2;
    while ((p * p) <= M) {
        if (sieve[p] != 0) {
            int64_t q = (p * p);
            while (q <= M) {
                sieve[q] = 0;
                q = (q + p);
            }
        }
        p = (p + 1);
    }
    int64_t pn = 0;
    i = 2;
    while (i <= M) {
        if (sieve[i] != 0) {
            primes[pn] = ((int32_t)(i));
            pn = (pn + 1);
        }
        i = (i + 1);
    }
    int64_t* exps = (int64_t*)(calloc(12, 8));
    exps[0] = 2;
    exps[1] = 3;
    exps[2] = 5;
    exps[3] = 7;
    exps[4] = 11;
    exps[5] = 13;
    exps[6] = 17;
    exps[7] = 19;
    exps[8] = 23;
    exps[9] = 29;
    exps[10] = 31;
    exps[11] = 37;
    int64_t* pp = (int64_t*)(calloc(200000, 8));
    int64_t m = 0;
    int64_t ei = 0;
    while (ei < 12) {
        int64_t qe = exps[ei];
        int64_t maxb = iroot_i64_i64(LIMIT, qe);
        int64_t j = 0;
        while (j < pn) {
            int64_t pr = ((int64_t)(primes[j]));
            if (pr > maxb) {
                break;
            }
            int64_t val = ipow_i64_i64(pr, qe);
            if ((val > 0 && val <= LIMIT)) {
                pp[m] = val;
                m = (m + 1);
            }
            j = (j + 1);
        }
        ei = (ei + 1);
    }
    heapsort_ptr_i64_i64(pp, m);
    int64_t sum_pq = 0;
    i = 0;
    while (i < m) {
        if ((i == 0 || pp[i] != pp[(i - 1)])) {
            sum_pq = (sum_pq + pp[i]);
        }
        i = (i + 1);
    }
    int64_t ans = ((sum_pp - sum_pq) - 16);
    printf("%lld\n", ans);
    free(arr);
    free(sieve);
    free(primes);
    free(exps);
    free(pp);
    return 0;
}

Generated MLIR

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