// File: /workspace/github_c_makefile_star2_O2/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 %rcx, %r15
movq %rdx, 0x10(%rsp)
movq %rsi, %r13
movq %rdi, %rbx
movsd 0xe89f(%rip), %xmm0     # 0x2dbc0
movsd %xmm0, 0x8(%rsp)
xorl %ebp, %ebp
xorl %r12d, %r12d
cmpq 0x48(%rbx), %r12
jae 0x1f46e
cmpl $0x0, 0x50(%rbx)
je 0x1f358
callq 0x9180
movq %rax, %rcx
leaq 0x1(%r12), %rsi
movq 0x48(%rbx), %rdx
leaq 0xe89c(%rip), %rdi      # 0x2dbf0
xorl %eax, %eax
callq *%rcx
callq 0x9370
movsd %xmm0, (%rsp)
movl 0x28(%rbx), %eax
cmpl $0x1, %eax
je 0x1f38c
testl %eax, %eax
jne 0x1f490
movq %rbx, %rdi
movq %r13, %rsi
movq 0x10(%rsp), %rdx
movq %r15, %rcx
movq 0x18(%rsp), %r8
callq 0x92a0
jmp 0x1f3a4
movq %rbx, %rdi
movq %r13, %rsi
movq 0x10(%rsp), %rdx
movq %r15, %rcx
movq 0x18(%rsp), %r8
callq 0x9100
cmpl $0x0, 0x50(%rbx)
je 0x1f3c8
callq 0x9180
movq %rax, %r14
callq 0x9370
subsd (%rsp), %xmm0
leaq 0xe84a(%rip), %rdi      # 0x2dc0d
movb $0x1, %al
callq *%r14
callq 0x9370
movsd %xmm0, 0x20(%rsp)
movq %rbx, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x94d0
movapd %xmm0, %xmm1
cmpl $0x0, 0x50(%rbx)
je 0x1f419
movsd %xmm1, (%rsp)
callq 0x9180
movq %rax, %r14
callq 0x9370
subsd 0x20(%rsp), %xmm0
leaq 0xe82a(%rip), %rdi      # 0x2dc34
movsd (%rsp), %xmm1
movb $0x2, %al
callq *%r14
movsd (%rsp), %xmm1
testq %r12, %r12
je 0x1f42a
movsd 0x8(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x1f466
testq %rbp, %rbp
jne 0x1f455
movl (%rbx), %edi
movsd %xmm1, (%rsp)
callq 0x1b3c5
imulq 0x8(%rbx), %rax
imulq 0x10(%rbx), %rax
movq %rax, %rdi
callq 0x95e0
movsd (%rsp), %xmm1
movq %rax, %rbp
movq 0x58(%rbx), %rax
movq %rbp, 0x58(%rbx)
movq %rax, %rbp
movsd %xmm1, 0x8(%rsp)
incq %r12
jmp 0x1f32c
movq 0x58(%rbx), %rdi
callq 0x95b0
movq %rbp, 0x58(%rbx)
movsd 0x8(%rsp), %xmm0
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x90b0