#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 */

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ heap_sort(int *);
int *malloc(int);
int /*<<< orphan*/ print_tree(int *, int);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(void) {
  int i;
  int *arr;
  srand(time(NULL));
  arr = malloc(sizeof(int) * 100);
  for (i = 0; i < 100; i++) {
    arr[i] = rand() % 1000;
  }
  i = 0;
  print_tree(arr, 1);
  heap_sort(arr);
  print_tree(arr, 1);
  free(arr);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
mov    $0x190,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x64,-0x8(%rbp)
jge    11e6 <main+0x66>
mov    $0x0,%al
call   10a0 <rand@plt>
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11b4 <main+0x34>
movl   $0x0,-0x8(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1080 <print_tree@plt>
mov    -0x10(%rbp),%rdi
call   1040 <heap_sort@plt>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1080 <print_tree@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
mov    $0x190,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   10a0 <rand@plt>
cltq
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
imul   $0x3e8,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,(%r14,%rbx,4)
add    $0x1,%rbx
cmp    $0x64,%rbx
jne    11b0 <main+0x30>
mov    %r14,%rdi
mov    $0x1,%esi
call   1080 <print_tree@plt>
mov    %r14,%rdi
call   1040 <heap_sort@plt>
mov    %r14,%rdi
mov    $0x1,%esi
call   1080 <print_tree@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
store i32 0, i32* %1
%4 = call i32 @time(i32* null)
%5 = call i32 @srand(i32 %4)
%6 = call i32* @malloc(i32 400)
store i32* %6, i32** %3
store i32 0, i32* %2
br label %7
7: ; preds = %17, %0
%8 = load i32, i32* %2
%9 = icmp slt i32 %8, 100
br i1 %9, label %10, label %20
10: ; preds = %7
%11 = call i32 (...) @rand()
%12 = srem i32 %11, 1000
%13 = load i32*, i32** %3
%14 = load i32, i32* %2
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i32, i32* %13, i64 %15
store i32 %12, i32* %16
br label %17
17: ; preds = %10
%18 = load i32, i32* %2
%19 = add nsw i32 %18, 1
store i32 %19, i32* %2
br label %7
20: ; preds = %7
store i32 0, i32* %2
%21 = load i32*, i32** %3
%22 = call i32 @print_tree(i32* %21, i32 1)
%23 = load i32*, i32** %3
%24 = call i32 @heap_sort(i32* %23)
%25 = load i32*, i32** %3
%26 = call i32 @print_tree(i32* %25, i32 1)
%27 = load i32*, i32** %3
%28 = call i32 @free(i32* %27)
%29 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
define i32 @main() {
%1 = tail call i32 @time(i32* null)
%2 = tail call i32 @srand(i32 %1)
%3 = tail call i32* @malloc(i32 400)
br label %4
4: ; preds = %0, %4
%5 = phi i64 [ 0, %0 ], [ %9, %4 ]
%6 = tail call i32 (...) @rand()
%7 = srem i32 %6, 1000
%8 = getelementptr inbounds i32, i32* %3, i64 %5
store i32 %7, i32* %8
%9 = add nuw nsw i64 %5, 1
%10 = icmp eq i64 %9, 100
br i1 %10, label %11, label %4
11: ; preds = %4
%12 = tail call i32 @print_tree(i32* %3, i32 1)
%13 = tail call i32 @heap_sort(i32* %3)
%14 = tail call i32 @print_tree(i32* %3, i32 1)
%15 = tail call i32 @free(i32* %3)
%16 = tail call i32 @exit(i32 0)
unreachable
}