#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 binary_search_iterative(int *, int, int);
int binary_search_recursive(int *, int /*<<< orphan*/, int, int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int len = 100;
  int mubiao = 50;
  int arr[len];
  int key;
  for (int i = 0; i < len; i++) {
    arr[i] = 2 * i;
  }
  printf("Recursive\n");
  key = binary_search_recursive(arr, 0, len - 1, mubiao);
  if (key != -1)
    printf("Value %d Found!!, key is %d\n", mubiao, key);
  else
    printf("Value %d not found...\n\n", mubiao);
  printf("Iterative\n");
  key = binary_search_iterative(arr, len - 1, mubiao);
  if (key != -1)
    printf("Value %d Found!!, key is %d\n", mubiao, key);
  else
    printf("Value %d not found...\n", mubiao);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x64,-0x8(%rbp)
movl   $0x32,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11a6 <main+0x76>
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%edx
shl    $0x1,%edx
movslq -0x28(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    117b <main+0x4b>
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%edx
sub    $0x1,%edx
mov    -0xc(%rbp),%ecx
xor    %esi,%esi
call   1040 <binary_search_recursive@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
je     11ee <main+0xbe>
mov    -0xc(%rbp),%esi
mov    -0x24(%rbp),%edx
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ff <main+0xcf>
mov    -0xc(%rbp),%esi
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%esi
sub    $0x1,%esi
mov    -0xc(%rbp),%edx
call   1050 <binary_search_iterative@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
je     1245 <main+0x115>
mov    -0xc(%rbp),%esi
mov    -0x24(%rbp),%edx
lea    0xdd2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1256 <main+0x126>
mov    -0xc(%rbp),%esi
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x198,%rsp
movaps 0xeb2(%rip),%xmm0
movaps %xmm0,(%rsp)
movaps 0xeb7(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xebb(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xebf(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xec3(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xec7(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xecb(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xecf(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xed3(%rip),%xmm0
movaps %xmm0,0x80(%rsp)
movaps 0xed4(%rip),%xmm0
movaps %xmm0,0x90(%rsp)
movaps 0xed5(%rip),%xmm0
movaps %xmm0,0xa0(%rsp)
movaps 0xed6(%rip),%xmm0
movaps %xmm0,0xb0(%rsp)
movaps 0xed7(%rip),%xmm0
movaps %xmm0,0xc0(%rsp)
movaps 0xed8(%rip),%xmm0
movaps %xmm0,0xd0(%rsp)
movaps 0xed9(%rip),%xmm0
movaps %xmm0,0xe0(%rsp)
movaps 0xeda(%rip),%xmm0
movaps %xmm0,0xf0(%rsp)
movaps 0xedb(%rip),%xmm0
movaps %xmm0,0x100(%rsp)
movaps 0xedc(%rip),%xmm0
movaps %xmm0,0x110(%rsp)
movaps 0xedd(%rip),%xmm0
movaps %xmm0,0x120(%rsp)
movaps 0xede(%rip),%xmm0
movaps %xmm0,0x130(%rsp)
movaps 0xedf(%rip),%xmm0
movaps %xmm0,0x140(%rsp)
movaps 0xee0(%rip),%xmm0
movaps %xmm0,0x150(%rsp)
movaps 0xee1(%rip),%xmm0
movaps %xmm0,0x160(%rsp)
movaps 0xee2(%rip),%xmm0
movaps %xmm0,0x170(%rsp)
movaps 0xee3(%rip),%xmm0
movaps %xmm0,0x180(%rsp)
lea    0xf30(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x63,%edx
mov    $0x32,%ecx
call   1050 <binary_search_recursive@plt>
cmp    $0xffffffff,%eax
je     12e1 <main+0x1a1>
lea    0xebf(%rip),%rdi
mov    $0x32,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    12f4 <main+0x1b4>
lea    0xec5(%rip),%rdi
mov    $0x32,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeeb(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
mov    $0x63,%esi
mov    $0x32,%edx
call   1060 <binary_search_iterative@plt>
cmp    $0xffffffff,%eax
je     132e <main+0x1ee>
lea    0xe72(%rip),%rdi
mov    $0x32,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1341 <main+0x201>
lea    0xe90(%rip),%rdi
mov    $0x32,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x198,%rsp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"Recursive\0A\00"
@.str.1 = [29 x i8] c"Value %d Found!!, key is %d\0A\00"
@.str.2 = [24 x i8] c"Value %d not found...\0A\0A\00"
@.str.3 = [11 x i8] c"Iterative\0A\00"
@.str.4 = [23 x i8] c"Value %d not found...\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
store i32 100, i32* %2
store i32 50, i32* %3
%8 = load i32, i32* %2
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %4
%11 = alloca i32, i64 %9
store i64 %9, i64* %5
store i32 0, i32* %7
br label %12
12: ; preds = %22, %0
%13 = load i32, i32* %7
%14 = load i32, i32* %2
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %25
16: ; preds = %12
%17 = load i32, i32* %7
%18 = mul nsw i32 2, %17
%19 = load i32, i32* %7
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i32, i32* %11, i64 %20
store i32 %18, i32* %21
br label %22
22: ; preds = %16
%23 = load i32, i32* %7
%24 = add nsw i32 %23, 1
store i32 %24, i32* %7
br label %12
25: ; preds = %12
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%27 = load i32, i32* %2
%28 = sub nsw i32 %27, 1
%29 = load i32, i32* %3
%30 = call i32 @binary_search_recursive(i32* %11, i32 0, i32 %28, i32 %29)
store i32 %30, i32* %6
%31 = load i32, i32* %6
%32 = icmp ne i32 %31, -1
br i1 %32, label %33, label %37
33: ; preds = %25
%34 = load i32, i32* %3
%35 = load i32, i32* %6
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %34, i32 %35)
br label %40
37: ; preds = %25
%38 = load i32, i32* %3
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %38)
br label %40
40: ; preds = %37, %33
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%42 = load i32, i32* %2
%43 = sub nsw i32 %42, 1
%44 = load i32, i32* %3
%45 = call i32 @binary_search_iterative(i32* %11, i32 %43, i32 %44)
store i32 %45, i32* %6
%46 = load i32, i32* %6
%47 = icmp ne i32 %46, -1
br i1 %47, label %48, label %52
48: ; preds = %40
%49 = load i32, i32* %3
%50 = load i32, i32* %6
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %49, i32 %50)
br label %55
52: ; preds = %40
%53 = load i32, i32* %3
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %53)
br label %55
55: ; preds = %52, %48
store i32 0, i32* %1
%56 = load i8*, i8** %4
%57 = load i32, i32* %1
ret i32 %57
}

LLVM IR (-O2):
@.str.1 = [29 x i8] c"Value %d Found!!, key is %d\0A\00"
@.str.2 = [24 x i8] c"Value %d not found...\0A\0A\00"
@.str.4 = [23 x i8] c"Value %d not found...\0A\00"
@str = [10 x i8] c"Recursive\00"
@str.5 = [10 x i8] c"Iterative\00"
define i32 @main() {
%1 = alloca [100 x i32]
%2 = bitcast [100 x i32]* %1 to <4 x i32>*
store <4 x i32> <i32 0, i32 2, i32 4, i32 6>, <4 x i32>* %2
%3 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 4
%4 = bitcast i32* %3 to <4 x i32>*
store <4 x i32> <i32 8, i32 10, i32 12, i32 14>, <4 x i32>* %4
%5 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 8
%6 = bitcast i32* %5 to <4 x i32>*
store <4 x i32> <i32 16, i32 18, i32 20, i32 22>, <4 x i32>* %6
%7 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 12
%8 = bitcast i32* %7 to <4 x i32>*
store <4 x i32> <i32 24, i32 26, i32 28, i32 30>, <4 x i32>* %8
%9 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 16
%10 = bitcast i32* %9 to <4 x i32>*
store <4 x i32> <i32 32, i32 34, i32 36, i32 38>, <4 x i32>* %10
%11 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 20
%12 = bitcast i32* %11 to <4 x i32>*
store <4 x i32> <i32 40, i32 42, i32 44, i32 46>, <4 x i32>* %12
%13 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 24
%14 = bitcast i32* %13 to <4 x i32>*
store <4 x i32> <i32 48, i32 50, i32 52, i32 54>, <4 x i32>* %14
%15 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 28
%16 = bitcast i32* %15 to <4 x i32>*
store <4 x i32> <i32 56, i32 58, i32 60, i32 62>, <4 x i32>* %16
%17 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 32
%18 = bitcast i32* %17 to <4 x i32>*
store <4 x i32> <i32 64, i32 66, i32 68, i32 70>, <4 x i32>* %18
%19 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 36
%20 = bitcast i32* %19 to <4 x i32>*
store <4 x i32> <i32 72, i32 74, i32 76, i32 78>, <4 x i32>* %20
%21 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 40
%22 = bitcast i32* %21 to <4 x i32>*
store <4 x i32> <i32 80, i32 82, i32 84, i32 86>, <4 x i32>* %22
%23 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 44
%24 = bitcast i32* %23 to <4 x i32>*
store <4 x i32> <i32 88, i32 90, i32 92, i32 94>, <4 x i32>* %24
%25 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 48
%26 = bitcast i32* %25 to <4 x i32>*
store <4 x i32> <i32 96, i32 98, i32 100, i32 102>, <4 x i32>* %26
%27 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 52
%28 = bitcast i32* %27 to <4 x i32>*
store <4 x i32> <i32 104, i32 106, i32 108, i32 110>, <4 x i32>* %28
%29 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 56
%30 = bitcast i32* %29 to <4 x i32>*
store <4 x i32> <i32 112, i32 114, i32 116, i32 118>, <4 x i32>* %30
%31 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 60
%32 = bitcast i32* %31 to <4 x i32>*
store <4 x i32> <i32 120, i32 122, i32 124, i32 126>, <4 x i32>* %32
%33 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 64
%34 = bitcast i32* %33 to <4 x i32>*
store <4 x i32> <i32 128, i32 130, i32 132, i32 134>, <4 x i32>* %34
%35 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 68
%36 = bitcast i32* %35 to <4 x i32>*
store <4 x i32> <i32 136, i32 138, i32 140, i32 142>, <4 x i32>* %36
%37 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 72
%38 = bitcast i32* %37 to <4 x i32>*
store <4 x i32> <i32 144, i32 146, i32 148, i32 150>, <4 x i32>* %38
%39 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 76
%40 = bitcast i32* %39 to <4 x i32>*
store <4 x i32> <i32 152, i32 154, i32 156, i32 158>, <4 x i32>* %40
%41 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 80
%42 = bitcast i32* %41 to <4 x i32>*
store <4 x i32> <i32 160, i32 162, i32 164, i32 166>, <4 x i32>* %42
%43 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 84
%44 = bitcast i32* %43 to <4 x i32>*
store <4 x i32> <i32 168, i32 170, i32 172, i32 174>, <4 x i32>* %44
%45 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 88
%46 = bitcast i32* %45 to <4 x i32>*
store <4 x i32> <i32 176, i32 178, i32 180, i32 182>, <4 x i32>* %46
%47 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 92
%48 = bitcast i32* %47 to <4 x i32>*
store <4 x i32> <i32 184, i32 186, i32 188, i32 190>, <4 x i32>* %48
%49 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 96
%50 = bitcast i32* %49 to <4 x i32>*
store <4 x i32> <i32 192, i32 194, i32 196, i32 198>, <4 x i32>* %50
%51 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 0
%52 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%53 = call i32 @binary_search_recursive(i32* %51, i32 0, i32 99, i32 50)
%54 = icmp eq i32 %53, -1
br i1 %54, label %57, label %55
55: ; preds = %0
%56 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 50, i32 %53)
br label %59
57: ; preds = %0
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 50)
br label %59
59: ; preds = %57, %55
%60 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.5, i64 0, i64 0))
%61 = call i32 @binary_search_iterative(i32* %51, i32 99, i32 50)
%62 = icmp eq i32 %61, -1
br i1 %62, label %65, label %63
63: ; preds = %59
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 50, i32 %61)
br label %67
65: ; preds = %59
%66 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 50)
br label %67
67: ; preds = %65, %63
ret i32 0
}