#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 iaArr[100], iKey, iNum, i, iLow, iMid, iHigh, iProbe;
  printf("\nEnter the number of elements\n");
  scanf("%d", &iNum);
  printf("\nEnter %d elements in ascending order\n", iNum);
  for (i = 0; i < iNum; i++) {
    scanf("%d", &iaArr[i]);
  }
  printf("\nEnter the key element\n");
  scanf("%d", &iKey);
  iLow = 0;
  iHigh = iNum - 1;
  iProbe = 0;
  while (iLow <= iHigh) {
    iProbe++;
    iMid = (iLow + iHigh) / 2;
    if (iKey == iaArr[iMid]) {
      printf("\nElement %d found at %d position\n", iKey, iMid + 1);
      break;
    } else if (iKey < iaArr[iMid])
      iHigh = iMid - 1;
    else
      iLow = iMid + 1;
  }
  if (iLow > iHigh)
    printf("\nElement not found\n");
  printf("\nTotal number of probes required is %d\n", iProbe);
  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    0xed8(%rip),%rdi
lea    -0x1a8(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x1a8(%rbp),%esi
lea    0xec2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1ac(%rbp)
mov    -0x1ac(%rbp),%eax
cmp    -0x1a8(%rbp),%eax
jge    11b8 <main+0x98>
movslq -0x1ac(%rbp),%rax
lea    -0x1a0(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe80(%rip),%rdi
call   1040 <scanf@plt>
mov    -0x1ac(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1ac(%rbp)
jmp    1171 <main+0x51>
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe52(%rip),%rdi
lea    -0x1a4(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0x1b0(%rbp)
mov    -0x1a8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1b8(%rbp)
movl   $0x0,-0x1bc(%rbp)
mov    -0x1b0(%rbp),%eax
cmp    -0x1b8(%rbp),%eax
jg     12ba <main+0x19a>
mov    -0x1bc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1bc(%rbp)
mov    -0x1b0(%rbp),%eax
add    -0x1b8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1b4(%rbp)
mov    -0x1a4(%rbp),%eax
movslq -0x1b4(%rbp),%rcx
cmp    -0x1a0(%rbp,%rcx,4),%eax
jne    1273 <main+0x153>
mov    -0x1a4(%rbp),%esi
mov    -0x1b4(%rbp),%edx
add    $0x1,%edx
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12ba <main+0x19a>
mov    -0x1a4(%rbp),%eax
movslq -0x1b4(%rbp),%rcx
cmp    -0x1a0(%rbp,%rcx,4),%eax
jge    12a1 <main+0x181>
mov    -0x1b4(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1b8(%rbp)
jmp    12b0 <main+0x190>
mov    -0x1b4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1b0(%rbp)
jmp    12b5 <main+0x195>
jmp    11fc <main+0xdc>
mov    -0x1b0(%rbp),%eax
cmp    -0x1b8(%rbp),%eax
jle    12da <main+0x1ba>
lea    0xdb0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1bc(%rbp),%esi
lea    0xdb0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x1c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x1a8,%rsp
lea    0xf30(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb0(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x8(%rsp),%esi
lea    0xe9e(%rip),%rdi
xor    %r15d,%r15d
xor    %eax,%eax
call   1040 <printf@plt>
cmpl   $0x0,0x8(%rsp)
jle    11ad <main+0x7d>
lea    0x10(%rsp),%rbx
xor    %ebp,%ebp
lea    0xe7c(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
add    $0x1,%rbp
movslq 0x8(%rsp),%rax
add    $0x4,%rbx
cmp    %rax,%rbp
jl     1190 <main+0x60>
lea    0xede(%rip),%rdi
call   1030 <puts@plt>
lea    0xe40(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x8(%rsp),%eax
test   %eax,%eax
jle    120d <main+0xdd>
add    $0xffffffff,%eax
xor    %r15d,%r15d
mov    0xc(%rsp),%esi
xor    %ecx,%ecx
jmp    11ed <main+0xbd>
add    $0x1,%edx
mov    %edx,%ecx
add    $0x1,%r15d
cmp    %eax,%ecx
jg     120d <main+0xdd>
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    %edi,%esi
je     121b <main+0xeb>
jge    11e0 <main+0xb0>
add    $0xffffffff,%edx
mov    %edx,%eax
jmp    11e5 <main+0xb5>
lea    0xe95(%rip),%rdi
call   1030 <puts@plt>
jmp    1230 <main+0x100>
add    $0x1,%edx
lea    0xe05(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r15d
lea    0xe15(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x1a8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [39 x i8] c"\0AEnter %d elements in ascending order\0A\00"
@.str.4 = [34 x i8] c"\0AElement %d found at %d position\0A\00"
@.str.6 = [40 x i8] c"\0ATotal number of probes required is %d\0A\00"
@str = [30 x i8] c"\0AEnter the number of elements\00"
@str.7 = [23 x i8] c"\0AEnter the key element\00"
@str.8 = [19 x i8] c"\0AElement not 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 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 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* %3)
%9 = load i32, i32* %3
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%11 = load i32, i32* %3
%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* %3
%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 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.7, i64 0, i64 0))
%23 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%24 = load i32, i32* %3
%25 = icmp slt i32 %24, 1
br i1 %25, label %50, label %26
26: ; preds = %21
%27 = add nsw i32 %24, -1
%28 = load i32, i32* %2
br label %29
29: ; preds = %26, %40
%30 = phi i32 [ 0, %26 ], [ %33, %40 ]
%31 = phi i32 [ %27, %26 ], [ %45, %40 ]
%32 = phi i32 [ 0, %26 ], [ %44, %40 ]
%33 = add nuw nsw i32 %30, 1
%34 = add nsw i32 %31, %32
%35 = sdiv i32 %34, 2
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 %36
%38 = load i32, i32* %37
%39 = icmp eq i32 %28, %38
br i1 %39, label %47, label %40
40: ; preds = %29
%41 = icmp slt i32 %28, %38
%42 = add nsw i32 %35, -1
%43 = add nsw i32 %35, 1
%44 = select i1 %41, i32 %32, i32 %43
%45 = select i1 %41, i32 %42, i32 %31
%46 = icmp sgt i32 %44, %45
br i1 %46, label %50, label %29
47: ; preds = %29
%48 = add nsw i32 %35, 1
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i32 %28, i32 %48)
br label %53
50: ; preds = %40, %21
%51 = phi i32 [ 0, %21 ], [ %33, %40 ]
%52 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.8, i64 0, i64 0))
br label %53
53: ; preds = %47, %50
%54 = phi i32 [ %51, %50 ], [ %33, %47 ]
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0), i32 %54)
ret i32 0
}