LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_cpp_makefile_star2_O3/Ciaxur[P]yagb-emu/src/Instructions.cc
// Function: CPU::ADD(unsigned char)
void CPU::ADD(uint8_t u8) {                 // ADD A, u8
  uint8_t result = this->reg.A + u8;

  // Set Flags
  this->setZeroFlag(result == 0);     // Zero Flag
  this->setAddSubFlag(false);   // Unset N Flag
  this->checkHalfCarry(result, this->reg.A);
  this->checkCarry(this->reg.A, result);

  // New A Value
  this->reg.A = result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
movl %esi, %r14d
movq %rdi, %rbx
xorl %esi, %esi
addb 0x118(%rdi), %r14b
sete %sil
callq 0x300ee
movq %rbx, %rdi
xorl %esi, %esi
callq 0x3010a
movzbl 0x118(%rbx), %edx
movzbl %r14b, %r14d
movq %rbx, %rdi
movl %r14d, %esi
callq 0x3015e
movzbl 0x118(%rbx), %esi
movq %rbx, %rdi
movl %r14d, %edx
callq 0x3018c
movb %r14b, 0x118(%rbx)
popq %rbx
popq %r14
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/Ciaxur[P]yagb-emu/src/Instructions.cc
// Function: CPU::AND(unsigned char)
void CPU::AND(uint8_t u8) {                 // AND A, u8
  uint8_t result = this->reg.A & u8;

  // Set Flags
  this->setZeroFlag(result == 0);     // Zero Flag
  this->setAddSubFlag(false);   // Unset N Flag
  this->setHalfCarryFlag(true); // Set H Flag
  this->setCarryFlag(false);    // Unset C Flag

  // New A Value
  this->reg.A = result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
movl %esi, %ebx
movq %rdi, %r14
xorl %esi, %esi
andb 0x118(%rdi), %bl
sete %sil
callq 0x300ee
movq %r14, %rdi
xorl %esi, %esi
callq 0x3010a
movq %r14, %rdi
movl $0x1, %esi
callq 0x30126
movq %r14, %rdi
xorl %esi, %esi
callq 0x30142
movb %bl, 0x118(%r14)
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/Ciaxur[P]yagb-emu/src/Instructions.cc
// Function: CPU::CP(unsigned char)
void CPU::CP(uint8_t u8) {                  // CP A, u8
  uint8_t result = this->reg.A - u8;

  // Set Flags
  this->setZeroFlag(result == 0);     // Zero Flag
  this->setAddSubFlag(true);  // Set N Flag
  this->checkHalfCarry(this->reg.A, result); // Set if borrow from bit 4
  this->checkCarry(u8, this->reg.A); // Set if borrow
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %ebx
movq %rdi, %r14
movb 0x118(%rdi), %r15b
xorl %esi, %esi
subb %bl, %r15b
sete %sil
callq 0x300ee
movq %r14, %rdi
movl $0x1, %esi
callq 0x3010a
movzbl 0x118(%r14), %esi
movzbl %r15b, %edx
movq %r14, %rdi
callq 0x3015e
movzbl 0x118(%r14), %edx
movq %r14, %rdi
movl %ebx, %esi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x3018c
nop
// File: /workspace/github_cpp_makefile_star2_O3/Ciaxur[P]yagb-emu/src/Instructions.cc
// Function: CPU::DEC(unsigned char*)
void CPU::DEC(uint8_t *r8) {                // DEC r8
  uint8_t result = *r8 - 1;

  // Set Flags
  this->setZeroFlag(result == 0);   // Zero Flag
  this->setAddSubFlag(true);  // Set N Flag
  this->checkHalfCarry(*r8, result); // Set if borrow from bit 4

  // New r8 value
  *r8 = result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
movb (%rsi), %r15b
xorl %esi, %esi
decb %r15b
sete %sil
callq 0x300ee
movq %r14, %rdi
movl $0x1, %esi
callq 0x3010a
movzbl (%rbx), %esi
movzbl %r15b, %r15d
movq %r14, %rdi
movl %r15d, %edx
callq 0x3015e
movb %r15b, (%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/Ciaxur[P]yagb-emu/src/Instructions.cc
// Function: CPU::DEC(unsigned short)
void CPU::DEC(uint16_t a16) {               // DEC [HL]
  uint8_t result = this->memory.read(a16) - 1;

  // Set Flags
  this->setZeroFlag(result == 0);   // Zero Flag
  this->setAddSubFlag(true);  // Set N Flag
  this->checkHalfCarry(this->memory.read(a16), result); // Set if borrow from bit 4

  this->memory.write(a16, result);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %esi, %ebx
movq %rdi, %r15
leaq 0x130(%rdi), %r14
movq %r14, %rdi
callq 0x3c974
movl %eax, %r12d
xorl %esi, %esi
decb %r12b
sete %sil
movq %r15, %rdi
callq 0x300ee
movq %r15, %rdi
movl $0x1, %esi
callq 0x3010a
movq %r14, %rdi
movl %ebx, %esi
callq 0x3c974
movzbl %r12b, %r12d
movzbl %al, %esi
movq %r15, %rdi
movl %r12d, %edx
callq 0x3015e
movq %r14, %rdi
movl %ebx, %esi
movl %r12d, %edx
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x3c980
nop
// File: /workspace/github_cpp_makefile_star2_O3/Ciaxur[P]yagb-emu/src/Instructions.cc
// Function: CPU::INC(unsigned char*)
void CPU::INC(uint8_t *r8) {                // INC r8
  uint8_t result = *r8 + 1;

  // Set Flags
  this->setZeroFlag(result == 0);   // Zero Flag
  this->setAddSubFlag(false);       // Unset N Flag
  this->checkHalfCarry(*r8, result);     // Set if overflow from bit 3

  // New r8 value
  *r8 = result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
movb (%rsi), %r15b
xorl %esi, %esi
incb %r15b
sete %sil
callq 0x300ee
movq %r14, %rdi
xorl %esi, %esi
callq 0x3010a
movzbl (%rbx), %esi
movzbl %r15b, %r15d
movq %r14, %rdi
movl %r15d, %edx
callq 0x3015e
movb %r15b, (%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/Ciaxur[P]yagb-emu/src/Instructions.cc
// Function: CPU::OR(unsigned char)
void CPU::OR(uint8_t u8) {                  // OR A, u8
  uint8_t result = this->reg.A | u8;

  // Set Flags
  this->reg.F = 0x00;                // Reset Flags
  this->setZeroFlag(result == 0);     // Zero Flag

  this->reg.A = result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
movl %esi, %ebx
movq %rdi, %r14
movb $0x0, 0x11d(%rdi)
xorl %esi, %esi
orb 0x118(%rdi), %bl
sete %sil
callq 0x300ee
movb %bl, 0x118(%r14)
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/Ciaxur[P]yagb-emu/src/Instructions.cc
// Function: CPU::SBC(unsigned char)
void CPU::SBC(uint8_t u8) {                 // SBC A, u8
  uint8_t result = this->reg.A - u8 - ((this->reg.F & 0x10) >> 4);

  // Set Flags
  this->setZeroFlag(result == 0);     // Zero Flag
  this->setAddSubFlag(true);  // Set N Flag
  this->checkHalfCarry(this->reg.A, result);
  this->checkCarry(u8 + ((this->reg.F & 0x10) >> 4), this->reg.A);  // Check Carry for Subtraction

  this->reg.A = result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %r14d
movq %rdi, %rbx
movzbl 0x11d(%rdi), %eax
btl $0x4, %eax
movl %r14d, %eax
adcb $0x0, %al
movb 0x118(%rdi), %r15b
xorl %esi, %esi
subb %al, %r15b
sete %sil
callq 0x300ee
movq %rbx, %rdi
movl $0x1, %esi
callq 0x3010a
movzbl 0x118(%rbx), %esi
movzbl %r15b, %r15d
movq %rbx, %rdi
movl %r15d, %edx
callq 0x3015e
movzbl 0x11d(%rbx), %eax
btl $0x4, %eax
adcb $0x0, %r14b
movzbl 0x118(%rbx), %edx
movzbl %r14b, %esi
movq %rbx, %rdi
callq 0x3018c
movb %r15b, 0x118(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/Ciaxur[P]yagb-emu/src/Instructions.cc
// Function: CPU::SUB(unsigned char)
void CPU::SUB(uint8_t u8) {                 // SUB A, u8
  uint8_t result = this->reg.A - u8;

  // Set Flags
  this->setZeroFlag(result == 0);      // Zero Flag
  this->setAddSubFlag(true);  // Set N Flag
  this->checkHalfCarry(this->reg.A, result);
  this->checkCarry(u8, this->reg.A);  // Check Carry for Subtraction

  this->reg.A = result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %r14d
movq %rdi, %rbx
movb 0x118(%rdi), %r15b
xorl %esi, %esi
subb %r14b, %r15b
sete %sil
callq 0x300ee
movq %rbx, %rdi
movl $0x1, %esi
callq 0x3010a
movzbl 0x118(%rbx), %esi
movzbl %r15b, %r15d
movq %rbx, %rdi
movl %r15d, %edx
callq 0x3015e
movzbl 0x118(%rbx), %edx
movq %rbx, %rdi
movl %r14d, %esi
callq 0x3018c
movb %r15b, 0x118(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/Ciaxur[P]yagb-emu/src/Instructions.cc
// Function: CPU::ADDHL(unsigned short)
void CPU::ADDHL(uint16_t r16) {             // ADD HL, r16
  uint16_t HL = (this->reg.H << 8) | this->reg.L;
  uint16_t result = HL + r16;

  // Set Flags
  this->setAddSubFlag(false);  // Unset N Flag
  this->checkHalfCarry(HL >> 8, result >> 8);
  this->checkCarry_16(HL, HL + r16);

  this->reg.H = result >> 8;
  this->reg.L = result & 0xFF;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movzbl 0x11e(%rdi), %r14d
movl %r14d, %eax
shll $0x8, %eax
movzbl 0x11f(%rdi), %r15d
orl %eax, %r15d
leal (%rsi,%r15), %r13d
xorl %esi, %esi
callq 0x3010a
movl %r13d, %r12d
andl $0xffff, %r12d          # imm = 0xFFFF
movl %r12d, %edx
shrl $0x8, %edx
movq %rbx, %rdi
movl %r14d, %esi
callq 0x3015e
movq %rbx, %rdi
movl %r15d, %esi
movl %r12d, %edx
callq 0x301ac
rolw $0x8, %r13w
movw %r13w, 0x11e(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/Ciaxur[P]yagb-emu/src/Instructions.cc
// Function: CPU::BIT(unsigned char, unsigned char*)
void CPU::BIT(uint8_t u3, uint8_t *r8) {     // BIT u3, r8
  // Check bit at u3 in r8's Bytes
  // Shift byte to u3 Bit to check if R8 Bit is set
  if ( ((1 << u3) & *r8) == 0 ) {
    this->setZeroFlag(true);
  }
  this->setAddSubFlag(false);
  this->setHalfCarryFlag(true);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
movzbl (%rdx), %eax
btl %esi, %eax
jb 0x3b4e6
movq %rbx, %rdi
movl $0x1, %esi
callq 0x300ee
movq %rbx, %rdi
xorl %esi, %esi
callq 0x3010a
movq %rbx, %rdi
movl $0x1, %esi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x30126
nop
// File: /workspace/github_cpp_makefile_star2_O3/Ciaxur[P]yagb-emu/src/Instructions.cc
// Function: CPU::BIT(unsigned char, unsigned short)
void CPU::BIT(uint8_t u3, uint16_t a16) {    // BIT u3, [HL]
  uint8_t value = this->memory.read(a16);
  this->BIT(u3, &value);
  this->memory.write(a16, value);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edx, %ebx
movl %esi, %r14d
movq %rdi, %r15
leaq 0x130(%rdi), %r12
movq %r12, %rdi
movl %edx, %esi
callq 0x3c974
movl %eax, %r13d
leaq -0x29(%rbp), %rdx
movb %al, (%rdx)
movq %r15, %rdi
movl %r14d, %esi
callq 0x3b4c8
movzbl %r13b, %edx
movq %r12, %rdi
movl %ebx, %esi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3c980
nop
// File: /workspace/github_cpp_makefile_star2_O3/Ciaxur[P]yagb-emu/src/Instructions.cc
// Function: CPU::RES(unsigned char, unsigned short)
void CPU::RES(uint8_t u3, uint16_t a16) {    // RES u3, [HL]
  uint8_t value = this->memory.read(a16);
  this->RES(u3, &value);
  this->memory.write(a16, value);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %edx, %ebx
movl %esi, %r14d
movq %rdi, %r15
addq $0x130, %r15            # imm = 0x130
movq %r15, %rdi
movl %edx, %esi
callq 0x3c974
movl $0x1, %edx
movl %r14d, %ecx
shll %cl, %edx
notb %dl
andb %al, %dl
movzbl %dl, %edx
movq %r15, %rdi
movl %ebx, %esi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x3c980
// File: /workspace/github_cpp_makefile_star2_O3/Ciaxur[P]yagb-emu/src/Instructions.cc
// Function: CPU::SWAP(unsigned char*)
void CPU::SWAP(uint8_t *r8) {               // SWAP r8
  uint8_t L = *r8 >> 4;
  uint8_t R = *r8 << 4;
  uint8_t result = L | R;

  // Set Flags
  this->setZeroFlag(result == 0);     // Zero Flag
  this->setAddSubFlag(false);     // Unset N Flag
  this->setHalfCarryFlag(false);  // Unset Half Carry Flag
  this->setCarryFlag(false);      // Unset Carry Flag
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
xorl %eax, %eax
cmpb $0x0, (%rsi)
sete %al
movl %eax, %esi
callq 0x300ee
movq %rbx, %rdi
xorl %esi, %esi
callq 0x3010a
movq %rbx, %rdi
xorl %esi, %esi
callq 0x30126
movq %rbx, %rdi
xorl %esi, %esi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x30142
// File: /workspace/github_cpp_makefile_star2_O3/Ciaxur[P]yagb-emu/src/Instructions.cc
// Function: CPU::SWAP(unsigned short)
void CPU::SWAP(uint16_t a16) {             // SWAP [HL]
  uint8_t value = this->memory.read(a16);
  this->SWAP(&value);
  this->memory.write(a16, value);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movl %esi, %ebx
movq %rdi, %r14
leaq 0x130(%rdi), %r15
movq %r15, %rdi
callq 0x3c974
movl %eax, %r12d
leaq -0x21(%rbp), %rsi
movb %al, (%rsi)
movq %r14, %rdi
callq 0x3b610
movzbl %r12b, %edx
movq %r15, %rdi
movl %ebx, %esi
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x3c980
// File: /workspace/github_cpp_makefile_star2_O3/Ciaxur[P]yagb-emu/src/Instructions.cc
// Function: CPU::RL(unsigned char*)
void CPU::RL(uint8_t *r8) {                // RL r8
  uint8_t carry = (this->reg.F & 0x10) << 3;

  // Set Carry flag according to 7th Bit
  this->setCarryFlag((*r8 & 0x80) != 0);

  *r8 = (*r8 << 1) | carry;  // Set right most bit

  // Set Flags
  if (*r8 == 0)
    this->setZeroFlag(true);
  this->setAddSubFlag(false);
  this->setHalfCarryFlag(false);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
movb 0x11d(%rdi), %r15b
shlb $0x3, %r15b
andb $-0x80, %r15b
movb (%rsi), %al
shrb $0x7, %al
movzbl %al, %esi
callq 0x30142
movb (%r14), %al
addb %al, %al
orb %r15b, %al
movb %al, (%r14)
jne 0x3b6e0
movq %rbx, %rdi
movl $0x1, %esi
callq 0x300ee
movq %rbx, %rdi
xorl %esi, %esi
callq 0x3010a
movq %rbx, %rdi
xorl %esi, %esi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x30126
// File: /workspace/github_cpp_makefile_star2_O3/Ciaxur[P]yagb-emu/src/Instructions.cc
// Function: CPU::RL(unsigned short)
void CPU::RL(uint16_t a16) {               // RL [HL]
  uint8_t value = this->memory.read(a16);
  this->RL(&value);
  this->memory.write(a16, value);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movl %esi, %ebx
movq %rdi, %r14
leaq 0x130(%rdi), %r15
movq %r15, %rdi
callq 0x3c974
leaq -0x21(%rbp), %r12
movb %al, (%r12)
movq %r14, %rdi
movq %r12, %rsi
callq 0x3b69a
movzbl (%r12), %edx
movq %r15, %rdi
movl %ebx, %esi
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x3c980
nop
// File: /workspace/github_cpp_makefile_star2_O3/Ciaxur[P]yagb-emu/src/Instructions.cc
// Function: CPU::RLC(unsigned char*)
void CPU::RLC(uint8_t *r8) {               // RLC r8
  // Set Carry flag according to 7th Bit
  this->setCarryFlag((*r8 & 0x80) != 0);

  // Carry 7th Bit over
  *r8 = (*r8 << 1) | ((this->reg.F & 0x10) >> 4);

  // Set Flags
  if (*r8 == 0)
    this->setZeroFlag(true);
  this->setAddSubFlag(false);
  this->setHalfCarryFlag(false);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
movq %rsi, %r14
movq %rdi, %rbx
movb (%rsi), %al
shrb $0x7, %al
movzbl %al, %esi
callq 0x30142
movb (%r14), %al
addb %al, %al
movb 0x11d(%rbx), %cl
shrb $0x4, %cl
andb $0x1, %cl
orb %al, %cl
movb %cl, (%r14)
jne 0x3b7b5
movq %rbx, %rdi
movl $0x1, %esi
callq 0x300ee
movq %rbx, %rdi
xorl %esi, %esi
callq 0x3010a
movq %rbx, %rdi
xorl %esi, %esi
popq %rbx
popq %r14
popq %rbp
jmp 0x30126
nop
// File: /workspace/github_cpp_makefile_star2_O3/Ciaxur[P]yagb-emu/src/Instructions.cc
// Function: CPU::RR(unsigned char*)
void CPU::RR(uint8_t *r8) {                // RR r8
  uint8_t carry = (this->reg.F & 0x10) << 3; // Set to Top Bit

  // Set Carry flag according to 7th Bit
  this->setCarryFlag((*r8 & 0x01) != 0);

  *r8 = (*r8 >> 1) | carry;  // Set left most bit

  // Set Flags
  if (*r8 == 0)
    this->setZeroFlag(true);
  this->setAddSubFlag(false);
  this->setHalfCarryFlag(false);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
movb 0x11d(%rdi), %r15b
shlb $0x3, %r15b
andb $-0x80, %r15b
movzbl (%rsi), %esi
andl $0x1, %esi
callq 0x30142
movb (%r14), %al
shrb %al
orb %r15b, %al
movb %al, (%r14)
jne 0x3b88a
movq %rbx, %rdi
movl $0x1, %esi
callq 0x300ee
movq %rbx, %rdi
xorl %esi, %esi
callq 0x3010a
movq %rbx, %rdi
xorl %esi, %esi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x30126
// File: /workspace/github_cpp_makefile_star2_O3/Ciaxur[P]yagb-emu/src/Instructions.cc
// Function: CPU::RRC(unsigned char*)
void CPU::RRC(uint8_t *r8) {                // RRC r8
  // Set Carry flag according to 7th Bit
  this->setCarryFlag((*r8 & 0x01) != 0);

  // Carry 7th Bit over
  *r8 = (*r8 >> 1) | ((this->reg.F & 0x10) << 3);

  // Set Flags
  if (*r8 == 0)
    this->setZeroFlag(true);
  this->setAddSubFlag(false);
  this->setHalfCarryFlag(false);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
movq %rsi, %r14
movq %rdi, %rbx
movzbl (%rsi), %esi
andl $0x1, %esi
callq 0x30142
movb (%r14), %al
shrb %al
movb 0x11d(%rbx), %cl
shlb $0x3, %cl
andb $-0x80, %cl
orb %al, %cl
movb %cl, (%r14)
jne 0x3b95d
movq %rbx, %rdi
movl $0x1, %esi
callq 0x300ee
movq %rbx, %rdi
xorl %esi, %esi
callq 0x3010a
movq %rbx, %rdi
xorl %esi, %esi
popq %rbx
popq %r14
popq %rbp
jmp 0x30126
nop
// File: /workspace/github_cpp_makefile_star2_O3/Ciaxur[P]yagb-emu/src/Instructions.cc
// Function: CPU::SLA(unsigned char*)
void CPU::SLA(uint8_t *r8) {               // SLA r8
  // Set Carry from Left Shift
  this->setCarryFlag((*r8 & 0x80) != 0);

  // Shift Left
  *r8 = *r8 << 1;

  // Set Flags
  if (*r8 == 0)
    this->setZeroFlag(true);
  this->setAddSubFlag(false);
  this->setHalfCarryFlag(false);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
movq %rsi, %r14
movq %rdi, %rbx
movb (%rsi), %al
shrb $0x7, %al
movzbl %al, %esi
callq 0x30142
movb (%r14), %al
addb %al, %al
movb %al, (%r14)
jne 0x3ba1f
movq %rbx, %rdi
movl $0x1, %esi
callq 0x300ee
movq %rbx, %rdi
xorl %esi, %esi
callq 0x3010a
movq %rbx, %rdi
xorl %esi, %esi
popq %rbx
popq %r14
popq %rbp
jmp 0x30126
nop
// File: /workspace/github_cpp_makefile_star2_O3/Ciaxur[P]yagb-emu/src/Instructions.cc
// Function: CPU::SRA(unsigned char*)
void CPU::SRA(uint8_t *r8) {               // SRA r8
  // Set Carry from Right Shift
  this->setCarryFlag((*r8 & 0x01) != 0);

  // Shift Arithmetic Right
  uint8_t topBit = *r8 & 0x80;
  *r8 = topBit | (*r8 >> 1);

  // Set Flags
  if (*r8 == 0)
    this->setZeroFlag(true);
  this->setAddSubFlag(false);
  this->setHalfCarryFlag(false);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
movq %rsi, %r14
movq %rdi, %rbx
movzbl (%rsi), %esi
andl $0x1, %esi
callq 0x30142
movb (%r14), %al
movl %eax, %ecx
andb $-0x80, %cl
shrb %al
orb %cl, %al
movb %al, (%r14)
jne 0x3bac0
movq %rbx, %rdi
movl $0x1, %esi
callq 0x300ee
movq %rbx, %rdi
xorl %esi, %esi
callq 0x3010a
movq %rbx, %rdi
xorl %esi, %esi
popq %rbx
popq %r14
popq %rbp
jmp 0x30126
// File: /workspace/github_cpp_makefile_star2_O3/Ciaxur[P]yagb-emu/src/Instructions.cc
// Function: CPU::SRL(unsigned char*)
void CPU::SRL(uint8_t *r8) {                // SRL r8
  // Set Carry from Right Shift
  this->setCarryFlag((*r8 & 0x01) != 0);

  // Shift Logic Right
  *r8 = *r8 >> 1;

  // Set Flags
  if (*r8 == 0)
    this->setZeroFlag(true);
  this->setAddSubFlag(false);
  this->setHalfCarryFlag(false);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
movq %rsi, %r14
movq %rdi, %rbx
movzbl (%rsi), %esi
andl $0x1, %esi
callq 0x30142
movb (%r14), %al
movl %eax, %ecx
shrb %cl
movb %cl, (%r14)
cmpb $0x1, %al
ja 0x3bb5d
movq %rbx, %rdi
movl $0x1, %esi
callq 0x300ee
movq %rbx, %rdi
xorl %esi, %esi
callq 0x3010a
movq %rbx, %rdi
xorl %esi, %esi
popq %rbx
popq %r14
popq %rbp
jmp 0x30126
nop
// File: /workspace/github_cpp_makefile_star2_O3/Ciaxur[P]yagb-emu/src/Instructions.cc
// Function: CPU::LDHLI()
void CPU::LDHLI() {            // LD [HLI], A
  uint16_t HL = (this->reg.H << 8) | this->reg.L;

  this->memory.write(HL, this->reg.A);
  HL++;

  this->reg.H = HL >> 8;
  this->reg.L = HL & 0xFF;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
movq %rdi, %rbx
movzwl 0x11e(%rdi), %r14d
rolw $0x8, %r14w
addq $0x130, %rdi            # imm = 0x130
movzbl 0x118(%rbx), %edx
movzwl %r14w, %esi
callq 0x3c980
leal 0x1(%r14), %eax
rolw $0x8, %ax
movw %ax, 0x11e(%rbx)
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/Ciaxur[P]yagb-emu/src/Instructions.cc
// Function: CPU::LDHLD()
void CPU::LDHLD() {                         // LD [HLD], A
  uint16_t HL = (this->reg.H << 8) | this->reg.L;

  this->memory.write(HL, this->reg.A);
  HL--;

  this->reg.H = HL >> 8;
  this->reg.L = HL & 0xFF;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
movq %rdi, %rbx
movzwl 0x11e(%rdi), %r14d
rolw $0x8, %r14w
addq $0x130, %rdi            # imm = 0x130
movzbl 0x118(%rbx), %edx
movzwl %r14w, %esi
callq 0x3c980
leal -0x1(%r14), %eax
rolw $0x8, %ax
movw %ax, 0x11e(%rbx)
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/Ciaxur[P]yagb-emu/src/Instructions.cc
// Function: CPU::CALL(unsigned short)
void CPU::CALL(uint16_t u16) {                  // CALL, u16
  // Push Address to Stack
  uint16_t offsetAddr = this->PC + 0x03;        // Offset from CALL
  this->PUSH(&offsetAddr);

  // JP to address
  this->PC = u16 - 0x03;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x10, %rsp
movl %esi, %ebx
movq %rdi, %r14
movl 0x12c(%rdi), %eax
addl $0x3, %eax
leaq -0x12(%rbp), %rsi
movw %ax, (%rsi)
callq 0x3bda6
addl $-0x3, %ebx
movw %bx, 0x12c(%r14)
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/Ciaxur[P]yagb-emu/src/Instructions.cc
// Function: CPU::CALL(ConditionCode, unsigned short)
void CPU::CALL(ConditionCode cc, uint16_t a16) {   // CALL cc, u16
  this->extraCycles = 3;

  switch (cc) {
    case Z:
      if ((this->reg.F & 0x80) != 0)
        return this->CALL(a16);
      break;
    case NZ:
      if ((this->reg.F & 0x80) == 0)
        return this->CALL(a16);
      break;
    case C:
      if ((this->reg.F & 0x10) != 0)
        return this->CALL(a16);
      break;
    case NC:
      if ((this->reg.F & 0x10) == 0)
        return this->CALL(a16);
      break;
  }

  this->extraCycles = 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rdi, %r14
movl $0x3, 0xc(%rdi)
cmpl $0x3, %esi
ja 0x3bebc
movl %edx, %ebx
movl %esi, %eax
leaq 0x7905f(%rip), %rcx     # 0xb4e94
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpb $0x0, 0x11d(%r14)
jns 0x3bebc
movl 0x12c(%r14), %eax
addl $0x3, %eax
leaq -0x12(%rbp), %rsi
jmp 0x3bea4
testb $0x10, 0x11d(%r14)
je 0x3bebc
movl 0x12c(%r14), %eax
addl $0x3, %eax
leaq -0x16(%rbp), %rsi
jmp 0x3bea4
testb $0x10, 0x11d(%r14)
jne 0x3bebc
movl 0x12c(%r14), %eax
addl $0x3, %eax
leaq -0x18(%rbp), %rsi
jmp 0x3bea4
cmpb $0x0, 0x11d(%r14)
js 0x3bebc
movl 0x12c(%r14), %eax
addl $0x3, %eax
leaq -0x14(%rbp), %rsi
movw %ax, (%rsi)
movq %r14, %rdi
callq 0x3bda6
addl $-0x3, %ebx
movw %bx, 0x12c(%r14)
jmp 0x3bec4
movl $0x0, 0xc(%r14)
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/Ciaxur[P]yagb-emu/src/Instructions.cc
// Function: CPU::JP(ConditionCode, unsigned short)
void CPU::JP(ConditionCode cc, uint16_t a16) {  // JP cc, u16
  this->extraCycles = 1;

  switch (cc) {
    case Z:
      if ((this->reg.F & 0x80) != 0)
        return this->JP(a16);
      break;
    case NZ:
      if ((this->reg.F & 0x80) == 0)
        return this->JP(a16);
      break;
    case C:
      if ((this->reg.F & 0x10) != 0)
        return this->JP(a16);
      break;
    case NC:
      if ((this->reg.F & 0x10) == 0)
        return this->JP(a16);
      break;
  }

  this->extraCycles = 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movl $0x1, 0xc(%rdi)
cmpl $0x3, %esi
ja 0x3bf19
movl %esi, %eax
leaq 0x78f9d(%rip), %rcx     # 0xb4ea4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpb $0x0, 0x11d(%rdi)
js 0x3bf41
movl $0x0, 0xc(%rdi)
jmp 0x3bf4b
testb $0x10, 0x11d(%rdi)
je 0x3bf19
jmp 0x3bf41
testb $0x10, 0x11d(%rdi)
jne 0x3bf19
jmp 0x3bf41
cmpb $0x0, 0x11d(%rdi)
js 0x3bf19
addl $-0x3, %edx
movw %dx, 0x12c(%rdi)
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/Ciaxur[P]yagb-emu/src/Instructions.cc
// Function: CPU::JR(ConditionCode, signed char)
void CPU::JR(ConditionCode cc, int8_t e8) {     // JR cc, e8
  this->extraCycles = 1;

  switch (cc) {
    case Z:
      if ((this->reg.F & 0x80) != 0)
        return this->JR(e8);
      break;
    case NZ:
      if ((this->reg.F & 0x80) == 0)
        return this->JR(e8);
      break;
    case C:
      if ((this->reg.F & 0x10) != 0)
        return this->JR(e8);
      break;
    case NC:
      if ((this->reg.F & 0x10) == 0)
        return this->JR(e8);
      break;
  }

  this->extraCycles = 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movl $0x1, 0xc(%rdi)
cmpl $0x3, %esi
ja 0x3bf87
movl %esi, %eax
leaq 0x78f3f(%rip), %rcx     # 0xb4eb4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpb $0x0, 0x11d(%rdi)
js 0x3bfaf
movl $0x0, 0xc(%rdi)
jmp 0x3bfb9
testb $0x10, 0x11d(%rdi)
je 0x3bf87
jmp 0x3bfaf
testb $0x10, 0x11d(%rdi)
jne 0x3bf87
jmp 0x3bfaf
cmpb $0x0, 0x11d(%rdi)
js 0x3bf87
movsbl %dl, %eax
addw %ax, 0x12c(%rdi)
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/Ciaxur[P]yagb-emu/src/Instructions.cc
// Function: CPU::RET(ConditionCode)
void CPU::RET(ConditionCode cc) {                 // RET cc
  this->extraCycles = 3;

  switch (cc) {
    case Z:
      if ((this->reg.F & 0x80) != 0)
        return this->RET();
      break;
    case NZ:
      if ((this->reg.F & 0x80) == 0)
        return this->RET();
      break;
    case C:
      if ((this->reg.F & 0x10) != 0)
        return this->RET();
      break;
    case NC:
      if ((this->reg.F & 0x10) == 0)
        return this->RET();
      break;
  }

  this->extraCycles = 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
movl $0x3, 0xc(%rdi)
cmpl $0x3, %esi
ja 0x3bfec
movl %esi, %eax
leaq 0x78eea(%rip), %rcx     # 0xb4ec4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpb $0x0, 0x11d(%rbx)
js 0x3c014
movl $0x0, 0xc(%rbx)
jmp 0x3c02a
testb $0x10, 0x11d(%rbx)
je 0x3bfec
jmp 0x3c014
testb $0x10, 0x11d(%rbx)
jne 0x3bfec
jmp 0x3c014
cmpb $0x0, 0x11d(%rbx)
js 0x3bfec
leaq 0x12c(%rbx), %rsi
movq %rbx, %rdi
callq 0x3c056
decw 0x12c(%rbx)
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/Ciaxur[P]yagb-emu/src/Instructions.cc
// Function: CPU::ADDSP(signed char)
void CPU::ADDSP(int8_t e8) {                     // ADD SP, e8
  uint16_t result = this->SP + e8;

  // Set Flags
  this->setZeroFlag(false);
  this->setAddSubFlag(false);
  this->checkHalfCarry(this->SP >> 8, result >> 8);
  this->checkCarry_16(SP, SP + e8);

  this->SP = result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %r14d
movq %rdi, %rbx
movzwl 0x12e(%rdi), %eax
addw %r14w, %ax
movzwl %ax, %r15d
xorl %esi, %esi
callq 0x300ee
movq %rbx, %rdi
xorl %esi, %esi
callq 0x3010a
movzbl 0x12f(%rbx), %esi
movl %r15d, %edx
shrl $0x8, %edx
movq %rbx, %rdi
callq 0x3015e
movzwl 0x12e(%rbx), %esi
addl %esi, %r14d
movzwl %r14w, %edx
movq %rbx, %rdi
callq 0x301ac
movw %r15w, 0x12e(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/Ciaxur[P]yagb-emu/src/Instructions.cc
// Function: CPU::LDHL(signed char)
void CPU::LDHL(int8_t e8) {                      // LD HL, SP+e8
  uint16_t result = this->SP + e8;

  // Set Flags
  this->setZeroFlag(false);
  this->setAddSubFlag(false);
  this->checkHalfCarry(this->SP >> 8, result >> 8);
  this->checkCarry_16(SP, SP + e8);

  // Store into HL
  this->reg.H = this->SP << 8;
  this->reg.L = this->SP & 0xFF;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %r14d
movq %rdi, %rbx
movzwl 0x12e(%rdi), %eax
addw %r14w, %ax
movzwl %ax, %r15d
xorl %esi, %esi
callq 0x300ee
movq %rbx, %rdi
xorl %esi, %esi
callq 0x3010a
movzbl 0x12f(%rbx), %esi
shrl $0x8, %r15d
movq %rbx, %rdi
movl %r15d, %edx
callq 0x3015e
movzwl 0x12e(%rbx), %esi
addl %esi, %r14d
movzwl %r14w, %edx
movq %rbx, %rdi
callq 0x301ac
movb $0x0, 0x11e(%rbx)
movb 0x12e(%rbx), %al
movb %al, 0x11f(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/Ciaxur[P]yagb-emu/src/Instructions.cc
// Function: CPU::CCF()
void CPU::CCF() {                                // CCF
  // Set Flags
  this->setAddSubFlag(false);
  this->setHalfCarryFlag(false);
  this->reg.F ^= 0x10;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
xorl %esi, %esi
callq 0x3010a
movq %rbx, %rdi
xorl %esi, %esi
callq 0x30126
xorb $0x10, 0x11d(%rbx)
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/Ciaxur[P]yagb-emu/src/Instructions.cc
// Function: CPU::CPL()
void CPU::CPL() {                                // CPL
  this->reg.A = ~this->reg.A;

  // Set Flags
  this->setZeroFlag(false);
  this->setHalfCarryFlag(false);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
notb 0x118(%rdi)
xorl %esi, %esi
callq 0x300ee
movq %rbx, %rdi
xorl %esi, %esi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x30126
// File: /workspace/github_cpp_makefile_star2_O3/Ciaxur[P]yagb-emu/src/Instructions.cc
// Function: CPU::DAA()
void CPU::DAA() {                                // DAA
  uint8_t A = this->reg.A;
  bool isAddedSix = false;

  // Addition
  if (!(this->reg.F & 0x40)) {
    if (this->reg.F & 0x20 || (A & 0x0F) > 0x09) {
      A += 0x06;
      isAddedSix = true;
    }
    if (this->reg.F & 0x10 || A > 0x9F || isAddedSix && A < 0x06) { // PATCHED END: If overflow from prev A
      A += 0x60;
      this->setCarryFlag(true);
    }
  }
  
  // Subtraction
  else {
    if (this->reg.F & 0x20) {
      A -= 0x06;
    }
    if (this->reg.F & 0x10) {
      A -= 0x60;
    }
  }

  this->setZeroFlag(A == 0);
  this->setHalfCarryFlag(false);

  // Set the Value
  this->reg.A = A;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
movq %rdi, %rbx
movb 0x118(%rdi), %cl
movzbl 0x11d(%rdi), %eax
testb $0x40, %al
jne 0x3c4b1
movl %eax, %esi
andl $0x20, %esi
shrl $0x5, %esi
movl %ecx, %edx
andb $0xe, %dl
cmpb $0xa, %dl
setae %dl
orb %sil, %dl
movzbl %cl, %esi
addb $0x6, %cl
movzbl %cl, %r14d
testb %dl, %dl
cmovel %esi, %r14d
cmpb $0x6, %r14b
setb %cl
testb $0x10, %al
jne 0x3c49e
cmpb $-0x61, %r14b
ja 0x3c49e
andb %cl, %dl
je 0x3c4cc
addb $0x60, %r14b
movq %rbx, %rdi
movl $0x1, %esi
callq 0x30142
jmp 0x3c4cc
leal -0x6(%rcx), %edx
testb $0x20, %al
movzbl %cl, %ecx
movzbl %dl, %edx
cmovel %ecx, %edx
leal -0x60(%rdx), %ecx
testb $0x10, %al
movzbl %cl, %r14d
cmovel %edx, %r14d
xorl %esi, %esi
testb %r14b, %r14b
sete %sil
movq %rbx, %rdi
callq 0x300ee
movq %rbx, %rdi
xorl %esi, %esi
callq 0x30126
movb %r14b, 0x118(%rbx)
popq %rbx
popq %r14
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/Ciaxur[P]yagb-emu/src/Instructions.cc
// Function: CPU::SCF()
void CPU::SCF() {                                // SCF
  // Set Flags
  this->setAddSubFlag(false);
  this->setHalfCarryFlag(false);
  this->setCarryFlag(true);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
xorl %esi, %esi
callq 0x3010a
movq %rbx, %rdi
xorl %esi, %esi
callq 0x30126
movq %rbx, %rdi
movl $0x1, %esi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x30142
nop
// File: /workspace/github_cpp_makefile_star2_O3/Ciaxur[P]yagb-emu/src/Memory.cc
// Function: Memory::Memory(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
Memory::Memory(std::string ROMPath) {
  std::cout << "Dumping ROM...\n";
  dumpROM(ROMPath);

  // Populate Memory
  std::cout << "Populating Memory...\n";
  if (disassembledROM.size() >= 0x7FFF) {
    for (int i = 0; i <= 0x7FFF; i++) {
      memory[i] = disassembledROM[i];
    }
  } else {
    // TODO: Halt, bad dump
  }

  // TODO: Intitial Values
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x20, %rsp
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x8(%rdi), %r14
movl $0x10018, %edx          # imm = 0x10018
movq %r14, %rdi
xorl %esi, %esi
callq 0xc260
movq 0xba96d(%rip), %rdi     # 0xf6ee8
leaq 0x78952(%rip), %rsi     # 0xb4ed4
movl $0xf, %edx
callq 0xc830
leaq -0x30(%rbp), %r12
movq %r12, -0x10(%r12)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
leaq -0x40(%rbp), %rdi
callq 0x3a1dc
leaq -0x40(%rbp), %rsi
movq %rbx, %rdi
callq 0x3c650
movq -0x40(%rbp), %rdi
cmpq %r12, %rdi
je 0x3c5c9
movq -0x30(%rbp), %rsi
incq %rsi
callq 0xc0d0
movq 0xba918(%rip), %rdi     # 0xf6ee8
leaq 0x7890d(%rip), %rsi     # 0xb4ee4
movl $0x15, %edx
callq 0xc830
movq 0x8(%rbx), %rax
movq 0x10(%rbx), %rcx
subq %rax, %rcx
cmpq $0x7fff, %rcx           # imm = 0x7FFF
jb 0x3c60a
xorl %ecx, %ecx
movb (%rax,%rcx), %dl
movb %dl, 0x20(%rbx,%rcx)
incq %rcx
cmpq $0x8000, %rcx           # imm = 0x8000
jne 0x3c5f7
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r15
movq -0x40(%rbp), %rdi
cmpq %r12, %rdi
je 0x3c634
movq -0x30(%rbp), %rsi
incq %rsi
callq 0xc0d0
jmp 0x3c634
movq %rax, %r15
movq (%r14), %rdi
testq %rdi, %rdi
je 0x3c648
movq 0x18(%rbx), %rsi
subq %rdi, %rsi
callq 0xc0d0
movq %r15, %rdi
callq 0xc560
// File: /workspace/github_cpp_makefile_star2_O3/Ciaxur[P]yagb-emu/src/Memory.cc
// Function: Memory::dumpROM(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void Memory::dumpROM(std::string ROMPath) {
  std::ifstream infile;
  infile.open(ROMPath);

  // Check if file exists
  if (!infile) {
    std::cout << "ROM not found" << std::endl;
    return;
  }

  // Allocate Space
  disassembledROM.clear();
  disassembledROM.reserve(1024 * 32);

  uint8_t buffer[1];
  for (int i=0; !infile.eof(); i++) {
    infile.read((char *) buffer, 1);
    if (infile.gcount())
      disassembledROM.push_back(buffer[0]);
  }
  std::cout << "ROM Disassembled!\n";
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x210, %rsp            # imm = 0x210
movq %rsi, %r14
movq %rdi, %rbx
leaq -0x230(%rbp), %r15
movq %r15, %rdi
callq 0xc2d0
movq %r15, %rdi
movq %r14, %rsi
movl $0x8, %edx
callq 0xc1b0
movq -0x230(%rbp), %rax
movq -0x18(%rax), %rax
testb $0x5, -0x210(%rbp,%rax)
je 0x3c6e7
movq 0xba845(%rip), %rbx     # 0xf6ee8
leaq 0x78850(%rip), %rsi     # 0xb4efa
movl $0xd, %edx
movq %rbx, %rdi
callq 0xc830
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0xc8b0
movsbl %al, %esi
movq 0xba813(%rip), %rdi     # 0xf6ee8
callq 0xc4a0
movq %rax, %rdi
callq 0xc440
jmp 0x3c786
leaq 0x8(%rbx), %r14
movq 0x8(%rbx), %rax
cmpq %rax, 0x10(%rbx)
je 0x3c6f9
movq %rax, 0x10(%rbx)
movl $0x8000, %esi           # imm = 0x8000
movq %r14, %rdi
callq 0x3cab6
movq -0x230(%rbp), %rax
movq -0x18(%rax), %rax
testb $0x2, -0x210(%rbp,%rax)
jne 0x3c76e
leaq -0x21(%rbp), %r12
movl $0x1, %edx
movq %r15, %rdi
movq %r12, %rsi
callq 0xc420
cmpq $0x0, -0x228(%rbp)
je 0x3c759
movq 0x10(%rbx), %rsi
cmpq 0x18(%rbx), %rsi
je 0x3c74e
movb -0x21(%rbp), %al
movb %al, (%rsi)
incq 0x10(%rbx)
jmp 0x3c759
movq %r14, %rdi
movq %r12, %rdx
callq 0x3cb5a
movq -0x230(%rbp), %rax
movq -0x18(%rax), %rax
testb $0x2, -0x210(%rbp,%rax)
je 0x3c71f
movq 0xba773(%rip), %rdi     # 0xf6ee8
leaq 0x7878c(%rip), %rsi     # 0xb4f08
movl $0x12, %edx
callq 0xc830
leaq -0x230(%rbp), %rdi
callq 0xc030
addq $0x210, %rsp            # imm = 0x210
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3c7a6
jmp 0x3c7a6
movq %rax, %rbx
leaq -0x230(%rbp), %rdi
callq 0xc030
movq %rbx, %rdi
callq 0xc560
nop
// File: /workspace/github_cpp_makefile_star2_O3/Ciaxur[P]yagb-emu/src/Memory.cc
// Function: Memory::dump(std::ostream&)
void Memory::dump(std::ostream &out) {
  std::ios init(nullptr);
  init.copyfmt(out);
  out << std::hex << std::uppercase << std::setfill('0') << std::setw(4) << 0 << ": ";

  int j = 0;
  for (int i = 0; i < 0xFFFF; i++) {
    if (j == 16) {
      j = 0;
      out << "\n" << std::setw(4) << i << ": ";
    }
    j++;
    out << std::setw(2) << (int)memory[i] << (j == 8 ? "\t\t" : " ");
  }
  out.copyfmt(init);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %rsi, %rbx
movq %rdi, %r14
leaq -0x130(%rbp), %r15
movq %r15, %rdi
xorl %esi, %esi
callq 0xc5f0
movq (%rbx), %rax
movq -0x18(%rax), %rsi
addq %rbx, %rsi
movq %r15, %rdi
callq 0xc250
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movl 0x18(%rbx,%rcx), %edx
andl $-0x4b, %edx
orl $0x8, %edx
movl %edx, 0x18(%rbx,%rcx)
movq -0x18(%rax), %rcx
orl $0x4000, 0x18(%rbx,%rcx) # imm = 0x4000
movq -0x18(%rax), %rcx
leaq (%rbx,%rcx), %r15
cmpb $0x0, 0xe1(%rbx,%rcx)
jne 0x3c846
movq %r15, %rdi
movl $0x20, %esi
callq 0xc8b0
movb $0x1, 0xe1(%r15)
movq (%rbx), %rax
movb $0x30, 0xe0(%r15)
movq -0x18(%rax), %rax
movq $0x4, 0x10(%rbx,%rax)
movq %rbx, %rdi
xorl %esi, %esi
callq 0xc270
leaq 0x7481a(%rip), %rsi     # 0xb1086
movl $0x2, %edx
movq %rax, %rdi
callq 0xc830
xorl %r15d, %r15d
leaq 0x7c97d(%rip), %r13     # 0xb9200
xorl %r12d, %r12d
cmpl $0x10, %r12d
jne 0x3c8d2
movl $0x1, %edx
movq %rbx, %rdi
leaq 0x84ffc(%rip), %rsi     # 0xc1897
callq 0xc830
movq (%rbx), %rax
movq -0x18(%rax), %rax
movq $0x4, 0x10(%rbx,%rax)
movq %rbx, %rdi
movl %r15d, %esi
callq 0xc270
xorl %r12d, %r12d
movl $0x2, %edx
movq %rax, %rdi
leaq 0x747b9(%rip), %rsi     # 0xb1086
callq 0xc830
movq (%rbx), %rax
movq -0x18(%rax), %rax
movq $0x2, 0x10(%rbx,%rax)
movzbl 0x20(%r14,%r15), %esi
movq %rbx, %rdi
callq 0xc270
incl %r12d
xorl %edx, %edx
cmpl $0x8, %r12d
sete %dl
movq %r13, %rsi
leaq 0x78615(%rip), %rcx     # 0xb4f1b
cmoveq %rcx, %rsi
incq %rdx
movq %rax, %rdi
callq 0xc830
incq %r15
cmpq $0xffff, %r15           # imm = 0xFFFF
jne 0x3c886
movq (%rbx), %rax
addq -0x18(%rax), %rbx
leaq -0x130(%rbp), %rsi
movq %rbx, %rdi
callq 0xc250
leaq -0x130(%rbp), %rdi
callq 0xc5e0
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3c95d
jmp 0x3c95d
movq %rax, %rbx
leaq -0x130(%rbp), %rdi
callq 0xc5e0
movq %rbx, %rdi
callq 0xc560
// File: /workspace/github_cpp_makefile_star2_O3/Ciaxur[P]yagb-emu/src/Memory.cc
// Function: Memory::write(unsigned short, unsigned char)
void Memory::write(uint16_t address, uint8_t value) {
  // TODO: MBC Switch
  if (address < 0x7FFF) {

  }

  // Output Serial Link
  else if (address == 0xFF02 && value == 0x81) {
//    std::cout << "Serial Link Value: " << std::hex << (int)this->read(0xFF01) << '\n';
    std::cout << (char)this->read(0xFF01);

    // Serial Write Interrupt
    memory[0xFF0F] |= 0x08;
  }

  // VRAM Write
  else if (address >= 0x8000 && address <= 0x9FFF && *(this->LCDMode) != 3) {
    memory[address] = value;
  }

  // Reset DIV if writen to
  else if (address == 0xFF04) {
    memory[0xFF04] = 0;
  }

  // Prohibited Areas, NO.
  else if (!(address >= 0xE000 && address <= 0xFDFF) && !(address >= 0xFEA0 && address <= 0xFEFF)) {
    memory[address] = value;
  }

  else {
    // Writing out of range
    std::cout << "Memory.write [" << std::hex << address << std::dec << "]: INVALID RANGE!\n";
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x10, %rsp
cmpl $0x7fff, %esi           # imm = 0x7FFF
jb 0x3caac
movq %rdi, %r14
movzwl %si, %ebx
cmpl $0xff02, %ebx           # imm = 0xFF02
setne %al
cmpb $-0x7f, %dl
setne %cl
orb %al, %cl
jne 0x3c9db
movb 0xff21(%r14), %al
leaq -0x11(%rbp), %rsi
movb %al, (%rsi)
movq 0xba524(%rip), %rdi     # 0xf6ee8
movl $0x1, %edx
callq 0xc830
orb $0x8, 0xff2f(%r14)
jmp 0x3caac
cmpl $0x7fff, %ebx           # imm = 0x7FFF
sete %al
cmpl $0xa000, %ebx           # imm = 0xA000
setae %cl
orb %al, %cl
jne 0x3ca02
movq 0x10020(%r14), %rax
cmpb $0x3, (%rax)
je 0x3ca17
jmp 0x3caa7
cmpl $0xff04, %ebx           # imm = 0xFF04
jne 0x3ca17
movb $0x0, 0xff24(%r14)
jmp 0x3caac
leal 0x2000(%rsi), %eax
movzwl %ax, %eax
cmpl $0x1e00, %eax           # imm = 0x1E00
setb %al
addl $0x160, %esi            # imm = 0x160
cmpw $0x60, %si
setb %cl
orb %al, %cl
je 0x3caa7
movq 0xba4a8(%rip), %r14     # 0xf6ee8
leaq 0x784d7(%rip), %rsi     # 0xb4f1e
movl $0xe, %edx
movq %r14, %rdi
callq 0xc830
movq (%r14), %rax
movq -0x18(%rax), %rax
movl 0x18(%r14,%rax), %ecx
andl $-0x4b, %ecx
orl $0x8, %ecx
movl %ecx, 0x18(%r14,%rax)
movq %r14, %rdi
movq %rbx, %rsi
callq 0xc460
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x2, %edx
movl %edx, 0x18(%rax,%rcx)
leaq 0x7849b(%rip), %rsi     # 0xb4f2d
movl $0x12, %edx
movq %rax, %rdi
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
jmp 0xc830
movb %dl, 0x20(%r14,%rbx)
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/Ciaxur[P]yagb-emu/src/Opcode.cc
// Function: Opcode::Opcode(unsigned char, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, unsigned short, unsigned short, std::function<void ()>)
Opcode::Opcode(uint8_t opcode, std::string label, uint16_t machineCycles, uint16_t length, std::function<void()> exec) {
    this->opcode = opcode;
    this->label = label;
    this->machineCycles = machineCycles;
    this->length = length;
    this->exec = exec;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r9, %r13
movl %r8d, %ebx
movl %ecx, %r14d
movq %rdi, %r12
addq $0x8, %rdi
leaq 0x18(%r12), %rax
movq %rax, -0x30(%rbp)
movq %rax, 0x8(%r12)
movq $0x0, 0x10(%r12)
movb $0x0, 0x18(%r12)
leaq 0x30(%r12), %r15
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%r12)
movups %xmm0, 0x40(%r12)
movb %sil, (%r12)
movq %rdi, -0x38(%rbp)
movq %rdx, %rsi
callq 0xc920
movw %r14w, 0x28(%r12)
movw %bx, 0x2a(%r12)
movq %r15, %rdi
movq %r13, %rsi
callq 0x3cd42
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x40(%r12), %rax
testq %rax, %rax
je 0x3ccf6
movq %r15, %rdi
movq %r15, %rsi
movl $0x3, %edx
callq *%rax
movq -0x38(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0xca08
movq %rbx, %rdi
callq 0xc560
movq %rax, %rdi
callq 0x39dbe
nop
// File: /workspace/github_cpp_makefile_star2_O3/Ciaxur[P]yagb-emu/src/PPU.cc
// Function: PPU::execute()
void PPU::execute() {
  // Set current LY Value for CPU
  if (memory->read(0xFF40) & 0x80) {
    memory->write(0xFF44, this->LY);
  } else {
    memory->write(0xFF44, 0);
  }

  // Determine LCDMode based on LY State
  if (this->LY < 144) {
    if (cpu->cyclesLeft > 94) {
      this->LCDMode = 2;
    } else if (cpu->cyclesLeft > 22) {
      this->LCDMode = 3;
    } else if (cpu->cyclesLeft < 22) {
      this->LCDMode = 0;
    }
  } else {
    this->LCDMode = 1;
  }

  // Update PPU and CPU state based on both
  //  CPU's current States
  if (cpu->cyclesLeft <= 0) { // End of current scanline
    if (this->LY == 143) {
      // VBlank Area
      uint8_t IF = memory->read(0xFF0F);
      IF |= 0x01;
      memory->write(0xFF0F, IF);

      this->LY = 144;
      this->currentFrame++;
      cpu->cyclesLeft += 114;   // Account for Extra Cycles Taken
    } else {
      this->LY = (this->LY + 1) % 154;
      cpu->cyclesLeft += 114;
    }
  }

  // Execute CPU
  cpu->execute();

  // TODO: Perform PPU functions based on current LCD Mode
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
movq %rdi, %rbx
movq 0x10(%rdi), %rdi
movl $0xff40, %esi           # imm = 0xFF40
callq 0x3c974
movq 0x10(%rbx), %rdi
sarb $0x7, %al
andb 0x20(%rbx), %al
movzbl %al, %edx
movl $0xff44, %esi           # imm = 0xFF44
callq 0x3c980
movb 0x20(%rbx), %al
cmpb $-0x71, %al
ja 0x3ce99
movq 0x18(%rbx), %rcx
movl 0x8(%rcx), %edx
movb $0x2, %sil
cmpl $0x5e, %edx
jg 0x3ce8d
movb $0x3, %sil
cmpl $0x16, %edx
jle 0x3cee2
movb %sil, (%rbx)
addq $0x18, %rbx
movq %rbx, %r14
jmp 0x3cf05
movb $0x1, (%rbx)
movq 0x18(%rbx), %rcx
movl 0x8(%rcx), %edx
leaq 0x18(%rbx), %r14
testl %edx, %edx
jg 0x3cf05
cmpb $-0x71, %al
jne 0x3cee9
movq 0x10(%rbx), %rdi
movl $0xff0f, %esi           # imm = 0xFF0F
callq 0x3c974
orb $0x1, %al
movq 0x10(%rbx), %rdi
movzbl %al, %edx
movl $0xff0f, %esi           # imm = 0xFF0F
callq 0x3c980
movb $-0x70, 0x20(%rbx)
incq 0x8(%rbx)
movq 0x18(%rbx), %rax
addl $0x72, 0x8(%rax)
jmp 0x3cf05
je 0x3ce90
movb $0x0, (%rbx)
jmp 0x3cea3
cmpb $-0x67, %al
movl $0x1, %esi
movl $0x67, %edi
cmovbl %esi, %edi
addb %al, %dil
movb %dil, 0x20(%rbx)
addl $0x72, %edx
movl %edx, 0x8(%rcx)
movq (%r14), %rdi
popq %rbx
popq %r14
popq %rbp
jmp 0x30e36
nopl (%rax)
// File: /workspace/github_cpp_makefile_star2_O3/Ciaxur[P]yagb-emu/src/main.cc
// Function: handleEventPolling(CPU*)
void handleEventPolling(CPU *cpu) {
  SDL_Event windowEvent;

  while (SDL_PollEvent(&windowEvent) != 0) {
    ImGui_ImplSDL2_ProcessEvent(&windowEvent);

    // Check if close button was clicked
    if (windowEvent.type == SDL_QUIT) {
      std::cout << "Quitting...\n";
      cpu->stop();
      return;
    }

    switch (windowEvent.type) {
    // Handle Key Presses
    case SDL_KEYDOWN:
      if (windowEvent.key.keysym.sym == SDL_KeyCode::SDLK_s) {
        if (keystate.step_instr_hold == 0)
          keystate.step_instr = true;
        keystate.step_instr_hold++;
      }
      if (windowEvent.key.keysym.sym == SDL_KeyCode::SDLK_m) {
        if (keystate.step_frame_hold == 0)
          keystate.step_frame = true;
        keystate.step_frame_hold++;
      }


      break;
    case SDL_KEYUP:
      // TODO: Key Press Here
      if (windowEvent.key.keysym.sym == SDL_KeyCode::SDLK_s) {
        keystate.step_instr = false;
        keystate.step_instr_hold = 0;
      }
      if (windowEvent.key.keysym.sym == SDL_KeyCode::SDLK_m) {
        keystate.step_frame = false;
        keystate.step_frame_hold = 0;
      }

      break;

    default:
      break;
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x40, %rsp
movq %rdi, %rbx
leaq -0x48(%rbp), %rdi
callq 0xc8e0
testl %eax, %eax
je 0x3d002
leaq -0x48(%rbp), %r14
movq %r14, %rdi
callq 0xadf64
movl -0x48(%rbp), %eax
cmpl $0x300, %eax            # imm = 0x300
je 0x3cf7c
cmpl $0x301, %eax            # imm = 0x301
je 0x3cf5c
cmpl $0x100, %eax            # imm = 0x100
jne 0x3cfd0
jmp 0x3cfe2
movl -0x34(%rbp), %eax
cmpl $0x6d, %eax
je 0x3cfa4
cmpl $0x73, %eax
jne 0x3cfd0
movb $0x0, 0xbebf0(%rip)     # 0xfbb60
movl $0x0, 0xbebea(%rip)     # 0xfbb64
jmp 0x3cfd0
movl -0x34(%rbp), %eax
cmpl $0x6d, %eax
je 0x3cfb7
cmpl $0x73, %eax
jne 0x3cfd0
movl 0xbebd5(%rip), %eax     # 0xfbb64
testl %eax, %eax
jne 0x3cf9a
movb $0x1, 0xbebc6(%rip)     # 0xfbb60
incl %eax
movl %eax, 0xbebc2(%rip)     # 0xfbb64
jmp 0x3cfd0
movb $0x0, 0xbebb6(%rip)     # 0xfbb61
movl $0x0, 0xbebb3(%rip)     # 0xfbb68
jmp 0x3cfd0
movl 0xbebab(%rip), %eax     # 0xfbb68
testl %eax, %eax
jne 0x3cfc8
movb $0x1, 0xbeb99(%rip)     # 0xfbb61
incl %eax
movl %eax, 0xbeb98(%rip)     # 0xfbb68
movq %r14, %rdi
callq 0xc8e0
testl %eax, %eax
jne 0x3cf37
jmp 0x3d002
movq 0xb9eff(%rip), %rdi     # 0xf6ee8
leaq 0x78048(%rip), %rsi     # 0xb5038
movl $0xc, %edx
callq 0xc830
movq %rbx, %rdi
callq 0x31294
addq $0x40, %rsp
popq %rbx
popq %r14
popq %rbp
retq