#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 *);
void main() {
  int i, a[10], n, src, flg = 1, lb, ub, mid;
  printf("Enter the how mny nos......\n");
  scanf("%d", &n);
  printf("Enter the element in sorted order .......\n");
  for (i = 0; i < n; i++)
    scanf("%d", &a[i]);
  printf("Enter the searching element......\n");
  scanf("%d", &src);
  lb = 0;
  ub = n - 1;
  while (lb <= ub) {
    mid = (lb + ub) / 2;
    if (a[mid] == src) {
      printf("%d is in %d position\n", src, mid + 1);
      flg = 0;
      break;
    } else if (src < a[mid])
      ub = mid - 1;
    else
      lb = mid + 1;
  }
  if (flg)
    printf("Not found");
  printf("\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x1,-0x3c(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed9(%rip),%rdi
lea    -0x34(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xecc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    1197 <main+0x77>
movslq -0x4(%rbp),%rax
lea    -0x30(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe99(%rip),%rdi
call   1040 <scanf@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1162 <main+0x42>
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe71(%rip),%rdi
lea    -0x38(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0x40(%rbp)
mov    -0x34(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x44(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x44(%rbp),%eax
jg     1248 <main+0x128>
mov    -0x40(%rbp),%eax
add    -0x44(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x48(%rbp)
movslq -0x48(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%eax
cmp    -0x38(%rbp),%eax
jne    1216 <main+0xf6>
mov    -0x38(%rbp),%esi
mov    -0x48(%rbp),%edx
add    $0x1,%edx
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x3c(%rbp)
jmp    1248 <main+0x128>
mov    -0x38(%rbp),%eax
movslq -0x48(%rbp),%rcx
cmp    -0x30(%rbp,%rcx,4),%eax
jge    1235 <main+0x115>
mov    -0x48(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    123e <main+0x11e>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    1243 <main+0x123>
jmp    11c5 <main+0xa5>
cmpl   $0x0,-0x3c(%rbp)
je     1260 <main+0x140>
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xde2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x40,%rsp
lea    0xed3(%rip),%rdi
call   1040 <puts@plt>
lea    0xea4(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1060 <scanf@plt>
lea    0xed2(%rip),%rdi
call   1040 <puts@plt>
cmpl   $0x0,0x8(%rsp)
jle    11ad <main+0x6d>
lea    0x10(%rsp),%r15
xor    %ebx,%ebx
lea    0xe79(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <scanf@plt>
add    $0x1,%rbx
movslq 0x8(%rsp),%rax
add    $0x4,%r15
cmp    %rax,%rbx
jl     1190 <main+0x50>
lea    0xeb5(%rip),%rdi
call   1040 <puts@plt>
lea    0xe40(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
mov    0x8(%rsp),%eax
test   %eax,%eax
jle    120b <main+0xcb>
add    $0xffffffff,%eax
xor    %ecx,%ecx
mov    0xc(%rsp),%esi
jmp    11e9 <main+0xa9>
nopl   (%rax)
add    $0x1,%edx
mov    %edx,%ecx
cmp    %eax,%ecx
jg     120b <main+0xcb>
lea    (%rax,%rcx,1),%edi
mov    %edi,%edx
shr    $0x1f,%edx
add    %edi,%edx
sar    %edx
movslq %edx,%rdi
mov    0x10(%rsp,%rdi,4),%edi
cmp    %esi,%edi
je     121b <main+0xdb>
jle    11e0 <main+0xa0>
add    $0xffffffff,%edx
mov    %edx,%eax
cmp    %eax,%ecx
jle    11e9 <main+0xa9>
lea    0xe07(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    122c <main+0xec>
add    $0x1,%edx
lea    0xdde(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [29 x i8] c"Enter the how mny nos......\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [43 x i8] c"Enter the element in sorted order .......\0A\00"
@.str.3 = [35 x i8] c"Enter the searching element......\0A\00"
@.str.4 = [22 x i8] c"%d is in %d position\0A\00"
@.str.5 = [10 x i8] c"Not found\00"
@.str.6 = [2 x i8] c"\0A\00"
define void @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
store i32 1, i32* %5
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %12
12: ; preds = %21, %0
%13 = load i32, i32* %1
%14 = load i32, i32* %3
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %24
16: ; preds = %12
%17 = load i32, i32* %1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %18
%20 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %19)
br label %21
21: ; preds = %16
%22 = load i32, i32* %1
%23 = add nsw i32 %22, 1
store i32 %23, i32* %1
br label %12
24: ; preds = %12
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
%26 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
store i32 0, i32* %6
%27 = load i32, i32* %3
%28 = sub nsw i32 %27, 1
store i32 %28, i32* %7
br label %29
29: ; preds = %63, %24
%30 = load i32, i32* %6
%31 = load i32, i32* %7
%32 = icmp sle i32 %30, %31
br i1 %32, label %33, label %64
33: ; preds = %29
%34 = load i32, i32* %6
%35 = load i32, i32* %7
%36 = add nsw i32 %34, %35
%37 = sdiv i32 %36, 2
store i32 %37, i32* %8
%38 = load i32, i32* %8
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %39
%41 = load i32, i32* %40
%42 = load i32, i32* %4
%43 = icmp eq i32 %41, %42
br i1 %43, label %44, label %49
44: ; preds = %33
%45 = load i32, i32* %4
%46 = load i32, i32* %8
%47 = add nsw i32 %46, 1
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 %45, i32 %47)
store i32 0, i32* %5
br label %64
49: ; preds = %33
%50 = load i32, i32* %4
%51 = load i32, i32* %8
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %52
%54 = load i32, i32* %53
%55 = icmp slt i32 %50, %54
br i1 %55, label %56, label %59
56: ; preds = %49
%57 = load i32, i32* %8
%58 = sub nsw i32 %57, 1
store i32 %58, i32* %7
br label %62
59: ; preds = %49
%60 = load i32, i32* %8
%61 = add nsw i32 %60, 1
store i32 %61, i32* %6
br label %62
62: ; preds = %59, %56
br label %63
63: ; preds = %62
br label %29
64: ; preds = %44, %29
%65 = load i32, i32* %5
%66 = icmp ne i32 %65, 0
br i1 %66, label %67, label %69
67: ; preds = %64
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
br label %69
69: ; preds = %67, %64
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.4 = [22 x i8] c"%d is in %d position\0A\00"
@.str.5 = [10 x i8] c"Not found\00"
@str = [28 x i8] c"Enter the how mny nos......\00"
@str.7 = [42 x i8] c"Enter the element in sorted order .......\00"
@str.8 = [34 x i8] c"Enter the searching element......\00"
define void @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 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 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 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.7, 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 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.8, 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 %47, label %25
25: ; preds = %20
%26 = add nsw i32 %23, -1
%27 = load i32, i32* %3
br label %28
28: ; preds = %25, %40
%29 = phi i32 [ %26, %25 ], [ %45, %40 ]
%30 = phi i32 [ 0, %25 ], [ %44, %40 ]
%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 %35, %27
br i1 %36, label %37, label %40
37: ; preds = %28
%38 = add nsw i32 %32, 1
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 %27, i32 %38)
br label %49
40: ; preds = %28
%41 = icmp slt i32 %27, %35
%42 = add nsw i32 %32, -1
%43 = add nsw i32 %32, 1
%44 = select i1 %41, i32 %30, i32 %43
%45 = select i1 %41, i32 %42, i32 %29
%46 = icmp sgt i32 %44, %45
br i1 %46, label %47, label %28
47: ; preds = %40, %20
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
br label %49
49: ; preds = %37, %47
%50 = call i32 @putchar(i32 10)
ret void
}