#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*/ array;

/* Variables and functions */
int EXIT_SUCCESS;
int binary_search(int *, size_t, int);
int /*<<< orphan*/ printf(char *, int, int);
int main(void) {
  int array[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
  size_t size = sizeof(array) / sizeof(array[0]);
  printf("Found %d at index: %d\n\n", 2, binary_search(array, size, 2));
  printf("Found %d at index: %d\n\n", 5, binary_search(array, 4, 5));
  printf("Found %d at index: %d\n", 999, binary_search(array, size, 999));
  return (EXIT_SUCCESS);
}


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    $0x28,%edx
call   1040 <memcpy@plt>
movq   $0xa,-0x38(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    $0x2,%edx
call   1050 <binary_search@plt>
mov    %eax,%edx
lea    0xeb1(%rip),%rdi
mov    $0x2,%esi
call   1030 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    $0x4,%esi
mov    $0x5,%edx
call   1050 <binary_search@plt>
mov    %eax,%edx
lea    0xe8b(%rip),%rdi
mov    $0x5,%esi
call   1030 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    $0x3e7,%edx
call   1050 <binary_search@plt>
mov    %eax,%edx
lea    0xe7e(%rip),%rdi
mov    $0x3e7,%esi
call   1030 <printf@plt>
mov    0x2e0d(%rip),%rax
mov    (%rax),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    0xef2(%rip),%rax
mov    %rax,0x20(%rsp)
movaps 0xed6(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xeba(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%r14
mov    $0xa,%esi
mov    %r14,%rdi
mov    $0x2,%edx
call   1040 <binary_search@plt>
lea    0xec2(%rip),%rbx
mov    %rbx,%rdi
mov    $0x2,%esi
mov    %eax,%edx
call   1030 <printf@plt>
mov    $0x4,%esi
mov    %r14,%rdi
mov    $0x5,%edx
call   1040 <binary_search@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
mov    %eax,%edx
call   1030 <printf@plt>
mov    $0xa,%esi
mov    %r14,%rdi
mov    $0x3e7,%edx
call   1040 <binary_search@plt>
lea    0xe91(%rip),%rdi
mov    $0x3e7,%esi
mov    %eax,%edx
call   1030 <printf@plt>
mov    0x2e1e(%rip),%rax
mov    (%rax),%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.array = [10 x i32] [i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9]
@.str = [24 x i8] c"Found %d at index: %d\0A\0A\00"
@.str.1 = [23 x i8] c"Found %d at index: %d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i32]
%3 = alloca i64
store i32 0, i32* %1
%4 = bitcast [10 x i32]* %2 to i8*
store i64 10, i64* %3
%5 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%6 = load i64, i64* %3
%7 = call i32 @binary_search(i32* %5, i64 %6, i32 2)
%8 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 2, i32 %7)
%9 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%10 = call i32 @binary_search(i32* %9, i64 4, i32 5)
%11 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 5, i32 %10)
%12 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%13 = load i64, i64* %3
%14 = call i32 @binary_search(i32* %12, i64 %13, i32 999)
%15 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 999, i32 %14)
%16 = load i32, i32* @EXIT_SUCCESS
ret i32 %16
}

LLVM IR (-O2):
@__const.main.array = [10 x i32] [i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9]
@.str = [24 x i8] c"Found %d at index: %d\0A\0A\00"
@.str.1 = [23 x i8] c"Found %d at index: %d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca [10 x i32]
%2 = bitcast [10 x i32]* %1 to i8*
%3 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 0
%4 = call i32 @binary_search(i32* %3, i64 10, i32 2)
%5 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 2, i32 %4)
%6 = call i32 @binary_search(i32* %3, i64 4, i32 5)
%7 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 5, i32 %6)
%8 = call i32 @binary_search(i32* %3, i64 10, i32 999)
%9 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 999, i32 %8)
%10 = load i32, i32* @EXIT_SUCCESS
ret i32 %10
}