// File: /workspace/github_c_makefile_star2_O1/qad114[P]yobeboy/src/gpu.c
// Function: GPU_renderToFrameBuffer
void GPU_renderToFrameBuffer(GPU* gpu, Memory* mem) {
    uint8_t LCDC = mem->logicalMemory[REG_LCDC];
    if (!getBit(LCDC, 7)) {
        // LCD disabled, return a blank screen
        for (int i = 0; i < (160 * 144 * 4); i += 4) {
            memcpy(gpu->framebuffer + i, &(gpu->colorPalette[0]), 3);
            gpu->framebuffer[i + 3] = 0xFF;
        }
        gpu->fbUpdated = true;
        return;
    }

    if (getBit(LCDC, 0)) {
        //renderBackground(gpu, mem);
        if (getBit(LCDC, 5)) renderWindow(gpu, mem);
    };
    if (getBit(LCDC, 1)) renderObjects(gpu, mem);
    gpu->fbUpdated = true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
movb 0xff40(%rsi), %bpl
testb %bpl, %bpl
js 0x5e9d
leaq 0x28(%rbx), %rax
movq $-0x4, %rcx
movq 0x8(%rbx), %rdx
movb 0x2(%rax), %sil
movb %sil, 0x6(%rdx,%rcx)
movzwl (%rax), %esi
movw %si, 0x4(%rdx,%rcx)
movq 0x8(%rbx), %rdx
movb $-0x1, 0x7(%rdx,%rcx)
addq $0x4, %rcx
cmpq $0x167fc, %rcx          # imm = 0x167FC
jb 0x5e6d
jmp 0x623a
movq %rsi, %r14
movl %ebp, %eax
notb %al
testb $0x21, %al
jne 0x6071
movl $0x10000, %edi          # imm = 0x10000
callq 0x2200
movzbl 0xff4b(%r14), %ecx
movl %ecx, 0x4(%rsp)
movzbl 0xff4a(%r14), %ecx
movq %rcx, 0x8(%rsp)
movl %ebp, %ecx
shrb $0x6, %cl
movzbl %cl, %ecx
shll $0xa, %ecx
orq $0x9800, %rcx           # imm = 0x9800
movq %rcx, 0x18(%rsp)
xorl %r10d, %r10d
movq %rax, 0x10(%rsp)
movq %rax, %r11
movq %r10, 0x28(%rsp)
shlq $0x5, %r10
addq 0x18(%rsp), %r10
movq %r11, 0x20(%rsp)
xorl %r15d, %r15d
leaq (%r10,%r15), %rax
movzbl (%r14,%rax), %eax
movsbl %al, %ecx
shll $0x4, %eax
orl $0x8000, %eax           # imm = 0x8000
shll $0x4, %ecx
addl $0x9000, %ecx           # imm = 0x9000
testb $0x10, %bpl
cmovneq %rax, %rcx
movzwl %cx, %r12d
movq %r11, %r13
xorl %edx, %edx
leaq (%rdx,%r12), %rsi
movb 0x1(%r14,%rsi), %r9b
movb $0x7, %cl
movzbl (%r14,%rsi), %edi
xorl %esi, %esi
movl %r9d, %eax
shrb %cl, %al
addb %al, %al
andb $0x2, %al
movzbl %cl, %ecx
btl %ecx, %edi
setb %r8b
orb %al, %r8b
movb %r8b, (%r13,%rsi)
incq %rsi
decb %cl
cmpq $0x8, %rsi
jne 0x5f47
leaq 0x2(%rdx), %rax
addq $0x100, %r13            # imm = 0x100
cmpq $0xe, %rdx
movq %rax, %rdx
jb 0x5f35
incq %r15
addq $0x8, %r11
cmpq $0x20, %r15
jne 0x5f07
movq 0x28(%rsp), %r10
incq %r10
movq 0x20(%rsp), %r11
addq $0x800, %r11            # imm = 0x800
cmpq $0x20, %r10
jne 0x5ef1
movq 0x8(%rsp), %r13
cmpb $-0x71, %r13b
movl 0x4(%rsp), %edi
ja 0x6063
cmpl $0x8, %edi
movl $0x7, %eax
cmovgel %edi, %eax
leaq (,%r13,4), %r12
addq %r13, %r12
shll $0x5, %r12d
addq %rax, %r12
leaq -0xa7(%rax), %r8
subl %edi, %eax
cltq
movq 0x10(%rsp), %r9
addq %rax, %r9
leaq 0x28(%rbx), %r10
movq %r12, %rdx
movq %r9, %r11
movq %r8, %r15
cmpb $-0x5a, %dil
ja 0x6049
movb (%r11), %cl
addb %cl, %cl
movzbl 0xff47(%r14), %eax
movl $0x3, %esi
shll %cl, %esi
andl %eax, %esi
shrl %cl, %esi
movq 0x8(%rbx), %rax
movb 0x2(%r10,%rsi,4), %cl
movb %cl, -0x1a(%rax,%rdx,4)
movzwl (%r10,%rsi,4), %ecx
movw %cx, -0x1c(%rax,%rdx,4)
movq 0x8(%rbx), %rax
movb $-0x1, -0x19(%rax,%rdx,4)
incq %r11
incq %rdx
incq %r15
jne 0x6006
incq %r13
addq $0x100, %r9             # imm = 0x100
addq $0xa0, %r12
cmpq $0x90, %r13
jne 0x5ff7
movb $0x1, 0x10(%rbx)
movq 0x10(%rsp), %rdi
callq 0x21b0
testb $0x2, %bpl
je 0x623a
leaq 0x28(%rbx), %rax
movl $0xfe00, %ecx           # imm = 0xFE00
movq %rcx, 0x8(%rsp)
movzbl 0x1(%r14,%rcx), %ecx
cmpl $0xa7, %ecx
ja 0x6224
movq 0x8(%rsp), %rdx
movzbl (%r14,%rdx), %esi
movl %esi, 0x28(%rsp)
movzbl 0x2(%r14,%rdx), %esi
shll $0x4, %esi
orq $0x8000, %rsi           # imm = 0x8000
movq %rsi, 0x20(%rsp)
movb 0x3(%r14,%rdx), %dl
movb 0xff40(%r14), %sil
andb $0x4, %sil
shrb $0x2, %sil
movzbl %sil, %r9d
shll $0x4, %r9d
leal 0xf(%r9), %ebp
xorl %esi, %esi
testb $0x40, %dl
sete %sil
movl $0x0, %edi
cmovel %edi, %ebp
movl %edx, %edi
shrb $0x5, %dil
movl %edx, %r8d
andb $0x10, %r8b
cmpb $0x1, %r8b
movl $0xff49, %r15d          # imm = 0xFF49
sbbq $0x0, %r15
movzbl %dil, %r12d
andl $0x1, %r12d
negq %r12
orq $0x1, %r12
addq $0x10, %r9
movq %r9, 0x18(%rsp)
testb $0x20, %dl
leal -0x2(,%rsi,4), %edx
movl %edx, 0x10(%rsp)
leaq 0x37(%rsp), %r11
leaq 0x30(%rsp), %rdx
cmoveq %rdx, %r11
leal -0x2820(,%rcx,4), %edx
movl %edx, 0x4(%rsp)
movl %ecx, %edx
addq $-0x8, %rdx
xorl %esi, %esi
movq 0x20(%rsp), %rcx
addq %rsi, %rcx
movzbl (%r14,%rcx), %r9d
movzbl 0x1(%r14,%rcx), %r13d
movl $0x7, %ecx
movq %r11, %rdi
movl %r13d, %r10d
shrl %cl, %r10d
addb %r10b, %r10b
andb $0x2, %r10b
btl %ecx, %r9d
setb %r8b
orb %r10b, %r8b
movb %r8b, (%rdi)
addq %r12, %rdi
addl $-0x1, %ecx
jb 0x616c
movl %ebp, %ecx
shrl $0x1f, %ecx
addl %ebp, %ecx
shrl %ecx
addl 0x28(%rsp), %ecx
leal (%rcx,%rcx,4), %r9d
shll $0x7, %r9d
addl 0x4(%rsp), %r9d
xorl %r10d, %r10d
movzbl 0x30(%rsp,%r10), %ecx
testl %ecx, %ecx
je 0x6204
leal (%rdx,%r10), %edi
cmpl $0x9f, %edi
ja 0x6204
cmpl $0x167ff, %r9d          # imm = 0x167FF
ja 0x6204
addl %ecx, %ecx
movl $0x3, %edi
shll %cl, %edi
movzbl (%r14,%r15), %r8d
andl %r8d, %edi
shrl %cl, %edi
movq 0x8(%rbx), %rcx
movl %r9d, %r8d
movb 0x2(%rax,%rdi,4), %r13b
movb %r13b, 0x2(%rcx,%r8)
movzwl (%rax,%rdi,4), %edi
movw %di, (%rcx,%r8)
movq 0x8(%rbx), %rcx
leal 0x3(%r9), %edi
movb $-0x1, (%rcx,%rdi)
incq %r10
addl $0x4, %r9d
cmpq $0x8, %r10
jne 0x61ac
addl 0x10(%rsp), %ebp
addq $0x2, %rsi
cmpq 0x18(%rsp), %rsi
jb 0x6151
movq 0x8(%rsp), %rdx
leaq 0x4(%rdx), %rcx
cmpq $0xfe9b, %rdx           # imm = 0xFE9B
jb 0x6084
movb $0x1, 0x10(%rbx)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)