// File: /workspace/github_c_makefile_star2_O0/zpole[P]IICV/vl/gmm.c
// Function: vl_get_gmm_data_posteriors_f
double
VL_XCAT(vl_get_gmm_data_posteriors_, SFX)
(TYPE * posteriors,
 vl_size numClusters,
 vl_size numData,
 TYPE const * priors,
 TYPE const * means,
 vl_size dimension,
 TYPE const * covariances,
 TYPE const * data)
{
  vl_index i_d, i_cl;
  vl_size dim;
  double LL = 0;

  TYPE halfDimLog2Pi = (dimension / 2.0) * log(2.0*VL_PI);
  TYPE * logCovariances ;
  TYPE * logWeights ;
  TYPE * invCovariances ;

#if (FLT == VL_TYPE_FLOAT)
  VlFloatVector3ComparisonFunction distFn = vl_get_vector_3_comparison_function_f(VlDistanceMahalanobis) ;
#else
  VlDoubleVector3ComparisonFunction distFn = vl_get_vector_3_comparison_function_d(VlDistanceMahalanobis) ;
#endif

  logCovariances = vl_malloc(sizeof(TYPE) * numClusters) ;
  invCovariances = vl_malloc(sizeof(TYPE) * numClusters * dimension) ;
  logWeights = vl_malloc(sizeof(TYPE) * numClusters) ;

#if defined(_OPENMP)
#pragma omp parallel for private(i_cl,dim) num_threads(vl_get_max_threads())
#endif
  for (i_cl = 0 ; i_cl < (signed)numClusters ; ++ i_cl) {
    TYPE logSigma = 0 ;
    if (priors[i_cl] < VL_GMM_MIN_PRIOR) {
      logWeights[i_cl] = - (TYPE) VL_INFINITY_D ;
    } else {
      logWeights[i_cl] = log(priors[i_cl]);
    }
    for(dim = 0 ; dim < dimension ; ++ dim) {
      logSigma += log(covariances[i_cl*dimension + dim]);
      invCovariances [i_cl*dimension + dim] = (TYPE) 1.0 / covariances[i_cl*dimension + dim];
    }
    logCovariances[i_cl] = logSigma;
  } /* end of parallel region */

#if defined(_OPENMP)
#pragma omp parallel for private(i_cl,i_d) reduction(+:LL) \
num_threads(vl_get_max_threads())
#endif
  for (i_d = 0 ; i_d < (signed)numData ; ++ i_d) {
    TYPE clusterPosteriorsSum = 0;
    TYPE maxPosterior = (TYPE)(-VL_INFINITY_D) ;

    for (i_cl = 0 ; i_cl < (signed)numClusters ; ++ i_cl) {
      TYPE p =
      logWeights[i_cl]
      - halfDimLog2Pi
      - 0.5 * logCovariances[i_cl]
      - 0.5 * distFn (dimension,
                      data + i_d * dimension,
                      means + i_cl * dimension,
                      invCovariances + i_cl * dimension) ;
      posteriors[i_cl + i_d * numClusters] = p ;
      if (p > maxPosterior) { maxPosterior = p ; }
    }

    for (i_cl = 0 ; i_cl < (signed)numClusters ; ++i_cl) {
      TYPE p = posteriors[i_cl + i_d * numClusters] ;
      p =  exp(p - maxPosterior) ;
      posteriors[i_cl + i_d * numClusters] = p ;
      clusterPosteriorsSum += p ;
    }

    LL +=  log(clusterPosteriorsSum) + (double) maxPosterior ;

    for (i_cl = 0 ; i_cl < (signed)numClusters ; ++i_cl) {
      posteriors[i_cl + i_d * numClusters] /= clusterPosteriorsSum ;
    }
  } /* end of parallel region */

  vl_free(logCovariances);
  vl_free(logWeights);
  vl_free(invCovariances);

  return LL;
}

