#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 binsearch(int, int *, int);
int /*<<< orphan*/ printf(char *, int, int);
int main(int argc, char *argv[]) {
  int array[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
  int index;
  index = binsearch(9, array, (sizeof array) / (sizeof array[0]));
  printf("find %d in array %d\n", 9, index);
  index = binsearch(-2, array, (sizeof array) / (sizeof array[0]));
  printf("find %d in array %d\n", -2, index);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xeaf(%rip),%rsi
mov    $0x28,%edx
call   1050 <memcpy@plt>
lea    -0x40(%rbp),%rsi
mov    $0x9,%edi
mov    $0xa,%edx
call   1030 <binsearch@plt>
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%edx
lea    0xead(%rip),%rdi
mov    $0x9,%esi
call   1040 <printf@plt>
lea    -0x40(%rbp),%rsi
mov    $0xfffffffe,%edi
mov    $0xa,%edx
call   1030 <binsearch@plt>
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%edx
lea    0xe83(%rip),%rdi
mov    $0xfffffffe,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x50,%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    $0x9,%edi
mov    %r14,%rsi
mov    $0xa,%edx
call   1030 <binsearch@plt>
lea    0xec2(%rip),%rbx
mov    %rbx,%rdi
mov    $0x9,%esi
mov    %eax,%edx
call   1040 <printf@plt>
mov    $0xfffffffe,%edi
mov    %r14,%rsi
mov    $0xa,%edx
call   1030 <binsearch@plt>
mov    %rbx,%rdi
mov    $0xfffffffe,%esi
mov    %eax,%edx
call   1040 <printf@plt>
xor    %eax,%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 = [21 x i8] c"find %d in array %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [10 x i32]
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = bitcast [10 x i32]* %6 to i8*
%9 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 0
%10 = call i32 @binsearch(i32 9, i32* %9, i32 10)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 9, i32 %11)
%13 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 0
%14 = call i32 @binsearch(i32 -2, i32* %13, i32 10)
store i32 %14, i32* %7
%15 = load i32, i32* %7
%16 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 -2, i32 %15)
ret i32 0
}

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 = [21 x i8] c"find %d in array %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [10 x i32]
%4 = bitcast [10 x i32]* %3 to i8*
%5 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 0
%6 = call i32 @binsearch(i32 9, i32* %5, i32 10)
%7 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 9, i32 %6)
%8 = call i32 @binsearch(i32 -2, i32* %5, i32 10)
%9 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 -2, i32 %8)
ret i32 0
}