#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);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scamf(char *, int *);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int *a, size, i;
  printf("\nEnter Size :");
  scamf("%d", &size);
  printf("\nEnter Elements :");
  for (i = 0; i < size; i++) {
    scanf("%d", a + i);
  }
  printf("\nBefore Sorting:\n");
  for (i = 0; i < size; i++) {
    printf(" %d ", *(a + i));
  }
  heapsort(a, size);
  printf("\nAfter Sorting:\n");
  for (i = 0; i < size; i++) {
    printf("%d\n", *(a + i));
  }
  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   1030 <printf@plt>
lea    0xeaa(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1060 <scamf@plt>
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11b7 <main+0x77>
mov    -0x10(%rbp),%rsi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe6a(%rip),%rdi
call   1050 <scanf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1182 <main+0x42>
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11ff <main+0xbf>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11cc <main+0x8c>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <heapsort@plt>
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1253 <main+0x113>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1220 <main+0xe0>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
lea    0xea6(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xea4(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1070 <scamf@plt>
lea    0xe96(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmpl   $0x0,0x4(%rsp)
jle    11a1 <main+0x51>
lea    0xe7e(%rip),%rbx
mov    %rbx,%rdi
call   1060 <scanf@plt>
add    $0x1,%ebp
cmp    0x4(%rsp),%ebp
jl     1190 <main+0x40>
lea    0xe84(%rip),%rdi
call   1030 <puts@plt>
mov    0x4(%rsp),%esi
test   %esi,%esi
jle    11d5 <main+0x85>
lea    0xe67(%rip),%rbx
xor    %ebp,%ebp
xchg   %ax,%ax
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebp
mov    0x4(%rsp),%esi
cmp    %esi,%ebp
jl     11c0 <main+0x70>
call   1050 <heapsort@plt>
lea    0xe5c(%rip),%rdi
call   1030 <puts@plt>
cmpl   $0x0,0x4(%rsp)
jle    1213 <main+0xc3>
lea    0xe34(%rip),%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebp
cmp    0x4(%rsp),%ebp
jl     1200 <main+0xb0>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"\0AEnter Size :\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [18 x i8] c"\0AEnter Elements :\00"
@.str.3 = [18 x i8] c"\0ABefore Sorting:\0A\00"
@.str.4 = [5 x i8] c" %d \00"
@.str.5 = [17 x i8] c"\0AAfter Sorting:\0A\00"
@.str.6 = [4 x i8] c"%d\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 ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scamf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %4
br label %8
8: ; preds = %18, %0
%9 = load i32, i32* %4
%10 = load i32, i32* %3
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %21
12: ; preds = %8
%13 = load i32*, i32** %2
%14 = load i32, i32* %4
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i32, i32* %13, i64 %15
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %16)
br label %18
18: ; preds = %12
%19 = load i32, i32* %4
%20 = add nsw i32 %19, 1
store i32 %20, i32* %4
br label %8
21: ; preds = %8
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %4
br label %23
23: ; preds = %34, %21
%24 = load i32, i32* %4
%25 = load i32, i32* %3
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %37
27: ; preds = %23
%28 = load i32*, i32** %2
%29 = load i32, i32* %4
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %28, i64 %30
%32 = load i32, i32* %31
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %32)
br label %34
34: ; preds = %27
%35 = load i32, i32* %4
%36 = add nsw i32 %35, 1
store i32 %36, i32* %4
br label %23
37: ; preds = %23
%38 = load i32*, i32** %2
%39 = load i32, i32* %3
%40 = call i32 @heapsort(i32* %38, i32 %39)
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %4
br label %42
42: ; preds = %53, %37
%43 = load i32, i32* %4
%44 = load i32, i32* %3
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %56
46: ; preds = %42
%47 = load i32*, i32** %2
%48 = load i32, i32* %4
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i32, i32* %47, i64 %49
%51 = load i32, i32* %50
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %51)
br label %53
53: ; preds = %46
%54 = load i32, i32* %4
%55 = add nsw i32 %54, 1
store i32 %55, i32* %4
br label %42
56: ; preds = %42
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"\0AEnter Size :\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [18 x i8] c"\0AEnter Elements :\00"
@.str.4 = [5 x i8] c" %d \00"
@.str.6 = [4 x i8] c"%d\0A\00"
@str = [17 x i8] c"\0ABefore Sorting:\00"
@str.7 = [16 x i8] c"\0AAfter Sorting:\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scamf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%6 = load i32, i32* %1
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %14
8: ; preds = %0, %8
%9 = phi i32 [ %11, %8 ], [ 0, %0 ]
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* poison)
%11 = add nuw nsw i32 %9, 1
%12 = load i32, i32* %1
%13 = icmp slt i32 %11, %12
br i1 %13, label %8, label %14
14: ; preds = %8, %0
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%16 = load i32, i32* %1
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %14, %18
%19 = phi i32 [ %21, %18 ], [ 0, %14 ]
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 undef)
%21 = add nuw nsw i32 %19, 1
%22 = load i32, i32* %1
%23 = icmp slt i32 %21, %22
br i1 %23, label %18, label %24
24: ; preds = %18, %14
%25 = phi i32 [ %16, %14 ], [ %22, %18 ]
%26 = call i32 @heapsort(i32* undef, i32 %25)
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.7, i64 0, i64 0))
%28 = load i32, i32* %1
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %36
30: ; preds = %24, %30
%31 = phi i32 [ %33, %30 ], [ 0, %24 ]
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 undef)
%33 = add nuw nsw i32 %31, 1
%34 = load i32, i32* %1
%35 = icmp slt i32 %33, %34
br i1 %35, label %30, label %36
36: ; preds = %30, %24
ret i32 0
}