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

    if (bounding_box)
    {
        int reticle_radius = 3;
        for (int x = bounding_box->center_x - reticle_radius;
            x <= bounding_box->center_x + reticle_radius;
            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, bounding_box->center_y, buffer->height/2),
                    color);
        }
        for (int y = bounding_box->center_y - reticle_radius;
            y <= bounding_box->center_y + reticle_radius;
            y++)
        {
            sim_set_pixel(
                    buffer,
                    sim_calc_render_offset(view->zoom, view->dx, bounding_box->center_x, buffer->width/2),
                    sim_calc_render_offset(view->zoom, view->dy, y, buffer->height/2),
                    color);
        }

        float half_length_x = bounding_box->side_length_x / 2;
        float half_length_y = bounding_box->side_length_y / 2;

        for (int x = (bounding_box->center_x - half_length_x);
            x <= (bounding_box->center_x + half_length_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, bounding_box->center_y - half_length_y, buffer->height/2),
                    color);
            sim_set_pixel(
                    buffer,
                    sim_calc_render_offset(view->zoom, view->dx, x, buffer->width/2),
                    sim_calc_render_offset(view->zoom, view->dy, bounding_box->center_y + half_length_y, buffer->height/2),
                    color);
        }

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rcx, %rbx
testq %rdi, %rdi
sete %al
testq %rsi, %rsi
sete %cl
orb %al, %cl
jne 0x2611
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %r15
movss (%rsi), %xmm1
movss 0xe01(%rip), %xmm0      # 0x30b8
addss %xmm1, %xmm0
cvttss2si %xmm0, %r12d
cvtsi2ss %r12d, %xmm0
addss 0xdef(%rip), %xmm1      # 0x30bc
ucomiss %xmm0, %xmm1
jb 0x233c
movss 0x8(%rbx), %xmm1
movl 0x8(%r15), %eax
movl 0xc(%r15), %ecx
shrl %eax
cvtsi2ss %eax, %xmm2
movss 0xd27(%rip), %xmm3      # 0x3014
subss %xmm1, %xmm3
addss (%rbx), %xmm0
mulss %xmm1, %xmm0
mulss %xmm3, %xmm2
addss %xmm0, %xmm2
cvttss2si %xmm2, %rsi
shrl %ecx
cvtsi2ss %ecx, %xmm0
movss 0x4(%rbx), %xmm2
addss 0x4(%r14), %xmm2
mulss %xmm1, %xmm2
mulss %xmm3, %xmm0
addss %xmm2, %xmm0
cvttss2si %xmm0, %rdx
movq %r15, %rdi
movl %ebp, %ecx
callq 0x2086
incl %r12d
movss (%r14), %xmm1
jmp 0x22c0
movss 0x4(%r14), %xmm1
movss 0xd6e(%rip), %xmm0      # 0x30b8
addss %xmm1, %xmm0
cvttss2si %xmm0, %r12d
cvtsi2ss %r12d, %xmm0
addss 0xd5c(%rip), %xmm1      # 0x30bc
ucomiss %xmm0, %xmm1
jb 0x23cf
movss (%rbx), %xmm1
movss 0x8(%rbx), %xmm2
movl 0x8(%r15), %eax
movl 0xc(%r15), %ecx
shrl %eax
cvtsi2ss %eax, %xmm3
movss 0xc90(%rip), %xmm4      # 0x3014
subss %xmm2, %xmm4
addss (%r14), %xmm1
mulss %xmm2, %xmm1
mulss %xmm4, %xmm3
addss %xmm1, %xmm3
cvttss2si %xmm3, %rsi
shrl %ecx
cvtsi2ss %ecx, %xmm1
addss 0x4(%rbx), %xmm0
mulss %xmm2, %xmm0
mulss %xmm4, %xmm1
addss %xmm0, %xmm1
cvttss2si %xmm1, %rdx
movq %r15, %rdi
movl %ebp, %ecx
callq 0x2086
incl %r12d
movss 0x4(%r14), %xmm1
jmp 0x2353
movss 0xcdd(%rip), %xmm0      # 0x30b4
movss 0x8(%r14), %xmm2
mulss %xmm0, %xmm2
mulss 0xc(%r14), %xmm0
movss %xmm0, 0x4(%rsp)
movss (%r14), %xmm0
movaps %xmm0, %xmm1
movss %xmm2, 0xc(%rsp)
subss %xmm2, %xmm1
cvttss2si %xmm1, %r12d
cvtsi2ss %r12d, %xmm4
addss 0xc(%rsp), %xmm0
ucomiss %xmm4, %xmm0
jb 0x2501
movl 0x8(%r15), %eax
shrl %eax
cvtsi2ss %eax, %xmm0
movss 0x8(%rbx), %xmm1
movl 0xc(%r15), %eax
movss 0xbe1(%rip), %xmm2      # 0x3014
subss %xmm1, %xmm2
movss (%rbx), %xmm3
addss %xmm4, %xmm3
mulss %xmm1, %xmm3
mulss %xmm2, %xmm0
addss %xmm3, %xmm0
cvttss2si %xmm0, %rsi
movss 0x4(%r14), %xmm0
shrl %eax
cvtsi2ss %eax, %xmm3
subss 0x4(%rsp), %xmm0
addss 0x4(%rbx), %xmm0
mulss %xmm1, %xmm0
mulss %xmm2, %xmm3
addss %xmm0, %xmm3
cvttss2si %xmm3, %rdx
movq %r15, %rdi
movl %ebp, %ecx
movss %xmm4, 0x8(%rsp)
callq 0x2086
movl 0x8(%r15), %eax
shrl %eax
cvtsi2ss %eax, %xmm0
movss 0x8(%rbx), %xmm1
movl 0xc(%r15), %eax
movss 0xb71(%rip), %xmm2      # 0x3014
subss %xmm1, %xmm2
movss 0x8(%rsp), %xmm3
addss (%rbx), %xmm3
mulss %xmm1, %xmm3
mulss %xmm2, %xmm0
addss %xmm3, %xmm0
cvttss2si %xmm0, %rsi
movss 0x4(%r14), %xmm0
shrl %eax
cvtsi2ss %eax, %xmm3
addss 0x4(%rsp), %xmm0
addss 0x4(%rbx), %xmm0
mulss %xmm1, %xmm0
mulss %xmm2, %xmm3
addss %xmm0, %xmm3
cvttss2si %xmm3, %rdx
movq %r15, %rdi
movl %ebp, %ecx
callq 0x2086
incl %r12d
movss (%r14), %xmm0
jmp 0x2404
movss 0x4(%r14), %xmm0
movaps %xmm0, %xmm1
subss 0x4(%rsp), %xmm1
cvttss2si %xmm1, %r12d
cvtsi2ss %r12d, %xmm4
addss 0x4(%rsp), %xmm0
ucomiss %xmm4, %xmm0
jb 0x2611
movss 0x8(%rbx), %xmm0
movss (%r14), %xmm1
subss 0xc(%rsp), %xmm1
movl 0x8(%r15), %eax
movl 0xc(%r15), %ecx
shrl %eax
cvtsi2ss %eax, %xmm2
movss 0xac5(%rip), %xmm3      # 0x3014
subss %xmm0, %xmm3
addss (%rbx), %xmm1
mulss %xmm0, %xmm1
mulss %xmm3, %xmm2
addss %xmm1, %xmm2
cvttss2si %xmm2, %rsi
shrl %ecx
cvtsi2ss %ecx, %xmm1
movss 0x4(%rbx), %xmm2
addss %xmm4, %xmm2
mulss %xmm0, %xmm2
mulss %xmm3, %xmm1
addss %xmm2, %xmm1
cvttss2si %xmm1, %rdx
movq %r15, %rdi
movl %ebp, %ecx
movss %xmm4, 0x8(%rsp)
callq 0x2086
movss 0x8(%rbx), %xmm0
movss (%r14), %xmm1
addss 0xc(%rsp), %xmm1
movl 0x8(%r15), %eax
movl 0xc(%r15), %ecx
shrl %eax
cvtsi2ss %eax, %xmm2
movss 0xa56(%rip), %xmm3      # 0x3014
subss %xmm0, %xmm3
addss (%rbx), %xmm1
mulss %xmm0, %xmm1
mulss %xmm3, %xmm2
addss %xmm1, %xmm2
cvttss2si %xmm2, %rsi
shrl %ecx
cvtsi2ss %ecx, %xmm1
movss 0x8(%rsp), %xmm2
addss 0x4(%rbx), %xmm2
mulss %xmm0, %xmm2
mulss %xmm3, %xmm1
addss %xmm2, %xmm1
cvttss2si %xmm1, %rdx
movq %r15, %rdi
movl %ebp, %ecx
callq 0x2086
incl %r12d
movss 0x4(%r14), %xmm0
jmp 0x2515
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq