// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %edx, 0x10(%rsp)
movl %esi, %r15d
movq %rdi, %r14
movl $0x1a0, %edi            # imm = 0x1A0
callq 0x4320
movq %rax, %rbx
movq %rax, %rdi
callq 0x19e1c
movb $0x0, 0x50(%rbx)
movl 0x158(%r14), %eax
movl %eax, 0x158(%rbx)
movq %rbx, %r12
movl $0x160, %ebx            # imm = 0x160
leaq (%r14,%rbx), %rsi
movq %r14, %r13
leaq 0x28(%rsp), %r14
movq %r14, %rdi
callq 0x4430
addq %r12, %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x41a0
leaq 0x28(%rsp), %rdi
callq 0x4170
movl $0x180, %r14d           # imm = 0x180
movq %r13, 0x18(%rsp)
leaq (%r14,%r13), %rsi
leaq 0x28(%rsp), %rbx
movq %rbx, %rdi
callq 0x4430
movq %r12, 0x8(%rsp)
movq %r12, %rdi
addq %r14, %rdi
movq %rbx, %rsi
callq 0x41a0
leaq 0x28(%rsp), %rdi
callq 0x4170
xorl %ecx, %ecx
movq 0x8(%rsp), %rbx
movq 0x18(%rsp), %rdi
movl %ecx, 0x28(%rsp)
movq 0x10(%rdi), %rax
subq 0x8(%rdi), %rax
shrq $0x3, %rax
cmpl %eax, %ecx
jae 0x1a49d
movl %ecx, 0x14(%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 %ebx, %ebx
movq %r12, 0x20(%rsp)
movl %ebx, 0x4(%rsp)
movq %r12, %rdi
callq 0x1786c
cmpl %eax, %ebx
jae 0x1a461
movq %r12, %rdi
leaq 0x4(%rsp), %rsi
callq 0x17802
movq %rax, %rbp
pushq $0x18
popq %rdi
callq 0x4320
movq %rax, %r12
movq %rax, %rdi
callq 0x23990
xorl %ebx, %ebx
movl %ebx, (%rsp)
movq %rbp, %rdi
callq 0x23aee
cmpl %eax, %ebx
jae 0x1a418
movq %rbp, %rdi
movq %rsp, %rsi
callq 0x239f2
movq %rax, %rbx
testb %r15b, %r15b
je 0x1a3ce
movq %rbx, %rdi
callq 0xea64
cmpb $0x0, (%rax)
je 0x1a411
movl $0x238, %edi            # imm = 0x238
callq 0x4320
movq %rax, %r13
movq %rax, %rdi
callq 0xdee4
movq %r13, %rdi
movq %rbx, %rsi
callq 0xe844
movq 0x8(%rsp), %rdi
movq %r13, %rsi
callq 0x1a23a
movq %r12, %rdi
movq %r13, %rsi
callq 0x239aa
movq %r14, %rdi
movq %r13, %rsi
callq 0x177a8
movl (%rsp), %ebx
incl %ebx
jmp 0x1a39f
movq %r12, %rdi
callq 0x23aee
testl %eax, %eax
je 0x1a43e
movq 0x8(%rsp), %rdi
movq %r12, %rsi
callq 0x1a572
movq %r14, %rdi
movq %r12, %rsi
callq 0x1777c
jmp 0x1a451
movq %r12, %rdi
callq 0xf036
movq %r12, %rdi
pushq $0x18
popq %rsi
callq 0x4330
movq 0x20(%rsp), %r12
movl 0x4(%rsp), %ebx
incl %ebx
jmp 0x1a366
movq %r14, %rdi
callq 0x1786c
testl %eax, %eax
movq 0x8(%rsp), %rbx
je 0x1a47f
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1a5a2
jmp 0x1a492
movq %r14, %rdi
callq 0x1cb16
movq %r14, %rdi
pushq $0x30
popq %rsi
callq 0x4330
movl 0x14(%rsp), %ecx
incl %ecx
jmp 0x1a31e
cmpb $0x0, 0x10(%rsp)
jne 0x1a4aa
movq (%rdi), %rax
callq *0x8(%rax)
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 0x1a4cc
movq %rax, %r15
leaq 0x28(%rsp), %rdi
callq 0x4170
jmp 0x1a50e
movq %rax, %r15
movl $0x1a0, %esi            # imm = 0x1A0
movq %rbx, %rdi
jmp 0x1a509
movq %rax, %r15
pushq $0x30
popq %rsi
movq %r14, %rdi
jmp 0x1a509
movq %rax, %r15
pushq $0x18
popq %rsi
movq %r12, %rdi
jmp 0x1a509
movq %rax, %r15
movl $0x238, %esi            # imm = 0x238
movq %r13, %rdi
callq 0x4330
movq %r15, %rdi
callq 0x4560