// File: /workspace/github_cpp_makefile_star2_O3/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 0x228f3
movl %esi, %eax
xorl $0x1000, %eax           # imm = 0x1000
cmpb $0x0, 0x50(%rdi)
cmovnsl %esi, %eax
movzwl %ax, %eax
cmpl $0x7ff, %eax            # imm = 0x7FF
ja 0x22793
movzbl 0x53(%rdi), %ecx
movq 0x20(%rdi), %rdx
cmpq %rdx, 0x28(%rdi)
je 0x227ed
movl %ecx, %esi
andl $-0x8, %esi
andl $0x6, %ecx
shll $0xa, %ecx
addq (%rdx,%rsi), %rcx
jmp 0x22801
cmpl $0xfff, %eax            # imm = 0xFFF
ja 0x227c0
movzbl 0x54(%rdi), %ecx
movq 0x20(%rdi), %rdx
cmpq %rdx, 0x28(%rdi)
je 0x22832
movl %ecx, %esi
andl $-0x8, %esi
andl $0x6, %ecx
shll $0xa, %ecx
addq (%rdx,%rsi), %rcx
jmp 0x22846
cmpl $0x13ff, %eax           # imm = 0x13FF
ja 0x22805
movzbl 0x55(%rdi), %ecx
movq 0x20(%rdi), %rdx
cmpq %rdx, 0x28(%rdi)
je 0x22879
movl %ecx, %esi
andl $-0x8, %esi
andl $0x7, %ecx
shll $0xa, %ecx
addq (%rdx,%rsi), %rcx
jmp 0x22887
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 0x22850
movzbl 0x56(%rdi), %ecx
movq 0x20(%rdi), %rdx
cmpq %rdx, 0x28(%rdi)
je 0x228ab
movl %ecx, %esi
andl $-0x8, %esi
andl $0x7, %ecx
shll $0xa, %ecx
addq (%rdx,%rsi), %rcx
jmp 0x228b9
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
movq 0x20(%rdi), %rcx
movq 0x28(%rdi), %rsi
cmpl $0x1bff, %eax           # imm = 0x1BFF
ja 0x22891
movzbl 0x57(%rdi), %edx
cmpq %rcx, %rsi
je 0x228c3
movl %edx, %esi
andl $-0x8, %esi
andl $0x7, %edx
shll $0xa, %edx
addq (%rcx,%rsi), %rdx
jmp 0x228d1
movq 0x48(%rdi), %rdx
shll $0xa, %ecx
addq %rdx, %rcx
addq $0x8, %rcx
addq %rcx, %rax
addq $-0x1000, %rax          # imm = 0xF000
retq
movzbl 0x58(%rdi), %edx
cmpq %rcx, %rsi
je 0x228db
movl %edx, %esi
andl $-0x8, %esi
andl $0x7, %edx
shll $0xa, %edx
addq (%rcx,%rsi), %rdx
jmp 0x228e9
movq 0x48(%rdi), %rdx
shll $0xa, %ecx
addq %rdx, %rcx
addq $0x8, %rcx
addq %rcx, %rax
addq $-0x1400, %rax          # imm = 0xEC00
retq
movq 0x48(%rdi), %rcx
shll $0xa, %edx
addq %rcx, %rdx
addq $0x8, %rdx
addq %rdx, %rax
addq $-0x1800, %rax          # imm = 0xE800
retq
movq 0x48(%rdi), %rcx
shll $0xa, %edx
addq %rcx, %rdx
addq $0x8, %rdx
addq %rdx, %rax
addq $-0x1c00, %rax          # imm = 0xE400
retq
pushq %rbp
movq %rsp, %rbp
leaq 0x120be(%rip), %rdi     # 0x349bc
leaq 0x11e06(%rip), %rsi     # 0x3470b
leaq 0x120bf(%rip), %rcx     # 0x349cb
movl $0x19e, %edx            # imm = 0x19E
callq 0xa160