#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, int, int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int array[10] = {0, 2, 4, 6, 8, 10, 12, 14, 16, 18};
  int index;
  index = binary_search(array, 0, 9, 16);
  printf("16 is in position: %d\n", index);
  index = binary_search(array, 0, 9, 100);
  if (index == -1)
    printf("100 is not in the list\n");
  index = binary_search(array, 9, 0, 10);
  if (index == -2)
    printf("limits out of order\n");
  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    $0x28,%edx
call   1040 <memcpy@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x9,%edx
mov    $0x10,%ecx
call   1050 <binary_search@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%esi
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x9,%edx
mov    $0x64,%ecx
call   1050 <binary_search@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0xffffffff,-0x34(%rbp)
jne    11ad <main+0x7d>
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    $0x9,%esi
xor    %edx,%edx
mov    $0xa,%ecx
call   1050 <binary_search@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0xfffffffe,-0x34(%rbp)
jne    11dd <main+0xad>
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
mov    0xee4(%rip),%rax
mov    %rax,0x20(%rsp)
movaps 0xec8(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xeac(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x9,%edx
mov    $0x10,%ecx
call   1050 <binary_search@plt>
lea    0xeb2(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x9,%edx
mov    $0x64,%ecx
call   1050 <binary_search@plt>
cmp    $0xffffffff,%eax
jne    11a4 <main+0x74>
lea    0xeb4(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
mov    $0x9,%esi
xor    %edx,%edx
mov    $0xa,%ecx
call   1050 <binary_search@plt>
cmp    $0xfffffffe,%eax
jne    11c9 <main+0x99>
lea    0xe7b(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.array = [10 x i32] [i32 0, i32 2, i32 4, i32 6, i32 8, i32 10, i32 12, i32 14, i32 16, i32 18]
@.str = [23 x i8] c"16 is in position: %d\0A\00"
@.str.1 = [24 x i8] c"100 is not in the list\0A\00"
@.str.2 = [21 x i8] c"limits out of order\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i32]
%3 = alloca i32
store i32 0, i32* %1
%4 = bitcast [10 x i32]* %2 to i8*
%5 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%6 = call i32 @binary_search(i32* %5, i32 0, i32 9, i32 16)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%10 = call i32 @binary_search(i32* %9, i32 0, i32 9, i32 100)
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %0
%16 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%17 = call i32 @binary_search(i32* %16, i32 9, i32 0, i32 10)
store i32 %17, i32* %3
%18 = load i32, i32* %3
%19 = icmp eq i32 %18, -2
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %22
22: ; preds = %20, %15
ret i32 0
}

LLVM IR (-O2):
@__const.main.array = [10 x i32] [i32 0, i32 2, i32 4, i32 6, i32 8, i32 10, i32 12, i32 14, i32 16, i32 18]
@.str = [23 x i8] c"16 is in position: %d\0A\00"
@str = [20 x i8] c"limits out of order\00"
@str.3 = [23 x i8] c"100 is not in the list\00"
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, i32 0, i32 9, i32 16)
%5 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = call i32 @binary_search(i32* %3, i32 0, i32 9, i32 100)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.3, i64 0, i64 0))
br label %10
10: ; preds = %8, %0
%11 = call i32 @binary_search(i32* %3, i32 9, i32 0, i32 10)
%12 = icmp eq i32 %11, -2
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %15
15: ; preds = %13, %10
ret i32 0
}