// File: /workspace/github_c_makefile_star2_O3/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 0x233ee
movq %rcx, %r15
movq %rsi, %r13
movsd 0xf978(%rip), %xmm0     # 0x32c08
movsd %xmm0, 0x8(%rsp)
xorl %r12d, %r12d
xorl %ebp, %ebp
cmpl $0x0, 0x50(%rbx)
je 0x232bd
callq 0x9180
movq %rax, %rcx
leaq 0x1(%r12), %rsi
movq 0x48(%rbx), %rdx
leaq 0xf95f(%rip), %rdi      # 0x32c18
xorl %eax, %eax
callq *%rcx
callq 0x9350
movsd %xmm0, (%rsp)
movl 0x28(%rbx), %eax
cmpl $0x1, %eax
je 0x232f1
testl %eax, %eax
jne 0x2341e
movq %rbx, %rdi
movq %r13, %rsi
movq 0x10(%rsp), %rdx
movq %r15, %rcx
movq 0x18(%rsp), %r8
callq 0x9290
jmp 0x23309
movq %rbx, %rdi
movq %r13, %rsi
movq 0x10(%rsp), %rdx
movq %r15, %rcx
movq 0x18(%rsp), %r8
callq 0x9100
cmpl $0x0, 0x50(%rbx)
je 0x2332d
callq 0x9180
movq %rax, %r14
callq 0x9350
subsd (%rsp), %xmm0
leaq 0xf90d(%rip), %rdi      # 0x32c35
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 0x2337e
callq 0x9180
movq %rax, %r14
callq 0x9350
subsd 0x20(%rsp), %xmm0
leaq 0xf8ed(%rip), %rdi      # 0x32c5c
movsd (%rsp), %xmm1
movb $0x2, %al
callq *%r14
movsd (%rsp), %xmm1
testq %r12, %r12
je 0x2339c
movsd 0x8(%rsp), %xmm0
ucomisd %xmm1, %xmm0
ja 0x2339c
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rsp)
jmp 0x233df
testq %rbp, %rbp
jne 0x233ce
movl (%rbx), %eax
decl %eax
cmpl $0xa, %eax
jae 0x2341e
movl %eax, %eax
movq 0x8(%rbx), %rdi
leaq 0xfdb9(%rip), %rcx      # 0x33170
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 0x2329b
jmp 0x233fd
movsd 0xf812(%rip), %xmm0     # 0x32c08
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