#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 */
typedef int clock_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ EOF;
int clock();
int /*<<< orphan*/ displayOutput(int *, int, int, int, int, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, int *);
int iterativeBinarySearch(int *, int, int);
int /*<<< orphan*/ printf(char *);
int recursiveBinarySearch(int *, int, int /*<<< orphan*/, int);
int readInput(FILE *input_file, char file_name[], int values[],
              int desired_number) {
  int count = 0;
  int value = 0;
  int array_size;
  input_file = fopen(file_name, "r");
  if (feof(input_file) != 0) {
    printf("Error: can't open file\n");
    return -1;
  } else {
    printf("File opened successfully\n");
  }
  while (fscanf(input_file, "%d", &value) != EOF) {
    if (count == 0) {
      array_size = value - 1;
    } else {
      values[count - 1] = value;
    }
    count++;
  }
  fclose(input_file);
  int delta;
  clock_t t1, t2;
  t1 = clock();
  int recursive_result =
      recursiveBinarySearch(values, desired_number, 0, array_size);
  t2 = clock();
  delta = t2 - t1;
  int delta1;
  clock_t t3, t4;
  t3 = clock();
  int iterative_result =
      iterativeBinarySearch(values, desired_number, array_size);
  t4 = clock();
  delta1 = t3 - t4;
  displayOutput(values, array_size, recursive_result, delta, delta1,
                iterative_result);
  return 0;
}


x86 assembly (clang, -O0):
<readInput>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe40(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1090 <feof@plt>
cmp    $0x0,%rax
je     11f4 <readInput+0x64>
lea    0xe1f(%rip),%rdi
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ec <readInput+0x15c>
lea    0xe1f(%rip),%rdi
call   1070 <printf@plt>
jmp    1205 <readInput+0x75>
mov    -0x10(%rbp),%rdi
lea    0xe24(%rip),%rsi
lea    -0x2c(%rbp),%rdx
call   1080 <fscanf@plt>
mov    0x2dc8(%rip),%rcx
cmp    (%rcx),%rax
je     1262 <readInput+0xd2>
cmpl   $0x0,-0x28(%rbp)
jne    1241 <readInput+0xb1>
mov    -0x2c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1254 <readInput+0xc4>
mov    -0x2c(%rbp),%edx
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1205 <readInput+0x75>
mov    -0x10(%rbp),%rdi
call   1060 <fclose@plt>
mov    $0x0,%al
call   1050 <clock@plt>
mov    %eax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x30(%rbp),%ecx
xor    %edx,%edx
call   1030 <recursiveBinarySearch@plt>
mov    %eax,-0x40(%rbp)
mov    $0x0,%al
call   1050 <clock@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
sub    -0x38(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    $0x0,%al
call   1050 <clock@plt>
mov    %eax,-0x48(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x30(%rbp),%edx
call   1040 <iterativeBinarySearch@plt>
mov    %eax,-0x50(%rbp)
mov    $0x0,%al
call   1050 <clock@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x48(%rbp),%eax
sub    -0x4c(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%esi
mov    -0x40(%rbp),%edx
mov    -0x34(%rbp),%ecx
mov    -0x44(%rbp),%r8d
mov    -0x50(%rbp),%r9d
call   10a0 <displayOutput@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readInput>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%r12d
mov    %rdx,%r13
mov    %rsi,%rdi
movl   $0x0,0x8(%rsp)
lea    0xe4a(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   1090 <feof@plt>
test   %rax,%rax
je     11e1 <readInput+0x51>
lea    0xe4c(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebp
jmp    12eb <readInput+0x15b>
lea    0xe1d(%rip),%rdi
call   1030 <puts@plt>
lea    0xe0e(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %rbp,%rdi
call   1080 <fscanf@plt>
mov    0x2de0(%rip),%r14
cmp    (%r14),%rax
je     1279 <readInput+0xe9>
mov    0x8(%rsp),%r15d
add    $0xffffffff,%r15d
lea    0xde5(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %rbp,%rdi
call   1080 <fscanf@plt>
cmp    (%r14),%rax
je     1279 <readInput+0xe9>
mov    %r12d,0xc(%rsp)
mov    %r13,%r12
lea    0xdc4(%rip),%r13
lea    0x8(%rsp),%rbx
mov    %r12,0x10(%rsp)
nopl   0x0(%rax,%rax,1)
mov    0x8(%rsp),%eax
mov    %eax,(%r12)
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1080 <fscanf@plt>
add    $0x4,%r12
cmp    (%r14),%rax
jne    1250 <readInput+0xc0>
mov    0xc(%rsp),%r12d
mov    0x10(%rsp),%r13
mov    %rbp,%rdi
call   1070 <fclose@plt>
xor    %ebp,%ebp
xor    %eax,%eax
call   1060 <clock@plt>
mov    %eax,%ebx
mov    %r13,%rdi
mov    %r12d,%esi
xor    %edx,%edx
mov    %r15d,%ecx
call   1040 <recursiveBinarySearch@plt>
mov    %eax,0xc(%rsp)
xor    %eax,%eax
call   1060 <clock@plt>
mov    %eax,%r14d
sub    %ebx,%r14d
xor    %eax,%eax
call   1060 <clock@plt>
mov    %eax,%ebx
mov    %r13,%rdi
mov    %r12d,%esi
mov    %r15d,%edx
call   1050 <iterativeBinarySearch@plt>
mov    %r13,%r12
mov    %eax,%r13d
xor    %eax,%eax
call   1060 <clock@plt>
sub    %eax,%ebx
mov    %r12,%rdi
mov    %r15d,%esi
mov    0xc(%rsp),%edx
mov    %r14d,%ecx
mov    %ebx,%r8d
mov    %r13d,%r9d
call   10a0 <displayOutput@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [24 x i8] c"Error: can't open file\0A\00"
@.str.2 = [26 x i8] c"File opened successfully\0A\00"
@.str.3 = [3 x i8] c"%d\00"
@EOF = global i64 0
define i32 @readInput(i32* %0, i8* %1, i32* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
store i32* %0, i32** %6
store i8* %1, i8** %7
store i32* %2, i32** %8
store i32 %3, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
%21 = load i8*, i8** %7
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %22, i32** %6
%23 = load i32*, i32** %6
%24 = call i64 @feof(i32* %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %4
%27 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %5
br label %80
28: ; preds = %4
%29 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %30
30: ; preds = %28
br label %31
31: ; preds = %49, %30
%32 = load i32*, i32** %6
%33 = call i64 @fscanf(i32* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %11)
%34 = load i64, i64* @EOF
%35 = icmp ne i64 %33, %34
br i1 %35, label %36, label %52
36: ; preds = %31
%37 = load i32, i32* %10
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %36
%40 = load i32, i32* %11
%41 = sub nsw i32 %40, 1
store i32 %41, i32* %12
br label %49
42: ; preds = %36
%43 = load i32, i32* %11
%44 = load i32*, i32** %8
%45 = load i32, i32* %10
%46 = sub nsw i32 %45, 1
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i32, i32* %44, i64 %47
store i32 %43, i32* %48
br label %49
49: ; preds = %42, %39
%50 = load i32, i32* %10
%51 = add nsw i32 %50, 1
store i32 %51, i32* %10
br label %31
52: ; preds = %31
%53 = load i32*, i32** %6
%54 = call i32 @fclose(i32* %53)
%55 = call i32 (...) @clock()
store i32 %55, i32* %14
%56 = load i32*, i32** %8
%57 = load i32, i32* %9
%58 = load i32, i32* %12
%59 = call i32 @recursiveBinarySearch(i32* %56, i32 %57, i32 0, i32 %58)
store i32 %59, i32* %16
%60 = call i32 (...) @clock()
store i32 %60, i32* %15
%61 = load i32, i32* %15
%62 = load i32, i32* %14
%63 = sub nsw i32 %61, %62
store i32 %63, i32* %13
%64 = call i32 (...) @clock()
store i32 %64, i32* %18
%65 = load i32*, i32** %8
%66 = load i32, i32* %9
%67 = load i32, i32* %12
%68 = call i32 @iterativeBinarySearch(i32* %65, i32 %66, i32 %67)
store i32 %68, i32* %20
%69 = call i32 (...) @clock()
store i32 %69, i32* %19
%70 = load i32, i32* %18
%71 = load i32, i32* %19
%72 = sub nsw i32 %70, %71
store i32 %72, i32* %17
%73 = load i32*, i32** %8
%74 = load i32, i32* %12
%75 = load i32, i32* %16
%76 = load i32, i32* %13
%77 = load i32, i32* %17
%78 = load i32, i32* %20
%79 = call i32 @displayOutput(i32* %73, i32 %74, i32 %75, i32 %76, i32 %77, i32 %78)
store i32 0, i32* %5
br label %80
80: ; preds = %52, %26
%81 = load i32, i32* %5
ret i32 %81
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.3 = [3 x i8] c"%d\00"
@EOF = global i64 0
@str = [25 x i8] c"File opened successfully\00"
@str.4 = [23 x i8] c"Error: can't open file\00"
define i32 @readInput(i32* nocapture readnone %0, i8* nocapture %1, i32* %2, i32 %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%7 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = tail call i64 @feof(i32* %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %4
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.4, i64 0, i64 0))
br label %44
12: ; preds = %4
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%14 = call i64 @fscanf(i32* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %5)
%15 = load i64, i64* @EOF
%16 = icmp eq i64 %14, %15
br i1 %16, label %32, label %17
17: ; preds = %12
%18 = load i32, i32* %5
%19 = add nsw i32 %18, -1
%20 = call i64 @fscanf(i32* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %5)
%21 = load i64, i64* @EOF
%22 = icmp eq i64 %20, %21
br i1 %22, label %32, label %23
23: ; preds = %17, %23
%24 = phi i64 [ %28, %23 ], [ 1, %17 ]
%25 = load i32, i32* %5
%26 = add nsw i64 %24, -1
%27 = getelementptr inbounds i32, i32* %2, i64 %26
store i32 %25, i32* %27
%28 = add nuw i64 %24, 1
%29 = call i64 @fscanf(i32* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %5)
%30 = load i64, i64* @EOF
%31 = icmp eq i64 %29, %30
br i1 %31, label %32, label %23
32: ; preds = %23, %17, %12
%33 = phi i32 [ undef, %12 ], [ %19, %17 ], [ %19, %23 ]
%34 = call i32 @fclose(i32* %7)
%35 = call i32 (...) @clock()
%36 = call i32 @recursiveBinarySearch(i32* %2, i32 %3, i32 0, i32 %33)
%37 = call i32 (...) @clock()
%38 = sub nsw i32 %37, %35
%39 = call i32 (...) @clock()
%40 = call i32 @iterativeBinarySearch(i32* %2, i32 %3, i32 %33)
%41 = call i32 (...) @clock()
%42 = sub nsw i32 %39, %41
%43 = call i32 @displayOutput(i32* %2, i32 %33, i32 %36, i32 %38, i32 %42, i32 %40)
br label %44
44: ; preds = %32, %10
%45 = phi i32 [ -1, %10 ], [ 0, %32 ]
ret i32 %45
}