// File: /workspace/github_cpp_makefile_star2_O2/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 $0x28, %rsp
cmpl $0x3f, %esi
jbe 0xdade
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdi, %r15
movl %esi, %eax
movl 0x208(%rdi,%rax,4), %ebp
movzbl %bpl, %eax
movl %ebp, %ebx
shrl $0x18, %ebx
movl %ebp, %r14d
andl $0x400000, %r14d        # imm = 0x400000
movl %ebp, %r9d
andl $0x800000, %r9d         # imm = 0x800000
movl %ebp, %r12d
shrl $0x10, %r12d
andl $0x3, %r12d
orl $0x4, %r12d
movl %ebp, %r13d
shrl $0x8, %r13d
movzbl 0x21850(%rdi), %esi
testb $0x20, %sil
jne 0xdb6d
shrl $0x3, %esi
andl $0x1, %esi
movzbl %r13b, %edx
leaq 0x8(%r15), %r13
shrl $0x16, %r14d
shrl $0x17, %r9d
movq %r15, %rdi
movq %rax, %r15
movl %r12d, %ecx
movl %r14d, %r8d
callq 0xcf7a
movq %r15, %rcx
incl %ecx
movq %r13, %rdi
movq %rax, %rsi
movl %ebx, %edx
btl $0x15, %ebp
jae 0xdcad
jmp 0xdd17
movl %r13d, %edx
andl $0x1, %edx
andl $0xfe, %r13d
leal 0x1(%r13), %r8d
leaq 0x8(%r15), %rcx
movq %rcx, 0x18(%rsp)
shrl $0x16, %r14d
leal 0x1(%rax), %ecx
movl %ecx, 0xc(%rsp)
addl $0x9, %eax
btl $0x15, %ebp
movq %rax, 0x20(%rsp)
jb 0xdbfb
testl %r9d, %r9d
jne 0xdc56
movq %r15, %rdi
movl %edx, %ebp
movl %edx, %esi
movl %r13d, %edx
movl %r12d, %ecx
movl %r8d, 0x10(%rsp)
movl %r14d, %r8d
xorl %r9d, %r9d
callq 0xcf7a
movq 0x18(%rsp), %r13
movq %r13, %rdi
movq %rax, %rsi
movl %ebx, %edx
movl 0xc(%rsp), %ecx
callq 0x1056c
movq %r15, %rdi
movl %ebp, %esi
movl 0x10(%rsp), %edx
movl %r12d, %ecx
movl %r14d, %r8d
xorl %r9d, %r9d
callq 0xcf7a
movq %r13, %rdi
jmp 0xdca3
testl %r9d, %r9d
jne 0xdcc0
movq %r15, %rdi
movl %edx, %ebp
movl %edx, %esi
movl %r13d, %edx
movl %r12d, %ecx
movl %r8d, 0x10(%rsp)
movl %r14d, %r8d
xorl %r9d, %r9d
callq 0xcf7a
movq 0x18(%rsp), %r13
movq %r13, %rdi
movq %rax, %rsi
movl %ebx, %edx
movl 0xc(%rsp), %ecx
callq 0x1059a
movq %r15, %rdi
movl %ebp, %esi
movl 0x10(%rsp), %edx
movl %r12d, %ecx
movl %r14d, %r8d
xorl %r9d, %r9d
callq 0xcf7a
movq %r13, %rdi
jmp 0xdd0d
pushq $0x1
popq %r9
movq %r15, %rdi
movl %edx, %esi
movl %edx, 0x14(%rsp)
movl %r8d, %edx
movl %r12d, %ecx
movl %r14d, %r8d
callq 0xcf7a
movq 0x18(%rsp), %rbp
movq %rbp, %rdi
movq %rax, %rsi
movl %ebx, %edx
movl 0xc(%rsp), %ecx
callq 0x1056c
movq %r15, %rdi
movl 0x14(%rsp), %esi
movl %r13d, %edx
movl %r12d, %ecx
movl %r14d, %r8d
pushq $0x1
popq %r9
callq 0xcf7a
movq %rbp, %rdi
movq %rax, %rsi
movl %ebx, %edx
movq 0x20(%rsp), %rcx
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1056c
pushq $0x1
popq %r9
movq %r15, %rdi
movl %edx, %esi
movl %edx, 0x14(%rsp)
movl %r8d, %edx
movl %r12d, %ecx
movl %r14d, %r8d
callq 0xcf7a
movq 0x18(%rsp), %rbp
movq %rbp, %rdi
movq %rax, %rsi
movl %ebx, %edx
movl 0xc(%rsp), %ecx
callq 0x1059a
movq %r15, %rdi
movl 0x14(%rsp), %esi
movl %r13d, %edx
movl %r12d, %ecx
movl %r14d, %r8d
pushq $0x1
popq %r9
callq 0xcf7a
movq %rbp, %rdi
movq %rax, %rsi
movl %ebx, %edx
movq 0x20(%rsp), %rcx
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1059a