// File: /workspace/github_cpp_makefile_star2_O3/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, %r12
movl $0x1a0, %edi            # imm = 0x1A0
callq 0x42d0
movq %rax, %rbx
movq %rax, %rdi
callq 0x23410
movb $0x1, 0x50(%rbx)
movl 0x158(%r12), %eax
movl %eax, 0x158(%rbx)
leaq 0x20(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x160(%r12), %rsi
movq 0x168(%r12), %rdx
addq %rsi, %rdx
leaq 0x10(%rsp), %r14
movq %r14, %rdi
callq 0x647c
leaq 0x160(%rbx), %rdi
movq %r14, %rsi
callq 0x4180
movq 0x10(%rsp), %rdi
cmpq %r15, %rdi
je 0x23f8b
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x42e0
leaq 0x10(%rsp), %r14
movq %r15, (%r14)
movq 0x180(%r12), %rsi
movq 0x188(%r12), %rdx
addq %rsi, %rdx
movq %r14, %rdi
callq 0x647c
movq %rbx, %rdi
addq $0x180, %rdi            # imm = 0x180
movq %r14, %rsi
callq 0x4180
movq 0x10(%rsp), %rdi
cmpq %r15, %rdi
je 0x23fd7
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x42e0
movq 0x8(%r12), %rax
movq 0x10(%r12), %rcx
subq %rax, %rcx
movq %rcx, %rdx
shrq $0x3, %rdx
testl %edx, %edx
je 0x241c0
xorl %esi, %esi
movq %r12, 0x38(%rsp)
sarq $0x3, %rcx
cmpq %rsi, %rcx
movq %rsi, 0x40(%rsp)
jbe 0x2400e
movq (%rax,%rsi,8), %r12
jmp 0x24011
xorl %r12d, %r12d
movl $0x30, %edi
callq 0x42d0
movq %rax, %r13
movq %rax, %rdi
callq 0x203b4
movl $0x0, 0x10(%rsp)
movq %r12, %rdi
callq 0x204e0
testl %eax, %eax
movq %r12, 0x30(%rsp)
je 0x24146
movq %r12, %rdi
leaq 0x10(%rsp), %rsi
callq 0x20486
movq %rax, %r14
movl $0x18, %edi
callq 0x42d0
movq %rax, %r15
movq %rax, %rdi
callq 0x2f47c
movl $0x0, 0xc(%rsp)
movq %r14, %rdi
callq 0x2f5c2
testl %eax, %eax
je 0x240d9
movq %r14, %rdi
leaq 0xc(%rsp), %rsi
callq 0x2f4ec
movq %rax, %r12
testb %bpl, %bpl
je 0x2409e
movq %r12, %rdi
callq 0x1496e
cmpb $0x0, (%rax)
je 0x240bf
movq %rbx, %rdi
movq %r12, %rsi
callq 0x23978
movq %r15, %rdi
movq %r12, %rsi
callq 0x2f49a
movq %r13, %rdi
movq %r12, %rsi
callq 0x20422
movl 0xc(%rsp), %r12d
incl %r12d
movl %r12d, 0xc(%rsp)
movq %r14, %rdi
callq 0x2f5c2
cmpl %eax, %r12d
jb 0x2407c
movq %r15, %rdi
callq 0x2f5c2
testl %eax, %eax
je 0x24102
movq %rbx, %rdi
movq %r15, %rsi
callq 0x23dc0
movq %r13, %rdi
movq %r15, %rsi
callq 0x203e0
movq 0x30(%rsp), %r12
jmp 0x24128
movq (%r15), %rdi
testq %rdi, %rdi
movq 0x30(%rsp), %r12
je 0x2411b
movq 0x10(%r15), %rsi
subq %rdi, %rsi
callq 0x42e0
movl $0x18, %esi
movq %r15, %rdi
callq 0x42e0
movl 0x10(%rsp), %r14d
incl %r14d
movl %r14d, 0x10(%rsp)
movq %r12, %rdi
callq 0x204e0
cmpl %eax, %r14d
jb 0x24043
movq %r13, %rdi
callq 0x204e0
testl %eax, %eax
je 0x2415f
movq %rbx, %rdi
movq %r13, %rsi
callq 0x23e06
jmp 0x24196
movq 0x18(%r13), %rdi
testq %rdi, %rdi
je 0x24174
movq 0x28(%r13), %rsi
subq %rdi, %rsi
callq 0x42e0
movq (%r13), %rdi
testq %rdi, %rdi
je 0x24189
movq 0x10(%r13), %rsi
subq %rdi, %rsi
callq 0x42e0
movl $0x30, %esi
movq %r13, %rdi
callq 0x42e0
movq 0x40(%rsp), %rsi
incq %rsi
movq 0x38(%rsp), %rcx
movq 0x8(%rcx), %rax
movq 0x10(%rcx), %rcx
subq %rax, %rcx
movq %rcx, %rdx
shrq $0x3, %rdx
movl %edx, %edx
cmpq %rdx, %rsi
jb 0x23ffa
movq %rbx, %rdi
callq 0x23e82
movb %al, 0xa8(%rbx)
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x241e2
movq %rax, %r14
movq 0x10(%rsp), %rdi
cmpq %r15, %rdi
je 0x24223
movq 0x20(%rsp), %rsi
incq %rsi
jmp 0x2421e
movq %rax, %r14
movl $0x1a0, %esi            # imm = 0x1A0
movq %rbx, %rdi
jmp 0x2421e
movq %rax, %r14
movl $0x30, %esi
movq %r13, %rdi
jmp 0x2421e
movq %rax, %r14
movl $0x18, %esi
movq %r15, %rdi
callq 0x42e0
movq %r14, %rdi
callq 0x4550
nop