// File: CominLab[P]QCluster/em.cc
// Function: eval_confidence(int, int, int, double**, double**, double*, double**, double*, double*)
static void eval_confidence(int K, int N, int row_length, double **data,
double **centroids, double *Z, double **quality, double *expected_qual, double *expected_freq)
{
	static const double KL_DIST_CUTOFF = 10; // set exponential to zero
		// if we exceed this negative exponent
	for (int n=0; n<N; n++){
		double* row = Z + n*K;
		for(int k=0; k<K; k++){
			row[k] = kl_distance(centroids[k], data[n], row_length, NULL, 
								 quality[n], expected_qual, expected_freq);
		}
		double min_dist = *row;
		for(int k=1; k<K; k++){
			if (min_dist > row[k]){
				min_dist = row[k];
			}
		}
		double S = 0;
		for(int k=0; k<K; k++){
			row[k] -= min_dist;
			S += row[k] = row[k] > KL_DIST_CUTOFF ? 0 : exp(-row[k]);
		}
		for(int k=0; k<K; k++){
			row[k] /= S;
		}
	}
	return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
movl %edx, -0xc(%rbp)
movq %rcx, -0x18(%rbp)
movq %r8, -0x20(%rbp)
movq %r9, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x6dfd
movq -0x28(%rbp), %rax
movl -0x2c(%rbp), %ecx
imull -0x4(%rbp), %ecx
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x6cb6
movq -0x20(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movl -0xc(%rbp), %edx
movq 0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %r8
movq 0x18(%rbp), %r9
movq 0x20(%rbp), %rax
xorl %ecx, %ecx
movq %rax, (%rsp)
callq 0x6fc0
movq -0x38(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x6c5c
movq -0x38(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x48(%rbp)
movl $0x1, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x6d05
movsd -0x48(%rbp), %xmm0
movq -0x38(%rbp), %rax
movslq -0x4c(%rbp), %rcx
ucomisd (%rax,%rcx,8), %xmm0
jbe 0x6cf8
movq -0x38(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x48(%rbp)
jmp 0x6cfa
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x6cca
xorps %xmm0, %xmm0
movsd %xmm0, -0x58(%rbp)
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x6db8
movsd -0x48(%rbp), %xmm1
movq -0x38(%rbp), %rax
movslq -0x5c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movq -0x38(%rbp), %rax
movslq -0x5c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd 0x4e30(%rip), %xmm1     # 0xbb80
ucomisd %xmm1, %xmm0
jbe 0x6d60
xorps %xmm0, %xmm0
movsd %xmm0, -0x68(%rbp)
jmp 0x6d8e
movq -0x38(%rbp), %rax
movslq -0x5c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
callq 0x3440
movsd %xmm0, -0x68(%rbp)
movsd -0x68(%rbp), %xmm0
movq -0x38(%rbp), %rax
movslq -0x5c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
addsd -0x58(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x6d14
movl $0x0, -0x60(%rbp)
movl -0x60(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x6ded
movsd -0x58(%rbp), %xmm1
movq -0x38(%rbp), %rax
movslq -0x60(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x6dbf
jmp 0x6def
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x6c30
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)