// File: /workspace/github_c_makefile_star2_O2/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, %r13
movq %r8, %rbx
movq %rcx, %r12
movl %edx, -0x34(%rbp)
movq %rsi, %r15
testq %rdi, %rdi
movq %rcx, -0x58(%rbp)
je 0x1dfc
movq %rdi, -0x48(%rbp)
movq %rdi, -0x30(%rbp)
movq %rbx, -0x50(%rbp)
movq %r13, -0x60(%rbp)
movb $0x1, %al
movq %rdi, -0x40(%rbp)
testb $0x1, %al
je 0x1e86
testq %rdi, %rdi
je 0x1d33
movq (%rdi), %rdi
movq %r15, %rsi
callq 0x10f0
movq -0x40(%rbp), %rcx
testl %eax, %eax
jne 0x1def
pushq $0x28
popq %rdi
callq 0x1110
movq %r12, %rbx
movq %rax, %r12
movq %r15, %rdi
callq 0x1090
leaq 0x1(%rax), %rdi
callq 0x1110
movq %rax, %r14
movq %rax, (%r12)
movq %rbx, %rdi
callq 0x1090
leaq 0x1(%rax), %rdi
callq 0x1110
movq %rax, %rbx
movq %rax, 0x10(%r12)
movq %r13, %rdi
callq 0x1090
leaq 0x1(%rax), %rdi
callq 0x1110
movq %rax, %r13
movq %rax, 0x18(%r12)
movq %r14, %rdi
movq %r15, %r14
movq %r15, %rsi
callq 0x1040
movq %rbx, %rdi
movq -0x58(%rbp), %rsi
movq %rsi, %r15
callq 0x1040
movq %r13, %rdi
movq -0x60(%rbp), %r13
movq %r13, %rsi
callq 0x1040
movq -0x40(%rbp), %rdi
movl -0x34(%rbp), %eax
movl %eax, 0x8(%r12)
movq %rdi, 0x20(%r12)
cmpq %rdi, -0x30(%rbp)
je 0x1dd8
movq -0x48(%rbp), %rax
movq %r12, 0x20(%rax)
jmp 0x1ddc
movq %r12, -0x30(%rbp)
movq -0x50(%rbp), %rbx
incl (%rbx)
xorl %eax, %eax
movq %r15, %r12
movq %r14, %r15
jmp 0x1d0f
movq 0x20(%rcx), %rdi
movq %rcx, -0x48(%rbp)
jmp 0x1d09
pushq $0x28
popq %rdi
callq 0x1110
movq %rax, %r14
movq %r15, %rdi
callq 0x1090
leaq 0x1(%rax), %rdi
callq 0x1110
movq %rax, -0x40(%rbp)
movq %rax, (%r14)
movq %r12, %rdi
callq 0x1090
leaq 0x1(%rax), %rdi
callq 0x1110
movq %rax, -0x30(%rbp)
movq %rax, 0x10(%r14)
movq %r13, %rdi
callq 0x1090
leaq 0x1(%rax), %rdi
callq 0x1110
movq %rax, %r12
movq %rax, 0x18(%r14)
movq -0x40(%rbp), %rdi
movq %r15, %rsi
callq 0x1040
movq -0x30(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x1040
movq %r12, %rdi
movq %r13, %rsi
callq 0x1040
movl -0x34(%rbp), %eax
movl %eax, 0x8(%r14)
movq %r14, -0x30(%rbp)
andq $0x0, 0x20(%r14)
incl (%rbx)
movq -0x30(%rbp), %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq