#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 binary_ser(int, int *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int i, arr[10];
  int n, num;
  int pos = 0;
  printf("Enter the size of array of numbers\n");
  scanf("%d", &n);
  printf("Enter %d numbers in increasing order\n", n);
  for (i = 0; i < n; ++i) {
    scanf("%d", &arr[i]);
  }
  printf("Enter the number to be searched in the array\n");
  scanf("%d", &num);
  pos = binary_ser(num, arr, n);
  if (pos == -1) {
    printf("The number is not present\n");
  } else {
    printf("The number is at position %d in the list\n", pos + 1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x3c(%rbp)
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec9(%rip),%rdi
lea    -0x34(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x34(%rbp),%esi
lea    0xeb9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    11b1 <main+0x81>
movslq -0x8(%rbp),%rax
lea    -0x30(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe86(%rip),%rdi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    117c <main+0x4c>
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe5e(%rip),%rdi
lea    -0x38(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x38(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   1050 <binary_ser@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0xffffffff,-0x3c(%rbp)
jne    11fe <main+0xce>
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1212 <main+0xe2>
mov    -0x3c(%rbp),%esi
add    $0x1,%esi
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x40,%rsp
lea    0xf03(%rip),%rdi
call   1030 <puts@plt>
lea    0xea4(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x8(%rsp),%esi
lea    0xe92(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmpl   $0x0,0x8(%rsp)
jle    11ad <main+0x6d>
lea    0x10(%rsp),%r15
xor    %ebx,%ebx
lea    0xe73(%rip),%r14
nopl   (%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+0x50>
lea    0xec2(%rip),%rdi
call   1030 <puts@plt>
lea    0xe40(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%edi
mov    0x8(%rsp),%edx
lea    0x10(%rsp),%rsi
call   1060 <binary_ser@plt>
cmp    $0xffffffff,%eax
je     11f6 <main+0xb6>
add    $0x1,%eax
lea    0xe3e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1202 <main+0xc2>
lea    0xea6(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [36 x i8] c"Enter the size of array of numbers\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [38 x i8] c"Enter %d numbers in increasing order\0A\00"
@.str.3 = [46 x i8] c"Enter the number to be searched in the array\0A\00"
@.str.4 = [27 x i8] c"The number is not present\0A\00"
@.str.5 = [42 x i8] c"The number is at position %d in the list\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [10 x i32]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %6
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 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* %4)
%9 = load i32, i32* %4
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %9)
store i32 0, i32* %2
br label %11
11: ; preds = %20, %0
%12 = load i32, i32* %2
%13 = load i32, i32* %4
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %23
15: ; preds = %11
%16 = load i32, i32* %2
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 %17
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %18)
br label %20
20: ; preds = %15
%21 = load i32, i32* %2
%22 = add nsw i32 %21, 1
store i32 %22, i32* %2
br label %11
23: ; preds = %11
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0))
%25 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
%26 = load i32, i32* %5
%27 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 0
%28 = load i32, i32* %4
%29 = call i32 @binary_ser(i32 %26, i32* %27, i32 %28)
store i32 %29, i32* %6
%30 = load i32, i32* %6
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %34
32: ; preds = %23
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
br label %38
34: ; preds = %23
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0), i32 %36)
br label %38
38: ; preds = %34, %32
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [38 x i8] c"Enter %d numbers in increasing order\0A\00"
@.str.5 = [42 x i8] c"The number is at position %d in the list\0A\00"
@str = [35 x i8] c"Enter the size of array of numbers\00"
@str.6 = [45 x i8] c"Enter the number to be searched in the array\00"
@str.7 = [26 x i8] c"The number is not present\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 ([35 x i8], [35 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 ([38 x i8], [38 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 [10 x i32], [10 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 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.6, 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* %3
%25 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 0
%26 = load i32, i32* %2
%27 = call i32 @binary_ser(i32 %24, i32* %25, i32 %26)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %31
29: ; preds = %21
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.7, i64 0, i64 0))
br label %34
31: ; preds = %21
%32 = add nuw nsw i32 %27, 1
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0), i32 %32)
br label %34
34: ; preds = %31, %29
ret i32 0
}