// File: /workspace/github_c_makefile_star2_O1/adelciotto[P]scg/examples/../scg.h
// Function: scg_image_draw_image_rotate_scale
void scg_image_draw_image_rotate_scale(scg_image_t *dest, scg_image_t *src,
                                       int x, int y, float32_t angle,
                                       float32_t sx, float32_t sy) {
    if (sx <= 0.0f)
        sx = 1.0f;
    if (sy <= 0.0f)
        sy = 1.0f;

    float32_t src_w = src->width;
    float32_t src_h = src->height;
    float32_t src_sw = src_w * sx;
    float32_t src_sh = src_h * sy;

    float32_t ratio_x = src_w / src_sw;
    float32_t ratio_y = src_h / src_sh;
    float32_t origin_x = src_w * 0.5f;
    float32_t origin_y = src_h * 0.5f;

    float32_t sin_theta = sinf(-angle);
    float32_t cos_theta = cosf(-angle);

    float32_t a = src_sw * cos_theta;
    float32_t b = src_sh * cos_theta;
    float32_t c = src_sw * sin_theta;
    float32_t d = src_sh * sin_theta;
    float32_t e = -src_sw * cos_theta;
    float32_t f = -src_sw * sin_theta;
    int x0 = (int)(e + d);
    int y0 = (int)(f - b);
    int x1 = (int)(a + d);
    int y1 = (int)(c - b);
    int x2 = (int)(a - d);
    int y2 = (int)(c + b);
    int x3 = (int)(e - d);
    int y3 = (int)(f + b);

    int minx =
        scg_min_int(0, scg_min_int(scg_min_int(x0, scg_min_int(x1, x2)), x3));
    int miny =
        scg_min_int(0, scg_min_int(scg_min_int(y0, scg_min_int(y1, y2)), y3));
    int maxx = scg_max_int(x0, scg_max_int(x1, scg_max_int(x2, x3)));
    int maxy = scg_max_int(y0, scg_max_int(y1, scg_max_int(y2, y3)));

    for (int i = miny; i < maxy; i++) {
        for (int j = minx; j < maxx; j++) {
            float32_t image_x = (float32_t)j * ratio_x - origin_x;
            float32_t image_y = (float32_t)i * ratio_y - origin_y;
            float32_t xt =
                (image_x * cos_theta - image_y * sin_theta) + origin_x;
            float32_t yt =
                (image_x * sin_theta + image_y * cos_theta) + origin_y;

            if (xt >= 0 && xt < src_w && yt >= 0 && yt < src_h) {
                scg_pixel_t color = scg_image_get_pixel(src, (int)xt, (int)yt);
                scg_image_set_pixel(dest, x + j, y + i, color);
            }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rcx, 0x50(%rsp)
movq %rdx, 0x58(%rsp)
movq %rsi, %r15
movq %rdi, %r12
xorps %xmm3, %xmm3
movaps %xmm1, %xmm5
cmpnless %xmm3, %xmm5
andps %xmm5, %xmm1
movss 0x2fee(%rip), %xmm4     # 0x6008
andnps %xmm4, %xmm5
orps %xmm1, %xmm5
movaps %xmm2, %xmm6
cmpnless %xmm3, %xmm6
andps %xmm6, %xmm2
andnps %xmm4, %xmm6
xorps %xmm3, %xmm3
cvtsi2ssl (%rsi), %xmm3
orps %xmm2, %xmm6
xorps %xmm1, %xmm1
cvtsi2ssl 0x4(%rsi), %xmm1
movss %xmm3, 0xc(%rsp)
mulss %xmm3, %xmm5
movaps %xmm5, 0x40(%rsp)
movss %xmm1, 0x8(%rsp)
mulss %xmm1, %xmm6
movaps %xmm6, 0x30(%rsp)
xorps 0x2ffb(%rip), %xmm0     # 0x6060
movaps %xmm0, 0x20(%rsp)
callq 0x21d0
movss %xmm0, (%rsp)
movaps 0x20(%rsp), %xmm0
callq 0x2180
movaps 0x30(%rsp), %xmm9
movaps 0x40(%rsp), %xmm8
movaps %xmm0, %xmm7
movaps %xmm8, %xmm1
mulss %xmm0, %xmm1
movaps %xmm9, %xmm0
mulss %xmm7, %xmm0
movaps %xmm8, %xmm2
movss (%rsp), %xmm6
mulss %xmm6, %xmm2
movaps %xmm6, %xmm3
mulss %xmm9, %xmm3
movaps %xmm8, %xmm4
xorps 0x2fa3(%rip), %xmm4     # 0x6060
movaps %xmm7, %xmm5
mulss %xmm4, %xmm5
mulss %xmm6, %xmm4
movaps %xmm5, %xmm6
addss %xmm3, %xmm6
cvttss2si %xmm6, %edx
movaps %xmm4, %xmm6
subss %xmm0, %xmm6
cvttss2si %xmm6, %eax
movaps %xmm1, %xmm6
addss %xmm3, %xmm6
cvttss2si %xmm6, %edi
movaps %xmm2, %xmm6
subss %xmm0, %xmm6
cvttss2si %xmm6, %esi
subss %xmm3, %xmm1
cvttss2si %xmm1, %r9d
addss %xmm0, %xmm2
cvttss2si %xmm2, %r8d
xorps %xmm2, %xmm2
subss %xmm3, %xmm5
cvttss2si %xmm5, %r13d
addss %xmm0, %xmm4
cvttss2si %xmm4, %r11d
cmpl %r9d, %edi
movl %r9d, %ecx
cmovll %edi, %ecx
cmpl %ecx, %edx
cmovll %edx, %ecx
cmpl %r13d, %ecx
cmovgel %r13d, %ecx
cmpl %r8d, %esi
movl %r8d, %r10d
cmovll %esi, %r10d
cmpl %r10d, %eax
cmovll %eax, %r10d
cmpl %r11d, %r10d
cmovgel %r11d, %r10d
movl %r10d, %ebx
sarl $0x1f, %ebx
andl %r10d, %ebx
cmpl %r13d, %r9d
cmovgl %r9d, %r13d
cmpl %r13d, %edi
cmovgl %edi, %r13d
cmpl %r13d, %edx
cmovgl %edx, %r13d
cmpl %r11d, %r8d
cmovgl %r8d, %r11d
cmpl %r11d, %esi
cmovgl %esi, %r11d
cmpl %r11d, %eax
cmovgl %eax, %r11d
movl %r11d, 0x14(%rsp)
cmpl %r11d, %ebx
jge 0x3323
movss 0xc(%rsp), %xmm0
movaps %xmm0, %xmm4
divss %xmm8, %xmm4
movss 0x8(%rsp), %xmm1
movaps %xmm1, %xmm3
divss %xmm9, %xmm3
movss %xmm3, 0x10(%rsp)
movss 0x2e51(%rip), %xmm3     # 0x6004
movaps %xmm0, %xmm5
mulss %xmm3, %xmm5
mulss %xmm1, %xmm3
movl %ecx, %eax
sarl $0x1f, %eax
andl %ecx, %eax
movl %eax, 0x4(%rsp)
movaps %xmm5, %xmm6
movaps 0x2e8d(%rip), %xmm0     # 0x6060
xorps %xmm0, %xmm6
movaps %xmm3, 0x30(%rsp)
xorps %xmm0, %xmm3
movaps %xmm3, 0x60(%rsp)
movss %xmm7, 0x1c(%rsp)
movss %xmm4, 0x18(%rsp)
movaps %xmm5, 0x80(%rsp)
movaps %xmm6, 0x70(%rsp)
cmpl %r13d, 0x4(%rsp)
jge 0x3317
xorps %xmm8, %xmm8
cvtsi2ss %ebx, %xmm8
mulss 0x10(%rsp), %xmm8
addss 0x60(%rsp), %xmm8
movaps %xmm7, %xmm0
mulss %xmm8, %xmm0
movss %xmm0, 0x40(%rsp)
xorps 0x2e2c(%rip), %xmm8     # 0x6060
mulss (%rsp), %xmm8
movq 0x50(%rsp), %rax
leal (%rbx,%rax), %ebp
movl 0x4(%rsp), %eax
movl %eax, %r14d
movaps %xmm8, 0x20(%rsp)
xorps %xmm0, %xmm0
cvtsi2ss %r14d, %xmm0
mulss %xmm4, %xmm0
addss %xmm6, %xmm0
movaps %xmm0, %xmm1
mulss %xmm7, %xmm1
addss %xmm8, %xmm1
addss %xmm5, %xmm1
ucomiss %xmm2, %xmm1
jb 0x330b
movss 0xc(%rsp), %xmm3
ucomiss %xmm1, %xmm3
jbe 0x330b
mulss (%rsp), %xmm0
addss 0x40(%rsp), %xmm0
addss 0x30(%rsp), %xmm0
ucomiss %xmm2, %xmm0
jb 0x330b
movss 0x8(%rsp), %xmm3
ucomiss %xmm0, %xmm3
jbe 0x330b
cvttss2si %xmm1, %eax
movl $0xffff00ff, %ecx       # imm = 0xFFFF00FF
testl %eax, %eax
js 0x32d6
cvttss2si %xmm0, %esi
testl %esi, %esi
js 0x32d6
movl (%r15), %edx
cmpl %eax, %edx
jle 0x32d6
cmpl %esi, 0x4(%r15)
jle 0x32d6
imull %esi, %edx
addl %eax, %edx
movq 0x10(%r15), %rax
movl (%rax,%rdx,4), %ecx
movq 0x58(%rsp), %rax
leal (%rax,%r14), %esi
movq %r12, %rdi
movl %ebp, %edx
callq 0x2b68
xorps %xmm2, %xmm2
movss 0x1c(%rsp), %xmm7
movss 0x18(%rsp), %xmm4
movaps 0x80(%rsp), %xmm5
movaps 0x70(%rsp), %xmm6
movaps 0x20(%rsp), %xmm8
incl %r14d
cmpl %r14d, %r13d
jne 0x324f
incl %ebx
cmpl 0x14(%rsp), %ebx
jne 0x31fc
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq