#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_head(int *, int);
int /*<<< orphan*/ display(int *, int);
int insert_heap(int, int *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
void main() {
  int a[10];
  int n = 0, choice, item;
  for (;;) {
    printf("1. Insert\n");
    printf("2. Delete\n");
    printf("3. Display\n");
    printf("4. Exit\n");
    printf("Enter your choice: ");
    scanf("%d", &choice);
    switch (choice) {
    case 1:
      printf("Enter the item to be inserted\n");
      scanf("%d", &item);
      n = insert_heap(item, a, n);
      break;
    case 2:
      n = delete_head(a, n);
      break;
    case 3:
      display(a, n);
      break;
    default:
      return;
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x34(%rbp)
lea    0xe9a(%rip),%rdi
call   1040 <printf@plt>
lea    0xe99(%rip),%rdi
call   1040 <printf@plt>
lea    0xe98(%rip),%rdi
call   1040 <printf@plt>
lea    0xe98(%rip),%rdi
call   1040 <printf@plt>
lea    0xe95(%rip),%rdi
call   1040 <printf@plt>
lea    0xe9d(%rip),%rdi
lea    -0x38(%rbp),%rsi
call   1070 <scanf@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-0x40(%rbp)
sub    $0x1,%eax
je     11e1 <main+0x91>
jmp    11bf <main+0x6f>
mov    -0x40(%rbp),%eax
sub    $0x2,%eax
je     1214 <main+0xc4>
jmp    11d0 <main+0x80>
mov    -0x40(%rbp),%eax
sub    $0x3,%eax
je     1228 <main+0xd8>
jmp    1239 <main+0xe9>
lea    0xe5a(%rip),%rdi
call   1040 <printf@plt>
lea    0xe4b(%rip),%rdi
lea    -0x3c(%rbp),%rsi
call   1070 <scanf@plt>
mov    -0x3c(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   1060 <insert_heap@plt>
mov    %eax,-0x34(%rbp)
jmp    123f <main+0xef>
lea    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%esi
call   1050 <delete_head@plt>
mov    %eax,-0x34(%rbp)
jmp    123f <main+0xef>
lea    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%esi
call   1030 <display@plt>
jmp    123f <main+0xef>
add    $0x40,%rsp
pop    %rbp
ret
jmp    115f <main+0xf>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
xor    %r14d,%r14d
lea    0xebe(%rip),%r13
lea    0xe81(%rip),%rbx
lea    0xe8e(%rip),%rbp
lea    0xc(%rsp),%r15
lea    0x10(%rsp),%r12
jmp    11ab <main+0x4b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rdi
mov    %r14d,%esi
call   1040 <display@plt>
lea    0xe65(%rip),%rdi
call   1030 <puts@plt>
lea    0xe63(%rip),%rdi
call   1030 <puts@plt>
lea    0xe61(%rip),%rdi
call   1030 <puts@plt>
mov    %r13,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
call   1080 <scanf@plt>
mov    0xc(%rsp),%eax
cmp    $0x3,%eax
je     11a0 <main+0x40>
cmp    $0x2,%eax
je     122a <main+0xca>
cmp    $0x1,%eax
jne    123d <main+0xdd>
lea    0xe3a(%rip),%rdi
call   1030 <puts@plt>
mov    %rbp,%rdi
lea    0x8(%rsp),%rsi
call   1080 <scanf@plt>
mov    0x8(%rsp),%edi
mov    %r12,%rsi
mov    %r14d,%edx
call   1070 <insert_heap@plt>
mov    %eax,%r14d
jmp    11ab <main+0x4b>
mov    %r12,%rdi
mov    %r14d,%esi
call   1060 <delete_head@plt>
mov    %eax,%r14d
jmp    11ab <main+0x4b>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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