#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 (int *, int);
int insert(int *, int);
int merge(int *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ search(int *, int);
int /*<<< orphan*/ sort(int *, int);
int /*<<< orphan*/ traverse(int *, int);
main() {
  int a[100], n, pos, len, i, ch;
  printf("\nEnter the number of numbers:");
  scanf("%d", &len);
  for (i = 0; i < len; i++) {
    printf("Enter the %dth element:", i + 1);
    scanf("%d", &a[i]);
  }
  do {
    printf("\n**MENU**\n\n1.INSERT\n2.DELETE\n3.SORT\n4.SEARCH");
    printf("\n5.MERGE\n6.EXIT\n");
    printf("\nEnter your choice:");
    scanf("%d", &ch);
    switch (ch) {
    case 1:
      len = insert(a, len);
      traverse(a, len);
      break;
    case 2:
      len = delete (a, len);
      traverse(a, len);
      break;
    case 3:
      sort(a, len);
      traverse(a, len);
      break;
    case 4:
      search(a, len);
      traverse(a, len);
      break;
    case 5:
      len = merge(a, len);
      traverse(a, len);
      break;
    case 6:
      printf("\nbye\n");
      break;
    default:
      printf("\nInvalid choice Try again!!");
      break;
    }
  } while (ch != 6);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1d0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe8f(%rip),%rdi
lea    -0x1ac(%rbp),%rsi
call   1080 <scanf@plt>
movl   $0x0,-0x1b0(%rbp)
mov    -0x1b0(%rbp),%eax
cmp    -0x1ac(%rbp),%eax
jge    121b <main+0x9b>
mov    -0x1b0(%rbp),%esi
add    $0x1,%esi
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movslq -0x1b0(%rbp),%rax
lea    -0x1a0(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe34(%rip),%rdi
call   1080 <scanf@plt>
mov    -0x1b0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1b0(%rbp)
jmp    11bd <main+0x3d>
jmp    1220 <main+0xa0>
lea    0xe2a(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x1c1(%rbp)
call   1030 <printf@plt>
mov    -0x1c1(%rbp),%al
lea    0xe3d(%rip),%rdi
call   1030 <printf@plt>
mov    -0x1c1(%rbp),%al
lea    0xe3c(%rip),%rdi
call   1030 <printf@plt>
lea    0xdd7(%rip),%rdi
lea    -0x1b4(%rbp),%rsi
call   1080 <scanf@plt>
mov    -0x1b4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x1c0(%rbp)
sub    $0x5,%eax
ja     138f <main+0x20f>
mov    -0x1c0(%rbp),%rax
lea    0xd6c(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    -0x1a0(%rbp),%rdi
mov    -0x1ac(%rbp),%esi
call   1090 <insert@plt>
mov    %eax,-0x1ac(%rbp)
lea    -0x1a0(%rbp),%rdi
mov    -0x1ac(%rbp),%esi
call   1050 <traverse@plt>
jmp    139d <main+0x21d>
lea    -0x1a0(%rbp),%rdi
mov    -0x1ac(%rbp),%esi
call   10a0 <delete@plt>
mov    %eax,-0x1ac(%rbp)
lea    -0x1a0(%rbp),%rdi
mov    -0x1ac(%rbp),%esi
call   1050 <traverse@plt>
jmp    139d <main+0x21d>
lea    -0x1a0(%rbp),%rdi
mov    -0x1ac(%rbp),%esi
call   1040 <sort@plt>
lea    -0x1a0(%rbp),%rdi
mov    -0x1ac(%rbp),%esi
call   1050 <traverse@plt>
jmp    139d <main+0x21d>
lea    -0x1a0(%rbp),%rdi
mov    -0x1ac(%rbp),%esi
call   1060 <search@plt>
lea    -0x1a0(%rbp),%rdi
mov    -0x1ac(%rbp),%esi
call   1050 <traverse@plt>
jmp    139d <main+0x21d>
lea    -0x1a0(%rbp),%rdi
mov    -0x1ac(%rbp),%esi
call   1070 <merge@plt>
mov    %eax,-0x1ac(%rbp)
lea    -0x1a0(%rbp),%rdi
mov    -0x1ac(%rbp),%esi
call   1050 <traverse@plt>
jmp    139d <main+0x21d>
lea    0xd20(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    139d <main+0x21d>
lea    0xd13(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    13a2 <main+0x222>
cmpl   $0x6,-0x1b4(%rbp)
jne    1220 <main+0xa0>
mov    -0x4(%rbp),%eax
add    $0x1d0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1a8,%rsp
lea    0xe73(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe83(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1090 <scanf@plt>
cmpl   $0x0,0x8(%rsp)
jle    1235 <main+0xa5>
lea    0x10(%rsp),%r12
lea    0xe69(%rip),%r14
lea    0xe5f(%rip),%r15
xor    %ebx,%ebx
nopl   0x0(%rax)
add    $0x1,%rbx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1090 <scanf@plt>
movslq 0x8(%rsp),%rax
add    $0x4,%r12
cmp    %rax,%rbx
jl     11e0 <main+0x50>
jmp    1235 <main+0xa5>
mov    0x8(%rsp),%esi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   10a0 <insert@plt>
mov    %eax,0x8(%rsp)
mov    %rbx,%rdi
mov    %eax,%esi
call   1060 <traverse@plt>
cmpl   $0x6,0xc(%rsp)
je     130a <main+0x17a>
lea    0xe15(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe64(%rip),%rdi
call   1030 <puts@plt>
lea    0xe28(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xdd2(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1090 <scanf@plt>
mov    0xc(%rsp),%eax
add    $0xffffffff,%eax
cmp    $0x5,%eax
ja     12a0 <main+0x110>
lea    0xd7f(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x8(%rsp),%esi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   10b0 <delete@plt>
jmp    121c <main+0x8c>
lea    0xdeb(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    122a <main+0x9a>
mov    0x8(%rsp),%esi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <sort@plt>
jmp    12d7 <main+0x147>
mov    0x8(%rsp),%esi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <search@plt>
mov    0x8(%rsp),%esi
mov    %rbx,%rdi
jmp    1225 <main+0x95>
mov    0x8(%rsp),%esi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1080 <merge@plt>
jmp    121c <main+0x8c>
lea    0xdbe(%rip),%rdi
call   1030 <puts@plt>
jmp    122a <main+0x9a>
xor    %eax,%eax
add    $0x1a8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [30 x i8] c"\0AEnter the number of numbers:\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [24 x i8] c"Enter the %dth element:\00"
@.str.3 = [45 x i8] c"\0A**MENU**\0A\0A1.INSERT\0A2.DELETE\0A3.SORT\0A4.SEARCH\00"
@.str.4 = [17 x i8] c"\0A5.MERGE\0A6.EXIT\0A\00"
@.str.5 = [20 x i8] c"\0AEnter your choice:\00"
@.str.6 = [6 x i8] c"\0Abye\0A\00"
@.str.7 = [28 x i8] c"\0AInvalid choice Try again!!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
store i32 0, i32* %6
br label %10
10: ; preds = %22, %0
%11 = load i32, i32* %6
%12 = load i32, i32* %5
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %25
14: ; preds = %10
%15 = load i32, i32* %6
%16 = add nsw i32 %15, 1
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%18 = load i32, i32* %6
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %19
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %20)
br label %22
22: ; preds = %14
%23 = load i32, i32* %6
%24 = add nsw i32 %23, 1
store i32 %24, i32* %6
br label %10
25: ; preds = %10
br label %26
26: ; preds = %72, %25
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0))
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%30 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %7)
%31 = load i32, i32* %7
switch i32 %31, label %69 [
i32 1, label %32
i32 2, label %39
i32 3, label %46
i32 4, label %53
i32 5, label %60
i32 6, label %67
]
32: ; preds = %26
%33 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%34 = load i32, i32* %5
%35 = call i32 @insert(i32* %33, i32 %34)
store i32 %35, i32* %5
%36 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%37 = load i32, i32* %5
%38 = call i32 @traverse(i32* %36, i32 %37)
br label %71
39: ; preds = %26
%40 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%41 = load i32, i32* %5
%42 = call i32 @delete(i32* %40, i32 %41)
store i32 %42, i32* %5
%43 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%44 = load i32, i32* %5
%45 = call i32 @traverse(i32* %43, i32 %44)
br label %71
46: ; preds = %26
%47 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%48 = load i32, i32* %5
%49 = call i32 @sort(i32* %47, i32 %48)
%50 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%51 = load i32, i32* %5
%52 = call i32 @traverse(i32* %50, i32 %51)
br label %71
53: ; preds = %26
%54 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%55 = load i32, i32* %5
%56 = call i32 @search(i32* %54, i32 %55)
%57 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%58 = load i32, i32* %5
%59 = call i32 @traverse(i32* %57, i32 %58)
br label %71
60: ; preds = %26
%61 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%62 = load i32, i32* %5
%63 = call i32 @merge(i32* %61, i32 %62)
store i32 %63, i32* %5
%64 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%65 = load i32, i32* %5
%66 = call i32 @traverse(i32* %64, i32 %65)
br label %71
67: ; preds = %26
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
br label %71
69: ; preds = %26
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0))
br label %71
71: ; preds = %69, %67, %60, %53, %46, %39, %32
br label %72
72: ; preds = %71
%73 = load i32, i32* %7
%74 = icmp ne i32 %73, 6
br i1 %74, label %26, label %75
75: ; preds = %72
%76 = load i32, i32* %1
ret i32 %76
}

LLVM IR (-O2):
@.str = [30 x i8] c"\0AEnter the number of numbers:\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [24 x i8] c"Enter the %dth element:\00"
@.str.3 = [45 x i8] c"\0A**MENU**\0A\0A1.INSERT\0A2.DELETE\0A3.SORT\0A4.SEARCH\00"
@.str.5 = [20 x i8] c"\0AEnter your choice:\00"
@.str.7 = [28 x i8] c"\0AInvalid choice Try again!!\00"
@str = [16 x i8] c"\0A5.MERGE\0A6.EXIT\00"
@str.8 = [5 x i8] c"\0Abye\00"
define i32 @main() {
%1 = alloca [100 x i32]
%2 = alloca i32
%3 = alloca i32
%4 = bitcast [100 x i32]* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 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* %2)
%9 = load i32, i32* %2
%10 = icmp sgt i32 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %13, %0
%12 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 0
br label %23
13: ; preds = %0, %13
%14 = phi i64 [ %15, %13 ], [ 0, %0 ]
%15 = add nuw nsw i64 %14, 1
%16 = trunc i64 %15 to i32
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%18 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 %14
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %18)
%20 = load i32, i32* %2
%21 = sext i32 %20 to i64
%22 = icmp slt i64 %15, %21
br i1 %22, label %13, label %11
23: ; preds = %11, %55
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0))
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%27 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%28 = load i32, i32* %3
switch i32 %28, label %53 [
i32 1, label %29
i32 2, label %33
i32 3, label %37
i32 4, label %42
i32 5, label %47
i32 6, label %51
]
29: ; preds = %23
%30 = load i32, i32* %2
%31 = call i32 @insert(i32* %12, i32 %30)
store i32 %31, i32* %2
%32 = call i32 @traverse(i32* %12, i32 %31)
br label %55
33: ; preds = %23
%34 = load i32, i32* %2
%35 = call i32 @delete(i32* %12, i32 %34)
store i32 %35, i32* %2
%36 = call i32 @traverse(i32* %12, i32 %35)
br label %55
37: ; preds = %23
%38 = load i32, i32* %2
%39 = call i32 @sort(i32* %12, i32 %38)
%40 = load i32, i32* %2
%41 = call i32 @traverse(i32* %12, i32 %40)
br label %55
42: ; preds = %23
%43 = load i32, i32* %2
%44 = call i32 @search(i32* %12, i32 %43)
%45 = load i32, i32* %2
%46 = call i32 @traverse(i32* %12, i32 %45)
br label %55
47: ; preds = %23
%48 = load i32, i32* %2
%49 = call i32 @merge(i32* %12, i32 %48)
store i32 %49, i32* %2
%50 = call i32 @traverse(i32* %12, i32 %49)
br label %55
51: ; preds = %23
%52 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.8, i64 0, i64 0))
br label %55
53: ; preds = %23
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0))
br label %55
55: ; preds = %29, %33, %37, %42, %47, %51, %53
%56 = load i32, i32* %3
%57 = icmp eq i32 %56, 6
br i1 %57, label %58, label %23
58: ; preds = %55
ret i32 0
}