// File: /workspace/github_c_makefile_star2_O1/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
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %r15
testq %r15, %r15
je 0x23c5
testq %r14, %r14
je 0x23c5
movq 0x8(%r14), %rsi
testq %rsi, %rsi
je 0x23c5
cmpq $0x0, 0x10(%r14)
je 0x23c5
cmpq $0x0, 0x18(%r14)
je 0x23c5
cmpq $0x0, 0x20(%r14)
je 0x23c5
movq (%r14), %rax
movss (%rax), %xmm0
movss 0x8(%rax), %xmm1
movaps %xmm0, %xmm2
subss %xmm1, %xmm2
addss %xmm0, %xmm1
cvttps2dq %xmm2, %xmm3
cvtdq2ps %xmm3, %xmm6
ucomiss %xmm6, %xmm1
jb 0x22e0
cvttss2si %xmm2, %ecx
movss 0x8(%rbx), %xmm2
movss (%rbx), %xmm3
movss 0x4(%rbx), %xmm4
movss 0x1daa(%rip), %xmm5     # 0x4014
subss %xmm2, %xmm5
addss 0x4(%rax), %xmm4
mulss %xmm2, %xmm4
incl %ecx
movl 0x8(%r15), %edi
movl %edi, %edx
shrl %edx
xorps %xmm7, %xmm7
cvtsi2ss %edx, %xmm7
addss %xmm3, %xmm6
mulss %xmm2, %xmm6
mulss %xmm5, %xmm7
addss %xmm6, %xmm7
cvttss2si %xmm7, %rdx
cmpl %edx, %edi
jbe 0x22d2
movl 0xc(%r15), %r8d
movl %r8d, %edi
shrl %edi
xorps %xmm6, %xmm6
cvtsi2ss %edi, %xmm6
mulss %xmm5, %xmm6
addss %xmm4, %xmm6
cvttss2si %xmm6, %rdi
cmpl %edi, %r8d
jbe 0x22d2
movq (%r15), %r8
imull 0x10(%r15), %edi
leal (%rdi,%rdx,4), %edx
movl %ebp, (%r8,%rdx)
xorps %xmm6, %xmm6
cvtsi2ss %ecx, %xmm6
incl %ecx
ucomiss %xmm6, %xmm1
jae 0x2279
movss 0x4(%rax), %xmm1
movss 0xc(%rax), %xmm3
movaps %xmm1, %xmm2
subss %xmm3, %xmm2
addss %xmm3, %xmm1
cvttps2dq %xmm2, %xmm3
cvtdq2ps %xmm3, %xmm5
ucomiss %xmm5, %xmm1
jb 0x238d
cvttss2si %xmm2, %eax
movss 0x4(%rbx), %xmm2
movss 0x8(%rbx), %xmm3
movss 0x1cf9(%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 0x237f
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 0x237f
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 0x2329
movq %r15, %rdi
movl %ebp, %edx
movq %rbx, %rcx
callq 0x21d7
movq 0x10(%r14), %rsi
movq %r15, %rdi
movl %ebp, %edx
movq %rbx, %rcx
callq 0x21d7
movq 0x18(%r14), %rsi
movq %r15, %rdi
movl %ebp, %edx
movq %rbx, %rcx
callq 0x21d7
movq 0x20(%r14), %r14
jmp 0x21e9
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq