// File: /workspace/github_c_makefile_star2_O0/ugobas[P]tnm/interactions_tnm.c
// Function: Interactions_all_ref
int Interactions_all_ref(struct interaction *Int_list, float thr,
			atom *atoms, int N_atoms, int N_res, char *REF)
{
  int N_int=0, i1, i2, i1_start=0, i2_start=0;
  atom *atom1=atoms, *atom2;
  float thr2=thr*thr;
  float t_max2=thr+22; t_max2*=t_max2;
  float d, d2, d2_min;
  int res1, res2;
  int CB1=0, CB2=0; //i1_min, i2_min, 
  int *notfound=malloc(N_res*sizeof(int));

  for(res1=0; res1<N_res; res1++)notfound[res1]=0;

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

    while(atoms[i1_start].res< res1)i1_start++;
    CB1=i1_start;
    if(Find_atom(atoms, &CB1, res1, N_atoms, REF)<0){
      if(notfound[res1]==0)
	printf("WARNING, %s atom not found, res= %d\n", REF, res1);
      continue;
    }
    i2_start=i1_start+1;

    for(res2=res1+1; res2<N_res; res2++){
      while(atoms[i2_start].res< res2)i2_start++;
      CB2=i2_start;
      if(Find_atom(atoms, &CB2, res2, N_atoms, REF)<0){
	if(notfound[res2]==0)
	  printf("WARNING, %s atom not found, res= %d\n", REF, res2);
	notfound[res2]=1;
	continue;
      }
      d2_min=10000;

      // Check if contact
      for(i1=i1_start; i1<N_atoms; i1++){
	atom1=atoms+i1; if(atom1->res != res1)break;
	for(i2=i2_start; i2<N_atoms; i2++){
	  atom2=atoms+i2; if(atom2->res != res2)break;

	  // 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;}
	}
      }

      // store interaction
      if(d2_min < thr2){
	// Interacting atoms set as CB (CA if Gly)
	Int_list[N_int].i1=CB1; Int_list[N_int].i2=CB2;
	//Int_list[N_int].r0=sqrt(Dist2(atoms[CB1].r, atoms[CB2].r));
	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;
    }
  }
  free(notfound);
  return(N_int);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movss %xmm0, -0xc(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x48(%rbp)
movss -0xc(%rbp), %xmm0
mulss -0xc(%rbp), %xmm0
movss %xmm0, -0x54(%rbp)
movss 0x5c52a(%rip), %xmm0    # 0x7bff0
addss -0xc(%rbp), %xmm0
movss %xmm0, -0x58(%rbp)
movss -0x58(%rbp), %xmm0
mulss -0x58(%rbp), %xmm0
movss %xmm0, -0x58(%rbp)
movl $0x0, -0x70(%rbp)
movl $0x0, -0x74(%rbp)
movslq -0x20(%rbp), %rdi
shlq $0x2, %rdi
callq 0x1180
movq %rax, -0x80(%rbp)
movl $0x0, -0x68(%rbp)
movl -0x68(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x1fb27
movq -0x80(%rbp), %rax
movslq -0x68(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0x1fb05
movl $0x0, -0x68(%rbp)
movl -0x68(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x1feea
jmp 0x1fb3c
movq -0x18(%rbp), %rax
movslq -0x38(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movl 0x64(%rax), %eax
cmpl -0x68(%rbp), %eax
jge 0x1fb5e
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x1fb3c
movl -0x38(%rbp), %eax
movl %eax, -0x70(%rbp)
movq -0x18(%rbp), %rdi
movl -0x68(%rbp), %edx
movl -0x1c(%rbp), %ecx
movq -0x28(%rbp), %r8
leaq -0x70(%rbp), %rsi
callq 0x214a0
cmpl $0x0, %eax
jge 0x1fba8
movq -0x80(%rbp), %rax
movslq -0x68(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x1fba3
movq -0x28(%rbp), %rsi
movl -0x68(%rbp), %edx
leaq 0x5c5e6(%rip), %rdi     # 0x7c182
movb $0x0, %al
callq 0x10d0
jmp 0x1fedc
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x1feda
jmp 0x1fbc8
movq -0x18(%rbp), %rax
movslq -0x3c(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movl 0x64(%rax), %eax
cmpl -0x6c(%rbp), %eax
jge 0x1fbea
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x1fbc8
movl -0x3c(%rbp), %eax
movl %eax, -0x74(%rbp)
movq -0x18(%rbp), %rdi
movl -0x6c(%rbp), %edx
movl -0x1c(%rbp), %ecx
movq -0x28(%rbp), %r8
leaq -0x74(%rbp), %rsi
callq 0x214a0
cmpl $0x0, %eax
jge 0x1fc43
movq -0x80(%rbp), %rax
movslq -0x6c(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x1fc2f
movq -0x28(%rbp), %rsi
movl -0x6c(%rbp), %edx
leaq 0x5c55a(%rip), %rdi     # 0x7c182
movb $0x0, %al
callq 0x10d0
movq -0x80(%rbp), %rax
movslq -0x6c(%rbp), %rcx
movl $0x1, (%rax,%rcx,4)
jmp 0x1fecc
movss 0x5c3a9(%rip), %xmm0    # 0x7bff4
movss %xmm0, -0x64(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x1fe0e
movq -0x18(%rbp), %rax
movslq -0x30(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movl 0x64(%rax), %eax
cmpl -0x68(%rbp), %eax
je 0x1fc86
jmp 0x1fe0e
movl -0x3c(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x1fdfe
movq -0x18(%rbp), %rax
movslq -0x34(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movl 0x64(%rax), %eax
cmpl -0x6c(%rbp), %eax
je 0x1fcbc
jmp 0x1fdfe
leaq 0x6b8fd(%rip), %rax     # 0x8b5c0
cmpl $0x0, (%rax)
je 0x1fce5
movl -0x68(%rbp), %edi
movl -0x6c(%rbp), %esi
movq -0x48(%rbp), %rdx
movq -0x50(%rbp), %rcx
callq 0x215f0
cmpl $0x0, %eax
je 0x1fce5
jmp 0x1fdf0
movq -0x50(%rbp), %rax
movsd (%rax), %xmm0
movq -0x48(%rbp), %rax
subsd (%rax), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x5c(%rbp)
movss -0x5c(%rbp), %xmm0
mulss -0x5c(%rbp), %xmm0
movss %xmm0, -0x60(%rbp)
movss -0x60(%rbp), %xmm0
ucomiss -0x54(%rbp), %xmm0
jbe 0x1fd2d
movss -0x60(%rbp), %xmm0
ucomiss -0x58(%rbp), %xmm0
jbe 0x1fd28
jmp 0x1feca
jmp 0x1fdf0
movq -0x50(%rbp), %rax
movsd 0x8(%rax), %xmm0
movq -0x48(%rbp), %rax
subsd 0x8(%rax), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x5c(%rbp)
movss -0x5c(%rbp), %xmm0
movss -0x5c(%rbp), %xmm2
movss -0x60(%rbp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x60(%rbp)
movss -0x60(%rbp), %xmm0
ucomiss -0x54(%rbp), %xmm0
jbe 0x1fd81
movss -0x60(%rbp), %xmm0
ucomiss -0x58(%rbp), %xmm0
jbe 0x1fd7f
jmp 0x1feca
jmp 0x1fdf0
movq -0x50(%rbp), %rax
movsd 0x10(%rax), %xmm0
movq -0x48(%rbp), %rax
subsd 0x10(%rax), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x5c(%rbp)
movss -0x5c(%rbp), %xmm0
movss -0x5c(%rbp), %xmm2
movss -0x60(%rbp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x60(%rbp)
movss -0x60(%rbp), %xmm0
ucomiss -0x54(%rbp), %xmm0
jbe 0x1fdd5
movss -0x60(%rbp), %xmm0
ucomiss -0x58(%rbp), %xmm0
jbe 0x1fdd3
jmp 0x1feca
jmp 0x1fdf0
movss -0x60(%rbp), %xmm1
movss -0x64(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x1fdee
movss -0x60(%rbp), %xmm0
movss %xmm0, -0x64(%rbp)
jmp 0x1fdf0
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x1fc8c
jmp 0x1fe00
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x1fc56
movss -0x64(%rbp), %xmm1
movss -0x54(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x1fec8
movl -0x70(%rbp), %ecx
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rdx
imulq $0xc8, %rdx, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movl -0x74(%rbp), %ecx
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rdx
imulq $0xc8, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x4(%rax)
movss -0x64(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x1220
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
imulq $0xc8, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, 0x20(%rax)
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
imulq $0xc8, %rcx, %rcx
addq %rcx, %rax
movsd 0x561b9(%rip), %xmm0    # 0x76048
movsd %xmm0, 0x28(%rax)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
leaq 0x7c3f1(%rip), %rcx     # 0x9c298
cmpl (%rcx), %eax
jl 0x1fec6
movl -0x2c(%rbp), %esi
leaq 0x5c226(%rip), %rdi     # 0x7c0db
movb $0x0, %al
callq 0x10d0
movl $0x8, %edi
callq 0x1210
jmp 0x1fec8
jmp 0x1feca
jmp 0x1fecc
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x1fbba
jmp 0x1fedc
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0x1fb2e
movq -0x80(%rbp), %rdi
callq 0x1040
movl -0x2c(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nop