#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 *);
int main() {
  int a[10], i, n, m, c = 0, l, u, mid;
  printf("Enter the size of an array: ");
  scanf("%d", &n);
  printf("Enter the elements in ascending order: ");
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  printf("Enter the number to be search: ");
  scanf("%d", &m);
  l = 0, u = n - 1;
  while (l <= u) {
    mid = (l + u) / 2;
    if (m == a[mid]) {
      c = 1;
      break;
    } else if (m < a[mid]) {
      u = mid - 1;
    } else
      l = mid + 1;
  }
  if (c == 0)
    printf("The number is not found.");
  else
    printf("The number is found.");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x40(%rbp)
lea    0xec3(%rip),%rdi
call   1030 <printf@plt>
lea    0xed4(%rip),%rdi
lea    -0x38(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xec7(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x38(%rbp),%eax
jge    119a <main+0x7a>
movslq -0x34(%rbp),%rax
lea    -0x30(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe96(%rip),%rdi
call   1040 <scanf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1165 <main+0x45>
lea    0xea7(%rip),%rdi
call   1030 <printf@plt>
lea    0xe70(%rip),%rdi
lea    -0x3c(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0x44(%rbp)
mov    -0x38(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x48(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x48(%rbp),%eax
jg     1232 <main+0x112>
mov    -0x44(%rbp),%eax
add    -0x48(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4c(%rbp)
mov    -0x3c(%rbp),%eax
movslq -0x4c(%rbp),%rcx
cmp    -0x30(%rbp,%rcx,4),%eax
jne    1200 <main+0xe0>
movl   $0x1,-0x40(%rbp)
jmp    1232 <main+0x112>
mov    -0x3c(%rbp),%eax
movslq -0x4c(%rbp),%rcx
cmp    -0x30(%rbp,%rcx,4),%eax
jge    121f <main+0xff>
mov    -0x4c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    1228 <main+0x108>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    122d <main+0x10d>
jmp    11c6 <main+0xa6>
cmpl   $0x0,-0x40(%rbp)
jne    124d <main+0x12d>
lea    0xe25(%rip),%rdi
call   1030 <printf@plt>
jmp    1259 <main+0x139>
lea    0xe2d(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x40,%rsp
lea    0xed0(%rip),%rdi
call   1030 <printf@plt>
lea    0xee1(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1040 <scanf@plt>
lea    0xed3(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x0,0x8(%rsp)
jle    118d <main+0x6d>
lea    0x10(%rsp),%r15
xor    %ebx,%ebx
lea    0xeb6(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <scanf@plt>
add    $0x1,%rbx
movslq 0x8(%rsp),%rax
add    $0x4,%r15
cmp    %rax,%rbx
jl     1170 <main+0x50>
lea    0xeb4(%rip),%rdi
call   1030 <printf@plt>
lea    0xe7d(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1040 <scanf@plt>
mov    0x8(%rsp),%eax
lea    0xeb3(%rip),%rdi
test   %eax,%eax
jle    1200 <main+0xe0>
add    $0xffffffff,%eax
xor    %esi,%esi
mov    0xc(%rsp),%edx
lea    0xeb8(%rip),%r8
jmp    11d9 <main+0xb9>
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebx
mov    %ebx,%esi
cmp    %eax,%esi
jg     1200 <main+0xe0>
lea    (%rax,%rsi,1),%ecx
mov    %ecx,%ebx
shr    $0x1f,%ebx
add    %ecx,%ebx
sar    %ebx
movslq %ebx,%rcx
mov    0x10(%rsp,%rcx,4),%ecx
cmp    %ecx,%edx
je     11fd <main+0xdd>
jge    11d0 <main+0xb0>
add    $0xffffffff,%ebx
mov    %ebx,%eax
cmp    %eax,%esi
jle    11d9 <main+0xb9>
jmp    1200 <main+0xe0>
mov    %r8,%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [29 x i8] c"Enter the size of an array: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [40 x i8] c"Enter the elements in ascending order: \00"
@.str.3 = [32 x i8] c"Enter the number to be search: \00"
@.str.4 = [25 x i8] c"The number is not found.\00"
@.str.5 = [21 x i8] c"The number is found.\00"
define i32 @main() {
%1 = alloca [10 x i32]
%2 = alloca i32
%3 = alloca i32
%4 = bitcast [10 x i32]* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%9 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
%10 = load i32, i32* %2
%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 [10 x i32], [10 x i32]* %1, i64 0, i64 %13
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, 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 %16, %18
br i1 %19, label %12, label %20
20: ; preds = %12, %0
%21 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
%22 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%23 = load i32, i32* %2
%24 = icmp slt i32 %23, 1
br i1 %24, label %44, label %25
25: ; preds = %20
%26 = add nsw i32 %23, -1
%27 = load i32, i32* %3
br label %28
28: ; preds = %25, %37
%29 = phi i32 [ %26, %25 ], [ %42, %37 ]
%30 = phi i32 [ 0, %25 ], [ %41, %37 ]
%31 = add nsw i32 %29, %30
%32 = sdiv i32 %31, 2
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 %33
%35 = load i32, i32* %34
%36 = icmp eq i32 %27, %35
br i1 %36, label %44, label %37
37: ; preds = %28
%38 = icmp slt i32 %27, %35
%39 = add nsw i32 %32, -1
%40 = add nsw i32 %32, 1
%41 = select i1 %38, i32 %30, i32 %40
%42 = select i1 %38, i32 %39, i32 %29
%43 = icmp sgt i32 %41, %42
br i1 %43, label %44, label %28
44: ; preds = %28, %37, %20
%45 = phi i8* [ getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), %20 ], [ getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), %37 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), %28 ]
%46 = call i32 @printf(i8* dereferenceable(1) %45)
ret i32 0
}