// File: /workspace/github_c_makefile_star2_O3/heltilda[P]cicada/cmpile.c
// Function: findToken
ccInt findToken(compiler_type *compiler, linkedlist *tokenStringList, char **scriptStringPtr, ccInt *whichElement,
        ccBool endWithNull, ccBool maybeVariableName)
{
    ccInt loopElement, searchBottom = 1, searchTop = tokenStringList->elementNum;
    ccInt numLanguageOps = compiler->numLanguageOps[(ccInt) **scriptStringPtr], directionToAdjust;
    char *scriptChar, *storedChar, *scriptStringStart = *scriptStringPtr;
    ccBool isWord = ccFalse, comparingLanguageOp = ccTrue, maybeFinishedScriptToken, finishedScriptToken, finishedStoredToken;
    
    if (searchTop == 0)  {  *whichElement = 1;  return ccFalse;  }
    
    
        // loop over all tokens in the current list
    
    *whichElement = 0;
    do  {
        scriptChar = scriptStringStart;
        
        if (searchBottom > numLanguageOps)  {
            if ((comparingLanguageOp) && (*whichElement > 0))  break;       // interpret it as a language op if possible
            comparingLanguageOp = ccFalse;      }
        
        if (comparingLanguageOp)  loopElement = searchBottom;               // first do an enumerative search over all built-in operators,
        else  loopElement = (searchBottom+searchTop)/2;                     // then a binary search over the stored variable names
        
        
            // try to match all of the characters of this particular token
        
        storedChar = ((tokenStringType *) element(tokenStringList, loopElement))->name;
        while (*storedChar != 0)  {
            
            isWord = ccFalse;
            if (*storedChar != ' ')  {
                if ((lettertype(scriptChar) == a_letter) || (lettertype(scriptChar) == a_number))  isWord = ccTrue;
                if (*scriptChar != *storedChar)  break;
                
                nextChar(&scriptChar);
                storedChar++;       }
            
            else  {                         // spaces get special treatment
                if ((*(storedChar+1) == ' ') && (*scriptChar != *storedChar))  break;
                else  {
                    while (*storedChar == ' ')  storedChar++;
                    while ((*scriptChar == ' ') || (*scriptChar == '\t') || (lettertype(scriptChar) == unprintable))  {
                        scriptChar++;
        }   }   }   }
        
        
            // figure out if we have to move up (directionToAdjust = 1), down (directionToAdjust = -1), or if we have a match
        
        if ( ((isWord) && ((lettertype(scriptChar) == a_letter) || (lettertype(scriptChar) == a_number)))
                    || ((endWithNull) && (lettertype(scriptChar) != a_null)) )  {
            finishedScriptToken = maybeFinishedScriptToken = ccFalse;       }
        else  {
            finishedScriptToken = (!comparingLanguageOp);
            maybeFinishedScriptToken = ccTrue;            }
        finishedStoredToken = (*storedChar == 0);
        
        if ((maybeFinishedScriptToken) && (finishedStoredToken))  directionToAdjust = 0;
        else if (finishedScriptToken)  directionToAdjust = -1;
        else if (finishedStoredToken) directionToAdjust = 1;
        else  {
            while (lettertype(storedChar) == a_space)  nextChar(&storedChar);       // operator spaces confuse the alphabetization
            while (lettertype(scriptChar) == a_space)  scriptChar++;
            
            if (*scriptChar < *storedChar)  directionToAdjust = -1;
            else  directionToAdjust = 1;            }
        
        
            // adjust searchBottom/searchTop accordingly
        
        if (directionToAdjust == -1)  {
            if (!comparingLanguageOp)  searchTop = loopElement-1;
            else if ((!maybeVariableName) || (!(*whichElement == 0)))  break;
            else  searchBottom = numLanguageOps+1;      }
        
        else if (directionToAdjust == 0)  {
            *whichElement = loopElement;
            *scriptStringPtr = scriptChar;
            if (!comparingLanguageOp)  break;
            else  searchBottom++;           }
        
        else  searchBottom = loopElement+1;
        
    }  while (searchBottom <= searchTop);
    
    
        // if the string wasn't found, return the position where a new entry can be inserted
    
    if (*whichElement == 0)  {
        *whichElement = searchBottom;
        return  ccFalse;       }
    
    else  return ccTrue;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %r9d, 0x20(%rsp)
movl %r8d, 0x24(%rsp)
movq %rsi, 0x40(%rsp)
movl (%rsi), %ebx
testl %ebx, %ebx
je 0xb757
movq %rdx, 0x28(%rsp)
movq (%rdx), %rax
movq %rax, 0x30(%rsp)
movsbq (%rax), %rax
movl 0x1000(%rdi,%rax,4), %eax
movq %rcx, 0x10(%rsp)
movl $0x0, (%rcx)
movq %rax, 0x38(%rsp)
incl %eax
movl %eax, 0x1c(%rsp)
movb $0x1, %al
movl %eax, 0xc(%rsp)
movl $0x1, %ebp
xorl %r12d, %r12d
leaq 0x16baf(%rip), %r15     # 0x22180
cmpl 0x38(%rsp), %ebp
jle 0xb5ed
cmpb $0x0, 0xc(%rsp)
je 0xb5fa
movq 0x10(%rsp), %rax
cmpl $0x0, (%rax)
jle 0xb5fa
jmp 0xb75e
movb $0x1, %r14b
movl %ebp, %r13d
cmpb $0x0, 0xc(%rsp)
jne 0xb615
leal (%rbx,%rbp), %eax
movl %eax, %r13d
shrl $0x1f, %r13d
addl %eax, %r13d
sarl %r13d
xorl %r14d, %r14d
movl $0x0, 0xc(%rsp)
movq 0x40(%rsp), %rdi
movl %r13d, %esi
callq 0x91d8
movq (%rax), %rcx
movq 0x30(%rsp), %rax
movzbl (%rcx), %edx
cmpl $0x20, %edx
je 0xb666
testl %edx, %edx
je 0xb69c
movzbl (%rax), %edi
movl (%r15,%rdi,4), %esi
leal -0x3(%rsi), %r8d
cmpl $0x2, %r8d
setb %r12b
cmpb %dl, %dil
jne 0xb69c
cmpl $0x6, %esi
je 0xb661
movzbl 0x1(%rax), %edx
incq %rax
cmpl $0x0, (%r15,%rdx,4)
je 0xb653
incq %rcx
jmp 0xb62a
cmpb $0x20, 0x1(%rcx)
jne 0xb671
cmpb $0x20, (%rax)
jne 0xb6b2
decq %rcx
cmpb $0x20, 0x1(%rcx)
leaq 0x1(%rcx), %rcx
je 0xb674
jmp 0xb683
incq %rax
movzbl (%rax), %edx
cmpl $0x9, %edx
je 0xb680
cmpl $0x20, %edx
je 0xb680
cmpl $0x0, (%r15,%rdx,4)
je 0xb680
xorl %r12d, %r12d
jmp 0xb62a
testb %r12b, %r12b
je 0xb6b2
movzbl (%rax), %esi
movl (%r15,%rsi,4), %esi
addl $-0x3, %esi
cmpl $0x2, %esi
jae 0xb6b5
jmp 0xb6d1
xorl %r12d, %r12d
cmpb $0x0, 0x24(%rsp)
je 0xb6c6
movzbl (%rax), %esi
cmpl $0x6, (%r15,%rsi,4)
jne 0xb6d1
testb %dl, %dl
je 0xb72e
testb %r14b, %r14b
jne 0xb6d5
jmp 0xb726
testb %dl, %dl
je 0xb71e
cmpl $0x1, (%r15,%rdx,4)
jne 0xb6ec
incq %rcx
movzbl (%rcx), %edx
incq %rcx
cmpl $0x2, (%r15,%rdx,4)
jb 0xb6df
movzbl (%rax), %ecx
incq %rax
cmpl $0x1, (%r15,%rcx,4)
je 0xb6ec
cmpb %dl, %cl
jge 0xb71e
testb %r14b, %r14b
je 0xb726
movq 0x10(%rsp), %rax
movl (%rax), %r13d
cmpb $0x0, 0x20(%rsp)
je 0xb765
movl 0x1c(%rsp), %eax
movl %eax, %ebp
testl %r13d, %r13d
je 0xb745
jmp 0xb75e
incl %r13d
movl %r13d, %ebp
jmp 0xb745
decl %r13d
movl %r13d, %ebx
jmp 0xb745
movq 0x10(%rsp), %rcx
movl %r13d, (%rcx)
movq 0x28(%rsp), %rcx
movq %rax, (%rcx)
testb %r14b, %r14b
je 0xb765
incl %ebp
cmpl %ebx, %ebp
jle 0xb5d1
movq 0x10(%rsp), %rcx
movl (%rcx), %r13d
jmp 0xb76a
movl $0x1, %ebp
jmp 0xb774
movl $0x1, %eax
jmp 0xb778
movq 0x10(%rsp), %rcx
movl $0x1, %eax
testl %r13d, %r13d
jne 0xb778
movl %ebp, (%rcx)
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq