#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 /*<<< orphan*/ printArray(char *, int *);
int /*<<< orphan*/ printf(char *, int);
int main() {
  int array[20] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
  int tam = 10;
  printArray("Original Array: ", array);
  printf(("[search] Looking for 11, returned: %d\n"),
         binary_search(array, 0, tam, 11));
  printf(("[search] Looking for 1, returned: %d\n"),
         binary_search(array, 0, tam, 1));
  printf(("[search] Looking for 10, returned: %d\n"),
         binary_search(array, 0, tam, 10));
  printf(("[search] Looking for 9, returned: %d\n"),
         binary_search(array, 0, tam, 9));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x60(%rbp),%rdi
lea    0xea6(%rip),%rsi
mov    $0x50,%edx
call   1040 <memcpy@plt>
movl   $0xa,-0x64(%rbp)
lea    -0x60(%rbp),%rsi
lea    0xeda(%rip),%rdi
call   1060 <printArray@plt>
lea    -0x60(%rbp),%rdi
mov    -0x64(%rbp),%edx
xor    %esi,%esi
mov    $0xb,%ecx
call   1050 <binary_search@plt>
mov    %eax,%esi
lea    0xeca(%rip),%rdi
call   1030 <printf@plt>
lea    -0x60(%rbp),%rdi
mov    -0x64(%rbp),%edx
xor    %esi,%esi
mov    $0x1,%ecx
call   1050 <binary_search@plt>
mov    %eax,%esi
lea    0xed0(%rip),%rdi
call   1030 <printf@plt>
lea    -0x60(%rbp),%rdi
mov    -0x64(%rbp),%edx
xor    %esi,%esi
mov    $0xa,%ecx
call   1050 <binary_search@plt>
mov    %eax,%esi
lea    0xed5(%rip),%rdi
call   1030 <printf@plt>
lea    -0x60(%rbp),%rdi
mov    -0x64(%rbp),%edx
xor    %esi,%esi
mov    $0x9,%ecx
call   1050 <binary_search@plt>
mov    %eax,%esi
lea    0xedb(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x50,%rsp
movaps 0xf04(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xee8(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xecc(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xeb0(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe94(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xed9(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1050 <printArray@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xa,%edx
mov    $0xb,%ecx
call   1040 <binary_search@plt>
lea    0xec4(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xa,%edx
mov    $0x1,%ecx
call   1040 <binary_search@plt>
lea    0xec9(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xa,%edx
mov    $0xa,%ecx
call   1040 <binary_search@plt>
lea    0xecd(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xa,%edx
mov    $0x9,%ecx
call   1040 <binary_search@plt>
lea    0xed2(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.array = <{ [10 x i32], [10 x i32] }> <{ [10 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10], [10 x i32] zeroinitializer }>
@.str = [17 x i8] c"Original Array: \00"
@.str.1 = [39 x i8] c"[search] Looking for 11, returned: %d\0A\00"
@.str.2 = [38 x i8] c"[search] Looking for 1, returned: %d\0A\00"
@.str.3 = [39 x i8] c"[search] Looking for 10, returned: %d\0A\00"
@.str.4 = [38 x i8] c"[search] Looking for 9, returned: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [20 x i32]
%3 = alloca i32
store i32 0, i32* %1
%4 = bitcast [20 x i32]* %2 to i8*
store i32 10, i32* %3
%5 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 0
%6 = call i32 @printArray(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32* %5)
%7 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 0
%8 = load i32, i32* %3
%9 = call i32 @binary_search(i32* %7, i32 0, i32 %8, i32 11)
%10 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 0
%12 = load i32, i32* %3
%13 = call i32 @binary_search(i32* %11, i32 0, i32 %12, i32 1)
%14 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%15 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 0
%16 = load i32, i32* %3
%17 = call i32 @binary_search(i32* %15, i32 0, i32 %16, i32 10)
%18 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i32 %17)
%19 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 0
%20 = load i32, i32* %3
%21 = call i32 @binary_search(i32* %19, i32 0, i32 %20, i32 9)
%22 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i32 %21)
ret i32 0
}

LLVM IR (-O2):
@__const.main.array = <{ [10 x i32], [10 x i32] }> <{ [10 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10], [10 x i32] zeroinitializer }>
@.str = [17 x i8] c"Original Array: \00"
@.str.1 = [39 x i8] c"[search] Looking for 11, returned: %d\0A\00"
@.str.2 = [38 x i8] c"[search] Looking for 1, returned: %d\0A\00"
@.str.3 = [39 x i8] c"[search] Looking for 10, returned: %d\0A\00"
@.str.4 = [38 x i8] c"[search] Looking for 9, returned: %d\0A\00"
define i32 @main() {
%1 = alloca [20 x i32]
%2 = bitcast [20 x i32]* %1 to i8*
%3 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 0
%4 = call i32 @printArray(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32* %3)
%5 = call i32 @binary_search(i32* %3, i32 0, i32 10, i32 11)
%6 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%7 = call i32 @binary_search(i32* %3, i32 0, i32 10, i32 1)
%8 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%9 = call i32 @binary_search(i32* %3, i32 0, i32 10, i32 10)
%10 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i32 %9)
%11 = call i32 @binary_search(i32* %3, i32 0, i32 10, i32 9)
%12 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i32 %11)
ret i32 0
}