#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 binarySearchIterative(int *, int, int);
int binarySearchRecursive(int *, int /*<<< orphan*/, int, int);
int /*<<< orphan*/ printf(char *, int, int);
void binarySearch_test() {
  int n, data, A[10] = {3, 6, 19, 25, 33, 39, 55, 78, 99, 100};
  n = 10;
  data = 20;
  printf("\nElement %d is at location: %d (-1 indicates not present in array)",
         data, binarySearchIterative(A, n, data));
  printf("\nElement %d is at location: %d (-1 indicates not present in array)",
         data, binarySearchRecursive(A, 0, n - 1, data));
  data = 39;
  printf("\nElement %d is at location: %d (-1 indicates not present in array)",
         data, binarySearchIterative(A, n, data));
  printf("\nElement %d is at location: %d (-1 indicates not present in array)",
         data, binarySearchRecursive(A, 0, n - 1, data));
}


x86 assembly (clang, -O0):
<binarySearch_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
lea    -0x30(%rbp),%rdi
lea    0xead(%rip),%rsi
mov    $0x28,%edx
call   1050 <memcpy@plt>
movl   $0xa,-0x4(%rbp)
movl   $0x14,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x40(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
call   1060 <binarySearchIterative@plt>
mov    -0x40(%rbp),%esi
mov    %eax,%edx
lea    0xe9c(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x3c(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x4(%rbp),%edx
sub    $0x1,%edx
mov    -0x8(%rbp),%ecx
xor    %esi,%esi
call   1040 <binarySearchRecursive@plt>
mov    -0x3c(%rbp),%esi
mov    %eax,%edx
lea    0xe71(%rip),%rdi
call   1030 <printf@plt>
movl   $0x27,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x38(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
call   1060 <binarySearchIterative@plt>
mov    -0x38(%rbp),%esi
mov    %eax,%edx
lea    0xe44(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x34(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x4(%rbp),%edx
sub    $0x1,%edx
mov    -0x8(%rbp),%ecx
xor    %esi,%esi
call   1040 <binarySearchRecursive@plt>
mov    -0x34(%rbp),%esi
mov    %eax,%edx
lea    0xe19(%rip),%rdi
call   1030 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<binarySearch_test>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    0xee2(%rip),%rax
mov    %rax,0x20(%rsp)
movaps 0xec6(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xeaa(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0xa,%esi
mov    $0x14,%edx
call   1050 <binarySearchIterative@plt>
lea    0xeb2(%rip),%rbx
mov    %rbx,%rdi
mov    $0x14,%esi
mov    %eax,%edx
call   1030 <printf@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x9,%edx
mov    $0x14,%ecx
call   1040 <binarySearchRecursive@plt>
mov    %rbx,%rdi
mov    $0x14,%esi
mov    %eax,%edx
call   1030 <printf@plt>
mov    %r14,%rdi
mov    $0xa,%esi
mov    $0x27,%edx
call   1050 <binarySearchIterative@plt>
mov    %rbx,%rdi
mov    $0x27,%esi
mov    %eax,%edx
call   1030 <printf@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x9,%edx
mov    $0x27,%ecx
call   1040 <binarySearchRecursive@plt>
mov    %rbx,%rdi
mov    $0x27,%esi
mov    %eax,%edx
call   1030 <printf@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.binarySearch_test.A = [10 x i32] [i32 3, i32 6, i32 19, i32 25, i32 33, i32 39, i32 55, i32 78, i32 99, i32 100]
@.str = [67 x i8] c"\0AElement %d is at location: %d (-1 indicates not present in array)\00"
define void @binarySearch_test() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [10 x i32]
%4 = bitcast [10 x i32]* %3 to i8*
store i32 10, i32* %1
store i32 20, i32* %2
%5 = load i32, i32* %2
%6 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 0
%7 = load i32, i32* %1
%8 = load i32, i32* %2
%9 = call i32 @binarySearchIterative(i32* %6, i32 %7, i32 %8)
%10 = call i32 @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %9)
%11 = load i32, i32* %2
%12 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 0
%13 = load i32, i32* %1
%14 = sub nsw i32 %13, 1
%15 = load i32, i32* %2
%16 = call i32 @binarySearchRecursive(i32* %12, i32 0, i32 %14, i32 %15)
%17 = call i32 @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %16)
store i32 39, i32* %2
%18 = load i32, i32* %2
%19 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 0
%20 = load i32, i32* %1
%21 = load i32, i32* %2
%22 = call i32 @binarySearchIterative(i32* %19, i32 %20, i32 %21)
%23 = call i32 @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str, i64 0, i64 0), i32 %18, i32 %22)
%24 = load i32, i32* %2
%25 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 0
%26 = load i32, i32* %1
%27 = sub nsw i32 %26, 1
%28 = load i32, i32* %2
%29 = call i32 @binarySearchRecursive(i32* %25, i32 0, i32 %27, i32 %28)
%30 = call i32 @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str, i64 0, i64 0), i32 %24, i32 %29)
ret void
}

LLVM IR (-O2):
@__const.binarySearch_test.A = [10 x i32] [i32 3, i32 6, i32 19, i32 25, i32 33, i32 39, i32 55, i32 78, i32 99, i32 100]
@.str = [67 x i8] c"\0AElement %d is at location: %d (-1 indicates not present in array)\00"
define void @binarySearch_test() {
%1 = alloca [10 x i32]
%2 = bitcast [10 x i32]* %1 to i8*
%3 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 0
%4 = call i32 @binarySearchIterative(i32* %3, i32 10, i32 20)
%5 = call i32 @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str, i64 0, i64 0), i32 20, i32 %4)
%6 = call i32 @binarySearchRecursive(i32* %3, i32 0, i32 9, i32 20)
%7 = call i32 @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str, i64 0, i64 0), i32 20, i32 %6)
%8 = call i32 @binarySearchIterative(i32* %3, i32 10, i32 39)
%9 = call i32 @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str, i64 0, i64 0), i32 39, i32 %8)
%10 = call i32 @binarySearchRecursive(i32* %3, i32 0, i32 9, i32 39)
%11 = call i32 @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str, i64 0, i64 0), i32 39, i32 %10)
ret void
}