// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Grid.cpp
// Function: gaps::R3Grid::RasterizeGridPlane(gaps::R3Plane const&, double, int)
void R3Grid::
RasterizeGridPlane(const R3Plane& plane, RNScalar value, int operation)
{
  // Load info to pass to MarchingCubes
  R3Point corner_points[8];
  RNScalar corner_levels[8];
  R3Point triangle_points[3 * 8];
  R3Box grid_box = GridBox();
  for (int octant = 0; octant < 8; octant++) {
    corner_points[octant] = grid_box.Corner(octant);
    corner_levels[octant] = R3SignedDistance(plane, corner_points[octant]);
  }

  // Determine triangles 
  int npoints = MarchingCubes(corner_points, corner_levels, 0, triangle_points);

  // Rasterize triangles into temporary grid
  R3Grid tmp(grid_resolution[0], grid_resolution[1], grid_resolution[2]);
  for (int i = 0; i < npoints; i += 3) {
    tmp.RasterizeGridTriangle(triangle_points[i], triangle_points[i+1], triangle_points[i+2], 1);
  }
  
  // Add value to this grid where temporary grid is nonzero (avoids double counting at triangle boundaries)
  for (int iz = 0; iz < grid_resolution[2]; iz++) {
    for (int iy = 0; iy < grid_resolution[1]; iy++) {
      for (int ix = 0; ix < grid_resolution[0]; ix++) {
        if (tmp.GridValue(ix, iy, iz) > 0) {
          RasterizeGridValue(ix, iy, iz, value, operation);
        }
      }
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x608, %rsp            # imm = 0x608
movl %edx, %ebx
movsd %xmm0, (%rsp)
movq %rsi, %r15
movq %rdi, %r14
xorl %r12d, %r12d
leaq (%rsp,%r12), %rdi
addq $0xb0, %rdi
callq 0x3ca24
addq $0x18, %r12
cmpq $0xc0, %r12
jne 0x351f7
xorl %r12d, %r12d
leaq (%rsp,%r12), %rdi
addq $0x3c0, %rdi            # imm = 0x3C0
callq 0x3ca24
addq $0x18, %r12
cmpq $0x240, %r12            # imm = 0x240
jne 0x35217
movl 0x238(%r14), %eax
decl %eax
cvtsi2sd %eax, %xmm3
movl 0x23c(%r14), %eax
decl %eax
cvtsi2sd %eax, %xmm4
movl 0x240(%r14), %eax
decl %eax
cvtsi2sd %eax, %xmm5
leaq 0x38(%rsp), %rdi
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
callq 0x27590
leaq 0xb0(%rsp), %r13
xorl %ebp, %ebp
leaq 0x170(%rsp), %r12
movq %r12, %rdi
leaq 0x38(%rsp), %rsi
movl %ebp, %edx
callq 0x2777e
movq %r13, %rdi
movq %r12, %rsi
callq 0x3cd94
movq %r15, %rdi
movq %r13, %rsi
callq 0x4a10f
movsd %xmm0, 0x70(%rsp,%rbp,8)
incq %rbp
addq $0x18, %r13
cmpq $0x8, %rbp
jne 0x35283
leaq 0xb0(%rsp), %rdi
leaq 0x70(%rsp), %rsi
leaq 0x3c0(%rsp), %rdx
xorpd %xmm0, %xmm0
callq 0x354c2
movl %eax, %ebp
movl 0x238(%r14), %esi
movl 0x23c(%r14), %edx
movl 0x240(%r14), %ecx
leaq 0x170(%rsp), %rdi
callq 0x2e74c
testl %ebp, %ebp
jle 0x353cd
xorl %r12d, %r12d
leaq 0x400(%rsp), %r13
leaq 0x8(%rsp), %r15
movupd -0x40(%r13), %xmm0
movapd 0x6cced(%rip), %xmm1    # 0xa2010
addpd %xmm1, %xmm0
cvttpd2dq %xmm0, %xmm0
movlpd %xmm0, 0x28(%rsp)
movsd -0x30(%r13), %xmm0
movsd 0x6ccf1(%rip), %xmm2    # 0xa2030
addsd %xmm2, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x30(%rsp)
movsd -0x18(%r13), %xmm0
addsd %xmm2, %xmm0
cvttsd2si %xmm0, %eax
movupd -0x28(%r13), %xmm0
addpd %xmm1, %xmm0
cvttpd2dq %xmm0, %xmm0
movlpd %xmm0, 0x18(%rsp)
movl %eax, 0x20(%rsp)
movupd -0x10(%r13), %xmm0
addpd %xmm1, %xmm0
cvttpd2dq %xmm0, %xmm0
movlpd %xmm0, 0x8(%rsp)
movsd (%r13), %xmm0
addsd %xmm2, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x10(%rsp)
leaq 0x170(%rsp), %rdi
leaq 0x28(%rsp), %rsi
leaq 0x18(%rsp), %rdx
movq %r15, %rcx
movsd 0x6cc84(%rip), %xmm0    # 0xa2038
xorl %r8d, %r8d
callq 0x34c56
addq $0x48, %r13
addl $0x3, %r12d
cmpl %r12d, %ebp
jg 0x35315
cmpl $0x0, 0x240(%r14)
jle 0x3546a
xorl %ebp, %ebp
cmpl $0x0, 0x23c(%r14)
jle 0x3545b
xorl %r15d, %r15d
cmpl $0x0, 0x238(%r14)
jle 0x3544f
xorl %r12d, %r12d
movq 0x3a0(%rsp), %rax
movl 0x3b8(%rsp), %ecx
imull %ebp, %ecx
movl 0x3b4(%rsp), %edx
imull %r15d, %edx
addl %ecx, %edx
addl %r12d, %edx
movslq %edx, %rcx
movsd (%rax,%rcx,8), %xmm0
ucomisd 0x6cdbf(%rip), %xmm0    # 0xa21e8
jbe 0x35443
movq %r14, %rdi
movl %r12d, %esi
movl %r15d, %edx
movl %ebp, %ecx
movsd (%rsp), %xmm0
movl %ebx, %r8d
callq 0x341de
incl %r12d
cmpl 0x238(%r14), %r12d
jl 0x353f7
incl %r15d
cmpl 0x23c(%r14), %r15d
jl 0x353ea
incl %ebp
cmpl 0x240(%r14), %ebp
jl 0x353dd
leaq 0x170(%rsp), %rdi
callq 0x2f17c
leaq 0x38(%rsp), %rdi
callq 0x28348
addq $0x608, %rsp            # imm = 0x608
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3549b
jmp 0x3549b
jmp 0x354a0
jmp 0x3549b
movq %rax, %rbx
jmp 0x354b0
movq %rax, %rbx
leaq 0x170(%rsp), %rdi
callq 0x2f17c
leaq 0x38(%rsp), %rdi
callq 0x28348
movq %rbx, %rdi
callq 0xe7e0