// File: /workspace/github_cpp_makefile_star2_O1/ivanzamanov[P]kmeans/src/kmeans/kmeans.cpp
// Function: computeCentroid(vector&, list<vector*> const&)
void computeCentroid(vector& centroid, const list<vector*> &vectors) {
	if(vectors.size() == 0)
		return;
	list<iter*> iters;
	for(int i=0; i<vectors.size(); i++) {
		iter *it = new iter;
		it->size = vectors.get(i)->size;
		iters.add(it);
	}

	int stop = 0;
	while(!stop) {
		int min_key = 1 << 30;
		stop = 1;
		for(int i=0; i<iters.size(); i++) {
			iter& it = *(iters.get(i));
			int key = vectors.get(i)->keys[it.index];
			if(key < min_key && it.index < it.size) {
				stop = 0;
				min_key = key;
			}
		}
		if(stop)
			break;

		expandVector(centroid);
		centroid.keys[centroid.size - 1] = min_key;

		double value = 0;
		for(int i=0; i<iters.size(); i++) {
			iter& it = *(iters.get(i));
			int key = vectors.get(i)->keys[it.index];
			double val = vectors.get(i)->values[it.index];
			if(key == min_key && it.index < it.size) {
				value += val;
				it.index++;
			}
		}

		centroid.values[centroid.size - 1] = value;
	}

	for(int i=0; i<centroid.size; i++)
		centroid.values[i] /= vectors.size();
	for(int i=0; i<iters.size(); i++)
		delete iters.get(i);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
cmpl $0x0, (%rsi)
je 0x169a
movq %rsi, %r14
movq %rdi, %rbx
movabsq $0x200000000, %rax      # imm = 0x200000000
movq %rax, (%rsp)
movl $0x10, %edi
callq 0x1030
movq %rax, 0x8(%rsp)
cmpl $0x0, (%r14)
jle 0x15d2
xorl %r13d, %r13d
movq %rsp, %r15
leaq 0x10(%rsp), %r12
movl $0x8, %edi
callq 0x10e0
movl $0x0, 0x4(%rax)
movq %rax, 0x10(%rsp)
movq 0x8(%r14), %rcx
movq (%rcx,%r13,8), %rcx
movl (%rcx), %ecx
movl %ecx, (%rax)
movq %r15, %rdi
movq %r12, %rsi
callq 0x1c7e
incq %r13
movslq (%r14), %rax
cmpq %rax, %r13
jl 0x1521
jmp 0x15d2
movq %rbx, %rdi
callq 0x128c
movq 0x8(%rbx), %rax
movslq (%rbx), %rcx
movl %ebp, -0x4(%rax,%rcx,4)
movslq (%rsp), %rax
testq %rax, %rax
jle 0x15bc
movq 0x8(%rsp), %rcx
movq 0x8(%r14), %rdx
xorpd %xmm0, %xmm0
xorl %esi, %esi
movq (%rcx,%rsi,8), %rdi
movq (%rdx,%rsi,8), %r9
movslq 0x4(%rdi), %r8
movq 0x8(%r9), %r10
cmpl %ebp, (%r10,%r8,4)
jne 0x15b2
cmpl (%rdi), %r8d
jge 0x15b2
movq 0x10(%r9), %r9
addsd (%r9,%r8,8), %xmm0
incl %r8d
movl %r8d, 0x4(%rdi)
incq %rsi
cmpq %rsi, %rax
jne 0x1586
jmp 0x15c0
xorpd %xmm0, %xmm0
movq 0x10(%rbx), %rax
movslq (%rbx), %rcx
movsd %xmm0, -0x8(%rax,%rcx,8)
testb %r15b, %r15b
je 0x1638
movslq (%rsp), %rax
testq %rax, %rax
jle 0x1627
movq 0x8(%rsp), %rcx
movq 0x8(%r14), %rdx
movl $0x40000000, %ebp       # imm = 0x40000000
movl $0x1, %esi
xorl %edi, %edi
movq (%rcx,%rdi,8), %r8
movq (%rdx,%rdi,8), %r9
movq 0x8(%r9), %r9
movslq 0x4(%r8), %r10
movl (%r9,%r10,4), %r9d
cmpl %ebp, %r9d
jge 0x1617
xorl %r11d, %r11d
cmpl (%r8), %r10d
cmovll %r9d, %ebp
cmovll %r11d, %esi
incq %rdi
cmpq %rdi, %rax
jne 0x15f0
testl %esi, %esi
sete %r15b
jmp 0x162f
xorl %r15d, %r15d
movl $0x40000000, %ebp       # imm = 0x40000000
testb %r15b, %r15b
jne 0x155b
movslq (%rbx), %rax
testq %rax, %rax
jle 0x1664
xorps %xmm0, %xmm0
cvtsi2sdl (%r14), %xmm0
movq 0x10(%rbx), %rcx
xorl %edx, %edx
movsd (%rcx,%rdx,8), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rcx,%rdx,8)
incq %rdx
cmpq %rdx, %rax
jne 0x164e
cmpl $0x0, (%rsp)
jle 0x168b
xorl %ebx, %ebx
movq 0x8(%rsp), %rax
movq (%rax,%rbx,8), %rdi
testq %rdi, %rdi
je 0x167f
callq 0x10d0
incq %rbx
movslq (%rsp), %rax
cmpq %rax, %rbx
jl 0x166c
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x169a
callq 0x10d0
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x16ab
movq %rax, %rbx
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x16bd
callq 0x10d0
movq %rbx, %rdi
callq 0x1170