#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(int *, int, int);
int binary_search_recursive(int *, int /*<<< orphan*/, int, int);
int /*<<< orphan*/ printf(char *, int, ...);
int main() {
  int arr[] = {1, 5, 35, 112, 258, 324};
  int search_arr[] = {1, 35, 112, 324, 67};
  int i;
  for (i = 0; i < 5; i++) {
    int pos;
    pos = binary_search(arr, 6, search_arr[i]);
    if (pos >= 0) {
      printf("%d found at index %d.\n", search_arr[i], pos);
    } else {
      printf("%d not found.\n", search_arr[i]);
    }
    pos = binary_search_recursive(arr, 0, 5, search_arr[i]);
    if (pos >= 0) {
      printf("%d found at index %d, recursively\n", search_arr[i], pos);
    } else {
      printf("%d not found.\n", search_arr[i]);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeba(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xeb7(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xeb4(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0xeb9(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xeb6(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xeb4(%rip),%eax
mov    %eax,-0x30(%rbp)
movl   $0x0,-0x44(%rbp)
cmpl   $0x5,-0x44(%rbp)
jge    1253 <main+0x123>
lea    -0x20(%rbp),%rdi
movslq -0x44(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%edx
mov    $0x6,%esi
call   1040 <binary_search@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0x0,-0x48(%rbp)
jl     11d1 <main+0xa1>
movslq -0x44(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%esi
mov    -0x48(%rbp),%edx
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11e7 <main+0xb7>
movslq -0x44(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%esi
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x20(%rbp),%rdi
movslq -0x44(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%ecx
xor    %esi,%esi
mov    $0x5,%edx
call   1050 <binary_search_recursive@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0x0,-0x48(%rbp)
jl     122a <main+0xfa>
movslq -0x44(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%esi
mov    -0x48(%rbp),%edx
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1240 <main+0x110>
movslq -0x44(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%esi
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1245 <main+0x115>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1186 <main+0x56>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0xecb(%rip),%rax
mov    %rax,0x10(%rsp)
movaps 0xeaf(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xec4(%rip),%r13
mov    %rsp,%rbx
lea    0xef4(%rip),%r15
lea    0xede(%rip),%r12
xor    %r14d,%r14d
jmp    1196 <main+0x66>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x4,%r14
cmp    $0x14,%r14
je     1201 <main+0xd1>
mov    (%r14,%r13,1),%ebp
mov    %rbx,%rdi
mov    $0x6,%esi
mov    %ebp,%edx
call   1040 <binary_search@plt>
test   %eax,%eax
js     11d0 <main+0xa0>
lea    0xe80(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11dc <main+0xac>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x5,%edx
mov    %ebp,%ecx
call   1050 <binary_search_recursive@plt>
test   %eax,%eax
js     1180 <main+0x50>
mov    %r15,%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    118c <main+0x5c>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.arr = [6 x i32] [i32 1, i32 5, i32 35, i32 112, i32 258, i32 324]
@__const.main.search_arr = [5 x i32] [i32 1, i32 35, i32 112, i32 324, i32 67]
@.str = [23 x i8] c"%d found at index %d.\0A\00"
@.str.1 = [15 x i8] c"%d not found.\0A\00"
@.str.2 = [35 x i8] c"%d found at index %d, recursively\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [6 x i32]
%3 = alloca [5 x i32]
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = bitcast [6 x i32]* %2 to i8*
%7 = bitcast [5 x i32]* %3 to i8*
store i32 0, i32* %4
br label %8
8: ; preds = %56, %0
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 5
br i1 %10, label %11, label %59
11: ; preds = %8
%12 = getelementptr inbounds [6 x i32], [6 x i32]* %2, i64 0, i64 0
%13 = load i32, i32* %4
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [5 x i32], [5 x i32]* %3, i64 0, i64 %14
%16 = load i32, i32* %15
%17 = call i32 @binary_search(i32* %12, i32 6, i32 %16)
store i32 %17, i32* %5
%18 = load i32, i32* %5
%19 = icmp sge i32 %18, 0
br i1 %19, label %20, label %27
20: ; preds = %11
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [5 x i32], [5 x i32]* %3, i64 0, i64 %22
%24 = load i32, i32* %23
%25 = load i32, i32* %5
%26 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %24, i32 %25)
br label %33
27: ; preds = %11
%28 = load i32, i32* %4
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [5 x i32], [5 x i32]* %3, i64 0, i64 %29
%31 = load i32, i32* %30
%32 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %27, %20
%34 = getelementptr inbounds [6 x i32], [6 x i32]* %2, i64 0, i64 0
%35 = load i32, i32* %4
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [5 x i32], [5 x i32]* %3, i64 0, i64 %36
%38 = load i32, i32* %37
%39 = call i32 @binary_search_recursive(i32* %34, i32 0, i32 5, i32 %38)
store i32 %39, i32* %5
%40 = load i32, i32* %5
%41 = icmp sge i32 %40, 0
br i1 %41, label %42, label %49
42: ; preds = %33
%43 = load i32, i32* %4
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [5 x i32], [5 x i32]* %3, i64 0, i64 %44
%46 = load i32, i32* %45
%47 = load i32, i32* %5
%48 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %46, i32 %47)
br label %55
49: ; preds = %33
%50 = load i32, i32* %4
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [5 x i32], [5 x i32]* %3, i64 0, i64 %51
%53 = load i32, i32* %52
%54 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %53)
br label %55
55: ; preds = %49, %42
br label %56
56: ; preds = %55
%57 = load i32, i32* %4
%58 = add nsw i32 %57, 1
store i32 %58, i32* %4
br label %8
59: ; preds = %8
ret i32 0
}

LLVM IR (-O2):
@__const.main.arr = [6 x i32] [i32 1, i32 5, i32 35, i32 112, i32 258, i32 324]
@__const.main.search_arr = [5 x i32] [i32 1, i32 35, i32 112, i32 324, i32 67]
@.str = [23 x i8] c"%d found at index %d.\0A\00"
@.str.1 = [15 x i8] c"%d not found.\0A\00"
@.str.2 = [35 x i8] c"%d found at index %d, recursively\0A\00"
define i32 @main() {
%1 = alloca [6 x i32]
%2 = bitcast [6 x i32]* %1 to i8*
%3 = getelementptr inbounds [6 x i32], [6 x i32]* %1, i64 0, i64 0
br label %4
4: ; preds = %0, %21
%5 = phi i64 [ 0, %0 ], [ %22, %21 ]
%6 = getelementptr inbounds [5 x i32], [5 x i32]* @__const.main.search_arr, i64 0, i64 %5
%7 = load i32, i32* %6
%8 = call i32 @binary_search(i32* %3, i32 6, i32 %7)
%9 = icmp sgt i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %4
%11 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %8)
br label %14
12: ; preds = %4
%13 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %7)
br label %14
14: ; preds = %12, %10
%15 = call i32 @binary_search_recursive(i32* %3, i32 0, i32 5, i32 %7)
%16 = icmp sgt i32 %15, -1
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %7, i32 %15)
br label %21
19: ; preds = %14
%20 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %7)
br label %21
21: ; preds = %19, %17
%22 = add nuw nsw i64 %5, 1
%23 = icmp eq i64 %22, 5
br i1 %23, label %24, label %4
24: ; preds = %21
ret i32 0
}