#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 /*<<< orphan*/ getch();
int min(int *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
main() {
  int low, high, mid, i, tosearch, num;
  scanf("%d", &num);
  int input[num];
  for (i = 0; i <= num; ++i) {
    scanf("%d", &input[i]);
  }
  low = min(input, num);
  printf("%d", low);
  getch();
  scanf("What to search %d", &tosearch);
  while (low <= high) {
    mid = (low + high) / 2;
    if (tosearch < mid) {
      high = mid - 1;
    } else if (tosearch > mid) {
      low = mid + 1;
    } else {
      printf("found");
      getch();
    }
  }
  getch();
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeb9(%rip),%rdi
lea    -0x1c(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x1c(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jg     11c2 <main+0x82>
mov    -0x38(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe60(%rip),%rdi
call   1050 <scanf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    118d <main+0x4d>
mov    -0x38(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1040 <min@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1060 <getch@plt>
lea    0xe10(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     1269 <main+0x129>
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1230 <main+0xf0>
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1264 <main+0x124>
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
jle    124a <main+0x10a>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    125f <main+0x11f>
lea    0xdc1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1060 <getch@plt>
jmp    1264 <main+0x124>
jmp    11f9 <main+0xb9>
mov    $0x0,%al
call   1060 <getch@plt>
mov    -0x28(%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   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xeba(%rip),%rdi
lea    -0x2c(%rbp),%rsi
call   1050 <scanf@plt>
mov    %rsp,%r12
mov    -0x2c(%rbp),%eax
mov    %rsp,%r14
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    -0x2c(%rbp),%esi
test   %esi,%esi
js     11bc <main+0x7c>
mov    $0xffffffffffffffff,%r13
lea    0xe81(%rip),%r15
mov    %r14,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
movslq -0x2c(%rbp),%rsi
add    $0x1,%r13
add    $0x4,%rbx
cmp    %rsi,%r13
jl     11a0 <main+0x60>
mov    %r14,%rdi
call   1040 <min@plt>
mov    %eax,%r15d
lea    0xe41(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
call   1060 <getch@plt>
lea    0xe1b(%rip),%rdi
lea    -0x30(%rbp),%rsi
call   1050 <scanf@plt>
lea    0xe1d(%rip),%r14
jmp    120a <main+0xca>
nopw   0x0(%rax,%rax,1)
add    $0xffffffff,%eax
mov    %eax,%ebx
cmp    %ebx,%r15d
jg     1243 <main+0x103>
lea    (%r15,%rbx,1),%ecx
mov    %ecx,%eax
shr    $0x1f,%eax
add    %ecx,%eax
sar    %eax
cmp    %eax,-0x30(%rbp)
jl     1200 <main+0xc0>
jle    1230 <main+0xf0>
add    $0x1,%eax
mov    %eax,%r15d
jmp    1205 <main+0xc5>
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
call   1060 <getch@plt>
jmp    1205 <main+0xc5>
xor    %eax,%eax
call   1060 <getch@plt>
mov    %r12,%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [18 x i8] c"What to search %d\00"
@.str.2 = [6 x i8] c"found\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
store i32 0, i32* %1
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %7)
%11 = load i32, i32* %7
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %8
%14 = alloca i32, i64 %12
store i64 %12, i64* %9
store i32 0, i32* %5
br label %15
15: ; preds = %24, %0
%16 = load i32, i32* %5
%17 = load i32, i32* %7
%18 = icmp sle i32 %16, %17
br i1 %18, label %19, label %27
19: ; preds = %15
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %14, i64 %21
%23 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %22)
br label %24
24: ; preds = %19
%25 = load i32, i32* %5
%26 = add nsw i32 %25, 1
store i32 %26, i32* %5
br label %15
27: ; preds = %15
%28 = load i32, i32* %7
%29 = call i32 @min(i32* %14, i32 %28)
store i32 %29, i32* %2
%30 = load i32, i32* %2
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %30)
%32 = call i32 (...) @getch()
%33 = call i32 @scanf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32* %6)
br label %34
34: ; preds = %60, %27
%35 = load i32, i32* %2
%36 = load i32, i32* %3
%37 = icmp sle i32 %35, %36
br i1 %37, label %38, label %61
38: ; preds = %34
%39 = load i32, i32* %2
%40 = load i32, i32* %3
%41 = add nsw i32 %39, %40
%42 = sdiv i32 %41, 2
store i32 %42, i32* %4
%43 = load i32, i32* %6
%44 = load i32, i32* %4
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %49
46: ; preds = %38
%47 = load i32, i32* %4
%48 = sub nsw i32 %47, 1
store i32 %48, i32* %3
br label %60
49: ; preds = %38
%50 = load i32, i32* %6
%51 = load i32, i32* %4
%52 = icmp sgt i32 %50, %51
br i1 %52, label %53, label %56
53: ; preds = %49
%54 = load i32, i32* %4
%55 = add nsw i32 %54, 1
store i32 %55, i32* %2
br label %59
56: ; preds = %49
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%58 = call i32 (...) @getch()
br label %59
59: ; preds = %56, %53
br label %60
60: ; preds = %59, %46
br label %34
61: ; preds = %34
%62 = call i32 (...) @getch()
%63 = load i8*, i8** %8
%64 = load i32, i32* %1
ret i32 %64
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [18 x i8] c"What to search %d\00"
@.str.2 = [6 x i8] c"found\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%6 = load i32, i32* %2
%7 = zext i32 %6 to i64
%8 = call i8* @llvm.stacksave()
%9 = alloca i32, i64 %7
%10 = load i32, i32* %2
%11 = icmp slt i32 %10, 0
br i1 %11, label %20, label %12
12: ; preds = %0, %12
%13 = phi i64 [ %16, %12 ], [ 0, %0 ]
%14 = getelementptr inbounds i32, i32* %9, i64 %13
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %14)
%16 = add nuw nsw i64 %13, 1
%17 = load i32, i32* %2
%18 = sext i32 %17 to i64
%19 = icmp slt i64 %13, %18
br i1 %19, label %12, label %20
20: ; preds = %12, %0
%21 = phi i32 [ %10, %0 ], [ %17, %12 ]
%22 = call i32 @min(i32* %9, i32 %21)
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %22)
%24 = call i32 (...) @getch()
%25 = call i32 @scanf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32* %1)
br label %26
26: ; preds = %20, %42
%27 = phi i32 [ %22, %20 ], [ %44, %42 ]
%28 = phi i32 [ undef, %20 ], [ %43, %42 ]
%29 = add nsw i32 %27, %28
%30 = sdiv i32 %29, 2
%31 = load i32, i32* %1
%32 = icmp slt i32 %31, %30
br i1 %32, label %33, label %35
33: ; preds = %26
%34 = add nsw i32 %30, -1
br label %42
35: ; preds = %26
%36 = icmp sgt i32 %31, %30
br i1 %36, label %37, label %39
37: ; preds = %35
%38 = add nsw i32 %30, 1
br label %42
39: ; preds = %35
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%41 = call i32 (...) @getch()
br label %42
42: ; preds = %37, %39, %33
%43 = phi i32 [ %34, %33 ], [ %28, %37 ], [ %28, %39 ]
%44 = phi i32 [ %27, %33 ], [ %38, %37 ], [ %27, %39 ]
%45 = icmp sgt i32 %44, %43
br i1 %45, label %46, label %26
46: ; preds = %42
%47 = call i32 (...) @getch()
ret i32 0
}