// File: 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:
subq $0x98, %rsp
movq %rdi, 0x90(%rsp)
movq %rsi, 0x88(%rsp)
movsd %xmm0, 0x80(%rsp)
movsd %xmm1, 0x78(%rsp)
movl %edx, 0x74(%rsp)
movq 0x90(%rsp), %rax
movq %rax, 0x10(%rsp)
movl $0x0, 0x60(%rsp)
cmpl $0x2, 0x60(%rsp)
jge 0xacb45
movq 0x88(%rsp), %rdi
movl 0x60(%rsp), %esi
callq 0xa5bf0
addsd 0x80(%rsp), %xmm0
cvttsd2si %xmm0, %ecx
movslq 0x60(%rsp), %rax
movl %ecx, 0x64(%rsp,%rax,4)
movslq 0x60(%rsp), %rax
cmpl $0x0, 0x64(%rsp,%rax,4)
jge 0xaca82
jmp 0xacd1c
movq 0x10(%rsp), %rdi
movslq 0x60(%rsp), %rax
movl 0x64(%rsp,%rax,4), %eax
movl %eax, 0xc(%rsp)
movl 0x60(%rsp), %esi
callq 0xb9480
movl %eax, %ecx
movl 0xc(%rsp), %eax
subl $0x1, %ecx
cmpl %ecx, %eax
jle 0xacac6
movq 0x10(%rsp), %rdi
movl 0x60(%rsp), %esi
callq 0xb9480
movl %eax, %ecx
subl $0x1, %ecx
movslq 0x60(%rsp), %rax
movl %ecx, 0x64(%rsp,%rax,4)
movq 0x88(%rsp), %rdi
movl 0x60(%rsp), %esi
callq 0xa5bf0
movq 0x10(%rsp), %rdi
subsd 0x80(%rsp), %xmm0
cvttsd2si %xmm0, %ecx
movslq 0x60(%rsp), %rax
movl %ecx, 0x6c(%rsp,%rax,4)
movslq 0x60(%rsp), %rax
movl 0x6c(%rsp,%rax,4), %eax
movl %eax, 0x8(%rsp)
movl 0x60(%rsp), %esi
callq 0xb9480
movl %eax, %ecx
movl 0x8(%rsp), %eax
subl $0x1, %ecx
cmpl %ecx, %eax
jle 0xacb1a
jmp 0xacd1c
movslq 0x60(%rsp), %rax
cmpl $0x0, 0x6c(%rsp,%rax,4)
jge 0xacb33
movslq 0x60(%rsp), %rax
movl $0x0, 0x6c(%rsp,%rax,4)
jmp 0xacb35
movl 0x60(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x60(%rsp)
jmp 0xaca3f
movq 0x88(%rsp), %rdi
movl $0x1, %esi
callq 0xa5bf0
subsd 0x80(%rsp), %xmm0
movsd 0x864a8(%rip), %xmm1    # 0x133010
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x5c(%rsp)
movq 0x88(%rsp), %rdi
movl $0x1, %esi
callq 0xa5bf0
addsd 0x80(%rsp), %xmm0
movsd 0x86479(%rip), %xmm1    # 0x133010
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x58(%rsp)
movl 0x5c(%rsp), %eax
cmpl 0x70(%rsp), %eax
jge 0xacbb5
movl 0x70(%rsp), %eax
movl %eax, 0x5c(%rsp)
movl 0x58(%rsp), %eax
cmpl 0x68(%rsp), %eax
jle 0xacbc7
movl 0x68(%rsp), %eax
movl %eax, 0x58(%rsp)
movsd 0x80(%rsp), %xmm0
mulsd 0x80(%rsp), %xmm0
movsd %xmm0, 0x50(%rsp)
movl 0x5c(%rsp), %eax
movl %eax, 0x4c(%rsp)
movl 0x4c(%rsp), %eax
cmpl 0x58(%rsp), %eax
jg 0xacd1c
cvtsi2sdl 0x4c(%rsp), %xmm0
movsd %xmm0, (%rsp)
movq 0x88(%rsp), %rdi
movl $0x1, %esi
callq 0xa5bf0
movaps %xmm0, %xmm1
movsd (%rsp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x40(%rsp)
movsd 0x40(%rsp), %xmm0
mulsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
movsd 0x50(%rsp), %xmm0
subsd 0x38(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
movsd 0x30(%rsp), %xmm0
callq 0xf390
movsd %xmm0, 0x28(%rsp)
movq 0x88(%rsp), %rdi
xorl %esi, %esi
callq 0xa5bf0
subsd 0x28(%rsp), %xmm0
movsd 0x8639a(%rip), %xmm1    # 0x133010
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x24(%rsp)
movq 0x88(%rsp), %rdi
xorl %esi, %esi
callq 0xa5bf0
addsd 0x28(%rsp), %xmm0
movsd 0x86371(%rip), %xmm1    # 0x133010
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x20(%rsp)
movl 0x24(%rsp), %eax
cmpl 0x6c(%rsp), %eax
jge 0xaccbd
movl 0x6c(%rsp), %eax
movl %eax, 0x24(%rsp)
movl 0x20(%rsp), %eax
cmpl 0x64(%rsp), %eax
jle 0xacccf
movl 0x64(%rsp), %eax
movl %eax, 0x20(%rsp)
movl 0x24(%rsp), %eax
movl %eax, 0x1c(%rsp)
movl 0x1c(%rsp), %eax
cmpl 0x20(%rsp), %eax
jg 0xacd0a
movq 0x10(%rsp), %rdi
movl 0x1c(%rsp), %esi
movl 0x4c(%rsp), %edx
movsd 0x78(%rsp), %xmm0
movl 0x74(%rsp), %ecx
callq 0xb0550
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0xaccd7
jmp 0xacd0c
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4c(%rsp)
jmp 0xacbe7
addq $0x98, %rsp
retq
nopw %cs:(%rax,%rax)