// File: /workspace/github_cpp_makefile_star2_O2/rfotino[P]consolite-compiler/src/parser.cpp
// Function: Parser::writeInst(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
void Parser::writeInst(const std::string& inst) {
  // We want to optimize a PUSH followed by a POP by either
  // removing it entirely or by turning it into a single MOV
  // instruction.
  if (_pendingPushReg.empty() &&
      0 == inst.compare(0, std::string("PUSH").size(), "PUSH")) {
    // It is a PUSH instruction and there are no pending push instructions.
    // We need to save the register and write nothing, because the next
    // instruction could be a POP.
    _pendingPushReg = inst.substr(std::string("PUSH ").size());
    return;
  } else if (!_pendingPushReg.empty() &&
             0 == inst.compare(0, std::string("POP").size(), "POP")) {
    // It is a POP instruction and the previous instruction was a PUSH.
    // We can optimize this into nothing or a MOV instruction.
    std::string popReg = inst.substr(std::string("POP ").size());
    std::string pushReg = _pendingPushReg;
    _pendingPushReg = "";
    if (popReg != pushReg) {
      this->writeInst("MOV " + popReg + " " + pushReg);
    }
    return;
  }
  this->writeln("        " + inst);
  _bytePos += INST_SIZE;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0xa8, %rsp
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x238(%rdi), %r14
cmpq $0x0, 0x240(%rdi)
je 0x91e7
leaq 0x1ffab(%rip), %rsi     # 0x29120
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x9502
movq 0x10(%rsp), %rdx
leaq 0x1ff90(%rip), %rcx     # 0x29120
movq %r15, %rdi
xorl %esi, %esi
callq 0x73c0
movl %eax, %ebp
leaq 0x8(%rsp), %rdi
callq 0x75c8
testl %ebp, %ebp
je 0x923a
leaq 0x1ff79(%rip), %rsi     # 0x2912e
leaq 0x8(%rsp), %r14
movq %r14, %rdi
movq %r15, %rdx
callq 0x9980
movq %rbx, %rdi
movq %r14, %rsi
callq 0x93f2
leaq 0x8(%rsp), %rdi
callq 0x75c8
addw $0x4, 0x290(%rbx)
jmp 0x9370
leaq 0x1ff2d(%rip), %rsi     # 0x2911b
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x9502
movq 0x10(%rsp), %rdx
leaq 0x1ff12(%rip), %rcx     # 0x2911b
movq %r15, %rdi
xorl %esi, %esi
callq 0x73c0
movl %eax, %ebp
leaq 0x8(%rsp), %rdi
callq 0x75c8
testl %ebp, %ebp
je 0x9323
cmpq $0x0, 0x240(%rbx)
jne 0x916e
jmp 0x91ae
leaq 0x1fee3(%rip), %rsi     # 0x29124
leaq 0x28(%rsp), %rdi
leaq 0x48(%rsp), %rdx
callq 0x9502
movq 0x30(%rsp), %rdx
leaq 0x8(%rsp), %rdi
pushq $-0x1
popq %rcx
movq %r15, %rsi
callq 0x72f0
leaq 0x28(%rsp), %rdi
callq 0x75c8
leaq 0x28(%rsp), %rdi
movq %r14, %rsi
callq 0x73e0
leaq 0x20e4c(%rip), %rsi     # 0x2a0cf
movq %r14, %rdi
callq 0x7580
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x9aab
testb %al, %al
je 0x9312
leaq 0x1fe84(%rip), %rsi     # 0x29129
leaq 0x68(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x9980
leaq 0x1fe7a(%rip), %rdx     # 0x29135
leaq 0x88(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x9ad4
leaq 0x48(%rsp), %rdi
leaq 0x88(%rsp), %rsi
leaq 0x28(%rsp), %rdx
callq 0x9ab5
leaq 0x48(%rsp), %rsi
movq %rbx, %rdi
callq 0x914a
leaq 0x48(%rsp), %rdi
callq 0x75c8
leaq 0x88(%rsp), %rdi
callq 0x75c8
leaq 0x68(%rsp), %rdi
callq 0x75c8
leaq 0x28(%rsp), %rdi
callq 0x75c8
leaq 0x8(%rsp), %rdi
jmp 0x936b
leaq 0x1fe15(%rip), %rsi     # 0x2913f
leaq 0x28(%rsp), %rdi
leaq 0x48(%rsp), %rdx
callq 0x9502
movq 0x30(%rsp), %rdx
leaq 0x8(%rsp), %rdi
pushq $-0x1
popq %rcx
movq %r15, %rsi
callq 0x72f0
leaq 0x8(%rsp), %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x7360
movq %rbx, %rdi
callq 0x75c8
leaq 0x28(%rsp), %rdi
callq 0x75c8
addq $0xa8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
jmp 0x93c5
jmp 0x93e6
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x75c8
jmp 0x9394
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x75c8
jmp 0x93a6
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x75c8
jmp 0x93b7
jmp 0x93b4
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x75c8
jmp 0x93da
jmp 0x93d7
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
jmp 0x93df
jmp 0x93e6
jmp 0x93d7
jmp 0x93e6
jmp 0x93d7
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x75c8
jmp 0x93e9
movq %rax, %rbx
movq %rbx, %rdi
callq 0x7510
nop