// File: CK7[P]abawaca/src/ClusterQuality.cpp
// Function: standard_deviation(std::vector<std::pair<unsigned long, double>, std::allocator<std::pair<unsigned long, double>>>, double&, double&)
void standard_deviation(vector<pair<size_t, double> > data, double& mean, double& stdev)
{
	if(data.size() == 0) {
		mean = stdev = -1;
		return;
	}

	size_t	total_size = 0;
	mean=0;
	stdev=0;

	for(auto it=data.begin(); it!=data.end(); it++) {
		mean += it->first*it->second;
		total_size += it->first;
	}
	mean /= total_size;

	for(auto it=data.begin(); it!=data.end(); it++)
		stdev += it->first*(it->second-mean)*(it->second-mean);

	stdev = sqrt(stdev/(total_size-1));
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x58(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
callq 0x33240
cmpq $0x0, %rax
jne 0x32258
movq -0x18(%rbp), %rax
movsd 0x2df1(%rip), %xmm0     # 0x35030
movsd %xmm0, (%rax)
movq -0x10(%rbp), %rax
movsd 0x2de1(%rip), %xmm0     # 0x35030
movsd %xmm0, (%rax)
jmp 0x32472
movq -0x58(%rbp), %rdi
movq $0x0, -0x20(%rbp)
movq -0x10(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
movq -0x18(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
callq 0x33260
movq %rax, -0x28(%rbp)
movq -0x58(%rbp), %rdi
callq 0x332d0
movq %rax, -0x30(%rbp)
leaq -0x28(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x33290
testb $0x1, %al
jne 0x322a6
jmp 0x32329
leaq -0x28(%rbp), %rdi
callq 0x33300
movq (%rax), %xmm0
movaps 0x3ec6(%rip), %xmm1     # 0x36180
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x3eca(%rip), %xmm1     # 0x36190
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd %xmm0, -0x60(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x33300
movsd -0x60(%rbp), %xmm0
movsd 0x8(%rax), %xmm2
movq -0x10(%rbp), %rax
movsd (%rax), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rax)
leaq -0x28(%rbp), %rdi
callq 0x33300
movq (%rax), %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
leaq -0x28(%rbp), %rdi
xorl %esi, %esi
callq 0x33320
movq %rax, -0x38(%rbp)
jmp 0x32283
movq -0x58(%rbp), %rdi
movaps 0x3e4c(%rip), %xmm0     # 0x36180
movq -0x20(%rbp), %xmm1
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movapd 0x3e4b(%rip), %xmm0     # 0x36190
subpd %xmm0, %xmm1
movaps %xmm1, %xmm0
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm0, %xmm1
movq -0x10(%rbp), %rax
movsd (%rax), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, (%rax)
callq 0x33260
movq %rax, -0x40(%rbp)
movq -0x58(%rbp), %rdi
callq 0x332d0
movq %rax, -0x48(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x33290
testb $0x1, %al
jne 0x32390
jmp 0x3242b
leaq -0x40(%rbp), %rdi
callq 0x33300
movq (%rax), %xmm0
movaps 0x3ddc(%rip), %xmm1     # 0x36180
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x3de0(%rip), %xmm1     # 0x36190
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd %xmm0, -0x70(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x33300
movsd -0x70(%rbp), %xmm0
movsd 0x8(%rax), %xmm1
movq -0x10(%rbp), %rax
subsd (%rax), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0x68(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x33300
movsd -0x68(%rbp), %xmm0
movsd 0x8(%rax), %xmm2
movq -0x10(%rbp), %rax
subsd (%rax), %xmm2
movq -0x18(%rbp), %rax
movsd (%rax), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rax)
leaq -0x40(%rbp), %rdi
xorl %esi, %esi
callq 0x33320
movq %rax, -0x50(%rbp)
jmp 0x3236d
movq -0x18(%rbp), %rax
movsd (%rax), %xmm0
movq -0x20(%rbp), %rax
decq %rax
movq %rax, %xmm1
movaps 0x3d3a(%rip), %xmm2     # 0x36180
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x3d3e(%rip), %xmm2     # 0x36190
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
callq 0x5310
movq -0x18(%rbp), %rax
movsd %xmm0, (%rax)
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)