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

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int bsearch(int *, int, int);
int /*<<< orphan*/ printf(char *);
int r_bsearch(int *, int /*<<< orphan*/, int, int);
int main(int argc, char **argv) {
  int arr[] = {1, 2, 100, 200, 250, 500};
  printf("First search\n");
  assert(bsearch(arr, sizeof(arr) / sizeof(int), 100) == 3);
  printf("Second search\n");
  assert(bsearch(arr, sizeof(arr) / sizeof(int), 1) == 0);
  printf("Third search\n");
  assert(bsearch(arr, sizeof(arr) / sizeof(int), 1000) == -1);
  printf("First search\n");
  assert(r_bsearch(arr, 0, sizeof(arr) / sizeof(int) - 1, 100) == 2);
  printf("Second search\n");
  assert(r_bsearch(arr, 0, sizeof(arr) / sizeof(int) - 1, 1) == 0);
  printf("Third search\n");
  assert(r_bsearch(arr, 0, sizeof(arr) / sizeof(int) - 1, 1000) == -1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xea3(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xea0(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe9d(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xe9a(%rip),%rdi
call   1030 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    $0x6,%esi
mov    $0x64,%edx
call   1060 <bsearch@plt>
cmp    $0x3,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    0xe79(%rip),%rdi
call   1030 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    $0x6,%esi
mov    $0x1,%edx
call   1060 <bsearch@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    0xe59(%rip),%rdi
call   1030 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    $0x6,%esi
mov    $0x3e8,%edx
call   1060 <bsearch@plt>
cmp    $0xffffffff,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    0xe0d(%rip),%rdi
call   1030 <printf@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x5,%edx
mov    $0x64,%ecx
call   1050 <r_bsearch@plt>
cmp    $0x2,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    0xdea(%rip),%rdi
call   1030 <printf@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x5,%edx
mov    $0x1,%ecx
call   1050 <r_bsearch@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    0xdc8(%rip),%rdi
call   1030 <printf@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x5,%edx
mov    $0x3e8,%ecx
call   1050 <r_bsearch@plt>
cmp    $0xffffffff,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0xebe(%rip),%rax
mov    %rax,0x10(%rsp)
movaps 0xea2(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xeaf(%rip),%r14
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x6,%esi
mov    $0x64,%edx
call   1060 <bsearch@plt>
xor    %edi,%edi
cmp    $0x3,%eax
sete   %dil
call   1040 <assert@plt>
lea    0xe8a(%rip),%r15
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    $0x6,%esi
mov    $0x1,%edx
call   1060 <bsearch@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
lea    0xe6a(%rip),%r12
mov    %r12,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    $0x6,%esi
mov    $0x3e8,%edx
call   1060 <bsearch@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
sete   %dil
call   1040 <assert@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x5,%edx
mov    $0x64,%ecx
call   1050 <r_bsearch@plt>
xor    %edi,%edi
cmp    $0x2,%eax
sete   %dil
call   1040 <assert@plt>
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x5,%edx
mov    $0x1,%ecx
call   1050 <r_bsearch@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
mov    %r12,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x5,%edx
mov    $0x3e8,%ecx
call   1050 <r_bsearch@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
sete   %dil
call   1040 <assert@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.arr = [6 x i32] [i32 1, i32 2, i32 100, i32 200, i32 250, i32 500]
@.str = [14 x i8] c"First search\0A\00"
@.str.1 = [15 x i8] c"Second search\0A\00"
@.str.2 = [14 x i8] c"Third search\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [6 x i32]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = bitcast [6 x i32]* %6 to i8*
%8 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds [6 x i32], [6 x i32]* %6, i64 0, i64 0
%10 = call i32 @bsearch(i32* %9, i32 6, i32 100)
%11 = icmp eq i32 %10, 3
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%15 = getelementptr inbounds [6 x i32], [6 x i32]* %6, i64 0, i64 0
%16 = call i32 @bsearch(i32* %15, i32 6, i32 1)
%17 = icmp eq i32 %16, 0
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%21 = getelementptr inbounds [6 x i32], [6 x i32]* %6, i64 0, i64 0
%22 = call i32 @bsearch(i32* %21, i32 6, i32 1000)
%23 = icmp eq i32 %22, -1
%24 = zext i1 %23 to i32
%25 = call i32 @assert(i32 %24)
%26 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%27 = getelementptr inbounds [6 x i32], [6 x i32]* %6, i64 0, i64 0
%28 = call i32 @r_bsearch(i32* %27, i32 0, i32 5, i32 100)
%29 = icmp eq i32 %28, 2
%30 = zext i1 %29 to i32
%31 = call i32 @assert(i32 %30)
%32 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%33 = getelementptr inbounds [6 x i32], [6 x i32]* %6, i64 0, i64 0
%34 = call i32 @r_bsearch(i32* %33, i32 0, i32 5, i32 1)
%35 = icmp eq i32 %34, 0
%36 = zext i1 %35 to i32
%37 = call i32 @assert(i32 %36)
%38 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%39 = getelementptr inbounds [6 x i32], [6 x i32]* %6, i64 0, i64 0
%40 = call i32 @r_bsearch(i32* %39, i32 0, i32 5, i32 1000)
%41 = icmp eq i32 %40, -1
%42 = zext i1 %41 to i32
%43 = call i32 @assert(i32 %42)
ret i32 0
}

LLVM IR (-O2):
@__const.main.arr = [6 x i32] [i32 1, i32 2, i32 100, i32 200, i32 250, i32 500]
@str.5 = [13 x i8] c"First search\00"
@str.6 = [14 x i8] c"Second search\00"
@str.7 = [13 x i8] c"Third search\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [6 x i32]
%4 = bitcast [6 x i32]* %3 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.5, i64 0, i64 0))
%6 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 0
%7 = call i32 @bsearch(i32* %6, i32 6, i32 100)
%8 = icmp eq i32 %7, 3
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.6, i64 0, i64 0))
%12 = call i32 @bsearch(i32* %6, i32 6, i32 1)
%13 = icmp eq i32 %12, 0
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.7, i64 0, i64 0))
%17 = call i32 @bsearch(i32* %6, i32 6, i32 1000)
%18 = icmp eq i32 %17, -1
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.5, i64 0, i64 0))
%22 = call i32 @r_bsearch(i32* %6, i32 0, i32 5, i32 100)
%23 = icmp eq i32 %22, 2
%24 = zext i1 %23 to i32
%25 = call i32 @assert(i32 %24)
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.6, i64 0, i64 0))
%27 = call i32 @r_bsearch(i32* %6, i32 0, i32 5, i32 1)
%28 = icmp eq i32 %27, 0
%29 = zext i1 %28 to i32
%30 = call i32 @assert(i32 %29)
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.7, i64 0, i64 0))
%32 = call i32 @r_bsearch(i32* %6, i32 0, i32 5, i32 1000)
%33 = icmp eq i32 %32, -1
%34 = zext i1 %33 to i32
%35 = call i32 @assert(i32 %34)
ret i32 0
}