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

/* Variables and functions */
int binsearch(int, int *, int);
int /*<<< orphan*/ printf(char *, int, int);
int main(void) {
  int test[] = {1, 3, 5, 7, 9, 11, 13};
  int i;
  for (i = (sizeof(test) / sizeof(int)) - 1; i >= 0; --i)
    printf("looking for %d. Index=%d\n", test[i],
           binsearch(test[i], test, sizeof(test) / sizeof(*test)));
  return 0;
}


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    0xec4(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0xec2(%rip),%eax
mov    %eax,-0x8(%rbp)
movl   $0x6,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jl     11aa <main+0x8a>
movslq -0x24(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%eax
mov    %eax,-0x28(%rbp)
movslq -0x24(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%edi
lea    -0x20(%rbp),%rsi
mov    $0x7,%edx
call   1030 <binsearch@plt>
mov    -0x28(%rbp),%esi
mov    %eax,%edx
lea    0xe85(%rip),%rdi
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    1160 <main+0x40>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
movups 0xedd(%rip),%xmm0
movups %xmm0,0xc(%rsp)
movaps 0xec5(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%r14
mov    $0xd,%edi
mov    %r14,%rsi
mov    $0x7,%edx
call   1030 <binsearch@plt>
lea    0xec1(%rip),%rbx
mov    %rbx,%rdi
mov    $0xd,%esi
mov    %eax,%edx
call   1040 <printf@plt>
mov    0x14(%rsp),%ebp
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x7,%edx
call   1030 <binsearch@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %eax,%edx
call   1040 <printf@plt>
mov    0x10(%rsp),%ebp
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x7,%edx
call   1030 <binsearch@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %eax,%edx
call   1040 <printf@plt>
mov    0xc(%rsp),%ebp
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x7,%edx
call   1030 <binsearch@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %eax,%edx
call   1040 <printf@plt>
mov    0x8(%rsp),%ebp
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x7,%edx
call   1030 <binsearch@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %eax,%edx
call   1040 <printf@plt>
mov    0x4(%rsp),%ebp
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x7,%edx
call   1030 <binsearch@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %eax,%edx
call   1040 <printf@plt>
mov    (%rsp),%ebp
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x7,%edx
call   1030 <binsearch@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %eax,%edx
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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