// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x78, %rsp
movq %rdi, 0x70(%rsp)
movq %rsi, 0x68(%rsp)
movq %rdx, 0x60(%rsp)
movq %rcx, 0x58(%rsp)
movq %r8, 0x50(%rsp)
movsd 0x2952b(%rip), %xmm0    # 0x59a20
movsd %xmm0, 0x40(%rsp)
movq $0x0, 0x38(%rsp)
movq $0x0, 0x48(%rsp)
movq 0x48(%rsp), %rax
movq 0x70(%rsp), %rcx
cmpq 0x48(%rcx), %rax
jae 0x306df
movq 0x70(%rsp), %rax
cmpl $0x0, 0x50(%rax)
je 0x30551
callq 0x91a0
movq %rax, %rcx
movq 0x48(%rsp), %rsi
addq $0x1, %rsi
movq 0x70(%rsp), %rax
movq 0x48(%rax), %rdx
leaq 0x294db(%rip), %rdi     # 0x59a28
movb $0x0, %al
callq *%rcx
callq 0x93b0
movsd %xmm0, 0x28(%rsp)
movq 0x70(%rsp), %rax
movl 0x28(%rax), %eax
movl %eax, 0x1c(%rsp)
testl %eax, %eax
je 0x30579
jmp 0x3056e
movl 0x1c(%rsp), %eax
subl $0x1, %eax
je 0x30599
jmp 0x305b9
movq 0x70(%rsp), %rdi
movq 0x68(%rsp), %rsi
movq 0x60(%rsp), %rdx
movq 0x58(%rsp), %rcx
movq 0x50(%rsp), %r8
callq 0x92d0
jmp 0x305be
movq 0x70(%rsp), %rdi
movq 0x68(%rsp), %rsi
movq 0x60(%rsp), %rdx
movq 0x58(%rsp), %rcx
movq 0x50(%rsp), %r8
callq 0x9100
jmp 0x305be
callq 0x90b0
movq 0x70(%rsp), %rax
cmpl $0x0, 0x50(%rax)
je 0x305ee
callq 0x91a0
movq %rax, 0x10(%rsp)
callq 0x93b0
movq 0x10(%rsp), %rcx
subsd 0x28(%rsp), %xmm0
leaq 0x2945b(%rip), %rdi     # 0x59a45
movb $0x1, %al
callq *%rcx
callq 0x93b0
movsd %xmm0, 0x28(%rsp)
movq 0x70(%rsp), %rdi
movq 0x68(%rsp), %rsi
movq 0x58(%rsp), %rdx
callq 0x9540
movsd %xmm0, 0x30(%rsp)
movq 0x70(%rsp), %rax
cmpl $0x0, 0x50(%rax)
je 0x30649
callq 0x91a0
movq %rax, 0x8(%rsp)
callq 0x93b0
movq 0x8(%rsp), %rcx
subsd 0x28(%rsp), %xmm0
movsd 0x30(%rsp), %xmm1
leaq 0x29427(%rip), %rdi     # 0x59a6c
movb $0x2, %al
callq *%rcx
movsd 0x30(%rsp), %xmm1
movsd 0x40(%rsp), %xmm0
ucomisd %xmm1, %xmm0
ja 0x30663
cmpq $0x0, 0x48(%rsp)
jne 0x306ca
movsd 0x30(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
cmpq $0x0, 0x38(%rsp)
jne 0x306a4
movq 0x70(%rsp), %rax
movl (%rax), %edi
callq 0x2ec80
movq %rax, %rdi
movq 0x70(%rsp), %rax
imulq 0x8(%rax), %rdi
movq 0x70(%rsp), %rax
imulq 0x10(%rax), %rdi
callq 0x9660
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x70(%rsp), %rax
movq 0x58(%rax), %rax
movq %rax, 0x38(%rsp)
movq 0x20(%rsp), %rcx
movq 0x70(%rsp), %rax
movq %rcx, 0x58(%rax)
jmp 0x306cc
movq 0x48(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x48(%rsp)
jmp 0x3050d
movq 0x70(%rsp), %rax
movq 0x58(%rax), %rdi
callq 0x9620
movq 0x38(%rsp), %rcx
movq 0x70(%rsp), %rax
movq %rcx, 0x58(%rax)
movsd 0x40(%rsp), %xmm0
addq $0x78, %rsp
retq
nopw %cs:(%rax,%rax)