#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 binsearch(int, int *, int);
int binsearch2(int, int *, int);
int /*<<< orphan*/ printf(char *, int);
int main(void) {
  int x = 4;
  int n = 11;
  int v[11] = {0, 1, 4, 5, 6, 11, 16, 23, 34, 52};
  printf("Array index is %d\n", binsearch(x, v, n));
  printf("Array index is %d\n", binsearch2(x, v, n));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x4,-0x8(%rbp)
movl   $0xb,-0xc(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xe98(%rip),%rsi
mov    $0x2c,%edx
call   1060 <memcpy@plt>
mov    -0x8(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1030 <binsearch@plt>
mov    %eax,%esi
lea    0xea2(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1050 <binsearch2@plt>
mov    %eax,%esi
lea    0xe85(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x38,%rsp
movups 0xede(%rip),%xmm0
movups %xmm0,0x1c(%rsp)
movaps 0xec6(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xeaa(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%r14
mov    $0x4,%edi
mov    %r14,%rsi
mov    $0xb,%edx
call   1030 <binsearch@plt>
lea    0xeb6(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    $0x4,%edi
mov    %r14,%rsi
mov    $0xb,%edx
call   1050 <binsearch2@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.v = [11 x i32] [i32 0, i32 1, i32 4, i32 5, i32 6, i32 11, i32 16, i32 23, i32 34, i32 52, i32 0]
@.str = [19 x i8] c"Array index is %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [11 x i32]
store i32 0, i32* %1
store i32 4, i32* %2
store i32 11, i32* %3
%5 = bitcast [11 x i32]* %4 to i8*
%6 = load i32, i32* %2
%7 = getelementptr inbounds [11 x i32], [11 x i32]* %4, i64 0, i64 0
%8 = load i32, i32* %3
%9 = call i32 @binsearch(i32 %6, i32* %7, i32 %8)
%10 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = load i32, i32* %2
%12 = getelementptr inbounds [11 x i32], [11 x i32]* %4, i64 0, i64 0
%13 = load i32, i32* %3
%14 = call i32 @binsearch2(i32 %11, i32* %12, i32 %13)
%15 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %14)
ret i32 0
}

LLVM IR (-O2):
@__const.main.v = [11 x i32] [i32 0, i32 1, i32 4, i32 5, i32 6, i32 11, i32 16, i32 23, i32 34, i32 52, i32 0]
@.str = [19 x i8] c"Array index is %d\0A\00"
define i32 @main() {
%1 = alloca [11 x i32]
%2 = bitcast [11 x i32]* %1 to i8*
%3 = getelementptr inbounds [11 x i32], [11 x i32]* %1, i64 0, i64 0
%4 = call i32 @binsearch(i32 4, i32* %3, i32 11)
%5 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = call i32 @binsearch2(i32 4, i32* %3, i32 11)
%7 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %6)
ret i32 0
}