#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*/ create(int *);
int /*<<< orphan*/ down_adjust(int *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
void main() {
  int heap[30], n, i, last, temp;
  printf("Enter no. of elements:");
  scanf("%d", &n);
  printf("\nEnter elements:");
  for (i = 1; i <= n; i++)
    scanf("%d", &heap[i]);
  heap[0] = n;
  create(heap);
  while (heap[0] > 1) {
    last = heap[0];
    temp = heap[1];
    heap[1] = heap[last];
    heap[last] = temp;
    heap[0]--;
    down_adjust(heap, 1);
  }
  printf("\nArray after sorting:\n");
  for (i = 1; i <= n; i++)
    printf("%d ", heap[i]);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb7(%rip),%rdi
lea    -0x84(%rbp),%rsi
call   1060 <scanf@plt>
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x88(%rbp)
mov    -0x88(%rbp),%eax
cmp    -0x84(%rbp),%eax
jg     11c8 <main+0x88>
movslq -0x88(%rbp),%rax
lea    -0x80(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe68(%rip),%rdi
call   1060 <scanf@plt>
mov    -0x88(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x88(%rbp)
jmp    1184 <main+0x44>
mov    -0x84(%rbp),%eax
mov    %eax,-0x80(%rbp)
lea    -0x80(%rbp),%rdi
call   1040 <create@plt>
cmpl   $0x1,-0x80(%rbp)
jle    1231 <main+0xf1>
mov    -0x80(%rbp),%eax
mov    %eax,-0x8c(%rbp)
mov    -0x7c(%rbp),%eax
mov    %eax,-0x90(%rbp)
movslq -0x8c(%rbp),%rax
mov    -0x80(%rbp,%rax,4),%eax
mov    %eax,-0x7c(%rbp)
mov    -0x90(%rbp),%ecx
movslq -0x8c(%rbp),%rax
mov    %ecx,-0x80(%rbp,%rax,4)
mov    -0x80(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x80(%rbp)
lea    -0x80(%rbp),%rdi
mov    $0x1,%esi
call   1050 <down_adjust@plt>
jmp    11da <main+0x9a>
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x88(%rbp)
mov    -0x88(%rbp),%eax
cmp    -0x84(%rbp),%eax
jg     1288 <main+0x148>
movslq -0x88(%rbp),%rax
mov    -0x80(%rbp,%rax,4),%esi
lea    0xdd5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x88(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x88(%rbp)
jmp    1249 <main+0x109>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x90,%rsp
lea    0xe9d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xea6(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1070 <scanf@plt>
lea    0xe98(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
jle    11bd <main+0x6d>
lea    0x14(%rsp),%r15
xor    %ebx,%ebx
lea    0xe78(%rip),%r14
nop
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <scanf@plt>
movslq 0xc(%rsp),%rax
add    $0x1,%rbx
add    $0x4,%r15
cmp    %rax,%rbx
jl     11a0 <main+0x50>
mov    %eax,0x10(%rsp)
lea    0x10(%rsp),%rdi
call   1050 <create@plt>
mov    0x10(%rsp),%eax
cmp    $0x2,%eax
jl     120f <main+0xbf>
lea    0x10(%rsp),%rbx
nopl   0x0(%rax)
mov    0x14(%rsp),%ecx
mov    %eax,%edx
mov    0x10(%rsp,%rdx,4),%esi
mov    %esi,0x14(%rsp)
mov    %ecx,0x10(%rsp,%rdx,4)
add    $0xffffffff,%eax
mov    %eax,0x10(%rsp)
mov    %rbx,%rdi
mov    $0x1,%esi
call   1060 <down_adjust@plt>
mov    0x10(%rsp),%eax
cmp    $0x1,%eax
jg     11e0 <main+0x90>
lea    0xe19(%rip),%rdi
call   1030 <puts@plt>
cmpl   $0x0,0xc(%rsp)
jle    124c <main+0xfc>
lea    0xe02(%rip),%r14
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    0x14(%rsp,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movslq 0xc(%rsp),%rax
add    $0x1,%rbx
cmp    %rax,%rbx
jl     1230 <main+0xe0>
add    $0x90,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [23 x i8] c"Enter no. of elements:\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [17 x i8] c"\0AEnter elements:\00"
@.str.3 = [23 x i8] c"\0AArray after sorting:\0A\00"
@.str.4 = [4 x i8] c"%d \00"
define void @main() {
%1 = alloca [30 x i32]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 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* %2)
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %9
9: ; preds = %18, %0
%10 = load i32, i32* %3
%11 = load i32, i32* %2
%12 = icmp sle i32 %10, %11
br i1 %12, label %13, label %21
13: ; preds = %9
%14 = load i32, i32* %3
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [30 x i32], [30 x i32]* %1, i64 0, 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 = %13
%19 = load i32, i32* %3
%20 = add nsw i32 %19, 1
store i32 %20, i32* %3
br label %9
21: ; preds = %9
%22 = load i32, i32* %2
%23 = getelementptr inbounds [30 x i32], [30 x i32]* %1, i64 0, i64 0
store i32 %22, i32* %23
%24 = getelementptr inbounds [30 x i32], [30 x i32]* %1, i64 0, i64 0
%25 = call i32 @create(i32* %24)
br label %26
26: ; preds = %30, %21
%27 = getelementptr inbounds [30 x i32], [30 x i32]* %1, i64 0, i64 0
%28 = load i32, i32* %27
%29 = icmp sgt i32 %28, 1
br i1 %29, label %30, label %49
30: ; preds = %26
%31 = getelementptr inbounds [30 x i32], [30 x i32]* %1, i64 0, i64 0
%32 = load i32, i32* %31
store i32 %32, i32* %4
%33 = getelementptr inbounds [30 x i32], [30 x i32]* %1, i64 0, i64 1
%34 = load i32, i32* %33
store i32 %34, i32* %5
%35 = load i32, i32* %4
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [30 x i32], [30 x i32]* %1, i64 0, i64 %36
%38 = load i32, i32* %37
%39 = getelementptr inbounds [30 x i32], [30 x i32]* %1, i64 0, i64 1
store i32 %38, i32* %39
%40 = load i32, i32* %5
%41 = load i32, i32* %4
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [30 x i32], [30 x i32]* %1, i64 0, i64 %42
store i32 %40, i32* %43
%44 = getelementptr inbounds [30 x i32], [30 x i32]* %1, i64 0, i64 0
%45 = load i32, i32* %44
%46 = add nsw i32 %45, -1
store i32 %46, i32* %44
%47 = getelementptr inbounds [30 x i32], [30 x i32]* %1, i64 0, i64 0
%48 = call i32 @down_adjust(i32* %47, i32 1)
br label %26
49: ; preds = %26
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %51
51: ; preds = %61, %49
%52 = load i32, i32* %3
%53 = load i32, i32* %2
%54 = icmp sle i32 %52, %53
br i1 %54, label %55, label %64
55: ; preds = %51
%56 = load i32, i32* %3
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [30 x i32], [30 x i32]* %1, i64 0, i64 %57
%59 = load i32, i32* %58
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %59)
br label %61
61: ; preds = %55
%62 = load i32, i32* %3
%63 = add nsw i32 %62, 1
store i32 %63, i32* %3
br label %51
64: ; preds = %51
ret void
}

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