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

/* Variables and functions */
int binary_search(int *, int /*<<< orphan*/, int, int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int array[] = {1, 3, 5, 6, 7, 9, 11, 20, 33, 58, 89};
  int size = sizeof(array) / sizeof(array[0]);
  int idx_ret = binary_search(array, 0, size - 1, 11);
  if (idx_ret == -1) {
    printf("not found!\n");
  } else {
    printf("index = %d\n", idx_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    $0x2c,%edx
call   1040 <memcpy@plt>
movl   $0xb,-0x34(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
mov    $0xb,%ecx
call   1050 <binary_search@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0xffffffff,-0x38(%rbp)
jne    1191 <main+0x61>
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11a2 <main+0x72>
mov    -0x38(%rbp),%esi
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x38,%rsp
movups 0xee1(%rip),%xmm0
movups %xmm0,0x1c(%rsp)
movaps 0xec9(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xead(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0xa,%edx
mov    $0xb,%ecx
call   1050 <binary_search@plt>
cmp    $0xffffffff,%eax
je     1182 <main+0x52>
lea    0xeb5(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    118e <main+0x5e>
lea    0xeaf(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x38,%rsp
ret

LLVM IR (-O0):
@__const.main.array = [11 x i32] [i32 1, i32 3, i32 5, i32 6, i32 7, i32 9, i32 11, i32 20, i32 33, i32 58, i32 89]
@.str = [12 x i8] c"not found!\0A\00"
@.str.1 = [12 x i8] c"index = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [11 x i32]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = bitcast [11 x i32]* %2 to i8*
store i32 11, i32* %3
%6 = getelementptr inbounds [11 x i32], [11 x i32]* %2, i64 0, i64 0
%7 = load i32, i32* %3
%8 = sub nsw i32 %7, 1
%9 = call i32 @binary_search(i32* %6, i32 0, i32 %8, i32 11)
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %17
14: ; preds = %0
%15 = load i32, i32* %4
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %14, %12
ret i32 0
}

LLVM IR (-O2):
@__const.main.array = [11 x i32] [i32 1, i32 3, i32 5, i32 6, i32 7, i32 9, i32 11, i32 20, i32 33, i32 58, i32 89]
@.str.1 = [12 x i8] c"index = %d\0A\00"
@str = [11 x i8] c"not found!\00"
define i32 @main() {
%1 = alloca [11 x i32]
%2 = bitcast [11 x i32]* %1 to i8*
%3 = getelementptr inbounds [11 x i32], [11 x i32]* %1, i64 0, i64 0
%4 = call i32 @binary_search(i32* %3, i32 0, i32 10, i32 11)
%5 = icmp eq i32 %4, -1
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, i64 0, i64 0))
br label %10
8: ; preds = %0
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %4)
br label %10
10: ; preds = %8, %6
ret i32 0
}