// File: /workspace/github_c_makefile_star2_O2/ugobas[P]tnm/anharmonic_tnm.c
// Function: Energy_anharmonic
double Energy_anharmonic(float *r, atom *atoms, int natoms,
			 struct residue *seq, int nres,
			 struct interaction *Int_list, int N_int,
			 struct interaction **Int_KB, int NA,
			 struct axe *axe, int naxes,
			 double *delta_phi)
{
  if(INI_ENERGY==0){
    Initialize_energy(Int_list, N_int, r, atoms, natoms, nres);
  }

  double E_nat=0, E_nonat=0;
  for(int i=0; i<N_int_all; i++){
    int i1=Int_list_all[i].i1, i2=Int_list_all[i].i2;
    int n=nat_res1_res2[atoms[i1].res][atoms[i2].res];
    float d=Min_res_dist(r, atoms, &i1, &i2, n, natoms);
    if(d>=C_THR)continue;
    if(d<=0){
      printf("ERROR, d(%d,%d)= %.2g n=%d\n", i1, i2, d, n);
      exit(8);
    }
    if(n>=0){
      E_nat+=Compute_V(Int_list+n, d); //-Int_list[n].E_min;
    }else{
      int a=seq[atoms[i1].res].i_aa, b=seq[atoms[i2].res].i_aa;
      E_nonat+=Compute_V(Int_KB[a]+b, d); //-Int_KB[a][b].E_min;
    }
  }

  // Compute_torsional energy
  double E_phi=0, E_psi=0, E_omg=0, E_chi=0, E_BA=0, E_BL=0, E_BT=0;
  struct axe *ax=axe;
  for(int i=0; i<naxes; i++){
    float d2=delta_phi[i]*delta_phi[i];
    if(ax->type=='f'){E_phi+=d2;}
    else if(ax->type=='p'){E_psi+=d2;}
    else if(ax->type=='l'){E_BL+=d2;}
    else if(ax->type=='a'){E_BA+=d2;}
    else if(ax->type=='t'){E_BT+=d2;}
    else if(ax->type=='o'){E_omg+=d2;}
    else if(ax->type=='s'){E_chi+=d2;}
    ax++;
  }
  double E_tors=K_PHI*E_phi;
  if(E_psi)E_tors+=K_PSI*E_psi;
  if(E_omg)E_tors+=K_OMEGA*E_omg;
  if(E_chi)E_tors+=K_CHI*E_chi;
  if(E_BL)E_tors+=K_BL*E_BL;
  if(E_BA)E_tors+=K_BA*E_BA;
  if(E_BT)E_tors+=K_PHI*E_BT;
  return(E_nat+E_nonat+0.5*E_tors);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r9, 0x28(%rsp)
movq %rcx, 0x30(%rsp)
movl %edx, 0x14(%rsp)
movq %rsi, %r15
movq %rdi, %r12
cmpl $0x0, 0x5acdc(%rip)     # 0x7428c
jne 0x195ce
movl %r8d, %r9d
movl 0x70(%rsp), %esi
movq 0x28(%rsp), %rdi
movq %r12, %rdx
movq %r15, %rcx
movl 0x14(%rsp), %r8d
callq 0x1aaea
movq 0x88(%rsp), %r13
xorpd %xmm0, %xmm0
movsd %xmm0, 0x18(%rsp)
pushq $0x4
popq %rbx
xorl %ebp, %ebp
movsd %xmm0, 0x20(%rsp)
movslq 0x5acca(%rip), %rax     # 0x742bc
cmpq %rax, %rbp
jge 0x19706
movq 0x5acbe(%rip), %rax     # 0x742c0
movslq -0x4(%rax,%rbx), %rcx
movl %ecx, 0x10(%rsp)
movslq (%rax,%rbx), %rax
movl %eax, 0xc(%rsp)
movq 0x5acb6(%rip), %rdx     # 0x742d0
imulq $0x70, %rcx, %rcx
movslq 0x64(%r15,%rcx), %rcx
movq (%rdx,%rcx,8), %rcx
imulq $0x70, %rax, %rax
movslq 0x64(%r15,%rax), %rax
movl (%rcx,%rax,4), %r14d
movq %r12, %rdi
movq %r15, %rsi
leaq 0x10(%rsp), %rdx
leaq 0xc(%rsp), %rcx
movl %r14d, %r8d
movl 0x14(%rsp), %r9d
callq 0x1a8f8
leaq 0x4aa10(%rip), %rax     # 0x64068
ucomiss (%rax), %xmm0
jae 0x196f7
xorps %xmm1, %xmm1
ucomiss %xmm0, %xmm1
jae 0x198db
testl %r14d, %r14d
js 0x19699
imulq $0xc8, %r14, %rdi
addq 0x28(%rsp), %rdi
callq 0x1ac14
cvtss2sd %xmm0, %xmm0
movsd 0x20(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x20(%rsp)
jmp 0x196f7
movslq 0x10(%rsp), %rax
imulq $0x70, %rax, %rax
movslq 0x64(%r15,%rax), %rax
shlq $0x5, %rax
movq 0x30(%rsp), %rdx
movswq 0x14(%rdx,%rax), %rax
movslq 0xc(%rsp), %rcx
imulq $0x70, %rcx, %rcx
movslq 0x64(%r15,%rcx), %rcx
shlq $0x5, %rcx
movswq 0x14(%rdx,%rcx), %rcx
imulq $0xc8, %rcx, %rdi
movq 0x78(%rsp), %rcx
addq (%rcx,%rax,8), %rdi
callq 0x1ac14
cvtss2sd %xmm0, %xmm0
movsd 0x18(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x18(%rsp)
incq %rbp
addq $0xc8, %rbx
jmp 0x195eb
xorl %eax, %eax
movl 0x90(%rsp), %r8d
testl %r8d, %r8d
cmovlel %eax, %r8d
xorpd %xmm6, %xmm6
leaq 0x37bde(%rip), %rcx     # 0x51300
xorpd %xmm5, %xmm5
xorpd %xmm4, %xmm4
xorpd %xmm3, %xmm3
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
xorpd %xmm0, %xmm0
movq 0x98(%rsp), %rdi
cmpq %rax, %r8
je 0x197ab
movsd (%rdi,%rax,8), %xmm7
mulsd %xmm7, %xmm7
cvtsd2ss %xmm7, %xmm7
movzbl (%r13), %edx
leal -0x66(%rdx), %esi
cmpl $0xe, %esi
ja 0x19774
movslq (%rcx,%rsi,4), %rdx
addq %rcx, %rdx
cvtss2sd %xmm7, %xmm7
jmpq *%rdx
addsd %xmm7, %xmm6
jmp 0x1979f
cmpl $0x61, %edx
jne 0x1979f
cvtss2sd %xmm7, %xmm7
addsd %xmm7, %xmm1
jmp 0x1979f
addsd %xmm7, %xmm4
jmp 0x1979f
addsd %xmm7, %xmm0
jmp 0x1979f
addsd %xmm7, %xmm5
jmp 0x1979f
addsd %xmm7, %xmm2
jmp 0x1979f
addsd %xmm7, %xmm3
addq $0x158, %r13            # imm = 0x158
incq %rax
jmp 0x19742
leaq 0x4a8ee(%rip), %rax     # 0x640a0
movsd (%rax), %xmm7
mulsd %xmm7, %xmm6
leaq 0x4a8d7(%rip), %rax     # 0x64098
movsd (%rax), %xmm9
mulsd %xmm5, %xmm9
addsd %xmm6, %xmm9
xorpd %xmm8, %xmm8
cmpneqsd %xmm8, %xmm5
movapd %xmm5, %xmm10
andnpd %xmm6, %xmm10
andpd %xmm9, %xmm5
orpd %xmm10, %xmm5
leaq 0x4a89a(%rip), %rax     # 0x64090
movsd (%rax), %xmm6
mulsd %xmm4, %xmm6
addsd %xmm5, %xmm6
cmpneqsd %xmm8, %xmm4
movapd %xmm4, %xmm9
andnpd %xmm5, %xmm9
andpd %xmm6, %xmm4
orpd %xmm9, %xmm4
leaq 0x4a886(%rip), %rax     # 0x640a8
movsd (%rax), %xmm5
mulsd %xmm3, %xmm5
addsd %xmm4, %xmm5
cmpneqsd %xmm8, %xmm3
movapd %xmm3, %xmm6
andnpd %xmm4, %xmm6
andpd %xmm5, %xmm3
orpd %xmm6, %xmm3
leaq 0x4a86d(%rip), %rax     # 0x640b8
movsd (%rax), %xmm4
mulsd %xmm2, %xmm4
addsd %xmm3, %xmm4
cmpneqsd %xmm8, %xmm2
movapd %xmm2, %xmm5
andnpd %xmm3, %xmm5
andpd %xmm4, %xmm2
orpd %xmm5, %xmm2
leaq 0x4a83c(%rip), %rax     # 0x640b0
movsd (%rax), %xmm3
mulsd %xmm1, %xmm3
addsd %xmm2, %xmm3
cmpneqsd %xmm8, %xmm1
movapd %xmm1, %xmm4
andnpd %xmm2, %xmm4
andpd %xmm3, %xmm1
orpd %xmm4, %xmm1
mulsd %xmm0, %xmm7
addsd %xmm1, %xmm7
cmpneqsd %xmm8, %xmm0
movapd %xmm0, %xmm2
andnpd %xmm1, %xmm2
andpd %xmm7, %xmm0
orpd %xmm2, %xmm0
movsd 0x18(%rsp), %xmm1
addsd 0x20(%rsp), %xmm1
mulsd 0x317a8(%rip), %xmm0    # 0x4b070
addsd %xmm1, %xmm0
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x10(%rsp), %esi
movl 0xc(%rsp), %edx
cvtss2sd %xmm0, %xmm0
leaq 0x37f81(%rip), %rdi     # 0x5186f
movl %r14d, %ecx
movb $0x1, %al
callq 0x20f0
pushq $0x8
popq %rdi
callq 0x2270