#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], temp, i, j, n, x, p, mid1, mid2, low, high;
  printf("Enter the length of a array::\n");
  scanf("%d", &n);
  printf("Enter the elements in sorted order\n");
  for (i = 0; i <= n; i++)
    ;
  scanf("%d", &a[i]);
  printf("\nEnter a element to search in the array::\t");
  scanf("%d", &x);
  low = 0;
  high = n - 1;
  while (low <= high) {
    mid1 = (low + high) / 2;
    mid2 = 2 * mid1;
    if (x == a[mid1]) {
      printf("\nElement present in the array");
      printf("\nposition is %d\n\nvalue is %d\n", mid1 + 1, a[mid1]);
      break;
    } else if (x < a[mid1])
      high = mid1 - 1;
    else if (x == a[mid2]) {
      printf("\nElement present in the array");
      printf("\nposition is %d\n\nvalue is %d\n", mid2 + 1, a[mid2]);
      break;
    } else if (x < a[mid2]) {
      low = mid1 + 1;
      high = mid2 - 1;
    } else
      low = mid2 + 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xedb(%rip),%rdi
lea    -0x40(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xece(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x40(%rbp),%eax
jg     1181 <main+0x61>
jmp    1173 <main+0x53>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1162 <main+0x42>
movslq -0x38(%rbp),%rax
lea    -0x30(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe88(%rip),%rdi
call   1040 <scanf@plt>
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe6e(%rip),%rdi
lea    -0x44(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0x54(%rbp)
mov    -0x40(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x58(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0x58(%rbp),%eax
jg     12d4 <main+0x1b4>
mov    -0x54(%rbp),%eax
add    -0x58(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x50(%rbp)
mov    -0x44(%rbp),%eax
movslq -0x4c(%rbp),%rcx
cmp    -0x30(%rbp,%rcx,4),%eax
jne    1230 <main+0x110>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4c(%rbp),%esi
add    $0x1,%esi
movslq -0x4c(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%edx
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12d4 <main+0x1b4>
mov    -0x44(%rbp),%eax
movslq -0x4c(%rbp),%rcx
cmp    -0x30(%rbp,%rcx,4),%eax
jge    124f <main+0x12f>
mov    -0x4c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    12ca <main+0x1aa>
mov    -0x44(%rbp),%eax
movslq -0x50(%rbp),%rcx
cmp    -0x30(%rbp,%rcx,4),%eax
jne    128f <main+0x16f>
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x50(%rbp),%esi
add    $0x1,%esi
movslq -0x50(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%edx
lea    0xe0c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12d4 <main+0x1b4>
mov    -0x44(%rbp),%eax
movslq -0x50(%rbp),%rcx
cmp    -0x30(%rbp,%rcx,4),%eax
jge    12b7 <main+0x197>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
mov    -0x50(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    12c0 <main+0x1a0>
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    12c5 <main+0x1a5>
jmp    12ca <main+0x1aa>
jmp    12cf <main+0x1af>
jmp    11ca <main+0xaa>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
lea    0xf29(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb3(%rip),%rbx
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <scanf@plt>
lea    0xf27(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%eax
test   %eax,%eax
mov    $0xffffffff,%ecx
cmovns %eax,%ecx
add    $0x1,%ecx
lea    (%rsp,%rcx,4),%rsi
add    $0x10,%rsi
mov    %rbx,%rdi
call   1050 <scanf@plt>
lea    0xe75(%rip),%rdi
xor    %r14d,%r14d
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <scanf@plt>
mov    0x8(%rsp),%ecx
test   %ecx,%ecx
jle    125f <main+0x12f>
add    $0xffffffff,%ecx
mov    0xc(%rsp),%eax
jmp    11ce <main+0x9e>
nopw   0x0(%rax,%rax,1)
add    $0xffffffff,%ebp
mov    %ebp,%ecx
cmp    %ecx,%r14d
jg     125f <main+0x12f>
lea    (%rcx,%r14,1),%edx
mov    %edx,%ebx
shr    $0x1f,%ebx
add    %edx,%ebx
mov    %ebx,%ebp
sar    %ebp
and    $0xfffffffe,%ebx
movslq %ebp,%r15
cmp    0x10(%rsp,%r15,4),%eax
je     1218 <main+0xe8>
jl     11c0 <main+0x90>
movslq %ebx,%r14
cmp    0x10(%rsp,%r14,4),%eax
je     1239 <main+0x109>
jge    1210 <main+0xe0>
add    $0x1,%ebp
add    $0xffffffff,%ebx
mov    %ebp,%r14d
mov    %ebx,%ecx
jmp    11c5 <main+0x95>
cs nopw 0x0(%rax,%rax,1)
nop
or     $0x1,%ebx
mov    %ebx,%r14d
jmp    11c5 <main+0x95>
lea    0xe0f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebp
mov    0x10(%rsp,%r15,4),%edx
lea    0xe17(%rip),%rdi
mov    %ebp,%esi
jmp    1258 <main+0x128>
lea    0xdee(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
or     $0x1,%ebx
mov    0x10(%rsp,%r14,4),%edx
lea    0xdf6(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [31 x i8] c"Enter the length of a array::\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [36 x i8] c"Enter the elements in sorted order\0A\00"
@.str.3 = [43 x i8] c"\0AEnter a element to search in the array::\09\00"
@.str.4 = [30 x i8] c"\0AElement present in the array\00"
@.str.5 = [30 x i8] c"\0Aposition is %d\0A\0Avalue is %d\0A\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
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %1
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %4
br label %16
16: ; preds = %21, %0
%17 = load i32, i32* %4
%18 = load i32, i32* %6
%19 = icmp sle i32 %17, %18
br i1 %19, label %20, label %24
20: ; preds = %16
br label %21
21: ; preds = %20
%22 = load i32, i32* %4
%23 = add nsw i32 %22, 1
store i32 %23, i32* %4
br label %16
24: ; preds = %16
%25 = load i32, i32* %4
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %26
%28 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %27)
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0))
%30 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %7)
store i32 0, i32* %11
%31 = load i32, i32* %6
%32 = sub nsw i32 %31, 1
store i32 %32, i32* %12
br label %33
33: ; preds = %103, %24
%34 = load i32, i32* %11
%35 = load i32, i32* %12
%36 = icmp sle i32 %34, %35
br i1 %36, label %37, label %104
37: ; preds = %33
%38 = load i32, i32* %11
%39 = load i32, i32* %12
%40 = add nsw i32 %38, %39
%41 = sdiv i32 %40, 2
store i32 %41, i32* %9
%42 = load i32, i32* %9
%43 = mul nsw i32 2, %42
store i32 %43, i32* %10
%44 = load i32, i32* %7
%45 = load i32, i32* %9
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %46
%48 = load i32, i32* %47
%49 = icmp eq i32 %44, %48
br i1 %49, label %50, label %59
50: ; preds = %37
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
%52 = load i32, i32* %9
%53 = add nsw i32 %52, 1
%54 = load i32, i32* %9
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %55
%57 = load i32, i32* %56
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i32 %53, i32 %57)
br label %104
59: ; preds = %37
%60 = load i32, i32* %7
%61 = load i32, i32* %9
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %62
%64 = load i32, i32* %63
%65 = icmp slt i32 %60, %64
br i1 %65, label %66, label %69
66: ; preds = %59
%67 = load i32, i32* %9
%68 = sub nsw i32 %67, 1
store i32 %68, i32* %12
br label %102
69: ; preds = %59
%70 = load i32, i32* %7
%71 = load i32, i32* %10
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %72
%74 = load i32, i32* %73
%75 = icmp eq i32 %70, %74
br i1 %75, label %76, label %85
76: ; preds = %69
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
%78 = load i32, i32* %10
%79 = add nsw i32 %78, 1
%80 = load i32, i32* %10
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %81
%83 = load i32, i32* %82
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i32 %79, i32 %83)
br label %104
85: ; preds = %69
%86 = load i32, i32* %7
%87 = load i32, i32* %10
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %88
%90 = load i32, i32* %89
%91 = icmp slt i32 %86, %90
br i1 %91, label %92, label %97
92: ; preds = %85
%93 = load i32, i32* %9
%94 = add nsw i32 %93, 1
store i32 %94, i32* %11
%95 = load i32, i32* %10
%96 = sub nsw i32 %95, 1
store i32 %96, i32* %12
br label %100
97: ; preds = %85
%98 = load i32, i32* %10
%99 = add nsw i32 %98, 1
store i32 %99, i32* %11
br label %100
100: ; preds = %97, %92
br label %101
101: ; preds = %100
br label %102
102: ; preds = %101, %66
br label %103
103: ; preds = %102
br label %33
104: ; preds = %76, %50, %33
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [43 x i8] c"\0AEnter a element to search in the array::\09\00"
@.str.4 = [30 x i8] c"\0AElement present in the array\00"
@.str.5 = [30 x i8] c"\0Aposition is %d\0A\0Avalue is %d\0A\00"
@str = [30 x i8] c"Enter the length of a array::\00"
@str.6 = [35 x i8] c"Enter the elements in sorted 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 @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* %2)
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.6, i64 0, i64 0))
%10 = load i32, i32* %2
%11 = call i32 @llvm.smax.i32(i32 %10, i32 -1)
%12 = add nsw i32 %11, 1
%13 = zext i32 %12 to i64
%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 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0))
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%18 = load i32, i32* %2
%19 = icmp slt i32 %18, 1
br i1 %19, label %65, label %20
20: ; preds = %0
%21 = add nsw i32 %18, -1
%22 = load i32, i32* %3
br label %23
23: ; preds = %20, %61
%24 = phi i32 [ %21, %20 ], [ %63, %61 ]
%25 = phi i32 [ 0, %20 ], [ %62, %61 ]
%26 = add nsw i32 %24, %25
%27 = sdiv i32 %26, 2
%28 = shl nsw i32 %27, 1
%29 = sext i32 %27 to i64
%30 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 %29
%31 = load i32, i32* %30
%32 = icmp eq i32 %22, %31
br i1 %32, label %33, label %39
33: ; preds = %23
%34 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 %29
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
%36 = add nsw i32 %27, 1
%37 = load i32, i32* %34
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i32 %36, i32 %37)
br label %65
39: ; preds = %23
%40 = icmp slt i32 %22, %31
br i1 %40, label %41, label %43
41: ; preds = %39
%42 = add nsw i32 %27, -1
br label %61
43: ; preds = %39
%44 = sext i32 %28 to i64
%45 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 %44
%46 = load i32, i32* %45
%47 = icmp eq i32 %22, %46
br i1 %47, label %48, label %54
48: ; preds = %43
%49 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 %44
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
%51 = or i32 %28, 1
%52 = load i32, i32* %49
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i32 %51, i32 %52)
br label %65
54: ; preds = %43
%55 = icmp slt i32 %22, %46
br i1 %55, label %56, label %59
56: ; preds = %54
%57 = add nsw i32 %27, 1
%58 = add nsw i32 %28, -1
br label %61
59: ; preds = %54
%60 = or i32 %28, 1
br label %61
61: ; preds = %41, %56, %59
%62 = phi i32 [ %25, %41 ], [ %57, %56 ], [ %60, %59 ]
%63 = phi i32 [ %42, %41 ], [ %58, %56 ], [ %24, %59 ]
%64 = icmp sgt i32 %62, %63
br i1 %64, label %65, label %23
65: ; preds = %61, %0, %48, %33
ret i32 0
}