// File: /workspace/github_cpp_makefile_star2_O2/atfrank[P]PCASA/lib/Molecule.cpp
// Function: Molecule::copy(bool)
Molecule* Molecule::copy (bool selFlag){
  //Shallow copy of selected atom pointers.
  //Chains and Residues are required to be created new.
  //Useful when you need to make multiple selections
  Molecule *mol=new Molecule;
  Chain *c, *chnEntry;
  Residue *r, *resEntry;
  Atom *a;

  c=NULL;
  r=NULL;
  a=NULL;
  chnEntry=NULL;
  resEntry=NULL;
  mol->setCopyFlag(true); //Is a copy, do not destruct atoms!
  mol->setYear(this->getYear());
  mol->setExp(this->getExp());
  mol->setTag(this->getTag());

  for (unsigned int i=0; i< this->getChnVecSize(); i++){
    c=this->getChain(i);
    chnEntry=new Chain;

    for (unsigned int j=0; j< c->getResVecSize(); j++){
      r=c->getResidue(j);
      resEntry=new Residue;

      for (unsigned int k=0; k< r->getAtmVecSize(); k++){
        a=r->getAtom(k);
        if(selFlag == true && a->getSel() == false){
          continue;
        }
        //Add each selected atom
        mol->addAtom(a); //Copy atom pointer, not clone
        resEntry->addAtom(a);
        chnEntry->addAtom(a);
      }
      if (resEntry->getAtmVecSize() > 0){
        //Add each residue with selected atoms
        mol->addResidue(resEntry);
        chnEntry->addResidue(resEntry);
      }
      else{
        delete resEntry;
      }
    }
    if (chnEntry->getResVecSize() > 0){
      //Add each chain with selected atoms
      mol->addChain(chnEntry);
    }
    else{
      delete chnEntry;
    }     
  } 

  mol->setICodeFlag(mol->checkICode());

  return mol;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %esi, %ebp
movq %rdi, %r15
movl $0x1a0, %edi            # imm = 0x1A0
callq 0x4320
movq %rax, %rbx
movq %rax, %rdi
callq 0x19e1c
movb $0x1, 0x50(%rbx)
movl 0x158(%r15), %eax
movl %eax, 0x158(%rbx)
movl $0x160, %r14d           # imm = 0x160
leaq (%r15,%r14), %rsi
movq %r15, %r12
leaq 0x28(%rsp), %r15
movq %r15, %rdi
callq 0x4430
addq %rbx, %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x41a0
leaq 0x28(%rsp), %rdi
callq 0x4170
movl $0x180, %r15d           # imm = 0x180
movq %r12, 0x18(%rsp)
leaq (%r12,%r15), %rsi
leaq 0x28(%rsp), %r14
movq %r14, %rdi
callq 0x4430
movq %rbx, %rdi
addq %r15, %rdi
movq %r14, %rsi
callq 0x41a0
leaq 0x28(%rsp), %rdi
callq 0x4170
xorl %ecx, %ecx
movq 0x18(%rsp), %rdi
movl %ecx, 0x28(%rsp)
movq 0x10(%rdi), %rax
subq 0x8(%rdi), %rax
shrq $0x3, %rax
cmpl %eax, %ecx
jae 0x1a890
movl %ecx, 0xc(%rsp)
leaq 0x28(%rsp), %rsi
callq 0x19fb0
movq %rax, %r12
pushq $0x30
popq %rdi
callq 0x4320
movq %rax, %r14
movq %rax, %rdi
callq 0x17750
xorl %r15d, %r15d
movq %r12, 0x20(%rsp)
movl %r15d, 0x14(%rsp)
movq %r12, %rdi
callq 0x1786c
cmpl %eax, %r15d
jae 0x1a854
movq %r12, %rdi
leaq 0x14(%rsp), %rsi
callq 0x17802
movq %rax, %r13
pushq $0x18
popq %rdi
callq 0x4320
movq %rax, %r15
movq %rax, %rdi
callq 0x23990
xorl %r12d, %r12d
movl %r12d, 0x10(%rsp)
movq %r13, %rdi
callq 0x23aee
cmpl %eax, %r12d
jae 0x1a80b
movq %r13, %rdi
leaq 0x10(%rsp), %rsi
callq 0x239f2
movq %rax, %r12
testb %bpl, %bpl
je 0x1a7e0
movq %r12, %rdi
callq 0xea64
cmpb $0x0, (%rax)
je 0x1a801
movq %rbx, %rdi
movq %r12, %rsi
callq 0x1a23a
movq %r15, %rdi
movq %r12, %rsi
callq 0x239aa
movq %r14, %rdi
movq %r12, %rsi
callq 0x177a8
movl 0x10(%rsp), %r12d
incl %r12d
jmp 0x1a7ac
movq %r15, %rdi
callq 0x23aee
testl %eax, %eax
je 0x1a82f
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1a572
movq %r14, %rdi
movq %r15, %rsi
callq 0x1777c
jmp 0x1a842
movq %r15, %rdi
callq 0xf036
movq %r15, %rdi
pushq $0x18
popq %rsi
callq 0x4330
movq 0x20(%rsp), %r12
movl 0x14(%rsp), %r15d
incl %r15d
jmp 0x1a770
movq %r14, %rdi
callq 0x1786c
testl %eax, %eax
je 0x1a86d
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1a5a2
jmp 0x1a880
movq %r14, %rdi
callq 0x1cb16
movq %r14, %rdi
pushq $0x30
popq %rsi
callq 0x4330
movq 0x18(%rsp), %rdi
movl 0xc(%rsp), %ecx
incl %ecx
jmp 0x1a72c
movq %rbx, %rdi
callq 0x1a5f4
movb %al, 0xa8(%rbx)
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1a8b2
movq %rax, %r12
leaq 0x28(%rsp), %rdi
callq 0x4170
jmp 0x1a8e7
movq %rax, %r12
movl $0x1a0, %esi            # imm = 0x1A0
movq %rbx, %rdi
jmp 0x1a8e2
movq %rax, %r12
pushq $0x30
popq %rsi
movq %r14, %rdi
jmp 0x1a8e2
movq %rax, %r12
pushq $0x18
popq %rsi
movq %r15, %rdi
callq 0x4330
movq %r12, %rdi
callq 0x4560
nop