// File: /workspace/github_c_makefile_star2_O1/ugobas[P]tnm/allostery.c
// Function: Get_zeta
int Get_zeta(float **Coupling, int N)
{
  // Mean and standard deviation depending on l=|i-j|
  // Compute z=(c_{i,i+l}-<c>_l)/sigma_l
  // If |z| > 1, amplify c -> c*z
  int i, j, l, ll=-1, num_l=0;;
  float *c1=malloc(N*sizeof(float));
  float *c2=malloc(N*sizeof(float));
  double sum1_l=0, sum2_l=0;
  for(l=0; l<N; l++){
    double sum1=0, sum2=0; int num=N-l;
    for(i=0; i<(N-l); i++){
      float c=Coupling[i][i+l];
      sum1+=c; sum2+=c*c;
    }
    if(l==0){
      c1[l]=sum1/num;
      c2[l]=sqrt((sum2-num*c1[l]*c1[l])/(num-1));
    }else if((ll<0) && (l<N-9) && (fabs(c1[l]-c1[l-1]) > 3*c2[l-1]/sqrt(num))){
      c1[l]=sum1/num;
      c2[l]=sqrt((sum2-sum1*sum1/num)/(num-1));
    }else{
      if(ll<0){ll=l;} sum1_l+=sum1; sum2_l+=sum2; num_l+=num;
    }
  }
  sum1_l/=num_l;
  sum2_l=sqrt((sum2_l-num_l*sum1_l*sum1_l)/(num_l-1));
  for(l=ll; l<N; l++){
    c1[l]=sum1_l;
    c2[l]=sum2_l;
  }

  for(i=0; i<N; i++){
    float *c=Coupling[i];
    for(j=i+1; j<N; j++){
      float z=(c[j]-c1[j-i])/c2[j-i];
      if(z<0)z=-z;
      if(z>1){c[j]*=z; Coupling[j][i]=c[j];}
    }
  }
  free(c1); free(c2);
  return(0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movl %esi, %r13d
movq %rdi, %rbx
movslq %esi, %r12
leaq (,%r12,4), %r15
movq %r15, %rdi
callq 0x21d0
movq %rax, %r14
movq %r15, %rdi
callq 0x21d0
movq %rax, %r15
movl %r13d, %r11d
movq %r12, 0x28(%rsp)
testl %r12d, %r12d
movq %r11, 0x18(%rsp)
movq %r13, 0x30(%rsp)
jle 0x47020
leal -0x9(%r13), %eax
cltq
movq %rax, 0x68(%rsp)
cvtsi2sd %r13d, %xmm0
movsd %xmm0, 0x60(%rsp)
xorps %xmm0, %xmm0
cvtsi2ss %r13d, %xmm0
movss %xmm0, 0x24(%rsp)
leal -0x1(%r13), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x58(%rsp)
xorl %ebp, %ebp
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorpd %xmm5, %xmm5
xorl %r12d, %r12d
xorpd %xmm4, %xmm4
xorpd %xmm3, %xmm3
xorl %edx, %edx
movl %r13d, %r13d
movq %r11, %rdi
xorpd %xmm7, %xmm7
xorpd %xmm6, %xmm6
subq %r12, %rdi
jle 0x46e08
xorl %eax, %eax
movq (%rbx,%rax,8), %rcx
addq %rbp, %rcx
movss (%rcx,%rax,4), %xmm0
xorps %xmm1, %xmm1
cvtss2sd %xmm0, %xmm1
addsd %xmm1, %xmm7
mulss %xmm0, %xmm0
cvtss2sd %xmm0, %xmm0
addsd %xmm0, %xmm6
incq %rax
cmpq %rax, %r13
jne 0x46ddd
testq %r12, %r12
je 0x46e5d
testl %esi, %esi
jns 0x46fb7
cmpq 0x68(%rsp), %r12
jge 0x46fb7
movss (%r14,%r12,4), %xmm1
subss -0x4(%r14,%r12,4), %xmm1
movss -0x4(%r15,%r12,4), %xmm2
mulss 0xa1cc(%rip), %xmm2     # 0x51008
xorps %xmm8, %xmm8
cvtsi2sd %edi, %xmm8
ucomisd %xmm5, %xmm8
jb 0x46ee3
xorps %xmm0, %xmm0
sqrtsd %xmm8, %xmm0
jmp 0x46f62
divsd 0x60(%rsp), %xmm7
xorps %xmm0, %xmm0
cvtsd2ss %xmm7, %xmm0
movss %xmm0, (%r14)
movss 0x24(%rsp), %xmm1
mulss %xmm0, %xmm1
mulss %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtss2sd %xmm1, %xmm0
subsd %xmm0, %xmm6
divsd 0x58(%rsp), %xmm6
ucomisd %xmm5, %xmm6
jb 0x46e9d
xorps %xmm0, %xmm0
sqrtsd %xmm6, %xmm0
jmp 0x46ed5
movapd %xmm6, %xmm0
movl %esi, 0x4(%rsp)
movsd %xmm3, 0x8(%rsp)
movsd %xmm4, 0x10(%rsp)
movl %edx, (%rsp)
callq 0x2290
xorpd %xmm5, %xmm5
movl (%rsp), %edx
movsd 0x10(%rsp), %xmm4
movsd 0x8(%rsp), %xmm3
movl 0x4(%rsp), %esi
movq 0x18(%rsp), %r11
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%r15)
jmp 0x4700b
movapd %xmm8, %xmm0
movl %esi, 0x4(%rsp)
movsd %xmm3, 0x8(%rsp)
movsd %xmm4, 0x10(%rsp)
movl %edx, (%rsp)
movsd %xmm6, 0x50(%rsp)
movq %rdi, 0x48(%rsp)
movsd %xmm7, 0x40(%rsp)
movsd %xmm8, 0x38(%rsp)
movaps %xmm1, 0x70(%rsp)
movss %xmm2, 0x20(%rsp)
callq 0x2290
movss 0x20(%rsp), %xmm2
movaps 0x70(%rsp), %xmm1
movsd 0x38(%rsp), %xmm8
movsd 0x40(%rsp), %xmm7
movq 0x48(%rsp), %rdi
movsd 0x50(%rsp), %xmm6
xorpd %xmm5, %xmm5
movl (%rsp), %edx
movsd 0x10(%rsp), %xmm4
movsd 0x8(%rsp), %xmm3
movl 0x4(%rsp), %esi
movq 0x18(%rsp), %r11
andps 0x103b7(%rip), %xmm1    # 0x57320
cvtss2sd %xmm1, %xmm1
cvtss2sd %xmm2, %xmm2
divsd %xmm0, %xmm2
ucomisd %xmm2, %xmm1
jbe 0x46fb7
movapd %xmm7, %xmm0
divsd %xmm8, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%r14,%r12,4)
mulsd %xmm7, %xmm7
divsd %xmm8, %xmm7
decl %edi
xorps %xmm0, %xmm0
cvtsi2sd %edi, %xmm0
subsd %xmm7, %xmm6
divsd %xmm0, %xmm6
ucomisd %xmm5, %xmm6
jb 0x46fc9
xorps %xmm0, %xmm0
sqrtsd %xmm6, %xmm0
jmp 0x47001
testl %esi, %esi
cmovsl %r12d, %esi
addsd %xmm7, %xmm3
addsd %xmm6, %xmm4
addl %edi, %edx
jmp 0x4700b
movapd %xmm6, %xmm0
movl %esi, 0x4(%rsp)
movsd %xmm3, 0x8(%rsp)
movsd %xmm4, 0x10(%rsp)
movl %edx, (%rsp)
callq 0x2290
xorpd %xmm5, %xmm5
movl (%rsp), %edx
movsd 0x10(%rsp), %xmm4
movsd 0x8(%rsp), %xmm3
movl 0x4(%rsp), %esi
movq 0x18(%rsp), %r11
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%r15,%r12,4)
incq %r12
decl %r13d
addq $0x4, %rbp
cmpq %r11, %r12
jne 0x46dc8
jmp 0x4702f
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %edx, %edx
xorpd %xmm3, %xmm3
xorpd %xmm4, %xmm4
xorps %xmm0, %xmm0
cvtsi2sd %edx, %xmm0
divsd %xmm0, %xmm3
mulsd %xmm3, %xmm0
mulsd %xmm3, %xmm0
decl %edx
xorps %xmm1, %xmm1
cvtsi2sd %edx, %xmm1
subsd %xmm0, %xmm4
divsd %xmm1, %xmm4
ucomisd 0xa005(%rip), %xmm4     # 0x51060
jb 0x47066
xorps %xmm0, %xmm0
sqrtsd %xmm4, %xmm0
jmp 0x47084
movapd %xmm4, %xmm0
movl %esi, %ebp
movsd %xmm3, 0x8(%rsp)
callq 0x2290
movsd 0x8(%rsp), %xmm3
movl %ebp, %esi
movq 0x18(%rsp), %r11
movq 0x30(%rsp), %rcx
movq 0x28(%rsp), %rdx
cmpl %ecx, %esi
jge 0x470b4
xorps %xmm1, %xmm1
cvtsd2ss %xmm3, %xmm1
cvtsd2ss %xmm0, %xmm0
movslq %esi, %rax
movss %xmm1, (%r14,%rax,4)
movss %xmm0, (%r15,%rax,4)
incq %rax
cmpq %rax, %rdx
jne 0x470a0
testl %ecx, %ecx
jle 0x4713d
xorl %eax, %eax
movaps 0xf86b(%rip), %xmm0     # 0x56930
movss 0x9f43(%rip), %xmm1     # 0x51010
movq %r11, %rcx
movq %rbx, %rdx
xorl %esi, %esi
movq %rsi, %rdi
incq %rsi
cmpq %r11, %rsi
jae 0x4712d
movq (%rbx,%rdi,8), %r8
addq %rax, %r8
movl $0x1, %r9d
movss (%r8,%r9,4), %xmm2
movaps %xmm2, %xmm4
subss (%r14,%r9,4), %xmm4
divss (%r15,%r9,4), %xmm4
movaps %xmm4, %xmm3
xorps %xmm0, %xmm3
maxss %xmm4, %xmm3
ucomiss %xmm1, %xmm3
jbe 0x47125
mulss %xmm3, %xmm2
movss %xmm2, (%r8,%r9,4)
movq (%rdx,%r9,8), %r10
movss %xmm2, (%r10,%rdi,4)
incq %r9
cmpq %r9, %rcx
jne 0x470ed
addq $0x8, %rdx
addq $0x4, %rax
decq %rcx
cmpq %r11, %rsi
jne 0x470d5
movq %r14, %rdi
callq 0x2050
movq %r15, %rdi
callq 0x2050
xorl %eax, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq