#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*/ MaxHeapify(int *, int, int);
int /*<<< orphan*/ heapsort(int *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int a[20] = {0}, i, no;
  printf("Enter number of elements: ");
  scanf("%d", &no);
  for (i = 1; i <= no; i++) {
    scanf("%d", &a[i]);
  }
  for (i = no / 2; i >= 1; i--)
    MaxHeapify(a, i, no);
  heapsort(a, no);
  for (i = 1; i <= no; i++)
    printf("%d", a[i]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1040 <memset@plt>
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe97(%rip),%rdi
lea    -0x68(%rbp),%rsi
call   1060 <scanf@plt>
movl   $0x1,-0x64(%rbp)
mov    -0x64(%rbp),%eax
cmp    -0x68(%rbp),%eax
jg     11c9 <main+0x79>
movslq -0x64(%rbp),%rax
lea    -0x60(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe65(%rip),%rdi
call   1060 <scanf@plt>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    1194 <main+0x44>
mov    -0x68(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x64(%rbp)
cmpl   $0x1,-0x64(%rbp)
jl     11fe <main+0xae>
lea    -0x60(%rbp),%rdi
mov    -0x64(%rbp),%esi
mov    -0x68(%rbp),%edx
call   1070 <MaxHeapify@plt>
mov    -0x64(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x64(%rbp)
jmp    11d7 <main+0x87>
lea    -0x60(%rbp),%rdi
mov    -0x68(%rbp),%esi
call   1050 <heapsort@plt>
movl   $0x1,-0x64(%rbp)
mov    -0x64(%rbp),%eax
cmp    -0x68(%rbp),%eax
jg     1241 <main+0xf1>
movslq -0x64(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%esi
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    1211 <main+0xc1>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x68,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
lea    0xe92(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe9f(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%r15d
test   %r15d,%r15d
jle    120f <main+0xcf>
lea    0x14(%rsp),%r12
xor    %ebx,%ebx
lea    0xe7d(%rip),%r14
xchg   %ax,%ax
mov    %r14,%rdi
mov    %r12,%rsi
call   1050 <scanf@plt>
movslq 0xc(%rsp),%r15
add    $0x1,%rbx
add    $0x4,%r12
cmp    %r15,%rbx
jl     11a0 <main+0x60>
cmp    $0x2,%r15d
jl     120f <main+0xcf>
mov    %r15d,%r14d
shr    %r14d
lea    0x10(%rsp),%rdi
mov    %r14d,%esi
mov    %r15d,%edx
call   1060 <MaxHeapify@plt>
cmp    $0x4,%r15d
jb     120a <main+0xca>
add    $0x1,%r14d
lea    0x10(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
lea    -0x2(%r14),%esi
mov    0xc(%rsp),%edx
mov    %rbx,%rdi
call   1060 <MaxHeapify@plt>
add    $0xffffffff,%r14d
cmp    $0x2,%r14d
jg     11f0 <main+0xb0>
mov    0xc(%rsp),%r15d
lea    0x10(%rsp),%rdi
mov    %r15d,%esi
call   1040 <heapsort@plt>
cmpl   $0x0,0xc(%rsp)
jle    124c <main+0x10c>
lea    0xdf1(%rip),%r14
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    0x14(%rsp,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
movslq 0xc(%rsp),%rax
add    $0x1,%rbx
cmp    %rax,%rbx
jl     1230 <main+0xf0>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Enter number of elements: \00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [20 x i32]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = bitcast [20 x i32]* %2 to i8*
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
store i32 1, i32* %3
br label %8
8: ; preds = %17, %0
%9 = load i32, i32* %3
%10 = load i32, i32* %4
%11 = icmp sle i32 %9, %10
br i1 %11, label %12, label %20
12: ; preds = %8
%13 = load i32, i32* %3
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 %14
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %15)
br label %17
17: ; preds = %12
%18 = load i32, i32* %3
%19 = add nsw i32 %18, 1
store i32 %19, i32* %3
br label %8
20: ; preds = %8
%21 = load i32, i32* %4
%22 = sdiv i32 %21, 2
store i32 %22, i32* %3
br label %23
23: ; preds = %31, %20
%24 = load i32, i32* %3
%25 = icmp sge i32 %24, 1
br i1 %25, label %26, label %34
26: ; preds = %23
%27 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 0
%28 = load i32, i32* %3
%29 = load i32, i32* %4
%30 = call i32 @MaxHeapify(i32* %27, i32 %28, i32 %29)
br label %31
31: ; preds = %26
%32 = load i32, i32* %3
%33 = add nsw i32 %32, -1
store i32 %33, i32* %3
br label %23
34: ; preds = %23
%35 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 0
%36 = load i32, i32* %4
%37 = call i32 @heapsort(i32* %35, i32 %36)
store i32 1, i32* %3
br label %38
38: ; preds = %48, %34
%39 = load i32, i32* %3
%40 = load i32, i32* %4
%41 = icmp sle i32 %39, %40
br i1 %41, label %42, label %51
42: ; preds = %38
%43 = load i32, i32* %3
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 %44
%46 = load i32, i32* %45
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %46)
br label %48
48: ; preds = %42
%49 = load i32, i32* %3
%50 = add nsw i32 %49, 1
store i32 %50, i32* %3
br label %38
51: ; preds = %38
ret i32 0
}

LLVM IR (-O2):
@.str = [27 x i8] c"Enter number of elements: \00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca [20 x i32]
%2 = alloca i32
%3 = bitcast [20 x i32]* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 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* %2)
%7 = load i32, i32* %2
%8 = icmp slt i32 %7, 1
br i1 %8, label %32, label %9
9: ; preds = %0, %9
%10 = phi i64 [ %13, %9 ], [ 1, %0 ]
%11 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, 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* %2
%15 = sext i32 %14 to i64
%16 = icmp slt i64 %10, %15
br i1 %16, label %9, label %17
17: ; preds = %9
%18 = icmp sgt i32 %14, 1
br i1 %18, label %19, label %32
19: ; preds = %17
%20 = lshr i32 %14, 1
%21 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 0
%22 = call i32 @MaxHeapify(i32* %21, i32 %20, i32 %14)
%23 = icmp ugt i32 %14, 3
br i1 %23, label %24, label %30
24: ; preds = %19, %24
%25 = phi i32 [ %26, %24 ], [ %20, %19 ]
%26 = add nsw i32 %25, -1
%27 = load i32, i32* %2
%28 = call i32 @MaxHeapify(i32* %21, i32 %26, i32 %27)
%29 = icmp sgt i32 %25, 2
br i1 %29, label %24, label %30
30: ; preds = %24, %19
%31 = load i32, i32* %2
br label %32
32: ; preds = %0, %30, %17
%33 = phi i32 [ %31, %30 ], [ %14, %17 ], [ %7, %0 ]
%34 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 0
%35 = call i32 @heapsort(i32* %34, i32 %33)
%36 = load i32, i32* %2
%37 = icmp slt i32 %36, 1
br i1 %37, label %47, label %38
38: ; preds = %32, %38
%39 = phi i64 [ %43, %38 ], [ 1, %32 ]
%40 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 %39
%41 = load i32, i32* %40
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %41)
%43 = add nuw nsw i64 %39, 1
%44 = load i32, i32* %2
%45 = sext i32 %44 to i64
%46 = icmp slt i64 %39, %45
br i1 %46, label %38, label %47
47: ; preds = %38, %32
ret i32 0
}