// File: /workspace/github_c_makefile_star2_O3/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
movl %esi, %r13d
movq %rdi, %rbx
movslq %esi, %r12
leaq (,%r12,4), %r15
movq %r15, %rdi
callq 0x21e0
movq %rax, %r14
movq %r15, %rdi
callq 0x21e0
movq %r12, %r11
movq %rax, %r15
movl %r13d, %eax
movq %rax, 0x20(%rsp)
testl %r11d, %r11d
movq %r12, 0x8(%rsp)
movq %r13, 0x40(%rsp)
jle 0x47119
leal -0x9(%r13), %eax
cvtsi2sd %r13d, %xmm0
movsd %xmm0, 0x60(%rsp)
cltq
movq %rax, 0x68(%rsp)
xorps %xmm0, %xmm0
cvtsi2ss %r13d, %xmm0
movss %xmm0, 0x2c(%rsp)
leal -0x1(%r13), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x58(%rsp)
xorpd %xmm3, %xmm3
xorl %ebp, %ebp
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
xorpd %xmm4, %xmm4
movq %r13, %r12
xorl %r13d, %r13d
xorl %esi, %esi
movl %r12d, %r12d
movq %r11, %rdi
xorpd %xmm5, %xmm5
subq %r13, %rdi
jle 0x46f21
xorl %eax, %eax
movq (%rbx,%rax,8), %rcx
addq %rbp, %rcx
movss (%rcx,%rax,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 %rax
cmpq %rax, %r12
jne 0x46efc
testq %r13, %r13
je 0x46f72
testl %edx, %edx
jns 0x470ba
cmpq 0x68(%rsp), %r13
jge 0x470ba
movss (%r14,%r13,4), %xmm1
subss -0x4(%r14,%r13,4), %xmm1
movss -0x4(%r15,%r13,4), %xmm2
mulss 0xa1bf(%rip), %xmm2     # 0x51114
xorps %xmm6, %xmm6
cvtsi2sd %edi, %xmm6
ucomisd %xmm4, %xmm6
jb 0x46ff3
xorps %xmm0, %xmm0
sqrtsd %xmm6, %xmm0
jmp 0x4705f
movapd %xmm5, %xmm0
unpckhpd %xmm5, %xmm0            # xmm0 = xmm0[1],xmm5[1]
divsd 0x60(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%r14)
movss 0x2c(%rsp), %xmm1
mulss %xmm0, %xmm1
mulss %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtss2sd %xmm1, %xmm0
subsd %xmm0, %xmm5
divsd 0x58(%rsp), %xmm5
ucomisd %xmm4, %xmm5
jb 0x46fb7
xorps %xmm0, %xmm0
sqrtsd %xmm5, %xmm0
jmp 0x46fe5
movapd %xmm5, %xmm0
movl %edx, 0x10(%rsp)
movapd %xmm3, 0x30(%rsp)
movl %esi, 0x4(%rsp)
callq 0x22a0
xorpd %xmm4, %xmm4
movl 0x4(%rsp), %esi
movapd 0x30(%rsp), %xmm3
movl 0x10(%rsp), %edx
movq 0x8(%rsp), %r11
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%r15)
jmp 0x47102
movapd %xmm6, %xmm0
movl %edx, 0x10(%rsp)
movapd %xmm3, 0x30(%rsp)
movl %esi, 0x4(%rsp)
movapd %xmm5, 0x80(%rsp)
movq %rdi, 0x50(%rsp)
movsd %xmm6, 0x48(%rsp)
movaps %xmm1, 0x70(%rsp)
movss %xmm2, 0x28(%rsp)
callq 0x22a0
movss 0x28(%rsp), %xmm2
movaps 0x70(%rsp), %xmm1
movsd 0x48(%rsp), %xmm6
movq 0x50(%rsp), %rdi
movapd 0x80(%rsp), %xmm5
xorpd %xmm4, %xmm4
movl 0x4(%rsp), %esi
movapd 0x30(%rsp), %xmm3
movl 0x10(%rsp), %edx
movq 0x8(%rsp), %r11
andps 0x1027a(%rip), %xmm1    # 0x572e0
cvtss2sd %xmm1, %xmm1
cvtss2sd %xmm2, %xmm2
divsd %xmm0, %xmm2
ucomisd %xmm2, %xmm1
jbe 0x470ba
movapd %xmm5, %xmm0
unpckhpd %xmm5, %xmm0            # xmm0 = xmm0[1],xmm5[1]
movapd %xmm0, %xmm1
divsd %xmm6, %xmm1
cvtsd2ss %xmm1, %xmm1
movss %xmm1, (%r14,%r13,4)
mulsd %xmm0, %xmm0
divsd %xmm6, %xmm0
decl %edi
xorps %xmm1, %xmm1
cvtsi2sd %edi, %xmm1
subsd %xmm0, %xmm5
divsd %xmm1, %xmm5
ucomisd %xmm4, %xmm5
jb 0x470ca
xorps %xmm0, %xmm0
sqrtsd %xmm5, %xmm0
jmp 0x470f8
testl %edx, %edx
cmovsl %r13d, %edx
addpd %xmm5, %xmm3
addl %esi, %edi
movl %edi, %esi
jmp 0x47102
movapd %xmm5, %xmm0
movl %edx, 0x10(%rsp)
movapd %xmm3, 0x30(%rsp)
movl %esi, 0x4(%rsp)
callq 0x22a0
xorpd %xmm4, %xmm4
movl 0x4(%rsp), %esi
movapd 0x30(%rsp), %xmm3
movl 0x10(%rsp), %edx
movq 0x8(%rsp), %r11
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%r15,%r13,4)
incq %r13
decl %r12d
addq $0x4, %rbp
cmpq 0x20(%rsp), %r13
jne 0x46eeb
jmp 0x47124
xorpd %xmm3, %xmm3
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
xorl %esi, %esi
xorps %xmm0, %xmm0
cvtsi2sd %esi, %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 %esi
xorps %xmm0, %xmm0
cvtsi2sd %esi, %xmm0
divsd %xmm0, %xmm3
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm3
jb 0x47163
xorps %xmm0, %xmm0
sqrtsd %xmm3, %xmm0
jmp 0x47181
movapd %xmm3, %xmm0
movl %edx, %ebp
movapd %xmm1, 0x10(%rsp)
callq 0x22a0
movapd 0x10(%rsp), %xmm1
movl %ebp, %edx
movq 0x8(%rsp), %r11
movq 0x40(%rsp), %rcx
cmpl %ecx, %edx
jge 0x471a9
cvtsd2ss %xmm1, %xmm1
cvtsd2ss %xmm0, %xmm0
movslq %edx, %rax
movss %xmm1, (%r14,%rax,4)
movss %xmm0, (%r15,%rax,4)
incq %rax
cmpq %rax, %r11
jne 0x47195
testl %ecx, %ecx
jle 0x47236
xorl %eax, %eax
movaps 0x9e76(%rip), %xmm0     # 0x51030
movss 0x9f5a(%rip), %xmm1     # 0x5111c
movq 0x20(%rsp), %rcx
movq %rbx, %rdx
xorl %esi, %esi
movq %rsi, %rdi
incq %rsi
cmpq %r11, %rsi
jge 0x47224
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 0x4721c
mulss %xmm3, %xmm2
movss %xmm2, (%r8,%r9,4)
movq (%rdx,%r9,8), %r10
movss %xmm2, (%r10,%rdi,4)
incq %r9
cmpq %r9, %rcx
jne 0x471e4
addq $0x8, %rdx
addq $0x4, %rax
decq %rcx
cmpq 0x20(%rsp), %rsi
jne 0x471cc
movq %r14, %rdi
callq 0x2050
movq %r15, %rdi
callq 0x2050
xorl %eax, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq