#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 EXIT_SUCCESS;
int /*<<< orphan*/ heap_sort(int *, int);
int /*<<< orphan*/ make_heap(int *, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ print_array(int *, int);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int n, i, *A;
  scanf("%d", &n);
  A = (int *)malloc(sizeof(int) * n);
  for (i = 0; i < n; i++)
    scanf("%d", &A[i]);
  print_array(A, n);
  make_heap(A, n);
  print_array(A, n);
  heap_sort(A, n);
  print_array(A, n);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11be <main+0x6e>
mov    -0x18(%rbp),%rsi
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe55(%rip),%rdi
call   1060 <scanf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1189 <main+0x39>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1040 <print_array@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1070 <make_heap@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1040 <print_array@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1030 <heap_sort@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1040 <print_array@plt>
mov    0x2ddf(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xea1(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1060 <scanf@plt>
mov    0x4(%rsp),%edi
shl    $0x2,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    0x4(%rsp),%esi
test   %esi,%esi
jle    11ad <main+0x5d>
xor    %r12d,%r12d
lea    0xe76(%rip),%r15
mov    %r14,%rbx
nopl   (%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
add    $0x1,%r12
movslq 0x4(%rsp),%rsi
add    $0x4,%rbx
cmp    %rsi,%r12
jl     1190 <main+0x40>
mov    %r14,%rdi
call   1040 <print_array@plt>
mov    0x4(%rsp),%esi
mov    %r14,%rdi
call   1070 <make_heap@plt>
mov    0x4(%rsp),%esi
mov    %r14,%rdi
call   1040 <print_array@plt>
mov    0x4(%rsp),%esi
mov    %r14,%rdi
call   1030 <heap_sort@plt>
mov    0x4(%rsp),%esi
mov    %r14,%rdi
call   1040 <print_array@plt>
mov    0x2df4(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
store i32 0, i32* %1
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%6 = load i32, i32* %2
%7 = sext i32 %6 to i64
%8 = mul i64 4, %7
%9 = trunc i64 %8 to i32
%10 = call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to i32*
store i32* %11, i32** %4
store i32 0, i32* %3
br label %12
12: ; preds = %22, %0
%13 = load i32, i32* %3
%14 = load i32, i32* %2
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %25
16: ; preds = %12
%17 = load i32*, i32** %4
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i32, i32* %17, i64 %19
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %20)
br label %22
22: ; preds = %16
%23 = load i32, i32* %3
%24 = add nsw i32 %23, 1
store i32 %24, i32* %3
br label %12
25: ; preds = %12
%26 = load i32*, i32** %4
%27 = load i32, i32* %2
%28 = call i32 @print_array(i32* %26, i32 %27)
%29 = load i32*, i32** %4
%30 = load i32, i32* %2
%31 = call i32 @make_heap(i32* %29, i32 %30)
%32 = load i32*, i32** %4
%33 = load i32, i32* %2
%34 = call i32 @print_array(i32* %32, i32 %33)
%35 = load i32*, i32** %4
%36 = load i32, i32* %2
%37 = call i32 @heap_sort(i32* %35, i32 %36)
%38 = load i32*, i32** %4
%39 = load i32, i32* %2
%40 = call i32 @print_array(i32* %38, i32 %39)
%41 = load i32, i32* @EXIT_SUCCESS
ret i32 %41
}

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