// File: /workspace/github_c_makefile_star2_O3/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 0x17aa4(%rip), %rdi     # 0x5d87c
xorl %eax, %eax
callq 0x20f0
leaq 0x17abf(%rip), %rsi     # 0x5d8a5
leaq 0x100(%rsp), %rbx
movq %rbx, %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x2270
leaq 0x113fe(%rip), %rsi     # 0x57200
movq %rbx, %rdi
callq 0x2220
movq %rax, %rbp
leaq 0xbf3b(%rip), %rdi      # 0x51d4f
movq %rbx, %rsi
xorl %eax, %eax
callq 0x20f0
movups 0x17a97(%rip), %xmm0    # 0x5d8bc
movaps %xmm0, 0x30(%rsp)
testq %r13, %r13
je 0x45e45
leaq 0x30(%rsp), %rdi
callq 0x20d0
movups 0x17a8c(%rip), %xmm0    # 0x5d8cc
movups %xmm0, 0x30(%rsp,%rax)
testq %r12, %r12
je 0x45e72
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 0x45e98
leaq 0x30(%rsp), %rdi
callq 0x20d0
movabsq $0x61697261766f4320, %rcx # imm = 0x61697261766F4320
movq %rcx, 0x30(%rsp,%rax)
movl $0x65636e, 0x38(%rsp,%rax) # imm = 0x65636E
movq %r13, 0x8(%rsp)
movq %r12, 0x10(%rsp)
movq %r14, 0x20(%rsp)
movq %r15, 0x18(%rsp)
testq %r15, %r15
je 0x45ed9
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)
leaq 0x30(%rsp), %rbx
movq %rbx, %rdi
callq 0x20d0
movups 0x17a16(%rip), %xmm0    # 0x5d903
movups %xmm0, 0x30(%rsp,%rax)
movw $0x74, 0x40(%rsp,%rax)
leaq 0x17765(%rip), %rsi     # 0x5d665
movq %rbp, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x21a0
movl 0x210(%rsp), %eax
testl %eax, %eax
jle 0x46018
movq 0x208(%rsp), %r14
movl %eax, %r15d
leaq 0x118cb(%rip), %rbx     # 0x577f9
xorl %r13d, %r13d
movq %r13, %r12
movsbl (%r14,%r13), %edx
movsbl (%r14,%r12), %ecx
movq %rbp, %rdi
leaq 0x179cd(%rip), %rsi     # 0x5d915
xorl %eax, %eax
callq 0x21a0
movq 0x8(%rsp), %rax
testq %rax, %rax
je 0x45f74
movq (%rax,%r13,8), %rax
movsd (%rax,%r12,8), %xmm0
movq %rbp, %rdi
leaq 0xc31c(%rip), %rsi      # 0x52289
movb $0x1, %al
callq 0x21a0
movq 0x10(%rsp), %rax
testq %rax, %rax
je 0x45f95
movq (%rax,%r13,8), %rax
movsd (%rax,%r12,8), %xmm0
movq %rbp, %rdi
movq %rbx, %rsi
movb $0x1, %al
callq 0x21a0
movq 0x20(%rsp), %rax
testq %rax, %rax
je 0x45fb6
movq (%rax,%r13,8), %rax
movsd (%rax,%r12,8), %xmm0
movq %rbp, %rdi
movq %rbx, %rsi
movb $0x1, %al
callq 0x21a0
movq 0x18(%rsp), %rax
testq %rax, %rax
je 0x45fd7
movq (%rax,%r13,8), %rax
movsd (%rax,%r12,8), %xmm0
movq %rbp, %rdi
movq %rbx, %rsi
movb $0x1, %al
callq 0x21a0
movq 0x28(%rsp), %rax
movq (%rax,%r13,8), %rax
movsd (%rax,%r12,8), %xmm0
movq %rbp, %rdi
movq %rbx, %rsi
movb $0x1, %al
callq 0x21a0
movl $0xa, %edi
movq %rbp, %rsi
callq 0x2140
incq %r12
cmpq %r12, %r15
jne 0x45f34
incq %r13
cmpq %r15, %r13
jne 0x45f31
movq %rbp, %rdi
callq 0x20c0
addq $0x1c8, %rsp            # imm = 0x1C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq