// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Grid.cpp
// Function: gaps::R3Grid::RasterizeGridSpan(int const*, int const*, double, int)
void R3Grid::
RasterizeGridSpan(const int p1[3], const int p2[3], RNScalar value, int operation)
{
  // Get some convenient variables
  int d[3],p[3],dd[3],s[3];
  for (int i = 0; i < 3; i++) {
    d[i]= p2[i] - p1[i];
    if(d[i]<0){
      dd[i] = -d[i];
      s[i] = -1;
    }
    else{
      dd[i] = d[i];
      s[i] = 1;
    }
    p[i] = p1[i];
  }

  // Choose dimensions
  int i1=0;
  if(dd[1]>dd[i1]){i1=1;}
  if(dd[2]>dd[i1]){i1=2;}
  int i2=(i1+1)%3;
  int i3=(i1+2)%3;

  // Check span extent
  if(dd[i1]==0){
    // Span is a point - rasterize it
    if (((p[0] >= 0) && (p[0] < grid_resolution[0])) &&
        ((p[1] >= 0) && (p[1] < grid_resolution[1])) &&
        ((p[2] >= 0) && (p[2] < grid_resolution[2]))) {
      RasterizeGridValue(p[0], p[1], p[2], value, operation);
    }
  }
  else {
    // Step along span
    int off[3] = { 0, 0, 0 };
    for (int i = 0; i <= dd[i1]; i++) {
      if (((p[0] >= 0) && (p[0] < grid_resolution[0])) &&
          ((p[1] >= 0) && (p[1] < grid_resolution[1])) &&
          ((p[2] >= 0) && (p[2] < grid_resolution[2]))) {
        RasterizeGridValue(p[0], p[1], p[2], value, operation);
      }
      off[i2]+=dd[i2];
      off[i3]+=dd[i3];
      p[i1]+=s[i1];
      p[i2]+=s[i2]*off[i2]/dd[i1];
      p[i3]+=s[i3]*off[i3]/dd[i1];
      off[i2]%=dd[i1];
      off[i3]%=dd[i1];
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %ecx, 0x20(%rsp)
movsd %xmm0, 0x30(%rsp)
movq %rdi, %r14
xorl %eax, %eax
cmpq $0x3, %rax
je 0x30949
movl (%rdx,%rax,4), %ecx
movl (%rsi,%rax,4), %edi
subl %edi, %ecx
movl %ecx, %r8d
negl %r8d
cmovsl %ecx, %r8d
sarl $0x1f, %ecx
orl $0x1, %ecx
movl %r8d, 0x24(%rsp,%rax,4)
movl %ecx, 0x3c(%rsp,%rax,4)
movl %edi, 0x4(%rsp,%rax,4)
incq %rax
jmp 0x30919
movl 0x28(%rsp), %eax
xorl %ecx, %ecx
cmpl 0x24(%rsp), %eax
movl 0x2c(%rsp), %eax
setg %cl
cmpl 0x24(%rsp,%rcx,4), %eax
pushq $0x2
popq %rax
cmovlel %ecx, %eax
movl %eax, %r12d
movl 0x24(%rsp,%r12,4), %ebp
testl %ebp, %ebp
je 0x30a59
leal 0x2(%r12), %eax
xorl %r13d, %r13d
pushq $0x3
popq %rcx
xorl %edx, %edx
divl %ecx
movl %edx, %r15d
leal 0x1(%r12), %eax
cmpl $0x3, %eax
cmovel %r13d, %eax
andl $0x0, 0x18(%rsp)
andq $0x0, 0x10(%rsp)
movslq %eax, %rbx
cmpl %ebp, %r13d
jg 0x30ab6
movl 0x4(%rsp), %esi
testl %esi, %esi
js 0x309f8
cmpl 0x238(%r14), %esi
setl %al
movl 0x8(%rsp), %edx
testl %edx, %edx
setns %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x309f8
cmpl 0x23c(%r14), %edx
jge 0x309f8
movl 0xc(%rsp), %ecx
testl %ecx, %ecx
js 0x309f8
cmpl 0x240(%r14), %ecx
jge 0x309f8
movq %r14, %rdi
movsd 0x30(%rsp), %xmm0
movl 0x20(%rsp), %r8d
callq 0x301e4
movl 0x24(%rsp,%rbx,4), %eax
addl %eax, 0x10(%rsp,%rbx,4)
movl 0x10(%rsp,%r15,4), %ecx
addl 0x24(%rsp,%r15,4), %ecx
movl 0x3c(%rsp,%r12,4), %eax
addl %eax, 0x4(%rsp,%r12,4)
movl %ecx, 0x10(%rsp,%r15,4)
movl 0x10(%rsp,%rbx,4), %esi
movl 0x3c(%rsp,%rbx,4), %eax
imull %esi, %eax
cltd
idivl %ebp
addl %eax, 0x4(%rsp,%rbx,4)
imull 0x3c(%rsp,%r15,4), %ecx
movl %ecx, %eax
cltd
idivl %ebp
addl %eax, 0x4(%rsp,%r15,4)
movl %esi, %eax
cltd
idivl %ebp
movl %edx, 0x10(%rsp,%rbx,4)
movl 0x10(%rsp,%r15,4), %eax
cltd
idivl %ebp
movl %edx, 0x10(%rsp,%r15,4)
incl %r13d
jmp 0x309a0
movl 0x4(%rsp), %esi
testl %esi, %esi
js 0x30ab6
cmpl 0x238(%r14), %esi
setl %al
movl 0x8(%rsp), %edx
testl %edx, %edx
setns %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x30ab6
cmpl 0x23c(%r14), %edx
jge 0x30ab6
movl 0xc(%rsp), %ecx
testl %ecx, %ecx
js 0x30ab6
cmpl 0x240(%r14), %ecx
jge 0x30ab6
movq %r14, %rdi
movsd 0x30(%rsp), %xmm0
movl 0x20(%rsp), %r8d
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x301e4
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop