// File: /workspace/github_c_makefile_star2_O1/zpole[P]IICV/vl/kmeans.c
// Function: vl_kmeans_cluster
VL_EXPORT double
vl_kmeans_cluster (VlKMeans * self,
                   void const * data,
                   vl_size dimension,
                   vl_size numData,
                   vl_size numCenters)
{
  vl_uindex repetition ;
  double bestEnergy = VL_INFINITY_D ;
  void * bestCenters = NULL ;

  for (repetition = 0 ; repetition < self->numRepetitions ; ++ repetition) {
    double energy ;
    double timeRef ;

    if (self->verbosity) {
      VL_PRINTF("kmeans: repetition %d of %d\n", repetition + 1, self->numRepetitions) ;
    }

    timeRef = vl_get_cpu_time() ;
    switch (self->initialization) {
      case VlKMeansRandomSelection :
        vl_kmeans_init_centers_with_rand_data (self,
                                               data, dimension, numData,
                                               numCenters) ;
        break ;
      case VlKMeansPlusPlus :
        vl_kmeans_init_centers_plus_plus (self,
                                          data, dimension, numData,
                                          numCenters) ;
        break ;
      default:
        abort() ;
    }

    if (self->verbosity) {
      VL_PRINTF("kmeans: K-means initialized in %.2f s\n",
                vl_get_cpu_time() - timeRef) ;
    }

    timeRef = vl_get_cpu_time () ;
    energy = vl_kmeans_refine_centers (self, data, numData) ;
    if (self->verbosity) {
      VL_PRINTF("kmeans: K-means terminated in %.2f s with energy %g\n",
                vl_get_cpu_time() - timeRef, energy) ;
    }

    /* copy centers to output if current solution is optimal */
    /* check repetition == 0 as well in case energy = NaN, which */
    /* can happen if the data contain NaNs */
    if (energy < bestEnergy || repetition == 0) {
      void * temp ;
      bestEnergy = energy ;

      if (bestCenters == NULL) {
        bestCenters = vl_malloc(vl_get_type_size(self->dataType) *
                                self->dimension *
                                self->numCenters) ;
      }

      /* swap buffers */
      temp = bestCenters ;
      bestCenters = self->centers ;
      self->centers = temp ;
    } /* better energy */
  } /* next repetition */

  vl_free (self->centers) ;
  self->centers = bestCenters ;
  return bestEnergy ;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r8, 0x18(%rsp)
movq %rdx, 0x10(%rsp)
movq %rdi, %rbx
cmpq $0x0, 0x48(%rdi)
je 0x23374
movq %rcx, %r15
movq %rsi, %r13
movsd 0x10a02(%rip), %xmm0    # 0x33c18
movsd %xmm0, 0x8(%rsp)
xorl %r12d, %r12d
xorl %ebp, %ebp
cmpl $0x0, 0x50(%rbx)
je 0x23243
callq 0x9180
movq %rax, %rcx
leaq 0x1(%r12), %rsi
movq 0x48(%rbx), %rdx
leaq 0x109e9(%rip), %rdi     # 0x33c28
xorl %eax, %eax
callq *%rcx
callq 0x9350
movsd %xmm0, (%rsp)
movl 0x28(%rbx), %eax
cmpl $0x1, %eax
je 0x23277
testl %eax, %eax
jne 0x233a4
movq %rbx, %rdi
movq %r13, %rsi
movq 0x10(%rsp), %rdx
movq %r15, %rcx
movq 0x18(%rsp), %r8
callq 0x9290
jmp 0x2328f
movq %rbx, %rdi
movq %r13, %rsi
movq 0x10(%rsp), %rdx
movq %r15, %rcx
movq 0x18(%rsp), %r8
callq 0x9100
cmpl $0x0, 0x50(%rbx)
je 0x232b3
callq 0x9180
movq %rax, %r14
callq 0x9350
subsd (%rsp), %xmm0
leaq 0x10997(%rip), %rdi     # 0x33c45
movb $0x1, %al
callq *%r14
callq 0x9350
movsd %xmm0, 0x20(%rsp)
movq %rbx, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x94a0
movapd %xmm0, %xmm1
cmpl $0x0, 0x50(%rbx)
movsd %xmm0, (%rsp)
je 0x23304
callq 0x9180
movq %rax, %r14
callq 0x9350
subsd 0x20(%rsp), %xmm0
leaq 0x10977(%rip), %rdi     # 0x33c6c
movsd (%rsp), %xmm1
movb $0x2, %al
callq *%r14
movsd (%rsp), %xmm1
testq %r12, %r12
je 0x23322
movsd 0x8(%rsp), %xmm0
ucomisd %xmm1, %xmm0
ja 0x23322
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rsp)
jmp 0x23365
testq %rbp, %rbp
jne 0x23354
movl (%rbx), %eax
decl %eax
cmpl $0xa, %eax
jae 0x233a4
movl %eax, %eax
movq 0x8(%rbx), %rdi
leaq 0x10e43(%rip), %rcx     # 0x34180
imulq (%rcx,%rax,8), %rdi
imulq 0x10(%rbx), %rdi
callq 0x95b0
movq %rax, %rbp
movsd (%rsp), %xmm1
movq 0x58(%rbx), %rax
movq %rbp, 0x58(%rbx)
movq %rax, %rbp
movsd %xmm1, 0x8(%rsp)
incq %r12
cmpq 0x48(%rbx), %r12
jb 0x23221
jmp 0x23383
movsd 0x1089c(%rip), %xmm0    # 0x33c18
movsd %xmm0, (%rsp)
xorl %ebp, %ebp
movq 0x58(%rbx), %rdi
callq 0x9580
movq %rbp, 0x58(%rbx)
movsd (%rsp), %xmm0
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x90b0