// File: /workspace/github_c_makefile_star2_O1/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 $0x28, %rsp
movq %r9, 0x18(%rsp)
movq %rcx, 0x20(%rsp)
movl %edx, %ebp
movq %rsi, %r15
movq %rdi, %r12
cmpl $0x0, 0x5dd77(%rip)     # 0x7928c
jne 0x1b531
movl %r8d, %r9d
movl 0x60(%rsp), %esi
movq 0x18(%rsp), %rdi
movq %r12, %rdx
movq %r15, %rcx
movl %ebp, %r8d
callq 0x1cbc5
cmpl $0x0, 0x5dd84(%rip)     # 0x792bc
xorps %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
movsd %xmm0, 0x10(%rsp)
jle 0x1b671
movsd %xmm0, 0x10(%rsp)
movl $0x4, %r13d
xorl %ebx, %ebx
movsd %xmm0, 0x8(%rsp)
movq 0x5dd58(%rip), %rax     # 0x792c0
movslq -0x4(%rax,%r13), %rcx
movl %ecx, 0x4(%rsp)
movslq (%rax,%r13), %rax
movl %eax, (%rsp)
movq 0x5dd51(%rip), %rdx     # 0x792d0
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 0x4(%rsp), %rdx
movq %rsp, %rcx
movl %r14d, %r8d
movl %ebp, %r9d
callq 0x1c992
leaq 0x4daaf(%rip), %rax     # 0x69068
ucomiss (%rax), %xmm0
jae 0x1b657
xorps %xmm1, %xmm1
ucomiss %xmm0, %xmm1
jae 0x1b864
testl %r14d, %r14d
js 0x1b5fa
imulq $0xc8, %r14, %rdi
addq 0x18(%rsp), %rdi
callq 0x1ccef
cvtss2sd %xmm0, %xmm0
movsd 0x10(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
jmp 0x1b657
movslq 0x4(%rsp), %rax
imulq $0x70, %rax, %rax
movslq 0x64(%r15,%rax), %rax
shlq $0x5, %rax
movq 0x20(%rsp), %rdx
movswq 0x14(%rdx,%rax), %rax
movslq (%rsp), %rcx
imulq $0x70, %rcx, %rcx
movslq 0x64(%r15,%rcx), %rcx
shlq $0x5, %rcx
movswq 0x14(%rdx,%rcx), %rcx
imulq $0xc8, %rcx, %rdi
movq 0x68(%rsp), %rcx
addq (%rcx,%rax,8), %rdi
callq 0x1ccef
cvtss2sd %xmm0, %xmm0
movsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
incq %rbx
movslq 0x5dc5b(%rip), %rax     # 0x792bc
addq $0xc8, %r13
cmpq %rax, %rbx
jl 0x1b561
movl 0x80(%rsp), %edx
xorpd %xmm5, %xmm5
xorpd %xmm4, %xmm4
xorpd %xmm3, %xmm3
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
xorps %xmm0, %xmm0
testl %edx, %edx
xorpd %xmm10, %xmm10
jle 0x1b733
movq 0x88(%rsp), %rax
movq 0x78(%rsp), %rcx
movl %edx, %edx
xorl %esi, %esi
leaq 0x3bd2c(%rip), %rdi     # 0x573e0
movsd (%rax,%rsi,8), %xmm6
mulsd %xmm6, %xmm6
cvtsd2ss %xmm6, %xmm6
movzbl (%rcx), %r8d
leal -0x66(%r8), %r9d
cmpl $0xe, %r9d
ja 0x1b6e4
movslq (%rdi,%r9,4), %r8
addq %rdi, %r8
jmpq *%r8
cvtss2sd %xmm6, %xmm6
addsd %xmm6, %xmm10
jmp 0x1b724
cmpl $0x61, %r8d
jne 0x1b724
cvtss2sd %xmm6, %xmm6
addsd %xmm6, %xmm1
jmp 0x1b724
cvtss2sd %xmm6, %xmm6
addsd %xmm6, %xmm4
jmp 0x1b724
cvtss2sd %xmm6, %xmm6
addsd %xmm6, %xmm0
jmp 0x1b724
cvtss2sd %xmm6, %xmm6
addsd %xmm6, %xmm5
jmp 0x1b724
cvtss2sd %xmm6, %xmm6
addsd %xmm6, %xmm2
jmp 0x1b724
cvtss2sd %xmm6, %xmm6
addsd %xmm6, %xmm3
addq $0x158, %rcx            # imm = 0x158
incq %rsi
cmpq %rsi, %rdx
jne 0x1b6b4
leaq 0x4d966(%rip), %rax     # 0x690a0
movsd (%rax), %xmm6
mulsd %xmm6, %xmm10
leaq 0x4d94e(%rip), %rax     # 0x69098
movsd (%rax), %xmm8
mulsd %xmm5, %xmm8
addsd %xmm10, %xmm8
xorpd %xmm7, %xmm7
cmpneqsd %xmm7, %xmm5
movapd %xmm5, %xmm9
andnpd %xmm10, %xmm9
andpd %xmm8, %xmm5
orpd %xmm9, %xmm5
leaq 0x4d913(%rip), %rax     # 0x69090
movsd (%rax), %xmm8
mulsd %xmm4, %xmm8
addsd %xmm5, %xmm8
cmpneqsd %xmm7, %xmm4
movapd %xmm4, %xmm9
andnpd %xmm5, %xmm9
andpd %xmm8, %xmm4
orpd %xmm9, %xmm4
leaq 0x4d8fc(%rip), %rax     # 0x690a8
movsd (%rax), %xmm5
mulsd %xmm3, %xmm5
addsd %xmm4, %xmm5
cmpneqsd %xmm7, %xmm3
movapd %xmm3, %xmm8
andnpd %xmm4, %xmm8
andpd %xmm5, %xmm3
orpd %xmm8, %xmm3
leaq 0x4d8e1(%rip), %rax     # 0x690b8
movsd (%rax), %xmm4
mulsd %xmm2, %xmm4
addsd %xmm3, %xmm4
cmpneqsd %xmm7, %xmm2
movapd %xmm2, %xmm5
andnpd %xmm3, %xmm5
andpd %xmm4, %xmm2
orpd %xmm5, %xmm2
leaq 0x4d8b1(%rip), %rax     # 0x690b0
movsd (%rax), %xmm3
mulsd %xmm1, %xmm3
addsd %xmm2, %xmm3
cmpneqsd %xmm7, %xmm1
movapd %xmm1, %xmm4
andnpd %xmm2, %xmm4
andpd %xmm3, %xmm1
orpd %xmm4, %xmm1
mulsd %xmm0, %xmm6
addsd %xmm1, %xmm6
cmpneqsd %xmm7, %xmm0
movapd %xmm0, %xmm2
andnpd %xmm1, %xmm2
andpd %xmm6, %xmm0
orpd %xmm2, %xmm0
movsd 0x8(%rsp), %xmm1
addsd 0x10(%rsp), %xmm1
mulsd 0x35807(%rip), %xmm0    # 0x51058
addsd %xmm1, %xmm0
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x4(%rsp), %esi
movl (%rsp), %edx
cvtss2sd %xmm0, %xmm0
leaq 0x3c0d9(%rip), %rdi     # 0x5794f
movl %r14d, %ecx
movb $0x1, %al
callq 0x20f0
movl $0x8, %edi
callq 0x2270