// File: /workspace/github_cpp_makefile_star2_O3/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 0xf63c
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 0xf6cb
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 0xe9de
movq %r15, %rcx
incl %ecx
movq %r13, %rdi
movq %rax, %rsi
movl %ebx, %edx
btl $0x15, %ebp
jae 0xf809
jmp 0xf874
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)
movq %r15, %rdi
jb 0xf759
testl %r9d, %r9d
jne 0xf7b1
movl %edx, %ebp
movl %edx, %esi
movl %r13d, %edx
movl %r12d, %ecx
movl %r8d, 0x10(%rsp)
movl %r14d, %r8d
xorl %r9d, %r9d
callq 0xe9de
movq 0x18(%rsp), %r13
movq %r13, %rdi
movq %rax, %rsi
movl %ebx, %edx
movl 0xc(%rsp), %ecx
callq 0x12722
movq %r15, %rdi
movl %ebp, %esi
movl 0x10(%rsp), %edx
movl %r12d, %ecx
movl %r14d, %r8d
xorl %r9d, %r9d
callq 0xe9de
movq %r13, %rdi
jmp 0xf7ff
testl %r9d, %r9d
jne 0xf81c
movl %edx, %ebp
movl %edx, %esi
movl %r13d, %edx
movl %r12d, %ecx
movl %r8d, 0x10(%rsp)
movl %r14d, %r8d
xorl %r9d, %r9d
callq 0xe9de
movq 0x18(%rsp), %r13
movq %r13, %rdi
movq %rax, %rsi
movl %ebx, %edx
movl 0xc(%rsp), %ecx
callq 0x12750
movq %r15, %rdi
movl %ebp, %esi
movl 0x10(%rsp), %edx
movl %r12d, %ecx
movl %r14d, %r8d
xorl %r9d, %r9d
callq 0xe9de
movq %r13, %rdi
jmp 0xf86a
movl %edx, %esi
movl %edx, 0x14(%rsp)
movl %r8d, %edx
movl %r12d, %ecx
movl %r14d, %r8d
movl $0x1, %r9d
callq 0xe9de
movq 0x18(%rsp), %rbp
movq %rbp, %rdi
movq %rax, %rsi
movl %ebx, %edx
movl 0xc(%rsp), %ecx
callq 0x12722
movq %r15, %rdi
movl 0x14(%rsp), %esi
movl %r13d, %edx
movl %r12d, %ecx
movl %r14d, %r8d
movl $0x1, %r9d
callq 0xe9de
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 0x12722
movl %edx, %esi
movl %edx, 0x14(%rsp)
movl %r8d, %edx
movl %r12d, %ecx
movl %r14d, %r8d
movl $0x1, %r9d
callq 0xe9de
movq 0x18(%rsp), %rbp
movq %rbp, %rdi
movq %rax, %rsi
movl %ebx, %edx
movl 0xc(%rsp), %ecx
callq 0x12750
movq %r15, %rdi
movl 0x14(%rsp), %esi
movl %r13d, %edx
movl %r12d, %ecx
movl %r14d, %r8d
movl $0x1, %r9d
callq 0xe9de
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 0x12750
nop