// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x48, %rsp
movq %rdi, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
movl %edx, 0x34(%rsp)
movq %rcx, 0x28(%rsp)
cmpq $0x0, 0x40(%rsp)
jne 0x2a54
jmp 0x2cbb
cmpq $0x0, 0x38(%rsp)
je 0x2cbb
movq 0x38(%rsp), %rax
cmpq $0x0, 0x8(%rax)
je 0x2cbb
movq 0x38(%rsp), %rax
cmpq $0x0, 0x10(%rax)
je 0x2cbb
movq 0x38(%rsp), %rax
cmpq $0x0, 0x18(%rax)
je 0x2cbb
movq 0x38(%rsp), %rax
cmpq $0x0, 0x20(%rax)
je 0x2cbb
movq 0x38(%rsp), %rax
movq (%rax), %rax
movss (%rax), %xmm0
movq 0x38(%rsp), %rax
movq (%rax), %rax
subss 0x8(%rax), %xmm0
cvttss2si %xmm0, %eax
movl %eax, 0x24(%rsp)
cvtsi2ssl 0x24(%rsp), %xmm1
movq 0x38(%rsp), %rax
movq (%rax), %rax
movss (%rax), %xmm0
movq 0x38(%rsp), %rax
movq (%rax), %rax
addss 0x8(%rax), %xmm0
ucomiss %xmm1, %xmm0
jb 0x2b76
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x28(%rsp), %rcx
movss (%rcx), %xmm1
movss 0x8(%rcx), %xmm0
cvtsi2ssl 0x24(%rsp), %xmm2
movl 0x8(%rax), %eax
shrl %eax
cvtsi2ss %eax, %xmm3
callq 0x29e0
cvttss2si %xmm0, %rax
movl %eax, 0x1c(%rsp)
movq 0x28(%rsp), %rax
movss 0x4(%rax), %xmm1
movss 0x8(%rax), %xmm0
movq 0x38(%rsp), %rax
movq (%rax), %rax
movss 0x4(%rax), %xmm2
movq 0x40(%rsp), %rax
movl 0xc(%rax), %eax
shrl %eax
cvtsi2ss %eax, %xmm3
callq 0x29e0
movq 0x10(%rsp), %rdi
movl 0x1c(%rsp), %esi
cvttss2si %xmm0, %rax
movl %eax, %edx
movl 0x34(%rsp), %ecx
callq 0x2960
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x2ac1
movq 0x38(%rsp), %rax
movq (%rax), %rax
movss 0x4(%rax), %xmm0
movq 0x38(%rsp), %rax
movq (%rax), %rax
subss 0xc(%rax), %xmm0
cvttss2si %xmm0, %eax
movl %eax, 0x20(%rsp)
cvtsi2ssl 0x20(%rsp), %xmm1
movq 0x38(%rsp), %rax
movq (%rax), %rax
movss 0x4(%rax), %xmm0
movq 0x38(%rsp), %rax
movq (%rax), %rax
addss 0xc(%rax), %xmm0
ucomiss %xmm1, %xmm0
jb 0x2c4b
movq 0x40(%rsp), %rax
movq %rax, (%rsp)
movq 0x28(%rsp), %rcx
movss (%rcx), %xmm1
movss 0x8(%rcx), %xmm0
movq 0x38(%rsp), %rcx
movq (%rcx), %rcx
movss (%rcx), %xmm2
movl 0x8(%rax), %eax
shrl %eax
cvtsi2ss %eax, %xmm3
callq 0x29e0
cvttss2si %xmm0, %rax
movl %eax, 0xc(%rsp)
movq 0x28(%rsp), %rax
movss 0x4(%rax), %xmm1
movss 0x8(%rax), %xmm0
cvtsi2ssl 0x20(%rsp), %xmm2
movq 0x40(%rsp), %rax
movl 0xc(%rax), %eax
shrl %eax
cvtsi2ss %eax, %xmm3
callq 0x29e0
movq (%rsp), %rdi
movl 0xc(%rsp), %esi
cvttss2si %xmm0, %rax
movl %eax, %edx
movl 0x34(%rsp), %ecx
callq 0x2960
movl 0x20(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x20(%rsp)
jmp 0x2b98
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %rax
movq 0x8(%rax), %rsi
movl 0x34(%rsp), %edx
movq 0x28(%rsp), %rcx
callq 0x2a30
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rsi
movl 0x34(%rsp), %edx
movq 0x28(%rsp), %rcx
callq 0x2a30
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %rax
movq 0x18(%rax), %rsi
movl 0x34(%rsp), %edx
movq 0x28(%rsp), %rcx
callq 0x2a30
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %rax
movq 0x20(%rax), %rsi
movl 0x34(%rsp), %edx
movq 0x28(%rsp), %rcx
callq 0x2a30
addq $0x48, %rsp
retq