#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 delete_heap(int *, int);
int /*<<< orphan*/ display(int *, int);
int insert_heap(int, int *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int a[20];
  int n = 0, ch, item;
  while (1) {
    printf(
        "\n1. Insert\n2. Delete\n3. Display\n4. Exit\n Enter your choice : ");
    scanf("%d", &ch);
    switch (ch) {
    case 1:
      printf("Enter the item to insert : ");
      scanf("%d", &item);
      n = insert_heap(item, a, n);
      break;
    case 2:
      n = delete_heap(a, n);
      break;
    case 3:
      display(a, n);
      break;
    case 4:
      return 0;
    default:
      printf("Invalid Choice");
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x64(%rbp)
lea    0xea0(%rip),%rdi
call   1040 <printf@plt>
lea    0xed2(%rip),%rdi
lea    -0x68(%rbp),%rsi
call   1070 <scanf@plt>
mov    -0x68(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x78(%rbp)
sub    $0x3,%eax
ja     1211 <main+0xc1>
mov    -0x78(%rbp),%rax
lea    0xe5b(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe9c(%rip),%rdi
call   1040 <printf@plt>
lea    0xe8d(%rip),%rdi
lea    -0x6c(%rbp),%rsi
call   1070 <scanf@plt>
mov    -0x6c(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    -0x64(%rbp),%edx
call   1060 <insert_heap@plt>
mov    %eax,-0x64(%rbp)
jmp    121d <main+0xcd>
lea    -0x60(%rbp),%rdi
mov    -0x64(%rbp),%esi
call   1050 <delete_heap@plt>
mov    %eax,-0x64(%rbp)
jmp    121d <main+0xcd>
lea    -0x60(%rbp),%rdi
mov    -0x64(%rbp),%esi
call   1030 <display@plt>
jmp    121d <main+0xcd>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret
lea    0xe55(%rip),%rdi
call   1040 <printf@plt>
jmp    1169 <main+0x19>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
xor    %ebp,%ebp
lea    0xea9(%rip),%r14
lea    0xee0(%rip),%rbx
lea    0xc(%rsp),%r15
lea    0xe86(%rip),%r12
lea    0x10(%rsp),%r13
jmp    119c <main+0x4c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0xed6(%rip),%rdi
call   1040 <printf@plt>
mov    %r14,%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <scanf@plt>
mov    0xc(%rsp),%eax
add    $0xffffffff,%eax
cmp    $0x3,%eax
ja     1190 <main+0x40>
movslq (%r12,%rax,4),%rax
add    %r12,%rax
jmp    *%rax
mov    %r13,%rdi
mov    %ebp,%esi
call   1030 <display@plt>
jmp    119c <main+0x4c>
lea    0xe7a(%rip),%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
lea    0x8(%rsp),%rsi
call   1070 <scanf@plt>
mov    0x8(%rsp),%edi
mov    %r13,%rsi
mov    %ebp,%edx
call   1060 <insert_heap@plt>
mov    %eax,%ebp
jmp    119c <main+0x4c>
mov    %r13,%rdi
mov    %ebp,%esi
call   1050 <delete_heap@plt>
mov    %eax,%ebp
jmp    119c <main+0x4c>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [62 x i8] c"\0A1. Insert\0A2. Delete\0A3. Display\0A4. Exit\0A Enter your choice : \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [28 x i8] c"Enter the item to insert : \00"
@.str.3 = [15 x i8] c"Invalid Choice\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [20 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
br label %6
6: ; preds = %0, %28
%7 = call i32 @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%9 = load i32, i32* %4
switch i32 %9, label %26 [
i32 1, label %10
i32 2, label %17
i32 3, label %21
i32 4, label %25
]
10: ; preds = %6
%11 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
%13 = load i32, i32* %5
%14 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 0
%15 = load i32, i32* %3
%16 = call i32 @insert_heap(i32 %13, i32* %14, i32 %15)
store i32 %16, i32* %3
br label %28
17: ; preds = %6
%18 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 0
%19 = load i32, i32* %3
%20 = call i32 @delete_heap(i32* %18, i32 %19)
store i32 %20, i32* %3
br label %28
21: ; preds = %6
%22 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 0
%23 = load i32, i32* %3
%24 = call i32 @display(i32* %22, i32 %23)
br label %28
25: ; preds = %6
ret i32 0
26: ; preds = %6
%27 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %28
28: ; preds = %26, %21, %17, %10
br label %6
}

LLVM IR (-O2):
@.str = [62 x i8] c"\0A1. Insert\0A2. Delete\0A3. Display\0A4. Exit\0A Enter your choice : \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [28 x i8] c"Enter the item to insert : \00"
@.str.3 = [15 x i8] c"Invalid Choice\00"
define i32 @main() {
%1 = alloca [20 x i32]
%2 = alloca i32
%3 = alloca i32
%4 = bitcast [20 x i32]* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 0
br label %8
8: ; preds = %21, %0
%9 = phi i32 [ 0, %0 ], [ %22, %21 ]
br label %10
10: ; preds = %28, %8
%11 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%13 = load i32, i32* %2
switch i32 %13, label %26 [
i32 1, label %14
i32 2, label %19
i32 3, label %23
i32 4, label %25
]
14: ; preds = %10
%15 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%17 = load i32, i32* %3
%18 = call i32 @insert_heap(i32 %17, i32* %7, i32 %9)
br label %21
19: ; preds = %10
%20 = call i32 @delete_heap(i32* %7, i32 %9)
br label %21
21: ; preds = %19, %14
%22 = phi i32 [ %18, %14 ], [ %20, %19 ]
br label %8
23: ; preds = %10
%24 = call i32 @display(i32* %7, i32 %9)
br label %28
25: ; preds = %10
ret i32 0
26: ; preds = %10
%27 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %28
28: ; preds = %26, %23
br label %10
}