// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movss %xmm0, -0xc(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movss %xmm1, -0x24(%rbp)
movss %xmm2, -0x28(%rbp)
movss %xmm3, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x48(%rbp)
movss -0xc(%rbp), %xmm0
mulss -0xc(%rbp), %xmm0
movss %xmm0, -0x54(%rbp)
movss -0x24(%rbp), %xmm0
mulss -0x24(%rbp), %xmm0
movss %xmm0, -0x58(%rbp)
movss 0x5b7b0(%rip), %xmm0    # 0x7bff0
addss -0xc(%rbp), %xmm0
movss %xmm0, -0x5c(%rbp)
movss -0x5c(%rbp), %xmm0
mulss -0x5c(%rbp), %xmm0
movss %xmm0, -0x5c(%rbp)
movl $0xffffffff, -0x74(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x78(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x20ce0
jmp 0x2087c
movq -0x18(%rbp), %rax
movslq -0x3c(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movl 0x64(%rax), %eax
cmpl -0x6c(%rbp), %eax
jge 0x2089e
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x2087c
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
movl -0x70(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x20cd0
jmp 0x208be
movq -0x18(%rbp), %rax
movslq -0x40(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movl 0x64(%rax), %eax
cmpl -0x70(%rbp), %eax
jge 0x208e0
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x208be
movss 0x5b70c(%rip), %xmm0    # 0x7bff4
movss %xmm0, -0x68(%rbp)
movl $0x0, -0x7c(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x20be7
movq -0x18(%rbp), %rax
movslq -0x34(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movl 0x64(%rax), %eax
cmpl -0x6c(%rbp), %eax
je 0x2092a
jmp 0x20be7
cmpl $0x0, -0x7c(%rbp)
je 0x2094f
movq -0x48(%rbp), %rax
movsbl 0x18(%rax), %eax
cmpl $0x4e, %eax
je 0x2094f
movq -0x48(%rbp), %rax
movsbl 0x18(%rax), %eax
cmpl $0x4f, %eax
je 0x2094f
jmp 0x20bd9
movl -0x40(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x20bd7
movq -0x18(%rbp), %rax
movslq -0x38(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movl 0x64(%rax), %eax
cmpl -0x70(%rbp), %eax
je 0x20985
jmp 0x20bd7
cmpl $0x0, -0x7c(%rbp)
je 0x209aa
movq -0x50(%rbp), %rax
movsbl 0x18(%rax), %eax
cmpl $0x4e, %eax
je 0x209aa
movq -0x50(%rbp), %rax
movsbl 0x18(%rax), %eax
cmpl $0x4f, %eax
je 0x209aa
jmp 0x20bc9
leaq 0x6ac0f(%rip), %rax     # 0x8b5c0
cmpl $0x0, (%rax)
je 0x209d3
movl -0x6c(%rbp), %edi
movl -0x70(%rbp), %esi
movq -0x48(%rbp), %rdx
movq -0x50(%rbp), %rcx
callq 0x215f0
cmpl $0x0, %eax
je 0x209d3
jmp 0x20bc9
movq -0x50(%rbp), %rax
movsd (%rax), %xmm0
movq -0x48(%rbp), %rax
subsd (%rax), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x60(%rbp)
movss -0x60(%rbp), %xmm0
mulss -0x60(%rbp), %xmm0
movss %xmm0, -0x64(%rbp)
movss -0x64(%rbp), %xmm0
ucomiss -0x54(%rbp), %xmm0
jbe 0x20a1b
movss -0x64(%rbp), %xmm0
ucomiss -0x5c(%rbp), %xmm0
jbe 0x20a16
jmp 0x20cc0
jmp 0x20bc9
movq -0x50(%rbp), %rax
movsd 0x8(%rax), %xmm0
movq -0x48(%rbp), %rax
subsd 0x8(%rax), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x60(%rbp)
movss -0x60(%rbp), %xmm0
movss -0x60(%rbp), %xmm2
movss -0x64(%rbp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x64(%rbp)
movss -0x64(%rbp), %xmm0
ucomiss -0x54(%rbp), %xmm0
jbe 0x20a72
movss -0x64(%rbp), %xmm0
ucomiss -0x5c(%rbp), %xmm0
jbe 0x20a6d
jmp 0x20cc0
jmp 0x20bc9
movq -0x50(%rbp), %rax
movsd 0x10(%rax), %xmm0
movq -0x48(%rbp), %rax
subsd 0x10(%rax), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x60(%rbp)
movss -0x60(%rbp), %xmm0
movss -0x60(%rbp), %xmm2
movss -0x64(%rbp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x64(%rbp)
movss -0x64(%rbp), %xmm0
ucomiss -0x54(%rbp), %xmm0
jbe 0x20ac9
movss -0x64(%rbp), %xmm0
ucomiss -0x5c(%rbp), %xmm0
jbe 0x20ac4
jmp 0x20cc0
jmp 0x20bc9
movss -0x64(%rbp), %xmm1
movss -0x68(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x20aee
movss -0x64(%rbp), %xmm0
movss %xmm0, -0x68(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0x74(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0x78(%rbp)
movss -0x64(%rbp), %xmm1
movss -0x58(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x20bc7
movq -0x48(%rbp), %rax
movsbl 0x18(%rax), %eax
cmpl $0x4e, %eax
jne 0x20b5f
movq -0x50(%rbp), %rax
movsbl 0x18(%rax), %eax
cmpl $0x4f, %eax
jne 0x20b5f
movl -0x38(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x80(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rdx
movl -0x80(%rbp), %ecx
movl -0x38(%rbp), %r8d
movl -0x34(%rbp), %r9d
movss -0x64(%rbp), %xmm0
leaq -0x30(%rbp), %rsi
movl $0x1, (%rsp)
callq 0x21e70
addl -0x7c(%rbp), %eax
movl %eax, -0x7c(%rbp)
cmpl $0x2, -0x7c(%rbp)
jne 0x20b5d
jmp 0x20cc0
jmp 0x20bc5
movq -0x48(%rbp), %rax
movsbl 0x18(%rax), %eax
cmpl $0x4f, %eax
jne 0x20bc3
movq -0x50(%rbp), %rax
movsbl 0x18(%rax), %eax
cmpl $0x4e, %eax
jne 0x20bc3
movl -0x34(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x84(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rdx
movl -0x84(%rbp), %ecx
movl -0x34(%rbp), %r8d
movl -0x38(%rbp), %r9d
movss -0x64(%rbp), %xmm0
leaq -0x30(%rbp), %rsi
movl $0x2, (%rsp)
callq 0x21e70
addl -0x7c(%rbp), %eax
movl %eax, -0x7c(%rbp)
cmpl $0x2, -0x7c(%rbp)
jne 0x20bc1
jmp 0x20cc0
jmp 0x20bc3
jmp 0x20bc5
jmp 0x20bc7
jmp 0x20bc9
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x20955
jmp 0x20bd9
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x208fa
cmpl $0x0, -0x7c(%rbp)
jne 0x20bf8
movss -0x68(%rbp), %xmm0
ucomiss -0x54(%rbp), %xmm0
jb 0x20bfd
jmp 0x20cc0
movq -0x8(%rbp), %rax
movslq -0x30(%rbp), %rcx
imulq $0xc8, %rcx, %rcx
addq %rcx, %rax
movl $0x1, 0xc0(%rax)
movl -0x74(%rbp), %ecx
movq -0x8(%rbp), %rax
movslq -0x30(%rbp), %rdx
imulq $0xc8, %rdx, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movl -0x78(%rbp), %ecx
movq -0x8(%rbp), %rax
movslq -0x30(%rbp), %rdx
imulq $0xc8, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x4(%rax)
movss -0x68(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x1220
movq -0x8(%rbp), %rax
movslq -0x30(%rbp), %rcx
imulq $0xc8, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, 0x20(%rax)
movq -0x8(%rbp), %rax
movslq -0x30(%rbp), %rcx
imulq $0xc8, %rcx, %rcx
addq %rcx, %rax
movsd 0x553c1(%rip), %xmm0    # 0x76048
movsd %xmm0, 0x28(%rax)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
leaq 0x7b5f9(%rip), %rcx     # 0x9c298
cmpl (%rcx), %eax
jl 0x20cbe
movl -0x30(%rbp), %esi
leaq 0x5b42e(%rip), %rdi     # 0x7c0db
movb $0x0, %al
callq 0x10d0
movl $0x8, %edi
callq 0x1210
jmp 0x20cc0
jmp 0x20cc2
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0x208b0
jmp 0x20cd2
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x2086e
movl -0x30(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax)