// File: /workspace/github_c_makefile_star2_O0/zpole[P]IICV/vl/kmeans.c
// Function: vl_kmeans_quantize_ann_f
static void
VL_XCAT(_vl_kmeans_quantize_ann_, SFX)
(VlKMeans * self,
 vl_uint32 * assignments,
 TYPE * distances,
 TYPE const * data,
 vl_size numData,
 vl_bool update)
{
#if (FLT == VL_TYPE_FLOAT)
  VlFloatVectorComparisonFunction distFn = vl_get_vector_comparison_function_f(self->distance) ;
#else
  VlDoubleVectorComparisonFunction distFn = vl_get_vector_comparison_function_d(self->distance) ;
#endif

  VlKDForest * forest = vl_kdforest_new(self->dataType,self->dimension,self->numTrees, self->distance) ;
  vl_kdforest_set_max_num_comparisons(forest,self->maxNumComparisons);
  vl_kdforest_set_thresholding_method(forest,VL_KDTREE_MEDIAN);
  vl_kdforest_build(forest,self->numCenters,self->centers);

#ifdef _OPENMP
#pragma omp parallel default(none) \
  num_threads(vl_get_max_threads()) \
  shared(self, forest, update, assignments, distances, data, numData, distFn)
#endif
  {
    VlKDForestNeighbor neighbor ;
    VlKDForestSearcher * searcher ;
    vl_index x;

#ifdef _OPENMP
#pragma omp critical
#endif
    searcher = vl_kdforest_new_searcher (forest) ;

#ifdef _OPENMP
#pragma omp for
#endif
    for(x = 0 ; x < (signed)numData ; ++x) {
      vl_kdforestsearcher_query (searcher, &neighbor, 1, (TYPE const *) (data + x*self->dimension));

      if (distances) {
        if(!update) {
          distances[x] = (TYPE) neighbor.distance;
          assignments[x] = (vl_uint32) neighbor.index ;
        } else {
          TYPE prevDist = (TYPE) distFn(self->dimension,
                                        data + self->dimension * x,
                                        (TYPE*)self->centers + self->dimension *assignments[x]);
          if (prevDist > (TYPE) neighbor.distance) {
            distances[x] = (TYPE) neighbor.distance ;
            assignments[x] = (vl_uint32) neighbor.index ;
          } else {
            distances[x] = prevDist ;
          }
        }
      } else {
        assignments[x] = (vl_uint32) neighbor.index ;
      }
    } /* end for */
  } /* end of parallel region */

  vl_kdforest_delete(forest);
}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x60(%rsp)
movq %rsi, 0x58(%rsp)
movq %rdx, 0x50(%rsp)
movq %rcx, 0x48(%rsp)
movq %r8, 0x40(%rsp)
movl %r9d, 0x3c(%rsp)
movq 0x60(%rsp), %rax
movl 0x30(%rax), %edi
callq 0x9940
movq %rax, 0x30(%rsp)
movq 0x60(%rsp), %rax
movl (%rax), %edi
movq 0x60(%rsp), %rax
movq 0x8(%rax), %rsi
movq 0x60(%rsp), %rax
movq 0x18(%rax), %rdx
movq 0x60(%rsp), %rax
movl 0x30(%rax), %ecx
callq 0x9a80
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rdi
movq 0x60(%rsp), %rax
movq 0x20(%rax), %rsi
callq 0x9370
movq 0x28(%rsp), %rdi
xorl %esi, %esi
callq 0x9090
movq 0x28(%rsp), %rdi
movq 0x60(%rsp), %rax
movq 0x10(%rax), %rsi
movq 0x60(%rsp), %rax
movq 0x58(%rax), %rdx
callq 0x99a0
movq 0x28(%rsp), %rdi
callq 0x9130
movq %rax, 0x10(%rsp)
movq $0x0, 0x8(%rsp)
movq 0x8(%rsp), %rax
movq 0x40(%rsp), %rcx
movslq %ecx, %rcx
cmpq %rcx, %rax
jge 0x300de
movq 0x10(%rsp), %rdi
movq 0x48(%rsp), %rcx
movq 0x8(%rsp), %rax
movq 0x60(%rsp), %rdx
imulq 0x8(%rdx), %rax
shlq $0x2, %rax
addq %rax, %rcx
leaq 0x18(%rsp), %rsi
movl $0x1, %edx
callq 0x9320
cmpq $0x0, 0x50(%rsp)
je 0x300b5
cmpl $0x0, 0x3c(%rsp)
jne 0x2fffc
movsd 0x18(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
movq 0x50(%rsp), %rax
movq 0x8(%rsp), %rcx
movss %xmm0, (%rax,%rcx,4)
movq 0x20(%rsp), %rax
movl %eax, %edx
movq 0x58(%rsp), %rax
movq 0x8(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x300b3
movq 0x30(%rsp), %rax
movq 0x60(%rsp), %rcx
movq 0x8(%rcx), %rdi
movq 0x48(%rsp), %rsi
movq 0x60(%rsp), %rcx
movq 0x8(%rcx), %rcx
imulq 0x8(%rsp), %rcx
shlq $0x2, %rcx
addq %rcx, %rsi
movq 0x60(%rsp), %rcx
movq 0x58(%rcx), %rdx
movq 0x60(%rsp), %rcx
movq 0x8(%rcx), %rcx
movq 0x58(%rsp), %r8
movq 0x8(%rsp), %r9
movl (%r8,%r9,4), %r8d
imulq %r8, %rcx
shlq $0x2, %rcx
addq %rcx, %rdx
callq *%rax
movss %xmm0, 0x4(%rsp)
movss 0x4(%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
cvtsd2ss %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x3009c
movsd 0x18(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
movq 0x50(%rsp), %rax
movq 0x8(%rsp), %rcx
movss %xmm0, (%rax,%rcx,4)
movq 0x20(%rsp), %rax
movl %eax, %edx
movq 0x58(%rsp), %rax
movq 0x8(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x300b1
movss 0x4(%rsp), %xmm0
movq 0x50(%rsp), %rax
movq 0x8(%rsp), %rcx
movss %xmm0, (%rax,%rcx,4)
jmp 0x300b3
jmp 0x300c9
movq 0x20(%rsp), %rax
movl %eax, %edx
movq 0x58(%rsp), %rax
movq 0x8(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x300cb
movq 0x8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x8(%rsp)
jmp 0x2ff72
movq 0x28(%rsp), %rdi
callq 0x99b0
addq $0x68, %rsp
retq
nopl (%rax)