// File: /workspace/github_cpp_makefile_star2_O1/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 0xa472
leaq 0x50(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x2bcb8(%rip), %rsi     # 0x360df
leaq 0x2bccc(%rip), %rdx     # 0x360fa
leaq 0x40(%rsp), %rdi
callq 0xc0a4
leaq 0x40(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x34811
movq 0x40(%rsp), %rdi
cmpq %r14, %rdi
je 0xa45e
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 0xa502
leaq 0x50(%rsp), %r13
leaq 0x40(%rsp), %r15
movq (%r12), %rax
movq 0x8(%r12), %r14
testq %r14, %r14
je 0xa4b2
movq 0x3daf6(%rip), %rcx     # 0x47f98
cmpb $0x0, (%rcx)
je 0xa4ad
incl 0x8(%r14)
jmp 0xa4b2
lock
incl 0x8(%r14)
movq %r13, 0x40(%rsp)
movq 0x70(%rax), %rsi
movq 0x78(%rax), %rdx
addq %rsi, %rdx
movq %r15, %rdi
callq 0xc014
movq %rbx, %rdi
movq %r15, %rsi
callq 0xa948
movq 0x40(%rsp), %rdi
cmpq %r13, %rdi
je 0xa4ec
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x72c0
testq %r14, %r14
je 0xa4f9
movq %r14, %rdi
callq 0x81ea
addq $0x10, %r12
cmpq %rbp, %r12
jne 0xa48d
movq 0x20(%rbx), %r12
movq 0x28(%rbx), %rbp
cmpq %rbp, %r12
je 0xa58e
leaq 0x50(%rsp), %r13
leaq 0x40(%rsp), %r15
movq (%r12), %rax
movq 0x8(%r12), %r14
testq %r14, %r14
je 0xa53e
movq 0x3da6a(%rip), %rcx     # 0x47f98
cmpb $0x0, (%rcx)
je 0xa539
incl 0x8(%r14)
jmp 0xa53e
lock
incl 0x8(%r14)
movq %r13, 0x40(%rsp)
movq 0x58(%rax), %rsi
movq 0x60(%rax), %rdx
addq %rsi, %rdx
movq %r15, %rdi
callq 0xc014
movq %rbx, %rdi
movq %r15, %rsi
callq 0xa948
movq 0x40(%rsp), %rdi
cmpq %r13, %rdi
je 0xa578
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x72c0
testq %r14, %r14
je 0xa585
movq %r14, %rdi
callq 0x81ea
addq $0x10, %r12
cmpq %rbp, %r12
jne 0xa519
leaq 0x30(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x2bb5d(%rip), %rsi     # 0x360fb
leaq 0x2bb5b(%rip), %rdx     # 0x36100
leaq 0x20(%rsp), %rdi
callq 0xc0a4
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rdx
movq %rbx, %rsi
callq 0xa992
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0xa5d8
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x72c0
leaq 0x2bb22(%rip), %rsi     # 0x36101
leaq 0x20(%rsp), %rdi
leaq 0x40(%rsp), %rdx
callq 0xb963
leaq 0x20(%rsp), %rsi
movq %rbx, %rdi
callq 0xadb2
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0xa612
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x72c0
leaq 0x20(%rsp), %rdi
movq %r14, (%rdi)
leaq 0x2bae9(%rip), %rsi     # 0x3610a
leaq 0x2baeb(%rip), %rdx     # 0x36113
callq 0xc0a4
leaq 0x20(%rsp), %rsi
movq %rbx, %rdi
callq 0xadb2
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0xa651
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x72c0
leaq 0x10(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x2bab2(%rip), %rsi     # 0x36114
leaq 0x2babb(%rip), %rdx     # 0x36124
movq %rsp, %rdi
callq 0xc0a4
leaq 0x20(%rsp), %rdi
movq %rsp, %rdx
movq %rbx, %rsi
callq 0xa992
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0xa697
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 0xc014
leaq 0x2df42(%rip), %rsi     # 0x385f8
movq %rsp, %rdi
callq 0x7560
movq %rsp, %rsi
movq %rbx, %rdi
callq 0xb2c4
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0xa6df
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x72c0
leaq 0x2ba3f(%rip), %rsi     # 0x36125
movq %rsp, %rdi
leaq 0x20(%rsp), %rdx
callq 0xb963
movq %rsp, %rsi
movq %rbx, %rdi
callq 0xadb2
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0xa714
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x72c0
movq 0x8(%rbx), %r13
movq 0x10(%rbx), %rbp
cmpq %rbp, %r13
je 0xa764
movq 0x3d870(%rip), %r15     # 0x47f98
movq (%r13), %rdi
movq 0x8(%r13), %r14
testq %r14, %r14
je 0xa746
cmpb $0x0, (%r15)
je 0xa741
incl 0x8(%r14)
jmp 0xa746
lock
incl 0x8(%r14)
movq %rbx, %rsi
callq 0x1842a
testq %r14, %r14
je 0xa75b
movq %r14, %rdi
callq 0x81ea
addq $0x10, %r13
cmpq %rbp, %r13
jne 0xa728
movq 0x20(%rbx), %r13
movq 0x28(%rbx), %rbp
cmpq %rbp, %r13
je 0xa7b4
movq 0x3d820(%rip), %r15     # 0x47f98
movq (%r13), %rdi
movq 0x8(%r13), %r14
testq %r14, %r14
je 0xa796
cmpb $0x0, (%r15)
je 0xa791
incl 0x8(%r14)
jmp 0xa796
lock
incl 0x8(%r14)
movq %rbx, %rsi
callq 0x1b2f0
testq %r14, %r14
je 0xa7ab
movq %r14, %rdi
callq 0x81ea
addq $0x10, %r13
cmpq %rbp, %r13
jne 0xa778
movq %rsp, %rdi
movq %r12, (%rdi)
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rdx
addq %rsi, %rdx
callq 0xc014
leaq 0x2de25(%rip), %rsi     # 0x385f8
movq %rsp, %rdi
callq 0x7560
movq %rsp, %rsi
movq %rbx, %rdi
callq 0xb2c4
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0xa7fc
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x72c0
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
movl 0x64(%rsp), %ebp
je 0xa81c
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x72c0
leaq 0x50(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0xa451
jmp 0xa45e
jmp 0xa83f
jmp 0xa83f
jmp 0xa85e
jmp 0xa83f
jmp 0xa85e
jmp 0xa83f
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0xa8d7
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x72c0
jmp 0xa8d7
movq %rax, %rbx
jmp 0xa8d7
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0xa8f3
movq 0x10(%rsp), %rsi
jmp 0xa8eb
jmp 0xa88f
jmp 0xa880
jmp 0xa88f
movq %rax, %rbx
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
jne 0xa8e6
jmp 0xa8f3
movq %rax, %rbx
jmp 0xa8f3
movq %rax, %rbx
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0xa940
movq 0x30(%rsp), %rsi
jmp 0xa906
jmp 0xa8c0
movq %rax, %rbx
movq 0x40(%rsp), %rdi
cmpq %r14, %rdi
jne 0xa901
jmp 0xa940
movq %rax, %rbx
jmp 0xa940
jmp 0xa8c7
movq %rax, %rbx
testq %r14, %r14
je 0xa8d7
movq %r14, %rdi
callq 0x81ea
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0xa8f3
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x72c0
leaq 0x50(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xa940
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x72c0
jmp 0xa940
jmp 0xa914
jmp 0xa919
movq %rax, %rbx
jmp 0xa933
movq %rax, %rbx
movq 0x40(%rsp), %rdi
cmpq %r13, %rdi
je 0xa933
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x72c0
testq %r14, %r14
je 0xa940
movq %r14, %rdi
callq 0x81ea
movq %rbx, %rdi
callq 0x74f0