#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 */
typedef int /*<<< orphan*/ data;

/* Variables and functions */
int RecursiveBinarySearch(int *, int /*<<< orphan*/, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int key, index;
  printf("Binary Search : \n");
  printf("\n");
  int data[] = {1,  2,  4,   5,   7,   9,   12,  15,  16,  17,  20,
                24, 27, 28,  36,  38,  44,  45,  48,  50,  51,  52,
                54, 56, 60,  64,  72,  75,  77,  79,  80,  81,  89,
                94, 98, 100, 104, 116, 124, 156, 157, 164, 182, 200};
  printf("Element to be searched = ");
  scanf("%d", &key);
  printf("\n");
  index = RecursiveBinarySearch(data, 0, sizeof(data) / sizeof(*data), key);
  if (index == -1) {
    printf("Key not found! \n");
  } else {
    printf("Key found at index : %d \n", index);
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0xc0(%rbp),%rdi
lea    0xee4(%rip),%rsi
mov    $0xb0,%edx
call   1040 <memcpy@plt>
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe91(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0xc0(%rbp),%rdi
mov    -0x8(%rbp),%ecx
xor    %esi,%esi
mov    $0x2c,%edx
call   1060 <RecursiveBinarySearch@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11e8 <main+0xa8>
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f9 <main+0xb9>
mov    -0xc(%rbp),%esi
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0xc0,%rsp
lea    0xf78(%rip),%rdi
call   1040 <puts@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe7b(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    $0xb0,%edx
mov    %rbx,%rdi
call   1060 <memcpy@plt>
lea    0xf12(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xf1e(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1070 <scanf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0xc(%rsp),%ecx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x2c,%edx
call   1080 <RecursiveBinarySearch@plt>
cmp    $0xffffffff,%eax
je     11ea <main+0x8a>
lea    0xeee(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11f6 <main+0x96>
lea    0xf07(%rip),%rdi
call   1040 <puts@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0xc0,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Binary Search : \0A\00"
@.str.1 = [2 x i8] c"\0A\00"
@__const.main.data = [44 x i32] [i32 1, i32 2, i32 4, i32 5, i32 7, i32 9, i32 12, i32 15, i32 16, i32 17, i32 20, i32 24, i32 27, i32 28, i32 36, i32 38, i32 44, i32 45, i32 48, i32 50, i32 51, i32 52, i32 54, i32 56, i32 60, i32 64, i32 72, i32 75, i32 77, i32 79, i32 80, i32 81, i32 89, i32 94, i32 98, i32 100, i32 104, i32 116, i32 124, i32 156, i32 157, i32 164, i32 182, i32 200]
@.str.2 = [26 x i8] c"Element to be searched = \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [17 x i8] c"Key not found! \0A\00"
@.str.5 = [26 x i8] c"Key found at index : %d \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [44 x i32]
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = bitcast [44 x i32]* %4 to i8*
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = getelementptr inbounds [44 x i32], [44 x i32]* %4, i64 0, i64 0
%12 = load i32, i32* %2
%13 = call i32 @RecursiveBinarySearch(i32* %11, i32 0, i32 44, i32 %12)
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %0
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %21
18: ; preds = %0
%19 = load i32, i32* %3
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %18, %16
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@__const.main.data = [44 x i32] [i32 1, i32 2, i32 4, i32 5, i32 7, i32 9, i32 12, i32 15, i32 16, i32 17, i32 20, i32 24, i32 27, i32 28, i32 36, i32 38, i32 44, i32 45, i32 48, i32 50, i32 51, i32 52, i32 54, i32 56, i32 60, i32 64, i32 72, i32 75, i32 77, i32 79, i32 80, i32 81, i32 89, i32 94, i32 98, i32 100, i32 104, i32 116, i32 124, i32 156, i32 157, i32 164, i32 182, i32 200]
@.str.2 = [26 x i8] c"Element to be searched = \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.5 = [26 x i8] c"Key found at index : %d \0A\00"
@str = [17 x i8] c"Binary Search : \00"
@str.6 = [16 x i8] c"Key not found! \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [44 x i32]
%3 = bitcast i32* %1 to i8*
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%5 = tail call i32 @putchar(i32 10)
%6 = bitcast [44 x i32]* %2 to i8*
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%9 = call i32 @putchar(i32 10)
%10 = getelementptr inbounds [44 x i32], [44 x i32]* %2, i64 0, i64 0
%11 = load i32, i32* %1
%12 = call i32 @RecursiveBinarySearch(i32* %10, i32 0, i32 44, i32 %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.6, i64 0, i64 0))
br label %18
16: ; preds = %0
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i32 %12)
br label %18
18: ; preds = %16, %14
%19 = call i32 @putchar(i32 10)
ret i32 0
}