Problem 782

Distinct Rows and Columns -- C(10^4). Pure Flow port of the native C helper. qsort is replaced by a heapsort.

Answer318313204
Output318313204
StatusPASS
Native helperno
Runtime810 ms
Peak memory50320 KB
Time complexityO(n^2) (estimated)
Space complexityO(n) (estimated)

Performance comparison

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

Flow source

# Project Euler 782
# Distinct Rows and Columns -- C(10^4).
# Pure Flow port of the native C helper. qsort is replaced by a heapsort.

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

# Count k in [0..n^2] achievable with complexity <= 3.
function count_le_3(n: i32) -> i64 {
    let n2: i64 = (n as i64) * (n as i64)
    let half: i64 = n2 / 2
    let seen: ptr<i8> = calloc(half + 1, 1)

    # Orbit 1: k = x*y, 0 <= x <= y <= n.
    let mut y: i32 = 1
    while y <= n {
        let mut x: i32 = 0
        while x <= y {
            let mut k: i64 = (x as i64) * (y as i64)
            if k > half {
                k = n2 - k
            }
            seen[k] = 1
            x = x + 1
        }
        y = y + 1
    }
    seen[0] = 1

    # Orbit 2: k = v^2 - d^2, 0 <= d <= v <= n.
    let mut v: i32 = 0
    while v <= n {
        let vv: i64 = (v as i64) * (v as i64)
        let mut d: i32 = 0
        while d <= v {
            let mut k: i64 = vv - (d as i64) * (d as i64)
            if k > half {
                k = n2 - k
            }
            if k >= 0 && k <= half {
                seen[k] = 1
            }
            d = d + 1
        }
        v = v + 1
    }

    # q[b] = 2*b*(n-b) for b = 0..floor(n/2).
    let bmax_global: i32 = n / 2
    let q: ptr<i64> = malloc(((bmax_global + 1) as i64) * 8)
    let mut cur: i64 = 0
    let mut delta: i64 = 2 * ((n - 1) as i64)
    let mut b: i32 = 0
    while b < bmax_global {
        q[b] = cur
        cur = cur + delta
        delta = delta - 4
        b = b + 1
    }
    q[bmax_global] = cur

    # Orbits 3/4/5/6: depend on s = a+b and ab = a(s-a).
    let mut s: i32 = 0
    while s <= n {
        let c: i32 = n - s
        let c2: i64 = (c as i64) * (c as i64)
        let c2n: i64 = (c as i64) * (2 * (n as i64) - (c as i64))
        let cs: i64 = (c as i64) * (s as i64)

        if s % 2 == 0 {
            let v2: i32 = s / 2
            let base: i64 = (v2 as i64) * (v2 as i64)
            let mut d: i32 = 0
            while d <= v2 {
                let ab: i64 = base - (d as i64) * (d as i64)
                let two_ab: i64 = ab << 1
                let mut k: i64 = c2 + two_ab
                if k > half { k = n2 - k }
                seen[k] = 1
                k = c2n + two_ab
                if k > half { k = n2 - k }
                seen[k] = 1
                k = cs + ab
                if k > half { k = n2 - k }
                seen[k] = 1
                k = (cs + ab) << 1
                if k > half { k = n2 - k }
                seen[k] = 1
                d = d + 1
            }
        } else {
            let v2: i32 = s / 2
            let base: i64 = (v2 as i64) * ((v2 + 1) as i64)
            let mut pr: i64 = 0
            let mut step: i64 = 2
            let mut d: i32 = 0
            while d <= v2 {
                let ab: i64 = base - pr
                let two_ab: i64 = ab << 1
                let mut k: i64 = c2 + two_ab
                if k > half { k = n2 - k }
                seen[k] = 1
                k = c2n + two_ab
                if k > half { k = n2 - k }
                seen[k] = 1
                k = cs + ab
                if k > half { k = n2 - k }
                seen[k] = 1
                k = (cs + ab) << 1
                if k > half { k = n2 - k }
                seen[k] = 1
                pr = pr + step
                step = step + 2
                d = d + 1
            }
        }
        s = s + 1
    }

    # Orbit 7: k = c^2 + 2*b*(n-b), 0 <= b <= min(n-c, n/2).
    let mut c: i32 = 0
    while c <= n {
        let c2: i64 = (c as i64) * (c as i64)
        let mut bmax: i32 = n - c
        if bmax > bmax_global {
            bmax = bmax_global
        }
        let mut b: i32 = 0
        while b <= bmax {
            let mut k: i64 = c2 + q[b]
            if k > half { k = n2 - k }
            seen[k] = 1
            b = b + 1
        }
        c = c + 1
    }

    let mut cnt: i64 = 0
    let mut i: i64 = 0
    while i <= half {
        cnt = cnt + (seen[i] as i64)
        i = i + 1
    }
    let mut result: i64 = 2 * cnt
    if n2 % 2 == 0 {
        result = 2 * cnt - (seen[half] as i64)
    }
    free(seen)
    free(q)
    return result
}

# Heapsort on ptr<i64> of length m.
function sift_down(a: ptr<i64>, start: i32, end: i32) {
    let mut root: i32 = start
    while 2 * root + 1 <= end {
        let mut child: i32 = 2 * root + 1
        if child + 1 <= end {
            if a[child + 1] > a[child] {
                child = child + 1
            }
        }
        if a[child] > a[root] {
            let tmp: i64 = a[root]
            a[root] = a[child]
            a[child] = tmp
            root = child
        } else {
            return
        }
    }
}

function heapsort_i64(a: ptr<i64>, m: i32) {
    let mut start: i32 = (m - 2) / 2
    while start >= 0 {
        sift_down(a, start, m - 1)
        start = start - 1
    }
    let mut end: i32 = m - 1
    while end > 0 {
        let tmp: i64 = a[0]
        a[0] = a[end]
        a[end] = tmp
        end = end - 1
        sift_down(a, 0, end)
    }
}

# Count k in [0..n^2] whose minimum complexity is exactly 2.
function count_eq_2(n: i32) -> i64 {
    let n2: i64 = (n as i64) * (n as i64)
    let vals: ptr<i64> = malloc((4 * ((n + 1) as i64)) * 8)
    let mut m: i32 = 0
    let mut a: i32 = 0
    while a <= n {
        let a2: i64 = (a as i64) * (a as i64)
        let t: i64 = 2 * (a as i64) * ((n - a) as i64)
        vals[m] = a2
        m = m + 1
        vals[m] = n2 - a2
        m = m + 1
        vals[m] = t
        m = m + 1
        vals[m] = n2 - t
        m = m + 1
        a = a + 1
    }
    heapsort_i64(vals, m)
    let mut cnt: i64 = 0
    let mut i: i32 = 0
    while i < m {
        if vals[i] == 0 || vals[i] == n2 {
            i = i + 1
        } else {
            if i == 0 || vals[i] != vals[i - 1] {
                cnt = cnt + 1
            }
            i = i + 1
        }
    }
    free(vals)
    return cnt
}

function main() -> i32 {
    let n: i32 = 10000
    let n2: i64 = (n as i64) * (n as i64)
    let total: i64 = n2 + 1
    let s3: i64 = count_le_3(n)
    let n4: i64 = total - s3
    let n2cnt: i64 = count_eq_2(n)
    printf("%lld\n", 3 * total - 4 - n2cnt + n4)
    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 count_le_3_i32(int32_t n);
void sift_down_ptr_i64_i32_i32(int64_t* a, int32_t start, int32_t end);
void heapsort_i64_ptr_i64_i32(int64_t* a, int32_t m);
int64_t count_eq_2_i32(int32_t n);
int32_t main(void);




int64_t count_le_3_i32(int32_t n) {
    int64_t n2 = (((int64_t)(n)) * ((int64_t)(n)));
    int64_t half = FLOW_CHECKED_DIV((n2), (2));
    int8_t* seen = (int8_t*)(calloc((half + 1), 1));
    int32_t y = 1;
    while (y <= n) {
        int32_t x = 0;
        while (x <= y) {
            int64_t k = (((int64_t)(x)) * ((int64_t)(y)));
            if (k > half) {
                k = (n2 - k);
            }
            seen[k] = 1;
            x = (x + 1);
        }
        y = (y + 1);
    }
    seen[0] = 1;
    int32_t v = 0;
    while (v <= n) {
        int64_t vv = (((int64_t)(v)) * ((int64_t)(v)));
        int32_t d = 0;
        while (d <= v) {
            int64_t k = (vv - (((int64_t)(d)) * ((int64_t)(d))));
            if (k > half) {
                k = (n2 - k);
            }
            if ((k >= 0 && k <= half)) {
                seen[k] = 1;
            }
            d = (d + 1);
        }
        v = (v + 1);
    }
    int32_t bmax_global = FLOW_CHECKED_DIV((n), (2));
    int64_t* q = (int64_t*)(malloc((((int64_t)((bmax_global + 1))) * 8)));
    int64_t cur = 0;
    int64_t delta = (2 * ((int64_t)((n - 1))));
    int32_t b = 0;
    while (b < bmax_global) {
        q[b] = cur;
        cur = (cur + delta);
        delta = (delta - 4);
        b = (b + 1);
    }
    q[bmax_global] = cur;
    int32_t s = 0;
    while (s <= n) {
        int32_t c = (n - s);
        int64_t c2 = (((int64_t)(c)) * ((int64_t)(c)));
        int64_t c2n = (((int64_t)(c)) * ((2 * ((int64_t)(n))) - ((int64_t)(c))));
        int64_t cs = (((int64_t)(c)) * ((int64_t)(s)));
        if (FLOW_CHECKED_MOD((s), (2)) == 0) {
            int32_t v2 = FLOW_CHECKED_DIV((s), (2));
            int64_t base = (((int64_t)(v2)) * ((int64_t)(v2)));
            int32_t d = 0;
            while (d <= v2) {
                int64_t ab = (base - (((int64_t)(d)) * ((int64_t)(d))));
                int64_t two_ab = FLOW_CHECKED_SHL((ab), (1));
                int64_t k = (c2 + two_ab);
                if (k > half) {
                    k = (n2 - k);
                }
                seen[k] = 1;
                k = (c2n + two_ab);
                if (k > half) {
                    k = (n2 - k);
                }
                seen[k] = 1;
                k = (cs + ab);
                if (k > half) {
                    k = (n2 - k);
                }
                seen[k] = 1;
                k = FLOW_CHECKED_SHL(((cs + ab)), (1));
                if (k > half) {
                    k = (n2 - k);
                }
                seen[k] = 1;
                d = (d + 1);
            }
        } else {
            int32_t v2 = FLOW_CHECKED_DIV((s), (2));
            int64_t base = (((int64_t)(v2)) * ((int64_t)((v2 + 1))));
            int64_t pr = 0;
            int64_t step = 2;
            int32_t d = 0;
            while (d <= v2) {
                int64_t ab = (base - pr);
                int64_t two_ab = FLOW_CHECKED_SHL((ab), (1));
                int64_t k = (c2 + two_ab);
                if (k > half) {
                    k = (n2 - k);
                }
                seen[k] = 1;
                k = (c2n + two_ab);
                if (k > half) {
                    k = (n2 - k);
                }
                seen[k] = 1;
                k = (cs + ab);
                if (k > half) {
                    k = (n2 - k);
                }
                seen[k] = 1;
                k = FLOW_CHECKED_SHL(((cs + ab)), (1));
                if (k > half) {
                    k = (n2 - k);
                }
                seen[k] = 1;
                pr = (pr + step);
                step = (step + 2);
                d = (d + 1);
            }
        }
        s = (s + 1);
    }
    int32_t c = 0;
    while (c <= n) {
        int64_t c2 = (((int64_t)(c)) * ((int64_t)(c)));
        int32_t bmax = (n - c);
        if (bmax > bmax_global) {
            bmax = bmax_global;
        }
        int32_t b = 0;
        while (b <= bmax) {
            int64_t k = (c2 + q[b]);
            if (k > half) {
                k = (n2 - k);
            }
            seen[k] = 1;
            b = (b + 1);
        }
        c = (c + 1);
    }
    int64_t cnt = 0;
    int64_t i = 0;
    while (i <= half) {
        cnt = (cnt + ((int64_t)(seen[i])));
        i = (i + 1);
    }
    int64_t result = (2 * cnt);
    if (FLOW_CHECKED_MOD((n2), (2)) == 0) {
        result = ((2 * cnt) - ((int64_t)(seen[half])));
    }
    free(seen);
    free(q);
    return result;
}

void sift_down_ptr_i64_i32_i32(int64_t* a, int32_t start, int32_t end) {
    int32_t root = start;
    while (((2 * root) + 1) <= end) {
        int32_t child = ((2 * root) + 1);
        if ((child + 1) <= end) {
            if (a[(child + 1)] > a[child]) {
                child = (child + 1);
            }
        }
        if (a[child] > a[root]) {
            int64_t tmp = a[root];
            a[root] = a[child];
            a[child] = tmp;
            root = child;
        } else {
            return;
        }
    }
}

void heapsort_i64_ptr_i64_i32(int64_t* a, int32_t m) {
    int32_t start = FLOW_CHECKED_DIV(((m - 2)), (2));
    while (start >= 0) {
        sift_down_ptr_i64_i32_i32(a, start, (m - 1));
        start = (start - 1);
    }
    int32_t end = (m - 1);
    while (end > 0) {
        int64_t tmp = a[0];
        a[0] = a[end];
        a[end] = tmp;
        end = (end - 1);
        sift_down_ptr_i64_i32_i32(a, 0, end);
    }
}

int64_t count_eq_2_i32(int32_t n) {
    int64_t n2 = (((int64_t)(n)) * ((int64_t)(n)));
    int64_t* vals = (int64_t*)(malloc(((4 * ((int64_t)((n + 1)))) * 8)));
    int32_t m = 0;
    int32_t a = 0;
    while (a <= n) {
        int64_t a2 = (((int64_t)(a)) * ((int64_t)(a)));
        int64_t t = ((2 * ((int64_t)(a))) * ((int64_t)((n - a))));
        vals[m] = a2;
        m = (m + 1);
        vals[m] = (n2 - a2);
        m = (m + 1);
        vals[m] = t;
        m = (m + 1);
        vals[m] = (n2 - t);
        m = (m + 1);
        a = (a + 1);
    }
    heapsort_i64_ptr_i64_i32(vals, m);
    int64_t cnt = 0;
    int32_t i = 0;
    while (i < m) {
        if ((vals[i] == 0 || vals[i] == n2)) {
            i = (i + 1);
        } else {
            if ((i == 0 || vals[i] != vals[(i - 1)])) {
                cnt = (cnt + 1);
            }
            i = (i + 1);
        }
    }
    free(vals);
    return cnt;
}

int32_t main(void) {
    int32_t n = 10000;
    int64_t n2 = (((int64_t)(n)) * ((int64_t)(n)));
    int64_t total = (n2 + 1);
    int64_t s3 = count_le_3_i32(n);
    int64_t n4 = (total - s3);
    int64_t n2cnt = count_eq_2_i32(n);
    printf("%lld\n", ((((3 * total) - 4) - n2cnt) + n4));
    return 0;
}

Generated MLIR

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