// File: /workspace/github_c_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %r9d, 0x1c(%rsp)
movq %r8, 0x30(%rsp)
movq %rcx, %r14
movq %rdx, %r15
movq %rsi, 0x20(%rsp)
movq %rdi, %r13
movl 0x30(%rdi), %edi
callq 0x9830
movq %rax, 0x40(%rsp)
movl (%r13), %edi
movq 0x8(%r13), %rsi
movq 0x18(%r13), %rdx
movl 0x30(%r13), %ecx
callq 0x9970
movq %rax, %r12
movq 0x20(%r13), %rsi
movq %rax, %rdi
callq 0x9340
xorl %ebx, %ebx
movq %r12, %rdi
xorl %esi, %esi
callq 0x9090
movq 0x10(%r13), %rsi
movq %r13, 0x28(%rsp)
movq 0x58(%r13), %rdx
movq %r12, %rdi
callq 0x9890
movq %r12, 0x38(%rsp)
movq %r12, %rdi
callq 0x9130
movq %rax, %rbp
movslq 0x30(%rsp), %r12
testq %r12, %r12
cmovleq %rbx, %r12
leaq 0x8(%rsp), %r13
cmpq %rbx, %r12
je 0x1bdc9
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rax
imulq %rbx, %rax
leaq (%r14,%rax,4), %rcx
movq %rbp, %rdi
movq %r13, %rsi
pushq $0x1
popq %rdx
callq 0x92f0
testq %r15, %r15
je 0x1bd8d
cmpl $0x0, 0x1c(%rsp)
movq 0x20(%rsp), %rcx
je 0x1bd98
movq %r12, %r13
movq %rbp, %r12
movq 0x28(%rsp), %r8
movq 0x8(%r8), %rdi
movq %rdi, %rax
imulq %rbx, %rax
movq %r14, %rbp
leaq (%r14,%rax,4), %rsi
movl (%rcx,%rbx,4), %edx
imulq %rdi, %rdx
shlq $0x2, %rdx
addq 0x58(%r8), %rdx
movq %rcx, %r14
callq *0x40(%rsp)
cvtsd2ss 0x8(%rsp), %xmm1
ucomiss %xmm1, %xmm0
jbe 0x1bdad
movss %xmm1, (%r15,%rbx,4)
movl 0x10(%rsp), %eax
movl %eax, (%r14,%rbx,4)
jmp 0x1bdb3
movl 0x10(%rsp), %eax
movq 0x20(%rsp), %rcx
jmp 0x1bda8
cvtsd2ss 0x8(%rsp), %xmm0
movss %xmm0, (%r15,%rbx,4)
movl 0x10(%rsp), %eax
movl %eax, (%rcx,%rbx,4)
jmp 0x1bdc1
movss %xmm0, (%r15,%rbx,4)
movq %rbp, %r14
movq %r12, %rbp
movq %r13, %r12
leaq 0x8(%rsp), %r13
incq %rbx
jmp 0x1bd06
movq 0x38(%rsp), %rdi
callq 0x98a0
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq