// File: /workspace/github_c_makefile_star2_O1/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 $0x98, %rsp
movss %xmm1, 0x20(%rsp)
movl %edx, 0x30(%rsp)
movq %rdi, 0x38(%rsp)
movl $0x0, 0x14(%rsp)
movl %ecx, 0x24(%rsp)
testl %ecx, %ecx
jle 0x18891
movaps %xmm0, %xmm1
movaps %xmm0, %xmm2
mulss %xmm0, %xmm2
movss 0x20(%rsp), %xmm0
mulss %xmm0, %xmm0
movss %xmm0, 0x20(%rsp)
addss 0x3ea44(%rip), %xmm1    # 0x56eec
mulss %xmm1, %xmm1
movss %xmm1, 0x34(%rsp)
movslq 0x30(%rsp), %r8
leaq 0x64(%rsi), %rax
movq %rax, 0x70(%rsp)
xorl %edi, %edi
movl $0xffffffff, 0x2c(%rsp) # imm = 0xFFFFFFFF
movl $0xffffffff, 0x28(%rsp) # imm = 0xFFFFFFFF
movq $0x0, 0x60(%rsp)
movq %rsi, 0x40(%rsp)
movss %xmm2, 0x18(%rsp)
movq %r8, 0x48(%rsp)
movslq 0x60(%rsp), %r9
leal -0x1(%r9), %edx
imulq $0x70, %r9, %rax
addq 0x70(%rsp), %rax
incq %r9
incl %edx
leaq 0x70(%rax), %rcx
cmpl %edi, (%rax)
movq %rcx, %rax
jl 0x184fd
leal 0x1(%rdi), %eax
leaq -0x1(%r9), %rcx
movq %rcx, 0x60(%rsp)
cmpl 0x24(%rsp), %eax
movq %rax, 0x80(%rsp)
jge 0x1887f
movl %edx, 0x68(%rsp)
movl %eax, %r15d
movq %rdi, 0x50(%rsp)
movslq %r9d, %r9
imulq $0x70, %r9, %rax
decq %r9
movq 0x70(%rsp), %rcx
addq %rax, %rcx
addq %rsi, %rax
movq %r9, %r11
movq %rax, %rbx
incq %r9
leaq 0x70(%rcx), %rdx
addq $0x70, %rax
cmpl %r15d, (%rcx)
movq %rdx, %rcx
jl 0x1854c
movb $0x1, %al
movl 0x68(%rsp), %ecx
cmpl 0x30(%rsp), %ecx
movq %r9, 0x78(%rsp)
jge 0x187c9
movq %rbx, 0x88(%rsp)
xorl %ecx, %ecx
movq 0x60(%rsp), %rdx
movss 0x3e95f(%rip), %xmm3    # 0x56ef0
movq %r11, 0x90(%rsp)
imulq $0x70, %rdx, %r12
cmpl %edi, 0x64(%rsi,%r12)
jne 0x187c2
addq %rsi, %r12
testl %ecx, %ecx
movq %rdx, 0x58(%rsp)
je 0x185c3
movb 0x18(%r12), %al
andb $-0x2, %al
cmpb $0x4e, %al
jne 0x1879f
cmpl 0x30(%rsp), %r9d
jge 0x1879f
leal -0x1(%rdx), %eax
movl %eax, 0x6c(%rsp)
movq 0x88(%rsp), %rbp
movq %r11, %r14
movq %r9, %rbx
cmpl %r15d, 0x64(%rbp)
jne 0x1879f
testl %ecx, %ecx
je 0x185fe
movb 0x18(%rbp), %al
andb $-0x2, %al
cmpb $0x4e, %al
jne 0x1878c
leaq 0x4fffb(%rip), %rax     # 0x68600
cmpl $0x0, (%rax)
je 0x18642
movl %r15d, %esi
movq %r12, %rdx
movl %ecx, %r13d
movq %rbp, %rcx
movss %xmm3, 0x10(%rsp)
callq 0x18e79
movss 0x10(%rsp), %xmm3
movl %r13d, %ecx
movq 0x50(%rsp), %rdi
movq 0x48(%rsp), %r8
movss 0x18(%rsp), %xmm2
testl %eax, %eax
jne 0x1878c
movsd (%rbp), %xmm0
subsd (%r12), %xmm0
cvtsd2ss %xmm0, %xmm0
mulss %xmm0, %xmm0
ucomiss %xmm2, %xmm0
jbe 0x1866a
ucomiss 0x34(%rsp), %xmm0
jbe 0x1878c
jmp 0x18867
movsd 0x8(%rbp), %xmm1
subsd 0x8(%r12), %xmm1
cvtsd2ss %xmm1, %xmm1
mulss %xmm1, %xmm1
addss %xmm0, %xmm1
ucomiss %xmm2, %xmm1
jbe 0x18697
ucomiss 0x34(%rsp), %xmm1
jbe 0x1878c
jmp 0x18867
movsd 0x10(%rbp), %xmm0
subsd 0x10(%r12), %xmm0
cvtsd2ss %xmm0, %xmm0
mulss %xmm0, %xmm0
addss %xmm1, %xmm0
ucomiss %xmm2, %xmm0
ja 0x1865a
ucomiss %xmm0, %xmm3
movl 0x28(%rsp), %eax
cmoval 0x58(%rsp), %eax
movl %eax, 0x28(%rsp)
leal 0x1(%r14), %r9d
movl 0x2c(%rsp), %eax
cmoval %r9d, %eax
movl %eax, 0x2c(%rsp)
movaps %xmm0, %xmm4
minss %xmm3, %xmm4
movss 0x20(%rsp), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x18789
movzbl 0x18(%r12), %eax
cmpl $0x4f, %eax
je 0x1872f
cmpl $0x4e, %eax
jne 0x18789
cmpb $0x4f, 0x18(%rbp)
jne 0x1872b
movl $0x1, (%rsp)
movq 0x38(%rsp), %rdi
leaq 0x14(%rsp), %rsi
movq 0x40(%rsp), %rdx
movl %ecx, 0x10(%rsp)
movl %r14d, %ecx
movl %r9d, %r8d
movq 0x58(%rsp), %r9
jmp 0x18758
cmpb $0x4f, %al
jne 0x18789
cmpb $0x4e, 0x18(%rbp)
jne 0x18789
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
movss %xmm4, 0x1c(%rsp)
callq 0x1943b
movl 0x10(%rsp), %ecx
movq 0x50(%rsp), %rdi
movq 0x48(%rsp), %r8
movss 0x18(%rsp), %xmm2
addl %eax, %ecx
movss 0x1c(%rsp), %xmm3
cmpl $0x2, %ecx
jne 0x1878c
jmp 0x18867
movaps %xmm4, %xmm3
incq %rbx
incl %r14d
addq $0x70, %rbp
cmpq %r8, %rbx
jl 0x185e3
movq 0x58(%rsp), %rdx
incq %rdx
cmpq %r8, %rdx
movq 0x40(%rsp), %rsi
movq 0x78(%rsp), %r9
movq 0x90(%rsp), %r11
jl 0x18599
testl %ecx, %ecx
sete %al
jmp 0x187d1
movss 0x3e71f(%rip), %xmm3    # 0x56ef0
testb %al, %al
je 0x18867
ucomiss %xmm2, %xmm3
jae 0x18867
movslq 0x14(%rsp), %r14
imulq $0xc8, %r14, %rbx
movq 0x38(%rsp), %rax
movl $0x1, 0xc0(%rax,%rbx)
movl 0x28(%rsp), %ecx
movl %ecx, (%rax,%rbx)
movl 0x2c(%rsp), %ecx
movl %ecx, 0x4(%rax,%rbx)
xorps %xmm0, %xmm0
cvtss2sd %xmm3, %xmm0
ucomisd 0x38844(%rip), %xmm0    # 0x51060
jb 0x18824
sqrtsd %xmm0, %xmm0
jmp 0x18839
callq 0x2290
movq 0x50(%rsp), %rdi
movq 0x48(%rsp), %r8
movss 0x18(%rsp), %xmm2
movq 0x38(%rsp), %rax
movsd %xmm0, 0x20(%rax,%rbx)
movabsq $0x3ff0000000000000, %rcx # imm = 0x3FF0000000000000
movq %rcx, 0x28(%rax,%rbx)
incl %r14d
movl %r14d, 0x14(%rsp)
leaq 0x60a76(%rip), %rax     # 0x792d8
cmpl (%rax), %r14d
jge 0x188a7
incl %r15d
cmpl 0x24(%rsp), %r15d
movq 0x40(%rsp), %rsi
movq 0x78(%rsp), %r9
jne 0x18537
movq 0x80(%rsp), %rdi
cmpl 0x24(%rsp), %edi
jne 0x184eb
movl 0x14(%rsp), %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3e715(%rip), %rdi     # 0x56fc3
movl %r14d, %esi
xorl %eax, %eax
callq 0x20f0
movl $0x8, %edi
callq 0x2270