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

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main(int argc, char *argv[]) {
  int arraySize = 0;
  int *searchArray = NULL;
  int searchNum = 0;
  int splitNum = 0, lowBound = 0, highBound = 0;
  if (argc == 2) {
    searchNum = atoi(argv[1]);
  } else {
    printf("Please enter a number to search for.\n");
    scanf("%d", &searchNum);
  }
  FILE *fileHandle = fopen("./Data8.txt", "r");
  {
    fscanf(fileHandle, "%d", &arraySize);
    searchArray = (int *)(malloc(sizeof(int) * arraySize));
    for (int i = 0; i < arraySize; i++) {
      fscanf(fileHandle, "%d", &searchArray[i]);
    }
  }
  fclose(fileHandle);
  highBound = arraySize - 1;
  do {
    splitNum = (lowBound + highBound) / 2;
    if (searchNum < searchArray[splitNum]) {
      highBound = splitNum - 1;
    } else if (searchNum > searchArray[splitNum]) {
      lowBound = splitNum + 1;
    } else {
      printf("Number found at index %d.\n", splitNum);
      break;
    }
  } while (lowBound <= highBound);
  if (searchNum != searchArray[splitNum]) {
    printf("Number not found.\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    11d0 <main+0x60>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x24(%rbp)
jmp    11ee <main+0x7e>
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe41(%rip),%rdi
lea    -0x24(%rbp),%rsi
call   1070 <scanf@plt>
lea    0xe34(%rip),%rdi
lea    0xe39(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xe16(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1050 <fscanf@plt>
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    126c <main+0xfc>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rdx
movslq -0x3c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdx
lea    0xdcd(%rip),%rsi
call   1050 <fscanf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1233 <main+0xc3>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%eax
add    -0x30(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x20(%rbp),%rcx
movslq -0x28(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jge    12b1 <main+0x141>
mov    -0x28(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    12ee <main+0x17e>
mov    -0x24(%rbp),%eax
mov    -0x20(%rbp),%rcx
movslq -0x28(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jle    12d3 <main+0x163>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    12e9 <main+0x179>
mov    -0x28(%rbp),%esi
lea    0xd5a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12ff <main+0x18f>
jmp    12ee <main+0x17e>
jmp    12f3 <main+0x183>
mov    -0x2c(%rbp),%eax
cmp    -0x30(%rbp),%eax
jle    127e <main+0x10e>
mov    -0x24(%rbp),%eax
mov    -0x20(%rbp),%rcx
movslq -0x28(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
je     1321 <main+0x1b1>
lea    0xd38(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0x8(%rsp)
movl   $0x0,0xc(%rsp)
cmp    $0x2,%edi
jne    11b1 <main+0x31>
mov    0x8(%rsi),%rdi
call   10a0 <atoi@plt>
mov    %eax,0xc(%rsp)
jmp    11ce <main+0x4e>
lea    0xe74(%rip),%rdi
call   1030 <puts@plt>
lea    0xe3c(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1080 <scanf@plt>
lea    0xe2e(%rip),%rdi
lea    0xe33(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%r12
lea    0xe15(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %rax,%rdi
call   1060 <fscanf@plt>
mov    0x8(%rsp),%edi
shl    $0x2,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
cmpl   $0x0,0x8(%rsp)
jle    1240 <main+0xc0>
xor    %r13d,%r13d
lea    0xde8(%rip),%r15
mov    %r14,%rbx
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1060 <fscanf@plt>
add    $0x1,%r13
movslq 0x8(%rsp),%rax
add    $0x4,%rbx
cmp    %rax,%r13
jl     1220 <main+0xa0>
mov    %r12,%rdi
call   1040 <fclose@plt>
mov    0x8(%rsp),%ecx
add    $0xffffffff,%ecx
xor    %edx,%edx
mov    0xc(%rsp),%eax
jmp    1269 <main+0xe9>
nopw   0x0(%rax,%rax,1)
add    $0xffffffff,%edi
mov    %edi,%ecx
cmp    %ecx,%edx
jg     128b <main+0x10b>
lea    (%rcx,%rdx,1),%esi
mov    %esi,%edi
shr    $0x1f,%edi
add    %esi,%edi
sar    %edi
movslq %edi,%rbx
mov    (%r14,%rbx,4),%esi
cmp    %esi,%eax
jl     1260 <main+0xe0>
jle    12ab <main+0x12b>
add    $0x1,%edi
mov    %edi,%edx
cmp    %ecx,%edx
jle    1269 <main+0xe9>
cmp    %esi,%eax
je     129b <main+0x11b>
lea    0xdbb(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xd5f(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%eax
mov    (%r14,%rbx,4),%esi
cmp    %esi,%eax
jne    128f <main+0x10f>
jmp    129b <main+0x11b>

LLVM IR (-O0):
@.str = [38 x i8] c"Please enter a number to search for.\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [12 x i8] c"./Data8.txt\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [27 x i8] c"Number found at index %d.\0A\00"
@.str.5 = [19 x i8] c"Number not found.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32*
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32* null, i32** %7
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, 2
br i1 %15, label %16, label %21
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @atoi(i8* %19)
store i32 %20, i32* %8
br label %24
21: ; preds = %2
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 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* %8)
br label %24
24: ; preds = %21, %16
%25 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %25, i32** %12
%26 = load i32*, i32** %12
%27 = call i32 @fscanf(i32* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = mul i64 4, %29
%31 = trunc i64 %30 to i32
%32 = call i64 @malloc(i32 %31)
%33 = inttoptr i64 %32 to i32*
store i32* %33, i32** %7
store i32 0, i32* %13
br label %34
34: ; preds = %45, %24
%35 = load i32, i32* %13
%36 = load i32, i32* %6
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %48
38: ; preds = %34
%39 = load i32*, i32** %12
%40 = load i32*, i32** %7
%41 = load i32, i32* %13
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i32, i32* %40, i64 %42
%44 = call i32 @fscanf(i32* %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %43)
br label %45
45: ; preds = %38
%46 = load i32, i32* %13
%47 = add nsw i32 %46, 1
store i32 %47, i32* %13
br label %34
48: ; preds = %34
%49 = load i32*, i32** %12
%50 = call i32 @fclose(i32* %49)
%51 = load i32, i32* %6
%52 = sub nsw i32 %51, 1
store i32 %52, i32* %11
br label %53
53: ; preds = %84, %48
%54 = load i32, i32* %10
%55 = load i32, i32* %11
%56 = add nsw i32 %54, %55
%57 = sdiv i32 %56, 2
store i32 %57, i32* %9
%58 = load i32, i32* %8
%59 = load i32*, i32** %7
%60 = load i32, i32* %9
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i32, i32* %59, i64 %61
%63 = load i32, i32* %62
%64 = icmp slt i32 %58, %63
br i1 %64, label %65, label %68
65: ; preds = %53
%66 = load i32, i32* %9
%67 = sub nsw i32 %66, 1
store i32 %67, i32* %11
br label %83
68: ; preds = %53
%69 = load i32, i32* %8
%70 = load i32*, i32** %7
%71 = load i32, i32* %9
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i32, i32* %70, i64 %72
%74 = load i32, i32* %73
%75 = icmp sgt i32 %69, %74
br i1 %75, label %76, label %79
76: ; preds = %68
%77 = load i32, i32* %9
%78 = add nsw i32 %77, 1
store i32 %78, i32* %10
br label %82
79: ; preds = %68
%80 = load i32, i32* %9
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %80)
br label %88
82: ; preds = %76
br label %83
83: ; preds = %82, %65
br label %84
84: ; preds = %83
%85 = load i32, i32* %10
%86 = load i32, i32* %11
%87 = icmp sle i32 %85, %86
br i1 %87, label %53, label %88
88: ; preds = %84, %79
%89 = load i32, i32* %8
%90 = load i32*, i32** %7
%91 = load i32, i32* %9
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds i32, i32* %90, i64 %92
%94 = load i32, i32* %93
%95 = icmp ne i32 %89, %94
br i1 %95, label %96, label %98
96: ; preds = %88
%97 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
br label %98
98: ; preds = %96, %88
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [12 x i8] c"./Data8.txt\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [27 x i8] c"Number found at index %d.\0A\00"
@str = [37 x i8] c"Please enter a number to search for.\00"
@str.6 = [18 x i8] c"Number not found.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%6 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%7 = icmp eq i32 %0, 2
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
store i32 %11, i32* %4
br label %15
12: ; preds = %2
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 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* %4)
br label %15
15: ; preds = %12, %8
%16 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%17 = call i32 @fscanf(i32* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%18 = load i32, i32* %3
%19 = shl i32 %18, 2
%20 = call i64 @malloc(i32 %19)
%21 = inttoptr i64 %20 to i32*
%22 = load i32, i32* %3
%23 = icmp sgt i32 %22, 0
br i1 %23, label %29, label %24
24: ; preds = %29, %15
%25 = call i32 @fclose(i32* %16)
%26 = load i32, i32* %3
%27 = add nsw i32 %26, -1
%28 = load i32, i32* %4
br label %37
29: ; preds = %15, %29
%30 = phi i64 [ %33, %29 ], [ 0, %15 ]
%31 = getelementptr inbounds i32, i32* %21, i64 %30
%32 = call i32 @fscanf(i32* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %31)
%33 = add nuw nsw i64 %30, 1
%34 = load i32, i32* %3
%35 = sext i32 %34 to i64
%36 = icmp slt i64 %33, %35
br i1 %36, label %29, label %24
37: ; preds = %57, %24
%38 = phi i32 [ 0, %24 ], [ %58, %57 ]
%39 = phi i32 [ %27, %24 ], [ %59, %57 ]
%40 = add nsw i32 %39, %38
%41 = sdiv i32 %40, 2
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i32, i32* %21, i64 %42
%44 = load i32, i32* %43
%45 = icmp slt i32 %28, %44
br i1 %45, label %46, label %48
46: ; preds = %37
%47 = add nsw i32 %41, -1
br label %57
48: ; preds = %37
%49 = icmp sgt i32 %28, %44
br i1 %49, label %50, label %52
50: ; preds = %48
%51 = add nsw i32 %41, 1
br label %57
52: ; preds = %48
%53 = getelementptr inbounds i32, i32* %21, i64 %42
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %41)
%55 = load i32, i32* %4
%56 = load i32, i32* %53
br label %61
57: ; preds = %46, %50
%58 = phi i32 [ %38, %46 ], [ %51, %50 ]
%59 = phi i32 [ %47, %46 ], [ %39, %50 ]
%60 = icmp sgt i32 %58, %59
br i1 %60, label %61, label %37
61: ; preds = %57, %52
%62 = phi i32 [ %56, %52 ], [ %44, %57 ]
%63 = phi i32 [ %55, %52 ], [ %28, %57 ]
%64 = icmp eq i32 %63, %62
br i1 %64, label %67, label %65
65: ; preds = %61
%66 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.6, i64 0, i64 0))
br label %67
67: ; preds = %65, %61
ret i32 0
}