// File: /workspace/github_c_makefile_star2_O3/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
movq %rcx, %r15
movsd %xmm0, 0x58(%rsp)
movq %rsi, 0x40(%rsp)
movq %rdi, 0x38(%rsp)
movq $0x0, (%rdi)
movslq 0xc0(%rsp), %rcx
testq %rcx, %rcx
jle 0xacfb
movq %r8, %r14
movq 0x190(%rsp), %r13
leaq 0xc0(%rsp), %rax
movq 0xc0(%rax), %rsi
movq 0x38(%rax), %rdi
movq %rdi, 0x30(%rsp)
movq 0x48(%rax), %rax
movq %rax, 0x28(%rsp)
movl %r9d, 0xc(%rsp)
movl %r9d, %r12d
movl 0x198(%rsp), %ebp
xorl %ebx, %ebx
xorps %xmm1, %xmm1
movsd 0x46650(%rip), %xmm3    # 0x51148
xorpd %xmm0, %xmm0
movsd %xmm0, (%rsp)
movq %rsi, 0x10(%rsp)
movq %rdx, 0x20(%rsp)
movq %rcx, 0x18(%rsp)
cmpl $0x0, (%rsi,%rbx,4)
je 0xaced
movss (%rdx,%rbx,4), %xmm0
ucomiss %xmm0, %xmm1
jae 0xaced
movapd %xmm3, %xmm4
testq %r14, %r14
je 0xab77
cmpl $0x0, 0xc(%rsp)
jle 0xab73
movq 0x30(%rsp), %rax
movq (%rax,%rbx,8), %rax
xorpd %xmm4, %xmm4
xorl %ecx, %ecx
movslq (%r14,%rcx,4), %rdx
movss (%rax,%rdx,4), %xmm1
movss (%r15,%rdx,4), %xmm2
mulss %xmm1, %xmm2
mulss %xmm1, %xmm2
xorps %xmm1, %xmm1
cvtss2sd %xmm2, %xmm1
addsd %xmm1, %xmm4
incq %rcx
cmpq %rcx, %r12
jne 0xab47
jmp 0xab77
xorpd %xmm4, %xmm4
movapd %xmm3, %xmm2
testq %r13, %r13
je 0xabc0
movapd %xmm3, %xmm2
cmpl $0x0, 0x198(%rsp)
jle 0xabc0
movq 0x28(%rsp), %rax
movq (%rax,%rbx,8), %rax
xorl %ecx, %ecx
movapd %xmm3, %xmm2
movslq (%r13,%rcx,4), %rdx
testq %rdx, %rdx
js 0xabb8
movss (%rax,%rdx,4), %xmm1
mulss %xmm1, %xmm1
cvtss2sd %xmm1, %xmm1
subsd %xmm1, %xmm2
incq %rcx
cmpq %rcx, %rbp
jne 0xab9d
cvtss2sd %xmm0, %xmm0
ucomisd 0x465ac(%rip), %xmm0    # 0x51178
movsd %xmm4, 0x68(%rsp)
movsd %xmm2, 0x60(%rsp)
jb 0xabe0
sqrtsd %xmm0, %xmm0
jmp 0xabed
callq 0x22a0
movsd 0x4655b(%rip), %xmm3    # 0x51148
movapd %xmm3, %xmm1
divsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
mulsd 0x58(%rsp), %xmm0
movapd %xmm0, 0x70(%rsp)
xorpd 0x4647c(%rip), %xmm0    # 0x51090
callq 0x22b0
movsd 0x46527(%rip), %xmm1    # 0x51148
ucomisd %xmm0, %xmm1
jbe 0xacc4
subsd %xmm0, %xmm1
movsd %xmm1, 0x50(%rsp)
movsd %xmm0, 0x48(%rsp)
movapd %xmm1, %xmm0
callq 0x2120
movsd 0x464fc(%rip), %xmm3    # 0x51148
movapd 0x70(%rsp), %xmm4
movsd 0x48(%rsp), %xmm5
mulsd %xmm4, %xmm5
mulsd 0x4650c(%rip), %xmm4    # 0x51170
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 (%rsp), %xmm0
addsd %xmm5, %xmm0
movsd %xmm0, (%rsp)
movapd %xmm3, %xmm0
subsd %xmm2, %xmm0
mulsd %xmm4, %xmm2
movq 0x38(%rsp), %rax
addsd (%rax), %xmm2
movsd %xmm2, (%rax)
mulsd %xmm4, %xmm0
movq 0x40(%rsp), %rax
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
jmp 0xacda
leaq 0x47837(%rip), %rdi     # 0x52502
movb $0x1, %al
callq 0x20f0
movsd 0x4646e(%rip), %xmm3    # 0x51148
movq 0x20(%rsp), %rdx
movq 0x18(%rsp), %rcx
movq 0x10(%rsp), %rsi
xorpd %xmm1, %xmm1
incq %rbx
cmpq %rcx, %rbx
jne 0xab10
jmp 0xad04
xorpd %xmm0, %xmm0
movsd %xmm0, (%rsp)
movsd (%rsp), %xmm0
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq