// File: isaacbrodsky[P]K-means-plus-plus/k-means-multi.cpp
// Function: Cluster_set::Write_output_data()
void Cluster_set::Write_output_data(void){

	// local variables
	unsigned uInstance_index;
	int iCluster_index, iAttribute_index;
	vector< vector<Cluster_instance> > vclThe_cluster_set(iK_count);

	// declare an output stream
	ofstream strResults_out_stream;

	// Sort the cluster results
	for (uInstance_index = 0; uInstance_index < vclInput_data.size(); uInstance_index++)
	{
		vclThe_cluster_set[vclInput_data[uInstance_index].iCluster].push_back(vclInput_data[uInstance_index]);
	}

	// open the stream to write the output plaintext
	strResults_out_stream.open(sOut_file);

	if(iK_count < 1) { // we have an empty cluster_set
		cout << endl << "No clusters to send to output file!" << endl << endl;
	} else { // output the cluster results
		// loop thru each cluster
		for (iCluster_index = 0; iCluster_index < iK_count; iCluster_index++){

			// output a cluster header - cluster #, cluster mean
			strResults_out_stream << "Cluster #" << iCluster_index + 1 << " with mean ";
			for (iAttribute_index = 0; iAttribute_index < iAttribute_ct; iAttribute_index++){
				strResults_out_stream << vvfMeans[iCluster_index][iAttribute_index] << " ";
			} // for
			strResults_out_stream << "and member count "
				<< vclThe_cluster_set[iCluster_index].size() << "\n";

			// loop thru the cluster members
			for (uInstance_index = 0;
				uInstance_index < vclThe_cluster_set[iCluster_index].size(); uInstance_index++){

				// output the cluster member data
				for (iAttribute_index = 0; iAttribute_index < iAttribute_ct; iAttribute_index++){
					strResults_out_stream
						<< vclThe_cluster_set[iCluster_index][uInstance_index].vfAttribute[iAttribute_index];
					strResults_out_stream << " ";
				} // for
				strResults_out_stream << " ";
				strResults_out_stream << vclThe_cluster_set[iCluster_index][uInstance_index].sClassification;

				// output a CR/LF
				strResults_out_stream << "\n";
			} // for

			// output CR/LF
			strResults_out_stream << "\n";
		} // for
	} // if

	strResults_out_stream.close();

	return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2c0, %rsp            # imm = 0x2C0
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x260(%rbp)
movslq 0x30(%rax), %rax
movq %rax, -0x258(%rbp)
leaq -0x31(%rbp), %rdi
movq %rdi, -0x250(%rbp)
callq 0xa500
movq -0x258(%rbp), %rsi
movq -0x250(%rbp), %rdx
leaq -0x30(%rbp), %rdi
callq 0xa520
jmp 0x654e
leaq -0x31(%rbp), %rdi
callq 0xa590
leaq -0x248(%rbp), %rdi
callq 0x4510
jmp 0x6565
movl $0x0, -0xc(%rbp)
movq -0x260(%rbp), %rdi
movl -0xc(%rbp), %eax
movq %rax, -0x268(%rbp)
addq $0x80, %rdi
callq 0xa5b0
movq %rax, %rcx
movq -0x268(%rbp), %rax
cmpq %rcx, %rax
jae 0x6646
movq -0x260(%rbp), %rdi
subq $-0x80, %rdi
movq %rdi, -0x278(%rbp)
movl -0xc(%rbp), %eax
movl %eax, %esi
callq 0xa5f0
movslq 0x38(%rax), %rsi
leaq -0x30(%rbp), %rdi
callq 0xa5d0
movq -0x278(%rbp), %rdi
movq %rax, -0x270(%rbp)
movl -0xc(%rbp), %eax
movl %eax, %esi
callq 0xa5f0
movq -0x270(%rbp), %rdi
movq %rax, %rsi
callq 0xa3e0
jmp 0x65ee
jmp 0x65f0
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x656c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x31(%rbp), %rdi
callq 0xa590
jmp 0x6983
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x697a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x248(%rbp), %rdi
callq 0x4490
jmp 0x697a
movq -0x260(%rbp), %rsi
addq $0x58, %rsi
leaq -0x248(%rbp), %rdi
movl $0x10, %edx
callq 0x4160
jmp 0x6664
movq -0x260(%rbp), %rax
cmpl $0x1, 0x30(%rax)
jge 0x66df
movq 0x1b948(%rip), %rdi     # 0x21fc0
movq 0x1b909(%rip), %rsi     # 0x21f88
callq 0x4390
movq %rax, -0x280(%rbp)
jmp 0x668d
movq -0x280(%rbp), %rdi
leaq 0xff79(%rip), %rsi      # 0x16614
callq 0x4350
movq %rax, -0x288(%rbp)
jmp 0x66a9
movq -0x288(%rbp), %rdi
movq 0x1b8d1(%rip), %rsi     # 0x21f88
callq 0x4390
movq %rax, -0x290(%rbp)
jmp 0x66c5
movq -0x290(%rbp), %rdi
movq 0x1b8b5(%rip), %rsi     # 0x21f88
callq 0x4390
jmp 0x66da
jmp 0x694e
movl $0x0, -0x10(%rbp)
movq -0x260(%rbp), %rcx
movl -0x10(%rbp), %eax
cmpl 0x30(%rcx), %eax
jge 0x694c
leaq 0xff38(%rip), %rsi      # 0x16638
leaq -0x248(%rbp), %rdi
callq 0x4350
movq %rax, -0x298(%rbp)
jmp 0x6715
movq -0x298(%rbp), %rdi
movl -0x10(%rbp), %esi
incl %esi
callq 0x4520
movq %rax, -0x2a0(%rbp)
jmp 0x672f
movq -0x2a0(%rbp), %rdi
leaq 0xff05(%rip), %rsi      # 0x16642
callq 0x4350
jmp 0x6744
movl $0x0, -0x14(%rbp)
movq -0x260(%rbp), %rcx
movl -0x14(%rbp), %eax
cmpl 0x9c(%rcx), %eax
jge 0x67b4
movq -0x260(%rbp), %rdi
movslq -0x10(%rbp), %rsi
callq 0xa4e0
movq %rax, %rdi
movslq -0x14(%rbp), %rsi
callq 0xa3c0
movss (%rax), %xmm0
leaq -0x248(%rbp), %rdi
callq 0x4260
movq %rax, -0x2a8(%rbp)
jmp 0x6792
movq -0x2a8(%rbp), %rdi
leaq 0xff5e(%rip), %rsi      # 0x166fe
callq 0x4350
jmp 0x67a7
jmp 0x67a9
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x674b
leaq 0xfe93(%rip), %rsi      # 0x1664e
leaq -0x248(%rbp), %rdi
callq 0x4350
movq %rax, -0x2b0(%rbp)
jmp 0x67d0
movslq -0x10(%rbp), %rsi
leaq -0x30(%rbp), %rdi
callq 0xa5d0
movq %rax, %rdi
callq 0xa5b0
movq -0x2b0(%rbp), %rdi
movq %rax, %rsi
callq 0x40a0
movq %rax, -0x2b8(%rbp)
jmp 0x67fd
movq -0x2b8(%rbp), %rdi
leaq 0xfe55(%rip), %rsi      # 0x16660
callq 0x4350
jmp 0x6812
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
movq %rax, -0x2c0(%rbp)
movslq -0x10(%rbp), %rsi
leaq -0x30(%rbp), %rdi
callq 0xa5d0
movq %rax, %rdi
callq 0xa5b0
movq %rax, %rcx
movq -0x2c0(%rbp), %rax
cmpq %rcx, %rax
jae 0x6927
movl $0x0, -0x14(%rbp)
movq -0x260(%rbp), %rcx
movl -0x14(%rbp), %eax
cmpl 0x9c(%rcx), %eax
jge 0x68be
movslq -0x10(%rbp), %rsi
leaq -0x30(%rbp), %rdi
callq 0xa5d0
movq %rax, %rdi
movl -0xc(%rbp), %eax
movl %eax, %esi
callq 0xa5f0
movq %rax, %rdi
movslq -0x14(%rbp), %rsi
callq 0xa3c0
movss (%rax), %xmm0
leaq -0x248(%rbp), %rdi
callq 0x4260
jmp 0x689c
leaq 0xfe5b(%rip), %rsi      # 0x166fe
leaq -0x248(%rbp), %rdi
callq 0x4350
jmp 0x68b1
jmp 0x68b3
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x6852
leaq 0xfe39(%rip), %rsi      # 0x166fe
leaq -0x248(%rbp), %rdi
callq 0x4350
jmp 0x68d3
movslq -0x10(%rbp), %rsi
leaq -0x30(%rbp), %rdi
callq 0xa5d0
movq %rax, %rdi
movl -0xc(%rbp), %eax
movl %eax, %esi
callq 0xa5f0
movq %rax, %rsi
addq $0x18, %rsi
leaq -0x248(%rbp), %rdi
callq 0x42f0
jmp 0x6902
leaq 0xfd57(%rip), %rsi      # 0x16660
leaq -0x248(%rbp), %rdi
callq 0x4350
jmp 0x6917
jmp 0x6919
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x6819
leaq 0xfd32(%rip), %rsi      # 0x16660
leaq -0x248(%rbp), %rdi
callq 0x4350
jmp 0x693c
jmp 0x693e
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x66e6
jmp 0x694e
leaq -0x248(%rbp), %rdi
callq 0x4470
jmp 0x695c
leaq -0x248(%rbp), %rdi
callq 0x4490
leaq -0x30(%rbp), %rdi
callq 0xa610
addq $0x2c0, %rsp            # imm = 0x2C0
popq %rbp
retq
leaq -0x30(%rbp), %rdi
callq 0xa610
movq -0x40(%rbp), %rdi
callq 0x4530
nopl (%rax)