// File: /workspace/github_cpp_makefile_star2_O1/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 0x16cc(%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 0x1a18
shlq $0x3, %r15
leaq (%r15,%r15,4), %r15
xorl %ebx, %ebx
movabsq $0x200000000, %r12      # imm = 0x200000000
movl $0x0, 0x8(%r13,%rbx)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x10(%r13,%rbx)
movq %r12, 0x20(%r13,%rbx)
movl $0x10, %edi
callq 0x1030
movq %rax, 0x28(%r13,%rbx)
addq $0x28, %rbx
cmpq %rbx, %r15
jne 0x19e7
movq %r13, 0x10(%rsp)
leaq 0x8(%r13), %rbx
movq %rbx, %rdi
movq %r14, %rsi
movl %ebp, %edx
callq 0x1771
movq %rbx, %rdi
movl %ebp, %esi
callq 0x18eb
movsd 0x15d0(%rip), %xmm1     # 0x3010
subsd %xmm0, %xmm1
ucomisd 0x15cc(%rip), %xmm1     # 0x3018
jbe 0x1b61
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 0x161b(%rip), %rdi      # 0x3099
movl %esi, 0xc(%rsp)
xorl %eax, %eax
callq 0x1040
movq %r12, %r13
movq 0x18(%rsp), %r15
testl %ebp, %ebp
jle 0x1aa6
movq %r15, %rdi
callq 0x1e16
addq $0x28, %r15
decq %r13
jne 0x1a95
cmpl $0x0, (%r14)
leaq 0x30(%rsp), %r13
jle 0x1ae6
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 0x181b
leaq 0x18(%rax), %rdi
movq %r13, %rsi
callq 0x1d8e
incq %r15
movslq (%r14), %rax
cmpq %rax, %r15
jl 0x1ab4
leaq 0x1543(%rip), %rdi      # 0x3030
xorl %eax, %eax
callq 0x1040
testl %ebp, %ebp
leaq 0x1548(%rip), %rbp      # 0x3045
jle 0x1b26
movq %rbx, %r15
xorl %r13d, %r13d
movq %rbp, %rdi
movl %r13d, %esi
xorl %eax, %eax
callq 0x1040
movq %r15, %rdi
callq 0x16c5
incq %r13
addq $0x28, %r15
cmpq %r13, %r12
jne 0x1b05
movl $0xa, %edi
callq 0x1100
movq %rbx, %rdi
movl 0x8(%rsp), %ebp
movl %ebp, %esi
callq 0x18eb
cmpl $0x8, 0x20(%rsp)
movsd 0x28(%rsp), %xmm1
ja 0x1b61
subsd %xmm0, %xmm1
ucomisd 0x14c1(%rip), %xmm1     # 0x3018
movl 0xc(%rsp), %eax
ja 0x1a69
movq 0x10(%rsp), %r14
movq (%r14), %rax
testq %rax, %rax
je 0x1b8a
shlq $0x3, %rax
leaq (%rax,%rax,4), %rbx
movq (%r14,%rbx), %rdi
testq %rdi, %rdi
je 0x1b84
callq 0x10d0
addq $-0x28, %rbx
jne 0x1b76
movq %r14, %rdi
callq 0x10f0
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
testq %rbx, %rbx
je 0x1bbe
movq (%r13,%rbx), %rdi
testq %rdi, %rdi
je 0x1bb8
callq 0x10d0
addq $-0x28, %rbx
jne 0x1ba9
movq %r13, %rdi
callq 0x10f0
movq %r14, %rdi
callq 0x1170