// File: /workspace/github_c_makefile_star2_O1/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 $0x48, %rsp
movq %r8, %r15
movq %rcx, %rbx
movl %edx, %r13d
movq %rsi, %r12
testq %rdi, %rdi
movq %r9, -0x38(%rbp)
je 0x1f61
movq %rbx, -0x70(%rbp)
xorl %r14d, %r14d
movq %rdi, -0x60(%rbp)
movq %rdi, -0x30(%rbp)
movq %rdi, %rbx
movq %r15, -0x58(%rbp)
movl %r13d, -0x4c(%rbp)
movq %r12, -0x68(%rbp)
testq %rbx, %rbx
je 0x1e95
movq (%rbx), %rdi
movq %r12, %rsi
callq 0x10e0
testl %eax, %eax
je 0x1e95
movq %rbx, -0x60(%rbp)
movq 0x20(%rbx), %rbx
jmp 0x1f53
movl $0x28, %edi
callq 0x1100
movq %r12, %rdi
movq %rax, %r12
callq 0x1090
leaq 0x1(%rax), %rdi
callq 0x1100
movq %rax, -0x40(%rbp)
movq %rax, (%r12)
movq -0x70(%rbp), %r14
movq %r14, %rdi
callq 0x1090
leaq 0x1(%rax), %rdi
callq 0x1100
movq %rax, %r15
movq %rax, 0x10(%r12)
movq %rbx, -0x48(%rbp)
movq -0x38(%rbp), %rbx
movq %rbx, %rdi
callq 0x1090
leaq 0x1(%rax), %rdi
callq 0x1100
movq %rax, %r13
movq %rax, 0x18(%r12)
movq -0x40(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x1040
movq %r15, %rdi
movq %r14, %rsi
callq 0x1040
movq %r13, %rdi
movl -0x4c(%rbp), %r13d
movq %rbx, %rsi
movq -0x48(%rbp), %rbx
callq 0x1040
movl %r13d, 0x8(%r12)
movq %rbx, 0x20(%r12)
cmpq %rbx, -0x30(%rbp)
je 0x1f3e
movq -0x60(%rbp), %rax
movq %r12, 0x20(%rax)
jmp 0x1f42
movq %r12, -0x30(%rbp)
movq -0x58(%rbp), %r15
incl (%r15)
movl $0x1, %r14d
movq -0x68(%rbp), %r12
testl %r14d, %r14d
je 0x1e74
jmp 0x1fef
movl $0x28, %edi
callq 0x1100
movq %rax, %r14
movq %r12, %rdi
callq 0x1090
leaq 0x1(%rax), %rdi
callq 0x1100
movq %rax, -0x48(%rbp)
movq %rax, (%r14)
movq %rbx, %rdi
callq 0x1090
leaq 0x1(%rax), %rdi
callq 0x1100
movq %rax, -0x40(%rbp)
movq %rax, 0x10(%r14)
movq -0x38(%rbp), %rdi
callq 0x1090
leaq 0x1(%rax), %rdi
callq 0x1100
movq %r12, %rsi
movq %rax, %r12
movq %rax, 0x18(%r14)
movq -0x48(%rbp), %rdi
callq 0x1040
movq -0x40(%rbp), %rdi
movq %rbx, %rsi
callq 0x1040
movq %r12, %rdi
movq -0x38(%rbp), %rsi
callq 0x1040
movl %r13d, 0x8(%r14)
movq %r14, -0x30(%rbp)
movq $0x0, 0x20(%r14)
incl (%r15)
movq -0x30(%rbp), %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq