#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*/ heap_sort(int *, int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int a[100];
  a[0] = 15;
  a[1] = 2;
  a[2] = 8;
  a[3] = 7;
  a[4] = 3;
  a[5] = 6;
  a[6] = 9;
  a[7] = 17;
  int n = 8;
  heap_sort(a, n);
  for (int i = 0; i < n; i++) {
    printf("%d ", a[i]);
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1b0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xf,-0x1a0(%rbp)
movl   $0x2,-0x19c(%rbp)
movl   $0x8,-0x198(%rbp)
movl   $0x7,-0x194(%rbp)
movl   $0x3,-0x190(%rbp)
movl   $0x6,-0x18c(%rbp)
movl   $0x9,-0x188(%rbp)
movl   $0x11,-0x184(%rbp)
movl   $0x8,-0x1a4(%rbp)
lea    -0x1a0(%rbp),%rdi
mov    -0x1a4(%rbp),%esi
call   1030 <heap_sort@plt>
movl   $0x0,-0x1a8(%rbp)
mov    -0x1a8(%rbp),%eax
cmp    -0x1a4(%rbp),%eax
jge    11ea <main+0xca>
movslq -0x1a8(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%esi
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1a8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1a8(%rbp)
jmp    11a8 <main+0x88>
lea    0xe13(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x1b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x190,%rsp
movaps 0xec1(%rip),%xmm0
movaps %xmm0,(%rsp)
movaps 0xec6(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
mov    %rsp,%rdi
mov    $0x8,%esi
call   1040 <heap_sort@plt>
mov    (%rsp),%esi
lea    0xeba(%rip),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x14(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x18(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x1c(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x190,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d \00"
@.str.1 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i32]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
store i32 15, i32* %5
%6 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 1
store i32 2, i32* %6
%7 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 2
store i32 8, i32* %7
%8 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 3
store i32 7, i32* %8
%9 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 4
store i32 3, i32* %9
%10 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 5
store i32 6, i32* %10
%11 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 6
store i32 9, i32* %11
%12 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 7
store i32 17, i32* %12
store i32 8, i32* %3
%13 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%14 = load i32, i32* %3
%15 = call i32 @heap_sort(i32* %13, i32 %14)
store i32 0, i32* %4
br label %16
16: ; preds = %26, %0
%17 = load i32, i32* %4
%18 = load i32, i32* %3
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %29
20: ; preds = %16
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %22
%24 = load i32, i32* %23
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %24)
br label %26
26: ; preds = %20
%27 = load i32, i32* %4
%28 = add nsw i32 %27, 1
store i32 %28, i32* %4
br label %16
29: ; preds = %16
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d \00"
define i32 @main() {
%1 = alloca [100 x i32]
%2 = bitcast [100 x i32]* %1 to i8*
%3 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 0
%4 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 1
%5 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 2
%6 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 3
%7 = bitcast [100 x i32]* %1 to <4 x i32>*
store <4 x i32> <i32 15, i32 2, i32 8, i32 7>, <4 x i32>* %7
%8 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 4
%9 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 5
%10 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 6
%11 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 7
%12 = bitcast i32* %8 to <4 x i32>*
store <4 x i32> <i32 3, i32 6, i32 9, i32 17>, <4 x i32>* %12
%13 = call i32 @heap_sort(i32* %3, i32 8)
%14 = load i32, i32* %3
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = load i32, i32* %4
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = load i32, i32* %5
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = load i32, i32* %6
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = load i32, i32* %8
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %22)
%24 = load i32, i32* %9
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %24)
%26 = load i32, i32* %10
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %26)
%28 = load i32, i32* %11
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %28)
%30 = call i32 @putchar(i32 10)
ret i32 0
}