// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Grid.cpp
// Function: gaps::R2Grid::RasterizeGridCircle(gaps::R2Point const&, double, double, int)
void R2Grid::
RasterizeGridCircle(const R2Point& center, RNLength radius, RNScalar value, int operation)
{
  // Figure out the min and max in each dimension
  int mn[2], mx[2];
  for (int i = 0; i < 2; i++) {
    mx[i]= (int) (center[i]+radius);
    if (mx[i] < 0) return;
    if (mx[i] > Resolution(i)-1) mx[i] = Resolution(i)-1;
    mn[i]= (int) (center[i]-radius);
    if (mn[i] > Resolution(i)-1) return;
    if (mn[i] < 0) mn[i] = 0;
  }

  // Rasterize circle interior
  int y1 = (int) (center[1] - radius + 0.5);
  int y2 = (int) (center[1] + radius + 0.5);
  if (y1 < mn[1]) y1 = mn[1];
  if (y2 > mx[1]) y2 = mx[1];
  RNLength radius_squared = radius * radius;
  for (int j = y1; j <= y2; j++) {
    RNCoord y = j - center[1];
    RNCoord y_squared = y*y;
    RNLength x_squared = radius_squared - y_squared;
    RNLength x = sqrt(x_squared);
    int x1 = (int) (center[0] - x + 0.5);
    int x2 = (int) (center[0] + x + 0.5);
    if (x1 < mn[0]) x1 = mn[0];
    if (x2 > mx[0]) x2 = mx[0];
    for (int i = x1; i <= x2; i++) {
      RasterizeGridValue(i, j, value, operation);
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %edx, %ebx
movapd %xmm1, %xmm3
movq %rsi, %r14
movq %rdi, %r15
leaq 0xc0(%rdi), %rax
xorl %ecx, %ecx
xorl %edx, %edx
movsd (%r14,%rdx,2), %xmm2
movapd %xmm2, %xmm1
addsd %xmm0, %xmm1
cvttsd2si %xmm1, %edi
movl %edi, 0x18(%rsp,%rdx)
testl %edi, %edi
js 0x5d838
movl (%rax,%rdx), %esi
cmpl %edi, %esi
jg 0x5d6f5
leal -0x1(%rsi), %edi
movl %edi, 0x18(%rsp,%rdx)
subsd %xmm0, %xmm2
cvttsd2si %xmm2, %edi
movl %edi, 0x20(%rsp,%rdx)
cmpl %edi, %esi
jle 0x5d838
testl %edi, %edi
cmovlel %ecx, %edi
movl %edi, 0x20(%rsp,%rdx)
addq $0x4, %rdx
cmpq $0x4, %rdx
je 0x5d6c9
movsd 0x8(%r14), %xmm2
movapd %xmm2, %xmm1
subsd %xmm0, %xmm1
movsd 0x448fe(%rip), %xmm4    # 0xa2030
addsd %xmm4, %xmm1
cvttsd2si %xmm1, %r12d
addsd %xmm0, %xmm2
addsd %xmm4, %xmm2
cvttsd2si %xmm2, %ecx
movl 0x24(%rsp), %eax
cmpl %r12d, %eax
cmovgl %eax, %r12d
movl 0x1c(%rsp), %eax
cmpl %ecx, %eax
cmovll %eax, %ecx
movl %ecx, 0x14(%rsp)
cmpl %ecx, %r12d
jg 0x5d838
mulsd %xmm0, %xmm0
movl 0x20(%rsp), %eax
movl %eax, 0x10(%rsp)
movl 0x18(%rsp), %eax
movl %eax, 0xc(%rsp)
movsd %xmm3, 0x28(%rsp)
movsd %xmm0, 0x30(%rsp)
xorps %xmm1, %xmm1
cvtsi2sd %r12d, %xmm1
subsd 0x8(%r14), %xmm1
mulsd %xmm1, %xmm1
subsd %xmm1, %xmm0
ucomisd 0x44a42(%rip), %xmm0    # 0xa21e8
jb 0x5d7ae
sqrtsd %xmm0, %xmm0
jmp 0x5d7b9
callq 0xe340
movsd 0x28(%rsp), %xmm3
movsd (%r14), %xmm1
movapd %xmm1, %xmm2
subsd %xmm0, %xmm2
movsd 0x44862(%rip), %xmm4    # 0xa2030
addsd %xmm4, %xmm2
cvttsd2si %xmm2, %ebp
addsd %xmm1, %xmm0
addsd %xmm4, %xmm0
cvttsd2si %xmm0, %r13d
movl 0x10(%rsp), %eax
cmpl %ebp, %eax
cmovgl %eax, %ebp
movl 0xc(%rsp), %eax
cmpl %r13d, %eax
cmovll %eax, %r13d
cmpl %r13d, %ebp
jg 0x5d81f
incl %r13d
movq %r15, %rdi
movl %ebp, %esi
movl %r12d, %edx
movapd %xmm3, %xmm0
movl %ebx, %ecx
callq 0x5f8c6
movsd 0x28(%rsp), %xmm3
incl %ebp
cmpl %ebp, %r13d
jne 0x5d7ff
leal 0x1(%r12), %eax
cmpl 0x14(%rsp), %r12d
movl %eax, %r12d
movsd 0x30(%rsp), %xmm0
jne 0x5d788
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop