// File: 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:
subq $0x58, %rsp
leaq 0x60(%rsp), %rax
movq %rax, 0x8(%rsp)
movq %rdi, 0x50(%rsp)
movss %xmm0, 0x4c(%rsp)
movss %xmm1, 0x48(%rsp)
movss %xmm2, 0x44(%rsp)
movq 0x50(%rsp), %rdi
callq 0x11c00
movl %eax, %eax
cvtsi2ss %rax, %xmm0
movss %xmm0, 0x40(%rsp)
movq 0x50(%rsp), %rdi
callq 0x11c10
movl %eax, %eax
cvtsi2ss %rax, %xmm0
movss %xmm0, 0x3c(%rsp)
movss 0x4c(%rsp), %xmm0
subss 0x44(%rsp), %xmm0
callq 0x1c2a0
movss 0x40(%rsp), %xmm2
xorps %xmm1, %xmm1
callq 0x1bf00
cvttss2si %xmm0, %eax
movl %eax, 0x38(%rsp)
movss 0x4c(%rsp), %xmm0
addss 0x44(%rsp), %xmm0
callq 0x1c2c0
movss 0x40(%rsp), %xmm2
xorps %xmm1, %xmm1
callq 0x1bf00
cvttss2si %xmm0, %eax
movl %eax, 0x34(%rsp)
movss 0x48(%rsp), %xmm0
subss 0x44(%rsp), %xmm0
callq 0x1c2a0
movss 0x3c(%rsp), %xmm2
xorps %xmm1, %xmm1
callq 0x1bf00
cvttss2si %xmm0, %eax
movl %eax, 0x30(%rsp)
movss 0x48(%rsp), %xmm0
addss 0x44(%rsp), %xmm0
callq 0x1c2c0
movss 0x3c(%rsp), %xmm2
xorps %xmm1, %xmm1
callq 0x1bf00
cvttss2si %xmm0, %eax
movl %eax, 0x2c(%rsp)
movl 0x30(%rsp), %eax
movl %eax, 0x28(%rsp)
movl 0x28(%rsp), %eax
cmpl 0x2c(%rsp), %eax
jge 0x1d579
movl 0x38(%rsp), %eax
movl %eax, 0x24(%rsp)
movl 0x24(%rsp), %eax
cmpl 0x34(%rsp), %eax
jge 0x1d567
cvtsi2ssl 0x24(%rsp), %xmm0
movss 0xb87(%rip), %xmm1      # 0x1e030
addss %xmm1, %xmm0
movss %xmm0, 0x20(%rsp)
cvtsi2ssl 0x28(%rsp), %xmm0
movss 0xb6f(%rip), %xmm1      # 0x1e030
addss %xmm1, %xmm0
movss %xmm0, 0x1c(%rsp)
movss 0x20(%rsp), %xmm0
subss 0x4c(%rsp), %xmm0
movss %xmm0, 0x18(%rsp)
movss 0x1c(%rsp), %xmm0
subss 0x48(%rsp), %xmm0
movss %xmm0, 0x14(%rsp)
movss 0x18(%rsp), %xmm0
movss 0x18(%rsp), %xmm2
movss 0x14(%rsp), %xmm1
mulss 0x14(%rsp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
callq 0x1bf70
movss %xmm0, 0x10(%rsp)
movq 0x50(%rsp), %rdi
movl 0x24(%rsp), %esi
movl 0x28(%rsp), %edx
callq 0x1c470
movq 0x8(%rsp), %rdi
movq %rax, %rsi
movss 0x20(%rsp), %xmm0
movss 0x1c(%rsp), %xmm1
movss 0x4c(%rsp), %xmm2
movss 0x48(%rsp), %xmm3
movss 0x10(%rsp), %xmm4
callq 0x1c380
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x1d48d
jmp 0x1d569
movl 0x28(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x28(%rsp)
jmp 0x1d477
addq $0x58, %rsp
retq
nop