#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*/ heapsort(int *, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int n, *a, i, j;
  scanf("%d", &n);
  a = (int *)malloc((n + 1) * sizeof(int));
  for (i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  heapsort(a, n);
  for (i = 1; i <= n; i++)
    printf("%d ", a[i]);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11b2 <main+0x72>
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe61(%rip),%rdi
call   1060 <scanf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    117d <main+0x3d>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1040 <heapsort@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11f6 <main+0xb6>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe20(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11c5 <main+0x85>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xeb1(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1060 <scanf@plt>
mov    0x4(%rsp),%eax
lea    0x4(,%rax,4),%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    0x4(%rsp),%esi
test   %esi,%esi
jle    11ad <main+0x6d>
mov    %r14,%r12
add    $0x4,%r12
xor    %ebx,%ebx
lea    0xe7c(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
mov    %r12,%rsi
call   1060 <scanf@plt>
movslq 0x4(%rsp),%rsi
add    $0x1,%rbx
add    $0x4,%r12
cmp    %rsi,%rbx
jl     1190 <main+0x50>
mov    %r14,%rdi
call   1040 <heapsort@plt>
cmpl   $0x0,0x4(%rsp)
jle    11eb <main+0xab>
xor    %ebx,%ebx
lea    0xe3e(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x4(%r14,%rbx,4),%esi
mov    %r15,%rdi
call   1030 <printf@plt>
movslq 0x4(%rsp),%rax
add    $0x1,%rbx
cmp    %rax,%rbx
jl     11d0 <main+0x90>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%d \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%7 = load i32, i32* %2
%8 = add nsw i32 %7, 1
%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** %3
store i32 1, i32* %4
br label %14
14: ; preds = %24, %0
%15 = load i32, i32* %4
%16 = load i32, i32* %2
%17 = icmp sle i32 %15, %16
br i1 %17, label %18, label %27
18: ; preds = %14
%19 = load i32*, i32** %3
%20 = load i32, i32* %4
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %19, i64 %21
%23 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %22)
br label %24
24: ; preds = %18
%25 = load i32, i32* %4
%26 = add nsw i32 %25, 1
store i32 %26, i32* %4
br label %14
27: ; preds = %14
%28 = load i32*, i32** %3
%29 = load i32, i32* %2
%30 = call i32 @heapsort(i32* %28, i32 %29)
store i32 1, i32* %4
br label %31
31: ; preds = %42, %27
%32 = load i32, i32* %4
%33 = load i32, i32* %2
%34 = icmp sle i32 %32, %33
br i1 %34, label %35, label %45
35: ; preds = %31
%36 = load i32*, i32** %3
%37 = load i32, i32* %4
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %36, i64 %38
%40 = load i32, i32* %39
%41 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %40)
br label %42
42: ; preds = %35
%43 = load i32, i32* %4
%44 = add nsw i32 %43, 1
store i32 %44, i32* %4
br label %31
45: ; preds = %31
%46 = load i32, i32* %1
ret i32 %46
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%d \00"
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 = add i32 %5, 4
%7 = call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i32*
%9 = load i32, i32* %1
%10 = icmp slt i32 %9, 1
br i1 %10, label %19, label %11
11: ; preds = %0, %11
%12 = phi i64 [ %15, %11 ], [ 1, %0 ]
%13 = getelementptr inbounds i32, i32* %8, i64 %12
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %13)
%15 = add nuw nsw i64 %12, 1
%16 = load i32, i32* %1
%17 = sext i32 %16 to i64
%18 = icmp slt i64 %12, %17
br i1 %18, label %11, label %19
19: ; preds = %11, %0
%20 = phi i32 [ %9, %0 ], [ %16, %11 ]
%21 = call i32 @heapsort(i32* %8, i32 %20)
%22 = load i32, i32* %1
%23 = icmp slt i32 %22, 1
br i1 %23, label %33, label %24
24: ; preds = %19, %24
%25 = phi i64 [ %29, %24 ], [ 1, %19 ]
%26 = getelementptr inbounds i32, i32* %8, i64 %25
%27 = load i32, i32* %26
%28 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %27)
%29 = add nuw nsw i64 %25, 1
%30 = load i32, i32* %1
%31 = sext i32 %30 to i64
%32 = icmp slt i64 %25, %31
br i1 %32, label %24, label %33
33: ; preds = %24, %19
ret i32 0
}