// File: /workspace/github_c_makefile_star2_O1/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:
testq %rdi, %rdi
sete %al
testq %rsi, %rsi
sete %r8b
orb %al, %r8b
jne 0x27e3
movss (%rsi), %xmm3
movss 0x1ca2(%rip), %xmm1     # 0x4094
addss %xmm3, %xmm1
movss 0x1c9a(%rip), %xmm0     # 0x4098
addss %xmm3, %xmm0
cvttps2dq %xmm1, %xmm2
cvtdq2ps %xmm2, %xmm6
ucomiss %xmm6, %xmm0
jb 0x24ae
cvttss2si %xmm1, %eax
movss 0x8(%rcx), %xmm1
movss (%rcx), %xmm2
movss 0x4(%rcx), %xmm4
movss 0x1be8(%rip), %xmm5     # 0x4014
subss %xmm1, %xmm5
addss 0x4(%rsi), %xmm4
mulss %xmm1, %xmm4
incl %eax
testq %rdi, %rdi
je 0x24a0
movl 0x8(%rdi), %r9d
movl %r9d, %r8d
shrl %r8d
xorps %xmm7, %xmm7
cvtsi2ss %r8d, %xmm7
addss %xmm2, %xmm6
mulss %xmm1, %xmm6
mulss %xmm5, %xmm7
addss %xmm6, %xmm7
cvttss2si %xmm7, %r8
cmpl %r8d, %r9d
jbe 0x24a0
movl 0xc(%rdi), %r10d
movl %r10d, %r9d
shrl %r9d
xorps %xmm6, %xmm6
cvtsi2ss %r9d, %xmm6
mulss %xmm5, %xmm6
addss %xmm4, %xmm6
cvttss2si %xmm6, %r9
cmpl %r9d, %r10d
jbe 0x24a0
movq (%rdi), %r10
imull 0x10(%rdi), %r9d
leal (%r9,%r8,4), %r8d
movl %edx, (%r10,%r8)
xorps %xmm6, %xmm6
cvtsi2ss %eax, %xmm6
incl %eax
ucomiss %xmm6, %xmm0
jae 0x243b
movss 0x4(%rsi), %xmm0
movss 0x1bd9(%rip), %xmm2     # 0x4094
addss %xmm0, %xmm2
movss 0x1bd1(%rip), %xmm1     # 0x4098
addss %xmm0, %xmm1
cvttps2dq %xmm2, %xmm4
cvtdq2ps %xmm4, %xmm7
ucomiss %xmm7, %xmm1
jb 0x257c
cvttss2si %xmm2, %eax
movss 0x4(%rcx), %xmm2
movss 0x8(%rcx), %xmm4
movss 0x1b23(%rip), %xmm5     # 0x4014
subss %xmm4, %xmm5
movss (%rcx), %xmm6
addss %xmm3, %xmm6
mulss %xmm4, %xmm6
incl %eax
testq %rdi, %rdi
je 0x256e
movl 0x8(%rdi), %r9d
movl %r9d, %r8d
shrl %r8d
xorps %xmm8, %xmm8
cvtsi2ss %r8d, %xmm8
mulss %xmm5, %xmm8
addss %xmm6, %xmm8
cvttss2si %xmm8, %r8
cmpl %r8d, %r9d
jbe 0x256e
movl 0xc(%rdi), %r10d
movl %r10d, %r9d
shrl %r9d
xorps %xmm8, %xmm8
cvtsi2ss %r9d, %xmm8
addss %xmm2, %xmm7
mulss %xmm4, %xmm7
mulss %xmm5, %xmm8
addss %xmm7, %xmm8
cvttss2si %xmm8, %r9
cmpl %r9d, %r10d
jbe 0x256e
movq (%rdi), %r10
imull 0x10(%rdi), %r9d
leal (%r9,%r8,4), %r8d
movl %edx, (%r10,%r8)
xorps %xmm7, %xmm7
cvtsi2ss %eax, %xmm7
incl %eax
ucomiss %xmm7, %xmm1
jae 0x2503
movss 0x1b0c(%rip), %xmm4     # 0x4090
movss 0x8(%rsi), %xmm1
mulss %xmm4, %xmm1
mulss 0xc(%rsi), %xmm4
movaps %xmm3, %xmm2
subss %xmm1, %xmm2
addss %xmm3, %xmm1
cvttps2dq %xmm2, %xmm3
cvtdq2ps %xmm3, %xmm9
ucomiss %xmm9, %xmm1
jb 0x26d6
cvttss2si %xmm2, %eax
movss 0x8(%rcx), %xmm3
movss (%rcx), %xmm5
movss 0x4(%rcx), %xmm10
movss 0x1a4a(%rip), %xmm6     # 0x4014
subss %xmm3, %xmm6
movaps %xmm0, %xmm7
subss %xmm4, %xmm7
addss %xmm10, %xmm7
mulss %xmm3, %xmm7
movaps %xmm0, %xmm8
addss %xmm4, %xmm8
addss %xmm10, %xmm8
mulss %xmm3, %xmm8
incl %eax
addss %xmm5, %xmm9
mulss %xmm3, %xmm9
testq %rdi, %rdi
je 0x265f
movl 0x8(%rdi), %r8d
movl %r8d, %esi
shrl %esi
xorps %xmm10, %xmm10
cvtsi2ss %esi, %xmm10
mulss %xmm6, %xmm10
addss %xmm9, %xmm10
cvttss2si %xmm10, %rsi
cmpl %esi, %r8d
jbe 0x265f
movl 0xc(%rdi), %r9d
movl %r9d, %r8d
shrl %r8d
xorps %xmm10, %xmm10
cvtsi2ss %r8d, %xmm10
mulss %xmm6, %xmm10
addss %xmm7, %xmm10
cvttss2si %xmm10, %r8
cmpl %r8d, %r9d
jbe 0x265f
movq (%rdi), %r9
imull 0x10(%rdi), %r8d
leal (%r8,%rsi,4), %esi
movl %edx, (%r9,%rsi)
testq %rdi, %rdi
je 0x26c1
movl 0x8(%rdi), %r8d
movl %r8d, %esi
shrl %esi
xorps %xmm10, %xmm10
cvtsi2ss %esi, %xmm10
mulss %xmm6, %xmm10
addss %xmm9, %xmm10
cvttss2si %xmm10, %rsi
cmpl %esi, %r8d
jbe 0x26c1
movl 0xc(%rdi), %r9d
movl %r9d, %r8d
shrl %r8d
xorps %xmm9, %xmm9
cvtsi2ss %r8d, %xmm9
mulss %xmm6, %xmm9
addss %xmm8, %xmm9
cvttss2si %xmm9, %r8
cmpl %r8d, %r9d
jbe 0x26c1
movq (%rdi), %r9
imull 0x10(%rdi), %r8d
leal (%r8,%rsi,4), %esi
movl %edx, (%r9,%rsi)
xorps %xmm9, %xmm9
cvtsi2ss %eax, %xmm9
incl %eax
ucomiss %xmm9, %xmm1
jae 0x25f3
movaps %xmm0, %xmm3
subss %xmm4, %xmm3
addss %xmm4, %xmm0
cvttps2dq %xmm3, %xmm4
cvtdq2ps %xmm4, %xmm6
ucomiss %xmm6, %xmm0
jb 0x27e3
cvttss2si %xmm3, %eax
movss 0x8(%rcx), %xmm3
movss 0x1912(%rip), %xmm4     # 0x4014
subss %xmm3, %xmm4
movss (%rcx), %xmm7
movss 0x4(%rcx), %xmm5
addss %xmm7, %xmm2
mulss %xmm3, %xmm2
addss %xmm7, %xmm1
mulss %xmm3, %xmm1
incl %eax
addss %xmm5, %xmm6
mulss %xmm3, %xmm6
testq %rdi, %rdi
je 0x277d
movl 0x8(%rdi), %esi
movl %esi, %ecx
shrl %ecx
xorps %xmm7, %xmm7
cvtsi2ss %ecx, %xmm7
mulss %xmm4, %xmm7
addss %xmm2, %xmm7
cvttss2si %xmm7, %rcx
cmpl %ecx, %esi
jbe 0x277d
movl 0xc(%rdi), %r8d
movl %r8d, %esi
shrl %esi
xorps %xmm7, %xmm7
cvtsi2ss %esi, %xmm7
mulss %xmm4, %xmm7
addss %xmm6, %xmm7
cvttss2si %xmm7, %rsi
cmpl %esi, %r8d
jbe 0x277d
movq (%rdi), %r8
imull 0x10(%rdi), %esi
leal (%rsi,%rcx,4), %ecx
movl %edx, (%r8,%rcx)
testq %rdi, %rdi
je 0x27d1
movl 0x8(%rdi), %esi
movl %esi, %ecx
shrl %ecx
xorps %xmm7, %xmm7
cvtsi2ss %ecx, %xmm7
mulss %xmm4, %xmm7
addss %xmm1, %xmm7
cvttss2si %xmm7, %rcx
cmpl %ecx, %esi
jbe 0x27d1
movl 0xc(%rdi), %r8d
movl %r8d, %esi
shrl %esi
xorps %xmm7, %xmm7
cvtsi2ss %esi, %xmm7
mulss %xmm4, %xmm7
addss %xmm6, %xmm7
cvttss2si %xmm7, %rsi
cmpl %esi, %r8d
jbe 0x27d1
movq (%rdi), %r8
imull 0x10(%rdi), %esi
leal (%rsi,%rcx,4), %ecx
movl %edx, (%r8,%rcx)
xorps %xmm6, %xmm6
cvtsi2ss %eax, %xmm6
incl %eax
ucomiss %xmm6, %xmm0
jae 0x2721
retq