// File: /workspace/github_cpp_makefile_star2_O1/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
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
cmpq $0x3, %rax
jne 0x34a8d
movl 0x28(%rsp), %eax
movl 0x2c(%rsp), %ecx
xorl %edx, %edx
cmpl 0x24(%rsp), %eax
setg %dl
cmpl 0x24(%rsp,%rdx,4), %ecx
movl $0x2, %eax
cmovlel %edx, %eax
leal 0x1(%rax), %edx
xorl %ecx, %ecx
cmpl $0x3, %edx
cmovnel %edx, %ecx
leal 0x2(%rax), %edx
movl $0xaaaaaaab, %esi       # imm = 0xAAAAAAAB
imulq %rdx, %rsi
shrq $0x21, %rsi
leal (%rsi,%rsi,2), %edx
negl %edx
movl %eax, %r15d
movl 0x24(%rsp,%r15,4), %ebp
testl %ebp, %ebp
je 0x34be9
movl $0x0, 0x18(%rsp)
movq $0x0, 0x10(%rsp)
js 0x34c46
addl %edx, %eax
addl $0x2, %eax
movslq %ecx, %r12
movl %eax, %r13d
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl 0x4(%rsp), %esi
testl %esi, %esi
js 0x34b7e
cmpl 0x238(%r14), %esi
setl %al
movl 0x8(%rsp), %edx
testl %edx, %edx
setns %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x34b7e
cmpl 0x23c(%r14), %edx
jge 0x34b7e
movl 0xc(%rsp), %ecx
testl %ecx, %ecx
js 0x34b7e
cmpl 0x240(%r14), %ecx
jge 0x34b7e
movq %r14, %rdi
movsd 0x30(%rsp), %xmm0
movl 0x20(%rsp), %r8d
callq 0x341de
movl 0x24(%rsp,%r12,4), %eax
addl %eax, 0x10(%rsp,%r12,4)
movl 0x10(%rsp,%r13,4), %ecx
addl 0x24(%rsp,%r13,4), %ecx
movl 0x3c(%rsp,%r15,4), %eax
addl %eax, 0x4(%rsp,%r15,4)
movl %ecx, 0x10(%rsp,%r13,4)
movl 0x10(%rsp,%r12,4), %esi
movl 0x3c(%rsp,%r12,4), %eax
imull %esi, %eax
cltd
idivl %ebp
addl %eax, 0x4(%rsp,%r12,4)
imull 0x3c(%rsp,%r13,4), %ecx
movl %ecx, %eax
cltd
idivl %ebp
addl %eax, 0x4(%rsp,%r13,4)
movl %esi, %eax
cltd
idivl %ebp
movl %edx, 0x10(%rsp,%r12,4)
movl 0x10(%rsp,%r13,4), %eax
cltd
idivl %ebp
movl %edx, 0x10(%rsp,%r13,4)
incl %ebx
cmpl %ebx, %ebp
jne 0x34b2f
jmp 0x34c46
movl 0x4(%rsp), %esi
testl %esi, %esi
js 0x34c46
cmpl 0x238(%r14), %esi
setl %al
movl 0x8(%rsp), %edx
testl %edx, %edx
setns %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x34c46
cmpl 0x23c(%r14), %edx
jge 0x34c46
movl 0xc(%rsp), %ecx
testl %ecx, %ecx
js 0x34c46
cmpl 0x240(%r14), %ecx
jge 0x34c46
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 0x341de
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop