// File: /workspace/github_cpp_makefile_star2_O3/rfotino[P]consolite-compiler/src/parser.cpp
// Function: Parser::output(char*)
bool Parser::output(char *filename) {
  // Start by opening the output file.
  _outfile.open(filename, std::ofstream::out | std::ofstream::trunc);
  if (!_outfile.good()) {
    _error("Unable to open output file.");
    return false;
  }
  // Next assign labels for all globals and functions.
  for (auto global : _globals) {
    this->addLabel(global->name());
  }
  for (auto function : _functions) {
    this->addLabel(function->name());
  }
  // Output the "bootloader". This sets the stack pointer, calls main,
  // then goes into an infinite loop to prevent attempting to execute
  // code that wasn't meant to be executed.
  std::string stackLabel = this->getUnusedLabel("stack");
  this->writeInst("MOVI SP " + stackLabel);
  this->writeInst("CALL main");
  std::string finishedLabel = this->getUnusedLabel("program_finished");
  this->writeln(finishedLabel + ":");
  this->writeInst("JMPI " + finishedLabel);
  // Output global variables.
  for (auto global : _globals) {
    global->output(this);
  }
  // Output functions.
  for (auto function: _functions) {
    function->output(this);
  }
  // Output the stack position.
  this->writeln(stackLabel + ":");
  return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
addq $0x38, %rdi
movl $0x30, %edx
callq 0x7060
movq 0x38(%rbx), %rax
movq -0x18(%rax), %rax
movl 0x58(%rbx,%rax), %ebp
testl %ebp, %ebp
je 0xa21a
leaq 0x50(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x2af10(%rip), %rsi     # 0x350df
leaq 0x2af24(%rip), %rdx     # 0x350fa
leaq 0x40(%rsp), %rdi
callq 0xbdee
leaq 0x40(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x34178
movq 0x40(%rsp), %rdi
cmpq %r14, %rdi
je 0xa206
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x72c0
testl %ebp, %ebp
sete %al
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %ebp, 0x64(%rsp)
movq 0x8(%rbx), %r12
movq 0x10(%rbx), %rbp
cmpq %rbp, %r12
je 0xa2aa
leaq 0x50(%rsp), %r13
leaq 0x40(%rsp), %r15
movq (%r12), %rax
movq 0x8(%r12), %r14
testq %r14, %r14
je 0xa25a
movq 0x3cd4e(%rip), %rcx     # 0x46f98
cmpb $0x0, (%rcx)
je 0xa255
incl 0x8(%r14)
jmp 0xa25a
lock
incl 0x8(%r14)
movq %r13, 0x40(%rsp)
movq 0x70(%rax), %rsi
movq 0x78(%rax), %rdx
addq %rsi, %rdx
movq %r15, %rdi
callq 0xbd58
movq %rbx, %rdi
movq %r15, %rsi
callq 0xa6f0
movq 0x40(%rsp), %rdi
cmpq %r13, %rdi
je 0xa294
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x72c0
testq %r14, %r14
je 0xa2a1
movq %r14, %rdi
callq 0x8036
addq $0x10, %r12
cmpq %rbp, %r12
jne 0xa235
movq 0x20(%rbx), %r12
movq 0x28(%rbx), %rbp
cmpq %rbp, %r12
je 0xa336
leaq 0x50(%rsp), %r13
leaq 0x40(%rsp), %r15
movq (%r12), %rax
movq 0x8(%r12), %r14
testq %r14, %r14
je 0xa2e6
movq 0x3ccc2(%rip), %rcx     # 0x46f98
cmpb $0x0, (%rcx)
je 0xa2e1
incl 0x8(%r14)
jmp 0xa2e6
lock
incl 0x8(%r14)
movq %r13, 0x40(%rsp)
movq 0x58(%rax), %rsi
movq 0x60(%rax), %rdx
addq %rsi, %rdx
movq %r15, %rdi
callq 0xbd58
movq %rbx, %rdi
movq %r15, %rsi
callq 0xa6f0
movq 0x40(%rsp), %rdi
cmpq %r13, %rdi
je 0xa320
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x72c0
testq %r14, %r14
je 0xa32d
movq %r14, %rdi
callq 0x8036
addq $0x10, %r12
cmpq %rbp, %r12
jne 0xa2c1
leaq 0x30(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x2adb5(%rip), %rsi     # 0x350fb
leaq 0x2adb3(%rip), %rdx     # 0x35100
leaq 0x20(%rsp), %rdi
callq 0xbdee
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rdx
movq %rbx, %rsi
callq 0xa73a
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0xa380
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x72c0
leaq 0x2ad7a(%rip), %rsi     # 0x35101
leaq 0x20(%rsp), %rdi
leaq 0x40(%rsp), %rdx
callq 0xb692
leaq 0x20(%rsp), %rsi
movq %rbx, %rdi
callq 0xab5a
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0xa3ba
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x72c0
leaq 0x20(%rsp), %rdi
movq %r14, (%rdi)
leaq 0x2ad41(%rip), %rsi     # 0x3510a
leaq 0x2ad43(%rip), %rdx     # 0x35113
callq 0xbdee
leaq 0x20(%rsp), %rsi
movq %rbx, %rdi
callq 0xab5a
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0xa3f9
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x72c0
leaq 0x10(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x2ad0a(%rip), %rsi     # 0x35114
leaq 0x2ad13(%rip), %rdx     # 0x35124
movq %rsp, %rdi
callq 0xbdee
leaq 0x20(%rsp), %rdi
movq %rsp, %rdx
movq %rbx, %rsi
callq 0xa73a
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0xa43f
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x72c0
movq %rsp, %rdi
movq %r12, (%rdi)
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
addq %rsi, %rdx
callq 0xbd58
leaq 0x2d212(%rip), %rsi     # 0x37670
movq %rsp, %rdi
callq 0x7560
movq %rsp, %rsi
movq %rbx, %rdi
callq 0xaff2
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0xa487
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x72c0
leaq 0x2ac97(%rip), %rsi     # 0x35125
movq %rsp, %rdi
leaq 0x20(%rsp), %rdx
callq 0xb692
movq %rsp, %rsi
movq %rbx, %rdi
callq 0xab5a
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0xa4bc
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x72c0
movq 0x8(%rbx), %r13
movq 0x10(%rbx), %rbp
cmpq %rbp, %r13
je 0xa50c
movq 0x3cac8(%rip), %r15     # 0x46f98
movq (%r13), %rdi
movq 0x8(%r13), %r14
testq %r14, %r14
je 0xa4ee
cmpb $0x0, (%r15)
je 0xa4e9
incl 0x8(%r14)
jmp 0xa4ee
lock
incl 0x8(%r14)
movq %rbx, %rsi
callq 0x1803a
testq %r14, %r14
je 0xa503
movq %r14, %rdi
callq 0x8036
addq $0x10, %r13
cmpq %rbp, %r13
jne 0xa4d0
movq 0x20(%rbx), %r13
movq 0x28(%rbx), %rbp
cmpq %rbp, %r13
je 0xa55c
movq 0x3ca78(%rip), %r15     # 0x46f98
movq (%r13), %rdi
movq 0x8(%r13), %r14
testq %r14, %r14
je 0xa53e
cmpb $0x0, (%r15)
je 0xa539
incl 0x8(%r14)
jmp 0xa53e
lock
incl 0x8(%r14)
movq %rbx, %rsi
callq 0x1ad7e
testq %r14, %r14
je 0xa553
movq %r14, %rdi
callq 0x8036
addq $0x10, %r13
cmpq %rbp, %r13
jne 0xa520
movq %rsp, %rdi
movq %r12, (%rdi)
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rdx
addq %rsi, %rdx
callq 0xbd58
leaq 0x2d0f5(%rip), %rsi     # 0x37670
movq %rsp, %rdi
callq 0x7560
movq %rsp, %rsi
movq %rbx, %rdi
callq 0xaff2
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0xa5a4
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x72c0
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
movl 0x64(%rsp), %ebp
je 0xa5c4
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x72c0
leaq 0x50(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0xa1f9
jmp 0xa206
jmp 0xa5e7
jmp 0xa5e7
jmp 0xa606
jmp 0xa5e7
jmp 0xa606
jmp 0xa5e7
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0xa67f
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x72c0
jmp 0xa67f
movq %rax, %rbx
jmp 0xa67f
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0xa69b
movq 0x10(%rsp), %rsi
jmp 0xa693
jmp 0xa637
jmp 0xa628
jmp 0xa637
movq %rax, %rbx
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
jne 0xa68e
jmp 0xa69b
movq %rax, %rbx
jmp 0xa69b
movq %rax, %rbx
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0xa6e8
movq 0x30(%rsp), %rsi
jmp 0xa6ae
jmp 0xa668
movq %rax, %rbx
movq 0x40(%rsp), %rdi
cmpq %r14, %rdi
jne 0xa6a9
jmp 0xa6e8
movq %rax, %rbx
jmp 0xa6e8
jmp 0xa66f
movq %rax, %rbx
testq %r14, %r14
je 0xa67f
movq %r14, %rdi
callq 0x8036
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0xa69b
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x72c0
leaq 0x50(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xa6e8
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x72c0
jmp 0xa6e8
jmp 0xa6bc
jmp 0xa6c1
movq %rax, %rbx
jmp 0xa6db
movq %rax, %rbx
movq 0x40(%rsp), %rdi
cmpq %r13, %rdi
je 0xa6db
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x72c0
testq %r14, %r14
je 0xa6e8
movq %r14, %rdi
callq 0x8036
movq %rbx, %rdi
callq 0x74f0