// File: /workspace/github_c_makefile_star2_O3/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 0x2804
movss (%rsi), %xmm3
movss 0x1c89(%rip), %xmm0     # 0x4094
addss %xmm3, %xmm0
movss 0x1c81(%rip), %xmm1     # 0x4098
addss %xmm3, %xmm1
cvttps2dq %xmm0, %xmm2
cvtdq2ps %xmm2, %xmm7
ucomiss %xmm7, %xmm1
jae 0x2431
movss 0x4(%rsi), %xmm0
jmp 0x24cf
cvttss2si %xmm0, %eax
movss (%rcx), %xmm2
movss 0x8(%rcx), %xmm4
movss 0x1bce(%rip), %xmm5     # 0x4014
subss %xmm4, %xmm5
movss 0x4(%rsi), %xmm0
movss 0x4(%rcx), %xmm6
addss %xmm0, %xmm6
mulss %xmm4, %xmm6
incl %eax
movl 0x8(%rdi), %r9d
movl %r9d, %r8d
shrl %r8d
xorps %xmm8, %xmm8
cvtsi2ss %r8d, %xmm8
addss %xmm2, %xmm7
mulss %xmm4, %xmm7
mulss %xmm5, %xmm8
addss %xmm7, %xmm8
cvttss2si %xmm8, %r8
cmpl %r8d, %r9d
jbe 0x24c1
movl 0xc(%rdi), %r10d
movl %r10d, %r9d
shrl %r9d
xorps %xmm7, %xmm7
cvtsi2ss %r9d, %xmm7
mulss %xmm5, %xmm7
addss %xmm6, %xmm7
cvttss2si %xmm7, %r9
cmpl %r9d, %r10d
jbe 0x24c1
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 0x245e
movss 0x1bbd(%rip), %xmm2     # 0x4094
addss %xmm0, %xmm2
movss 0x1bb5(%rip), %xmm1     # 0x4098
addss %xmm0, %xmm1
cvttps2dq %xmm2, %xmm4
cvtdq2ps %xmm4, %xmm7
ucomiss %xmm7, %xmm1
jb 0x2593
cvttss2si %xmm2, %eax
movss 0x4(%rcx), %xmm2
movss 0x8(%rcx), %xmm4
movss 0x1b07(%rip), %xmm5     # 0x4014
subss %xmm4, %xmm5
movss (%rcx), %xmm6
addss %xmm3, %xmm6
mulss %xmm4, %xmm6
incl %eax
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 0x2585
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 0x2585
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 0x251f
movss 0x1af4(%rip), %xmm10    # 0x4090
movss 0x8(%rsi), %xmm1
mulss %xmm10, %xmm1
mulss 0xc(%rsi), %xmm10
movaps %xmm3, %xmm2
subss %xmm1, %xmm2
addss %xmm3, %xmm1
cvttps2dq %xmm2, %xmm3
cvtdq2ps %xmm3, %xmm9
ucomiss %xmm9, %xmm1
jae 0x25d7
movaps %xmm0, %xmm3
subss %xmm10, %xmm3
addss %xmm10, %xmm0
jmp 0x26f7
cvttss2si %xmm2, %eax
movss 0x8(%rcx), %xmm4
movss (%rcx), %xmm5
movss 0x4(%rcx), %xmm6
movss 0x1a23(%rip), %xmm7     # 0x4014
subss %xmm4, %xmm7
movaps %xmm0, %xmm3
subss %xmm10, %xmm3
movaps %xmm3, %xmm8
addss %xmm6, %xmm8
mulss %xmm4, %xmm8
addss %xmm10, %xmm0
addss %xmm0, %xmm6
mulss %xmm4, %xmm6
incl %eax
addss %xmm5, %xmm9
movl 0x8(%rdi), %r9d
movl %r9d, %esi
shrl %esi
xorps %xmm10, %xmm10
cvtsi2ss %esi, %xmm10
movl 0xc(%rdi), %r8d
mulss %xmm4, %xmm9
mulss %xmm7, %xmm10
addss %xmm9, %xmm10
cvttss2si %xmm10, %rsi
movl %r8d, %r10d
shrl %r10d
xorps %xmm10, %xmm10
cvtsi2ss %r10d, %xmm10
cmpl %esi, %r9d
jbe 0x26b9
movaps %xmm7, %xmm11
mulss %xmm10, %xmm11
addss %xmm8, %xmm11
cvttss2si %xmm11, %r10
cmpl %r10d, %r8d
jbe 0x26b9
movq (%rdi), %r8
imull 0x10(%rdi), %r10d
leal (%r10,%rsi,4), %esi
movl %edx, (%r8,%rsi)
movl 0x8(%rdi), %r9d
movl 0xc(%rdi), %r8d
movl %r9d, %esi
shrl %esi
xorps %xmm10, %xmm10
cvtsi2ss %esi, %xmm10
mulss %xmm7, %xmm10
addss %xmm9, %xmm10
cvttss2si %xmm10, %rsi
movl %r8d, %r10d
shrl %r10d
xorps %xmm10, %xmm10
cvtsi2ss %r10d, %xmm10
cmpl %esi, %r9d
jbe 0x26e2
mulss %xmm7, %xmm10
addss %xmm6, %xmm10
cvttss2si %xmm10, %r9
cmpl %r9d, %r8d
jbe 0x26e2
movq (%rdi), %r8
imull 0x10(%rdi), %r9d
leal (%r9,%rsi,4), %esi
movl %edx, (%r8,%rsi)
xorps %xmm9, %xmm9
cvtsi2ss %eax, %xmm9
incl %eax
ucomiss %xmm9, %xmm1
jae 0x261a
cvttps2dq %xmm3, %xmm4
cvtdq2ps %xmm4, %xmm6
ucomiss %xmm6, %xmm0
jb 0x2804
cvttss2si %xmm3, %eax
movss 0x8(%rcx), %xmm3
movss 0x18fc(%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
movl 0x8(%rdi), %ecx
movl %ecx, %esi
shrl %esi
xorps %xmm7, %xmm7
cvtsi2ss %esi, %xmm7
movl 0xc(%rdi), %esi
movaps %xmm4, %xmm8
mulss %xmm7, %xmm8
addss %xmm2, %xmm8
cvttss2si %xmm8, %r9
movl %esi, %r8d
shrl %r8d
xorps %xmm8, %xmm8
cvtsi2ss %r8d, %xmm8
addss %xmm5, %xmm6
mulss %xmm3, %xmm6
mulss %xmm4, %xmm8
addss %xmm6, %xmm8
cvttss2si %xmm8, %r8
cmpl %r9d, %ecx
jbe 0x27cc
cmpl %r8d, %esi
jbe 0x27cc
movq (%rdi), %rcx
imull 0x10(%rdi), %r8d
leal (%r8,%r9,4), %esi
movl %edx, (%rcx,%rsi)
movl 0x8(%rdi), %ecx
movl 0xc(%rdi), %esi
movl %ecx, %r8d
shrl %r8d
xorps %xmm7, %xmm7
cvtsi2ss %r8d, %xmm7
movl %esi, %r8d
shrl %r8d
xorps %xmm8, %xmm8
cvtsi2ss %r8d, %xmm8
mulss %xmm4, %xmm8
addss %xmm6, %xmm8
cvttss2si %xmm8, %r8
mulss %xmm4, %xmm7
addss %xmm1, %xmm7
cvttss2si %xmm7, %r9
cmpl %r9d, %ecx
jbe 0x27f2
cmpl %r8d, %esi
jbe 0x27f2
movq (%rdi), %rcx
imull 0x10(%rdi), %r8d
leal (%r8,%r9,4), %esi
movl %edx, (%rcx,%rsi)
xorps %xmm6, %xmm6
cvtsi2ss %eax, %xmm6
incl %eax
ucomiss %xmm6, %xmm0
jae 0x2737
retq