#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 */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ *fopen(char *, char const *);
char *getNextWord(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ setSortThreads(int);
int /*<<< orphan*/ sortThreaded(char **, unsigned int);
int main(int argv, char *argc[]) {
  FILE *fd;
  char **test;
  const char *mode = "r";
  test = (char **)calloc(500, sizeof(char *));
  unsigned int i = 0;
  printf("Hello\n");
  fd = fopen("/cs_Share/class/cs360/lib/gettysburg", mode);
  setSortThreads(20);
  printf("Hello this is main talking\n");
  do {
    test[i] = getNextWord(fd);
    i++;
  } while (test[i - 1] != NULL);
  sortThreaded(test, i - 1);
  int j;
  for (j = 0; j < i - 1; j++) {
    printf("%s\n", test[j]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe83(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    $0x1f4,%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rsi
lea    0xe55(%rip),%rdi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    $0x14,%edi
call   1060 <setSortThreads@plt>
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <getNextWord@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    %rdx,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
mov    %ecx,%ecx
cmpq   $0x0,(%rax,%rcx,8)
jne    11d5 <main+0x75>
mov    -0x20(%rbp),%rdi
mov    -0x2c(%rbp),%esi
sub    $0x1,%esi
call   1080 <sortThreaded@plt>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jae    125b <main+0xfb>
mov    -0x20(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1222 <main+0xc2>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    $0x1f4,%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,%r14
lea    0xea9(%rip),%rdi
call   1030 <puts@plt>
lea    0xe78(%rip),%rdi
lea    0xe6f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r15
mov    $0x14,%edi
call   1060 <setSortThreads@plt>
lea    0xe83(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%ebx
mov    %r15,%rdi
call   1040 <getNextWord@plt>
mov    %rax,(%r14,%rbx,8)
test   %rax,%rax
jne    11c0 <main+0x60>
mov    %r14,%rdi
mov    %ebx,%esi
call   1080 <sortThreaded@plt>
test   %ebx,%ebx
je     1202 <main+0xa2>
mov    %ebx,%r15d
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    (%r14,%rbx,8),%rdi
call   1030 <puts@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    11f0 <main+0x90>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [7 x i8] c"Hello\0A\00"
@.str.2 = [37 x i8] c"/cs_Share/class/cs360/lib/gettysburg\00"
@.str.3 = [28 x i8] c"Hello this is main talking\0A\00"
@.str.4 = [4 x i8] c"%s\0A\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 i8*
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %8
%11 = call i64 @calloc(i32 500, i32 8)
%12 = inttoptr i64 %11 to i8**
store i8** %12, i8*** %7
store i32 0, i32* %9
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%14 = load i8*, i8** %8
%15 = call i32* @fopen(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %14)
store i32* %15, i32** %6
%16 = call i32 @setSortThreads(i32 20)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
br label %18
18: ; preds = %27, %2
%19 = load i32*, i32** %6
%20 = call i8* @getNextWord(i32* %19)
%21 = load i8**, i8*** %7
%22 = load i32, i32* %9
%23 = zext i32 %22 to i64
%24 = getelementptr inbounds i8*, i8** %21, i64 %23
store i8* %20, i8** %24
%25 = load i32, i32* %9
%26 = add i32 %25, 1
store i32 %26, i32* %9
br label %27
27: ; preds = %18
%28 = load i8**, i8*** %7
%29 = load i32, i32* %9
%30 = sub i32 %29, 1
%31 = zext i32 %30 to i64
%32 = getelementptr inbounds i8*, i8** %28, i64 %31
%33 = load i8*, i8** %32
%34 = icmp ne i8* %33, null
br i1 %34, label %18, label %35
35: ; preds = %27
%36 = load i8**, i8*** %7
%37 = load i32, i32* %9
%38 = sub i32 %37, 1
%39 = call i32 @sortThreaded(i8** %36, i32 %38)
store i32 0, i32* %10
br label %40
40: ; preds = %52, %35
%41 = load i32, i32* %10
%42 = load i32, i32* %9
%43 = sub i32 %42, 1
%44 = icmp ult i32 %41, %43
br i1 %44, label %45, label %55
45: ; preds = %40
%46 = load i8**, i8*** %7
%47 = load i32, i32* %10
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8*, i8** %46, i64 %48
%50 = load i8*, i8** %49
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %50)
br label %52
52: ; preds = %45
%53 = load i32, i32* %10
%54 = add nsw i32 %53, 1
store i32 %54, i32* %10
br label %40
55: ; preds = %40
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.2 = [37 x i8] c"/cs_Share/class/cs360/lib/gettysburg\00"
@str = [6 x i8] c"Hello\00"
@str.5 = [27 x i8] c"Hello this is main talking\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 @calloc(i32 500, i32 8)
%4 = inttoptr i64 %3 to i8**
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @setSortThreads(i32 20)
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.5, i64 0, i64 0))
br label %9
9: ; preds = %9, %2
%10 = phi i32 [ 0, %2 ], [ %14, %9 ]
%11 = tail call i8* @getNextWord(i32* %6)
%12 = zext i32 %10 to i64
%13 = getelementptr inbounds i8*, i8** %4, i64 %12
store i8* %11, i8** %13
%14 = add i32 %10, 1
%15 = icmp eq i8* %11, null
br i1 %15, label %16, label %9
16: ; preds = %9
%17 = zext i32 %10 to i64
%18 = tail call i32 @sortThreaded(i8** %4, i32 %10)
%19 = icmp eq i32 %10, 0
br i1 %19, label %27, label %20
20: ; preds = %16, %20
%21 = phi i64 [ %25, %20 ], [ 0, %16 ]
%22 = getelementptr inbounds i8*, i8** %4, i64 %21
%23 = load i8*, i8** %22
%24 = tail call i32 @puts(i8* dereferenceable(1) %23)
%25 = add nuw nsw i64 %21, 1
%26 = icmp eq i64 %25, %17
br i1 %26, label %27, label %20
27: ; preds = %20, %16
ret i32 0
}