#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 BinarySearch(int, int *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
void main() {
  int x = 0, v[50], n = 0, i = 0, j = 0, temp = 0, position = 0;
  char flag;
  for (i = 0; i < 50; i++)
    v[i] = 0;
  for (i = 0; i < 50 && flag != 'n'; i++) {
    printf("\nInput the %d element of array:", i);
    scanf("%d", &v[i]);
    printf("Press n to exit");
    scanf("%c", &flag);
  }
  n = i;
  for (i = 0; i < n; i++)
    for (j = i + 1; j < n; j++)
      if (v[i] > v[j]) {
        temp = v[j];
        v[j] = v[i];
        v[i] = temp;
      }
  printf("\n\nInput the element to be searched:");
  scanf("%d", &x);
  position = BinarySearch(x, v, n);
  if (position != -1)
    printf("\nNumber %d is found at position %d of the array (0 is the "
           "starting position)\n\n",
           v[position], position - 1);
  else
    printf("\nNumber not Found\n\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xd4(%rbp)
movl   $0x0,-0xd8(%rbp)
movl   $0x0,-0xdc(%rbp)
movl   $0x0,-0xe0(%rbp)
movl   $0x0,-0xe4(%rbp)
movl   $0x0,-0xd8(%rbp)
cmpl   $0x32,-0xd8(%rbp)
jge    11b1 <main+0x81>
movslq -0xd8(%rbp),%rax
movl   $0x0,-0xd0(%rbp,%rax,4)
mov    -0xd8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xd8(%rbp)
jmp    117e <main+0x4e>
movl   $0x0,-0xd8(%rbp)
xor    %eax,%eax
cmpl   $0x32,-0xd8(%rbp)
mov    %al,-0xe6(%rbp)
jge    11e3 <main+0xb3>
movsbl -0xe5(%rbp),%eax
cmp    $0x6e,%eax
setne  %al
mov    %al,-0xe6(%rbp)
mov    -0xe6(%rbp),%al
test   $0x1,%al
jne    11f6 <main+0xc6>
jmp    1264 <main+0x134>
mov    -0xd8(%rbp),%esi
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movslq -0xd8(%rbp),%rax
lea    -0xd0(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdf1(%rip),%rdi
lea    -0xe5(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0xd8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xd8(%rbp)
jmp    11bb <main+0x8b>
mov    -0xd8(%rbp),%eax
mov    %eax,-0xd4(%rbp)
movl   $0x0,-0xd8(%rbp)
mov    -0xd8(%rbp),%eax
cmp    -0xd4(%rbp),%eax
jge    1345 <main+0x215>
mov    -0xd8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xdc(%rbp)
mov    -0xdc(%rbp),%eax
cmp    -0xd4(%rbp),%eax
jge    132c <main+0x1fc>
movslq -0xd8(%rbp),%rax
mov    -0xd0(%rbp,%rax,4),%eax
movslq -0xdc(%rbp),%rcx
cmp    -0xd0(%rbp,%rcx,4),%eax
jle    1313 <main+0x1e3>
movslq -0xdc(%rbp),%rax
mov    -0xd0(%rbp,%rax,4),%eax
mov    %eax,-0xe0(%rbp)
movslq -0xd8(%rbp),%rax
mov    -0xd0(%rbp,%rax,4),%ecx
movslq -0xdc(%rbp),%rax
mov    %ecx,-0xd0(%rbp,%rax,4)
mov    -0xe0(%rbp),%ecx
movslq -0xd8(%rbp),%rax
mov    %ecx,-0xd0(%rbp,%rax,4)
jmp    1318 <main+0x1e8>
mov    -0xdc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xdc(%rbp)
jmp    129b <main+0x16b>
jmp    1331 <main+0x201>
mov    -0xd8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xd8(%rbp)
jmp    127a <main+0x14a>
lea    0xcea(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xcc6(%rip),%rdi
lea    -0x4(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x4(%rbp),%edi
lea    -0xd0(%rbp),%rsi
mov    -0xd4(%rbp),%edx
call   1040 <BinarySearch@plt>
mov    %eax,-0xe4(%rbp)
cmpl   $0xffffffff,-0xe4(%rbp)
je     13b7 <main+0x287>
movslq -0xe4(%rbp),%rax
mov    -0xd0(%rbp,%rax,4),%esi
mov    -0xe4(%rbp),%edx
sub    $0x1,%edx
lea    0xcaf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    13c5 <main+0x295>
lea    0xceb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xd8,%rsp
movl   $0x0,0xc(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xc0(%rsp)
movq   $0x0,0xd0(%rsp)
lea    0x10(%rsp),%rbx
lea    0xe64(%rip),%r13
lea    0xe6d(%rip),%rbp
lea    0xb(%rsp),%r15
xor    %r12d,%r12d
xchg   %ax,%ax
mov    %r12,%r14
lea    0xe26(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe35(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
add    $0x1,%r12
cmp    $0x30,%r14
ja     1221 <main+0xe1>
add    $0x4,%rbx
cmpb   $0x6e,0xb(%rsp)
jne    11d0 <main+0x90>
lea    0x14(%rsp),%rax
lea    -0x1(%r12),%rcx
xor    %edx,%edx
jmp    123d <main+0xfd>
nop
add    $0x4,%rax
add    $0xffffffffffffffff,%rcx
cmp    %rdx,%r12
je     127b <main+0x13b>
mov    %rdx,%rsi
add    $0x1,%rdx
cmp    %r12,%rdx
jae    1230 <main+0xf0>
mov    0x10(%rsp,%rsi,4),%ebx
xor    %ebp,%ebp
jmp    1269 <main+0x129>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbp
cmp    %rbp,%rcx
je     1230 <main+0xf0>
mov    (%rax,%rbp,4),%edi
cmp    %edi,%ebx
jle    1260 <main+0x120>
mov    %ebx,(%rax,%rbp,4)
mov    %edi,0x10(%rsp,%rsi,4)
mov    %edi,%ebx
jmp    1260 <main+0x120>
lea    0xdb4(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xd90(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    0xc(%rsp),%edi
lea    0x10(%rsp),%rsi
mov    %r12d,%edx
call   1050 <BinarySearch@plt>
cmp    $0xffffffff,%eax
je     12ce <main+0x18e>
movslq %eax,%rcx
mov    0x10(%rsp,%rcx,4),%esi
add    $0xffffffff,%eax
lea    0xd97(%rip),%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    12da <main+0x19a>
lea    0xdd4(%rip),%rdi
call   1030 <puts@plt>
add    $0xd8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"\0AInput the %d element of array:\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [16 x i8] c"Press n to exit\00"
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [36 x i8] c"\0A\0AInput the element to be searched:\00"
@.str.5 = [79 x i8] c"\0ANumber %d is found at position %d of the array (0 is the starting position)\0A\0A\00"
@.str.6 = [20 x i8] c"\0ANumber not Found\0A\0A\00"
define void @main() {
%1 = alloca i32
%2 = alloca [50 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8
store i32 0, i32* %1
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %4
br label %9
9: ; preds = %16, %0
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 50
br i1 %11, label %12, label %19
12: ; preds = %9
%13 = load i32, i32* %4
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [50 x i32], [50 x i32]* %2, i64 0, i64 %14
store i32 0, i32* %15
br label %16
16: ; preds = %12
%17 = load i32, i32* %4
%18 = add nsw i32 %17, 1
store i32 %18, i32* %4
br label %9
19: ; preds = %9
store i32 0, i32* %4
br label %20
20: ; preds = %38, %19
%21 = load i32, i32* %4
%22 = icmp slt i32 %21, 50
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = load i8, i8* %8
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 110
br label %27
27: ; preds = %23, %20
%28 = phi i1 [ false, %20 ], [ %26, %23 ]
br i1 %28, label %29, label %41
29: ; preds = %27
%30 = load i32, i32* %4
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %30)
%32 = load i32, i32* %4
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [50 x i32], [50 x i32]* %2, i64 0, i64 %33
%35 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %34)
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%37 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %8)
br label %38
38: ; preds = %29
%39 = load i32, i32* %4
%40 = add nsw i32 %39, 1
store i32 %40, i32* %4
br label %20
41: ; preds = %27
%42 = load i32, i32* %4
store i32 %42, i32* %3
store i32 0, i32* %4
br label %43
43: ; preds = %85, %41
%44 = load i32, i32* %4
%45 = load i32, i32* %3
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %88
47: ; preds = %43
%48 = load i32, i32* %4
%49 = add nsw i32 %48, 1
store i32 %49, i32* %5
br label %50
50: ; preds = %81, %47
%51 = load i32, i32* %5
%52 = load i32, i32* %3
%53 = icmp slt i32 %51, %52
br i1 %53, label %54, label %84
54: ; preds = %50
%55 = load i32, i32* %4
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [50 x i32], [50 x i32]* %2, i64 0, i64 %56
%58 = load i32, i32* %57
%59 = load i32, i32* %5
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [50 x i32], [50 x i32]* %2, i64 0, i64 %60
%62 = load i32, i32* %61
%63 = icmp sgt i32 %58, %62
br i1 %63, label %64, label %80
64: ; preds = %54
%65 = load i32, i32* %5
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [50 x i32], [50 x i32]* %2, i64 0, i64 %66
%68 = load i32, i32* %67
store i32 %68, i32* %6
%69 = load i32, i32* %4
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds [50 x i32], [50 x i32]* %2, i64 0, i64 %70
%72 = load i32, i32* %71
%73 = load i32, i32* %5
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds [50 x i32], [50 x i32]* %2, i64 0, i64 %74
store i32 %72, i32* %75
%76 = load i32, i32* %6
%77 = load i32, i32* %4
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds [50 x i32], [50 x i32]* %2, i64 0, i64 %78
store i32 %76, i32* %79
br label %80
80: ; preds = %64, %54
br label %81
81: ; preds = %80
%82 = load i32, i32* %5
%83 = add nsw i32 %82, 1
store i32 %83, i32* %5
br label %50
84: ; preds = %50
br label %85
85: ; preds = %84
%86 = load i32, i32* %4
%87 = add nsw i32 %86, 1
store i32 %87, i32* %4
br label %43
88: ; preds = %43
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0))
%90 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%91 = load i32, i32* %1
%92 = getelementptr inbounds [50 x i32], [50 x i32]* %2, i64 0, i64 0
%93 = load i32, i32* %3
%94 = call i32 @BinarySearch(i32 %91, i32* %92, i32 %93)
store i32 %94, i32* %7
%95 = load i32, i32* %7
%96 = icmp ne i32 %95, -1
br i1 %96, label %97, label %105
97: ; preds = %88
%98 = load i32, i32* %7
%99 = sext i32 %98 to i64
%100 = getelementptr inbounds [50 x i32], [50 x i32]* %2, i64 0, i64 %99
%101 = load i32, i32* %100
%102 = load i32, i32* %7
%103 = sub nsw i32 %102, 1
%104 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str.5, i64 0, i64 0), i32 %101, i32 %103)
br label %107
105: ; preds = %88
%106 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
br label %107
107: ; preds = %105, %97
ret void
}

LLVM IR (-O2):
@.str = [32 x i8] c"\0AInput the %d element of array:\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [16 x i8] c"Press n to exit\00"
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [36 x i8] c"\0A\0AInput the element to be searched:\00"
@.str.5 = [79 x i8] c"\0ANumber %d is found at position %d of the array (0 is the starting position)\0A\0A\00"
@str = [19 x i8] c"\0ANumber not Found\0A\00"
define void @main() {
%1 = alloca i32
%2 = alloca [50 x i32]
%3 = bitcast [50 x i32]* %2 to i8*
%4 = alloca i8
%5 = bitcast i32* %1 to i8*
store i32 0, i32* %1
br label %9
6: ; preds = %9
%7 = trunc i64 %17 to i32
%8 = and i64 %17, 4294967295
br label %25
9: ; preds = %0, %9
%10 = phi i64 [ 0, %0 ], [ %17, %9 ]
%11 = trunc i64 %10 to i32
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = getelementptr inbounds [50 x i32], [50 x i32]* %2, i64 0, i64 %10
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %13)
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%17 = add nuw nsw i64 %10, 1
%18 = icmp ult i64 %10, 49
%19 = load i8, i8* %4
%20 = icmp ne i8 %19, 110
%21 = select i1 %18, i1 %20, i1 false
br i1 %21, label %9, label %6
22: ; preds = %40, %25
%23 = add nuw nsw i64 %27, 1
%24 = icmp eq i64 %28, %8
br i1 %24, label %44, label %25
25: ; preds = %6, %22
%26 = phi i64 [ 0, %6 ], [ %28, %22 ]
%27 = phi i64 [ 1, %6 ], [ %23, %22 ]
%28 = add nuw nsw i64 %26, 1
%29 = icmp ult i64 %28, %8
br i1 %29, label %30, label %22
30: ; preds = %25
%31 = getelementptr inbounds [50 x i32], [50 x i32]* %2, i64 0, i64 %26
%32 = load i32, i32* %31
br label %33
33: ; preds = %30, %40
%34 = phi i32 [ %32, %30 ], [ %41, %40 ]
%35 = phi i64 [ %27, %30 ], [ %42, %40 ]
%36 = getelementptr inbounds [50 x i32], [50 x i32]* %2, i64 0, i64 %35
%37 = load i32, i32* %36
%38 = icmp sgt i32 %34, %37
br i1 %38, label %39, label %40
39: ; preds = %33
store i32 %34, i32* %36
store i32 %37, i32* %31
br label %40
40: ; preds = %33, %39
%41 = phi i32 [ %34, %33 ], [ %37, %39 ]
%42 = add nuw nsw i64 %35, 1
%43 = icmp eq i64 %42, %8
br i1 %43, label %22, label %33
44: ; preds = %22
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0))
%46 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%47 = load i32, i32* %1
%48 = getelementptr inbounds [50 x i32], [50 x i32]* %2, i64 0, i64 0
%49 = call i32 @BinarySearch(i32 %47, i32* %48, i32 %7)
%50 = icmp eq i32 %49, -1
br i1 %50, label %57, label %51
51: ; preds = %44
%52 = sext i32 %49 to i64
%53 = getelementptr inbounds [50 x i32], [50 x i32]* %2, i64 0, i64 %52
%54 = load i32, i32* %53
%55 = add nsw i32 %49, -1
%56 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([79 x i8], [79 x i8]* @.str.5, i64 0, i64 0), i32 %54, i32 %55)
br label %59
57: ; preds = %44
%58 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %59
59: ; preds = %57, %51
ret void
}