#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 binsearchA(int, int *, int);
int binsearchB(int, int *, int);
int /*<<< orphan*/ printf(char *, int, int, int);
int main(void) {
  int e, maxe = 10;
  int v[maxe + 1];
  for (e = 0; e < maxe; ++e) {
    v[e] = e;
  }
  v[5] = v[6];
  for (e = 0; e <= maxe; ++e) {
    printf("binsearchA (%d, v, %d) = %d\n", e, maxe, binsearchA(e, v, maxe));
    printf("binsearchB (%d, v, %d) = %d\n\n", e, maxe, binsearchB(e, v, maxe));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xa,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    119f <main+0x6f>
mov    -0x28(%rbp),%rax
mov    -0x8(%rbp),%edx
movslq -0x8(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1177 <main+0x47>
mov    -0x28(%rbp),%rax
mov    0x18(%rax),%ecx
mov    %ecx,0x14(%rax)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     1228 <main+0xf8>
mov    -0x28(%rbp),%rsi
mov    -0x8(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%edx
call   1050 <binsearchA@plt>
mov    -0x38(%rbp),%esi
mov    -0x34(%rbp),%edx
mov    %eax,%ecx
lea    0xe1a(%rip),%rdi
call   1030 <printf@plt>
mov    -0x28(%rbp),%rsi
mov    -0x8(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%edx
call   1040 <binsearchB@plt>
mov    -0x30(%rbp),%esi
mov    -0x2c(%rbp),%edx
mov    %eax,%ecx
lea    0xe08(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11b0 <main+0x80>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x38,%rsp
movaps 0xebe(%rip),%xmm0
movaps %xmm0,(%rsp)
movabs $0x900000008,%rax
mov    %rax,0x20(%rsp)
movaps 0xeb4(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
xor    %ebx,%ebx
mov    %rsp,%r14
lea    0xeb3(%rip),%r15
lea    0xec9(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xa,%edx
call   1050 <binsearchA@plt>
mov    %r15,%rdi
mov    %ebx,%esi
mov    $0xa,%edx
mov    %eax,%ecx
call   1030 <printf@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xa,%edx
call   1040 <binsearchB@plt>
mov    %r12,%rdi
mov    %ebx,%esi
mov    $0xa,%edx
mov    %eax,%ecx
call   1030 <printf@plt>
add    $0x1,%ebx
cmp    $0xb,%ebx
jne    1180 <main+0x50>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [29 x i8] c"binsearchA (%d, v, %d) = %d\0A\00"
@.str.1 = [30 x i8] c"binsearchB (%d, v, %d) = %d\0A\0A\00"
define i32 @main() {
%1 = alloca [11 x i32]
%2 = getelementptr inbounds [11 x i32], [11 x i32]* %1, i64 0, i64 0
%3 = bitcast [11 x i32]* %1 to <4 x i32>*
store <4 x i32> <i32 0, i32 1, i32 2, i32 3>, <4 x i32>* %3
%4 = getelementptr inbounds [11 x i32], [11 x i32]* %1, i64 0, i64 4
%5 = getelementptr inbounds [11 x i32], [11 x i32]* %1, i64 0, i64 8
store i32 8, i32* %5
%6 = getelementptr inbounds [11 x i32], [11 x i32]* %1, i64 0, i64 9
store i32 9, i32* %6
%7 = bitcast i32* %4 to <4 x i32>*
store <4 x i32> <i32 4, i32 6, i32 6, i32 7>, <4 x i32>* %7
br label %8
8: ; preds = %0, %8
%9 = phi i32 [ 0, %0 ], [ %14, %8 ]
%10 = call i32 @binsearchA(i32 %9, i32* %2, i32 10)
%11 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %9, i32 10, i32 %10)
%12 = call i32 @binsearchB(i32 %9, i32* %2, i32 10)
%13 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %9, i32 10, i32 %12)
%14 = add nuw nsw i32 %9, 1
%15 = icmp eq i32 %14, 11
br i1 %15, label %16, label %8
16: ; preds = %8
ret i32 0
}