// File: /workspace/github_c_makefile_star2_O0/ugobas[P]tnm/anharmonic_tnm.c
// Function: Energy_anharmonic_new
float Energy_anharmonic_new(struct inter_new *New_inter,
			    int *N_int_new, int N_int_max,
			    int *nc_nat, int *nc_nonat,
			    float *Ene_nat_attr, float *Ene_nat_rep,
			    float *Ene_nonat,
			    float *coord, 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, int K_tors, int sec_der)
{

  if(INI_ENERGY==0){
    Initialize_energy(Int_list, N_int, coord, atoms, natoms, nres);
    INI_ENERGY=1;
  }

  *N_int_new=0; *nc_nat=0; *nc_nonat=0;
  *Ene_nat_attr=0; *Ene_nat_rep=0; *Ene_nonat=0;
  for(int i=0; i<N_int_all; i++){
    int i1=Int_list_all[i].i1, i2=Int_list_all[i].i2;
    float d=Min_res_dist(coord, atoms, &i1, &i2, -1, natoms);
    if(d>=C_THR)continue;
    int n=nat_res1_res2[atoms[i1].res][atoms[i2].res];
    if(d<=0){
      printf("ERROR, d(%d,%d)= %.2g n=%d\n", i1, i2, d, n);
      exit(8);
    }

    struct interaction *Int_k;
    float f0;
    if(n>=0){
      Int_k=Int_list+n;
      f0=Compute_V(Int_k, d);
      if(f0>0){(*Ene_nat_rep)+=f0;}
      else{(*Ene_nat_attr)+=f0;}
      (*nc_nat)++;
      if(f0< (Int_k->E_min-0.00001) || n>=N_int){
	printf("ERROR in Energy_anharmonic_new, inter. %d (nat=%d/%d) "
	       "res1=%d res2=%d d=%.4g d0= %.4g V(d)=%.4g < V(d0)=%.4g\n",
	       i,n,N_int,atoms[i1].res,atoms[i2].res,d,Int_k->r0,
	       f0,Int_k->E_min);
	exit(8);
      }

    }else{
      int a=seq[atoms[i1].res].i_aa, b=seq[atoms[i2].res].i_aa;
      Int_k=Int_KB[a]+b;
      f0=Compute_V(Int_k, d);
      (*Ene_nonat)+=f0; //-Int_KB[a][b].E_min;
      (*nc_nonat)++;
    }
    if(New_inter){
      struct inter_new *Int=New_inter+(*N_int_new);
      Int->i1=i1; Int->i2=i2;
      Int->nat=n;
      Int->f0=f0;
      Int->r=d;
      Int->f1=Compute_V1(Int_k, d);
      float *r1=coord+3*i1, *r2=coord+3*i2;
      for(int j=0; j<3; j++){
	Int->rj[j]=r2[j];
	Int->rji[j]=r2[j]-r1[j];
      }
      Vector_product(Int->crij, r1, r2);
      if(sec_der){
	Int->f2=Compute_V2(Int_k, d, 1); // do not assume it is minimum!
      }
    }
    (*N_int_new)++;
    if(*N_int_new > N_int_max){
      printf("ERROR, > %d interactions in Energy_anharmonic_new "
	     "Increase N_int_max\n", *N_int_new); exit(8);
    }
  }
  if(K_tors==0){return(*Ene_nat_attr+*Ene_nat_rep+*Ene_nonat);}

  // 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(*Ene_nat_attr+*Ene_nat_rep+*Ene_nonat+0.5*E_tors);

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movl 0x88(%rbp), %eax
movl 0x80(%rbp), %eax
movq 0x78(%rbp), %rax
movl 0x70(%rbp), %eax
movq 0x68(%rbp), %rax
movl 0x60(%rbp), %eax
movq 0x58(%rbp), %rax
movl 0x50(%rbp), %eax
movq 0x48(%rbp), %rax
movl 0x40(%rbp), %eax
movq 0x38(%rbp), %rax
movl 0x30(%rbp), %eax
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
cmpl $0x0, 0x74524(%rip)     # 0x9c24c
jne 0x27d50
movq 0x48(%rbp), %rdi
movl 0x50(%rbp), %esi
movq 0x20(%rbp), %rdx
movq 0x28(%rbp), %rcx
movl 0x30(%rbp), %r8d
movl 0x40(%rbp), %r9d
callq 0x27680
movl $0x1, 0x744fc(%rip)     # 0x9c24c
movq -0x18(%rbp), %rax
movl $0x0, (%rax)
movq -0x28(%rbp), %rax
movl $0x0, (%rax)
movq -0x30(%rbp), %rax
movl $0x0, (%rax)
movq -0x38(%rbp), %rax
xorps %xmm0, %xmm0
movss %xmm0, (%rax)
movq 0x10(%rbp), %rax
xorps %xmm0, %xmm0
movss %xmm0, (%rax)
movq 0x18(%rbp), %rax
xorps %xmm0, %xmm0
movss %xmm0, (%rax)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl 0x744dd(%rip), %eax     # 0x9c27c
jge 0x281b9
movq 0x744d4(%rip), %rax     # 0x9c280
movslq -0x3c(%rbp), %rcx
imulq $0xc8, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
movl %eax, -0x40(%rbp)
movq 0x744ba(%rip), %rax     # 0x9c280
movslq -0x3c(%rbp), %rcx
imulq $0xc8, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, -0x44(%rbp)
movq 0x20(%rbp), %rdi
movq 0x28(%rbp), %rsi
movl 0x30(%rbp), %r9d
leaq -0x40(%rbp), %rdx
leaq -0x44(%rbp), %rcx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
callq 0x27350
movss %xmm0, -0x48(%rbp)
movss -0x48(%rbp), %xmm0
leaq 0x6421e(%rip), %rax     # 0x8c028
ucomiss (%rax), %xmm0
jb 0x27e14
jmp 0x281ab
movq 0x74475(%rip), %rax     # 0x9c290
movq 0x28(%rbp), %rcx
movslq -0x40(%rbp), %rdx
imulq $0x70, %rdx, %rdx
addq %rdx, %rcx
movslq 0x64(%rcx), %rcx
movq (%rax,%rcx,8), %rax
movq 0x28(%rbp), %rcx
movslq -0x44(%rbp), %rdx
imulq $0x70, %rdx, %rdx
addq %rdx, %rcx
movslq 0x64(%rcx), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x4c(%rbp)
xorps %xmm0, %xmm0
ucomiss -0x48(%rbp), %xmm0
jb 0x27e7e
movl -0x40(%rbp), %esi
movl -0x44(%rbp), %edx
movss -0x48(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movl -0x4c(%rbp), %ecx
leaq 0x54bbb(%rip), %rdi     # 0x7ca28
movb $0x1, %al
callq 0x10d0
movl $0x8, %edi
callq 0x1210
cmpl $0x0, -0x4c(%rbp)
jl 0x27f8f
movq 0x48(%rbp), %rax
movslq -0x4c(%rbp), %rcx
imulq $0xc8, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
movss -0x48(%rbp), %xmm0
callq 0x27810
movss %xmm0, -0x5c(%rbp)
movss -0x5c(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x27ed1
movss -0x5c(%rbp), %xmm0
movq 0x10(%rbp), %rax
addss (%rax), %xmm0
movss %xmm0, (%rax)
jmp 0x27ee2
movss -0x5c(%rbp), %xmm0
movq -0x38(%rbp), %rax
addss (%rax), %xmm0
movss %xmm0, (%rax)
movq -0x28(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movss -0x5c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm1
movq -0x58(%rbp), %rax
movsd 0xb8(%rax), %xmm0
movsd 0x5451e(%rip), %xmm2    # 0x7c428
subsd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
ja 0x27f1c
movl -0x4c(%rbp), %eax
cmpl 0x50(%rbp), %eax
jl 0x27f8a
movl -0x3c(%rbp), %esi
movl -0x4c(%rbp), %edx
movl 0x50(%rbp), %ecx
movq 0x28(%rbp), %rax
movslq -0x40(%rbp), %rdi
imulq $0x70, %rdi, %rdi
addq %rdi, %rax
movl 0x64(%rax), %r8d
movq 0x28(%rbp), %rax
movslq -0x44(%rbp), %rdi
imulq $0x70, %rdi, %rdi
addq %rdi, %rax
movl 0x64(%rax), %r9d
movss -0x48(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movq -0x58(%rbp), %rax
movsd 0x20(%rax), %xmm1
movss -0x5c(%rbp), %xmm2
cvtss2sd %xmm2, %xmm2
movq -0x58(%rbp), %rax
movsd 0xb8(%rax), %xmm3
leaq 0x54acb(%rip), %rdi     # 0x7ca44
movb $0x4, %al
callq 0x10d0
movl $0x8, %edi
callq 0x1210
jmp 0x28026
movq 0x38(%rbp), %rax
movq 0x28(%rbp), %rcx
movslq -0x40(%rbp), %rdx
imulq $0x70, %rdx, %rdx
addq %rdx, %rcx
movslq 0x64(%rcx), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movswl 0x14(%rax), %eax
movl %eax, -0x60(%rbp)
movq 0x38(%rbp), %rax
movq 0x28(%rbp), %rcx
movslq -0x44(%rbp), %rdx
imulq $0x70, %rdx, %rdx
addq %rdx, %rcx
movslq 0x64(%rcx), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movswl 0x14(%rax), %eax
movl %eax, -0x64(%rbp)
movq 0x58(%rbp), %rax
movslq -0x60(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x64(%rbp), %rcx
imulq $0xc8, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
movss -0x48(%rbp), %xmm0
callq 0x27810
movss %xmm0, -0x5c(%rbp)
movss -0x5c(%rbp), %xmm0
movq 0x18(%rbp), %rax
addss (%rax), %xmm0
movss %xmm0, (%rax)
movq -0x30(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
cmpq $0x0, -0x10(%rbp)
je 0x28175
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq (%rcx), %rcx
imulq $0x44, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movl -0x40(%rbp), %ecx
movq -0x70(%rbp), %rax
movl %ecx, (%rax)
movl -0x44(%rbp), %ecx
movq -0x70(%rbp), %rax
movl %ecx, 0x4(%rax)
movl -0x4c(%rbp), %ecx
movq -0x70(%rbp), %rax
movl %ecx, 0x40(%rax)
movss -0x5c(%rbp), %xmm0
movq -0x70(%rbp), %rax
movss %xmm0, 0x8(%rax)
movss -0x48(%rbp), %xmm0
movq -0x70(%rbp), %rax
movss %xmm0, 0x18(%rax)
movq -0x58(%rbp), %rdi
movss -0x48(%rbp), %xmm0
callq 0x285e0
movq -0x70(%rbp), %rax
movss %xmm0, 0xc(%rax)
movq 0x20(%rbp), %rax
imull $0x3, -0x40(%rbp), %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x78(%rbp)
movq 0x20(%rbp), %rax
imull $0x3, -0x44(%rbp), %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x80(%rbp)
movl $0x0, -0x84(%rbp)
cmpl $0x3, -0x84(%rbp)
jge 0x28139
movq -0x80(%rbp), %rax
movslq -0x84(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
movq -0x70(%rbp), %rax
movslq -0x84(%rbp), %rcx
movss %xmm0, 0x1c(%rax,%rcx,4)
movq -0x80(%rbp), %rax
movslq -0x84(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
movq -0x78(%rbp), %rax
movslq -0x84(%rbp), %rcx
subss (%rax,%rcx,4), %xmm0
movq -0x70(%rbp), %rax
movslq -0x84(%rbp), %rcx
movss %xmm0, 0x28(%rax,%rcx,4)
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0x280cd
movq -0x70(%rbp), %rdi
addq $0x34, %rdi
movq -0x78(%rbp), %rsi
movq -0x80(%rbp), %rdx
callq 0x149c0
cmpl $0x0, 0x88(%rbp)
je 0x28173
movq -0x58(%rbp), %rdi
movss -0x48(%rbp), %xmm0
movl $0x1, %esi
callq 0x28af0
movq -0x70(%rbp), %rax
movss %xmm0, 0x10(%rax)
jmp 0x28175
movq -0x18(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
movl (%rax), %eax
cmpl -0x1c(%rbp), %eax
jle 0x281a9
movq -0x18(%rbp), %rax
movl (%rax), %esi
leaq 0x5491a(%rip), %rdi     # 0x7cab2
movb $0x0, %al
callq 0x10d0
movl $0x8, %edi
callq 0x1210
jmp 0x281ab
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x27d96
cmpl $0x0, 0x80(%rbp)
jne 0x281e4
movq -0x38(%rbp), %rax
movss (%rax), %xmm0
movq 0x10(%rbp), %rax
addss (%rax), %xmm0
movq 0x18(%rbp), %rax
addss (%rax), %xmm0
movss %xmm0, -0x4(%rbp)
jmp 0x285d2
xorps %xmm0, %xmm0
movsd %xmm0, -0x90(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x98(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0xa0(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0xa8(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0xb0(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0xb8(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0xc0(%rbp)
movq 0x68(%rbp), %rax
movq %rax, -0xc8(%rbp)
movl $0x0, -0xcc(%rbp)
movl -0xcc(%rbp), %eax
cmpl 0x70(%rbp), %eax
jge 0x283fa
movq 0x78(%rbp), %rax
movslq -0xcc(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x78(%rbp), %rax
movslq -0xcc(%rbp), %rcx
mulsd (%rax,%rcx,8), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0xd0(%rbp)
movq -0xc8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x66, %eax
jne 0x282b1
movss -0xd0(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
addsd -0x90(%rbp), %xmm0
movsd %xmm0, -0x90(%rbp)
jmp 0x283d2
movq -0xc8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x70, %eax
jne 0x282e1
movss -0xd0(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
addsd -0x98(%rbp), %xmm0
movsd %xmm0, -0x98(%rbp)
jmp 0x283d0
movq -0xc8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x6c, %eax
jne 0x28311
movss -0xd0(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
addsd -0xb8(%rbp), %xmm0
movsd %xmm0, -0xb8(%rbp)
jmp 0x283ce
movq -0xc8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x61, %eax
jne 0x28341
movss -0xd0(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
addsd -0xb0(%rbp), %xmm0
movsd %xmm0, -0xb0(%rbp)
jmp 0x283cc
movq -0xc8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x74, %eax
jne 0x2836e
movss -0xd0(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
addsd -0xc0(%rbp), %xmm0
movsd %xmm0, -0xc0(%rbp)
jmp 0x283ca
movq -0xc8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x6f, %eax
jne 0x2839b
movss -0xd0(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
addsd -0xa0(%rbp), %xmm0
movsd %xmm0, -0xa0(%rbp)
jmp 0x283c8
movq -0xc8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x73, %eax
jne 0x283c6
movss -0xd0(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
addsd -0xa8(%rbp), %xmm0
movsd %xmm0, -0xa8(%rbp)
jmp 0x283c8
jmp 0x283ca
jmp 0x283cc
jmp 0x283ce
jmp 0x283d0
jmp 0x283d2
movq -0xc8(%rbp), %rax
addq $0x158, %rax            # imm = 0x158
movq %rax, -0xc8(%rbp)
movl -0xcc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xcc(%rbp)
jmp 0x28246
leaq 0x63c5f(%rip), %rax     # 0x8c060
movsd (%rax), %xmm0
mulsd -0x90(%rbp), %xmm0
movsd %xmm0, -0xd8(%rbp)
movsd -0x98(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x2842a
jp 0x2842a
jmp 0x28455
leaq 0x63c27(%rip), %rax     # 0x8c058
movsd (%rax), %xmm0
movsd -0x98(%rbp), %xmm2
movsd -0xd8(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xd8(%rbp)
movsd -0xa0(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x2846a
jp 0x2846a
jmp 0x28495
leaq 0x63bdf(%rip), %rax     # 0x8c050
movsd (%rax), %xmm0
movsd -0xa0(%rbp), %xmm2
movsd -0xd8(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xd8(%rbp)
movsd -0xa8(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x284aa
jp 0x284aa
jmp 0x284d5
leaq 0x63bb7(%rip), %rax     # 0x8c068
movsd (%rax), %xmm0
movsd -0xa8(%rbp), %xmm2
movsd -0xd8(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xd8(%rbp)
movsd -0xb8(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x284ea
jp 0x284ea
jmp 0x28515
leaq 0x63b87(%rip), %rax     # 0x8c078
movsd (%rax), %xmm0
movsd -0xb8(%rbp), %xmm2
movsd -0xd8(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xd8(%rbp)
movsd -0xb0(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x2852a
jp 0x2852a
jmp 0x28555
leaq 0x63b3f(%rip), %rax     # 0x8c070
movsd (%rax), %xmm0
movsd -0xb0(%rbp), %xmm2
movsd -0xd8(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xd8(%rbp)
movsd -0xc0(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x2856a
jp 0x2856a
jmp 0x28595
leaq 0x63aef(%rip), %rax     # 0x8c060
movsd (%rax), %xmm0
movsd -0xc0(%rbp), %xmm2
movsd -0xd8(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xd8(%rbp)
movq -0x38(%rbp), %rax
movss (%rax), %xmm0
movq 0x10(%rbp), %rax
addss (%rax), %xmm0
movq 0x18(%rbp), %rax
addss (%rax), %xmm0
cvtss2sd %xmm0, %xmm1
movsd -0xd8(%rbp), %xmm0
movsd 0x4da47(%rip), %xmm2    # 0x76008
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x4(%rbp)
movss -0x4(%rbp), %xmm0
addq $0xe0, %rsp
popq %rbp
retq