// File: /workspace/github_c_makefile_star2_O2/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, 0x40(%rsp)
leaq 0x18(%rsp), %rax
andl $0x0, (%rax)
movaps %xmm0, %xmm2
mulss %xmm0, %xmm2
mulss %xmm1, %xmm1
movss %xmm1, 0x70(%rsp)
addss 0x3a541(%rip), %xmm0    # 0x50dfc
mulss %xmm0, %xmm0
movss %xmm0, 0x2c(%rsp)
movslq %edx, %r8
movq $0x0, 0x58(%rsp)
testl %ecx, %ecx
movl $0x0, %eax
movl %ecx, 0x6c(%rsp)
cmovgl %ecx, %eax
movl %eax, 0x64(%rsp)
leaq 0x64(%rsi), %rax
movq %rax, 0x78(%rsp)
pushq $-0x1
popq %rax
xorl %edi, %edi
movl %eax, 0x28(%rsp)
movl %eax, 0x24(%rsp)
movq %rsi, 0x30(%rsp)
movss %xmm2, 0x1c(%rsp)
movq %r8, 0x48(%rsp)
cmpl 0x64(%rsp), %edi
je 0x16c52
movslq 0x58(%rsp), %r12
imulq $0x70, %r12, %rax
addq 0x78(%rsp), %rax
incq %r12
leaq 0x70(%rax), %rcx
cmpl %edi, (%rax)
movq %rcx, %rax
jl 0x16921
leal 0x1(%rdi), %ebp
leaq -0x1(%r12), %rax
movq %rax, 0x58(%rsp)
movl %ebp, 0x68(%rsp)
movq %rdi, 0x50(%rsp)
cmpl 0x6c(%rsp), %ebp
jge 0x16c47
movslq %r12d, %r12
imulq $0x70, %r12, %rax
decq %r12
movq 0x78(%rsp), %rcx
addq %rax, %rcx
addq %rsi, %rax
movq %rax, %r15
incq %r12
leaq 0x70(%rcx), %rdx
addq $0x70, %rax
cmpl %ebp, (%rcx)
movq %rdx, %rcx
jl 0x16964
xorl %ecx, %ecx
movq 0x58(%rsp), %rdx
movss 0x3a478(%rip), %xmm3    # 0x50e00
movq %r15, 0x80(%rsp)
cmpq %r8, %rdx
jge 0x16ba7
imulq $0x70, %rdx, %r13
cmpl %edi, 0x64(%rsi,%r13)
jne 0x16ba7
addq %rsi, %r13
testl %ecx, %ecx
je 0x169bd
movb 0x18(%r13), %al
andb $-0x2, %al
cmpb $0x4e, %al
jne 0x16b9f
movq %rdx, 0x38(%rsp)
leal -0x1(%rdx), %eax
movl %eax, 0x74(%rsp)
movq %r12, %r14
cmpq %r8, %r14
jge 0x16b8d
cmpl %ebp, 0x64(%r15)
jne 0x16b8d
testl %ecx, %ecx
je 0x169f1
movb 0x18(%r15), %al
andb $-0x2, %al
cmpb $0x4e, %al
jne 0x16b81
leaq 0x4cc08(%rip), %rax     # 0x63600
cmpl $0x0, (%rax)
je 0x16a36
movl %ebp, %esi
movq %r13, %rdx
movl %ebp, %ebx
movl %ecx, %ebp
movq %r15, %rcx
movss %xmm3, 0x14(%rsp)
callq 0x171db
movss 0x14(%rsp), %xmm3
movl %ebp, %ecx
movl %ebx, %ebp
movq 0x50(%rsp), %rdi
movq 0x48(%rsp), %r8
movss 0x1c(%rsp), %xmm2
testl %eax, %eax
jne 0x16b81
movsd (%r15), %xmm0
subsd (%r13), %xmm0
cvtsd2ss %xmm0, %xmm0
mulss %xmm0, %xmm0
ucomiss %xmm2, %xmm0
jbe 0x16a5e
ucomiss 0x2c(%rsp), %xmm0
jbe 0x16b81
jmp 0x16c3b
movsd 0x8(%r15), %xmm1
subsd 0x8(%r13), %xmm1
cvtsd2ss %xmm1, %xmm1
mulss %xmm1, %xmm1
addss %xmm0, %xmm1
ucomiss %xmm2, %xmm1
jbe 0x16a8b
ucomiss 0x2c(%rsp), %xmm1
jbe 0x16b81
jmp 0x16c3b
movsd 0x10(%r15), %xmm0
subsd 0x10(%r13), %xmm0
cvtsd2ss %xmm0, %xmm0
mulss %xmm0, %xmm0
addss %xmm1, %xmm0
ucomiss %xmm2, %xmm0
ja 0x16a4e
ucomiss %xmm0, %xmm3
movl 0x28(%rsp), %eax
cmoval 0x38(%rsp), %eax
movl %eax, 0x28(%rsp)
movl 0x24(%rsp), %eax
cmoval %r14d, %eax
movl %eax, 0x24(%rsp)
movaps %xmm0, %xmm4
minss %xmm3, %xmm4
movss 0x70(%rsp), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x16b7e
movzbl 0x18(%r13), %eax
cmpl $0x4f, %eax
je 0x16b20
cmpl $0x4e, %eax
jne 0x16b7e
cmpb $0x4f, 0x18(%r15)
jne 0x16b7e
movl %ecx, 0x14(%rsp)
leal -0x1(%r14), %ecx
movl $0x1, (%rsp)
movq 0x40(%rsp), %rdi
leaq 0x18(%rsp), %rsi
movq 0x30(%rsp), %rdx
movl %r14d, %r8d
movq 0x38(%rsp), %r9
jmp 0x16b4d
cmpb $0x4e, 0x18(%r15)
jne 0x16b7e
movl $0x2, (%rsp)
movq 0x40(%rsp), %rdi
leaq 0x18(%rsp), %rsi
movq 0x30(%rsp), %rdx
movl %ecx, 0x14(%rsp)
movl 0x74(%rsp), %ecx
movq 0x38(%rsp), %r8
movl %r14d, %r9d
movss %xmm4, 0x20(%rsp)
callq 0x176a7
movl 0x14(%rsp), %ecx
movq 0x50(%rsp), %rdi
movq 0x48(%rsp), %r8
movss 0x1c(%rsp), %xmm2
addl %eax, %ecx
movss 0x20(%rsp), %xmm3
cmpl $0x2, %ecx
jne 0x16b81
jmp 0x16c3b
movaps %xmm4, %xmm3
incq %r14
addq $0x70, %r15
jmp 0x169cc
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq 0x80(%rsp), %r15
incq %rdx
jmp 0x16990
testl %ecx, %ecx
jne 0x16c3b
ucomiss %xmm2, %xmm3
jae 0x16c3b
movslq 0x18(%rsp), %rbx
imulq $0xc8, %rbx, %r14
movq 0x40(%rsp), %rax
movl $0x1, 0xc0(%rax,%r14)
movl 0x28(%rsp), %ecx
movl %ecx, (%rax,%r14)
movl 0x24(%rsp), %ecx
movl %ecx, 0x4(%rax,%r14)
cvtss2sd %xmm3, %xmm0
ucomisd 0x3445e(%rip), %xmm0    # 0x4b050
jb 0x16bfa
sqrtsd %xmm0, %xmm0
jmp 0x16c0f
callq 0x2290
movq 0x50(%rsp), %rdi
movq 0x48(%rsp), %r8
movss 0x1c(%rsp), %xmm2
movq 0x40(%rsp), %rax
movsd %xmm0, 0x20(%rax,%r14)
movabsq $0x3ff0000000000000, %rcx # imm = 0x3FF0000000000000
movq %rcx, 0x28(%rax,%r14)
incl %ebx
movl %ebx, 0x18(%rsp)
leaq 0x5d6a1(%rip), %rax     # 0x742d8
cmpl (%rax), %ebx
jge 0x16c68
incl %ebp
movq 0x30(%rsp), %rsi
jmp 0x16945
movl 0x68(%rsp), %eax
movl %eax, %edi
jmp 0x16909
movl 0x18(%rsp), %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3a264(%rip), %rdi     # 0x50ed3
movl %ebx, %esi
xorl %eax, %eax
callq 0x20f0
pushq $0x8
popq %rdi
callq 0x2270