#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 binary_search(int *, int /*<<< orphan*/, int, int);
int binary_search_recursive(int *, int /*<<< orphan*/, int, int);
int /*<<< orphan*/ printf(char *, int, ...);
int main() {
  int arr[5] = {11, 22, 33, 44, 55};
  int status = 0, l, r, key;
  int ret = 0;
  l = 0;
  r = 5 - 1;
  key = 33;
  status = binary_search(arr, 0, 4, key);
  if (status != -1)
    printf("binary_search():found %d at index %d\n", key, status);
  else {
    printf("binary_search():key %d not found\n", key);
    ret = -1;
  }
  key = 66;
  status = binary_search(arr, 0, 4, key);
  if (status != -1)
    printf("binary_search():found %d at index %d\n", key, status);
  else {
    printf("binary_search():key %d not found\n", key);
    ret = -1;
  }
  key = 22;
  status = binary_search_recursive(arr, 0, 4, key);
  if (status != -1)
    printf("binary_search_recursive():found %d at index %d\n", key, status);
  else {
    printf("binary_search_recursive():key %d not found\n", key);
    ret = -1;
  }
  key = 67;
  status = binary_search_recursive(arr, 0, 4, key);
  if (status != -1)
    printf("binary_search_recursive():found %d at index %d\n", key, status);
  else {
    printf("binary_search_recursive():key %d not found\n", key);
    ret = -1;
  }
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeba(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xeb7(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xeb5(%rip),%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x4,-0x2c(%rbp)
movl   $0x21,-0x30(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%ecx
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <binary_search@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
je     11ba <main+0x8a>
mov    -0x30(%rbp),%esi
mov    -0x24(%rbp),%edx
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11d2 <main+0xa2>
mov    -0x30(%rbp),%esi
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x34(%rbp)
movl   $0x42,-0x30(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%ecx
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <binary_search@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
je     1212 <main+0xe2>
mov    -0x30(%rbp),%esi
mov    -0x24(%rbp),%edx
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    122a <main+0xfa>
mov    -0x30(%rbp),%esi
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x34(%rbp)
movl   $0x16,-0x30(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%ecx
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <binary_search_recursive@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
je     126a <main+0x13a>
mov    -0x30(%rbp),%esi
mov    -0x24(%rbp),%edx
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1282 <main+0x152>
mov    -0x30(%rbp),%esi
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x34(%rbp)
movl   $0x43,-0x30(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%ecx
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <binary_search_recursive@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
je     12c2 <main+0x192>
mov    -0x30(%rbp),%esi
mov    -0x24(%rbp),%edx
lea    0xda6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12da <main+0x1aa>
mov    -0x30(%rbp),%esi
lea    0xdc0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x34(%rbp)
mov    -0x34(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
mov    0xed5(%rip),%eax
mov    %eax,0x10(%rsp)
movaps 0xeba(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rdi
xor    %ebx,%ebx
xor    %esi,%esi
mov    $0x4,%edx
mov    $0x21,%ecx
call   1040 <binary_search@plt>
cmp    $0xffffffff,%eax
je     117c <main+0x4c>
lea    0xea8(%rip),%rdi
mov    $0x21,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1194 <main+0x64>
lea    0xeb7(%rip),%rdi
mov    $0x21,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0xffffffff,%ebx
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x4,%edx
mov    $0x42,%ecx
call   1040 <binary_search@plt>
cmp    $0xffffffff,%eax
je     11c4 <main+0x94>
lea    0xe60(%rip),%rdi
mov    $0x42,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11dc <main+0xac>
lea    0xe6f(%rip),%rdi
mov    $0x42,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0xffffffff,%ebx
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x4,%edx
mov    $0x16,%ecx
call   1050 <binary_search_recursive@plt>
cmp    $0xffffffff,%eax
je     120c <main+0xdc>
lea    0xe60(%rip),%rdi
mov    $0x16,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1224 <main+0xf4>
lea    0xe79(%rip),%rdi
mov    $0x16,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0xffffffff,%ebx
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x4,%edx
mov    $0x43,%ecx
call   1050 <binary_search_recursive@plt>
cmp    $0xffffffff,%eax
je     1254 <main+0x124>
lea    0xe18(%rip),%rdi
mov    $0x43,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    126c <main+0x13c>
lea    0xe31(%rip),%rdi
mov    $0x43,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.arr = [5 x i32] [i32 11, i32 22, i32 33, i32 44, i32 55]
@.str = [38 x i8] c"binary_search():found %d at index %d\0A\00"
@.str.1 = [34 x i8] c"binary_search():key %d not found\0A\00"
@.str.2 = [48 x i8] c"binary_search_recursive():found %d at index %d\0A\00"
@.str.3 = [44 x i8] c"binary_search_recursive():key %d not found\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [5 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = bitcast [5 x i32]* %2 to i8*
store i32 0, i32* %3
store i32 0, i32* %7
store i32 0, i32* %4
store i32 4, i32* %5
store i32 33, i32* %6
%9 = getelementptr inbounds [5 x i32], [5 x i32]* %2, i64 0, i64 0
%10 = load i32, i32* %6
%11 = call i32 @binary_search(i32* %9, i32 0, i32 4, i32 %10)
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = icmp ne i32 %12, -1
br i1 %13, label %14, label %18
14: ; preds = %0
%15 = load i32, i32* %6
%16 = load i32, i32* %3
%17 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %15, i32 %16)
br label %21
18: ; preds = %0
%19 = load i32, i32* %6
%20 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %19)
store i32 -1, i32* %7
br label %21
21: ; preds = %18, %14
store i32 66, i32* %6
%22 = getelementptr inbounds [5 x i32], [5 x i32]* %2, i64 0, i64 0
%23 = load i32, i32* %6
%24 = call i32 @binary_search(i32* %22, i32 0, i32 4, i32 %23)
store i32 %24, i32* %3
%25 = load i32, i32* %3
%26 = icmp ne i32 %25, -1
br i1 %26, label %27, label %31
27: ; preds = %21
%28 = load i32, i32* %6
%29 = load i32, i32* %3
%30 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %28, i32 %29)
br label %34
31: ; preds = %21
%32 = load i32, i32* %6
%33 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %32)
store i32 -1, i32* %7
br label %34
34: ; preds = %31, %27
store i32 22, i32* %6
%35 = getelementptr inbounds [5 x i32], [5 x i32]* %2, i64 0, i64 0
%36 = load i32, i32* %6
%37 = call i32 @binary_search_recursive(i32* %35, i32 0, i32 4, i32 %36)
store i32 %37, i32* %3
%38 = load i32, i32* %3
%39 = icmp ne i32 %38, -1
br i1 %39, label %40, label %44
40: ; preds = %34
%41 = load i32, i32* %6
%42 = load i32, i32* %3
%43 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), i32 %41, i32 %42)
br label %47
44: ; preds = %34
%45 = load i32, i32* %6
%46 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i32 %45)
store i32 -1, i32* %7
br label %47
47: ; preds = %44, %40
store i32 67, i32* %6
%48 = getelementptr inbounds [5 x i32], [5 x i32]* %2, i64 0, i64 0
%49 = load i32, i32* %6
%50 = call i32 @binary_search_recursive(i32* %48, i32 0, i32 4, i32 %49)
store i32 %50, i32* %3
%51 = load i32, i32* %3
%52 = icmp ne i32 %51, -1
br i1 %52, label %53, label %57
53: ; preds = %47
%54 = load i32, i32* %6
%55 = load i32, i32* %3
%56 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), i32 %54, i32 %55)
br label %60
57: ; preds = %47
%58 = load i32, i32* %6
%59 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i32 %58)
store i32 -1, i32* %7
br label %60
60: ; preds = %57, %53
%61 = load i32, i32* %7
ret i32 %61
}

