#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 binary_search(int *, int, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ read_array(int *, int);
int /*<<< orphan*/ read_int(int *);
int main() {
  int n;
  read_int(&n);
  if (n <= 0)
    return 1;
  int a[n];
  read_array(a, n);
  int x;
  read_int(&x);
  int result = binary_search(a, n, x);
  printf("result = %d\n", result);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x8(%rbp),%rdi
call   1040 <read_int@plt>
cmpl   $0x0,-0x8(%rbp)
jg     116e <main+0x2e>
movl   $0x1,-0x4(%rbp)
jmp    11d5 <main+0x95>
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
lea    0xf(,%rax,4),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x28(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%esi
call   1060 <read_array@plt>
lea    -0x1c(%rbp),%rdi
call   1040 <read_int@plt>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1050 <binary_search@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xe3e(%rip),%rdi
call   1030 <printf@plt>
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
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    -0x14(%rbp),%rdi
call   1040 <read_int@plt>
mov    -0x14(%rbp),%eax
test   %eax,%eax
jle    11aa <main+0x6a>
mov    %rsp,%r14
mov    %rsp,%rbx
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    -0x14(%rbp),%esi
mov    %rbx,%rdi
call   1060 <read_array@plt>
lea    -0x18(%rbp),%rdi
call   1040 <read_int@plt>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    %rbx,%rdi
call   1050 <binary_search@plt>
lea    0xe64(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %eax,%eax
mov    %r14,%rsp
jmp    11af <main+0x6f>
mov    $0x1,%eax
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"result = %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
%7 = call i32 @read_int(i32* %2)
%8 = load i32, i32* %2
%9 = icmp sle i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %0
store i32 1, i32* %1
br label %25
11: ; preds = %0
%12 = load i32, i32* %2
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %3
%15 = alloca i32, i64 %13
store i64 %13, i64* %4
%16 = load i32, i32* %2
%17 = call i32 @read_array(i32* %15, i32 %16)
%18 = call i32 @read_int(i32* %5)
%19 = load i32, i32* %2
%20 = load i32, i32* %5
%21 = call i32 @binary_search(i32* %15, i32 %19, i32 %20)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %22)
store i32 0, i32* %1
%24 = load i8*, i8** %3
br label %25
25: ; preds = %11, %10
%26 = load i32, i32* %1
ret i32 %26
}

LLVM IR (-O2):
@.str = [13 x i8] c"result = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = call i32 @read_int(i32* %1)
%5 = load i32, i32* %1
%6 = icmp slt i32 %5, 1
br i1 %6, label %19, label %7
7: ; preds = %0
%8 = zext i32 %5 to i64
%9 = call i8* @llvm.stacksave()
%10 = alloca i32, i64 %8
%11 = load i32, i32* %1
%12 = call i32 @read_array(i32* %10, i32 %11)
%13 = bitcast i32* %2 to i8*
%14 = call i32 @read_int(i32* %2)
%15 = load i32, i32* %1
%16 = load i32, i32* %2
%17 = call i32 @binary_search(i32* %10, i32 %15, i32 %16)
%18 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %17)
br label %19
19: ; preds = %0, %7
%20 = phi i32 [ 0, %7 ], [ 1, %0 ]
ret i32 %20
}