#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*/ array;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int bsearch(int *, int *, int);
int main() {
  int array[] = {1, 2, 4, 4, 6, 8, 8, 8, 8};
  int length = sizeof(array) / sizeof(int);
  assert(bsearch(array, array + length, 0) == 0);
  assert(bsearch(array, array + length, 1) == 1);
  assert(bsearch(array, array + length, 2) == 2);
  assert(bsearch(array, array + length, 3) == 2);
  assert(bsearch(array, array + length, 4) == 4);
  assert(bsearch(array, array + length, 5) == 4);
  assert(bsearch(array, array + length, 6) == 5);
  assert(bsearch(array, array + length, 7) == 5);
  assert(bsearch(array, array + length, 8) == 9);
  assert(bsearch(array, array + length, 9) == 9);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xeb6(%rip),%rsi
mov    $0x24,%edx
call   1040 <memcpy@plt>
movl   $0x9,-0x34(%rbp)
lea    -0x30(%rbp),%rdi
lea    -0x30(%rbp),%rsi
movslq -0x34(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
xor    %edx,%edx
call   1050 <bsearch@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
lea    -0x30(%rbp),%rdi
lea    -0x30(%rbp),%rsi
movslq -0x34(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    $0x1,%edx
call   1050 <bsearch@plt>
cmp    $0x1,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
lea    -0x30(%rbp),%rdi
lea    -0x30(%rbp),%rsi
movslq -0x34(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    $0x2,%edx
call   1050 <bsearch@plt>
cmp    $0x2,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
lea    -0x30(%rbp),%rdi
lea    -0x30(%rbp),%rsi
movslq -0x34(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    $0x3,%edx
call   1050 <bsearch@plt>
cmp    $0x2,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
lea    -0x30(%rbp),%rdi
lea    -0x30(%rbp),%rsi
movslq -0x34(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    $0x4,%edx
call   1050 <bsearch@plt>
cmp    $0x4,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
lea    -0x30(%rbp),%rdi
lea    -0x30(%rbp),%rsi
movslq -0x34(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    $0x5,%edx
call   1050 <bsearch@plt>
cmp    $0x4,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
lea    -0x30(%rbp),%rdi
lea    -0x30(%rbp),%rsi
movslq -0x34(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    $0x6,%edx
call   1050 <bsearch@plt>
cmp    $0x5,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
lea    -0x30(%rbp),%rdi
lea    -0x30(%rbp),%rsi
movslq -0x34(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    $0x7,%edx
call   1050 <bsearch@plt>
cmp    $0x5,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
lea    -0x30(%rbp),%rdi
lea    -0x30(%rbp),%rsi
movslq -0x34(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    $0x8,%edx
call   1050 <bsearch@plt>
cmp    $0x9,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
lea    -0x30(%rbp),%rdi
lea    -0x30(%rbp),%rsi
movslq -0x34(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    $0x9,%edx
call   1050 <bsearch@plt>
cmp    $0x9,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    0xef3(%rip),%eax
mov    %eax,0x20(%rsp)
movaps 0xed8(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xebc(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0x24(%rsp),%r14
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1040 <bsearch@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1030 <assert@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <bsearch@plt>
xor    %edi,%edi
cmp    $0x1,%eax
sete   %dil
call   1030 <assert@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x2,%edx
call   1040 <bsearch@plt>
xor    %edi,%edi
cmp    $0x2,%eax
sete   %dil
call   1030 <assert@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x3,%edx
call   1040 <bsearch@plt>
xor    %edi,%edi
cmp    $0x2,%eax
sete   %dil
call   1030 <assert@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x4,%edx
call   1040 <bsearch@plt>
xor    %edi,%edi
cmp    $0x4,%eax
sete   %dil
call   1030 <assert@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x5,%edx
call   1040 <bsearch@plt>
xor    %edi,%edi
cmp    $0x4,%eax
sete   %dil
call   1030 <assert@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x6,%edx
call   1040 <bsearch@plt>
xor    %edi,%edi
cmp    $0x5,%eax
sete   %dil
call   1030 <assert@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x7,%edx
call   1040 <bsearch@plt>
xor    %edi,%edi
cmp    $0x5,%eax
sete   %dil
call   1030 <assert@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x8,%edx
call   1040 <bsearch@plt>
xor    %edi,%edi
cmp    $0x9,%eax
sete   %dil
call   1030 <assert@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x9,%edx
call   1040 <bsearch@plt>
xor    %edi,%edi
cmp    $0x9,%eax
sete   %dil
call   1030 <assert@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.array = [9 x i32] [i32 1, i32 2, i32 4, i32 4, i32 6, i32 8, i32 8, i32 8, i32 8]
define i32 @main() {
%1 = alloca i32
%2 = alloca [9 x i32]
%3 = alloca i32
store i32 0, i32* %1
%4 = bitcast [9 x i32]* %2 to i8*
store i32 9, i32* %3
%5 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 0
%6 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 0
%7 = load i32, i32* %3
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i32, i32* %6, i64 %8
%10 = call i32 @bsearch(i32* %5, i32* %9, i32 0)
%11 = icmp eq i32 %10, 0
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 0
%15 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 0
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %15, i64 %17
%19 = call i32 @bsearch(i32* %14, i32* %18, i32 1)
%20 = icmp eq i32 %19, 1
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 0
%24 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 0
%25 = load i32, i32* %3
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %24, i64 %26
%28 = call i32 @bsearch(i32* %23, i32* %27, i32 2)
%29 = icmp eq i32 %28, 2
%30 = zext i1 %29 to i32
%31 = call i32 @assert(i32 %30)
%32 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 0
%33 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 0
%34 = load i32, i32* %3
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %33, i64 %35
%37 = call i32 @bsearch(i32* %32, i32* %36, i32 3)
%38 = icmp eq i32 %37, 2
%39 = zext i1 %38 to i32
%40 = call i32 @assert(i32 %39)
%41 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 0
%42 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 0
%43 = load i32, i32* %3
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i32, i32* %42, i64 %44
%46 = call i32 @bsearch(i32* %41, i32* %45, i32 4)
%47 = icmp eq i32 %46, 4
%48 = zext i1 %47 to i32
%49 = call i32 @assert(i32 %48)
%50 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 0
%51 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 0
%52 = load i32, i32* %3
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i32, i32* %51, i64 %53
%55 = call i32 @bsearch(i32* %50, i32* %54, i32 5)
%56 = icmp eq i32 %55, 4
%57 = zext i1 %56 to i32
%58 = call i32 @assert(i32 %57)
%59 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 0
%60 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 0
%61 = load i32, i32* %3
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i32, i32* %60, i64 %62
%64 = call i32 @bsearch(i32* %59, i32* %63, i32 6)
%65 = icmp eq i32 %64, 5
%66 = zext i1 %65 to i32
%67 = call i32 @assert(i32 %66)
%68 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 0
%69 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 0
%70 = load i32, i32* %3
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i32, i32* %69, i64 %71
%73 = call i32 @bsearch(i32* %68, i32* %72, i32 7)
%74 = icmp eq i32 %73, 5
%75 = zext i1 %74 to i32
%76 = call i32 @assert(i32 %75)
%77 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 0
%78 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 0
%79 = load i32, i32* %3
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds i32, i32* %78, i64 %80
%82 = call i32 @bsearch(i32* %77, i32* %81, i32 8)
%83 = icmp eq i32 %82, 9
%84 = zext i1 %83 to i32
%85 = call i32 @assert(i32 %84)
%86 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 0
%87 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 0
%88 = load i32, i32* %3
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds i32, i32* %87, i64 %89
%91 = call i32 @bsearch(i32* %86, i32* %90, i32 9)
%92 = icmp eq i32 %91, 9
%93 = zext i1 %92 to i32
%94 = call i32 @assert(i32 %93)
ret i32 0
}

LLVM IR (-O2):
@__const.main.array = [9 x i32] [i32 1, i32 2, i32 4, i32 4, i32 6, i32 8, i32 8, i32 8, i32 8]
define i32 @main() {
%1 = alloca [9 x i32]
%2 = bitcast [9 x i32]* %1 to i8*
%3 = getelementptr inbounds [9 x i32], [9 x i32]* %1, i64 0, i64 0
%4 = getelementptr inbounds [9 x i32], [9 x i32]* %1, i64 0, i64 9
%5 = call i32 @bsearch(i32* %3, i32* %4, i32 0)
%6 = icmp eq i32 %5, 0
%7 = zext i1 %6 to i32
%8 = call i32 @assert(i32 %7)
%9 = call i32 @bsearch(i32* %3, i32* %4, i32 1)
%10 = icmp eq i32 %9, 1
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = call i32 @bsearch(i32* %3, i32* %4, i32 2)
%14 = icmp eq i32 %13, 2
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = call i32 @bsearch(i32* %3, i32* %4, i32 3)
%18 = icmp eq i32 %17, 2
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = call i32 @bsearch(i32* %3, i32* %4, i32 4)
%22 = icmp eq i32 %21, 4
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
%25 = call i32 @bsearch(i32* %3, i32* %4, i32 5)
%26 = icmp eq i32 %25, 4
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
%29 = call i32 @bsearch(i32* %3, i32* %4, i32 6)
%30 = icmp eq i32 %29, 5
%31 = zext i1 %30 to i32
%32 = call i32 @assert(i32 %31)
%33 = call i32 @bsearch(i32* %3, i32* %4, i32 7)
%34 = icmp eq i32 %33, 5
%35 = zext i1 %34 to i32
%36 = call i32 @assert(i32 %35)
%37 = call i32 @bsearch(i32* %3, i32* %4, i32 8)
%38 = icmp eq i32 %37, 9
%39 = zext i1 %38 to i32
%40 = call i32 @assert(i32 %39)
%41 = call i32 @bsearch(i32* %3, i32* %4, i32 9)
%42 = icmp eq i32 %41, 9
%43 = zext i1 %42 to i32
%44 = call i32 @assert(i32 %43)
ret i32 0
}