// File: /workspace/github_c_makefile_star2_O1/ugobas[P]tnm/kinetic_tnm.c
// Function: Correlate_Jacobian
int Correlate_Jacobian(struct Jacobian J,
		       struct Reference Ref,
		       struct axe *axe, int N_axes)
{
  // Jacobian: derivatives with respect to torsions for all atoms
  // (only internal degrees of freedom)
  char nameout[100]="Jacobian_correlations.dat";
  FILE *file_out=fopen(nameout, "w");
  printf("Writing %s\n", nameout);
  fprintf(file_out, "#r(J[k], index) loc_shift glob_shift loc_rot glob_rot\n");
  int N=Ref.N_ref, i, k;
  float D2[N], index[N];
  for(i=0; i<N; i++)index[i]=i;
  for(k=0; k<N_axes; k++){
    float *J_k=J.Jacobian_ar[k];
    for(i=0; i<N; i++){
      double D=0;
      D+=(*J_k)*(*J_k); J_k++;
      D+=(*J_k)*(*J_k); J_k++; 
      D+=(*J_k)*(*J_k); J_k++;
      D2[i]=D;
    }
    float slope, offset, r=Corr_coeff(index, D2, N, &slope, &offset);
    struct axe *axe_k=axe+k;
    fprintf(file_out, "%.3f %c", r, axe_k->type);
    float v2=Module(axe_k->local_shift); fprintf(file_out, " %.3f", v2);
    v2=Module(axe_k->global_shift);fprintf(file_out, " %.3f", v2);
    v2=Module(axe_k->local_rot);   fprintf(file_out, " %.3f", v2);
    v2=Module(axe_k->global_rot);  fprintf(file_out, " %.3f\n", v2);
  }
  fclose(file_out); //exit(8);
  return(0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movl %esi, %r13d
movq %rdi, -0x40(%rbp)
leaq 0x358f2(%rip), %rsi     # 0x58b10
leaq -0xd0(%rbp), %r15
movl $0xc, %ecx
movq %r15, %rdi
rep  movsq (%rsi), %es:(%rdi)
movl $0x0, 0x60(%r15)
leaq 0x34001(%rip), %rsi     # 0x57240
movq %r15, %rdi
callq 0x2210
movq %rax, %r14
leaq 0x2ea8a(%rip), %rdi     # 0x51cdb
movq %r15, %rsi
xorl %eax, %eax
callq 0x20f0
leaq 0x355f4(%rip), %rdi     # 0x58856
movl $0x36, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2280
movq %rsp, -0x48(%rbp)
movl 0x58(%rbp), %r15d
movq %rsp, %r12
leaq 0xf(,%r15,4), %rax
andq $-0x10, %rax
subq %rax, %r12
movq %r12, %rsp
movq %rsp, %rbx
subq %rax, %rbx
movq %rbx, %rsp
testl %r15d, %r15d
jle 0x232b5
xorl %eax, %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
movss %xmm0, (%rbx,%rax,4)
incq %rax
cmpq %rax, %r15
jne 0x232a1
testl %r13d, %r13d
jle 0x234f2
leaq 0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x50(%rbp)
movl %r13d, %eax
movq %rax, -0x58(%rbp)
xorl %r13d, %r13d
movq %r14, -0x38(%rbp)
movq %rbx, -0x30(%rbp)
testl %r15d, %r15d
jle 0x2332f
movq -0x50(%rbp), %rax
movq (%rax,%r13,8), %rax
xorl %ecx, %ecx
movss (%rax), %xmm0
movss 0x4(%rax), %xmm1
mulss %xmm0, %xmm0
cvtss2sd %xmm0, %xmm0
mulss %xmm1, %xmm1
cvtss2sd %xmm1, %xmm1
addsd %xmm0, %xmm1
movss 0x8(%rax), %xmm0
mulss %xmm0, %xmm0
cvtss2sd %xmm0, %xmm0
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%r12,%rcx,4)
incq %rcx
addq $0xc, %rax
cmpq %rcx, %r15
jne 0x232eb
movq %rbx, %rdi
movq %r12, %rsi
movl %r15d, %edx
leaq -0x60(%rbp), %rcx
leaq -0x5c(%rbp), %r8
callq 0x10d91
imulq $0x158, %r13, %rbx      # imm = 0x158
cvtss2sd %xmm0, %xmm0
movq -0x40(%rbp), %r14
movsbl (%r14,%rbx), %edx
movq -0x38(%rbp), %rdi
leaq 0x35529(%rip), %rsi     # 0x5888d
movb $0x1, %al
callq 0x2190
movsd 0xc0(%r14,%rbx), %xmm1
movsd 0xc8(%r14,%rbx), %xmm0
mulsd %xmm0, %xmm0
mulsd %xmm1, %xmm1
addsd %xmm0, %xmm1
movsd 0xd0(%r14,%rbx), %xmm0
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
ucomisd 0x2dcbb(%rip), %xmm0    # 0x51060
jb 0x233ad
sqrtsd %xmm0, %xmm0
jmp 0x233b2
callq 0x2290
addq -0x40(%rbp), %rbx
cvtsd2ss %xmm0, %xmm0
cvtss2sd %xmm0, %xmm0
movq -0x38(%rbp), %r14
movq %r14, %rdi
leaq 0x33743(%rip), %rsi     # 0x56b0f
movb $0x1, %al
callq 0x2190
movsd 0x90(%rbx), %xmm1
movsd 0x98(%rbx), %xmm0
mulsd %xmm0, %xmm0
mulsd %xmm1, %xmm1
addsd %xmm0, %xmm1
movsd 0xa0(%rbx), %xmm0
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
ucomisd 0x2dc59(%rip), %xmm0    # 0x51060
jb 0x2340f
sqrtsd %xmm0, %xmm0
jmp 0x23414
callq 0x2290
cvtsd2ss %xmm0, %xmm0
cvtss2sd %xmm0, %xmm0
movq %r14, %rdi
leaq 0x336e9(%rip), %rsi     # 0x56b0f
movb $0x1, %al
callq 0x2190
movsd 0xd8(%rbx), %xmm1
movsd 0xe0(%rbx), %xmm0
mulsd %xmm0, %xmm0
mulsd %xmm1, %xmm1
addsd %xmm0, %xmm1
movsd 0xe8(%rbx), %xmm0
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
ucomisd 0x2dbff(%rip), %xmm0    # 0x51060
jb 0x23469
sqrtsd %xmm0, %xmm0
jmp 0x2346e
callq 0x2290
cvtsd2ss %xmm0, %xmm0
cvtss2sd %xmm0, %xmm0
movq %r14, %rdi
leaq 0x3368f(%rip), %rsi     # 0x56b0f
movb $0x1, %al
callq 0x2190
movsd 0xa8(%rbx), %xmm1
movsd 0xb0(%rbx), %xmm0
mulsd %xmm0, %xmm0
mulsd %xmm1, %xmm1
addsd %xmm0, %xmm1
movsd 0xb8(%rbx), %xmm0
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
ucomisd 0x2dba5(%rip), %xmm0    # 0x51060
jb 0x234c3
sqrtsd %xmm0, %xmm0
jmp 0x234c8
callq 0x2290
movq -0x30(%rbp), %rbx
cvtsd2ss %xmm0, %xmm0
cvtss2sd %xmm0, %xmm0
movq %r14, %rdi
leaq 0x36903(%rip), %rsi     # 0x59de1
movb $0x1, %al
callq 0x2190
incq %r13
cmpq -0x58(%rbp), %r13
jne 0x232dc
movq %r14, %rdi
callq 0x20c0
movq -0x48(%rbp), %rsp
xorl %eax, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq