// File: 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
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movabsq $0x40c387feb851eb85, %rax # imm = 0x40C387FEB851EB85
movq %rax, -0x28(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x8c(%rbp)
testl %eax, %eax
je 0x29648
jmp 0x29623
movl -0x8c(%rbp), %eax
subl $0x1, %eax
je 0x29741
jmp 0x29634
movl -0x8c(%rbp), %eax
subl $0x2, %eax
je 0x298fa
jmp 0x29ab9
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jge 0x2973c
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x2c(%rbp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movsbl 0x58(%rax), %eax
cmpl $0x48, %eax
jne 0x29680
jmp 0x2972e
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jge 0x2972c
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x30(%rbp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movsbl 0x58(%rax), %eax
cmpl $0x48, %eax
jne 0x296b5
jmp 0x2971e
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movslq -0x2c(%rbp), %rax
imulq $0x60, %rax, %rax
addq %rax, %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rsi
movslq -0x30(%rbp), %rax
imulq $0x60, %rax, %rax
addq %rax, %rsi
callq 0x18f20
movsd %xmm0, -0x38(%rbp)
movsd -0x38(%rbp), %xmm1
movsd -0x28(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x29704
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x98(%rbp)
jmp 0x29711
movsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x98(%rbp)
movsd -0x98(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x29687
jmp 0x2972e
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x2964f
jmp 0x29ac5
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jge 0x298f5
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x3c(%rbp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x170(%rcx), %rax
je 0x297b3
movq -0x48(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x168(%rcx), %rax
je 0x297b3
movq -0x48(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x160(%rcx), %rax
je 0x297b3
movq -0x48(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x178(%rcx), %rax
jne 0x297b8
jmp 0x298e7
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x3c(%rbp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movsbl 0x58(%rax), %eax
cmpl $0x48, %eax
jne 0x297d9
jmp 0x298e7
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jge 0x298e5
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x4c(%rbp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x170(%rcx), %rax
je 0x2984b
movq -0x58(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x168(%rcx), %rax
je 0x2984b
movq -0x58(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x160(%rcx), %rax
je 0x2984b
movq -0x58(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x178(%rcx), %rax
jne 0x29850
jmp 0x298d7
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x4c(%rbp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movsbl 0x58(%rax), %eax
cmpl $0x48, %eax
jne 0x2986e
jmp 0x298d7
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movslq -0x3c(%rbp), %rax
imulq $0x60, %rax, %rax
addq %rax, %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rsi
movslq -0x4c(%rbp), %rax
imulq $0x60, %rax, %rax
addq %rax, %rsi
callq 0x18f20
movsd %xmm0, -0x60(%rbp)
movsd -0x60(%rbp), %xmm1
movsd -0x28(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x298bd
movsd -0x60(%rbp), %xmm0
movsd %xmm0, -0xa0(%rbp)
jmp 0x298ca
movsd -0x28(%rbp), %xmm0
movsd %xmm0, -0xa0(%rbp)
movsd -0xa0(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x297e0
jmp 0x298e7
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x29748
jmp 0x29ac5
movl $0x0, -0x64(%rbp)
movl -0x64(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jge 0x29ab7
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x64(%rbp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x170(%rcx), %rax
je 0x29971
movq -0x70(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x168(%rcx), %rax
je 0x29971
movq -0x70(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x160(%rcx), %rax
je 0x29971
movq -0x70(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x178(%rcx), %rax
je 0x29971
jmp 0x29aa9
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x64(%rbp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movsbl 0x58(%rax), %eax
cmpl $0x48, %eax
jne 0x29992
jmp 0x29aa9
movl $0x0, -0x74(%rbp)
movl -0x74(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jge 0x29aa7
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x74(%rbp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x170(%rcx), %rax
je 0x29a09
movq -0x80(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x168(%rcx), %rax
je 0x29a09
movq -0x80(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x160(%rcx), %rax
je 0x29a09
movq -0x80(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x178(%rcx), %rax
je 0x29a09
jmp 0x29a99
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x74(%rbp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movsbl 0x58(%rax), %eax
cmpl $0x48, %eax
jne 0x29a27
jmp 0x29a99
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movslq -0x64(%rbp), %rax
imulq $0x60, %rax, %rax
addq %rax, %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rsi
movslq -0x74(%rbp), %rax
imulq $0x60, %rax, %rax
addq %rax, %rsi
callq 0x18f20
movsd %xmm0, -0x88(%rbp)
movsd -0x88(%rbp), %xmm1
movsd -0x28(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x29a7f
movsd -0x88(%rbp), %xmm0
movsd %xmm0, -0xa8(%rbp)
jmp 0x29a8c
movsd -0x28(%rbp), %xmm0
movsd %xmm0, -0xa8(%rbp)
movsd -0xa8(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x29999
jmp 0x29aa9
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x29901
jmp 0x29ac5
movsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x29acf
movsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
movsd -0x8(%rbp), %xmm0
addq $0xb0, %rsp
popq %rbp
retq
nopl (%rax)