#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 *calloc(int, int);
int /*<<< orphan*/ heapSort(int *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int i, n;
  printf("Enter how many numbers you want to enter: ");
  scanf("%d", &n);
  int *A = calloc(n + 2, sizeof(int));
  for (i = 1; i < n + 1; i++) {
    scanf("%d", &A[i]);
  }
  heapSort(A, n);
  for (i = 1; i <= n; i++) {
    printf("%d  ", A[i]);
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xec7(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0xc(%rbp),%edi
add    $0x2,%edi
mov    $0x4,%esi
call   1050 <calloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    11c2 <main+0x82>
mov    -0x18(%rbp),%rsi
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe7c(%rip),%rdi
call   1060 <scanf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1188 <main+0x48>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <heapSort@plt>
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     1208 <main+0xc8>
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11d5 <main+0x95>
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xe9c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeb9(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1070 <scanf@plt>
mov    0xc(%rsp),%r15d
lea    0x2(%r15),%edi
mov    $0x4,%esi
call   1060 <calloc@plt>
mov    %rax,%r14
test   %r15d,%r15d
jle    11cd <main+0x7d>
mov    %r14,%r13
add    $0x4,%r13
xor    %ebx,%ebx
lea    0xe84(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r13,%rsi
call   1070 <scanf@plt>
movslq 0xc(%rsp),%r15
add    $0x1,%rbx
add    $0x4,%r13
cmp    %r15,%rbx
jl     11b0 <main+0x60>
mov    %r14,%rdi
mov    %r15d,%esi
call   1040 <heapSort@plt>
cmpl   $0x0,0xc(%rsp)
jle    120d <main+0xbd>
lea    0xe48(%rip),%r15
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    0x4(%r14,%rbx,4),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movslq 0xc(%rsp),%rax
add    $0x1,%rbx
cmp    %rax,%rbx
jl     11f0 <main+0xa0>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [43 x i8] c"Enter how many numbers you want to enter: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [5 x i8] c"%d \00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%7 = load i32, i32* %3
%8 = add nsw i32 %7, 2
%9 = call i32* @calloc(i32 %8, i32 4)
store i32* %9, i32** %4
store i32 1, i32* %2
br label %10
10: ; preds = %21, %0
%11 = load i32, i32* %2
%12 = load i32, i32* %3
%13 = add nsw i32 %12, 1
%14 = icmp slt i32 %11, %13
br i1 %14, label %15, label %24
15: ; preds = %10
%16 = load i32*, i32** %4
%17 = load i32, i32* %2
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i32, i32* %16, i64 %18
%20 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %19)
br label %21
21: ; preds = %15
%22 = load i32, i32* %2
%23 = add nsw i32 %22, 1
store i32 %23, i32* %2
br label %10
24: ; preds = %10
%25 = load i32*, i32** %4
%26 = load i32, i32* %3
%27 = call i32 @heapSort(i32* %25, i32 %26)
store i32 1, i32* %2
br label %28
28: ; preds = %39, %24
%29 = load i32, i32* %2
%30 = load i32, i32* %3
%31 = icmp sle i32 %29, %30
br i1 %31, label %32, label %42
32: ; preds = %28
%33 = load i32*, i32** %4
%34 = load i32, i32* %2
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %33, i64 %35
%37 = load i32, i32* %36
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %37)
br label %39
39: ; preds = %32
%40 = load i32, i32* %2
%41 = add nsw i32 %40, 1
store i32 %41, i32* %2
br label %28
42: ; preds = %28
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [43 x i8] c"Enter how many numbers you want to enter: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [5 x i8] c"%d \00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = add nsw i32 %5, 2
%7 = call i32* @calloc(i32 %6, i32 4)
%8 = icmp slt i32 %5, 1
br i1 %8, label %17, label %9
9: ; preds = %0, %9
%10 = phi i64 [ %13, %9 ], [ 1, %0 ]
%11 = getelementptr inbounds i32, i32* %7, i64 %10
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %11)
%13 = add nuw nsw i64 %10, 1
%14 = load i32, i32* %1
%15 = sext i32 %14 to i64
%16 = icmp slt i64 %10, %15
br i1 %16, label %9, label %17
17: ; preds = %9, %0
%18 = phi i32 [ %5, %0 ], [ %14, %9 ]
%19 = call i32 @heapSort(i32* %7, i32 %18)
%20 = load i32, i32* %1
%21 = icmp slt i32 %20, 1
br i1 %21, label %31, label %22
22: ; preds = %17, %22
%23 = phi i64 [ %27, %22 ], [ 1, %17 ]
%24 = getelementptr inbounds i32, i32* %7, i64 %23
%25 = load i32, i32* %24
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %25)
%27 = add nuw nsw i64 %23, 1
%28 = load i32, i32* %1
%29 = sext i32 %28 to i64
%30 = icmp slt i64 %23, %29
br i1 %30, label %22, label %31
31: ; preds = %22, %17
%32 = call i32 @putchar(i32 10)
ret i32 0
}