// File: /workspace/github_cpp_makefile_star2_O2/gjoni[P]iPot/src/Residue.cpp
// Function: Residue::Residue(__gnu_cxx::__normal_iterator<AtomRecord*, std::vector<AtomRecord, std::allocator<AtomRecord>>>, __gnu_cxx::__normal_iterator<AtomRecord*, std::vector<AtomRecord, std::allocator<AtomRecord>>>)
Residue::Residue(std::vector<AtomRecord>::iterator begin_it,
		std::vector<AtomRecord>::iterator end_it) :
		seqNum(begin_it->resNum), insCode(begin_it->insCode), atom(NULL), nAtoms(
				end_it - begin_it + 1), chainId(begin_it->chainId), ntFlag(
				false), ctFlag(false), N(NULL), CA(
		NULL), C(NULL), O(NULL), CB(NULL) {

	assert(nAtoms > 0); /* pedantic check */

	strcpy(name, begin_it->resName); /* residue name is read from the 1st atom */

	/* check for alternative conformations */
	std::vector<AtomRecord>::iterator it;
	bool fl = false;
	for (it = begin_it; it <= end_it; it++) {
		if (it->altLoc != ' ') {
			fl = true;
			break;
		}
	}

	if (!fl) { /* no alternative conformations */

		/* use all atoms */
		atom = new Atom[nAtoms];
		int idx = 0;
		for (it = begin_it; it <= end_it; it++) {
			atom[idx] = Atom(*it);
			atom[idx].residue = this;
			idx++;
		}

	} else { /* there are alternative conformations */

		/* save top-populated conformation for each atom */
		std::map<std::string, std::vector<AtomRecord>::iterator> atoms_map;
		std::map<std::string, std::vector<AtomRecord>::iterator>::iterator itmap;

		atoms_map[begin_it->atomName] = begin_it;
		for (it = begin_it + 1; it <= end_it; it++) {

			/* save only atoms with the same residue name as the first atom */
			if (strcmp(begin_it->resName, it->resName) == 0) {
				itmap = atoms_map.find(it->atomName);
				if (itmap == atoms_map.end()) {
					atoms_map[it->atomName] = it;
				} else {
					if (itmap->second->occup < it->occup) {
						itmap->second = it;
					}
				}
			}
		}

		/* save marked atoms */
		atom = new Atom[atoms_map.size()];
		nAtoms = 0;
		for (itmap = atoms_map.begin(); itmap != atoms_map.end(); itmap++) {
			atom[nAtoms] = Atom(*(itmap->second));
			atom[nAtoms].residue = this;
			nAtoms++;
		}

	}

	SetBBAtoms(); /* N, CA, C, O, CB are pointers - they need to be reinitialized */

	type = SetType(name);

	SetCentroid();

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rdx, %r15
movq %rsi, %rbp
movq %rdi, %rbx
movl 0x10(%rsi), %eax
movl %eax, 0x8(%rdi)
movb 0x14(%rsi), %al
movb %al, 0xc(%rdi)
andq $0x0, 0x10(%rdi)
movq %rdx, %rax
subq %rsi, %rax
pushq $0x60
popq %rcx
cqto
idivq %rcx
incl %eax
movl %eax, 0x18(%rdi)
movb 0xe(%rsi), %al
movb %al, 0x1c(%rdi)
leaq 0x38(%rdi), %r14
xorl %r12d, %r12d
movq %r14, %rdi
callq 0xdcb4
addq $-0x60, %r12
addq $0x60, %r14
cmpq $-0x120, %r12           # imm = 0xFEE0
jne 0x13447
andw $0x0, 0x158(%rbx)
xorpd %xmm0, %xmm0
andq $0x0, 0x180(%rbx)
movupd %xmm0, 0x160(%rbx)
movupd %xmm0, 0x170(%rbx)
cmpl $0x0, 0x18(%rbx)
jle 0x13758
leaq 0x1(%rbx), %rdi
leaq 0xa(%rbp), %rsi
movq %rdi, 0x20(%rsp)
movq %rsi, 0x8(%rsp)
callq 0x21e0
movq %rbp, %rax
cmpq %r15, %rax
ja 0x135b7
cmpb $0x20, 0x9(%rax)
leaq 0x60(%rax), %rax
je 0x134a8
leaq 0x30(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
leaq 0x4(%rbp), %rsi
leaq 0x58(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0xdbd4
movq %r15, 0x10(%rsp)
leaq 0x28(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x13cca
movq %rbp, (%rax)
leaq 0x58(%rsp), %r15
movq %r15, %rdi
callq 0x2100
addq $0x60, %rbp
movq %rbp, %r12
cmpq 0x10(%rsp), %r12
ja 0x13661
leaq 0xa(%r12), %rsi
movq 0x8(%rsp), %rdi
callq 0x2300
testl %eax, %eax
je 0x1353b
addq $0x60, %r12
addq $0x60, %rbp
jmp 0x13513
leaq 0x4(%r12), %r14
movq %r15, %rdi
movq %r14, %rsi
leaq 0x7(%rsp), %rdx
callq 0xdbd4
leaq 0x28(%rsp), %rdi
movq %r15, %rsi
callq 0x1413a
movq %rax, %r13
movq %r15, %rdi
callq 0x2100
leaq 0x30(%rsp), %rax
cmpq %rax, %r13
je 0x1358a
movq 0x40(%r13), %rax
movsd 0x30(%r12), %xmm0
ucomisd 0x30(%rax), %xmm0
jbe 0x13531
movq %rbp, 0x40(%r13)
jmp 0x13531
movq %r15, %rdi
movq %r14, %rsi
leaq 0x7(%rsp), %rdx
callq 0xdbd4
leaq 0x28(%rsp), %rdi
movq %r15, %rsi
callq 0x13cca
movq %rbp, (%rax)
movq %r15, %rdi
callq 0x2100
jmp 0x13531
movslq 0x18(%rbx), %r14
movq %r14, %rax
pushq $0x60
popq %rcx
mulq %rcx
seto %cl
orq $0x8, %rax
pushq $-0x1
popq %rdi
testb %cl, %cl
cmoveq %rax, %rdi
movq %rdi, 0x18(%rsp)
callq 0x2030
movq %r14, (%rax)
movq %rax, 0x10(%rsp)
addq $0x8, %rax
movq %rax, 0x8(%rsp)
testl %r14d, %r14d
je 0x13615
imulq $-0x60, %r14, %r13
xorl %r12d, %r12d
movq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0xdcb4
addq $-0x60, %r12
addq $0x60, %r14
cmpq %r12, %r13
jne 0x13600
movq 0x8(%rsp), %rax
movq %rax, 0x10(%rbx)
xorl %r12d, %r12d
leaq 0x58(%rsp), %r14
leaq (%r12,%rbp), %rsi
cmpq %r15, %rsi
ja 0x1372a
movq %r14, %rdi
callq 0xdd60
movq 0x10(%rbx), %rdi
addq %r12, %rdi
movq %r14, %rsi
callq 0xddf4
movq %r14, %rdi
callq 0xddf2
movq 0x10(%rbx), %rax
movq %rbx, 0x40(%rax,%r12)
addq $0x60, %r12
jmp 0x13626
movq 0x50(%rsp), %r14
movq %r14, %rax
pushq $0x60
popq %rcx
mulq %rcx
seto %cl
orq $0x8, %rax
pushq $-0x1
popq %r15
testb %cl, %cl
cmoveq %rax, %r15
movq %r15, %rdi
callq 0x2030
movq %r14, (%rax)
movq %rax, 0x8(%rsp)
leaq 0x8(%rax), %rbp
testq %r14, %r14
je 0x136b8
imulq $-0x60, %r14, %r12
xorl %r13d, %r13d
movq %rbp, %r14
movq %r14, %rdi
callq 0xdcb4
addq $-0x60, %r13
addq $0x60, %r14
cmpq %r13, %r12
jne 0x136a3
movq %rbp, 0x10(%rbx)
andl $0x0, 0x18(%rbx)
movq 0x40(%rsp), %r15
leaq 0x58(%rsp), %r14
leaq 0x30(%rsp), %r12
cmpq %r12, %r15
je 0x13720
movq 0x40(%r15), %rsi
movq %r14, %rdi
callq 0xdd60
movslq 0x18(%rbx), %rax
imulq $0x60, %rax, %rdi
addq 0x10(%rbx), %rdi
movq %r14, %rsi
callq 0xddf4
movq %r14, %rdi
callq 0xddf2
movq 0x10(%rbx), %rax
movslq 0x18(%rbx), %rcx
imulq $0x60, %rcx, %rdx
movq %rbx, 0x40(%rax,%rdx)
leal 0x1(%rcx), %eax
movl %eax, 0x18(%rbx)
movq %r15, %rdi
callq 0x2180
movq %rax, %r15
jmp 0x136cf
leaq 0x28(%rsp), %rdi
callq 0x13d30
movq %rbx, %rdi
callq 0x12f88
movq 0x20(%rsp), %rsi
callq 0x13316
movb %al, (%rbx)
movq %rbx, %rdi
callq 0x13350
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xb855(%rip), %rdi      # 0x1efb4
leaq 0xb859(%rip), %rsi      # 0x1efbf
leaq 0xb8b6(%rip), %rcx      # 0x1f023
pushq $0x54
popq %rdx
callq 0x2160
jmp 0x13801
jmp 0x1378c
jmp 0x13801
jmp 0x1381f
jmp 0x1378c
jmp 0x13801
jmp 0x13801
movq %rax, %r14
leaq 0x58(%rsp), %rdi
callq 0x2100
jmp 0x13813
movq %rax, %r14
testq %r13, %r13
je 0x137be
negq %r13
movq 0x8(%rsp), %r12
addq $-0x58, %r12
leaq (%r12,%r13), %rdi
callq 0xddf2
addq $-0x60, %r13
jne 0x137af
movq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x23f0
jmp 0x13813
movq %rax, %r14
testq %r12, %r12
je 0x137f0
negq %r12
movq 0x10(%rsp), %r15
addq $-0x58, %r15
leaq (%r15,%r12), %rdi
callq 0xddf2
addq $-0x60, %r12
jne 0x137e1
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x23f0
jmp 0x13831
movq %rax, %r14
jmp 0x13813
movq %rax, %r14
leaq 0x58(%rsp), %rdi
callq 0xddf2
leaq 0x28(%rsp), %rdi
callq 0x13d30
jmp 0x13831
movq %rax, %r14
jmp 0x13831
movq %rax, %r14
leaq 0x58(%rsp), %rdi
callq 0xddf2
movl $0xf8, %r15d
leaq (%rbx,%r15), %rdi
callq 0xddf2
addq $-0x60, %r15
cmpq $-0x28, %r15
jne 0x13837
movq %r14, %rdi
callq 0x23a0
movq %rax, %r14
testq %r12, %r12
je 0x1384a
negq %r12
addq $-0x28, %rbx
leaq (%rbx,%r12), %rdi
callq 0xddf2
addq $-0x60, %r12
jne 0x13861
jmp 0x1384a