LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_cpp_makefile_star2_O2/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 %rbx
pushq %rax
movq %rdi, %rbx
xorl %ebp, %ebp
testl %esi, %esi
je 0xc6ee
pushq $0x1
popq %r14
cmpl $0x100, %ebp            # imm = 0x100
je 0xc717
xorl %r15d, %r15d
cmpl $0x8, %r15d
je 0xc6ea
movq %rbx, %rdi
movl %r14d, %esi
movl %ebp, %edx
movl %r15d, %ecx
callq 0xc722
incl %r15d
jmp 0xc6cf
incl %ebp
jmp 0xc6c4
cmpl $0x100, %ebp            # imm = 0x100
je 0xc717
xorl %r14d, %r14d
cmpl $0x8, %r14d
je 0xc713
movq %rbx, %rdi
xorl %esi, %esi
movl %ebp, %edx
movl %r14d, %ecx
callq 0xc722
incl %r14d
jmp 0xc6f9
incl %ebp
jmp 0xc6ee
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/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 %r15
pushq %r14
pushq %rbx
movslq %esi, %rax
movslq %edx, %rdx
movslq %ecx, %rcx
shlq $0x10, %rax
shlq $0x8, %rdx
addq %rax, %rdx
shlq $0x5, %rcx
addq %rdx, %rcx
leaq (%rdi,%rcx), %rbx
addq $0x1850, %rbx           # imm = 0x1850
xorl %r14d, %r14d
cmpq $0x2, %r14
je 0xc780
xorl %r15d, %r15d
cmpq $0x2, %r15
je 0xc777
movq (%rbx,%r15,8), %rdi
testq %rdi, %rdi
je 0xc772
callq 0x4350
andq $0x0, (%rbx,%r15,8)
incq %r15
jmp 0xc759
incq %r14
addq $0x10, %rbx
jmp 0xc750
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_cpp_makefile_star2_O2/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 %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0xe81c(%rip), %rdi      # 0x1afb0
leaq 0x6db7(%rip), %rsi      # 0x13552
callq 0x4390
movl 0x1b8(%rbx), %esi
movq %rax, %rdi
callq 0x4270
leaq 0x79d7(%rip), %rsi      # 0x1418c
movq %rax, %rdi
callq 0x4390
movl 0x1bc(%rbx), %esi
movq %rax, %rdi
callq 0x4270
leaq 0x6d88(%rip), %rsi      # 0x1355a
movq %rax, %rdi
callq 0x4390
movl 0x1c0(%rbx), %esi
movq %rax, %rdi
callq 0x4270
leaq 0x6d78(%rip), %rsi      # 0x13567
movq %rax, %rdi
callq 0x4390
movl 0x1cc(%rbx), %esi
movq %rax, %rdi
callq 0x4270
leaq 0x7980(%rip), %rsi      # 0x1418c
movq %rax, %rdi
callq 0x4390
movl 0x1c4(%rbx), %esi
movq %rax, %rdi
callq 0x4270
leaq 0x6d57(%rip), %rsi      # 0x13580
movq %rax, %rdi
callq 0x4390
movl 0x1c8(%rbx), %esi
shrl $0x8, %esi
movq %rax, %rdi
callq 0x4270
movq %rax, %rdi
callq 0x41c0
leaq 0x6d46(%rip), %rsi      # 0x13597
movq %rax, %rdi
callq 0x4390
movq 0x1d8(%rbx), %rsi
movq %rax, %rdi
callq 0x4270
leaq 0x6d37(%rip), %rsi      # 0x135a6
movq %rax, %rdi
callq 0x4390
movl 0x2185c(%rbx), %esi
movq %rax, %rdi
callq 0x4610
movq %rax, %rdi
callq 0x41c0
movq %rbx, %rdi
xorl %esi, %esi
callq 0xc6b0
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0xc6b0
leaq 0x1f0(%rbx), %r14
cmpq $0x0, 0x200(%rbx)
je 0xc8bd
movq %r14, %rdi
callq 0xe0b4
jmp 0xc8a9
movq %r14, %rdi
callq 0xe0c8
addq $0x8, %rbx
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0xff48
movq %rax, %rdi
callq 0x8ff5
// File: /workspace/github_cpp_makefile_star2_O2/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 0xce5d
cmpl $0x1aa4, %esi           # imm = 0x1AA4
jae 0xce61
pushq $0x1
jmp 0xce88
pushq $0x5
jmp 0xce88
movl 0x2185c(%rdi), %eax
andl $0x1, %eax
movl %eax, %ecx
xorl $0x1bf9, %ecx           # imm = 0x1BF9
cmpl %esi, %ecx
jbe 0xce7a
pushq $0x2
jmp 0xce88
movl %eax, %ecx
xorl $0x15ba9, %ecx          # imm = 0x15BA9
cmpl %esi, %ecx
jbe 0xce8a
pushq $0x3
popq %rax
retq
movl $0x15cfe, %ecx          # imm = 0x15CFE
subl %eax, %ecx
xorl %eax, %eax
cmpl %esi, %ecx
seta %al
shll $0x2, %eax
retq
// File: /workspace/github_cpp_makefile_star2_O2/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 0xcecc
movl 0x208(%rbx), %eax
movzbl %al, %ebp
cmpl $0xef, %ebp
jb 0xced7
orl $-0x1, 0x6d0(%rbx)
pushq $-0x1
popq %rax
jmp 0xcf75
movl 0x6d0(%rbx), %eax
jmp 0xcf75
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 0xcf7a
movq 0x20(%rax), %rdx
movslq 0x18(%rax), %rsi
imull $0x155, %ebp, %eax      # imm = 0x155
leal (%r14,%rax), %ecx
addl $0x2aa, %ecx            # imm = 0x2AA
xorl %edi, %edi
pushq $-0x1
popq %rax
cmpq $0x8, %rdi
je 0xcf68
movq %rdx, %r9
xorl %r8d, %r8d
cmpq $-0xaa8, %r8            # imm = 0xF558
je 0xcf58
cmpb $0x4a, (%r9)
jne 0xcf63
addq $-0x155, %r8            # imm = 0xFEAB
addq %rsi, %r9
jmp 0xcf3d
incq %rdi
incq %rcx
incq %rdx
jmp 0xcf31
subl %r8d, %ecx
movl %ecx, %eax
movl %eax, 0x6d0(%rbx)
movb $0x0, 0x6d5(%rbx)
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/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 0xd1cb
movq %rsp, %r14
xorl %r15d, %r15d
movl $0x3c0, %edx            # imm = 0x3C0
movq %r14, %rdi
xorl %esi, %esi
callq 0x4210
andl $0x0, 0x6cc(%rbx)
movl 0x21850(%rbx), %eax
shrl $0x2, %eax
andl $0x8, %eax
movl $0xf0, %ecx
cmpq $0x40, %r15
je 0xd1d3
movzbl 0x208(%rbx,%r15,4), %edx
leal (%rdx,%rax), %esi
addl $0x8, %esi
cmpl %ecx, %esi
cmovael %ecx, %esi
cmpq %rsi, %rdx
jae 0xd1c6
incl (%rsp,%rdx,4)
incq %rdx
jmp 0xd1b9
incq %r15
jmp 0xd19f
movl 0x6cc(%rbx), %eax
jmp 0xd20b
xorl %ecx, %ecx
pushq $-0x1
popq %rax
cmpq $-0x13fb0, %rcx         # imm = 0xFFFEC050
je 0xd1fe
cmpl $0x8, (%r14)
jg 0xd1f4
addq $-0x155, %rcx           # imm = 0xFEAB
addq $0x4, %r14
jmp 0xd1d8
testq %rcx, %rcx
je 0xd1fe
negq %rcx
movl %ecx, %eax
movl %eax, 0x6cc(%rbx)
movb $0x0, 0x6d4(%rbx)
addq $0x3c0, %rsp            # imm = 0x3C0
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_cpp_makefile_star2_O2/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 %rax
movq %rdi, %rax
addq $0x1f0, %rdi            # imm = 0x1F0
cmpq $0x0, 0x200(%rax)
je 0xd25d
movq 0x1f8(%rax), %rax
cmpl %esi, 0x10(%rax)
je 0xd25b
shlq $0x20, %r8
movl %esi, %eax
orq %r8, %rax
movq %rsp, %rsi
movq %rax, (%rsi)
callq 0xe0bc
popq %rax
retq
cmpl %esi, 0x1e8(%rax)
jne 0xd247
jmp 0xd25b
nop
// File: /workspace/github_cpp_makefile_star2_O2/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:
movl %ecx, %eax
movl %edx, %r8d
movslq %esi, %rcx
movq 0x1710(%rdi,%rcx,8), %rdi
pushq $0x4
popq %r9
cltd
idivl %r9d
movl %edx, %ecx
movl %eax, %esi
movl %r8d, %eax
cltd
idivl %r9d
leal (%rax,%rsi,8), %eax
cltq
movb (%rdi,%rax), %al
cmpl $0x2, %edx
setge %sil
cmpl $0x2, %ecx
setge %dil
orb %sil, %dil
je 0xdd7a
cmpl $0x1, %edx
jg 0xdd72
shrb $0x4, %al
jmp 0xdd7a
cmpl $0x1, %ecx
jg 0xdd80
shrb $0x2, %al
andb $0x3, %al
movzbl %al, %eax
retq
shrb $0x6, %al
jmp 0xdd7c
nop
// File: /workspace/github_cpp_makefile_star2_O2/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 0xddea
cmpl $0x7, %ebp
jg 0xddea
cmpl $0x8, %ebx
jge 0xddea
movq %rdi, %r15
shll $0x4, %r14d
leal (%r14,%rbx), %esi
movq (%rdi), %rdi
callq 0x8f1a
movl %eax, %r12d
movq (%r15), %rdi
leal (%r14,%rbx), %esi
addl $0x8, %esi
callq 0x8f1a
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 0xde54
movq 0xd1bf(%rip), %rdi      # 0x1afb0
leaq 0x57e5(%rip), %rsi      # 0x135dd
callq 0x4390
movq %rax, %rdi
movl %r14d, %esi
callq 0x4610
leaq 0x637d(%rip), %rsi      # 0x1418c
movq %rax, %rdi
callq 0x4390
movq %rax, %rdi
movl %ebp, %esi
callq 0x4610
leaq 0x6368(%rip), %rsi      # 0x14190
movq %rax, %rdi
callq 0x4390
movq %rax, %rdi
movl %ebx, %esi
callq 0x4610
leaq 0x57a3(%rip), %rsi      # 0x135e4
movq %rax, %rdi
callq 0x4390
movq %rax, %rdi
callq 0x41c0
pushq $-0x1
popq %rax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/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 0x8f54
movl %eax, %ebp
testb $0x1, %bpl
je 0xde85
movq %rbx, %rdi
xorl %esi, %esi
callq 0xc6b0
testb $0x2, %bpl
je 0xde96
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0xc6b0
movl %ebp, %r14d
shrl $0x2, %r14d
andl $0x1, %r14d
movl %ebp, %eax
andl $0x18, %eax
orl %r14d, %eax
je 0xdebd
movq (%rbx), %rdi
callq 0x8efa
movq %rbx, %rdi
movl %eax, %esi
callq 0xc56a
testb $0x20, %bpl
je 0xdeca
andb $-0x11, 0x21850(%rbx)
testb $0x40, %bpl
je 0xded7
orb $0x10, 0x21850(%rbx)
testb %bpl, %bpl
jns 0xdee3
andb $-0x9, 0x21850(%rbx)
btl $0x8, %ebp
jae 0xdef0
orb $0x8, 0x21850(%rbx)
movl %ebp, %eax
shrl $0x3, %eax
andl $0x1, %eax
btl $0x4, %ebp
adcl %eax, %r14d
cmpl $0x2, %r14d
jb 0xdf24
movq 0xd0a4(%rip), %rdi      # 0x1afb0
leaq 0x571f(%rip), %rsi      # 0x13632
callq 0x4390
movq %rax, %rdi
popq %rbx
popq %r14
popq %rbp
jmp 0x41c0
popq %rbx
popq %r14
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/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 %rbx
movq %rdi, %rbx
movb 0x21860(%rdi), %al
movl %eax, %ecx
xorb $0x1, %cl
movb %cl, 0x21860(%rdi)
leaq 0x56c4(%rip), %rcx      # 0x1361e
leaq 0x56aa(%rip), %rsi      # 0x1360b
testb %al, %al
cmovneq %rcx, %rsi
movq 0xd042(%rip), %rdi      # 0x1afb0
callq 0x4390
movq %rax, %rdi
callq 0x41c0
movzbl 0x21860(%rbx), %esi
addq $0x8, %rbx
movq %rbx, %rdi
popq %rbx
jmp 0x10518
nop
// File: /workspace/github_cpp_makefile_star2_O2/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 %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x100, %rsp            # imm = 0x100
movq %rdi, %rbx
movq %rsp, %rdi
movl $0x100, %edx            # imm = 0x100
xorl %esi, %esi
callq 0x4210
addq $0x6ec, %rbx            # imm = 0x6EC
pushq $0xa
popq %rbp
leaq 0x44a6(%rip), %r14      # 0x12488
xorl %r15d, %r15d
cmpq $0x20, %r15
je 0xe027
xorl %r12d, %r12d
cmpq $0x20, %r12
je 0xe017
movzbl (%rbx,%r12), %esi
movq %r14, %rdi
xorl %eax, %eax
callq 0x4040
cmpq $0x1d, %r15
ja 0xe012
movzbl (%rbx,%r12), %eax
movb $0x1, (%rsp,%rax)
incq %r12
jmp 0xdfee
movl %ebp, %edi
callq 0x44b0
incq %r15
addq $0x20, %rbx
jmp 0xdfe5
pushq $0xa
popq %rdi
callq 0x44b0
leaq 0x563b(%rip), %rdi      # 0x13671
xorl %eax, %eax
callq 0x4040
leaq 0x4444(%rip), %rbx      # 0x12488
xorl %r14d, %r14d
cmpq $0x100, %r14            # imm = 0x100
je 0xe069
cmpb $0x1, (%rsp,%r14)
jne 0xe064
movq %rbx, %rdi
movl %r14d, %esi
xorl %eax, %eax
callq 0x4040
incq %r14
jmp 0xe047
pushq $0xa
popq %rdi
addq $0x100, %rsp            # imm = 0x100
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x44b0
// File: /workspace/github_cpp_makefile_star2_O2/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, 0xd225(%rip)      # 0x1b470
jne 0xe27f
xorl %ecx, %ecx
leaq 0xd222(%rip), %rax      # 0x1b478
pushq $-0x2
popq %rdx
cmpq $0x3e8, %rcx            # imm = 0x3E8
je 0xe278
movq %rcx, %rsi
shrq $0x6, %rsi
movq %rdx, %r8
rolq %cl, %r8
andq %r8, (%rax,%rsi,8)
incq %rcx
jmp 0xe259
movb $0x1, 0xd1f1(%rip)      # 0x1b470
pushq %rbx
subq $0x10, %rsp
movslq %edi, %rbx
movq %rbx, %rax
shrq $0x6, %rax
leaq 0xd1e3(%rip), %rcx      # 0x1b478
leaq (%rcx,%rax,8), %rax
movl %ebx, %ecx
andl $0x3f, %ecx
movq (%rax), %rdx
xorl %esi, %esi
btq %rcx, %rdx
setae %sil
movq %rsp, %rdi
movq %rax, (%rdi)
movq %rcx, 0x8(%rdi)
callq 0xe830
decl %ebx
cmpl $0x7, %ebx
ja 0xe2d8
movl %ebx, %eax
leaq 0x5806(%rip), %rcx      # 0x13ad0
movslq (%rcx,%rax,4), %rdi
addq %rcx, %rdi
xorl %eax, %eax
callq 0x4040
addq $0x10, %rsp
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O2/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 0xe342
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, 0xd113(%rip)      # 0x1b470
jne 0xe391
xorl %ecx, %ecx
leaq 0xd110(%rip), %rax      # 0x1b478
pushq $-0x2
popq %rdx
cmpq $0x3e8, %rcx            # imm = 0x3E8
je 0xe38a
movq %rcx, %rsi
shrq $0x6, %rsi
movq %rdx, %r8
rolq %cl, %r8
andq %r8, (%rax,%rsi,8)
incq %rcx
jmp 0xe36b
movb $0x1, 0xd0df(%rip)      # 0x1b470
movslq %edi, %rax
movq %rax, %rcx
shrq $0x6, %rcx
leaq 0xd0d6(%rip), %rdx      # 0x1b478
movq (%rdx,%rcx,8), %rcx
btq %rax, %rcx
jae 0xe3cc
decl %edi
cmpl $0x7, %edi
ja 0xe3df
movl %edi, %eax
leaq 0x5734(%rip), %rcx      # 0x13af0
movslq (%rcx,%rax,4), %rdi
addq %rcx, %rdi
xorl %eax, %eax
callq 0x4040
jmp 0xe3df
xorl %eax, %eax
cmpl $0x3e7, %edi            # imm = 0x3E7
jne 0xe40c
testb $0x2, 0xd09b(%rip)      # 0x1b478
je 0xe40c
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 0x43b0
addq $0xd0, %rsp
popq %rbx
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/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 0x4310
movl 0x14(%r14), %eax
subl %r15d, %eax
jge 0xe8e8
movq 0xc6fe(%rip), %rdi      # 0x1afb0
leaq 0x5527(%rip), %rsi      # 0x13de0
callq 0x4390
subl 0x14(%r14), %ebx
movq %rax, %rdi
movl %ebx, %esi
callq 0x4610
leaq 0x551f(%rip), %rsi      # 0x13df2
movq %rax, %rdi
callq 0x4390
movq %rax, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0x41c0
movl %eax, 0x14(%r14)
movq 0x8(%r14), %rcx
movq 0x10(%rcx), %rax
incq %rax
movl $0x2df, %esi            # imm = 0x2DF
xorl %edx, %edx
divq %rsi
movq %rdx, 0x10(%rcx)
popq %rbx
popq %r14
popq %r15
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/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 %rbx
movq %rdi, %r14
xorps %xmm0, %xmm0
andq $0x0, 0x48(%rdi)
movups %xmm0, 0x38(%rdi)
leaq 0x50(%rdi), %rbx
movq %rbx, 0x58(%rdi)
movq %rbx, 0x50(%rdi)
andq $0x0, 0x60(%rdi)
xorl %eax, %eax
movb %al, 0xb0(%rdi)
andl $0x0, 0x118(%rdi)
movb %al, 0x11c(%rdi)
movabsq $0x15d9200000000, %rcx  # imm = 0x15D9200000000
movq %rcx, 0x1d0(%rdi)
movb %al, 0x1cc(%rdi)
andq $0x0, 0x1c4(%rdi)
movb %al, 0x1d8(%rdi)
andl $0x0, 0x1dc(%rdi)
leaq 0x38(%rdi), %r15
andq $0x0, 0x220(%rdi)
movl $0xc000, 0x228(%rdi)    # imm = 0xC000
andl $0x0, 0x238(%rdi)
movups %xmm0, 0x8(%rdi)
andw $0x0, 0x234(%rdi)
andq $0x0, 0x22c(%rdi)
movl $0xb4, %ecx
cmpq $0xb9, %rcx
je 0xef05
movb %al, (%r14,%rcx)
andl $0x0, -0x214(%r14,%rcx,4)
andl $0x0, -0x200(%r14,%rcx,4)
movb %al, 0x30(%r14,%rcx)
movb %al, 0x35(%r14,%rcx)
andl $0x0, -0x1e0(%r14,%rcx,4)
andl $0x0, -0x1cc(%r14,%rcx,4)
movb %al, 0x69(%r14,%rcx)
andl $0x0, -0x1ac(%r14,%rcx,4)
andl $0x0, -0x198(%r14,%rcx,4)
andl $0x0, -0x184(%r14,%rcx,4)
andl $0x0, -0x170(%r14,%rcx,4)
andl $0x0, -0x15c(%r14,%rcx,4)
andl $0x0, -0x148(%r14,%rcx,4)
andl $0x0, -0x120(%r14,%rcx,4)
incq %rcx
jmp 0xee7e
andl $0x0, 0x68(%r14)
andl $0x0, 0x244(%r14)
movb $0x1, (%r14)
movzbl %sil, %esi
movq %r14, %rdi
callq 0xe920
movq %r14, %rdi
callq 0xebf8
movl 0x68(%r14), %edi
testl %edi, %edi
je 0xef39
xorl %esi, %esi
callq 0x4440
popq %rbx
popq %r14
popq %r15
retq
movq %rax, %r14
movq %rbx, %rdi
callq 0xfb76
movq %r15, %rdi
callq 0x9000
movq %r14, %rdi
callq 0x4640
// File: /workspace/github_cpp_makefile_star2_O2/khedoros[P]khednes/apu.cpp
// Function: apu::clock_quarter()
void apu::clock_quarter() {
    if(enable_linear_cntr && linear_cntr > 0) --linear_cntr;

    //Envelope decay and looping
    for(uint8_t voice = 0; voice < 4; ++voice) {
        if(voice == TRI) continue;
        if(enabled[voice] && enable_decay[voice] && length[voice] > 0) {
            if(decay_count[voice] == 0) {
                --decay_vol_lvl[voice];
                if(decay_vol_lvl[voice] > 15 && loop_decay[voice]) {
                    decay_vol_lvl[voice] = 15;
                }
                else if(decay_vol_lvl[voice] > 15) {
                    decay_vol_lvl[voice] = 0;
                    //enabled[voice] = false;
                    length[voice] = 0;
                }
                else {
                    decay_count[voice] = vol[voice];
                }
                //cout<<"Voice: "<<int(voice)<<" new vol: "<<decay_vol_lvl[voice]<<endl;
            }
            else {
                --decay_count[voice];
            }
        }
    }
}

// Assembly:
cmpb $0x1, 0x11c(%rdi)
jne 0xef7b
movl 0x118(%rdi), %eax
testl %eax, %eax
je 0xef7b
decl %eax
movl %eax, 0x118(%rdi)
xorl %eax, %eax
cmpq $0x2, %rax
je 0xeff0
cmpq $0x4, %rax
je 0xf007
cmpb $0x1, 0xb4(%rdi,%rax)
jne 0xeff0
cmpb $0x1, 0xe4(%rdi,%rax)
jne 0xeff0
cmpl $0x0, 0x174(%rdi,%rax,4)
jle 0xeff0
movl 0xd0(%rdi,%rax,4), %ecx
testl %ecx, %ecx
je 0xefb6
decl %ecx
jmp 0xefe9
movl 0xf0(%rdi,%rax,4), %ecx
decl %ecx
movl %ecx, 0xf0(%rdi,%rax,4)
cmpl $0x10, %ecx
jb 0xefe2
cmpb $0x1, 0xe9(%rdi,%rax)
jne 0xeff5
movl $0xf, 0xf0(%rdi,%rax,4)
jmp 0xeff0
movl 0xbc(%rdi,%rax,4), %ecx
movl %ecx, 0xd0(%rdi,%rax,4)
incq %rax
jmp 0xef7d
andl $0x0, 0xf0(%rdi,%rax,4)
andl $0x0, 0x174(%rdi,%rax,4)
jmp 0xeff0
retq
// File: /workspace/github_cpp_makefile_star2_O2/khedoros[P]khednes/apu.cpp
// Function: apu::clock_half()
void apu::clock_half() {
    for(uint8_t voice = 0; voice < 4; ++voice) {
        //clock length counter
        if(enabled[voice] && length[voice] > 0 && !loop_decay[voice] && (voice != TRI || !enable_linear_cntr)) length[voice]--;

        //Wavelength sweep
        if(voice < 2 && enabled[voice] && length[voice] > 0 && sweep_enable[voice]) {
            --sweep_count[voice];
            if(sweep_count[voice] == 0) {
                int sweep_amount = wavelength_count_reset[voice];
                sweep_amount>>=(sweep_shift[voice]);
                if(sweep_dir[voice] == 1) //decrease wavelength
                    sweep_amount *= -1;
                if(wavelength_count_reset[voice] + sweep_amount < 0x7ff && wavelength_count_reset[voice] + sweep_amount > 0x08) {
                    wavelength_count_reset[voice] += sweep_amount;
                    if(sweep_count[voice] == 0) sweep_count[voice] = sweep_rate[voice] + 1;
                }
                else {
                    length[voice] = 0;
                    //enabled[voice] = 0;
                }
            }
        }   
    }

}

// Assembly:
movb 0x11c(%rdi), %al
xorl %edx, %edx
cmpq $0x4, %rdx
je 0xf0e1
cmpb $0x1, 0xb4(%rdi,%rdx)
jne 0xf0d9
movl 0x174(%rdi,%rdx,4), %ecx
testl %ecx, %ecx
jle 0xf0d9
cmpb $0x0, 0xe9(%rdi,%rdx)
je 0xf045
xorl %ecx, %ecx
jmp 0xf063
cmpq $0x2, %rdx
jne 0xf053
testb $0x1, %al
jne 0xf0d9
leal -0x1(%rcx), %esi
movl %esi, 0x174(%rdi,%rdx,4)
cmpl $0x1, %ecx
sete %cl
cmpq $0x1, %rdx
ja 0xf0d9
testb %cl, %cl
jne 0xf0d9
cmpb $0x1, 0x11d(%rdi,%rdx)
jne 0xf0d9
decl 0x160(%rdi,%rdx,4)
jne 0xf0d9
movl 0x188(%rdi,%rdx,4), %esi
movb 0x124(%rdi,%rdx,4), %cl
movl %esi, %r8d
sarl %cl, %r8d
movl %r8d, %ecx
negl %ecx
cmpl $0x1, 0x138(%rdi,%rdx,4)
cmovnel %r8d, %ecx
leal (%rcx,%rsi), %r8d
addl $-0x9, %r8d
cmpl $0x7f5, %r8d            # imm = 0x7F5
ja 0xf0d1
addl %esi, %ecx
movl %ecx, 0x188(%rdi,%rdx,4)
movl 0x14c(%rdi,%rdx,4), %ecx
incl %ecx
movl %ecx, 0x160(%rdi,%rdx,4)
jmp 0xf0d9
andl $0x0, 0x174(%rdi,%rdx,4)
incq %rdx
jmp 0xf010
retq
// File: /workspace/github_cpp_makefile_star2_O2/khedoros[P]khednes/apu.cpp
// Function: apu::read_status()
int  apu::read_status() {
    status_reg a;
    a.sq1_on = (length[SQ1] > 0);
    a.sq2_on = (length[SQ2] > 0);
    a.tri_on = (length[TRI] > 0);
    a.noise_on = (length[NOISE] > 0);
    a.dmc_on = (length[DMC] > 0);
    return a.val;
}

// Assembly:
xorl %ecx, %ecx
cmpl $0x0, 0x174(%rdi)
movdqu 0x178(%rdi), %xmm0
pxor %xmm1, %xmm1
pcmpgtd %xmm1, %xmm0
pand 0x444b(%rip), %xmm0     # 0x13dc0
setg %cl
pshufd $0xee, %xmm0, %xmm1     # xmm1 = xmm0[2,3,2,3]
por %xmm0, %xmm1
pshufd $0x55, %xmm1, %xmm0     # xmm0 = xmm1[1,1,1,1]
por %xmm1, %xmm0
movd %xmm0, %eax
orl %ecx, %eax
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/khedoros[P]khednes/apu.cpp
// Function: apu::play_length(freq_len_reg)
const int apu::play_length(freq_len_reg val) {
    if(!(val.bit3 || val.bit7))
        return pal_len_table[val.mid];
    else if(!val.bit3 && val.bit7)
        return ntsc_len_table[val.mid];
    else
        return general_len_table[val.mid + val.bit7*128];
}

// Assembly:
movl %edi, %eax
shrl $0xc, %eax
andl $0x7, %eax
movl %edi, %ecx
andl $0x8800, %ecx           # imm = 0x8800
movl %ecx, %edx
negw %dx
jo 0xf9c8
testl %ecx, %ecx
jne 0xf9d3
movl %eax, %eax
leaq 0x1db6a(%rip), %rcx     # 0x2d530
jmp 0xf9e5
movl %eax, %eax
leaq 0x1db67(%rip), %rcx     # 0x2d538
jmp 0xf9e5
shrl $0x8, %edi
andl $0x80, %edi
orl %edi, %eax
leaq 0x1db5b(%rip), %rcx     # 0x2d540
addq %rax, %rcx
movzbl (%rcx), %eax
retq
// File: /workspace/github_cpp_makefile_star2_O2/khedoros[P]khednes/apu.cpp
// Function: apu::clock_duty(int)
void apu::clock_duty(int voice) {
    wavelength_count[voice] = wavelength_count_reset[voice];
    if(voice != NOISE)
        ++wave_pos[voice];
    switch(voice) {
        case SQ1:
        case SQ2:
            wave_pos[voice] %= SQ_LEN;
            break;
        case TRI:
            wave_pos[voice] %= TRI_LEN;
            break;
        case NOISE:
            if(noise_flip_flop) ++wave_pos[voice];
            noise_flip_flop = !noise_flip_flop;
            wave_pos[voice] %= NOISE_LEN[duty_cycle[voice]];
            break;
    }
}

// Assembly:
movslq %esi, %rcx
movl 0x188(%rdi,%rcx,4), %eax
movl %eax, 0x19c(%rdi,%rcx,4)
cmpl $0x3, %ecx
jne 0xfa2f
movzbl 0x1cc(%rdi), %edx
movl %edx, %eax
addl 0x1b0(%rdi,%rcx,4), %eax
xorb $0x1, %dl
movb %dl, 0x1cc(%rdi)
movl 0x104(%rdi,%rcx,4), %edx
leaq 0x1db87(%rip), %rsi     # 0x2d5b0
movzwl (%rsi,%rdx,2), %esi
jmp 0xfa4d
movl 0x1b0(%rdi,%rcx,4), %eax
incl %eax
movl %eax, 0x1b0(%rdi,%rcx,4)
cmpl $0x2, %ecx
jae 0xfa48
pushq $0x10
jmp 0xfa4c
jne 0xfa57
pushq $0x20
popq %rsi
cltd
idivl %esi
movl %edx, 0x1b0(%rdi,%rcx,4)
retq
// File: /workspace/github_cpp_makefile_star2_O2/khedoros[P]khednes/compositor.cpp
// Function: compositor::fill(int, SDL_Surface*)
void compositor::fill(int color, SDL_Surface * buff/*=buffer*/) {
    if(!buffer) return;

    if(!buff) buff = buffer;
    SDL_Rect all;
    all.x=0; all.y=0; all.w=1024; all.h=1024;
    SDL_FillRect(buff,&all,color);
}

// Assembly:
movq 0x10(%rdi), %rdi
testq %rdi, %rdi
je 0x101ce
subq $0x18, %rsp
movl %esi, %eax
testq %rdx, %rdx
cmovneq %rdx, %rdi
movaps 0x3ee3(%rip), %xmm0     # 0x140a0
movq %rsp, %rsi
movaps %xmm0, (%rsi)
movl %eax, %edx
callq 0x4060
addq $0x18, %rsp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/khedoros[P]khednes/compositor.cpp
// Function: compositor::get_color(int, int)
uint32_t compositor::get_color(int x,int y) {

    int wx=320;
    int wy=240;
    if(screen) {
        SDL_GetWindowSize(screen,&wx,&wy);
    }
    //cout<<"Requested ("<<x<<", "<<y<<"), current res: ("<<cur_x_res<<", "<<cur_y_res<<")"<<" window size: ("<<wx<<", "<<wy<<")"<<endl;
    if(x>=wx||y>=wy||x<0||y<0) {
        //cout<<"Requested ("<<x<<", "<<y<<"), current res: ("<<cur_x_res<<", "<<cur_y_res<<")"<<endl;
        return 0;
    }
    else {
        //cout<<"("<<x<<", "<<y;
        x = int(float(x) * (float(cur_x_res) / float(wx)));
        y = int(float(y) * (float(cur_y_res) / float(wy)));
        //cout<<") translated to ("<<x<<", "<<y<<")"<<endl;
    }

    size_t index = 0;
    if(buffer) {
        index = (y * buffer->pitch) + x;
    }

    int color_index = 1;
    if(screen) {
        color_index =  ((uint8_t *)(buffer->pixels))[index];
    }
    //                      blue                            green                                       red
    uint32_t color = palette_table[color_index *3+2] + ((palette_table[color_index * 3 + 1])<<(8)) + ((palette_table[color_index * 3])<<(16));
    return color;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %edx, %r14d
movl %esi, %ebp
movq %rdi, %rbx
movl $0x140, 0x4(%rsp)       # imm = 0x140
movl $0xf0, (%rsp)
movq (%rdi), %rdi
testq %rdi, %rdi
je 0x1020b
leaq 0x4(%rsp), %r15
movq %rsp, %rdx
movq %r15, %rsi
callq 0x4140
movl (%r15), %ecx
jmp 0x10210
movl $0x140, %ecx            # imm = 0x140
xorl %eax, %eax
cmpl %ebp, %ecx
jle 0x102b7
movl (%rsp), %edx
cmpl %r14d, %edx
setle %sil
movl %r14d, %edi
orl %ebp, %edi
sets %dil
orb %sil, %dil
jne 0x102b7
movq 0x10(%rbx), %rax
testq %rax, %rax
je 0x10283
cvtsi2ssl 0x17c(%rbx), %xmm0
cvtsi2ss %edx, %xmm1
cvtsi2ss %r14d, %xmm2
divss %xmm1, %xmm0
mulss %xmm0, %xmm2
cvttss2si %xmm2, %edx
cvtsi2ssl 0x178(%rbx), %xmm0
cvtsi2ss %ecx, %xmm1
cvtsi2ss %ebp, %xmm2
divss %xmm1, %xmm0
mulss %xmm0, %xmm2
cvttss2si %xmm2, %ecx
imull 0x18(%rax), %edx
addl %ecx, %edx
movslq %edx, %rcx
jmp 0x10285
xorl %ecx, %ecx
cmpq $0x0, (%rbx)
je 0x10298
movq 0x20(%rax), %rax
movzbl (%rax,%rcx), %eax
leal (%rax,%rax,2), %eax
jmp 0x1029b
pushq $0x3
popq %rax
leaq 0x3efe(%rip), %rcx      # 0x141a0
movl %eax, %edx
movl (%rcx,%rdx,4), %eax
movl 0x4(%rcx,%rdx,4), %esi
shll $0x8, %esi
addl 0x8(%rcx,%rdx,4), %esi
shll $0x10, %eax
addl %esi, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/khedoros[P]khednes/compositor.cpp
// Function: compositor::pset(int, int, int)
void compositor::pset(int x,int y,int color) {
    if(!overlay) return;
    //cout<<"X: "<<x<<" Y: "<<y<<" Color: "<<color<<endl;
    if(x>=overlay->w||y>=overlay->h||color>=76) {
        //cout<<"X: "<<x<<" Y: "<<y<<" Color: "<<color<<endl;
        //cout<<"cur_x_res: "<<cur_x_res<<" cur_y_res: "<<cur_y_res<<endl;
        //std::cout<<"Overlay: ("<<overlay->w<<", "<<overlay->h<<")"<<endl;
        std::cout<<"Pset: out of range ("<<x<<", "<<y<<"), "<<color<<endl;
        return;
    }
    //else cout<<"Pset: ("<<x<<", "<<y<<"), "<<color<<endl;
    //else {std::cout<<"pset ("<<x<<", "<<y<<"), "<<color<<std::endl;}
    ((uint8_t *)(overlay->pixels))[y*(overlay->pitch)+x]=color;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movq 0x20(%rdi), %rax
testq %rax, %rax
je 0x104b6
movl %ecx, %ebx
movl %edx, %ebp
movl %esi, %r14d
cmpl %esi, 0x10(%rax)
jle 0x104bb
cmpl $0x4b, %ebx
jg 0x104bb
cmpl %ebp, 0x14(%rax)
jle 0x104bb
imull 0x18(%rax), %ebp
movq 0x20(%rax), %rax
addl %r14d, %ebp
movslq %ebp, %rcx
movb %bl, (%rax,%rcx)
popq %rbx
popq %r14
popq %rbp
retq
movq 0xaaee(%rip), %rdi      # 0x1afb0
leaq 0x3cb1(%rip), %rsi      # 0x1417a
callq 0x4390
movq %rax, %rdi
movl %r14d, %esi
callq 0x4610
leaq 0x3cb0(%rip), %rsi      # 0x14190
movq %rax, %rdi
callq 0x4390
movq %rax, %rdi
movl %ebp, %esi
callq 0x4610
leaq 0x3c96(%rip), %rsi      # 0x1418f
movq %rax, %rdi
callq 0x4390
movq %rax, %rdi
movl %ebx, %esi
callq 0x4610
movq %rax, %rdi
popq %rbx
popq %r14
popq %rbp
jmp 0x41c0
nop
// File: /workspace/github_cpp_makefile_star2_O2/khedoros[P]khednes/compositor.cpp
// Function: compositor::table_view(bool)
void compositor::table_view(bool active) {
    tv=active;
    if(tv) {
        resize(1024,512,false);
        base_x_res = 1024;
        base_y_res = 512;
    }
    else {
        resize(320,240,false);
        base_x_res = 320;
        base_y_res = 240;
    }
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
movb %sil, 0x188(%rdi)
testl %esi, %esi
je 0x10542
movl $0x400, %esi            # imm = 0x400
movl $0x200, %edx            # imm = 0x200
xorl %ecx, %ecx
callq 0x102ca
movsd 0x3b90(%rip), %xmm0     # 0x140d0
jmp 0x1055b
movl $0x140, %esi            # imm = 0x140
movl $0xf0, %edx
xorl %ecx, %ecx
callq 0x102ca
movsd 0x3b65(%rip), %xmm0     # 0x140c0
movlps %xmm0, 0x180(%rbx)
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O2/khedoros[P]khednes/compositor.cpp
// Function: compositor::blit_hps(SDL_Surface*, int, int)
void compositor::blit_hps(SDL_Surface * s, int x, int y) {
    if(!hps) return;
    SDL_Rect pos;
    pos.x = x;
    pos.y = y;
    SDL_BlitSurface(s, NULL, hps, &pos);
}

// Assembly:
movl %edx, %eax
movq 0x38(%rdi), %rdx
testq %rdx, %rdx
je 0x10598
subq $0x18, %rsp
leaq 0x8(%rsp), %r8
movl %eax, (%r8)
movl %ecx, 0x4(%r8)
movq %rsi, %rdi
xorl %esi, %esi
movq %r8, %rcx
callq 0x4300
addq $0x18, %rsp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/khedoros[P]khednes/compositor.cpp
// Function: compositor::blit_lps(SDL_Surface*, int, int)
void compositor::blit_lps(SDL_Surface * s, int x, int y) {
    if(!lps) return;
    SDL_Rect pos;
    pos.x = x;
    pos.y = y;
    SDL_BlitSurface(s, NULL, lps, &pos);
}

// Assembly:
movl %edx, %eax
movq 0x28(%rdi), %rdx
testq %rdx, %rdx
je 0x105c6
subq $0x18, %rsp
leaq 0x8(%rsp), %r8
movl %eax, (%r8)
movl %ecx, 0x4(%r8)
movq %rsi, %rdi
xorl %esi, %esi
movq %r8, %rcx
callq 0x4300
addq $0x18, %rsp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/khedoros[P]khednes/compositor.cpp
// Function: compositor::blit_nt(SDL_Surface*, int, int)
void compositor::blit_nt(SDL_Surface * s, int x, int y) {
    if(!nt) return;
    SDL_Rect pos;
    pos.x = x;
    pos.y = y;
    SDL_BlitSurface(s, NULL, nt, &pos);
}

// Assembly:
movl %edx, %eax
movq 0x30(%rdi), %rdx
testq %rdx, %rdx
je 0x105f4
subq $0x18, %rsp
leaq 0x8(%rsp), %r8
movl %eax, (%r8)
movl %ecx, 0x4(%r8)
movq %rsi, %rdi
xorl %esi, %esi
movq %r8, %rcx
callq 0x4300
addq $0x18, %rsp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/khedoros[P]khednes/compositor.cpp
// Function: compositor::add_nt_area(int, int, int, int)
void compositor::add_nt_area(int sx, int sy, int ex, int ey) {
    if(nt_regions.size() > 1000) return;
    SDL_Rect * temp = new SDL_Rect;
    temp->x = sx;
    temp->y = sy;
    temp->w = ex - sx;
    temp->h = ey - sy;
    nt_regions.push_back(temp);
}

// Assembly:
cmpq $0x3e8, 0x1a0(%rdi) # imm = 0x3E8
ja 0x10698
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movl %r8d, %ebx
movl %ecx, %r15d
movl %edx, %ebp
movl %esi, %r12d
movq %rdi, %r14
addq $0x190, %r14            # imm = 0x190
pushq $0x10
popq %rdi
callq 0x43a0
leaq 0x8(%rsp), %rsi
movq %rax, (%rsi)
movl %r12d, (%rax)
movl %ebp, 0x4(%rax)
subl %r12d, %r15d
movl %r15d, 0x8(%rax)
subl %ebp, %ebx
movl %ebx, 0xc(%rax)
movq %r14, %rdi
callq 0x106a2
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/khedoros[P]khednes/mapper.cpp
// Function: mapper::get_pbyte(unsigned int)
const unsigned int mapper::get_pbyte(const unsigned int addr) {
    if(cart->prom_pages > 1) return cart->prom[addr-0x8000];
    else if(addr < 0xC000)
        return cart->prom[addr-0x8000];
    else
        return cart->prom[addr-0xC000];
}

// Assembly:
movq 0x8(%rdi), %rax
cmpl $0x2, 0x78(%rax)
jl 0x107ca
addl $0xffff8000, %esi       # imm = 0xFFFF8000
addq 0x28(%rax), %rsi
jmp 0x107e7
movq 0x28(%rax), %rax
cmpl $0xbfff, %esi           # imm = 0xBFFF
ja 0x107de
addl $0xffff8000, %esi       # imm = 0xFFFF8000
jmp 0x107e4
addl $0xffff4000, %esi       # imm = 0xFFFF4000
addq %rax, %rsi
movzbl (%rsi), %eax
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/khedoros[P]khednes/mapper.cpp
// Function: mapper::get_pword(unsigned int)
const unsigned int mapper::get_pword(const unsigned int addr) {
    if(cart->prom_pages > 1) return cart->prom_w[addr-0x8000];
    else if(addr < 0xC000) {
        //std::cout<<"Reading: 0x"<<std::hex<<addr<<" (0x"<<(addr-0x8000+prg_lo_offset)<<")"<<std::endl;
        return cart->prom_w[addr-0x8000];
    }
    else {
        //std::cout<<"Reading: 0x"<<std::hex<<addr<<" (0x"<<(addr-0xc000+prg_hi_offset)<<")"<<std::endl;
        return cart->prom_w[addr-0xC000];
    }
}

// Assembly:
movq 0x8(%rdi), %rax
cmpl $0x2, 0x78(%rax)
jl 0x10806
addl $0xffff8000, %esi       # imm = 0xFFFF8000
shlq $0x2, %rsi
addq 0x40(%rax), %rsi
jmp 0x10824
movq 0x40(%rax), %rax
cmpl $0xbfff, %esi           # imm = 0xBFFF
ja 0x1081a
addl $0xffff8000, %esi       # imm = 0xFFFF8000
jmp 0x10820
addl $0xffff4000, %esi       # imm = 0xFFFF4000
leaq (%rax,%rsi,4), %rsi
movl (%rsi), %eax
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/khedoros[P]khednes/mapper.cpp
// Function: mapper::get_cbyte(unsigned int)
const unsigned int mapper::get_cbyte(const unsigned int addr) {
    if(addr>=8192) {
        std::cout<<"Trying to get CHR byte at address: "<<addr<<std::endl;
        return 0;
    }
    return cart->crom[addr];
}

// Assembly:
pushq %rbx
movl %esi, %ebx
cmpl $0x2000, %esi           # imm = 0x2000
jb 0x1085c
movq 0xa776(%rip), %rdi      # 0x1afb0
leaq 0x3cef(%rip), %rsi      # 0x14530
callq 0x4390
movl %ebx, %esi
movq %rax, %rdi
callq 0x4270
movq %rax, %rdi
callq 0x41c0
xorl %eax, %eax
jmp 0x1086a
movq 0x8(%rdi), %rax
movl %ebx, %ecx
movq 0x58(%rax), %rax
movzbl (%rax,%rcx), %eax
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O2/khedoros[P]khednes/mapper_001_mmc1.cpp
// Function: mapper_001::mapper_001(rom*)
mapper_001::mapper_001(rom * r): mapper(r) {
    prg_lo_offset=0;
    prg_hi_offset=(cart->prom_pages - 1) * PRG_PAGE_SIZE;
    chr_lo_offset = 0;
    chr_hi_offset = 0x1000;

    mmc1_reg.reg0.val = 0x0c;
    mmc1_reg.reg1.val = 0;
    mmc1_reg.reg2.val = 0;
    mmc1_reg.reg3.val = 0;
    mmc1_reg.counter = 0;
    for(int i=0;i<5;++i) {
        mmc1_reg.temp[i]=false;
    }

    if(0x01 & (cart->header[6])) {
        mmc1_reg.reg0.mirror=false;
        mmc1_reg.reg0.obey_mirror=true;
    }
    else if(0x08 & (cart->header[6])) {
        mmc1_reg.reg0.mirror=false;
        mmc1_reg.reg0.obey_mirror=false;
    }
    else {
        mmc1_reg.reg0.mirror=true;
        mmc1_reg.reg0.obey_mirror=true;
    }
    mmc1_reg.reg0.high_low = true;
    mmc1_reg.reg0.large_small_prg = true;
    mmc1_reg.reg0.large_small_chr = false;
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
callq 0x107a4
leaq 0xa274(%rip), %rax      # 0x1ab10
movq %rax, (%rbx)
leaq 0x10(%rbx), %rax
movq %rax, 0x18(%rbx)
movq %rax, 0x10(%rbx)
andq $0x0, 0x20(%rbx)
andl $0x0, 0x44(%rbx)
movq 0x8(%rbx), %rcx
movl 0x78(%rcx), %eax
shll $0xe, %eax
addl $0xffffc000, %eax       # imm = 0xFFFFC000
movl %eax, 0x48(%rbx)
movabsq $0x100000000000, %rax   # imm = 0x100000000000
movq %rax, 0x4c(%rbx)
movb 0x28(%rbx), %al
andb $-0x20, %al
leal 0xc(%rax), %edx
movb %dl, 0x28(%rbx)
andb $-0x20, 0x2c(%rbx)
andb $-0x20, 0x30(%rbx)
andb $-0x10, 0x34(%rbx)
andl $0x0, 0x38(%rbx)
pushq $-0x5
popq %rsi
testq %rsi, %rsi
je 0x10901
movb $0x0, 0x41(%rbx,%rsi)
incq %rsi
jmp 0x108f2
movq 0x10(%rcx), %rcx
movb 0x6(%rcx), %cl
testb $0x1, %cl
jne 0x1091d
orb $0xf, %al
testb $0x8, %cl
movzbl %dl, %ecx
movzbl %al, %eax
cmovnel %ecx, %eax
jmp 0x1091f
orb $0xe, %al
movb %al, 0x28(%rbx)
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O2/khedoros[P]khednes/mapper_001_mmc1.cpp
// Function: mapper_001::get_pbyte(unsigned int)
const unsigned int mapper_001::get_pbyte(const unsigned int addr) {
    if(addr < 0xC000) {
        //std::cout<<std::hex<<"Addr: "<<addr<<"("<<addr-0x8000+prg_lo_offset<<")"<<std::endl;
        return cart->prom[addr-0x8000 + prg_lo_offset];
    }
    else {
        //std::cout<<std::hex<<"Addr: "<<addr<<"("<<addr-0xc000+prg_hi_offset<<")"<<std::endl;
        //std::cout<<"Cart: "<<cart<<std::endl;
        return cart->prom[addr-0xC000 + prg_hi_offset];
    }
}

// Assembly:
movq 0x8(%rdi), %rax
movq 0x28(%rax), %rax
cmpl $0xbfff, %esi           # imm = 0xBFFF
ja 0x10941
movl 0x44(%rdi), %ecx
addl %esi, %ecx
addl $0xffff8000, %ecx       # imm = 0xFFFF8000
jmp 0x1094c
movl 0x48(%rdi), %ecx
addl %esi, %ecx
addl $0xffff4000, %ecx       # imm = 0xFFFF4000
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/khedoros[P]khednes/mapper_001_mmc1.cpp
// Function: mapper_001::get_pword(unsigned int)
const unsigned int mapper_001::get_pword(const unsigned int addr) {
    if(addr < 0xC000) {
        //std::cout<<"Reading: 0x"<<std::hex<<addr<<" (0x"<<(addr-0x8000+prg_lo_offset)<<")"<<std::endl;
        return cart->prom_w[addr-0x8000 + prg_lo_offset];
    }
    else {
        //std::cout<<"Reading: 0x"<<std::hex<<addr<<" (0x"<<(addr-0xc000+prg_hi_offset)<<")"<<std::endl;
        return cart->prom_w[addr-0xC000 + prg_hi_offset];
    }
}

// Assembly:
movq 0x8(%rdi), %rax
movq 0x40(%rax), %rax
cmpl $0xbfff, %esi           # imm = 0xBFFF
ja 0x10971
movl 0x44(%rdi), %ecx
addl %esi, %ecx
addl $0xffff8000, %ecx       # imm = 0xFFFF8000
jmp 0x1097c
movl 0x48(%rdi), %ecx
addl %esi, %ecx
addl $0xffff4000, %ecx       # imm = 0xFFFF4000
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
retq