// File: /workspace/github_c_makefile_star2_O3/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, 0x18(%rsp)
movq %rdx, 0x30(%rsp)
movl (%rdx), %eax
movslq %eax, %rcx
imulq $0x70, %rcx, %rdx
movl 0x64(%rsi,%rdx), %edx
movl %edx, 0x4(%rsp)
movl %ecx, %edx
sarl $0x1f, %edx
andl %ecx, %edx
movl %edx, (%rsp)
imulq $0x70, %rax, %rcx
addq %rsi, %rcx
addq $-0xc, %rcx
movl 0x4(%rsp), %r8d
testl %eax, %eax
jle 0x1c2a1
leaq -0x70(%rcx), %rdx
decl %eax
cmpl %r8d, (%rcx)
movq %rdx, %rcx
je 0x1c28a
incl %eax
movl %eax, (%rsp)
movq 0x18(%rsp), %rax
movl (%rax), %eax
movslq %eax, %rcx
imulq $0x70, %rcx, %rdx
movl 0x64(%rsi,%rdx), %r13d
movl %ecx, %ebp
sarl $0x1f, %ebp
andl %ecx, %ebp
imulq $0x70, %rax, %rcx
addq %rsi, %rcx
addq $-0xc, %rcx
testl %eax, %eax
jle 0x1c2dc
leaq -0x70(%rcx), %rdx
decl %eax
cmpl %r13d, (%rcx)
movq %rdx, %rcx
je 0x1c2c6
incl %eax
movl %eax, %ebp
movslq (%rsp), %rax
imulq $0x70, %rax, %rbx
addq %rsi, %rbx
leal (%rax,%rax,2), %eax
cltq
leaq (%rdi,%rax,4), %r15
movslq %ebp, %rax
imulq $0x70, %rax, %rcx
addq %rsi, %rcx
movq %rcx, 0x28(%rsp)
leal (%rax,%rax,2), %eax
cltq
leaq (%rdi,%rax,4), %rax
addq $0x8, %rax
movq %rax, 0x20(%rsp)
movss 0x3af87(%rip), %xmm0    # 0x572a0
movl %ebp, 0x10(%rsp)
movl 0x4(%rsp), %eax
cmpl %eax, 0x64(%rbx)
jne 0x1c3fa
movq 0x20(%rsp), %r12
movq 0x28(%rsp), %r14
cmpl %r13d, 0x64(%r14)
jne 0x1c3dc
leaq 0x4c2bb(%rip), %rax     # 0x68600
cmpl $0x0, (%rax)
je 0x1c36c
movl 0x4(%rsp), %edi
movl %r13d, %esi
movq %rbx, %rdx
movq %r14, %rcx
movss %xmm0, 0x14(%rsp)
callq 0x18742
movss 0x14(%rsp), %xmm0
testl %eax, %eax
jne 0x1c3c8
movss (%r15), %xmm1
subss -0x8(%r12), %xmm1
mulss %xmm1, %xmm1
ucomiss %xmm0, %xmm1
ja 0x1c3c8
movss 0x4(%r15), %xmm2
subss -0x4(%r12), %xmm2
mulss %xmm2, %xmm2
addss %xmm1, %xmm2
ucomiss %xmm0, %xmm2
ja 0x1c3c8
movss 0x8(%r15), %xmm1
subss (%r12), %xmm1
mulss %xmm1, %xmm1
addss %xmm2, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x1c3c8
movq 0x30(%rsp), %rax
movl (%rsp), %ecx
movl %ecx, (%rax)
movq 0x18(%rsp), %rax
movl %ebp, (%rax)
movaps %xmm1, %xmm0
addq $0x70, %r14
incl %ebp
addq $0xc, %r12
cmpl 0x8(%rsp), %ebp
jl 0x1c334
addq $0xc, %r15
addq $0x70, %rbx
movl (%rsp), %eax
incl %eax
movl %eax, (%rsp)
cmpl 0x8(%rsp), %eax
movl 0x10(%rsp), %ebp
jl 0x1c31d
cmpl $0x0, 0xc(%rsp)
jns 0x1c418
movss 0x5ced3(%rip), %xmm1    # 0x792dc
ucomiss %xmm0, %xmm1
jae 0x1c418
movss 0x34d0a(%rip), %xmm0    # 0x51120
jmp 0x1c424
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jb 0x1c433
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 0x21d0