#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 */
char *checkPunctuation(char *);
int /*<<< orphan*/ deleteDictionary(char **, int *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ extendArraySize(char ***, int **, int, int);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ insertWord(char **, int *, int, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printDictionary(char **, int *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ saveDictionary(char **, int *, char *, int);
int searchArray(char **, int, char *);
int strlen(char *);
char tolower(char);
int main(int argc, char *argv[]) {
  if (argc != 3) {
    printf("Incorrect number of inputs. Exiting Now...\n");
    exit(0);
  }
  FILE *readfp = fopen(argv[1], "r");
  if (readfp == NULL) {
    printf("Error opening file to be read\n");
    exit(0);
  }
  int dictionarySize = 64;
  char **dictionary = (char **)malloc(sizeof(char *) * dictionarySize);
  int *countingArray = (int *)malloc(sizeof(int) * dictionarySize);
  int wordCount = 0;
  int rawWordCount = 0;
  char tempWord[64];
  while (fscanf(readfp, "%s", tempWord) == 1) {
    char *revised = checkPunctuation(tempWord);
    rawWordCount++;
    for (int i = 0; i < strlen(revised); i++) {
      revised[i] = tolower(revised[i]);
    }
    int wordCheck = searchArray(dictionary, wordCount, revised);
    if (wordCheck < 0) {
      if (wordCount == dictionarySize) {
        dictionarySize = dictionarySize * 2;
        extendArraySize(&dictionary, &countingArray, wordCount, dictionarySize);
      }
      insertWord(dictionary, countingArray, wordCount, revised);
      wordCount++;
    } else {
      countingArray[wordCheck]++;
    }
  }
  printDictionary(dictionary, countingArray, wordCount);
  saveDictionary(dictionary, countingArray, argv[2], wordCount);
  deleteDictionary(dictionary, countingArray, wordCount);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1216 <main+0x36>
lea    0xdf6(%rip),%rdi
call   1060 <printf@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe07(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    124c <main+0x6c>
lea    0xdee(%rip),%rdi
call   1060 <printf@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
movl   $0x40,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x28(%rbp)
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x80(%rbp),%rdx
lea    0xdb7(%rip),%rsi
call   1080 <fscanf@plt>
cmp    $0x1,%eax
jne    13b9 <main+0x1d9>
lea    -0x80(%rbp),%rdi
call   10b0 <checkPunctuation@plt>
mov    %rax,-0x88(%rbp)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
movl   $0x0,-0x8c(%rbp)
mov    -0x8c(%rbp),%eax
mov    %eax,-0x94(%rbp)
mov    -0x88(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x94(%rbp),%eax
cmp    %ecx,%eax
jge    132d <main+0x14d>
mov    -0x88(%rbp),%rax
movslq -0x8c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1090 <tolower@plt>
mov    %al,%dl
mov    -0x88(%rbp),%rax
movslq -0x8c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8c(%rbp)
jmp    12c7 <main+0xe7>
mov    -0x28(%rbp),%rdi
mov    -0x34(%rbp),%esi
mov    -0x88(%rbp),%rdx
call   10e0 <searchArray@plt>
mov    %eax,-0x90(%rbp)
cmpl   $0x0,-0x90(%rbp)
jge    13a0 <main+0x1c0>
mov    -0x34(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jne    137b <main+0x19b>
mov    -0x1c(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x34(%rbp),%edx
mov    -0x1c(%rbp),%ecx
lea    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1030 <extendArraySize@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x34(%rbp),%edx
mov    -0x88(%rbp),%rcx
call   10d0 <insertWord@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    13b4 <main+0x1d4>
mov    -0x30(%rbp),%rax
movslq -0x90(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
mov    %edx,(%rax,%rcx,4)
jmp    1287 <main+0xa7>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   1070 <printDictionary@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
mov    -0x34(%rbp),%ecx
call   1100 <saveDictionary@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   1040 <deleteDictionary@plt>
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
cmp    $0x3,%edi
jne    137e <main+0x19e>
mov    %rsi,%r15
mov    0x8(%rsi),%rdi
lea    0xdfb(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     1387 <main+0x1a7>
mov    %rax,%r13
mov    $0x200,%edi
call   10a0 <malloc@plt>
mov    %rax,%r14
mov    %rax,0x10(%rsp)
mov    $0x100,%edi
call   10a0 <malloc@plt>
mov    %rax,%rbp
mov    %rax,0x8(%rsp)
lea    0xdc1(%rip),%rsi
lea    0x20(%rsp),%rdx
mov    %r13,%rdi
call   1080 <fscanf@plt>
cmp    $0x1,%eax
jne    1327 <main+0x147>
mov    %r15,0x18(%rsp)
xor    %ebx,%ebx
mov    $0x40,%r15d
lea    0x20(%rsp),%r12
jmp    1296 <main+0xb6>
nopl   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rcx
mov    %eax,%eax
addl   $0x1,(%rcx,%rax,4)
mov    %r13,%rdi
lea    0xd7d(%rip),%rsi
mov    %r12,%rdx
call   1080 <fscanf@plt>
cmp    $0x1,%eax
jne    132b <main+0x14b>
mov    %r12,%rdi
call   10b0 <checkPunctuation@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1060 <strlen@plt>
test   %eax,%eax
jle    12d1 <main+0xf1>
xor    %ebp,%ebp
nop
movsbl (%r14,%rbp,1),%edi
call   1090 <tolower@plt>
mov    %al,(%r14,%rbp,1)
add    $0x1,%rbp
mov    %r14,%rdi
call   1060 <strlen@plt>
cltq
cmp    %rax,%rbp
jl     12b0 <main+0xd0>
mov    0x10(%rsp),%rdi
mov    %ebx,%esi
mov    %r14,%rdx
call   10e0 <searchArray@plt>
test   %eax,%eax
jns    1270 <main+0x90>
cmp    %r15d,%ebx
jne    130b <main+0x12b>
mov    %r13,%rbp
lea    (%r15,%r15,1),%r13d
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
mov    %r15d,%edx
mov    %r13d,%ecx
call   1030 <extendArraySize@plt>
mov    %r13d,%r15d
mov    %rbp,%r13
mov    0x10(%rsp),%rdi
mov    0x8(%rsp),%rsi
mov    %ebx,%edx
mov    %r14,%rcx
call   10d0 <insertWord@plt>
add    $0x1,%ebx
jmp    127b <main+0x9b>
xor    %ebx,%ebx
jmp    133a <main+0x15a>
mov    0x10(%rsp),%r14
mov    0x8(%rsp),%rbp
mov    0x18(%rsp),%r15
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %ebx,%edx
call   1070 <printDictionary@plt>
mov    0x10(%rsp),%rdi
mov    0x8(%rsp),%rsi
mov    0x10(%r15),%rdx
mov    %ebx,%ecx
call   1100 <saveDictionary@plt>
mov    0x10(%rsp),%rdi
mov    0x8(%rsp),%rsi
mov    %ebx,%edx
call   1050 <deleteDictionary@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc9e(%rip),%rdi
jmp    138e <main+0x1ae>
lea    0xc77(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
@.str = [44 x i8] c"Incorrect number of inputs. Exiting Now...\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [31 x i8] c"Error opening file to be read\0A\00"
@.str.3 = [3 x i8] c"%s\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 i8**
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca [64 x i8]
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 3
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @exit(i32 0)
unreachable
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %25, i32** %6
%26 = load i32*, i32** %6
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %31
28: ; preds = %21
%29 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%30 = call i32 @exit(i32 0)
unreachable
31: ; preds = %21
store i32 64, i32* %7
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = mul i64 8, %33
%35 = trunc i64 %34 to i32
%36 = call i64 @malloc(i32 %35)
%37 = inttoptr i64 %36 to i8**
store i8** %37, i8*** %8
%38 = load i32, i32* %7
%39 = sext i32 %38 to i64
%40 = mul i64 4, %39
%41 = trunc i64 %40 to i32
%42 = call i64 @malloc(i32 %41)
%43 = inttoptr i64 %42 to i32*
store i32* %43, i32** %9
store i32 0, i32* %10
store i32 0, i32* %11
br label %44
44: ; preds = %105, %31
%45 = load i32*, i32** %6
%46 = getelementptr inbounds [64 x i8], [64 x i8]* %12, i64 0, i64 0
%47 = call i32 @fscanf(i32* %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %46)
%48 = icmp eq i32 %47, 1
br i1 %48, label %49, label %106
49: ; preds = %44
%50 = getelementptr inbounds [64 x i8], [64 x i8]* %12, i64 0, i64 0
%51 = call i8* @checkPunctuation(i8* %50)
store i8* %51, i8** %13
%52 = load i32, i32* %11
%53 = add nsw i32 %52, 1
store i32 %53, i32* %11
store i32 0, i32* %14
br label %54
54: ; preds = %70, %49
%55 = load i32, i32* %14
%56 = load i8*, i8** %13
%57 = call i32 @strlen(i8* %56)
%58 = icmp slt i32 %55, %57
br i1 %58, label %59, label %73
59: ; preds = %54
%60 = load i8*, i8** %13
%61 = load i32, i32* %14
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %60, i64 %62
%64 = load i8, i8* %63
%65 = call signext i8 @tolower(i8 signext %64)
%66 = load i8*, i8** %13
%67 = load i32, i32* %14
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8, i8* %66, i64 %68
store i8 %65, i8* %69
br label %70
70: ; preds = %59
%71 = load i32, i32* %14
%72 = add nsw i32 %71, 1
store i32 %72, i32* %14
br label %54
73: ; preds = %54
%74 = load i8**, i8*** %8
%75 = load i32, i32* %10
%76 = load i8*, i8** %13
%77 = call i32 @searchArray(i8** %74, i32 %75, i8* %76)
store i32 %77, i32* %15
%78 = load i32, i32* %15
%79 = icmp slt i32 %78, 0
br i1 %79, label %80, label %98
80: ; preds = %73
%81 = load i32, i32* %10
%82 = load i32, i32* %7
%83 = icmp eq i32 %81, %82
br i1 %83, label %84, label %90
84: ; preds = %80
%85 = load i32, i32* %7
%86 = mul nsw i32 %85, 2
store i32 %86, i32* %7
%87 = load i32, i32* %10
%88 = load i32, i32* %7
%89 = call i32 @extendArraySize(i8*** %8, i32** %9, i32 %87, i32 %88)
br label %90
90: ; preds = %84, %80
%91 = load i8**, i8*** %8
%92 = load i32*, i32** %9
%93 = load i32, i32* %10
%94 = load i8*, i8** %13
%95 = call i32 @insertWord(i8** %91, i32* %92, i32 %93, i8* %94)
%96 = load i32, i32* %10
%97 = add nsw i32 %96, 1
store i32 %97, i32* %10
br label %105
98: ; preds = %73
%99 = load i32*, i32** %9
%100 = load i32, i32* %15
%101 = sext i32 %100 to i64
%102 = getelementptr inbounds i32, i32* %99, i64 %101
%103 = load i32, i32* %102
%104 = add nsw i32 %103, 1
store i32 %104, i32* %102
br label %105
105: ; preds = %98, %90
br label %44
106: ; preds = %44
%107 = load i8**, i8*** %8
%108 = load i32*, i32** %9
%109 = load i32, i32* %10
%110 = call i32 @printDictionary(i8** %107, i32* %108, i32 %109)
%111 = load i8**, i8*** %8
%112 = load i32*, i32** %9
%113 = load i8**, i8*** %5
%114 = getelementptr inbounds i8*, i8** %113, i64 2
%115 = load i8*, i8** %114
%116 = load i32, i32* %10
%117 = call i32 @saveDictionary(i8** %111, i32* %112, i8* %115, i32 %116)
%118 = load i8**, i8*** %8
%119 = load i32*, i32** %9
%120 = load i32, i32* %10
%121 = call i32 @deleteDictionary(i8** %118, i32* %119, i32 %120)
%122 = load i32, i32* %3
ret i32 %122
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [3 x i8] c"%s\00"
@str = [30 x i8] c"Error opening file to be read\00"
@str.4 = [43 x i8] c"Incorrect number of inputs. Exiting Now...\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8**
%4 = alloca i32*
%5 = alloca [64 x i8]
%6 = icmp eq i32 %0, 3
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str.4, i64 0, i64 0))
%9 = tail call i32 @exit(i32 0)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%17 = tail call i32 @exit(i32 0)
unreachable
18: ; preds = %10
%19 = bitcast i8*** %3 to i8*
%20 = tail call i64 @malloc(i32 512)
%21 = inttoptr i64 %20 to i8**
store i8** %21, i8*** %3
%22 = bitcast i32** %4 to i8*
%23 = tail call i64 @malloc(i32 256)
%24 = inttoptr i64 %23 to i32*
store i32* %24, i32** %4
%25 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%26 = call i32 @fscanf(i32* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %25)
%27 = icmp eq i32 %26, 1
br i1 %27, label %28, label %72
28: ; preds = %18, %64
%29 = phi i32 [ %66, %64 ], [ 64, %18 ]
%30 = phi i32 [ %65, %64 ], [ 0, %18 ]
%31 = call i8* @checkPunctuation(i8* %25)
%32 = call i32 @strlen(i8* %31)
%33 = icmp sgt i32 %32, 0
br i1 %33, label %38, label %34
34: ; preds = %38, %28
%35 = load i8**, i8*** %3
%36 = call i32 @searchArray(i8** %35, i32 %30, i8* %31)
%37 = icmp slt i32 %36, 0
br i1 %37, label %47, label %58
38: ; preds = %28, %38
%39 = phi i64 [ %43, %38 ], [ 0, %28 ]
%40 = getelementptr inbounds i8, i8* %31, i64 %39
%41 = load i8, i8* %40
%42 = call signext i8 @tolower(i8 signext %41)
store i8 %42, i8* %40
%43 = add nuw nsw i64 %39, 1
%44 = call i32 @strlen(i8* %31)
%45 = sext i32 %44 to i64
%46 = icmp slt i64 %43, %45
br i1 %46, label %38, label %34
47: ; preds = %34
%48 = icmp eq i32 %30, %29
br i1 %48, label %49, label %52
49: ; preds = %47
%50 = shl nsw i32 %29, 1
%51 = call i32 @extendArraySize(i8*** %3, i32** %4, i32 %29, i32 %50)
br label %52
52: ; preds = %49, %47
%53 = phi i32 [ %50, %49 ], [ %29, %47 ]
%54 = load i8**, i8*** %3
%55 = load i32*, i32** %4
%56 = call i32 @insertWord(i8** %54, i32* %55, i32 %30, i8* %31)
%57 = add nsw i32 %30, 1
br label %64
58: ; preds = %34
%59 = load i32*, i32** %4
%60 = zext i32 %36 to i64
%61 = getelementptr inbounds i32, i32* %59, i64 %60
%62 = load i32, i32* %61
%63 = add nsw i32 %62, 1
store i32 %63, i32* %61
br label %64
64: ; preds = %58, %52
%65 = phi i32 [ %57, %52 ], [ %30, %58 ]
%66 = phi i32 [ %53, %52 ], [ %29, %58 ]
%67 = call i32 @fscanf(i32* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %25)
%68 = icmp eq i32 %67, 1
br i1 %68, label %28, label %69
69: ; preds = %64
%70 = load i8**, i8*** %3
%71 = load i32*, i32** %4
br label %72
72: ; preds = %69, %18
%73 = phi i32* [ %24, %18 ], [ %71, %69 ]
%74 = phi i8** [ %21, %18 ], [ %70, %69 ]
%75 = phi i32 [ 0, %18 ], [ %65, %69 ]
%76 = call i32 @printDictionary(i8** %74, i32* %73, i32 %75)
%77 = load i8**, i8*** %3
%78 = load i32*, i32** %4
%79 = getelementptr inbounds i8*, i8** %1, i64 2
%80 = load i8*, i8** %79
%81 = call i32 @saveDictionary(i8** %77, i32* %78, i8* %80, i32 %75)
%82 = load i8**, i8*** %3
%83 = load i32*, i32** %4
%84 = call i32 @deleteDictionary(i8** %82, i32* %83, i32 %75)
ret i32 0
}