// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/R3Surfels/R3SurfelUtils.cpp
// Function: gaps::InsertNodes(gaps::R3SurfelNodeSet*, gaps::R3SurfelTree*, gaps::R3SurfelNode*, gaps::R3SurfelConstraint const*, gaps::R3Point const&, double, double, double, double)
static int
InsertNodes(R3SurfelNodeSet *nodeset, 
  R3SurfelTree *tree, R3SurfelNode *node,
  const R3SurfelConstraint *constraint,
  const R3Point& xycenter, RNLength xyradius,
  RNScalar center_resolution, RNScalar perimeter_resolution,
  RNScalar focus_exponent)
{
  // Check if node satisfies constraint
  if (constraint && !constraint->Check(node)) {
    return 0;
  }

  // Check if node is outside perimeter
  if ((perimeter_resolution == 0) && (xyradius > 0)) {
    RNScalar xydistance = XYDistance(xycenter, node->BBox());
    if (xydistance > xyradius) return 0;
  }

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

  // Check if this node has target resolution 
  if ((node->NBlocks() > 0) && (center_resolution > 0)) {
    // Compute the target resolution at node
    RNScalar target_resolution = center_resolution;
    if ((xyradius > 0) && (perimeter_resolution < center_resolution)) {
      RNLength xydistance =  XYDistance(xycenter, node->BBox());
      RNScalar t = 1 - xydistance / xyradius;
      target_resolution = perimeter_resolution + 
        (center_resolution - perimeter_resolution) * pow(t, focus_exponent);
    }
      
    // Check if this node is within the target resolution
    for (int i = 0; i < node->NParts(); i++) {
      R3SurfelNode *part = node->Part(i);
      if (part->Resolution() > target_resolution) {
        nodeset->InsertNode(node);
        return 1;
      }
    }
  }

  // Consider parts
  int status = 0;
  for (int i = 0; i < node->NParts(); i++) {
    R3SurfelNode *part = node->Part(i);
    status |= InsertNodes(nodeset, tree, part, constraint, xycenter, xyradius, 
      center_resolution, perimeter_resolution, focus_exponent);
  }

  // Return whether anything was added
  return status;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movsd %xmm3, 0x20(%rsp)
movsd %xmm1, 0x18(%rsp)
movapd %xmm0, %xmm3
movq %rcx, %r13
movq %rdx, %r12
movq %rsi, %rbx
movq %rdi, %r14
testq %rdx, %rdx
movsd %xmm2, (%rsp)
movsd %xmm0, 0x8(%rsp)
je 0x276ed
movq (%r12), %rax
movq %r12, %rdi
movq %rbx, %rsi
callq *0x18(%rax)
movsd 0x8(%rsp), %xmm3
movsd (%rsp), %xmm2
testl %eax, %eax
je 0x27897
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm3
jbe 0x27727
ucomisd %xmm0, %xmm2
jne 0x27727
jp 0x27727
movq %rbx, %rdi
callq 0x37838
movq %r13, %rdi
movq %rax, %rsi
callq 0x2ac79
movsd 0x8(%rsp), %xmm3
movsd (%rsp), %xmm2
ucomisd %xmm3, %xmm0
ja 0x27897
cmpl $0x0, 0x3c(%rbx)
je 0x27825
xorpd %xmm0, %xmm0
movsd 0x18(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x2784b
cmpl $0x0, 0x4c(%rbx)
jle 0x2784b
ucomisd %xmm0, %xmm3
movapd %xmm1, %xmm0
jbe 0x277b3
ucomisd %xmm2, %xmm1
movapd %xmm1, %xmm0
jbe 0x277b3
movq %rbx, %rdi
callq 0x37838
movq %r13, %rdi
movq %rax, %rsi
callq 0x2ac79
divsd 0x8(%rsp), %xmm0
movsd 0xb69cc(%rip), %xmm1    # 0xde150
subsd %xmm0, %xmm1
movsd 0x18(%rsp), %xmm0
subsd (%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movapd %xmm1, %xmm0
movsd 0x20(%rsp), %xmm1
callq 0x138a0
mulsd 0x10(%rsp), %xmm0
addsd (%rsp), %xmm0
movq %r13, 0x28(%rsp)
cmpl $0x0, 0x3c(%rbx)
setg %r13b
jle 0x27838
xorl %r15d, %r15d
xorl %ebp, %ebp
movsd %xmm0, 0x10(%rsp)
movq 0x30(%rbx), %rax
movq (%rax,%r15,8), %rdi
callq 0x37730
movapd %xmm0, %xmm1
movsd 0x10(%rsp), %xmm0
ucomisd %xmm0, %xmm1
jbe 0x2780d
movq (%r14), %rax
movq %r14, %rdi
movq %rbx, %rsi
movsd %xmm1, 0x30(%rsp)
callq *0x38(%rax)
movsd 0x30(%rsp), %xmm1
movsd 0x10(%rsp), %xmm0
movl $0x1, %ebp
ucomisd %xmm0, %xmm1
ja 0x2783a
incq %r15
movslq 0x3c(%rbx), %rax
cmpq %rax, %r15
setl %r13b
jl 0x277cd
jmp 0x2783a
movq (%r14), %rax
movq %r14, %rdi
movq %rbx, %rsi
callq *0x38(%rax)
movl $0x1, %ebp
jmp 0x27899
xorl %ebp, %ebp
testb $0x1, %r13b
movsd 0x8(%rsp), %xmm3
movq 0x28(%rsp), %r13
jne 0x27899
cmpl $0x0, 0x3c(%rbx)
jle 0x27897
xorl %r15d, %r15d
xorl %ebp, %ebp
movq 0x30(%rbx), %rax
movq (%rax,%r15,8), %rsi
movq %r14, %rdi
movq %r12, %rdx
movq %r13, %rcx
movapd %xmm3, %xmm0
movsd 0x18(%rsp), %xmm1
movsd (%rsp), %xmm2
movsd 0x20(%rsp), %xmm3
callq 0x27693
movsd 0x8(%rsp), %xmm3
orl %eax, %ebp
incq %r15
movslq 0x3c(%rbx), %rax
cmpq %rax, %r15
jl 0x27856
jmp 0x27899
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq