// File: /workspace/github_cpp_makefile_star2_O3/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, %r12
movq %rdi, %rbx
movl 0x10(%rsi), %eax
movl %eax, 0x8(%rdi)
movb 0x14(%rsi), %al
movb %al, 0xc(%rdi)
movq $0x0, 0x10(%rdi)
movq %rdx, %rax
subq %rsi, %rax
shrq $0x5, %rax
imull $0xaaaaaaab, %eax, %eax # imm = 0xAAAAAAAB
incl %eax
movl %eax, 0x18(%rdi)
movb 0xe(%rsi), %al
movb %al, 0x1c(%rdi)
leaq 0x38(%rdi), %r14
xorl %r13d, %r13d
movq %r14, %rdi
callq 0xe404
addq $-0x60, %r13
addq $0x60, %r14
cmpq $-0x120, %r13           # imm = 0xFEE0
jne 0x142d8
movw $0x0, 0x158(%rbx)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x160(%rbx)
movupd %xmm0, 0x170(%rbx)
movq $0x0, 0x180(%rbx)
cmpl $0x0, 0x18(%rbx)
jle 0x14745
leaq 0x1(%rbx), %rdi
leaq 0xa(%r12), %rbp
movq %rdi, 0x80(%rsp)
movq %rbp, %rsi
callq 0x21e0
cmpq %r15, %r12
ja 0x14357
movq %r12, %rax
cmpb $0x20, 0x9(%rax)
jne 0x14424
addq $0x60, %rax
cmpq %r15, %rax
jbe 0x14344
movslq 0x18(%rbx), %rbp
movl $0x60, %ecx
movq %rbp, %rax
mulq %rcx
seto %cl
orq $0x8, %rax
movq $-0x1, %rdi
testb %cl, %cl
cmoveq %rax, %rdi
movq %rdi, 0x78(%rsp)
callq 0x2030
movq %rbp, (%rax)
movq %rax, 0x10(%rsp)
addq $0x8, %rax
movq %rax, 0x8(%rsp)
testl %ebp, %ebp
je 0x143c8
shlq $0x5, %rbp
leaq (,%rbp,2), %r13
addq %rbp, %r13
negq %r13
xorl %r14d, %r14d
movq 0x8(%rsp), %rbp
movq %rbp, %rdi
callq 0xe404
addq $-0x60, %r14
addq $0x60, %rbp
cmpq %r14, %r13
jne 0x143b3
movq 0x8(%rsp), %rax
movq %rax, 0x10(%rbx)
cmpq %r15, %r12
ja 0x145a9
xorl %r14d, %r14d
leaq 0x18(%rsp), %r13
leaq (%r12,%r14), %rsi
movq %r13, %rdi
callq 0xe4b0
movq 0x10(%rbx), %rdi
addq %r14, %rdi
movq %r13, %rsi
callq 0xe548
movq %r13, %rdi
callq 0xe546
movq 0x10(%rbx), %rax
movq %rbx, 0x40(%rax,%r14)
leaq (%r12,%r14), %rax
addq $0x60, %rax
addq $0x60, %r14
cmpq %r15, %rax
jbe 0x143e2
jmp 0x145a9
leaq 0x90(%rsp), %rcx
movl $0x0, (%rcx)
xorl %eax, %eax
movq %rax, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq %rax, 0x20(%rcx)
leaq 0x4(%r12), %r13
leaq 0x28(%rsp), %rax
movq %rax, -0x10(%rax)
movq %r13, %rdi
callq 0x2100
leaq (%r12,%rax), %rdx
addq $0x4, %rdx
leaq 0x18(%rsp), %rdi
movq %r13, %rsi
callq 0xe36c
leaq 0x88(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x14d88
movq %r12, (%rax)
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x144a0
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x2220
leaq 0x60(%r12), %rax
movq %rax, 0x10(%rsp)
cmpq %r15, %rax
jbe 0x145ff
movq 0xb0(%rsp), %r13
movl $0x60, %ecx
movq %r13, %rax
mulq %rcx
seto %cl
orq $0x8, %rax
movq $-0x1, %r15
testb %cl, %cl
cmoveq %rax, %r15
movq %r15, %rdi
callq 0x2030
movq %r13, (%rax)
movq %rax, 0x8(%rsp)
leaq 0x8(%rax), %rbp
testq %r13, %r13
je 0x14520
shlq $0x5, %r13
leaq (,%r13,2), %r12
addq %r13, %r12
negq %r12
xorl %r14d, %r14d
movq %rbp, %r13
movq %r13, %rdi
callq 0xe404
addq $-0x60, %r14
addq $0x60, %r13
cmpq %r14, %r12
jne 0x1450b
movq %rbp, 0x10(%rbx)
movl $0x0, 0x18(%rbx)
movq 0xa0(%rsp), %r15
leaq 0x90(%rsp), %r14
cmpq %r14, %r15
je 0x1459c
leaq 0x18(%rsp), %r12
movq 0x40(%r15), %rsi
movq %r12, %rdi
callq 0xe4b0
movslq 0x18(%rbx), %rax
leaq (%rax,%rax,2), %rdi
shlq $0x5, %rdi
addq 0x10(%rbx), %rdi
movq %r12, %rsi
callq 0xe548
movq %r12, %rdi
callq 0xe546
movq 0x10(%rbx), %rax
movslq 0x18(%rbx), %rcx
leaq (%rcx,%rcx,2), %rdx
shlq $0x5, %rdx
movq %rbx, 0x40(%rax,%rdx)
leal 0x1(%rcx), %eax
movl %eax, 0x18(%rbx)
movq %r15, %rdi
callq 0x2180
movq %rax, %r15
cmpq %r14, %rax
jne 0x14545
leaq 0x88(%rsp), %rdi
callq 0x14e04
movq %rbx, %rdi
callq 0x13d94
leaq 0xc998(%rip), %r15      # 0x20f50
xorl %r14d, %r14d
movq 0x80(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x22e0
testl %eax, %eax
je 0x145e2
incq %r14
addq $0x4, %r15
cmpq $0x18, %r14
jne 0x145c3
movb $0x17, %r14b
movb %r14b, (%rbx)
movq %rbx, %rdi
callq 0x141d0
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r14d, %r14d
movq %rbp, 0x8(%rsp)
leaq (%r12,%r14), %rsi
addq $0x6a, %rsi
movq %rbp, %rdi
callq 0x22e0
testl %eax, %eax
je 0x14633
leaq (%r12,%r14), %rax
addq $0xc0, %rax
addq $0x60, %r14
cmpq %r15, %rax
jbe 0x14607
jmp 0x144b3
leaq (%r12,%r14), %rbp
addq $0x64, %rbp
leaq 0x28(%rsp), %rax
movq %rax, 0x18(%rsp)
movq %rbp, %rdi
callq 0x2100
addq %r14, %rax
leaq (%r12,%rax), %rdx
addq $0x64, %rdx
leaq 0x18(%rsp), %r13
movq %r13, %rdi
movq %rbp, %rsi
callq 0xe36c
leaq 0x88(%rsp), %rdi
movq %r13, %rsi
callq 0x1519c
movq %rax, %r13
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x14697
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x2220
leaq 0x90(%rsp), %rax
cmpq %rax, %r13
je 0x146d3
movq 0x40(%r13), %rax
movsd 0x90(%r12,%r14), %xmm0
ucomisd 0x30(%rax), %xmm0
movq 0x8(%rsp), %rbp
jbe 0x1461b
movq 0x10(%rsp), %rax
addq %r14, %rax
movq %rax, 0x40(%r13)
jmp 0x1461b
leaq 0x28(%rsp), %rax
movq %rax, 0x18(%rsp)
movq %rbp, %rdi
callq 0x2100
addq %r14, %rax
leaq (%r12,%rax), %rdx
addq $0x64, %rdx
leaq 0x18(%rsp), %r13
movq %r13, %rdi
movq %rbp, %rsi
callq 0xe36c
leaq 0x88(%rsp), %rdi
movq %r13, %rsi
callq 0x14d88
movq 0x10(%rsp), %rcx
addq %r14, %rcx
movq %rcx, (%rax)
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
movq 0x8(%rsp), %rbp
je 0x1461b
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x2220
jmp 0x1461b
leaq 0xc868(%rip), %rdi      # 0x20fb4
leaq 0xc86c(%rip), %rsi      # 0x20fbf
leaq 0xc8c9(%rip), %rcx      # 0x21023
movl $0x54, %edx
callq 0x2160
jmp 0x14793
jmp 0x14772
jmp 0x14793
jmp 0x14772
jmp 0x14793
jmp 0x147e6
jmp 0x14793
movq %rax, %rbp
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x147d7
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x2220
jmp 0x147d7
movq %rax, %rbp
jmp 0x147d7
movq %rax, %rbp
leaq 0x18(%rsp), %rdi
callq 0xe546
jmp 0x147d7
movq %rax, %rbp
testq %r14, %r14
je 0x147ca
negq %r14
movq 0x8(%rsp), %r12
addq $-0x58, %r12
leaq (%r12,%r14), %rdi
callq 0xe546
addq $-0x60, %r14
jne 0x147bb
movq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x23c0
leaq 0x88(%rsp), %rdi
callq 0x14e04
jmp 0x1482c
movq %rax, %rbp
jmp 0x1482c
movq %rax, %rbp
leaq 0x18(%rsp), %rdi
callq 0xe546
jmp 0x1482c
movq %rax, %rbp
testq %r14, %r14
je 0x1481d
negq %r14
movq 0x10(%rsp), %r15
addq $-0x58, %r15
leaq (%r15,%r14), %rdi
callq 0xe546
addq $-0x60, %r14
jne 0x1480e
movq 0x10(%rsp), %rdi
movq 0x78(%rsp), %rsi
callq 0x23c0
movl $0xf8, %r14d
leaq (%rbx,%r14), %rdi
callq 0xe546
addq $-0x60, %r14
cmpq $-0x28, %r14
jne 0x14832
jmp 0x14865
movq %rax, %rbp
testq %r13, %r13
je 0x14865
negq %r13
addq $-0x28, %rbx
leaq (%rbx,%r13), %rdi
callq 0xe546
addq $-0x60, %r13
jne 0x14856
movq %rbp, %rdi
callq 0x2380
nop