#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 */
typedef int /*<<< orphan*/ arr;

/* Variables and functions */
int binarySearch(int *, int /*<<< orphan*/, int, int);
int /*<<< orphan*/ printf(char *, int, int);
int recursiveBinarySearch(int *, int /*<<< orphan*/, int, int);
int main(void) {
  int arr[] = {1, 2, 3, 5};
  int size = sizeof(arr) / sizeof(arr[0]);
  int find = 3;
  printf("Position of %d is %d\n", find,
         recursiveBinarySearch(arr, 0, size - 1, find));
  printf("Position of %d is %d\n", find, binarySearch(arr, 0, size - 1, find));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeba(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xeb7(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x4,-0x24(%rbp)
movl   $0x3,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x30(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%edx
sub    $0x1,%edx
mov    -0x28(%rbp),%ecx
xor    %esi,%esi
call   1030 <recursiveBinarySearch@plt>
mov    -0x30(%rbp),%esi
mov    %eax,%edx
lea    0xe87(%rip),%rdi
call   1040 <printf@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x2c(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%edx
sub    $0x1,%edx
mov    -0x28(%rbp),%ecx
xor    %esi,%esi
call   1050 <binarySearch@plt>
mov    -0x2c(%rbp),%esi
mov    %eax,%edx
lea    0xe5c(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movaps 0xec2(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x3,%edx
mov    $0x3,%ecx
call   1030 <recursiveBinarySearch@plt>
lea    0xeb0(%rip),%rbx
mov    %rbx,%rdi
mov    $0x3,%esi
mov    %eax,%edx
call   1040 <printf@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x3,%edx
mov    $0x3,%ecx
call   1050 <binarySearch@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
mov    %eax,%edx
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.arr = [4 x i32] [i32 1, i32 2, i32 3, i32 5]
@.str = [22 x i8] c"Position of %d is %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [4 x i32]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = bitcast [4 x i32]* %2 to i8*
store i32 4, i32* %3
store i32 3, i32* %4
%6 = load i32, i32* %4
%7 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 0
%8 = load i32, i32* %3
%9 = sub nsw i32 %8, 1
%10 = load i32, i32* %4
%11 = call i32 @recursiveBinarySearch(i32* %7, i32 0, i32 %9, i32 %10)
%12 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %11)
%13 = load i32, i32* %4
%14 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 0
%15 = load i32, i32* %3
%16 = sub nsw i32 %15, 1
%17 = load i32, i32* %4
%18 = call i32 @binarySearch(i32* %14, i32 0, i32 %16, i32 %17)
%19 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %18)
ret i32 0
}

LLVM IR (-O2):
@__const.main.arr = [4 x i32] [i32 1, i32 2, i32 3, i32 5]
@.str = [22 x i8] c"Position of %d is %d\0A\00"
define i32 @main() {
%1 = alloca [4 x i32]
%2 = bitcast [4 x i32]* %1 to i8*
%3 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 0
%4 = call i32 @recursiveBinarySearch(i32* %3, i32 0, i32 3, i32 3)
%5 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 3, i32 %4)
%6 = call i32 @binarySearch(i32* %3, i32 0, i32 3, i32 3)
%7 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 3, i32 %6)
ret i32 0
}