// File: /workspace/github_c_makefile_star2_O1/heltilda[P]cicada/cmpile.c
// Function: relinkExpression
ccInt relinkExpression(compiler_type *compiler, ccInt *loopToken, ccInt topToken, ccInt endTokenType, ccInt expectedType,
        ccInt **lastOrderedToken, ccBool **lastRtrnTypes, ccInt *lastTokenToFix)
{
    ccInt rtrn, oneTokenType = 0, *enclosedArgs;
    tokenSpecType *oneSpec;
    linkedlist OoOblock;
    
    rtrn = newLinkedList(&OoOblock, 0, sizeof(ccInt), 2., ccFalse);
    if (rtrn != passed)  return rtrn;
    
    
        // loop over all tokens in our current block
    
    while (*loopToken <= topToken)  {
        
        scriptTokenType *oneScriptToken = scriptToken(*loopToken);
        oneTokenType = oneScriptToken->tokenID;
        if (oneTokenType == endTokenType)  break;
        
        
            // decide whether we've hit the end of a sentence or sentence block
        
        oneSpec = tokenSpec(oneTokenType);
        if (oneSpec->prevToken != 0)  {
            errPosition = oneScriptToken->tokenCharNum;
            return unexpected_token_err;       }
        
        
            // jot down the token for future reordering
        
        rtrn = addElements(&OoOblock, 1, ccFalse);
        if (rtrn != passed)  return rtrn;
        *LL_int(&OoOblock, OoOblock.elementNum) = *loopToken;
        
        
            // if the token expects a nextToken, recursively reorder everything from here to nextToken.
            // Multiple nextTokens are chained together here via their nextExpression fields
        
        enclosedArgs = &(oneScriptToken->enclosedArgs);
        
        while (scriptToken(*loopToken)->nextScriptToken != 0)  {
            
            ccInt previousScriptToken = *loopToken;
            
            (*loopToken)++;
            
            rtrn = relinkExpression(compiler, loopToken, topToken, oneSpec->nextToken, oneSpec->rightArgType,
                        &enclosedArgs, &(oneScriptToken->rtrnTypes), &(oneScriptToken->adapterTokenToFix));
            if (rtrn != passed)  {
                if ((rtrn == arg_expected_err) && (errPosition == 0))  errPosition = scriptToken(*loopToken)->tokenCharNum;
                return rtrn;        }
            
            scriptToken(previousScriptToken)->nextScriptToken = *loopToken;
            
            oneTokenType = scriptToken(*loopToken)->tokenID;
            oneSpec = tokenSpec(oneTokenType);        }
        
        
            // advance to the next token
        
        (*loopToken)++;
    }
    
    
        // if there's an ending token we're expecting, we'd better have ended with it
    
    if ((endTokenType != 0) && (oneTokenType != endTokenType))  {
        errPosition = lastScriptChar;
        expectedTokenName = tokenSpec(endTokenType)->name;
        return token_expected_err;       }
    
    
        // after we've recorded all the tokens in this expression, we do the reordering
    
    rtrn = relinkBestToken(compiler, &OoOblock, 1, OoOblock.elementNum, expectedType, lastOrderedToken, lastRtrnTypes, lastTokenToFix);
    
    deleteLinkedList(&OoOblock);
    
    return rtrn;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %r9, %r15
movl %r8d, 0xc(%rsp)
movl %ecx, %r14d
movl %edx, %ebx
movq %rsi, %r13
movq %rdi, %r12
leaq 0x48(%rsp), %rdi
movsd 0xf213(%rip), %xmm0     # 0x1b020
xorl %ebp, %ebp
xorl %esi, %esi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x83e1
testl %eax, %eax
je 0xbe30
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, 0x30(%rsp)
movl %r14d, 0x1c(%rsp)
movl (%r13), %esi
cmpl %ebx, %esi
movl 0xc(%rsp), %r15d
jg 0xc001
leaq 0x1440(%r12), %rax
movq %rax, 0x20(%rsp)
leaq 0x1200(%r12), %rax
movq %rax, 0x28(%rsp)
movq %r12, 0x10(%rsp)
movl %ebx, 0x4(%rsp)
movq 0x20(%rsp), %rdi
callq 0x911c
movq %rax, %r14
movl (%rax), %ebp
movl $0x3, %eax
cmpl 0x1c(%rsp), %ebp
je 0xbebb
movq 0x28(%rsp), %rdi
movl %ebp, %esi
callq 0x911c
cmpl $0x0, 0x24(%rax)
je 0xbed4
movl 0x4(%r14), %eax
movl %eax, 0x19404(%rip)     # 0x252a8
movl $0xa, 0x8(%rsp)
movl $0x1, %eax
movl 0xc(%rsp), %r15d
movq 0x10(%rsp), %r12
movl 0x4(%rsp), %ebx
testl %eax, %eax
jne 0xbffc
movl (%r13), %esi
cmpl %ebx, %esi
jle 0xbe6e
jmp 0xc001
movq %rax, %r12
leaq 0x48(%rsp), %r15
movq %r15, %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0x8b6a
testl %eax, %eax
je 0xbef8
movl %eax, 0x8(%rsp)
jmp 0xbfdd
movl (%r13), %ebx
movl 0x48(%rsp), %esi
movq %r15, %rdi
callq 0x911c
movl %ebx, (%rax)
leaq 0x10(%r14), %rax
movq %rax, 0x40(%rsp)
leaq 0x28(%r14), %rax
movq %rax, 0x38(%rsp)
addq $0x30, %r14
movl (%r13), %esi
movq 0x20(%rsp), %rdi
callq 0x911c
movl (%r13), %ebx
leal 0x1(%rbx), %ecx
cmpl $0x0, 0x14(%rax)
movl %ecx, (%r13)
je 0xbff5
movl 0x14(%r12), %r8d
movl 0x28(%r12), %ecx
movq 0x10(%rsp), %rdi
movq %r13, %rsi
movl 0x4(%rsp), %edx
leaq 0x40(%rsp), %r9
pushq %r14
pushq 0x40(%rsp)
callq 0xbddf
addq $0x10, %rsp
movl %eax, %r15d
testl %eax, %eax
je 0xbfa1
cmpl $0xc, %r15d
jne 0xbf9a
cmpl $0x0, 0x19327(%rip)     # 0x252a8
jne 0xbf9a
movl (%r13), %esi
movq 0x20(%rsp), %rdi
callq 0x911c
movl 0x4(%rax), %eax
movl %eax, 0x1930e(%rip)     # 0x252a8
movl %r15d, 0x8(%rsp)
jmp 0xbfd4
movl (%r13), %ebp
movq 0x20(%rsp), %r12
movq %r12, %rdi
movl %ebx, %esi
callq 0x911c
movl %ebp, 0x14(%rax)
movl (%r13), %esi
movq %r12, %rdi
callq 0x911c
movl (%rax), %ebp
movq 0x28(%rsp), %rdi
movl %ebp, %esi
callq 0x911c
movq %rax, %r12
testl %r15d, %r15d
je 0xbf20
movl 0xc(%rsp), %r15d
movq 0x10(%rsp), %r12
movl 0x4(%rsp), %ebx
movl $0x1, %eax
jmp 0xbebf
xorl %eax, %eax
jmp 0xbeb1
cmpl $0x3, %eax
jne 0xc07e
movl 0x1c(%rsp), %esi
testl %esi, %esi
je 0xc03c
cmpl %esi, %ebp
je 0xc03c
movl 0x192a5(%rip), %eax     # 0x252b8
movl %eax, 0x1928f(%rip)     # 0x252a8
addq $0x1200, %r12           # imm = 0x1200
movq %r12, %rdi
callq 0x911c
movq (%rax), %rax
movq %rax, 0x1927e(%rip)     # 0x252b0
movl $0xb, %eax
jmp 0xbe21
leaq 0x48(%rsp), %rbx
movl (%rbx), %ecx
movq %r12, %rdi
movq %rbx, %rsi
movl $0x1, %edx
movl %r15d, %r8d
movq 0x30(%rsp), %r9
pushq 0xa8(%rsp)
pushq 0xa8(%rsp)
callq 0xc4e0
addq $0x10, %rsp
movl %eax, %ebp
movq %rbx, %rdi
callq 0x847e
movl %ebp, %eax
jmp 0xbe21
movl 0x8(%rsp), %eax
jmp 0xbe21