#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 search(int *, int, int /*<<< orphan*/, int);
int test_large_array() {
  int array[1000000];
  for (int i = 0; i < 1000000; i++) {
    array[i] = i;
  }
  for (int i = 0; i < 1000000; i++) {
    int result = search(array, i, 0, 1000000);
    if (result != i)
      return 0;
  }
  return -1 == search(array, 1000000, 0, 1000000) &&
         -1 == search(array, -1, 0, 1000000);
}


x86 assembly (clang, -O0):
<test_large_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x3d0920,%rsp
movl   $0x0,-0x3d0914(%rbp)
cmpl   $0xf4240,-0x3d0914(%rbp)
jge    115d <test_large_array+0x4d>
mov    -0x3d0914(%rbp),%ecx
movslq -0x3d0914(%rbp),%rax
mov    %ecx,-0x3d0910(%rbp,%rax,4)
mov    -0x3d0914(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3d0914(%rbp)
jmp    1125 <test_large_array+0x15>
movl   $0x0,-0x3d0918(%rbp)
cmpl   $0xf4240,-0x3d0918(%rbp)
jge    11cd <test_large_array+0xbd>
lea    -0x3d0910(%rbp),%rdi
mov    -0x3d0918(%rbp),%esi
xor    %edx,%edx
mov    $0xf4240,%ecx
call   1030 <search@plt>
mov    %eax,-0x3d091c(%rbp)
mov    -0x3d091c(%rbp),%eax
cmp    -0x3d0918(%rbp),%eax
je     11b4 <test_large_array+0xa4>
movl   $0x0,-0x4(%rbp)
jmp    1231 <test_large_array+0x121>
jmp    11b9 <test_large_array+0xa9>
mov    -0x3d0918(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3d0918(%rbp)
jmp    1167 <test_large_array+0x57>
lea    -0x3d0910(%rbp),%rdi
mov    $0xf4240,%ecx
xor    %edx,%edx
mov    %ecx,%esi
call   1030 <search@plt>
mov    %eax,%edx
xor    %eax,%eax
mov    $0xffffffff,%ecx
cmp    %edx,%ecx
mov    %al,-0x3d091d(%rbp)
jne    1223 <test_large_array+0x113>
lea    -0x3d0910(%rbp),%rdi
mov    $0xffffffff,%esi
xor    %edx,%edx
mov    $0xf4240,%ecx
call   1030 <search@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
sete   %al
mov    %al,-0x3d091d(%rbp)
mov    -0x3d091d(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x3d0920,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_large_array>:
push   %rbp
push   %r14
push   %rbx
sub    $0x3d0900,%rsp
movdqa 0xedd(%rip),%xmm0
mov    $0x24,%eax
movdqa 0xedf(%rip),%xmm8
movdqa 0xee6(%rip),%xmm9
movdqa 0xeed(%rip),%xmm10
movdqa 0xef4(%rip),%xmm11
movdqa 0xefb(%rip),%xmm12
movdqa 0xf03(%rip),%xmm6
movdqa 0xf0b(%rip),%xmm7
movdqa 0xf13(%rip),%xmm1
movdqa 0xf1b(%rip),%xmm2
movdqa 0xf23(%rip),%xmm3
nopl   (%rax)
movdqa %xmm0,%xmm4
paddd  %xmm8,%xmm4
movdqa %xmm0,-0x90(%rsp,%rax,4)
ff ff
movdqa %xmm4,-0x80(%rsp,%rax,4)
movdqa %xmm0,%xmm4
paddd  %xmm9,%xmm4
movdqa %xmm0,%xmm5
paddd  %xmm10,%xmm5
movdqa %xmm4,-0x70(%rsp,%rax,4)
movdqa %xmm5,-0x60(%rsp,%rax,4)
movdqa %xmm0,%xmm4
paddd  %xmm11,%xmm4
movdqa %xmm0,%xmm5
paddd  %xmm12,%xmm5
movdqa %xmm4,-0x50(%rsp,%rax,4)
movdqa %xmm5,-0x40(%rsp,%rax,4)
movdqa %xmm0,%xmm4
paddd  %xmm6,%xmm4
movdqa %xmm0,%xmm5
paddd  %xmm7,%xmm5
movdqa %xmm4,-0x30(%rsp,%rax,4)
movdqa %xmm5,-0x20(%rsp,%rax,4)
movdqa %xmm0,%xmm4
paddd  %xmm1,%xmm4
movdqa %xmm0,%xmm5
paddd  %xmm2,%xmm5
movdqa %xmm4,-0x10(%rsp,%rax,4)
movdqa %xmm5,(%rsp,%rax,4)
paddd  %xmm3,%xmm0
add    $0x28,%rax
cmp    $0xf4264,%rax
jne    1180 <test_large_array+0x70>
xor    %r14d,%r14d
mov    %rsp,%rbx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %edx,%edx
mov    $0xf4240,%ecx
call   1030 <search@plt>
cmp    %eax,%ebp
jne    128a <test_large_array+0x17a>
add    $0x1,%ebp
cmp    $0xf4240,%ebp
jne    1230 <test_large_array+0x120>
mov    %rsp,%rdi
xor    %r14d,%r14d
mov    $0xf4240,%esi
xor    %edx,%edx
mov    $0xf4240,%ecx
call   1030 <search@plt>
cmp    $0xffffffff,%eax
jne    128a <test_large_array+0x17a>
mov    %rsp,%rdi
mov    $0xffffffff,%esi
xor    %edx,%edx
mov    $0xf4240,%ecx
call   1030 <search@plt>
xor    %r14d,%r14d
cmp    $0xffffffff,%eax
sete   %r14b
mov    %r14d,%eax
add    $0x3d0900,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @test_large_array() {
%1 = alloca i32
%2 = alloca [1000000 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %3
br label %6
6: ; preds = %14, %0
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 1000000
br i1 %8, label %9, label %17
9: ; preds = %6
%10 = load i32, i32* %3
%11 = load i32, i32* %3
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %2, i64 0, i64 %12
store i32 %10, i32* %13
br label %14
14: ; preds = %9
%15 = load i32, i32* %3
%16 = add nsw i32 %15, 1
store i32 %16, i32* %3
br label %6
17: ; preds = %6
store i32 0, i32* %4
br label %18
18: ; preds = %30, %17
%19 = load i32, i32* %4
%20 = icmp slt i32 %19, 1000000
br i1 %20, label %21, label %33
21: ; preds = %18
%22 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %2, i64 0, i64 0
%23 = load i32, i32* %4
%24 = call i32 @search(i32* %22, i32 %23, i32 0, i32 1000000)
store i32 %24, i32* %5
%25 = load i32, i32* %5
%26 = load i32, i32* %4
%27 = icmp ne i32 %25, %26
br i1 %27, label %28, label %29
28: ; preds = %21
store i32 0, i32* %1
br label %44
29: ; preds = %21
br label %30
30: ; preds = %29
%31 = load i32, i32* %4
%32 = add nsw i32 %31, 1
store i32 %32, i32* %4
br label %18
33: ; preds = %18
%34 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %2, i64 0, i64 0
%35 = call i32 @search(i32* %34, i32 1000000, i32 0, i32 1000000)
%36 = icmp eq i32 -1, %35
br i1 %36, label %37, label %41
37: ; preds = %33
%38 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %2, i64 0, i64 0
%39 = call i32 @search(i32* %38, i32 -1, i32 0, i32 1000000)
%40 = icmp eq i32 -1, %39
br label %41
41: ; preds = %37, %33
%42 = phi i1 [ false, %33 ], [ %40, %37 ]
%43 = zext i1 %42 to i32
store i32 %43, i32* %1
br label %44
44: ; preds = %41, %28
%45 = load i32, i32* %1
ret i32 %45
}

LLVM IR (-O2):
define i32 @test_large_array() {
%1 = alloca [1000000 x i32]
%2 = bitcast [1000000 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 [1000000 x i32], [1000000 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 [1000000 x i32], [1000000 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 [1000000 x i32], [1000000 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 [1000000 x i32], [1000000 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 [1000000 x i32], [1000000 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, 1000000
br i1 %41, label %42, label %3
42: ; preds = %3
%43 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %1, i64 0, i64 0
br label %47
44: ; preds = %47
%45 = add nuw nsw i32 %48, 1
%46 = icmp eq i32 %45, 1000000
br i1 %46, label %51, label %47
47: ; preds = %42, %44
%48 = phi i32 [ 0, %42 ], [ %45, %44 ]
%49 = call i32 @search(i32* %43, i32 %48, i32 0, i32 1000000)
%50 = icmp eq i32 %49, %48
br i1 %50, label %44, label %58
51: ; preds = %44
%52 = call i32 @search(i32* %43, i32 1000000, i32 0, i32 1000000)
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %58
54: ; preds = %51
%55 = call i32 @search(i32* %43, i32 -1, i32 0, i32 1000000)
%56 = icmp eq i32 %55, -1
%57 = zext i1 %56 to i32
br label %58
58: ; preds = %47, %51, %54
%59 = phi i32 [ 0, %51 ], [ %57, %54 ], [ 0, %47 ]
ret i32 %59
}