// File: /workspace/github_cpp_makefile_star2_O2/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 0x9bb1(%rip), %xmm0     # 0x1d648
testl %edx, %edx
je 0x13c5e
cmpl $0x1, %edx
je 0x13b89
cmpl $0x2, %edx
jne 0x13cbb
xorl %r15d, %r15d
movslq 0x18(%r14), %rax
cmpq %rax, %r15
jge 0x13cbb
movq 0x10(%r14), %rax
imulq $0x60, %r15, %r12
leaq (%rax,%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, %ecx
testl %ecx, %ecx
je 0x13b0f
cmpb $0x48, 0x58(%rax,%r12)
jne 0x13b14
incq %r15
jmp 0x13ab4
xorl %r13d, %r13d
xorl %ebp, %ebp
movslq 0x18(%rbx), %rax
cmpq %rax, %rbp
jge 0x13b0f
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, %ecx
testl %ecx, %ecx
je 0x13b80
cmpb $0x48, 0x58(%rax,%r13)
je 0x13b80
movq 0x10(%r14), %rdi
addq %r12, %rdi
movsd %xmm0, (%rsp)
callq 0xde70
minsd (%rsp), %xmm0
incq %rbp
addq $0x60, %r13
jmp 0x13b19
xorl %r15d, %r15d
movslq 0x18(%r14), %rax
cmpq %rax, %r15
jge 0x13cbb
imulq $0x60, %r15, %r12
movq 0x10(%r14), %rax
addq %r12, %rax
movdqu 0x160(%r14), %xmm3
movdqu 0x170(%r14), %xmm1
movq %rax, %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, %ecx
testl %ecx, %ecx
jne 0x13be4
cmpb $0x48, 0x58(%rax)
jne 0x13be9
incq %r15
jmp 0x13b8c
xorl %r13d, %r13d
xorl %ebp, %ebp
movslq 0x18(%rbx), %rax
cmpq %rax, %rbp
jge 0x13be4
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, %ecx
testl %ecx, %ecx
jne 0x13c55
cmpb $0x48, 0x58(%rax,%r13)
je 0x13c55
movq 0x10(%r14), %rdi
addq %r12, %rdi
movsd %xmm0, (%rsp)
callq 0xde70
minsd (%rsp), %xmm0
incq %rbp
addq $0x60, %r13
jmp 0x13bee
xorl %r15d, %r15d
movslq 0x18(%r14), %rax
cmpq %rax, %r15
jge 0x13cbb
movq 0x10(%r14), %rax
imulq $0x60, %r15, %r12
cmpb $0x48, 0x58(%rax,%r12)
jne 0x13c7f
incq %r15
jmp 0x13c61
xorl %r13d, %r13d
xorl %ebp, %ebp
movslq 0x18(%rbx), %rax
cmpq %rax, %rbp
jge 0x13c7a
movq 0x10(%rbx), %rsi
cmpb $0x48, 0x58(%rsi,%r13)
je 0x13cb2
addq %r13, %rsi
movq 0x10(%r14), %rdi
addq %r12, %rdi
movsd %xmm0, (%rsp)
callq 0xde70
minsd (%rsp), %xmm0
incq %rbp
addq $0x60, %r13
jmp 0x13c84
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq