#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 binsearch2(int, int *, int);
int /*<<< orphan*/ printf(char *, int, int);
int main() {
  int foo[5] = {1, 2, 3, 5, 6};
  int i;
  for (i = 1; i < 7; i++) {
    printf("binsearch2 for %d is %d\n", i, binsearch2(i, foo, 5));
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeca(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xec7(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xec5(%rip),%eax
mov    %eax,-0x10(%rbp)
movl   $0x1,-0x24(%rbp)
cmpl   $0x7,-0x24(%rbp)
jge    1195 <main+0x75>
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x5,%edx
call   1040 <binsearch2@plt>
mov    -0x28(%rbp),%esi
mov    %eax,%edx
lea    0xe92(%rip),%rdi
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1155 <main+0x35>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0xee3(%rip),%eax
mov    %eax,0x10(%rsp)
movaps 0xec8(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%r14
mov    $0x1,%edi
mov    %r14,%rsi
mov    $0x5,%edx
call   1040 <binsearch2@plt>
lea    0xebc(%rip),%rbx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %eax,%edx
call   1030 <printf@plt>
mov    $0x2,%edi
mov    %r14,%rsi
mov    $0x5,%edx
call   1040 <binsearch2@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
mov    %eax,%edx
call   1030 <printf@plt>
mov    $0x3,%edi
mov    %r14,%rsi
mov    $0x5,%edx
call   1040 <binsearch2@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
mov    %eax,%edx
call   1030 <printf@plt>
mov    $0x4,%edi
mov    %r14,%rsi
mov    $0x5,%edx
call   1040 <binsearch2@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
mov    %eax,%edx
call   1030 <printf@plt>
mov    $0x5,%edi
mov    %r14,%rsi
mov    $0x5,%edx
call   1040 <binsearch2@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
mov    %eax,%edx
call   1030 <printf@plt>
mov    $0x6,%edi
mov    %r14,%rsi
mov    $0x5,%edx
call   1040 <binsearch2@plt>
mov    %rbx,%rdi
mov    $0x6,%esi
mov    %eax,%edx
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.foo = [5 x i32] [i32 1, i32 2, i32 3, i32 5, i32 6]
@.str = [25 x i8] c"binsearch2 for %d is %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [5 x i32]
%3 = alloca i32
store i32 0, i32* %1
%4 = bitcast [5 x i32]* %2 to i8*
store i32 1, i32* %3
br label %5
5: ; preds = %14, %0
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 7
br i1 %7, label %8, label %17
8: ; preds = %5
%9 = load i32, i32* %3
%10 = load i32, i32* %3
%11 = getelementptr inbounds [5 x i32], [5 x i32]* %2, i64 0, i64 0
%12 = call i32 @binsearch2(i32 %10, i32* %11, i32 5)
%13 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %12)
br label %14
14: ; preds = %8
%15 = load i32, i32* %3
%16 = add nsw i32 %15, 1
store i32 %16, i32* %3
br label %5
17: ; preds = %5
%18 = load i32, i32* %1
ret i32 %18
}

LLVM IR (-O2):
@__const.main.foo = [5 x i32] [i32 1, i32 2, i32 3, i32 5, i32 6]
@.str = [25 x i8] c"binsearch2 for %d is %d\0A\00"
define i32 @main() {
%1 = alloca [5 x i32]
%2 = bitcast [5 x i32]* %1 to i8*
%3 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 0
%4 = call i32 @binsearch2(i32 1, i32* %3, i32 5)
%5 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 1, i32 %4)
%6 = call i32 @binsearch2(i32 2, i32* %3, i32 5)
%7 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 2, i32 %6)
%8 = call i32 @binsearch2(i32 3, i32* %3, i32 5)
%9 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 3, i32 %8)
%10 = call i32 @binsearch2(i32 4, i32* %3, i32 5)
%11 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 4, i32 %10)
%12 = call i32 @binsearch2(i32 5, i32* %3, i32 5)
%13 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 5, i32 %12)
%14 = call i32 @binsearch2(i32 6, i32* %3, i32 5)
%15 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 6, i32 %14)
ret i32 0
}