#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, int);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int myarray[100] = {2, 4, 7, 8, 11, 14, 17, 19, 21, 24};
  int position, key, i;
  int low, high;
  for (i = 0; i < 100; i++) {
    myarray[i] = 2 * i + 1;
  }
  printf("\nArray is ");
  for (i = 0; i < 100; ++i)
    printf("%d ", myarray[i]);
  printf("\nInput value to search for: ");
  scanf("%d", &key);
  low = 0;
  high = 99;
  position = BinarySearch(myarray, low, high, key);
  if (position == -1)
    printf("\nValue %d not found\n\n", key);
  else
    printf("\nValue %d found at array position: %d\n\n", myarray[position],
           position);
  getchar();
  getchar();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1c0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x1a0(%rbp),%rdi
lea    0xe90(%rip),%rsi
mov    $0x190,%edx
call   1060 <memcpy@plt>
movl   $0x0,-0x1ac(%rbp)
cmpl   $0x64,-0x1ac(%rbp)
jge    11bf <main+0x6f>
mov    -0x1ac(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
movslq -0x1ac(%rbp),%rax
mov    %ecx,-0x1a0(%rbp,%rax,4)
mov    -0x1ac(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1ac(%rbp)
jmp    1184 <main+0x34>
lea    0xfca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1ac(%rbp)
cmpl   $0x64,-0x1ac(%rbp)
jge    1214 <main+0xc4>
movslq -0x1ac(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%esi
lea    0xfa2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1ac(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1ac(%rbp)
jmp    11d7 <main+0x87>
lea    0xf84(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf93(%rip),%rdi
lea    -0x1a8(%rbp),%rsi
call   1070 <scanf@plt>
movl   $0x0,-0x1b0(%rbp)
movl   $0x63,-0x1b4(%rbp)
lea    -0x1a0(%rbp),%rdi
mov    -0x1b0(%rbp),%esi
mov    -0x1b4(%rbp),%edx
mov    -0x1a8(%rbp),%ecx
call   1050 <BinarySearch@plt>
mov    %eax,-0x1a4(%rbp)
cmpl   $0xffffffff,-0x1a4(%rbp)
jne    1293 <main+0x143>
mov    -0x1a8(%rbp),%esi
lea    0xf38(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12b5 <main+0x165>
movslq -0x1a4(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%esi
mov    -0x1a4(%rbp),%edx
lea    0xf27(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
xor    %eax,%eax
add    $0x1c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x1a8,%rsp
lea    0x102f(%rip),%rsi
lea    0x10(%rsp),%rdi
mov    $0x190,%edx
call   1060 <memcpy@plt>
movaps 0xe89(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe8d(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe91(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe95(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xe99(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xe9d(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xea1(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xea5(%rip),%xmm0
movaps %xmm0,0x80(%rsp)
movaps 0xea6(%rip),%xmm0
movaps %xmm0,0x90(%rsp)
movaps 0xea7(%rip),%xmm0
movaps %xmm0,0xa0(%rsp)
movaps 0xea8(%rip),%xmm0
movaps %xmm0,0xb0(%rsp)
movaps 0xea9(%rip),%xmm0
movaps %xmm0,0xc0(%rsp)
movaps 0xeaa(%rip),%xmm0
movaps %xmm0,0xd0(%rsp)
movaps 0xeab(%rip),%xmm0
movaps %xmm0,0xe0(%rsp)
movaps 0xeac(%rip),%xmm0
movaps %xmm0,0xf0(%rsp)
movaps 0xead(%rip),%xmm0
movaps %xmm0,0x100(%rsp)
movaps 0xeae(%rip),%xmm0
movaps %xmm0,0x110(%rsp)
movaps 0xeaf(%rip),%xmm0
movaps %xmm0,0x120(%rsp)
movaps 0xeb0(%rip),%xmm0
movaps %xmm0,0x130(%rsp)
movaps 0xeb1(%rip),%xmm0
movaps %xmm0,0x140(%rsp)
movaps 0xeb2(%rip),%xmm0
movaps %xmm0,0x150(%rsp)
movaps 0xeb3(%rip),%xmm0
movaps %xmm0,0x160(%rsp)
movaps 0xeb4(%rip),%xmm0
movaps %xmm0,0x170(%rsp)
movaps 0xeb5(%rip),%xmm0
movaps %xmm0,0x180(%rsp)
movaps 0xeb6(%rip),%xmm0
movaps %xmm0,0x190(%rsp)
lea    0x1047(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x1044(%rip),%r14
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    0x10(%rsp,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%rbx
cmp    $0x64,%rbx
jne    12f0 <main+0x1a0>
lea    0x1020(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x102f(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1070 <scanf@plt>
mov    0xc(%rsp),%ecx
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x63,%edx
call   1050 <BinarySearch@plt>
cmp    $0xffffffff,%eax
je     135a <main+0x20a>
movslq %eax,%rcx
mov    0x10(%rsp,%rcx,4),%esi
lea    0x1016(%rip),%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    136c <main+0x21c>
mov    0xc(%rsp),%esi
lea    0xfea(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
xor    %eax,%eax
add    $0x1a8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.myarray = <{ [10 x i32], [90 x i32] }> <{ [10 x i32] [i32 2, i32 4, i32 7, i32 8, i32 11, i32 14, i32 17, i32 19, i32 21, i32 24], [90 x i32] zeroinitializer }>
@.str = [11 x i8] c"\0AArray is \00"
@.str.1 = [4 x i8] c"%d \00"
@.str.2 = [29 x i8] c"\0AInput value to search for: \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [22 x i8] c"\0AValue %d not found\0A\0A\00"
@.str.5 = [40 x i8] c"\0AValue %d found at array position: %d\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = bitcast [100 x i32]* %2 to i8*
store i32 0, i32* %5
br label %9
9: ; preds = %19, %0
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 100
br i1 %11, label %12, label %22
12: ; preds = %9
%13 = load i32, i32* %5
%14 = mul nsw i32 2, %13
%15 = add nsw i32 %14, 1
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %17
store i32 %15, i32* %18
br label %19
19: ; preds = %12
%20 = load i32, i32* %5
%21 = add nsw i32 %20, 1
store i32 %21, i32* %5
br label %9
22: ; preds = %9
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %5
br label %24
24: ; preds = %33, %22
%25 = load i32, i32* %5
%26 = icmp slt i32 %25, 100
br i1 %26, label %27, label %36
27: ; preds = %24
%28 = load i32, i32* %5
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %29
%31 = load i32, i32* %30
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %27
%34 = load i32, i32* %5
%35 = add nsw i32 %34, 1
store i32 %35, i32* %5
br label %24
36: ; preds = %24
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%38 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %4)
store i32 0, i32* %6
store i32 99, i32* %7
%39 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%40 = load i32, i32* %6
%41 = load i32, i32* %7
%42 = load i32, i32* %4
%43 = call i32 @BinarySearch(i32* %39, i32 %40, i32 %41, i32 %42)
store i32 %43, i32* %3
%44 = load i32, i32* %3
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %49
46: ; preds = %36
%47 = load i32, i32* %4
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 %47)
br label %56
49: ; preds = %36
%50 = load i32, i32* %3
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %51
%53 = load i32, i32* %52
%54 = load i32, i32* %3
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i32 %53, i32 %54)
br label %56
56: ; preds = %49, %46
%57 = call i32 (...) @getchar()
%58 = call i32 (...) @getchar()
ret i32 0
}

LLVM IR (-O2):
@__const.main.myarray = <{ [10 x i32], [90 x i32] }> <{ [10 x i32] [i32 2, i32 4, i32 7, i32 8, i32 11, i32 14, i32 17, i32 19, i32 21, i32 24], [90 x i32] zeroinitializer }>
@.str = [11 x i8] c"\0AArray is \00"
@.str.1 = [4 x i8] c"%d \00"
@.str.2 = [29 x i8] c"\0AInput value to search for: \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [22 x i8] c"\0AValue %d not found\0A\0A\00"
@.str.5 = [40 x i8] c"\0AValue %d found at array position: %d\0A\0A\00"
define i32 @main() {
%1 = alloca [100 x i32]
%2 = alloca i32
%3 = bitcast [100 x i32]* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = bitcast [100 x i32]* %1 to <4 x i32>*
store <4 x i32> <i32 1, i32 3, i32 5, i32 7>, <4 x i32>* %5
%6 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 4
%7 = bitcast i32* %6 to <4 x i32>*
store <4 x i32> <i32 9, i32 11, i32 13, i32 15>, <4 x i32>* %7
%8 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 8
%9 = bitcast i32* %8 to <4 x i32>*
store <4 x i32> <i32 17, i32 19, i32 21, i32 23>, <4 x i32>* %9
%10 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 12
%11 = bitcast i32* %10 to <4 x i32>*
store <4 x i32> <i32 25, i32 27, i32 29, i32 31>, <4 x i32>* %11
%12 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 16
%13 = bitcast i32* %12 to <4 x i32>*
store <4 x i32> <i32 33, i32 35, i32 37, i32 39>, <4 x i32>* %13
%14 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 20
%15 = bitcast i32* %14 to <4 x i32>*
store <4 x i32> <i32 41, i32 43, i32 45, i32 47>, <4 x i32>* %15
%16 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 24
%17 = bitcast i32* %16 to <4 x i32>*
store <4 x i32> <i32 49, i32 51, i32 53, i32 55>, <4 x i32>* %17
%18 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 28
%19 = bitcast i32* %18 to <4 x i32>*
store <4 x i32> <i32 57, i32 59, i32 61, i32 63>, <4 x i32>* %19
%20 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 32
%21 = bitcast i32* %20 to <4 x i32>*
store <4 x i32> <i32 65, i32 67, i32 69, i32 71>, <4 x i32>* %21
%22 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 36
%23 = bitcast i32* %22 to <4 x i32>*
store <4 x i32> <i32 73, i32 75, i32 77, i32 79>, <4 x i32>* %23
%24 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 40
%25 = bitcast i32* %24 to <4 x i32>*
store <4 x i32> <i32 81, i32 83, i32 85, i32 87>, <4 x i32>* %25
%26 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 44
%27 = bitcast i32* %26 to <4 x i32>*
store <4 x i32> <i32 89, i32 91, i32 93, i32 95>, <4 x i32>* %27
%28 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 48
%29 = bitcast i32* %28 to <4 x i32>*
store <4 x i32> <i32 97, i32 99, i32 101, i32 103>, <4 x i32>* %29
%30 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 52
%31 = bitcast i32* %30 to <4 x i32>*
store <4 x i32> <i32 105, i32 107, i32 109, i32 111>, <4 x i32>* %31
%32 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 56
%33 = bitcast i32* %32 to <4 x i32>*
store <4 x i32> <i32 113, i32 115, i32 117, i32 119>, <4 x i32>* %33
%34 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 60
%35 = bitcast i32* %34 to <4 x i32>*
store <4 x i32> <i32 121, i32 123, i32 125, i32 127>, <4 x i32>* %35
%36 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 64
%37 = bitcast i32* %36 to <4 x i32>*
store <4 x i32> <i32 129, i32 131, i32 133, i32 135>, <4 x i32>* %37
%38 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 68
%39 = bitcast i32* %38 to <4 x i32>*
store <4 x i32> <i32 137, i32 139, i32 141, i32 143>, <4 x i32>* %39
%40 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 72
%41 = bitcast i32* %40 to <4 x i32>*
store <4 x i32> <i32 145, i32 147, i32 149, i32 151>, <4 x i32>* %41
%42 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 76
%43 = bitcast i32* %42 to <4 x i32>*
store <4 x i32> <i32 153, i32 155, i32 157, i32 159>, <4 x i32>* %43
%44 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 80
%45 = bitcast i32* %44 to <4 x i32>*
store <4 x i32> <i32 161, i32 163, i32 165, i32 167>, <4 x i32>* %45
%46 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 84
%47 = bitcast i32* %46 to <4 x i32>*
store <4 x i32> <i32 169, i32 171, i32 173, i32 175>, <4 x i32>* %47
%48 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 88
%49 = bitcast i32* %48 to <4 x i32>*
store <4 x i32> <i32 177, i32 179, i32 181, i32 183>, <4 x i32>* %49
%50 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 92
%51 = bitcast i32* %50 to <4 x i32>*
store <4 x i32> <i32 185, i32 187, i32 189, i32 191>, <4 x i32>* %51
%52 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 96
%53 = bitcast i32* %52 to <4 x i32>*
store <4 x i32> <i32 193, i32 195, i32 197, i32 199>, <4 x i32>* %53
%54 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %55
55: ; preds = %0, %55
%56 = phi i64 [ 0, %0 ], [ %60, %55 ]
%57 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 %56
%58 = load i32, i32* %57
%59 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %58)
%60 = add nuw nsw i64 %56, 1
%61 = icmp eq i64 %60, 100
br i1 %61, label %62, label %55
62: ; preds = %55
%63 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%64 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%65 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 0
%66 = load i32, i32* %2
%67 = call i32 @BinarySearch(i32* %65, i32 0, i32 99, i32 %66)
%68 = icmp eq i32 %67, -1
br i1 %68, label %69, label %72
69: ; preds = %62
%70 = load i32, i32* %2
%71 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 %70)
br label %77
72: ; preds = %62
%73 = sext i32 %67 to i64
%74 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 %73
%75 = load i32, i32* %74
%76 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i32 %75, i32 %67)
br label %77
77: ; preds = %72, %69
%78 = call i32 (...) @getchar()
%79 = call i32 (...) @getchar()
ret i32 0
}