#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, 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, size, 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),%esi
mov    $0xb,%edx
call   1050 <binary_search@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0xffffffff,-0x38(%rbp)
jne    118c <main+0x5c>
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    119d <main+0x6d>
mov    -0x38(%rbp),%esi
lea    0xea2(%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
mov    $0xb,%esi
mov    $0xb,%edx
call   1050 <binary_search@plt>
cmp    $0xffffffff,%eax
je     1180 <main+0x50>
lea    0xeb7(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    118c <main+0x5c>
lea    0xeb1(%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 = call i32 @binary_search(i32* %6, i32 %7, i32 11)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, -1
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))
br label %16
13: ; preds = %0
%14 = load i32, i32* %4
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %14)
br label %16
16: ; preds = %13, %11
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 11, 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
}