// File: CominLab[P]QCluster/freqs.cc
// Function: normalize_freq_matrix(double**, double**, int, int)
void normalize_freq_matrix(double** freq, double** qual, int N, int row_length)
{
	double tmp, sum_freq, sum_freq_square, V_freq;
	double sum_qual, sum_qual_square, V_qual;
	for(int l=0; l<row_length; ++l){
		sum_freq_square=0;
		sum_freq=0;
		sum_qual_square = 0;
		sum_qual = 0;
		for(int n=0; n<N; ++n){
			tmp = *(*(freq+n)+l);
			sum_freq_square += tmp*tmp;
			sum_freq += tmp;
			tmp = *(*(qual+n)+l);
			sum_qual_square += tmp*tmp;
			sum_qual += tmp;
		}
		//Variance:
		V_freq = sqrt( sum_freq_square/N - (sum_freq*sum_freq)/(N*N) );  
		V_qual = sqrt( sum_qual_square/N - (sum_qual*sum_qual)/(N*N) ); 
		if (V_freq>0 && V_qual>0){
			for(int n=0; n<N; ++n){
				*(*(freq+n)+l) /= V_freq;
				*(*(qual+n)+l) /= V_qual;				
			}
		}
	}
	return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x90bc
xorps %xmm0, %xmm0
movsd %xmm0, -0x30(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x28(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x48(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x40(%rbp)
movl $0x0, -0x58(%rbp)
movl -0x58(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x8fc4
movq -0x8(%rbp), %rax
movslq -0x58(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x54(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x20(%rbp)
movsd -0x20(%rbp), %xmm0
movsd -0x20(%rbp), %xmm2
movsd -0x30(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x20(%rbp), %xmm0
addsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
movq -0x10(%rbp), %rax
movslq -0x58(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x54(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x20(%rbp)
movsd -0x20(%rbp), %xmm0
movsd -0x20(%rbp), %xmm2
movsd -0x48(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x20(%rbp), %xmm0
addsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x8f20
movsd -0x30(%rbp), %xmm0
cvtsi2sdl -0x14(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd -0x28(%rbp), %xmm1
mulsd -0x28(%rbp), %xmm1
movl -0x14(%rbp), %eax
imull -0x14(%rbp), %eax
cvtsi2sd %eax, %xmm2
divsd %xmm2, %xmm1
subsd %xmm1, %xmm0
callq 0x31d0
movsd %xmm0, -0x38(%rbp)
movsd -0x48(%rbp), %xmm0
cvtsi2sdl -0x14(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd -0x40(%rbp), %xmm1
mulsd -0x40(%rbp), %xmm1
movl -0x14(%rbp), %eax
imull -0x14(%rbp), %eax
cvtsi2sd %eax, %xmm2
divsd %xmm2, %xmm1
subsd %xmm1, %xmm0
callq 0x31d0
movsd %xmm0, -0x50(%rbp)
movsd -0x38(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x90ac
movsd -0x50(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x90ac
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x90aa
movsd -0x38(%rbp), %xmm1
movq -0x8(%rbp), %rax
movslq -0x5c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x54(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movsd -0x50(%rbp), %xmm1
movq -0x10(%rbp), %rax
movslq -0x5c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x54(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x9051
jmp 0x90ac
jmp 0x90ae
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x8eed
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)