// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x68, %rsp
movq %rdi, 0x60(%rsp)
movq %rsi, 0x58(%rsp)
movq %rdx, 0x50(%rsp)
movq %rcx, 0x48(%rsp)
movq 0x60(%rsp), %rax
movq 0x20(%rax), %rax
cmpq $0x0, 0xe0(%rax)
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0x34(%rsp)
movq $0x0, 0x20(%rsp)
movq 0x60(%rsp), %rax
movq 0x48(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x48(%rax)
movq 0x60(%rsp), %rax
movq $0x0, 0x30(%rax)
movq 0x60(%rsp), %rax
movq $0x0, 0x28(%rax)
movq 0x60(%rsp), %rax
movq $0x0, 0x38(%rax)
movq 0x60(%rsp), %rax
movq $0x0, 0x40(%rax)
movq $0x0, 0x38(%rsp)
movq 0x38(%rsp), %rax
movq 0x60(%rsp), %rcx
movq 0x20(%rcx), %rcx
cmpq 0x40(%rcx), %rax
jae 0x2da2d
movq 0x60(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x60(%rsp), %rcx
imulq $0x18, 0x40(%rcx), %rcx
addq %rcx, %rax
movq %rax, 0x28(%rsp)
movq 0x60(%rsp), %rax
movq 0x20(%rax), %rax
movq 0x38(%rax), %rax
movq 0x38(%rsp), %rcx
movq (%rax,%rcx,8), %rcx
movq 0x28(%rsp), %rax
movq %rcx, (%rax)
movq 0x28(%rsp), %rax
movq $0x0, 0x8(%rax)
movq 0x28(%rsp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, 0x10(%rax)
movq 0x60(%rsp), %rax
movq 0x18(%rax), %rdi
movq 0x60(%rsp), %rsi
addq $0x40, %rsi
callq 0x2d870
movq 0x38(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x38(%rsp)
jmp 0x2d99c
jmp 0x2da2f
movb $0x1, %al
cmpl $0x0, 0x34(%rsp)
movb %al, 0x17(%rsp)
jne 0x2da5c
movq 0x60(%rsp), %rax
movq 0x28(%rax), %rax
movq 0x60(%rsp), %rcx
movq 0x20(%rcx), %rcx
cmpq 0xe0(%rcx), %rax
setb %al
movb %al, 0x17(%rsp)
movb 0x17(%rsp), %al
testb $0x1, %al
jne 0x2da69
jmp 0x2db2d
movq 0x60(%rsp), %rax
cmpq $0x0, 0x40(%rax)
jne 0x2da7a
jmp 0x2db2d
movq 0x60(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x8(%rsp)
movq 0x60(%rsp), %rax
movq 0x18(%rax), %rdi
movq 0x60(%rsp), %rsi
addq $0x40, %rsi
callq 0x2dbc0
movq %rax, %rcx
movq 0x8(%rsp), %rax
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x18(%rsp)
movq 0x20(%rsp), %rax
cmpq 0x50(%rsp), %rax
jne 0x2daeb
movq 0x58(%rsp), %rax
movsd (%rax), %xmm1
movq 0x18(%rsp), %rax
movsd 0x10(%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x2daeb
movq 0x60(%rsp), %rax
movq 0x38(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x38(%rax)
jmp 0x2db2d
movq 0x60(%rsp), %rdi
movq 0x18(%rsp), %rax
movq (%rax), %rsi
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rdx
movq 0x58(%rsp), %rcx
movq 0x50(%rsp), %r8
movq 0x18(%rsp), %rax
movsd 0x10(%rax), %xmm0
movq 0x48(%rsp), %rax
leaq 0x20(%rsp), %r9
movq %rax, (%rsp)
callq 0x2d140
jmp 0x2da2f
movq 0x20(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x40(%rsp), %rax
cmpq 0x50(%rsp), %rax
jae 0x2db8d
movq 0x58(%rsp), %rax
movq 0x40(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq $-0x1, 0x8(%rax)
movss 0x2be80(%rip), %xmm0    # 0x599e4
cvtss2sd %xmm0, %xmm0
movq 0x58(%rsp), %rax
movq 0x40(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd %xmm0, (%rax)
movq 0x40(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x40(%rsp)
jmp 0x2db37
jmp 0x2db8f
cmpq $0x0, 0x20(%rsp)
je 0x2dba8
movq 0x58(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x2dc30
jmp 0x2db8f
movq 0x60(%rsp), %rax
movq 0x28(%rax), %rax
addq $0x68, %rsp
retq
nopw %cs:(%rax,%rax)