// File: /workspace/github_cpp_makefile_star2_O2/atfrank[P]PCASA/lib/Molecule.cpp
// Function: Molecule::cat(Molecule*, bool, bool)
void Molecule::cat (Molecule* catmol, bool selFlag, bool keep){
  //Deep copy
  Chain *c, *chnEntry;
  Residue *r, *resEntry;
  Atom *a, *atmEntry;

  c=NULL;
  r=NULL;
  a=NULL;
  chnEntry=NULL;
  resEntry=NULL;
  atmEntry=NULL;
  this->setCopyFlag(false); //Not a copy
  this->setYear(catmol->getYear());
  this->setExp(catmol->getExp());
  this->setTag(catmol->getTag());

  for (unsigned int i=0; i< catmol->getChnVecSize(); i++){
    c=catmol->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
        this->addAtom(atmEntry);
        resEntry->addAtom(atmEntry);
        chnEntry->addAtom(atmEntry);
      }
      if (resEntry->getAtmVecSize() > 0){
        //Add each residue with selected atoms
        this->addResidue(resEntry);
        chnEntry->addResidue(resEntry);
      }
      else{
        delete resEntry;
      }
    }
    if (chnEntry->getResVecSize() > 0){
      //Add each chain with selected atoms
      this->addChain(chnEntry);
    }
    else{
      delete chnEntry;
    }
  }

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

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %ecx, 0x10(%rsp)
movl %edx, 0x14(%rsp)
movq %rsi, %r12
movq %rdi, %r14
movb $0x0, 0x50(%rdi)
movl 0x158(%rsi), %eax
movl %eax, 0x158(%rdi)
movl $0x160, %ebx            # imm = 0x160
addq %rbx, %rsi
leaq 0x28(%rsp), %r15
movq %r15, %rdi
callq 0x4430
addq %r14, %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x41a0
leaq 0x28(%rsp), %rdi
callq 0x4170
movl $0x180, %ebx            # imm = 0x180
leaq (%r12,%rbx), %rsi
leaq 0x28(%rsp), %r15
movq %r15, %rdi
callq 0x4430
addq %r14, %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x41a0
leaq 0x28(%rsp), %rdi
callq 0x4170
xorl %ecx, %ecx
movq %r12, 0x18(%rsp)
movl %ecx, 0x28(%rsp)
movq 0x10(%r12), %rax
subq 0x8(%r12), %rax
shrq $0x3, %rax
cmpl %eax, %ecx
jae 0x1ab07
movl %ecx, 0x4(%rsp)
movq %r12, %rdi
leaq 0x28(%rsp), %rsi
callq 0x19fb0
movq %rax, %r15
pushq $0x30
popq %rdi
callq 0x4320
movq %rax, %rbx
movq %rax, %rdi
callq 0x17750
xorl %ebp, %ebp
movq %r15, 0x20(%rsp)
movl %ebp, 0xc(%rsp)
movq %r15, %rdi
callq 0x1786c
cmpl %eax, %ebp
jae 0x1aacb
movq %r15, %rdi
leaq 0xc(%rsp), %rsi
callq 0x17802
movq %rax, %rbp
pushq $0x18
popq %rdi
callq 0x4320
movq %rax, %r12
movq %rax, %rdi
callq 0x23990
xorl %r15d, %r15d
movl %r15d, 0x8(%rsp)
movq %rbp, %rdi
callq 0x23aee
cmpl %eax, %r15d
jae 0x1aa84
movq %rbp, %rdi
leaq 0x8(%rsp), %rsi
callq 0x239f2
movq %rax, %r15
cmpb $0x0, 0x14(%rsp)
je 0x1aa36
movq %r15, %rdi
callq 0xea64
cmpb $0x0, (%rax)
je 0x1aa77
movl $0x238, %edi            # imm = 0x238
callq 0x4320
movq %rax, %r13
movq %rax, %rdi
callq 0xdee4
movq %r13, %rdi
movq %r15, %rsi
callq 0xe844
movq %r14, %rdi
movq %r13, %rsi
callq 0x1a23a
movq %r12, %rdi
movq %r13, %rsi
callq 0x239aa
movq %rbx, %rdi
movq %r13, %rsi
callq 0x177a8
movl 0x8(%rsp), %r15d
incl %r15d
jmp 0x1aa00
movq %r12, %rdi
callq 0x23aee
testl %eax, %eax
je 0x1aaa8
movq %r14, %rdi
movq %r12, %rsi
callq 0x1a572
movq %rbx, %rdi
movq %r12, %rsi
callq 0x1777c
jmp 0x1aabb
movq %r12, %rdi
callq 0xf036
movq %r12, %rdi
pushq $0x18
popq %rsi
callq 0x4330
movq 0x20(%rsp), %r15
movl 0xc(%rsp), %ebp
incl %ebp
jmp 0x1a9c6
movq %rbx, %rdi
callq 0x1786c
testl %eax, %eax
je 0x1aae4
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1a5a2
jmp 0x1aaf7
movq %rbx, %rdi
callq 0x1cb16
movq %rbx, %rdi
pushq $0x30
popq %rsi
callq 0x4330
movq 0x18(%rsp), %r12
movl 0x4(%rsp), %ecx
incl %ecx
jmp 0x1a97e
cmpb $0x0, 0x10(%rsp)
jne 0x1ab18
movq (%r12), %rax
movq %r12, %rdi
callq *0x8(%rax)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1ab29
movq %rax, %r14
leaq 0x28(%rsp), %rdi
callq 0x4170
jmp 0x1ab5e
movq %rax, %r14
pushq $0x30
popq %rsi
movq %rbx, %rdi
jmp 0x1ab59
movq %rax, %r14
pushq $0x18
popq %rsi
movq %r12, %rdi
jmp 0x1ab59
movq %rax, %r14
movl $0x238, %esi            # imm = 0x238
movq %r13, %rdi
callq 0x4330
movq %r14, %rdi
callq 0x4560