// File: /workspace/github_c_makefile_star2_O0/zpole[P]IICV/vl/gmm.c
// Function: vl_gmm_cluster
double vl_gmm_cluster (VlGMM * self,
                       void const * data,
                       vl_size numData)
{
  void * bestPriors = NULL ;
  void * bestMeans = NULL;
  void * bestCovariances = NULL;
  void * bestPosteriors = NULL;
  vl_size size = vl_get_type_size(self->dataType) ;
  double bestLL = -VL_INFINITY_D;
  vl_uindex repetition;

  assert(self->numRepetitions >=1) ;

  bestPriors = vl_malloc(size * self->numClusters) ;
  bestMeans = vl_malloc(size * self->dimension * self->numClusters) ;
  bestCovariances = vl_malloc(size * self->dimension * self->numClusters) ;
  bestPosteriors = vl_malloc(size * self->numClusters * numData) ;

#if 0
  feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
#endif

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

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

    /* initialize a new mixture model */
    timeRef = vl_get_cpu_time() ;
    switch (self->initialization) {
      case VlGMMKMeans : vl_gmm_init_with_kmeans (self, data, numData, NULL) ; break ;
      case VlGMMRand : vl_gmm_init_with_rand_data (self, data, numData) ; break ;
      case VlGMMCustom : break ;
      default: abort() ;
    }
    if (self->verbosity) {
      VL_PRINTF("gmm: model initialized in %.2f s\n",
                vl_get_cpu_time() - timeRef) ;
    }

    /* fit the model to data by running EM */
    timeRef = vl_get_cpu_time () ;
    LL = vl_gmm_em (self, data, numData) ;
    if (self->verbosity) {
      VL_PRINTF("gmm: optimization terminated in %.2f s with loglikelihood %f\n",
                vl_get_cpu_time() - timeRef, LL) ;
    }

    if (LL > bestLL || repetition == 0) {
      void * temp ;

      temp = bestPriors ;
      bestPriors = self->priors ;
      self->priors = temp ;

      temp = bestMeans ;
      bestMeans = self->means ;
      self->means = temp ;

      temp = bestCovariances ;
      bestCovariances = self->covariances ;
      self->covariances = temp ;

      temp = bestPosteriors ;
      bestPosteriors = self->posteriors ;
      self->posteriors = temp ;

      bestLL = LL;
    }
  }

  vl_free (self->priors) ;
  vl_free (self->means) ;
  vl_free (self->covariances) ;
  vl_free (self->posteriors) ;

  self->priors = bestPriors ;
  self->means = bestMeans ;
  self->covariances = bestCovariances ;
  self->posteriors = bestPosteriors ;
  self->LL = bestLL;

  if (self->verbosity) {
    VL_PRINTF("gmm: all repetitions terminated with final loglikelihood %f\n", self->LL) ;
  }

  return bestLL ;
}

