#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*/ print_array(int *, int);
int /*<<< orphan*/ printf(char *);
scalar_t__ test_sorted_array(int *, int);
int main() {
  int array[] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
  printf("Unsorted array : \n");
  print_array(array, 10);
  heap_sort(array, 10);
  printf("Sorted array : \n");
  print_array(array, 10);
  printf("Testing if array is actually sorted or not...\n");
  if (test_sorted_array(array, 10)) {
    printf("Array is sorted.\n");
  } else {
    printf("Array is not sorted.\n");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xe96(%rip),%rsi
mov    $0x28,%edx
call   1070 <memcpy@plt>
lea    0xead(%rip),%rdi
call   1060 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    $0xa,%esi
call   1050 <print_array@plt>
lea    -0x30(%rbp),%rdi
mov    $0xa,%esi
call   1030 <heap_sort@plt>
lea    0xe98(%rip),%rdi
call   1060 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    $0xa,%esi
call   1050 <print_array@plt>
lea    0xe8f(%rip),%rdi
call   1060 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    $0xa,%esi
call   1040 <test_sorted_array@plt>
cmp    $0x0,%rax
je     11eb <main+0x9b>
lea    0xe9a(%rip),%rdi
call   1060 <printf@plt>
jmp    11f7 <main+0xa7>
lea    0xe9b(%rip),%rdi
call   1060 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
mov    0xed4(%rip),%rax
mov    %rax,0x20(%rsp)
movaps 0xeb8(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe9c(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xeb9(%rip),%rdi
call   1050 <puts@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0xa,%esi
call   1060 <print_array@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1030 <heap_sort@plt>
lea    0xea2(%rip),%rdi
call   1050 <puts@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1060 <print_array@plt>
lea    0xe99(%rip),%rdi
call   1050 <puts@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1040 <test_sorted_array@plt>
test   %rax,%rax
lea    0xeab(%rip),%rax
lea    0xeb9(%rip),%rdi
cmove  %rax,%rdi
call   1050 <puts@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.array = [10 x i32] [i32 10, i32 9, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1]
@.str = [19 x i8] c"Unsorted array : \0A\00"
@.str.1 = [17 x i8] c"Sorted array : \0A\00"
@.str.2 = [47 x i8] c"Testing if array is actually sorted or not...\0A\00"
@.str.3 = [18 x i8] c"Array is sorted.\0A\00"
@.str.4 = [22 x i8] c"Array is not sorted.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i32]
store i32 0, i32* %1
%3 = bitcast [10 x i32]* %2 to i8*
%4 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%6 = call i32 @print_array(i32* %5, i32 10)
%7 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%8 = call i32 @heap_sort(i32* %7, i32 10)
%9 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%10 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%11 = call i32 @print_array(i32* %10, i32 10)
%12 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0))
%13 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%14 = call i64 @test_sorted_array(i32* %13, i32 10)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %0
%17 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
br label %20
18: ; preds = %0
%19 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
br label %20
20: ; preds = %18, %16
%21 = load i32, i32* %1
ret i32 %21
}

LLVM IR (-O2):
@__const.main.array = [10 x i32] [i32 10, i32 9, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1]
@str = [18 x i8] c"Unsorted array : \00"
@str.5 = [16 x i8] c"Sorted array : \00"
@str.6 = [46 x i8] c"Testing if array is actually sorted or not...\00"
@str.7 = [21 x i8] c"Array is not sorted.\00"
@str.8 = [17 x i8] c"Array is sorted.\00"
define i32 @main() {
%1 = alloca [10 x i32]
%2 = bitcast [10 x i32]* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%4 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 0
%5 = call i32 @print_array(i32* %4, i32 10)
%6 = call i32 @heap_sort(i32* %4, i32 10)
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.5, i64 0, i64 0))
%8 = call i32 @print_array(i32* %4, i32 10)
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str.6, i64 0, i64 0))
%10 = call i64 @test_sorted_array(i32* %4, i32 10)
%11 = icmp eq i64 %10, 0
%12 = select i1 %11, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @str.7, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @str.8, i64 0, i64 0)
%13 = call i32 @puts(i8* dereferenceable(1) %12)
ret i32 0
}