// File: atfrank[P]PCASA/lib/Molecule.cpp
// Function: Molecule::clone(bool, bool)
Molecule* Molecule::clone (bool selFlag, bool keep){
  //Deep copy
  Molecule *mol=new Molecule;
  Chain *c, *chnEntry;
  Residue *r, *resEntry;
  Atom *a, *atmEntry;

  c=NULL;
  r=NULL;
  a=NULL;
  chnEntry=NULL;
  resEntry=NULL;
  atmEntry=NULL;
  mol->setCopyFlag(false); //Not a copy
  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; //Deleted later if no residues/atoms

    for (unsigned int j=0; j< c->getResVecSize(); j++){
      r=c->getResidue(j);
      resEntry=new Residue; //Deleted later if no atoms

      for (unsigned int k=0; k< r->getAtmVecSize(); k++){
        a=r->getAtom(k);
        if(selFlag == true && a->getSel() == false){
          continue;
        }
        //Add each selected atom
        atmEntry=new Atom; //This is necessary!
        atmEntry->clone(a); //Clone Atom
        mol->addAtom(atmEntry);
        resEntry->addAtom(atmEntry);
        chnEntry->addAtom(atmEntry);
      }
      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;
    }
  }

  if (keep == false){
    delete this;
  }

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

  return mol;
}

// Assembly:
subq $0x138, %rsp            # imm = 0x138
movb %dl, %al
movb %sil, %cl
movq %rdi, 0x130(%rsp)
andb $0x1, %cl
movb %cl, 0x12f(%rsp)
andb $0x1, %al
movb %al, 0x12e(%rsp)
movq 0x130(%rsp), %rax
movq %rax, 0x78(%rsp)
movl $0x1a0, %edi            # imm = 0x1A0
callq 0x5410
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x80(%rsp)
callq 0x41a20
jmp 0x42343
movq 0x80(%rsp), %rax
movq %rax, 0x120(%rsp)
movq $0x0, 0x108(%rsp)
movq $0x0, 0xf8(%rsp)
movq $0x0, 0xe8(%rsp)
movq $0x0, 0x100(%rsp)
movq $0x0, 0xf0(%rsp)
movq $0x0, 0xe0(%rsp)
movq 0x120(%rsp), %rdi
xorl %esi, %esi
callq 0x428b0
movq 0x78(%rsp), %rdi
movq 0x120(%rsp), %rax
movq %rax, 0x60(%rsp)
callq 0x428f0
movq 0x60(%rsp), %rdi
movl %eax, 0xdc(%rsp)
leaq 0xdc(%rsp), %rsi
callq 0x428d0
movq 0x78(%rsp), %rsi
movq 0x120(%rsp), %rax
movq %rax, 0x68(%rsp)
leaq 0xb8(%rsp), %rdi
movq %rdi, 0x70(%rsp)
callq 0x42940
movq 0x68(%rsp), %rdi
movq 0x70(%rsp), %rsi
callq 0x42910
jmp 0x4240f
leaq 0xb8(%rsp), %rdi
callq 0x5250
movq 0x78(%rsp), %rsi
movq 0x120(%rsp), %rax
movq %rax, 0x50(%rsp)
leaq 0x98(%rsp), %rdi
movq %rdi, 0x58(%rsp)
callq 0x429a0
movq 0x50(%rsp), %rdi
movq 0x58(%rsp), %rsi
callq 0x42970
jmp 0x42451
leaq 0x98(%rsp), %rdi
callq 0x5250
movl $0x0, 0x94(%rsp)
movq 0x78(%rsp), %rdi
movl 0x94(%rsp), %eax
movl %eax, 0x4c(%rsp)
callq 0x41e20
movl %eax, %ecx
movl 0x4c(%rsp), %eax
cmpl %ecx, %eax
jae 0x42840
movq 0x78(%rsp), %rdi
leaq 0x94(%rsp), %rsi
callq 0x41e40
movq %rax, 0x108(%rsp)
movl $0x30, %edi
callq 0x5410
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x40(%rsp)
callq 0x3a320
jmp 0x424c2
movq 0x40(%rsp), %rax
movq %rax, 0x100(%rsp)
movl $0x0, 0x90(%rsp)
movl 0x90(%rsp), %eax
movl %eax, 0x3c(%rsp)
movq 0x108(%rsp), %rdi
callq 0x3a570
movl %eax, %ecx
movl 0x3c(%rsp), %eax
cmpl %ecx, %eax
jae 0x427d1
movq 0x108(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x3a490
movq %rax, 0xf8(%rsp)
movl $0x18, %edi
callq 0x5410
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x30(%rsp)
callq 0x5de80
jmp 0x42539
movq 0x30(%rsp), %rax
movq %rax, 0xf0(%rsp)
movl $0x0, 0x8c(%rsp)
movl 0x8c(%rsp), %eax
movl %eax, 0x2c(%rsp)
movq 0xf8(%rsp), %rdi
callq 0x5e110
movl %eax, %ecx
movl 0x2c(%rsp), %eax
cmpl %ecx, %eax
jae 0x4274d
movq 0xf8(%rsp), %rdi
leaq 0x8c(%rsp), %rsi
callq 0x5df30
movq %rax, 0xe8(%rsp)
movb 0x12f(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x42692
movq 0xe8(%rsp), %rdi
callq 0x1f780
movb (%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x42692
jmp 0x4270f
movq 0x80(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x118(%rsp)
movl %eax, 0x114(%rsp)
movl $0x1a0, %esi            # imm = 0x1A0
callq 0x5420
jmp 0x428a3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x118(%rsp)
movl %eax, 0x114(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0x5250
jmp 0x428a3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x118(%rsp)
movl %eax, 0x114(%rsp)
leaq 0x98(%rsp), %rdi
callq 0x5250
jmp 0x428a3
movq 0x40(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x118(%rsp)
movl %eax, 0x114(%rsp)
movl $0x30, %esi
callq 0x5420
jmp 0x428a3
movq 0x30(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x118(%rsp)
movl %eax, 0x114(%rsp)
movl $0x18, %esi
callq 0x5420
jmp 0x428a3
movl $0x238, %edi            # imm = 0x238
callq 0x5410
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x20(%rsp)
callq 0x1e7f0
jmp 0x426ae
movq 0x20(%rsp), %rax
movq %rax, 0xe0(%rsp)
movq 0xe0(%rsp), %rdi
movq 0xe8(%rsp), %rsi
callq 0x1f2a0
movq 0x120(%rsp), %rdi
movq 0xe0(%rsp), %rsi
callq 0x422b0
movq 0xf0(%rsp), %rdi
movq 0xe0(%rsp), %rsi
callq 0x5dec0
movq 0x100(%rsp), %rdi
movq 0xe0(%rsp), %rsi
callq 0x3a3e0
movl 0x8c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x8c(%rsp)
jmp 0x42551
movq 0x20(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x118(%rsp)
movl %eax, 0x114(%rsp)
movl $0x238, %esi            # imm = 0x238
callq 0x5420
jmp 0x428a3
movq 0xf0(%rsp), %rdi
callq 0x5e110
cmpl $0x0, %eax
jbe 0x4278b
movq 0x120(%rsp), %rdi
movq 0xf0(%rsp), %rsi
callq 0x429d0
movq 0x100(%rsp), %rdi
movq 0xf0(%rsp), %rsi
callq 0x3a3a0
jmp 0x427b9
movq 0xf0(%rsp), %rax
movq %rax, 0x18(%rsp)
cmpq $0x0, %rax
je 0x427b7
movq 0x18(%rsp), %rdi
callq 0x46fa0
movq 0x18(%rsp), %rdi
movl $0x18, %esi
callq 0x5420
jmp 0x427b9
jmp 0x427bb
movl 0x90(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x90(%rsp)
jmp 0x424da
movq 0x100(%rsp), %rdi
callq 0x3a570
cmpl $0x0, %eax
jbe 0x427fa
movq 0x120(%rsp), %rdi
movq 0x100(%rsp), %rsi
callq 0x42a10
jmp 0x42828
movq 0x100(%rsp), %rax
movq %rax, 0x10(%rsp)
cmpq $0x0, %rax
je 0x42826
movq 0x10(%rsp), %rdi
callq 0x46fb0
movq 0x10(%rsp), %rdi
movl $0x30, %esi
callq 0x5420
jmp 0x42828
jmp 0x4282a
movl 0x94(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x94(%rsp)
jmp 0x42469
movb 0x12e(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x42869
movq 0x78(%rsp), %rax
cmpq $0x0, %rax
je 0x42867
movq 0x78(%rsp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x42869
movq 0x120(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x120(%rsp), %rdi
callq 0x42ab0
movq 0x8(%rsp), %rdi
movzbl %al, %esi
andl $0x1, %esi
callq 0x42a80
movq 0x120(%rsp), %rax
addq $0x138, %rsp            # imm = 0x138
retq
movq 0x118(%rsp), %rdi
callq 0x5720