// File: /workspace/github_c_makefile_star2_O1/heltilda[P]cicada/cmpile.c
// Function: writeTokenOps
ccInt writeTokenOps(compiler_type *compiler, ccInt theToken, ccBool replaceCommandWords)
{
    ccInt nextOpPosition, loopToken, loopJump, rtrn;
    ccInt tokenCharNum = scriptToken(theToken)->tokenCharNum;
    ccInt jumpMarkers[9], jumps[9], jumpTo[9], numJumps = 0;
    ccInt theTokenID = scriptToken(theToken)->tokenID;
    tokenSpecType *theTokenSpec = tokenSpec(theTokenID);
    
    
        // transcribe the bytecode words of our operator
    
    loopToken = 1;
    while (loopToken <= theTokenSpec->numCodeWords)  {
        
        ccInt *toWrite = LL_int(&(compiler->allCodeWords), theTokenSpec->firstCodeWord + loopToken-1);
        ccInt loopWrite, numTimesToWrite = 1;
        ccBool regularCommand = ccTrue;
        
        nextOpPosition = compiler->bytecode.elementNum + 1;
        
        
            // handle special bytecode commands in the code word sequence
        
        if (toWrite[0] == 0)  {
        if ((replaceCommandWords) || (toWrite[1] <= 1))  {
            
            regularCommand = ccFalse;
            
            
                // maybe we just wanted to write command #0 -- this is represented in bytecode by (0, 0)
            
            if (toWrite[1] == 0)  {
                
                if ((!replaceCommandWords) && (theTokenID != 3))  numTimesToWrite = 2;
                
                loopToken++;
                regularCommand = ccTrue;        }
            
            
                // if we are to write an argument of the operator, we call this function for the n'th argument
                // command is (0, 1, arg #)
            
            else if (toWrite[1] == 1)  {
                
                ccInt theArg, numArgsAhead;
                
                loopToken += 3;
                
                theArg = scriptToken(theToken)->firstArg;
                numArgsAhead = toWrite[2]-1;
                
                while (numArgsAhead > 0)  {
                    theArg = scriptToken(theArg)->nextExpression;
                    if (theArg == 0)  break;
                    numArgsAhead--;     }
                
                if (theArg != 0)  {
                    rtrn = writeTokenOps(compiler, theArg, replaceCommandWords);
                    if (rtrn != passed)  return rtrn;
            }   }
            
                // the code sequence for a jump-position marker is (0, 2, marker #)
            
            else if (toWrite[1] == 2)  {
                
                jumpMarkers[toWrite[2]-1] = nextOpPosition;
                
                loopToken += 3;            }
            
            
                // a jump command is represented by (0, 3, marker #)
            
            else if (toWrite[1] == 3)  {
                
                rtrn = addElements(&(compiler->bytecode), 1, ccFalse);
                if (rtrn == passed)  rtrn = addElements(&(compiler->opCharNum), 1, ccFalse);
                if (rtrn != passed)  return rtrn;
                
                *LL_int(&(compiler->opCharNum), nextOpPosition) = tokenCharNum;
                
                jumpTo[numJumps] = toWrite[2];
                jumps[numJumps] = nextOpPosition;
                numJumps++;
                
                loopToken += 3;     }
            
            
                // a new hidden variable is represented by (0, 4)
            
            else if (toWrite[1] == 4)  {
                
                compiler->anonymousMemberNum--;
                toWrite = &(compiler->anonymousMemberNum);
                regularCommand = ccTrue;
                
                loopToken++;
        }}  }
        
        
            // if it's a regular bytecode command, just copy it into the bytecode array
        
        if (regularCommand)  {
            loopToken++;
            for (loopWrite = 0; loopWrite < numTimesToWrite; loopWrite++)  {
                rtrn = addElements(&(compiler->bytecode), 1, ccFalse);
                if (rtrn == passed)  rtrn = addElements(&(compiler->opCharNum), 1, ccFalse);
                if (rtrn != passed)  return rtrn;
                
                *LL_int(&(compiler->bytecode), nextOpPosition+loopWrite) = *toWrite;
                *LL_int(&(compiler->opCharNum), nextOpPosition+loopWrite) = tokenCharNum;
    }   }   }
    
    
        // fill in all the jump offsets after the bytecode has been transcribed
    
    for (loopJump = 0; loopJump < numJumps; loopJump++)  {
        *LL_int(&(compiler->bytecode), jumps[loopJump]) = jumpMarkers[jumpTo[loopJump]-1] - jumps[loopJump];    }
    
    
        // next, copy any constant data into the bytecode
    
    if (scriptToken(theToken)->constData != NULL)  {
        
        ccInt loopInt, numInts = scriptToken(theToken)->constDataSize;
        
        nextOpPosition = compiler->bytecode.elementNum + 1;
        
        rtrn = addElements(&(compiler->bytecode), numInts, ccFalse);
        if (rtrn != passed)  return rtrn;
        
        setElements(&(compiler->bytecode), nextOpPosition, nextOpPosition+numInts-1,
                        (void *) scriptToken(theToken)->constData);
        
        if (!replaceCommandWords)  {
        for (loopInt = 0; loopInt < numInts; loopInt++)  {
        if (*LL_int(&(compiler->bytecode), nextOpPosition+loopInt) == 0)  {
            rtrn = insertElements(&(compiler->bytecode), nextOpPosition+loopInt+1, numInts, ccTrue);
            if (rtrn != passed)  return rtrn;
            numInts++;
            loopInt++;      // get past the new 0
        }}}
        
        rtrn = addElements(&(compiler->opCharNum), numInts, ccFalse);
        if (rtrn != passed)  return rtrn;
        
        for (loopInt = 1; loopInt <= numInts; loopInt++)  {
            *LL_int(&(compiler->opCharNum), nextOpPosition+loopInt-1) = tokenCharNum;
    }   }
    
    return passed;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movl %edx, %ebx
movl %esi, %ebp
movq %rdi, %r12
leaq 0x1440(%rdi), %r15
movq %r15, %rdi
callq 0x911c
movl 0x4(%rax), %r14d
movq %r15, 0x20(%rsp)
movq %r15, %rdi
movl %ebp, 0x18(%rsp)
movl %ebp, %esi
callq 0x911c
movl (%rax), %ebp
leaq 0x1200(%r12), %rdi
movl %ebp, %esi
callq 0x911c
movq %rax, 0x58(%rsp)
leaq 0x1220(%r12), %rax
movq %rax, 0x50(%rsp)
leaq 0x1460(%r12), %r13
movl %ebx, 0x1c(%rsp)
testb %bl, %bl
sete %al
leaq 0x143c(%r12), %rcx
movq %rcx, 0x48(%rsp)
movq %r12, 0x40(%rsp)
leaq 0x1480(%r12), %r15
cmpl $0x3, %ebp
setne %cl
andb %al, %cl
movzbl %cl, %eax
incl %eax
movl %eax, 0x3c(%rsp)
movq $0x0, 0x28(%rsp)
movl $0x1, %r12d
movq %r13, 0x30(%rsp)
movq 0x58(%rsp), %rax
cmpl 0x30(%rax), %r12d
jg 0xc37b
movl 0x2c(%rax), %eax
leal (%r12,%rax), %esi
decl %esi
movq 0x50(%rsp), %rdi
callq 0x911c
movl (%r13), %ebp
incl %ebp
movl $0x1, %ebx
movq %rax, 0x10(%rsp)
cmpl $0x0, (%rax)
je 0xc1ff
movq %r12, 0x8(%rsp)
xorl %edx, %edx
movb $0x1, %r12b
testb %dl, %dl
jne 0xc2c0
movq 0x8(%rsp), %rax
incl %eax
movq %rax, 0x8(%rsp)
movq %r13, %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0x8b6a
testl %eax, %eax
jne 0xc1b3
movq %r15, %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0x8b6a
testl %eax, %eax
sete %r12b
jne 0xc2bc
movq %r15, %r13
movl %r14d, %r15d
movq 0x10(%rsp), %rax
movl (%rax), %r14d
movq 0x30(%rsp), %rdi
movl %ebp, %esi
callq 0x911c
movl %r14d, (%rax)
movl %r15d, %r14d
movq %r13, %r15
movq 0x30(%rsp), %r13
movq %r15, %rdi
movl %ebp, %esi
callq 0x911c
movl %r14d, (%rax)
incl %ebp
decl %ebx
jne 0xc191
jmp 0xc2c0
cmpb $0x0, 0x1c(%rsp)
jne 0xc215
movq 0x10(%rsp), %rax
cmpl $0x1, 0x4(%rax)
jg 0xc173
movq 0x10(%rsp), %rax
movl 0x4(%rax), %eax
movb $0x1, %dl
cmpq $0x4, %rax
movl 0x18(%rsp), %esi
movq 0x20(%rsp), %rdi
ja 0xc280
leaq 0xee6f(%rip), %rcx      # 0x1b0a4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
incl %r12d
movq %r12, 0x8(%rsp)
xorl %edx, %edx
movl 0x3c(%rsp), %ebx
jmp 0xc17a
movq 0x48(%rsp), %rax
decl (%rax)
incl %r12d
movq %r12, 0x8(%rsp)
xorl %edx, %edx
movq %rax, 0x10(%rsp)
jmp 0xc17a
movq 0x10(%rsp), %rax
movslq 0x8(%rax), %rax
movl %ebp, 0xbc(%rsp,%rax,4)
addl $0x3, %r12d
movq %r12, 0x8(%rsp)
jmp 0xc17a
movq %r13, %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0x8b6a
testl %eax, %eax
jne 0xc2ac
movq %r15, %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0x8b6a
testl %eax, %eax
je 0xc33c
movq %r12, 0x8(%rsp)
xorl %r12d, %r12d
movl %eax, 0x4(%rsp)
testb %r12b, %r12b
movq 0x8(%rsp), %r12
jne 0xc138
jmp 0xc4ca
addl $0x3, %r12d
movq %r12, 0x8(%rsp)
callq 0x911c
movl 0x8(%rax), %esi
movq 0x10(%rsp), %rax
movl 0x8(%rax), %r12d
incl %r12d
decl %r12d
cmpl $0x2, %r12d
jl 0xc30c
movq 0x20(%rsp), %rdi
callq 0x911c
movl 0xc(%rax), %esi
testl %esi, %esi
jne 0xc2f0
xorl %esi, %esi
testl %esi, %esi
je 0xc32b
movsbl 0x1c(%rsp), %edx
movq 0x40(%rsp), %rdi
callq 0xc087
testl %eax, %eax
je 0xc32b
xorl %ecx, %ecx
movl %eax, 0x4(%rsp)
jmp 0xc32d
movb $0x1, %cl
testb %cl, %cl
movb $0x1, %dl
jne 0xc17a
xorl %r12d, %r12d
jmp 0xc2c0
movq %r15, %rdi
movl %ebp, %esi
callq 0x911c
movl %r14d, (%rax)
movq 0x10(%rsp), %rax
movl 0x8(%rax), %eax
movq 0x28(%rsp), %rcx
movslq %ecx, %rcx
movl %eax, 0x60(%rsp,%rcx,4)
movl %ebp, 0x90(%rsp,%rcx,4)
incl %ecx
movq %rcx, 0x28(%rsp)
addl $0x3, %r12d
movq %r12, 0x8(%rsp)
movb $0x1, %dl
jmp 0xc17a
movq 0x28(%rsp), %rax
testl %eax, %eax
jle 0xc3b1
movl %eax, %ebx
xorl %r12d, %r12d
movslq 0x60(%rsp,%r12,4), %rax
movl 0xbc(%rsp,%rax,4), %ebp
movl 0x90(%rsp,%r12,4), %esi
subl %esi, %ebp
movq %r13, %rdi
callq 0x911c
movl %ebp, (%rax)
incq %r12
cmpq %r12, %rbx
jne 0xc389
movq 0x20(%rsp), %rdi
movl 0x18(%rsp), %esi
callq 0x911c
cmpq $0x0, 0x18(%rax)
je 0xc4c2
movq 0x20(%rsp), %rdi
movl 0x18(%rsp), %r12d
movl %r12d, %esi
callq 0x911c
movl 0x20(%rax), %ebx
movq 0x40(%rsp), %rax
movl 0x1460(%rax), %ebp
movq %r13, %rdi
movl %ebx, %esi
xorl %edx, %edx
callq 0x8b6a
testl %eax, %eax
je 0xc405
movl %eax, 0x4(%rsp)
xorl %ebp, %ebp
jmp 0xc4bd
leal 0x1(%rbp), %eax
movq %rax, 0x10(%rsp)
addl %ebx, %ebp
movq 0x20(%rsp), %rdi
movl %r12d, %esi
callq 0x911c
movq 0x18(%rax), %rcx
movq %r13, %rdi
movq 0x10(%rsp), %r13
movl %r13d, %esi
movl %ebp, %edx
callq 0x8f0d
cmpb $0x0, 0x1c(%rsp)
setne %al
testl %ebx, %ebx
setle %cl
orb %al, %cl
jne 0xc487
xorl %r12d, %r12d
leal (%r12,%r13), %ebp
movq 0x30(%rsp), %r13
movq %r13, %rdi
movl %ebp, %esi
callq 0x911c
cmpl $0x0, (%rax)
jne 0xc47a
incl %ebp
movq %r13, %rdi
movl %ebp, %esi
movl %ebx, %edx
movl $0x1, %ecx
callq 0x84af
testl %eax, %eax
jne 0xc4b7
incl %ebx
incl %r12d
incl %r12d
cmpl %ebx, %r12d
movq 0x10(%rsp), %r13
jl 0xc446
xorl %ebp, %ebp
movq %r15, %rdi
movl %ebx, %esi
xorl %edx, %edx
callq 0x8b6a
testl %eax, %eax
jne 0xc4b9
movb $0x1, %bpl
testl %ebx, %ebx
jle 0xc4bd
movq %r15, %rdi
movl %r13d, %esi
callq 0x911c
movl %r14d, (%rax)
incl %r13d
decl %ebx
jne 0xc4a0
jmp 0xc4bd
xorl %ebp, %ebp
movl %eax, 0x4(%rsp)
testb %bpl, %bpl
je 0xc4ca
movl $0x0, 0x4(%rsp)
movl 0x4(%rsp), %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq