// File: /workspace/github_c_makefile_star2_O3/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 $0xd8, %rsp
movl %edx, %r13d
movl %esi, %ebp
movq %rdi, %r15
leaq 0x1440(%rdi), %rbx
movq %rbx, %rdi
callq 0x91d8
movl 0x4(%rax), %eax
movl %eax, 0x18(%rsp)
movq %rbx, 0x38(%rsp)
movq %rbx, %rdi
movl %ebp, %esi
callq 0x91d8
movl (%rax), %r14d
leaq 0x1200(%r15), %rdi
movl %r14d, %esi
callq 0x91d8
cmpl $0x0, 0x30(%rax)
movl %r13d, 0x1c(%rsp)
jle 0xc251
movq %rax, %rbx
movl %ebp, 0x4(%rsp)
leaq 0x1220(%r15), %rdi
leaq 0x1460(%r15), %r12
testb %r13b, %r13b
sete %al
leaq 0x143c(%r15), %rcx
movq %rcx, 0x40(%rsp)
leaq 0x1480(%r15), %rbp
cmpl $0x3, %r14d
setne %cl
andb %al, %cl
movzbl %cl, %eax
incl %eax
movl %eax, 0x34(%rsp)
movl $0x1, %ecx
movq $0x0, 0x20(%rsp)
movq %r15, 0x10(%rsp)
movq %rbx, 0x28(%rsp)
movq %rdi, 0x48(%rsp)
movl 0x2c(%rbx), %eax
movq %rcx, 0x8(%rsp)
leal (%rcx,%rax), %esi
decl %esi
callq 0x91d8
movq %rax, %r14
movl (%r12), %r15d
incl %r15d
cmpl $0x0, (%rax)
jne 0xc05e
movl 0x4(%r14), %eax
testb %r13b, %r13b
jne 0xc0da
cmpl $0x1, %eax
jle 0xc0da
movl $0x1, %ebx
movq 0x8(%rsp), %rcx
incl %ecx
movq %rcx, 0x8(%rsp)
movq %r12, %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0x8bb3
testl %eax, %eax
jne 0xc335
movq %rbp, %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0x8bb3
testl %eax, %eax
jne 0xc335
movl (%r14), %r13d
movq %r12, %rdi
movl %r15d, %esi
callq 0x91d8
movl %r13d, (%rax)
movq %rbp, %rdi
movl %r15d, %esi
callq 0x91d8
movl 0x18(%rsp), %ecx
movl %ecx, (%rax)
incl %r15d
decl %ebx
jne 0xc06f
movq 0x10(%rsp), %r15
movq 0x28(%rsp), %rbx
movq 0x8(%rsp), %rcx
jmp 0xc192
cmpl $0x4, %eax
movq 0x8(%rsp), %rcx
ja 0xc18d
movl %eax, %eax
leaq 0xef8f(%rip), %rdx      # 0x1b080
movslq (%rdx,%rax,4), %rax
addq %rdx, %rax
jmpq *%rax
incl %ecx
movl 0x34(%rsp), %ebx
jmp 0xc068
movq 0x40(%rsp), %r14
decl (%r14)
incl %ecx
movl $0x1, %ebx
jmp 0xc068
movslq 0x8(%r14), %rax
movl %r15d, 0xac(%rsp,%rax,4)
jmp 0xc18a
movq %r12, %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0x8bb3
testl %eax, %eax
jne 0xc335
movq %rbp, %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0x8bb3
testl %eax, %eax
jne 0xc335
movq %rbp, %rdi
movl %r15d, %esi
callq 0x91d8
movl 0x18(%rsp), %ecx
movl %ecx, (%rax)
movl 0x8(%r14), %eax
movq 0x20(%rsp), %rcx
movslq %ecx, %rcx
movl %eax, 0x50(%rsp,%rcx,4)
movl %r15d, 0x80(%rsp,%rcx,4)
incl %ecx
movq %rcx, 0x20(%rsp)
movq 0x8(%rsp), %rcx
addl $0x3, %ecx
movq 0x10(%rsp), %r15
cmpl 0x30(%rbx), %ecx
movl 0x1c(%rsp), %r13d
movq 0x48(%rsp), %rdi
jle 0xc02b
jmp 0xc213
addl $0x3, %ecx
movq %rcx, 0x8(%rsp)
movq 0x38(%rsp), %r15
movq %r15, %rdi
movl 0x4(%rsp), %esi
callq 0x91d8
movl 0x8(%rax), %esi
movl 0x8(%r14), %ebx
movq %r15, %r14
incl %ebx
movq 0x10(%rsp), %r15
decl %ebx
cmpl $0x2, %ebx
jl 0xc1ec
movq %r14, %rdi
callq 0x91d8
movl 0xc(%rax), %esi
testl %esi, %esi
jne 0xc1d1
jmp 0xc0cb
testl %esi, %esi
movq 0x28(%rsp), %rbx
je 0xc0d0
movsbl %r13b, %edx
movq %r15, %rdi
callq 0xbf6f
testl %eax, %eax
movq 0x8(%rsp), %rcx
je 0xc192
jmp 0xc335
movq 0x20(%rsp), %rax
testl %eax, %eax
movl 0x4(%rsp), %ebp
jle 0xc251
movl %eax, %ebx
xorl %r14d, %r14d
movslq 0x50(%rsp,%r14,4), %rax
movl 0xac(%rsp,%rax,4), %ebp
movl 0x80(%rsp,%r14,4), %esi
subl %esi, %ebp
movq %r12, %rdi
callq 0x91d8
movl %ebp, (%rax)
movl 0x4(%rsp), %ebp
incq %r14
cmpq %r14, %rbx
jne 0xc225
movq 0x38(%rsp), %r14
movq %r14, %rdi
movl %ebp, %esi
callq 0x91d8
cmpq $0x0, 0x18(%rax)
je 0xc34d
movq %r14, %rdi
movl %ebp, %esi
callq 0x91d8
movl %ebp, 0x4(%rsp)
movl 0x20(%rax), %ebp
movq %r15, %rbx
addq $0x1460, %r15           # imm = 0x1460
movl 0x1460(%rbx), %r12d
movq %r15, %rdi
movl %ebp, %esi
xorl %edx, %edx
callq 0x8bb3
testl %eax, %eax
jne 0xc335
movq %rbx, 0x10(%rsp)
movq %r14, %rdi
leal 0x1(%r12), %r14d
addl %ebp, %r12d
movl 0x4(%rsp), %esi
callq 0x91d8
movq 0x18(%rax), %rcx
movq %r15, %rdi
movl %r14d, %esi
movl %r12d, %edx
callq 0x8fba
cmpb $0x0, 0x1c(%rsp)
setne %al
testl %ebp, %ebp
setle %cl
orb %al, %cl
jne 0xc316
xorl %ebx, %ebx
leal (%rbx,%r14), %r12d
movq %r15, %rdi
movl %r12d, %esi
callq 0x91d8
cmpl $0x0, (%rax)
jne 0xc310
incl %r12d
movq %r15, %rdi
movl %r12d, %esi
movl %ebp, %edx
movl $0x1, %ecx
callq 0x84af
testl %eax, %eax
jne 0xc335
incl %ebp
incl %ebx
incl %ebx
cmpl %ebp, %ebx
jl 0xc2df
movq 0x10(%rsp), %rbx
addq $0x1480, %rbx           # imm = 0x1480
xorl %r13d, %r13d
movq %rbx, %rdi
movl %ebp, %esi
xorl %edx, %edx
callq 0x8bb3
testl %eax, %eax
je 0xc352
movl %eax, %r13d
movl %r13d, %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r13d, %r13d
jmp 0xc338
testl %ebp, %ebp
jle 0xc338
movl 0x18(%rsp), %r15d
movq %rbx, %rdi
movl %r14d, %esi
callq 0x91d8
movl %r15d, (%rax)
incl %r14d
decl %ebp
jne 0xc35b
jmp 0xc338