// File: 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:
subq $0x128, %rsp            # imm = 0x128
movb %sil, %al
movq %rdi, 0x120(%rsp)
andb $0x1, %al
movb %al, 0x11f(%rsp)
movq 0x120(%rsp), %rax
movq %rax, 0x70(%rsp)
movl $0x1a0, %edi            # imm = 0x1A0
callq 0x5410
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x78(%rsp)
callq 0x41a20
jmp 0x42bb4
movq 0x78(%rsp), %rax
movq %rax, 0x110(%rsp)
movq $0x0, 0xf8(%rsp)
movq $0x0, 0xe8(%rsp)
movq $0x0, 0xd8(%rsp)
movq $0x0, 0xf0(%rsp)
movq $0x0, 0xe0(%rsp)
movq 0x110(%rsp), %rdi
movl $0x1, %esi
callq 0x428b0
movq 0x70(%rsp), %rdi
movq 0x110(%rsp), %rax
movq %rax, 0x58(%rsp)
callq 0x428f0
movq 0x58(%rsp), %rdi
movl %eax, 0xd4(%rsp)
leaq 0xd4(%rsp), %rsi
callq 0x428d0
movq 0x70(%rsp), %rsi
movq 0x110(%rsp), %rax
movq %rax, 0x60(%rsp)
leaq 0xb0(%rsp), %rdi
movq %rdi, 0x68(%rsp)
callq 0x42940
movq 0x60(%rsp), %rdi
movq 0x68(%rsp), %rsi
callq 0x42910
jmp 0x42c74
leaq 0xb0(%rsp), %rdi
callq 0x5250
movq 0x70(%rsp), %rsi
movq 0x110(%rsp), %rax
movq %rax, 0x48(%rsp)
leaq 0x90(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0x429a0
movq 0x48(%rsp), %rdi
movq 0x50(%rsp), %rsi
callq 0x42970
jmp 0x42cb6
leaq 0x90(%rsp), %rdi
callq 0x5250
movl $0x0, 0x8c(%rsp)
movq 0x70(%rsp), %rdi
movl 0x8c(%rsp), %eax
movl %eax, 0x44(%rsp)
callq 0x41e20
movl %eax, %ecx
movl 0x44(%rsp), %eax
cmpl %ecx, %eax
jae 0x4303c
movq 0x70(%rsp), %rdi
leaq 0x8c(%rsp), %rsi
callq 0x41e40
movq %rax, 0xf8(%rsp)
movl $0x30, %edi
callq 0x5410
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x38(%rsp)
callq 0x3a320
jmp 0x42d27
movq 0x38(%rsp), %rax
movq %rax, 0xf0(%rsp)
movl $0x0, 0x88(%rsp)
movl 0x88(%rsp), %eax
movl %eax, 0x34(%rsp)
movq 0xf8(%rsp), %rdi
callq 0x3a570
movl %eax, %ecx
movl 0x34(%rsp), %eax
cmpl %ecx, %eax
jae 0x42fcd
movq 0xf8(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x3a490
movq %rax, 0xe8(%rsp)
movl $0x18, %edi
callq 0x5410
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x28(%rsp)
callq 0x5de80
jmp 0x42d9e
movq 0x28(%rsp), %rax
movq %rax, 0xe0(%rsp)
movl $0x0, 0x84(%rsp)
movl 0x84(%rsp), %eax
movl %eax, 0x24(%rsp)
movq 0xe8(%rsp), %rdi
callq 0x5e110
movl %eax, %ecx
movl 0x24(%rsp), %eax
cmpl %ecx, %eax
jae 0x42f49
movq 0xe8(%rsp), %rdi
leaq 0x84(%rsp), %rsi
callq 0x5df30
movq %rax, 0xd8(%rsp)
movb 0x11f(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x42ef4
movq 0xd8(%rsp), %rdi
callq 0x1f780
movb (%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x42ef4
jmp 0x42f33
movq 0x78(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x108(%rsp)
movl %eax, 0x104(%rsp)
movl $0x1a0, %esi            # imm = 0x1A0
callq 0x5420
jmp 0x43076
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x108(%rsp)
movl %eax, 0x104(%rsp)
leaq 0xb0(%rsp), %rdi
callq 0x5250
jmp 0x43076
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x108(%rsp)
movl %eax, 0x104(%rsp)
leaq 0x90(%rsp), %rdi
callq 0x5250
jmp 0x43076
movq 0x38(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x108(%rsp)
movl %eax, 0x104(%rsp)
movl $0x30, %esi
callq 0x5420
jmp 0x43076
movq 0x28(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x108(%rsp)
movl %eax, 0x104(%rsp)
movl $0x18, %esi
callq 0x5420
jmp 0x43076
movq 0x110(%rsp), %rdi
movq 0xd8(%rsp), %rsi
callq 0x422b0
movq 0xe0(%rsp), %rdi
movq 0xd8(%rsp), %rsi
callq 0x5dec0
movq 0xf0(%rsp), %rdi
movq 0xd8(%rsp), %rsi
callq 0x3a3e0
movl 0x84(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x84(%rsp)
jmp 0x42db6
movq 0xe0(%rsp), %rdi
callq 0x5e110
cmpl $0x0, %eax
jbe 0x42f87
movq 0x110(%rsp), %rdi
movq 0xe0(%rsp), %rsi
callq 0x429d0
movq 0xf0(%rsp), %rdi
movq 0xe0(%rsp), %rsi
callq 0x3a3a0
jmp 0x42fb5
movq 0xe0(%rsp), %rax
movq %rax, 0x18(%rsp)
cmpq $0x0, %rax
je 0x42fb3
movq 0x18(%rsp), %rdi
callq 0x46fa0
movq 0x18(%rsp), %rdi
movl $0x18, %esi
callq 0x5420
jmp 0x42fb5
jmp 0x42fb7
movl 0x88(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x88(%rsp)
jmp 0x42d3f
movq 0xf0(%rsp), %rdi
callq 0x3a570
cmpl $0x0, %eax
jbe 0x42ff6
movq 0x110(%rsp), %rdi
movq 0xf0(%rsp), %rsi
callq 0x42a10
jmp 0x43024
movq 0xf0(%rsp), %rax
movq %rax, 0x10(%rsp)
cmpq $0x0, %rax
je 0x43022
movq 0x10(%rsp), %rdi
callq 0x46fb0
movq 0x10(%rsp), %rdi
movl $0x30, %esi
callq 0x5420
jmp 0x43024
jmp 0x43026
movl 0x8c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x8c(%rsp)
jmp 0x42cce
movq 0x110(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x110(%rsp), %rdi
callq 0x42ab0
movq 0x8(%rsp), %rdi
movzbl %al, %esi
andl $0x1, %esi
callq 0x42a80
movq 0x110(%rsp), %rax
addq $0x128, %rsp            # imm = 0x128
retq
movq 0x108(%rsp), %rdi
callq 0x5720
nopw %cs:(%rax,%rax)