// File: /workspace/github_c_makefile_star2_O3/ugobas[P]tnm/mutation.c
// Function: Compute_mut_def
void Compute_mut_def(float *pred_mut_Cart, int N_Cart,
		     float *pred_mut_Tors, int N_axes,
		     float *DE, float *Force_coeff, float *Force,
		     struct Normal_Mode NM, float *sigma2, float mass)
{
  int a, i;
  for(i=0; i<N_Cart; i++)pred_mut_Cart[i]=0;
  for(i=0; i<N_axes; i++)pred_mut_Tors[i]=0;

  /*double F=0;
  for(i=0; i<N_Cart; i++){F+=Force[i]*Force[i];}
  printf("RMS of mutational force: %.3f\n", sqrt(3*F/N_Cart)); */
  double DE_tmp=0;

  // Compute predicted deformation of kinetic atoms (Cart)
  for(a=0; a<NM.N; a++){
    if((NM.Cart_coll[a]<COLL_THR_MUT)||(sigma2[a]<=0)){
      Force_coeff[a]=0; continue;
    }
    float *f=Force, *x=NM.Cart[a];
    double xf=0; // Projection of force on normal mode
    for(i=0; i<N_Cart; i++){xf+=(*x)*(*f); x++; f++;}
    Force_coeff[a]=xf;
    //(*DE)+=xf*xf/sigma2[a];
    DE_tmp+=xf*xf*sigma2[a]; // OK
    xf*=sigma2[a];
    float *m=pred_mut_Cart; x=NM.Cart[a];
    for(i=0; i<N_Cart; i++){
      (*m)+=(*x)*xf; x++; m++;
    }
    m=pred_mut_Tors; x=NM.Tors[a];
    for(i=0; i<N_axes; i++){
      (*m)+=(*x)*xf; x++; m++;
    }
  }
  *DE=DE_tmp;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r9, %r14
movq %r8, 0x10(%rsp)
movl %ecx, 0xc(%rsp)
movq %rdx, %r15
movl %esi, %r12d
movq %rdi, %r13
movl %esi, %ebx
testl %esi, %esi
jle 0x3f3a1
leaq (,%rbx,4), %rdx
movq %r13, %rdi
xorl %esi, %esi
callq 0x2110
leaq 0x58(%rsp), %r8
movl 0xc(%rsp), %eax
movl %eax, %ebp
testl %eax, %eax
jle 0x3f3c7
leaq (,%rbp,4), %rdx
movq %r15, %rdi
xorl %esi, %esi
callq 0x2110
leaq 0x58(%rsp), %r8
movslq (%r8), %rax
testq %rax, %rax
jle 0x3f4f5
movq 0x128(%rsp), %rcx
movq 0x50(%rsp), %rdx
movq 0x68(%r8), %rsi
movq 0x38(%r8), %rdi
movq 0x40(%r8), %r8
xorpd %xmm0, %xmm0
xorl %r9d, %r9d
xorps %xmm1, %xmm1
movss 0x29b4e(%rip), %xmm2    # 0x68f4c
ucomiss (%rsi,%r9,4), %xmm2
ja 0x3f4db
ucomiss (%rcx,%r9,4), %xmm1
jae 0x3f4db
movq (%rdi,%r9,8), %r10
xorps %xmm2, %xmm2
testl %r12d, %r12d
jle 0x3f43f
xorl %r11d, %r11d
movss (%r10,%r11,4), %xmm3
mulss (%rdx,%r11,4), %xmm3
cvtss2sd %xmm3, %xmm3
addsd %xmm3, %xmm2
incq %r11
cmpl %r11d, %ebx
jne 0x3f423
xorps %xmm3, %xmm3
cvtsd2ss %xmm2, %xmm3
movss %xmm3, (%r14,%r9,4)
xorps %xmm4, %xmm4
cvtss2sd (%rcx,%r9,4), %xmm4
movapd %xmm2, %xmm3
mulsd %xmm4, %xmm3
testl %r12d, %r12d
jle 0x3f493
xorl %r11d, %r11d
xorps %xmm5, %xmm5
cvtss2sd (%r10,%r11,4), %xmm5
xorps %xmm6, %xmm6
cvtss2sd (%r13,%r11,4), %xmm6
mulsd %xmm3, %xmm5
addsd %xmm6, %xmm5
cvtsd2ss %xmm5, %xmm5
movss %xmm5, (%r13,%r11,4)
incq %r11
cmpl %r11d, %ebx
jne 0x3f465
mulsd %xmm2, %xmm2
mulsd %xmm4, %xmm2
addsd %xmm2, %xmm0
cmpl $0x0, 0xc(%rsp)
jle 0x3f4e3
movq (%r8,%r9,8), %r10
xorl %r11d, %r11d
xorps %xmm2, %xmm2
cvtss2sd (%r10,%r11,4), %xmm2
xorps %xmm4, %xmm4
cvtss2sd (%r15,%r11,4), %xmm4
mulsd %xmm3, %xmm2
addsd %xmm4, %xmm2
cvtsd2ss %xmm2, %xmm2
movss %xmm2, (%r15,%r11,4)
incq %r11
cmpl %r11d, %ebp
jne 0x3f4ad
jmp 0x3f4e3
movl $0x0, (%r14,%r9,4)
incq %r9
cmpq %rax, %r9
jne 0x3f3f6
cvtsd2ss %xmm0, %xmm0
jmp 0x3f4f8
xorps %xmm0, %xmm0
movq 0x10(%rsp), %rax
movss %xmm0, (%rax)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq