// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r9, %rbx
movl %edx, 0x2c(%rsp)
movq %rdi, 0x30(%rsp)
movl 0xb0(%rsp), %ebp
movq 0x98(%rsp), %r14
movq 0x90(%rsp), %r15
cmpl $0x0, 0x5c2bc(%rip)     # 0x7928c
movq %rsi, 0x20(%rsp)
jne 0x1d021
movq %rcx, %r13
movl 0xc0(%rsp), %r9d
movq 0xc8(%rsp), %rdi
movl 0xd0(%rsp), %esi
movq 0xa0(%rsp), %rdx
movq 0xa8(%rsp), %rcx
movq %r8, %r12
movl %ebp, %r8d
callq 0x1cbc5
movq %r13, %rcx
movq %r12, %r8
movq 0x20(%rsp), %rsi
movl $0x1, 0x5c26b(%rip)     # 0x7928c
xorl %eax, %eax
movl %eax, (%rsi)
movq %rcx, 0x40(%rsp)
movl %eax, (%rcx)
movq %r8, 0x38(%rsp)
movl %eax, (%r8)
movq %rbx, 0x18(%rsp)
movl %eax, (%rbx)
movl %eax, (%r15)
movl %eax, (%r14)
cmpl %eax, 0x5c275(%rip)     # 0x792bc
movq 0xa8(%rsp), %rbx
jle 0x1d2fe
xorl %r14d, %r14d
leaq 0x8(%rsp), %r15
leaq 0x4(%rsp), %r12
leaq 0x4bfff(%rip), %r13     # 0x69068
movq 0x5c250(%rip), %rax     # 0x792c0
imulq $0xc8, %r14, %rcx
movl (%rax,%rcx), %edx
movl %edx, 0x8(%rsp)
movl 0x4(%rax,%rcx), %eax
movl %eax, 0x4(%rsp)
movq 0xa0(%rsp), %rdi
movq %rbx, %rsi
movq %r15, %rdx
movq %r12, %rcx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
movl %ebp, %r9d
callq 0x1c992
ucomiss (%r13), %xmm0
jae 0x1d2eb
movaps %xmm0, %xmm1
movq 0x5c216(%rip), %rcx     # 0x792d0
movl 0x8(%rsp), %eax
movl %eax, 0xc(%rsp)
movslq %eax, %rsi
imulq $0x70, %rsi, %rbp
movslq 0x64(%rbx,%rbp), %rax
movq (%rcx,%rax,8), %rdx
movl 0x4(%rsp), %r13d
movslq %r13d, %rdi
imulq $0x70, %rdi, %r12
movslq 0x64(%rbx,%r12), %rcx
movl (%rdx,%rcx,4), %r15d
xorps %xmm0, %xmm0
ucomiss %xmm1, %xmm0
jae 0x1d563
movq %rdi, 0x48(%rsp)
movq %rsi, 0x50(%rsp)
testl %r15d, %r15d
movss %xmm1, (%rsp)
js 0x1d18d
imulq $0xc8, %r15, %rbx
movq 0xc8(%rsp), %rax
leaq (%rax,%rbx), %rdi
movq %rdi, 0x10(%rsp)
movaps %xmm1, %xmm0
callq 0x1ccef
ucomiss 0x33eda(%rip), %xmm0    # 0x5100c
movq 0x18(%rsp), %rax
cmovaq 0x90(%rsp), %rax
movss (%rax), %xmm1
addss %xmm0, %xmm1
movss %xmm1, (%rax)
movq 0x40(%rsp), %rax
incl (%rax)
cvtss2sd %xmm0, %xmm2
movq 0xc8(%rsp), %rax
movsd 0xb8(%rax,%rbx), %xmm3
movapd %xmm3, %xmm1
addsd 0x3a1f4(%rip), %xmm1    # 0x57368
ucomisd %xmm2, %xmm1
ja 0x1d584
cmpl 0xd0(%rsp), %r15d
jl 0x1d1e3
jmp 0x1d584
shlq $0x5, %rax
movq 0xb8(%rsp), %rdx
movswq 0x14(%rdx,%rax), %rax
shlq $0x5, %rcx
movswq 0x14(%rdx,%rcx), %rcx
imulq $0xc8, %rcx, %rdi
movq 0xd8(%rsp), %rcx
addq (%rcx,%rax,8), %rdi
movq %rdi, 0x10(%rsp)
movaps %xmm1, %xmm0
callq 0x1ccef
movaps %xmm0, %xmm1
movq 0x98(%rsp), %rax
addss (%rax), %xmm1
movss %xmm1, (%rax)
movq 0x38(%rsp), %rax
incl (%rax)
cmpq $0x0, 0x30(%rsp)
movq 0x20(%rsp), %rbx
je 0x1d2ba
movslq (%rbx), %rax
movq %rax, %rcx
shlq $0x6, %rcx
leaq (%rcx,%rax,4), %rbx
movq 0x30(%rsp), %r12
leaq (%r12,%rbx), %rbp
movl 0xc(%rsp), %eax
movl %eax, (%r12,%rbx)
movl %r13d, 0x4(%r12,%rbx)
movl %r15d, 0x40(%r12,%rbx)
movss %xmm0, 0x8(%r12,%rbx)
movss (%rsp), %xmm0
movss %xmm0, 0x18(%r12,%rbx)
movq 0x10(%rsp), %rdi
callq 0x1d5d6
movss %xmm0, 0xc(%r12,%rbx)
movq 0x50(%rsp), %rax
leaq (%rax,%rax,2), %rax
movq 0xa0(%rsp), %rcx
leaq (%rcx,%rax,4), %rsi
movq 0x48(%rsp), %rax
leaq (%rax,%rax,2), %rax
leaq (%rcx,%rax,4), %rdx
xorl %eax, %eax
movss (%rdx,%rax,4), %xmm0
movss %xmm0, 0x1c(%rbp,%rax,4)
movss (%rdx,%rax,4), %xmm0
subss (%rsi,%rax,4), %xmm0
movss %xmm0, 0x28(%rbp,%rax,4)
incq %rax
cmpq $0x3, %rax
jne 0x1d265
leaq 0x34(%rbp), %rdi
callq 0x10818
cmpl $0x0, 0x108(%rsp)
movq 0x20(%rsp), %rbx
je 0x1d2ba
movq 0x10(%rsp), %rdi
movss (%rsp), %xmm0
movl $0x1, %esi
callq 0x1d8bb
movss %xmm0, 0x10(%rbp)
movl (%rbx), %eax
leal 0x1(%rax), %esi
movl %esi, (%rbx)
cmpl 0x2c(%rsp), %eax
movq 0xa8(%rsp), %rbx
movl 0xb0(%rsp), %ebp
leaq 0x8(%rsp), %r15
leaq 0x4(%rsp), %r12
leaq 0x4bd83(%rip), %r13     # 0x69068
jge 0x1d553
incq %r14
movslq 0x5bfc7(%rip), %rax     # 0x792bc
cmpq %rax, %r14
jl 0x1d069
cmpl $0x0, 0x100(%rsp)
je 0x1d523
movl 0xf0(%rsp), %edx
xorps %xmm1, %xmm1
xorpd %xmm7, %xmm7
xorpd %xmm6, %xmm6
xorpd %xmm5, %xmm5
xorpd %xmm4, %xmm4
xorpd %xmm2, %xmm2
xorpd %xmm3, %xmm3
xorps %xmm0, %xmm0
testl %edx, %edx
movq 0x18(%rsp), %r10
movq 0x98(%rsp), %r11
jle 0x1d3f4
movq 0xf8(%rsp), %rax
movq 0xe8(%rsp), %rcx
movl %edx, %edx
xorl %esi, %esi
leaq 0x3a0bb(%rip), %rdi     # 0x5741c
movsd (%rax,%rsi,8), %xmm8
mulsd %xmm8, %xmm8
cvtsd2ss %xmm8, %xmm8
movzbl (%rcx), %r8d
leal -0x66(%r8), %r9d
cmpl $0xe, %r9d
ja 0x1d395
movslq (%rdi,%r9,4), %r8
addq %rdi, %r8
jmpq *%r8
cvtss2sd %xmm8, %xmm8
addsd %xmm8, %xmm7
jmp 0x1d3e1
cmpl $0x61, %r8d
jne 0x1d3e1
cvtss2sd %xmm8, %xmm8
addsd %xmm8, %xmm2
jmp 0x1d3e1
cvtss2sd %xmm8, %xmm8
addsd %xmm8, %xmm5
jmp 0x1d3e1
cvtss2sd %xmm8, %xmm8
addsd %xmm8, %xmm0
jmp 0x1d3e1
cvtss2sd %xmm8, %xmm8
addsd %xmm8, %xmm6
jmp 0x1d3e1
cvtss2sd %xmm8, %xmm8
addsd %xmm8, %xmm3
jmp 0x1d3e1
cvtss2sd %xmm8, %xmm8
addsd %xmm8, %xmm4
addq $0x158, %rcx            # imm = 0x158
incq %rsi
cmpq %rsi, %rdx
jne 0x1d361
leaq 0x4bca5(%rip), %rax     # 0x690a0
movsd (%rax), %xmm8
mulsd %xmm8, %xmm7
leaq 0x4bc8c(%rip), %rax     # 0x69098
movsd (%rax), %xmm9
mulsd %xmm6, %xmm9
addsd %xmm7, %xmm9
cmpneqsd %xmm1, %xmm6
movapd %xmm6, %xmm10
andnpd %xmm7, %xmm10
andpd %xmm9, %xmm6
orpd %xmm10, %xmm6
leaq 0x4bc55(%rip), %rax     # 0x69090
movsd (%rax), %xmm7
mulsd %xmm5, %xmm7
addsd %xmm6, %xmm7
cmpneqsd %xmm1, %xmm5
movapd %xmm5, %xmm9
andnpd %xmm6, %xmm9
andpd %xmm7, %xmm5
orpd %xmm9, %xmm5
leaq 0x4bc42(%rip), %rax     # 0x690a8
movsd (%rax), %xmm6
mulsd %xmm4, %xmm6
addsd %xmm5, %xmm6
cmpneqsd %xmm1, %xmm4
movapd %xmm4, %xmm7
andnpd %xmm5, %xmm7
andpd %xmm6, %xmm4
orpd %xmm7, %xmm4
leaq 0x4bc2a(%rip), %rax     # 0x690b8
movsd (%rax), %xmm5
mulsd %xmm3, %xmm5
addsd %xmm4, %xmm5
cmpneqsd %xmm1, %xmm3
movapd %xmm3, %xmm6
andnpd %xmm4, %xmm6
andpd %xmm5, %xmm3
orpd %xmm6, %xmm3
leaq 0x4bbfa(%rip), %rax     # 0x690b0
movsd (%rax), %xmm4
mulsd %xmm2, %xmm4
addsd %xmm3, %xmm4
cmpneqsd %xmm1, %xmm2
movapd %xmm2, %xmm5
andnpd %xmm3, %xmm5
andpd %xmm4, %xmm2
orpd %xmm5, %xmm2
mulsd %xmm0, %xmm8
addsd %xmm2, %xmm8
cmpneqsd %xmm1, %xmm0
movapd %xmm0, %xmm1
andnpd %xmm2, %xmm1
andpd %xmm8, %xmm0
orpd %xmm1, %xmm0
movss (%r10), %xmm1
movq 0x90(%rsp), %rax
addss (%rax), %xmm1
addss (%r11), %xmm1
mulsd 0x33b43(%rip), %xmm0    # 0x51058
cvtss2sd %xmm1, %xmm1
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
jmp 0x1d544
movq 0x18(%rsp), %rax
movss (%rax), %xmm0
movq 0x90(%rsp), %rax
addss (%rax), %xmm0
movq 0x98(%rsp), %rax
addss (%rax), %xmm0
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3a47f(%rip), %rdi     # 0x579d9
xorl %eax, %eax
callq 0x20f0
jmp 0x1d5cc
xorps %xmm0, %xmm0
cvtss2sd %xmm1, %xmm0
leaq 0x3a3de(%rip), %rdi     # 0x5794f
movl 0xc(%rsp), %esi
movl %r13d, %edx
movl %r15d, %ecx
movb $0x1, %al
callq 0x20f0
jmp 0x1d5cc
movq 0xa8(%rsp), %rcx
leaq (%rcx,%rbp), %rax
addq $0x64, %rax
leaq 0x64(%rcx,%r12), %rcx
movl (%rax), %r8d
movl (%rcx), %r9d
xorps %xmm0, %xmm0
cvtss2sd (%rsp), %xmm0
movq 0x10(%rsp), %rax
movsd 0x20(%rax), %xmm1
leaq 0x3a3b3(%rip), %rdi     # 0x5796b
movl %r14d, %esi
movl %r15d, %edx
movl 0xd0(%rsp), %ecx
movb $0x4, %al
callq 0x20f0
movl $0x8, %edi
callq 0x2270