// File: /workspace/github_c_makefile_star2_O0/adelciotto[P]scg/examples/rotozoom.c
// Function: draw
static void draw(scg_image_t *draw_target, scg_image_t *src_image,
                 float32_t angle, float32_t scale) {
    scg_image_clear(draw_target, SCG_COLOR_BLACK);

    int w = draw_target->width;
    int h = draw_target->height;
    const int src_w = src_image->width;
    const int src_h = src_image->height;

    float32_t s = sinf(angle);
    float32_t c = cosf(angle);

    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            float32_t tx = (x * c - y * s) * scale;
            float32_t ty = (x * s + y * c) * scale;

            // No need for mod because image width is 256px.
            int src_x = (int)tx & 255;

            int src_y = (int)ty % src_h;
            while (src_y < 0) {
                src_y += src_h;
            }

            int src_i = scg_pixel_index_from_xy(src_x, src_y, src_w);
            scg_pixel_t color = scg_pixel_new_uint32(src_image->pixels[src_i]);

            int dest_i = scg_pixel_index_from_xy(x, y, w);
            draw_target->pixels[dest_i] = color.packed;
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movss %xmm0, -0x14(%rbp)
movss %xmm1, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movb $0x0, -0x1c(%rbp)
movb $0x0, -0x1b(%rbp)
movb $0x0, -0x1a(%rbp)
movb $-0x1, -0x19(%rbp)
movl -0x1c(%rbp), %esi
callq 0x3100
movq -0x8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x2c(%rbp)
movss -0x14(%rbp), %xmm0
callq 0x21d0
movss %xmm0, -0x30(%rbp)
movss -0x14(%rbp), %xmm0
callq 0x2180
movss %xmm0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x698f
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x697f
cvtsi2ssl -0x3c(%rbp), %xmm0
movss -0x34(%rbp), %xmm2
cvtsi2ssl -0x38(%rbp), %xmm1
mulss -0x30(%rbp), %xmm1
movd %xmm1, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
mulss -0x18(%rbp), %xmm0
movss %xmm0, -0x40(%rbp)
cvtsi2ssl -0x3c(%rbp), %xmm0
movss -0x30(%rbp), %xmm2
cvtsi2ssl -0x38(%rbp), %xmm1
mulss -0x34(%rbp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
mulss -0x18(%rbp), %xmm0
movss %xmm0, -0x44(%rbp)
cvttss2si -0x40(%rbp), %eax
andl $0xff, %eax
movl %eax, -0x48(%rbp)
cvttss2si -0x44(%rbp), %eax
cltd
idivl -0x2c(%rbp)
movl %edx, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
jge 0x6933
movl -0x2c(%rbp), %eax
addl -0x4c(%rbp), %eax
movl %eax, -0x4c(%rbp)
jmp 0x6922
movl -0x4c(%rbp), %eax
imull -0x28(%rbp), %eax
addl -0x48(%rbp), %eax
movl %eax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x50(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x54(%rbp)
movl -0x38(%rbp), %eax
imull -0x20(%rbp), %eax
addl -0x3c(%rbp), %eax
movl %eax, -0x58(%rbp)
movl -0x54(%rbp), %edx
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x58(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x68a4
jmp 0x6981
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x6891
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)