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

/* Variables and functions */
int binarySearch(int *, int /*<<< orphan*/, int, int);
int /*<<< orphan*/ printList(int *, int);
int /*<<< orphan*/ showResult(int, int);
int main(int argc, const char *argv[]) {
  int key;
  int list[10] = {1, 3, 4, 5, 6, 7, 8, 9, 12, 20};
  int size = ((int)sizeof(list) / sizeof(int));
  int pos;
  printList(list, size);
  key = 3;
  pos = binarySearch(list, 0, size - 1, key);
  showResult(pos, key);
  key = 20;
  pos = binarySearch(list, 0, size - 1, key);
  showResult(pos, key);
  key = 10;
  pos = binarySearch(list, 0, size - 1, key);
  showResult(pos, key);
  key = -1;
  pos = binarySearch(list, 0, size - 1, key);
  showResult(pos, key);
  int list1[1] = {2};
  key = 1;
  pos = binarySearch(list1, 0, 0, key);
  showResult(pos, key);
  int list2[2] = {1, 3};
  key = 1;
  pos = binarySearch(list2, 0, 1, key);
  showResult(pos, key);
  key = 3;
  pos = binarySearch(list, 0, 1, key);
  showResult(pos, key);
  key = 0;
  pos = binarySearch(list, 0, 1, key);
  showResult(pos, key);
  key = 4;
  pos = binarySearch(list, 0, 1, key);
  showResult(pos, key);
  key = 2;
  pos = binarySearch(list, 0, 1, key);
  showResult(pos, key);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xe9f(%rip),%rsi
mov    $0x28,%edx
call   1040 <memcpy@plt>
movl   $0xa,-0x44(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x44(%rbp),%esi
call   1060 <printList@plt>
movl   $0x3,-0x14(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x44(%rbp),%edx
sub    $0x1,%edx
mov    -0x14(%rbp),%ecx
xor    %esi,%esi
call   1050 <binarySearch@plt>
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1030 <showResult@plt>
movl   $0x14,-0x14(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x44(%rbp),%edx
sub    $0x1,%edx
mov    -0x14(%rbp),%ecx
xor    %esi,%esi
call   1050 <binarySearch@plt>
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1030 <showResult@plt>
movl   $0xa,-0x14(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x44(%rbp),%edx
sub    $0x1,%edx
mov    -0x14(%rbp),%ecx
xor    %esi,%esi
call   1050 <binarySearch@plt>
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1030 <showResult@plt>
movl   $0xffffffff,-0x14(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x44(%rbp),%edx
sub    $0x1,%edx
mov    -0x14(%rbp),%ecx
xor    %esi,%esi
call   1050 <binarySearch@plt>
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1030 <showResult@plt>
mov    0xe00(%rip),%eax
mov    %eax,-0x4c(%rbp)
movl   $0x1,-0x14(%rbp)
lea    -0x4c(%rbp),%rdi
mov    -0x14(%rbp),%ecx
xor    %edx,%edx
mov    %edx,%esi
call   1050 <binarySearch@plt>
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1030 <showResult@plt>
mov    0xdd5(%rip),%rax
mov    %rax,-0x54(%rbp)
movl   $0x1,-0x14(%rbp)
lea    -0x54(%rbp),%rdi
mov    -0x14(%rbp),%ecx
xor    %esi,%esi
mov    $0x1,%edx
call   1050 <binarySearch@plt>
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1030 <showResult@plt>
movl   $0x3,-0x14(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x14(%rbp),%ecx
xor    %esi,%esi
mov    $0x1,%edx
call   1050 <binarySearch@plt>
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1030 <showResult@plt>
movl   $0x0,-0x14(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x14(%rbp),%ecx
xor    %esi,%esi
mov    $0x1,%edx
call   1050 <binarySearch@plt>
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1030 <showResult@plt>
movl   $0x4,-0x14(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x14(%rbp),%ecx
xor    %esi,%esi
mov    $0x1,%edx
call   1050 <binarySearch@plt>
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1030 <showResult@plt>
movl   $0x2,-0x14(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x14(%rbp),%ecx
xor    %esi,%esi
mov    $0x1,%edx
call   1050 <binarySearch@plt>
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1030 <showResult@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x40,%rsp
mov    0xee4(%rip),%rax
mov    %rax,0x30(%rsp)
movaps 0xec8(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xeac(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xa,%esi
call   1050 <printList@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x9,%edx
mov    $0x3,%ecx
call   1040 <binarySearch@plt>
mov    %eax,%edi
mov    $0x3,%esi
call   1030 <showResult@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x9,%edx
mov    $0x14,%ecx
call   1040 <binarySearch@plt>
mov    %eax,%edi
mov    $0x14,%esi
call   1030 <showResult@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x9,%edx
mov    $0xa,%ecx
call   1040 <binarySearch@plt>
mov    %eax,%edi
mov    $0xa,%esi
call   1030 <showResult@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x9,%edx
mov    $0xffffffff,%ecx
call   1040 <binarySearch@plt>
mov    %eax,%edi
mov    $0xffffffff,%esi
call   1030 <showResult@plt>
movl   $0x2,0x4(%rsp)
lea    0x4(%rsp),%rdi
xor    %esi,%esi
xor    %edx,%edx
mov    $0x1,%ecx
call   1040 <binarySearch@plt>
mov    %eax,%edi
mov    $0x1,%esi
call   1030 <showResult@plt>
movabs $0x300000001,%rax
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%rdi
xor    %esi,%esi
mov    $0x1,%edx
mov    $0x1,%ecx
call   1040 <binarySearch@plt>
mov    %eax,%edi
mov    $0x1,%esi
call   1030 <showResult@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x1,%edx
mov    $0x3,%ecx
call   1040 <binarySearch@plt>
mov    %eax,%edi
mov    $0x3,%esi
call   1030 <showResult@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1040 <binarySearch@plt>
mov    %eax,%edi
xor    %esi,%esi
call   1030 <showResult@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x1,%edx
mov    $0x4,%ecx
call   1040 <binarySearch@plt>
mov    %eax,%edi
mov    $0x4,%esi
call   1030 <showResult@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x1,%edx
mov    $0x2,%ecx
call   1040 <binarySearch@plt>
mov    %eax,%edi
mov    $0x2,%esi
call   1030 <showResult@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@__const.main.list = [10 x i32] [i32 1, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 12, i32 20]
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [10 x i32]
%4 = alloca [1 x i32]
%5 = alloca i64
%6 = bitcast [10 x i32]* %3 to i8*
%7 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 0
%8 = call i32 @printList(i32* %7, i32 10)
%9 = call i32 @binarySearch(i32* %7, i32 0, i32 9, i32 3)
%10 = call i32 @showResult(i32 %9, i32 3)
%11 = call i32 @binarySearch(i32* %7, i32 0, i32 9, i32 20)
%12 = call i32 @showResult(i32 %11, i32 20)
%13 = call i32 @binarySearch(i32* %7, i32 0, i32 9, i32 10)
%14 = call i32 @showResult(i32 %13, i32 10)
%15 = call i32 @binarySearch(i32* %7, i32 0, i32 9, i32 -1)
%16 = call i32 @showResult(i32 %15, i32 -1)
%17 = bitcast [1 x i32]* %4 to i8*
%18 = getelementptr inbounds [1 x i32], [1 x i32]* %4, i64 0, i64 0
store i32 2, i32* %18
%19 = call i32 @binarySearch(i32* %18, i32 0, i32 0, i32 1)
%20 = call i32 @showResult(i32 %19, i32 1)
%21 = bitcast i64* %5 to i8*
store i64 12884901889, i64* %5
%22 = bitcast i64* %5 to i32*
%23 = call i32 @binarySearch(i32* %22, i32 0, i32 1, i32 1)
%24 = call i32 @showResult(i32 %23, i32 1)
%25 = call i32 @binarySearch(i32* %7, i32 0, i32 1, i32 3)
%26 = call i32 @showResult(i32 %25, i32 3)
%27 = call i32 @binarySearch(i32* %7, i32 0, i32 1, i32 0)
%28 = call i32 @showResult(i32 %27, i32 0)
%29 = call i32 @binarySearch(i32* %7, i32 0, i32 1, i32 4)
%30 = call i32 @showResult(i32 %29, i32 4)
%31 = call i32 @binarySearch(i32* %7, i32 0, i32 1, i32 2)
%32 = call i32 @showResult(i32 %31, i32 2)
ret i32 0
}