// File: /workspace/github_c_makefile_star2_O3/ugobas[P]tnm/interactions_tnm.c
// Function: Interactions_HB
int Interactions_HB(struct interaction *Int_list, float thr,
		    atom *atoms, int N_atoms, int N_res,
		    float thr_NO, float cos_HB, float ene_HB)
{
  // Hydrogen bonds, in the form of N-O pairs, are separated
  int N_int=0, i1, i2, i1_start=0, i2_start=0;
  atom *atom1=atoms, *atom2;
  float thr2=thr*thr;
  float thr2_NO=thr_NO*thr_NO;
  float t_max2=thr+22; t_max2*=t_max2;
  float d, d2, d2_min;
  int res1, res2;
  int i1_min=-1, i2_min=-1, i_hb;

  for(res1=0; res1<N_res; res1++){

    while(atoms[i1_start].res< res1)i1_start++;
    i2_start=i1_start+1;

    for(res2=res1+1; res2<N_res; res2++){
      while(atoms[i2_start].res< res2)i2_start++;
      d2_min=10000; i_hb=0;

      // Check if contact
      for(i1=i1_start; i1<N_atoms; i1++){
	atom1=atoms+i1; if(atom1->res != res1)break;
	if((i_hb)&&(atom1->name[0]!='N')&&(atom1->name[0]!='O'))continue;
	for(i2=i2_start; i2<N_atoms; i2++){
	  atom2=atoms+i2; if(atom2->res != res2)break;
	  if((i_hb)&&(atom2->name[0]!='N')&&(atom2->name[0]!='O'))continue;

	  // Check if covalent
	  if((NOCOV) && Covalent(res1, res2, atom1, atom2))continue;

	  // Interatomic distance
	  d=atom2->r[0]-atom1->r[0];
	  d2 =d*d; if(d2>thr2){if(d2 > t_max2)goto next2; continue;}
	  d=atom2->r[1]-atom1->r[1];
	  d2+=d*d; if(d2>thr2){if(d2 > t_max2)goto next2; continue;}
	  d=atom2->r[2]-atom1->r[2];
	  d2+=d*d; if(d2>thr2){if(d2 > t_max2)goto next2; continue;}
	  if(d2 < d2_min){d2_min=d2; i1_min=i1; i2_min=i2;}
	  if(d2 < thr2_NO){
	    if((atom1->name[0]=='N')&&(atom2->name[0]=='O')){
	      int i_AA=i2-1;
	      i_hb+=Check_store_HB(Int_list,&N_int,atoms,i_AA,i2,i1,1,d2);
	      if(i_hb==2)goto next2;
	    }else if((atom1->name[0]=='O')&&(atom2->name[0]=='N')){
	      int i_AA=i1-1;
	      i_hb+=Check_store_HB(Int_list,&N_int,atoms,i_AA,i1,i2,2,d2);
	      if(i_hb==2)goto next2;
	    }
	  }
	}
      }

      // store interaction
      if((i_hb)||(d2_min >= thr2))goto next2;
      Int_list[N_int].type=1;
      Int_list[N_int].i1=i1_min; Int_list[N_int].i2=i2_min;
      Int_list[N_int].r0=sqrt(d2_min); Int_list[N_int].sec_der=1;
      N_int++;
      if(N_int >= INT_MAX){
	printf("ERROR, too many interactions %d\n", N_int); exit(8);
      }

    next2: continue;
    }
  }
  return(N_int);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdi, 0x38(%rsp)
movl $0x0, 0x14(%rsp)
movl %ecx, 0x28(%rsp)
testl %ecx, %ecx
jle 0x18171
movaps %xmm0, %xmm3
movaps %xmm0, %xmm4
mulss %xmm3, %xmm4
mulss %xmm1, %xmm1
addss 0x3f11a(%rip), %xmm3    # 0x56eac
mulss %xmm3, %xmm3
movl %edx, 0x34(%rsp)
movslq %edx, %r8
leaq 0x64(%rsi), %rax
movq %rax, 0x70(%rsp)
xorl %edi, %edi
movl $0xffffffff, 0x30(%rsp) # imm = 0xFFFFFFFF
movl $0xffffffff, 0x2c(%rsp) # imm = 0xFFFFFFFF
movq $0x0, 0x60(%rsp)
movss %xmm1, 0x20(%rsp)
movq %rsi, 0x40(%rsp)
movss %xmm3, 0x1c(%rsp)
movss %xmm4, 0x18(%rsp)
movq %r8, 0x48(%rsp)
movslq 0x60(%rsp), %r13
leal -0x1(%r13), %edx
imulq $0x70, %r13, %rax
addq 0x70(%rsp), %rax
incq %r13
incl %edx
leaq 0x70(%rax), %rcx
cmpl %edi, (%rax)
movq %rcx, %rax
jl 0x17def
leal 0x1(%rdi), %eax
leaq -0x1(%r13), %rcx
movq %rcx, 0x60(%rsp)
cmpl 0x28(%rsp), %eax
movq %rax, 0x78(%rsp)
jge 0x1815c
movl %edx, 0x68(%rsp)
movl %eax, %r12d
movq %rdi, 0x50(%rsp)
movslq %r13d, %r13
imulq $0x70, %r13, %rax
decq %r13
movq 0x70(%rsp), %rcx
addq %rax, %rcx
addq %rsi, %rax
movq %rax, %r9
incq %r13
leaq 0x70(%rcx), %rdx
addq $0x70, %rax
cmpl %r12d, (%rcx)
movq %rdx, %rcx
jl 0x17e3b
movb $0x1, %al
movl 0x68(%rsp), %ecx
cmpl 0x34(%rsp), %ecx
jge 0x1809e
movq %r9, 0x80(%rsp)
xorl %ecx, %ecx
movq 0x60(%rsp), %rdx
movss 0x3f038(%rip), %xmm5    # 0x56eb0
imulq $0x70, %rdx, %rbx
cmpl %edi, 0x64(%rsi,%rbx)
jne 0x18097
addq %rsi, %rbx
testl %ecx, %ecx
movq %rdx, 0x58(%rsp)
je 0x17e9f
movb 0x18(%rbx), %al
andb $-0x2, %al
cmpb $0x4e, %al
jne 0x18081
cmpl 0x34(%rsp), %r13d
jge 0x18081
leal -0x1(%rdx), %eax
movl %eax, 0x6c(%rsp)
movq 0x80(%rsp), %rbp
movq %r13, %r14
cmpl %r12d, 0x64(%rbp)
jne 0x18081
testl %ecx, %ecx
je 0x17ed7
movb 0x18(%rbp), %al
andb $-0x2, %al
cmpb $0x4e, %al
jne 0x18071
leaq 0x50722(%rip), %rax     # 0x68600
cmpl $0x0, (%rax)
je 0x17f2d
movl %r12d, %esi
movq %rbx, %rdx
movl %r12d, %r15d
movl %ecx, %r12d
movq %rbp, %rcx
movss %xmm5, 0x10(%rsp)
callq 0x18742
movss 0x10(%rsp), %xmm5
movl %r12d, %ecx
movl %r15d, %r12d
movq 0x50(%rsp), %rdi
movq 0x48(%rsp), %r8
movss 0x18(%rsp), %xmm4
movss 0x1c(%rsp), %xmm3
movss 0x20(%rsp), %xmm1
testl %eax, %eax
jne 0x18071
movsd (%rbp), %xmm0
subsd (%rbx), %xmm0
cvtsd2ss %xmm0, %xmm0
mulss %xmm0, %xmm0
ucomiss %xmm4, %xmm0
jbe 0x17f51
ucomiss %xmm3, %xmm0
jbe 0x18071
jmp 0x18149
movsd 0x8(%rbp), %xmm2
subsd 0x8(%rbx), %xmm2
cvtsd2ss %xmm2, %xmm2
mulss %xmm2, %xmm2
addss %xmm0, %xmm2
ucomiss %xmm4, %xmm2
jbe 0x17f7a
ucomiss %xmm3, %xmm2
jbe 0x18071
jmp 0x18149
movsd 0x10(%rbp), %xmm0
subsd 0x10(%rbx), %xmm0
cvtsd2ss %xmm0, %xmm0
mulss %xmm0, %xmm0
addss %xmm2, %xmm0
ucomiss %xmm4, %xmm0
ja 0x17f43
ucomiss %xmm0, %xmm5
movl 0x2c(%rsp), %eax
cmoval 0x58(%rsp), %eax
movl %eax, 0x2c(%rsp)
movl 0x30(%rsp), %eax
cmoval %r14d, %eax
movl %eax, 0x30(%rsp)
movaps %xmm0, %xmm2
minss %xmm5, %xmm2
ucomiss %xmm0, %xmm1
jbe 0x1806e
movzbl 0x18(%rbx), %eax
cmpl $0x4f, %eax
je 0x18005
cmpl $0x4e, %eax
jne 0x1806e
cmpb $0x4f, 0x18(%rbp)
jne 0x1806e
movl %ecx, 0x10(%rsp)
leal -0x1(%r14), %ecx
movl $0x1, (%rsp)
movq 0x38(%rsp), %rdi
leaq 0x14(%rsp), %rsi
movq 0x40(%rsp), %rdx
movl %r14d, %r8d
movq 0x58(%rsp), %r9
jmp 0x18031
cmpb $0x4e, 0x18(%rbp)
jne 0x1806e
movl $0x2, (%rsp)
movq 0x38(%rsp), %rdi
leaq 0x14(%rsp), %rsi
movq 0x40(%rsp), %rdx
movl %ecx, 0x10(%rsp)
movl 0x6c(%rsp), %ecx
movq 0x58(%rsp), %r8
movl %r14d, %r9d
movss %xmm2, 0x24(%rsp)
callq 0x18c57
movl 0x10(%rsp), %ecx
movq 0x50(%rsp), %rdi
movq 0x48(%rsp), %r8
movss 0x18(%rsp), %xmm4
movss 0x1c(%rsp), %xmm3
movss 0x20(%rsp), %xmm1
addl %eax, %ecx
movss 0x24(%rsp), %xmm5
cmpl $0x2, %ecx
jne 0x18071
jmp 0x18149
movaps %xmm2, %xmm5
incq %r14
addq $0x70, %rbp
cmpq %r8, %r14
jl 0x17ebc
movq 0x58(%rsp), %rdx
incq %rdx
cmpq %r8, %rdx
movq 0x40(%rsp), %rsi
jl 0x17e78
testl %ecx, %ecx
sete %al
jmp 0x180a6
movss 0x3ee0a(%rip), %xmm5    # 0x56eb0
testb %al, %al
je 0x18149
ucomiss %xmm4, %xmm5
jae 0x18149
movslq 0x14(%rsp), %rbx
imulq $0xc8, %rbx, %r14
movq 0x38(%rsp), %rax
movl $0x1, 0xc0(%rax,%r14)
movl 0x2c(%rsp), %ecx
movl %ecx, (%rax,%r14)
movl 0x30(%rsp), %ecx
movl %ecx, 0x4(%rax,%r14)
xorps %xmm0, %xmm0
cvtss2sd %xmm5, %xmm0
ucomisd 0x39084(%rip), %xmm0    # 0x51178
jb 0x180fc
sqrtsd %xmm0, %xmm0
jmp 0x1811d
callq 0x22a0
movq 0x50(%rsp), %rdi
movq 0x48(%rsp), %r8
movss 0x18(%rsp), %xmm4
movss 0x1c(%rsp), %xmm3
movss 0x20(%rsp), %xmm1
movq 0x38(%rsp), %rax
movsd %xmm0, 0x20(%rax,%r14)
movabsq $0x3ff0000000000000, %rcx # imm = 0x3FF0000000000000
movq %rcx, 0x28(%rax,%r14)
incl %ebx
movl %ebx, 0x14(%rsp)
leaq 0x61193(%rip), %rax     # 0x792d8
cmpl (%rax), %ebx
jge 0x18185
incl %r12d
cmpl 0x28(%rsp), %r12d
movq 0x40(%rsp), %rsi
jne 0x17e26
movq 0x78(%rsp), %rdi
cmpl 0x28(%rsp), %edi
jne 0x17ddd
movl 0x14(%rsp), %eax
jmp 0x18173
xorl %eax, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3edf7(%rip), %rdi     # 0x56f83
movl %ebx, %esi
xorl %eax, %eax
callq 0x20f0
movl $0x8, %edi
callq 0x2280