// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Grid.cpp
// Function: gaps::R3Grid::RasterizeGridPoint(double, double, double, double, int)
void R3Grid::
RasterizeGridPoint(RNScalar x, RNScalar y, RNScalar z, RNScalar value, 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;

  // Trilinear interpolation
  int ix1 = (int) x;
  int iy1 = (int) y;
  int iz1 = (int) z;
  int ix2 = ix1 + 1;
  int iy2 = iy1 + 1;
  int iz2 = iz1 + 1;
  if (ix2 >= grid_resolution[0]) ix2 = ix1;
  if (iy2 >= grid_resolution[1]) iy2 = iy1;
  if (iz2 >= grid_resolution[2]) iz2 = iz1;
  RNScalar dx = x - ix1;
  RNScalar dy = y - iy1;
  RNScalar dz = z - iz1;
  RasterizeGridValue(ix1, iy1, iz1, value * (1.0-dx) * (1.0-dy) * (1.0-dz), operation);
  RasterizeGridValue(ix1, iy1, iz2, value * (1.0-dx) * (1.0-dy) * dz, operation);
  RasterizeGridValue(ix1, iy2, iz1, value * (1.0-dx) * dy * (1.0-dz), operation);
  RasterizeGridValue(ix1, iy2, iz2, value * (1.0-dx) * dy * dz, operation);
  RasterizeGridValue(ix2, iy1, iz1, value * dx * (1.0-dy) * (1.0-dz), operation);
  RasterizeGridValue(ix2, iy1, iz2, value * dx * (1.0-dy) * dz, operation);
  RasterizeGridValue(ix2, iy2, iz1, value * dx * dy * (1.0-dz), operation);
  RasterizeGridValue(ix2, iy2, iz2, value * dx * dy * dz, operation);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
xorpd %xmm4, %xmm4
ucomisd %xmm0, %xmm4
jbe 0x302bf
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
ucomisd %xmm1, %xmm4
ja 0x302b0
movq %rdi, %r14
movl 0x238(%rdi), %eax
leal -0x1(%rax), %ecx
cvtsi2sd %ecx, %xmm4
ucomisd %xmm4, %xmm0
ja 0x302b0
xorpd %xmm4, %xmm4
ucomisd %xmm2, %xmm4
ja 0x302b0
movl 0x23c(%r14), %ecx
leal -0x1(%rcx), %edx
cvtsi2sd %edx, %xmm4
ucomisd %xmm4, %xmm1
ja 0x302b0
movl %esi, %ebx
movl 0x240(%r14), %edx
leal -0x1(%rdx), %esi
cvtsi2sd %esi, %xmm4
ucomisd %xmm4, %xmm2
ja 0x302b0
cvttsd2si %xmm0, %ebp
cvttsd2si %xmm1, %r13d
cvttsd2si %xmm2, %edi
leal 0x1(%rbp), %esi
leal 0x1(%r13), %r9d
leal 0x1(%rdi), %r12d
cmpl %eax, %esi
cmovgel %ebp, %esi
movl %esi, 0x1c(%rsp)
cmpl %ecx, %r9d
cmovgel %r13d, %r9d
movl %r9d, %r15d
cmpl %edx, %r12d
cmovgel %edi, %r12d
movq %rdi, %rcx
movq %rdi, 0x48(%rsp)
cvttpd2dq %xmm0, %xmm4
movapd %xmm2, %xmm5
cvtdq2pd %xmm4, %xmm2
movapd %xmm0, %xmm4
cvttpd2dq %xmm1, %xmm0
subsd %xmm2, %xmm4
movapd %xmm4, 0x20(%rsp)
cvtdq2pd %xmm0, %xmm0
subsd %xmm0, %xmm1
movapd %xmm1, 0x60(%rsp)
cvttpd2dq %xmm5, %xmm0
cvtdq2pd %xmm0, %xmm0
subsd %xmm0, %xmm5
movapd %xmm5, 0x30(%rsp)
movsd 0x62c79(%rip), %xmm2    # 0x93008
movapd %xmm2, %xmm6
subsd %xmm4, %xmm6
mulsd %xmm3, %xmm6
movsd %xmm6, (%rsp)
movapd %xmm2, %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
mulsd %xmm0, %xmm6
movsd %xmm6, 0x40(%rsp)
subsd %xmm5, %xmm2
movsd %xmm2, 0x10(%rsp)
movapd %xmm6, %xmm0
mulsd %xmm2, %xmm0
movq %r14, %rdi
movl %ebp, %esi
movl %r13d, %edx
movq %r13, 0x50(%rsp)
movl %ebx, %r8d
movsd %xmm3, 0x58(%rsp)
callq 0x301e4
movsd 0x40(%rsp), %xmm0
mulsd 0x30(%rsp), %xmm0
movq %r14, %rdi
movl %ebp, %esi
movl %r13d, %edx
movl %r12d, %ecx
movl %ebx, %r8d
callq 0x301e4
movsd (%rsp), %xmm0
mulsd 0x60(%rsp), %xmm0
movsd %xmm0, (%rsp)
mulsd 0x10(%rsp), %xmm0
movq %r14, %rdi
movl %ebp, %esi
movl %r15d, 0x18(%rsp)
movl %r15d, %edx
movq 0x48(%rsp), %r13
movl %r13d, %ecx
movl %ebx, %r8d
callq 0x301e4
movsd (%rsp), %xmm0
mulsd 0x30(%rsp), %xmm0
movq %r14, %rdi
movl %ebp, %esi
movl %r15d, %edx
movl %r12d, %ecx
movl %ebx, %r8d
callq 0x301e4
movapd 0x20(%rsp), %xmm0
mulsd 0x58(%rsp), %xmm0
movapd %xmm0, 0x20(%rsp)
movsd 0x8(%rsp), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movapd %xmm1, %xmm0
mulsd 0x10(%rsp), %xmm0
movq %r14, %rdi
movl 0x1c(%rsp), %ebp
movl %ebp, %esi
movq 0x50(%rsp), %r15
movl %r15d, %edx
movl %r13d, %ecx
movl %ebx, %r8d
callq 0x301e4
movsd 0x8(%rsp), %xmm0
mulsd 0x30(%rsp), %xmm0
movq %r14, %rdi
movl %ebp, %esi
movl %r15d, %edx
movl %r12d, %ecx
movl %ebx, %r8d
callq 0x301e4
movapd 0x20(%rsp), %xmm1
mulsd 0x60(%rsp), %xmm1
movapd %xmm1, 0x20(%rsp)
movsd 0x10(%rsp), %xmm0
mulsd %xmm1, %xmm0
movq %r14, %rdi
movl %ebp, %esi
movl 0x18(%rsp), %r15d
movl %r15d, %edx
movl %r13d, %ecx
movl %ebx, %r8d
callq 0x301e4
movapd 0x20(%rsp), %xmm0
mulsd 0x30(%rsp), %xmm0
movq %r14, %rdi
movl %ebp, %esi
movl %r15d, %edx
movl %r12d, %ecx
movl %ebx, %r8d
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x301e4
nop