// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xb0, %rsp
movl 0xe8(%rbp), %eax
movq 0xe0(%rbp), %rax
leaq 0x10(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movsd %xmm0, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movl %r9d, -0x34(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x40(%rbp)
movq -0x8(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
movl $0x0, -0x44(%rbp)
movq -0xa8(%rbp), %rcx
movl -0x44(%rbp), %eax
cmpl (%rcx), %eax
jge 0xd267
movq -0xa8(%rbp), %rax
movq 0xc0(%rax), %rax
movslq -0x44(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
je 0xcf95
movq -0x18(%rbp), %rax
movslq -0x44(%rbp), %rcx
xorps %xmm0, %xmm0
ucomiss (%rax,%rcx,4), %xmm0
jb 0xcf9a
jmp 0xd259
movsd 0x690a6(%rip), %xmm0    # 0x76048
movsd %xmm0, -0x50(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0xd02c
movq -0xa8(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, -0x50(%rbp)
movq 0x38(%rax), %rax
movslq -0x44(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x58(%rbp)
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0xd02a
movq -0x30(%rbp), %rax
movslq -0x5c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x60(%rbp)
movq -0x28(%rbp), %rax
movslq -0x60(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
movq -0x58(%rbp), %rax
movslq -0x60(%rbp), %rcx
mulss (%rax,%rcx,4), %xmm0
movq -0x58(%rbp), %rax
movslq -0x60(%rbp), %rcx
mulss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
addsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0xcfd4
jmp 0xd02c
movsd 0x69014(%rip), %xmm0    # 0x76048
movsd %xmm0, -0x68(%rbp)
cmpq $0x0, 0xe0(%rbp)
je 0xd0be
movq -0xa8(%rbp), %rax
movq 0x48(%rax), %rax
movslq -0x44(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x70(%rbp)
movl $0x0, -0x74(%rbp)
movl -0x74(%rbp), %eax
cmpl 0xe8(%rbp), %eax
jge 0xd0bc
movq 0xe0(%rbp), %rax
movslq -0x74(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x78(%rbp)
cmpl $0x0, -0x78(%rbp)
jl 0xd0af
movq -0x70(%rbp), %rax
movslq -0x78(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
movq -0x70(%rbp), %rax
movslq -0x78(%rbp), %rcx
mulss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm1
movsd -0x68(%rbp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, -0x68(%rbp)
jmp 0xd0b1
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0xd061
jmp 0xd0be
movq -0x18(%rbp), %rax
movslq -0x44(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x1220
movaps %xmm0, %xmm1
movsd 0x68f69(%rip), %xmm0    # 0x76048
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x7c(%rbp)
movsd -0x20(%rbp), %xmm0
movss -0x7c(%rbp), %xmm1
cvtss2sd %xmm1, %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0x88(%rbp)
movsd -0x88(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
callq 0x1230
movsd %xmm0, -0x90(%rbp)
movsd 0x68f0e(%rip), %xmm0    # 0x76048
ucomisd -0x90(%rbp), %xmm0
jbe 0xd241
movsd 0x68ef8(%rip), %xmm0    # 0x76048
subsd -0x90(%rbp), %xmm0
callq 0x10f0
movsd %xmm0, -0x98(%rbp)
movsd -0x50(%rbp), %xmm0
movsd -0x88(%rbp), %xmm1
movsd 0x68ede(%rip), %xmm2    # 0x76058
divsd %xmm2, %xmm1
addsd -0x98(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0xa0(%rbp)
movsd -0x68(%rbp), %xmm0
mulsd -0x50(%rbp), %xmm0
movsd -0x98(%rbp), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm2
movsd -0x88(%rbp), %xmm1
mulsd -0x90(%rbp), %xmm1
movsd 0x68e75(%rip), %xmm3    # 0x76048
subsd -0x90(%rbp), %xmm3
divsd %xmm3, %xmm1
addsd %xmm1, %xmm2
movsd -0x40(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x68(%rbp), %xmm0
movsd -0xa0(%rbp), %xmm2
movq -0x8(%rbp), %rax
movsd (%rax), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rax)
movsd 0x68e2a(%rip), %xmm0    # 0x76048
subsd -0x68(%rbp), %xmm0
movsd -0xa0(%rbp), %xmm2
movq -0x10(%rbp), %rax
movsd (%rax), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rax)
jmp 0xd257
movsd -0x90(%rbp), %xmm0
leaq 0x6aa9b(%rip), %rdi     # 0x77ceb
movb $0x1, %al
callq 0x10d0
jmp 0xd259
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0xcf5a
movsd -0x40(%rbp), %xmm0
addq $0xb0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)