// File: /workspace/github_c_makefile_star2_O3/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 %esi, %r14d
movq %rdi, %rbx
movq 0x8(%rdi), %r12
addq $0x8, %rbx
testq %r12, %r12
je 0x1abe
movq %r12, %r13
movq %r12, %r15
cmpb %r14b, (%r12)
jg 0x1af2
je 0x1b32
movq 0x10(%r15), %r12
movq %r15, %r13
testq %r12, %r12
jne 0x1aa1
jmp 0x1af5
testl %edx, %edx
jne 0x1af9
movl $0x18, %edi
callq 0x1110
movq %rax, %r15
movq %rax, (%rbx)
movb %r14b, (%rax)
movq $0x0, 0x10(%rax)
movl $0x1, %edi
movl $0x18, %esi
callq 0x10e0
movq %rax, 0x8(%r15)
jmp 0x1b36
movq %r15, %r12
testl %edx, %edx
je 0x1afd
xorl %eax, %eax
jmp 0x1b36
movl $0x18, %edi
callq 0x1110
movq %rax, %r15
movb %r14b, (%rax)
movq %r12, 0x10(%rax)
movl $0x1, %edi
movl $0x18, %esi
callq 0x10e0
movq %rax, 0x8(%r15)
leaq 0x10(%r13), %rax
cmpq %r12, %r13
cmoveq %rbx, %rax
movq %r15, (%rax)
movq 0x8(%r15), %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq