Problem 732

Standing on the Shoulders of Trolls - Q(1000). Generates trolls from r[i] = (5^i mod 1e9+7) mod 101 + 50, then solves a 0/1 knapsack-over-time scheduling problem (earliest-deadline-first DP).

Answer45609
Output45609
StatusPASS
Native helperno
Runtime20 ms
Peak memory1392 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 732
# Standing on the Shoulders of Trolls - Q(1000).
# Generates trolls from r[i] = (5^i mod 1e9+7) mod 101 + 50, then solves
# a 0/1 knapsack-over-time scheduling problem (earliest-deadline-first DP).

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

# Integer square root for non-negative i64.
function isqrt_ll(x: i64) -> i64 {
    if x < 0 {
        return 0
    }
    if x < 2 {
        return x
    }
    let mut x0: i64 = x
    let mut x1: i64 = (x0 + 1) / 2
    while x1 < x0 {
        x0 = x1
        x1 = (x0 + x / x0) / 2
    }
    return x0
}

# ceil(s / sqrt(2)) exactly: smallest y with 2*y^2 >= s^2.
function ceil_div_sqrt2(s: i64) -> i64 {
    let a: i64 = s * s
    return isqrt_ll((a - 1) / 2) + 1
}

# Heapsort jobs by deadline (ascending).
function sift_down(d: ptr<i64>, p: ptr<i64>, prof: 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 d[child] < d[child + 1] {
                child = child + 1
            }
        }
        if d[root] < d[child] {
            let td: i64 = d[root]
            d[root] = d[child]
            d[child] = td
            let tp: i64 = p[root]
            p[root] = p[child]
            p[child] = tp
            let tq: i64 = prof[root]
            prof[root] = prof[child]
            prof[child] = tq
            root = child
        } else {
            return
        }
    }
}

function heap_sort(d: ptr<i64>, p: ptr<i64>, prof: ptr<i64>, n: i32) {
    let mut start: i32 = (n - 2) / 2
    while start >= 0 {
        sift_down(d, p, prof, start, n - 1)
        start = start - 1
    }
    let mut end: i32 = n - 1
    while end > 0 {
        let td: i64 = d[0]
        d[0] = d[end]
        d[end] = td
        let tp: i64 = p[0]
        p[0] = p[end]
        p[end] = tp
        let tq: i64 = prof[0]
        prof[0] = prof[end]
        prof[end] = tq
        end = end - 1
        sift_down(d, p, prof, 0, end)
    }
}

function main() -> i32 {
    let n: i32 = 1000
    let total_r: i32 = 3 * n

    # Generate r[0..3n-1].
    let r: ptr<i64> = calloc((total_r as i64), 8)
    if r == null {
        return 1
    }
    let mut p: i64 = 1
    for i in 0..total_r {
        r[i] = (p % 101) + 50
        p = (p * 5) % 1000000007
    }

    let mut total_h: i64 = 0
    for k in 0..n {
        total_h = total_h + r[3 * k]
    }

    let y: i64 = ceil_div_sqrt2(total_h)
    let base: i64 = total_h - y

    # Build jobs.
    let jd: ptr<i64> = calloc((n as i64), 8)
    let jp: ptr<i64> = calloc((n as i64), 8)
    let jq: ptr<i64> = calloc((n as i64), 8)
    if jd == null || jp == null || jq == null {
        return 1
    }
    let mut njobs: i32 = 0
    let mut max_d: i64 = 0
    for k in 0..n {
        let h: i64 = r[3 * k]
        let l: i64 = r[3 * k + 1]
        let q: i64 = r[3 * k + 2]
        let d: i64 = base + l + h
        if h <= d {
            jd[njobs] = d
            jp[njobs] = h
            jq[njobs] = q
            njobs = njobs + 1
            if d > max_d {
                max_d = d
            }
        }
    }

    heap_sort(jd, jp, jq, njobs)

    # 0/1 knapsack DP over time. dp[t] = max profit with total time exactly t.
    let sz: i64 = max_d + 1
    let dp: ptr<i64> = calloc(sz, 8)
    if dp == null {
        return 1
    }
    for i in 0..sz {
        dp[i] = -1
    }
    dp[0] = 0

    for j in 0..njobs {
        let d: i64 = jd[j]
        let pp: i64 = jp[j]
        let profit: i64 = jq[j]
        let mut t: i64 = d
        while t >= pp {
            if dp[t - pp] != -1 {
                let cand: i64 = dp[t - pp] + profit
                if cand > dp[t] {
                    dp[t] = cand
                }
            }
            t = t - 1
        }
    }

    let mut best: i64 = 0
    for i in 0..sz {
        if dp[i] > best {
            best = dp[i]
        }
    }

    printf("%lld\n", best)
    free(dp)
    free(jq)
    free(jp)
    free(jd)
    free(r)
    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_ll_i64(int64_t x);
int64_t ceil_div_sqrt2_i64(int64_t s);
void sift_down_ptr_i64_ptr_i64_ptr_i64_i32_i32(int64_t* d, int64_t* p, int64_t* prof, int32_t start, int32_t end);
void heap_sort_ptr_i64_ptr_i64_ptr_i64_i32(int64_t* d, int64_t* p, int64_t* prof, int32_t n);
int32_t main(void);



int64_t isqrt_ll_i64(int64_t x) {
    if (x < 0) {
        return 0;
    }
    if (x < 2) {
        return x;
    }
    int64_t x0 = x;
    int64_t x1 = FLOW_CHECKED_DIV(((x0 + 1)), (2));
    while (x1 < x0) {
        x0 = x1;
        x1 = FLOW_CHECKED_DIV(((x0 + FLOW_CHECKED_DIV((x), (x0)))), (2));
    }
    return x0;
}

int64_t ceil_div_sqrt2_i64(int64_t s) {
    int64_t a = (s * s);
    return (isqrt_ll_i64(FLOW_CHECKED_DIV(((a - 1)), (2))) + 1);
}

void sift_down_ptr_i64_ptr_i64_ptr_i64_i32_i32(int64_t* d, int64_t* p, int64_t* prof, 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 (d[child] < d[(child + 1)]) {
                child = (child + 1);
            }
        }
        if (d[root] < d[child]) {
            int64_t td = d[root];
            d[root] = d[child];
            d[child] = td;
            int64_t tp = p[root];
            p[root] = p[child];
            p[child] = tp;
            int64_t tq = prof[root];
            prof[root] = prof[child];
            prof[child] = tq;
            root = child;
        } else {
            return;
        }
    }
}

void heap_sort_ptr_i64_ptr_i64_ptr_i64_i32(int64_t* d, int64_t* p, int64_t* prof, int32_t n) {
    int32_t start = FLOW_CHECKED_DIV(((n - 2)), (2));
    while (start >= 0) {
        sift_down_ptr_i64_ptr_i64_ptr_i64_i32_i32(d, p, prof, start, (n - 1));
        start = (start - 1);
    }
    int32_t end = (n - 1);
    while (end > 0) {
        int64_t td = d[0];
        d[0] = d[end];
        d[end] = td;
        int64_t tp = p[0];
        p[0] = p[end];
        p[end] = tp;
        int64_t tq = prof[0];
        prof[0] = prof[end];
        prof[end] = tq;
        end = (end - 1);
        sift_down_ptr_i64_ptr_i64_ptr_i64_i32_i32(d, p, prof, 0, end);
    }
}

int32_t main(void) {
    int32_t n = 1000;
    int32_t total_r = (3 * n);
    int64_t* r = (int64_t*)(calloc(((int64_t)(total_r)), 8));
    if (r == NULL) {
        return 1;
    }
    int64_t p = 1;
    int32_t __flow_step_1 = 1;
    for (int32_t i = 0; (0 <= total_r) ? i < total_r : i > total_r; i += (0 <= total_r) ? 1 : -1) {
        r[i] = (FLOW_CHECKED_MOD((p), (101)) + 50);
        p = FLOW_CHECKED_MOD(((p * 5)), (1000000007));
    }
    int64_t total_h = 0;
    int32_t __flow_step_2 = 1;
    for (int32_t k = 0; (0 <= n) ? k < n : k > n; k += (0 <= n) ? 1 : -1) {
        total_h = (total_h + r[(3 * k)]);
    }
    int64_t y = ceil_div_sqrt2_i64(total_h);
    int64_t base = (total_h - y);
    int64_t* jd = (int64_t*)(calloc(((int64_t)(n)), 8));
    int64_t* jp = (int64_t*)(calloc(((int64_t)(n)), 8));
    int64_t* jq = (int64_t*)(calloc(((int64_t)(n)), 8));
    if (((jd == NULL || jp == NULL) || jq == NULL)) {
        return 1;
    }
    int32_t njobs = 0;
    int64_t max_d = 0;
    int32_t __flow_step_3 = 1;
    for (int32_t k = 0; (0 <= n) ? k < n : k > n; k += (0 <= n) ? 1 : -1) {
        int64_t h = r[(3 * k)];
        int64_t l = r[((3 * k) + 1)];
        int64_t q = r[((3 * k) + 2)];
        int64_t d = ((base + l) + h);
        if (h <= d) {
            jd[njobs] = d;
            jp[njobs] = h;
            jq[njobs] = q;
            njobs = (njobs + 1);
            if (d > max_d) {
                max_d = d;
            }
        }
    }
    heap_sort_ptr_i64_ptr_i64_ptr_i64_i32(jd, jp, jq, njobs);
    int64_t sz = (max_d + 1);
    int64_t* dp = (int64_t*)(calloc(sz, 8));
    if (dp == NULL) {
        return 1;
    }
    int32_t __flow_step_4 = 1;
    for (int32_t i = 0; (0 <= sz) ? i < sz : i > sz; i += (0 <= sz) ? 1 : -1) {
        dp[i] = (-1);
    }
    dp[0] = 0;
    int32_t __flow_step_5 = 1;
    for (int32_t j = 0; (0 <= njobs) ? j < njobs : j > njobs; j += (0 <= njobs) ? 1 : -1) {
        int64_t d = jd[j];
        int64_t pp = jp[j];
        int64_t profit = jq[j];
        int64_t t = d;
        while (t >= pp) {
            if (dp[(t - pp)] != (-1)) {
                int64_t cand = (dp[(t - pp)] + profit);
                if (cand > dp[t]) {
                    dp[t] = cand;
                }
            }
            t = (t - 1);
        }
    }
    int64_t best = 0;
    int32_t __flow_step_6 = 1;
    for (int32_t i = 0; (0 <= sz) ? i < sz : i > sz; i += (0 <= sz) ? 1 : -1) {
        if (dp[i] > best) {
            best = dp[i];
        }
    }
    printf("%lld\n", best);
    free(dp);
    free(jq);
    free(jp);
    free(jd);
    free(r);
    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_ll(%arg0: i64) -> i64 {
    %0 = arith.constant 0 : i32
    %2 = arith.extsi %0 : i32 to i64
    %1 = arith.cmpi slt, %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 = arith.constant 2 : i32
    %7 = arith.extsi %5 : i32 to i64
    %6 = arith.cmpi slt, %arg0, %7 : i64
    cf.cond_br %6, ^bb3, ^bb4
    ^bb3:
      func.return %arg0 : i64
    ^bb4:
      cf.br ^bb5
    ^bb5:
    %8 = llvm.mlir.constant(1 : i64) : i64
    %9 = llvm.alloca %8 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %9 : i64, !llvm.ptr
    %10 = llvm.load %9 : !llvm.ptr -> i64
    %11 = arith.constant 1 : i32
    %13 = arith.extsi %11 : i32 to i64
    %12 = arith.addi %10, %13 : i64
    %14 = arith.constant 2 : i32
    %16 = arith.extsi %14 : i32 to i64
    %15 = arith.divsi %12, %16 : i64
    %17 = llvm.mlir.constant(1 : i64) : i64
    %18 = llvm.alloca %17 x i64 : (i64) -> !llvm.ptr
    llvm.store %15, %18 : i64, !llvm.ptr
    cf.br ^bb6
    ^bb6:
    %19 = llvm.load %18 : !llvm.ptr -> i64
    %20 = llvm.load %9 : !llvm.ptr -> i64
    %21 = arith.cmpi slt, %19, %20 : i64
    cf.cond_br %21, ^bb7, ^bb8
    ^bb7:
      %22 = llvm.load %18 : !llvm.ptr -> i64
      llvm.store %22, %9 : i64, !llvm.ptr
      %23 = llvm.load %9 : !llvm.ptr -> i64
      %24 = llvm.load %9 : !llvm.ptr -> i64
      %25 = arith.divsi %arg0, %24 : i64
      %26 = arith.addi %23, %25 : i64
      %27 = arith.constant 2 : i32
      %29 = arith.extsi %27 : i32 to i64
      %28 = arith.divsi %26, %29 : i64
      llvm.store %28, %18 : i64, !llvm.ptr
      cf.br ^bb6
    ^bb8:
    %30 = llvm.load %9 : !llvm.ptr -> i64
    func.return %30 : i64
  }
  func.func @ceil_div_sqrt2(%arg0: i64) -> i64 {
    %31 = arith.muli %arg0, %arg0 : i64
    %33 = arith.constant 1 : i32
    %35 = arith.extsi %33 : i32 to i64
    %34 = arith.subi %31, %35 : i64
    %36 = arith.constant 2 : i32
    %38 = arith.extsi %36 : i32 to i64
    %37 = arith.divsi %34, %38 : i64
    %32 = func.call @isqrt_ll(%37) : (i64) -> i64
    %39 = arith.constant 1 : i32
    %41 = arith.extsi %39 : i32 to i64
    %40 = arith.addi %32, %41 : i64
    func.return %40 : i64
  }
  func.func @sift_down(%arg0: !llvm.ptr, %arg1: !llvm.ptr, %arg2: !llvm.ptr, %arg3: i32, %arg4: i32) -> () {
    %42 = llvm.mlir.constant(1 : i64) : i64
    %43 = llvm.alloca %42 x i32 : (i64) -> !llvm.ptr
    llvm.store %arg3, %43 : i32, !llvm.ptr
    cf.br ^bb9
    ^bb9:
    %44 = arith.constant 2 : i32
    %45 = llvm.load %43 : !llvm.ptr -> i32
    %46 = arith.muli %44, %45 : i32
    %47 = arith.constant 1 : i32
    %48 = arith.addi %46, %47 : i32
    %49 = arith.cmpi sle, %48, %arg4 : i32
    cf.cond_br %49, ^bb10, ^bb11
    ^bb10:
      %50 = arith.constant 2 : i32
      %51 = llvm.load %43 : !llvm.ptr -> i32
      %52 = arith.muli %50, %51 : i32
      %53 = arith.constant 1 : i32
      %54 = arith.addi %52, %53 : i32
      %55 = llvm.mlir.constant(1 : i64) : i64
      %56 = llvm.alloca %55 x i32 : (i64) -> !llvm.ptr
      llvm.store %54, %56 : i32, !llvm.ptr
      %57 = llvm.load %56 : !llvm.ptr -> i32
      %58 = arith.constant 1 : i32
      %59 = arith.addi %57, %58 : i32
      %60 = arith.cmpi sle, %59, %arg4 : i32
      cf.cond_br %60, ^bb12, ^bb13
      ^bb12:
        %62 = llvm.load %56 : !llvm.ptr -> i32
        %63 = arith.extsi %62 : i32 to i64
        %64 = llvm.getelementptr %arg0[%63] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %61 = llvm.load %64 : !llvm.ptr -> i64
        %66 = llvm.load %56 : !llvm.ptr -> i32
        %67 = arith.constant 1 : i32
        %68 = arith.addi %66, %67 : i32
        %69 = arith.extsi %68 : i32 to i64
        %70 = llvm.getelementptr %arg0[%69] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %65 = llvm.load %70 : !llvm.ptr -> i64
        %71 = arith.cmpi slt, %61, %65 : i64
        cf.cond_br %71, ^bb15, ^bb16
        ^bb15:
          %72 = llvm.load %56 : !llvm.ptr -> i32
          %73 = arith.constant 1 : i32
          %74 = arith.addi %72, %73 : i32
          llvm.store %74, %56 : i32, !llvm.ptr
          cf.br ^bb17
        ^bb16:
          cf.br ^bb17
        ^bb17:
        cf.br ^bb14
      ^bb13:
        cf.br ^bb14
      ^bb14:
      %76 = llvm.load %43 : !llvm.ptr -> i32
      %77 = arith.extsi %76 : i32 to i64
      %78 = llvm.getelementptr %arg0[%77] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %75 = llvm.load %78 : !llvm.ptr -> i64
      %80 = llvm.load %56 : !llvm.ptr -> i32
      %81 = arith.extsi %80 : i32 to i64
      %82 = llvm.getelementptr %arg0[%81] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %79 = llvm.load %82 : !llvm.ptr -> i64
      %83 = arith.cmpi slt, %75, %79 : i64
      cf.cond_br %83, ^bb18, ^bb19
      ^bb18:
        %85 = llvm.load %43 : !llvm.ptr -> i32
        %86 = arith.extsi %85 : i32 to i64
        %87 = llvm.getelementptr %arg0[%86] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %84 = llvm.load %87 : !llvm.ptr -> i64
        %89 = llvm.load %56 : !llvm.ptr -> i32
        %90 = arith.extsi %89 : i32 to i64
        %91 = llvm.getelementptr %arg0[%90] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %88 = llvm.load %91 : !llvm.ptr -> i64
        %92 = llvm.load %43 : !llvm.ptr -> i32
        %93 = arith.extsi %92 : i32 to i64
        %94 = llvm.getelementptr %arg0[%93] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %88, %94 : i64, !llvm.ptr
        %95 = llvm.load %56 : !llvm.ptr -> i32
        %96 = arith.extsi %95 : i32 to i64
        %97 = llvm.getelementptr %arg0[%96] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %84, %97 : i64, !llvm.ptr
        %99 = llvm.load %43 : !llvm.ptr -> i32
        %100 = arith.extsi %99 : i32 to i64
        %101 = llvm.getelementptr %arg1[%100] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %98 = llvm.load %101 : !llvm.ptr -> i64
        %103 = llvm.load %56 : !llvm.ptr -> i32
        %104 = arith.extsi %103 : i32 to i64
        %105 = llvm.getelementptr %arg1[%104] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %102 = llvm.load %105 : !llvm.ptr -> i64
        %106 = llvm.load %43 : !llvm.ptr -> i32
        %107 = arith.extsi %106 : i32 to i64
        %108 = llvm.getelementptr %arg1[%107] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %102, %108 : i64, !llvm.ptr
        %109 = llvm.load %56 : !llvm.ptr -> i32
        %110 = arith.extsi %109 : i32 to i64
        %111 = llvm.getelementptr %arg1[%110] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %98, %111 : i64, !llvm.ptr
        %113 = llvm.load %43 : !llvm.ptr -> i32
        %114 = arith.extsi %113 : i32 to i64
        %115 = llvm.getelementptr %arg2[%114] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %112 = llvm.load %115 : !llvm.ptr -> i64
        %117 = llvm.load %56 : !llvm.ptr -> i32
        %118 = arith.extsi %117 : i32 to i64
        %119 = llvm.getelementptr %arg2[%118] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %116 = llvm.load %119 : !llvm.ptr -> i64
        %120 = llvm.load %43 : !llvm.ptr -> i32
        %121 = arith.extsi %120 : i32 to i64
        %122 = llvm.getelementptr %arg2[%121] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %116, %122 : i64, !llvm.ptr
        %123 = llvm.load %56 : !llvm.ptr -> i32
        %124 = arith.extsi %123 : i32 to i64
        %125 = llvm.getelementptr %arg2[%124] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %112, %125 : i64, !llvm.ptr
        %126 = llvm.load %56 : !llvm.ptr -> i32
        llvm.store %126, %43 : i32, !llvm.ptr
        cf.br ^bb20
      ^bb19:
        func.return
      ^bb20:
      cf.br ^bb9
    ^bb11:
    func.return
  }
  func.func @heap_sort(%arg0: !llvm.ptr, %arg1: !llvm.ptr, %arg2: !llvm.ptr, %arg3: i32) -> () {
    %127 = arith.constant 2 : i32
    %128 = arith.subi %arg3, %127 : i32
    %129 = arith.constant 2 : i32
    %130 = arith.divsi %128, %129 : i32
    %131 = llvm.mlir.constant(1 : i64) : i64
    %132 = llvm.alloca %131 x i32 : (i64) -> !llvm.ptr
    llvm.store %130, %132 : i32, !llvm.ptr
    cf.br ^bb21
    ^bb21:
    %133 = llvm.load %132 : !llvm.ptr -> i32
    %134 = arith.constant 0 : i32
    %135 = arith.cmpi sge, %133, %134 : i32
    cf.cond_br %135, ^bb22, ^bb23
    ^bb22:
      %137 = llvm.load %132 : !llvm.ptr -> i32
      %138 = arith.constant 1 : i32
      %139 = arith.subi %arg3, %138 : i32
      func.call @sift_down(%arg0, %arg1, %arg2, %137, %139) : (!llvm.ptr, !llvm.ptr, !llvm.ptr, i32, i32) -> ()
      %140 = llvm.load %132 : !llvm.ptr -> i32
      %141 = arith.constant 1 : i32
      %142 = arith.subi %140, %141 : i32
      llvm.store %142, %132 : i32, !llvm.ptr
      cf.br ^bb21
    ^bb23:
    %143 = arith.constant 1 : i32
    %144 = arith.subi %arg3, %143 : i32
    %145 = llvm.mlir.constant(1 : i64) : i64
    %146 = llvm.alloca %145 x i32 : (i64) -> !llvm.ptr
    llvm.store %144, %146 : i32, !llvm.ptr
    cf.br ^bb24
    ^bb24:
    %147 = llvm.load %146 : !llvm.ptr -> i32
    %148 = arith.constant 0 : i32
    %149 = arith.cmpi sgt, %147, %148 : i32
    cf.cond_br %149, ^bb25, ^bb26
    ^bb25:
      %151 = arith.constant 0 : i32
      %152 = arith.extsi %151 : i32 to i64
      %153 = llvm.getelementptr %arg0[%152] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %150 = llvm.load %153 : !llvm.ptr -> i64
      %155 = llvm.load %146 : !llvm.ptr -> i32
      %156 = arith.extsi %155 : i32 to i64
      %157 = llvm.getelementptr %arg0[%156] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %154 = llvm.load %157 : !llvm.ptr -> i64
      %158 = arith.constant 0 : i32
      %159 = arith.extsi %158 : i32 to i64
      %160 = llvm.getelementptr %arg0[%159] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %154, %160 : i64, !llvm.ptr
      %161 = llvm.load %146 : !llvm.ptr -> i32
      %162 = arith.extsi %161 : i32 to i64
      %163 = llvm.getelementptr %arg0[%162] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %150, %163 : i64, !llvm.ptr
      %165 = arith.constant 0 : i32
      %166 = arith.extsi %165 : i32 to i64
      %167 = llvm.getelementptr %arg1[%166] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %164 = llvm.load %167 : !llvm.ptr -> i64
      %169 = llvm.load %146 : !llvm.ptr -> i32
      %170 = arith.extsi %169 : i32 to i64
      %171 = llvm.getelementptr %arg1[%170] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %168 = llvm.load %171 : !llvm.ptr -> i64
      %172 = arith.constant 0 : i32
      %173 = arith.extsi %172 : i32 to i64
      %174 = llvm.getelementptr %arg1[%173] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %168, %174 : i64, !llvm.ptr
      %175 = llvm.load %146 : !llvm.ptr -> i32
      %176 = arith.extsi %175 : i32 to i64
      %177 = llvm.getelementptr %arg1[%176] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %164, %177 : i64, !llvm.ptr
      %179 = arith.constant 0 : i32
      %180 = arith.extsi %179 : i32 to i64
      %181 = llvm.getelementptr %arg2[%180] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %178 = llvm.load %181 : !llvm.ptr -> i64
      %183 = llvm.load %146 : !llvm.ptr -> i32
      %184 = arith.extsi %183 : i32 to i64
      %185 = llvm.getelementptr %arg2[%184] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %182 = llvm.load %185 : !llvm.ptr -> i64
      %186 = arith.constant 0 : i32
      %187 = arith.extsi %186 : i32 to i64
      %188 = llvm.getelementptr %arg2[%187] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %182, %188 : i64, !llvm.ptr
      %189 = llvm.load %146 : !llvm.ptr -> i32
      %190 = arith.extsi %189 : i32 to i64
      %191 = llvm.getelementptr %arg2[%190] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %178, %191 : i64, !llvm.ptr
      %192 = llvm.load %146 : !llvm.ptr -> i32
      %193 = arith.constant 1 : i32
      %194 = arith.subi %192, %193 : i32
      llvm.store %194, %146 : i32, !llvm.ptr
      %196 = arith.constant 0 : i32
      %197 = llvm.load %146 : !llvm.ptr -> i32
      func.call @sift_down(%arg0, %arg1, %arg2, %196, %197) : (!llvm.ptr, !llvm.ptr, !llvm.ptr, i32, i32) -> ()
      cf.br ^bb24
    ^bb26:
    func.return
  }
  func.func @main() -> i32 {
    %198 = arith.constant 1000 : i32
    %199 = arith.constant 3 : i32
    %200 = arith.muli %199, %198 : i32
    %202 = arith.extsi %200 : i32 to i64
    %203 = arith.constant 8 : i32
    %204 = arith.extsi %203 : i32 to i64
    %201 = func.call @calloc(%202, %204) : (i64, i64) -> !llvm.ptr
    %205 = llvm.mlir.zero : !llvm.ptr
    %206 = llvm.icmp "eq" %201, %205 : !llvm.ptr
    cf.cond_br %206, ^bb27, ^bb28
    ^bb27:
      %207 = arith.constant 1 : i32
      func.return %207 : i32
    ^bb28:
      cf.br ^bb29
    ^bb29:
    %208 = arith.constant 1 : i32
    %209 = arith.extsi %208 : i32 to i64
    %210 = llvm.mlir.constant(1 : i64) : i64
    %211 = llvm.alloca %210 x i64 : (i64) -> !llvm.ptr
    llvm.store %209, %211 : i64, !llvm.ptr
    %212 = arith.constant 0 : i32
    %213 = arith.index_cast %212 : i32 to index
    %214 = arith.index_cast %200 : i32 to index
    %216 = arith.constant 1 : index
    %217 = arith.constant -1 : index
    %218 = arith.cmpi sle, %213, %214 : index
    %215 = arith.select %218, %216, %217 : index
    cf.br ^bb30(%213 : index)
    ^bb30(%219: index):
    %220 = arith.cmpi slt, %219, %214 : index
    %221 = arith.cmpi sgt, %219, %214 : index
    %222 = arith.select %218, %220, %221 : i1
    cf.cond_br %222, ^bb31(%219 : index), ^bb32(%219 : index)
    ^bb31(%223: index):
      %224 = llvm.load %211 : !llvm.ptr -> i64
      %225 = arith.constant 101 : i32
      %227 = arith.extsi %225 : i32 to i64
      %226 = arith.remsi %224, %227 : i64
      %228 = arith.constant 50 : i32
      %230 = arith.extsi %228 : i32 to i64
      %229 = arith.addi %226, %230 : i64
      %231 = arith.index_cast %223 : index to i64
      %232 = llvm.getelementptr %201[%231] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %229, %232 : i64, !llvm.ptr
      %233 = llvm.load %211 : !llvm.ptr -> i64
      %234 = arith.constant 5 : i32
      %236 = arith.extsi %234 : i32 to i64
      %235 = arith.muli %233, %236 : i64
      %237 = arith.constant 1000000007 : i32
      %239 = arith.extsi %237 : i32 to i64
      %238 = arith.remsi %235, %239 : i64
      llvm.store %238, %211 : i64, !llvm.ptr
      %240 = arith.addi %223, %215 : index
      cf.br ^bb30(%240 : index)
    ^bb32(%241: index):
    %242 = arith.constant 0 : i32
    %243 = arith.extsi %242 : i32 to i64
    %244 = llvm.mlir.constant(1 : i64) : i64
    %245 = llvm.alloca %244 x i64 : (i64) -> !llvm.ptr
    llvm.store %243, %245 : i64, !llvm.ptr
    %246 = arith.constant 0 : i32
    %247 = arith.index_cast %246 : i32 to index
    %248 = arith.index_cast %198 : i32 to index
    %250 = arith.constant 1 : index
    %251 = arith.constant -1 : index
    %252 = arith.cmpi sle, %247, %248 : index
    %249 = arith.select %252, %250, %251 : index
    cf.br ^bb33(%247 : index)
    ^bb33(%253: index):
    %254 = arith.cmpi slt, %253, %248 : index
    %255 = arith.cmpi sgt, %253, %248 : index
    %256 = arith.select %252, %254, %255 : i1
    cf.cond_br %256, ^bb34(%253 : index), ^bb35(%253 : index)
    ^bb34(%257: index):
      %258 = llvm.load %245 : !llvm.ptr -> i64
      %260 = arith.constant 3 : i32
      %262 = arith.index_cast %257 : index to i32
      %261 = arith.muli %260, %262 : i32
      %263 = arith.extsi %261 : i32 to i64
      %264 = llvm.getelementptr %201[%263] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %259 = llvm.load %264 : !llvm.ptr -> i64
      %265 = arith.addi %258, %259 : i64
      llvm.store %265, %245 : i64, !llvm.ptr
      %266 = arith.addi %257, %249 : index
      cf.br ^bb33(%266 : index)
    ^bb35(%267: index):
    %269 = llvm.load %245 : !llvm.ptr -> i64
    %268 = func.call @ceil_div_sqrt2(%269) : (i64) -> i64
    %270 = llvm.load %245 : !llvm.ptr -> i64
    %271 = arith.subi %270, %268 : i64
    %273 = arith.extsi %198 : i32 to i64
    %274 = arith.constant 8 : i32
    %275 = arith.extsi %274 : i32 to i64
    %272 = func.call @calloc(%273, %275) : (i64, i64) -> !llvm.ptr
    %277 = arith.extsi %198 : i32 to i64
    %278 = arith.constant 8 : i32
    %279 = arith.extsi %278 : i32 to i64
    %276 = func.call @calloc(%277, %279) : (i64, i64) -> !llvm.ptr
    %281 = arith.extsi %198 : i32 to i64
    %282 = arith.constant 8 : i32
    %283 = arith.extsi %282 : i32 to i64
    %280 = func.call @calloc(%281, %283) : (i64, i64) -> !llvm.ptr
    %284 = llvm.mlir.zero : !llvm.ptr
    %285 = llvm.icmp "eq" %272, %284 : !llvm.ptr
    %286 = scf.if %285 -> (i1) {
      %287 = arith.constant true
      scf.yield %287 : i1
    } else {
      %288 = llvm.mlir.zero : !llvm.ptr
      %289 = llvm.icmp "eq" %276, %288 : !llvm.ptr
      scf.yield %289 : i1
    }
    %290 = scf.if %286 -> (i1) {
      %291 = arith.constant true
      scf.yield %291 : i1
    } else {
      %292 = llvm.mlir.zero : !llvm.ptr
      %293 = llvm.icmp "eq" %280, %292 : !llvm.ptr
      scf.yield %293 : i1
    }
    cf.cond_br %290, ^bb36, ^bb37
    ^bb36:
      %294 = arith.constant 1 : i32
      func.return %294 : i32
    ^bb37:
      cf.br ^bb38
    ^bb38:
    %295 = arith.constant 0 : i32
    %296 = llvm.mlir.constant(1 : i64) : i64
    %297 = llvm.alloca %296 x i32 : (i64) -> !llvm.ptr
    llvm.store %295, %297 : i32, !llvm.ptr
    %298 = arith.constant 0 : i32
    %299 = arith.extsi %298 : i32 to i64
    %300 = llvm.mlir.constant(1 : i64) : i64
    %301 = llvm.alloca %300 x i64 : (i64) -> !llvm.ptr
    llvm.store %299, %301 : i64, !llvm.ptr
    %302 = arith.constant 0 : i32
    %303 = arith.index_cast %302 : i32 to index
    %304 = arith.index_cast %198 : i32 to index
    %306 = arith.constant 1 : index
    %307 = arith.constant -1 : index
    %308 = arith.cmpi sle, %303, %304 : index
    %305 = arith.select %308, %306, %307 : index
    cf.br ^bb39(%303 : index)
    ^bb39(%309: index):
    %310 = arith.cmpi slt, %309, %304 : index
    %311 = arith.cmpi sgt, %309, %304 : index
    %312 = arith.select %308, %310, %311 : i1
    cf.cond_br %312, ^bb40(%309 : index), ^bb41(%309 : index)
    ^bb40(%313: index):
      %315 = arith.constant 3 : i32
      %317 = arith.index_cast %313 : index to i32
      %316 = arith.muli %315, %317 : i32
      %318 = arith.extsi %316 : i32 to i64
      %319 = llvm.getelementptr %201[%318] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %314 = llvm.load %319 : !llvm.ptr -> i64
      %321 = arith.constant 3 : i32
      %323 = arith.index_cast %313 : index to i32
      %322 = arith.muli %321, %323 : i32
      %324 = arith.constant 1 : i32
      %325 = arith.addi %322, %324 : i32
      %326 = arith.extsi %325 : i32 to i64
      %327 = llvm.getelementptr %201[%326] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %320 = llvm.load %327 : !llvm.ptr -> i64
      %329 = arith.constant 3 : i32
      %331 = arith.index_cast %313 : index to i32
      %330 = arith.muli %329, %331 : i32
      %332 = arith.constant 2 : i32
      %333 = arith.addi %330, %332 : i32
      %334 = arith.extsi %333 : i32 to i64
      %335 = llvm.getelementptr %201[%334] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %328 = llvm.load %335 : !llvm.ptr -> i64
      %336 = arith.addi %271, %320 : i64
      %337 = arith.addi %336, %314 : i64
      %338 = arith.cmpi sle, %314, %337 : i64
      cf.cond_br %338, ^bb42, ^bb43
      ^bb42:
        %339 = llvm.load %297 : !llvm.ptr -> i32
        %340 = arith.extsi %339 : i32 to i64
        %341 = llvm.getelementptr %272[%340] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %337, %341 : i64, !llvm.ptr
        %342 = llvm.load %297 : !llvm.ptr -> i32
        %343 = arith.extsi %342 : i32 to i64
        %344 = llvm.getelementptr %276[%343] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %314, %344 : i64, !llvm.ptr
        %345 = llvm.load %297 : !llvm.ptr -> i32
        %346 = arith.extsi %345 : i32 to i64
        %347 = llvm.getelementptr %280[%346] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %328, %347 : i64, !llvm.ptr
        %348 = llvm.load %297 : !llvm.ptr -> i32
        %349 = arith.constant 1 : i32
        %350 = arith.addi %348, %349 : i32
        llvm.store %350, %297 : i32, !llvm.ptr
        %351 = llvm.load %301 : !llvm.ptr -> i64
        %352 = arith.cmpi sgt, %337, %351 : i64
        cf.cond_br %352, ^bb45, ^bb46
        ^bb45:
          llvm.store %337, %301 : i64, !llvm.ptr
          cf.br ^bb47
        ^bb46:
          cf.br ^bb47
        ^bb47:
        cf.br ^bb44
      ^bb43:
        cf.br ^bb44
      ^bb44:
      %353 = arith.addi %313, %305 : index
      cf.br ^bb39(%353 : index)
    ^bb41(%354: index):
    %356 = llvm.load %297 : !llvm.ptr -> i32
    func.call @heap_sort(%272, %276, %280, %356) : (!llvm.ptr, !llvm.ptr, !llvm.ptr, i32) -> ()
    %357 = llvm.load %301 : !llvm.ptr -> i64
    %358 = arith.constant 1 : i32
    %360 = arith.extsi %358 : i32 to i64
    %359 = arith.addi %357, %360 : i64
    %362 = arith.constant 8 : i32
    %363 = arith.extsi %362 : i32 to i64
    %361 = func.call @calloc(%359, %363) : (i64, i64) -> !llvm.ptr
    %364 = llvm.mlir.zero : !llvm.ptr
    %365 = llvm.icmp "eq" %361, %364 : !llvm.ptr
    cf.cond_br %365, ^bb48, ^bb49
    ^bb48:
      %366 = arith.constant 1 : i32
      func.return %366 : i32
    ^bb49:
      cf.br ^bb50
    ^bb50:
    %367 = arith.constant 0 : i32
    %368 = arith.index_cast %367 : i32 to index
    %369 = arith.index_cast %359 : i32 to index
    %371 = arith.constant 1 : index
    %372 = arith.constant -1 : index
    %373 = arith.cmpi sle, %368, %369 : index
    %370 = arith.select %373, %371, %372 : index
    cf.br ^bb51(%368 : index)
    ^bb51(%374: index):
    %375 = arith.cmpi slt, %374, %369 : index
    %376 = arith.cmpi sgt, %374, %369 : index
    %377 = arith.select %373, %375, %376 : i1
    cf.cond_br %377, ^bb52(%374 : index), ^bb53(%374 : index)
    ^bb52(%378: index):
      %379 = arith.constant 1 : i32
      %381 = arith.constant 0 : i32
      %380 = arith.subi %381, %379 : i32
      %382 = arith.extsi %380 : i32 to i64
      %383 = arith.index_cast %378 : index to i64
      %384 = llvm.getelementptr %361[%383] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %382, %384 : i64, !llvm.ptr
      %385 = arith.addi %378, %370 : index
      cf.br ^bb51(%385 : index)
    ^bb53(%386: index):
    %387 = arith.constant 0 : i32
    %388 = arith.constant 0 : i32
    %389 = arith.extsi %387 : i32 to i64
    %390 = arith.extsi %388 : i32 to i64
    %391 = llvm.getelementptr %361[%390] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %389, %391 : i64, !llvm.ptr
    %392 = arith.constant 0 : i32
    %393 = llvm.load %297 : !llvm.ptr -> i32
    %394 = arith.index_cast %392 : i32 to index
    %395 = arith.index_cast %393 : i32 to index
    %397 = arith.constant 1 : index
    %398 = arith.constant -1 : index
    %399 = arith.cmpi sle, %394, %395 : index
    %396 = arith.select %399, %397, %398 : index
    cf.br ^bb54(%394 : index)
    ^bb54(%400: index):
    %401 = arith.cmpi slt, %400, %395 : index
    %402 = arith.cmpi sgt, %400, %395 : index
    %403 = arith.select %399, %401, %402 : i1
    cf.cond_br %403, ^bb55(%400 : index), ^bb56(%400 : index)
    ^bb55(%404: index):
      %406 = arith.index_cast %404 : index to i64
      %407 = llvm.getelementptr %272[%406] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %405 = llvm.load %407 : !llvm.ptr -> i64
      %409 = arith.index_cast %404 : index to i64
      %410 = llvm.getelementptr %276[%409] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %408 = llvm.load %410 : !llvm.ptr -> i64
      %412 = arith.index_cast %404 : index to i64
      %413 = llvm.getelementptr %280[%412] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %411 = llvm.load %413 : !llvm.ptr -> i64
      %414 = llvm.mlir.constant(1 : i64) : i64
      %415 = llvm.alloca %414 x i64 : (i64) -> !llvm.ptr
      llvm.store %405, %415 : i64, !llvm.ptr
      cf.br ^bb57
      ^bb57:
      %416 = llvm.load %415 : !llvm.ptr -> i64
      %417 = arith.cmpi sge, %416, %408 : i64
      cf.cond_br %417, ^bb58, ^bb59
      ^bb58:
        %419 = llvm.load %415 : !llvm.ptr -> i64
        %420 = arith.subi %419, %408 : i64
        %421 = llvm.getelementptr %361[%420] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %418 = llvm.load %421 : !llvm.ptr -> i64
        %422 = arith.constant 1 : i32
        %424 = arith.constant 0 : i32
        %423 = arith.subi %424, %422 : i32
        %426 = arith.extsi %423 : i32 to i64
        %425 = arith.cmpi ne, %418, %426 : i64
        cf.cond_br %425, ^bb60, ^bb61
        ^bb60:
          %428 = llvm.load %415 : !llvm.ptr -> i64
          %429 = arith.subi %428, %408 : i64
          %430 = llvm.getelementptr %361[%429] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %427 = llvm.load %430 : !llvm.ptr -> i64
          %431 = arith.addi %427, %411 : i64
          %433 = llvm.load %415 : !llvm.ptr -> i64
          %434 = llvm.getelementptr %361[%433] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %432 = llvm.load %434 : !llvm.ptr -> i64
          %435 = arith.cmpi sgt, %431, %432 : i64
          cf.cond_br %435, ^bb63, ^bb64
          ^bb63:
            %436 = llvm.load %415 : !llvm.ptr -> i64
            %437 = llvm.getelementptr %361[%436] : (!llvm.ptr, i64) -> !llvm.ptr, i64
            llvm.store %431, %437 : i64, !llvm.ptr
            cf.br ^bb65
          ^bb64:
            cf.br ^bb65
          ^bb65:
          cf.br ^bb62
        ^bb61:
          cf.br ^bb62
        ^bb62:
        %438 = llvm.load %415 : !llvm.ptr -> i64
        %439 = arith.constant 1 : i32
        %441 = arith.extsi %439 : i32 to i64
        %440 = arith.subi %438, %441 : i64
        llvm.store %440, %415 : i64, !llvm.ptr
        cf.br ^bb57
      ^bb59:
      %442 = arith.addi %404, %396 : index
      cf.br ^bb54(%442 : index)
    ^bb56(%443: index):
    %444 = arith.constant 0 : i32
    %445 = arith.extsi %444 : i32 to i64
    %446 = llvm.mlir.constant(1 : i64) : i64
    %447 = llvm.alloca %446 x i64 : (i64) -> !llvm.ptr
    llvm.store %445, %447 : i64, !llvm.ptr
    %448 = arith.constant 0 : i32
    %449 = arith.index_cast %448 : i32 to index
    %450 = arith.index_cast %359 : i32 to index
    %452 = arith.constant 1 : index
    %453 = arith.constant -1 : index
    %454 = arith.cmpi sle, %449, %450 : index
    %451 = arith.select %454, %452, %453 : index
    cf.br ^bb66(%449 : index)
    ^bb66(%455: index):
    %456 = arith.cmpi slt, %455, %450 : index
    %457 = arith.cmpi sgt, %455, %450 : index
    %458 = arith.select %454, %456, %457 : i1
    cf.cond_br %458, ^bb67(%455 : index), ^bb68(%455 : index)
    ^bb67(%459: index):
      %461 = arith.index_cast %459 : index to i64
      %462 = llvm.getelementptr %361[%461] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %460 = llvm.load %462 : !llvm.ptr -> i64
      %463 = llvm.load %447 : !llvm.ptr -> i64
      %464 = arith.cmpi sgt, %460, %463 : i64
      cf.cond_br %464, ^bb69, ^bb70
      ^bb69:
        %466 = arith.index_cast %459 : index to i64
        %467 = llvm.getelementptr %361[%466] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %465 = llvm.load %467 : !llvm.ptr -> i64
        llvm.store %465, %447 : i64, !llvm.ptr
        cf.br ^bb71
      ^bb70:
        cf.br ^bb71
      ^bb71:
      %468 = arith.addi %459, %451 : index
      cf.br ^bb66(%468 : index)
    ^bb68(%469: index):
    %470 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %471 = llvm.load %447 : !llvm.ptr -> i64
    %472 = llvm.call @printf(%470, %471) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    func.call @free(%361) : (!llvm.ptr) -> ()
    func.call @free(%280) : (!llvm.ptr) -> ()
    func.call @free(%276) : (!llvm.ptr) -> ()
    func.call @free(%272) : (!llvm.ptr) -> ()
    func.call @free(%201) : (!llvm.ptr) -> ()
    %478 = arith.constant 0 : i32
    func.return %478 : i32
  }
}