// File: /workspace/github_cpp_makefile_star2_O1/gjoni[P]iPot/src/Chain.cpp
// Function: Chain::InitChain(std::vector<AtomRecord, std::allocator<AtomRecord>>&)
void Chain::InitChain(std::vector<AtomRecord> &atomRecordVector) {

	/* define boundaries for all residues : insCode + resNum */
	std::vector<int> first, last; /* residues boundaries */
	first.push_back(0); /* first atom of the first residue */
	nAtoms = atomRecordVector.size();
	for (int i = 1; i < nAtoms; i++) {
		if (atomRecordVector[i].insCode != atomRecordVector[i - 1].insCode
				|| atomRecordVector[i].resNum
						!= atomRecordVector[i - 1].resNum) {
			first.push_back(i);
			last.push_back(i - 1);
		}
	}
	last.push_back(nAtoms - 1); /* last atom of the last residue */

	assert(first.size() == last.size()); /* unexpectedly :-) */

	/*
	 * TODO: temp. solution for eliminating incomplete residues
	 */
	bool *fl = (bool*) calloc(first.size(), sizeof(bool));
	nRes = 0;
	for (unsigned i = 0; i < first.size(); i++) {
		for (int j = first[i]; j <= last[i]; j++) {
			if (strcmp(atomRecordVector[j].atomName, "CA") == 0) {
				fl[i] = true;
			}
		}
		nRes += fl[i];
	}

	/* initialize residues */
	residue = new Residue[nRes];
	int idx = 0;
	nAtoms = 0;
	for (unsigned i = 0; i < first.size(); i++) {
		if (fl[i]) {
			residue[idx] = Residue(atomRecordVector.begin() + first[i],
					atomRecordVector.begin() + last[i]);
			//nAtoms += last[i] - first[i] + 1;
			nAtoms += residue[idx].nAtoms;
			idx++;
		}
	}
	free(fl);

	/* initialize pointers to atoms */
	atom = new Atom*[nAtoms]; /* array of pointers to atoms */
	SetAtomPointers();

	SetKD();

	/* initialize CA trace */
	ca_trace = (double**) malloc(nRes * sizeof(double*));
	for (int i = 0; i < nRes; i++) {
		ca_trace[i] = (double*) malloc(3 * sizeof(double));
		ca_trace[i][0] = residue[i].CA->x;
		ca_trace[i][1] = residue[i].CA->y;
		ca_trace[i][2] = residue[i].CA->z;
	}

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1e8, %rsp            # imm = 0x1E8
movq %rsi, 0x40(%rsp)
movq %rdi, %rbx
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
xorl %eax, %eax
movq %rax, 0x10(%rsp)
movq %rax, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movl $0x0, 0x60(%rsp)
movq 0x8(%rsp), %rsi
testq %rsi, %rsi
je 0xeca0
movl $0x0, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rsp)
jmp 0xecad
movq %rsp, %rdi
leaq 0x60(%rsp), %rdx
callq 0x1074e
movq 0x40(%rsp), %rcx
movq 0x8(%rcx), %rax
subq (%rcx), %rax
shrq $0x5, %rax
imull $0xaaaaaaab, %eax, %ecx # imm = 0xAAAAAAAB
movl %ecx, 0x38(%rbx)
movl $0x1, 0x60(%rsp)
cmpl $0x2, %ecx
jl 0xed7f
movl $0x1, %eax
movq %rsp, %r15
leaq 0x60(%rsp), %r12
leaq 0x20(%rsp), %r13
leaq 0x4c(%rsp), %rbp
movslq %eax, %rdx
movq 0x40(%rsp), %rcx
movq (%rcx), %rcx
leaq (%rdx,%rdx,2), %rdx
shlq $0x5, %rdx
movb 0x14(%rcx,%rdx), %sil
cmpb -0x4c(%rcx,%rdx), %sil
jne 0xed18
addq %rdx, %rcx
movl 0x10(%rcx), %edx
cmpl -0x50(%rcx), %edx
je 0xed6a
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0xed31
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rsp)
jmp 0xed3c
movq %r15, %rdi
movq %r12, %rdx
callq 0x1088a
movl 0x60(%rsp), %eax
decl %eax
movl %eax, 0x4c(%rsp)
movq 0x28(%rsp), %rsi
cmpq 0x30(%rsp), %rsi
je 0xed5f
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x28(%rsp)
jmp 0xed6a
movq %r13, %rdi
movq %rbp, %rdx
callq 0x1074e
movl 0x60(%rsp), %eax
incl %eax
movl %eax, 0x60(%rsp)
movl 0x38(%rbx), %ecx
cmpl %ecx, %eax
jl 0xecee
decl %ecx
movl %ecx, 0x60(%rsp)
movq 0x28(%rsp), %rsi
cmpq 0x30(%rsp), %rsi
je 0xed9e
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x28(%rsp)
jmp 0xedad
leaq 0x20(%rsp), %rdi
leaq 0x60(%rsp), %rdx
callq 0x1074e
movq (%rsp), %r13
movq 0x8(%rsp), %r14
movq %r14, %r12
subq %r13, %r12
movq 0x20(%rsp), %rbp
movq 0x28(%rsp), %rax
subq %rbp, %rax
cmpq %rax, %r12
jne 0xf069
sarq $0x2, %r12
movl $0x1, %esi
movq %r12, %rdi
callq 0x2170
movq %rax, %r15
movl $0x0, 0x48(%rbx)
cmpq %r13, %r14
je 0xee58
movl 0x48(%rbx), %eax
movq 0x40(%rsp), %rcx
movq (%rcx), %rcx
addq $0x4, %rcx
xorl %edx, %edx
movslq (%r13,%rdx,4), %r8
movl (%rbp,%rdx,4), %esi
cmpl %esi, %r8d
jg 0xee44
leaq (%r8,%r8,2), %rdi
shlq $0x5, %rdi
addq %rcx, %rdi
subl %r8d, %esi
incl %esi
movzwl (%rdi), %r8d
xorl $0x4143, %r8d           # imm = 0x4143
movzbl 0x2(%rdi), %r9d
orw %r8w, %r9w
jne 0xee3c
movb $0x1, (%r15,%rdx)
addq $0x60, %rdi
decl %esi
jne 0xee21
movzbl (%r15,%rdx), %esi
addl %esi, %eax
movl %eax, 0x48(%rbx)
incq %rdx
movl %edx, %esi
cmpq %rsi, %r12
ja 0xee03
movslq 0x48(%rbx), %rbp
movl $0x188, %ecx            # imm = 0x188
movq %rbp, %rax
mulq %rcx
movq %rax, %r12
seto %al
addq $0x8, %r12
movq $-0x1, %rcx
cmovbq %rcx, %r12
testb %al, %al
cmovneq %rcx, %r12
movq %r12, %rdi
callq 0x2030
movq %rbp, (%rax)
movq %rax, 0x50(%rsp)
addq $0x8, %rax
movq %rax, 0x58(%rsp)
testl %ebp, %ebp
je 0xeec9
imulq $-0x188, %rbp, %r14     # imm = 0xFE78
xorl %r13d, %r13d
movq 0x58(%rsp), %rbp
movq %rbp, %rdi
callq 0x13cd0
addq $-0x188, %r13           # imm = 0xFE78
addq $0x188, %rbp            # imm = 0x188
cmpq %r13, %r14
jne 0xeeae
movq 0x58(%rsp), %rax
movq %rax, 0x40(%rbx)
movl $0x0, 0x38(%rbx)
movq (%rsp), %rcx
cmpq %rcx, 0x8(%rsp)
je 0xef7e
xorl %eax, %eax
movl $0x1, %ebp
leaq 0x60(%rsp), %r12
xorl %r13d, %r13d
cmpb $0x1, (%r15,%rax)
jne 0xef61
movq 0x40(%rsp), %rdx
movq (%rdx), %rdi
movslq (%rcx,%rax,4), %rcx
leaq (%rcx,%rcx,2), %rsi
shlq $0x5, %rsi
addq %rdi, %rsi
movq 0x20(%rsp), %rcx
movslq (%rcx,%rax,4), %rax
leaq (%rax,%rax,2), %rdx
shlq $0x5, %rdx
addq %rdi, %rdx
movq %r12, %rdi
callq 0x1446a
movslq %r13d, %rax
imulq $0x188, %rax, %r14      # imm = 0x188
movq 0x40(%rbx), %rdi
addq %r14, %rdi
movq %r12, %rsi
callq 0x14ad0
movq %r12, %rdi
callq 0x14a50
movq 0x40(%rbx), %rax
movl 0x18(%rax,%r14), %eax
addl %eax, 0x38(%rbx)
incl %r13d
movl %ebp, %eax
movq (%rsp), %rcx
movq 0x8(%rsp), %rdx
subq %rcx, %rdx
sarq $0x2, %rdx
incl %ebp
cmpq %rax, %rdx
ja 0xeef7
movq %r15, %rdi
callq 0x2270
movslq 0x38(%rbx), %rax
leaq (,%rax,8), %rcx
testq %rax, %rax
movq $-0x1, %rdi
cmovnsq %rcx, %rdi
callq 0x2030
movq %rax, 0x30(%rbx)
movq %rbx, %rdi
callq 0xf2c4
movq %rbx, %rdi
callq 0xf328
movslq 0x48(%rbx), %r14
leaq (,%r14,8), %rdi
callq 0x22d0
movq %rax, 0x68(%rbx)
testq %r14, %r14
jle 0xf02a
movl $0x168, %r15d           # imm = 0x168
xorl %r12d, %r12d
movl $0x18, %edi
callq 0x22d0
movq 0x68(%rbx), %rcx
movq %rax, (%rcx,%r12,8)
movq 0x40(%rbx), %rax
movq 0x68(%rbx), %rcx
movq (%rax,%r15), %rax
movsd 0x10(%rax), %xmm0
movq (%rcx,%r12,8), %rcx
movsd %xmm0, (%rcx)
movsd 0x18(%rax), %xmm0
movsd %xmm0, 0x8(%rcx)
movsd 0x20(%rax), %xmm0
movsd %xmm0, 0x10(%rcx)
incq %r12
addq $0x188, %r15            # imm = 0x188
cmpq %r12, %r14
jne 0xefdc
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0xf041
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2230
movq (%rsp), %rdi
testq %rdi, %rdi
je 0xf057
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2230
addq $0x1e8, %rsp            # imm = 0x1E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xbb02(%rip), %rdi      # 0x1ab72
leaq 0xbb17(%rip), %rsi      # 0x1ab8e
leaq 0xbb1e(%rip), %rcx      # 0x1ab9c
movl $0x71, %edx
callq 0x2160
jmp 0xf094
jmp 0xf094
jmp 0xf094
jmp 0xf094
jmp 0xf094
jmp 0xf094
movq %rax, %rbx
jmp 0xf0de
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x14a50
jmp 0xf0de
movq %rax, %rbx
testq %r13, %r13
je 0xf0d1
negq %r13
movq 0x50(%rsp), %r14
addq $-0x180, %r14           # imm = 0xFE80
leaq (%r14,%r13), %rdi
callq 0x14a50
addq $-0x188, %r13           # imm = 0xFE78
jne 0xf0bf
movq 0x50(%rsp), %rdi
movq %r12, %rsi
callq 0x23d0
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0xf0f5
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2230
movq (%rsp), %rdi
testq %rdi, %rdi
je 0xf10b
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2230
movq %rbx, %rdi
callq 0x2390
nop