#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*/ nums;

/* Variables and functions */
int binsearch_iter(int *, int /*<<< orphan*/, int, int);
int binsearch_recur(int *, int /*<<< orphan*/, int, int);
int /*<<< orphan*/ printf(char *, int, int);
int main(int argc, char *argv[]) {
  int nums[] = {0, 1, 2, 3};
  int i = 0, max = (sizeof(nums) - sizeof(int)) / sizeof(int);
  for (i = -1; i < 5; ++i) {
    printf("Iter: %d is at index %d, ", i, binsearch_iter(nums, 0, max, i));
    printf("Recur: %d is at index %d\n", i, binsearch_recur(nums, 0, max, i));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xeb3(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xeb0(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x3,-0x28(%rbp)
movl   $0xffffffff,-0x24(%rbp)
cmpl   $0x5,-0x24(%rbp)
jge    11d9 <main+0xa9>
mov    -0x24(%rbp),%eax
mov    %eax,-0x30(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%edx
mov    -0x24(%rbp),%ecx
xor    %esi,%esi
call   1040 <binsearch_iter@plt>
mov    -0x30(%rbp),%esi
mov    %eax,%edx
lea    0xe72(%rip),%rdi
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x2c(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%edx
mov    -0x24(%rbp),%ecx
xor    %esi,%esi
call   1050 <binsearch_recur@plt>
mov    -0x2c(%rbp),%esi
mov    %eax,%edx
lea    0xe64(%rip),%rdi
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1171 <main+0x41>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movaps 0xec0(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x3,%edx
mov    $0xffffffff,%ecx
call   1040 <binsearch_iter@plt>
lea    0xeae(%rip),%r14
mov    %r14,%rdi
mov    $0xffffffff,%esi
mov    %eax,%edx
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x3,%edx
mov    $0xffffffff,%ecx
call   1050 <binsearch_recur@plt>
lea    0xe9e(%rip),%r15
mov    %r15,%rdi
mov    $0xffffffff,%esi
mov    %eax,%edx
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x3,%edx
xor    %ecx,%ecx
call   1040 <binsearch_iter@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    %eax,%edx
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x3,%edx
xor    %ecx,%ecx
call   1050 <binsearch_recur@plt>
mov    %r15,%rdi
xor    %esi,%esi
mov    %eax,%edx
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x3,%edx
mov    $0x1,%ecx
call   1040 <binsearch_iter@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    %eax,%edx
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x3,%edx
mov    $0x1,%ecx
call   1050 <binsearch_recur@plt>
mov    %r15,%rdi
mov    $0x1,%esi
mov    %eax,%edx
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x3,%edx
mov    $0x2,%ecx
call   1040 <binsearch_iter@plt>
mov    %r14,%rdi
mov    $0x2,%esi
mov    %eax,%edx
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x3,%edx
mov    $0x2,%ecx
call   1050 <binsearch_recur@plt>
mov    %r15,%rdi
mov    $0x2,%esi
mov    %eax,%edx
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x3,%edx
mov    $0x3,%ecx
call   1040 <binsearch_iter@plt>
mov    %r14,%rdi
mov    $0x3,%esi
mov    %eax,%edx
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x3,%edx
mov    $0x3,%ecx
call   1050 <binsearch_recur@plt>
mov    %r15,%rdi
mov    $0x3,%esi
mov    %eax,%edx
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x3,%edx
mov    $0x4,%ecx
call   1040 <binsearch_iter@plt>
mov    %r14,%rdi
mov    $0x4,%esi
mov    %eax,%edx
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x3,%edx
mov    $0x4,%ecx
call   1050 <binsearch_recur@plt>
mov    %r15,%rdi
mov    $0x4,%esi
mov    %eax,%edx
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.nums = [4 x i32] [i32 0, i32 1, i32 2, i32 3]
@.str = [26 x i8] c"Iter: %d is at index %d, \00"
@.str.1 = [26 x i8] c"Recur: %d is at index %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [4 x i32]
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = bitcast [4 x i32]* %6 to i8*
store i32 0, i32* %7
store i32 3, i32* %8
store i32 -1, i32* %7
br label %10
10: ; preds = %26, %2
%11 = load i32, i32* %7
%12 = icmp slt i32 %11, 5
br i1 %12, label %13, label %29
13: ; preds = %10
%14 = load i32, i32* %7
%15 = getelementptr inbounds [4 x i32], [4 x i32]* %6, i64 0, i64 0
%16 = load i32, i32* %8
%17 = load i32, i32* %7
%18 = call i32 @binsearch_iter(i32* %15, i32 0, i32 %16, i32 %17)
%19 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %14, i32 %18)
%20 = load i32, i32* %7
%21 = getelementptr inbounds [4 x i32], [4 x i32]* %6, i64 0, i64 0
%22 = load i32, i32* %8
%23 = load i32, i32* %7
%24 = call i32 @binsearch_recur(i32* %21, i32 0, i32 %22, i32 %23)
%25 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %20, i32 %24)
br label %26
26: ; preds = %13
%27 = load i32, i32* %7
%28 = add nsw i32 %27, 1
store i32 %28, i32* %7
br label %10
29: ; preds = %10
ret i32 0
}

LLVM IR (-O2):
@__const.main.nums = [4 x i32] [i32 0, i32 1, i32 2, i32 3]
@.str = [26 x i8] c"Iter: %d is at index %d, \00"
@.str.1 = [26 x i8] c"Recur: %d is at index %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [4 x i32]
%4 = bitcast [4 x i32]* %3 to i8*
%5 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 0
%6 = call i32 @binsearch_iter(i32* %5, i32 0, i32 3, i32 -1)
%7 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 -1, i32 %6)
%8 = call i32 @binsearch_recur(i32* %5, i32 0, i32 3, i32 -1)
%9 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 -1, i32 %8)
%10 = call i32 @binsearch_iter(i32* %5, i32 0, i32 3, i32 0)
%11 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 0, i32 %10)
%12 = call i32 @binsearch_recur(i32* %5, i32 0, i32 3, i32 0)
%13 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 %12)
%14 = call i32 @binsearch_iter(i32* %5, i32 0, i32 3, i32 1)
%15 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 1, i32 %14)
%16 = call i32 @binsearch_recur(i32* %5, i32 0, i32 3, i32 1)
%17 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 1, i32 %16)
%18 = call i32 @binsearch_iter(i32* %5, i32 0, i32 3, i32 2)
%19 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 2, i32 %18)
%20 = call i32 @binsearch_recur(i32* %5, i32 0, i32 3, i32 2)
%21 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 2, i32 %20)
%22 = call i32 @binsearch_iter(i32* %5, i32 0, i32 3, i32 3)
%23 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 3, i32 %22)
%24 = call i32 @binsearch_recur(i32* %5, i32 0, i32 3, i32 3)
%25 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 3, i32 %24)
%26 = call i32 @binsearch_iter(i32* %5, i32 0, i32 3, i32 4)
%27 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 4, i32 %26)
%28 = call i32 @binsearch_recur(i32* %5, i32 0, i32 3, i32 4)
%29 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 4, i32 %28)
ret i32 0
}