#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 floor(int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int value;
  scanf("%d", &value);
  int arr_size;
  scanf("%d", &arr_size);
  int A[1000];
  for (int i = 0; i < arr_size; i++) {
    scanf("%d ", &A[i]);
  }
  int min, max, mid;
  min = 0;
  max = arr_size - 1;
  while (min <= max) {
    mid = floor((min + max) / 2);
    if (A[mid] < value) {
      min = mid + 1;
    } else if (A[mid] > value) {
      max = mid - 1;
    } else {
      printf("%d\n", mid);
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xfc0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeb7(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xea7(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0xfb4(%rbp)
mov    -0xfb4(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b0 <main+0x80>
movslq -0xfb4(%rbp),%rax
lea    -0xfb0(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe6c(%rip),%rdi
call   1040 <scanf@plt>
mov    -0xfb4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xfb4(%rbp)
jmp    116c <main+0x3c>
movl   $0x0,-0xfb8(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0xfbc(%rbp)
mov    -0xfb8(%rbp),%eax
cmp    -0xfbc(%rbp),%eax
jg     1270 <main+0x140>
mov    -0xfb8(%rbp),%eax
add    -0xfbc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   1050 <floor@plt>
mov    %eax,-0xfc0(%rbp)
movslq -0xfc0(%rbp),%rax
mov    -0xfb0(%rbp,%rax,4),%eax
cmp    -0x8(%rbp),%eax
jge    1224 <main+0xf4>
mov    -0xfc0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xfb8(%rbp)
jmp    126b <main+0x13b>
movslq -0xfc0(%rbp),%rax
mov    -0xfb0(%rbp,%rax,4),%eax
cmp    -0x8(%rbp),%eax
jle    124f <main+0x11f>
mov    -0xfc0(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0xfbc(%rbp)
jmp    1266 <main+0x136>
mov    -0xfc0(%rbp),%esi
lea    0xdab(%rip),%rdi
call   1030 <printf@plt>
jmp    1270 <main+0x140>
jmp    126b <main+0x13b>
jmp    11c6 <main+0x96>
xor    %eax,%eax
add    $0xfc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xfb8,%rsp
lea    0xebb(%rip),%rbx
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <scanf@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <scanf@plt>
cmpl   $0x0,0x8(%rsp)
jle    11f6 <main+0xc6>
lea    0x10(%rsp),%r12
xor    %ebx,%ebx
lea    0xe8b(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r12,%rsi
call   1040 <scanf@plt>
add    $0x1,%rbx
movslq 0x8(%rsp),%r15
add    $0x4,%r12
cmp    %r15,%rbx
jl     1180 <main+0x50>
test   %r15d,%r15d
jle    11f6 <main+0xc6>
add    $0xffffffff,%r15d
xor    %ebx,%ebx
jmp    11ba <main+0x8a>
nopw   0x0(%rax,%rax,1)
add    $0x1,%eax
mov    %eax,%ebx
cmp    %r15d,%ebx
jg     11f6 <main+0xc6>
lea    (%r15,%rbx,1),%eax
mov    %eax,%edi
shr    $0x1f,%edi
add    %eax,%edi
sar    %edi
call   1050 <floor@plt>
movslq %eax,%rcx
mov    0xc(%rsp),%edx
cmp    %edx,0x10(%rsp,%rcx,4)
jl     11b0 <main+0x80>
jle    11e8 <main+0xb8>
add    $0xffffffff,%eax
mov    %eax,%r15d
cmp    %r15d,%ebx
jle    11ba <main+0x8a>
jmp    11f6 <main+0xc6>
lea    0xe18(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0xfb8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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