#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 binsearch(int, int *, int);
int /*<<< orphan*/ printf(char *, int);
int main() {
  int array[] = {1,  3,  4,   5,   7,   9,   12,    12,    12,   12,
                 23, 24, 188, 188, 188, 234, 21234, 21234, 21234};
  int array_n = sizeof(array) / sizeof(*array);
  printf("%d\n", -1 == binsearch(35, array, array_n));
  printf("%d\n", 12 == binsearch(188, array, array_n));
  printf("%d\n", 0 == binsearch(1, array, array_n));
  printf("%d\n", 6 == binsearch(12, array, array_n));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xeb6(%rip),%rsi
mov    $0x4c,%edx
call   1050 <memcpy@plt>
movl   $0x13,-0x54(%rbp)
lea    -0x50(%rbp),%rsi
mov    -0x54(%rbp),%edx
mov    $0x23,%edi
call   1030 <binsearch@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%esi
lea    0xec8(%rip),%rdi
call   1040 <printf@plt>
lea    -0x50(%rbp),%rsi
mov    -0x54(%rbp),%edx
mov    $0xbc,%edi
call   1030 <binsearch@plt>
mov    %eax,%ecx
mov    $0xc,%eax
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%esi
lea    0xe9a(%rip),%rdi
call   1040 <printf@plt>
lea    -0x50(%rbp),%rsi
mov    -0x54(%rbp),%edx
mov    $0x1,%edi
call   1030 <binsearch@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%esi
lea    0xe6f(%rip),%rdi
call   1040 <printf@plt>
lea    -0x50(%rbp),%rsi
mov    -0x54(%rbp),%edx
mov    $0xc,%edi
call   1030 <binsearch@plt>
mov    %eax,%ecx
mov    $0x6,%eax
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%esi
lea    0xe41(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x58,%rsp
movups 0xf0e(%rip),%xmm0
movups %xmm0,0x3c(%rsp)
movaps 0xef6(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xeda(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xebe(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xea2(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%r14
mov    $0x23,%edi
mov    %r14,%rsi
mov    $0x13,%edx
call   1030 <binsearch@plt>
xor    %esi,%esi
cmp    $0xffffffff,%eax
sete   %sil
lea    0xec5(%rip),%rbx
mov    %rbx,%rdi
call   1040 <printf@plt>
mov    $0xbc,%edi
mov    %r14,%rsi
mov    $0x13,%edx
call   1030 <binsearch@plt>
xor    %esi,%esi
cmp    $0xc,%eax
sete   %sil
mov    %rbx,%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
mov    %r14,%rsi
mov    $0x13,%edx
call   1030 <binsearch@plt>
xor    %esi,%esi
test   %eax,%eax
sete   %sil
mov    %rbx,%rdi
call   1040 <printf@plt>
mov    $0xc,%edi
mov    %r14,%rsi
mov    $0x13,%edx
call   1030 <binsearch@plt>
xor    %esi,%esi
cmp    $0x6,%eax
sete   %sil
mov    %rbx,%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.array = [19 x i32] [i32 1, i32 3, i32 4, i32 5, i32 7, i32 9, i32 12, i32 12, i32 12, i32 12, i32 23, i32 24, i32 188, i32 188, i32 188, i32 234, i32 21234, i32 21234, i32 21234]
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [19 x i32]
%3 = alloca i32
store i32 0, i32* %1
%4 = bitcast [19 x i32]* %2 to i8*
store i32 19, i32* %3
%5 = getelementptr inbounds [19 x i32], [19 x i32]* %2, i64 0, i64 0
%6 = load i32, i32* %3
%7 = call i32 @binsearch(i32 35, i32* %5, i32 %6)
%8 = icmp eq i32 -1, %7
%9 = zext i1 %8 to i32
%10 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = getelementptr inbounds [19 x i32], [19 x i32]* %2, i64 0, i64 0
%12 = load i32, i32* %3
%13 = call i32 @binsearch(i32 188, i32* %11, i32 %12)
%14 = icmp eq i32 12, %13
%15 = zext i1 %14 to i32
%16 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = getelementptr inbounds [19 x i32], [19 x i32]* %2, i64 0, i64 0
%18 = load i32, i32* %3
%19 = call i32 @binsearch(i32 1, i32* %17, i32 %18)
%20 = icmp eq i32 0, %19
%21 = zext i1 %20 to i32
%22 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %21)
%23 = getelementptr inbounds [19 x i32], [19 x i32]* %2, i64 0, i64 0
%24 = load i32, i32* %3
%25 = call i32 @binsearch(i32 12, i32* %23, i32 %24)
%26 = icmp eq i32 6, %25
%27 = zext i1 %26 to i32
%28 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %27)
ret i32 0
}

LLVM IR (-O2):
@__const.main.array = [19 x i32] [i32 1, i32 3, i32 4, i32 5, i32 7, i32 9, i32 12, i32 12, i32 12, i32 12, i32 23, i32 24, i32 188, i32 188, i32 188, i32 234, i32 21234, i32 21234, i32 21234]
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca [19 x i32]
%2 = bitcast [19 x i32]* %1 to i8*
%3 = getelementptr inbounds [19 x i32], [19 x i32]* %1, i64 0, i64 0
%4 = call i32 @binsearch(i32 35, i32* %3, i32 19)
%5 = icmp eq i32 %4, -1
%6 = zext i1 %5 to i32
%7 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = call i32 @binsearch(i32 188, i32* %3, i32 19)
%9 = icmp eq i32 %8, 12
%10 = zext i1 %9 to i32
%11 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = call i32 @binsearch(i32 1, i32* %3, i32 19)
%13 = icmp eq i32 %12, 0
%14 = zext i1 %13 to i32
%15 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = call i32 @binsearch(i32 12, i32* %3, i32 19)
%17 = icmp eq i32 %16, 6
%18 = zext i1 %17 to i32
%19 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %18)
ret i32 0
}