// File: /workspace/github_cpp_makefile_star2_O3/gjoni[P]iPot/src/Residue.cpp
// Function: Residue::MinDist(Residue const&, Residue const&, int)
double Residue::MinDist(const Residue &R1, const Residue &R2, int mode) {

	double dmin = 9999.99;

	switch (mode) {

	case 0: /* SC + BB */
		for (int i = 0; i < R1.nAtoms; i++) {
			if (R1.atom[i].type == 'H') {
				continue;
			}
			for (int j = 0; j < R2.nAtoms; j++) {
				if (R2.atom[j].type == 'H') {
					continue;
				}
				double d = Atom::Dist(R1.atom[i], R2.atom[j]);
				dmin = d < dmin ? d : dmin;
			}
		}
		break;

	case 1: /* SC */
		for (int i = 0; i < R1.nAtoms; i++) {
			Atom *A = &(R1.atom[i]);
			if (A == R1.C || A == R1.CA || A == R1.N || A == R1.O) {
				continue;
			}
			if (R1.atom[i].type == 'H') {
				continue;
			}
			for (int j = 0; j < R2.nAtoms; j++) {
				Atom *B = &(R2.atom[j]);
				if (B == R2.C || B == R2.CA || B == R2.N || B == R2.O) {
					continue;
				}
				if (R2.atom[j].type == 'H') {
					continue;
				}
				double d = Atom::Dist(R1.atom[i], R2.atom[j]);
				dmin = d < dmin ? d : dmin;
			}
		}
		break;

	case 2: /* BB */
		for (int i = 0; i < R1.nAtoms; i++) {
			Atom *A = &(R1.atom[i]);
			if (A != R1.C && A != R1.CA && A != R1.N && A != R1.O) {
				continue;
			}
			if (R1.atom[i].type == 'H') {
				continue;
			}
			for (int j = 0; j < R2.nAtoms; j++) {
				Atom *B = &(R2.atom[j]);
				if (B != R2.C && B != R2.CA && B != R2.N && B != R2.O) {
					continue;
				}
				if (R2.atom[j].type == 'H') {
					continue;
				}
				double d = Atom::Dist(R1.atom[i], R2.atom[j]);
				dmin = d < dmin ? d : dmin;
			}
		}
		break;

	default:
		return dmin;
		break;

	}

	return dmin;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
movsd 0xab77(%rip), %xmm0     # 0x1f648
testl %edx, %edx
je 0x14cff
cmpl $0x1, %edx
je 0x14bf8
cmpl $0x2, %edx
jne 0x14d78
movl 0x18(%r14), %eax
testl %eax, %eax
jle 0x14d78
movsd 0xab49(%rip), %xmm0     # 0x1f648
xorl %r15d, %r15d
movq 0x10(%r14), %rcx
leaq (%r15,%r15,2), %r12
shlq $0x5, %r12
leaq (%rcx,%r12), %rdx
movdqu 0x160(%r14), %xmm3
movdqu 0x170(%r14), %xmm1
movq %rdx, %xmm2
pshufd $0x44, %xmm2, %xmm2     # xmm2 = xmm2[0,1,0,1]
pcmpeqd %xmm2, %xmm1
pcmpeqd %xmm2, %xmm3
movdqa %xmm3, %xmm2
shufps $0xdd, %xmm1, %xmm2     # xmm2 = xmm2[1,3],xmm1[1,3]
shufps $0x88, %xmm1, %xmm3     # xmm3 = xmm3[0,2],xmm1[0,2]
andps %xmm2, %xmm3
movmskps %xmm3, %edx
testl %edx, %edx
je 0x14be4
cmpb $0x48, 0x58(%rcx,%r12)
setne %dl
movl 0x18(%rbx), %ecx
testl %ecx, %ecx
setg %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0x14be4
xorl %r13d, %r13d
xorl %ebp, %ebp
movq 0x10(%rbx), %rax
leaq (%rax,%r13), %rsi
movdqu 0x160(%rbx), %xmm3
movdqu 0x170(%rbx), %xmm1
movq %rsi, %xmm2
pshufd $0x44, %xmm2, %xmm2     # xmm2 = xmm2[0,1,0,1]
pcmpeqd %xmm2, %xmm1
pcmpeqd %xmm2, %xmm3
movdqa %xmm3, %xmm2
shufps $0xdd, %xmm1, %xmm2     # xmm2 = xmm2[1,3],xmm1[1,3]
shufps $0x88, %xmm1, %xmm3     # xmm3 = xmm3[0,2],xmm1[0,2]
andps %xmm2, %xmm3
movmskps %xmm3, %edx
testl %edx, %edx
je 0x14bd1
cmpb $0x48, 0x58(%rax,%r13)
je 0x14bd1
movq 0x10(%r14), %rdi
addq %r12, %rdi
movsd %xmm0, (%rsp)
callq 0xe5c4
minsd (%rsp), %xmm0
movl 0x18(%rbx), %ecx
incq %rbp
movslq %ecx, %rax
addq $0x60, %r13
cmpq %rax, %rbp
jl 0x14b70
movl 0x18(%r14), %eax
incq %r15
movslq %eax, %rcx
cmpq %rcx, %r15
jl 0x14b02
jmp 0x14d78
movl 0x18(%r14), %eax
testl %eax, %eax
jle 0x14d78
movsd 0xaa3c(%rip), %xmm0     # 0x1f648
xorl %r15d, %r15d
leaq (%r15,%r15,2), %r12
shlq $0x5, %r12
movq 0x10(%r14), %rcx
addq %r12, %rcx
movdqu 0x160(%r14), %xmm3
movdqu 0x170(%r14), %xmm1
movq %rcx, %xmm2
pshufd $0x44, %xmm2, %xmm2     # xmm2 = xmm2[0,1,0,1]
pcmpeqd %xmm2, %xmm1
pcmpeqd %xmm2, %xmm3
movdqa %xmm3, %xmm2
shufps $0xdd, %xmm1, %xmm2     # xmm2 = xmm2[1,3],xmm1[1,3]
shufps $0x88, %xmm1, %xmm3     # xmm3 = xmm3[0,2],xmm1[0,2]
andps %xmm2, %xmm3
movmskps %xmm3, %edx
testl %edx, %edx
jne 0x14cee
cmpb $0x48, 0x58(%rcx)
setne %dl
movl 0x18(%rbx), %ecx
testl %ecx, %ecx
setg %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0x14cee
xorl %r13d, %r13d
xorl %ebp, %ebp
movq 0x10(%rbx), %rax
leaq (%rax,%r13), %rsi
movdqu 0x160(%rbx), %xmm3
movdqu 0x170(%rbx), %xmm1
movq %rsi, %xmm2
pshufd $0x44, %xmm2, %xmm2     # xmm2 = xmm2[0,1,0,1]
pcmpeqd %xmm2, %xmm1
pcmpeqd %xmm2, %xmm3
movdqa %xmm3, %xmm2
shufps $0xdd, %xmm1, %xmm2     # xmm2 = xmm2[1,3],xmm1[1,3]
shufps $0x88, %xmm1, %xmm3     # xmm3 = xmm3[0,2],xmm1[0,2]
andps %xmm2, %xmm3
movmskps %xmm3, %edx
testl %edx, %edx
jne 0x14cdb
cmpb $0x48, 0x58(%rax,%r13)
je 0x14cdb
movq 0x10(%r14), %rdi
addq %r12, %rdi
movsd %xmm0, (%rsp)
callq 0xe5c4
minsd (%rsp), %xmm0
movl 0x18(%rbx), %ecx
incq %rbp
movslq %ecx, %rax
addq $0x60, %r13
cmpq %rax, %rbp
jl 0x14c7a
movl 0x18(%r14), %eax
incq %r15
movslq %eax, %rcx
cmpq %rcx, %r15
jl 0x14c0f
jmp 0x14d78
movl 0x18(%r14), %ecx
testl %ecx, %ecx
jle 0x14d78
movl 0x18(%rbx), %eax
movsd 0xa936(%rip), %xmm0     # 0x1f648
xorl %r15d, %r15d
movq 0x10(%r14), %rdx
leaq (%r15,%r15,2), %r12
shlq $0x5, %r12
cmpb $0x48, 0x58(%rdx,%r12)
je 0x14d6d
testl %eax, %eax
jle 0x14d6d
xorl %r13d, %r13d
xorl %ebp, %ebp
movq 0x10(%rbx), %rsi
cmpb $0x48, 0x58(%rsi,%r13)
je 0x14d5a
addq %r13, %rsi
movq 0x10(%r14), %rdi
addq %r12, %rdi
movsd %xmm0, (%rsp)
callq 0xe5c4
minsd (%rsp), %xmm0
movl 0x18(%rbx), %eax
incq %rbp
movslq %eax, %rcx
addq $0x60, %r13
cmpq %rcx, %rbp
jl 0x14d32
movl 0x18(%r14), %ecx
incq %r15
movslq %ecx, %rdx
cmpq %rdx, %r15
jl 0x14d15
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop