#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 *, int, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ printfHeader();
int /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  int a[15];
  int i;
  int key;
  int result;
  for (i = 0; i < 15; i++) {
    a[i] = 2 * i;
  }
  printf("Enter a number between 0 and 28: ");
  scanf("%d", &key);
  printfHeader();
  result = binarySearch(a, key, 0, 15 - 1);
  if (result != -1) {
    printf("\n%d found in array element %d\n", key, result);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x44(%rbp)
cmpl   $0xf,-0x44(%rbp)
jge    117c <main+0x3c>
mov    -0x44(%rbp),%ecx
shl    $0x1,%ecx
movslq -0x44(%rbp),%rax
mov    %ecx,-0x40(%rbp,%rax,4)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1156 <main+0x16>
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe91(%rip),%rdi
lea    -0x48(%rbp),%rsi
call   1060 <scanf@plt>
mov    $0x0,%al
call   1030 <printfHeader@plt>
lea    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%esi
xor    %edx,%edx
mov    $0xe,%ecx
call   1050 <binarySearch@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0xffffffff,-0x4c(%rbp)
je     11d5 <main+0x95>
mov    -0x48(%rbp),%esi
mov    -0x4c(%rbp),%edx
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x58,%rsp
movaps 0xeb5(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xeb9(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xebd(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movabs $0x1a00000018,%rax
mov    %rax,0x40(%rsp)
movl   $0x1c,0x48(%rsp)
lea    0xeaa(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xebe(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
xor    %eax,%eax
call   1030 <printfHeader@plt>
mov    0xc(%rsp),%esi
lea    0x10(%rsp),%rdi
xor    %edx,%edx
mov    $0xe,%ecx
call   1050 <binarySearch@plt>
cmp    $0xffffffff,%eax
je     11d3 <main+0x93>
mov    0xc(%rsp),%esi
lea    0xe8b(%rip),%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x58,%rsp
ret

LLVM IR (-O0):
@.str = [34 x i8] c"Enter a number between 0 and 28: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [31 x i8] c"\0A%d found in array element %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [15 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
br label %6
6: ; preds = %15, %0
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 15
br i1 %8, label %9, label %18
9: ; preds = %6
%10 = load i32, i32* %3
%11 = mul nsw i32 2, %10
%12 = load i32, i32* %3
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [15 x i32], [15 x i32]* %2, i64 0, i64 %13
store i32 %11, i32* %14
br label %15
15: ; preds = %9
%16 = load i32, i32* %3
%17 = add nsw i32 %16, 1
store i32 %17, i32* %3
br label %6
18: ; preds = %6
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%21 = call i32 (...) @printfHeader()
%22 = getelementptr inbounds [15 x i32], [15 x i32]* %2, i64 0, i64 0
%23 = load i32, i32* %4
%24 = call i32 @binarySearch(i32* %22, i32 %23, i32 0, i32 14)
store i32 %24, i32* %5
%25 = load i32, i32* %5
%26 = icmp ne i32 %25, -1
br i1 %26, label %27, label %31
27: ; preds = %18
%28 = load i32, i32* %4
%29 = load i32, i32* %5
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %28, i32 %29)
br label %31
31: ; preds = %27, %18
%32 = load i32, i32* %1
ret i32 %32
}

LLVM IR (-O2):
@.str = [34 x i8] c"Enter a number between 0 and 28: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [31 x i8] c"\0A%d found in array element %d\0A\00"
define i32 @main() {
%1 = alloca [15 x i32]
%2 = alloca i32
%3 = bitcast [15 x i32]* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = getelementptr inbounds [15 x i32], [15 x i32]* %1, i64 0, i64 0
%6 = bitcast [15 x i32]* %1 to <4 x i32>*
store <4 x i32> <i32 0, i32 2, i32 4, i32 6>, <4 x i32>* %6
%7 = getelementptr inbounds [15 x i32], [15 x i32]* %1, i64 0, i64 4
%8 = bitcast i32* %7 to <4 x i32>*
store <4 x i32> <i32 8, i32 10, i32 12, i32 14>, <4 x i32>* %8
%9 = getelementptr inbounds [15 x i32], [15 x i32]* %1, i64 0, i64 8
%10 = bitcast i32* %9 to <4 x i32>*
store <4 x i32> <i32 16, i32 18, i32 20, i32 22>, <4 x i32>* %10
%11 = getelementptr inbounds [15 x i32], [15 x i32]* %1, i64 0, i64 12
store i32 24, i32* %11
%12 = getelementptr inbounds [15 x i32], [15 x i32]* %1, i64 0, i64 13
store i32 26, i32* %12
%13 = getelementptr inbounds [15 x i32], [15 x i32]* %1, i64 0, i64 14
store i32 28, i32* %13
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%16 = call i32 (...) @printfHeader()
%17 = load i32, i32* %2
%18 = call i32 @binarySearch(i32* %5, i32 %17, i32 0, i32 14)
%19 = icmp eq i32 %18, -1
br i1 %19, label %23, label %20
20: ; preds = %0
%21 = load i32, i32* %2
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %21, i32 %18)
br label %23
23: ; preds = %20, %0
ret i32 0
}