#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
main() {
  int i, n, l, h, m, key, f = 0;
  scanf("%d", &n);
  int a[n];
  for (i = 0; i < n; i++)
    scanf("%d", &a[i]);
  scanf("%d", &key);
  l = 0;
  h = n - 1;
  while (l <= h) {
    m = (l + h) / 2;
    if (a[m] == key) {
      printf("Key is at %d position", m + 1);
      f = 1;
      break;
    } else if (a[m] > key)
      h = m - 1;
    else if (a[m] < key)
      l = m + 1;
  }
  if (f == 0)
    printf("Not found");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x20(%rbp)
lea    0xec3(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0xc(%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,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a9 <main+0x89>
mov    -0x38(%rbp),%rsi
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe6a(%rip),%rdi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1174 <main+0x54>
lea    0xe50(%rip),%rdi
lea    -0x1c(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     126a <main+0x14a>
mov    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,-0x18(%rbp)
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x1c(%rbp),%eax
jne    121c <main+0xfc>
mov    -0x18(%rbp),%esi
add    $0x1,%esi
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x20(%rbp)
jmp    126a <main+0x14a>
mov    -0x38(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x1c(%rbp),%eax
jle    123e <main+0x11e>
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1260 <main+0x140>
mov    -0x38(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x1c(%rbp),%eax
jge    125b <main+0x13b>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1260 <main+0x140>
jmp    1265 <main+0x145>
jmp    11c9 <main+0xa9>
cmpl   $0x0,-0x20(%rbp)
jne    1282 <main+0x162>
lea    0xd9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@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    0xecb(%rip),%rdi
lea    -0x2c(%rbp),%rsi
call   1040 <scanf@plt>
mov    %rsp,%r15
mov    -0x2c(%rbp),%eax
mov    %rsp,%r12
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
cmpl   $0x0,-0x2c(%rbp)
jle    118c <main+0x6c>
xor    %r13d,%r13d
lea    0xe97(%rip),%r14
mov    %r12,%rbx
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <scanf@plt>
add    $0x1,%r13
movslq -0x2c(%rbp),%rax
add    $0x4,%rbx
cmp    %rax,%r13
jl     1170 <main+0x50>
lea    0xe6d(%rip),%rdi
lea    -0x30(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x2c(%rbp),%eax
test   %eax,%eax
jle    11de <main+0xbe>
add    $0xffffffff,%eax
xor    %edx,%edx
mov    -0x30(%rbp),%ecx
nopl   0x0(%rax,%rax,1)
lea    (%rdx,%rax,1),%edi
mov    %edi,%esi
shr    $0x1f,%esi
add    %edi,%esi
sar    %esi
movslq %esi,%rdi
mov    (%r12,%rdi,4),%edi
cmp    %ecx,%edi
je     11ee <main+0xce>
lea    -0x1(%rsi),%ebx
add    $0x1,%esi
cmp    %ecx,%edi
cmovge %edx,%esi
cmovg  %ebx,%eax
cmovg  %edx,%esi
mov    %esi,%edx
cmp    %eax,%esi
jle    11b0 <main+0x90>
lea    0xe34(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11ff <main+0xdf>
add    $0x1,%esi
lea    0xe0b(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15,%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 = [22 x i8] c"Key is at %d position\00"
@.str.2 = [10 x i8] c"Not 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 i32
%9 = alloca i8*
%10 = alloca i64
store i32 0, i32* %1
store i32 0, i32* %8
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%12 = load i32, i32* %3
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %9
%15 = alloca i32, i64 %13
store i64 %13, i64* %10
store i32 0, i32* %2
br label %16
16: ; preds = %25, %0
%17 = load i32, i32* %2
%18 = load i32, i32* %3
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %28
20: ; preds = %16
%21 = load i32, i32* %2
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %15, i64 %22
%24 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %23)
br label %25
25: ; preds = %20
%26 = load i32, i32* %2
%27 = add nsw i32 %26, 1
store i32 %27, i32* %2
br label %16
28: ; preds = %16
%29 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %7)
store i32 0, i32* %4
%30 = load i32, i32* %3
%31 = sub nsw i32 %30, 1
store i32 %31, i32* %5
br label %32
32: ; preds = %73, %28
%33 = load i32, i32* %4
%34 = load i32, i32* %5
%35 = icmp sle i32 %33, %34
br i1 %35, label %36, label %74
36: ; preds = %32
%37 = load i32, i32* %4
%38 = load i32, i32* %5
%39 = add nsw i32 %37, %38
%40 = sdiv i32 %39, 2
store i32 %40, i32* %6
%41 = load i32, i32* %6
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i32, i32* %15, i64 %42
%44 = load i32, i32* %43
%45 = load i32, i32* %7
%46 = icmp eq i32 %44, %45
br i1 %46, label %47, label %51
47: ; preds = %36
%48 = load i32, i32* %6
%49 = add nsw i32 %48, 1
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %49)
store i32 1, i32* %8
br label %74
51: ; preds = %36
%52 = load i32, i32* %6
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i32, i32* %15, i64 %53
%55 = load i32, i32* %54
%56 = load i32, i32* %7
%57 = icmp sgt i32 %55, %56
br i1 %57, label %58, label %61
58: ; preds = %51
%59 = load i32, i32* %6
%60 = sub nsw i32 %59, 1
store i32 %60, i32* %5
br label %72
61: ; preds = %51
%62 = load i32, i32* %6
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i32, i32* %15, i64 %63
%65 = load i32, i32* %64
%66 = load i32, i32* %7
%67 = icmp slt i32 %65, %66
br i1 %67, label %68, label %71
68: ; preds = %61
%69 = load i32, i32* %6
%70 = add nsw i32 %69, 1
store i32 %70, i32* %4
br label %71
71: ; preds = %68, %61
br label %72
72: ; preds = %71, %58
br label %73
73: ; preds = %72
br label %32
74: ; preds = %47, %32
%75 = load i32, i32* %8
%76 = icmp eq i32 %75, 0
br i1 %76, label %77, label %79
77: ; preds = %74
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %79
79: ; preds = %77, %74
%80 = load i8*, i8** %9
%81 = load i32, i32* %1
ret i32 %81
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [22 x i8] c"Key is at %d position\00"
@.str.2 = [10 x i8] c"Not 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* %1)
%6 = load i32, i32* %1
%7 = zext i32 %6 to i64
%8 = call i8* @llvm.stacksave()
%9 = alloca i32, i64 %7
%10 = load i32, i32* %1
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %20
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* %1
%18 = sext i32 %17 to i64
%19 = icmp slt i64 %16, %18
br i1 %19, label %12, label %20
20: ; preds = %12, %0
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%22 = load i32, i32* %1
%23 = icmp slt i32 %22, 1
br i1 %23, label %48, label %24
24: ; preds = %20
%25 = add nsw i32 %22, -1
%26 = load i32, i32* %2
br label %27
27: ; preds = %24, %39
%28 = phi i32 [ 0, %24 ], [ %46, %39 ]
%29 = phi i32 [ %25, %24 ], [ %45, %39 ]
%30 = add nsw i32 %28, %29
%31 = sdiv i32 %30, 2
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %9, i64 %32
%34 = load i32, i32* %33
%35 = icmp eq i32 %34, %26
br i1 %35, label %36, label %39
36: ; preds = %27
%37 = add nsw i32 %31, 1
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %37)
br label %50
39: ; preds = %27
%40 = icmp sgt i32 %34, %26
%41 = add nsw i32 %31, -1
%42 = icmp slt i32 %34, %26
%43 = add nsw i32 %31, 1
%44 = select i1 %42, i32 %43, i32 %28
%45 = select i1 %40, i32 %41, i32 %29
%46 = select i1 %40, i32 %28, i32 %44
%47 = icmp sgt i32 %46, %45
br i1 %47, label %48, label %27
48: ; preds = %39, %20
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %50
50: ; preds = %36, %48
ret i32 0
}