// File: /workspace/github_cpp_makefile_star2_O1/rfotino[P]consolite-compiler/src/syntax.cpp
// Function: FunctionCallToken::output(Parser*)
void FunctionCallToken::output(Parser *parser) {
  // Check if the function is a builtin, in which case the assembly
  // output will look different (with no CALL instruction).
  if ("COLOR" == _funcName) {
    // Signature is "void COLOR(uint16 color)"
    _arguments[0]->output(parser, VarLocation("M"));
    parser->writeInst("COLOR M");
  } else if ("PIXEL" == _funcName) {
    // Signature is "void PIXEL(uint16 x, uint16 y)"
    _arguments[0]->output(parser, VarLocation("M"));
    _arguments[1]->output(parser, VarLocation("N"));
    parser->writeInst("PIXEL M N");
  } else if ("TIMERST" == _funcName) {
    // Signatue is "void TIMERST()"
    parser->writeInst("TIMERST");
  } else if ("TIME" == _funcName) {
    // Signature is "uint16 TIME()"
    parser->writeInst("TIME L");
  } else if ("INPUT" == _funcName) {
    // Signature is "uint16 INPUT(uint16 input_id)"
    _arguments[0]->output(parser, VarLocation("M"));
    parser->writeInst("INPUT L M");
  } else if ("RND" == _funcName) {
    // Signature is "uint16 RND()"
    parser->writeInst("RND L");
  } else {
    // Save registers A through D if we are using them as arguments.
    std::stack<std::string> savedRegisters;
    std::string reg = "A";
    for (size_t i = 0; i < 4 && i < _arguments.size(); i++, reg[0]++) {
      parser->writeInst("PUSH " + reg);
      savedRegisters.push(reg);
    }
    // Evaluate up to the first four arguments and store them in registers
    // A through D.
    reg = "A";
    for (size_t i = 0; i < 4 && i < _arguments.size(); i++, reg[0]++) {
      _arguments[i]->output(parser, VarLocation(reg));
    }
    // Push any overflow arguments onto the stack. In reverse order so that
    // it matches the callee's expectations of the order.
    for (int i = _arguments.size() - 1; 4 <= i; i--) {
      _arguments[i]->output(parser, VarLocation("L"));
      parser->writeInst("PUSH L");
    }
    // Call the function
    parser->writeInst("CALL " + _funcName);
    // Restore registers A through D if they were used as arguments.
    while (!savedRegisters.empty()) {
      parser->writeInst("POP " + savedRegisters.top());
      savedRegisters.pop();
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rsi, %r13
movq %rdi, %r14
leaq 0x10(%rdi), %rbx
leaq 0x1f791(%rip), %rsi     # 0x36045
movq %rbx, %rdi
callq 0x70c0
testl %eax, %eax
je 0x16cbf
leaq 0x1f78d(%rip), %rsi     # 0x36058
movq %rbx, %rdi
callq 0x70c0
testl %eax, %eax
je 0x16d72
leaq 0x1f77e(%rip), %rsi     # 0x36060
movq %rbx, %rdi
callq 0x70c0
testl %eax, %eax
je 0x16eaf
leaq 0x1f76f(%rip), %rsi     # 0x36068
movq %rbx, %rdi
callq 0x70c0
testl %eax, %eax
je 0x16ee2
leaq 0x1f75d(%rip), %rsi     # 0x3606d
movq %rbx, %rdi
callq 0x70c0
testl %eax, %eax
je 0x16f15
leaq 0x1f755(%rip), %rsi     # 0x3607c
movq %rbx, %rdi
callq 0x70c0
testl %eax, %eax
je 0x16fc5
movq %rbx, 0xc0(%rsp)
movq %r13, %rbx
xorps %xmm0, %xmm0
leaq 0x30(%rsp), %rdi
movaps %xmm0, 0x40(%rdi)
movaps %xmm0, 0x30(%rdi)
movaps %xmm0, 0x20(%rdi)
movaps %xmm0, 0x10(%rdi)
movaps %xmm0, (%rdi)
xorl %esi, %esi
callq 0xbc88
leaq 0x90(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x1fee4(%rip), %rsi     # 0x3685b
leaq 0x1fede(%rip), %rdx     # 0x3685c
leaq 0x80(%rsp), %rdi
callq 0xc0a4
xorl %r15d, %r15d
leaq 0x8(%rsp), %r13
leaq 0x80(%rsp), %rbp
leaq 0x30(%rsp), %r12
movq 0x38(%r14), %rax
subq 0x30(%r14), %rax
sarq $0x4, %rax
cmpq %rax, %r15
jae 0x16a08
movq %r13, %rdi
leaq 0x1f794(%rip), %rsi     # 0x3614f
movq %rbp, %rdx
callq 0xb963
movq %rbx, %rdi
movq %r13, %rsi
callq 0xadb2
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x169ea
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x72c0
movq %r12, %rdi
movq %rbp, %rsi
callq 0x309f4
incq %r15
movq 0x80(%rsp), %rax
incb (%rax)
cmpq $0x4, %r15
jne 0x169a0
leaq 0x1fe4c(%rip), %rsi     # 0x3685b
leaq 0x80(%rsp), %rdi
callq 0x73d0
xorl %r15d, %r15d
leaq 0x8(%rsp), %r12
xorl %ebp, %ebp
movq 0x30(%r14), %rax
movq 0x38(%r14), %rcx
subq %rax, %rcx
sarq $0x4, %rcx
cmpq %rcx, %rbp
jae 0x16aa4
movq (%rax,%r15), %r13
leaq 0x18(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x80(%rsp), %rsi
movq 0x88(%rsp), %rdx
addq %rsi, %rdx
movq %r12, %rdi
callq 0xc014
movq %r13, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x1592e
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x16a8d
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x72c0
movq 0x80(%rsp), %rax
incb (%rax)
incq %rbp
addq $0x10, %r15
cmpq $0x4, %rbp
jne 0x16a26
movq 0x38(%r14), %rax
subq 0x30(%r14), %rax
shrq $0x4, %rax
decl %eax
cmpl $0x4, %eax
jl 0x16bc9
movl %eax, %ebp
leaq 0x1(%rbp), %r15
shlq $0x4, %rbp
leaq 0x8(%rsp), %r12
movq 0x30(%r14), %rax
movq (%rax,%rbp), %r13
leaq 0xb0(%rsp), %rax
movq %rax, 0xa0(%rsp)
leaq 0xa0(%rsp), %rdi
leaq 0x1ffe7(%rip), %rsi     # 0x36ad8
leaq 0x1ffe1(%rip), %rdx     # 0x36ad9
callq 0xc0a4
leaq 0x18(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0xa0(%rsp), %rsi
movq 0xa8(%rsp), %rdx
addq %rsi, %rdx
movq %r12, %rdi
callq 0xc014
movq %r13, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x1592e
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x16b4c
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x72c0
movq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rax
cmpq %rax, %rdi
je 0x16b71
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x72c0
leaq 0x18(%rsp), %rax
movq %rax, 0x8(%rsp)
movq %r12, %rdi
leaq 0x1fc26(%rip), %rsi     # 0x367ab
leaq 0x1fc25(%rip), %rdx     # 0x367b1
callq 0xc0a4
movq %rbx, %rdi
movq %r12, %rsi
callq 0xadb2
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x16bb8
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x72c0
decq %r15
addq $-0x10, %rbp
cmpq $0x4, %r15
jg 0x16aca
leaq 0x1ff0a(%rip), %rsi     # 0x36ada
leaq 0x8(%rsp), %rdi
movq 0xc0(%rsp), %rdx
callq 0xb963
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0xadb2
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x16c0b
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x72c0
movq 0x60(%rsp), %rdx
cmpq 0x40(%rsp), %rdx
je 0x16c8b
movl $0x200, %r13d           # imm = 0x200
leaq 0x1f510(%rip), %r14     # 0x36134
leaq 0x8(%rsp), %r15
leaq 0x30(%rsp), %r12
cmpq 0x68(%rsp), %rdx
jne 0x16c41
movq 0x78(%rsp), %rax
movq -0x8(%rax), %rdx
addq %r13, %rdx
addq $-0x20, %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0xb963
movq %rbx, %rdi
movq %r15, %rsi
callq 0xadb2
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x16c77
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x72c0
movq %r12, %rdi
callq 0x30864
movq 0x60(%rsp), %rdx
cmpq 0x40(%rsp), %rdx
jne 0x16c2e
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x16cb0
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x72c0
leaq 0x30(%rsp), %rdi
callq 0xbe00
jmp 0x1700a
movq 0x30(%r14), %rax
movq (%rax), %r14
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x1fa4a(%rip), %rsi     # 0x36720
leaq 0x1fa44(%rip), %rdx     # 0x36721
leaq 0x8(%rsp), %rdi
callq 0xc0a4
leaq 0x40(%rsp), %rbx
movq %rbx, -0x10(%rbx)
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
addq %rsi, %rdx
leaq 0x30(%rsp), %rdi
callq 0xc014
leaq 0x30(%rsp), %rdx
movq %r14, %rdi
movq %r13, %rsi
callq 0x1592e
movq 0x30(%rsp), %rdi
cmpq %rbx, %rdi
je 0x16d2e
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x72c0
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0x16d45
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x72c0
leaq 0x30(%rsp), %rdi
movq %rbx, (%rdi)
leaq 0x1fd5d(%rip), %rsi     # 0x36ab1
leaq 0x1fd5d(%rip), %rdx     # 0x36ab8
callq 0xc0a4
leaq 0x30(%rsp), %rsi
movq %r13, %rdi
callq 0xadb2
jmp 0x16ff3
movq 0x30(%r14), %rax
movq (%rax), %r15
leaq 0x18(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0x1f997(%rip), %rsi     # 0x36720
leaq 0x1f991(%rip), %rdx     # 0x36721
leaq 0x8(%rsp), %rdi
callq 0xc0a4
leaq 0x40(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
addq %rsi, %rdx
leaq 0x30(%rsp), %rdi
callq 0xc014
leaq 0x30(%rsp), %rdx
movq %r15, %rdi
movq %r13, %rsi
callq 0x1592e
movq 0x30(%rsp), %rdi
cmpq %r12, %rdi
je 0x16de2
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x72c0
movq 0x8(%rsp), %rdi
cmpq %rbx, %rdi
je 0x16df9
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x72c0
movq 0x30(%r14), %rax
movq 0x10(%rax), %r14
leaq 0x8(%rsp), %rdi
movq %rbx, (%rdi)
leaq 0x1f9e8(%rip), %rsi     # 0x367f8
leaq 0x1f9e2(%rip), %rdx     # 0x367f9
callq 0xc0a4
leaq 0x30(%rsp), %rdi
movq %r12, (%rdi)
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
addq %rsi, %rdx
callq 0xc014
leaq 0x30(%rsp), %rdx
movq %r14, %rdi
movq %r13, %rsi
callq 0x1592e
movq 0x30(%rsp), %rdi
cmpq %r12, %rdi
je 0x16e5d
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x72c0
movq 0x8(%rsp), %rdi
cmpq %rbx, %rdi
je 0x16e74
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x72c0
leaq 0x30(%rsp), %rdi
movq %r12, (%rdi)
leaq 0x1fc36(%rip), %rsi     # 0x36ab9
leaq 0x1fc38(%rip), %rdx     # 0x36ac2
callq 0xc0a4
leaq 0x30(%rsp), %rsi
movq %r13, %rdi
callq 0xadb2
movq 0x30(%rsp), %rdi
cmpq %r12, %rdi
jne 0x16ffd
jmp 0x1700a
leaq 0x40(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0x1f1a1(%rip), %rsi     # 0x36060
leaq 0x1f1a1(%rip), %rdx     # 0x36067
leaq 0x30(%rsp), %rdi
callq 0xc0a4
leaq 0x30(%rsp), %rsi
movq %r13, %rdi
callq 0xadb2
jmp 0x16ff3
leaq 0x40(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0x1fbd1(%rip), %rsi     # 0x36ac3
leaq 0x1fbd0(%rip), %rdx     # 0x36ac9
leaq 0x30(%rsp), %rdi
callq 0xc0a4
leaq 0x30(%rsp), %rsi
movq %r13, %rdi
callq 0xadb2
jmp 0x16ff3
movq 0x30(%r14), %rax
movq (%rax), %r14
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x1f7f4(%rip), %rsi     # 0x36720
leaq 0x1f7ee(%rip), %rdx     # 0x36721
leaq 0x8(%rsp), %rdi
callq 0xc0a4
leaq 0x40(%rsp), %rbx
movq %rbx, -0x10(%rbx)
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
addq %rsi, %rdx
leaq 0x30(%rsp), %rdi
callq 0xc014
leaq 0x30(%rsp), %rdx
movq %r14, %rdi
movq %r13, %rsi
callq 0x1592e
movq 0x30(%rsp), %rdi
cmpq %rbx, %rdi
je 0x16f84
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x72c0
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0x16f9b
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x72c0
leaq 0x30(%rsp), %rdi
movq %rbx, (%rdi)
leaq 0x1fb20(%rip), %rsi     # 0x36aca
leaq 0x1fb22(%rip), %rdx     # 0x36ad3
callq 0xc0a4
leaq 0x30(%rsp), %rsi
movq %r13, %rdi
callq 0xadb2
jmp 0x16ff3
leaq 0x40(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0x1faff(%rip), %rsi     # 0x36ad4
leaq 0x1fafd(%rip), %rdx     # 0x36ad9
leaq 0x30(%rsp), %rdi
callq 0xc0a4
leaq 0x30(%rsp), %rsi
movq %r13, %rdi
callq 0xadb2
movq 0x30(%rsp), %rdi
cmpq %rbx, %rdi
je 0x1700a
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x72c0
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x170b4
jmp 0x1710d
jmp 0x170b4
jmp 0x1710d
jmp 0x170ce
jmp 0x170ea
jmp 0x1710d
jmp 0x1716d
jmp 0x17168
jmp 0x17168
movq %rax, %r14
jmp 0x171b1
jmp 0x170b4
jmp 0x1710d
jmp 0x170b4
jmp 0x1710d
movq %rax, %r14
movq 0x30(%rsp), %rdi
cmpq %r12, %rdi
jne 0x170c5
jmp 0x171bb
jmp 0x1710d
jmp 0x17084
jmp 0x170a0
jmp 0x1710d
movq %rax, %r14
movq 0x30(%rsp), %rdi
cmpq %r12, %rdi
je 0x170a3
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x72c0
jmp 0x170a3
movq %rax, %r14
movq 0x8(%rsp), %rdi
cmpq %rbx, %rdi
jne 0x170fb
jmp 0x171bb
jmp 0x1710d
movq %rax, %r14
movq 0x30(%rsp), %rdi
cmpq %rbx, %rdi
je 0x171bb
movq 0x40(%rsp), %rsi
jmp 0x17100
jmp 0x1710d
movq %rax, %r14
movq 0x30(%rsp), %rdi
cmpq %rbx, %rdi
je 0x170ed
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x72c0
jmp 0x170ed
movq %rax, %r14
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0x171bb
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x72c0
jmp 0x171bb
movq %rax, %r14
jmp 0x171bb
jmp 0x1716d
jmp 0x17168
jmp 0x17168
jmp 0x17168
jmp 0x1716d
jmp 0x17168
movq %rax, %r14
jmp 0x17145
movq %rax, %r14
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x17145
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x72c0
movq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rax
cmpq %rax, %rdi
je 0x1718c
movq 0xb0(%rsp), %rsi
jmp 0x17184
jmp 0x17168
jmp 0x1716d
movq %rax, %r14
jmp 0x1718c
movq %rax, %r14
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x1718c
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x72c0
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x171b1
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x72c0
leaq 0x30(%rsp), %rdi
callq 0xbe00
movq %r14, %rdi
callq 0x74f0
nop