// File: /workspace/github_cpp_makefile_star2_O3/ivanzamanov[P]kmeans/src/kmeans/kmeans.cpp
// Function: clusterize(int, list<article_entry*>&)
void clusterize(int k, entryList &l) {
	printf("Clusterizing in %d clusters\n", k);
	cluster *clusters = new cluster[k];
	selectSeeds(clusters, l, k);
	double RSS = printRSS(clusters, k);
	double prevRSS = 1e+20;

	int iterations = 0;
	while(iterations < MAX_ITERATIONS && (prevRSS - RSS) > THRESHOLD) {
		iterations++;
		printf("Iteration %d\n", iterations);
		// Clear cluster members.
		for(int i=0; i<k; i++)
			clusters[i].members.clear();

		// Find the best cluster for each entry
		// and add as a member
		for(int i=0; i<l.size(); i++) {
			article_entry* entry = l.get(i);
			cluster& cl = findBestCluster(clusters, k, entry->v);
			cl.members.add(entry);
		}

		// Recompute centroids
		printf("Computing centroids ");
		for(int i=0; i<k; i++) {
			printf("%d ", i);
			recomputeCentroid(clusters[i]);
		}
		printf("\n");

		prevRSS = RSS;
		RSS = printRSS(clusters, k);
	}

	delete[] clusters;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %r14
movl %edi, %ebp
movslq %edi, %r15
movl $0x28, %ecx
movq %r15, %rax
mulq %rcx
seto %cl
addq $0x8, %rax
movq $-0x1, %rbx
cmovbq %rbx, %rax
leaq 0x16fe(%rip), %rdi      # 0x307c
testb %cl, %cl
cmoveq %rax, %rbx
movl %r15d, %esi
xorl %eax, %eax
callq 0x1040
movq %rbx, %rdi
callq 0x1030
movq %rax, %r13
movq %r15, (%rax)
testl %r15d, %r15d
je 0x19e7
shlq $0x3, %r15
leaq (%r15,%r15,4), %rbx
xorl %r15d, %r15d
movabsq $0x200000000, %r12      # imm = 0x200000000
movl $0x0, 0x8(%r13,%r15)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x10(%r13,%r15)
movq %r12, 0x20(%r13,%r15)
movl $0x10, %edi
callq 0x1030
movq %rax, 0x28(%r13,%r15)
addq $0x28, %r15
cmpq %r15, %rbx
jne 0x19b6
movq %r13, 0x10(%rsp)
leaq 0x8(%r13), %rbx
movq %rbx, %rdi
movq %r14, %rsi
movl %ebp, %edx
callq 0x173f
movq %rbx, %rdi
movl %ebp, %esi
callq 0x18b9
movsd 0x1601(%rip), %xmm1     # 0x3010
subsd %xmm0, %xmm1
ucomisd 0x15fd(%rip), %xmm1     # 0x3018
jbe 0x1b30
movl %ebp, %r12d
movq 0x10(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x18(%rsp)
xorl %eax, %eax
movl %ebp, 0x8(%rsp)
movsd %xmm0, 0x28(%rsp)
movq %rax, 0x20(%rsp)
leal 0x1(%rax), %esi
leaq 0x164c(%rip), %rdi      # 0x3099
movl %esi, 0xc(%rsp)
xorl %eax, %eax
callq 0x1040
movq %r12, %r13
movq 0x18(%rsp), %r15
testl %ebp, %ebp
jle 0x1a75
movq %r15, %rdi
callq 0x1dc8
addq $0x28, %r15
decq %r13
jne 0x1a64
cmpl $0x0, (%r14)
leaq 0x30(%rsp), %r13
jle 0x1ab5
xorl %r15d, %r15d
movq 0x8(%r14), %rax
movq (%rax,%r15,8), %rdx
movq %rdx, 0x30(%rsp)
addq $0x8, %rdx
movq %rbx, %rdi
movl %ebp, %esi
callq 0x17e9
leaq 0x18(%rax), %rdi
movq %r13, %rsi
callq 0x1d46
incq %r15
movslq (%r14), %rax
cmpq %rax, %r15
jl 0x1a83
leaq 0x1574(%rip), %rdi      # 0x3030
xorl %eax, %eax
callq 0x1040
testl %ebp, %ebp
leaq 0x1579(%rip), %rbp      # 0x3045
jle 0x1af5
movq %rbx, %r15
xorl %r13d, %r13d
movq %rbp, %rdi
movl %r13d, %esi
xorl %eax, %eax
callq 0x1040
movq %r15, %rdi
callq 0x169d
incq %r13
addq $0x28, %r15
cmpq %r13, %r12
jne 0x1ad4
movl $0xa, %edi
callq 0x1100
movq %rbx, %rdi
movl 0x8(%rsp), %ebp
movl %ebp, %esi
callq 0x18b9
cmpl $0x8, 0x20(%rsp)
movsd 0x28(%rsp), %xmm1
ja 0x1b30
subsd %xmm0, %xmm1
ucomisd 0x14f2(%rip), %xmm1     # 0x3018
movl 0xc(%rsp), %eax
ja 0x1a38
movq 0x10(%rsp), %r14
movq (%r14), %rax
testq %rax, %rax
je 0x1b54
shlq $0x3, %rax
leaq (%rax,%rax,4), %rbx
movq (%r14,%rbx), %rdi
callq 0x10d0
addq $-0x28, %rbx
jne 0x1b45
movq %r14, %rdi
callq 0x10f0
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
testq %r15, %r15
je 0x1b83
movq (%r13,%r15), %rdi
callq 0x10d0
addq $-0x28, %r15
jne 0x1b73
movq %r13, %rdi
callq 0x10f0
movq %rbx, %rdi
callq 0x1170