// File: /workspace/github_c_makefile_star2_O3/mesbahamin[P]star-sim/src/sim.c
// Function: sim_grid_render
void sim_grid_render(struct OffscreenBuffer *buffer, struct QuadTreeNode *node, uint32_t color, struct SimView *view)
{
    if (!buffer)
    {
        // TODO: handle invalid pointer error
        return;
    }

    if (node && node->ne && node->nw && node->sw && node->se)
    {
        for (int x = (node->cell->center_x - node->cell->distance_x);
            x <= (node->cell->center_x + node->cell->distance_x);
            ++x)
        {
            sim_set_pixel(
                    buffer,
                    sim_calc_render_offset(view->zoom, view->dx, x, buffer->width/2),
                    sim_calc_render_offset(view->zoom, view->dy, node->cell->center_y, buffer->height/2),
                    color);
        }

        for (int y = (node->cell->center_y - node->cell->distance_y);
            y <= (node->cell->center_y + node->cell->distance_y);
            ++y)
        {
            sim_set_pixel(
                    buffer,
                    sim_calc_render_offset(view->zoom, view->dx, node->cell->center_x, buffer->width/2),
                    sim_calc_render_offset(view->zoom, view->dy, y, buffer->height/2),
                    color);
        }

        sim_grid_render(buffer, node->ne, color, view);
        sim_grid_render(buffer, node->nw, color, view);
        sim_grid_render(buffer, node->sw, color, view);
        sim_grid_render(buffer, node->se, color, view);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rcx, %rbx
testq %rdi, %rdi
sete %al
testq %rsi, %rsi
sete %cl
orb %al, %cl
jne 0x23de
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %r15
movq 0x8(%r14), %rsi
testq %rsi, %rsi
je 0x23de
cmpq $0x0, 0x10(%r14)
je 0x23de
cmpq $0x0, 0x18(%r14)
je 0x23de
cmpq $0x0, 0x20(%r14)
je 0x23de
movq (%r14), %rax
movss (%rax), %xmm0
movss 0x8(%rax), %xmm2
movaps %xmm0, %xmm1
subss %xmm2, %xmm1
addss %xmm0, %xmm2
cvttps2dq %xmm1, %xmm3
cvtdq2ps %xmm3, %xmm7
ucomiss %xmm7, %xmm2
jae 0x2262
movss 0x4(%rax), %xmm1
jmp 0x22fa
cvttss2si %xmm1, %ecx
movss (%rbx), %xmm3
movss 0x8(%rbx), %xmm4
movss 0x1d9d(%rip), %xmm5     # 0x4014
subss %xmm4, %xmm5
movss 0x4(%rax), %xmm1
movss 0x4(%rbx), %xmm6
addss %xmm1, %xmm6
mulss %xmm4, %xmm6
incl %ecx
movl 0x8(%r15), %edi
movl %edi, %edx
shrl %edx
xorps %xmm8, %xmm8
cvtsi2ss %edx, %xmm8
addss %xmm3, %xmm7
mulss %xmm4, %xmm7
mulss %xmm5, %xmm8
addss %xmm7, %xmm8
cvttss2si %xmm8, %rdx
cmpl %edx, %edi
jbe 0x22ec
movl 0xc(%r15), %r8d
movl %r8d, %edi
shrl %edi
xorps %xmm7, %xmm7
cvtsi2ss %edi, %xmm7
mulss %xmm5, %xmm7
addss %xmm6, %xmm7
cvttss2si %xmm7, %rdi
cmpl %edi, %r8d
jbe 0x22ec
movq (%r15), %r8
imull 0x10(%r15), %edi
leal (%rdi,%rdx,4), %edx
movl %ebp, (%r8,%rdx)
xorps %xmm7, %xmm7
cvtsi2ss %ecx, %xmm7
incl %ecx
ucomiss %xmm7, %xmm2
jae 0x228f
movss 0xc(%rax), %xmm3
movaps %xmm1, %xmm2
subss %xmm3, %xmm2
addss %xmm3, %xmm1
cvttps2dq %xmm2, %xmm3
cvtdq2ps %xmm3, %xmm5
ucomiss %xmm5, %xmm1
jb 0x23a2
cvttss2si %xmm2, %eax
movss 0x4(%rbx), %xmm2
movss 0x8(%rbx), %xmm3
movss 0x1ce4(%rip), %xmm4     # 0x4014
subss %xmm3, %xmm4
addss (%rbx), %xmm0
mulss %xmm3, %xmm0
incl %eax
movl 0x8(%r15), %edx
movl %edx, %ecx
shrl %ecx
xorps %xmm6, %xmm6
cvtsi2ss %ecx, %xmm6
mulss %xmm4, %xmm6
addss %xmm0, %xmm6
cvttss2si %xmm6, %rcx
cmpl %ecx, %edx
jbe 0x2394
movl 0xc(%r15), %edi
movl %edi, %edx
shrl %edx
xorps %xmm6, %xmm6
cvtsi2ss %edx, %xmm6
addss %xmm2, %xmm5
mulss %xmm3, %xmm5
mulss %xmm4, %xmm6
addss %xmm5, %xmm6
cvttss2si %xmm6, %rdx
cmpl %edx, %edi
jbe 0x2394
movq (%r15), %rdi
imull 0x10(%r15), %edx
leal (%rdx,%rcx,4), %ecx
movl %ebp, (%rdi,%rcx)
xorps %xmm5, %xmm5
cvtsi2ss %eax, %xmm5
incl %eax
ucomiss %xmm5, %xmm1
jae 0x233e
movq %r15, %rdi
movl %ebp, %edx
movq %rbx, %rcx
callq 0x21e1
movq 0x10(%r14), %rsi
movq %r15, %rdi
movl %ebp, %edx
movq %rbx, %rcx
callq 0x21e1
movq 0x18(%r14), %rsi
movq %r15, %rdi
movl %ebp, %edx
movq %rbx, %rcx
callq 0x21e1
movq 0x20(%r14), %r14
testq %r14, %r14
jne 0x2207
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq