#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 /*<<< orphan*/, int, int);
int /*<<< orphan*/ display(int *, int);
scalar_t__ indexFound(int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int a[15] = {101, 102, 103, 104, 105, 106, 107, 108,
               109, 110, 111, 112, 113, 114, 115};
  int key1 = 113;
  int key2 = 99;
  int resultIndex = -1;
  printf("input: ");
  display(a, 15);
  printf("\n");
  printf("key1: %d\n", key1);
  resultIndex = binarySearch(a, 0, 15 - 1, key1);
  if (indexFound(resultIndex)) {
    printf("result index: %d, found!\n", resultIndex);
  } else {
    printf("result index: %d, not found!\n", resultIndex);
  }
  printf("\n");
  printf("key2: %d\n", key2);
  resultIndex = binarySearch(a, 0, 15 - 1, key2);
  if (indexFound(resultIndex)) {
    printf("result index: %d, found!\n", resultIndex);
  } else {
    printf("result index: %d, not found!\n", resultIndex);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xe96(%rip),%rsi
mov    $0x3c,%edx
call   1060 <memcpy@plt>
movl   $0x71,-0x44(%rbp)
movl   $0x63,-0x48(%rbp)
movl   $0xffffffff,-0x4c(%rbp)
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x40(%rbp),%rdi
mov    $0xf,%esi
call   1040 <display@plt>
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x44(%rbp),%esi
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x40(%rbp),%rdi
mov    -0x44(%rbp),%ecx
xor    %esi,%esi
mov    $0xe,%edx
call   1070 <binarySearch@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%edi
call   1030 <indexFound@plt>
cmp    $0x0,%rax
je     1202 <main+0xb2>
mov    -0x4c(%rbp),%esi
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1213 <main+0xc3>
mov    -0x4c(%rbp),%esi
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x48(%rbp),%esi
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%ecx
xor    %esi,%esi
mov    $0xe,%edx
call   1070 <binarySearch@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%edi
call   1030 <indexFound@plt>
cmp    $0x0,%rax
je     1270 <main+0x120>
mov    -0x4c(%rbp),%esi
lea    0xdea(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1281 <main+0x131>
mov    -0x4c(%rbp),%esi
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x48,%rsp
movups 0xecb(%rip),%xmm0
movups %xmm0,0x2c(%rsp)
movaps 0xeb3(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe97(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe7b(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xeac(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0xf,%esi
call   1050 <display@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe8c(%rip),%rdi
mov    $0x71,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xe,%edx
mov    $0x71,%ecx
call   1070 <binarySearch@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1040 <indexFound@plt>
test   %rax,%rax
lea    0xe7d(%rip),%r15
lea    0xe5c(%rip),%rbx
mov    %rbx,%rdi
cmove  %r15,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe73(%rip),%rdi
mov    $0x63,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xe,%edx
mov    $0x63,%ecx
call   1070 <binarySearch@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1040 <indexFound@plt>
test   %rax,%rax
cmove  %r15,%rbx
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.a = [15 x i32] [i32 101, i32 102, i32 103, i32 104, i32 105, i32 106, i32 107, i32 108, i32 109, i32 110, i32 111, i32 112, i32 113, i32 114, i32 115]
@.str = [8 x i8] c"input: \00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [10 x i8] c"key1: %d\0A\00"
@.str.3 = [26 x i8] c"result index: %d, found!\0A\00"
@.str.4 = [30 x i8] c"result index: %d, not found!\0A\00"
@.str.5 = [10 x i8] c"key2: %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
%6 = bitcast [15 x i32]* %2 to i8*
store i32 113, i32* %3
store i32 99, i32* %4
store i32 -1, i32* %5
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds [15 x i32], [15 x i32]* %2, i64 0, i64 0
%9 = call i32 @display(i32* %8, i32 15)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = load i32, i32* %3
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%13 = getelementptr inbounds [15 x i32], [15 x i32]* %2, i64 0, i64 0
%14 = load i32, i32* %3
%15 = call i32 @binarySearch(i32* %13, i32 0, i32 14, i32 %14)
store i32 %15, i32* %5
%16 = load i32, i32* %5
%17 = call i64 @indexFound(i32 %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %0
%20 = load i32, i32* %5
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %20)
br label %25
22: ; preds = %0
%23 = load i32, i32* %5
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %22, %19
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%27 = load i32, i32* %4
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 %27)
%29 = getelementptr inbounds [15 x i32], [15 x i32]* %2, i64 0, i64 0
%30 = load i32, i32* %4
%31 = call i32 @binarySearch(i32* %29, i32 0, i32 14, i32 %30)
store i32 %31, i32* %5
%32 = load i32, i32* %5
%33 = call i64 @indexFound(i32 %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %25
%36 = load i32, i32* %5
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %36)
br label %41
38: ; preds = %25
%39 = load i32, i32* %5
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 %39)
br label %41
41: ; preds = %38, %35
ret i32 0
}

LLVM IR (-O2):
@__const.main.a = [15 x i32] [i32 101, i32 102, i32 103, i32 104, i32 105, i32 106, i32 107, i32 108, i32 109, i32 110, i32 111, i32 112, i32 113, i32 114, i32 115]
@.str = [8 x i8] c"input: \00"
@.str.2 = [10 x i8] c"key1: %d\0A\00"
@.str.3 = [26 x i8] c"result index: %d, found!\0A\00"
@.str.4 = [30 x i8] c"result index: %d, not found!\0A\00"
@.str.5 = [10 x i8] c"key2: %d\0A\00"
define i32 @main() {
%1 = alloca [15 x i32]
%2 = bitcast [15 x i32]* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%4 = getelementptr inbounds [15 x i32], [15 x i32]* %1, i64 0, i64 0
%5 = call i32 @display(i32* %4, i32 15)
%6 = call i32 @putchar(i32 10)
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 113)
%8 = call i32 @binarySearch(i32* %4, i32 0, i32 14, i32 113)
%9 = call i64 @indexFound(i32 %8)
%10 = icmp eq i64 %9, 0
%11 = select i1 %10, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0)
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %11, i32 %8)
%13 = call i32 @putchar(i32 10)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 99)
%15 = call i32 @binarySearch(i32* %4, i32 0, i32 14, i32 99)
%16 = call i64 @indexFound(i32 %15)
%17 = icmp eq i64 %16, 0
%18 = select i1 %17, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0)
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %18, i32 %15)
ret i32 0
}