// File: RasmusFonseca[P]PDBCluster/main.cpp
// Function: medoidCosts_maxDistSum(std::vector<int, std::allocator<int>>&, Matrix&)
double medoidCosts_maxDistSum(vector<int> &medoids, Matrix &dMat){
	double maxDists[medoids.size()];
	for(unsigned int i=0;i<medoids.size(); i++) maxDists[i] = 0;

	for(unsigned int i=0;i<dMat.cols();i++){
		double min = 1000000000.0;
		int minMedoid = -1;

		for(unsigned int j=0;j<medoids.size();j++){
			int m = medoids[j];
			double d = dMat.get(m,i);
			if( d<min ) {
				min = d;
				minMedoid = j;
			}
		}
		if(min>maxDists[minMedoid]) maxDists[minMedoid] = min;
	}
	double ret = 0;
	for(unsigned int j=0;j<medoids.size();j++)
		ret+=maxDists[j];
	return ret/medoids.size();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
callq 0x5d90
movq %rax, %rcx
movq %rcx, %rax
movq %rsp, %rdx
movq %rdx, -0x18(%rbp)
leaq 0xf(,%rcx,8), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x60(%rbp)
movq %rcx, %rsp
movq %rax, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq %rax, -0x68(%rbp)
movq -0x8(%rbp), %rdi
callq 0x5d90
movq %rax, %rcx
movq -0x68(%rbp), %rax
cmpq %rcx, %rax
jae 0x39c3
movq -0x60(%rbp), %rax
movl -0x24(%rbp), %ecx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x398d
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x6c(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2720
movl %eax, %ecx
movl -0x6c(%rbp), %eax
cmpl %ecx, %eax
jae 0x3aa7
movsd 0x76ba(%rip), %xmm0     # 0xb0a8
movsd %xmm0, -0x30(%rbp)
movl $0xffffffff, -0x34(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
movq %rax, -0x78(%rbp)
movq -0x8(%rbp), %rdi
callq 0x5d90
movq %rax, %rcx
movq -0x78(%rbp), %rax
cmpq %rcx, %rax
jae 0x3a71
movq -0x8(%rbp), %rdi
movl -0x38(%rbp), %eax
movl %eax, %esi
callq 0x5db0
movl (%rax), %eax
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rdi
movl -0x3c(%rbp), %esi
movl -0x28(%rbp), %edx
callq 0x2730
movsd %xmm0, -0x48(%rbp)
movsd -0x48(%rbp), %xmm1
movsd -0x30(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x3a64
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0x34(%rbp)
jmp 0x3a66
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x3a01
movq -0x60(%rbp), %rax
movsd -0x30(%rbp), %xmm0
movslq -0x34(%rbp), %rcx
ucomisd (%rax,%rcx,8), %xmm0
jbe 0x3a97
movq -0x60(%rbp), %rax
movsd -0x30(%rbp), %xmm0
movslq -0x34(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
jmp 0x3a99
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x39ca
xorps %xmm0, %xmm0
movsd %xmm0, -0x50(%rbp)
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
movq %rax, -0x80(%rbp)
movq -0x8(%rbp), %rdi
callq 0x5d90
movq %rax, %rcx
movq -0x80(%rbp), %rax
cmpq %rcx, %rax
jae 0x3af3
movq -0x60(%rbp), %rax
movl -0x54(%rbp), %ecx
movsd (%rax,%rcx,8), %xmm0
addsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x3ab6
movsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x88(%rbp)
movq -0x8(%rbp), %rdi
callq 0x5d90
movsd -0x88(%rbp), %xmm0
movq %rax, %xmm1
movaps 0x75a3(%rip), %xmm2     # 0xb0c0
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x75a7(%rip), %xmm2     # 0xb0d0
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movq -0x18(%rbp), %rax
movq %rax, %rsp
movq %rbp, %rsp
popq %rbp
retq
nopl (%rax,%rax)