// File: /workspace/github_c_makefile_star2_O3/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, -0x58(%rbp)
leaq 0x35f57(%rip), %rsi     # 0x58ae0
leaq -0xd0(%rbp), %r15
movl $0xc, %ecx
movq %r15, %rdi
rep  movsq (%rsi), %es:(%rdi)
movl $0x0, 0x60(%r15)
leaq 0x34656(%rip), %rsi     # 0x57200
movq %r15, %rdi
callq 0x2220
movq %rax, %rbx
leaq 0x2f193(%rip), %rdi     # 0x51d4f
movq %r15, %rsi
xorl %eax, %eax
callq 0x20f0
leaq 0x35c5f(%rip), %rdi     # 0x5882c
movl $0x36, %esi
movl $0x1, %edx
movq %rbx, -0x30(%rbp)
movq %rbx, %rcx
callq 0x2290
movq %rsp, -0x38(%rbp)
movl 0x58(%rbp), %r15d
movq %rsp, %r12
leaq 0xf(,%r15,4), %rax
andq $-0x10, %rax
subq %rax, %r12
movq %r12, %rsp
movq %rsp, %rsi
subq %rax, %rsi
movq %rsi, %rsp
testl %r15d, %r15d
jle 0x22cb1
leal 0x1(%r15), %eax
andl $-0x2, %eax
leaq -0x1(%r15), %rcx
movq %rcx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
movdqa 0x2e3f1(%rip), %xmm1    # 0x51020
xorl %ecx, %ecx
movdqa 0x2e3f7(%rip), %xmm2    # 0x51030
pxor %xmm2, %xmm0
pcmpeqd %xmm3, %xmm3
movdqa 0x2e3f7(%rip), %xmm4    # 0x51040
movdqa %xmm1, %xmm5
pxor %xmm2, %xmm5
movdqa %xmm5, %xmm6
pcmpgtd %xmm0, %xmm6
pcmpeqd %xmm0, %xmm5
pshufd $0xf5, %xmm5, %xmm7     # xmm7 = xmm5[1,1,3,3]
pand %xmm6, %xmm7
pshufd $0xf5, %xmm6, %xmm5     # xmm5 = xmm6[1,1,3,3]
por %xmm7, %xmm5
movd %xmm5, %edx
notl %edx
testb $0x1, %dl
je 0x22c86
xorps %xmm6, %xmm6
cvtsi2ss %ecx, %xmm6
movss %xmm6, (%rsi,%rcx,4)
pxor %xmm3, %xmm5
pextrw $0x4, %xmm5, %edx
testb $0x1, %dl
je 0x22ca4
leal 0x1(%rcx), %edx
xorps %xmm5, %xmm5
cvtsi2ss %edx, %xmm5
movss %xmm5, 0x4(%rsi,%rcx,4)
addq $0x2, %rcx
paddq %xmm4, %xmm1
cmpq %rcx, %rax
jne 0x22c49
testl %r13d, %r13d
jle 0x22ebd
leaq 0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x40(%rbp)
movl %r13d, %eax
movq %rax, -0x48(%rbp)
xorl %ebx, %ebx
movq %rsi, -0x50(%rbp)
movq -0x58(%rbp), %r13
testl %r15d, %r15d
jle 0x22d23
movq -0x40(%rbp), %rax
movq (%rax,%rbx,8), %rax
xorl %ecx, %ecx
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, (%r12,%rcx,4)
incq %rcx
addq $0xc, %rax
cmpq %rcx, %r15
jne 0x22ce6
movq -0x50(%rbp), %rdi
movq %r12, %rsi
movl %r15d, %edx
leaq -0x68(%rbp), %rcx
leaq -0x64(%rbp), %r8
callq 0x108db
imulq $0x158, %rbx, %r14      # imm = 0x158
cvtss2sd %xmm0, %xmm0
movsbl (%r13,%r14), %edx
movq %rbx, -0x60(%rbp)
movq -0x30(%rbp), %rbx
movq %rbx, %rdi
leaq 0x35b06(%rip), %rsi     # 0x58863
movb $0x1, %al
callq 0x21a0
movsd 0xc0(%r13,%r14), %xmm0
movsd 0xc8(%r13,%r14), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
movsd 0xd0(%r13,%r14), %xmm1
mulsd %xmm1, %xmm1
addsd %xmm0, %xmm1
xorps %xmm0, %xmm0
sqrtsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
cvtss2sd %xmm0, %xmm0
movq %rbx, %rdi
leaq 0x33d74(%rip), %rsi     # 0x56b23
movb $0x1, %al
callq 0x21a0
movsd 0x90(%r13,%r14), %xmm0
movsd 0x98(%r13,%r14), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
movsd 0xa0(%r13,%r14), %xmm1
mulsd %xmm1, %xmm1
addsd %xmm0, %xmm1
xorps %xmm0, %xmm0
sqrtsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
cvtss2sd %xmm0, %xmm0
movq %rbx, %rdi
leaq 0x33d22(%rip), %rsi     # 0x56b23
movb $0x1, %al
callq 0x21a0
movsd 0xd8(%r13,%r14), %xmm0
movsd 0xe0(%r13,%r14), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
movsd 0xe8(%r13,%r14), %xmm1
mulsd %xmm1, %xmm1
addsd %xmm0, %xmm1
xorps %xmm0, %xmm0
sqrtsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
cvtss2sd %xmm0, %xmm0
movq %rbx, %rdi
leaq 0x33cd0(%rip), %rsi     # 0x56b23
movb $0x1, %al
callq 0x21a0
movsd 0xa8(%r13,%r14), %xmm0
movsd 0xb0(%r13,%r14), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
movsd 0xb8(%r13,%r14), %xmm1
mulsd %xmm1, %xmm1
addsd %xmm0, %xmm1
xorps %xmm0, %xmm0
sqrtsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
cvtss2sd %xmm0, %xmm0
movq %rbx, %rdi
movq -0x60(%rbp), %rbx
leaq 0x36edc(%rip), %rsi     # 0x59d85
movb $0x1, %al
callq 0x21a0
incq %rbx
cmpq -0x48(%rbp), %rbx
jne 0x22cd7
movq -0x30(%rbp), %rdi
callq 0x20c0
movq -0x38(%rbp), %rsp
xorl %eax, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq