// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/R3Utils/../../pkgs/R3Shapes/R3Kdtree.cpp
// Function: void gaps::R3Kdtree<gaps::R3SegmentationPoint*>::FindAll<gaps::R3Line>(gaps::R3KdtreeNode<gaps::R3SegmentationPoint*>*, gaps::R3Box const&, gaps::R3Line const&, double, double, gaps::RNArray<gaps::R3SegmentationPoint*>&) const
void R3Kdtree<PtrType>::
FindAll(R3KdtreeNode<PtrType> *node, const R3Box& node_box, 
  const Shape& query_shape, 
  RNScalar min_distance, RNScalar max_distance, 
  RNArray<PtrType>& points) const
{
  // Check if node is interior
  if (node->children[0]) {
    assert(node->children[1]);

    // Check node box
    if (max_distance == 0) {
      if (!R3Intersects(query_shape, node_box)) return;
    }
    else {
      // Check distance from shape to node box
      RNLength distance = R3Distance(query_shape, node_box);
      if (distance >= max_distance) return;
    }

    // Search negative side 
    R3Box child_box1(node_box);
    child_box1[RN_HI][node->split_dimension] = node->split_coordinate;
    FindAll(node->children[0], child_box1, query_shape,
      min_distance, max_distance, 
      points);

    // Search positive side
    R3Box child_box2(node_box);
    child_box2[RN_LO][node->split_dimension] = node->split_coordinate;
    FindAll(node->children[1], child_box2, query_shape,
      min_distance, max_distance, 
      points);
  }
  else {
    // Search points
    for (int i = 0; i < node->npoints; i++) {
      PtrType point = node->points[i];

      if (max_distance == 0) {
        if (R3Intersects(query_shape, Position(point))) {
          points.Insert(point);
        }
      }
      else {
        RNLength distance = R3Distance(query_shape, Position(point));
        if ((distance >= min_distance) && (distance <= max_distance)) {
          points.Insert(point);
        }
      }
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %r8, 0x10(%rsp)
movsd %xmm0, 0x8(%rsp)
movq %rcx, %r14
movq %rsi, %r12
movq %rdi, %r15
cmpq $0x0, 0x8(%rsi)
movsd %xmm1, (%rsp)
je 0x2c9fe
movq %rdx, %r13
xorpd %xmm0, %xmm0
movq %r14, %rdi
movq %rdx, %rsi
ucomisd %xmm0, %xmm1
jne 0x2ca80
jp 0x2ca80
xorl %edx, %edx
callq 0x5b15a
testl %eax, %eax
jne 0x2ca94
jmp 0x2cb31
xorl %ebx, %ebx
leaq 0x50(%rsp), %r13
movslq 0x128(%r12), %rax
cmpq %rax, %rbx
movsd (%rsp), %xmm0
jge 0x2cb31
ucomisd 0xc1625(%rip), %xmm0    # 0xee048
movq 0x28(%r12,%rbx,8), %rbp
movq %r13, %rdi
movq %r15, %rsi
movq %rbp, %rdx
jne 0x2ca4b
jp 0x2ca4b
callq 0x1a086
movq %r13, %rdi
movq %r14, %rsi
callq 0x5a94d
testl %eax, %eax
jne 0x2ca6e
jmp 0x2ca7b
callq 0x1a086
movq %r13, %rdi
movq %r14, %rsi
callq 0x60ea0
ucomisd 0x8(%rsp), %xmm0
jb 0x2ca7b
movsd (%rsp), %xmm1
ucomisd %xmm0, %xmm1
jb 0x2ca7b
movq 0x10(%rsp), %rdi
movq %rbp, %rsi
callq 0x1a04c
incq %rbx
jmp 0x2ca05
callq 0x619df
movsd (%rsp), %xmm1
ucomisd %xmm1, %xmm0
jae 0x2cb31
leaq 0x50(%rsp), %rbp
movq %rbp, %rdi
movq %r13, %rsi
callq 0x7bef2
movsd 0x18(%r12), %xmm0
movslq 0x20(%r12), %rax
movsd %xmm0, 0x70(%rsp,%rax,8)
movq 0x8(%r12), %rsi
movq %r15, %rdi
movq %rbp, %rdx
movq %r14, %rcx
movsd 0x8(%rsp), %xmm0
movsd (%rsp), %xmm1
movq 0x10(%rsp), %r8
callq 0x2c99c
leaq 0x18(%rsp), %rdi
movq %r13, %rsi
callq 0x7bef2
movsd 0x18(%r12), %xmm0
movslq 0x20(%r12), %rax
movsd %xmm0, 0x20(%rsp,%rax,8)
movq 0x10(%r12), %rsi
leaq 0x18(%rsp), %rdx
movq %r15, %rdi
movq %r14, %rcx
movsd 0x8(%rsp), %xmm0
movsd (%rsp), %xmm1
movq 0x10(%rsp), %r8
callq 0x2c99c
leaq 0x18(%rsp), %rdi
callq 0x7cbba
leaq 0x50(%rsp), %rdi
callq 0x7cbba
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x7cbba
jmp 0x2cb57
jmp 0x2cb54
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x7cbba
movq %rbx, %rdi
callq 0x15af0
nop