#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 x[100], n, m, lower, upper, mid, i, p, f;
  printf("Enter the number of elements in the array ");
  scanf("%d", &n);
  printf("Enter %d elements in the array ", n);
  for (i = 0; i < n; i++)
    scanf("%d", &x[i]);
  printf("Enter the element to be searched ");
  scanf("%d", &m);
  lower = 0;
  upper = n - 1;
  while (lower < upper) {
    mid = (lower + upper) / 2;
    if (x[mid] == m) {
      f = 1;
      p = mid + 1;
      break;
    } else if (x[mid] < m)
      lower = mid + 1;
    else
      upper = mid - 1;
  }
  if (f == 1)
    printf("Element found at position %d\n", p);
  else
    printf("Element not found\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1c0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xec7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee4(%rip),%rdi
lea    -0x1a4(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x1a4(%rbp),%esi
lea    0xece(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1b8(%rbp)
mov    -0x1b8(%rbp),%eax
cmp    -0x1a4(%rbp),%eax
jge    11b8 <main+0x98>
movslq -0x1b8(%rbp),%rax
lea    -0x1a0(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe8c(%rip),%rdi
call   1040 <scanf@plt>
mov    -0x1b8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1b8(%rbp)
jmp    1171 <main+0x51>
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe5e(%rip),%rdi
lea    -0x1a8(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0x1ac(%rbp)
mov    -0x1a4(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1b0(%rbp)
mov    -0x1ac(%rbp),%eax
cmp    -0x1b0(%rbp),%eax
jge    129d <main+0x17d>
mov    -0x1ac(%rbp),%eax
add    -0x1b0(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1b4(%rbp)
movslq -0x1b4(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%eax
cmp    -0x1a8(%rbp),%eax
jne    1256 <main+0x136>
movl   $0x1,-0x1c0(%rbp)
mov    -0x1b4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1bc(%rbp)
jmp    129d <main+0x17d>
movslq -0x1b4(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%eax
cmp    -0x1a8(%rbp),%eax
jge    1284 <main+0x164>
mov    -0x1b4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1ac(%rbp)
jmp    1293 <main+0x173>
mov    -0x1b4(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1b0(%rbp)
jmp    1298 <main+0x178>
jmp    11f2 <main+0xd2>
cmpl   $0x1,-0x1c0(%rbp)
jne    12c3 <main+0x1a3>
mov    -0x1bc(%rbp),%esi
lea    0xdb9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12d1 <main+0x1b1>
lea    0xdc4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
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    0xeea(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1040 <scanf@plt>
mov    0x8(%rsp),%esi
lea    0xed8(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
cmpl   $0x0,0x8(%rsp)
jle    119d <main+0x7d>
lea    0x10(%rsp),%r15
xor    %ebx,%ebx
lea    0xeb9(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <scanf@plt>
add    $0x1,%rbx
movslq 0x8(%rsp),%rax
add    $0x4,%r15
cmp    %rax,%rbx
jl     1180 <main+0x60>
lea    0xeaa(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe77(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1040 <scanf@plt>
mov    0x8(%rsp),%ecx
add    $0xffffffff,%ecx
mov    0xc(%rsp),%eax
mov    %ecx,%esi
shr    %esi
mov    0x10(%rsp,%rsi,4),%edx
jmp    11f8 <main+0xd8>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0xffffffff,%esi
mov    %esi,%ecx
lea    (%rbx,%rcx,1),%edx
mov    %edx,%esi
shr    $0x1f,%esi
add    %edx,%esi
sar    %esi
movslq %esi,%rdx
mov    0x10(%rsp,%rdx,4),%edx
cmp    %eax,%edx
je     1207 <main+0xe7>
cmp    %eax,%edx
jge    11e0 <main+0xc0>
add    $0x1,%esi
mov    %esi,%ebx
jmp    11e5 <main+0xc5>
add    $0x1,%esi
lea    0xe5f(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x1a0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [43 x i8] c"Enter the number of elements in the array \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [32 x i8] c"Enter %d elements in the array \00"
@.str.3 = [34 x i8] c"Enter the element to be searched \00"
@.str.4 = [30 x i8] c"Element found at position %d\0A\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 ([43 x i8], [43 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 = load i32, i32* %2
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%11 = load i32, i32* %2
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %21
13: ; preds = %0, %13
%14 = phi i64 [ %17, %13 ], [ 0, %0 ]
%15 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 %14
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %15)
%17 = add nuw nsw i64 %14, 1
%18 = load i32, i32* %2
%19 = sext i32 %18 to i64
%20 = icmp slt i64 %17, %19
br i1 %20, label %13, label %21
21: ; preds = %13, %0
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
%23 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%24 = load i32, i32* %2
%25 = add nsw i32 %24, -1
%26 = load i32, i32* %3
%27 = icmp sgt i32 %24, 1
%28 = lshr i32 %25, 1
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 %29
%31 = load i32, i32* %30
%32 = icmp eq i32 %31, %26
br i1 %32, label %33, label %37
33: ; preds = %37, %21
%34 = phi i32 [ %28, %21 ], [ %49, %37 ]
%35 = add nsw i32 %34, 1
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 %35)
ret i32 0
37: ; preds = %21, %37
%38 = phi i32 [ %52, %37 ], [ %31, %21 ]
%39 = phi i32 [ %49, %37 ], [ %28, %21 ]
%40 = phi i32 [ %46, %37 ], [ 0, %21 ]
%41 = phi i32 [ %45, %37 ], [ %25, %21 ]
%42 = icmp slt i32 %38, %26
%43 = add nsw i32 %39, 1
%44 = add nsw i32 %39, -1
%45 = select i1 %42, i32 %41, i32 %44
%46 = select i1 %42, i32 %43, i32 %40
%47 = icmp slt i32 %46, %45
%48 = add nsw i32 %46, %45
%49 = sdiv i32 %48, 2
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 %50
%52 = load i32, i32* %51
%53 = icmp eq i32 %52, %26
br i1 %53, label %33, label %37
}