// File: /workspace/github_cpp_makefile_star2_O1/mindbeast[P]rnes/mmc.cpp
// Function: Rnes::Mmc3::getChrPointer(unsigned short)
uint8_t *Mmc3::getChrPointer(uint16_t addr) {
  bool a12Invert = isChrA12Inverted();
  assert(addr <= 0x1fff);

  if (a12Invert) {
    addr ^= (1 << 12);
  }
  if (addr <= 0x7ff) {
    return get2kChrBank(bankRegister[0]) + addr;
  } else if (addr >= 0x800 and addr <= 0xfff) {
    return get2kChrBank(bankRegister[1]) + addr - 0x800;
  } else if (addr >= 0x1000 and addr <= 0x13ff) {
    return get1kChrBank(bankRegister[2]) + addr - 0x1000;
  } else if (addr >= 0x1400 and addr <= 0x17ff) {
    return get1kChrBank(bankRegister[3]) + addr - 0x1400;
  } else if (addr >= 0x1800 and addr <= 0x1bff) {
    return get1kChrBank(bankRegister[4]) + addr - 0x1800;
  } else if (addr >= 0x1c00 and addr <= 0x1fff) {
    return get1kChrBank(bankRegister[5]) + addr - 0x1c00;
  }
  return 0;
}

// Assembly:
cmpl $0x2000, %esi           # imm = 0x2000
jae 0x23903
movl %esi, %eax
xorl $0x1000, %eax           # imm = 0x1000
cmpb $0x0, 0x50(%rdi)
cmovnsl %esi, %eax
movzwl %ax, %eax
cmpl $0x7ff, %eax            # imm = 0x7FF
ja 0x23797
movzbl 0x53(%rdi), %ecx
movq 0x20(%rdi), %rdx
cmpq %rdx, 0x28(%rdi)
je 0x237f1
movl %ecx, %esi
andl $-0x8, %esi
andl $0x6, %ecx
shll $0xa, %ecx
addq (%rdx,%rsi), %rcx
jmp 0x23805
cmpl $0xfff, %eax            # imm = 0xFFF
ja 0x237c4
movzbl 0x54(%rdi), %ecx
movq 0x20(%rdi), %rdx
cmpq %rdx, 0x28(%rdi)
je 0x23836
movl %ecx, %esi
andl $-0x8, %esi
andl $0x6, %ecx
shll $0xa, %ecx
addq (%rdx,%rsi), %rcx
jmp 0x2384a
cmpl $0x13ff, %eax           # imm = 0x13FF
ja 0x23809
movzbl 0x55(%rdi), %ecx
movq 0x20(%rdi), %rdx
cmpq %rdx, 0x28(%rdi)
je 0x2387a
movl %ecx, %esi
andl $-0x8, %esi
andl $0x7, %ecx
shll $0xa, %ecx
addq (%rdx,%rsi), %rcx
jmp 0x23888
movq 0x48(%rdi), %rdx
shll $0xa, %ecx
andl $0x3f800, %ecx          # imm = 0x3F800
addq %rdx, %rcx
addq $0x8, %rcx
addq %rcx, %rax
retq
cmpl $0x17ff, %eax           # imm = 0x17FF
ja 0x23854
movzbl 0x56(%rdi), %ecx
movq 0x20(%rdi), %rdx
cmpq %rdx, 0x28(%rdi)
je 0x238b8
movl %ecx, %esi
andl $-0x8, %esi
andl $0x7, %ecx
shll $0xa, %ecx
addq (%rdx,%rsi), %rcx
jmp 0x238c6
movq 0x48(%rdi), %rdx
shll $0xa, %ecx
andl $0x3f800, %ecx          # imm = 0x3F800
addq %rdx, %rcx
addq $0x8, %rcx
addq %rcx, %rax
addq $-0x800, %rax           # imm = 0xF800
retq
cmpl $0x1bff, %eax           # imm = 0x1BFF
ja 0x23892
movzbl 0x57(%rdi), %ecx
movq 0x20(%rdi), %rdx
cmpq %rdx, 0x28(%rdi)
je 0x238d3
movl %ecx, %esi
andl $-0x8, %esi
andl $0x7, %ecx
shll $0xa, %ecx
addq (%rdx,%rsi), %rcx
jmp 0x238e1
movq 0x48(%rdi), %rdx
shll $0xa, %ecx
addq %rdx, %rcx
addq $0x8, %rcx
addq %rcx, %rax
addq $-0x1000, %rax          # imm = 0xF000
retq
cmpl $0x1fff, %eax           # imm = 0x1FFF
ja 0x238d0
movzbl 0x58(%rdi), %ecx
movq 0x20(%rdi), %rdx
cmpq %rdx, 0x28(%rdi)
je 0x238eb
movl %ecx, %esi
andl $-0x8, %esi
andl $0x7, %ecx
shll $0xa, %ecx
addq (%rdx,%rsi), %rcx
jmp 0x238f9
movq 0x48(%rdi), %rdx
shll $0xa, %ecx
addq %rdx, %rcx
addq $0x8, %rcx
addq %rcx, %rax
addq $-0x1400, %rax          # imm = 0xEC00
retq
xorl %eax, %eax
retq
movq 0x48(%rdi), %rdx
shll $0xa, %ecx
addq %rdx, %rcx
addq $0x8, %rcx
addq %rcx, %rax
addq $-0x1800, %rax          # imm = 0xE800
retq
movq 0x48(%rdi), %rdx
shll $0xa, %ecx
addq %rdx, %rcx
addq $0x8, %rcx
addq %rcx, %rax
addq $-0x1c00, %rax          # imm = 0xE400
retq
pushq %rbp
movq %rsp, %rbp
leaq 0x120ae(%rip), %rdi     # 0x359bc
leaq 0x11df6(%rip), %rsi     # 0x3570b
leaq 0x120af(%rip), %rcx     # 0x359cb
movl $0x19e, %edx            # imm = 0x19E
callq 0xb160