#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 binarySearch(int const *, int /*<<< orphan*/, int, int const);
int /*<<< orphan*/ printf(char *, int const, ...);
int main(int argc, char **argv) {
  const int arr[10] = {2, 4, 5, 6, 8, 10, 13, 16, 20, 33};
  const int find = 8;
  int result = binarySearch(arr, 0, 9, find);
  if (result < 0) {
    printf("C - Could not find %d in list\n", find);
  } else {
    printf("C - Element %d found at index %d\n", find, result);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xeaf(%rip),%rsi
mov    $0x28,%edx
call   1040 <memcpy@plt>
movl   $0x8,-0x44(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x9,%edx
mov    $0x8,%ecx
call   1050 <binarySearch@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0x0,-0x48(%rbp)
jge    119c <main+0x6c>
lea    0xe9d(%rip),%rdi
mov    $0x8,%esi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b2 <main+0x82>
mov    -0x48(%rbp),%edx
lea    0xea1(%rip),%rdi
mov    $0x8,%esi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x28,%rsp
mov    0xef5(%rip),%rax
mov    %rax,0x20(%rsp)
movaps 0xed9(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xebd(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x9,%edx
mov    $0x8,%ecx
call   1040 <binarySearch@plt>
test   %eax,%eax
js     1176 <main+0x56>
lea    0xee1(%rip),%rdi
mov    $0x8,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1189 <main+0x69>
lea    0xeab(%rip),%rdi
mov    $0x8,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
ret

LLVM IR (-O0):
@__const.main.arr = [10 x i32] [i32 2, i32 4, i32 5, i32 6, i32 8, i32 10, i32 13, i32 16, i32 20, i32 33]
@.str = [31 x i8] c"C - Could not find %d in list\0A\00"
@.str.1 = [34 x i8] c"C - Element %d found at index %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [10 x i32]
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = bitcast [10 x i32]* %6 to i8*
store i32 8, i32* %7
%10 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 0
%11 = call i32 @binarySearch(i32* %10, i32 0, i32 9, i32 8)
store i32 %11, i32* %8
%12 = load i32, i32* %8
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 8)
br label %19
16: ; preds = %2
%17 = load i32, i32* %8
%18 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 8, i32 %17)
br label %19
19: ; preds = %16, %14
ret i32 0
}

LLVM IR (-O2):
@__const.main.arr = [10 x i32] [i32 2, i32 4, i32 5, i32 6, i32 8, i32 10, i32 13, i32 16, i32 20, i32 33]
@.str = [31 x i8] c"C - Could not find %d in list\0A\00"
@.str.1 = [34 x i8] c"C - Element %d found at index %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [10 x i32]
%4 = bitcast [10 x i32]* %3 to i8*
%5 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 0
%6 = call i32 @binarySearch(i32* %5, i32 0, i32 9, i32 8)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 8)
br label %12
10: ; preds = %2
%11 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 8, i32 %6)
br label %12
12: ; preds = %10, %8
ret i32 0
}