LLVM IR (-O2):
@__const.main.arr = [5 x i32] [i32 11, i32 22, i32 33, i32 44, i32 55]
@.str = [38 x i8] c"binary_search():found %d at index %d\0A\00"
@.str.1 = [34 x i8] c"binary_search():key %d not found\0A\00"
@.str.2 = [48 x i8] c"binary_search_recursive():found %d at index %d\0A\00"
@.str.3 = [44 x i8] c"binary_search_recursive():key %d not found\0A\00"
define i32 @main() {
%1 = alloca [5 x i32]
%2 = bitcast [5 x i32]* %1 to i8*
%3 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 0
%4 = call i32 @binary_search(i32* %3, i32 0, i32 4, i32 33)
%5 = icmp eq i32 %4, -1
br i1 %5, label %8, label %6
6: ; preds = %0
%7 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 33, i32 %4)
br label %10
8: ; preds = %0
%9 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 33)
br label %10
10: ; preds = %8, %6
%11 = phi i32 [ 0, %6 ], [ -1, %8 ]
%12 = call i32 @binary_search(i32* %3, i32 0, i32 4, i32 66)
%13 = icmp eq i32 %12, -1
br i1 %13, label %16, label %14
14: ; preds = %10
%15 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 66, i32 %12)
br label %18
16: ; preds = %10
%17 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 66)
br label %18
18: ; preds = %16, %14
%19 = phi i32 [ %11, %14 ], [ -1, %16 ]
%20 = call i32 @binary_search_recursive(i32* %3, i32 0, i32 4, i32 22)
%21 = icmp eq i32 %20, -1
br i1 %21, label %24, label %22
22: ; preds = %18
%23 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), i32 22, i32 %20)
br label %26
24: ; preds = %18
%25 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i32 22)
br label %26
26: ; preds = %24, %22
%27 = phi i32 [ %19, %22 ], [ -1, %24 ]
%28 = call i32 @binary_search_recursive(i32* %3, i32 0, i32 4, i32 67)
%29 = icmp eq i32 %28, -1
br i1 %29, label %32, label %30
30: ; preds = %26
%31 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), i32 67, i32 %28)
br label %34
32: ; preds = %26
%33 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i32 67)
br label %34
34: ; preds = %32, %30
%35 = phi i32 [ %27, %30 ], [ -1, %32 ]
ret i32 %35
}