// File: /workspace/github_c_makefile_star2_O2/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 $0x118, %rsp            # imm = 0x118
movl %r8d, %ebp
movl %esi, %ebx
movq %rdi, %r15
leaq 0x10d56(%rip), %rsi     # 0x4fcbc
xorl %r13d, %r13d
leaq 0x50(%rsp), %r14
movq %r14, %rdi
movq %rdx, 0x10(%rsp)
movq %rcx, 0x40(%rsp)
xorl %eax, %eax
callq 0x2260
leaq 0x121c7(%rip), %rsi     # 0x51150
movq %r14, %rdi
callq 0x2210
movq %rax, (%rsp)
leaq 0xcd0b(%rip), %rdi      # 0x4bca7
movq %r14, %rsi
xorl %eax, %eax
callq 0x20f0
testl %ebx, %ebx
movl $0x0, %r12d
cmovgl %ebx, %r12d
xorpd %xmm0, %xmm0
movss 0x12232(%rip), %xmm7    # 0x511f0
xorps %xmm8, %xmm8
pushq $0x2
popq %rcx
xorl %eax, %eax
cmpq %r12, %r13
je 0x3f012
movq (%r15,%r13,8), %rdx
movq %rcx, %rsi
cmpl %ebx, %esi
jge 0x3f00a
movss (%rdx,%rsi,4), %xmm1
movaps %xmm1, %xmm2
mulss %xmm1, %xmm2
movaps %xmm1, %xmm3
unpcklps %xmm2, %xmm3            # xmm3 = xmm3[0],xmm2[0],xmm3[1],xmm2[1]
cvtps2pd %xmm3, %xmm2
addpd %xmm2, %xmm0
incl %eax
movaps %xmm1, %xmm2
maxss %xmm8, %xmm2
minss %xmm7, %xmm1
incq %rsi
movaps %xmm2, %xmm8
movaps %xmm1, %xmm7
jmp 0x3efd3
incq %r13
incq %rcx
jmp 0x3efc7
cvtsi2sd %eax, %xmm1
movapd %xmm0, %xmm5
divsd %xmm1, %xmm5
mulsd %xmm5, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
mulsd %xmm5, %xmm1
subsd %xmm1, %xmm0
decl %eax
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x3f048
sqrtsd %xmm0, %xmm1
jmp 0x3f077
movapd %xmm5, 0x20(%rsp)
movss %xmm7, 0x8(%rsp)
movss %xmm8, 0x1c(%rsp)
callq 0x2290
movss 0x1c(%rsp), %xmm8
movss 0x8(%rsp), %xmm7
movapd 0x20(%rsp), %xmm5
movapd %xmm0, %xmm1
ucomisd %xmm5, %xmm5
movq %r12, 0x8(%rsp)
movq %r15, 0x38(%rsp)
jp 0x3f207
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm5
jne 0x3f09b
jnp 0x3f207
ucomisd %xmm0, %xmm1
jne 0x3f0a7
jnp 0x3f207
ucomisd %xmm1, %xmm1
jp 0x3f207
leaq 0x23188(%rip), %rax     # 0x62240
cvtss2sd (%rax), %xmm4
movaps %xmm4, %xmm0
mulsd %xmm1, %xmm0
movapd %xmm5, %xmm6
subsd %xmm0, %xmm6
addsd %xmm5, %xmm0
cvtss2sd %xmm8, %xmm3
movapd %xmm5, %xmm2
addsd %xmm3, %xmm2
movsd 0xbf8b(%rip), %xmm8     # 0x4b070
mulsd %xmm8, %xmm2
cmpnlesd %xmm0, %xmm3
andpd %xmm3, %xmm0
andnpd %xmm2, %xmm3
orpd %xmm0, %xmm3
cvtss2sd %xmm7, %xmm0
movapd %xmm5, %xmm7
addsd %xmm0, %xmm7
mulsd %xmm8, %xmm7
movapd %xmm6, %xmm2
cmpnlesd %xmm0, %xmm2
andpd %xmm2, %xmm6
andnpd %xmm7, %xmm2
orpd %xmm6, %xmm2
leaq 0x18170(%rip), %rsi     # 0x57298
movq (%rsp), %r14
movq %r14, %rdi
movapd %xmm5, %xmm0
movapd %xmm2, 0x20(%rsp)
movapd %xmm3, 0x40(%rsp)
movb $0x5, %al
callq 0x2190
leaq 0x1817e(%rip), %rsi     # 0x572cb
movq %r14, %rdi
movq 0x10(%rsp), %rdx
xorl %eax, %eax
callq 0x2190
leaq 0x18190(%rip), %rdi     # 0x572f3
pushq $0x14
popq %rsi
pushq $0x1
popq %rdx
movq %r14, %rcx
callq 0x2280
xorl %eax, %eax
leaq 0x1818e(%rip), %r13     # 0x57308
xorl %r14d, %r14d
cmpq %r12, %r14
je 0x3f1ea
movq (%r15,%r14,8), %r12
movq %rax, 0x10(%rsp)
addq %rax, %r12
pushq $0x1
popq %r15
leaq (%r14,%r15), %rcx
cmpl %ebx, %ecx
jge 0x3f1d2
cvtss2sd (%r12,%r15,4), %xmm0
testl %ebp, %ebp
je 0x3f1ae
jle 0x3f1c4
ucomisd 0x40(%rsp), %xmm0
jb 0x3f1bf
movq (%rsp), %rdi
movq %r13, %rsi
movl %r14d, %edx
movb $0x1, %al
callq 0x2190
incq %r15
jmp 0x3f192
movapd 0x20(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jae 0x3f1ae
jmp 0x3f1bf
incq %r14
movq 0x10(%rsp), %rax
addq $0x4, %rax
movq 0x38(%rsp), %r15
movq 0x8(%rsp), %r12
jmp 0x3f17d
movq (%rsp), %rdi
callq 0x20c0
xorl %eax, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movsd %xmm1, (%rsp)
movapd %xmm5, 0x20(%rsp)
leaq 0x18044(%rip), %rdi     # 0x5725d
xorl %r15d, %r15d
movq 0x40(%rsp), %rsi
xorl %eax, %eax
callq 0x20f0
leaq 0x17293(%rip), %r14     # 0x564c2
xorl %r13d, %r13d
cmpq 0x8(%rsp), %r13
je 0x3f277
movq 0x38(%rsp), %rax
movq (%rax,%r13,8), %r12
addq %r15, %r12
pushq $0x1
popq %rbp
leal (%r13,%rbp), %eax
cmpl %ebx, %eax
jge 0x3f266
cvtss2sd (%r12,%rbp,4), %xmm0
movq %r14, %rdi
movb $0x1, %al
callq 0x20f0
incq %rbp
jmp 0x3f248
incq %r13
pushq $0xa
popq %rdi
callq 0x2060
addq $0x4, %r15
jmp 0x3f232
leaq 0x17fdf(%rip), %rdi     # 0x5725d
movq 0x40(%rsp), %rsi
xorl %eax, %eax
callq 0x20f0
leaq 0x17ff0(%rip), %rdi     # 0x57281
movaps 0x20(%rsp), %xmm0
movsd (%rsp), %xmm1
movb $0x2, %al
callq 0x20f0
pushq $0x8
popq %rdi
callq 0x2270