// File: /workspace/github_c_makefile_star2_O2/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 $0xb8, %rsp
movl %esi, %r15d
movq %rdi, -0x58(%rbp)
leaq 0x10(%rbp), %r14
leaq 0x31ee4(%rip), %rsi     # 0x52a40
pushq $0x64
popq %rcx
leaq -0xe0(%rbp), %rbx
movq %rbx, %rdi
rep  movsb (%rsi), %es:(%rdi)
leaq 0x305de(%rip), %rsi     # 0x51150
movq %rbx, %rdi
callq 0x2210
movq %rax, %r13
leaq 0x2b123(%rip), %rdi     # 0x4bca7
xorl %r12d, %r12d
movq %rbx, %rsi
xorl %eax, %eax
callq 0x20f0
leaq 0x31bf4(%rip), %rdi     # 0x5278c
pushq $0x36
popq %rsi
pushq $0x1
popq %rdx
movq %r13, -0x30(%rbp)
movq %r13, %rcx
callq 0x2280
movq %rsp, -0x40(%rbp)
movl 0x58(%rbp), %ecx
movq %rsp, %r13
leaq 0xf(,%rcx,4), %rax
andq $-0x10, %rax
subq %rax, %r13
movq %r13, %rsp
movq %rsp, %rdx
subq %rax, %rdx
movq %rdx, -0x38(%rbp)
movq %rdx, %rsp
testl %ecx, %ecx
movl $0x0, %ebx
movq %rcx, -0x50(%rbp)
cmovgl %ecx, %ebx
movq -0x38(%rbp), %rax
cmpq %r12, %rbx
je 0x20bfa
cvtsi2ss %r12d, %xmm0
movss %xmm0, (%rax,%r12,4)
incq %r12
jmp 0x20be5
movq 0x10(%r14), %rax
movq %rax, -0x48(%rbp)
xorl %r14d, %r14d
testl %r15d, %r15d
cmovlel %r14d, %r15d
movq %r15, -0x60(%rbp)
movq -0x30(%rbp), %r15
cmpq -0x60(%rbp), %r14
je 0x20d55
movq -0x48(%rbp), %rax
movq (%rax,%r14,8), %rax
xorl %ecx, %ecx
cmpq %rcx, %rbx
je 0x20c68
movsd (%rax), %xmm0
mulps %xmm0, %xmm0
cvtps2pd %xmm0, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movss 0x8(%rax), %xmm0
mulss %xmm0, %xmm0
cvtss2sd %xmm0, %xmm0
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%r13,%rcx,4)
incq %rcx
addq $0xc, %rax
jmp 0x20c28
movq -0x38(%rbp), %rdi
movq %r13, %rsi
movq -0x50(%rbp), %rdx
leaq -0x78(%rbp), %rcx
leaq -0x74(%rbp), %r8
callq 0xfe18
imulq $0x158, %r14, %rax      # imm = 0x158
movq %rax, -0x68(%rbp)
cvtss2sd %xmm0, %xmm0
movq %r14, -0x70(%rbp)
movq -0x58(%rbp), %r14
leaq 0xc0(%r14,%rax), %r12
movsbl -0xc0(%r12), %edx
movq %r15, %rdi
leaq 0x31b11(%rip), %rsi     # 0x527c3
movb $0x1, %al
callq 0x2190
movq %r12, %rdi
callq 0x20d73
cvtss2sd %xmm0, %xmm0
movq %r15, %rdi
leaq 0x2fda4(%rip), %rsi     # 0x50a73
movb $0x1, %al
callq 0x2190
movq -0x68(%rbp), %r12
leaq (%r14,%r12), %rdi
addq $0x90, %rdi
callq 0x20d73
cvtss2sd %xmm0, %xmm0
movq %r15, %rdi
leaq 0x2fd7b(%rip), %rsi     # 0x50a73
movb $0x1, %al
callq 0x2190
leaq (%r14,%r12), %rdi
addq $0xd8, %rdi
callq 0x20d73
cvtss2sd %xmm0, %xmm0
movq %r15, %rdi
leaq 0x2fd56(%rip), %rsi     # 0x50a73
movb $0x1, %al
callq 0x2190
leaq (%r14,%r12), %rdi
addq $0xa8, %rdi
movq -0x70(%rbp), %r14
callq 0x20d73
cvtss2sd %xmm0, %xmm0
movq %r15, %rdi
leaq 0x32f9f(%rip), %rsi     # 0x53ce5
movb $0x1, %al
callq 0x2190
incq %r14
jmp 0x20c14
movq -0x30(%rbp), %rdi
callq 0x20c0
movq -0x40(%rbp), %rsp
xorl %eax, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq