#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*/ allocate(char ***, int);
int atoi(char *);
int binary_search(char **, char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ destroy(char ***, int);
int file_line_count(char *);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ insert_data(char **, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ sort_data(char **, int);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ write_data(char **, char *, int);
int main(int argc, char *argv[]) {
  if (argc < 4) {
    printf("Missing arguements\n");
    return -1;
  }
  int size = 0;
  if (strcmp(argv[1], "MAX_SIZE") == 0) {
    size = file_line_count(argv[2]);
  } else {
    size = atoi(argv[1]);
  }
  char **data;
  int i = 0;
  allocate(&data, size);
  insert_data(data, argv[2], size);
  sort_data(data, size);
  char yes;
  do {
    char target[25];
    printf("Searching for: ");
    scanf("%s", target);
    getchar();
    int found = binary_search(data, target, 0, size - 1);
    if (found >= 0) {
      printf("%s is in this dataset\n", target);
    } else {
      printf("Not in the dataset!\n");
    }
    printf("Continue? (y/n): ");
    scanf("%c", &yes);
    getchar();
  } while (yes != 'n');
  write_data(data, argv[3], size);
  destroy(&data, size);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    11fa <main+0x3a>
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1335 <main+0x175>
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe04(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1234 <main+0x74>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10b0 <file_line_count@plt>
mov    %eax,-0x14(%rbp)
jmp    1244 <main+0x84>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x14(%rbp),%esi
lea    -0x20(%rbp),%rdi
call   10d0 <allocate@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    -0x14(%rbp),%edx
call   1030 <insert_data@plt>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   10e0 <sort_data@plt>
lea    0xd9f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x40(%rbp),%rsi
lea    0xd9d(%rip),%rdi
call   10a0 <scanf@plt>
mov    $0x0,%al
call   1070 <getchar@plt>
mov    -0x20(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
xor    %edx,%edx
call   1090 <binary_search@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jl     12d5 <main+0x115>
lea    -0x40(%rbp),%rsi
lea    0xd67(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12e3 <main+0x123>
lea    0xd6b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd72(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd76(%rip),%rdi
lea    -0x25(%rbp),%rsi
call   10a0 <scanf@plt>
mov    $0x0,%al
call   1070 <getchar@plt>
movsbl -0x25(%rbp),%eax
cmp    $0x6e,%eax
jne    1277 <main+0xb7>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
mov    -0x14(%rbp),%edx
call   1060 <write_data@plt>
mov    -0x14(%rbp),%esi
lea    -0x20(%rbp),%rdi
call   1080 <destroy@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
cmp    $0x3,%edi
jg     11f9 <main+0x29>
lea    0xe72(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%eax
jmp    131f <main+0x14f>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xdf9(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     121c <main+0x4c>
mov    0x8(%rbx),%rdi
call   10d0 <atoi@plt>
jmp    1225 <main+0x55>
mov    0x10(%rbx),%rdi
call   10c0 <file_line_count@plt>
mov    %eax,%ebp
lea    0x8(%rsp),%rdi
mov    %eax,%esi
call   10e0 <allocate@plt>
mov    0x8(%rsp),%rdi
mov    %rbx,0x18(%rsp)
mov    0x10(%rbx),%rsi
mov    %ebp,%edx
call   1030 <insert_data@plt>
mov    0x8(%rsp),%rdi
mov    %ebp,%esi
call   10f0 <sort_data@plt>
mov    %rbp,0x10(%rsp)
add    $0xffffffff,%ebp
lea    0xdb6(%rip),%r13
lea    0x20(%rsp),%rbx
lea    0xdc4(%rip),%r15
lea    0xdcf(%rip),%r14
lea    0x7(%rsp),%r12
jmp    12af <main+0xdf>
nopl   (%rax)
lea    0xdc1(%rip),%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   10b0 <scanf@plt>
xor    %eax,%eax
call   1080 <getchar@plt>
cmpb   $0x6e,0x7(%rsp)
je     12f7 <main+0x127>
lea    0xd53(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
call   10b0 <scanf@plt>
xor    %eax,%eax
call   1080 <getchar@plt>
mov    0x8(%rsp),%rdi
mov    %rbx,%rsi
xor    %edx,%edx
mov    %ebp,%ecx
call   10a0 <binary_search@plt>
test   %eax,%eax
js     1280 <main+0xb0>
lea    0xd31(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    128c <main+0xbc>
mov    0x8(%rsp),%rdi
mov    0x18(%rsp),%rax
mov    0x18(%rax),%rsi
mov    0x10(%rsp),%rbx
mov    %ebx,%edx
call   1070 <write_data@plt>
lea    0x8(%rsp),%rdi
mov    %ebx,%esi
call   1090 <destroy@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Missing arguements\0A\00"
@.str.1 = [9 x i8] c"MAX_SIZE\00"
@.str.2 = [16 x i8] c"Searching for: \00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [23 x i8] c"%s is in this dataset\0A\00"
@.str.5 = [21 x i8] c"Not in the dataset!\0A\00"
@.str.6 = [18 x i8] c"Continue? (y/n): \00"
@.str.7 = [3 x i8] c"%c\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i8
%10 = alloca [25 x i8]
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 4
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %78
16: ; preds = %2
store i32 0, i32* %6
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %16
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = call i32 @file_line_count(i8* %25)
store i32 %26, i32* %6
br label %32
27: ; preds = %16
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32 @atoi(i8* %30)
store i32 %31, i32* %6
br label %32
32: ; preds = %27, %22
store i32 0, i32* %8
%33 = load i32, i32* %6
%34 = call i32 @allocate(i8*** %7, i32 %33)
%35 = load i8**, i8*** %7
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 2
%38 = load i8*, i8** %37
%39 = load i32, i32* %6
%40 = call i32 @insert_data(i8** %35, i8* %38, i32 %39)
%41 = load i8**, i8*** %7
%42 = load i32, i32* %6
%43 = call i32 @sort_data(i8** %41, i32 %42)
br label %44
44: ; preds = %65, %32
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%46 = getelementptr inbounds [25 x i8], [25 x i8]* %10, i64 0, i64 0
%47 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %46)
%48 = call i32 (...) @getchar()
%49 = load i8**, i8*** %7
%50 = getelementptr inbounds [25 x i8], [25 x i8]* %10, i64 0, i64 0
%51 = load i32, i32* %6
%52 = sub nsw i32 %51, 1
%53 = call i32 @binary_search(i8** %49, i8* %50, i32 0, i32 %52)
store i32 %53, i32* %11
%54 = load i32, i32* %11
%55 = icmp sge i32 %54, 0
br i1 %55, label %56, label %59
56: ; preds = %44
%57 = getelementptr inbounds [25 x i8], [25 x i8]* %10, i64 0, i64 0
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %57)
br label %61
59: ; preds = %44
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
br label %61
61: ; preds = %59, %56
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
%63 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* %9)
%64 = call i32 (...) @getchar()
br label %65
65: ; preds = %61
%66 = load i8, i8* %9
%67 = sext i8 %66 to i32
%68 = icmp ne i32 %67, 110
br i1 %68, label %44, label %69
69: ; preds = %65
%70 = load i8**, i8*** %7
%71 = load i8**, i8*** %5
%72 = getelementptr inbounds i8*, i8** %71, i64 3
%73 = load i8*, i8** %72
%74 = load i32, i32* %6
%75 = call i32 @write_data(i8** %70, i8* %73, i32 %74)
%76 = load i32, i32* %6
%77 = call i32 @destroy(i8*** %7, i32 %76)
br label %78
78: ; preds = %69, %14
%79 = load i32, i32* %3
ret i32 %79
}

LLVM IR (-O2):
@.str.1 = [9 x i8] c"MAX_SIZE\00"
@.str.2 = [16 x i8] c"Searching for: \00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [23 x i8] c"%s is in this dataset\0A\00"
@.str.6 = [18 x i8] c"Continue? (y/n): \00"
@.str.7 = [3 x i8] c"%c\00"
@str = [20 x i8] c"Not in the dataset!\00"
@str.8 = [19 x i8] c"Missing arguements\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8**
%4 = alloca i8
%5 = alloca [25 x i8]
%6 = icmp slt i32 %0, 4
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.8, i64 0, i64 0))
br label %56
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
%17 = tail call i32 @file_line_count(i8* %16)
br label %21
18: ; preds = %9
%19 = load i8*, i8** %10
%20 = tail call i32 @atoi(i8* %19)
br label %21
21: ; preds = %18, %14
%22 = phi i32 [ %17, %14 ], [ %20, %18 ]
%23 = bitcast i8*** %3 to i8*
%24 = call i32 @allocate(i8*** %3, i32 %22)
%25 = load i8**, i8*** %3
%26 = getelementptr inbounds i8*, i8** %1, i64 2
%27 = load i8*, i8** %26
%28 = call i32 @insert_data(i8** %25, i8* %27, i32 %22)
%29 = load i8**, i8*** %3
%30 = call i32 @sort_data(i8** %29, i32 %22)
%31 = getelementptr inbounds [25 x i8], [25 x i8]* %5, i64 0, i64 0
%32 = add nsw i32 %22, -1
br label %33
33: ; preds = %44, %21
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%35 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %31)
%36 = call i32 (...) @getchar()
%37 = load i8**, i8*** %3
%38 = call i32 @binary_search(i8** %37, i8* %31, i32 0, i32 %32)
%39 = icmp sgt i32 %38, -1
br i1 %39, label %40, label %42
40: ; preds = %33
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %31)
br label %44
42: ; preds = %33
%43 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %44
44: ; preds = %42, %40
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
%46 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* %4)
%47 = call i32 (...) @getchar()
%48 = load i8, i8* %4
%49 = icmp eq i8 %48, 110
br i1 %49, label %50, label %33
50: ; preds = %44
%51 = load i8**, i8*** %3
%52 = getelementptr inbounds i8*, i8** %1, i64 3
%53 = load i8*, i8** %52
%54 = call i32 @write_data(i8** %51, i8* %53, i32 %22)
%55 = call i32 @destroy(i8*** %3, i32 %22)
br label %56
56: ; preds = %50, %7
%57 = phi i32 [ -1, %7 ], [ 0, %50 ]
ret i32 %57
}