#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], n, i, item, flag = 0, low = 0, high, mid;
  printf("ENTER SIZE OF ARRAY :");
  scanf("%d", &n);
  printf("ENTER ARRAY IN ASCENDING ORDER \n");
  for (i = 0; i < n; ++i) {
    printf("ENTER ELEMENT %d :", i + 1);
    scanf("%d", &a[i]);
  }
  printf("ENTER THE ELEMNT TO BE SEARCHED");
  scanf("%d", &item);
  high = n;
  while (low < high) {
    mid = (high + low) / 2;
    if (item > a[mid]) {
      low = mid + 1;
    } else if (item < a[mid]) {
      high = mid - 1;
    } else {
      flag = 1;
      i = mid;
      break;
    }
  }
  if (flag == 0) {
    printf("element not found");
  } else {
    printf("ELEMENT AT %d", i + 1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
lea    0xebc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf35(%rip),%rdi
lea    -0x34(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xeb4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    11b9 <main+0x99>
mov    -0x38(%rbp),%esi
add    $0x1,%esi
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movslq -0x38(%rbp),%rax
lea    -0x30(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xee1(%rip),%rdi
call   1040 <scanf@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1170 <main+0x50>
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb9(%rip),%rdi
lea    -0x3c(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x48(%rbp),%eax
jge    1254 <main+0x134>
mov    -0x48(%rbp),%eax
add    -0x44(%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
jle    1219 <main+0xf9>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    124f <main+0x12f>
mov    -0x3c(%rbp),%eax
movslq -0x4c(%rbp),%rcx
cmp    -0x30(%rbp,%rcx,4),%eax
jge    1238 <main+0x118>
mov    -0x4c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    124a <main+0x12a>
movl   $0x1,-0x40(%rbp)
mov    -0x4c(%rbp),%eax
mov    %eax,-0x38(%rbp)
jmp    1254 <main+0x134>
jmp    124f <main+0x12f>
jmp    11dd <main+0xbd>
cmpl   $0x0,-0x40(%rbp)
jne    1271 <main+0x151>
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1285 <main+0x165>
mov    -0x38(%rbp),%esi
add    $0x1,%esi
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x38,%rsp
lea    0xebe(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xf16(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1050 <scanf@plt>
lea    0xf08(%rip),%rdi
call   1030 <puts@plt>
cmpl   $0x0,0x8(%rsp)
jle    11b9 <main+0x89>
lea    0x10(%rsp),%r12
lea    0xe9d(%rip),%r14
lea    0xee6(%rip),%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%rbx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <scanf@plt>
movslq 0x8(%rsp),%rax
add    $0x4,%r12
cmp    %rax,%rbx
jl     1190 <main+0x60>
lea    0xe69(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe96(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x8(%rsp),%ecx
test   %ecx,%ecx
jle    1219 <main+0xe9>
mov    0xc(%rsp),%eax
jmp    11f9 <main+0xc9>
nopl   0x0(%rax,%rax,1)
add    $0x1,%esi
mov    %esi,%ebx
cmp    %ecx,%ebx
jge    1219 <main+0xe9>
lea    (%rcx,%rbx,1),%edx
mov    %edx,%esi
shr    $0x1f,%esi
add    %edx,%esi
sar    %esi
movslq %esi,%rdx
cmp    0x10(%rsp,%rdx,4),%eax
jg     11f0 <main+0xc0>
jge    1229 <main+0xf9>
add    $0xffffffff,%esi
mov    %esi,%ecx
cmp    %ecx,%ebx
jl     11f9 <main+0xc9>
lea    0xe29(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    123a <main+0x10a>
add    $0x1,%esi
lea    0xe28(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [22 x i8] c"ENTER SIZE OF ARRAY :\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [33 x i8] c"ENTER ARRAY IN ASCENDING ORDER \0A\00"
@.str.3 = [19 x i8] c"ENTER ELEMENT %d :\00"
@.str.4 = [32 x i8] c"ENTER THE ELEMNT TO BE SEARCHED\00"
@.str.5 = [18 x i8] c"element not found\00"
@.str.6 = [14 x i8] c"ELEMENT AT %d\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
store i32 0, i32* %7
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 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* %3)
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %4
br label %13
13: ; preds = %25, %0
%14 = load i32, i32* %4
%15 = load i32, i32* %3
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %28
17: ; preds = %13
%18 = load i32, i32* %4
%19 = add nsw i32 %18, 1
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %19)
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %22
%24 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %23)
br label %25
25: ; preds = %17
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 1
store i32 %27, i32* %4
br label %13
28: ; preds = %13
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
%30 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
%31 = load i32, i32* %3
store i32 %31, i32* %8
br label %32
32: ; preds = %63, %28
%33 = load i32, i32* %7
%34 = load i32, i32* %8
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %64
36: ; preds = %32
%37 = load i32, i32* %8
%38 = load i32, i32* %7
%39 = add nsw i32 %37, %38
%40 = sdiv i32 %39, 2
store i32 %40, i32* %9
%41 = load i32, i32* %5
%42 = load i32, i32* %9
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %43
%45 = load i32, i32* %44
%46 = icmp sgt i32 %41, %45
br i1 %46, label %47, label %50
47: ; preds = %36
%48 = load i32, i32* %9
%49 = add nsw i32 %48, 1
store i32 %49, i32* %7
br label %63
50: ; preds = %36
%51 = load i32, i32* %5
%52 = load i32, i32* %9
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %53
%55 = load i32, i32* %54
%56 = icmp slt i32 %51, %55
br i1 %56, label %57, label %60
57: ; preds = %50
%58 = load i32, i32* %9
%59 = sub nsw i32 %58, 1
store i32 %59, i32* %8
br label %62
60: ; preds = %50
store i32 1, i32* %6
%61 = load i32, i32* %9
store i32 %61, i32* %4
br label %64
62: ; preds = %57
br label %63
63: ; preds = %62, %47
br label %32
64: ; preds = %60, %32
%65 = load i32, i32* %6
%66 = icmp eq i32 %65, 0
br i1 %66, label %67, label %69
67: ; preds = %64
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
br label %73
69: ; preds = %64
%70 = load i32, i32* %4
%71 = add nsw i32 %70, 1
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i32 %71)
br label %73
73: ; preds = %69, %67
ret i32 0
}

LLVM IR (-O2):
@.str = [22 x i8] c"ENTER SIZE OF ARRAY :\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [19 x i8] c"ENTER ELEMENT %d :\00"
@.str.4 = [32 x i8] c"ENTER THE ELEMNT TO BE SEARCHED\00"
@.str.5 = [18 x i8] c"element not found\00"
@.str.6 = [14 x i8] c"ELEMENT AT %d\00"
@str = [32 x i8] c"ENTER ARRAY IN ASCENDING ORDER \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 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 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 ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
%10 = load i32, i32* %2
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %22
12: ; preds = %0, %12
%13 = phi i64 [ %14, %12 ], [ 0, %0 ]
%14 = add nuw nsw i64 %13, 1
%15 = trunc i64 %14 to i32
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %15)
%17 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 %13
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %17)
%19 = load i32, i32* %2
%20 = sext i32 %19 to i64
%21 = icmp slt i64 %14, %20
br i1 %21, label %12, label %22
22: ; preds = %12, %0
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
%24 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%25 = load i32, i32* %2
%26 = icmp sgt i32 %25, 0
br i1 %26, label %27, label %48
27: ; preds = %22
%28 = load i32, i32* %3
br label %29
29: ; preds = %27, %44
%30 = phi i32 [ %25, %27 ], [ %46, %44 ]
%31 = phi i32 [ 0, %27 ], [ %45, %44 ]
%32 = add nsw i32 %30, %31
%33 = sdiv i32 %32, 2
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 %34
%36 = load i32, i32* %35
%37 = icmp sgt i32 %28, %36
br i1 %37, label %38, label %40
38: ; preds = %29
%39 = add nsw i32 %33, 1
br label %44
40: ; preds = %29
%41 = icmp slt i32 %28, %36
br i1 %41, label %42, label %50
42: ; preds = %40
%43 = add nsw i32 %33, -1
br label %44
44: ; preds = %42, %38
%45 = phi i32 [ %39, %38 ], [ %31, %42 ]
%46 = phi i32 [ %30, %38 ], [ %43, %42 ]
%47 = icmp slt i32 %45, %46
br i1 %47, label %29, label %48
48: ; preds = %44, %22
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
br label %53
50: ; preds = %40
%51 = add nsw i32 %33, 1
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i32 %51)
br label %53
53: ; preds = %50, %48
ret i32 0
}