// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/R3Surfels/R3SurfelNodeSet.cpp
// Function: gaps::R3SurfelNodeSet::InsertNodes(gaps::R3SurfelTree*, gaps::R3SurfelNode*, gaps::R3Point const&, double, double, double, double, double, double)
void R3SurfelNodeSet::
InsertNodes(R3SurfelTree *tree, R3SurfelNode *node,
  const R3Point& xycenter, RNLength xyradius, 
  RNCoord zmin, RNCoord zmax,
  RNScalar center_resolution, RNScalar perimeter_resolution,
  RNScalar focus_exponent)
{
  // Check if node is in infinite cylinder
  if (node->BBox().ZMin() > zmax) return;
  if (node->BBox().ZMax() < zmin) return;
  RNLength squared_xydistance = SquaredXYDistance(xycenter, node->BBox());
  if ((xyradius > 0) && (squared_xydistance > xyradius * xyradius)) return;

  // Check if this node is a leaf
  if (node->NParts() == 0) {
    // Simply insert leaf node
    InsertNode(node);
    return;
  }

  // Check if we are selecting interior nodes based on resolution
  if (center_resolution > 0) {
    // Compute the target resolution at this node position
    RNScalar target_resolution = center_resolution;
    if ((xyradius > 0) && (perimeter_resolution > 0)) {
      RNLength xydistance = sqrt(squared_xydistance);
      RNScalar t = 1 - xydistance / xyradius;
      target_resolution = perimeter_resolution + 
        (center_resolution - perimeter_resolution) * pow(t, focus_exponent);
    }

    // Check if this node is within a factor of two of target resolution
    if (node->Resolution() > 0.5 * target_resolution) {
      // Insert all parts of this node and don't recurse 
      for (int i = 0; i < node->NParts(); i++) InsertNode(node->Part(i));
      return;
    }
  }

  // Recurse to parts 
  for (int i = 0; i < node->NParts(); i++) {
    R3SurfelNode *part = node->Part(i);
    InsertNodes(tree, part, xycenter, xyradius, zmin, zmax, center_resolution, perimeter_resolution);
  }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x40, %rsp
movsd %xmm5, 0x10(%rsp)
movsd %xmm4, 0x28(%rsp)
movsd %xmm3, 0x18(%rsp)
movsd %xmm2, 0x38(%rsp)
movsd %xmm1, 0x20(%rsp)
movsd %xmm0, 0x8(%rsp)
movq %rcx, %r15
movq %rdx, %rbx
movq %rsi, %r12
movq %rdi, %r14
movq %rdx, %rdi
callq 0x37838
movsd 0x18(%rax), %xmm0
ucomisd 0x38(%rsp), %xmm0
ja 0x38ead
movq %rbx, %rdi
callq 0x37838
movsd 0x20(%rsp), %xmm0
ucomisd 0x30(%rax), %xmm0
ja 0x38ead
movq %rbx, %rdi
callq 0x37838
movsd (%r15), %xmm0
leaq 0xfbfad(%rip), %rcx     # 0x134c08
movsd (%rcx), %xmm2
movapd %xmm0, %xmm1
subsd 0x20(%rax), %xmm1
ucomisd %xmm2, %xmm1
ja 0x38c99
movsd 0x8(%rax), %xmm3
movapd %xmm0, %xmm4
subsd %xmm3, %xmm4
movapd 0xa571d(%rip), %xmm5    # 0xde3a0
xorpd %xmm2, %xmm5
xorpd %xmm1, %xmm1
ucomisd %xmm4, %xmm5
jbe 0x38c99
subsd %xmm0, %xmm3
movapd %xmm3, %xmm1
movsd 0x8(%r15), %xmm3
movapd %xmm3, %xmm0
subsd 0x28(%rax), %xmm0
ucomisd %xmm2, %xmm0
ja 0x38cd5
movsd 0x10(%rax), %xmm4
movapd %xmm3, %xmm5
xorpd 0xa56e1(%rip), %xmm2    # 0xde3a0
subsd %xmm4, %xmm5
xorpd %xmm0, %xmm0
ucomisd %xmm5, %xmm2
jbe 0x38cd5
subsd %xmm3, %xmm4
movapd %xmm4, %xmm0
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm0
jne 0x38ceb
jp 0x38ceb
mulsd %xmm1, %xmm1
movapd %xmm1, %xmm0
jmp 0x38cff
ucomisd %xmm2, %xmm1
mulsd %xmm0, %xmm0
jne 0x38cf7
jnp 0x38cff
mulsd %xmm1, %xmm1
addsd %xmm1, %xmm0
movsd 0x8(%rsp), %xmm2
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm2
jbe 0x38d21
movapd %xmm2, %xmm1
mulsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
ja 0x38ead
cmpl $0x0, 0x3c(%rbx)
je 0x38d79
xorpd %xmm3, %xmm3
movsd 0x18(%rsp), %xmm2
ucomisd %xmm3, %xmm2
movsd 0x20(%rsp), %xmm1
movsd 0x8(%rsp), %xmm2
jbe 0x38e57
ucomisd %xmm3, %xmm2
movsd 0x18(%rsp), %xmm2
jbe 0x38ddd
xorpd %xmm1, %xmm1
movsd 0x28(%rsp), %xmm2
ucomisd %xmm1, %xmm2
movsd 0x18(%rsp), %xmm2
jbe 0x38ddd
ucomisd %xmm1, %xmm0
jb 0x38d95
sqrtsd %xmm0, %xmm0
jmp 0x38d9a
movq (%r14), %rax
movq 0x38(%rax), %rax
movq %r14, %rdi
movq %rbx, %rsi
addq $0x40, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmpq *%rax
callq 0x133c0
divsd 0x8(%rsp), %xmm0
movsd 0xa53a8(%rip), %xmm1    # 0xde150
subsd %xmm0, %xmm1
movsd 0x18(%rsp), %xmm0
subsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
movapd %xmm1, %xmm0
movsd 0x10(%rsp), %xmm1
callq 0x138a0
movapd %xmm0, %xmm2
mulsd 0x30(%rsp), %xmm2
addsd 0x28(%rsp), %xmm2
movsd %xmm2, 0x10(%rsp)
movq %rbx, %rdi
callq 0x37730
movsd 0x10(%rsp), %xmm3
mulsd 0xa5347(%rip), %xmm3    # 0xde140
ucomisd %xmm3, %xmm0
movsd 0x20(%rsp), %xmm1
movsd 0x8(%rsp), %xmm2
jbe 0x38e57
movsd %xmm0, 0x30(%rsp)
movsd %xmm3, 0x10(%rsp)
cmpl $0x0, 0x3c(%rbx)
jle 0x38e3d
xorl %r13d, %r13d
movq 0x30(%rbx), %rax
movq (%rax,%r13,8), %rsi
movq (%r14), %rax
movq %r14, %rdi
callq *0x38(%rax)
incq %r13
movslq 0x3c(%rbx), %rax
cmpq %rax, %r13
jl 0x38e20
movsd 0x30(%rsp), %xmm0
ucomisd 0x10(%rsp), %xmm0
movsd 0x20(%rsp), %xmm1
movsd 0x8(%rsp), %xmm2
ja 0x38ead
cmpl $0x0, 0x3c(%rbx)
jle 0x38ead
xorl %r13d, %r13d
movq 0x30(%rbx), %rax
movq (%rax,%r13,8), %rdx
movq (%r14), %rax
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rcx
movapd %xmm2, %xmm0
movsd 0x38(%rsp), %xmm2
movsd 0x18(%rsp), %xmm3
movsd 0x28(%rsp), %xmm4
movsd 0xa5c86(%rip), %xmm5    # 0xdeb18
callq *0x30(%rax)
movsd 0x20(%rsp), %xmm1
movsd 0x8(%rsp), %xmm2
incq %r13
movslq 0x3c(%rbx), %rax
cmpq %rax, %r13
jl 0x38e60
addq $0x40, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
nop