// File: /workspace/github_c_makefile_star2_O1/devkot[P]SearchEngine/Crawler/trie.c
// Function: findNextTrieNode
TrieNode * findNextTrieNode(TrieNode *root, char c, int searchMode){
    int done = 0;
    TrieNodeList *curNode = root->charList, *prevNode = root->charList, *newNode;

    if (!curNode){                          // if our trie node does not have a list of child nodes
        if (searchMode)                     // if we are simply searching for a word
            return NULL;                    // return NULL
        root->charList = curNode = newNode = (TrieNodeList *) malloc(sizeof(TrieNodeList)); // create the first node of the list
        newNode->letter = c;                // assign the letter
        newNode->next   = NULL;             // next pointer is null
        newNode->node   = createTrieNode(); // create the actual trie node
    }
    else{                                   // if our trie node has at least one child node
        while (!done){                      // start iterating the list of nodes
            if (!curNode || c < curNode->letter){ // if the current node corresponds to a letter bigger than the one we want
                if (searchMode)                   // if we are simply searching for a word
                    return NULL;                  // return NULL

                newNode = (TrieNodeList *) malloc(sizeof(TrieNodeList));
                newNode->letter = c;              // assign the letter
                newNode->next = curNode;          // next node of the new node is the current node
                newNode->node = createTrieNode(); // create the actual trie node
                if (prevNode != curNode)          // if the new node is not actually going to be the first node
                    prevNode->next = newNode;     // previous node will point to current node
                else                              // if this is the new head of the list
                    root->charList = newNode;     // make sure it now points to the new node
                curNode = newNode;                // store it here to return it at the end of the function
                done = 1;
            }
            else if (c == curNode->letter){ // if the node we are looking for already exists
                done = 1;
            }
            else{                         // if the current node corresponds to a letter lower than the one we want
                prevNode = curNode;       // go to next node
                curNode = curNode->next;  // go to next node
            }
        }
    }

    return curNode->node;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edx, %r12d
movl %esi, %ebx
movq %rdi, -0x30(%rbp)
movq 0x8(%rdi), %r15
testq %r15, %r15
je 0x1b13
movq %r15, %r13
xorl %eax, %eax
testq %r13, %r13
je 0x1aa9
cmpb %bl, (%r13)
jle 0x1ae8
testl %r12d, %r12d
jne 0x1b18
movl $0x18, %edi
callq 0x1100
movq %rax, %r14
movb %bl, (%rax)
movq %r13, 0x10(%rax)
movl $0x18, %edi
callq 0x1100
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
movq %rax, 0x8(%r14)
cmpq %r13, %r15
je 0x1af4
movq %r14, 0x10(%r15)
jmp 0x1afc
jne 0x1b0a
movl $0x1, %eax
movq %r13, %r14
jmp 0x1b01
movq -0x30(%rbp), %rax
movq %r14, 0x8(%rax)
movl $0x1, %eax
movq %r14, %r13
testl %eax, %eax
je 0x1a9e
jmp 0x1b52
movq 0x10(%r13), %r14
movq %r13, %r15
jmp 0x1b01
testl %r12d, %r12d
je 0x1b1c
xorl %eax, %eax
jmp 0x1b56
movl $0x18, %edi
callq 0x1100
movq %rax, %r14
movq -0x30(%rbp), %rax
movq %r14, 0x8(%rax)
movb %bl, (%r14)
xorl %ebx, %ebx
movq %rbx, 0x10(%r14)
movl $0x18, %edi
callq 0x1100
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq %rbx, 0x10(%rax)
movq %rax, 0x8(%r14)
movq 0x8(%r14), %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq