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

/* Variables and functions */
int binary_search(int *, int, int);
int /*<<< orphan*/ printf(char *, int, ...);
int main() {
  int ar[] = {3, 4, 8, 14, 15, 19, 23, 25, 31, 39, 43, 49, 52, 55};
  int ar1[] = {-1};
  int ret, i;
  for (i = 0; i < sizeof(ar1) / sizeof(ar1[0]); i++) {
    printf("[%d] %d\n", i, ar1[i]);
  }
  ret = binary_search(ar1, -2, sizeof(ar1) / sizeof(int));
  if (ret >= 0)
    printf("binary search found ret = %d\n", ret);
  else
    printf("not found insert at %d\n", ~ret);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xeb6(%rip),%rsi
mov    $0x38,%edx
call   1040 <memcpy@plt>
mov    0xede(%rip),%eax
mov    %eax,-0x44(%rbp)
movl   $0x0,-0x4c(%rbp)
movslq -0x4c(%rbp),%rax
cmp    $0x1,%rax
jae    1199 <main+0x69>
mov    -0x4c(%rbp),%esi
movslq -0x4c(%rbp),%rax
mov    -0x44(%rbp,%rax,4),%edx
lea    0xeb8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    1164 <main+0x34>
lea    -0x44(%rbp),%rdi
mov    $0xfffffffe,%esi
mov    $0x1,%edx
call   1050 <binary_search@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0x0,-0x48(%rbp)
jl     11cf <main+0x9f>
mov    -0x48(%rbp),%esi
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11e3 <main+0xb3>
mov    -0x48(%rbp),%esi
xor    $0xffffffff,%esi
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
movl   $0xffffffff,0x4(%rsp)
ff
lea    0xed0(%rip),%rdi
xor    %esi,%esi
mov    $0xffffffff,%edx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x4(%rsp),%rdi
mov    $0xfffffffe,%esi
mov    $0x1,%edx
call   1040 <binary_search@plt>
test   %eax,%eax
js     115f <main+0x3f>
lea    0xeac(%rip),%rdi
jmp    1168 <main+0x48>
not    %eax
lea    0xebf(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@__const.main.ar = [14 x i32] [i32 3, i32 4, i32 8, i32 14, i32 15, i32 19, i32 23, i32 25, i32 31, i32 39, i32 43, i32 49, i32 52, i32 55]
@__const.main.ar1 = [1 x i32] [i32 -1]
@.str = [9 x i8] c"[%d] %d\0A\00"
@.str.1 = [30 x i8] c"binary search found ret = %d\0A\00"
@.str.2 = [24 x i8] c"not found insert at %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [14 x i32]
%3 = alloca [1 x i32]
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = bitcast [14 x i32]* %2 to i8*
%7 = bitcast [1 x i32]* %3 to i8*
store i32 0, i32* %5
br label %8
8: ; preds = %19, %0
%9 = load i32, i32* %5
%10 = sext i32 %9 to i64
%11 = icmp ult i64 %10, 1
br i1 %11, label %12, label %22
12: ; preds = %8
%13 = load i32, i32* %5
%14 = load i32, i32* %5
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [1 x i32], [1 x i32]* %3, i64 0, i64 %15
%17 = load i32, i32* %16
%18 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %17)
br label %19
19: ; preds = %12
%20 = load i32, i32* %5
%21 = add nsw i32 %20, 1
store i32 %21, i32* %5
br label %8
22: ; preds = %8
%23 = getelementptr inbounds [1 x i32], [1 x i32]* %3, i64 0, i64 0
%24 = call i32 @binary_search(i32* %23, i32 -2, i32 1)
store i32 %24, i32* %4
%25 = load i32, i32* %4
%26 = icmp sge i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %22
%28 = load i32, i32* %4
%29 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %28)
br label %34
30: ; preds = %22
%31 = load i32, i32* %4
%32 = xor i32 %31, -1
%33 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %32)
br label %34
34: ; preds = %30, %27
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"[%d] %d\0A\00"
@.str.1 = [30 x i8] c"binary search found ret = %d\0A\00"
@.str.2 = [24 x i8] c"not found insert at %d\0A\00"
define i32 @main() {
%1 = alloca [1 x i32]
%2 = bitcast [1 x i32]* %1 to i8*
%3 = getelementptr inbounds [1 x i32], [1 x i32]* %1, i64 0, i64 0
store i32 -1, i32* %3
%4 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 0, i32 -1)
%5 = call i32 @binary_search(i32* %3, i32 -2, i32 1)
%6 = icmp sgt i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %5)
br label %12
9: ; preds = %0
%10 = xor i32 %5, -1
%11 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %10)
br label %12
12: ; preds = %9, %7
ret i32 0
}