// File: /workspace/github_cpp_makefile_star2_O1/misohena[P]drawstars/drawstars.cpp
// Function: void fillCircle<PixelPlotter>(Image<ColorRGB<double>>&, float, float, float, PixelPlotter)
void fillCircle(ImageType &canvas, float cx, float cy, float radius, F funcPlot)
{
    const float canvasW = canvas.width();
    const float canvasH = canvas.height();
    const int xmin = static_cast<int>(clamp(std::floor(cx - radius), 0.0f, canvasW));
    const int xmax = static_cast<int>(clamp(std::ceil(cx + radius), 0.0f, canvasW));
    const int ymin = static_cast<int>(clamp(std::floor(cy - radius), 0.0f, canvasH));
    const int ymax = static_cast<int>(clamp(std::ceil(cy + radius), 0.0f, canvasH));
    for(int py = ymin; py < ymax; ++py){
        for(int px = xmin; px < xmax; ++px){
            const float pxf = px + 0.5f;
            const float pyf = py + 0.5f;
            const float dx = pxf - cx;
            const float dy = pyf - cy;
            const float dist = std::sqrt(dx*dx + dy*dy);
            funcPlot(canvas.at(px, py), pxf, pyf, cx, cy, dist);
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movss %xmm2, (%rsp)
movss %xmm1, 0x4(%rsp)
movq %rdi, %rbx
movl 0x4(%rdi), %eax
xorps %xmm1, %xmm1
cvtsi2ss %rax, %xmm1
movaps %xmm1, 0x30(%rsp)
movss %xmm0, 0x8(%rsp)
movl (%rdi), %r15d
subss %xmm2, %xmm0
callq 0x4110
movaps %xmm0, 0x10(%rsp)
movss 0x8(%rsp), %xmm0
addss (%rsp), %xmm0
callq 0x4190
movaps %xmm0, 0x40(%rsp)
movss 0x4(%rsp), %xmm0
subss (%rsp), %xmm0
callq 0x4110
movaps %xmm0, 0x20(%rsp)
movss (%rsp), %xmm0
addss 0x4(%rsp), %xmm0
callq 0x4190
movaps 0x20(%rsp), %xmm2
unpcklps %xmm0, %xmm2            # xmm2 = xmm2[0],xmm0[0],xmm2[1],xmm0[1]
xorps %xmm0, %xmm0
movaps 0x30(%rsp), %xmm1
shufps $0x0, %xmm1, %xmm1      # xmm1 = xmm1[0,0,0,0]
minps %xmm2, %xmm1
cmpnltps %xmm0, %xmm2
andps %xmm1, %xmm2
cvttps2dq %xmm2, %xmm0
movd %xmm0, %ebp
pshufd $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
movd %xmm0, %eax
movl %eax, 0xc(%rsp)
cmpl %eax, %ebp
jge 0xc4a7
xorps %xmm0, %xmm0
cvtsi2ss %r15, %xmm0
movaps %xmm0, %xmm1
movaps 0x10(%rsp), %xmm2
minss %xmm2, %xmm1
xorps %xmm3, %xmm3
cmpltss %xmm3, %xmm2
andnps %xmm1, %xmm2
cvttss2si %xmm2, %r15d
movaps 0x40(%rsp), %xmm1
minss %xmm1, %xmm0
cmpltss %xmm3, %xmm1
andnps %xmm0, %xmm1
cvttss2si %xmm1, %r12d
leaq 0x90(%rsp), %rax
movss 0x18(%rax), %xmm0
addss 0xc87(%rip), %xmm0      # 0xd02c
movss %xmm0, 0x30(%rsp)
movups (%rax), %xmm0
movaps %xmm0, 0x20(%rsp)
movsd 0x10(%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
cmpl %r12d, %r15d
jge 0xc49b
xorps %xmm0, %xmm0
cvtsi2ss %ebp, %xmm0
addss 0xc3e(%rip), %xmm0      # 0xd014
subss 0x4(%rsp), %xmm0
mulss %xmm0, %xmm0
movss %xmm0, (%rsp)
movl %r15d, %r13d
xorps %xmm0, %xmm0
cvtsi2ss %r13d, %xmm0
addss 0xc1c(%rip), %xmm0      # 0xd014
subss 0x8(%rsp), %xmm0
mulss %xmm0, %xmm0
addss (%rsp), %xmm0
ucomiss %xmm3, %xmm0
jb 0xc415
xorps %xmm1, %xmm1
sqrtss %xmm0, %xmm1
jmp 0xc420
callq 0x4530
xorps %xmm3, %xmm3
movaps %xmm0, %xmm1
divss 0x30(%rsp), %xmm1
movss 0xbe2(%rip), %xmm0      # 0xd010
subss %xmm1, %xmm0
movl (%rbx), %eax
imull %ebp, %eax
addl %r13d, %eax
leaq (%rax,%rax,2), %r14
shlq $0x3, %r14
maxss %xmm3, %xmm0
addq 0x8(%rbx), %r14
ucomiss %xmm3, %xmm0
jb 0xc455
sqrtss %xmm0, %xmm0
jmp 0xc45d
callq 0x4530
xorps %xmm3, %xmm3
cvtss2sd %xmm0, %xmm0
movsd 0x10(%rsp), %xmm1
mulsd %xmm0, %xmm1
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
mulpd 0x20(%rsp), %xmm0
movupd (%r14), %xmm2
addpd %xmm0, %xmm2
movupd %xmm2, (%r14)
addsd 0x10(%r14), %xmm1
movsd %xmm1, 0x10(%r14)
incl %r13d
cmpl %r13d, %r12d
jne 0xc3e8
incl %ebp
cmpl 0xc(%rsp), %ebp
jne 0xc3be
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq