// File: /workspace/github_cpp_makefile_star2_O3/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 0x24(%rsp), %rsi
leaq 0x1c(%rsp), %rdi
movb $0x1, %al
xorl %r8d, %r8d
leaq 0x20(%rsp), %rcx
leaq 0x18(%rsp), %rdx
movsd (%r14,%r8,8), %xmm2
movapd %xmm2, %xmm1
addsd %xmm0, %xmm1
cvttsd2si %xmm1, %r9d
movl %r9d, (%rdi)
testl %r9d, %r9d
js 0x5cadd
movl 0xc0(%r15,%r8,4), %r8d
cmpl %r9d, %r8d
jg 0x5c990
leal -0x1(%r8), %r9d
movl %r9d, (%rdi)
subsd %xmm0, %xmm2
cvttsd2si %xmm2, %edi
cmpl %edi, %r8d
jle 0x5cadd
xorl %r8d, %r8d
testl %edi, %edi
cmovlel %r8d, %edi
movl %edi, (%rsi)
movl $0x1, %r8d
movq %rdx, %rdi
movq %rcx, %rsi
testb $0x1, %al
movl $0x0, %eax
jne 0x5c95d
movsd 0x8(%r14), %xmm2
movapd %xmm2, %xmm1
subsd %xmm0, %xmm1
movsd 0x45659(%rip), %xmm4    # 0xa2030
addsd %xmm4, %xmm1
cvttsd2si %xmm1, %r12d
addsd %xmm0, %xmm2
addsd %xmm4, %xmm2
cvttsd2si %xmm2, %ecx
movl 0x20(%rsp), %eax
cmpl %r12d, %eax
cmovgl %eax, %r12d
movl 0x18(%rsp), %eax
cmpl %ecx, %eax
cmovll %eax, %ecx
movl %ecx, 0x14(%rsp)
cmpl %ecx, %r12d
jg 0x5cadd
mulsd %xmm0, %xmm0
movl 0x24(%rsp), %eax
movl %eax, 0x10(%rsp)
movl 0x1c(%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 0x4579d(%rip), %xmm0    # 0xa21e8
jb 0x5ca53
sqrtsd %xmm0, %xmm0
jmp 0x5ca5e
callq 0xe340
movsd 0x28(%rsp), %xmm3
movsd (%r14), %xmm1
movapd %xmm1, %xmm2
subsd %xmm0, %xmm2
movsd 0x455bd(%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 0x5cac4
incl %r13d
movq %r15, %rdi
movl %ebp, %esi
movl %r12d, %edx
movapd %xmm3, %xmm0
movl %ebx, %ecx
callq 0x5eb14
movsd 0x28(%rsp), %xmm3
incl %ebp
cmpl %ebp, %r13d
jne 0x5caa4
leal 0x1(%r12), %eax
cmpl 0x14(%rsp), %r12d
movl %eax, %r12d
movsd 0x30(%rsp), %xmm0
jne 0x5ca2d
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq