#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, ...);
void main() {
  int c, pos;
  int data[1000];
  int i;
  int toFind[4] = {36, 457, 913, 1906};
  for (i = 0; i < 1000; i++)
    data[i] = i;
  for (c = 0; c < 4; c++)
    if ((pos = binSearch2(toFind[c], data, 1000)) == -1)
      printf("%d not found\n", toFind[c]);
    else
      printf("%d found at pos %d\n", toFind[c], pos);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xfd0,%rsp
mov    0xece(%rip),%rax
mov    %rax,-0xfd0(%rbp)
mov    0xec8(%rip),%rax
mov    %rax,-0xfc8(%rbp)
movl   $0x0,-0xfb4(%rbp)
cmpl   $0x3e8,-0xfb4(%rbp)
jge    1189 <main+0x69>
mov    -0xfb4(%rbp),%ecx
movslq -0xfb4(%rbp),%rax
mov    %ecx,-0xfb0(%rbp,%rax,4)
mov    -0xfb4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xfb4(%rbp)
jmp    1151 <main+0x31>
movl   $0x0,-0x4(%rbp)
cmpl   $0x4,-0x4(%rbp)
jge    120f <main+0xef>
movslq -0x4(%rbp),%rax
mov    -0xfd0(%rbp,%rax,4),%edi
lea    -0xfb0(%rbp),%rsi
mov    $0x3e8,%edx
call   1040 <binSearch2@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    11e0 <main+0xc0>
movslq -0x4(%rbp),%rax
mov    -0xfd0(%rbp,%rax,4),%esi
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11fc <main+0xdc>
movslq -0x4(%rbp),%rax
mov    -0xfd0(%rbp,%rax,4),%esi
mov    -0x8(%rbp),%edx
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1201 <main+0xe1>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1190 <main+0x70>
add    $0xfd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0xfa8,%rsp
movdqa 0xed1(%rip),%xmm0
xor    %eax,%eax
movdqa 0xed6(%rip),%xmm8
movdqa 0xedd(%rip),%xmm9
movdqa 0xee4(%rip),%xmm10
movdqa 0xeeb(%rip),%xmm11
movdqa 0xef2(%rip),%xmm12
movdqa 0xefa(%rip),%xmm6
movdqa 0xf02(%rip),%xmm7
movdqa 0xf0a(%rip),%xmm1
movdqa 0xf12(%rip),%xmm2
movdqa 0xf1a(%rip),%xmm3
cs nopw 0x0(%rax,%rax,1)
movdqa %xmm0,%xmm4
paddd  %xmm8,%xmm4
movdqa %xmm0,(%rsp,%rax,4)
movdqa %xmm4,0x10(%rsp,%rax,4)
movdqa %xmm0,%xmm4
paddd  %xmm9,%xmm4
movdqa %xmm0,%xmm5
paddd  %xmm10,%xmm5
movdqa %xmm4,0x20(%rsp,%rax,4)
movdqa %xmm5,0x30(%rsp,%rax,4)
movdqa %xmm0,%xmm4
paddd  %xmm11,%xmm4
movdqa %xmm0,%xmm5
paddd  %xmm12,%xmm5
movdqa %xmm4,0x40(%rsp,%rax,4)
movdqa %xmm5,0x50(%rsp,%rax,4)
movdqa %xmm0,%xmm4
paddd  %xmm6,%xmm4
movdqa %xmm0,%xmm5
paddd  %xmm7,%xmm5
movdqa %xmm4,0x60(%rsp,%rax,4)
movdqa %xmm5,0x70(%rsp,%rax,4)
movdqa %xmm0,%xmm4
paddd  %xmm1,%xmm4
movdqa %xmm0,%xmm5
paddd  %xmm2,%xmm5
movdqa %xmm4,0x80(%rsp,%rax,4)
movdqa %xmm5,0x90(%rsp,%rax,4)
add    $0x28,%rax
paddd  %xmm3,%xmm0
cmp    $0x3e8,%rax
jne    1190 <main+0x70>
mov    %rsp,%rsi
mov    $0x24,%edi
mov    $0x3e8,%edx
call   1040 <binSearch2@plt>
cmp    $0xffffffff,%eax
je     1260 <main+0x140>
lea    0xe6e(%rip),%rdi
mov    $0x24,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1273 <main+0x153>
lea    0xe49(%rip),%rdi
mov    $0x24,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rsp,%rsi
mov    $0x1c9,%edi
mov    $0x3e8,%edx
call   1040 <binSearch2@plt>
cmp    $0xffffffff,%eax
je     12a1 <main+0x181>
lea    0xe2d(%rip),%rdi
mov    $0x1c9,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    12b4 <main+0x194>
lea    0xe08(%rip),%rdi
mov    $0x1c9,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rsp,%rsi
mov    $0x391,%edi
mov    $0x3e8,%edx
call   1040 <binSearch2@plt>
cmp    $0xffffffff,%eax
je     12e2 <main+0x1c2>
lea    0xdec(%rip),%rdi
mov    $0x391,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    12f5 <main+0x1d5>
lea    0xdc7(%rip),%rdi
mov    $0x391,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rsp,%rsi
mov    $0x772,%edi
mov    $0x3e8,%edx
call   1040 <binSearch2@plt>
cmp    $0xffffffff,%eax
je     1329 <main+0x209>
lea    0xdab(%rip),%rdi
mov    $0x772,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
add    $0xfa8,%rsp
ret
lea    0xd80(%rip),%rdi
mov    $0x772,%esi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0xfa8,%rsp
ret

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

LLVM IR (-O2):
@.str = [14 x i8] c"%d not found\0A\00"
@.str.1 = [20 x i8] c"%d found at pos %d\0A\00"
define void @main() {
%1 = alloca [1000 x i32]
%2 = bitcast [1000 x i32]* %1 to i8*
br label %3
3: ; preds = %3, %0
%4 = phi i64 [ 0, %0 ], [ %39, %3 ]
%5 = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %0 ], [ %40, %3 ]
%6 = add <4 x i32> %5, <i32 4, i32 4, i32 4, i32 4>
%7 = getelementptr inbounds [1000 x i32], [1000 x i32]* %1, i64 0, i64 %4
%8 = bitcast i32* %7 to <4 x i32>*
store <4 x i32> %5, <4 x i32>* %8
%9 = getelementptr inbounds i32, i32* %7, i64 4
%10 = bitcast i32* %9 to <4 x i32>*
store <4 x i32> %6, <4 x i32>* %10
%11 = add nuw nsw i64 %4, 8
%12 = add <4 x i32> %5, <i32 8, i32 8, i32 8, i32 8>
%13 = add <4 x i32> %5, <i32 12, i32 12, i32 12, i32 12>
%14 = getelementptr inbounds [1000 x i32], [1000 x i32]* %1, i64 0, i64 %11
%15 = bitcast i32* %14 to <4 x i32>*
store <4 x i32> %12, <4 x i32>* %15
%16 = getelementptr inbounds i32, i32* %14, i64 4
%17 = bitcast i32* %16 to <4 x i32>*
store <4 x i32> %13, <4 x i32>* %17
%18 = add nuw nsw i64 %4, 16
%19 = add <4 x i32> %5, <i32 16, i32 16, i32 16, i32 16>
%20 = add <4 x i32> %5, <i32 20, i32 20, i32 20, i32 20>
%21 = getelementptr inbounds [1000 x i32], [1000 x i32]* %1, i64 0, i64 %18
%22 = bitcast i32* %21 to <4 x i32>*
store <4 x i32> %19, <4 x i32>* %22
%23 = getelementptr inbounds i32, i32* %21, i64 4
%24 = bitcast i32* %23 to <4 x i32>*
store <4 x i32> %20, <4 x i32>* %24
%25 = add nuw nsw i64 %4, 24
%26 = add <4 x i32> %5, <i32 24, i32 24, i32 24, i32 24>
%27 = add <4 x i32> %5, <i32 28, i32 28, i32 28, i32 28>
%28 = getelementptr inbounds [1000 x i32], [1000 x i32]* %1, i64 0, i64 %25
%29 = bitcast i32* %28 to <4 x i32>*
store <4 x i32> %26, <4 x i32>* %29
%30 = getelementptr inbounds i32, i32* %28, i64 4
%31 = bitcast i32* %30 to <4 x i32>*
store <4 x i32> %27, <4 x i32>* %31
%32 = add nuw nsw i64 %4, 32
%33 = add <4 x i32> %5, <i32 32, i32 32, i32 32, i32 32>
%34 = add <4 x i32> %5, <i32 36, i32 36, i32 36, i32 36>
%35 = getelementptr inbounds [1000 x i32], [1000 x i32]* %1, i64 0, i64 %32
%36 = bitcast i32* %35 to <4 x i32>*
store <4 x i32> %33, <4 x i32>* %36
%37 = getelementptr inbounds i32, i32* %35, i64 4
%38 = bitcast i32* %37 to <4 x i32>*
store <4 x i32> %34, <4 x i32>* %38
%39 = add nuw nsw i64 %4, 40
%40 = add <4 x i32> %5, <i32 40, i32 40, i32 40, i32 40>
%41 = icmp eq i64 %39, 1000
br i1 %41, label %42, label %3
42: ; preds = %3
%43 = getelementptr inbounds [1000 x i32], [1000 x i32]* %1, i64 0, i64 0
%44 = call i32 @binSearch2(i32 36, i32* %43, i32 1000)
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %48
46: ; preds = %42
%47 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 36)
br label %50
48: ; preds = %42
%49 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 36, i32 %44)
br label %50
50: ; preds = %46, %48
%51 = call i32 @binSearch2(i32 457, i32* %43, i32 1000)
%52 = icmp eq i32 %51, -1
br i1 %52, label %55, label %53
53: ; preds = %50
%54 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 457, i32 %51)
br label %57
55: ; preds = %50
%56 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 457)
br label %57
57: ; preds = %55, %53
%58 = call i32 @binSearch2(i32 913, i32* %43, i32 1000)
%59 = icmp eq i32 %58, -1
br i1 %59, label %62, label %60
60: ; preds = %57
%61 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 913, i32 %58)
br label %64
62: ; preds = %57
%63 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 913)
br label %64
64: ; preds = %62, %60
%65 = call i32 @binSearch2(i32 1906, i32* %43, i32 1000)
%66 = icmp eq i32 %65, -1
br i1 %66, label %69, label %67
67: ; preds = %64
%68 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 1906, i32 %65)
br label %71
69: ; preds = %64
%70 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 1906)
br label %71
71: ; preds = %69, %67
ret void
}