// File: isaacbrodsky[P]K-means-plus-plus/k-means-multi.cpp
// Function: Cluster_set::Cluster_data_process(unsigned int, unsigned int)
void Cluster_set::Cluster_data_process(unsigned uIndex, unsigned uLength)
{
	// local variables
	float fDifference;
	float fSquared_difference, fSum_of_squares;
	float fBest_squared_difference;
	int iBest_index;
	int iK_index, iAttribute_index;
	unsigned uLast = uIndex + uLength;

	// loop for all the input data values
	for (; uIndex < uLast; uIndex++) {

		// initialize the tracking variables
		fBest_squared_difference = FLT_MAX; // make this erroneously big
		iBest_index = -1; // Forces taking the first value

		// get the next data vector
		Cluster_instance& clData_instance = vclInput_data[uIndex];

		// loop thru all of the mean values
		for (iK_index = 0; iK_index < iK_count; iK_index++) {

			// initialize the variables
			fDifference = 0;
			fSum_of_squares = 0;

			// compare the data vector to the mean vector
			for (iAttribute_index = 0; iAttribute_index < iAttribute_ct; iAttribute_index++){
				// calculate the difference between the data value and the mean value
				fDifference = (clData_instance.vfAttribute[iAttribute_index] - vvfMeans[iK_index][iAttribute_index]);
				// square the difference
				fSquared_difference = fDifference * fDifference;
				// add to the sum of squares
				fSum_of_squares = fSum_of_squares + fSquared_difference;
			} // for

			// if this value is less than the best squared difference (BSD)
			if (iBest_index == -1 || fSum_of_squares < fBest_squared_difference){
				fBest_squared_difference = fSum_of_squares; // save it as BSD

				// and save the this index as best index
				iBest_index = iK_index;

			} // if
		} // for

		clData_instance.iCluster = iBest_index;
	} // for

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x40(%rbp)
movl -0xc(%rbp), %eax
addl -0x10(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0xc(%rbp), %eax
cmpl -0x30(%rbp), %eax
jae 0x73bc
movq -0x40(%rbp), %rdi
movss 0xedd9(%rip), %xmm0     # 0x16084
movss %xmm0, -0x20(%rbp)
movl $0xffffffff, -0x24(%rbp) # imm = 0xFFFFFFFF
addq $0x80, %rdi
movl -0xc(%rbp), %eax
movl %eax, %esi
callq 0xa5f0
movq %rax, -0x38(%rbp)
movl $0x0, -0x28(%rbp)
movq -0x40(%rbp), %rcx
movl -0x28(%rbp), %eax
cmpl 0x30(%rcx), %eax
jge 0x73a4
xorps %xmm0, %xmm0
movss %xmm0, -0x14(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x1c(%rbp)
movl $0x0, -0x2c(%rbp)
movq -0x40(%rbp), %rcx
movl -0x2c(%rbp), %eax
cmpl 0x9c(%rcx), %eax
jge 0x736f
movq -0x38(%rbp), %rdi
movslq -0x2c(%rbp), %rsi
callq 0xa3c0
movq -0x40(%rbp), %rdi
movss (%rax), %xmm0
movss %xmm0, -0x44(%rbp)
movslq -0x28(%rbp), %rsi
callq 0xa4e0
movq %rax, %rdi
movslq -0x2c(%rbp), %rsi
callq 0xa3c0
movss -0x44(%rbp), %xmm0
subss (%rax), %xmm0
movss %xmm0, -0x14(%rbp)
movss -0x14(%rbp), %xmm0
mulss -0x14(%rbp), %xmm0
movss %xmm0, -0x18(%rbp)
movss -0x1c(%rbp), %xmm0
addss -0x18(%rbp), %xmm0
movss %xmm0, -0x1c(%rbp)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x72fa
cmpl $-0x1, -0x24(%rbp)
je 0x7384
movss -0x1c(%rbp), %xmm1
movss -0x20(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x7394
movss -0x1c(%rbp), %xmm0
movss %xmm0, -0x20(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x24(%rbp)
jmp 0x7396
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x72d3
movl -0x24(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x38(%rax)
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x7293
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)