// File: /workspace/github_c_makefile_star2_O3/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, %xmm5
cmpnless %xmm3, %xmm5
andps %xmm5, %xmm1
movss 0x2f24(%rip), %xmm4     # 0x6008
andnps %xmm4, %xmm5
orps %xmm1, %xmm5
movaps %xmm2, %xmm1
cmpnless %xmm3, %xmm1
andps %xmm1, %xmm2
andnps %xmm4, %xmm1
orps %xmm2, %xmm1
movaps %xmm1, %xmm3
movsd (%rsi), %xmm1
cvtdq2ps %xmm1, %xmm2
movaps %xmm2, %xmm1
shufps $0x55, %xmm2, %xmm1     # xmm1 = xmm1[1,1],xmm2[1,1]
movaps %xmm2, 0x70(%rsp)
mulss %xmm2, %xmm5
movaps %xmm5, 0x50(%rsp)
movaps %xmm1, 0x10(%rsp)
mulss %xmm1, %xmm3
movaps %xmm3, 0x40(%rsp)
xorps 0x2f51(%rip), %xmm0     # 0x6080
movaps %xmm0, 0x30(%rsp)
callq 0x21d0
movaps %xmm0, 0x20(%rsp)
movaps 0x30(%rsp), %xmm0
callq 0x2180
movaps 0x20(%rsp), %xmm9
movaps 0x40(%rsp), %xmm8
movaps 0x50(%rsp), %xmm7
movaps %xmm0, %xmm6
movaps %xmm7, %xmm0
mulss %xmm6, %xmm0
movaps %xmm9, %xmm1
mulss %xmm8, %xmm1
movaps %xmm7, %xmm2
xorps 0x2f0a(%rip), %xmm2     # 0x6080
movaps %xmm6, %xmm3
mulss %xmm2, %xmm3
movaps %xmm3, %xmm4
addss %xmm1, %xmm4
cvttss2si %xmm4, %ecx
movaps %xmm0, %xmm4
addss %xmm1, %xmm4
cvttss2si %xmm4, %edx
subss %xmm1, %xmm0
cvttss2si %xmm0, %esi
movaps %xmm8, %xmm0
subss %xmm1, %xmm3
cvttss2si %xmm3, %r13d
mulss %xmm6, %xmm0
movaps %xmm9, %xmm1
shufps $0x0, %xmm9, %xmm1      # xmm1 = xmm1[0,0],xmm9[0,0]
movaps %xmm7, %xmm3
shufps $0x0, %xmm2, %xmm3      # xmm3 = xmm3[0,0],xmm2[0,0]
mulps %xmm1, %xmm3
shufps $0x0, %xmm0, %xmm0      # xmm0 = xmm0[0,0,0,0]
movaps %xmm3, %xmm1
subps %xmm0, %xmm1
addps %xmm3, %xmm0
shufps $0xd8, %xmm0, %xmm1     # xmm1 = xmm1[0,2],xmm0[1,3]
shufps $0xd8, %xmm1, %xmm1     # xmm1 = xmm1[0,2,1,3]
cmpl %esi, %edx
movl %esi, %eax
cmovll %edx, %eax
cvttps2dq %xmm1, %xmm1
cmpl %eax, %ecx
cmovll %ecx, %eax
cmpl %r13d, %eax
cmovgel %r13d, %eax
pshufd $0xee, %xmm1, %xmm2     # xmm2 = xmm1[2,3,2,3]
movdqa %xmm1, %xmm0
pcmpgtd %xmm2, %xmm0
movdqa %xmm0, %xmm3
pandn %xmm1, %xmm3
movdqa %xmm2, %xmm4
pand %xmm0, %xmm4
por %xmm3, %xmm4
pshufd $0x55, %xmm4, %xmm3     # xmm3 = xmm4[1,1,1,1]
movdqa %xmm3, %xmm5
pcmpgtd %xmm4, %xmm5
pand %xmm5, %xmm4
pandn %xmm3, %xmm5
por %xmm4, %xmm5
movd %xmm5, %edi
movl %edi, %ebx
sarl $0x1f, %ebx
andl %edi, %ebx
cmpl %r13d, %esi
cmovgl %esi, %r13d
cmpl %r13d, %edx
cmovgl %edx, %r13d
cmpl %r13d, %ecx
cmovgl %ecx, %r13d
pand %xmm0, %xmm1
pandn %xmm2, %xmm0
por %xmm1, %xmm0
pshufd $0x55, %xmm0, %xmm1     # xmm1 = xmm0[1,1,1,1]
movdqa %xmm0, %xmm2
pcmpgtd %xmm1, %xmm2
pand %xmm2, %xmm0
pandn %xmm1, %xmm2
por %xmm0, %xmm2
movd %xmm2, %ecx
pxor %xmm2, %xmm2
movl %ecx, 0xc(%rsp)
cmpl %ecx, %ebx
jge 0x340f
movaps 0x70(%rsp), %xmm0
movaps %xmm0, %xmm3
divss %xmm7, %xmm3
movaps 0x10(%rsp), %xmm1
divss %xmm8, %xmm1
movaps %xmm1, 0x10(%rsp)
movaps 0x2e00(%rip), %xmm4     # 0x60a0
mulps %xmm0, %xmm4
movl %eax, %ecx
sarl $0x1f, %ecx
andl %eax, %ecx
movl %ecx, 0x8(%rsp)
movaps %xmm4, %xmm5
movaps 0x2dc8(%rip), %xmm0     # 0x6080
xorps %xmm0, %xmm5
movaps %xmm4, %xmm1
shufps $0x55, %xmm4, %xmm1     # xmm1 = xmm1[1,1],xmm4[1,1]
xorps %xmm0, %xmm1
movaps %xmm1, 0x90(%rsp)
movlhps %xmm9, %xmm6            # xmm6 = xmm6[0],xmm9[0]
movaps %xmm6, %xmm0
shufps $0xe2, %xmm9, %xmm0     # xmm0 = xmm0[2,0],xmm9[2,3]
movaps %xmm0, 0x80(%rsp)
shufps $0xe8, %xmm9, %xmm6     # xmm6 = xmm6[0,2],xmm9[2,3]
movaps %xmm6, 0x40(%rsp)
movaps %xmm3, 0x30(%rsp)
movaps %xmm4, 0x20(%rsp)
movaps %xmm5, 0xa0(%rsp)
cmpl %r13d, 0x8(%rsp)
jge 0x3403
xorps %xmm0, %xmm0
cvtsi2ss %ebx, %xmm0
mulss 0x10(%rsp), %xmm0
addss 0x90(%rsp), %xmm0
movaps %xmm0, %xmm7
xorps 0x2d58(%rip), %xmm7     # 0x6080
unpcklps %xmm0, %xmm7            # xmm7 = xmm7[0],xmm0[0],xmm7[1],xmm0[1]
mulps 0x80(%rsp), %xmm7
movq 0x60(%rsp), %rax
leal (%rbx,%rax), %ebp
movl 0x8(%rsp), %eax
movl %eax, %r14d
movaps %xmm7, 0x50(%rsp)
xorps %xmm0, %xmm0
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 0x33f7
movaps %xmm0, %xmm1
cmpltps 0x70(%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 0x33f7
cvttss2si %xmm0, %eax
movl $0xffff00ff, %ecx       # imm = 0xFFFF00FF
testl %eax, %eax
js 0x33c5
cvttss2si %xmm1, %esi
testl %esi, %esi
js 0x33c5
movl (%r15), %edx
cmpl %eax, %edx
jle 0x33c5
cmpl %esi, 0x4(%r15)
jle 0x33c5
imull %esi, %edx
addl %eax, %edx
movq 0x10(%r15), %rax
movl (%rax,%rdx,4), %ecx
movq 0x68(%rsp), %rax
leal (%rax,%r14), %esi
movq %r12, %rdi
movl %ebp, %edx
callq 0x2b68
xorps %xmm2, %xmm2
movaps 0x40(%rsp), %xmm6
movaps 0x30(%rsp), %xmm3
movaps 0x20(%rsp), %xmm4
movaps 0xa0(%rsp), %xmm5
movaps 0x50(%rsp), %xmm7
incl %r14d
cmpl %r14d, %r13d
jne 0x3347
incl %ebx
cmpl 0xc(%rsp), %ebx
jne 0x32fd
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq