#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 main(void) {
  int x = -1;
  int max = 10000;
  int arr[max];
  int i, k;
  for (i = 0; i < max; i++)
    arr[i] = i * 2;
  printf("Position: %d\n", binsearch2(x, arr, max));
  for (i = 0; i < 10000; i++)
    for (k = 0; k < 10000; k++)
      binsearch2(x, arr, max);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xffffffff,-0x8(%rbp)
movl   $0x2710,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1196 <main+0x76>
mov    -0x30(%rbp),%rax
mov    -0x24(%rbp),%edx
shl    $0x1,%edx
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    116b <main+0x4b>
mov    -0x30(%rbp),%rsi
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%edx
call   1040 <binsearch2@plt>
mov    %eax,%esi
lea    0xe52(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0x2710,-0x24(%rbp)
jge    120b <main+0xeb>
movl   $0x0,-0x28(%rbp)
cmpl   $0x2710,-0x28(%rbp)
jge    11f8 <main+0xd8>
mov    -0x30(%rbp),%rsi
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%edx
call   1040 <binsearch2@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11ce <main+0xae>
jmp    11fd <main+0xdd>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11ba <main+0x9a>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x9c40,%rsp
movdqa 0xecd(%rip),%xmm0
mov    $0xc,%eax
movdqa 0xed0(%rip),%xmm1
movdqa 0xed8(%rip),%xmm2
movdqa 0xee0(%rip),%xmm3
movdqa %xmm0,%xmm4
paddd  %xmm0,%xmm4
movdqa %xmm4,%xmm5
paddd  %xmm1,%xmm5
movdqa %xmm4,-0x30(%rsp,%rax,4)
movdqa %xmm5,-0x20(%rsp,%rax,4)
movdqa %xmm4,%xmm5
paddd  %xmm2,%xmm5
paddd  %xmm3,%xmm4
movdqa %xmm5,-0x10(%rsp,%rax,4)
movdqa %xmm4,(%rsp,%rax,4)
paddd  %xmm2,%xmm0
add    $0x10,%rax
cmp    $0x271c,%rax
jne    1150 <main+0x30>
mov    %rsp,%rbx
mov    $0xffffffff,%edi
mov    %rbx,%rsi
mov    $0x2710,%edx
call   1040 <binsearch2@plt>
lea    0xe91(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %r14d,%r14d
nopl   0x0(%rax)
mov    $0x2710,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0xffffffff,%edi
mov    %rbx,%rsi
mov    $0x2710,%edx
call   1040 <binsearch2@plt>
add    $0xffffffff,%ebp
jne    11d0 <main+0xb0>
add    $0x1,%r14d
cmp    $0x2710,%r14d
jne    11c0 <main+0xa0>
xor    %eax,%eax
add    $0x9c40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"Position: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
store i32 -1, i32* %2
store i32 10000, i32* %3
%8 = load i32, i32* %3
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %4
%11 = alloca i32, i64 %9
store i64 %9, i64* %5
store i32 0, i32* %6
br label %12
12: ; preds = %22, %0
%13 = load i32, i32* %6
%14 = load i32, i32* %3
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %25
16: ; preds = %12
%17 = load i32, i32* %6
%18 = mul nsw i32 %17, 2
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i32, i32* %11, i64 %20
store i32 %18, i32* %21
br label %22
22: ; preds = %16
%23 = load i32, i32* %6
%24 = add nsw i32 %23, 1
store i32 %24, i32* %6
br label %12
25: ; preds = %12
%26 = load i32, i32* %2
%27 = load i32, i32* %3
%28 = call i32 @binsearch2(i32 %26, i32* %11, i32 %27)
%29 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %28)
store i32 0, i32* %6
br label %30
30: ; preds = %45, %25
%31 = load i32, i32* %6
%32 = icmp slt i32 %31, 10000
br i1 %32, label %33, label %48
33: ; preds = %30
store i32 0, i32* %7
br label %34
34: ; preds = %41, %33
%35 = load i32, i32* %7
%36 = icmp slt i32 %35, 10000
br i1 %36, label %37, label %44
37: ; preds = %34
%38 = load i32, i32* %2
%39 = load i32, i32* %3
%40 = call i32 @binsearch2(i32 %38, i32* %11, i32 %39)
br label %41
41: ; preds = %37
%42 = load i32, i32* %7
%43 = add nsw i32 %42, 1
store i32 %43, i32* %7
br label %34
44: ; preds = %34
br label %45
45: ; preds = %44
%46 = load i32, i32* %6
%47 = add nsw i32 %46, 1
store i32 %47, i32* %6
br label %30
48: ; preds = %30
store i32 0, i32* %1
%49 = load i8*, i8** %4
%50 = load i32, i32* %1
ret i32 %50
}

LLVM IR (-O2):
@.str = [14 x i8] c"Position: %d\0A\00"
define i32 @main() {
%1 = alloca [10000 x i32]
br label %2
2: ; preds = %2, %0
%3 = phi i64 [ 0, %0 ], [ %21, %2 ]
%4 = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %0 ], [ %22, %2 ]
%5 = getelementptr inbounds [10000 x i32], [10000 x i32]* %1, i64 0, i64 %3
%6 = shl <4 x i32> %4, <i32 1, i32 1, i32 1, i32 1>
%7 = shl <4 x i32> %4, <i32 1, i32 1, i32 1, i32 1>
%8 = add <4 x i32> %7, <i32 8, i32 8, i32 8, i32 8>
%9 = bitcast i32* %5 to <4 x i32>*
store <4 x i32> %6, <4 x i32>* %9
%10 = getelementptr inbounds i32, i32* %5, i64 4
%11 = bitcast i32* %10 to <4 x i32>*
store <4 x i32> %8, <4 x i32>* %11
%12 = or i64 %3, 8
%13 = add <4 x i32> %4, <i32 8, i32 8, i32 8, i32 8>
%14 = getelementptr inbounds [10000 x i32], [10000 x i32]* %1, i64 0, i64 %12
%15 = shl <4 x i32> %13, <i32 1, i32 1, i32 1, i32 1>
%16 = shl <4 x i32> %13, <i32 1, i32 1, i32 1, i32 1>
%17 = add <4 x i32> %16, <i32 8, i32 8, i32 8, i32 8>
%18 = bitcast i32* %14 to <4 x i32>*
store <4 x i32> %15, <4 x i32>* %18
%19 = getelementptr inbounds i32, i32* %14, i64 4
%20 = bitcast i32* %19 to <4 x i32>*
store <4 x i32> %17, <4 x i32>* %20
%21 = add nuw nsw i64 %3, 16
%22 = add <4 x i32> %4, <i32 16, i32 16, i32 16, i32 16>
%23 = icmp eq i64 %21, 10000
br i1 %23, label %24, label %2
24: ; preds = %2
%25 = getelementptr inbounds [10000 x i32], [10000 x i32]* %1, i64 0, i64 0
%26 = call i32 @binsearch2(i32 -1, i32* %25, i32 10000)
%27 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %24, %35
%29 = phi i32 [ 0, %24 ], [ %36, %35 ]
br label %30
30: ; preds = %28, %30
%31 = phi i32 [ 0, %28 ], [ %33, %30 ]
%32 = call i32 @binsearch2(i32 -1, i32* %25, i32 10000)
%33 = add nuw nsw i32 %31, 1
%34 = icmp eq i32 %33, 10000
br i1 %34, label %35, label %30
35: ; preds = %30
%36 = add nuw nsw i32 %29, 1
%37 = icmp eq i32 %36, 10000
br i1 %37, label %38, label %28
38: ; preds = %35
ret i32 0
}