// File: /workspace/github_c_makefile_star2_O1/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 $0xa8, %rsp
movq %r9, 0xa0(%rsp)
movq %rcx, 0x80(%rsp)
movq %rsi, %rbx
movq %rdi, 0x68(%rsp)
movl 0x5d4d4(%rip), %esi     # 0x792bc
testl %esi, %esi
jle 0x1c1e3
movl %edx, %r13d
movq %r8, 0x70(%rsp)
movl $0xffffffff, 0x10(%rsp) # imm = 0xFFFFFFFF
movsd 0x3b118(%rip), %xmm0    # 0x56f20
movsd %xmm0, 0x40(%rsp)
xorl %ebp, %ebp
xorps %xmm0, %xmm0
movsd %xmm0, 0x28(%rsp)
movl $0x4, %r14d
movsd %xmm0, 0x20(%rsp)
movl $0x0, 0x14(%rsp)
xorl %r12d, %r12d
movsd %xmm0, 0x50(%rsp)
movl $0xffffffff, 0x4(%rsp)  # imm = 0xFFFFFFFF
movq %rbx, 0x58(%rsp)
movl %edx, 0x38(%rsp)
movq 0x5d472(%rip), %rax     # 0x792c0
movslq -0x4(%rax,%r14), %rcx
movl %ecx, 0xc(%rsp)
movslq (%rax,%r14), %rax
movl %eax, 0x8(%rsp)
movq 0x5d46a(%rip), %rdx     # 0x792d0
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), %r15d
movq 0x68(%rsp), %rdi
movq %rbx, %rsi
leaq 0xc(%rsp), %rdx
leaq 0x8(%rsp), %rcx
movl %r15d, %r8d
movl %r13d, %r9d
callq 0x1c992
leaq 0x4d1c4(%rip), %rax     # 0x69068
ucomiss (%rax), %xmm0
jae 0x1c1b8
movaps %xmm0, %xmm1
xorps %xmm0, %xmm0
ucomiss %xmm1, %xmm0
jae 0x1c30c
movl %r12d, 0x3c(%rsp)
testl %r15d, %r15d
movss %xmm1, 0x18(%rsp)
js 0x1bfa9
imulq $0xc8, %r15, %r12
movq 0xa0(%rsp), %rbx
leaq (%rbx,%r12), %r13
movq %r13, %rdi
movaps %xmm1, %xmm0
callq 0x1ccef
cvtss2sd %xmm0, %xmm0
subsd 0xb8(%rbx,%r12), %xmm0
cvtsd2ss %xmm0, %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm0, %xmm1
xorps %xmm3, %xmm3
cvtss2sd %xmm0, %xmm3
jbe 0x1bf3e
xorps %xmm1, %xmm1
cvtss2sd 0x18(%rsp), %xmm1
movsd 0x20(%r13), %xmm2
leaq 0x3bafa(%rip), %rdi     # 0x57a1f
movaps %xmm3, %xmm0
movl %r15d, %esi
movb $0x3, %al
movsd %xmm3, 0x48(%rsp)
callq 0x20f0
movsd 0x48(%rsp), %xmm3
xorps %xmm0, %xmm0
cvtss2sd 0x18(%rsp), %xmm0
movaps %xmm0, %xmm1
subsd 0x20(%r13), %xmm1
cvtsd2ss %xmm1, %xmm1
andps 0x3b3c5(%rip), %xmm1    # 0x57320
xorps %xmm2, %xmm2
cvtss2sd %xmm1, %xmm2
ucomisd 0x3b3f6(%rip), %xmm2    # 0x57360
movl 0x14(%rsp), %eax
ja 0x1c32e
movsd 0x28(%rsp), %xmm1
addsd %xmm3, %xmm1
movsd %xmm1, 0x28(%rsp)
movsd 0x50(%rsp), %xmm1
addsd %xmm2, %xmm1
movsd %xmm1, 0x50(%rsp)
incl %eax
movl %eax, 0x14(%rsp)
movl 0x3c(%rsp), %r12d
movq 0x58(%rsp), %rbx
jmp 0x1c1b3
movslq 0xc(%rsp), %rcx
movq %rcx, 0x48(%rsp)
imulq $0x70, %rcx, %rax
movq %rax, 0x90(%rsp)
movslq 0x64(%rbx,%rax), %rax
shlq $0x5, %rax
movq 0x80(%rsp), %rcx
movswq 0x14(%rcx,%rax), %r12
movslq 0x8(%rsp), %rdx
movq %rdx, 0x60(%rsp)
imulq $0x70, %rdx, %rax
movq %rax, 0x98(%rsp)
movslq 0x64(%rbx,%rax), %rax
shlq $0x5, %rax
movswq 0x14(%rcx,%rax), %rax
movq %rax, 0x88(%rsp)
imulq $0xc8, %rax, %r13
movq 0xe8(%rsp), %r15
movq (%r15,%r12,8), %rdi
addq %r13, %rdi
movaps %xmm1, %xmm0
callq 0x1ccef
cvtss2sd %xmm0, %xmm0
movq (%r15,%r12,8), %rax
subsd 0xb8(%rax,%r13), %xmm0
xorps %xmm1, %xmm1
cvtsd2ss %xmm0, %xmm1
xorps %xmm0, %xmm0
ucomiss %xmm1, %xmm0
jbe 0x1c160
xorps %xmm0, %xmm0
cvtss2sd 0x18(%rsp), %xmm0
movsd %xmm0, 0x78(%rsp)
leaq 0x3ba46(%rip), %rdi     # 0x57aa2
movb $0x1, %al
movss %xmm1, 0x34(%rsp)
callq 0x20f0
xorps %xmm0, %xmm0
cvtss2sd 0x34(%rsp), %xmm0
leaq 0x3ba41(%rip), %rdi     # 0x57aba
movl %r12d, %esi
movq 0x88(%rsp), %rdx
movsd 0x78(%rsp), %xmm1
movb $0x2, %al
callq 0x20f0
movq 0xe8(%rsp), %rax
movq (%rax,%r12,8), %rax
movsd 0x30(%rax,%r13), %xmm0
movsd 0x38(%rax,%r13), %xmm1
movsd 0x40(%rax,%r13), %xmm2
movsd 0x48(%rax,%r13), %xmm3
leaq 0x3ba20(%rip), %rdi     # 0x57ae0
movb $0x4, %al
callq 0x20f0
movq 0x90(%rsp), %rax
leaq (%rbx,%rax), %rsi
addq $0x18, %rsi
movl 0x4c(%rsi), %ecx
movq 0x48(%rsp), %rdx
leaq (%rdx,%rdx,2), %rax
movq 0x68(%rsp), %r15
xorps %xmm0, %xmm0
cvtss2sd (%r15,%rax,4), %xmm0
xorps %xmm1, %xmm1
cvtss2sd 0x4(%r15,%rax,4), %xmm1
xorps %xmm2, %xmm2
cvtss2sd 0x8(%r15,%rax,4), %xmm2
leaq 0x3b9f9(%rip), %rdi     # 0x57b05
movb $0x3, %al
callq 0x20f0
movq 0x98(%rsp), %rax
leaq (%rbx,%rax), %rsi
addq $0x18, %rsi
movl 0x4c(%rsi), %ecx
movq 0x60(%rsp), %rdx
leaq (%rdx,%rdx,2), %rax
xorps %xmm0, %xmm0
cvtss2sd (%r15,%rax,4), %xmm0
xorps %xmm1, %xmm1
cvtss2sd 0x4(%r15,%rax,4), %xmm1
xorps %xmm2, %xmm2
cvtss2sd 0x8(%r15,%rax,4), %xmm2
leaq 0x3b9d3(%rip), %rdi     # 0x57b26
movb $0x3, %al
callq 0x20f0
movss 0x34(%rsp), %xmm1
movl 0x3c(%rsp), %r12d
incl %r12d
xorps %xmm0, %xmm0
cvtss2sd 0x18(%rsp), %xmm0
movsd 0x40(%rsp), %xmm3
ucomisd %xmm0, %xmm3
movl 0x4(%rsp), %eax
cmoval 0x60(%rsp), %eax
movl %eax, 0x4(%rsp)
movl 0x10(%rsp), %eax
cmoval 0x48(%rsp), %eax
movl %eax, 0x10(%rsp)
cvtss2sd %xmm1, %xmm1
movsd 0x20(%rsp), %xmm2
addsd %xmm1, %xmm2
movsd %xmm2, 0x20(%rsp)
minsd %xmm3, %xmm0
movsd %xmm0, 0x40(%rsp)
movl 0x38(%rsp), %r13d
incq %rbp
movslq 0x5d0fa(%rip), %rsi     # 0x792bc
addq $0xc8, %r14
cmpq %rsi, %rbp
jl 0x1be47
movl 0x10(%rsp), %r14d
movq 0x70(%rsp), %r8
movl 0x14(%rsp), %r15d
jmp 0x1c21a
xorl %r12d, %r12d
movsd 0x3ad32(%rip), %xmm0    # 0x56f20
movsd %xmm0, 0x40(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x50(%rsp)
movl $0xffffffff, 0x4(%rsp)  # imm = 0xFFFFFFFF
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
xorl %r15d, %r15d
movsd %xmm0, 0x20(%rsp)
movsd %xmm0, 0x28(%rsp)
movl 0xe0(%rsp), %ebp
leal -0x1(%r8), %eax
imull %r8d, %eax
movl %eax, %edx
shrl $0x1f, %edx
addl %eax, %edx
sarl %edx
leaq 0x3b90e(%rip), %rdi     # 0x57b47
xorl %eax, %eax
callq 0x20f0
leaq 0x4ce21(%rip), %rax     # 0x69068
xorps %xmm0, %xmm0
cvtss2sd (%rax), %xmm0
leaq 0x3b919(%rip), %rdi     # 0x57b6e
movl %r15d, %esi
movl %ebp, %edx
movl %r12d, %ecx
movb $0x1, %al
callq 0x20f0
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
movsd 0x50(%rsp), %xmm1
divsd %xmm0, %xmm1
leaq 0x3b91f(%rip), %rdi     # 0x57b9c
movsd 0x28(%rsp), %xmm0
movsd 0x20(%rsp), %xmm2
movb $0x3, %al
callq 0x20f0
testl %r14d, %r14d
js 0x1c2ee
leaq 0x3b931(%rip), %rdi     # 0x57bcd
movsd 0x40(%rsp), %xmm0
movb $0x1, %al
callq 0x20f0
movl %r14d, %eax
imulq $0x70, %rax, %rax
leaq (%rbx,%rax), %rsi
addq $0x18, %rsi
movl 0x4c(%rsi), %ecx
leaq 0x3b91d(%rip), %rdi     # 0x57bdf
movl %r14d, %edx
xorl %eax, %eax
callq 0x20f0
movslq 0x4(%rsp), %rdx
imulq $0x70, %rdx, %rax
leaq (%rbx,%rax), %rsi
addq $0x18, %rsi
movl 0x4c(%rsi), %ecx
leaq 0x3b909(%rip), %rdi     # 0x57bf0
xorl %eax, %eax
callq 0x20f0
movsd 0x20(%rsp), %xmm0
addsd 0x28(%rsp), %xmm0
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0xc(%rsp), %esi
movl 0x8(%rsp), %edx
xorps %xmm0, %xmm0
cvtss2sd %xmm1, %xmm0
leaq 0x3b62d(%rip), %rdi     # 0x5794f
movl %r15d, %ecx
movb $0x1, %al
callq 0x20f0
jmp 0x1c3a8
movslq 0xc(%rsp), %rax
imulq $0x70, %rax, %rax
movslq 0x8(%rsp), %rcx
imulq $0x70, %rcx, %rsi
movq 0x58(%rsp), %rbx
leaq (%rbx,%rax), %rdx
addq $0x18, %rdx
movl 0x4c(%rdx), %ecx
leaq 0x18(%rbx,%rsi), %r8
movl 0x4c(%r8), %r9d
leaq 0x3b6e5(%rip), %rdi     # 0x57a45
movl %r15d, %esi
movb $0x1, %al
movsd %xmm0, 0x18(%rsp)
callq 0x20f0
movslq (%r13), %rax
imulq $0x70, %rax, %rax
movslq 0x4(%r13), %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 0x3b6dd(%rip), %rdi     # 0x57a78
movsd 0x18(%rsp), %xmm0
movb $0x1, %al
callq 0x20f0
movl $0x8, %edi
callq 0x2270