#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 c, first, last, middle, n, search, array[100];
  printf("\nenterthe no of element ");
  scanf("%d", &n);
  printf("\nenter the %d integers ", n);
  for (c = 0; c < n; ++c) {
    scanf("%d", &array[c]);
  }
  printf("Enter the value to find \n");
  scanf("%d", &search);
  first = 0;
  last = n - 1;
  middle = (first + last) / 2;
  while (first <= last) {
    if (array[middle] < search) {
      first = middle + 1;
    } else if (array[middle] == search) {
      printf("%d found at location %d\n", search, middle + 1);
      break;
    } else
      last = middle + 1;
    middle = (first + last) / 2;
  }
  if (first > last) {
    printf("Not found \n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1b0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xec7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed2(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x18(%rbp),%esi
lea    0xec2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11a0 <main+0x80>
movslq -0x8(%rbp),%rax
lea    -0x1b0(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe8c(%rip),%rdi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1168 <main+0x48>
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe64(%rip),%rdi
lea    -0x1c(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     1261 <main+0x141>
movslq -0x14(%rbp),%rax
mov    -0x1b0(%rbp,%rax,4),%eax
cmp    -0x1c(%rbp),%eax
jge    120d <main+0xed>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    124b <main+0x12b>
movslq -0x14(%rbp),%rax
mov    -0x1b0(%rbp,%rax,4),%eax
cmp    -0x1c(%rbp),%eax
jne    123d <main+0x11d>
mov    -0x1c(%rbp),%esi
mov    -0x14(%rbp),%edx
add    $0x1,%edx
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1261 <main+0x141>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    124b <main+0x12b>
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
jmp    11df <main+0xbf>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jle    127b <main+0x15b>
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x1b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x1a0,%rsp
lea    0xebd(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xec8(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x8(%rsp),%esi
lea    0xeb6(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmpl   $0x0,0x8(%rsp)
jle    11ad <main+0x7d>
lea    0x10(%rsp),%r15
xor    %ebx,%ebx
lea    0xe97(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <scanf@plt>
add    $0x1,%rbx
movslq 0x8(%rsp),%rax
add    $0x4,%r15
cmp    %rax,%rbx
jl     1190 <main+0x60>
lea    0xe99(%rip),%rdi
call   1030 <puts@plt>
lea    0xe59(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x8(%rsp),%edi
test   %edi,%edi
jle    1208 <main+0xd8>
add    $0xffffffff,%edi
xor    %eax,%eax
mov    0xc(%rsp),%esi
mov    %edi,%ecx
jmp    11e9 <main+0xb9>
nop
mov    %edx,%eax
lea    (%rcx,%rax,1),%edi
cmp    %ecx,%eax
jg     1208 <main+0xd8>
mov    %edi,%edx
shr    $0x1f,%edx
add    %edi,%edx
sar    %edx
movslq %edx,%rdi
mov    0x10(%rsp,%rdi,4),%edi
add    $0x1,%edx
cmp    %esi,%edi
jl     11e0 <main+0xb0>
cmp    %esi,%edi
je     1216 <main+0xe6>
mov    %edx,%ecx
jmp    11e2 <main+0xb2>
lea    0xe57(%rip),%rdi
call   1030 <puts@plt>
jmp    1224 <main+0xf4>
lea    0xe17(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x1a0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [25 x i8] c"\0Aenterthe no of element \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [24 x i8] c"\0Aenter the %d integers \00"
@.str.4 = [25 x i8] c"%d found at location %d\0A\00"
@str = [25 x i8] c"Enter the value to find \00"
@str.6 = [11 x i8] c"Not found \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [100 x i32]
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast [100 x i32]* %3 to i8*
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 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* %1)
%9 = load i32, i32* %1
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%11 = load i32, i32* %1
%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]* %3, 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* %1
%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 ([25 x i8], [25 x i8]* @str, 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* %1
%25 = add nsw i32 %24, -1
%26 = icmp slt i32 %24, 1
br i1 %26, label %50, label %27
27: ; preds = %21
%28 = load i32, i32* %2
br label %29
29: ; preds = %27, %43
%30 = phi i32 [ %25, %27 ], [ %46, %43 ]
%31 = phi i32 [ %25, %27 ], [ %45, %43 ]
%32 = phi i32 [ 0, %27 ], [ %44, %43 ]
%33 = sdiv i32 %30, 2
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %34
%36 = load i32, i32* %35
%37 = icmp slt i32 %36, %28
br i1 %37, label %38, label %40
38: ; preds = %29
%39 = add nsw i32 %33, 1
br label %43
40: ; preds = %29
%41 = icmp eq i32 %36, %28
%42 = add nsw i32 %33, 1
br i1 %41, label %48, label %43
43: ; preds = %40, %38
%44 = phi i32 [ %39, %38 ], [ %32, %40 ]
%45 = phi i32 [ %31, %38 ], [ %42, %40 ]
%46 = add nsw i32 %45, %44
%47 = icmp sgt i32 %44, %45
br i1 %47, label %50, label %29
48: ; preds = %40
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i32 %28, i32 %42)
br label %52
50: ; preds = %43, %21
%51 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.6, i64 0, i64 0))
br label %52
52: ; preds = %48, %50
ret i32 0
}