// File: /workspace/github_c_makefile_star2_O0/mesbahamin[P]star-sim/src/sim.c
// Function: sim_render
void sim_render(struct OffscreenBuffer *buffer, float dt, struct SimState *sim_state)
{
    if (!buffer || !sim_state)
    {
        // TODO: handle invalid pointer error
        return;
    }

    int num_stars = sim_state->num_stars;
    struct Star *stars = sim_state->stars;
    struct QuadTree *qt = sim_state->qt;

    float dx = sim_state->view.dx;
    float dy = sim_state->view.dy;
    float zoom = sim_state->view.zoom;

    for (int i = 0; i < num_stars; ++i)
    {
        uint32_t color;
        if (BRUTE_FORCE)
        {
            color = COLOR_CYAN;
        }
        else
        {
            color = stars[i].color;
        }
        sim_set_pixel(
            buffer,
            sim_calc_render_offset(zoom, dx, stars[i].x + (sinf(stars[i].angle) * stars[i].speed) * dt, buffer->width/2),
            sim_calc_render_offset(zoom, dy, stars[i].y - (cosf(stars[i].angle) * stars[i].speed) * dt, buffer->height/2),
            color);
    }

    if (RENDER_GRID)
    {
        sim_grid_render(buffer, qt->root, COLOR_GREEN, &sim_state->view);
    }
    if (RENDER_BOUNDING_BOX)
    {
        sim_bounding_box_render(buffer, &sim_state->bounding_box, COLOR_RED, &sim_state->view);
    }
}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x60(%rsp)
movss %xmm0, 0x5c(%rsp)
movq %rsi, 0x50(%rsp)
cmpq $0x0, 0x60(%rsp)
je 0x26f4
cmpq $0x0, 0x50(%rsp)
jne 0x26f9
jmp 0x294e
movq 0x50(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x4c(%rsp)
movq 0x50(%rsp), %rax
addq $0x28, %rax
movq %rax, 0x40(%rsp)
movq 0x50(%rsp), %rax
movq 0x20(%rax), %rax
movq %rax, 0x38(%rsp)
movq 0x50(%rsp), %rax
movss 0x14(%rax), %xmm0
movss %xmm0, 0x34(%rsp)
movq 0x50(%rsp), %rax
movss 0x18(%rax), %xmm0
movss %xmm0, 0x30(%rsp)
movq 0x50(%rsp), %rax
movss 0x1c(%rax), %xmm0
movss %xmm0, 0x2c(%rsp)
movl $0x0, 0x28(%rsp)
movl 0x28(%rsp), %eax
cmpl 0x4c(%rsp), %eax
jge 0x28fb
testb $0x1, 0x39d4(%rip)      # 0x6141
je 0x2779
movl $0x2aa198, 0x24(%rsp)   # imm = 0x2AA198
jmp 0x2791
movq 0x40(%rsp), %rax
movslq 0x28(%rsp), %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
movl %eax, 0x24(%rsp)
movq 0x60(%rsp), %rax
movq %rax, 0x18(%rsp)
movss 0x2c(%rsp), %xmm0
movss %xmm0, 0x8(%rsp)
movss 0x34(%rsp), %xmm0
movss %xmm0, 0x4(%rsp)
movq 0x40(%rsp), %rax
movslq 0x28(%rsp), %rdx
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rdx, %rcx
movss (%rax,%rcx), %xmm0
movss 0x10(%rax,%rcx), %xmm1
movss %xmm1, (%rsp)
callq 0x1130
movss (%rsp), %xmm3
movss 0x4(%rsp), %xmm1
movaps %xmm0, %xmm2
movss 0x8(%rsp), %xmm0
movq 0x40(%rsp), %rax
movslq 0x28(%rsp), %rdx
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rdx, %rcx
movss 0x4(%rax,%rcx), %xmm4
mulss %xmm4, %xmm2
movss 0x5c(%rsp), %xmm4
mulss %xmm4, %xmm2
addss %xmm3, %xmm2
movq 0x60(%rsp), %rax
movl 0x8(%rax), %eax
shrl %eax
cvtsi2ss %eax, %xmm3
callq 0x29e0
cvttss2si %xmm0, %rax
movl %eax, 0x20(%rsp)
movss 0x2c(%rsp), %xmm0
movss %xmm0, 0x14(%rsp)
movss 0x30(%rsp), %xmm0
movss %xmm0, 0x10(%rsp)
movq 0x40(%rsp), %rax
movslq 0x28(%rsp), %rdx
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rdx, %rcx
movss (%rax,%rcx), %xmm0
movss 0x14(%rax,%rcx), %xmm1
movss %xmm1, 0xc(%rsp)
callq 0x10f0
movss 0xc(%rsp), %xmm2
movss 0x10(%rsp), %xmm1
movaps %xmm0, %xmm3
movss 0x14(%rsp), %xmm0
movq 0x40(%rsp), %rax
movslq 0x28(%rsp), %rdx
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rdx, %rcx
movss 0x4(%rax,%rcx), %xmm4
mulss %xmm4, %xmm3
movss 0x5c(%rsp), %xmm4
mulss %xmm4, %xmm3
subss %xmm3, %xmm2
movq 0x60(%rsp), %rax
movl 0xc(%rax), %eax
shrl %eax
cvtsi2ss %eax, %xmm3
callq 0x29e0
movq 0x18(%rsp), %rdi
movl 0x20(%rsp), %esi
cvttss2si %xmm0, %rax
movl %eax, %edx
movl 0x24(%rsp), %ecx
callq 0x2960
movl 0x28(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x28(%rsp)
jmp 0x2758
testb $0x1, 0x3840(%rip)      # 0x6142
je 0x2924
movq 0x60(%rsp), %rdi
movq 0x38(%rsp), %rax
movq (%rax), %rsi
movq 0x50(%rsp), %rcx
addq $0x14, %rcx
movl $0x859900, %edx         # imm = 0x859900
callq 0x2a30
testb $0x1, 0x3818(%rip)      # 0x6143
je 0x294e
movq 0x60(%rsp), %rdi
movq 0x50(%rsp), %rsi
addq $0x4, %rsi
movq 0x50(%rsp), %rcx
addq $0x14, %rcx
movl $0xdc322f, %edx         # imm = 0xDC322F
callq 0x2cc0
addq $0x68, %rsp
retq
nopw %cs:(%rax,%rax)