// File: 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:
subq $0x98, %rsp
movq %rdi, 0x90(%rsp)
movq %rsi, 0x88(%rsp)
movq %rdx, 0x80(%rsp)
movsd %xmm0, 0x78(%rsp)
movl %ecx, 0x74(%rsp)
movq 0x90(%rsp), %rax
movq %rax, 0x18(%rsp)
movl $0x0, 0x40(%rsp)
cmpl $0x3, 0x40(%rsp)
jge 0x60559
movq 0x80(%rsp), %rax
movslq 0x40(%rsp), %rcx
movl (%rax,%rcx,4), %ecx
movq 0x88(%rsp), %rax
movslq 0x40(%rsp), %rdx
subl (%rax,%rdx,4), %ecx
movslq 0x40(%rsp), %rax
movl %ecx, 0x68(%rsp,%rax,4)
movslq 0x40(%rsp), %rax
cmpl $0x0, 0x68(%rsp,%rax,4)
jge 0x60511
movslq 0x40(%rsp), %rax
xorl %ecx, %ecx
subl 0x68(%rsp,%rax,4), %ecx
movslq 0x40(%rsp), %rax
movl %ecx, 0x50(%rsp,%rax,4)
movslq 0x40(%rsp), %rax
movl $0xffffffff, 0x44(%rsp,%rax,4) # imm = 0xFFFFFFFF
jmp 0x60530
movslq 0x40(%rsp), %rax
movl 0x68(%rsp,%rax,4), %ecx
movslq 0x40(%rsp), %rax
movl %ecx, 0x50(%rsp,%rax,4)
movslq 0x40(%rsp), %rax
movl $0x1, 0x44(%rsp,%rax,4)
movq 0x88(%rsp), %rax
movslq 0x40(%rsp), %rcx
movl (%rax,%rcx,4), %ecx
movslq 0x40(%rsp), %rax
movl %ecx, 0x5c(%rsp,%rax,4)
movl 0x40(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x40(%rsp)
jmp 0x604ae
movl $0x0, 0x3c(%rsp)
movl 0x54(%rsp), %eax
movslq 0x3c(%rsp), %rcx
cmpl 0x50(%rsp,%rcx,4), %eax
jle 0x60578
movl $0x1, 0x3c(%rsp)
movl 0x58(%rsp), %eax
movslq 0x3c(%rsp), %rcx
cmpl 0x50(%rsp,%rcx,4), %eax
jle 0x6058f
movl $0x2, 0x3c(%rsp)
movl 0x3c(%rsp), %eax
addl $0x1, %eax
movl $0x3, %ecx
cltd
idivl %ecx
movl %edx, 0x38(%rsp)
movl 0x3c(%rsp), %eax
addl $0x2, %eax
movl $0x3, %ecx
cltd
idivl %ecx
movl %edx, 0x34(%rsp)
movslq 0x3c(%rsp), %rax
cmpl $0x0, 0x50(%rsp,%rax,4)
jne 0x6062f
cmpl $0x0, 0x5c(%rsp)
jl 0x6062a
movq 0x18(%rsp), %rcx
movl 0x5c(%rsp), %eax
cmpl 0x238(%rcx), %eax
jge 0x6062a
cmpl $0x0, 0x60(%rsp)
jl 0x6062a
movq 0x18(%rsp), %rcx
movl 0x60(%rsp), %eax
cmpl 0x23c(%rcx), %eax
jge 0x6062a
cmpl $0x0, 0x64(%rsp)
jl 0x6062a
movq 0x18(%rsp), %rcx
movl 0x64(%rsp), %eax
cmpl 0x240(%rcx), %eax
jge 0x6062a
movq 0x18(%rsp), %rdi
movl 0x5c(%rsp), %esi
movl 0x60(%rsp), %edx
movl 0x64(%rsp), %ecx
movsd 0x78(%rsp), %xmm0
movl 0x74(%rsp), %r8d
callq 0x5f820
jmp 0x607b6
leaq 0x28(%rsp), %rdi
xorl %esi, %esi
movl $0xc, %edx
callq 0xf280
movl $0x0, 0x24(%rsp)
movl 0x24(%rsp), %eax
movslq 0x3c(%rsp), %rcx
cmpl 0x50(%rsp,%rcx,4), %eax
jg 0x607b4
cmpl $0x0, 0x5c(%rsp)
jl 0x606c4
movq 0x18(%rsp), %rcx
movl 0x5c(%rsp), %eax
cmpl 0x238(%rcx), %eax
jge 0x606c4
cmpl $0x0, 0x60(%rsp)
jl 0x606c4
movq 0x18(%rsp), %rcx
movl 0x60(%rsp), %eax
cmpl 0x23c(%rcx), %eax
jge 0x606c4
cmpl $0x0, 0x64(%rsp)
jl 0x606c4
movq 0x18(%rsp), %rcx
movl 0x64(%rsp), %eax
cmpl 0x240(%rcx), %eax
jge 0x606c4
movq 0x18(%rsp), %rdi
movl 0x5c(%rsp), %esi
movl 0x60(%rsp), %edx
movl 0x64(%rsp), %ecx
movsd 0x78(%rsp), %xmm0
movl 0x74(%rsp), %r8d
callq 0x5f820
movslq 0x38(%rsp), %rax
movl 0x50(%rsp,%rax,4), %ecx
movslq 0x38(%rsp), %rax
addl 0x28(%rsp,%rax,4), %ecx
movl %ecx, 0x28(%rsp,%rax,4)
movslq 0x34(%rsp), %rax
movl 0x50(%rsp,%rax,4), %ecx
movslq 0x34(%rsp), %rax
addl 0x28(%rsp,%rax,4), %ecx
movl %ecx, 0x28(%rsp,%rax,4)
movslq 0x3c(%rsp), %rax
movl 0x44(%rsp,%rax,4), %ecx
movslq 0x3c(%rsp), %rax
addl 0x5c(%rsp,%rax,4), %ecx
movl %ecx, 0x5c(%rsp,%rax,4)
movslq 0x38(%rsp), %rax
movl 0x44(%rsp,%rax,4), %eax
movslq 0x38(%rsp), %rcx
imull 0x28(%rsp,%rcx,4), %eax
movslq 0x3c(%rsp), %rcx
cltd
idivl 0x50(%rsp,%rcx,4)
movl %eax, %ecx
movslq 0x38(%rsp), %rax
addl 0x5c(%rsp,%rax,4), %ecx
movl %ecx, 0x5c(%rsp,%rax,4)
movslq 0x34(%rsp), %rax
movl 0x44(%rsp,%rax,4), %eax
movslq 0x34(%rsp), %rcx
imull 0x28(%rsp,%rcx,4), %eax
movslq 0x3c(%rsp), %rcx
cltd
idivl 0x50(%rsp,%rcx,4)
movl %eax, %ecx
movslq 0x34(%rsp), %rax
addl 0x5c(%rsp,%rax,4), %ecx
movl %ecx, 0x5c(%rsp,%rax,4)
movslq 0x3c(%rsp), %rax
movl 0x50(%rsp,%rax,4), %ecx
movslq 0x38(%rsp), %rax
movq %rax, 0x8(%rsp)
movl 0x28(%rsp,%rax,4), %eax
cltd
idivl %ecx
movq 0x8(%rsp), %rax
movl %edx, 0x28(%rsp,%rax,4)
movslq 0x3c(%rsp), %rax
movl 0x50(%rsp,%rax,4), %ecx
movslq 0x34(%rsp), %rax
movq %rax, 0x10(%rsp)
movl 0x28(%rsp,%rax,4), %eax
cltd
idivl %ecx
movq 0x10(%rsp), %rax
movl %edx, 0x28(%rsp,%rax,4)
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x60648
jmp 0x607b6
addq $0x98, %rsp
retq
nop