// File: /workspace/github_c_makefile_star2_O2/ugobas[P]tnm/anharmonic_tnm.c
// Function: Energy_debug
double Energy_debug(float *r, atom *atoms, int natoms,
		    struct residue *seq, int nres,
		    struct interaction *Int_list, int N_int,
		    struct interaction **Int_KB, int NA)
{
  double E_nat=0, E_nonat=0; int n_nat=0, n_not=0;
  double d_min=100, d_nat_ave=0; int i1_min=-1, i2_min=-1;
  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){
      float e=Compute_V(Int_list+n, d)-Int_list[n].E_min;
      if(e<0)printf("Neg SB de= %.2g n=%d d= %.3f d0=%.3f\n",
		     e, n, d, Int_list[n].r0);
      E_nat+=e;
      float x=fabs(d-Int_list[n].r0);
      if(x>0.01){
	atom *a1=atoms+i1, *a2=atoms+i2;
	printf("ERROR in interaction %d, %s r%d - %s r%d, d= %.2f\n",
	       n, a1->name, a1->res, a2->name, a2->res, d);
	a1=atoms+Int_list[n].i1; a2=atoms+Int_list[n].i2; 
	printf("Contact matrix: %s r%d - %s r%d, d= %.2f\n",
	       a1->name, a1->res, a2->name, a2->res, d); exit(8);
      }
      d_nat_ave+=x;
      n_nat++;
    }else{
      int a=seq[atoms[i1].res].i_aa, b=seq[atoms[i2].res].i_aa;
      float e=Compute_V(Int_KB[a]+b, d)-Int_KB[a][b].E_min;
      if(e<0){
	printf("Non-native int. d=%.5g\n", d);
	printf("Neg KB energy= %.3g ab=%d-%d d= %.3f\n", e, a, b, d);
	printf("A0= %.2g A1= %.2g A2= %.2g A4= %.2g\n",
	       Int_KB[a][b].A0, Int_KB[a][b].A1,
	       Int_KB[a][b].A2, Int_KB[a][b].A4);
	int j=3*i1;
	printf("a1: %s %d r%d\tr= %.3g %.3g %.3g\t",
	       atoms[i1].name, i1, atoms[i1].res,
	       r[j], r[j+1], r[j+2]);
	//atoms[i1].r[0], atoms[i1].r[1], atoms[i1].r[2]);
	j=3*i2;
	printf("a2: %s %d r%d\tr= %.3g %.3g %.3g\n",
	       atoms[i2].name, i2, atoms[i2].res,
	       r[j], r[j+1], r[j+2]); 
	//atoms[i2].r[0], atoms[i2].r[1], atoms[i2].r[2]);
      }
      E_nonat+=e; n_not++;
      if(d<d_min){d_min=d; i1_min=i1; i2_min=i2;}
    }
  }
  printf("%d tested interactions over %d pairs, ", N_int_all, nres*(nres-1)/2);
  printf("%d native over %d, %d non-native d_thr= %.2f\n",
	 n_nat, N_int, n_not, C_THR);
  printf("Energy: native %.4g |r0-d|=%.3g non-native %.4g\n",
	 E_nat, d_nat_ave/n_nat, E_nonat);
  if(i1_min>=0){
    printf("d_min_nonat=%.5g ", d_min);
    printf("a1: %s %d r %d  ",atoms[i1_min].name, i1_min, atoms[i1_min].res);
    printf("a2: %s %d r %d\n",atoms[i2_min].name, i2_min, atoms[i2_min].res);
  }
  return(E_nat+E_nonat);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %r9, 0x90(%rsp)
movq %r8, 0x70(%rsp)
movq %rcx, 0x78(%rsp)
movl %edx, 0x64(%rsp)
movq %rsi, %rbx
movq %rdi, %rbp
xorl %r15d, %r15d
movsd 0x37002(%rip), %xmm0    # 0x50e30
movsd %xmm0, 0x40(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x50(%rsp)
pushq $-0x1
popq %rax
pushq $0x4
popq %r14
leaq 0x4a21d(%rip), %r13     # 0x64068
movsd %xmm0, 0x28(%rsp)
movsd %xmm0, 0x30(%rsp)
movl %eax, 0x10(%rsp)
movl %eax, 0x14(%rsp)
movl $0x0, 0x20(%rsp)
movl $0x0, 0x24(%rsp)
movq %rdi, 0x48(%rsp)
movslq 0x5a441(%rip), %rsi     # 0x742bc
cmpq %rsi, %r15
jge 0x1a1ee
movq 0x5a435(%rip), %rax     # 0x742c0
movslq -0x4(%rax,%r14), %rcx
movl %ecx, 0xc(%rsp)
movslq (%rax,%r14), %rax
movl %eax, 0x8(%rsp)
movq 0x5a42d(%rip), %rdx     # 0x742d0
imulq $0x70, %rcx, %rcx
movslq 0x64(%rbx,%rcx), %rcx
movq (%rdx,%rcx,8), %rcx
imulq $0x70, %rax, %rax
movslq 0x64(%rbx,%rax), %rax
movl (%rcx,%rax,4), %r12d
movq %rbp, %rdi
movq %rbx, %rsi
leaq 0xc(%rsp), %rdx
leaq 0x8(%rsp), %rcx
movl %r12d, %r8d
movl 0x64(%rsp), %r9d
callq 0x1a8f8
ucomiss (%r13), %xmm0
jae 0x1a1df
movaps %xmm0, %xmm1
xorps %xmm0, %xmm0
ucomiss %xmm1, %xmm0
jae 0x1a2d9
movq %r15, 0x58(%rsp)
testl %r12d, %r12d
movss %xmm1, (%rsp)
js 0x19f76
movq %rbx, %r15
imulq $0xc8, %r12, %r13
movq 0x90(%rsp), %rbx
leaq (%rbx,%r13), %rbp
movq %rbp, %rdi
movaps %xmm1, %xmm0
callq 0x1ac14
cvtss2sd %xmm0, %xmm0
subsd 0xb8(%rbx,%r13), %xmm0
cvtsd2ss %xmm0, %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm0, %xmm1
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x18(%rsp)
jbe 0x1a116
cvtss2sd (%rsp), %xmm1
movsd %xmm1, (%rsp)
movsd 0x20(%rbp), %xmm2
leaq 0x379dd(%rip), %rdi     # 0x5193f
movl %r12d, %esi
movb $0x3, %al
callq 0x20f0
movsd (%rsp), %xmm0
jmp 0x1a11b
movslq 0xc(%rsp), %rax
movq %rax, 0x18(%rsp)
imulq $0x70, %rax, %rax
movq %rax, 0x80(%rsp)
movslq 0x64(%rbx,%rax), %rax
shlq $0x5, %rax
movq 0x78(%rsp), %rcx
movswq 0x14(%rcx,%rax), %r13
movslq 0x8(%rsp), %rax
movq %rax, 0x68(%rsp)
imulq $0x70, %rax, %rax
movq %rax, 0x88(%rsp)
movslq 0x64(%rbx,%rax), %rax
shlq $0x5, %rax
movswq 0x14(%rcx,%rax), %rbp
imulq $0xc8, %rbp, %r12
movq 0xd8(%rsp), %r15
movq (%r15,%r13,8), %rdi
addq %r12, %rdi
movaps %xmm1, %xmm0
callq 0x1ac14
cvtss2sd %xmm0, %xmm0
movq (%r15,%r13,8), %rax
subsd 0xb8(%rax,%r12), %xmm0
cvtsd2ss %xmm0, %xmm1
xorps %xmm0, %xmm0
ucomiss %xmm1, %xmm0
jbe 0x1a17c
cvtss2sd (%rsp), %xmm0
movsd %xmm0, (%rsp)
leaq 0x379ac(%rip), %rdi     # 0x519c2
movb $0x1, %al
movss %xmm1, 0x38(%rsp)
callq 0x20f0
cvtss2sd 0x38(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
leaq 0x379a4(%rip), %rdi     # 0x519da
movl %r13d, %esi
movl %ebp, %edx
movsd (%rsp), %xmm1
movb $0x2, %al
callq 0x20f0
movq (%r15,%r13,8), %rax
movsd 0x30(%rax,%r12), %xmm0
movsd 0x38(%rax,%r12), %xmm1
movsd 0x40(%rax,%r12), %xmm2
movsd 0x48(%rax,%r12), %xmm3
leaq 0x37992(%rip), %rdi     # 0x51a00
movb $0x4, %al
callq 0x20f0
movq 0x80(%rsp), %rax
leaq (%rbx,%rax), %rsi
addq $0x18, %rsi
movl 0x4c(%rsi), %ecx
movq 0x18(%rsp), %rdx
imulq $0xc, %rdx, %rax
movq 0x48(%rsp), %rbp
cvtss2sd (%rbp,%rax), %xmm0
cvtss2sd 0x4(%rbp,%rax), %xmm1
cvtss2sd 0x8(%rbp,%rax), %xmm2
leaq 0x37976(%rip), %rdi     # 0x51a25
movb $0x3, %al
callq 0x20f0
movq 0x88(%rsp), %rax
leaq (%rbx,%rax), %rsi
addq $0x18, %rsi
movl 0x4c(%rsi), %ecx
movq 0x68(%rsp), %r12
imulq $0xc, %r12, %rax
cvtss2sd (%rbp,%rax), %xmm0
cvtss2sd 0x4(%rbp,%rax), %xmm1
cvtss2sd 0x8(%rbp,%rax), %xmm2
leaq 0x3795b(%rip), %rdi     # 0x51a46
movl %r12d, %edx
movb $0x3, %al
callq 0x20f0
movsd 0x38(%rsp), %xmm3
movsd (%rsp), %xmm2
leaq 0x49f61(%rip), %r13     # 0x64068
movq 0x58(%rsp), %r15
movq 0x18(%rsp), %rcx
jmp 0x1a1a0
cvtss2sd (%rsp), %xmm0
movaps %xmm0, %xmm1
subsd 0x20(%rbp), %xmm1
cvtsd2ss %xmm1, %xmm1
andps 0x37102(%rip), %xmm1    # 0x51230
cvtss2sd %xmm1, %xmm2
ucomisd 0x37156(%rip), %xmm2    # 0x51290
movq %r15, %rbx
ja 0x1a2f8
movsd 0x30(%rsp), %xmm1
addsd 0x18(%rsp), %xmm1
movsd %xmm1, 0x30(%rsp)
movsd 0x50(%rsp), %xmm1
addsd %xmm2, %xmm1
movsd %xmm1, 0x50(%rsp)
incl 0x24(%rsp)
leaq 0x49ef8(%rip), %r13     # 0x64068
movq 0x48(%rsp), %rbp
movq 0x58(%rsp), %r15
jmp 0x1a1df
cvtss2sd %xmm1, %xmm3
cvtss2sd (%rsp), %xmm2
leaq 0x49edc(%rip), %r13     # 0x64068
movq 0x48(%rsp), %rbp
movq 0x58(%rsp), %r15
movq 0x18(%rsp), %rcx
movq 0x68(%rsp), %r12
incl 0x20(%rsp)
movsd 0x40(%rsp), %xmm1
ucomisd %xmm2, %xmm1
movl 0x10(%rsp), %eax
cmoval %r12d, %eax
movl %eax, 0x10(%rsp)
movl 0x14(%rsp), %eax
cmoval %ecx, %eax
movl %eax, 0x14(%rsp)
movsd 0x28(%rsp), %xmm0
addsd %xmm3, %xmm0
movsd %xmm0, 0x28(%rsp)
minsd %xmm1, %xmm2
movsd %xmm2, 0x40(%rsp)
incq %r15
addq $0xc8, %r14
jmp 0x19e74
movq 0x70(%rsp), %rcx
leal -0x1(%rcx), %eax
imull %ecx, %eax
pushq $0x2
popq %rcx
cltd
idivl %ecx
leaq 0x37861(%rip), %rdi     # 0x51a67
movl %eax, %edx
xorl %eax, %eax
callq 0x20f0
cvtss2sd (%r13), %xmm0
leaq 0x37872(%rip), %rdi     # 0x51a8e
movl 0x24(%rsp), %ebp
movl %ebp, %esi
movl 0xd0(%rsp), %edx
movl 0x20(%rsp), %ecx
movb $0x1, %al
callq 0x20f0
cvtsi2sd %ebp, %xmm0
movsd 0x50(%rsp), %xmm1
divsd %xmm0, %xmm1
leaq 0x37873(%rip), %rdi     # 0x51abc
movsd 0x30(%rsp), %xmm0
movsd 0x28(%rsp), %xmm2
movb $0x3, %al
callq 0x20f0
movl 0x14(%rsp), %ebp
testl %ebp, %ebp
js 0x1a2bb
leaq 0x37882(%rip), %rdi     # 0x51aed
movsd 0x40(%rsp), %xmm0
movb $0x1, %al
callq 0x20f0
movl %ebp, %eax
imulq $0x70, %rax, %rax
leaq (%rbx,%rax), %rsi
addq $0x18, %rsi
movl 0x4c(%rsi), %ecx
leaq 0x3786f(%rip), %rdi     # 0x51aff
movl %ebp, %edx
xorl %eax, %eax
callq 0x20f0
movslq 0x10(%rsp), %rdx
imulq $0x70, %rdx, %rax
leaq (%rbx,%rax), %rsi
addq $0x18, %rsi
movl 0x4c(%rsi), %ecx
leaq 0x3785c(%rip), %rdi     # 0x51b10
xorl %eax, %eax
callq 0x20f0
movsd 0x28(%rsp), %xmm0
addsd 0x30(%rsp), %xmm0
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0xc(%rsp), %esi
movl 0x8(%rsp), %edx
cvtss2sd %xmm1, %xmm0
leaq 0x37583(%rip), %rdi     # 0x5186f
movl %r12d, %ecx
movb $0x1, %al
callq 0x20f0
jmp 0x1a36b
movslq 0xc(%rsp), %rax
imulq $0x70, %rax, %rax
movslq 0x8(%rsp), %rcx
imulq $0x70, %rcx, %rsi
leaq (%rbx,%rax), %rdx
addq $0x18, %rdx
movl 0x4c(%rdx), %ecx
leaq 0x18(%rbx,%rsi), %r8
movl 0x4c(%r8), %r9d
leaq 0x37640(%rip), %rdi     # 0x51965
movl %r12d, %esi
movb $0x1, %al
movsd %xmm0, (%rsp)
callq 0x20f0
movslq (%rbp), %rax
imulq $0x70, %rax, %rax
movslq 0x4(%rbp), %rcx
imulq $0x70, %rcx, %rcx
leaq (%rbx,%rax), %rsi
addq $0x18, %rsi
movl 0x4c(%rsi), %edx
leaq 0x18(%rbx,%rcx), %rcx
movl 0x4c(%rcx), %r8d
leaq 0x37639(%rip), %rdi     # 0x51998
movsd (%rsp), %xmm0
movb $0x1, %al
callq 0x20f0
pushq $0x8
popq %rdi
callq 0x2270