// File: /workspace/github_c_makefile_star2_O1/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 0x17c1b(%rip), %rdi     # 0x5d8ac
xorl %eax, %eax
callq 0x20f0
leaq 0x17c36(%rip), %rsi     # 0x5d8d5
leaq 0x100(%rsp), %rbx
movq %rbx, %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x2260
leaq 0x11585(%rip), %rsi     # 0x57240
movq %rbx, %rdi
callq 0x2210
movq %rax, %rbp
leaq 0xc00e(%rip), %rdi      # 0x51cdb
movq %rbx, %rsi
xorl %eax, %eax
callq 0x20f0
movups 0x17c0e(%rip), %xmm0    # 0x5d8ec
movaps %xmm0, 0x30(%rsp)
testq %r13, %r13
je 0x45cfe
leaq 0x30(%rsp), %rdi
callq 0x20d0
movups 0x17c03(%rip), %xmm0    # 0x5d8fc
movups %xmm0, 0x30(%rsp,%rax)
testq %r12, %r12
je 0x45d2b
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 0x45d51
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 0x45d92
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 0x17b8d(%rip), %xmm0    # 0x5d933
movups %xmm0, 0x30(%rsp,%rax)
movw $0x74, 0x40(%rsp,%rax)
leaq 0x178dc(%rip), %rsi     # 0x5d695
movq %rbp, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2190
movl 0x210(%rsp), %eax
testl %eax, %eax
jle 0x45ed1
movq 0x208(%rsp), %r14
movl %eax, %r15d
leaq 0x11a52(%rip), %rbx     # 0x57839
xorl %r13d, %r13d
movq %r13, %r12
movsbl (%r14,%r13), %edx
movsbl (%r14,%r12), %ecx
movq %rbp, %rdi
leaq 0x17b44(%rip), %rsi     # 0x5d945
xorl %eax, %eax
callq 0x2190
movq 0x8(%rsp), %rax
testq %rax, %rax
je 0x45e2d
movq (%rax,%r13,8), %rax
movsd (%rax,%r12,8), %xmm0
movq %rbp, %rdi
leaq 0xc3ef(%rip), %rsi      # 0x52215
movb $0x1, %al
callq 0x2190
movq 0x10(%rsp), %rax
testq %rax, %rax
je 0x45e4e
movq (%rax,%r13,8), %rax
movsd (%rax,%r12,8), %xmm0
movq %rbp, %rdi
movq %rbx, %rsi
movb $0x1, %al
callq 0x2190
movq 0x20(%rsp), %rax
testq %rax, %rax
je 0x45e6f
movq (%rax,%r13,8), %rax
movsd (%rax,%r12,8), %xmm0
movq %rbp, %rdi
movq %rbx, %rsi
movb $0x1, %al
callq 0x2190
movq 0x18(%rsp), %rax
testq %rax, %rax
je 0x45e90
movq (%rax,%r13,8), %rax
movsd (%rax,%r12,8), %xmm0
movq %rbp, %rdi
movq %rbx, %rsi
movb $0x1, %al
callq 0x2190
movq 0x28(%rsp), %rax
movq (%rax,%r13,8), %rax
movsd (%rax,%r12,8), %xmm0
movq %rbp, %rdi
movq %rbx, %rsi
movb $0x1, %al
callq 0x2190
movl $0xa, %edi
movq %rbp, %rsi
callq 0x2140
incq %r12
cmpq %r12, %r15
jne 0x45ded
incq %r13
cmpq %r15, %r13
jne 0x45dea
movq %rbp, %rdi
callq 0x20c0
addq $0x1c8, %rsp            # imm = 0x1C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq