#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 BinarySearch(int *, int, int);
int /*<<< orphan*/ printf(char *, int);
int main(int argc, char **argv) {
  int a[10000] = {0};
  for (int i = 0; i < 10000; i++) {
    a[i] = i + 1;
  }
  int c = BinarySearch(a, 10000, -1);
  printf("index:%d\n", c);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x9c60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x9c50(%rbp),%rdi
xor    %esi,%esi
mov    $0x9c40,%edx
call   1040 <memset@plt>
movl   $0x0,-0x9c54(%rbp)
cmpl   $0x2710,-0x9c54(%rbp)
jge    11a1 <main+0x71>
mov    -0x9c54(%rbp),%ecx
add    $0x1,%ecx
movslq -0x9c54(%rbp),%rax
mov    %ecx,-0x9c50(%rbp,%rax,4)
mov    -0x9c54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c54(%rbp)
jmp    1166 <main+0x36>
lea    -0x9c50(%rbp),%rdi
mov    $0x2710,%esi
mov    $0xffffffff,%edx
call   1050 <BinarySearch@plt>
mov    %eax,-0x9c58(%rbp)
mov    -0x9c58(%rbp),%esi
lea    0xe36(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x9c60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x9c48,%rsp
mov    %rsp,%rdi
mov    $0x9c40,%edx
xor    %esi,%esi
call   1040 <memset@plt>
movaps 0xeb3(%rip),%xmm0
movaps 0xebc(%rip),%xmm1
mov    $0xc,%eax
pcmpeqd %xmm8,%xmm8
movdqa 0xeb9(%rip),%xmm9
movdqa 0xec1(%rip),%xmm4
movdqa 0xec9(%rip),%xmm5
movdqa 0xed1(%rip),%xmm6
nop
movaps %xmm1,%xmm7
shufps $0x88,%xmm0,%xmm7
movaps %xmm7,%xmm2
psubd  %xmm8,%xmm2
movaps %xmm7,%xmm3
paddd  %xmm9,%xmm3
movdqa %xmm2,-0x30(%rsp,%rax,4)
movdqa %xmm3,-0x20(%rsp,%rax,4)
movaps %xmm7,%xmm2
paddd  %xmm4,%xmm2
paddd  %xmm5,%xmm7
movdqa %xmm2,-0x10(%rsp,%rax,4)
movdqa %xmm7,(%rsp,%rax,4)
paddq  %xmm6,%xmm1
paddq  %xmm6,%xmm0
add    $0x10,%rax
cmp    $0x271c,%rax
jne    1180 <main+0x50>
mov    %rsp,%rdi
mov    $0x2710,%esi
mov    $0xffffffff,%edx
call   1050 <BinarySearch@plt>
lea    0xe7a(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x9c48,%rsp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"index:%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [10000 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 [10000 x i32]* %6 to i8*
store i32 0, i32* %7
br label %10
10: ; preds = %19, %2
%11 = load i32, i32* %7
%12 = icmp slt i32 %11, 10000
br i1 %12, label %13, label %22
13: ; preds = %10
%14 = load i32, i32* %7
%15 = add nsw i32 %14, 1
%16 = load i32, i32* %7
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [10000 x i32], [10000 x i32]* %6, i64 0, i64 %17
store i32 %15, i32* %18
br label %19
19: ; preds = %13
%20 = load i32, i32* %7
%21 = add nsw i32 %20, 1
store i32 %21, i32* %7
br label %10
22: ; preds = %10
%23 = getelementptr inbounds [10000 x i32], [10000 x i32]* %6, i64 0, i64 0
%24 = call i32 @BinarySearch(i32* %23, i32 10000, i32 -1)
store i32 %24, i32* %8
%25 = load i32, i32* %8
%26 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %25)
ret i32 0
}

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