// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Grid.cpp
// Function: gaps::R3Grid::RasterizeGridPoint(double, double, double, double, double, int)
void R3Grid::
RasterizeGridPoint(RNScalar x, RNScalar y, RNScalar z, RNScalar value, RNLength sigma, int operation)
{
  // Check if within bounds
  if ((x < 0) || (x > grid_resolution[0]-1)) return;
  if ((y < 0) || (y > grid_resolution[1]-1)) return;
  if ((z < 0) || (z > grid_resolution[2]-1)) return;

  // Determine filter extent
  int f = (int) (3 * sigma + 0.5);
  int xmin = (int) (x - f + 0.5);
  int xmax = (int) (x + f + 0.5);
  int ymin = (int) (y - f + 0.5);
  int ymax = (int) (y + f + 0.5);
  int zmin = (int) (z - f + 0.5);
  int zmax = (int) (z + f + 0.5);
  if (xmin < 0) xmin = 0;
  if (xmax > XResolution()-1) xmax = XResolution()-1;
  if (ymin < 0) ymin = 0;
  if (ymax > YResolution()-1) ymax = YResolution()-1;
  if (zmin < 0) zmin = 0;
  if (zmax > ZResolution()-1) zmax = ZResolution()-1;

  // Compute Gaussian weighting variables
  double a = sqrt(2.0 * RN_PI) * sigma;
  double fac = 1.0 / (a * a * a);
  double denom = 2.0 * sigma * sigma;

  // Compute total weight of Gaussian filter
  RNScalar weight = 0.0;
  for (int k = zmin; k <= zmax; k++) {
    for (int j = ymin; j <= ymax; j++) {
      for (int i = xmin; i <= xmax; i++) {
        RNScalar dx = x - i;
        RNScalar dy = y - j;
        RNScalar dz = z - k;
        RNScalar d = sqrt(dx*dx + dy*dy + dz*dz);
        RNScalar w = fac * exp(-d * d / denom);
        value += w * GridValue(i, j, k);
        weight += w;
      }
    }
  }

  // Splat values into grid (scaled by total weight of Gaussian filter)
  if (RNIsPositive(weight)) {
    for (int k = zmin; k <= zmax; k++) {
      for (int j = ymin; j <= ymax; j++) {
        for (int i = xmin; i <= xmax; i++) {
          RNScalar dx = x - i;
          RNScalar dy = y - j;
          RNScalar dz = z - k;
          RNScalar d = sqrt(dx*dx + dy*dy + dz*dz);
          RNScalar w = fac * exp(-d * d / denom);
          RasterizeGridValue(i, j, k, w * value / weight, operation);
        }
      }
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movsd %xmm2, 0x18(%rsp)
movapd %xmm1, 0x40(%rsp)
movapd %xmm0, %xmm7
xorpd %xmm0, %xmm0
ucomisd %xmm7, %xmm0
jbe 0x343b1
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
ucomisd 0x40(%rsp), %xmm0
ja 0x3439f
movq %rdi, %r14
movl 0x238(%rdi), %r15d
leal -0x1(%r15), %ebp
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
ucomisd %xmm0, %xmm7
ja 0x3439f
xorpd %xmm0, %xmm0
ucomisd 0x18(%rsp), %xmm0
ja 0x3439f
movl 0x23c(%r14), %r13d
leal -0x1(%r13), %r12d
xorps %xmm0, %xmm0
cvtsi2sd %r12d, %xmm0
movapd 0x40(%rsp), %xmm1
ucomisd %xmm0, %xmm1
ja 0x3439f
movl 0x240(%r14), %eax
leal -0x1(%rax), %ecx
movl %ecx, 0x4(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
movsd 0x18(%rsp), %xmm1
ucomisd %xmm0, %xmm1
ja 0x3439f
movsd 0x6ddac(%rip), %xmm0    # 0xa21d8
mulsd %xmm4, %xmm0
movsd 0x6dbf8(%rip), %xmm1    # 0xa2030
addsd %xmm1, %xmm0
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm5
movsd 0x18(%rsp), %xmm2
movapd %xmm2, %xmm0
subsd %xmm5, %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
movapd %xmm5, %xmm0
addsd %xmm2, %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %edx
xorl %ebx, %ebx
testl %ecx, %ecx
cmovgl %ecx, %ebx
cmpl %edx, %eax
movl 0x4(%rsp), %eax
cmovgl %edx, %eax
movl %eax, 0x4(%rsp)
leaq 0x75b43(%rip), %rax     # 0xa9fc8
movsd (%rax), %xmm0
addsd %xmm0, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
movl %esi, 0x3c(%rsp)
movapd %xmm7, 0x80(%rsp)
jb 0x344aa
sqrtsd %xmm0, %xmm0
jmp 0x344dc
movsd %xmm3, 0x10(%rsp)
movsd %xmm4, 0x20(%rsp)
movapd %xmm5, 0x60(%rsp)
callq 0xe340
movapd 0x60(%rsp), %xmm5
movsd 0x20(%rsp), %xmm4
movapd 0x80(%rsp), %xmm7
movsd 0x10(%rsp), %xmm3
cmpl 0x4(%rsp), %ebx
jg 0x3439f
movapd %xmm7, %xmm2
unpcklpd 0x40(%rsp), %xmm2       # xmm2 = xmm2[0],mem[0]
unpcklpd %xmm5, %xmm5            # xmm5 = xmm5[0,0]
movapd 0x6db14(%rip), %xmm6    # 0xa2010
movapd %xmm5, %xmm8
addpd %xmm2, %xmm8
subpd %xmm5, %xmm2
addpd %xmm6, %xmm8
movd %r13d, %xmm5
movd %r15d, %xmm1
punpckldq %xmm5, %xmm1    # xmm1 = xmm1[0],xmm5[0],xmm1[1],xmm5[1]
addpd %xmm6, %xmm2
cvttpd2dq %xmm8, %xmm6
movd %r12d, %xmm8
movd %ebp, %xmm5
punpckldq %xmm8, %xmm5    # xmm5 = xmm5[0],xmm8[0],xmm5[1],xmm8[1]
cvttpd2dq %xmm2, %xmm2
pcmpgtd %xmm6, %xmm1
pxor %xmm9, %xmm9
movapd %xmm2, %xmm8
pcmpgtd %xmm9, %xmm8
pand %xmm1, %xmm6
pandn %xmm5, %xmm1
por %xmm6, %xmm1
pand %xmm2, %xmm8
mulsd %xmm4, %xmm0
movapd %xmm0, %xmm2
mulsd %xmm0, %xmm2
mulsd %xmm0, %xmm2
movsd 0x6dac4(%rip), %xmm0    # 0xa2038
divsd %xmm2, %xmm0
movsd %xmm0, 0x60(%rsp)
movapd %xmm4, %xmm2
addsd %xmm4, %xmm2
mulsd %xmm4, %xmm2
movdqa %xmm8, %xmm0
pcmpgtd %xmm1, %xmm0
pshufd $0x50, %xmm0, %xmm0     # xmm0 = xmm0[0,0,1,1]
movmskpd %xmm0, %eax
movl %eax, 0xc(%rsp)
shrb %al
movb %al, 0x3(%rsp)
pshufd $0x55, %xmm8, %xmm0     # xmm0 = xmm8[1,1,1,1]
movd %xmm0, 0x28(%rsp)
movdqa %xmm8, 0x90(%rsp)
movd %xmm8, 0x8(%rsp)
pshufd $0x55, %xmm1, %xmm0     # xmm0 = xmm1[1,1,1,1]
movd %xmm0, 0x2c(%rsp)
movd %xmm1, %r13d
incl %r13d
pxor %xmm1, %xmm1
movapd 0x6da3e(%rip), %xmm4    # 0xa2020
movl %ebx, %r15d
movsd %xmm2, 0x58(%rsp)
cmpb $0x0, 0x3(%rsp)
jne 0x34704
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
movsd 0x18(%rsp), %xmm5
subsd %xmm0, %xmm5
movl 0x28(%rsp), %eax
movl %eax, %ebp
movsd %xmm5, 0x30(%rsp)
testb $0x1, 0xc(%rsp)
jne 0x346f5
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
movapd 0x40(%rsp), %xmm6
subsd %xmm0, %xmm6
mulsd %xmm6, %xmm6
movapd %xmm6, 0x70(%rsp)
movl 0x8(%rsp), %r12d
movq %xmm1, 0x20(%rsp)
movsd %xmm3, 0x10(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %r12d, %xmm0
subsd %xmm0, %xmm7
mulsd %xmm7, %xmm7
addsd 0x70(%rsp), %xmm7
movapd %xmm5, %xmm0
mulsd %xmm5, %xmm0
addsd %xmm7, %xmm0
xorps %xmm1, %xmm1
sqrtsd %xmm0, %xmm1
movapd %xmm1, %xmm0
xorpd %xmm4, %xmm0
mulsd %xmm1, %xmm0
divsd %xmm2, %xmm0
callq 0xe7f0
movsd 0x30(%rsp), %xmm5
movapd 0x6d989(%rip), %xmm4    # 0xa2020
movsd 0x20(%rsp), %xmm1
movsd 0x58(%rsp), %xmm2
movapd 0x80(%rsp), %xmm7
movsd 0x10(%rsp), %xmm3
mulsd 0x60(%rsp), %xmm0
movq 0x230(%r14), %rax
movl 0x248(%r14), %ecx
imull %r15d, %ecx
movl 0x244(%r14), %edx
imull %ebp, %edx
addl %ecx, %edx
addl %r12d, %edx
movslq %edx, %rcx
addsd %xmm0, %xmm1
mulsd (%rax,%rcx,8), %xmm0
addsd %xmm0, %xmm3
incl %r12d
cmpl %r12d, %r13d
jne 0x3463f
leal 0x1(%rbp), %eax
cmpl 0x2c(%rsp), %ebp
movl %eax, %ebp
jne 0x34614
leal 0x1(%r15), %eax
cmpl 0x4(%rsp), %r15d
movl %eax, %r15d
jne 0x345eb
leaq 0xb147b(%rip), %rax     # 0xe5b98
movq %xmm1, 0x20(%rsp)
ucomisd (%rax), %xmm1
jbe 0x3439f
cmpl 0x4(%rsp), %ebx
jg 0x3439f
movl 0xc(%rsp), %eax
shrb %al
movb %al, 0x3(%rsp)
movapd 0x90(%rsp), %xmm0
movss %xmm0, 0x8(%rsp)
movl 0x3c(%rsp), %r15d
movsd %xmm3, 0x10(%rsp)
cmpb $0x0, 0x3(%rsp)
jne 0x34843
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
movsd 0x18(%rsp), %xmm3
subsd %xmm0, %xmm3
mulsd %xmm3, %xmm3
movl 0x28(%rsp), %eax
movl %eax, %r12d
movsd %xmm3, 0x30(%rsp)
testb $0x1, 0xc(%rsp)
jne 0x34830
xorps %xmm0, %xmm0
cvtsi2sd %r12d, %xmm0
movapd 0x40(%rsp), %xmm1
subsd %xmm0, %xmm1
mulsd %xmm1, %xmm1
movapd %xmm1, 0x70(%rsp)
movl 0x8(%rsp), %ebp
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
subsd %xmm0, %xmm7
mulsd %xmm7, %xmm7
addsd 0x70(%rsp), %xmm7
addsd %xmm3, %xmm7
xorps %xmm1, %xmm1
sqrtsd %xmm7, %xmm1
movapd %xmm1, %xmm0
xorpd %xmm4, %xmm0
mulsd %xmm1, %xmm0
divsd %xmm2, %xmm0
callq 0xe7f0
mulsd 0x60(%rsp), %xmm0
mulsd 0x10(%rsp), %xmm0
divsd 0x20(%rsp), %xmm0
movq %r14, %rdi
movl %ebp, %esi
movl %r12d, %edx
movl %ebx, %ecx
movl %r15d, %r8d
callq 0x34032
movsd 0x30(%rsp), %xmm3
movapd 0x6d806(%rip), %xmm4    # 0xa2020
movsd 0x58(%rsp), %xmm2
movapd 0x80(%rsp), %xmm7
incl %ebp
cmpl %ebp, %r13d
jne 0x347b3
leal 0x1(%r12), %eax
cmpl 0x2c(%rsp), %r12d
movl %eax, %r12d
jne 0x34788
leal 0x1(%rbx), %eax
cmpl 0x4(%rsp), %ebx
movl %eax, %ebx
movsd 0x10(%rsp), %xmm3
jne 0x34755
jmp 0x3439f
nop