// File: /workspace/github_c_makefile_star2_O2/ugobas[P]tnm/allostery.c
// Function: Coupling_chains
void Coupling_chains(double **Chain_dir, double **Chain_coord,
		     double **Chain_def, double **Chain_cov,
		     double **norm_chain, char *ch, int Na,
		     char *chain_label, int Nchain, char *nameout1)
{
  printf("Printing average couplings of %d chains\n", Nchain);


  char nameout[200];
  //sprintf(nameout, "%s.chain%c_couplings.dat", nameout1,chain_label[i]);
  sprintf(nameout, "%s.chain_couplings.dat", nameout1);
  FILE *file_out=fopen(nameout, "w");
  printf("Writing %s\n", nameout);

  char header[200]; sprintf(header, "#chain1 chain2 ");
  if(Chain_dir)strcat(header,  " Directionality");
  if(Chain_coord)strcat(header," Coordination");
  if(Chain_cov)strcat(header,  " Covariance");
  if(Chain_def)strcat(header,  " Deformation");
  strcat(header,  " Proximity_weight");
  fprintf(file_out, "%s\n", header);

  for(int i=0; i<Nchain; i++){
    for(int j=i; j<Nchain; j++){
      fprintf(file_out, "%c %c ", chain_label[i], chain_label[j]);
      if(Chain_dir)fprintf(file_out, " %.4g", Chain_dir[i][j]);
      if(Chain_coord)fprintf(file_out, "\t%.4g", Chain_coord[i][j]);
      if(Chain_cov)fprintf(file_out, "\t%.4g", Chain_cov[i][j]);
      if(Chain_def)fprintf(file_out, "\t%.4g", Chain_def[i][j]);
      fprintf(file_out, "\t%.4g", norm_chain[i][j]);
      fprintf(file_out, "\n");
    }
  }
  fclose(file_out);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1c8, %rsp            # imm = 0x1C8
movq %r8, 0x28(%rsp)
movq %rcx, %r14
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r13
movl 0x210(%rsp), %esi
movq 0x218(%rsp), %rbp
leaq 0x17483(%rip), %rdi     # 0x577ec
xorl %eax, %eax
callq 0x20f0
leaq 0x1749e(%rip), %rsi     # 0x57815
leaq 0x100(%rsp), %rbx
movq %rbx, %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x2260
leaq 0x10dbd(%rip), %rsi     # 0x51150
movq %rbx, %rdi
callq 0x2210
movq %rax, %rbp
leaq 0xb902(%rip), %rdi      # 0x4bca7
movq %rbx, %rsi
xorl %eax, %eax
callq 0x20f0
movups 0x17476(%rip), %xmm0    # 0x5782c
movaps %xmm0, 0x30(%rsp)
testq %r13, %r13
je 0x403d6
leaq 0x30(%rsp), %rdi
callq 0x20d0
movups 0x1746b(%rip), %xmm0    # 0x5783c
movups %xmm0, 0x30(%rsp,%rax)
testq %r12, %r12
je 0x40403
leaq 0x30(%rsp), %rdi
callq 0x20d0
movabsq $0x6e6964726f6f4320, %rcx # imm = 0x6E6964726F6F4320
movq %rcx, 0x30(%rsp,%rax)
movabsq $0x6e6f6974616e69, %rcx # imm = 0x6E6F6974616E69
movq %rcx, 0x36(%rsp,%rax)
testq %r14, %r14
je 0x40429
leaq 0x30(%rsp), %rdi
callq 0x20d0
movabsq $0x61697261766f4320, %rcx # imm = 0x61697261766F4320
movq %rcx, 0x30(%rsp,%rax)
movl $0x65636e, 0x38(%rsp,%rax) # imm = 0x65636E
movq %r12, 0x10(%rsp)
movq %r14, 0x20(%rsp)
testq %r15, %r15
je 0x40460
leaq 0x30(%rsp), %rdi
callq 0x20d0
movabsq $0x616d726f66654420, %rcx # imm = 0x616D726F66654420
movq %rcx, 0x30(%rsp,%rax)
movabsq $0x6e6f6974616d72, %rcx # imm = 0x6E6F6974616D72
movq %rcx, 0x35(%rsp,%rax)
movq %r15, 0x18(%rsp)
leaq 0x30(%rsp), %rbx
movq %rbx, %rdi
callq 0x20d0
movups 0x173fa(%rip), %xmm0    # 0x57873
movups %xmm0, 0x30(%rsp,%rax)
movw $0x74, 0x40(%rsp,%rax)
leaq 0x17149(%rip), %rsi     # 0x575d5
movq %rbp, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2190
movl 0x210(%rsp), %eax
testl %eax, %eax
movl $0x0, %ecx
cmovgl %eax, %ecx
movq %rcx, 0x8(%rsp)
movl %eax, %r14d
leaq 0x112a0(%rip), %rbx     # 0x51759
xorl %r12d, %r12d
movq %r12, %r15
cmpq 0x8(%rsp), %r12
je 0x405b1
cmpq %r15, %r14
je 0x405a9
movq 0x208(%rsp), %rax
movsbl (%rax,%r12), %edx
movsbl (%rax,%r15), %ecx
movq %rbp, %rdi
leaq 0x17396(%rip), %rsi     # 0x57885
xorl %eax, %eax
callq 0x2190
testq %r13, %r13
je 0x40517
movq (%r13,%r12,8), %rax
movsd (%rax,%r15,8), %xmm0
movq %rbp, %rdi
leaq 0xbcd1(%rip), %rsi      # 0x4c1e1
movb $0x1, %al
callq 0x2190
movq 0x10(%rsp), %rax
testq %rax, %rax
je 0x40538
movq (%rax,%r12,8), %rax
movsd (%rax,%r15,8), %xmm0
movq %rbp, %rdi
movq %rbx, %rsi
movb $0x1, %al
callq 0x2190
movq 0x20(%rsp), %rax
testq %rax, %rax
je 0x40559
movq (%rax,%r12,8), %rax
movsd (%rax,%r15,8), %xmm0
movq %rbp, %rdi
movq %rbx, %rsi
movb $0x1, %al
callq 0x2190
movq 0x18(%rsp), %rax
testq %rax, %rax
je 0x4057a
movq (%rax,%r12,8), %rax
movsd (%rax,%r15,8), %xmm0
movq %rbp, %rdi
movq %rbx, %rsi
movb $0x1, %al
callq 0x2190
movq 0x28(%rsp), %rax
movq (%rax,%r12,8), %rax
movsd (%rax,%r15,8), %xmm0
movq %rbp, %rdi
movq %rbx, %rsi
movb $0x1, %al
callq 0x2190
pushq $0xa
popq %rdi
movq %rbp, %rsi
callq 0x2140
incq %r15
jmp 0x404ca
incq %r12
jmp 0x404bc
movq %rbp, %rdi
callq 0x20c0
addq $0x1c8, %rsp            # imm = 0x1C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq