#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 */
typedef int /*<<< orphan*/ a;

/* Variables and functions */
int binSearch2(int *, int /*<<< orphan*/, int, int);
int findInInfiniteArray(int *, int);
int /*<<< orphan*/ printf(char *, int, ...);
int main(int argc, char *argv[]) {
  int a[] = {1, 2, 3, 4, 5, 6, 7, 8};
  int len = sizeof(a) / sizeof(a[0]);
  printf("array size %d\n", len);
  printf("Index of %d is %d\n", 5, binSearch2(a, 0, len, 5));
  printf("Index of %d is %d(In Infinite Array method)\n", 1,
         findInInfiniteArray(a, 1));
  printf("Index of %d is %d(In Infinite Array method)\n", 8,
         findInInfiniteArray(a, 8));
  printf("Index of %d is %d(In Infinite Array method)\n", 5,
         findInInfiniteArray(a, 5));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xeba(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xeb7(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xeb4(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xeb1(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x8,-0x34(%rbp)
mov    -0x34(%rbp),%esi
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%edx
xor    %esi,%esi
mov    $0x5,%ecx
call   1040 <binSearch2@plt>
mov    %eax,%edx
lea    0xe90(%rip),%rdi
mov    $0x5,%esi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    $0x1,%esi
call   1050 <findInInfiniteArray@plt>
mov    %eax,%edx
lea    0xe80(%rip),%rdi
mov    $0x1,%esi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    $0x8,%esi
call   1050 <findInInfiniteArray@plt>
mov    %eax,%edx
lea    0xe5d(%rip),%rdi
mov    $0x8,%esi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    $0x5,%esi
call   1050 <findInInfiniteArray@plt>
mov    %eax,%edx
lea    0xe3a(%rip),%rdi
mov    $0x5,%esi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
movaps 0xed2(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xeb6(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xecb(%rip),%rdi
mov    $0x8,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x8,%edx
mov    $0x5,%ecx
call   1040 <binSearch2@plt>
lea    0xeb0(%rip),%rdi
mov    $0x5,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14,%rdi
mov    $0x1,%esi
call   1050 <findInInfiniteArray@plt>
lea    0xea1(%rip),%rbx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14,%rdi
mov    $0x8,%esi
call   1050 <findInInfiniteArray@plt>
mov    %rbx,%rdi
mov    $0x8,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14,%rdi
mov    $0x5,%esi
call   1050 <findInInfiniteArray@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.a = [8 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8]
@.str = [15 x i8] c"array size %d\0A\00"
@.str.1 = [19 x i8] c"Index of %d is %d\0A\00"
@.str.2 = [45 x i8] c"Index of %d is %d(In Infinite Array method)\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca [8 x i32]
%6 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%7 = bitcast [8 x i32]* %5 to i8*
store i32 8, i32* %6
%8 = load i32, i32* %6
%9 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = getelementptr inbounds [8 x i32], [8 x i32]* %5, i64 0, i64 0
%11 = load i32, i32* %6
%12 = call i32 @binSearch2(i32* %10, i32 0, i32 %11, i32 5)
%13 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 5, i32 %12)
%14 = getelementptr inbounds [8 x i32], [8 x i32]* %5, i64 0, i64 0
%15 = call i32 @findInInfiniteArray(i32* %14, i32 1)
%16 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i32 1, i32 %15)
%17 = getelementptr inbounds [8 x i32], [8 x i32]* %5, i64 0, i64 0
%18 = call i32 @findInInfiniteArray(i32* %17, i32 8)
%19 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i32 8, i32 %18)
%20 = getelementptr inbounds [8 x i32], [8 x i32]* %5, i64 0, i64 0
%21 = call i32 @findInInfiniteArray(i32* %20, i32 5)
%22 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i32 5, i32 %21)
ret i32 0
}

LLVM IR (-O2):
@__const.main.a = [8 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8]
@.str = [15 x i8] c"array size %d\0A\00"
@.str.1 = [19 x i8] c"Index of %d is %d\0A\00"
@.str.2 = [45 x i8] c"Index of %d is %d(In Infinite Array method)\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [8 x i32]
%4 = bitcast [8 x i32]* %3 to i8*
%5 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 8)
%6 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 0
%7 = call i32 @binSearch2(i32* %6, i32 0, i32 8, i32 5)
%8 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 5, i32 %7)
%9 = call i32 @findInInfiniteArray(i32* %6, i32 1)
%10 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i32 1, i32 %9)
%11 = call i32 @findInInfiniteArray(i32* %6, i32 8)
%12 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i32 8, i32 %11)
%13 = call i32 @findInInfiniteArray(i32* %6, i32 5)
%14 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i32 5, i32 %13)
ret i32 0
}