#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ time_t;
typedef int /*<<< orphan*/ arr;

/* Variables and functions */
scalar_t__ malloc(int);
int /*<<< orphan*/ min_heap_sort(int *, int);
int /*<<< orphan*/ print_heap(int *, int);
int rand();
int /*<<< orphan*/ srand(unsigned int);
scalar_t__ time(int /*<<< orphan*/ *);
int main() {
  int a_len = 20;
  int *a = (int *)malloc(sizeof(int) * a_len);
  time_t t;
  srand((unsigned)time(&t));
  for (int i = 0; i < a_len; i++)
    a[i] = rand() % 10000 + 1;
  min_heap_sort(a, a_len);
  print_heap(a, a_len);
  int arr[] = {4, 1, 3, 2, 16, 9, 10, 14, 8, 7};
  int len = sizeof(arr) / sizeof(int);
  min_heap_sort(arr, len);
  print_heap(arr, len);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x14,-0x8(%rbp)
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
lea    -0x14(%rbp),%rdi
call   1050 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11e7 <main+0x77>
mov    $0x0,%al
call   1090 <rand@plt>
mov    $0x2710,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11b0 <main+0x40>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1070 <min_heap_sort@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1080 <print_heap@plt>
lea    -0x40(%rbp),%rdi
lea    0xdf6(%rip),%rsi
mov    $0x28,%edx
call   1040 <memcpy@plt>
movl   $0xa,-0x44(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x44(%rbp),%esi
call   1070 <min_heap_sort@plt>
lea    -0x40(%rbp),%rdi
mov    -0x44(%rbp),%esi
call   1080 <print_heap@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    $0x50,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
lea    0xc(%rsp),%rdi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1080 <rand@plt>
cltq
imul   $0x68db8bad,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x2c,%rcx
add    %edx,%ecx
imul   $0x2710,%ecx,%ecx
neg    %ecx
add    %ecx,%eax
add    $0x1,%eax
mov    %eax,(%r14,%rbx,4)
add    $0x1,%rbx
cmp    $0x14,%rbx
jne    1190 <main+0x30>
mov    %r14,%rdi
mov    $0x14,%esi
call   1060 <min_heap_sort@plt>
mov    %r14,%rdi
mov    $0x14,%esi
call   1070 <print_heap@plt>
mov    0xe37(%rip),%rax
mov    %rax,0x30(%rsp)
movaps 0xe1b(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xdff(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xa,%esi
call   1060 <min_heap_sort@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1070 <print_heap@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.arr = [10 x i32] [i32 4, i32 1, i32 3, i32 2, i32 16, i32 9, i32 10, i32 14, i32 8, i32 7]
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [10 x i32]
%7 = alloca i32
store i32 0, i32* %1
store i32 20, i32* %2
%8 = load i32, i32* %2
%9 = sext i32 %8 to i64
%10 = mul i64 4, %9
%11 = trunc i64 %10 to i32
%12 = call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i32*
store i32* %13, i32** %3
%14 = call i64 @time(i32* %4)
%15 = trunc i64 %14 to i32
%16 = call i32 @srand(i32 %15)
store i32 0, i32* %5
br label %17
17: ; preds = %29, %0
%18 = load i32, i32* %5
%19 = load i32, i32* %2
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %32
21: ; preds = %17
%22 = call i32 (...) @rand()
%23 = srem i32 %22, 10000
%24 = add nsw i32 %23, 1
%25 = load i32*, i32** %3
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %25, i64 %27
store i32 %24, i32* %28
br label %29
29: ; preds = %21
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
store i32 %31, i32* %5
br label %17
32: ; preds = %17
%33 = load i32*, i32** %3
%34 = load i32, i32* %2
%35 = call i32 @min_heap_sort(i32* %33, i32 %34)
%36 = load i32*, i32** %3
%37 = load i32, i32* %2
%38 = call i32 @print_heap(i32* %36, i32 %37)
%39 = bitcast [10 x i32]* %6 to i8*
store i32 10, i32* %7
%40 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 0
%41 = load i32, i32* %7
%42 = call i32 @min_heap_sort(i32* %40, i32 %41)
%43 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 0
%44 = load i32, i32* %7
%45 = call i32 @print_heap(i32* %43, i32 %44)
ret i32 0
}

LLVM IR (-O2):
@__const.main.arr = [10 x i32] [i32 4, i32 1, i32 3, i32 2, i32 16, i32 9, i32 10, i32 14, i32 8, i32 7]
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i32]
%3 = tail call i64 @malloc(i32 80)
%4 = inttoptr i64 %3 to i32*
%5 = bitcast i32* %1 to i8*
%6 = call i64 @time(i32* %1)
%7 = trunc i64 %6 to i32
%8 = call i32 @srand(i32 %7)
br label %16
9: ; preds = %16
%10 = call i32 @min_heap_sort(i32* %4, i32 20)
%11 = call i32 @print_heap(i32* %4, i32 20)
%12 = bitcast [10 x i32]* %2 to i8*
%13 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%14 = call i32 @min_heap_sort(i32* %13, i32 10)
%15 = call i32 @print_heap(i32* %13, i32 10)
ret i32 0
16: ; preds = %0, %16
%17 = phi i64 [ 0, %0 ], [ %22, %16 ]
%18 = call i32 (...) @rand()
%19 = srem i32 %18, 10000
%20 = add nsw i32 %19, 1
%21 = getelementptr inbounds i32, i32* %4, i64 %17
store i32 %20, i32* %21
%22 = add nuw nsw i64 %17, 1
%23 = icmp eq i64 %22, 20
br i1 %23, label %9, label %16
}