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

/* Variables and functions */
int *heapSort(int *, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ printArray(int *, int);
int /*<<< orphan*/ printf(char *);
int main() {
  int array[] = {25, 21, 20, 5, 10, 12, 15, 8, 2, 6, 2, 9};
  int n = (int)sizeof(array) / sizeof(array[0]), i;
  int *newArray = (int *)malloc(n * sizeof(int));
  int *newArray1 = (int *)malloc(n * sizeof(int));
  printf("Before Heapsort:\n");
  printArray(array, n);
  printf("After Heapsort:\n");
  newArray = heapSort(array, n);
  printArray(newArray, n);
  printArray(array, n);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xe96(%rip),%rsi
mov    $0x30,%edx
call   1050 <memcpy@plt>
movl   $0xc,-0x44(%rbp)
movslq -0x44(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x50(%rbp)
movslq -0x44(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x58(%rbp)
lea    0xe88(%rip),%rdi
call   1040 <printf@plt>
lea    -0x40(%rbp),%rdi
mov    -0x44(%rbp),%esi
call   1070 <printArray@plt>
lea    0xe82(%rip),%rdi
call   1040 <printf@plt>
lea    -0x40(%rbp),%rdi
mov    -0x44(%rbp),%esi
call   1030 <heapSort@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x44(%rbp),%esi
call   1070 <printArray@plt>
lea    -0x40(%rbp),%rdi
mov    -0x44(%rbp),%esi
call   1070 <printArray@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
movaps 0xed4(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xeb8(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe9c(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    $0x30,%edi
call   1050 <malloc@plt>
mov    $0x30,%edi
call   1050 <malloc@plt>
lea    0xead(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0xc,%esi
call   1060 <printArray@plt>
lea    0xea2(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    $0xc,%esi
call   1040 <heapSort@plt>
mov    %rax,%rdi
mov    $0xc,%esi
call   1060 <printArray@plt>
mov    %rbx,%rdi
mov    $0xc,%esi
call   1060 <printArray@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.array = [12 x i32] [i32 25, i32 21, i32 20, i32 5, i32 10, i32 12, i32 15, i32 8, i32 2, i32 6, i32 2, i32 9]
@.str = [18 x i8] c"Before Heapsort:\0A\00"
@.str.1 = [17 x i8] c"After Heapsort:\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [12 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
store i32 0, i32* %1
%7 = bitcast [12 x i32]* %2 to i8*
store i32 12, i32* %3
%8 = load i32, i32* %3
%9 = sext i32 %8 to i64
%10 = mul i64 %9, 4
%11 = trunc i64 %10 to i32
%12 = call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i32*
store i32* %13, i32** %5
%14 = load i32, i32* %3
%15 = sext i32 %14 to i64
%16 = mul i64 %15, 4
%17 = trunc i64 %16 to i32
%18 = call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to i32*
store i32* %19, i32** %6
%20 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%21 = getelementptr inbounds [12 x i32], [12 x i32]* %2, i64 0, i64 0
%22 = load i32, i32* %3
%23 = call i32 @printArray(i32* %21, i32 %22)
%24 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%25 = getelementptr inbounds [12 x i32], [12 x i32]* %2, i64 0, i64 0
%26 = load i32, i32* %3
%27 = call i32* @heapSort(i32* %25, i32 %26)
store i32* %27, i32** %5
%28 = load i32*, i32** %5
%29 = load i32, i32* %3
%30 = call i32 @printArray(i32* %28, i32 %29)
%31 = getelementptr inbounds [12 x i32], [12 x i32]* %2, i64 0, i64 0
%32 = load i32, i32* %3
%33 = call i32 @printArray(i32* %31, i32 %32)
ret i32 0
}

LLVM IR (-O2):
@__const.main.array = [12 x i32] [i32 25, i32 21, i32 20, i32 5, i32 10, i32 12, i32 15, i32 8, i32 2, i32 6, i32 2, i32 9]
@str = [17 x i8] c"Before Heapsort:\00"
@str.2 = [16 x i8] c"After Heapsort:\00"
define i32 @main() {
%1 = alloca [12 x i32]
%2 = bitcast [12 x i32]* %1 to i8*
%3 = tail call i64 @malloc(i32 48)
%4 = tail call i64 @malloc(i32 48)
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%6 = getelementptr inbounds [12 x i32], [12 x i32]* %1, i64 0, i64 0
%7 = call i32 @printArray(i32* %6, i32 12)
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.2, i64 0, i64 0))
%9 = call i32* @heapSort(i32* %6, i32 12)
%10 = call i32 @printArray(i32* %9, i32 12)
%11 = call i32 @printArray(i32* %6, i32 12)
ret i32 0
}