#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 binarySearch(int *, int, int);
int /*<<< orphan*/ printf(char *, int, ...);
int main() {
  int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
  int n = 9;
  int i;
  for (i = 0; i <= 10; ++i) {
    int index = binarySearch(arr, n, i);
    if (index != -1) {
      printf("%d found at index %d\n", i, index);
    } else {
      printf("%d not found\n", i);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xeb6(%rip),%rsi
mov    $0x24,%edx
call   1040 <memcpy@plt>
movl   $0x9,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
cmpl   $0xa,-0x38(%rbp)
jg     11c5 <main+0x95>
lea    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%esi
mov    -0x38(%rbp),%edx
call   1050 <binarySearch@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0xffffffff,-0x3c(%rbp)
je     11a1 <main+0x71>
mov    -0x38(%rbp),%esi
mov    -0x3c(%rbp),%edx
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b2 <main+0x82>
mov    -0x38(%rbp),%esi
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b7 <main+0x87>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1162 <main+0x32>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    0xef0(%rip),%eax
mov    %eax,0x20(%rsp)
movaps 0xed5(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xeb9(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rbx
lea    0xee5(%rip),%r14
lea    0xec8(%rip),%r15
xor    %ebp,%ebp
jmp    1174 <main+0x54>
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%ebp
cmp    $0xb,%ebp
je     1198 <main+0x78>
mov    %rbx,%rdi
mov    $0x9,%esi
mov    %ebp,%edx
call   1040 <binarySearch@plt>
cmp    $0xffffffff,%eax
je     1160 <main+0x40>
mov    %r15,%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    116c <main+0x4c>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.arr = [9 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9]
@.str = [22 x i8] c"%d found at index %d\0A\00"
@.str.1 = [14 x i8] c"%d not found\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [9 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = bitcast [9 x i32]* %2 to i8*
store i32 9, i32* %3
store i32 0, i32* %4
br label %7
7: ; preds = %25, %0
%8 = load i32, i32* %4
%9 = icmp sle i32 %8, 10
br i1 %9, label %10, label %28
10: ; preds = %7
%11 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 0
%12 = load i32, i32* %3
%13 = load i32, i32* %4
%14 = call i32 @binarySearch(i32* %11, i32 %12, i32 %13)
store i32 %14, i32* %5
%15 = load i32, i32* %5
%16 = icmp ne i32 %15, -1
br i1 %16, label %17, label %21
17: ; preds = %10
%18 = load i32, i32* %4
%19 = load i32, i32* %5
%20 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %18, i32 %19)
br label %24
21: ; preds = %10
%22 = load i32, i32* %4
%23 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %22)
br label %24
24: ; preds = %21, %17
br label %25
25: ; preds = %24
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 1
store i32 %27, i32* %4
br label %7
28: ; preds = %7
ret i32 0
}

LLVM IR (-O2):
@__const.main.arr = [9 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9]
@.str = [22 x i8] c"%d found at index %d\0A\00"
@.str.1 = [14 x i8] c"%d not found\0A\00"
define i32 @main() {
%1 = alloca [9 x i32]
%2 = bitcast [9 x i32]* %1 to i8*
%3 = getelementptr inbounds [9 x i32], [9 x i32]* %1, i64 0, i64 0
br label %4
4: ; preds = %0, %12
%5 = phi i32 [ 0, %0 ], [ %13, %12 ]
%6 = call i32 @binarySearch(i32* %3, i32 9, i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %10, label %8
8: ; preds = %4
%9 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %6)
br label %12
10: ; preds = %4
%11 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %5)
br label %12
12: ; preds = %10, %8
%13 = add nuw nsw i32 %5, 1
%14 = icmp eq i32 %13, 11
br i1 %14, label %15, label %4
15: ; preds = %12
ret i32 0
}