// File: /workspace/github_c_makefile_star2_O3/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 $0x38, %rsp
movl %r9d, 0x4(%rsp)
movq %r8, %rbx
movq %rcx, %r14
movq %rdx, %r15
movq %rsi, 0x10(%rsp)
movq %rdi, %r13
movl 0x30(%rdi), %edi
callq 0x97d0
movq %rax, 0x30(%rsp)
movl (%r13), %edi
movq 0x8(%r13), %rsi
movq 0x18(%r13), %rdx
movl 0x30(%r13), %ecx
callq 0x9900
movq %rax, %r12
movq 0x20(%r13), %rsi
movq %rax, %rdi
callq 0x9330
movq %r12, %rdi
xorl %esi, %esi
callq 0x9090
movq 0x10(%r13), %rsi
movq 0x58(%r13), %rdx
movq %r12, %rdi
callq 0x9830
movq %r12, 0x28(%rsp)
movq %r12, %rdi
callq 0x9130
movslq %ebx, %rbx
testq %rbx, %rbx
jle 0x1f405
movq %rax, %rbp
xorl %r12d, %r12d
movq %rbx, 0x8(%rsp)
movq 0x8(%r13), %rax
imulq %r12, %rax
leaq (%r14,%rax,4), %rcx
movl $0x1, %edx
movq %rbp, %rdi
leaq 0x18(%rsp), %rsi
callq 0x92e0
testq %r15, %r15
je 0x1f3c4
cmpl $0x0, 0x4(%rsp)
movq 0x10(%rsp), %rcx
je 0x1f3cf
movq %rbp, %rbx
movq 0x8(%r13), %rdi
movq %rdi, %rax
imulq %r12, %rax
movq %r14, %rbp
leaq (%r14,%rax,4), %rsi
movl (%rcx,%r12,4), %edx
imulq %rdi, %rdx
shlq $0x2, %rdx
addq 0x58(%r13), %rdx
movq %rcx, %r14
callq *0x30(%rsp)
xorps %xmm1, %xmm1
cvtsd2ss 0x18(%rsp), %xmm1
ucomiss %xmm1, %xmm0
jbe 0x1f3e8
movss %xmm1, (%r15,%r12,4)
movl 0x20(%rsp), %eax
movl %eax, (%r14,%r12,4)
jmp 0x1f3ee
movl 0x20(%rsp), %eax
movq 0x10(%rsp), %rcx
jmp 0x1f3e2
xorps %xmm0, %xmm0
cvtsd2ss 0x18(%rsp), %xmm0
movss %xmm0, (%r15,%r12,4)
movl 0x20(%rsp), %eax
movl %eax, (%rcx,%r12,4)
jmp 0x1f3f9
movss %xmm0, (%r15,%r12,4)
movq %rbp, %r14
movq %rbx, %rbp
movq 0x8(%rsp), %rbx
incq %r12
cmpq %r12, %rbx
jne 0x1f34b
movq 0x28(%rsp), %rdi
callq 0x9840
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq