// File: /workspace/github_c_makefile_star2_O3/devkot[P]SearchEngine/Crawler/helpers.c
// Function: addWordSearchNode
WordSearchNode *addWordSearchNode(WordSearchNode *head, char *fileName, int line, char *contents, int *numOfDocs, char *word){
    WordSearchNode *curNode = head, *prevNode = head, *newNode;
    int done = 0;

    if(!head){              // if list is empty
        head = (WordSearchNode *) malloc(sizeof(WordSearchNode));
        head->fileName = (char *) malloc(strlen(fileName) + 1);
        head->contents = (char *) malloc(strlen(contents) + 1);
        head->word     = (char *) malloc(strlen(word) + 1);

        strcpy(head->fileName, fileName);
        strcpy(head->contents, contents);
        strcpy(head->word, word);

        head->line     = line;
        head->next     = NULL;
        (*numOfDocs)++;
    }
    else{                   // if list is not empty
        while(!done){
            if((!curNode || !strcmp(curNode->fileName, fileName))){

                newNode = (WordSearchNode *) malloc(sizeof(WordSearchNode));
                newNode->fileName = (char *) malloc(strlen(fileName) + 1);
                newNode->contents = (char *) malloc(strlen(contents) + 1);
                newNode->word     = (char *) malloc(strlen(word) + 1);

                strcpy(newNode->fileName, fileName);
                strcpy(newNode->contents, contents);
                strcpy(newNode->word, word);

                newNode->line = line;
                newNode->next = curNode;

                if (head == curNode)
                    head = newNode;
                else
                    prevNode->next = newNode;
                (*numOfDocs)++;
                done = 1;
            }
            else if(strcmp(curNode->fileName, fileName) != 0){      // we still need to traverse the list
                prevNode = curNode;
                curNode = curNode->next;
            }
            else if(!strcmp(curNode->word, word))
                done = 1;
            else
                done = 1;
        }
    }
    return head;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r9, %r12
movq %r8, -0x60(%rbp)
movq %rsi, %rbx
testq %rdi, %rdi
movl %edx, -0x2c(%rbp)
movq %rcx, -0x40(%rbp)
je 0x1e3a
movq %rdi, %r13
movq %rdi, -0x38(%rbp)
movq %rdi, %r14
movq %r13, %r15
movq (%r13), %rdi
movq %rbx, %rsi
callq 0x10f0
testl %eax, %eax
je 0x1eca
movq 0x20(%r15), %r13
movq %r15, %r14
testq %r13, %r13
jne 0x1e12
jmp 0x1ecd
movq %rcx, %r15
movl $0x28, %edi
callq 0x1110
movq %rax, %r14
movq %rbx, %rdi
callq 0x1090
leaq 0x1(%rax), %rdi
callq 0x1110
movq %rax, -0x38(%rbp)
movq %rax, (%r14)
movq %r15, %rdi
callq 0x1090
leaq 0x1(%rax), %rdi
callq 0x1110
movq %r12, %r15
movq %rax, %r12
movq %rax, 0x10(%r14)
movq %r15, %rdi
callq 0x1090
leaq 0x1(%rax), %rdi
callq 0x1110
movq %rax, %r13
movq %rax, 0x18(%r14)
movq -0x38(%rbp), %rdi
movq %rbx, %rsi
callq 0x1040
movq %r12, %rdi
movq -0x40(%rbp), %rsi
callq 0x1040
movq %r13, %rdi
movq %r15, %rsi
callq 0x1040
movl -0x2c(%rbp), %eax
movl %eax, 0x8(%r14)
xorl %r15d, %r15d
movq %r14, %rax
jmp 0x1f61
movq %r15, %r13
movl $0x28, %edi
callq 0x1110
movq %rax, %r15
movq %rbx, %rdi
callq 0x1090
leaq 0x1(%rax), %rdi
callq 0x1110
movq %rax, -0x58(%rbp)
movq %rax, (%r15)
movq -0x40(%rbp), %rdi
callq 0x1090
leaq 0x1(%rax), %rdi
callq 0x1110
movq %rax, -0x50(%rbp)
movq %rax, 0x10(%r15)
movq %r12, %rdi
callq 0x1090
leaq 0x1(%rax), %rdi
callq 0x1110
movq %r12, -0x48(%rbp)
movq %rax, %r12
movq %rax, 0x18(%r15)
movq -0x58(%rbp), %rdi
movq %rbx, %rsi
callq 0x1040
movq -0x50(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x1040
movq %r12, %rdi
movq -0x48(%rbp), %rsi
callq 0x1040
movl -0x2c(%rbp), %eax
movl %eax, 0x8(%r15)
movq %r13, 0x20(%r15)
movq -0x38(%rbp), %rax
cmpq %rax, %r13
je 0x1f68
movq %r15, 0x20(%r14)
movq %rax, %r15
movq -0x60(%rbp), %rax
incl (%rax)
movq %r15, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq