// File: /workspace/github_c_makefile_star2_O2/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 $0xb8, %rsp
movq %rcx, 0x60(%rsp)
movq %rdx, 0x68(%rsp)
movq %rsi, %r15
movq %rdi, %r12
xorps %xmm3, %xmm3
movaps %xmm1, %xmm4
cmpnless %xmm3, %xmm4
andps %xmm4, %xmm1
movss 0x305b(%rip), %xmm5     # 0x6008
andnps %xmm5, %xmm4
orps %xmm1, %xmm4
movaps %xmm4, %xmm6
movaps %xmm2, %xmm1
cmpnless %xmm3, %xmm1
andps %xmm1, %xmm2
andnps %xmm5, %xmm1
orps %xmm2, %xmm1
movaps %xmm1, %xmm3
movsd (%rsi), %xmm1
cvtdq2ps %xmm1, %xmm4
movaps %xmm4, %xmm1
shufps $0x55, %xmm4, %xmm1     # xmm1 = xmm1[1,1],xmm4[1,1]
mulss %xmm4, %xmm6
movaps %xmm6, 0x40(%rsp)
mulss %xmm1, %xmm3
movaps %xmm3, 0x50(%rsp)
movaps %xmm4, %xmm2
divss %xmm6, %xmm2
movaps %xmm2, 0x80(%rsp)
divss %xmm3, %xmm1
movaps %xmm1, 0x90(%rsp)
movaps 0x3054(%rip), %xmm1     # 0x6060
movaps %xmm4, 0xa0(%rsp)
mulps %xmm4, %xmm1
movaps %xmm1, 0x70(%rsp)
shufps $0x55, %xmm1, %xmm1     # xmm1 = xmm1[1,1,1,1]
movaps %xmm1, 0x20(%rsp)
xorps 0x3044(%rip), %xmm0     # 0x6070
movaps %xmm0, 0x30(%rsp)
callq 0x21d0
movaps %xmm0, 0x10(%rsp)
movaps 0x30(%rsp), %xmm0
callq 0x2180
movaps 0x40(%rsp), %xmm4
movaps %xmm4, %xmm1
mulss %xmm0, %xmm1
movaps 0x10(%rsp), %xmm8
movaps %xmm8, %xmm2
movaps 0x50(%rsp), %xmm9
mulss %xmm9, %xmm2
movaps %xmm4, %xmm3
movaps %xmm4, %xmm6
movaps 0x2ffd(%rip), %xmm7     # 0x6070
xorps %xmm7, %xmm3
movaps %xmm0, %xmm4
mulss %xmm3, %xmm4
movaps %xmm4, %xmm5
addss %xmm2, %xmm5
cvttss2si %xmm5, %eax
movaps %xmm1, %xmm5
addss %xmm2, %xmm5
cvttss2si %xmm5, %ecx
subss %xmm2, %xmm1
cvttss2si %xmm1, %edx
subss %xmm2, %xmm4
cvttss2si %xmm4, %r13d
movaps %xmm9, %xmm4
mulss %xmm0, %xmm4
movaps %xmm8, %xmm1
shufps $0x0, %xmm8, %xmm1      # xmm1 = xmm1[0,0],xmm8[0,0]
movaps %xmm6, %xmm2
shufps $0x0, %xmm3, %xmm2      # xmm2 = xmm2[0,0],xmm3[0,0]
mulps %xmm1, %xmm2
movaps %xmm4, %xmm3
shufps $0x0, %xmm4, %xmm3      # xmm3 = xmm3[0,0],xmm4[0,0]
movaps %xmm2, %xmm1
subps %xmm3, %xmm1
addps %xmm2, %xmm3
shufps $0xd8, %xmm3, %xmm1     # xmm1 = xmm1[0,2],xmm3[1,3]
shufps $0xd8, %xmm1, %xmm1     # xmm1 = xmm1[0,2,1,3]
cvttps2dq %xmm1, %xmm2
cmpl %edx, %ecx
movl %edx, %esi
cmovll %ecx, %esi
cmpl %esi, %eax
cmovll %eax, %esi
cmpl %r13d, %esi
cmovgel %r13d, %esi
movl %esi, %edi
sarl $0x1f, %edi
andl %esi, %edi
movl %edi, 0x8(%rsp)
pshufd $0xee, %xmm2, %xmm1     # xmm1 = xmm2[2,3,2,3]
movdqa %xmm1, %xmm3
pcmpgtd %xmm2, %xmm3
pshufd $0x55, %xmm2, %xmm4     # xmm4 = xmm2[1,1,1,1]
pshufd $0xff, %xmm2, %xmm5     # xmm5 = xmm2[3,3,3,3]
movd %xmm2, %esi
pand %xmm3, %xmm2
pandn %xmm1, %xmm3
por %xmm2, %xmm3
pshufd $0x55, %xmm3, %xmm2     # xmm2 = xmm3[1,1,1,1]
movdqa %xmm2, %xmm6
pcmpgtd %xmm3, %xmm6
pand %xmm6, %xmm3
pandn %xmm2, %xmm6
pxor %xmm2, %xmm2
por %xmm3, %xmm6
movaps 0x80(%rsp), %xmm3
movd %xmm6, %edi
movl %edi, %ebx
sarl $0x1f, %ebx
andl %edi, %ebx
cmpl %r13d, %edx
cmovgl %edx, %r13d
unpcklps %xmm0, %xmm8            # xmm8 = xmm8[0],xmm0[0],xmm8[1],xmm0[1]
cmpl %r13d, %ecx
cmovgl %ecx, %r13d
cmpl %r13d, %eax
cmovgl %eax, %r13d
movd %xmm4, %eax
movaps 0x70(%rsp), %xmm4
movd %xmm5, %ecx
cmpl %ecx, %eax
cmovgl %eax, %ecx
cmpl %ecx, %esi
cmovgl %esi, %ecx
movd %xmm1, %eax
cmpl %ecx, %eax
cmovgl %eax, %ecx
movl %ecx, 0xc(%rsp)
movaps %xmm4, %xmm5
xorps %xmm7, %xmm5
movaps 0x20(%rsp), %xmm0
xorps %xmm7, %xmm0
movaps %xmm0, 0x20(%rsp)
movaps %xmm8, 0x10(%rsp)
movaps %xmm8, %xmm6
shufps $0xe1, %xmm8, %xmm6     # xmm6 = xmm6[1,0],xmm8[2,3]
movaps %xmm5, 0x40(%rsp)
movaps %xmm6, 0x30(%rsp)
cmpl 0xc(%rsp), %ebx
je 0x32a4
cvtsi2ss %ebx, %xmm0
mulss 0x90(%rsp), %xmm0
addss 0x20(%rsp), %xmm0
movaps %xmm0, %xmm7
xorps 0x2e90(%rip), %xmm7     # 0x6070
unpcklps %xmm0, %xmm7            # xmm7 = xmm7[0],xmm0[0],xmm7[1],xmm0[1]
mulps 0x10(%rsp), %xmm7
movq 0x60(%rsp), %rax
leal (%rbx,%rax), %ebp
movl 0x8(%rsp), %eax
movl %eax, %r14d
movaps %xmm7, 0x50(%rsp)
cmpl %r14d, %r13d
je 0x329d
cvtsi2ss %r14d, %xmm0
mulss %xmm3, %xmm0
addss %xmm5, %xmm0
shufps $0x0, %xmm0, %xmm0      # xmm0 = xmm0[0,0,0,0]
mulps %xmm6, %xmm0
addps %xmm7, %xmm0
addps %xmm4, %xmm0
ucomiss %xmm2, %xmm0
jb 0x3295
movaps %xmm0, %xmm1
cmpltps 0xa0(%rsp), %xmm1
unpcklps %xmm1, %xmm1            # xmm1 = xmm1[0,0,1,1]
movmskpd %xmm1, %eax
movl %eax, %ecx
shrb %cl
movaps %xmm0, %xmm1
shufps $0x55, %xmm0, %xmm1     # xmm1 = xmm1[1,1],xmm0[1,1]
ucomiss %xmm2, %xmm1
setae %dl
andb %al, %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x3295
cvttss2si %xmm0, %esi
cvttss2si %xmm1, %edx
movq %r15, %rdi
callq 0x2b28
movq 0x68(%rsp), %rcx
leal (%rcx,%r14), %esi
movq %r12, %rdi
movl %ebp, %edx
movl %eax, %ecx
callq 0x2b4d
movaps 0x50(%rsp), %xmm7
movaps 0x30(%rsp), %xmm6
movaps 0x40(%rsp), %xmm5
movaps 0x70(%rsp), %xmm4
movaps 0x80(%rsp), %xmm3
xorps %xmm2, %xmm2
incl %r14d
jmp 0x31fc
incl %ebx
jmp 0x31b9
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq