#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 *, ...);
scalar_t__ scanf(char *, int *);
int main(void) {
  int arr[100];
  int num, key, beg, mid, last, pos = -1;
  printf("Enter number of elements: ");
  if (scanf("%d", &num) != 0) {
    for (size_t i = 0; i < num; i++) {
      if (scanf("%d", &arr[i]) != 0) {
      } else {
        printf("Please enter appropriate input!");
        goto end;
      }
    }
  } else {
    printf("Please enter appropriate input!");
    goto end;
  }
  printf("Enter number to search: ");
  if (scanf("%d", &key) != 0) {
    beg = 0;
    last = num - 1;
    while (beg <= last) {
      mid = (beg + last) / 2;
      if (key == arr[mid]) {
        pos = mid - 1;
        break;
      } else if (key >= arr[mid]) {
        beg = mid + 1;
      } else
        last = mid - 1;
    }
    if (pos == -1) {
      printf("Not found");
    } else {
      printf("The number %d is found", key);
    }
  } else {
    printf("Please enter appropriate input!");
    goto end;
  }
end:
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1c0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xffffffff,-0x1b8(%rbp)
ff ff ff
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeca(%rip),%rdi
lea    -0x1a4(%rbp),%rsi
call   1040 <scanf@plt>
cmp    $0x0,%rax
je     11ed <main+0xcd>
movq   $0x0,-0x1c0(%rbp)
mov    -0x1c0(%rbp),%rax
movslq -0x1a4(%rbp),%rcx
cmp    %rcx,%rax
jae    11e8 <main+0xc8>
mov    -0x1c0(%rbp),%rax
lea    -0x1a0(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe76(%rip),%rdi
call   1040 <scanf@plt>
cmp    $0x0,%rax
je     11b9 <main+0x99>
jmp    11cc <main+0xac>
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1336 <main+0x216>
jmp    11d1 <main+0xb1>
mov    -0x1c0(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x1c0(%rbp)
jmp    1172 <main+0x52>
jmp    1200 <main+0xe0>
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1336 <main+0x216>
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe06(%rip),%rdi
lea    -0x1a8(%rbp),%rsi
call   1040 <scanf@plt>
cmp    $0x0,%rax
je     131e <main+0x1fe>
movl   $0x0,-0x1ac(%rbp)
mov    -0x1a4(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1b4(%rbp)
mov    -0x1ac(%rbp),%eax
cmp    -0x1b4(%rbp),%eax
jg     12e5 <main+0x1c5>
mov    -0x1ac(%rbp),%eax
add    -0x1b4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1b0(%rbp)
mov    -0x1a8(%rbp),%eax
movslq -0x1b0(%rbp),%rcx
cmp    -0x1a0(%rbp,%rcx,4),%eax
jne    129e <main+0x17e>
mov    -0x1b0(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1b8(%rbp)
jmp    12e5 <main+0x1c5>
mov    -0x1a8(%rbp),%eax
movslq -0x1b0(%rbp),%rcx
cmp    -0x1a0(%rbp,%rcx,4),%eax
jl     12cc <main+0x1ac>
mov    -0x1b0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1ac(%rbp)
jmp    12db <main+0x1bb>
mov    -0x1b0(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1b4(%rbp)
jmp    12e0 <main+0x1c0>
jmp    1244 <main+0x124>
cmpl   $0xffffffff,-0x1b8(%rbp)
jne    1305 <main+0x1e5>
lea    0xd5e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1319 <main+0x1f9>
mov    -0x1a8(%rbp),%esi
lea    0xd4f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1331 <main+0x211>
lea    0xcf9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1336 <main+0x216>
jmp    1336 <main+0x216>
xor    %eax,%eax
add    $0x1c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x1a0,%rsp
lea    0xecd(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeda(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1040 <scanf@plt>
test   %rax,%rax
je     11fd <main+0xdd>
cmpl   $0x0,0x8(%rsp)
je     1192 <main+0x72>
lea    0x10(%rsp),%r15
xor    %ebx,%ebx
lea    0xeb2(%rip),%r14
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <scanf@plt>
test   %rax,%rax
je     11fd <main+0xdd>
add    $0x1,%rbx
movslq 0x8(%rsp),%rax
add    $0x4,%r15
cmp    %rax,%rbx
jb     1170 <main+0x50>
lea    0xea5(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe74(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1040 <scanf@plt>
test   %rax,%rax
je     11fd <main+0xdd>
mov    0x8(%rsp),%eax
test   %eax,%eax
jle    120e <main+0xee>
add    $0xffffffff,%eax
xor    %ecx,%ecx
mov    0xc(%rsp),%esi
jmp    11d9 <main+0xb9>
nopl   0x0(%rax)
add    $0x1,%edx
mov    %edx,%ecx
cmp    %eax,%ecx
jg     120e <main+0xee>
lea    (%rax,%rcx,1),%edi
mov    %edi,%edx
shr    $0x1f,%edx
add    %edi,%edx
sar    %edx
movslq %edx,%rbx
mov    0x10(%rsp,%rbx,4),%ebx
cmp    %ebx,%esi
je     1206 <main+0xe6>
jge    11d0 <main+0xb0>
add    $0xffffffff,%edx
mov    %edx,%eax
cmp    %eax,%ecx
jle    11d9 <main+0xb9>
jmp    120e <main+0xee>
lea    0xe1a(%rip),%rdi
jmp    1215 <main+0xf5>
add    $0x1,%edi
cmp    $0x3,%edi
jae    122b <main+0x10b>
lea    0xe42(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x1a0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe2f(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    121c <main+0xfc>

LLVM IR (-O0):
@.str = [27 x i8] c"Enter number of elements: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [32 x i8] c"Please enter appropriate input!\00"
@.str.3 = [25 x i8] c"Enter number to search: \00"
@.str.4 = [10 x i8] c"Not found\00"
@.str.5 = [23 x i8] c"The number %d is found\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
store i32 0, i32* %1
store i32 -1, i32* %8
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%11 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %32
13: ; preds = %0
store i64 0, i64* %9
br label %14
14: ; preds = %28, %13
%15 = load i64, i64* %9
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = icmp ult i64 %15, %17
br i1 %18, label %19, label %31
19: ; preds = %14
%20 = load i64, i64* %9
%21 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %20
%22 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %19
br label %27
25: ; preds = %19
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %86
27: ; preds = %24
br label %28
28: ; preds = %27
%29 = load i64, i64* %9
%30 = add i64 %29, 1
store i64 %30, i64* %9
br label %14
31: ; preds = %14
br label %34
32: ; preds = %0
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %86
34: ; preds = %31
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%36 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %83
38: ; preds = %34
store i32 0, i32* %5
%39 = load i32, i32* %3
%40 = sub nsw i32 %39, 1
store i32 %40, i32* %7
br label %41
41: ; preds = %73, %38
%42 = load i32, i32* %5
%43 = load i32, i32* %7
%44 = icmp sle i32 %42, %43
br i1 %44, label %45, label %74
45: ; preds = %41
%46 = load i32, i32* %5
%47 = load i32, i32* %7
%48 = add nsw i32 %46, %47
%49 = sdiv i32 %48, 2
store i32 %49, i32* %6
%50 = load i32, i32* %4
%51 = load i32, i32* %6
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %52
%54 = load i32, i32* %53
%55 = icmp eq i32 %50, %54
br i1 %55, label %56, label %59
56: ; preds = %45
%57 = load i32, i32* %6
%58 = sub nsw i32 %57, 1
store i32 %58, i32* %8
br label %74
59: ; preds = %45
%60 = load i32, i32* %4
%61 = load i32, i32* %6
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %62
%64 = load i32, i32* %63
%65 = icmp sge i32 %60, %64
br i1 %65, label %66, label %69
66: ; preds = %59
%67 = load i32, i32* %6
%68 = add nsw i32 %67, 1
store i32 %68, i32* %5
br label %72
69: ; preds = %59
%70 = load i32, i32* %6
%71 = sub nsw i32 %70, 1
store i32 %71, i32* %7
br label %72
72: ; preds = %69, %66
br label %73
73: ; preds = %72
br label %41
74: ; preds = %56, %41
%75 = load i32, i32* %8
%76 = icmp eq i32 %75, -1
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.4, i64 0, i64 0))
br label %82
79: ; preds = %74
%80 = load i32, i32* %4
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %80)
br label %82
82: ; preds = %79, %77
br label %85
83: ; preds = %34
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %86
85: ; preds = %82
br label %86
86: ; preds = %85, %83, %32, %25
ret i32 0
}

LLVM IR (-O2):
@.str = [27 x i8] c"Enter number of elements: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [32 x i8] c"Please enter appropriate input!\00"
@.str.3 = [25 x i8] c"Enter number to search: \00"
@.str.4 = [10 x i8] c"Not found\00"
@.str.5 = [23 x i8] c"The number %d is found\00"
define i32 @main() {
%1 = alloca [100 x i32]
%2 = alloca i32
%3 = alloca i32
%4 = bitcast [100 x i32]* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%8 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%9 = icmp eq i64 %8, 0
br i1 %9, label %25, label %10
10: ; preds = %0
%11 = load i32, i32* %2
%12 = icmp eq i32 %11, 0
br i1 %12, label %27, label %17
13: ; preds = %17
%14 = load i32, i32* %2
%15 = sext i32 %14 to i64
%16 = icmp ult i64 %22, %15
br i1 %16, label %17, label %27
17: ; preds = %10, %13
%18 = phi i64 [ %22, %13 ], [ 0, %10 ]
%19 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 %18
%20 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %19)
%21 = icmp eq i64 %20, 0
%22 = add nuw i64 %18, 1
br i1 %21, label %23, label %13
23: ; preds = %17
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %62
25: ; preds = %0
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %62
27: ; preds = %13, %10
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%29 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%30 = icmp eq i64 %29, 0
br i1 %30, label %60, label %31
31: ; preds = %27
%32 = load i32, i32* %2
%33 = icmp slt i32 %32, 1
br i1 %33, label %56, label %34
34: ; preds = %31
%35 = add nsw i32 %32, -1
%36 = load i32, i32* %3
br label %37
37: ; preds = %34, %49
%38 = phi i32 [ %35, %34 ], [ %54, %49 ]
%39 = phi i32 [ 0, %34 ], [ %53, %49 ]
%40 = add nsw i32 %38, %39
%41 = sdiv i32 %40, 2
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 %42
%44 = load i32, i32* %43
%45 = icmp eq i32 %36, %44
br i1 %45, label %46, label %49
46: ; preds = %37
%47 = add i32 %40, 1
%48 = icmp ult i32 %47, 3
br i1 %48, label %56, label %58
49: ; preds = %37
%50 = icmp slt i32 %36, %44
%51 = add nsw i32 %41, 1
%52 = add nsw i32 %41, -1
%53 = select i1 %50, i32 %39, i32 %51
%54 = select i1 %50, i32 %52, i32 %38
%55 = icmp sgt i32 %53, %54
br i1 %55, label %56, label %37
56: ; preds = %49, %31, %46
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
br label %62
58: ; preds = %46
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %36)
br label %62
60: ; preds = %27
%61 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %62
62: ; preds = %23, %25, %60, %56, %58
ret i32 0
}