// File: /workspace/github_c_makefile_star2_O2/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, 0x30(%rsp)
movl %r8d, 0x24(%rsp)
movl %ecx, %r14d
movl %edx, %ebx
movq %rsi, %r12
movq %rdi, %rbp
leaq 0x48(%rsp), %rdi
pushq $0x4
popq %rdx
movsd 0xd999(%rip), %xmm0     # 0x19020
xorl %r15d, %r15d
xorl %esi, %esi
xorl %ecx, %ecx
callq 0x83d5
testl %eax, %eax
je 0xb69f
movl %eax, %r13d
jmp 0xb7ff
movl %ebx, 0xc(%rsp)
movl %r14d, 0x8(%rsp)
leaq 0x1440(%rbp), %rbx
movq %rbp, 0x28(%rsp)
leaq 0x1200(%rbp), %rax
movq %rax, 0x18(%rsp)
movl (%r12), %esi
cmpl 0xc(%rsp), %esi
jg 0xb811
movq %rbx, %rdi
callq 0x9088
movq %rax, 0x10(%rsp)
movl (%rax), %r15d
cmpl 0x8(%rsp), %r15d
je 0xb842
movq 0x18(%rsp), %rdi
movl %r15d, %esi
callq 0x9088
cmpl $0x0, 0x24(%rax)
jne 0xb883
movq %rax, %rbp
leaq 0x48(%rsp), %r14
movq %r14, %rdi
pushq $0x1
popq %rsi
xorl %edx, %edx
callq 0x8b0f
testl %eax, %eax
jne 0xb697
movq %r14, %rdi
movl (%r12), %r14d
movl 0x48(%rsp), %esi
callq 0x9088
movl %r14d, (%rax)
movq 0x10(%rsp), %rcx
leaq 0x10(%rcx), %rax
movq %rax, 0x40(%rsp)
leaq 0x28(%rcx), %rax
movq %rax, 0x38(%rsp)
addq $0x30, %rcx
movq %rcx, 0x10(%rsp)
movl (%r12), %esi
movq %rbx, %rdi
callq 0x9088
movl (%r12), %r14d
leal 0x1(%r14), %esi
cmpl $0x0, 0x14(%rax)
movl %esi, (%r12)
je 0xb6c4
movl 0x14(%rbp), %r8d
movl 0x28(%rbp), %ecx
movq 0x28(%rsp), %rdi
movq %r12, %rsi
movl 0xc(%rsp), %edx
leaq 0x40(%rsp), %r9
pushq 0x10(%rsp)
pushq 0x40(%rsp)
callq 0xb654
addq $0x10, %rsp
testl %eax, %eax
jne 0xb7d5
movl (%r12), %ebp
movq %rbx, %rdi
movl %r14d, %esi
callq 0x9088
movl %ebp, 0x14(%rax)
movl (%r12), %esi
movq %rbx, %rdi
callq 0x9088
movl (%rax), %r15d
movq 0x18(%rsp), %rdi
movl %r15d, %esi
callq 0x9088
movq %rax, %rbp
jmp 0xb750
movl %eax, %r13d
cmpl $0xc, %eax
jne 0xb7ff
cmpl $0x0, 0x18ac4(%rip)     # 0x242a8
jne 0xb7ff
movl (%r12), %esi
movq %rbx, %rdi
callq 0x9088
movl 0x4(%rax), %eax
movl %eax, 0x18aad(%rip)     # 0x242a8
pushq $0xc
popq %r13
movl %r13d, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x8(%rsp), %esi
testl %esi, %esi
je 0xb842
cmpl %esi, %r15d
je 0xb842
movl 0x18a94(%rip), %eax     # 0x242b8
movl %eax, 0x18a7e(%rip)     # 0x242a8
movq 0x18(%rsp), %rdi
callq 0x9088
movq (%rax), %rax
movq %rax, 0x18a72(%rip)     # 0x242b0
pushq $0xb
jmp 0xb7fd
leaq 0x48(%rsp), %rbx
movl (%rbx), %ecx
pushq $0x1
popq %rdx
movq 0x28(%rsp), %rdi
movq %rbx, %rsi
movl 0x24(%rsp), %r8d
movq 0x30(%rsp), %r9
pushq 0xa8(%rsp)
pushq 0xa8(%rsp)
callq 0xbc61
popq %rcx
popq %rdx
movl %eax, %r13d
movq %rbx, %rdi
callq 0x846b
jmp 0xb7ff
movq 0x10(%rsp), %rax
movl 0x4(%rax), %eax
movl %eax, 0x18a17(%rip)     # 0x242a8
pushq $0xa
jmp 0xb7fd