// File: /workspace/github_cpp_makefile_star2_O1/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 $0xb8, %rsp
movl %esi, 0x4c(%rsp)
movq %xmm3, 0x40(%rsp)
movsd %xmm2, 0x20(%rsp)
movapd %xmm1, 0x50(%rsp)
xorpd %xmm1, %xmm1
movapd %xmm0, 0x80(%rsp)
ucomisd %xmm0, %xmm1
jbe 0x3456c
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
ucomisd 0x50(%rsp), %xmm1
ja 0x3455a
movq %rdi, %r14
movl 0x238(%rdi), %ecx
leal -0x1(%rcx), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movapd 0x80(%rsp), %xmm1
ucomisd %xmm0, %xmm1
ja 0x3455a
xorpd %xmm0, %xmm0
ucomisd 0x20(%rsp), %xmm0
ja 0x3455a
movl 0x23c(%r14), %edi
leal -0x1(%rdi), %esi
xorps %xmm0, %xmm0
cvtsi2sd %esi, %xmm0
movapd 0x50(%rsp), %xmm1
ucomisd %xmm0, %xmm1
ja 0x3455a
movl 0x240(%r14), %edx
leal -0x1(%rdx), %r8d
movl %r8d, 0xc(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %r8d, %xmm0
movsd 0x20(%rsp), %xmm1
ucomisd %xmm0, %xmm1
ja 0x3455a
movsd 0x6dbe9(%rip), %xmm0    # 0xa21d8
mulsd %xmm4, %xmm0
movsd 0x6da35(%rip), %xmm1    # 0xa2030
addsd %xmm1, %xmm0
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
movsd 0x20(%rsp), %xmm3
movapd %xmm3, %xmm2
subsd %xmm0, %xmm2
addsd %xmm1, %xmm2
cvttsd2si %xmm2, %r8d
movapd %xmm0, %xmm2
addsd %xmm3, %xmm2
addsd %xmm1, %xmm2
cvttsd2si %xmm2, %r9d
movapd 0x80(%rsp), %xmm1
unpcklpd 0x50(%rsp), %xmm1       # xmm1 = xmm1[0],mem[0]
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
movapd %xmm1, %xmm2
subpd %xmm0, %xmm2
movapd 0x6d9be(%rip), %xmm3    # 0xa2010
addpd %xmm3, %xmm2
cvttpd2dq %xmm2, %xmm5
addpd %xmm1, %xmm0
addpd %xmm3, %xmm0
cvttpd2dq %xmm0, %xmm3
movd %edi, %xmm0
movd %ecx, %xmm6
punpckldq %xmm0, %xmm6    # xmm6 = xmm6[0],xmm0[0],xmm6[1],xmm0[1]
pcmpgtd %xmm3, %xmm6
pxor %xmm0, %xmm0
movapd %xmm5, %xmm7
pcmpgtd %xmm0, %xmm7
movd %esi, %xmm0
movd %eax, %xmm1
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
pand %xmm6, %xmm3
pandn %xmm1, %xmm6
xorl %ebx, %ebx
testl %r8d, %r8d
cmovgl %r8d, %ebx
cmpl %r9d, %edx
movl 0xc(%rsp), %eax
cmovgl %r9d, %eax
movl %eax, 0xc(%rsp)
leaq 0x758f3(%rip), %rax     # 0xa9fa8
movsd (%rax), %xmm0
addsd %xmm0, %xmm0
xorpd %xmm2, %xmm2
pxor %xmm1, %xmm1
movq %xmm1, 0x28(%rsp)
ucomisd %xmm2, %xmm0
jb 0x346d7
sqrtsd %xmm0, %xmm0
jmp 0x34724
movapd %xmm5, 0xa0(%rsp)
movdqa %xmm3, 0x90(%rsp)
movsd %xmm4, 0x30(%rsp)
movdqa %xmm6, 0x70(%rsp)
movdqa %xmm7, 0x60(%rsp)
callq 0xe340
movdqa 0x60(%rsp), %xmm7
movdqa 0x70(%rsp), %xmm6
movsd 0x30(%rsp), %xmm4
movdqa 0x90(%rsp), %xmm3
movapd 0xa0(%rsp), %xmm5
andpd %xmm7, %xmm5
por %xmm6, %xmm3
mulsd %xmm4, %xmm0
movapd %xmm0, %xmm1
mulsd %xmm0, %xmm1
mulsd %xmm0, %xmm1
movsd 0x6d8f4(%rip), %xmm0    # 0xa2038
divsd %xmm1, %xmm0
movsd %xmm0, 0x30(%rsp)
movapd %xmm4, %xmm0
addsd %xmm4, %xmm0
mulsd %xmm4, %xmm0
movsd %xmm0, 0x70(%rsp)
cmpl 0xc(%rsp), %ebx
movapd %xmm5, 0xa0(%rsp)
movdqa %xmm3, 0x90(%rsp)
jg 0x348f9
movapd %xmm5, %xmm0
pcmpgtd %xmm3, %xmm0
pshufd $0x50, %xmm0, %xmm0     # xmm0 = xmm0[0,0,1,1]
movmskpd %xmm0, %eax
movl %eax, 0x1c(%rsp)
shrb %al
movb %al, 0x10(%rsp)
pshufd $0x55, %xmm5, %xmm0     # xmm0 = xmm5[1,1,1,1]
movd %xmm0, 0x48(%rsp)
movd %xmm5, 0x14(%rsp)
pshufd $0x55, %xmm3, %xmm0     # xmm0 = xmm3[1,1,1,1]
movd %xmm0, 0x18(%rsp)
movd %xmm3, %r13d
incl %r13d
pxor %xmm0, %xmm0
movq %xmm0, 0x28(%rsp)
movl %ebx, %r15d
cmpb $0x0, 0x10(%rsp)
jne 0x348e7
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
movsd 0x20(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, 0x38(%rsp)
movl 0x48(%rsp), %eax
movl %eax, %ebp
testb $0x1, 0x1c(%rsp)
jne 0x348d8
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
movapd 0x50(%rsp), %xmm1
subsd %xmm0, %xmm1
mulsd %xmm1, %xmm1
movapd %xmm1, 0x60(%rsp)
movl 0x14(%rsp), %r12d
xorps %xmm0, %xmm0
cvtsi2sd %r12d, %xmm0
movapd 0x80(%rsp), %xmm1
subsd %xmm0, %xmm1
mulsd %xmm1, %xmm1
addsd 0x60(%rsp), %xmm1
movsd 0x38(%rsp), %xmm0
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
ucomisd 0x6d997(%rip), %xmm0    # 0xa21e8
jb 0x34859
sqrtsd %xmm0, %xmm0
jmp 0x3485e
callq 0xe340
movapd %xmm0, %xmm1
xorpd 0x6d7b6(%rip), %xmm1    # 0xa2020
mulsd %xmm0, %xmm1
divsd 0x70(%rsp), %xmm1
movapd %xmm1, %xmm0
callq 0xe7f0
mulsd 0x30(%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
movsd 0x28(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x28(%rsp)
mulsd (%rax,%rcx,8), %xmm0
movsd 0x40(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x40(%rsp)
incl %r12d
cmpl %r12d, %r13d
jne 0x3481c
leal 0x1(%rbp), %eax
cmpl 0x18(%rsp), %ebp
movl %eax, %ebp
jne 0x347f1
leal 0x1(%r15), %eax
cmpl 0xc(%rsp), %r15d
movl %eax, %r15d
jne 0x347c8
leaq 0xb1298(%rip), %rax     # 0xe5b98
movsd 0x28(%rsp), %xmm0
ucomisd (%rax), %xmm0
jbe 0x3455a
cmpl 0xc(%rsp), %ebx
jg 0x3455a
movdqa 0xa0(%rsp), %xmm1
movdqa %xmm1, %xmm0
movdqa 0x90(%rsp), %xmm2
pcmpgtd %xmm2, %xmm0
pshufd $0x50, %xmm0, %xmm0     # xmm0 = xmm0[0,0,1,1]
movmskpd %xmm0, %eax
movl %eax, 0x1c(%rsp)
shrb %al
movb %al, 0x14(%rsp)
pshufd $0x55, %xmm1, %xmm0     # xmm0 = xmm1[1,1,1,1]
movd %xmm0, 0x10(%rsp)
movd %xmm1, 0x18(%rsp)
pshufd $0x55, %xmm2, %xmm0     # xmm0 = xmm2[1,1,1,1]
movd %xmm0, %r13d
movd %xmm2, %r15d
incl %r15d
cmpb $0x0, 0x14(%rsp)
jne 0x34a5c
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
movsd 0x20(%rsp), %xmm1
subsd %xmm0, %xmm1
mulsd %xmm1, %xmm1
movsd %xmm1, 0x38(%rsp)
movl 0x10(%rsp), %eax
movl %eax, %r12d
testb $0x1, 0x1c(%rsp)
jne 0x34a4b
xorps %xmm0, %xmm0
cvtsi2sd %r12d, %xmm0
movapd 0x50(%rsp), %xmm1
subsd %xmm0, %xmm1
mulsd %xmm1, %xmm1
movapd %xmm1, 0x60(%rsp)
movl 0x18(%rsp), %ebp
xorps %xmm1, %xmm1
cvtsi2sd %ebp, %xmm1
movapd 0x80(%rsp), %xmm0
subsd %xmm1, %xmm0
mulsd %xmm0, %xmm0
addsd 0x60(%rsp), %xmm0
addsd 0x38(%rsp), %xmm0
ucomisd 0x6d7fa(%rip), %xmm0    # 0xa21e8
jb 0x349f6
sqrtsd %xmm0, %xmm0
jmp 0x349fb
callq 0xe340
movapd %xmm0, %xmm1
xorpd 0x6d619(%rip), %xmm1    # 0xa2020
mulsd %xmm0, %xmm1
divsd 0x70(%rsp), %xmm1
movapd %xmm1, %xmm0
callq 0xe7f0
mulsd 0x30(%rsp), %xmm0
mulsd 0x40(%rsp), %xmm0
divsd 0x28(%rsp), %xmm0
movq %r14, %rdi
movl %ebp, %esi
movl %r12d, %edx
movl %ebx, %ecx
movl 0x4c(%rsp), %r8d
callq 0x341de
incl %ebp
cmpl %ebp, %r15d
jne 0x349c2
leal 0x1(%r12), %eax
cmpl %r13d, %r12d
movl %eax, %r12d
jne 0x34997
leal 0x1(%rbx), %eax
cmpl 0xc(%rsp), %ebx
movl %eax, %ebx
jne 0x3496a
jmp 0x3455a