LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_cpp_makefile_star2_O1/mindbeast[P]rnes/cpu.cpp
// Function: Rnes::Cpu::lsrInstReg(unsigned short)
void Cpu::lsrInstReg(uint16_t) {
  uint8_t result = a >> 1;
  setZeroAndNeg(result);
  if (a & 1) {
    setFlag(CARRY);
  } else {
    clearFlag(CARRY);
  }
  a = result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movb 0x8(%rdi), %al
movb 0x18(%rdi), %cl
cmpb $0x2, %al
setb %dl
andb $0x7c, %cl
addb %dl, %dl
orb %cl, %dl
leal 0x1(%rdx), %ecx
testb $0x1, %al
movzbl %dl, %edx
movzbl %cl, %ecx
cmovel %edx, %ecx
movb %cl, 0x18(%rdi)
shrb %al
movb %al, 0x8(%rdi)
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/mindbeast[P]rnes/cpu.cpp
// Function: Rnes::Cpu::rolInstReg(unsigned short)
void Cpu::rolInstReg(uint16_t) {
  uint8_t result = a << 1 | (getFlag(CARRY) ? 1 : 0);
  if (a & (1 << 7)) {
    setFlag(CARRY);
  } else {
    clearFlag(CARRY);
  }
  a = result;
  setZeroAndNeg(a);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movb 0x8(%rdi), %al
movb 0x18(%rdi), %cl
movl %ecx, %edx
andb $0x1, %dl
andb $0x7c, %cl
movl %eax, %esi
shrb $0x7, %sil
orb %cl, %sil
addb %al, %al
orb %al, %dl
movb %dl, 0x8(%rdi)
sete %cl
addb %cl, %cl
orb %sil, %cl
andb $-0x80, %al
orb %cl, %al
movb %al, 0x18(%rdi)
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O1/mindbeast[P]rnes/cpu.cpp
// Function: Rnes::Cpu::rolInstMem(unsigned short)
void Cpu::rolInstMem(uint16_t addr) {
  uint8_t t = load(addr);
  uint8_t result = (t << 1) | (getFlag(CARRY) ? 1 : 0);
  if (t & (1 << 7)) {
    setFlag(CARRY);
  } else {
    clearFlag(CARRY);
  }
  store(addr, result);
  setZeroAndNeg(result);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %esi, %r15d
movq %rdi, %rbx
movq (%rdi), %rdi
callq 0x216a8
movl %eax, %r14d
movb 0x18(%rbx), %al
movl %eax, %ecx
andb $0x1, %cl
andb $-0x2, %al
movl %r14d, %edx
shrb $0x7, %dl
orb %al, %dl
movb %dl, 0x18(%rbx)
addb %r14b, %r14b
orb %r14b, %cl
movq (%rbx), %rdi
movzbl %cl, %r12d
movl %r15d, %esi
movl %r12d, %edx
callq 0x215d0
testb %r12b, %r12b
sete %al
movb 0x18(%rbx), %cl
andb $0x7d, %cl
addb %al, %al
orb %cl, %al
andb $-0x80, %r14b
orb %al, %r14b
movb %r14b, 0x18(%rbx)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O1/mindbeast[P]rnes/cpu.cpp
// Function: Rnes::Cpu::rorInstReg(unsigned short)
void Cpu::rorInstReg(uint16_t) {
  uint8_t result = (a >> 1) | (getFlag(CARRY) ? 1u << 7 : 0);
  if (a & 1) {
    setFlag(CARRY);
  } else {
    clearFlag(CARRY);
  }
  a = result;
  setZeroAndNeg(a);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movb 0x8(%rdi), %al
movb 0x18(%rdi), %cl
movl %eax, %edx
andb $0x1, %dl
movl %ecx, %esi
andb $0x7c, %sil
orb %dl, %sil
shrb %al
shlb $0x7, %cl
orb %al, %cl
movb %cl, 0x8(%rdi)
testb %cl, %cl
sete %al
addb %al, %al
orb %sil, %al
andb $-0x80, %cl
orb %al, %cl
movb %cl, 0x18(%rdi)
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/mindbeast[P]rnes/cpu.cpp
// Function: Rnes::Cpu::rorInstMem(unsigned short)
void Cpu::rorInstMem(uint16_t addr) {
  uint8_t t = load(addr);
  uint8_t result = (t >> 1) | (getFlag(CARRY) ? 1u << 7 : 0);
  if (t & 1) {
    setFlag(CARRY);
  } else {
    clearFlag(CARRY);
  }
  store(addr, result);
  setZeroAndNeg(result);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %r14d
movq %rdi, %rbx
movq (%rdi), %rdi
callq 0x216a8
movb 0x18(%rbx), %cl
movl %eax, %edx
andb $0x1, %dl
movl %ecx, %esi
andb $-0x2, %sil
orb %dl, %sil
movb %sil, 0x18(%rbx)
shrb %al
shlb $0x7, %cl
orb %al, %cl
movq (%rbx), %rdi
movzbl %cl, %r15d
movl %r14d, %esi
movl %r15d, %edx
callq 0x215d0
testb %r15b, %r15b
sete %al
movb 0x18(%rbx), %cl
andb $0x7d, %cl
addb %al, %al
orb %cl, %al
andb $-0x80, %r15b
orb %al, %r15b
movb %r15b, 0x18(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/mindbeast[P]rnes/cpu.cpp
// Function: Rnes::Cpu::rtiInst(unsigned short)
void Cpu::rtiInst(uint16_t) {
  uint16_t targetPc;
  status = (popStack() & ~BREAK) | ONE;

  targetPc = popStack();
  targetPc |= ((uint16_t)popStack() << 8);
  pc = targetPc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movb 0xe(%rdi), %al
incb %al
movb %al, 0xe(%rdi)
movzbl %al, %esi
movl $0x100, %r15d           # imm = 0x100
orl %r15d, %esi
movq (%rdi), %rdi
callq 0x216a8
andb $-0x31, %al
orb $0x20, %al
movb %al, 0x18(%rbx)
movb 0xe(%rbx), %al
incb %al
movb %al, 0xe(%rbx)
movzbl %al, %esi
orl %r15d, %esi
movq (%rbx), %rdi
callq 0x216a8
movl %eax, %r14d
movb 0xe(%rbx), %al
incb %al
movb %al, 0xe(%rbx)
movzbl %al, %esi
orl %r15d, %esi
movq (%rbx), %rdi
callq 0x216a8
movzbl %al, %eax
shll $0x8, %eax
movzbl %r14b, %ecx
orl %eax, %ecx
movw %cx, 0xc(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/mindbeast[P]rnes/cpu.cpp
// Function: Rnes::Cpu::sbcInst(unsigned short)
void Cpu::sbcInst(uint16_t addr) {
  uint8_t v = load(addr);
  int16_t sresult = (int16_t)(int8_t)a - (int16_t)(int8_t)v - (getFlag(CARRY) ? 0 : 1);
  int16_t uresult = (int16_t)a - (int16_t)v - (getFlag(CARRY) ? 0 : 1);

  if (uresult >= 0) {
    setFlag(CARRY);
  } else {
    clearFlag(CARRY);
  }
  if (sresult > 127 || sresult < -128) {
    setFlag(OVERFL);
  } else {
    clearFlag(OVERFL);
  }
  a = (uint8_t)uresult;
  setZeroAndNeg(a);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq (%rdi), %rdi
callq 0x216a8
movzbl 0x8(%rbx), %ecx
movsbl %cl, %edx
movsbl %al, %eax
movb 0x18(%rbx), %sil
xorl %edi, %edi
testb $0x1, %sil
sete %dil
movzbl %al, %r8d
subl %r8d, %ecx
subl %edi, %ecx
andb $0x3c, %sil
testw %cx, %cx
setns %r8b
orb %sil, %r8b
subl %eax, %edx
subl %edi, %edx
movsbl %dl, %eax
cmpl %edx, %eax
setne %al
shlb $0x6, %al
orb %r8b, %al
movb %cl, 0x8(%rbx)
testb %cl, %cl
sete %dl
addb %dl, %dl
orb %al, %dl
andb $-0x80, %cl
orb %dl, %cl
movb %cl, 0x18(%rbx)
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O1/mindbeast[P]rnes/cpu.cpp
// Function: Rnes::Cpu::dcpInst(unsigned short)
void Cpu::dcpInst(uint16_t addr) {
  uint8_t result = load(addr) - 1;
  // setZeroAndNeg(result);
  store(addr, result);
  if (x >= result) {
    setFlag(CARRY);
  } else {
    clearFlag(CARRY);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %ebx
movq %rdi, %r14
movq (%rdi), %rdi
callq 0x216a8
decb %al
movq (%r14), %rdi
movzbl %al, %r15d
movl %ebx, %esi
movl %r15d, %edx
callq 0x215d0
movb 0x18(%r14), %al
cmpb %r15b, 0x9(%r14)
setae %cl
andb $-0x2, %al
orb %cl, %al
movb %al, 0x18(%r14)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/mindbeast[P]rnes/cpu.cpp
// Function: Rnes::Cpu::runInst()
uint32_t Cpu::runInst() {
  // check for nmi
  if (nmiRequested()) {
    return doNmi();
  }
  // check for lower priority maskable interrupts
  if (intRequested() && !getFlag(INT_DISABLE)) {
    return doInt();
  }

  // load opcode using current pc
  uint8_t opcode = load(pc);

  // look up instruction in the table
  auto itr = instTable.find(opcode);
  if (itr == instTable.end()) {
    assert(0);
    return 0;
  }

  // run the instruction
  const Instruction &ins = itr->second;
  (this->*(ins.func))(ins);

  // update the cycle count
  cycle += ins.cycles;
  return ins.cycles;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
movq (%rdi), %rdi
callq 0x218a2
testb %al, %al
je 0x1cb6c
movq %rbx, %rdi
callq 0x1bb92
movl $0x7, %eax
jmp 0x1cbf5
movq (%rbx), %rdi
callq 0x218b0
testb %al, %al
je 0x1cb88
testb $0x4, 0x18(%rbx)
jne 0x1cb88
movq %rbx, %rdi
callq 0x1bafa
jmp 0x1cb62
movzwl 0xc(%rbx), %esi
movq (%rbx), %rdi
callq 0x216a8
leaq -0x11(%rbp), %rcx
movb %al, (%rcx)
movzbl %al, %r8d
leaq 0x2bc1b(%rip), %rdi     # 0x487c0
xorl %r14d, %r14d
movq %r8, %rax
xorl %edx, %edx
divq 0x2bc14(%rip)           # 0x487c8
movq %rdx, %rsi
movq %rcx, %rdx
movq %r8, %rcx
callq 0x211c4
testq %rax, %rax
je 0x1cbca
movq (%rax), %r14
testq %r14, %r14
je 0x1cbfe
leaq 0x10(%r14), %rsi
movq 0x38(%r14), %rax
movq 0x40(%r14), %rdi
addq %rbx, %rdi
testb $0x1, %al
je 0x1cbea
movq (%rdi), %rcx
movq -0x1(%rcx,%rax), %rax
callq *%rax
movzwl 0x30(%r14), %eax
addq %rax, 0x10(%rbx)
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq
leaq 0x1789f(%rip), %rdi     # 0x344a4
leaq 0x18746(%rip), %rsi     # 0x35352
leaq 0x18747(%rip), %rcx     # 0x3535a
movl $0x3c7, %edx            # imm = 0x3C7
callq 0xb160
nop
// File: /workspace/github_cpp_makefile_star2_O1/mindbeast[P]rnes/cpu.cpp
// Function: Rnes::Cpu::reset()
void Cpu::reset() {
  setFlag(INT_DISABLE);
  setFlag(ONE);
  pc = load16(resetBaseAddr);
  sp = stackPointerStart;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
movq %rdi, %rbx
orb $0x24, 0x18(%rdi)
movq (%rdi), %rdi
movl $0xfffc, %esi           # imm = 0xFFFC
callq 0x216a8
movl %eax, %r14d
movq (%rbx), %rdi
movl $0xfffd, %esi           # imm = 0xFFFD
callq 0x216a8
movzbl %al, %eax
shll $0x8, %eax
movzbl %r14b, %ecx
orl %eax, %ecx
movw %cx, 0xc(%rbx)
movb $-0x3, 0xe(%rbx)
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/mindbeast[P]rnes/cpu.cpp
// Function: Rnes::Cpu::dumpRegs()
void Cpu::dumpRegs() {
  using namespace std;
  cerr << setfill('0') << right;
  cerr << "A:" << setw(2) << (int)a << " ";
  cerr << "X:" << setw(2) << (int)x << " ";
  cerr << "Y:" << setw(2) << (int)y << " ";
  cerr << "P:" << setw(2) << (int)status << " ";
  cerr << "SP:" << setw(2) << (int)sp << " ";
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdi, %r14
movq 0x2b379(%rip), %rbx     # 0x47ff0
movq (%rbx), %rax
movq -0x18(%rax), %rax
leaq (%rbx,%rax), %r15
cmpb $0x0, 0xe1(%rbx,%rax)
jne 0x1cca8
movq %r15, %rdi
movl $0x20, %esi
callq 0xb850
movb %al, 0xe0(%r15)
movb $0x1, 0xe1(%r15)
movb $0x30, 0xe0(%r15)
movq (%rbx), %rax
movq -0x18(%rax), %rax
movl $0xffffff4f, %ecx       # imm = 0xFFFFFF4F
andl 0x18(%rbx,%rax), %ecx
orl $0x80, %ecx
movl %ecx, 0x18(%rbx,%rax)
leaq 0x186a7(%rip), %rsi     # 0x35378
movl $0x2, %r12d
movl $0x2, %edx
movq %rbx, %rdi
callq 0xb7a0
movq (%rbx), %rax
movq -0x18(%rax), %rax
movq %r12, 0x10(%rbx,%rax)
movzbl 0x8(%r14), %esi
movq %rbx, %rdi
callq 0xb290
leaq 0x18683(%rip), %r15     # 0x35387
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0xb7a0
leaq 0x18660(%rip), %rsi     # 0x3537b
movl $0x2, %edx
movq %rbx, %rdi
callq 0xb7a0
movq (%rbx), %rax
movq -0x18(%rax), %rax
movq %r12, 0x10(%rbx,%rax)
movzbl 0x9(%r14), %esi
movq %rbx, %rdi
callq 0xb290
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0xb7a0
leaq 0x18626(%rip), %rsi     # 0x3537e
movl $0x2, %edx
movq %rbx, %rdi
callq 0xb7a0
movq (%rbx), %rax
movq -0x18(%rax), %rax
movq %r12, 0x10(%rbx,%rax)
movzbl 0xa(%r14), %esi
movq %rbx, %rdi
callq 0xb290
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0xb7a0
leaq 0x185ed(%rip), %rsi     # 0x35382
movl $0x2, %edx
movq %rbx, %rdi
callq 0xb7a0
movq (%rbx), %rax
movq -0x18(%rax), %rax
movq %r12, 0x10(%rbx,%rax)
movzbl 0x18(%r14), %esi
movq %rbx, %rdi
callq 0xb290
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0xb7a0
leaq 0x185af(%rip), %rsi     # 0x35381
movl $0x3, %edx
movq %rbx, %rdi
callq 0xb7a0
movq (%rbx), %rax
movq -0x18(%rax), %rax
movq %r12, 0x10(%rbx,%rax)
movzbl 0xe(%r14), %esi
movq %rbx, %rdi
callq 0xb290
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0xb7a0
// File: /workspace/github_cpp_makefile_star2_O1/mindbeast[P]rnes/cpu.cpp
// Function: Rnes::Cpu::dumpInstructionBytes(int)
void Cpu::dumpInstructionBytes(int bytes) {
  using namespace std;
  cerr << setfill('0') << right;
  for (int i = 0; i < bytes; i++) {
    cerr << setw(2) << uppercase << (int)load(pc + i) << " ";
  }
  for (int i = 0; i < maxInstLength - bytes; i++) {
    cerr << "   ";
  }
  cerr << " ";
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %esi, %ebx
movq %rdi, %r14
movq 0x2b108(%rip), %r15     # 0x47ff0
movq (%r15), %rax
movq -0x18(%rax), %rax
leaq (%r15,%rax), %r12
cmpb $0x0, 0xe1(%r15,%rax)
jne 0x1cf1c
movq %r12, %rdi
movl $0x20, %esi
callq 0xb850
movb %al, 0xe0(%r12)
movb $0x1, 0xe1(%r12)
movb $0x30, 0xe0(%r12)
movq (%r15), %rax
movq -0x18(%rax), %rax
movl $0xffffff4f, %ecx       # imm = 0xFFFFFF4F
andl 0x18(%r15,%rax), %ecx
orl $0x80, %ecx
movl %ecx, 0x18(%r15,%rax)
testl %ebx, %ebx
jle 0x1cfa1
xorl %r13d, %r13d
leaq 0x18438(%rip), %r12     # 0x35387
movq (%r15), %rax
movq -0x18(%rax), %rcx
movq $0x2, 0x10(%r15,%rcx)
movq -0x18(%rax), %rax
orl $0x4000, 0x18(%r15,%rax) # imm = 0x4000
movl 0xc(%r14), %eax
addl %r13d, %eax
movq (%r14), %rdi
movzwl %ax, %esi
callq 0x216a8
movzbl %al, %esi
movq %r15, %rdi
callq 0xb290
movl $0x1, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0xb7a0
incl %r13d
cmpl %r13d, %ebx
jne 0x1cf4f
cmpl $0x2, %ebx
jg 0x1cfdd
movl $0x3, %eax
subl %ebx, %eax
cmpl $0x2, %eax
movl $0x1, %r15d
cmovgel %eax, %r15d
movq 0x2b02f(%rip), %rbx     # 0x47ff0
leaq 0x183bd(%rip), %r14     # 0x35385
movl $0x3, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0xb7a0
decl %r15d
jne 0x1cfc8
movq 0x2b00c(%rip), %rdi     # 0x47ff0
leaq 0x1839c(%rip), %rsi     # 0x35387
movl $0x1, %edx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xb7a0
nop
// File: /workspace/github_cpp_makefile_star2_O1/mindbeast[P]rnes/cpu.cpp
// Function: Rnes::Cpu::dumpPPUTiming()
void Cpu::dumpPPUTiming() {
  using namespace std;
  // const int initScanLine = 0;
  cerr << setfill(' ') << right;
  cerr << "CYC:" << dec << setw(3) << (3 * cycle) % 341;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %r14
movq 0x2afd8(%rip), %rbx     # 0x47ff0
movq (%rbx), %rax
movq -0x18(%rax), %rax
leaq (%rbx,%rax), %r15
cmpb $0x0, 0xe1(%rbx,%rax)
jne 0x1d049
movq %r15, %rdi
movl $0x20, %esi
callq 0xb850
movb %al, 0xe0(%r15)
movb $0x1, 0xe1(%r15)
movb $0x20, 0xe0(%r15)
movq (%rbx), %rax
movq -0x18(%rax), %rax
movl $0xffffff4f, %ecx       # imm = 0xFFFFFF4F
andl 0x18(%rbx,%rax), %ecx
orl $0x80, %ecx
movl %ecx, 0x18(%rbx,%rax)
leaq 0x18317(%rip), %rsi     # 0x35389
movl $0x4, %edx
movq %rbx, %rdi
callq 0xb7a0
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movl 0x18(%rbx,%rcx), %edx
andl $-0x4b, %edx
orl $0x2, %edx
movl %edx, 0x18(%rbx,%rcx)
movq -0x18(%rax), %rax
movq $0x3, 0x10(%rbx,%rax)
movq 0x10(%r14), %rax
leaq (%rax,%rax,2), %rsi
movabsq $-0x7f9fe7f9fe7f9fe7, %rcx # imm = 0x8060180601806019
movq %rsi, %rax
mulq %rcx
movq %rsi, %rax
subq %rdx, %rax
shrq %rax
addq %rdx, %rax
shrq $0x8, %rax
imulq $0x155, %rax, %rax      # imm = 0x155
subq %rax, %rsi
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0xb3e0
nop
// File: /workspace/github_cpp_makefile_star2_O1/mindbeast[P]rnes/cpu.cpp
// Function: Rnes::Cpu::save(Rnes::CpuState&)
void Cpu::save(CpuState &pb) {
  // Registers
  pb.set_a(a);
  pb.set_x(x);
  pb.set_y(y);

  // Program counter
  pb.set_pc(pc);

  // stack pointer
  pb.set_sp(sp);

  // cycle count
  pb.set_cycle(cycle);

  // processor status register
  pb.set_status(status);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movzbl 0x8(%rdi), %ecx
movl 0x10(%rsi), %eax
movl %eax, %edx
orl $0x1, %edx
movl %edx, 0x10(%rsi)
movl %ecx, 0x18(%rsi)
movzbl 0x9(%rdi), %ecx
movl %eax, %edx
orl $0x3, %edx
movl %edx, 0x10(%rsi)
movl %ecx, 0x1c(%rsi)
movzbl 0xa(%rdi), %ecx
movl %eax, %edx
orl $0x7, %edx
movl %edx, 0x10(%rsi)
movl %ecx, 0x20(%rsi)
movzwl 0xc(%rdi), %ecx
movl %eax, %edx
orl $0xf, %edx
movl %edx, 0x10(%rsi)
movl %ecx, 0x24(%rsi)
movzbl 0xe(%rdi), %ecx
movl %eax, %edx
orl $0x1f, %edx
movl %edx, 0x10(%rsi)
movl %ecx, 0x28(%rsi)
movq 0x10(%rdi), %rcx
movl %eax, %edx
orl $0x5f, %edx
movl %edx, 0x10(%rsi)
movq %rcx, 0x30(%rsi)
movzbl 0x18(%rdi), %ecx
orl $0x7f, %eax
movl %eax, 0x10(%rsi)
movl %ecx, 0x2c(%rsi)
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O1/mindbeast[P]rnes/cpu.cpp
// Function: Rnes::Cpu::restore(Rnes::CpuState const&)
void Cpu::restore(const CpuState &pb) {
  // Registers
  a = pb.a();
  x = pb.x();
  y = pb.y();

  // Program counter
  pc = pb.pc();

  // stack pointer
  sp = pb.sp();

  // cycle count
  cycle = pb.cycle();

  // processor status register
  status = pb.status();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movb 0x18(%rsi), %al
movb %al, 0x8(%rdi)
movb 0x1c(%rsi), %al
movb %al, 0x9(%rdi)
movb 0x20(%rsi), %al
movb %al, 0xa(%rdi)
movzwl 0x24(%rsi), %eax
movw %ax, 0xc(%rdi)
movb 0x28(%rsi), %al
movb %al, 0xe(%rdi)
movq 0x30(%rsi), %rax
movq %rax, 0x10(%rdi)
movb 0x2c(%rsi), %al
movb %al, 0x18(%rdi)
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/mindbeast[P]rnes/cpu.cpp
// Function: Rnes::Cpu::Cpu(Rnes::Nes*)
Cpu::Cpu(Nes *system) {
  a = 0;
  x = 0;
  y = 0;
  pc = 0;
  status = 0;
  sp = 0;
  cycle = 0;
  nes = system;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
xorl %eax, %eax
movw %ax, 0x8(%rdi)
movb %al, 0xa(%rdi)
movw %ax, 0xc(%rdi)
movb %al, 0x18(%rdi)
movb %al, 0xe(%rdi)
movq $0x0, 0x10(%rdi)
movq %rsi, (%rdi)
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/mindbeast[P]rnes/cpu.cpp
// Function: void Rnes::Cpu::indexedIndirectFormat<&Rnes::Cpu::staInst(unsigned short)>(Rnes::Cpu::Instruction const&)
void Cpu::indexedIndirectFormat(const Instruction &ins) {
  uint16_t immediateAddr = pc + 1;
  uint8_t immed = load(immediateAddr);
  uint8_t tableAddr = immed + x;
  uint16_t finalAddr = load(tableAddr);
  finalAddr |= (uint16_t)load((tableAddr + 1) & 0xff) << 8;

  std::stringstream str;
  str << std::setfill('0') << std::right;
  str << ins.nemonic << " ($" << std::hex << std::uppercase << std::setw(2) << (int)immed << ",X)";

  instTrace(str.str(), 2);

  pc += 2;
  (this->*fx)(finalAddr);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1b8, %rsp            # imm = 0x1B8
movq %rsi, %r13
movq %rdi, %rbx
movl 0xc(%rdi), %eax
incl %eax
movq (%rdi), %rdi
movzwl %ax, %esi
callq 0x216a8
movl %eax, %r12d
movb 0x9(%rbx), %al
addb %r12b, %al
movq (%rbx), %rdi
movzbl %al, %r14d
movl %r14d, %esi
callq 0x216a8
movb %al, -0x29(%rbp)
incb %r14b
movq (%rbx), %rdi
movzbl %r14b, %esi
callq 0x216a8
movl %eax, %r15d
leaq -0x1d8(%rbp), %r14
movq %r14, %rdi
callq 0xb260
movq 0x10(%r14), %rax
movq -0x18(%rax), %rax
leaq (%rax,%rbp), %r14
addq $-0x1c8, %r14           # imm = 0xFE38
cmpb $0x0, 0xe1(%r14)
jne 0x1f21d
movq %r14, %rdi
movl $0x20, %esi
callq 0xb850
movb %al, 0xe0(%r14)
movb $0x1, 0xe1(%r14)
leaq -0x1c8(%rbp), %rdi
movb $0x30, 0xe0(%r14)
movq (%rdi), %rax
movq -0x18(%rax), %rax
movl $0xffffff4f, %ecx       # imm = 0xFFFFFF4F
andl -0x1b0(%rbp,%rax), %ecx
orl $0x80, %ecx
movl %ecx, -0x1b0(%rbp,%rax)
movq (%r13), %rsi
movq 0x8(%r13), %rdx
callq 0xb7a0
movq %rax, %r13
leaq 0x1612b(%rip), %rsi     # 0x3538e
movl $0x3, %edx
movq %rax, %rdi
callq 0xb7a0
movq (%r13), %rax
movq -0x18(%rax), %rcx
movl 0x18(%r13,%rcx), %edx
andl $-0x4b, %edx
orl $0x8, %edx
movl %edx, 0x18(%r13,%rcx)
movq -0x18(%rax), %rcx
orl $0x4000, 0x18(%r13,%rcx) # imm = 0x4000
movzbl %r12b, %esi
movq -0x18(%rax), %rax
movq $0x2, 0x10(%r13,%rax)
movq %r13, %rdi
callq 0xb290
leaq 0x160dd(%rip), %rsi     # 0x35392
movl $0x3, %edx
movq %rax, %rdi
callq 0xb7a0
leaq -0x1c0(%rbp), %rsi
leaq -0x50(%rbp), %rdi
callq 0xb310
movzbl %r15b, %eax
shll $0x8, %eax
movzbl -0x29(%rbp), %r14d
orl %eax, %r14d
leaq -0x40(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1f2fa
movq -0x40(%rbp), %rsi
incq %rsi
callq 0xb0e0
addw $0x2, 0xc(%rbx)
movzbl 0x8(%rbx), %edx
movq (%rbx), %rdi
movzwl %r14w, %esi
callq 0x215d0
movq 0x28cc2(%rip), %rsi     # 0x47fd8
leaq -0x1d8(%rbp), %rdi
callq 0xb5c0
leaq -0x158(%rbp), %rdi
callq 0xb560
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1f342
movq %rax, %rbx
movq 0x28c8c(%rip), %rsi     # 0x47fd8
leaq -0x1d8(%rbp), %rdi
callq 0xb5c0
leaq -0x158(%rbp), %rdi
callq 0xb560
movq %rbx, %rdi
callq 0xb4d0
// File: /workspace/github_cpp_makefile_star2_O1/mindbeast[P]rnes/cpu.cpp
// Function: void Rnes::Cpu::zeroPageFormat<&Rnes::Cpu::styInst(unsigned short)>(Rnes::Cpu::Instruction const&)
void Cpu::zeroPageFormat(const Instruction &ins) {
  uint16_t zeroPageAddr = pc + 1;

  if (debug) {
    int zeroPageLoad = load(zeroPageAddr);
    std::stringstream str;
    str << std::setfill('0') << std::right;
    str << ins.nemonic << " $" << std::hex << std::uppercase << std::setw(2) << zeroPageLoad;
    instTrace(str.str(), 2);
  }
  pc += 2;
  (this->*fx)((uint16_t)load(zeroPageAddr));
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
movl 0xc(%rdi), %eax
leal 0x1(%rax), %ecx
addl $0x2, %eax
movw %ax, 0xc(%rdi)
movq (%rdi), %rdi
movzwl %cx, %esi
callq 0x216a8
movzbl 0xa(%rbx), %edx
movq (%rbx), %rdi
movzbl %al, %esi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x215d0
// File: /workspace/github_cpp_makefile_star2_O1/mindbeast[P]rnes/cpu.cpp
// Function: void Rnes::Cpu::absoluteFormat<&Rnes::Cpu::styInst(unsigned short)>(Rnes::Cpu::Instruction const&)
void Cpu::absoluteFormat(const Instruction &ins) {
  uint16_t immediateAddr = pc + 1;
  uint16_t absAddr = load(immediateAddr);
  absAddr |= ((uint16_t)load(immediateAddr + 1)) << 8;

  if (debug) {
    int immed = load16(immediateAddr);
    std::stringstream str;
    str << std::setfill('0') << std::right;
    str << ins.nemonic << " $" << std::hex << std::uppercase << std::setw(4) << immed;
    instTrace(str.str(), 3);
  }
  pc += 3;
  (this->*fx)(absAddr);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdi, %rbx
movl 0xc(%rdi), %r14d
leal 0x1(%r14), %esi
movq (%rdi), %rdi
movl $0xffff, %r12d          # imm = 0xFFFF
andl %r12d, %esi
callq 0x216a8
movl %eax, %r15d
addl $0x2, %r14d
movq (%rbx), %rdi
andl %r12d, %r14d
movl %r14d, %esi
callq 0x216a8
movzbl %al, %eax
shll $0x8, %eax
addw $0x3, 0xc(%rbx)
movzbl %r15b, %esi
orl %eax, %esi
movzbl 0xa(%rbx), %edx
movq (%rbx), %rdi
andl %r12d, %esi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x215d0
// File: /workspace/github_cpp_makefile_star2_O1/mindbeast[P]rnes/cpu.cpp
// Function: void Rnes::Cpu::relativeFormat<&Rnes::Cpu::bplInst(unsigned short)>(Rnes::Cpu::Instruction const&)
void Cpu::relativeFormat(const Instruction &ins) {
  uint16_t immedAddr = pc + 1;
  int8_t relativeAddr = load(immedAddr);

  if (debug) {
    std::stringstream str;
    str << std::setfill('0') << std::right;
    str << ins.nemonic << " $" << std::hex << std::uppercase << std::setw(4)
        << relativeAddr + pc + 2;
    instTrace(str.str(), 2);
  }
  pc += 2;

  (this->*fx)((int16_t)relativeAddr);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
movl 0xc(%rdi), %eax
incl %eax
movq (%rdi), %rdi
movzwl %ax, %esi
callq 0x216a8
movl 0xc(%rbx), %ecx
addl $0x2, %ecx
movw %cx, 0xc(%rbx)
cmpb $0x0, 0x18(%rbx)
js 0x1d741
movsbl %al, %eax
addl %ecx, %eax
movl %eax, %edx
xorl %ecx, %edx
movzwl %dx, %ecx
cmpl $0x100, %ecx            # imm = 0x100
movq 0x10(%rbx), %rcx
sbbq $0x0, %rcx
addq $0x2, %rcx
movq %rcx, 0x10(%rbx)
movw %ax, 0xc(%rbx)
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/mindbeast[P]rnes/cpu.cpp
// Function: void Rnes::Cpu::indirectIndexedFormat<&Rnes::Cpu::staInst(unsigned short)>(Rnes::Cpu::Instruction const&)
void Cpu::indirectIndexedFormat(const Instruction &ins) {
  uint16_t immediateAddr = pc + 1;
  uint8_t immed = load(immediateAddr);

  uint16_t tableAddr = load(immed);
  tableAddr |= (uint16_t)load((immed + 1) & 0xff) << 8;

  uint16_t finalAddr = tableAddr + y;

  if (debug) {
    std::stringstream str;
    str << std::setfill('0') << std::right;
    str << ins.nemonic << " ($" << std::hex << std::uppercase << std::setw(2) << (int)immed
        << "),Y";
    instTrace(str.str(), 2);
  }

  // Add a penalty when y causes the table addr and final address to
  // not be on the same page
  if (ins.cycles == 5) {
    if ((tableAddr & 0xff00) != ((tableAddr + y) & 0xff00)) {
      cycle++;
    }
  }

  pc += 2;
  (this->*fx)(finalAddr);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rsi, %r14
movq %rdi, %rbx
movl 0xc(%rdi), %eax
incl %eax
movq (%rdi), %rdi
movzwl %ax, %esi
callq 0x216a8
movq (%rbx), %rdi
movzbl %al, %r15d
movl %r15d, %esi
callq 0x216a8
movl %eax, %r12d
incb %r15b
movq (%rbx), %rdi
movzbl %r15b, %esi
callq 0x216a8
movzbl %al, %ecx
shll $0x8, %ecx
movzbl %r12b, %edx
orl %ecx, %edx
movzbl 0xa(%rbx), %eax
addl %edx, %eax
cmpw $0x5, 0x20(%r14)
jne 0x1f628
movl %eax, %edx
andl $0xff00, %edx           # imm = 0xFF00
cmpl %edx, %ecx
je 0x1f628
incq 0x10(%rbx)
addw $0x2, 0xc(%rbx)
movzbl 0x8(%rbx), %edx
movq (%rbx), %rdi
movzwl %ax, %esi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x215d0
// File: /workspace/github_cpp_makefile_star2_O1/mindbeast[P]rnes/cpu.cpp
// Function: void Rnes::Cpu::zeroPageXFormat<&Rnes::Cpu::styInst(unsigned short)>(Rnes::Cpu::Instruction const&)
void Cpu::zeroPageXFormat(const Instruction &ins) {
  uint16_t zeroPageAddr = pc + 1;

  if (debug) {
    int zeroPageLoad = load(zeroPageAddr);
    std::stringstream str;
    str << std::setfill('0') << std::right;
    str << ins.nemonic << " $" << std::hex << std::uppercase << std::setw(2) << zeroPageLoad
        << ",X";
    instTrace(str.str(), 2);
  }
  pc += 2;
  (this->*fx)((uint16_t)((load(zeroPageAddr) + x) & 0xff));
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
movl 0xc(%rdi), %eax
leal 0x1(%rax), %ecx
addl $0x2, %eax
movw %ax, 0xc(%rdi)
movq (%rdi), %rdi
movzwl %cx, %esi
callq 0x216a8
addb 0x9(%rbx), %al
movzbl 0xa(%rbx), %edx
movq (%rbx), %rdi
movzbl %al, %esi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x215d0
nop
// File: /workspace/github_cpp_makefile_star2_O1/mindbeast[P]rnes/cpu.cpp
// Function: void Rnes::Cpu::absoluteYFormat<&Rnes::Cpu::staInst(unsigned short)>(Rnes::Cpu::Instruction const&)
void Cpu::absoluteYFormat(const Instruction &ins) {
  uint16_t relativeAddr = pc + 1;
  uint16_t absAddr = load(relativeAddr);
  absAddr |= ((uint16_t)load(relativeAddr + 1)) << 8;

  if (debug) {
    std::stringstream str;
    str << std::setfill('0') << std::right;
    str << ins.nemonic << " $" << std::hex << std::uppercase << std::setw(4) << (int)absAddr
        << ",Y";
    instTrace(str.str(), 3);
  }

  // instructions that have a base cycle count of 4, will take a 1 cycle
  // penalty when they cross
  if (ins.cycles == 4) {
    if ((absAddr & 0xff00) != ((absAddr + y) & 0xff00)) {
      cycle++;
    }
  }

  absAddr += y;
  pc += 3;
  (this->*fx)(absAddr);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
movl 0xc(%rdi), %r15d
leal 0x1(%r15), %esi
movq (%rdi), %rdi
movl $0xffff, %r13d          # imm = 0xFFFF
andl %r13d, %esi
callq 0x216a8
movl %eax, %r12d
addl $0x2, %r15d
movq (%rbx), %rdi
andl %r13d, %r15d
movl %r15d, %esi
callq 0x216a8
movzbl %al, %ecx
shll $0x8, %ecx
movzbl %r12b, %eax
orl %ecx, %eax
cmpw $0x4, 0x20(%r14)
jne 0x1f76f
movzwl %ax, %ecx
movzbl 0xa(%rbx), %edx
addl %ecx, %edx
xorl %ecx, %edx
testl $0xff00, %edx           # imm = 0xFF00
je 0x1f76f
incq 0x10(%rbx)
movzbl 0xa(%rbx), %ecx
addw $0x3, 0xc(%rbx)
addl %ecx, %eax
movzbl 0x8(%rbx), %edx
movq (%rbx), %rdi
movzwl %ax, %esi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x215d0
nop
// File: /workspace/github_cpp_makefile_star2_O1/mindbeast[P]rnes/cpu.cpp
// Function: void Rnes::Cpu::absoluteXFormat<&Rnes::Cpu::staInst(unsigned short)>(Rnes::Cpu::Instruction const&)
void Cpu::absoluteXFormat(const Instruction &ins) {
  uint16_t relativeAddr = pc + 1;
  uint16_t absAddr = load(relativeAddr);
  absAddr |= ((uint16_t)load(relativeAddr + 1)) << 8;

  if (debug) {
    std::stringstream str;
    str << std::setfill('0') << std::right;
    str << ins.nemonic << " $" << std::hex << std::uppercase << std::setw(4) << (int)absAddr
        << ",X";
    instTrace(str.str(), 3);
  }

  // instructions that have a base cycle count of 4, will take a 1 cycle
  // penalty when they cross
  if (ins.cycles == 4) {
    if ((absAddr & 0xff00) != ((absAddr + x) & 0xff00)) {
      cycle++;
    }
  }

  absAddr += x;
  pc += 3;
  (this->*fx)(absAddr);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
movl 0xc(%rdi), %r15d
leal 0x1(%r15), %esi
movq (%rdi), %rdi
movl $0xffff, %r13d          # imm = 0xFFFF
andl %r13d, %esi
callq 0x216a8
movl %eax, %r12d
addl $0x2, %r15d
movq (%rbx), %rdi
andl %r13d, %r15d
movl %r15d, %esi
callq 0x216a8
movzbl %al, %ecx
shll $0x8, %ecx
movzbl %r12b, %eax
orl %ecx, %eax
cmpw $0x4, 0x20(%r14)
jne 0x1f815
movzwl %ax, %ecx
movzbl 0x9(%rbx), %edx
addl %ecx, %edx
xorl %ecx, %edx
testl $0xff00, %edx           # imm = 0xFF00
je 0x1f815
incq 0x10(%rbx)
movzbl 0x9(%rbx), %ecx
addw $0x3, 0xc(%rbx)
addl %ecx, %eax
movzbl 0x8(%rbx), %edx
movq (%rbx), %rdi
movzwl %ax, %esi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x215d0
nop
// File: /workspace/github_cpp_makefile_star2_O1/mindbeast[P]rnes/cpu.cpp
// Function: void Rnes::Cpu::indirectFormat<&Rnes::Cpu::jmpInst(unsigned short)>(Rnes::Cpu::Instruction const&)
void Cpu::indirectFormat(const Instruction &ins) {
  uint16_t immediateAddr = pc + 1u;
  uint16_t absAddr = load(immediateAddr);
  absAddr |= ((uint16_t)load(immediateAddr + 1u)) << 8;

  uint16_t finalAddr = load(absAddr);
  // bug in jmp (yes, this needs to work)
  if ((absAddr & 0xff) == 0xff) {
    finalAddr |= ((uint16_t)load(absAddr & 0xff00)) << 8;
  } else {
    finalAddr |= ((uint16_t)load(absAddr + 1u)) << 8;
  }

  if (debug) {
    std::stringstream str;
    str << std::setfill('0') << std::right;
    str << ins.nemonic << " ($" << std::hex << std::uppercase << std::setw(4) << (int)absAddr
        << ")";
    instTrace(str.str(), 3);
  }

  pc += 3;
  (this->*fx)(finalAddr);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movl 0xc(%rdi), %r14d
leal 0x1(%r14), %esi
movq (%rdi), %rdi
movl $0xffff, %r12d          # imm = 0xFFFF
andl %r12d, %esi
callq 0x216a8
movl %eax, %r15d
addl $0x2, %r14d
movq (%rbx), %rdi
andl %r12d, %r14d
movl %r14d, %esi
callq 0x216a8
movzbl %al, %r13d
shll $0x8, %r13d
movzbl %r15b, %r15d
leal (%r15,%r13), %esi
movq (%rbx), %rdi
andl %r12d, %esi
callq 0x216a8
movl %eax, %r14d
cmpb $-0x1, %r15b
leal 0x1(%r13,%r15), %esi
cmovel %r13d, %esi
movq (%rbx), %rdi
andl %r12d, %esi
callq 0x216a8
movzbl %al, %eax
shll $0x8, %eax
movzbl %r14b, %ecx
orl %eax, %ecx
movw %cx, 0xc(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/mindbeast[P]rnes/cpu.cpp
// Function: void Rnes::Cpu::zeroPageYFormat<&Rnes::Cpu::stxInst(unsigned short)>(Rnes::Cpu::Instruction const&)
void Cpu::zeroPageYFormat(const Instruction &ins) {
  uint16_t zeroPageAddr = pc + 1;

  if (debug) {
    int zeroPageLoad = load(zeroPageAddr);
    std::stringstream str;
    str << std::setfill('0') << std::right;
    str << ins.nemonic << " $" << std::hex << std::uppercase << std::setw(2) << zeroPageLoad
        << ",Y";
    instTrace(str.str(), 2);
  }
  pc += 2;
  (this->*fx)((uint16_t)((load(zeroPageAddr) + y)) & 0xff);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
movl 0xc(%rdi), %eax
leal 0x1(%rax), %ecx
addl $0x2, %eax
movw %ax, 0xc(%rdi)
movq (%rdi), %rdi
movzwl %cx, %esi
callq 0x216a8
addb 0xa(%rbx), %al
movzbl 0x9(%rbx), %edx
movq (%rbx), %rdi
movzbl %al, %esi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x215d0
nop
// File: /workspace/github_cpp_makefile_star2_O1/mindbeast[P]rnes/nes.cpp
// Function: Rnes::Controller::setShiftReg()
void Controller::setShiftReg() {
  sdl->parseInput();
  shiftReg = 0;
  shiftReg |= (sdl->getButtonState(Sdl::BUTTON_A) ? 1u : 0u) << 0;
  shiftReg |= (sdl->getButtonState(Sdl::BUTTON_B) ? 1u : 0u) << 1;
  shiftReg |= (sdl->getButtonState(Sdl::BUTTON_SELECT) ? 1u : 0u) << 2;
  shiftReg |= (sdl->getButtonState(Sdl::BUTTON_START) ? 1u : 0u) << 3;
  shiftReg |= (sdl->getButtonState(Sdl::BUTTON_UP) ? 1u : 0u) << 4;
  shiftReg |= (sdl->getButtonState(Sdl::BUTTON_DOWN) ? 1u : 0u) << 5;
  shiftReg |= (sdl->getButtonState(Sdl::BUTTON_LEFT) ? 1u : 0u) << 6;
  shiftReg |= (sdl->getButtonState(Sdl::BUTTON_RIGHT) ? 1u : 0u) << 7;

  if (debug) {
    std::cerr << "shiftReg: " << std::hex << (int)shiftReg << "\n";
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq (%rdi), %rdi
callq 0x22aa6
movb $0x0, 0x9(%rbx)
movq (%rbx), %rdi
movl $0x6, %esi
callq 0x22bce
orb %al, 0x9(%rbx)
movq (%rbx), %rdi
movl $0x7, %esi
callq 0x22bce
addb %al, %al
orb %al, 0x9(%rbx)
movq (%rbx), %rdi
movl $0x5, %esi
callq 0x22bce
shlb $0x2, %al
orb %al, 0x9(%rbx)
movq (%rbx), %rdi
movl $0x4, %esi
callq 0x22bce
shlb $0x3, %al
orb %al, 0x9(%rbx)
movq (%rbx), %rdi
xorl %esi, %esi
callq 0x22bce
shlb $0x4, %al
orb %al, 0x9(%rbx)
movq (%rbx), %rdi
movl $0x1, %esi
callq 0x22bce
shlb $0x5, %al
orb %al, 0x9(%rbx)
movq (%rbx), %rdi
movl $0x2, %esi
callq 0x22bce
shlb $0x6, %al
orb %al, 0x9(%rbx)
movq (%rbx), %rdi
movl $0x3, %esi
callq 0x22bce
shlb $0x7, %al
orb %al, 0x9(%rbx)
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O1/mindbeast[P]rnes/nes.cpp
// Function: Rnes::Controller::read()
uint8_t Controller::read() {
  if (control & 0x1) {
    sdl->parseInput();
    return (sdl->getButtonState(Sdl::BUTTON_A) ? 1u : 0u) << 0;
  } else {
    uint8_t ret = 0;
    ret |= shiftReg & 0x1;
    shiftReg >>= 1;
    shiftReg |= 1u << 7;
    return ret;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
testb $0x1, 0x8(%rdi)
jne 0x21548
movb 0x9(%rbx), %cl
movl %ecx, %eax
andb $0x1, %al
shrb %cl
orb $-0x80, %cl
movb %cl, 0x9(%rbx)
jmp 0x2155d
movq (%rbx), %rdi
callq 0x22aa6
movq (%rbx), %rdi
movl $0x6, %esi
callq 0x22bce
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/mindbeast[P]rnes/nes.cpp
// Function: Rnes::Nes::spriteDmaExecute()
uint32_t Nes::spriteDmaExecute() {
  const uint32_t cyclesPerItr = 2;
  assert(spriteDmaMode);
  cpuMemWrite(ppuRegBase + Ppu::SPR_DATA_REG, cpuMemRead(spriteDmaSourceAddr));
  spriteDmaSourceAddr++;
  spriteDmaCycle += cyclesPerItr;
  if (spriteDmaCycleEnd == spriteDmaCycle) {
    spriteDmaMode = false;
  }
  return cyclesPerItr;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
cmpb $0x0, 0x30(%rdi)
je 0x215b0
movq %rdi, %rbx
movzwl 0x38(%rdi), %esi
callq 0x216a8
movzbl %al, %edx
movq %rbx, %rdi
movl $0x2004, %esi           # imm = 0x2004
callq 0x215d0
incw 0x38(%rbx)
movl 0x34(%rbx), %eax
addl $0x2, %eax
movl %eax, 0x34(%rbx)
cmpl $0x200, %eax            # imm = 0x200
jne 0x215a4
movb $0x0, 0x30(%rbx)
movl $0x2, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
leaq 0x13eba(%rip), %rdi     # 0x35471
leaq 0x13ec1(%rip), %rsi     # 0x3547f
leaq 0x13ec2(%rip), %rcx     # 0x35487
movl $0x83, %edx
callq 0xb160
nop
// File: /workspace/github_cpp_makefile_star2_O1/mindbeast[P]rnes/nes.cpp
// Function: Rnes::Nes::cpuMemWrite(unsigned short, unsigned char)
void Nes::cpuMemWrite(uint16_t addr, uint8_t val) {
  addr = translateCpuWindows(addr);
  if (addr >= ppuRegBase && addr <= ppuRegEnd) {
    ppu->writeReg(addr - ppuRegBase, val);
  } else if (addr == spriteDmaAddr) {
    spriteDmaSetup(val);
  } else if (addr == joypadAddr) {
    pad->write(val);
  } else if (addr >= apuRegBase && addr <= apuRegEnd) {
    apu->writeReg(addr - apuRegBase, val);
  } else {
    cpuMemory->store(addr, val);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
movl %edx, %ebx
leal -0x800(%rsi), %eax
movzwl %ax, %eax
movl %esi, %ecx
andl $0x7ff, %ecx            # imm = 0x7FF
orl $0x800, %ecx            # imm = 0x800
cmpl $0x1800, %eax           # imm = 0x1800
cmovael %esi, %ecx
movl %ecx, %eax
andl $0xe000, %eax           # imm = 0xE000
movl %ecx, %esi
andl $0x2007, %esi           # imm = 0x2007
movl $0x2000, %edx           # imm = 0x2000
cmpl %edx, %eax
cmovnel %ecx, %esi
movl %esi, %eax
andl $-0x8, %eax
cmpl %edx, %eax
jne 0x21630
movq 0x58(%rdi), %rdi
addl $0xffffe000, %esi       # imm = 0xFFFFE000
movzbl %bl, %edx
popq %rbx
popq %r14
popq %rbp
jmp 0x1951a
cmpl $0x4016, %esi           # imm = 0x4016
je 0x21657
cmpl $0x4014, %esi           # imm = 0x4014
jne 0x21679
movb $0x1, 0x30(%rdi)
movl $0x0, 0x34(%rdi)
movzbl %bl, %eax
shll $0x8, %eax
movw %ax, 0x38(%rdi)
jmp 0x21674
movq 0x68(%rdi), %r14
testb $0x1, %bl
jne 0x21670
movb 0x8(%r14), %al
andb $0x1, %al
je 0x21670
movq %r14, %rdi
callq 0x21450
movb %bl, 0x8(%r14)
popq %rbx
popq %r14
popq %rbp
retq
leal -0x4000(%rsi), %eax
cmpw $0x17, %ax
ja 0x21697
movq 0x60(%rdi), %rdi
movzbl %bl, %edx
movl %eax, %esi
popq %rbx
popq %r14
popq %rbp
jmp 0x1a2d6
movq 0x70(%rdi), %rdi
movzbl %bl, %edx
popq %rbx
popq %r14
popq %rbp
jmp 0x23dd4
nop
// File: /workspace/github_cpp_makefile_star2_O1/mindbeast[P]rnes/nes.cpp
// Function: Rnes::Nes::cpuMemRead(unsigned short)
uint8_t Nes::cpuMemRead(uint16_t addr) {
  addr = translateCpuWindows(addr);
  if (addr >= ppuRegBase && addr <= ppuRegEnd) {
    return ppu->readReg(addr - ppuRegBase);
  } else if (addr == joypadAddr) {
    return pad->read();
  } else if (addr >= apuRegBase && addr <= apuRegEnd) {
    return apu->readReg(addr - apuRegBase);
  } else {
    return cpuMemory->load(addr);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
leal -0x800(%rsi), %eax
movzwl %ax, %eax
movl %esi, %ecx
andl $0x7ff, %ecx            # imm = 0x7FF
orl $0x800, %ecx            # imm = 0x800
cmpl $0x1800, %eax           # imm = 0x1800
cmovael %esi, %ecx
movl %ecx, %eax
andl $0xe000, %eax           # imm = 0xE000
movl %ecx, %esi
andl $0x2007, %esi           # imm = 0x2007
movl $0x2000, %edx           # imm = 0x2000
cmpl %edx, %eax
cmovnel %ecx, %esi
movl %esi, %eax
andl $-0x8, %eax
cmpl %edx, %eax
jne 0x216fd
movq 0x58(%rdi), %rdi
addl $0xffffe000, %esi       # imm = 0xFFFFE000
popq %rbp
jmp 0x19680
cmpl $0x4016, %esi           # imm = 0x4016
jne 0x2170f
movq 0x68(%rdi), %rdi
popq %rbp
jmp 0x21528
leal -0x4000(%rsi), %eax
cmpw $0x17, %ax
ja 0x21727
movq 0x60(%rdi), %rdi
movl %eax, %esi
popq %rbp
jmp 0x1a3e6
movq 0x70(%rdi), %rdi
popq %rbp
jmp 0x23d74
nop
// File: /workspace/github_cpp_makefile_star2_O1/mindbeast[P]rnes/nes.cpp
// Function: Rnes::Nes::vidMemWrite(unsigned short, unsigned char)
static uint16_t translatePpuWindows(uint16_t addr) {
  // Name table mirrors.
  if (addr >= 0x3000 && addr < 0x3f00) {
    addr = (addr & (0xf00 - 1)) + 0x2000;
  }
  // ??
  if (addr >= 0x4000) {
    addr = addr - 0x4000;
  }

  // palette mirroring
  if (addr == 0x3f10) {
    addr = 0x3f00;
  } else if (addr == 0x3f14) {
    addr = 0x3f04;
  } else if (addr == 0x3f18) {
    addr = 0x3f08;
  } else if (addr == 0x3f1c) {
    addr = 0x3f0c;
  }
  return addr;
}

// Assembly:
leal -0x3000(%rsi), %ecx
movl $0xffff, %eax           # imm = 0xFFFF
andl %eax, %ecx
movl %esi, %r8d
andl $0x2eff, %r8d           # imm = 0x2EFF
cmpl $0xf00, %ecx            # imm = 0xF00
cmovael %esi, %r8d
leal -0x4000(%r8), %ecx
cmpl $0x4000, %r8d           # imm = 0x4000
cmovbl %r8d, %ecx
andl %ecx, %eax
cmpl $0x3f10, %eax           # imm = 0x3F10
je 0x217a0
cmpl $0x3f18, %eax           # imm = 0x3F18
je 0x2179a
cmpl $0x3f14, %eax           # imm = 0x3F14
jne 0x217a6
movw $0x3f04, %ax            # imm = 0x3F04
jmp 0x217b7
movw $0x3f08, %ax            # imm = 0x3F08
jmp 0x217b7
movw $0x3f00, %ax            # imm = 0x3F00
jmp 0x217b7
movzwl %cx, %ecx
cmpl $0x3f1c, %ecx           # imm = 0x3F1C
movl $0x3f0c, %eax           # imm = 0x3F0C
cmovnel %ecx, %eax
movzwl %ax, %esi
cmpl $0x4000, %esi           # imm = 0x4000
jae 0x217ce
movq 0x78(%rdi), %rdi
movzbl %dl, %edx
jmp 0x24038
pushq %rbp
movq %rsp, %rbp
leaq 0x13cd5(%rip), %rdi     # 0x354ae
leaq 0x13c9f(%rip), %rsi     # 0x3547f
leaq 0x13cde(%rip), %rcx     # 0x354c5
movl $0xb1, %edx
callq 0xb160
nop
// File: /workspace/github_cpp_makefile_star2_O1/mindbeast[P]rnes/nes.cpp
// Function: Rnes::Nes::run()
void Nes::run() {
  uint32_t inputCycles = 1 << 16;
  cpu->reset();
  while (1) {
    uint32_t cpuCycles;
    if (!spriteDmaMode) {
      cpuCycles = cpu->runInst();
    } else {
      cpuCycles = spriteDmaExecute();
    }
    apu->run(cpuCycles);
    ppu->run(cpuCycles);

    cycles += cpuCycles;
    if ((cycles % inputCycles) == 0) {
      sdl->parseInput();

      void loadNesState(Nes * nes, std::string saveFile);
      void saveNesState(Nes * nes, std::string saveFile);
      std::string getGameSaveDir(const std::string & romFile);

      if (sdl->getButtonState(Sdl::BUTTON_SAVE)) {
        saveNesState(this, getGameSaveDir(romFile));
      }
      if (sdl->getButtonState(Sdl::BUTTON_RESTORE)) {
        loadNesState(this, getGameSaveDir(romFile));
      }
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %rbx
movq 0x50(%rdi), %rdi
callq 0x1cc1e
leaq 0x10(%rbx), %r14
leaq -0x68(%rbp), %r15
leaq -0x48(%rbp), %r12
cmpb $0x0, 0x30(%rbx)
je 0x21913
movq %rbx, %rdi
callq 0x21564
movl $0x2, %r13d
jmp 0x2191f
movq 0x50(%rbx), %rdi
callq 0x1cb40
movl %eax, %r13d
movq 0x60(%rbx), %rdi
movl %r13d, %esi
callq 0x1a2b4
movq 0x58(%rbx), %rdi
movl %r13d, %esi
callq 0x19370
movl %r13d, %eax
addq 0x40(%rbx), %rax
movq %rax, 0x40(%rbx)
testw %ax, %ax
jne 0x218fd
movq 0x48(%rbx), %rdi
callq 0x22aa6
movq 0x48(%rbx), %rdi
movl $0x8, %esi
callq 0x22bce
testb %al, %al
je 0x21991
movq %r15, %rdi
movq %r14, %rsi
callq 0x15407
movq %rbx, %rdi
movq %r15, %rsi
callq 0x15bcc
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x21991
movq -0x58(%rbp), %rsi
incq %rsi
callq 0xb0e0
movq 0x48(%rbx), %rdi
movl $0x9, %esi
callq 0x22bce
testb %al, %al
je 0x218fd
movq %r12, %rdi
movq %r14, %rsi
callq 0x15407
movq %rbx, %rdi
movq %r12, %rsi
callq 0x15a2f
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x218fd
movq -0x38(%rbp), %rsi
incq %rsi
callq 0xb0e0
jmp 0x218fd
movq %rax, %rbx
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rcx
movq %rcx, %rax
cmpq %rcx, %rdi
jne 0x21a04
jmp 0x21a0f
movq %rax, %rbx
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x21a0f
movq (%rax), %rsi
incq %rsi
callq 0xb0e0
movq %rbx, %rdi
callq 0xb4d0
nop
// File: /workspace/github_cpp_makefile_star2_O1/mindbeast[P]rnes/nes.cpp
// Function: Rnes::Nes::save(Rnes::SaveState&)
void Nes::save(SaveState &pb) {
  // date??

  // Dma state
  DmaState *dma = pb.mutable_dma();
  dma->set_spritedmamode(spriteDmaMode);
  dma->set_spritedmacycle(spriteDmaCycle);
  dma->set_spritedmasourceaddr(spriteDmaSourceAddr);

  // 6502 state
  cpu->save(*pb.mutable_cpu());

  // Audio state
  apu->save(*pb.mutable_apu());

  // PPU state
  ppu->save(*pb.mutable_ppu());

  // Controller state.
  pad->save(*pb.mutable_controller());

  // SRAM state.
  cpuMemory->save(*pb.mutable_cpumem());
  videoMemory->save(*pb.mutable_vidmem());
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
orb $0x2, 0x10(%rsi)
movq %rdi, %r14
cmpq $0x0, 0x20(%rsi)
jne 0x21a4a
movq 0x8(%rbx), %rdi
testb $0x1, %dil
jne 0x21bcb
callq 0x32386
movq %rax, 0x20(%rbx)
movq 0x20(%rbx), %rax
movb 0x30(%r14), %cl
movl 0x10(%rax), %edx
movl %edx, %esi
orl $0x1, %esi
movl %esi, 0x10(%rax)
movb %cl, 0x18(%rax)
movl 0x34(%r14), %ecx
movl %edx, %esi
orl $0x3, %esi
movl %esi, 0x10(%rax)
movl %ecx, 0x1c(%rax)
movzwl 0x38(%r14), %ecx
orl $0x7, %edx
movl %edx, 0x10(%rax)
movl %ecx, 0x20(%rax)
movq 0x50(%r14), %r15
orl $0x4, 0x10(%rbx)
cmpq $0x0, 0x28(%rbx)
jne 0x21aa3
movq 0x8(%rbx), %rdi
testb $0x1, %dil
jne 0x21bd7
callq 0x31c3c
movq %rax, 0x28(%rbx)
movq 0x28(%rbx), %rsi
movq %r15, %rdi
callq 0x1d0ec
movq 0x60(%r14), %r15
orl $0x8, 0x10(%rbx)
cmpq $0x0, 0x30(%rbx)
jne 0x21ad5
movq 0x8(%rbx), %rdi
testb $0x1, %dil
jne 0x21be3
callq 0x31dec
movq %rax, 0x30(%rbx)
movq 0x30(%rbx), %rsi
movq %r15, %rdi
callq 0x1a44c
movq 0x58(%r14), %r15
orl $0x10, 0x10(%rbx)
cmpq $0x0, 0x38(%rbx)
jne 0x21b07
movq 0x8(%rbx), %rdi
testb $0x1, %dil
jne 0x21bef
callq 0x31ed6
movq %rax, 0x38(%rbx)
movq 0x38(%rbx), %rsi
movq %r15, %rdi
callq 0x18fdc
movq 0x68(%r14), %r15
orl $0x20, 0x10(%rbx)
cmpq $0x0, 0x40(%rbx)
jne 0x21b39
movq 0x8(%rbx), %rdi
testb $0x1, %dil
jne 0x21bfb
callq 0x321d2
movq %rax, 0x40(%rbx)
movq 0x40(%rbx), %rax
movzbl 0x8(%r15), %ecx
movl 0x10(%rax), %edx
movl %edx, %esi
orl $0x1, %esi
movl %esi, 0x10(%rax)
movl %ecx, 0x18(%rax)
movzbl 0x9(%r15), %ecx
orl $0x3, %edx
movl %edx, 0x10(%rax)
movl %ecx, 0x1c(%rax)
movq 0x70(%r14), %r15
orl $0x40, 0x10(%rbx)
cmpq $0x0, 0x48(%rbx)
jne 0x21b84
movq 0x8(%rbx), %rdi
testb $0x1, %dil
jne 0x21c07
callq 0x32234
movq %rax, 0x48(%rbx)
movq 0x48(%rbx), %rsi
movq %r15, %rdi
callq 0x23e4a
movq 0x78(%r14), %r14
orl $0x80, 0x10(%rbx)
cmpq $0x0, 0x50(%rbx)
jne 0x21bb5
movq 0x8(%rbx), %rdi
testb $0x1, %dil
jne 0x21c13
callq 0x32306
movq %rax, 0x50(%rbx)
movq 0x50(%rbx), %rsi
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x2408a
andq $-0x2, %rdi
movq (%rdi), %rdi
jmp 0x21a41
andq $-0x2, %rdi
movq (%rdi), %rdi
jmp 0x21a9a
andq $-0x2, %rdi
movq (%rdi), %rdi
jmp 0x21acc
andq $-0x2, %rdi
movq (%rdi), %rdi
jmp 0x21afe
andq $-0x2, %rdi
movq (%rdi), %rdi
jmp 0x21b30
andq $-0x2, %rdi
movq (%rdi), %rdi
jmp 0x21b7b
andq $-0x2, %rdi
movq (%rdi), %rdi
jmp 0x21bac
// File: /workspace/github_cpp_makefile_star2_O1/mindbeast[P]rnes/nes.cpp
// Function: Rnes::Nes::restore(Rnes::SaveState const&)
void Nes::restore(const SaveState &pb) {
  // date??

  // Dma State
  spriteDmaMode = pb.dma().spritedmamode();
  spriteDmaCycle = pb.dma().spritedmacycle();
  spriteDmaSourceAddr = pb.dma().spritedmasourceaddr();

  // 6502 state.
  cpu->restore(pb.cpu());

  // Audio state.
  apu->restore(pb.apu());

  // PPU state.
  ppu->restore(pb.ppu());

  // Controller state.
  pad->restore(pb.controller());

  // SRAM state.
  cpuMemory->restore(pb.cpumem());
  videoMemory->restore(pb.vidmem());
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
movq %rsi, %rbx
movq %rdi, %r14
movq 0x20(%rsi), %rax
testq %rax, %rax
jne 0x21c39
leaq 0x26edf(%rip), %rax     # 0x48b18
movb 0x18(%rax), %cl
movb %cl, 0x30(%r14)
movl 0x1c(%rax), %ecx
movl %ecx, 0x34(%r14)
movzwl 0x20(%rax), %eax
movw %ax, 0x38(%r14)
movq 0x50(%r14), %rdi
movq 0x28(%rbx), %rsi
testq %rsi, %rsi
jne 0x21c64
leaq 0x26ba4(%rip), %rsi     # 0x48808
callq 0x1d15e
movq 0x60(%r14), %rdi
movq 0x30(%rbx), %rsi
testq %rsi, %rsi
jne 0x21c7d
leaq 0x26c63(%rip), %rsi     # 0x488e0
callq 0x1a684
movq 0x58(%r14), %rdi
movq 0x38(%rbx), %rsi
testq %rsi, %rsi
jne 0x21c96
leaq 0x26ce2(%rip), %rsi     # 0x48978
callq 0x191c8
movq 0x68(%r14), %rax
movq 0x40(%rbx), %rcx
testq %rcx, %rcx
jne 0x21caf
leaq 0x26df1(%rip), %rcx     # 0x48aa0
movb 0x18(%rcx), %dl
movb %dl, 0x8(%rax)
movb 0x1c(%rcx), %cl
movb %cl, 0x9(%rax)
movq 0x70(%r14), %rdi
movq 0x48(%rbx), %rsi
testq %rsi, %rsi
jne 0x21ccf
leaq 0x26df1(%rip), %rsi     # 0x48ac0
callq 0x23f7a
movq 0x78(%r14), %rdi
movq 0x50(%rbx), %rsi
testq %rsi, %rsi
jne 0x21ce8
leaq 0x26e00(%rip), %rsi     # 0x48ae8
popq %rbx
popq %r14
popq %rbp
jmp 0x24246
nop