// Assembly:
subq $0xa8, %rsp
movq 0xb8(%rsp), %rax
movq 0xb0(%rsp), %rax
movq %rdi, 0xa0(%rsp)
movq %rsi, 0x98(%rsp)
movq %rdx, 0x90(%rsp)
movq %rcx, 0x88(%rsp)
movq %r8, 0x80(%rsp)
movq %r9, 0x78(%rsp)
movq $0x0, 0x58(%rsp)
movaps 0x40c8c(%rip), %xmm1    # 0x59160
movq 0x78(%rsp), %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x40c8a(%rip), %xmm1    # 0x59170
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd 0x40be3(%rip), %xmm1    # 0x590e0
divsd %xmm1, %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0x40d21(%rip), %xmm0    # 0x59230
callq 0x94c0
movaps %xmm0, %xmm1
movsd 0x10(%rsp), %xmm0
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x54(%rsp)
movl $0x5, %edi
callq 0x9b60
movq %rax, 0x30(%rsp)
movq 0x98(%rsp), %rdi
shlq $0x2, %rdi
callq 0x9660
movq %rax, 0x48(%rsp)
movq 0x98(%rsp), %rdi
shlq $0x2, %rdi
imulq 0x78(%rsp), %rdi
callq 0x9660
movq %rax, 0x38(%rsp)
movq 0x98(%rsp), %rdi
shlq $0x2, %rdi
callq 0x9660
movq %rax, 0x40(%rsp)
movq $0x0, 0x68(%rsp)
movq 0x68(%rsp), %rax
movq 0x98(%rsp), %rcx
movslq %ecx, %rcx
cmpq %rcx, %rax
jge 0x186fd
xorps %xmm0, %xmm0
movss %xmm0, 0x2c(%rsp)
movq 0x88(%rsp), %rax
movq 0x68(%rsp), %rcx
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x40c7d(%rip), %xmm0    # 0x59248
ucomisd %xmm1, %xmm0
jbe 0x185fb
movsd 0x40da7(%rip), %xmm0    # 0x59380
cvtsd2ss %xmm0, %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
movq 0x40(%rsp), %rax
movq 0x68(%rsp), %rcx
movss %xmm0, (%rax,%rcx,4)
jmp 0x18629
movq 0x88(%rsp), %rax
movq 0x68(%rsp), %rcx
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x94c0
cvtsd2ss %xmm0, %xmm0
movq 0x40(%rsp), %rax
movq 0x68(%rsp), %rcx
movss %xmm0, (%rax,%rcx,4)
movq $0x0, 0x60(%rsp)
movq 0x60(%rsp), %rax
cmpq 0x78(%rsp), %rax
jae 0x186d5
movq 0xb0(%rsp), %rax
movq 0x68(%rsp), %rcx
imulq 0x78(%rsp), %rcx
addq 0x60(%rsp), %rcx
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x94c0
movaps %xmm0, %xmm1
movss 0x2c(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x2c(%rsp)
movq 0xb0(%rsp), %rax
movq 0x68(%rsp), %rcx
imulq 0x78(%rsp), %rcx
addq 0x60(%rsp), %rcx
movss 0x40aed(%rip), %xmm0    # 0x59190
divss (%rax,%rcx,4), %xmm0
movq 0x38(%rsp), %rax
movq 0x68(%rsp), %rcx
imulq 0x78(%rsp), %rcx
addq 0x60(%rsp), %rcx
movss %xmm0, (%rax,%rcx,4)
movq 0x60(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x60(%rsp)
jmp 0x18632
movss 0x2c(%rsp), %xmm0
movq 0x48(%rsp), %rax
movq 0x68(%rsp), %rcx
movss %xmm0, (%rax,%rcx,4)
movq 0x68(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x68(%rsp)
jmp 0x1858b
movq $0x0, 0x70(%rsp)
movq 0x70(%rsp), %rax
movq 0x90(%rsp), %rcx
movslq %ecx, %rcx
cmpq %rcx, %rax
jge 0x189dd
xorps %xmm0, %xmm0
movss %xmm0, 0x28(%rsp)
movsd 0x40c50(%rip), %xmm0    # 0x59380
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x24(%rsp)
movq $0x0, 0x68(%rsp)
movq 0x68(%rsp), %rax
movq 0x98(%rsp), %rcx
movslq %ecx, %rcx
cmpq %rcx, %rax
jge 0x18887
movq 0x40(%rsp), %rax
movq 0x68(%rsp), %rcx
movss (%rax,%rcx,4), %xmm0
subss 0x54(%rsp), %xmm0
cvtss2sd %xmm0, %xmm1
movq 0x48(%rsp), %rax
movq 0x68(%rsp), %rcx
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x40941(%rip), %xmm2    # 0x590e8
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x30(%rsp), %rax
movq 0x78(%rsp), %rdi
movq 0xb8(%rsp), %rsi
movq 0x70(%rsp), %rcx
imulq 0x78(%rsp), %rcx
shlq $0x2, %rcx
addq %rcx, %rsi
movq 0x80(%rsp), %rdx
movq 0x68(%rsp), %rcx
imulq 0x78(%rsp), %rcx
shlq $0x2, %rcx
addq %rcx, %rdx
movq 0x38(%rsp), %rcx
movq 0x68(%rsp), %r8
imulq 0x78(%rsp), %r8
shlq $0x2, %r8
addq %r8, %rcx
callq *%rax
movsd 0x8(%rsp), %xmm1
cvtss2sd %xmm0, %xmm0
movsd 0x408ca(%rip), %xmm2    # 0x590e8
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x20(%rsp)
movss 0x20(%rsp), %xmm0
movq 0xa0(%rsp), %rax
movq 0x68(%rsp), %rcx
movq 0x70(%rsp), %rdx
imulq 0x98(%rsp), %rdx
addq %rdx, %rcx
movss %xmm0, (%rax,%rcx,4)
movss 0x20(%rsp), %xmm0
ucomiss 0x24(%rsp), %xmm0
jbe 0x18872
movss 0x20(%rsp), %xmm0
movss %xmm0, 0x24(%rsp)
jmp 0x18874
movq 0x68(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x68(%rsp)
jmp 0x1875a
movq $0x0, 0x68(%rsp)
movq 0x68(%rsp), %rax
movq 0x98(%rsp), %rcx
movslq %ecx, %rcx
cmpq %rcx, %rax
jge 0x1893f
movq 0xa0(%rsp), %rax
movq 0x68(%rsp), %rcx
movq 0x70(%rsp), %rdx
imulq 0x98(%rsp), %rdx
addq %rdx, %rcx
movss (%rax,%rcx,4), %xmm0
movss %xmm0, 0x1c(%rsp)
movss 0x1c(%rsp), %xmm0
subss 0x24(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x9c10
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x1c(%rsp)
movss 0x1c(%rsp), %xmm0
movq 0xa0(%rsp), %rax
movq 0x68(%rsp), %rcx
movq 0x70(%rsp), %rdx
imulq 0x98(%rsp), %rdx
addq %rdx, %rcx
movss %xmm0, (%rax,%rcx,4)
movss 0x1c(%rsp), %xmm0
addss 0x28(%rsp), %xmm0
movss %xmm0, 0x28(%rsp)
movq 0x68(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x68(%rsp)
jmp 0x18890
movss 0x28(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x94c0
movss 0x24(%rsp), %xmm1
cvtss2sd %xmm1, %xmm1
addsd %xmm1, %xmm0
addsd 0x58(%rsp), %xmm0
movsd %xmm0, 0x58(%rsp)
movq $0x0, 0x68(%rsp)
movq 0x68(%rsp), %rax
movq 0x98(%rsp), %rcx
movslq %ecx, %rcx
cmpq %rcx, %rax
jge 0x189c8
movss 0x28(%rsp), %xmm1
movq 0xa0(%rsp), %rax
movq 0x68(%rsp), %rcx
movq 0x70(%rsp), %rdx
imulq 0x98(%rsp), %rdx
addq %rdx, %rcx
movss (%rax,%rcx,4), %xmm0
divss %xmm1, %xmm0
movss %xmm0, (%rax,%rcx,4)
movq 0x68(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x68(%rsp)
jmp 0x18971
jmp 0x189ca
movq 0x70(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x70(%rsp)
jmp 0x18706
movq 0x48(%rsp), %rdi
callq 0x9620
movq 0x40(%rsp), %rdi
callq 0x9620
movq 0x38(%rsp), %rdi
callq 0x9620
movsd 0x58(%rsp), %xmm0
addq $0xa8, %rsp
retq
nopl (%rax)