// File: /workspace/github_c_makefile_star2_O3/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 $0x58, %rsp
movq %r9, 0x20(%rsp)
movl %r8d, 0x14(%rsp)
movl %ecx, %ebx
movl %edx, %r14d
movq %rsi, %r12
movq %rdi, %r15
leaq 0x38(%rsp), %rdi
movsd 0xf301(%rip), %xmm0     # 0x1b020
xorl %ebp, %ebp
xorl %esi, %esi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x83e1
testl %eax, %eax
je 0xbd48
movl %eax, %r13d
movl %r13d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %ebx, (%rsp)
movq %r15, 0x8(%rsp)
movl (%r12), %esi
cmpl %r14d, %esi
jle 0xbd9b
movl (%rsp), %esi
testl %esi, %esi
je 0xbf15
cmpl %esi, %ebp
je 0xbf15
movl 0x19546(%rip), %eax     # 0x252b8
movl %eax, 0x19530(%rip)     # 0x252a8
movq 0x8(%rsp), %rdi
addq $0x1200, %rdi           # imm = 0x1200
callq 0x91d8
movq (%rax), %rax
movq %rax, 0x1951d(%rip)     # 0x252b0
movl $0xb, %r13d
jmp 0xbd36
movq 0x8(%rsp), %rax
leaq 0x1440(%rax), %rbx
addq $0x1200, %rax           # imm = 0x1200
movq %rax, 0x18(%rsp)
leaq 0x38(%rsp), %r13
movl %r14d, 0x4(%rsp)
movq %rbx, %rdi
callq 0x91d8
movl (%rax), %ebp
cmpl (%rsp), %ebp
je 0xbf15
movq %rax, %r15
movq 0x18(%rsp), %rdi
movl %ebp, %esi
callq 0x91d8
cmpl $0x0, 0x24(%rax)
jne 0xbf5a
movq %rax, %r14
movq %r13, %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0x8bb3
testl %eax, %eax
jne 0xbd33
movq %r13, %rdi
movl (%r12), %r13d
movl 0x38(%rsp), %esi
callq 0x91d8
movl %r13d, (%rax)
leaq 0x10(%r15), %rax
movq %rax, 0x30(%rsp)
movl (%r12), %esi
movq %rbx, %rdi
callq 0x91d8
cmpl $0x0, 0x14(%rax)
je 0xbeb9
leaq 0x28(%r15), %rax
movq %rax, 0x28(%rsp)
addq $0x30, %r15
movl (%r12), %ebp
leal 0x1(%rbp), %eax
movl %eax, (%r12)
movl 0x14(%r14), %r8d
movl 0x28(%r14), %ecx
movq 0x8(%rsp), %rdi
movq %r12, %rsi
movl 0x4(%rsp), %edx
leaq 0x30(%rsp), %r9
pushq %r15
pushq 0x30(%rsp)
callq 0xbcef
addq $0x10, %rsp
testl %eax, %eax
jne 0xbedc
movl (%r12), %r14d
movq %rbx, %rdi
movl %ebp, %esi
callq 0x91d8
movl %r14d, 0x14(%rax)
movl (%r12), %esi
movq %rbx, %rdi
callq 0x91d8
movl (%rax), %ebp
movq 0x18(%rsp), %rdi
movl %ebp, %esi
callq 0x91d8
movq %rax, %r14
movl (%r12), %esi
movq %rbx, %rdi
callq 0x91d8
cmpl $0x0, 0x14(%rax)
jne 0xbe41
movl (%r12), %eax
leal 0x1(%rax), %esi
movl %esi, (%r12)
movl 0x4(%rsp), %r14d
cmpl %r14d, %eax
leaq 0x38(%rsp), %r13
jl 0xbdbc
jmp 0xbd59
movl %eax, %r13d
cmpl $0xc, %eax
jne 0xbd36
cmpl $0x0, 0x193b9(%rip)     # 0x252a8
jne 0xbd36
movl (%r12), %esi
movq %rbx, %rdi
callq 0x91d8
movl 0x4(%rax), %eax
movl %eax, 0x1939e(%rip)     # 0x252a8
movl $0xc, %r13d
jmp 0xbd36
leaq 0x38(%rsp), %rbx
movl (%rbx), %ecx
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
movl $0x1, %edx
movl 0x14(%rsp), %r8d
movq 0x20(%rsp), %r9
pushq 0x98(%rsp)
pushq 0x98(%rsp)
callq 0xc372
addq $0x10, %rsp
movl %eax, %r13d
movq %rbx, %rdi
callq 0x847e
jmp 0xbd36
movl 0x4(%r15), %eax
movl %eax, 0x19344(%rip)     # 0x252a8
movl $0xa, %r13d
jmp 0xbd36