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

/* Variables and functions */
int binary_search(int *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int number[10] = {0, 2, 6, 8, 10, 15, 18, 40, 99};
  int what_i_want = 18;
  int ret = 0;
  ret = binary_search(number, sizeof(number) / sizeof(number[0]), what_i_want);
  if (ret < 0) {
    printf("Not found!\n");
    return 0;
  }
  printf("location:%d number[%d]:%d\n", ret, ret, number[ret]);
  what_i_want = 1;
  ret = binary_search(number, sizeof(number) / sizeof(number[0]), what_i_want);
  if (ret < 0) {
    printf("Not found!\n");
    return 0;
  }
  printf("location:%d number[%d]:%d\n", ret, ret, number[ret]);
  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>
movl   $0x12,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%edx
mov    $0xa,%esi
call   1050 <binary_search@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jge    119a <main+0x6a>
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1218 <main+0xe8>
mov    -0x38(%rbp),%esi
mov    -0x38(%rbp),%edx
movslq -0x38(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%ecx
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x34(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%edx
mov    $0xa,%esi
call   1050 <binary_search@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jge    11f5 <main+0xc5>
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1218 <main+0xe8>
mov    -0x38(%rbp),%esi
mov    -0x38(%rbp),%edx
movslq -0x38(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%ecx
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x28,%rsp
mov    0xee5(%rip),%rax
mov    %rax,0x20(%rsp)
movaps 0xec9(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xead(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rdi
mov    $0xa,%esi
mov    $0x12,%edx
call   1050 <binary_search@plt>
test   %eax,%eax
js     11b3 <main+0x83>
mov    %eax,%ecx
mov    (%rsp,%rcx,4),%ecx
lea    0xeaf(%rip),%rdi
mov    %eax,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rsp,%rdi
mov    $0xa,%esi
mov    $0x1,%edx
call   1050 <binary_search@plt>
test   %eax,%eax
js     11b3 <main+0x83>
mov    %eax,%ecx
mov    (%rsp,%rcx,4),%ecx
lea    0xe82(%rip),%rdi
mov    %eax,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11bf <main+0x8f>
lea    0xe89(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x28,%rsp
ret

LLVM IR (-O0):
@__const.main.number = [10 x i32] [i32 0, i32 2, i32 6, i32 8, i32 10, i32 15, i32 18, i32 40, i32 99, i32 0]
@.str = [12 x i8] c"Not found!\0A\00"
@.str.1 = [27 x i8] c"location:%d number[%d]:%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i32]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = bitcast [10 x i32]* %2 to i8*
store i32 18, i32* %3
store i32 0, i32* %4
%6 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%7 = load i32, i32* %3
%8 = call i32 @binary_search(i32* %6, i32 10, i32 %7)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %36
13: ; preds = %0
%14 = load i32, i32* %4
%15 = load i32, i32* %4
%16 = load i32, i32* %4
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %17
%19 = load i32, i32* %18
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %14, i32 %15, i32 %19)
store i32 1, i32* %3
%21 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%22 = load i32, i32* %3
%23 = call i32 @binary_search(i32* %21, i32 10, i32 %22)
store i32 %23, i32* %4
%24 = load i32, i32* %4
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %13
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %36
28: ; preds = %13
%29 = load i32, i32* %4
%30 = load i32, i32* %4
%31 = load i32, i32* %4
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %32
%34 = load i32, i32* %33
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %29, i32 %30, i32 %34)
store i32 0, i32* %1
br label %36
36: ; preds = %28, %26, %11
%37 = load i32, i32* %1
ret i32 %37
}

LLVM IR (-O2):
@__const.main.number = [10 x i32] [i32 0, i32 2, i32 6, i32 8, i32 10, i32 15, i32 18, i32 40, i32 99, i32 0]
@.str.1 = [27 x i8] c"location:%d number[%d]:%d\0A\00"
@str.2 = [11 x i8] c"Not found!\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 10, i32 18)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.2, i64 0, i64 0))
br label %22
8: ; preds = %0
%9 = zext i32 %4 to i64
%10 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 %9
%11 = load i32, i32* %10
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %4, i32 %4, i32 %11)
%13 = call i32 @binary_search(i32* %3, i32 10, i32 1)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %8
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.2, i64 0, i64 0))
br label %22
17: ; preds = %8
%18 = zext i32 %13 to i64
%19 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 %18
%20 = load i32, i32* %19
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %13, i32 %13, i32 %20)
br label %22
22: ; preds = %17, %15, %6
ret i32 0
}