// File: /workspace/github_c_makefile_star2_O2/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 $0x98, %rsp
movq %rdi, %rbx
movslq %esi, %r14
leaq (,%r14,4), %r15
movq %r15, %rdi
callq 0x21d0
movq %rax, %r12
movq %r15, %rdi
callq 0x21d0
movq %r12, %rdi
xorl %r15d, %r15d
testl %r14d, %r14d
movl $0x0, %r12d
cmovgl %r14d, %r12d
cvtsi2sd %r14d, %xmm0
movsd %xmm0, 0x50(%rsp)
cvtsi2ss %r14d, %xmm0
movss %xmm0, 0x3c(%rsp)
leal -0x9(%r14), %edx
leal -0x1(%r14), %ecx
cvtsi2sd %ecx, %xmm0
movsd %xmm0, 0x48(%rsp)
movslq %edx, %rcx
movq %rcx, 0x58(%rsp)
xorpd %xmm3, %xmm3
pushq $-0x1
popq %rsi
xorpd %xmm4, %xmm4
xorl %r13d, %r13d
xorl %ebp, %ebp
movq %rdi, 0x18(%rsp)
movq %rax, 0x8(%rsp)
movq %r12, 0x10(%rsp)
cmpq %r12, %r13
je 0x4163a
movq %r14, %r12
subq %r13, %r12
xorpd %xmm5, %xmm5
xorl %edx, %edx
cmpq %r12, %rdx
jge 0x4145c
movq (%rbx,%rdx,8), %rcx
addq %r15, %rcx
movss (%rcx,%rdx,4), %xmm0
movaps %xmm0, %xmm1
mulss %xmm0, %xmm1
unpcklps %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
cvtps2pd %xmm1, %xmm0
addpd %xmm0, %xmm5
incq %rdx
jmp 0x41435
movapd %xmm5, %xmm6
unpckhpd %xmm5, %xmm6            # xmm6 = xmm6[1],xmm5[1]
testq %r13, %r13
je 0x414ac
testl %esi, %esi
jns 0x415db
cmpq 0x58(%rsp), %r13
jge 0x415db
movss (%rdi,%r13,4), %xmm1
subss -0x4(%rdi,%r13,4), %xmm1
movss -0x4(%rax,%r13,4), %xmm2
mulss 0x9b70(%rip), %xmm2     # 0x4b008
cvtsi2sd %r12d, %xmm7
ucomisd %xmm4, %xmm7
jb 0x4151d
sqrtsd %xmm7, %xmm0
jmp 0x4158c
divsd 0x50(%rsp), %xmm6
cvtsd2ss %xmm6, %xmm0
movss %xmm0, (%rdi)
movss 0x3c(%rsp), %xmm1
mulss %xmm0, %xmm1
mulss %xmm0, %xmm1
cvtss2sd %xmm1, %xmm0
subsd %xmm0, %xmm5
divsd 0x48(%rsp), %xmm5
ucomisd %xmm4, %xmm5
jb 0x414e2
sqrtsd %xmm5, %xmm0
jmp 0x4150b
movapd %xmm5, %xmm0
movl %esi, %r12d
movapd %xmm3, 0x20(%rsp)
callq 0x2290
xorpd %xmm4, %xmm4
movapd 0x20(%rsp), %xmm3
movl %r12d, %esi
movq 0x8(%rsp), %rax
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %r12
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%rax)
jmp 0x4162e
movapd %xmm7, %xmm0
movl %ebp, 0x38(%rsp)
movl %esi, %ebp
movapd %xmm3, 0x20(%rsp)
movapd %xmm5, 0x80(%rsp)
movapd %xmm6, 0x70(%rsp)
movsd %xmm7, 0x40(%rsp)
movaps %xmm1, 0x60(%rsp)
movss %xmm2, 0x34(%rsp)
callq 0x2290
movss 0x34(%rsp), %xmm2
movaps 0x60(%rsp), %xmm1
movsd 0x40(%rsp), %xmm7
movapd 0x70(%rsp), %xmm6
movapd 0x80(%rsp), %xmm5
xorpd %xmm4, %xmm4
movapd 0x20(%rsp), %xmm3
movl %ebp, %esi
movl 0x38(%rsp), %ebp
movq 0x8(%rsp), %rax
movq 0x18(%rsp), %rdi
andps 0xfc9d(%rip), %xmm1     # 0x51230
cvtss2sd %xmm1, %xmm1
cvtss2sd %xmm2, %xmm2
divsd %xmm0, %xmm2
ucomisd %xmm2, %xmm1
jbe 0x415db
movapd %xmm6, %xmm0
divsd %xmm7, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%rdi,%r13,4)
mulsd %xmm6, %xmm6
divsd %xmm7, %xmm6
decl %r12d
cvtsi2sd %r12d, %xmm0
subsd %xmm6, %xmm5
divsd %xmm0, %xmm5
ucomisd %xmm4, %xmm5
jb 0x415f2
sqrtsd %xmm5, %xmm0
jmp 0x4161f
testl %esi, %esi
cmovsl %r13d, %esi
addpd %xmm5, %xmm3
addl %ebp, %r12d
movl %r12d, %ebp
movq 0x10(%rsp), %r12
jmp 0x4162e
movapd %xmm5, %xmm0
movl %ebp, %r12d
movl %esi, %ebp
movapd %xmm3, 0x20(%rsp)
callq 0x2290
xorpd %xmm4, %xmm4
movapd 0x20(%rsp), %xmm3
movl %ebp, %esi
movl %r12d, %ebp
movq 0x8(%rsp), %rax
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %r12
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%rax,%r13,4)
incq %r13
addq $0x4, %r15
jmp 0x41420
cvtsi2sd %ebp, %xmm0
movapd %xmm3, %xmm1
unpckhpd %xmm3, %xmm1            # xmm1 = xmm1[1],xmm3[1]
divsd %xmm0, %xmm1
mulsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
subsd %xmm0, %xmm3
decl %ebp
cvtsi2sd %ebp, %xmm0
divsd %xmm0, %xmm3
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm3
jb 0x41670
sqrtsd %xmm3, %xmm0
jmp 0x41693
movapd %xmm3, %xmm0
movl %esi, %ebp
movapd %xmm1, 0x20(%rsp)
callq 0x2290
movapd 0x20(%rsp), %xmm1
movl %ebp, %esi
movq 0x8(%rsp), %rax
movq 0x18(%rsp), %rdi
cvtsd2ss %xmm1, %xmm1
cvtsd2ss %xmm0, %xmm0
movslq %esi, %rcx
cmpq %r14, %rcx
jge 0x416b2
movss %xmm1, (%rdi,%rcx,4)
movss %xmm0, (%rax,%rcx,4)
incq %rcx
jmp 0x4169e
pushq $0x1
popq %r11
xorl %ecx, %ecx
movaps 0xf1a1(%rip), %xmm0     # 0x50860
movss 0x9949(%rip), %xmm1     # 0x4b010
movq %rax, %rdx
movq %rdi, %rsi
cmpq %r12, %rcx
je 0x4172b
movslq %r11d, %r10
movq (%rbx,%rcx,8), %r8
cmpq %r14, %r10
jge 0x4171b
movss (%r8,%r10,4), %xmm2
movaps %xmm2, %xmm4
subss (%rsi,%r10,4), %xmm4
divss (%rdx,%r10,4), %xmm4
movaps %xmm4, %xmm3
xorps %xmm0, %xmm3
maxss %xmm4, %xmm3
ucomiss %xmm1, %xmm3
jbe 0x41716
mulss %xmm3, %xmm2
movss %xmm2, (%r8,%r10,4)
movq (%rbx,%r10,8), %r9
movss %xmm2, (%r9,%rcx,4)
incq %r10
jmp 0x416d9
incq %rcx
incl %r11d
addq $-0x4, %rsi
addq $-0x4, %rdx
jmp 0x416cd
callq 0x2050
movq 0x8(%rsp), %rdi
callq 0x2050
xorl %eax, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq