// File: /workspace/github_c_makefile_star2_O2/ugobas[P]tnm/main_tnm.c
// Function: Compute_entropy
double Compute_entropy(double *Free_Ene, double *Free_Ene_rigid,
		       struct Normal_Mode NM, float *sigma2,
		       double beta_omega, float *mass_coord,
		       int *Cart_interface, int N_Cart_inter,
		       int *rigid_inter, int N_rigid)
{
  double entropy=0; *Free_Ene=0;
  for(int i=0; i<NM.N; i++){
    if((NM.select[i]==0)||(sigma2[i]<=0))continue;
    double w_interface=1;
    if(Cart_interface){
      w_interface=0; float *xi=NM.Cart[i];
      for(int k=0; k<N_Cart_inter; k++){
	int j=Cart_interface[k]; w_interface+=mass_coord[j]*xi[j]*xi[j];
      }
    }
    double w_internal=1;
    if(rigid_inter){
      float *xi=NM.MW_Tors[i];
      for(int k=0; k<N_rigid; k++){
	int a=rigid_inter[k]; if(a>=0)w_internal-=xi[a]*xi[a];
      }
    }

    float omega=1./sqrt(sigma2[i]);
    double x=beta_omega*omega, f=exp(-x);
    if(f<1){
      double lf= log(1.-f), G=w_interface*(x/2+lf);
      entropy+=w_internal*w_interface*(-lf+x*f/(1.-f));
      (*Free_Ene)+=w_internal*G;
      (*Free_Ene_rigid)+=(1-w_internal)*G;
    }else{
      printf("WARNING, exp(-h/omega/kT)= %.2g\n", f);
    }
  }
  return(entropy);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movl %r9d, %ebx
movq %r8, %r14
movq %rcx, %r15
movsd %xmm0, 0x58(%rsp)
movq %rsi, 0x30(%rsp)
movq 0x190(%rsp), %r13
movl 0x198(%rsp), %ebp
movq %rdi, 0x28(%rsp)
andq $0x0, (%rdi)
movl 0xc0(%rsp), %eax
xorl %r12d, %r12d
testl %r9d, %r9d
cmovlel %r12d, %ebx
movq 0x180(%rsp), %rcx
testl %ebp, %ebp
cmovlel %r12d, %ebp
movq 0xf8(%rsp), %rsi
movq %rsi, 0x40(%rsp)
testl %eax, %eax
cmovlel %r12d, %eax
movq 0x108(%rsp), %rsi
movq %rsi, 0x38(%rsp)
xorps %xmm1, %xmm1
movsd 0x40af0(%rip), %xmm3    # 0x4b048
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
movq %rdx, 0x20(%rsp)
movq %rax, 0x18(%rsp)
movq %rcx, 0x10(%rsp)
cmpq %rax, %r12
je 0xa746
cmpl $0x0, (%rcx,%r12,4)
je 0xa73e
movss (%rdx,%r12,4), %xmm0
ucomiss %xmm0, %xmm1
jae 0xa73e
movapd %xmm3, %xmm4
testq %r14, %r14
je 0xa5d5
movq 0x40(%rsp), %rax
movq (%rax,%r12,8), %rax
xorpd %xmm4, %xmm4
xorl %ecx, %ecx
cmpq %rcx, %rbx
je 0xa5d5
movslq (%r14,%rcx,4), %rdx
movss (%rax,%rdx,4), %xmm1
movss (%r15,%rdx,4), %xmm2
mulss %xmm1, %xmm2
mulss %xmm1, %xmm2
cvtss2sd %xmm2, %xmm1
addsd %xmm1, %xmm4
incq %rcx
jmp 0xa5ac
movapd %xmm3, %xmm2
testq %r13, %r13
je 0xa612
movq 0x38(%rsp), %rax
movq (%rax,%r12,8), %rax
xorl %ecx, %ecx
movapd %xmm3, %xmm2
cmpq %rcx, %rbp
je 0xa612
movslq (%r13,%rcx,4), %rdx
testq %rdx, %rdx
js 0xa60d
movss (%rax,%rdx,4), %xmm1
mulss %xmm1, %xmm1
cvtss2sd %xmm1, %xmm1
subsd %xmm1, %xmm2
incq %rcx
jmp 0xa5ed
cvtss2sd %xmm0, %xmm0
ucomisd 0x40a32(%rip), %xmm0    # 0x4b050
movsd %xmm4, 0x68(%rsp)
movsd %xmm2, 0x60(%rsp)
jb 0xa632
sqrtsd %xmm0, %xmm0
jmp 0xa63f
callq 0x2290
movsd 0x40a09(%rip), %xmm3    # 0x4b048
movapd %xmm3, %xmm1
divsd %xmm0, %xmm1
cvtsd2ss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
mulsd 0x58(%rsp), %xmm0
movapd %xmm0, 0x70(%rsp)
xorpd 0x40a5d(%rip), %xmm0    # 0x4b0c0
callq 0x22a0
movsd 0x409d8(%rip), %xmm1    # 0x4b048
ucomisd %xmm0, %xmm1
jbe 0xa715
subsd %xmm0, %xmm1
movsd %xmm1, 0x50(%rsp)
movsd %xmm0, 0x48(%rsp)
movapd %xmm1, %xmm0
callq 0x2120
movsd 0x409ad(%rip), %xmm3    # 0x4b048
movapd 0x70(%rsp), %xmm4
movsd 0x48(%rsp), %xmm5
mulsd %xmm4, %xmm5
mulsd 0x409bd(%rip), %xmm4    # 0x4b070
addsd %xmm0, %xmm4
movsd 0x68(%rsp), %xmm1
mulsd %xmm1, %xmm4
movsd 0x60(%rsp), %xmm2
mulsd %xmm2, %xmm1
divsd 0x50(%rsp), %xmm5
subsd %xmm0, %xmm5
mulsd %xmm1, %xmm5
movsd 0x8(%rsp), %xmm0
addsd %xmm5, %xmm0
movsd %xmm0, 0x8(%rsp)
movapd %xmm3, %xmm0
subsd %xmm2, %xmm0
mulsd %xmm4, %xmm2
movq 0x28(%rsp), %rax
addsd (%rax), %xmm2
movsd %xmm2, (%rax)
mulsd %xmm4, %xmm0
movq 0x30(%rsp), %rax
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
jmp 0xa72b
leaq 0x41d3e(%rip), %rdi     # 0x4c45a
movb $0x1, %al
callq 0x20f0
movsd 0x4091d(%rip), %xmm3    # 0x4b048
movq 0x20(%rsp), %rdx
movq 0x18(%rsp), %rax
movq 0x10(%rsp), %rcx
xorpd %xmm1, %xmm1
incq %r12
jmp 0xa571
movsd 0x8(%rsp), %xmm0
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq