#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 /*<<< orphan*/ binarySearch(int *, int, int);
int /*<<< orphan*/ free(int *);
int *malloc(int);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  size_t i = 0;
  int NUM_LOOKUPS = 1024 * 512 * 16;
  int *array;
  int *lookups;
  srand(time(NULL));
  array = malloc(1024 * 512 * 16 * sizeof(int));
  lookups = malloc(NUM_LOOKUPS * sizeof(int));
  for (i = 0; i < 1024 * 512 * 16; i++)
    array[i] = i;
  for (i = 0; i < NUM_LOOKUPS; i++)
    lookups[i] = rand() % 1024 * 512 * 16;
  for (i = 0; i < NUM_LOOKUPS; i++)
    binarySearch(array, 1024 * 512 * 16, lookups[i]);
  free(array);
  free(lookups);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0x800000,-0x14(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    $0x2000000,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x10(%rbp)
cmpq   $0x800000,-0x10(%rbp)
jae    11e7 <main+0x87>
mov    -0x10(%rbp),%rax
mov    %eax,%edx
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11b7 <main+0x57>
movq   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmp    %rcx,%rax
jae    1231 <main+0xd1>
mov    $0x0,%al
call   1080 <rand@plt>
mov    $0x400,%ecx
cltd
idiv   %ecx
shl    $0x9,%edx
shl    $0x4,%edx
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11ef <main+0x8f>
movq   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmp    %rcx,%rax
jae    1274 <main+0x114>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    $0x800000,%esi
call   1060 <binarySearch@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1239 <main+0xd9>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    $0x2000000,%edi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    $0x2000000,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
movdqa 0xe6b(%rip),%xmm0
mov    $0x1c,%eax
movdqa 0xe6d(%rip),%xmm8
movdqa 0xe74(%rip),%xmm9
movdqa 0xe7b(%rip),%xmm10
movdqa 0xe83(%rip),%xmm4
movdqa 0xe8b(%rip),%xmm5
movdqa 0xe93(%rip),%xmm6
movdqa 0xe9b(%rip),%xmm7
movdqa 0xea3(%rip),%xmm1
nopl   (%rax)
movdqa %xmm0,%xmm2
paddd  %xmm8,%xmm2
movdqu %xmm0,-0x70(%r15,%rax,4)
movdqu %xmm2,-0x60(%r15,%rax,4)
movdqa %xmm0,%xmm2
paddd  %xmm9,%xmm2
movdqa %xmm0,%xmm3
paddd  %xmm10,%xmm3
movdqu %xmm2,-0x50(%r15,%rax,4)
movdqu %xmm3,-0x40(%r15,%rax,4)
movdqa %xmm0,%xmm2
paddd  %xmm4,%xmm2
movdqa %xmm0,%xmm3
paddd  %xmm5,%xmm3
movdqu %xmm2,-0x30(%r15,%rax,4)
movdqu %xmm3,-0x20(%r15,%rax,4)
movdqa %xmm0,%xmm2
paddd  %xmm6,%xmm2
movdqa %xmm0,%xmm3
paddd  %xmm7,%xmm3
movdqu %xmm2,-0x10(%r15,%rax,4)
movdqu %xmm3,(%r15,%rax,4)
paddd  %xmm1,%xmm0
add    $0x20,%rax
cmp    $0x80001c,%rax
jne    11e0 <main+0x80>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1080 <rand@plt>
lea    0x3ff(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0x7fc00,%ecx
sub    %ecx,%eax
shl    $0xd,%eax
mov    %eax,(%r14,%rbx,4)
add    $0x1,%rbx
cmp    $0x800000,%rbx
jne    1270 <main+0x110>
xor    %ebx,%ebx
mov    (%r14,%rbx,4),%edx
mov    %r15,%rdi
mov    $0x800000,%esi
call   1060 <binarySearch@plt>
add    $0x1,%rbx
cmp    $0x800000,%rbx
jne    12a0 <main+0x140>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
store i32 0, i32* %1
store i64 0, i64* %2
store i32 8388608, i32* %3
%6 = call i32 @time(i32* null)
%7 = call i32 @srand(i32 %6)
%8 = call i32* @malloc(i32 33554432)
store i32* %8, i32** %4
%9 = load i32, i32* %3
%10 = sext i32 %9 to i64
%11 = mul i64 %10, 4
%12 = trunc i64 %11 to i32
%13 = call i32* @malloc(i32 %12)
store i32* %13, i32** %5
store i64 0, i64* %2
br label %14
14: ; preds = %23, %0
%15 = load i64, i64* %2
%16 = icmp ult i64 %15, 8388608
br i1 %16, label %17, label %26
17: ; preds = %14
%18 = load i64, i64* %2
%19 = trunc i64 %18 to i32
%20 = load i32*, i32** %4
%21 = load i64, i64* %2
%22 = getelementptr inbounds i32, i32* %20, i64 %21
store i32 %19, i32* %22
br label %23
23: ; preds = %17
%24 = load i64, i64* %2
%25 = add i64 %24, 1
store i64 %25, i64* %2
br label %14
26: ; preds = %14
store i64 0, i64* %2
br label %27
27: ; preds = %40, %26
%28 = load i64, i64* %2
%29 = load i32, i32* %3
%30 = sext i32 %29 to i64
%31 = icmp ult i64 %28, %30
br i1 %31, label %32, label %43
32: ; preds = %27
%33 = call i32 (...) @rand()
%34 = srem i32 %33, 1024
%35 = mul nsw i32 %34, 512
%36 = mul nsw i32 %35, 16
%37 = load i32*, i32** %5
%38 = load i64, i64* %2
%39 = getelementptr inbounds i32, i32* %37, i64 %38
store i32 %36, i32* %39
br label %40
40: ; preds = %32
%41 = load i64, i64* %2
%42 = add i64 %41, 1
store i64 %42, i64* %2
br label %27
43: ; preds = %27
store i64 0, i64* %2
br label %44
44: ; preds = %56, %43
%45 = load i64, i64* %2
%46 = load i32, i32* %3
%47 = sext i32 %46 to i64
%48 = icmp ult i64 %45, %47
br i1 %48, label %49, label %59
49: ; preds = %44
%50 = load i32*, i32** %4
%51 = load i32*, i32** %5
%52 = load i64, i64* %2
%53 = getelementptr inbounds i32, i32* %51, i64 %52
%54 = load i32, i32* %53
%55 = call i32 @binarySearch(i32* %50, i32 8388608, i32 %54)
br label %56
56: ; preds = %49
%57 = load i64, i64* %2
%58 = add i64 %57, 1
store i64 %58, i64* %2
br label %44
59: ; preds = %44
%60 = load i32*, i32** %4
%61 = call i32 @free(i32* %60)
%62 = load i32*, i32** %5
%63 = call i32 @free(i32* %62)
%64 = load i32, i32* %1
ret i32 %64
}

LLVM IR (-O2):
define i32 @main() {
%1 = tail call i32 @time(i32* null)
%2 = tail call i32 @srand(i32 %1)
%3 = tail call i32* @malloc(i32 33554432)
%4 = tail call i32* @malloc(i32 33554432)
br label %5
5: ; preds = %5, %0
%6 = phi i64 [ 0, %0 ], [ %34, %5 ]
%7 = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %0 ], [ %35, %5 ]
%8 = add <4 x i32> %7, <i32 4, i32 4, i32 4, i32 4>
%9 = getelementptr inbounds i32, i32* %3, i64 %6
%10 = bitcast i32* %9 to <4 x i32>*
store <4 x i32> %7, <4 x i32>* %10
%11 = getelementptr inbounds i32, i32* %9, i64 4
%12 = bitcast i32* %11 to <4 x i32>*
store <4 x i32> %8, <4 x i32>* %12
%13 = or i64 %6, 8
%14 = add <4 x i32> %7, <i32 8, i32 8, i32 8, i32 8>
%15 = add <4 x i32> %7, <i32 12, i32 12, i32 12, i32 12>
%16 = getelementptr inbounds i32, i32* %3, i64 %13
%17 = bitcast i32* %16 to <4 x i32>*
store <4 x i32> %14, <4 x i32>* %17
%18 = getelementptr inbounds i32, i32* %16, i64 4
%19 = bitcast i32* %18 to <4 x i32>*
store <4 x i32> %15, <4 x i32>* %19
%20 = or i64 %6, 16
%21 = add <4 x i32> %7, <i32 16, i32 16, i32 16, i32 16>
%22 = add <4 x i32> %7, <i32 20, i32 20, i32 20, i32 20>
%23 = getelementptr inbounds i32, i32* %3, i64 %20
%24 = bitcast i32* %23 to <4 x i32>*
store <4 x i32> %21, <4 x i32>* %24
%25 = getelementptr inbounds i32, i32* %23, i64 4
%26 = bitcast i32* %25 to <4 x i32>*
store <4 x i32> %22, <4 x i32>* %26
%27 = or i64 %6, 24
%28 = add <4 x i32> %7, <i32 24, i32 24, i32 24, i32 24>
%29 = add <4 x i32> %7, <i32 28, i32 28, i32 28, i32 28>
%30 = getelementptr inbounds i32, i32* %3, i64 %27
%31 = bitcast i32* %30 to <4 x i32>*
store <4 x i32> %28, <4 x i32>* %31
%32 = getelementptr inbounds i32, i32* %30, i64 4
%33 = bitcast i32* %32 to <4 x i32>*
store <4 x i32> %29, <4 x i32>* %33
%34 = add nuw nsw i64 %6, 32
%35 = add <4 x i32> %7, <i32 32, i32 32, i32 32, i32 32>
%36 = icmp eq i64 %34, 8388608
br i1 %36, label %37, label %5
37: ; preds = %5, %37
%38 = phi i64 [ %43, %37 ], [ 0, %5 ]
%39 = tail call i32 (...) @rand()
%40 = srem i32 %39, 1024
%41 = shl nsw i32 %40, 13
%42 = getelementptr inbounds i32, i32* %4, i64 %38
store i32 %41, i32* %42
%43 = add nuw nsw i64 %38, 1
%44 = icmp eq i64 %43, 8388608
br i1 %44, label %45, label %37
45: ; preds = %37, %45
%46 = phi i64 [ %50, %45 ], [ 0, %37 ]
%47 = getelementptr inbounds i32, i32* %4, i64 %46
%48 = load i32, i32* %47
%49 = tail call i32 @binarySearch(i32* %3, i32 8388608, i32 %48)
%50 = add nuw nsw i64 %46, 1
%51 = icmp eq i64 %50, 8388608
br i1 %51, label %52, label %45
52: ; preds = %45
%53 = tail call i32 @free(i32* %3)
%54 = tail call i32 @free(i32* %4)
ret i32 0
}