// File: /workspace/github_c_makefile_star2_O2/devkot[P]SearchEngine/Crawler/functions.c
// Function: readFile
int readFile(char *inputFile, TrieNode *trie, int *nWords, int *nChars, int *nLines){
    char lineBuffer[100000], *word, whitespaces[3] = " \t";
    char tags[100] = "<html></html><head></head><body></body><!DOCTYPE html></a><a href html";
    int lineNumber = 0;
    FILE *file;
    file = fopen(inputFile, "r");                           // Open file

    if (file == NULL){
        perror("Error: ");
        exit(EXIT_FAILURE);
    }

    while(fgets(lineBuffer, 99999, file)){
        (*nChars) += strlen(lineBuffer);                    // calculate total file characters (with whitespaces and \n)

        strtok(lineBuffer, "\n");                           // remove the useless \n character at the end of the line

        word = strtok(lineBuffer, whitespaces);             // feed strtok

        if(!strstr(tags,word)) {                            // filter out tags
            insertWord(trie, word, lineNumber, inputFile);  // insert to trie
            (*nWords)++;                                    // increase the total number of words of Trie
        }

        while ((word = strtok(NULL, whitespaces))){         // start reading the document word by word
            if(!strstr(tags,word)){                         // filter out tags
//                continue;

                insertWord(trie, word, lineNumber, inputFile);  // insert to trie (filename, line, n)
                (*nWords)++;                                    // increase the total number of words of Trie
//			    docWords++;                                     // increase the total number of words of current document
            }
        }
        lineNumber++;

    }
    (*nLines) += lineNumber;
    fclose(file);

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18738, %rsp          # imm = 0x18738
movq %r8, -0x48(%rbp)
movq %rcx, -0x50(%rbp)
movq %rdx, -0x58(%rbp)
movq %rsi, -0x40(%rbp)
movq %rdi, %rax
leaq 0xb06(%rip), %rsi       # 0x20c0
pushq $0x64
popq %rcx
leaq -0xc0(%rbp), %rdi
rep  movsb (%rsi), %es:(%rdi)
leaq 0xaae(%rip), %rsi       # 0x207b
movq %rax, -0x38(%rbp)
movq %rax, %rdi
callq 0x1130
movq %rax, -0x30(%rbp)
testq %rax, %rax
je 0x16ae
xorl %r14d, %r14d
leaq -0x18760(%rbp), %rbx
leaq 0xa90(%rip), %r15       # 0x2087
leaq -0xc0(%rbp), %r12
movq %rbx, %rdi
movl $0x1869f, %esi          # imm = 0x1869F
movq -0x30(%rbp), %rdx
callq 0x10d0
testq %rax, %rax
je 0x168c
movq %rbx, %rdi
callq 0x1090
movq -0x50(%rbp), %rcx
addl %eax, (%rcx)
movq %rbx, %rdi
leaq 0xa59(%rip), %rsi       # 0x2085
callq 0x1150
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1150
movq %rax, %r13
movq %r12, %rdi
movq %rax, %rsi
callq 0x11a0
testq %rax, %rax
je 0x1669
xorl %edi, %edi
movq %r15, %rsi
callq 0x1150
testq %rax, %rax
je 0x1684
movq %rax, %r13
movq %r12, %rdi
movq %rax, %rsi
jmp 0x1645
movq -0x40(%rbp), %rdi
movq %r13, %rsi
movl %r14d, %edx
movq -0x38(%rbp), %rcx
callq 0x192a
movq -0x58(%rbp), %rax
incl (%rax)
jmp 0x164f
incl %r14d
jmp 0x15fe
movq -0x48(%rbp), %rax
addl %r14d, (%rax)
movq -0x30(%rbp), %rdi
callq 0x1070
addq $0x18738, %rsp          # imm = 0x18738
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x9c8(%rip), %rdi       # 0x207d
callq 0x1140
pushq $0x1
popq %rdi
callq 0x1190