// File: gjoni[P]iPot/src/Chain.cpp
// Function: Chain::operator=(Chain const&)
Chain & Chain::operator =(const Chain & source) {

	delete[] atom;
	delete[] residue;
	for (int i = 0; i < nRes; i++) {
		free(ca_trace[i]);
	}
	free(ca_trace);

	/* copy residues */
	nRes = source.nRes;
	residue = new Residue[nRes];
	for (int i = 0; i < nRes; i++) {
		residue[i] = source.residue[i];
	}

	/* set pointers to atoms */
	nAtoms = source.nAtoms;
	atom = new Atom*[nAtoms];

	SetAtomPointers();

	SetKD();

	//resmap = source.resmap;
	SetResMap();

	/* 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;
	}

	return *this;

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x40(%rbp)
movq 0x30(%rax), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
je 0x1a7b2
movq -0x38(%rbp), %rdi
callq 0x3380
movq -0x40(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x48(%rbp)
cmpq $0x0, %rax
je 0x1a82e
movq -0x48(%rbp), %rcx
movq %rcx, %rax
addq $-0x8, %rax
movq %rax, -0x60(%rbp)
movq -0x8(%rcx), %rax
movq %rax, -0x58(%rbp)
imulq $0x188, %rax, %rdx      # imm = 0x188
movq %rcx, %rax
addq %rdx, %rax
cmpq %rax, %rcx
movq %rax, -0x50(%rbp)
je 0x1a816
movq -0x50(%rbp), %rdi
addq $-0x188, %rdi           # imm = 0xFE78
movq %rdi, -0x68(%rbp)
callq 0x29280
movq -0x48(%rbp), %rcx
movq -0x68(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x50(%rbp)
jne 0x1a7f1
movq -0x60(%rbp), %rdi
movq -0x58(%rbp), %rax
imulq $0x188, %rax, %rsi      # imm = 0x188
addq $0x8, %rsi
callq 0x34a0
movl $0x0, -0x14(%rbp)
movq -0x40(%rbp), %rcx
movl -0x14(%rbp), %eax
cmpl 0x48(%rcx), %eax
jge 0x1a861
movq -0x40(%rbp), %rax
movq 0x68(%rax), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x3320
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x1a835
movq -0x40(%rbp), %rax
movq 0x68(%rax), %rdi
callq 0x3320
movq -0x40(%rbp), %rax
movq -0x10(%rbp), %rcx
movl 0x48(%rcx), %ecx
movl %ecx, 0x48(%rax)
movslq 0x48(%rax), %rax
movq %rax, -0x80(%rbp)
movl $0x188, %ecx            # imm = 0x188
mulq %rcx
movq %rax, %rdi
seto %cl
addq $0x8, %rdi
setb %al
orb %al, %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
movq %rdi, -0x88(%rbp)
callq 0x3030
movq %rax, %rcx
movq -0x80(%rbp), %rax
movq %rcx, -0x78(%rbp)
movq %rax, (%rcx)
addq $0x8, %rcx
movq %rcx, -0x70(%rbp)
cmpq $0x0, %rax
je 0x1a929
movq -0x70(%rbp), %rax
movq -0x80(%rbp), %rcx
imulq $0x188, %rcx, %rdx      # imm = 0x188
movq %rax, %rcx
addq %rdx, %rcx
movq %rcx, -0x98(%rbp)
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rdi
movq %rdi, -0xa0(%rbp)
callq 0x279a0
jmp 0x1a909
movq -0x98(%rbp), %rcx
movq -0xa0(%rbp), %rax
addq $0x188, %rax            # imm = 0x188
cmpq %rcx, %rax
movq %rax, -0x90(%rbp)
jne 0x1a8f4
movq -0x40(%rbp), %rax
movq -0x70(%rbp), %rcx
movq %rcx, 0x40(%rax)
movl $0x0, -0x28(%rbp)
movq -0x40(%rbp), %rcx
movl -0x28(%rbp), %eax
cmpl 0x48(%rcx), %eax
jge 0x1a9ef
movq -0x40(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x40(%rcx), %rsi
movslq -0x28(%rbp), %rcx
imulq $0x188, %rcx, %rcx      # imm = 0x188
addq %rcx, %rsi
movq 0x40(%rax), %rdi
movslq -0x28(%rbp), %rax
imulq $0x188, %rax, %rax      # imm = 0x188
addq %rax, %rdi
callq 0x29350
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x1a93c
movq -0x70(%rbp), %rcx
movq %rax, %rsi
movq -0xa0(%rbp), %rax
movq %rsi, -0x20(%rbp)
movl %edx, -0x24(%rbp)
cmpq %rax, %rcx
movq %rax, -0xa8(%rbp)
je 0x1a9da
movq -0xa8(%rbp), %rdi
addq $-0x188, %rdi           # imm = 0xFE78
movq %rdi, -0xb0(%rbp)
callq 0x29280
movq -0x70(%rbp), %rcx
movq -0xb0(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0xa8(%rbp)
jne 0x1a9a9
movq -0x88(%rbp), %rsi
movq -0x78(%rbp), %rdi
callq 0x34a0
jmp 0x1ab38
movq -0x40(%rbp), %rax
movq -0x10(%rbp), %rcx
movl 0x38(%rcx), %ecx
movl %ecx, 0x38(%rax)
movslq 0x38(%rax), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x3030
movq -0x40(%rbp), %rdi
movq %rax, 0x30(%rdi)
callq 0x1a010
movq -0x40(%rbp), %rdi
callq 0x1a0c0
movq -0x40(%rbp), %rdi
callq 0x19da0
movq -0x40(%rbp), %rax
movslq 0x48(%rax), %rdi
shlq $0x3, %rdi
callq 0x3390
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x68(%rax)
movl $0x0, -0x2c(%rbp)
movq -0x40(%rbp), %rcx
movl -0x2c(%rbp), %eax
cmpl 0x48(%rcx), %eax
jge 0x1ab2b
movl $0x18, %edi
callq 0x3390
movq %rax, %rsi
movq -0x40(%rbp), %rax
movq 0x68(%rax), %rcx
movslq -0x2c(%rbp), %rdx
movq %rsi, (%rcx,%rdx,8)
movq 0x40(%rax), %rcx
movslq -0x2c(%rbp), %rdx
imulq $0x188, %rdx, %rdx      # imm = 0x188
addq %rdx, %rcx
movq 0x168(%rcx), %rcx
movsd 0x10(%rcx), %xmm0
movq 0x68(%rax), %rcx
movslq -0x2c(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movsd %xmm0, (%rcx)
movq 0x40(%rax), %rcx
movslq -0x2c(%rbp), %rdx
imulq $0x188, %rdx, %rdx      # imm = 0x188
addq %rdx, %rcx
movq 0x168(%rcx), %rcx
movsd 0x18(%rcx), %xmm0
movq 0x68(%rax), %rcx
movslq -0x2c(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movsd %xmm0, 0x8(%rcx)
movq 0x40(%rax), %rcx
movslq -0x2c(%rbp), %rdx
imulq $0x188, %rdx, %rdx      # imm = 0x188
addq %rdx, %rcx
movq 0x168(%rcx), %rcx
movsd 0x20(%rcx), %xmm0
movq 0x68(%rax), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsd %xmm0, 0x10(%rax)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x1aa64
movq -0x40(%rbp), %rax
addq $0xb0, %rsp
popq %rbp
retq
movq -0x20(%rbp), %rdi
callq 0x3460
nopw %cs:(%rax,%rax)