// File: /workspace/github_cpp_makefile_star2_O2/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, %rbx
movq %rdi, %r14
leaq 0x10(%rdi), %r15
leaq 0x17aa5(%rip), %rdi     # 0x29035
movq %r15, %rsi
callq 0x97dd
testb %al, %al
je 0x11617
movq 0x30(%r14), %rax
movq (%rax), %r14
leaq 0x18176(%rip), %rsi     # 0x29720
leaq 0x8(%rsp), %rdi
leaq 0x88(%rsp), %rdx
callq 0x9502
leaq 0x38(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x73e0
leaq 0x38(%rsp), %rdx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x10ca6
leaq 0x38(%rsp), %rdi
callq 0x75c8
leaq 0x8(%rsp), %rdi
callq 0x75c8
leaq 0x184bb(%rip), %rsi     # 0x29ab1
leaq 0x38(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x9502
leaq 0x38(%rsp), %rsi
movq %rbx, %rdi
callq 0x914a
jmp 0x11834
leaq 0x17a2a(%rip), %rdi     # 0x29048
movq %r15, %rsi
callq 0x97dd
testb %al, %al
je 0x116fd
movq 0x30(%r14), %rax
movq (%rax), %r15
leaq 0x180e4(%rip), %rsi     # 0x29720
leaq 0x8(%rsp), %rdi
leaq 0x88(%rsp), %rdx
callq 0x9502
leaq 0x38(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x73e0
leaq 0x38(%rsp), %rdx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x10ca6
leaq 0x38(%rsp), %rdi
callq 0x75c8
leaq 0x8(%rsp), %rdi
callq 0x75c8
movq 0x30(%r14), %rax
movq 0x10(%rax), %r14
leaq 0x18168(%rip), %rsi     # 0x297f8
leaq 0x8(%rsp), %rdi
leaq 0x88(%rsp), %rdx
callq 0x9502
leaq 0x38(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x73e0
leaq 0x38(%rsp), %rdx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x10ca6
leaq 0x38(%rsp), %rdi
callq 0x75c8
leaq 0x8(%rsp), %rdi
callq 0x75c8
leaq 0x183dd(%rip), %rsi     # 0x29ab9
leaq 0x38(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x9502
leaq 0x38(%rsp), %rsi
movq %rbx, %rdi
callq 0x914a
jmp 0x11834
leaq 0x1794c(%rip), %rdi     # 0x29050
movq %r15, %rsi
callq 0x97dd
testb %al, %al
je 0x11738
leaq 0x17939(%rip), %rsi     # 0x29050
leaq 0x38(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x9502
leaq 0x38(%rsp), %rsi
movq %rbx, %rdi
callq 0x914a
jmp 0x11834
leaq 0x17919(%rip), %rdi     # 0x29058
movq %r15, %rsi
callq 0x97dd
testb %al, %al
je 0x11773
leaq 0x18371(%rip), %rsi     # 0x29ac3
leaq 0x38(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x9502
leaq 0x38(%rsp), %rsi
movq %rbx, %rdi
callq 0x914a
jmp 0x11834
leaq 0x178e3(%rip), %rdi     # 0x2905d
movq %r15, %rsi
callq 0x97dd
testb %al, %al
je 0x117fe
movq 0x30(%r14), %rax
movq (%rax), %r14
leaq 0x17f8c(%rip), %rsi     # 0x29720
leaq 0x8(%rsp), %rdi
leaq 0x88(%rsp), %rdx
callq 0x9502
leaq 0x38(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x73e0
leaq 0x38(%rsp), %rdx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x10ca6
leaq 0x38(%rsp), %rdi
callq 0x75c8
leaq 0x8(%rsp), %rdi
callq 0x75c8
leaq 0x182ea(%rip), %rsi     # 0x29aca
leaq 0x38(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x9502
leaq 0x38(%rsp), %rsi
movq %rbx, %rdi
callq 0x914a
jmp 0x11834
leaq 0x17867(%rip), %rdi     # 0x2906c
movq %r15, %rsi
callq 0x97dd
testb %al, %al
je 0x11850
leaq 0x182bc(%rip), %rsi     # 0x29ad4
leaq 0x38(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x9502
leaq 0x38(%rsp), %rsi
movq %rbx, %rdi
callq 0x914a
leaq 0x38(%rsp), %rdi
callq 0x75c8
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, 0x30(%rsp)
leaq 0x38(%rsp), %rdi
callq 0x9bde
leaq 0x17ff5(%rip), %rsi     # 0x2985b
leaq 0x88(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x9502
xorl %ebx, %ebx
leaq 0x8(%rsp), %r13
leaq 0x88(%rsp), %rbp
leaq 0x38(%rsp), %r12
cmpq $0x4, %rbx
je 0x118e4
movq 0x38(%r14), %rax
subq 0x30(%r14), %rax
sarq $0x4, %rax
cmpq %rax, %rbx
jae 0x118e4
movq %r13, %rdi
leaq 0x17892(%rip), %rsi     # 0x2913f
movq %rbp, %rdx
callq 0x9980
movq 0x30(%rsp), %rdi
movq %r13, %rsi
callq 0x914a
movq %r13, %rdi
callq 0x75c8
movq %r12, %rdi
movq %rbp, %rsi
callq 0x2554a
incq %rbx
movq 0x88(%rsp), %rax
incb (%rax)
jmp 0x1188c
leaq 0x17f70(%rip), %rsi     # 0x2985b
leaq 0x88(%rsp), %rdi
callq 0x7580
xorl %ebx, %ebx
leaq 0x8(%rsp), %r12
xorl %r13d, %r13d
movq 0x30(%r14), %rcx
movq 0x38(%r14), %rax
subq %rcx, %rax
cmpq $0x4, %r13
je 0x1195e
movq %rax, %rdx
sarq $0x4, %rdx
cmpq %rdx, %r13
jae 0x1195e
movq (%rcx,%rbx), %rbp
movq %r12, %rdi
leaq 0x88(%rsp), %rsi
callq 0x73e0
movq %rbp, %rdi
movq 0x30(%rsp), %rsi
movq %r12, %rdx
callq 0x10ca6
movq %r12, %rdi
callq 0x75c8
incq %r13
movq 0x88(%rsp), %rax
incb (%rax)
addq $0x10, %rbx
jmp 0x11902
shrq $0x4, %rax
movl %eax, %ebx
leaq 0xa8(%rsp), %r13
leaq 0x8(%rsp), %r12
decq %rbx
cmpl $0x3, %ebx
jle 0x119f7
movl %ebx, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq 0x30(%r14), %rcx
shlq $0x4, %rax
movq (%rcx,%rax), %rbp
movq %r13, %rdi
leaq 0x18142(%rip), %rsi     # 0x29ad8
leaq 0x7(%rsp), %rdx
callq 0x9502
movq %r12, %rdi
movq %r13, %rsi
callq 0x73e0
movq %rbp, %rdi
movq 0x30(%rsp), %rsi
movq %r12, %rdx
callq 0x10ca6
movq %r12, %rdi
callq 0x75c8
movq %r13, %rdi
callq 0x75c8
movq %r12, %rdi
leaq 0x17dd6(%rip), %rsi     # 0x297ab
movq %r13, %rdx
callq 0x9502
movq 0x30(%rsp), %rdi
movq %r12, %rsi
callq 0x914a
movq %r12, %rdi
callq 0x75c8
jmp 0x11971
leaq 0x180dc(%rip), %rsi     # 0x29ada
leaq 0x8(%rsp), %rdi
movq %r15, %rdx
callq 0x9980
leaq 0x8(%rsp), %rsi
movq 0x30(%rsp), %r13
movq %r13, %rdi
callq 0x914a
leaq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0x75c8
movl $0x200, %ebx            # imm = 0x200
leaq 0x176ee(%rip), %r15     # 0x29124
leaq 0x38(%rsp), %r12
movq 0x68(%rsp), %rdx
cmpq 0x48(%rsp), %rdx
je 0x11a89
cmpq 0x70(%rsp), %rdx
jne 0x11a5d
movq 0x80(%rsp), %rax
movq -0x8(%rax), %rdx
addq %rbx, %rdx
addq $-0x20, %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x9980
movq %r13, %rdi
movq %r14, %rsi
callq 0x914a
movq %r14, %rdi
callq 0x75c8
movq %r12, %rdi
callq 0x25368
jmp 0x11a3b
leaq 0x88(%rsp), %rdi
callq 0x75c8
leaq 0x38(%rsp), %rdi
callq 0xa0da
jmp 0x1183e
jmp 0x11b2f
jmp 0x11b3e
jmp 0x11b3e
jmp 0x11b5a
movq %rax, %rbx
jmp 0x11b4e
jmp 0x11b84
jmp 0x11b5a
jmp 0x11b84
jmp 0x11b66
jmp 0x11b75
jmp 0x11b84
jmp 0x11b5a
jmp 0x11b84
jmp 0x11b5a
jmp 0x11b84
jmp 0x11b2f
jmp 0x11b3e
jmp 0x11b3e
jmp 0x11b5a
jmp 0x11b84
jmp 0x11b66
jmp 0x11b75
jmp 0x11b84
jmp 0x11b66
jmp 0x11b75
jmp 0x11b84
jmp 0x11b3e
jmp 0x11b2f
jmp 0x11b2f
jmp 0x11b3e
movq %rax, %rbx
jmp 0x11b23
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x75c8
leaq 0xa8(%rsp), %rdi
jmp 0x11b37
jmp 0x11b3e
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x75c8
jmp 0x11b41
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x75c8
leaq 0x38(%rsp), %rdi
callq 0xa0da
jmp 0x11b87
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
jmp 0x11b7d
jmp 0x11b84
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x75c8
jmp 0x11b78
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x75c8
jmp 0x11b87
movq %rax, %rbx
movq %rbx, %rdi
callq 0x7510
nop