// File: /workspace/github_c_makefile_star2_O2/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), %rax
testq %rax, %rax
je 0x1a25
movq %rax, %r13
movb $0x1, %cl
movq %rax, %r14
testb $0x1, %cl
je 0x1a2e
testq %r14, %r14
je 0x19e1
cmpb %bl, (%r14)
jle 0x1a1a
testl %r12d, %r12d
jne 0x1a2a
pushq $0x18
popq %rdi
callq 0x1110
movq %rax, %r15
movb %bl, (%rax)
movq %r14, 0x10(%rax)
callq 0x190c
movq %rax, 0x8(%r15)
cmpq %r14, %r13
je 0x1a0b
movq %r15, 0x10(%r13)
jmp 0x1a13
movq -0x30(%rbp), %rax
movq %r15, 0x8(%rax)
xorl %ecx, %ecx
movq %r15, %r14
jmp 0x19d2
je 0x1a2e
movq 0x10(%r14), %rax
movq %r14, %r13
jmp 0x19cd
testl %r12d, %r12d
je 0x1a34
xorl %eax, %eax
jmp 0x1a58
movq 0x8(%r14), %rax
jmp 0x1a58
pushq $0x18
popq %rdi
callq 0x1110
movq %rax, %r15
movq -0x30(%rbp), %rax
movq %r15, 0x8(%rax)
movb %bl, (%r15)
andq $0x0, 0x10(%r15)
callq 0x190c
movq %rax, 0x8(%r15)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq