// File: /workspace/github_cpp_makefile_star2_O1/khedoros[P]khednes/ppu3.cpp
// Function: ppu::blit_sprite(int)
void ppu::blit_sprite(int spr) {
    if(spr < 0 || spr > 63) return;
    int spry = sprites[spr].y;
    int sprx = sprites[spr].x;
    bool priority = !sprites[spr].priority;
    bool hf = sprites[spr].hflip;
    bool vf = sprites[spr].vflip;
    int palnum = sprites[spr].pal | 4;
    int tile1 = sprites[spr].tile;
    int table = control0.sprite_table;
    int tile2 = -1;
    if(control0.big_sprites) {
        if(tile1%2 == 0)
            table = 0;
        else
            table = 1;
        tile1 &= 0xfe;
        tile2 = tile1 + 1;
    }
    if(priority) {
        if(control0.big_sprites) {
            if(vf) {
                screen.blit_hps(get_Surface(table,tile2,palnum,hf,vf), sprx,spry+1);
                screen.blit_hps(get_Surface(table,tile1,palnum,hf,vf), sprx,spry+9);
            }
            else {
                screen.blit_hps(get_Surface(table,tile1,palnum,hf,vf), sprx,spry+1);
                screen.blit_hps(get_Surface(table,tile2,palnum,hf,vf), sprx,spry+9);
            }
        }
        else {
            screen.blit_hps(get_Surface(table,tile1,palnum,hf,vf), sprx,spry+1);
        }
    }
    else {
        if(control0.big_sprites) {
            if(vf) {
                screen.blit_lps(get_Surface(table,tile2,palnum,hf,vf), sprx,spry+1);
                screen.blit_lps(get_Surface(table,tile1,palnum,hf,vf), sprx,spry+9);
            }
            else {
                screen.blit_lps(get_Surface(table,tile1,palnum,hf,vf), sprx,spry+1);
                screen.blit_lps(get_Surface(table,tile2,palnum,hf,vf), sprx,spry+9);
            }
        }
        else {
            screen.blit_lps(get_Surface(table,tile1,palnum,hf,vf), sprx,spry+1);
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
cmpl $0x3f, %esi
jbe 0xf624
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdi, %r12
movl %esi, %eax
movl 0x208(%rdi,%rax,4), %eax
movl $0xff, %ecx
movl %eax, %r8d
andl %ecx, %r8d
movl %eax, %edx
shrl $0x18, %edx
movl %edx, (%rsp)
movl %eax, %r9d
andl $0x800000, %r9d         # imm = 0x800000
movl %eax, %r15d
shrl $0x10, %r15d
andl $0x3, %r15d
orl $0x4, %r15d
movl %eax, %r13d
shrl $0x8, %r13d
andl %r13d, %ecx
movl 0x21850(%rdi), %edx
movl %edx, %esi
shrl $0x3, %esi
andl $0x1, %esi
movl %edx, %edi
andb $0x20, %dil
movl %r13d, %ebp
andl $0x1, %ebp
andl $0xfe, %r13d
xorl %ebx, %ebx
cmpb $0x1, %dil
sbbl %ebx, %ebx
orl %r13d, %ebx
testb %dil, %dil
cmovel %ecx, %r13d
cmovel %esi, %ebp
orl $0x1, %ebx
leaq 0x8(%r12), %rcx
movq %rcx, 0x8(%rsp)
movl %eax, %r14d
shrl $0x16, %r14d
andl $0x1, %r14d
btl $0x15, %eax
jb 0xf6ed
testb $0x20, %dl
jne 0xf724
shrl $0x17, %r9d
movq %r12, %rdi
movl %ebp, %esi
movl %r13d, %edx
movl %r15d, %ecx
movq %r8, %rbx
movl %r14d, %r8d
callq 0xe972
incl %ebx
movq 0x8(%rsp), %rdi
movq %rax, %rsi
movl (%rsp), %edx
movl %ebx, %ecx
jmp 0xf84f
testb $0x20, %dl
jne 0xf791
shrl $0x17, %r9d
movq %r12, %rdi
movl %ebp, %esi
movl %r13d, %edx
movl %r15d, %ecx
movq %r8, %rbx
movl %r14d, %r8d
callq 0xe972
incl %ebx
movq 0x8(%rsp), %rdi
movq %rax, %rsi
movl (%rsp), %edx
movl %ebx, %ecx
jmp 0xf8b3
leal 0x1(%r8), %eax
movl %eax, 0x4(%rsp)
addl $0x9, %r8d
movq %r8, 0x10(%rsp)
movq %r12, %rdi
movl %ebp, %esi
testl %r9d, %r9d
jne 0xf7fe
movl %r13d, %edx
movl %r15d, %ecx
movl %r14d, %r8d
xorl %r9d, %r9d
callq 0xe972
movq 0x8(%rsp), %rdi
movq %rax, %rsi
movl (%rsp), %r13d
movl %r13d, %edx
movl 0x4(%rsp), %ecx
callq 0x1283e
movq %r12, %rdi
movl %ebp, %esi
movl %ebx, %edx
movl %r15d, %ecx
movl %r14d, %r8d
xorl %r9d, %r9d
callq 0xe972
movq 0x8(%rsp), %rdi
movq %rax, %rsi
movl %r13d, %edx
jmp 0xf84a
leal 0x1(%r8), %eax
movl %eax, 0x4(%rsp)
addl $0x9, %r8d
movq %r8, 0x10(%rsp)
movq %r12, %rdi
movl %ebp, %esi
testl %r9d, %r9d
jne 0xf862
movl %r13d, %edx
movl %r15d, %ecx
movl %r14d, %r8d
xorl %r9d, %r9d
callq 0xe972
movq 0x8(%rsp), %rdi
movq %rax, %rsi
movl (%rsp), %r13d
movl %r13d, %edx
movl 0x4(%rsp), %ecx
callq 0x1286c
movq %r12, %rdi
movl %ebp, %esi
movl %ebx, %edx
movl %r15d, %ecx
movl %r14d, %r8d
xorl %r9d, %r9d
callq 0xe972
movq 0x8(%rsp), %rdi
movq %rax, %rsi
movl %r13d, %edx
jmp 0xf8ae
movl %ebx, %edx
movl %r15d, %ecx
movl %r14d, %r8d
movl $0x1, %r9d
callq 0xe972
movq 0x8(%rsp), %rdi
movq %rax, %rsi
movl (%rsp), %ebx
movl %ebx, %edx
movl 0x4(%rsp), %ecx
callq 0x1283e
movq %r12, %rdi
movl %ebp, %esi
movl %r13d, %edx
movl %r15d, %ecx
movl %r14d, %r8d
movl $0x1, %r9d
callq 0xe972
movq 0x8(%rsp), %rdi
movq %rax, %rsi
movl %ebx, %edx
movq 0x10(%rsp), %rcx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1283e
movl %ebx, %edx
movl %r15d, %ecx
movl %r14d, %r8d
movl $0x1, %r9d
callq 0xe972
movq 0x8(%rsp), %rdi
movq %rax, %rsi
movl (%rsp), %ebx
movl %ebx, %edx
movl 0x4(%rsp), %ecx
callq 0x1286c
movq %r12, %rdi
movl %ebp, %esi
movl %r13d, %edx
movl %r15d, %ecx
movl %r14d, %r8d
movl $0x1, %r9d
callq 0xe972
movq 0x8(%rsp), %rdi
movq %rax, %rsi
movl %ebx, %edx
movq 0x10(%rsp), %rcx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1286c