LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_cpp_makefile_star2_O3/khedoros[P]khednes/cpu2.cpp
// Function: cpu::cpu(mem*, apu*, unsigned int, bool)
cpu::cpu(mem * data, apu * ap, const unsigned int start_loc, bool is_nsf) : nsf_mode(is_nsf) {
    for(int i=0;i<256;++i) {
        inst_counts[i]=0;
    }
    memory=data;
    audio=ap;
    pc=start_loc;
    status.reg=0;//FLAG_TRUE|FLAG_BRK;
    sp=0;
    acc=0;
    x=0;
    y=0;
    ops_ahead=0;
    ppu_cycle=0;
    addr=0;
    prevpc=0;
    prevop=0;
    prevopaddr = 0;
    prevopoffset = 0;
    prevoparg = 0;
    nextop = 0;
    nextopaddr = 0;
    nextopoffset = 0;
    nextoparg = 0;
    frame = 0;

    addresses.resize(17); //17th page is for any PC values that occur in RAM instead of ROM
    for(int page=0;page<16;page++) {
        addresses[page].resize(PRG_PAGE_SIZE);
        for(int paddr=0;paddr<PRG_PAGE_SIZE;paddr++) {
            addresses[page][paddr] = 0;
        }
    }
    addresses[16].resize(0x8000);
    for(int paddr=0;paddr<0x8000;paddr++) {
        addresses[16][paddr] = 0;
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movl %ecx, %ebx
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %r12
movb %r8b, 0x527(%rdi)
addq $0x20, %rdi
xorl %r13d, %r13d
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x4220
movq %r15, 0x10(%r12)
movq %r14, 0x18(%r12)
movl %ebx, (%r12)
movb %r13b, 0x8(%r12)
movb %r13b, 0xe(%r12)
movb %r13b, 0x4(%r12)
movw $0x0, 0xc(%r12)
movq %r13, 0x460(%r12)
movl %r13d, 0x448(%r12)
movl %r13d, 0x468(%r12)
movq %r13, 0x420(%r12)
movb %r13b, 0x428(%r12)
xorps %xmm0, %xmm0
movups %xmm0, 0x42c(%r12)
movq %r13, 0x439(%r12)
leaq 0x10fba(%rip), %rdi     # 0x1c370
movl $0x11, %esi
callq 0xcdc6
movq 0x10fa9(%rip), %rbx     # 0x1c370
addq %r13, %rbx
movl $0x4000, %esi           # imm = 0x4000
movq %rbx, %rdi
callq 0xce48
movq 0x10f92(%rip), %rbx     # 0x1c370
movq (%rbx,%r13), %rdi
movl $0x10000, %edx          # imm = 0x10000
xorl %esi, %esi
callq 0x4220
addq $0x18, %r13
cmpq $0x180, %r13            # imm = 0x180
jne 0xb3c7
addq $0x180, %rbx            # imm = 0x180
movl $0x8000, %esi           # imm = 0x8000
movq %rbx, %rdi
callq 0xce48
movq 0x10f5a(%rip), %rax     # 0x1c370
movq 0x180(%rax), %rdi
movl $0x20000, %edx          # imm = 0x20000
xorl %esi, %esi
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x4220
// File: /workspace/github_cpp_makefile_star2_O3/khedoros[P]khednes/cpu2.cpp
// Function: cpu::stat_string(cpu::statreg_t)
char * cpu::stat_string(statreg_t status) {
    if(util::is_active(ORIGIN)) {
        for(int i=0;i<9;++i) {
            st[i]=0;
        }
        strncat(st,((status.sign)?"N":"n"),1);
        strncat(st,((status.verflow)?"V":"v"),1);        
        strncat(st,((status.tru)?"T":"t"),1);        
        strncat(st,((status.brk)?"B":"b"),1);        
        strncat(st,((status.dec)?"D":"d"),1);        
        strncat(st,((status.inter)?"I":"i"),1);        
        strncat(st,((status.zero)?"Z":"z"),1);        
        strncat(st,((status.carry)?"C":"c"),1);        
    }
    return st;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %esi, %ebp
movq %rdi, %rbx
movl $0x1, %edi
callq 0xfdac
testb %al, %al
je 0xcc1e
leaq 0x4c7(%rbx), %r14
movb $0x0, 0x4cf(%rbx)
movq $0x0, 0x4c7(%rbx)
movd %ebp, %xmm0
pshufd $0x0, %xmm0, %xmm0      # xmm0 = xmm0[0,0,0,0]
movdqa 0x87d1(%rip), %xmm1     # 0x152b0
pand %xmm0, %xmm1
movdqa %xmm1, 0x10(%rsp)
pand 0x87cf(%rip), %xmm0     # 0x152c0
movdqa %xmm0, (%rsp)
movq %r14, %rdi
callq 0x41c0
pxor %xmm0, %xmm0
movdqa (%rsp), %xmm2
pcmpeqd %xmm0, %xmm2
movdqa 0x10(%rsp), %xmm1
pcmpeqd %xmm0, %xmm1
packssdw %xmm2, %xmm1
packsswb %xmm1, %xmm1
pmovmskb %xmm1, %ebp
movl %ebp, %ecx
andb $0x2, %cl
shrb %cl
movb %cl, 0x10(%rsp)
movl %ebp, %ecx
andb $0x4, %cl
shrb $0x2, %cl
movb %cl, (%rsp)
movl %ebp, %r13d
andb $0x8, %r13b
shrb $0x3, %r13b
movl %ebp, %r15d
andb $0x10, %r15b
shrb $0x4, %r15b
movl %ebp, %r12d
shrb $0x6, %r12b
movl %ebp, %ecx
shrb $0x7, %cl
movzbl %cl, %ecx
shll $0x5, %ecx
orl $0x4e, %ecx
movw %cx, 0x4c7(%rbx,%rax)
movq %r14, %rdi
callq 0x41c0
movzbl %r12b, %ecx
shll $0x5, %ecx
orl $0x56, %ecx
movw %cx, 0x4c7(%rbx,%rax)
movq %r14, %rdi
callq 0x41c0
movl %ebp, %ecx
andl $0x20, %ecx
orl $0x54, %ecx
movw %cx, 0x4c7(%rbx,%rax)
movq %r14, %rdi
callq 0x41c0
movzbl %r15b, %ecx
shll $0x5, %ecx
orl $0x42, %ecx
movw %cx, 0x4c7(%rbx,%rax)
movq %r14, %rdi
callq 0x41c0
movzbl %r13b, %ecx
shll $0x5, %ecx
orl $0x44, %ecx
movw %cx, 0x4c7(%rbx,%rax)
movq %r14, %rdi
callq 0x41c0
movzbl (%rsp), %ecx
shll $0x5, %ecx
orl $0x49, %ecx
movw %cx, 0x4c7(%rbx,%rax)
movq %r14, %rdi
callq 0x41c0
movzbl 0x10(%rsp), %ecx
shll $0x5, %ecx
orl $0x5a, %ecx
movw %cx, 0x4c7(%rbx,%rax)
movq %r14, %rdi
callq 0x41c0
andl $0x1, %ebp
shll $0x5, %ebp
orl $0x43, %ebp
movw %bp, 0x4c7(%rbx,%rax)
addq $0x4c7, %rbx            # imm = 0x4C7
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/khedoros[P]khednes/cpu2.cpp
// Function: cpu::trigger_nmi()
void cpu::trigger_nmi() {
    push2(pc);
    status.inter = 0;
    push(status.reg);
    pc=memory->read2(NM_INT_INSERTION);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movl (%rdi), %ebp
movl %ebp, %edx
shrl $0x8, %edx
movq 0x10(%rdi), %rdi
movzbl 0xe(%rbx), %esi
movl $0x100, %r14d           # imm = 0x100
orl %r14d, %esi
movl $0xff, %r15d
andl %r15d, %edx
callq 0xab46
movb 0xe(%rbx), %al
decb %al
movb %al, 0xe(%rbx)
movq 0x10(%rbx), %rdi
movzbl %al, %esi
orl %r14d, %esi
andl %r15d, %ebp
movl %ebp, %edx
callq 0xab46
movb 0xe(%rbx), %al
decb %al
movb %al, 0xe(%rbx)
movzbl 0x8(%rbx), %edx
andl $-0x5, %edx
movb %dl, 0x8(%rbx)
movq 0x10(%rbx), %rdi
movzbl %al, %esi
orl %r14d, %esi
callq 0xab46
decb 0xe(%rbx)
movq 0x10(%rbx), %rdi
movl $0xfffa, %esi           # imm = 0xFFFA
callq 0xaaac
movl %eax, (%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/khedoros[P]khednes/cpu2.cpp
// Function: cpu::op_brk()
inline void cpu::op_brk() {
    pc++;
    push2(pc);
    status.brk = 1;
    push(status.reg);
    status.inter = 1;
    pc=memory->read2(0xFFFE);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movl (%rdi), %ebp
incl %ebp
movl %ebp, (%rdi)
movl %ebp, %edx
shrl $0x8, %edx
movq 0x10(%rdi), %rdi
movzbl 0xe(%rbx), %esi
movl $0x100, %r14d           # imm = 0x100
orl %r14d, %esi
movl $0xff, %r15d
andl %r15d, %edx
callq 0xab46
movb 0xe(%rbx), %al
decb %al
movb %al, 0xe(%rbx)
movq 0x10(%rbx), %rdi
movzbl %al, %esi
orl %r14d, %esi
andl %r15d, %ebp
movl %ebp, %edx
callq 0xab46
movb 0xe(%rbx), %al
decb %al
movb %al, 0xe(%rbx)
movzbl 0x8(%rbx), %edx
orl $0x10, %edx
movb %dl, 0x8(%rbx)
movq 0x10(%rbx), %rdi
movzbl %al, %esi
orl %r14d, %esi
callq 0xab46
decb 0xe(%rbx)
orb $0x4, 0x8(%rbx)
movq 0x10(%rbx), %rdi
movl $0xfffe, %esi           # imm = 0xFFFE
callq 0xaaac
movl %eax, (%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/khedoros[P]khednes/cpu2.cpp
// Function: cpu::op_ora(int)
inline void cpu::op_ora(int addr) {
    temp=memory->read(addr);
    acc|=temp;
    set_sign(acc);
    set_zero(acc);
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
movq 0x10(%rdi), %rdi
callq 0xa836
movl %eax, 0x454(%rbx)
orb 0x4(%rbx), %al
movb %al, 0x4(%rbx)
movl %eax, %ecx
andb $-0x80, %cl
movb 0x8(%rbx), %dl
andb $0x7d, %dl
orb %cl, %dl
testb %al, %al
sete %al
addb %al, %al
orb %dl, %al
movb %al, 0x8(%rbx)
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O3/khedoros[P]khednes/cpu2.cpp
// Function: cpu::op_aslm(int)
inline void cpu::op_aslm(int addr) {
    temp=memory->read(addr);
    set_carry(temp&0x80);
    temp<<=(1);
    set_zero(temp);
    set_sign(temp);
    memory->write(addr,temp);
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %ebx
movq %rdi, %r14
movq 0x10(%rdi), %rdi
callq 0xa836
movl %eax, %ecx
shrb $0x7, %cl
movb 0x8(%r14), %sil
andb $0x7c, %sil
orb %cl, %sil
addl %eax, %eax
movl %eax, 0x454(%r14)
testb %al, %al
sete %cl
addb %cl, %cl
movzbl %al, %edx
andb $-0x80, %al
orb %cl, %al
orb %sil, %al
movb %al, 0x8(%r14)
movq 0x10(%r14), %rdi
movl %ebx, %esi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0xab46
// File: /workspace/github_cpp_makefile_star2_O3/khedoros[P]khednes/cpu2.cpp
// Function: cpu::op_jsr(int)
inline void cpu::op_jsr(int addr) {
    //saves address immediately BEFORE the one I want to return to!!!
    //REASON: RTS pops the stack to the PC, THEN increments PC by 1
    pc--;
    push2(pc);
    pc=addr;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %esi, %ebx
movq %rdi, %r14
movl (%rdi), %ebp
decl %ebp
movl %ebp, (%rdi)
movl %ebp, %edx
shrl $0x8, %edx
movq 0x10(%rdi), %rdi
movzbl 0xe(%r14), %esi
movl $0x100, %r15d           # imm = 0x100
orl %r15d, %esi
movl $0xff, %r12d
andl %r12d, %edx
callq 0xab46
movb 0xe(%r14), %al
decb %al
movb %al, 0xe(%r14)
movq 0x10(%r14), %rdi
movzbl %al, %esi
orl %r15d, %esi
andl %r12d, %ebp
movl %ebp, %edx
callq 0xab46
decb 0xe(%r14)
movl %ebx, (%r14)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/khedoros[P]khednes/cpu2.cpp
// Function: cpu::op_bit(int)
inline void cpu::op_bit(int addr) {
    temp=memory->read(addr);
    set_zero(acc&temp);
    set_sign(temp);
    if((temp&0x40)>0)
        status.verflow = 1;
    else
        status.verflow = 0;
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
movq 0x10(%rdi), %rdi
callq 0xa836
movl %eax, 0x454(%rbx)
testb %al, 0x4(%rbx)
sete %cl
movb 0x8(%rbx), %dl
addb %cl, %cl
andb $0x3d, %dl
movl %eax, %esi
andb $-0x80, %sil
orb %dl, %sil
orb %cl, %sil
andb $0x40, %al
orb %sil, %al
movb %al, 0x8(%rbx)
popq %rbx
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/khedoros[P]khednes/cpu2.cpp
// Function: cpu::op_eor(int)
inline void cpu::op_eor(int addr) {
    temp=memory->read(addr);
    acc^=temp;
    set_sign(acc);
    set_zero(acc);
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
movq 0x10(%rdi), %rdi
callq 0xa836
movl %eax, 0x454(%rbx)
movb 0x4(%rbx), %cl
movb 0x8(%rbx), %dl
movl %ecx, %esi
xorb %al, %sil
movb %sil, 0x4(%rbx)
andb $-0x80, %sil
andb $0x7d, %dl
cmpb %al, %cl
sete %al
addb %al, %al
orb %sil, %al
orb %dl, %al
movb %al, 0x8(%rbx)
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O3/khedoros[P]khednes/cpu2.cpp
// Function: cpu::op_lsrm(int)
inline void cpu::op_lsrm(int addr) {
    temp=memory->read(addr);
    status.sign = 0;
    set_carry(temp&0x01);
    temp>>=(1);
    set_zero(temp);
    memory->write(addr,temp);
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %ebx
movq %rdi, %r14
movq 0x10(%rdi), %rdi
callq 0xa836
movb 0x8(%r14), %cl
movl %eax, %edx
andb $0x1, %dl
andb $0x7c, %cl
orb %dl, %cl
shrl %eax
movl %eax, 0x454(%r14)
testb %al, %al
sete %dl
addb %dl, %dl
orb %cl, %dl
movb %dl, 0x8(%r14)
movq 0x10(%r14), %rdi
movzbl %al, %edx
movl %ebx, %esi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0xab46
nop
// File: /workspace/github_cpp_makefile_star2_O3/khedoros[P]khednes/cpu2.cpp
// Function: cpu::op_adc(int)
inline void cpu::op_adc(int addr) {
    temp=memory->read(addr);
    temp2=temp+acc+status.carry;
    //if the operands have the same sign, AND      The operands have the same sign as the result
    if (!((acc ^ temp) & 0x80) && ((acc ^ temp2) & 0x80))
        status.verflow = 1;
    else
        status.verflow = 0;
    set_zero(temp2);
    set_sign(temp2);
    if((int(temp)+int(acc)+status.carry)>0xFF)
        status.carry = 1;
    else
        status.carry = 0;
    acc=temp2;
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
movq 0x10(%rdi), %rdi
callq 0xa836
movl %eax, 0x454(%rbx)
movzbl 0x4(%rbx), %edi
leal (%rax,%rdi), %edx
movzbl 0x8(%rbx), %esi
movl %esi, %ecx
andl $0x1, %ecx
addl %edx, %ecx
movl %ecx, 0x458(%rbx)
movl %edi, %r8d
xorb %al, %r8b
js 0xd3ea
xorb %cl, %dil
js 0xd3f0
andb $-0x41, %sil
jmp 0xd3f4
orb $0x40, %sil
testb %cl, %cl
sete %al
addb %al, %al
movl %esi, %edi
andb $0x7c, %dil
movl %ecx, %r8d
andb $-0x80, %r8b
orb %al, %r8b
orb %dil, %r8b
andb $0x1, %sil
movzbl %sil, %eax
addl %eax, %edx
cmpl $0x100, %edx            # imm = 0x100
setge %al
orb %r8b, %al
movb %al, 0x8(%rbx)
movb %cl, 0x4(%rbx)
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O3/khedoros[P]khednes/cpu2.cpp
// Function: cpu::ind()
inline int cpu::ind() {
    int addr=memory->read2(pc+1);
    if((addr&0xFF)==0xFF) {
        return (memory->read(addr))|((memory->read(addr-0xFF))<<(8));
    }
    else {
        return memory->read2(addr);
    }
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movq %rdi, %rbx
movq 0x10(%rdi), %rdi
movl (%rbx), %esi
incl %esi
callq 0xaaac
movl %eax, %ebp
movq 0x10(%rbx), %rdi
cmpb $-0x1, %bpl
jne 0xd54a
movl %ebp, %esi
callq 0xa836
movl %eax, %r14d
movq 0x10(%rbx), %rdi
addl $0xffffff01, %ebp       # imm = 0xFFFFFF01
movl %ebp, %esi
callq 0xa836
shll $0x8, %eax
orl %r14d, %eax
popq %rbx
popq %r14
popq %rbp
retq
movl %ebp, %esi
popq %rbx
popq %r14
popq %rbp
jmp 0xaaac
nop
// File: /workspace/github_cpp_makefile_star2_O3/khedoros[P]khednes/cpu2.cpp
// Function: cpu::op_cpy(int)
inline void cpu::op_cpy(int addr) {
    temp=memory->read(addr);
    if(y>=temp)
        status.carry = 1;
    else
        status.carry = 0;
    temp=y-temp;
    set_sign(temp);
    set_zero(temp);
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
movq 0x10(%rdi), %rdi
callq 0xa836
movzbl 0xd(%rbx), %ecx
subl %eax, %ecx
setae %al
movb 0x8(%rbx), %dl
andb $0x7c, %dl
orb %al, %dl
movl %ecx, 0x454(%rbx)
movl %ecx, %eax
andb $-0x80, %al
testb %cl, %cl
sete %cl
addb %cl, %cl
orb %al, %cl
orb %dl, %cl
movb %cl, 0x8(%rbx)
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O3/khedoros[P]khednes/cpu2.cpp
// Function: cpu::op_dec(int)
inline void cpu::op_dec(int addr) {
    temp=memory->read(addr);
    temp--;
    set_sign(temp);
    set_zero(temp);
    memory->write(addr,temp);
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %ebx
movq %rdi, %r14
movq 0x10(%rdi), %rdi
callq 0xa836
decl %eax
movl %eax, 0x454(%r14)
movl %eax, %ecx
andb $-0x80, %cl
movb 0x8(%r14), %dl
andb $0x7d, %dl
orb %cl, %dl
testb %al, %al
sete %cl
addb %cl, %cl
orb %dl, %cl
movb %cl, 0x8(%r14)
movq 0x10(%r14), %rdi
movzbl %al, %edx
movl %ebx, %esi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0xab46
nop
// File: /workspace/github_cpp_makefile_star2_O3/khedoros[P]khednes/cpu2.cpp
// Function: cpu::op_sbc(int)
inline void cpu::op_sbc(int addr) {
    temp=memory->read(addr);
    temp2=temp;
    temp+=(status.carry?0:1);
    set_zero(acc-temp);
    set_sign(acc-temp);
    if(((acc^temp)&0x80)>0&&((acc^temp2)&0x80)>0) //magic code from 6502 docs
        status.verflow = 1;
    else
        status.verflow = 0;

    if(acc>=temp) {
        status.carry = 1;
    }
    else {
        status.carry = 0;
    }
    acc-=temp;
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
movq 0x10(%rdi), %rdi
callq 0xa836
movl %eax, 0x458(%rbx)
movl 0x8(%rbx), %r8d
movl %r8d, %ecx
notl %ecx
andl $0x1, %ecx
addl %eax, %ecx
movl %ecx, 0x454(%rbx)
movzbl 0x4(%rbx), %esi
movl %esi, %edx
subb %cl, %dl
sete %dil
addb %dil, %dil
andb $0x7d, %r8b
orb %dil, %r8b
movl %edx, %edi
andb $-0x80, %dil
orb %r8b, %dil
movl %ecx, %r8d
xorb %sil, %r8b
jns 0xd73f
xorb %sil, %al
js 0xd745
andb $-0x41, %dil
jmp 0xd749
orb $0x40, %dil
cmpl %esi, %ecx
setbe %al
andb $-0x2, %dil
orb %al, %dil
movb %dil, 0x8(%rbx)
movb %dl, 0x4(%rbx)
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O3/khedoros[P]khednes/ppu3.cpp
// Function: ppu::set_mirror(unsigned int)
void ppu::set_mirror(unsigned int mode) {
    if(mode == VERT) {
        nt[0] = &(name_table[NT0_OFFSET]);
        nt[2] = nt[0];

        at[0] = &(name_table[AT0_OFFSET]);
        at[2] = at[0];

        nt[1] = &(name_table[NT1_OFFSET]);
        nt[3] = nt[1];

        at[1] = &(name_table[AT1_OFFSET]);
        at[3] = at[1];
    }
    else if(mode == HORIZ) {
        nt[0] = &(name_table[NT0_OFFSET]);
        nt[1] = nt[0];

        at[0] = &(name_table[AT0_OFFSET]);
        at[1] = at[0];

        nt[2] = &(name_table[NT1_OFFSET]);
        nt[3] = nt[2];

        at[2] = &(name_table[AT1_OFFSET]);
        at[3] = at[2];
    }
    else if(mode == FOUR_SCR) {
        nt[0] = &(name_table[NT0_OFFSET]);
        at[0] = &(name_table[AT0_OFFSET]);

        nt[1] = &(name_table[NT1_OFFSET]);
        at[1] = &(name_table[AT1_OFFSET]);

        nt[2] = &(name_table[NT2_OFFSET]);
        at[2] = &(name_table[AT2_OFFSET]);

        nt[3] = &(name_table[NT3_OFFSET]);
        at[3] = &(name_table[AT3_OFFSET]);
    }
    else { cout<<"WTF? Unrecognized mirror mode."<<endl;}
}

// Assembly:
cmpl $0x2, %esi
je 0xdcab
cmpl $0x1, %esi
je 0xdc5c
testl %esi, %esi
jne 0xdd1c
leaq 0x6ec(%rdi), %rax
movq %rax, 0x16f0(%rdi)
movq %rax, 0x1700(%rdi)
leaq 0xaac(%rdi), %rax
movq %rax, 0x1710(%rdi)
movq %rax, 0x1720(%rdi)
leaq 0xaec(%rdi), %rax
movq %rax, 0x16f8(%rdi)
movq %rax, 0x1708(%rdi)
leaq 0xeac(%rdi), %rax
movq %rax, 0x1718(%rdi)
jmp 0xdd14
leaq 0x6ec(%rdi), %rax
movq %rax, 0x16f0(%rdi)
movq %rax, 0x16f8(%rdi)
leaq 0xaac(%rdi), %rax
movq %rax, 0x1710(%rdi)
movq %rax, 0x1718(%rdi)
leaq 0xaec(%rdi), %rax
movq %rax, 0x1700(%rdi)
movq %rax, 0x1708(%rdi)
leaq 0xeac(%rdi), %rax
movq %rax, 0x1720(%rdi)
jmp 0xdd14
leaq 0x6ec(%rdi), %rax
movq %rax, 0x16f0(%rdi)
leaq 0xaac(%rdi), %rax
movq %rax, 0x1710(%rdi)
leaq 0xaec(%rdi), %rax
movq %rax, 0x16f8(%rdi)
leaq 0xeac(%rdi), %rax
movq %rax, 0x1718(%rdi)
leaq 0xeec(%rdi), %rax
movq %rax, 0x1700(%rdi)
leaq 0x12ac(%rdi), %rax
movq %rax, 0x1720(%rdi)
leaq 0x12ec(%rdi), %rax
movq %rax, 0x1708(%rdi)
leaq 0x16ac(%rdi), %rax
movq %rax, 0x1728(%rdi)
retq
pushq %rbx
movq 0xe28c(%rip), %rbx      # 0x1bfb0
leaq 0x783d(%rip), %rsi      # 0x15568
movl $0x1e, %edx
movq %rbx, %rdi
callq 0x4410
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4390
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4030
movq %rax, %rdi
popq %rbx
jmp 0x4290
// File: /workspace/github_cpp_makefile_star2_O3/khedoros[P]khednes/ppu3.cpp
// Function: ppu::clear_surfaces(bool)
void ppu::clear_surfaces(bool bank) {
    if(!bank)
        for(int tile = 0; tile < 256; ++tile)
            for(int palette = 0; palette < 8; ++palette)
                unget_Surface(0,tile,palette);
    else
        for(int tile = 0; tile < 256; ++tile)
            for(int palette = 0; palette < 8; ++palette)
                unget_Surface(1,tile,palette);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
addq $0x1850, %rdi           # imm = 0x1850
movq %rdi, 0x10(%rsp)
xorl %r15d, %r15d
testl %esi, %esi
je 0xde1f
movq %r15, (%rsp)
shlq $0x8, %r15
addq 0x10(%rsp), %r15
xorl %r13d, %r13d
movb $0x1, %bpl
movq %r13, 0x8(%rsp)
shlq $0x5, %r13
xorl %ebx, %ebx
shlq $0x4, %rbx
addq %r13, %rbx
addq %r15, %rbx
movb $0x1, %r14b
xorl %eax, %eax
movq 0x10000(%rbx,%rax,8), %rdi
testq %rdi, %rdi
je 0xddd7
leaq (%rbx,%rax,8), %r12
addq $0x10000, %r12          # imm = 0x10000
callq 0x4360
movq $0x0, (%r12)
movl $0x1, %eax
testb $0x1, %r14b
movl $0x0, %r14d
jne 0xddb2
movl $0x1, %ebx
testb $0x1, %bpl
movl $0x0, %ebp
jne 0xdda3
movq 0x8(%rsp), %r13
incq %r13
cmpq $0x8, %r13
jne 0xdd95
movq (%rsp), %r15
incq %r15
cmpq $0x100, %r15            # imm = 0x100
jne 0xdd85
jmp 0xdea9
movq %r15, (%rsp)
shlq $0x8, %r15
addq 0x10(%rsp), %r15
xorl %r13d, %r13d
movb $0x1, %bpl
movq %r13, 0x8(%rsp)
shlq $0x5, %r13
xorl %ebx, %ebx
shlq $0x4, %rbx
addq %r13, %rbx
addq %r15, %rbx
movb $0x1, %r14b
xorl %eax, %eax
movq (%rbx,%rax,8), %rdi
testq %rdi, %rdi
je 0xde66
leaq (%rbx,%rax,8), %r12
callq 0x4360
movq $0x0, (%r12)
movl $0x1, %eax
testb $0x1, %r14b
movl $0x0, %r14d
jne 0xde4c
movl $0x1, %ebx
testb $0x1, %bpl
movl $0x0, %ebp
jne 0xde3d
movq 0x8(%rsp), %r13
incq %r13
cmpq $0x8, %r13
jne 0xde2f
movq (%rsp), %r15
incq %r15
cmpq $0x100, %r15            # imm = 0x100
jne 0xde1f
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/khedoros[P]khednes/ppu3.cpp
// Function: ppu::unget_Surface(int, int, int)
void ppu::unget_Surface(int table, int tile, int palnum) {
    for(int hf = 0; hf < 2; ++hf) {
        for(int vf = 0; vf < 2; ++vf) {
            SDL_Surface * temp = tile_cache[table][tile][palnum][hf][vf];
            if(!temp) continue;
            SDL_FreeSurface(temp);
            tile_cache[table][tile][palnum][hf][vf] = NULL;
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
addq $0x1850, %rdi           # imm = 0x1850
movslq %esi, %rax
movslq %edx, %rdx
movslq %ecx, %rbx
movb $0x1, %bpl
xorl %r14d, %r14d
shlq $0x10, %rax
addq %rdi, %rax
shlq $0x8, %rdx
shlq $0x5, %rbx
addq %rdx, %rbx
addq %rax, %rbx
shlq $0x4, %r14
addq %rbx, %r14
movb $0x1, %r15b
xorl %eax, %eax
movq (%r14,%rax,8), %rdi
testq %rdi, %rdi
je 0xdf11
leaq (%r14,%rax,8), %r12
callq 0x4360
movq $0x0, (%r12)
movl $0x1, %eax
testb $0x1, %r15b
movl $0x0, %r15d
jne 0xdef7
movl $0x1, %r14d
testb $0x1, %bpl
movl $0x0, %ebp
jne 0xdeeb
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/khedoros[P]khednes/ppu3.cpp
// Function: ppu::~ppu()
ppu::~ppu() {
    //cout<<"Start ppu desctructor"<<endl;
    cout<<"Reads: "<<s.reads<<" ("<<s.twok2_reads<<" to 0x2002, "<<s.reads_during_render<<" during render) Writes: "<<s.writes<<" ("<<s.writes_during_render<<" during render) DMAs: "<<(s.dmas/256)<<endl<<"Total cycles: "<<s.cycles<<" Total frames: "<<frame<<endl;
    clear_surfaces(false);
    clear_surfaces(true);
    while(scroll_shifts.size() > 0) scroll_shifts.pop_front();
    //cout<<"End ppu destructor"<<endl<<endl;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rdi, %rbx
movq 0xe065(%rip), %rdi      # 0x1bfb0
leaq 0x7652(%rip), %rsi      # 0x155a4
movl $0x7, %edx
callq 0x4410
movl 0x1b8(%rbx), %esi
movq 0xe047(%rip), %rdi      # 0x1bfb0
callq 0x4280
movq %rax, %r14
leaq 0x8244(%rip), %rsi      # 0x161bc
movl $0x2, %edx
movq %rax, %rdi
callq 0x4410
movl 0x1bc(%rbx), %esi
movq %r14, %rdi
callq 0x4280
movq %rax, %r14
leaq 0x760f(%rip), %rsi      # 0x155ac
movl $0xc, %edx
movq %rax, %rdi
callq 0x4410
movl 0x1c0(%rbx), %esi
movq %r14, %rdi
callq 0x4280
movq %rax, %r14
leaq 0x75f7(%rip), %rsi      # 0x155b9
movl $0x18, %edx
movq %rax, %rdi
callq 0x4410
movl 0x1cc(%rbx), %esi
movq %r14, %rdi
callq 0x4280
movq %rax, %r14
leaq 0x81d5(%rip), %rsi      # 0x161bc
movl $0x2, %edx
movq %rax, %rdi
callq 0x4410
movl 0x1c4(%rbx), %esi
movq %r14, %rdi
callq 0x4280
movq %rax, %r14
leaq 0x75c6(%rip), %rsi      # 0x155d2
movl $0x16, %edx
movq %rax, %rdi
callq 0x4410
movl 0x1c8(%rbx), %esi
shrl $0x8, %esi
movq %r14, %rdi
callq 0x4280
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x4390
movsbl %al, %esi
movq %r14, %rdi
callq 0x4030
movq %rax, %rdi
callq 0x4290
movq %rax, %r14
leaq 0x758b(%rip), %rsi      # 0x155e9
movl $0xe, %edx
movq %rax, %rdi
callq 0x4410
movq 0x1d8(%rbx), %rsi
movq %r14, %rdi
callq 0x4280
movq %rax, %r14
leaq 0x7574(%rip), %rsi      # 0x155f8
movl $0xf, %edx
movq %rax, %rdi
callq 0x4410
movl 0x2185c(%rbx), %esi
movq %r14, %rdi
callq 0x45e0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x4390
movsbl %al, %esi
movq %r14, %rdi
callq 0x4030
movq %rax, %rdi
callq 0x4290
movq %rbx, %rdi
xorl %esi, %esi
callq 0xdd60
movq %rbx, %rdi
movl $0x1, %esi
callq 0xdd60
leaq 0x1f0(%rbx), %r15
movq 0x200(%rbx), %rax
testq %rax, %rax
je 0xe116
movq 0x1f0(%rbx), %r14
decq %rax
movq %rax, 0x200(%rbx)
movq %r14, %rdi
callq 0x4590
movq %r14, %rdi
callq 0x4380
jmp 0xe0e7
movq (%r15), %rdi
cmpq %r15, %rdi
je 0xe12e
movq (%rdi), %r14
callq 0x4380
movq %r14, %rdi
cmpq %r15, %r14
jne 0xe11e
addq $0x8, %rbx
movq %rbx, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0x12010
movq %rax, %rdi
callq 0xfcd9
nop
// File: /workspace/github_cpp_makefile_star2_O3/khedoros[P]khednes/ppu3.cpp
// Function: ppu::phase(unsigned int)
const ppu::ppu_phase ppu::phase(const unsigned int cycle) {
    int odd_diff = ((frame % 2 == 0)?0:1);
    ppu_phase choice = DUNNO;

    if(!control1.bits.show_bg && !control1.bits.show_sprites) choice = DISABLED; //DISABLED
    else if(cycle < (unsigned int)(VINT_LINES * CLK_PER_LINE)) choice = VINT; //VINT
    else if(cycle < (unsigned int)((VINT_LINES + PRE_RENDER_LINES) * CLK_PER_LINE - odd_diff)) choice = PRE_RENDER; //PRE_RENDER
    else if(cycle < (unsigned int)((VINT_LINES + PRE_RENDER_LINES + RENDER_LINES) * CLK_PER_LINE) - odd_diff) choice = RENDER; //RENDER
    else if(cycle < (unsigned int)((VINT_LINES + PRE_RENDER_LINES + RENDER_LINES + POST_RENDER_LINES) * CLK_PER_LINE) - odd_diff) choice = POST_RENDER; //POST_RENDER
    return choice;
}

// Assembly:
testb $0x18, 0x21854(%rdi)
je 0xe8f9
movl $0x1, %eax
cmpl $0x1aa4, %esi           # imm = 0x1AA4
jb 0xe8f8
movl 0x2185c(%rdi), %ecx
andl $0x1, %ecx
movl %ecx, %edx
xorl $0x1bf9, %edx           # imm = 0x1BF9
movl $0x2, %eax
cmpl %esi, %edx
ja 0xe8f8
movl %ecx, %edx
xorl $0x15ba9, %edx          # imm = 0x15BA9
movl $0x3, %eax
cmpl %esi, %edx
ja 0xe8f8
movl $0x15cfe, %edx          # imm = 0x15CFE
subl %ecx, %edx
xorl %eax, %eax
cmpl %esi, %edx
seta %al
shll $0x2, %eax
retq
movl $0x5, %eax
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/khedoros[P]khednes/ppu3.cpp
// Function: ppu::s0_hit_cycle(unsigned int)
unsigned int ppu::s0_hit_cycle(unsigned int cycle) {
    //TODO: This is an inexact estimate. It needs fixed, sometime.
    //      (Better than the last version of the estimate, though ;-)
    if(recalc_s0) {
        if(sprites[0].y + 1 > 239) spr_hit0_cycle = -1;
        else {
            int spry = sprites[0].y + 1;
            int sprx = sprites[0].x;
            bool hf = sprites[0].hflip;
            bool vf = sprites[0].vflip;
            int palnum = sprites[0].pal | 4;
            int tile = sprites[0].tile;
            int table = control0.sprite_table;
            SDL_Surface * s = get_Surface(table, tile, palnum, hf, vf);
            int px = -1;
            int py = -1;
            for(int x = 0; x < 8; ++x)
                for(int y = 0; y < 8; ++y) {
                    unsigned char t =((unsigned char *)s->pixels)[y*(s->pitch)+x];
                    if(t != NES_TRANSPARENT) {
                        px = x; py = y; /*cout<<"x: "<<x<<" y: "<<y<<" val: "<<int(t)<<endl;*/ goto loop_exit;
                    }
                }
            loop_exit:
            if(px == -1) spr_hit0_cycle = -1;
            else spr_hit0_cycle = ((spry + 1 + py) * CLK_PER_LINE + sprx + px);
            recalc_s0 = false;
        }
    }
    return spr_hit0_cycle;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movq %rdi, %rbx
cmpb $0x0, 0x6d5(%rdi)
je 0xe935
movl 0x208(%rbx), %eax
movzbl %al, %ebp
cmpl $0xef, %ebp
jb 0xe940
movl $0xffffffff, 0x6d0(%rbx) # imm = 0xFFFFFFFF
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0xe9d8
movl 0x6d0(%rbx), %eax
jmp 0xe9d8
movl %eax, %r14d
shrl $0x18, %r14d
movl %eax, %ecx
shrl $0x10, %ecx
andl $0x3, %ecx
orl $0x4, %ecx
movzbl %ah, %edx
movl 0x21850(%rbx), %esi
shrl $0x3, %esi
andl $0x1, %esi
movl %eax, %r8d
shrl $0x16, %r8d
andl $0x1, %r8d
shrl $0x17, %eax
andl $0x1, %eax
movq %rbx, %rdi
movl %eax, %r9d
callq 0xe9de
movq 0x20(%rax), %rcx
movslq 0x18(%rax), %rdx
imull $0x155, %ebp, %eax      # imm = 0x155
addl %r14d, %eax
addl $0x2aa, %eax            # imm = 0x2AA
xorl %esi, %esi
movq %rcx, %r8
xorl %edi, %edi
cmpb $0x4a, (%r8)
jne 0xe9c9
addq $-0x155, %rdi           # imm = 0xFEAB
addq %rdx, %r8
cmpq $-0xaa8, %rdi           # imm = 0xF558
jne 0xe99a
incq %rsi
incq %rax
incq %rcx
cmpq $0x8, %rsi
jne 0xe995
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0xe9cb
subl %edi, %eax
movl %eax, 0x6d0(%rbx)
movb $0x0, 0x6d5(%rbx)
popq %rbx
popq %r14
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/khedoros[P]khednes/ppu3.cpp
// Function: ppu::overflow_cycle(unsigned int)
unsigned int ppu::overflow_cycle(unsigned int cycle) {
    if(recalc_overflow) {
        int lines[240] = {0};
        spr_overflow_cycle = 0;
        for(int sprite = 0; sprite < 64; ++sprite) { //For each sprite...
            //Increment sprite count for each line that the sprite is visible on
            for(int y = sprites[sprite].y; (y < sprites[sprite].y + 8 + (control0.big_sprites * 8)) && y < 240; ++y)
                ++lines[y];
        }
        for(int line = 0; line < 240; ++line) {
            if(lines[line] > 8) {
                spr_overflow_cycle = line * CLK_PER_LINE;
                break;
            }
        }
        //if no overflow found, set the overflow value out of range (ie no overflow occurs)
        if(spr_overflow_cycle == 0) spr_overflow_cycle = -1;
        recalc_overflow = false;
    }
    return spr_overflow_cycle;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x3c0, %rsp            # imm = 0x3C0
movq %rdi, %rbx
cmpb $0x0, 0x6d4(%rdi)
je 0xec62
movq %rsp, %r14
xorl %r15d, %r15d
movl $0x3c0, %edx            # imm = 0x3C0
movq %r14, %rdi
xorl %esi, %esi
callq 0x4220
movl $0x0, 0x6cc(%rbx)
movl 0x21850(%rbx), %eax
shrl $0x2, %eax
andl $0x8, %eax
movl $0xf0, %ecx
movzbl 0x208(%rbx,%r15,4), %edx
leal (%rdx,%rax), %esi
addl $0x8, %esi
cmpl %ecx, %esi
cmovael %ecx, %esi
cmpl %esi, %edx
jae 0xec3d
movl %esi, %esi
incl (%rsp,%rdx,4)
incq %rdx
cmpq %rdx, %rsi
jne 0xec32
incq %r15
cmpq $0x40, %r15
jne 0xec18
xorl %eax, %eax
cmpl $0x8, (%r14)
jg 0xec6a
addq $-0x155, %rax           # imm = 0xFEAB
addq $0x4, %r14
cmpq $-0x13fb0, %rax         # imm = 0xFFFEC050
jne 0xec48
jmp 0xec74
movl 0x6cc(%rbx), %eax
jmp 0xec86
testq %rax, %rax
je 0xec74
negq %rax
jmp 0xec79
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, 0x6cc(%rbx)
movb $0x0, 0x6d4(%rbx)
addq $0x3c0, %rsp            # imm = 0x3C0
popq %rbx
popq %r14
popq %r15
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/khedoros[P]khednes/ppu3.cpp
// Function: ppu::set_scroll(int, int, int, int)
void ppu::set_scroll(int rx, int ry, int mod_col, int mod_row) {
    if(scroll_shifts.size() == 0 && rx != init_scroll_x) {
        //cout<<"First: Shifting scroll to "<<rx<<" at line "<<mod_row<<", frame "<<frame<<" (isx="<<init_scroll_x<<", size="<<scroll_shifts.size()<<")"<<endl;
        scroll_shifts.push_back(std::make_pair(rx,mod_row));
    }
    else if(scroll_shifts.size() > 0 && rx != scroll_shifts.back().first) {
        //cout<<"C1: "<<(scroll_shifts.size() == 0)<<" C2: "<<(rx!=init_scroll_x)<<endl;
        //cout<<"Second: Shifting scroll to "<<rx<<" at line "<<mod_row<<", frame "<<frame<<" (isx="<<init_scroll_x<<", size="<<scroll_shifts.size()<<")"<<endl;
        scroll_shifts.push_back(std::make_pair(rx,mod_row));
    }
    else {
        //cout<<"Filtering this scroll."<<endl;
        return;
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rdi, %rbx
cmpq $0x0, 0x200(%rdi)
je 0xecf7
movq 0x1f8(%rbx), %rax
cmpl %esi, 0x10(%rax)
je 0xecf1
leaq 0x1f0(%rbx), %r14
shlq $0x20, %r8
movl %esi, %r15d
orq %r8, %r15
movl $0x18, %edi
callq 0x43b0
movq %r15, 0x10(%rax)
movq %rax, %rdi
movq %r14, %rsi
callq 0x4080
incq 0x200(%rbx)
popq %rbx
popq %r14
popq %r15
retq
cmpl %esi, 0x1e8(%rbx)
jne 0xecc0
jmp 0xecf1
nop
// File: /workspace/github_cpp_makefile_star2_O3/khedoros[P]khednes/ppu3.cpp
// Function: ppu::get_nt_pal(int, int, int)
int ppu::get_nt_pal(int table, int tx, int ty) {
    byte at_val;
    at_val.val = at[table][(ty/4)*8+(tx/4)];
    if(tx % 4 < 2 && ty % 4 < 2) return at_val.pairs.first;
    else if(tx % 4 < 2) return at_val.pairs.third;
    else if(ty % 4 < 2) return at_val.pairs.second;
    else return at_val.pairs.fourth;
}

// Assembly:
movslq %esi, %rax
movq 0x1710(%rdi,%rax,8), %rax
leal 0x3(%rcx), %esi
testl %ecx, %ecx
cmovnsl %ecx, %esi
movl %esi, %edi
sarl $0x2, %edi
leal 0x3(%rdx), %r8d
testl %edx, %edx
cmovnsl %edx, %r8d
movl %r8d, %r9d
sarl $0x2, %r9d
leal (%r9,%rdi,8), %edi
movslq %edi, %rdi
movb (%rax,%rdi), %al
andl $-0x4, %r8d
subl %r8d, %edx
cmpl $0x2, %edx
setge %dil
andl $-0x4, %esi
subl %esi, %ecx
cmpl $0x2, %ecx
setge %sil
orb %dil, %sil
je 0xf8ec
cmpl $0x1, %edx
jg 0xf8e4
shrb $0x4, %al
jmp 0xf8ec
cmpl $0x1, %ecx
jg 0xf8f2
shrb $0x2, %al
andb $0x3, %al
movzbl %al, %eax
retq
shrb $0x6, %al
jmp 0xf8ee
nop
// File: /workspace/github_cpp_makefile_star2_O3/khedoros[P]khednes/ppu3.cpp
// Function: ppu::get_color(int, int, int)
int ppu::get_color(int tile, int x, int y) {
    if(y >= 8 || x >= 8 || tile >= 512) {
        cout<<"Tile: "<<tile<<" ("<<x<<", "<<y<<") doesn't exist."<<endl;
        return -1;
    }
    int address = tile * 16 + y;
    int byte1 = cart.get_cbyte(address);
    int byte2 = cart.get_cbyte(address + 8);
    return ((((byte1 & (128>>(x))) > 0)?1:0) + (((byte2 & (128>>(x))) > 0)?2:0));
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %ecx, %ebx
movl %edx, %ebp
movl %esi, %r14d
cmpl $0x1ff, %esi            # imm = 0x1FF
jg 0xf95f
cmpl $0x7, %ebp
jg 0xf95f
cmpl $0x8, %ebx
jge 0xf95f
movq %rdi, %r15
shll $0x4, %r14d
leal (%r14,%rbx), %esi
movq (%rdi), %rdi
callq 0xa03e
movl %eax, %r12d
movq (%r15), %rdi
leal (%r14,%rbx), %esi
addl $0x8, %esi
callq 0xa03e
movl $0x80, %edx
movl %ebp, %ecx
shrl %cl, %edx
xorl %ecx, %ecx
testl %edx, %r12d
setne %cl
xorl %esi, %esi
testl %edx, %eax
setne %sil
leal (%rcx,%rsi,2), %eax
jmp 0xfa0a
movq 0xc64a(%rip), %r15      # 0x1bfb0
leaq 0x5cc2(%rip), %rsi      # 0x1562f
movl $0x6, %edx
movq %r15, %rdi
callq 0x4410
movq %r15, %rdi
movl %r14d, %esi
callq 0x45e0
movq %rax, %r14
leaq 0x682d(%rip), %rsi      # 0x161bc
movl $0x2, %edx
movq %rax, %rdi
callq 0x4410
movq %r14, %rdi
movl %ebp, %esi
callq 0x45e0
movq %rax, %r14
leaq 0x6810(%rip), %rsi      # 0x161c0
movl $0x2, %edx
movq %rax, %rdi
callq 0x4410
movq %r14, %rdi
movl %ebx, %esi
callq 0x45e0
movq %rax, %rbx
leaq 0x5c65(%rip), %rsi      # 0x15636
movl $0x10, %edx
movq %rax, %rdi
callq 0x4410
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4390
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4030
movq %rax, %rdi
callq 0x4290
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/khedoros[P]khednes/ppu3.cpp
// Function: ppu::apply_updates_to(int)
void ppu::apply_updates_to(int curcycle) {
    //If there've been any mid-screen updates, apply them at the appropriate time (accurate to 1 vertical tile-ish
    rom::ppu_change_t changes = cart.cycle_forward(curcycle - (8 * 2* CLK_PER_LINE));
    if(changes.lo_crom == 1) clear_surfaces(false);
    if(changes.hi_crom == 1) clear_surfaces(true);
    if(changes.set_horiz == 1 || changes.set_vert == 1 || changes.set_4_scr == 1) set_mirror(cart.get_mode());
    if(changes.set_bg0 == 1) control0.bg_table = 0;
    if(changes.set_bg1 == 1) control0.bg_table = 1;
    if(changes.set_spr0 == 1) control0.sprite_table = 0;
    if(changes.set_spr1 == 1) control0.sprite_table = 1;
    int mode_count = changes.set_horiz + changes.set_vert + changes.set_4_scr;
    if(mode_count > 1) cout<<"Multiple mirroring modes set during one vertical tile of time!"<<endl; 
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movq %rdi, %rbx
movq (%rdi), %rdi
addl $0xffffeab0, %esi       # imm = 0xFFFFEAB0
callq 0xa078
movl %eax, %ebp
testb $0x1, %bpl
je 0xfa3b
movq %rbx, %rdi
xorl %esi, %esi
callq 0xdd60
testb $0x2, %bpl
je 0xfa4e
movq %rbx, %rdi
movl $0x1, %esi
callq 0xdd60
movl %ebp, %r14d
shrl $0x2, %r14d
andl $0x1, %r14d
movl %ebp, %eax
andl $0x18, %eax
orl %r14d, %eax
je 0xfa75
movq (%rbx), %rdi
callq 0xa01e
movq %rbx, %rdi
movl %eax, %esi
callq 0xdbf4
testb $0x20, %bpl
je 0xfa82
andb $-0x11, 0x21850(%rbx)
testb $0x40, %bpl
je 0xfa8f
orb $0x10, 0x21850(%rbx)
testb %bpl, %bpl
jns 0xfa9b
andb $-0x9, 0x21850(%rbx)
btl $0x8, %ebp
jae 0xfaa8
orb $0x8, 0x21850(%rbx)
movl %ebp, %eax
shrl $0x3, %eax
andl $0x1, %eax
btl $0x4, %ebp
adcl %eax, %r14d
cmpl $0x2, %r14d
jb 0xfb03
movq 0xc4ec(%rip), %rbx      # 0x1bfb0
leaq 0x5bb9(%rip), %rsi      # 0x15684
movl $0x3e, %edx
movq %rbx, %rdi
callq 0x4410
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4390
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4030
movq %rax, %rdi
popq %rbx
popq %r14
popq %rbp
jmp 0x4290
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/khedoros[P]khednes/ppu3.cpp
// Function: ppu::toggle_table_view()
void ppu::toggle_table_view() {
    table_view = !table_view;
    if(table_view)
        cout<<"Turn on table view"<<endl;
    else
        cout<<"Turn off table view"<<endl;
    screen.table_view(table_view);
    
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movb 0x21860(%rdi), %al
movl %eax, %ecx
xorb $0x1, %cl
movb %cl, 0x21860(%rdi)
movq 0xc475(%rip), %rdi      # 0x1bfb0
testb %al, %al
je 0xfb4d
leaq 0x5b2a(%rip), %rsi      # 0x15670
movl $0x13, %edx
jmp 0xfb59
leaq 0x5b09(%rip), %rsi      # 0x1565d
movl $0x12, %edx
callq 0x4410
movq 0xc44b(%rip), %r14      # 0x1bfb0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x4390
movsbl %al, %esi
movq %r14, %rdi
callq 0x4030
movq %rax, %rdi
callq 0x4290
movzbl 0x21860(%rbx), %esi
addq $0x8, %rbx
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x126ce
// File: /workspace/github_cpp_makefile_star2_O3/khedoros[P]khednes/ppu3.cpp
// Function: ppu::print_name_table()
void ppu::print_name_table() {
    bool vars[256] = {false};
    for(int big_y=0;big_y<1;++big_y) {
        for(int tile_y=0;tile_y<32;++tile_y) {
            for(int big_x=0;big_x<1;++big_x) {
                for(int tile_x=0;tile_x<32;++tile_x) {
                    printf("%02x ", name_table[tile_x+32*tile_y+1024*big_x+2048*big_y]);
                    if(tile_y < 30) {
                        vars[name_table[tile_x+32*tile_y+1024*big_x+2048*big_y]] = true;
                    }
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    printf("Contains these values: ");
    for(int i=0;i<256;++i) if(vars[i]) printf("%02x ", i);
    printf("\n");
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %rdi, %rbx
movq %rsp, %rdi
movl $0x100, %edx            # imm = 0x100
xorl %esi, %esi
callq 0x4220
addq $0x6ec, %rbx            # imm = 0x6EC
leaq 0x48ae(%rip), %r14      # 0x144a4
xorl %r15d, %r15d
xorl %r12d, %r12d
movzbl (%rbx,%r12), %esi
movq %r14, %rdi
xorl %eax, %eax
callq 0x4050
cmpq $0x1d, %r15
ja 0xfc1a
movzbl (%rbx,%r12), %eax
movb $0x1, (%rsp,%rax)
incq %r12
cmpq $0x20, %r12
jne 0xfbfc
movl $0xa, %edi
callq 0x44c0
incq %r15
addq $0x20, %rbx
cmpq $0x20, %r15
jne 0xfbf9
movl $0xa, %edi
callq 0x44c0
leaq 0x5a78(%rip), %rdi      # 0x156c3
xorl %eax, %eax
callq 0x4050
leaq 0x484b(%rip), %rbx      # 0x144a4
xorl %r14d, %r14d
cmpb $0x1, (%rsp,%r14)
jne 0xfc70
movq %rbx, %rdi
movl %r14d, %esi
xorl %eax, %eax
callq 0x4050
incq %r14
cmpq $0x100, %r14            # imm = 0x100
jne 0xfc5c
movl $0xa, %edi
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x44c0
// File: /workspace/github_cpp_makefile_star2_O3/khedoros[P]khednes/util.cpp
// Function: util::toggle_log(int)
void util::toggle_log(int origin) {
    if(!init) {
        for(int i=0;i<1000;++i) active[i] = false;
        init=true;
    }
    active[origin]=!(active[origin]);
    switch(origin) {
    case 1:
        printf("1 (CPU)");
        break;
    case 2:
        printf("2 (MAIN)");
        break;
    case 3:
        printf("3 (MEM)");
        break;
    case 4:
        printf("4 (PPU)");
        break;
    case 5:
        printf("5 (ROM)");
        break;
    case 6:
        printf("6 (UTIL)");
        break;
    case 7:
        printf("7 (WAV)");
        break;
    case 8:
        printf("8 (APU)");
        break;
    }
}

// Assembly:
cmpb $0x0, 0xc735(%rip)      # 0x1c460
jne 0xfd5e
xorl %ecx, %ecx
leaq 0xc732(%rip), %rax      # 0x1c468
movq %rcx, %rdx
movq $-0x2, %rsi
rolq %cl, %rsi
shrq $0x6, %rdx
andq %rsi, (%rax,%rdx,8)
incq %rcx
cmpq $0x3e8, %rcx            # imm = 0x3E8
jne 0xfd36
movb $0x1, 0xc702(%rip)      # 0x1c460
movslq %edi, %rax
movq %rax, %rcx
shrq $0x6, %rcx
leaq 0xc6f9(%rip), %rdx      # 0x1c468
movq (%rdx,%rcx,8), %rsi
movq %rsi, %rdi
btrq %rax, %rdi
movq %rsi, %r8
btsq %rax, %r8
btq %rax, %rsi
cmovbq %rdi, %r8
movq %r8, (%rdx,%rcx,8)
decl %eax
cmpl $0x7, %eax
ja 0xfdab
movl %eax, %eax
leaq 0x5d83(%rip), %rcx      # 0x15b20
movslq (%rcx,%rax,4), %rdi
addq %rcx, %rdi
xorl %eax, %eax
jmp 0x4050
retq
// File: /workspace/github_cpp_makefile_star2_O3/khedoros[P]khednes/util.cpp
// Function: util::debug(int, char const*, ...)
int util::debug(int orig,const char * fmt,...) {
    if(!init) {
        for(int i=0;i<1000;++i) {
            active[i]=false;
        }
        init=true;
    }

    if(active[orig]||(orig==999&&active[1])) {
        switch(orig) {
                case 1:
                        printf("CPU: ");
                        break;
                case 2:
                        printf("MAIN: ");
                        break;
                case 3:
                        printf("MEM: ");
                        break;
                case 4:
                        printf("PPU: ");
                        break;
                case 5:
                        printf("ROM: ");
                        break;
                case 6:
                        printf("UTIL: ");
                        break;
                case 7:
                        printf("WAV: ");
                        break;
                case 8:
                        printf("APU: ");
                        break;
                default:
                        break; //Don't print origin label
        }
        va_list ap;
        va_start(ap,fmt);
        return vprintf(fmt,ap);
    }
    else {
        return 0;
    }
}

// Assembly:
pushq %rbx
subq $0xd0, %rsp
movq %rsi, %rbx
testb %al, %al
je 0xfe10
movaps %xmm0, 0x50(%rsp)
movaps %xmm1, 0x60(%rsp)
movaps %xmm2, 0x70(%rsp)
movaps %xmm3, 0x80(%rsp)
movaps %xmm4, 0x90(%rsp)
movaps %xmm5, 0xa0(%rsp)
movaps %xmm6, 0xb0(%rsp)
movaps %xmm7, 0xc0(%rsp)
movq %rdx, 0x30(%rsp)
movq %rcx, 0x38(%rsp)
movq %r8, 0x40(%rsp)
movq %r9, 0x48(%rsp)
cmpb $0x0, 0xc635(%rip)      # 0x1c460
jne 0xfe5e
xorl %ecx, %ecx
leaq 0xc632(%rip), %rax      # 0x1c468
movq %rcx, %rdx
movq $-0x2, %rsi
rolq %cl, %rsi
shrq $0x6, %rdx
andq %rsi, (%rax,%rdx,8)
incq %rcx
cmpq $0x3e8, %rcx            # imm = 0x3E8
jne 0xfe36
movb $0x1, 0xc602(%rip)      # 0x1c460
movslq %edi, %rax
movq %rax, %rcx
shrq $0x6, %rcx
leaq 0xc5f9(%rip), %rdx      # 0x1c468
movq (%rdx,%rcx,8), %rcx
btq %rax, %rcx
jae 0xfe99
decl %edi
cmpl $0x7, %edi
ja 0xfeac
movl %edi, %eax
leaq 0x5cb7(%rip), %rcx      # 0x15b40
movslq (%rcx,%rax,4), %rdi
addq %rcx, %rdi
xorl %eax, %eax
callq 0x4050
jmp 0xfeac
xorl %eax, %eax
cmpl $0x3e7, %edi            # imm = 0x3E7
jne 0xfed9
testb $0x2, 0xc5be(%rip)      # 0x1c468
je 0xfed9
leaq 0x20(%rsp), %rax
movq %rsp, %rsi
movq %rax, 0x10(%rsi)
leaq 0xe0(%rsp), %rax
movq %rax, 0x8(%rsi)
movabsq $0x3000000010, %rax     # imm = 0x3000000010
movq %rax, (%rsi)
movq %rbx, %rdi
callq 0x43c0
addq $0xd0, %rsp
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O3/khedoros[P]khednes/apu.cpp
// Function: my_callback(void*, unsigned char*, int)
void my_callback(void * ud, Uint8 * stream, int len) {
    //cout<<"Actual callback size: "<<len<<endl;
    userdata * dat = (userdata *)(ud);
    //dat->first = !(dat->first);
    //Copy the audio data
    //cout<<"Read: Index: "<<(dat->apui->buffer_read_pos)<<" Samples: "<<(len*(dat->apui->buffer_read_pos))<<" -> "<<(len*(dat->apui->buffer_read_pos+1))<<" len: "<<len<<endl;
    memcpy(stream, &dat->buffer[len*(dat->apui->buffer_read_pos)], len);
    if(dat->buffered >= len) {
        dat->buffered -= len;
        dat->apui->buffer_read_pos++;
        dat->apui->buffer_read_pos%=dat->apui->SAMPLES_PER_FRAME;
        //cout<<"Consume "<<len<<endl;
    }
    else {
        cout<<"Underbuffered by "<<len - dat->buffered<<" bytes!"<<endl;
        //memset(stream + dat->buffered, 0, len - dat->buffered);
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movl %edx, %ebx
movq %rsi, %rax
movq %rdi, %r14
movslq %edx, %r15
movq 0x8(%rdi), %rcx
movq 0x10(%rcx), %rsi
imulq %r15, %rsi
addq (%rdi), %rsi
movq %rax, %rdi
movq %r15, %rdx
callq 0x4330
movl 0x14(%r14), %eax
subl %r15d, %eax
jge 0x10753
movq 0xb8c2(%rip), %r15      # 0x1bfb0
leaq 0x572b(%rip), %rsi      # 0x15e20
movl $0x11, %edx
movq %r15, %rdi
callq 0x4410
subl 0x14(%r14), %ebx
movq %r15, %rdi
movl %ebx, %esi
callq 0x45e0
movq %rax, %rbx
leaq 0x5718(%rip), %rsi      # 0x15e32
movl $0x7, %edx
movq %rax, %rdi
callq 0x4410
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4390
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4030
movq %rax, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0x4290
movl %eax, 0x14(%r14)
movq 0x8(%r14), %rcx
movq 0x10(%rcx), %rsi
leaq 0x1(%rsi), %rax
movabsq $-0x4dabb629196d0487, %rdx # imm = 0xB25449D6E692FB79
mulq %rdx
shrq $0x9, %rdx
imulq $0x2df, %rdx, %rax      # imm = 0x2DF
negq %rax
addq %rsi, %rax
incq %rax
movq %rax, 0x10(%rcx)
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_cpp_makefile_star2_O3/khedoros[P]khednes/apu.cpp
// Function: apu::apu(bool)
apu::apu(bool headless/* =false */) {
    //std::cout<<"apu constructor"<<std::endl;
    stat.val = 0;
    linear_cntr = 0;
    enable_linear_cntr = false;
    pin1_enabled = 0;
    pin2_enabled = 0;
    noise_flip_flop = false;
    framecounter_pos = 0;
    framecounter_reset = 89490;
    enable_irq = false;
    counter_mode = 0;

    dmc_pcm_data = 0;
    dmc_addr=0;
    dmc_addr_reset=0xc000;
    dmc_freq_cnt=0;
    dmc_freq=0;
    dmc_length=0;
    dmc_gen_irq=false;
    dmc_loop=false;

    buffer_read_pos = 0;
    buffer_write_pos = 0;

    for(int i=0; i<5; ++i) {
        enabled[i] = false;
        vol[i] = 0;
        decay_count[i] = 0;
        enable_decay[i] = false;
        loop_decay[i] = false;
        decay_vol_lvl[i] = 0;
        duty_cycle[i] = 0;
        sweep_enable[i] = false;
        sweep_shift[i] = 0;
        sweep_dir[i] = 0;
        sweep_rate[i] = 0;
        sweep_count[i] = 0;
        length[i] = 0;
        wavelength_count_reset[i] = 0;
        wave_pos[i] = 0;
    }

    id = 0;
    frame = 0;
    write_pos = 1;

    init(headless);
    generate_arrays();
    
    //Unpause the audio stream
    if(id > 0)
        SDL_PauseAudioDevice(id, false);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
leaq 0x38(%rdi), %r14
xorps %xmm0, %xmm0
movups %xmm0, 0x38(%rdi)
xorl %eax, %eax
movq %rax, 0x48(%rdi)
leaq 0x50(%rdi), %r15
movq %r15, 0x58(%rdi)
movq %r15, 0x50(%rdi)
movq %rax, 0x60(%rdi)
movb %al, 0xb0(%rdi)
movl %eax, 0x118(%rdi)
movb %al, 0x11c(%rdi)
movabsq $0x15d9200000000, %rcx  # imm = 0x15D9200000000
movq %rcx, 0x1d0(%rdi)
movq %rax, 0x1c4(%rdi)
movb %al, 0x1cc(%rdi)
movb %al, 0x1d8(%rdi)
movl %eax, 0x1dc(%rdi)
movq %rax, 0x220(%rdi)
movl $0xc000, 0x228(%rdi)    # imm = 0xC000
movl %eax, 0x238(%rdi)
movl %eax, 0xb4(%rdi)
movb %al, 0xb8(%rdi)
movb %al, 0x121(%rdi)
movl %eax, 0x11d(%rdi)
movl %eax, 0x1c0(%rdi)
movups %xmm0, 0x1b0(%rdi)
movl %eax, 0x68(%rdi)
movl %eax, 0x244(%rdi)
movups %xmm0, 0x8(%rdi)
movw %ax, 0xec(%rdi)
movups %xmm0, 0xdc(%rdi)
movups %xmm0, 0xcc(%rdi)
movups %xmm0, 0xbc(%rdi)
movq %rax, 0x110(%rdi)
movups %xmm0, 0x100(%rdi)
movups %xmm0, 0xf0(%rdi)
movq %rax, 0x194(%rdi)
movups %xmm0, 0x184(%rdi)
movups %xmm0, 0x174(%rdi)
movups %xmm0, 0x164(%rdi)
movups %xmm0, 0x154(%rdi)
movups %xmm0, 0x144(%rdi)
movups %xmm0, 0x134(%rdi)
movups %xmm0, 0x124(%rdi)
movw %ax, 0x234(%rdi)
movq %rax, 0x22c(%rdi)
movb $0x1, (%rdi)
callq 0x107a2
movq %rbx, %rdi
callq 0x10bca
movl 0x68(%rbx), %edi
testl %edi, %edi
je 0x10ea8
xorl %esi, %esi
callq 0x4470
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq %rax, %rbx
movq (%r15), %rdi
cmpq %r15, %rdi
je 0x10ecf
movq (%rdi), %r12
callq 0x4380
movq %r12, %rdi
cmpq %r15, %r12
jne 0x10ebf
movq (%r14), %rdi
testq %rdi, %rdi
je 0x10edc
callq 0x4380
movq %rbx, %rdi
callq 0x4610