#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*/ BinSearch(int *, int, int);
int /*<<< orphan*/ LinSearch(int *, int, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int n;
  do {
    int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    int num;
    printf("1. Linear Search\n");
    printf("2. Binary Search\n");
    printf("0. Exit\n");
    printf("Enter Input: ");
    scanf("%d", &n);
    switch (n) {
    case 1:
      printf("Enter Number to Search: ");
      scanf("%d", &num);
      LinSearch(A, 10, num);
      break;
    case 2:
      printf("Enter Number to Search: ");
      scanf("%d", &num);
      BinSearch(A, 10, num);
      break;
    case 0:
      break;
    default:
      printf("Invalid Input. Try Again.\n");
    }
  } while (n != 0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeca(%rip),%rax
mov    %rax,-0x10(%rbp)
movaps 0xeaf(%rip),%xmm0
movaps %xmm0,-0x20(%rbp)
movaps 0xe94(%rip),%xmm0
movaps %xmm0,-0x30(%rbp)
lea    0xeb1(%rip),%rdi
call   1030 <printf@plt>
lea    0xeb7(%rip),%rdi
call   1030 <printf@plt>
lea    0xebd(%rip),%rdi
call   1030 <printf@plt>
lea    0xeba(%rip),%rdi
call   1030 <printf@plt>
lea    0xebc(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x38(%rbp)
test   %eax,%eax
je     1249 <main+0x109>
jmp    11c3 <main+0x83>
mov    -0x38(%rbp),%eax
sub    $0x1,%eax
je     11e5 <main+0xa5>
jmp    11d4 <main+0x94>
mov    -0x38(%rbp),%eax
sub    $0x2,%eax
je     1217 <main+0xd7>
jmp    124e <main+0x10e>
lea    0xe7a(%rip),%rdi
call   1030 <printf@plt>
lea    0xe6b(%rip),%rdi
lea    -0x34(%rbp),%rsi
call   1060 <scanf@plt>
lea    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%edx
mov    $0xa,%esi
call   1050 <LinSearch@plt>
jmp    125a <main+0x11a>
lea    0xe48(%rip),%rdi
call   1030 <printf@plt>
lea    0xe39(%rip),%rdi
lea    -0x34(%rbp),%rsi
call   1060 <scanf@plt>
lea    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%edx
mov    $0xa,%esi
call   1040 <BinSearch@plt>
jmp    125a <main+0x11a>
jmp    125a <main+0x11a>
lea    0xe2a(%rip),%rdi
call   1030 <printf@plt>
jmp    125f <main+0x11f>
cmpl   $0x0,-0x8(%rbp)
jne    114f <main+0xf>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
lea    0xeed(%rip),%r14
lea    0xef7(%rip),%r15
lea    0xf01(%rip),%r12
lea    0xeae(%rip),%r13
lea    0xeb5(%rip),%rbx
lea    0xc(%rsp),%rbp
jmp    11c7 <main+0x77>
nopl   0x0(%rax,%rax,1)
lea    0xea2(%rip),%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
lea    0x8(%rsp),%rsi
call   1070 <scanf@plt>
mov    0x8(%rsp),%edx
lea    0x10(%rsp),%rdi
mov    $0xa,%esi
call   1050 <BinSearch@plt>
cmpl   $0x0,0xc(%rsp)
je     1271 <main+0x121>
mov    0xe52(%rip),%rax
mov    %rax,0x30(%rsp)
movaps 0xe36(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe1a(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %r12,%rdi
call   1030 <puts@plt>
mov    %r13,%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1070 <scanf@plt>
mov    0xc(%rsp),%eax
cmp    $0x1,%eax
je     1240 <main+0xf0>
cmp    $0x2,%eax
je     1190 <main+0x40>
test   %eax,%eax
je     1271 <main+0x121>
lea    0xe49(%rip),%rdi
call   1030 <puts@plt>
jmp    11bc <main+0x6c>
nopw   0x0(%rax,%rax,1)
lea    0xdf2(%rip),%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
lea    0x8(%rsp),%rsi
call   1070 <scanf@plt>
mov    0x8(%rsp),%edx
lea    0x10(%rsp),%rdi
mov    $0xa,%esi
call   1060 <LinSearch@plt>
jmp    11bc <main+0x6c>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.A = [10 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10]
@.str = [18 x i8] c"1. Linear Search\0A\00"
@.str.1 = [18 x i8] c"2. Binary Search\0A\00"
@.str.2 = [9 x i8] c"0. Exit\0A\00"
@.str.3 = [14 x i8] c"Enter Input: \00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [25 x i8] c"Enter Number to Search: \00"
@.str.6 = [27 x i8] c"Invalid Input. Try Again.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [10 x i32]
%4 = alloca i32
store i32 0, i32* %1
br label %5
5: ; preds = %29, %0
%6 = bitcast [10 x i32]* %3 to i8*
%7 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %2)
%12 = load i32, i32* %2
switch i32 %12, label %26 [
i32 1, label %13
i32 2, label %19
i32 0, label %25
]
13: ; preds = %5
%14 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %4)
%16 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 0
%17 = load i32, i32* %4
%18 = call i32 @LinSearch(i32* %16, i32 10, i32 %17)
br label %28
19: ; preds = %5
%20 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %4)
%22 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 0
%23 = load i32, i32* %4
%24 = call i32 @BinSearch(i32* %22, i32 10, i32 %23)
br label %28
25: ; preds = %5
br label %28
26: ; preds = %5
%27 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0))
br label %28
28: ; preds = %26, %25, %19, %13
br label %29
29: ; preds = %28
%30 = load i32, i32* %2
%31 = icmp ne i32 %30, 0
br i1 %31, label %5, label %32
32: ; preds = %29
%33 = load i32, i32* %1
ret i32 %33
}

LLVM IR (-O2):
@__const.main.A = [10 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10]
@.str.3 = [14 x i8] c"Enter Input: \00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [25 x i8] c"Enter Number to Search: \00"
@str = [17 x i8] c"1. Linear Search\00"
@str.7 = [17 x i8] c"2. Binary Search\00"
@str.8 = [8 x i8] c"0. Exit\00"
@str.9 = [26 x i8] c"Invalid Input. Try Again.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i32]
%3 = alloca i32
%4 = bitcast i32* %1 to i8*
%5 = bitcast [10 x i32]* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
br label %8
8: ; preds = %28, %0
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.7, i64 0, i64 0))
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.8, i64 0, i64 0))
%12 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %1)
%14 = load i32, i32* %1
switch i32 %14, label %26 [
i32 1, label %16
i32 2, label %21
i32 0, label %15
]
15: ; preds = %8
br label %31
16: ; preds = %8
%17 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %3)
%19 = load i32, i32* %3
%20 = call i32 @LinSearch(i32* %7, i32 10, i32 %19)
br label %28
21: ; preds = %8
%22 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
%23 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %3)
%24 = load i32, i32* %3
%25 = call i32 @BinSearch(i32* %7, i32 10, i32 %24)
br label %28
26: ; preds = %8
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.9, i64 0, i64 0))
br label %28
28: ; preds = %26, %21, %16
%29 = load i32, i32* %1
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %8
31: ; preds = %28, %15
ret i32 0
}