// File: /workspace/github_cpp_makefile_star2_O3/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 $0x58, %rsp
movl %edx, 0x1c(%rsp)
movl %esi, %r15d
movq %rdi, %r13
movl $0x1a0, %edi            # imm = 0x1A0
callq 0x42d0
movq %rax, %rbx
movq %rax, %rdi
callq 0x23410
movb $0x0, 0x50(%rbx)
movl 0x158(%r13), %eax
movl %eax, 0x158(%rbx)
leaq 0x30(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x160(%r13), %rsi
movq 0x168(%r13), %rdx
addq %rsi, %rdx
movq %rbx, %r14
leaq 0x20(%rsp), %rbx
movq %rbx, %rdi
callq 0x647c
movq %r14, 0x10(%rsp)
leaq 0x160(%r14), %rdi
movq %rbx, %rsi
callq 0x4180
movq 0x20(%rsp), %rdi
cmpq %r12, %rdi
je 0x23a52
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x42e0
leaq 0x20(%rsp), %rbx
movq %r12, (%rbx)
movq 0x180(%r13), %rsi
movq 0x188(%r13), %rdx
addq %rsi, %rdx
movq %rbx, %rdi
callq 0x647c
movq 0x10(%rsp), %rdi
addq $0x180, %rdi            # imm = 0x180
movq %rbx, %rsi
callq 0x4180
movq 0x20(%rsp), %rdi
cmpq %r12, %rdi
je 0x23a9e
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x42e0
movq 0x8(%r13), %rax
movq 0x10(%r13), %rcx
subq %rax, %rcx
movq %rcx, %rdx
shrq $0x3, %rdx
testl %edx, %edx
movq 0x10(%rsp), %rbx
je 0x23cb2
xorl %esi, %esi
movq %r13, 0x48(%rsp)
sarq $0x3, %rcx
cmpq %rsi, %rcx
movq %rsi, 0x50(%rsp)
jbe 0x23ad8
movq (%rax,%rsi,8), %r14
jmp 0x23adb
xorl %r14d, %r14d
movl $0x30, %edi
callq 0x42d0
movq %rax, %rbp
movq %rax, %rdi
callq 0x203b4
movl $0x0, 0x20(%rsp)
movq %r14, %rdi
callq 0x204e0
testl %eax, %eax
movq %r14, 0x40(%rsp)
je 0x23c2e
movq %r14, %rdi
leaq 0x20(%rsp), %rsi
callq 0x20486
movq %rax, %r14
movl $0x18, %edi
callq 0x42d0
movq %rax, %r12
movq %rax, %rdi
callq 0x2f47c
movl $0x0, 0xc(%rsp)
movq %r14, %rdi
callq 0x2f5c2
testl %eax, %eax
je 0x23bc1
movq %r14, %rdi
leaq 0xc(%rsp), %rsi
callq 0x2f4ec
movq %rax, %rbx
testb %r15b, %r15b
je 0x23b68
movq %rbx, %rdi
callq 0x1496e
cmpb $0x0, (%rax)
je 0x23bab
movl $0x238, %edi            # imm = 0x238
callq 0x42d0
movq %rax, %r13
movq %rax, %rdi
callq 0x138dc
movq %r13, %rdi
movq %rbx, %rsi
callq 0x1474e
movq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0x23978
movq %r12, %rdi
movq %r13, %rsi
callq 0x2f49a
movq %rbp, %rdi
movq %r13, %rsi
callq 0x20422
movl 0xc(%rsp), %ebx
incl %ebx
movl %ebx, 0xc(%rsp)
movq %r14, %rdi
callq 0x2f5c2
cmpl %eax, %ebx
jb 0x23b46
movq %r12, %rdi
callq 0x2f5c2
testl %eax, %eax
je 0x23bec
movq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x23dc0
movq %rbp, %rdi
movq %r12, %rsi
callq 0x203e0
movq 0x40(%rsp), %r14
jmp 0x23c14
movq (%r12), %rdi
testq %rdi, %rdi
movq 0x40(%rsp), %r14
je 0x23c07
movq 0x10(%r12), %rsi
subq %rdi, %rsi
callq 0x42e0
movl $0x18, %esi
movq %r12, %rdi
callq 0x42e0
movl 0x20(%rsp), %ebx
incl %ebx
movl %ebx, 0x20(%rsp)
movq %r14, %rdi
callq 0x204e0
cmpl %eax, %ebx
jb 0x23b0d
movq %rbp, %rdi
callq 0x204e0
testl %eax, %eax
je 0x23c4c
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x23e06
jmp 0x23c88
movq 0x18(%rbp), %rdi
testq %rdi, %rdi
movq 0x10(%rsp), %rbx
je 0x23c66
movq 0x28(%rbp), %rsi
subq %rdi, %rsi
callq 0x42e0
movq (%rbp), %rdi
testq %rdi, %rdi
je 0x23c7b
movq 0x10(%rbp), %rsi
subq %rdi, %rsi
callq 0x42e0
movl $0x30, %esi
movq %rbp, %rdi
callq 0x42e0
movq 0x50(%rsp), %rsi
incq %rsi
movq 0x48(%rsp), %r13
movq 0x8(%r13), %rax
movq 0x10(%r13), %rcx
subq %rax, %rcx
movq %rcx, %rdx
shrq $0x3, %rdx
movl %edx, %edx
cmpq %rdx, %rsi
jb 0x23ac4
cmpb $0x0, 0x1c(%rsp)
jne 0x23cc3
movq (%r13), %rax
movq %r13, %rdi
callq *0x8(%rax)
movq %rbx, %rdi
callq 0x23e82
movb %al, 0xa8(%rbx)
movq %rbx, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x23ce5
movq %rax, %r14
movq 0x20(%rsp), %rdi
cmpq %r12, %rdi
je 0x23d33
movq 0x30(%rsp), %rsi
incq %rsi
jmp 0x23d2e
movq %rax, %r14
movl $0x1a0, %esi            # imm = 0x1A0
movq %rbx, %rdi
jmp 0x23d2e
movq %rax, %r14
movl $0x30, %esi
movq %rbp, %rdi
jmp 0x23d2e
movq %rax, %r14
movl $0x18, %esi
movq %r12, %rdi
jmp 0x23d2e
movq %rax, %r14
movl $0x238, %esi            # imm = 0x238
movq %r13, %rdi
callq 0x42e0
movq %r14, %rdi
callq 0x4550
nop