// File: /workspace/github_cpp_makefile_star2_O2/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
movsd %xmm1, 0x30(%rsp)
movq %rsi, %r12
movq %rdi, %r15
leaq 0xc0(%rdi), %rax
xorl %ecx, %ecx
xorl %edx, %edx
cmpq $0x8, %rdx
je 0x54caa
movsd (%r12,%rdx,2), %xmm2
movapd %xmm2, %xmm1
addsd %xmm0, %xmm1
cvttsd2si %xmm1, %edi
movl %edi, 0x18(%rsp,%rdx)
testl %edi, %edi
js 0x54dab
movl (%rax,%rdx), %esi
cmpl %edi, %esi
jg 0x54c8b
leal -0x1(%rsi), %edi
movl %edi, 0x18(%rsp,%rdx)
subsd %xmm0, %xmm2
cvttsd2si %xmm2, %edi
cmpl %edi, %esi
jle 0x54dab
testl %edi, %edi
cmovlel %ecx, %edi
movl %edi, 0x20(%rsp,%rdx)
addq $0x4, %rdx
jmp 0x54c59
movsd 0x8(%r12), %xmm2
movapd %xmm2, %xmm1
subsd %xmm0, %xmm1
movsd 0x3e34f(%rip), %xmm3    # 0x93010
addsd %xmm3, %xmm1
cvttsd2si %xmm1, %ebp
addsd %xmm0, %xmm2
addsd %xmm3, %xmm2
cvttsd2si %xmm2, %ecx
movl 0x24(%rsp), %eax
cmpl %ebp, %eax
cmovgl %eax, %ebp
movl 0x20(%rsp), %eax
movl %eax, 0x10(%rsp)
movl 0x18(%rsp), %eax
movl %eax, 0xc(%rsp)
movl 0x1c(%rsp), %eax
cmpl %ecx, %eax
cmovll %eax, %ecx
movl %ecx, 0x14(%rsp)
mulsd %xmm0, %xmm0
movsd %xmm0, 0x28(%rsp)
cmpl 0x14(%rsp), %ebp
jg 0x54dab
cvtsi2sd %ebp, %xmm1
subsd 0x8(%r12), %xmm1
mulsd %xmm1, %xmm1
subsd %xmm1, %xmm0
ucomisd 0x3e4be(%rip), %xmm0    # 0x931e8
jb 0x54d32
sqrtsd %xmm0, %xmm0
jmp 0x54d37
callq 0xe350
movq %r12, %r14
movsd (%r12), %xmm1
movapd %xmm1, %xmm2
subsd %xmm0, %xmm2
movsd 0x3e2c0(%rip), %xmm3    # 0x93010
addsd %xmm3, %xmm2
cvttsd2si %xmm2, %r12d
addsd %xmm1, %xmm0
addsd %xmm3, %xmm0
cvttsd2si %xmm0, %r13d
movl 0x10(%rsp), %eax
cmpl %r12d, %eax
cmovgl %eax, %r12d
movl 0xc(%rsp), %eax
cmpl %r13d, %eax
cmovll %eax, %r13d
cmpl %r13d, %r12d
jg 0x54d9b
movq %r15, %rdi
movl %r12d, %esi
movl %ebp, %edx
movsd 0x30(%rsp), %xmm0
movl %ebx, %ecx
callq 0x569e8
incl %r12d
jmp 0x54d7c
incl %ebp
movsd 0x28(%rsp), %xmm0
movq %r14, %r12
jmp 0x54d05
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq