#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 /*<<< orphan*/ printf(char *, int, int, int);
int main(void) {
  int maxv = 10;
  int vector[maxv + 1];
  int e, ee;
  for (e = 0; e < maxv; ++e) {
    vector[e] = 20 + e;
  }
  vector[5] = vector[6];
  vector[maxv] = -1;
  for (e = -5; e < maxv + 5; ++e) {
    ee = (binsearch(e + 20, vector, maxv) != -1)
             ? binsearch(e + 20, vector, maxv)
             : maxv;
    printf("%d = vector[%d] = %d\n", e, ee, vector[ee]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xa,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1192 <main+0x72>
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%edx
add    $0x14,%edx
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1167 <main+0x47>
mov    -0x28(%rbp),%rax
mov    0x18(%rax),%ecx
mov    %ecx,0x14(%rax)
movslq -0x8(%rbp),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
movl   $0xfffffffb,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x8(%rbp),%ecx
add    $0x5,%ecx
cmp    %ecx,%eax
jge    122b <main+0x10b>
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edi
add    $0x14,%edi
mov    -0x8(%rbp),%edx
call   1030 <binsearch@plt>
cmp    $0xffffffff,%eax
je     11f4 <main+0xd4>
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edi
add    $0x14,%edi
mov    -0x8(%rbp),%edx
call   1030 <binsearch@plt>
mov    %eax,-0x2c(%rbp)
jmp    11fa <main+0xda>
mov    -0x8(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    %ecx,-0x20(%rbp)
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
lea    0xde8(%rip),%rdi
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ae <main+0x8e>
movl   $0x0,-0x4(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
movaps 0xecf(%rip),%xmm0
movaps %xmm0,(%rsp)
movabs $0x1d0000001c,%rax
mov    %rax,0x20(%rsp)
movaps 0xec5(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movl   $0xffffffff,0x28(%rsp)
ff
mov    $0xf,%ebx
mov    %rsp,%r14
lea    0xeb9(%rip),%r15
jmp    1188 <main+0x68>
nopl   0x0(%rax)
movslq %eax,%rdx
mov    (%rsp,%rdx,4),%ecx
mov    %r15,%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
add    $0x1,%ebx
cmp    $0x23,%ebx
je     11b7 <main+0x97>
lea    -0x14(%rbx),%ebp
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xa,%edx
call   1030 <binsearch@plt>
mov    %eax,%ecx
mov    $0xa,%eax
cmp    $0xffffffff,%ecx
je     1170 <main+0x50>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xa,%edx
call   1030 <binsearch@plt>
jmp    1170 <main+0x50>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [22 x i8] c"%d = vector[%d] = %d\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 20, i32 21, i32 22, i32 23>, <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 28, i32* %5
%6 = getelementptr inbounds [11 x i32], [11 x i32]* %1, i64 0, i64 9
store i32 29, i32* %6
%7 = bitcast i32* %4 to <4 x i32>*
store <4 x i32> <i32 24, i32 26, i32 26, i32 27>, <4 x i32>* %7
%8 = getelementptr inbounds [11 x i32], [11 x i32]* %1, i64 0, i64 10
store i32 -1, i32* %8
br label %9
9: ; preds = %0, %16
%10 = phi i32 [ -5, %0 ], [ %22, %16 ]
%11 = add nsw i32 %10, 20
%12 = call i32 @binsearch(i32 %11, i32* %2, i32 10)
%13 = icmp eq i32 %12, -1
br i1 %13, label %16, label %14
14: ; preds = %9
%15 = call i32 @binsearch(i32 %11, i32* %2, i32 10)
br label %16
16: ; preds = %9, %14
%17 = phi i32 [ %15, %14 ], [ 10, %9 ]
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [11 x i32], [11 x i32]* %1, i64 0, i64 %18
%20 = load i32, i32* %19
%21 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %17, i32 %20)
%22 = add nsw i32 %10, 1
%23 = icmp eq i32 %22, 15
br i1 %23, label %24, label %9
24: ; preds = %16
ret i32 0
}