// File: /workspace/github_c_makefile_star2_O3/zpole[P]IICV/vl/kdtree.c
// Function: vl_kdforestsearcher_query
vl_size
vl_kdforestsearcher_query (VlKDForestSearcher * self,
                           VlKDForestNeighbor * neighbors,
                           vl_size numNeighbors,
                           void const * query)
{

  vl_uindex i, ti ;
  vl_bool exactSearch = self->forest->searchMaxNumComparisons == 0 ;

  VlKDForestSearchState * searchState  ;
  vl_size numAddedNeighbors = 0 ;

  assert (neighbors) ;
  assert (numNeighbors > 0) ;
  assert (query) ;

  /* this number is used to differentiate a query from the next */
  self -> searchId += 1 ;
  self -> searchNumRecursions = 0 ;

  self->searchNumComparisons = 0 ;
  self->searchNumSimplifications = 0 ;

  /* put the root node into the search heap */
  self->searchHeapNumNodes = 0 ;
  for (ti = 0 ; ti < self->forest->numTrees ; ++ ti) {
    searchState = self->searchHeapArray + self->searchHeapNumNodes ;
    searchState -> tree = self->forest->trees[ti] ;
    searchState -> nodeIndex = 0 ;
    searchState -> distanceLowerBound = 0 ;

    vl_kdforest_search_heap_push (self->searchHeapArray, &self->searchHeapNumNodes) ;
  }

  /* branch and bound */
  while (exactSearch || self->searchNumComparisons < self->forest->searchMaxNumComparisons)
  {
    /* pop the next optimal search node */
    VlKDForestSearchState * searchState ;

    /* break if search space completed */
    if (self->searchHeapNumNodes == 0) {
      break ;
    }
    searchState = self->searchHeapArray +
                  vl_kdforest_search_heap_pop (self->searchHeapArray, &self->searchHeapNumNodes) ;
    /* break if no better solution may exist */
    if (numAddedNeighbors == numNeighbors &&
        neighbors[0].distance < searchState->distanceLowerBound) {
      self->searchNumSimplifications ++ ;
      break ;
    }
    vl_kdforest_query_recursively (self,
                                   searchState->tree,
                                   searchState->nodeIndex,
                                   neighbors,
                                   numNeighbors,
                                   &numAddedNeighbors,
                                   searchState->distanceLowerBound,
                                   query) ;
  }

  /* sort neighbors by increasing distance */
  for (i = numAddedNeighbors ; i < numNeighbors ; ++ i) {
    neighbors[i].index = -1 ;
    neighbors[i].distance = VL_NAN_F ;
  }

  while (numAddedNeighbors) {
    vl_kdforest_neighbor_heap_pop (neighbors, &numAddedNeighbors) ;
  }

  return self->searchNumComparisons ;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rcx, %r15
movq %rdi, %r12
movq 0x20(%rdi), %rcx
movq 0xe0(%rcx), %rbp
movq $0x0, 0x30(%rsp)
incq 0x48(%rdi)
movq %rdx, %r14
movq %rsi, %rbx
leaq 0x28(%rdi), %r13
xorpd %xmm0, %xmm0
movupd %xmm0, 0x28(%rdi)
movupd %xmm0, 0x38(%rdi)
cmpq $0x0, 0x40(%rcx)
je 0x1dff5
xorl %esi, %esi
xorl %eax, %eax
movq 0x18(%r12), %rdx
leaq (%rsi,%rsi,2), %rsi
movq 0x38(%rcx), %rdi
movq (%rdi,%rax,8), %rdi
movq %rdi, (%rdx,%rsi,8)
movupd %xmm0, 0x8(%rdx,%rsi,8)
movq 0x40(%r12), %rsi
testq %rsi, %rsi
je 0x1de05
leaq -0x1(%rsi), %rcx
leaq (%rsi,%rsi,2), %r8
movq %rcx, %rsi
shrq %rsi
leaq (%rsi,%rsi,2), %rdi
movsd 0x10(%rdx,%rdi,8), %xmm1
ucomisd 0x10(%rdx,%r8,8), %xmm1
jbe 0x1ddf6
movq 0x10(%rdx,%r8,8), %r9
movq %r9, 0x20(%rsp)
movups (%rdx,%r8,8), %xmm1
movaps %xmm1, 0x10(%rsp)
movq 0x10(%rdx,%rdi,8), %r9
movq %r9, 0x10(%rdx,%r8,8)
movups (%rdx,%rdi,8), %xmm1
movups %xmm1, (%rdx,%r8,8)
movq 0x20(%rsp), %r8
movq %r8, 0x10(%rdx,%rdi,8)
movapd 0x10(%rsp), %xmm1
movupd %xmm1, (%rdx,%rdi,8)
cmpq $0x1, %rcx
ja 0x1dd93
movq 0x20(%r12), %rcx
movq 0x40(%r12), %rsi
incq %rsi
jmp 0x1de0a
movl $0x1, %esi
movq %rsi, 0x40(%r12)
incq %rax
cmpq 0x40(%rcx), %rax
jb 0x1dd6e
jmp 0x1dff5
movq 0x18(%r12), %rax
decq %rcx
movq %rcx, 0x40(%r12)
movq 0x10(%rax), %rdx
movq %rdx, 0x20(%rsp)
movups (%rax), %xmm0
movaps %xmm0, 0x10(%rsp)
leaq (%rcx,%rcx,2), %rcx
movq 0x10(%rax,%rcx,8), %rdx
movq %rdx, 0x10(%rax)
movups (%rax,%rcx,8), %xmm0
movups %xmm0, (%rax)
movq 0x20(%rsp), %rdx
movq %rdx, 0x10(%rax,%rcx,8)
movapd 0x10(%rsp), %xmm0
movupd %xmm0, (%rax,%rcx,8)
movq 0x40(%r12), %rcx
cmpq $0x2, %rcx
jb 0x1dfae
movl $0x1, %edx
xorl %esi, %esi
xorl %edi, %edi
addq $0x2, %rsi
cmpq %rcx, %rsi
jae 0x1df5e
leaq (%rdx,%rdx,2), %r8
movsd 0x10(%rax,%r8,8), %xmm0
leaq (%rsi,%rsi,2), %r9
movsd 0x10(%rax,%r9,8), %xmm1
ucomisd %xmm0, %xmm1
leaq (%rdi,%rdi,2), %rdi
movsd 0x10(%rax,%rdi,8), %xmm2
jbe 0x1defb
ucomisd %xmm0, %xmm2
jbe 0x1dfae
movq 0x10(%rax,%rdi,8), %rsi
movq %rsi, 0x20(%rsp)
movups (%rax,%rdi,8), %xmm0
movaps %xmm0, 0x10(%rsp)
movq 0x10(%rax,%r8,8), %rsi
movq %rsi, 0x10(%rax,%rdi,8)
movups (%rax,%r8,8), %xmm0
movups %xmm0, (%rax,%rdi,8)
movq 0x20(%rsp), %rsi
movq %rsi, 0x10(%rax,%r8,8)
movapd 0x10(%rsp), %xmm0
movupd %xmm0, (%rax,%r8,8)
jmp 0x1df44
ucomisd %xmm1, %xmm2
jbe 0x1dfae
movq 0x10(%rax,%rdi,8), %rdx
movq %rdx, 0x20(%rsp)
movups (%rax,%rdi,8), %xmm0
movaps %xmm0, 0x10(%rsp)
movq 0x10(%rax,%r9,8), %rdx
movq %rdx, 0x10(%rax,%rdi,8)
movups (%rax,%r9,8), %xmm0
movups %xmm0, (%rax,%rdi,8)
movq 0x20(%rsp), %rdx
movq %rdx, 0x10(%rax,%r9,8)
movapd 0x10(%rsp), %xmm0
movupd %xmm0, (%rax,%r9,8)
movq %rsi, %rdx
movq %rdx, %rdi
leaq (%rdx,%rdx), %rsi
leaq 0x1(,%rdx,2), %rdx
cmpq %rcx, %rdx
jb 0x1de80
jmp 0x1dfae
leaq (%rdi,%rdi,2), %rsi
movsd 0x10(%rax,%rsi,8), %xmm0
leaq (%rdx,%rdx,2), %rcx
ucomisd 0x10(%rax,%rcx,8), %xmm0
jbe 0x1dfae
movq 0x10(%rax,%rsi,8), %rdx
movq %rdx, 0x20(%rsp)
movups (%rax,%rsi,8), %xmm0
movaps %xmm0, 0x10(%rsp)
movq 0x10(%rax,%rcx,8), %rdx
movq %rdx, 0x10(%rax,%rsi,8)
movups (%rax,%rcx,8), %xmm0
movups %xmm0, (%rax,%rsi,8)
movq 0x20(%rsp), %rdx
movq %rdx, 0x10(%rax,%rcx,8)
movapd 0x10(%rsp), %xmm0
movupd %xmm0, (%rax,%rcx,8)
movq 0x40(%r12), %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %rax
cmpq %r14, 0x30(%rsp)
jne 0x1dfd2
movsd 0x10(%rax), %xmm0
ucomisd (%rbx), %xmm0
jbe 0x1dfd7
jmp 0x1e05c
movsd 0x10(%rax), %xmm0
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq %r15, (%rsp)
leaq 0x30(%rsp), %r9
movq %r12, %rdi
movq %rbx, %rcx
movq %r14, %r8
callq 0x1d918
testq %rbp, %rbp
je 0x1e00d
movq 0x20(%r12), %rax
movq 0x28(%r12), %rcx
cmpq 0xe0(%rax), %rcx
jae 0x1e01b
movq 0x40(%r12), %rcx
testq %rcx, %rcx
jne 0x1de21
movq 0x30(%rsp), %rax
cmpq %r14, %rax
jae 0x1e054
movq %rax, %rcx
shlq $0x4, %rcx
addq %rbx, %rcx
addq $0x8, %rcx
movabsq $0x7ff8000000000000, %rdx # imm = 0x7FF8000000000000
movq $-0x1, (%rcx)
movq %rdx, -0x8(%rcx)
decq %r14
addq $0x10, %rcx
cmpq %r14, %rax
jne 0x1e03d
movq %rax, %r14
jmp 0x1e16f
incq 0x38(%r12)
jmp 0x1e16f
decq %r14
movups (%rbx), %xmm0
movaps %xmm0, 0x10(%rsp)
movq %r14, %rax
shlq $0x4, %rax
movups (%rbx,%rax), %xmm0
movups %xmm0, (%rbx)
movapd 0x10(%rsp), %xmm0
movupd %xmm0, (%rbx,%rax)
cmpq $0x2, %r14
jb 0x1e16f
movl $0x1, %eax
xorl %edx, %edx
xorl %ecx, %ecx
addq $0x2, %rdx
cmpq %r14, %rdx
jae 0x1e13d
movq %rdx, %rdi
shlq $0x4, %rdi
movsd (%rbx,%rdi), %xmm0
movq %rax, %r8
shlq $0x4, %r8
movsd (%rbx,%r8), %xmm1
shlq $0x4, %rcx
leaq (%rbx,%rcx), %rsi
ucomisd %xmm0, %xmm1
movsd (%rbx,%rcx), %xmm2
jbe 0x1e0ff
ucomisd %xmm2, %xmm1
jbe 0x1e16f
addq %rbx, %r8
movups (%rsi), %xmm0
movaps %xmm0, 0x10(%rsp)
movups (%r8), %xmm0
movups %xmm0, (%rsi)
movapd 0x10(%rsp), %xmm0
movupd %xmm0, (%r8)
jmp 0x1e123
ucomisd %xmm2, %xmm0
jbe 0x1e16f
addq %rbx, %rdi
movups (%rsi), %xmm0
movaps %xmm0, 0x10(%rsp)
movups (%rdi), %xmm0
movups %xmm0, (%rsi)
movapd 0x10(%rsp), %xmm0
movupd %xmm0, (%rdi)
movq %rdx, %rax
movq %rax, %rcx
leaq (%rax,%rax), %rdx
leaq 0x1(,%rax,2), %rax
cmpq %r14, %rax
jb 0x1e09d
jmp 0x1e16f
shlq $0x4, %rax
movsd (%rbx,%rax), %xmm0
shlq $0x4, %rcx
ucomisd (%rbx,%rcx), %xmm0
jbe 0x1e16f
addq %rbx, %rax
addq %rbx, %rcx
movups (%rcx), %xmm0
movaps %xmm0, 0x10(%rsp)
movups (%rax), %xmm0
movups %xmm0, (%rcx)
movapd 0x10(%rsp), %xmm0
movupd %xmm0, (%rax)
testq %r14, %r14
jne 0x1e066
movq (%r13), %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq