// File: /workspace/github_c_makefile_star2_O3/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)
movq %rsi, 0x48(%rsp)
movl 0x5dc2b(%rip), %esi     # 0x792bc
testl %esi, %esi
jle 0x1bac6
movl %edx, %r14d
movq %rdi, %r12
movl $0xffffffff, 0x20(%rsp) # imm = 0xFFFFFFFF
movsd 0x3b831(%rip), %xmm0    # 0x56ee0
movsd %xmm0, 0x50(%rsp)
xorl %ebp, %ebp
xorps %xmm0, %xmm0
movsd %xmm0, 0x30(%rsp)
movl $0x4, %ebx
leaq 0x4(%rsp), %r13
movsd %xmm0, 0x28(%rsp)
movl $0x0, 0x18(%rsp)
movl $0x0, 0x10(%rsp)
movsd %xmm0, 0x40(%rsp)
movl $0xffffffff, 0x14(%rsp) # imm = 0xFFFFFFFF
movl %edx, 0x24(%rsp)
movq %rdi, 0x60(%rsp)
movq 0x5dbc2(%rip), %rax     # 0x792c0
movslq -0x4(%rax,%rbx), %rcx
movl %ecx, 0x4(%rsp)
movslq (%rax,%rbx), %rax
movl %eax, 0x1c(%rsp)
movq 0x5dbba(%rip), %rdx     # 0x792d0
imulq $0x70, %rcx, %rcx
movq 0x48(%rsp), %rsi
movslq 0x64(%rsi,%rcx), %rcx
movq (%rdx,%rcx,8), %rcx
imulq $0x70, %rax, %rax
movslq 0x64(%rsi,%rax), %rax
movl (%rcx,%rax,4), %r15d
movq %r12, %rdi
movq %r13, %rdx
leaq 0x1c(%rsp), %rcx
movl %r15d, %r8d
movl %r14d, %r9d
callq 0x1c23d
leaq 0x4d916(%rip), %rax     # 0x69068
ucomiss (%rax), %xmm0
jae 0x1ba9c
movaps %xmm0, %xmm1
xorps %xmm0, %xmm0
ucomiss %xmm1, %xmm0
jae 0x1bbf3
testl %r15d, %r15d
movss %xmm1, 0x8(%rsp)
js 0x1b7ec
imulq $0xc8, %r15, %r14
movq 0x90(%rsp), %r12
leaq (%r12,%r14), %r13
movq %r13, %rdi
movaps %xmm1, %xmm0
callq 0x1c59a
cvtss2sd %xmm0, %xmm0
subsd 0xb8(%r12,%r14), %xmm0
cvtsd2ss %xmm0, %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm0, %xmm1
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x38(%rsp)
jbe 0x1b9c8
xorps %xmm1, %xmm1
cvtss2sd 0x8(%rsp), %xmm1
movsd %xmm1, 0x8(%rsp)
movsd 0x20(%r13), %xmm2
leaq 0x3c208(%rip), %rdi     # 0x579df
movl %r15d, %esi
movb $0x3, %al
callq 0x20f0
movsd 0x8(%rsp), %xmm0
jmp 0x1b9d1
movslq 0x4(%rsp), %rax
movq %rax, 0x38(%rsp)
imulq $0x70, %rax, %rax
movq 0x48(%rsp), %rcx
movq %rax, 0x80(%rsp)
movslq 0x64(%rcx,%rax), %rax
shlq $0x5, %rax
movq %rcx, %rdx
movq 0x78(%rsp), %rcx
movswq 0x14(%rcx,%rax), %r12
movslq 0x1c(%rsp), %rax
movq %rax, 0x68(%rsp)
imulq $0x70, %rax, %rax
movq %rax, 0x88(%rsp)
movslq 0x64(%rdx,%rax), %rax
shlq $0x5, %rax
movswq 0x14(%rcx,%rax), %r14
imulq $0xc8, %r14, %r15
movq 0xd8(%rsp), %r13
movq (%r13,%r12,8), %rdi
addq %r15, %rdi
movaps %xmm1, %xmm0
callq 0x1c59a
cvtss2sd %xmm0, %xmm0
movq (%r13,%r12,8), %rax
subsd 0xb8(%rax,%r15), %xmm0
xorps %xmm1, %xmm1
cvtsd2ss %xmm0, %xmm1
xorps %xmm0, %xmm0
ucomiss %xmm1, %xmm0
jbe 0x1ba34
xorps %xmm0, %xmm0
cvtss2sd 0x8(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
leaq 0x3c1c4(%rip), %rdi     # 0x57a62
movb $0x1, %al
movss %xmm1, 0x58(%rsp)
callq 0x20f0
xorps %xmm0, %xmm0
cvtss2sd 0x58(%rsp), %xmm0
movsd %xmm0, 0x58(%rsp)
leaq 0x3c1b9(%rip), %rdi     # 0x57a7a
movl %r12d, %esi
movl %r14d, %edx
movsd 0x8(%rsp), %xmm1
movb $0x2, %al
callq 0x20f0
movq (%r13,%r12,8), %rax
movsd 0x30(%rax,%r15), %xmm0
movsd 0x38(%rax,%r15), %xmm1
movsd 0x40(%rax,%r15), %xmm2
movsd 0x48(%rax,%r15), %xmm3
leaq 0x3c1a4(%rip), %rdi     # 0x57aa0
movb $0x4, %al
callq 0x20f0
movq 0x48(%rsp), %r14
movq 0x80(%rsp), %rax
leaq (%r14,%rax), %rsi
addq $0x18, %rsi
movl 0x4c(%rsi), %ecx
movq 0x38(%rsp), %rdx
leaq (%rdx,%rdx,2), %rax
movq 0x60(%rsp), %r12
xorps %xmm0, %xmm0
cvtss2sd (%r12,%rax,4), %xmm0
xorps %xmm1, %xmm1
cvtss2sd 0x4(%r12,%rax,4), %xmm1
xorps %xmm2, %xmm2
cvtss2sd 0x8(%r12,%rax,4), %xmm2
leaq 0x3c178(%rip), %rdi     # 0x57ac5
movb $0x3, %al
callq 0x20f0
movq 0x88(%rsp), %rax
leaq (%r14,%rax), %rsi
addq $0x18, %rsi
movl 0x4c(%rsi), %ecx
movq 0x68(%rsp), %r15
leaq (%r15,%r15,2), %rax
xorps %xmm0, %xmm0
cvtss2sd (%r12,%rax,4), %xmm0
xorps %xmm1, %xmm1
cvtss2sd 0x4(%r12,%rax,4), %xmm1
xorps %xmm2, %xmm2
cvtss2sd 0x8(%r12,%rax,4), %xmm2
leaq 0x3c152(%rip), %rdi     # 0x57ae6
movl %r15d, %edx
movb $0x3, %al
callq 0x20f0
movsd 0x58(%rsp), %xmm3
movsd 0x8(%rsp), %xmm2
movsd 0x28(%rsp), %xmm0
movl 0x10(%rsp), %eax
movl 0x24(%rsp), %r14d
leaq 0x4(%rsp), %r13
movq 0x38(%rsp), %rcx
jmp 0x1ba61
xorps %xmm0, %xmm0
cvtss2sd 0x8(%rsp), %xmm0
movsd 0x30(%rsp), %xmm1
movsd 0x40(%rsp), %xmm2
movl 0x18(%rsp), %eax
movaps %xmm0, %xmm3
subsd 0x20(%r13), %xmm3
cvtsd2ss %xmm3, %xmm3
andps 0x3b8eb(%rip), %xmm3    # 0x572e0
cvtss2sd %xmm3, %xmm3
ucomisd 0x3b92f(%rip), %xmm3    # 0x57330
movq 0x60(%rsp), %r12
ja 0x1bc15
addsd 0x38(%rsp), %xmm1
movsd %xmm1, 0x30(%rsp)
addsd %xmm3, %xmm2
movsd %xmm2, 0x40(%rsp)
incl %eax
movl %eax, 0x18(%rsp)
movl 0x24(%rsp), %r14d
leaq 0x4(%rsp), %r13
jmp 0x1ba9c
cvtss2sd %xmm1, %xmm3
cvtss2sd 0x8(%rsp), %xmm2
movsd 0x28(%rsp), %xmm0
movl 0x10(%rsp), %eax
movl 0x24(%rsp), %r14d
movq 0x60(%rsp), %r12
leaq 0x4(%rsp), %r13
movq 0x38(%rsp), %rcx
movq 0x68(%rsp), %r15
incl %eax
movl %eax, 0x10(%rsp)
movsd 0x50(%rsp), %xmm1
ucomisd %xmm2, %xmm1
movl 0x14(%rsp), %eax
cmoval %r15d, %eax
movl %eax, 0x14(%rsp)
movl 0x20(%rsp), %eax
cmoval %ecx, %eax
movl %eax, 0x20(%rsp)
addsd %xmm3, %xmm0
movsd %xmm0, 0x28(%rsp)
minsd %xmm1, %xmm2
movsd %xmm2, 0x50(%rsp)
incq %rbp
movslq 0x5d816(%rip), %rsi     # 0x792bc
addq $0xc8, %rbx
cmpq %rsi, %rbp
jl 0x1b6f7
movl 0x20(%rsp), %ebx
movl 0x10(%rsp), %r14d
movl 0x18(%rsp), %r15d
jmp 0x1bafc
xorl %r14d, %r14d
movsd 0x3b40f(%rip), %xmm0    # 0x56ee0
movsd %xmm0, 0x50(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x40(%rsp)
movl $0xffffffff, 0x14(%rsp) # imm = 0xFFFFFFFF
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
xorl %r15d, %r15d
movsd %xmm0, 0x28(%rsp)
movsd %xmm0, 0x30(%rsp)
movl 0xd0(%rsp), %ebp
movq 0x70(%rsp), %rcx
leal -0x1(%rcx), %eax
imull %ecx, %eax
movl %eax, %edx
shrl $0x1f, %edx
addl %eax, %edx
sarl %edx
leaq 0x3bfe9(%rip), %rdi     # 0x57b07
xorl %eax, %eax
callq 0x20f0
leaq 0x4d53c(%rip), %rax     # 0x69068
xorps %xmm0, %xmm0
cvtss2sd (%rax), %xmm0
leaq 0x3bff4(%rip), %rdi     # 0x57b2e
movl %r15d, %esi
movl %ebp, %edx
movl %r14d, %ecx
movb $0x1, %al
callq 0x20f0
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
movsd 0x40(%rsp), %xmm1
divsd %xmm0, %xmm1
leaq 0x3bffa(%rip), %rdi     # 0x57b5c
movsd 0x30(%rsp), %xmm0
movsd 0x28(%rsp), %xmm2
movb $0x3, %al
callq 0x20f0
testl %ebx, %ebx
js 0x1bbd5
leaq 0x3c00d(%rip), %rdi     # 0x57b8d
movsd 0x50(%rsp), %xmm0
movb $0x1, %al
callq 0x20f0
movl %ebx, %eax
imulq $0x70, %rax, %rax
movq 0x48(%rsp), %r14
leaq (%r14,%rax), %rsi
addq $0x18, %rsi
movl 0x4c(%rsi), %ecx
leaq 0x3bff5(%rip), %rdi     # 0x57b9f
movl %ebx, %edx
xorl %eax, %eax
callq 0x20f0
movslq 0x14(%rsp), %rdx
imulq $0x70, %rdx, %rax
leaq (%r14,%rax), %rsi
addq $0x18, %rsi
movl 0x4c(%rsi), %ecx
leaq 0x3bfe2(%rip), %rdi     # 0x57bb0
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 0x4(%rsp), %esi
movl 0x1c(%rsp), %edx
xorps %xmm0, %xmm0
cvtss2sd %xmm1, %xmm0
leaq 0x3bd06(%rip), %rdi     # 0x5790f
movl %r15d, %ecx
movb $0x1, %al
callq 0x20f0
jmp 0x1bc8f
movslq 0x4(%rsp), %rax
imulq $0x70, %rax, %rax
movslq 0x1c(%rsp), %rcx
imulq $0x70, %rcx, %rsi
movq 0x48(%rsp), %rbx
leaq (%rbx,%rax), %rdx
addq $0x18, %rdx
movl 0x4c(%rdx), %ecx
leaq 0x18(%rbx,%rsi), %r8
movl 0x4c(%r8), %r9d
leaq 0x3bdbe(%rip), %rdi     # 0x57a05
movl %r15d, %esi
movb $0x1, %al
movsd %xmm0, 0x8(%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 0x3bdb6(%rip), %rdi     # 0x57a38
movsd 0x8(%rsp), %xmm0
movb $0x1, %al
callq 0x20f0
movl $0x8, %edi
callq 0x2280