// File: /workspace/github_c_makefile_star2_O2/ugobas[P]tnm/anharmonic_tnm.c
// Function: Min_res_dist
float Min_res_dist(float *r, atom *atoms, int *i1, int *i2, int n, int natm)
{
  int res1=atoms[*i1].res, j1=Start_res(atoms, *i1, res1);
  // YY ??? think because it's the ID of CA, so goes -1 to start with N.
  int res2=atoms[*i2].res, j2=Start_res(atoms, *i2, res2);

  float d, d2, d2_min=1000;
  atom *atom1=atoms+j1; float *r1=r+3*j1;
  // YY coord of atom j1 (r beginning of array with all atom coord)
  while(atom1->res==res1){
    atom *atom2=atoms+j2; float *r2=r+3*j2; int jj2=j2;
    while(atom2->res==res2){
      if((NOCOV) && Covalent(res1, res2, atom1, atom2))goto next;
      d=r1[0]-r2[0]; d2 =d*d; if(d2>d2_min)goto next;
      d=r1[1]-r2[1]; d2+=d*d; if(d2>d2_min)goto next;
      d=r1[2]-r2[2]; d2+=d*d; if(d2>d2_min)goto next;
      if(d2<d2_min){d2_min=d2; *i1=j1; *i2=jj2;}
    next:
      r2+=3; atom2++; jj2++; if(jj2>=natm)break;
    }
    r1+=3; atom1++; j1++; if(j1>=natm)break;
  }
  if((d2_min<=C22)||(n>=0))return(sqrt(d2_min));
  return(100);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %r9d, 0x8(%rsp)
movl %r8d, 0xc(%rsp)
movq %rcx, %rbx
movq %rsi, %r15
movq %rdi, %r12
movq %rdx, 0x28(%rsp)
movslq (%rdx), %rsi
imulq $0x70, %rsi, %rax
movl 0x64(%r15,%rax), %edx
movq %r15, %rdi
movl %edx, 0x4(%rsp)
callq 0x1aac0
movl %eax, %ebp
movq %rbx, 0x30(%rsp)
movslq (%rbx), %rsi
imulq $0x70, %rsi, %rax
movl 0x64(%r15,%rax), %ebx
movq %r15, %rdi
movl %ebx, %edx
callq 0x1aac0
movl %ebp, (%rsp)
movslq %ebp, %rcx
imulq $0x70, %rcx, %r14
addq %r15, %r14
leal (%rcx,%rcx,2), %ecx
movslq %ecx, %rcx
leaq (%r12,%rcx,4), %r13
movl %eax, 0x10(%rsp)
cltq
imulq $0x70, %rax, %rcx
addq %r15, %rcx
movq %rcx, 0x20(%rsp)
leal (%rax,%rax,2), %eax
cltq
leaq (%r12,%rax,4), %rax
addq $0x8, %rax
movq %rax, 0x18(%rsp)
movss 0x3685a(%rip), %xmm0    # 0x511f0
movl 0x4(%rsp), %eax
cmpl %eax, 0x64(%r14)
jne 0x1aa74
movq 0x18(%rsp), %r12
movq 0x20(%rsp), %r15
movl 0x10(%rsp), %ebp
cmpl %ebx, 0x64(%r15)
jne 0x1aa5a
leaq 0x48c3d(%rip), %rax     # 0x63600
cmpl $0x0, (%rax)
je 0x1a9e9
movl 0x4(%rsp), %edi
movl %ebx, %esi
movq %r14, %rdx
movq %r15, %rcx
movss %xmm0, 0x14(%rsp)
callq 0x171db
movss 0x14(%rsp), %xmm0
testl %eax, %eax
jne 0x1aa46
movss (%r13), %xmm1
subss -0x8(%r12), %xmm1
mulss %xmm1, %xmm1
ucomiss %xmm0, %xmm1
ja 0x1aa46
movss 0x4(%r13), %xmm2
subss -0x4(%r12), %xmm2
mulss %xmm2, %xmm2
addss %xmm1, %xmm2
ucomiss %xmm0, %xmm2
ja 0x1aa46
movss 0x8(%r13), %xmm1
subss (%r12), %xmm1
mulss %xmm1, %xmm1
addss %xmm2, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x1aa46
movq 0x28(%rsp), %rax
movl (%rsp), %ecx
movl %ecx, (%rax)
movq 0x30(%rsp), %rax
movl %ebp, (%rax)
movaps %xmm1, %xmm0
addq $0x70, %r15
incl %ebp
addq $0xc, %r12
cmpl 0x8(%rsp), %ebp
jl 0x1a9b2
addq $0xc, %r13
addq $0x70, %r14
movl (%rsp), %eax
incl %eax
movl %eax, (%rsp)
cmpl 0x8(%rsp), %eax
jl 0x1a996
cmpl $0x0, 0xc(%rsp)
jns 0x1aa92
movss 0x59859(%rip), %xmm1    # 0x742dc
ucomiss %xmm0, %xmm1
jae 0x1aa92
movss 0x30584(%rip), %xmm0    # 0x4b014
jmp 0x1aa9e
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jb 0x1aaad
sqrtss %xmm0, %xmm0
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x21c0