// Assembly:
subq $0x88, %rsp
movq %rdi, 0x80(%rsp)
movq %rsi, 0x78(%rsp)
movq %rdx, 0x70(%rsp)
movq $0x0, 0x68(%rsp)
movq $0x0, 0x60(%rsp)
movq $0x0, 0x58(%rsp)
movq $0x0, 0x50(%rsp)
movq 0x80(%rsp), %rax
movl (%rax), %edi
callq 0x18080
movq %rax, 0x48(%rsp)
movsd 0x3f807(%rip), %xmm0    # 0x59380
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, 0x40(%rsp)
movq 0x48(%rsp), %rdi
movq 0x80(%rsp), %rax
imulq 0x10(%rax), %rdi
callq 0x9660
movq %rax, 0x68(%rsp)
movq 0x48(%rsp), %rdi
movq 0x80(%rsp), %rax
imulq 0x8(%rax), %rdi
movq 0x80(%rsp), %rax
imulq 0x10(%rax), %rdi
callq 0x9660
movq %rax, 0x60(%rsp)
movq 0x48(%rsp), %rdi
movq 0x80(%rsp), %rax
imulq 0x8(%rax), %rdi
movq 0x80(%rsp), %rax
imulq 0x10(%rax), %rdi
callq 0x9660
movq %rax, 0x58(%rsp)
movq 0x48(%rsp), %rdi
movq 0x80(%rsp), %rax
imulq 0x10(%rax), %rdi
imulq 0x70(%rsp), %rdi
callq 0x9660
movq %rax, 0x50(%rsp)
movq $0x0, 0x38(%rsp)
movq 0x38(%rsp), %rax
movq 0x80(%rsp), %rcx
cmpq 0x28(%rcx), %rax
jae 0x19e6e
movq 0x80(%rsp), %rax
cmpl $0x0, 0x30(%rax)
je 0x19c7c
callq 0x91a0
movq %rax, %rcx
movq 0x38(%rsp), %rsi
addq $0x1, %rsi
movq 0x80(%rsp), %rax
movq 0x28(%rax), %rdx
leaq 0x3f710(%rip), %rdi     # 0x59388
movb $0x0, %al
callq *%rcx
callq 0x93b0
movsd %xmm0, 0x28(%rsp)
movq 0x80(%rsp), %rax
movl 0x60(%rax), %eax
movl %eax, 0x1c(%rsp)
testl %eax, %eax
je 0x19cb2
jmp 0x19c9c
movl 0x1c(%rsp), %eax
subl $0x1, %eax
je 0x19ccf
jmp 0x19ca7
movl 0x1c(%rsp), %eax
subl $0x2, %eax
je 0x19ce8
jmp 0x19cea
movq 0x80(%rsp), %rdi
movq 0x78(%rsp), %rsi
movq 0x70(%rsp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x99c0
jmp 0x19cef
movq 0x80(%rsp), %rdi
movq 0x78(%rsp), %rsi
movq 0x70(%rsp), %rdx
callq 0x9170
jmp 0x19cef
jmp 0x19cef
callq 0x90b0
movq 0x80(%rsp), %rax
cmpl $0x0, 0x30(%rax)
je 0x19d22
callq 0x91a0
movq %rax, 0x10(%rsp)
callq 0x93b0
movq 0x10(%rsp), %rcx
subsd 0x28(%rsp), %xmm0
leaq 0x3f699(%rip), %rdi     # 0x593b7
movb $0x1, %al
callq *%rcx
callq 0x93b0
movsd %xmm0, 0x28(%rsp)
movq 0x80(%rsp), %rdi
movq 0x78(%rsp), %rsi
movq 0x70(%rsp), %rdx
callq 0x9ad0
movsd %xmm0, 0x30(%rsp)
movq 0x80(%rsp), %rax
cmpl $0x0, 0x30(%rax)
je 0x19d83
callq 0x91a0
movq %rax, 0x8(%rsp)
callq 0x93b0
movq 0x8(%rsp), %rcx
subsd 0x28(%rsp), %xmm0
movsd 0x30(%rsp), %xmm1
leaq 0x3f65a(%rip), %rdi     # 0x593d9
movb $0x2, %al
callq *%rcx
movsd 0x30(%rsp), %xmm0
ucomisd 0x40(%rsp), %xmm0
ja 0x19d9d
cmpq $0x0, 0x38(%rsp)
jne 0x19e59
movq 0x68(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x80(%rsp), %rax
movq 0x48(%rax), %rax
movq %rax, 0x68(%rsp)
movq 0x20(%rsp), %rcx
movq 0x80(%rsp), %rax
movq %rcx, 0x48(%rax)
movq 0x60(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x80(%rsp), %rax
movq 0x38(%rax), %rax
movq %rax, 0x60(%rsp)
movq 0x20(%rsp), %rcx
movq 0x80(%rsp), %rax
movq %rcx, 0x38(%rax)
movq 0x58(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x80(%rsp), %rax
movq 0x40(%rax), %rax
movq %rax, 0x58(%rsp)
movq 0x20(%rsp), %rcx
movq 0x80(%rsp), %rax
movq %rcx, 0x40(%rax)
movq 0x50(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x80(%rsp), %rax
movq 0x50(%rax), %rax
movq %rax, 0x50(%rsp)
movq 0x20(%rsp), %rcx
movq 0x80(%rsp), %rax
movq %rcx, 0x50(%rax)
movsd 0x30(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
jmp 0x19e5b
movq 0x38(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x38(%rsp)
jmp 0x19c2f
movq 0x80(%rsp), %rax
movq 0x48(%rax), %rdi
callq 0x9620
movq 0x80(%rsp), %rax
movq 0x38(%rax), %rdi
callq 0x9620
movq 0x80(%rsp), %rax
movq 0x40(%rax), %rdi
callq 0x9620
movq 0x80(%rsp), %rax
movq 0x50(%rax), %rdi
callq 0x9620
movq 0x68(%rsp), %rcx
movq 0x80(%rsp), %rax
movq %rcx, 0x48(%rax)
movq 0x60(%rsp), %rcx
movq 0x80(%rsp), %rax
movq %rcx, 0x38(%rax)
movq 0x58(%rsp), %rcx
movq 0x80(%rsp), %rax
movq %rcx, 0x40(%rax)
movq 0x50(%rsp), %rcx
movq 0x80(%rsp), %rax
movq %rcx, 0x50(%rax)
movsd 0x40(%rsp), %xmm0
movq 0x80(%rsp), %rax
movsd %xmm0, 0x70(%rax)
movq 0x80(%rsp), %rax
cmpl $0x0, 0x30(%rax)
je 0x19f37
callq 0x91a0
movq %rax, %rcx
movq 0x80(%rsp), %rax
movsd 0x70(%rax), %xmm0
leaq 0x3f4e4(%rip), %rdi     # 0x59417
movb $0x1, %al
callq *%rcx
movsd 0x40(%rsp), %xmm0
addq $0x88, %rsp
retq
nopw %cs:(%rax,%rax)