#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 argc, char *argv[]) {
  int a0[] = {1};
  heap_sort(a0, 0);
  if (a0[0] != 1)
    printf("wrong answer!\n");
  heap_sort(a0, 1);
  if (a0[0] != 1)
    printf("wrong answer!\n");
  int a[100];
  for (int i = 0; i < 100; ++i) {
    a[i] = 100 - i;
  }
  heap_sort(a, 100);
  for (int i = 0; i < 100; ++i) {
    if (a[i] != i + 1) {
      printf("wrong answer for a[%d] = %d!\n", i, a[i]);
    }
  }
  printf("everyting is fine!\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1c0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xec1(%rip),%eax
mov    %eax,-0x14(%rbp)
lea    -0x14(%rbp),%rdi
xor    %esi,%esi
call   1030 <heap_sort@plt>
cmpl   $0x1,-0x14(%rbp)
je     1165 <main+0x45>
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x14(%rbp),%rdi
mov    $0x1,%esi
call   1030 <heap_sort@plt>
cmpl   $0x1,-0x14(%rbp)
je     118b <main+0x6b>
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x1b4(%rbp)
cmpl   $0x64,-0x1b4(%rbp)
jge    11cf <main+0xaf>
mov    $0x64,%ecx
sub    -0x1b4(%rbp),%ecx
movslq -0x1b4(%rbp),%rax
mov    %ecx,-0x1b0(%rbp,%rax,4)
mov    -0x1b4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1b4(%rbp)
jmp    1195 <main+0x75>
lea    -0x1b0(%rbp),%rdi
mov    $0x64,%esi
call   1030 <heap_sort@plt>
movl   $0x0,-0x1b8(%rbp)
cmpl   $0x64,-0x1b8(%rbp)
jge    1251 <main+0x131>
movslq -0x1b8(%rbp),%rax
mov    -0x1b0(%rbp,%rax,4),%eax
mov    -0x1b8(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
je     1238 <main+0x118>
mov    -0x1b8(%rbp),%esi
movslq -0x1b8(%rbp),%rax
mov    -0x1b0(%rbp,%rax,4),%edx
lea    0xde2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    123d <main+0x11d>
mov    -0x1b8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1b8(%rbp)
jmp    11ea <main+0xca>
lea    0xdd9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x1c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x1a8,%rsp
movl   $0x1,0xc(%rsp)
lea    0xc(%rsp),%rdi
xor    %esi,%esi
call   1030 <heap_sort@plt>
cmpl   $0x1,0xc(%rsp)
je     1161 <main+0x31>
lea    0x1065(%rip),%rdi
call   1040 <puts@plt>
lea    0xc(%rsp),%rdi
mov    $0x1,%esi
call   1030 <heap_sort@plt>
cmpl   $0x1,0xc(%rsp)
je     1183 <main+0x53>
lea    0x1043(%rip),%rdi
call   1040 <puts@plt>
movaps 0xe76(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe7a(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe7e(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe82(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xe86(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xe8a(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xe8e(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xe92(%rip),%xmm0
movaps %xmm0,0x80(%rsp)
movaps 0xe93(%rip),%xmm0
movaps %xmm0,0x90(%rsp)
movaps 0xe94(%rip),%xmm0
movaps %xmm0,0xa0(%rsp)
movaps 0xe95(%rip),%xmm0
movaps %xmm0,0xb0(%rsp)
movaps 0xe96(%rip),%xmm0
movaps %xmm0,0xc0(%rsp)
movaps 0xe97(%rip),%xmm0
movaps %xmm0,0xd0(%rsp)
movaps 0xe98(%rip),%xmm0
movaps %xmm0,0xe0(%rsp)
movaps 0xe99(%rip),%xmm0
movaps %xmm0,0xf0(%rsp)
movaps 0xe9a(%rip),%xmm0
movaps %xmm0,0x100(%rsp)
movaps 0xe9b(%rip),%xmm0
movaps %xmm0,0x110(%rsp)
movaps 0xe9c(%rip),%xmm0
movaps %xmm0,0x120(%rsp)
movaps 0xe9d(%rip),%xmm0
movaps %xmm0,0x130(%rsp)
movaps 0xe9e(%rip),%xmm0
movaps %xmm0,0x140(%rsp)
movaps 0xe9f(%rip),%xmm0
movaps %xmm0,0x150(%rsp)
movaps 0xea0(%rip),%xmm0
movaps %xmm0,0x160(%rsp)
movaps 0xea1(%rip),%xmm0
movaps %xmm0,0x170(%rsp)
movaps 0xea2(%rip),%xmm0
movaps %xmm0,0x180(%rsp)
movaps 0xea3(%rip),%xmm0
movaps %xmm0,0x190(%rsp)
lea    0x10(%rsp),%rdi
mov    $0x64,%esi
call   1030 <heap_sort@plt>
lea    0xe95(%rip),%r14
xor    %esi,%esi
jmp    1309 <main+0x1d9>
nop
mov    %rbx,%rsi
cmp    $0x64,%rbx
je     1322 <main+0x1f2>
mov    0x10(%rsp,%rsi,4),%edx
lea    0x1(%rsi),%rbx
cmp    %rdx,%rbx
je     1300 <main+0x1d0>
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1300 <main+0x1d0>
lea    0xe85(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x1a8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.a0 = [1 x i32] [i32 1]
@.str = [15 x i8] c"wrong answer!\0A\00"
@.str.1 = [30 x i8] c"wrong answer for a[%d] = %d!\0A\00"
@.str.2 = [20 x i8] c"everyting is fine!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1 x i32]
%7 = alloca [100 x i32]
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = bitcast [1 x i32]* %6 to i8*
%11 = getelementptr inbounds [1 x i32], [1 x i32]* %6, i64 0, i64 0
%12 = call i32 @heap_sort(i32* %11, i32 0)
%13 = getelementptr inbounds [1 x i32], [1 x i32]* %6, i64 0, i64 0
%14 = load i32, i32* %13
%15 = icmp ne i32 %14, 1
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %2
%19 = getelementptr inbounds [1 x i32], [1 x i32]* %6, i64 0, i64 0
%20 = call i32 @heap_sort(i32* %19, i32 1)
%21 = getelementptr inbounds [1 x i32], [1 x i32]* %6, i64 0, i64 0
%22 = load i32, i32* %21
%23 = icmp ne i32 %22, 1
br i1 %23, label %24, label %26
24: ; preds = %18
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %26
26: ; preds = %24, %18
store i32 0, i32* %8
br label %27
27: ; preds = %36, %26
%28 = load i32, i32* %8
%29 = icmp slt i32 %28, 100
br i1 %29, label %30, label %39
30: ; preds = %27
%31 = load i32, i32* %8
%32 = sub nsw i32 100, %31
%33 = load i32, i32* %8
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [100 x i32], [100 x i32]* %7, i64 0, i64 %34
store i32 %32, i32* %35
br label %36
36: ; preds = %30
%37 = load i32, i32* %8
%38 = add nsw i32 %37, 1
store i32 %38, i32* %8
br label %27
39: ; preds = %27
%40 = getelementptr inbounds [100 x i32], [100 x i32]* %7, i64 0, i64 0
%41 = call i32 @heap_sort(i32* %40, i32 100)
store i32 0, i32* %9
br label %42
42: ; preds = %61, %39
%43 = load i32, i32* %9
%44 = icmp slt i32 %43, 100
br i1 %44, label %45, label %64
45: ; preds = %42
%46 = load i32, i32* %9
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [100 x i32], [100 x i32]* %7, i64 0, i64 %47
%49 = load i32, i32* %48
%50 = load i32, i32* %9
%51 = add nsw i32 %50, 1
%52 = icmp ne i32 %49, %51
br i1 %52, label %53, label %60
53: ; preds = %45
%54 = load i32, i32* %9
%55 = load i32, i32* %9
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [100 x i32], [100 x i32]* %7, i64 0, i64 %56
%58 = load i32, i32* %57
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %54, i32 %58)
br label %60
60: ; preds = %53, %45
br label %61
61: ; preds = %60
%62 = load i32, i32* %9
%63 = add nsw i32 %62, 1
store i32 %63, i32* %9
br label %42
64: ; preds = %42
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [30 x i8] c"wrong answer for a[%d] = %d!\0A\00"
@str = [19 x i8] c"everyting is fine!\00"
@str.4 = [14 x i8] c"wrong answer!\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1 x i32]
%4 = alloca [100 x i32]
%5 = bitcast [1 x i32]* %3 to i8*
%6 = getelementptr inbounds [1 x i32], [1 x i32]* %3, i64 0, i64 0
store i32 1, i32* %6
%7 = call i32 @heap_sort(i32* %6, i32 0)
%8 = load i32, i32* %6
%9 = icmp eq i32 %8, 1
br i1 %9, label %12, label %10
10: ; preds = %2
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.4, i64 0, i64 0))
br label %12
12: ; preds = %10, %2
%13 = call i32 @heap_sort(i32* %6, i32 1)
%14 = load i32, i32* %6
%15 = icmp eq i32 %14, 1
br i1 %15, label %18, label %16
16: ; preds = %12
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.4, i64 0, i64 0))
br label %18
18: ; preds = %16, %12
%19 = bitcast [100 x i32]* %4 to i8*
%20 = bitcast [100 x i32]* %4 to <4 x i32>*
store <4 x i32> <i32 100, i32 99, i32 98, i32 97>, <4 x i32>* %20
%21 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 4
%22 = bitcast i32* %21 to <4 x i32>*
store <4 x i32> <i32 96, i32 95, i32 94, i32 93>, <4 x i32>* %22
%23 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 8
%24 = bitcast i32* %23 to <4 x i32>*
store <4 x i32> <i32 92, i32 91, i32 90, i32 89>, <4 x i32>* %24
%25 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 12
%26 = bitcast i32* %25 to <4 x i32>*
store <4 x i32> <i32 88, i32 87, i32 86, i32 85>, <4 x i32>* %26
%27 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 16
%28 = bitcast i32* %27 to <4 x i32>*
store <4 x i32> <i32 84, i32 83, i32 82, i32 81>, <4 x i32>* %28
%29 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 20
%30 = bitcast i32* %29 to <4 x i32>*
store <4 x i32> <i32 80, i32 79, i32 78, i32 77>, <4 x i32>* %30
%31 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 24
%32 = bitcast i32* %31 to <4 x i32>*
store <4 x i32> <i32 76, i32 75, i32 74, i32 73>, <4 x i32>* %32
%33 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 28
%34 = bitcast i32* %33 to <4 x i32>*
store <4 x i32> <i32 72, i32 71, i32 70, i32 69>, <4 x i32>* %34
%35 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 32
%36 = bitcast i32* %35 to <4 x i32>*
store <4 x i32> <i32 68, i32 67, i32 66, i32 65>, <4 x i32>* %36
%37 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 36
%38 = bitcast i32* %37 to <4 x i32>*
store <4 x i32> <i32 64, i32 63, i32 62, i32 61>, <4 x i32>* %38
%39 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 40
%40 = bitcast i32* %39 to <4 x i32>*
store <4 x i32> <i32 60, i32 59, i32 58, i32 57>, <4 x i32>* %40
%41 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 44
%42 = bitcast i32* %41 to <4 x i32>*
store <4 x i32> <i32 56, i32 55, i32 54, i32 53>, <4 x i32>* %42
%43 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 48
%44 = bitcast i32* %43 to <4 x i32>*
store <4 x i32> <i32 52, i32 51, i32 50, i32 49>, <4 x i32>* %44
%45 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 52
%46 = bitcast i32* %45 to <4 x i32>*
store <4 x i32> <i32 48, i32 47, i32 46, i32 45>, <4 x i32>* %46
%47 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 56
%48 = bitcast i32* %47 to <4 x i32>*
store <4 x i32> <i32 44, i32 43, i32 42, i32 41>, <4 x i32>* %48
%49 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 60
%50 = bitcast i32* %49 to <4 x i32>*
store <4 x i32> <i32 40, i32 39, i32 38, i32 37>, <4 x i32>* %50
%51 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 64
%52 = bitcast i32* %51 to <4 x i32>*
store <4 x i32> <i32 36, i32 35, i32 34, i32 33>, <4 x i32>* %52
%53 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 68
%54 = bitcast i32* %53 to <4 x i32>*
store <4 x i32> <i32 32, i32 31, i32 30, i32 29>, <4 x i32>* %54
%55 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 72
%56 = bitcast i32* %55 to <4 x i32>*
store <4 x i32> <i32 28, i32 27, i32 26, i32 25>, <4 x i32>* %56
%57 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 76
%58 = bitcast i32* %57 to <4 x i32>*
store <4 x i32> <i32 24, i32 23, i32 22, i32 21>, <4 x i32>* %58
%59 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 80
%60 = bitcast i32* %59 to <4 x i32>*
store <4 x i32> <i32 20, i32 19, i32 18, i32 17>, <4 x i32>* %60
%61 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 84
%62 = bitcast i32* %61 to <4 x i32>*
store <4 x i32> <i32 16, i32 15, i32 14, i32 13>, <4 x i32>* %62
%63 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 88
%64 = bitcast i32* %63 to <4 x i32>*
store <4 x i32> <i32 12, i32 11, i32 10, i32 9>, <4 x i32>* %64
%65 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 92
%66 = bitcast i32* %65 to <4 x i32>*
store <4 x i32> <i32 8, i32 7, i32 6, i32 5>, <4 x i32>* %66
%67 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 96
%68 = bitcast i32* %67 to <4 x i32>*
store <4 x i32> <i32 4, i32 3, i32 2, i32 1>, <4 x i32>* %68
%69 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 0
%70 = call i32 @heap_sort(i32* %69, i32 100)
br label %73
71: ; preds = %83
%72 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
ret i32 0
73: ; preds = %18, %83
%74 = phi i64 [ 0, %18 ], [ %77, %83 ]
%75 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 %74
%76 = load i32, i32* %75
%77 = add nuw nsw i64 %74, 1
%78 = zext i32 %76 to i64
%79 = icmp eq i64 %77, %78
br i1 %79, label %83, label %80
80: ; preds = %73
%81 = trunc i64 %74 to i32
%82 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %81, i32 %76)
br label %83
83: ; preds = %73, %80
%84 = icmp eq i64 %77, 100
br i1 %84, label %71, label %73
}