// File: /workspace/github_c_makefile_star2_O3/ugobas[P]tnm/allostery.c
// Function: Print_links
int Print_links(float **Coupling, int N, char *nameout1, char *ext, int sign)
{
  char nameout[200]; int i, j;
  sprintf(nameout, "%s%s", nameout1, ext);
  FILE *file_out=fopen(nameout, "w");
  printf("Writing %s\n", nameout);

  // Mean and standard deviation
  double sum1=0, sum2=0; int norm=0;
  float max=0, min=1000;
  for(i=0; i<N; i++){
    float *c=Coupling[i]+i+2;
    for(j=i+2; j<N; j++){
      sum1+=*c; sum2+=(*c)*(*c); norm++;
      if(*c>max){max=*c;}
      if(*c<min){min=*c;} c++;
    }
  }
  sum1/=norm; sum2=sqrt((sum2-norm*sum1*sum1)/(norm-1));
  if(sum1==0 || sum2==0 || isnan(sum1)|| isnan(sum2)){
    printf("ERROR in Print_links, coupling= %s\n", ext);
    for(i=0; i<N; i++){
      float *c=Coupling[i];
      for(j=i+1; j<N; j++){printf("%.3g ",c[j]);} printf("\n");
    }
    printf("ERROR in Print_links, coupling= %s\n", ext);
    printf("Mean= %.3g s.d.= %.3g\n", sum1, sum2); exit(8);
  }

  double thrmax=sum1+SIGMA*sum2, thrmin=sum1-SIGMA*sum2;
  if(thrmax>=max){thrmax=(max+sum1)/2;}
  if(thrmin<=min){thrmin=(min+sum1)/2;}
  fprintf(file_out, "# mean= %.3g s.d.= %.3g thr=%.2g %.2g SIGMA= %.3g\n",
	  sum1, sum2, thrmin, thrmax, SIGMA);
  fprintf(file_out, "#Residue names written in %s.names.dat\n", nameout1);
  fprintf(file_out, "#resi resj coupling\n");
  for(i=0; i<N; i++){
    float *c=Coupling[i];
    for(j=i+1; j<N; j++){
      if((sign==0)||
	 ((sign>0)&&(c[j]>=thrmax))||
	 ((sign<0)&&(c[j]<=thrmin))){
	fprintf(file_out, "%d %d %.3g\n", i, j, c[j]);
      }
    }
  }
  fclose(file_out);
  return(0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movl %r8d, 0x18(%rsp)
movq %rcx, %r14
movq %rdx, %rbp
movl %esi, %r15d
movq %rdi, 0x8(%rsp)
leaq 0x1164e(%rip), %rsi     # 0x55d6c
xorl %r13d, %r13d
leaq 0x40(%rsp), %r12
movq %r12, %rdi
xorl %eax, %eax
callq 0x2270
leaq 0x12ac9(%rip), %rsi     # 0x57200
movq %r12, %rdi
callq 0x2220
movq %rax, (%rsp)
leaq 0xd605(%rip), %rdi      # 0x51d4f
movq %r12, %rsi
xorl %eax, %eax
callq 0x20f0
xorpd %xmm1, %xmm1
movl %r15d, %ebx
testl %r15d, %r15d
jle 0x447f3
leal -0x2(%r15), %eax
xorpd %xmm0, %xmm0
xorl %ecx, %ecx
xorps %xmm3, %xmm3
movss 0x12b27(%rip), %xmm2    # 0x572a0
movq %rbx, %rdx
xorl %esi, %esi
xorl %r13d, %r13d
leaq 0x2(%rsi), %rdi
cmpq %rbx, %rdi
jae 0x447d2
addl %eax, %r13d
movq 0x8(%rsp), %rdi
movq (%rdi,%rsi,8), %rdi
addq %rcx, %rdi
movl $0x2, %r8d
movaps %xmm3, %xmm4
movaps %xmm2, %xmm5
movss (%rdi,%r8,4), %xmm2
movaps %xmm2, %xmm3
mulss %xmm2, %xmm3
movaps %xmm2, %xmm6
unpcklps %xmm3, %xmm6            # xmm6 = xmm6[0],xmm3[0],xmm6[1],xmm3[1]
cvtps2pd %xmm6, %xmm3
addpd %xmm3, %xmm0
movaps %xmm2, %xmm3
maxss %xmm4, %xmm3
minss %xmm5, %xmm2
incq %r8
cmpl %r8d, %edx
jne 0x4479f
incq %rsi
decl %eax
addq $0x4, %rcx
decq %rdx
cmpq %rbx, %rsi
jne 0x44781
cvtss2sd %xmm3, %xmm3
movaps %xmm3, 0x20(%rsp)
cvtss2sd %xmm2, %xmm8
jmp 0x44808
xorpd %xmm0, %xmm0
movsd 0x16560(%rip), %xmm8    # 0x5ad60
xorps %xmm2, %xmm2
movaps %xmm2, 0x20(%rsp)
xorps %xmm2, %xmm2
cvtsi2sd %r13d, %xmm2
movapd %xmm0, %xmm6
divsd %xmm2, %xmm6
mulsd %xmm6, %xmm2
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
mulsd %xmm6, %xmm2
decl %r13d
xorps %xmm3, %xmm3
cvtsi2sd %r13d, %xmm3
subsd %xmm2, %xmm0
divsd %xmm3, %xmm0
ucomisd %xmm1, %xmm0
jb 0x44846
xorps %xmm1, %xmm1
sqrtsd %xmm0, %xmm1
jmp 0x44869
movapd %xmm6, 0x30(%rsp)
movsd %xmm8, 0x10(%rsp)
callq 0x22a0
movsd 0x10(%rsp), %xmm8
movapd 0x30(%rsp), %xmm6
movapd %xmm0, %xmm1
ucomisd %xmm6, %xmm6
jp 0x449fb
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm6
jne 0x44883
jnp 0x449fb
ucomisd %xmm0, %xmm1
jne 0x4488f
jnp 0x449fb
ucomisd %xmm1, %xmm1
jp 0x449fb
leaq 0x229a0(%rip), %rax     # 0x67240
xorps %xmm4, %xmm4
cvtss2sd (%rax), %xmm4
movaps %xmm4, %xmm0
mulsd %xmm1, %xmm0
movapd %xmm6, %xmm7
subsd %xmm0, %xmm7
addsd %xmm6, %xmm0
movapd %xmm6, %xmm2
movapd 0x20(%rsp), %xmm3
addsd %xmm3, %xmm2
movsd 0xc8a0(%rip), %xmm5     # 0x51170
mulsd %xmm5, %xmm2
cmpnlesd %xmm0, %xmm3
andpd %xmm3, %xmm0
andnpd %xmm2, %xmm3
orpd %xmm0, %xmm3
movapd %xmm6, %xmm0
addsd %xmm8, %xmm0
mulsd %xmm5, %xmm0
movapd %xmm7, %xmm2
cmpnlesd %xmm8, %xmm2
andpd %xmm2, %xmm7
andnpd %xmm0, %xmm2
orpd %xmm7, %xmm2
leaq 0x18a19(%rip), %rsi     # 0x5d328
movq (%rsp), %r12
movq %r12, %rdi
movapd %xmm6, %xmm0
movapd %xmm2, 0x30(%rsp)
movapd %xmm3, 0x20(%rsp)
movb $0x5, %al
callq 0x21a0
leaq 0x18a27(%rip), %rsi     # 0x5d35b
movq %r12, %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x21a0
leaq 0x18a3b(%rip), %rdi     # 0x5d383
movl $0x1, %r14d
movl $0x14, %esi
movl $0x1, %edx
movq %r12, %rcx
callq 0x2290
testl %r15d, %r15d
jle 0x449de
xorl %r12d, %r12d
leaq 0x18a29(%rip), %r15     # 0x5d398
leaq 0x1(%r12), %rax
movq %rax, 0x10(%rsp)
cmpq %rbx, %rax
jae 0x449d1
movq 0x8(%rsp), %rax
movq (%rax,%r12,8), %rbp
movq %r14, %r13
xorps %xmm0, %xmm0
cvtss2sd (%rbp,%r13,4), %xmm0
cmpl $0x0, 0x18(%rsp)
je 0x449a5
jle 0x449c3
ucomisd 0x20(%rsp), %xmm0
jb 0x449b9
movq (%rsp), %rdi
movq %r15, %rsi
movl %r12d, %edx
movl %r13d, %ecx
movb $0x1, %al
callq 0x21a0
incq %r13
cmpq %r13, %rbx
jne 0x4498a
jmp 0x449d1
movapd 0x30(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jae 0x449a5
jmp 0x449b9
incq %r14
movq 0x10(%rsp), %r12
cmpq %rbx, %r12
jne 0x4496f
movq (%rsp), %rdi
callq 0x20c0
xorl %eax, %eax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movsd %xmm1, 0x20(%rsp)
movapd %xmm6, 0x30(%rsp)
leaq 0x188df(%rip), %rdi     # 0x5d2ed
movq %r14, (%rsp)
movq %r14, %rsi
xorl %eax, %eax
callq 0x20f0
testl %r15d, %r15d
jle 0x44a8a
xorl %r15d, %r15d
leaq 0x17b2f(%rip), %r14     # 0x5c55a
movq %rbx, %r12
xorl %eax, %eax
leaq 0x1(%rax), %rcx
movq %rcx, 0x18(%rsp)
cmpq %rbx, %rcx
jae 0x44a6c
movq 0x8(%rsp), %rcx
movq (%rcx,%rax,8), %rbp
addq %r15, %rbp
movl $0x1, %r13d
xorps %xmm0, %xmm0
cvtss2sd (%rbp,%r13,4), %xmm0
movq %r14, %rdi
movb $0x1, %al
callq 0x20f0
incq %r13
cmpq %r13, %r12
jne 0x44a50
movl $0xa, %edi
callq 0x2060
addq $0x4, %r15
decq %r12
movq 0x18(%rsp), %rcx
movq %rcx, %rax
cmpq %rbx, %rcx
jne 0x44a30
leaq 0x1885c(%rip), %rdi     # 0x5d2ed
movq (%rsp), %rsi
xorl %eax, %eax
callq 0x20f0
leaq 0x1886e(%rip), %rdi     # 0x5d311
movaps 0x30(%rsp), %xmm0
movsd 0x20(%rsp), %xmm1
movb $0x2, %al
callq 0x20f0
movl $0x8, %edi
callq 0x2280