// File: /workspace/github_cpp_makefile_star2_O1/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 0xe50c
addq $-0x60, %r13
addq $0x60, %r14
cmpq $-0x120, %r13           # imm = 0xFEE0
jne 0x144ba
movw $0x0, 0x158(%rbx)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x160(%rbx)
movupd %xmm0, 0x170(%rbx)
movq $0x0, 0x180(%rbx)
cmpl $0x0, 0x18(%rbx)
jle 0x14927
leaq 0x1(%rbx), %rdi
leaq 0xa(%r12), %rbp
movq %rdi, 0x80(%rsp)
movq %rbp, %rsi
callq 0x21f0
cmpq %r15, %r12
ja 0x14539
movq %r12, %rax
cmpb $0x20, 0x9(%rax)
jne 0x14606
addq $0x60, %rax
cmpq %r15, %rax
jbe 0x14526
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 0x145aa
shlq $0x5, %rbp
leaq (,%rbp,2), %r13
addq %rbp, %r13
negq %r13
xorl %r14d, %r14d
movq 0x8(%rsp), %rbp
movq %rbp, %rdi
callq 0xe50c
addq $-0x60, %r14
addq $0x60, %rbp
cmpq %r14, %r13
jne 0x14595
movq 0x8(%rsp), %rax
movq %rax, 0x10(%rbx)
cmpq %r15, %r12
ja 0x1478b
xorl %r14d, %r14d
leaq 0x18(%rsp), %r13
leaq (%r12,%r14), %rsi
movq %r13, %rdi
callq 0xe5e0
movq 0x10(%rbx), %rdi
addq %r14, %rdi
movq %r13, %rsi
callq 0xe69c
movq %r13, %rdi
callq 0xe69a
movq 0x10(%rbx), %rax
movq %rbx, 0x40(%rax,%r14)
leaq (%r12,%r14), %rax
addq $0x60, %rax
addq $0x60, %r14
cmpq %r15, %rax
jbe 0x145c4
jmp 0x1478b
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 0xe47c
leaq 0x88(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x14eda
movq %r12, (%rax)
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x14682
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x2230
leaq 0x60(%r12), %rax
movq %rax, 0x10(%rsp)
cmpq %r15, %rax
jbe 0x147e1
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 0x14702
shlq $0x5, %r13
leaq (,%r13,2), %r12
addq %r13, %r12
negq %r12
xorl %r14d, %r14d
movq %rbp, %r13
movq %r13, %rdi
callq 0xe50c
addq $-0x60, %r14
addq $0x60, %r13
cmpq %r14, %r12
jne 0x146ed
movq %rbp, 0x10(%rbx)
movl $0x0, 0x18(%rbx)
movq 0xa0(%rsp), %r15
leaq 0x90(%rsp), %r14
cmpq %r14, %r15
je 0x1477e
leaq 0x18(%rsp), %r12
movq 0x40(%r15), %rsi
movq %r12, %rdi
callq 0xe5e0
movslq 0x18(%rbx), %rax
leaq (%rax,%rax,2), %rdi
shlq $0x5, %rdi
addq 0x10(%rbx), %rdi
movq %r12, %rsi
callq 0xe69c
movq %r12, %rdi
callq 0xe69a
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 0x14727
leaq 0x88(%rsp), %rdi
callq 0x14f56
movq %rbx, %rdi
callq 0x13f74
leaq 0xc7b6(%rip), %r15      # 0x20f50
xorl %r14d, %r14d
movq 0x80(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x22f0
testl %eax, %eax
je 0x147c4
incq %r14
addq $0x4, %r15
cmpq $0x18, %r14
jne 0x147a5
movb $0x17, %r14b
movb %r14b, (%rbx)
movq %rbx, %rdi
callq 0x143ac
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 0x22f0
testl %eax, %eax
je 0x14815
leaq (%r12,%r14), %rax
addq $0xc0, %rax
addq $0x60, %r14
cmpq %r15, %rax
jbe 0x147e9
jmp 0x14695
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 0xe47c
leaq 0x88(%rsp), %rdi
movq %r13, %rsi
callq 0x152ee
movq %rax, %r13
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x14879
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x2230
leaq 0x90(%rsp), %rax
cmpq %rax, %r13
je 0x148b5
movq 0x40(%r13), %rax
movsd 0x90(%r12,%r14), %xmm0
ucomisd 0x30(%rax), %xmm0
movq 0x8(%rsp), %rbp
jbe 0x147fd
movq 0x10(%rsp), %rax
addq %r14, %rax
movq %rax, 0x40(%r13)
jmp 0x147fd
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 0xe47c
leaq 0x88(%rsp), %rdi
movq %r13, %rsi
callq 0x14eda
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 0x147fd
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x2230
jmp 0x147fd
leaq 0xc686(%rip), %rdi      # 0x20fb4
leaq 0xc68a(%rip), %rsi      # 0x20fbf
leaq 0xc6e7(%rip), %rcx      # 0x21023
movl $0x54, %edx
callq 0x2160
jmp 0x14975
jmp 0x14954
jmp 0x14975
jmp 0x14954
jmp 0x14975
jmp 0x149c8
jmp 0x14975
movq %rax, %rbp
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x149b9
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x2230
jmp 0x149b9
movq %rax, %rbp
jmp 0x149b9
movq %rax, %rbp
leaq 0x18(%rsp), %rdi
callq 0xe69a
jmp 0x149b9
movq %rax, %rbp
testq %r14, %r14
je 0x149ac
negq %r14
movq 0x8(%rsp), %r12
addq $-0x58, %r12
leaq (%r12,%r14), %rdi
callq 0xe69a
addq $-0x60, %r14
jne 0x1499d
movq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x23d0
leaq 0x88(%rsp), %rdi
callq 0x14f56
jmp 0x14a0e
movq %rax, %rbp
jmp 0x14a0e
movq %rax, %rbp
leaq 0x18(%rsp), %rdi
callq 0xe69a
jmp 0x14a0e
movq %rax, %rbp
testq %r14, %r14
je 0x149ff
negq %r14
movq 0x10(%rsp), %r15
addq $-0x58, %r15
leaq (%r15,%r14), %rdi
callq 0xe69a
addq $-0x60, %r14
jne 0x149f0
movq 0x10(%rsp), %rdi
movq 0x78(%rsp), %rsi
callq 0x23d0
movl $0xf8, %r14d
leaq (%rbx,%r14), %rdi
callq 0xe69a
addq $-0x60, %r14
cmpq $-0x28, %r14
jne 0x14a14
jmp 0x14a47
movq %rax, %rbp
testq %r13, %r13
je 0x14a47
negq %r13
addq $-0x28, %rbx
leaq (%rbx,%r13), %rdi
callq 0xe69a
addq $-0x60, %r13
jne 0x14a38
movq %rbp, %rdi
callq 0x2390
nop