// File: atfrank[P]PCASA/lib/Select.cpp
// Function: Select::makeSel(Molecule*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool, bool)
void Select::makeSel (Molecule* mol, std::string selin, bool dieFlag, bool verbose){

  std::vector<Atom *> ref;
  unsigned int i;

  //Convert selection to uppercase
  selin=Misc::toupper(selin);

  //Initialize special selection keys
  Select *sel=new Select;
  sel->initKeys(mol);

  ref=mol->getAtmVecClone(); //Always make a clone of the pointers and sort it!
  std::sort(ref.begin(), ref.end());

  //Passing mol->getAtmVec() directly won't work
  //because it is not properly sorted!
  if (selin.find(":") == std::string::npos || selin.find(".") == std::string::npos){
    std::cerr << std::endl << "Warning: Each selection expression should contain ";
    std::cerr << "both a \":\" and a \".\" in order to be parsed correctly!" << std::endl;
  }
  std::vector<Atom *> atmSel=sel->recursiveDescentParser(selin, ref);

  if (atmSel.size() == 0){
    if (verbose == true){
      std::cerr << std::endl << "Error: Selection \"";
      std::cerr << selin << "\" did not match any atoms";
      if (mol->getTag().length() > 0){
        std::cerr << " in tag " << mol->getTag();
      }
      std::cerr << std::endl << std::endl;
    }
    if (dieFlag == true){
      exit(1);
    }
  }

  mol->deselAll();
  for (i=0; i< atmSel.size(); i++){
    atmSel.at(i)->setSel(true);
  }

  delete sel;
}

// Assembly:
subq $0x1a8, %rsp            # imm = 0x1A8
movq %rsi, 0x88(%rsp)
movb %cl, %al
movb %dl, %cl
movq %rdi, 0x1a0(%rsp)
movq %rsi, 0x198(%rsp)
andb $0x1, %cl
movb %cl, 0x197(%rsp)
andb $0x1, %al
movb %al, 0x196(%rsp)
leaq 0x178(%rsp), %rdi
callq 0x202a0
movq 0x88(%rsp), %rsi
leaq 0x150(%rsp), %rdi
callq 0x3e230
jmp 0x5f7ea
movq 0x88(%rsp), %rdi
leaq 0x150(%rsp), %rsi
movq %rsi, 0x78(%rsp)
callq 0x5510
movq 0x78(%rsp), %rdi
callq 0x5250
movl $0x60, %edi
callq 0x5410
movq %rax, 0x80(%rsp)
jmp 0x5f822
movq 0x80(%rsp), %rdi
callq 0x6bc20
movq 0x80(%rsp), %rax
movq %rax, 0x138(%rsp)
movq 0x138(%rsp), %rdi
movq 0x1a0(%rsp), %rsi
callq 0x5fd00
jmp 0x5f856
movq 0x1a0(%rsp), %rsi
leaq 0x120(%rsp), %rdi
callq 0x437d0
jmp 0x5f86d
leaq 0x178(%rsp), %rdi
movq %rdi, 0x70(%rsp)
leaq 0x120(%rsp), %rsi
movq %rsi, 0x68(%rsp)
callq 0x6bc50
movq 0x68(%rsp), %rdi
callq 0x202e0
movq 0x70(%rsp), %rdi
callq 0x17530
movq 0x70(%rsp), %rdi
movq %rax, 0x118(%rsp)
callq 0x175a0
movq %rax, 0x110(%rsp)
movq 0x118(%rsp), %rdi
movq 0x110(%rsp), %rsi
callq 0x6bc90
jmp 0x5f8d1
movq 0x88(%rsp), %rdi
leaq 0x1b947(%rip), %rsi     # 0x7b227
xorl %eax, %eax
movl %eax, %edx
callq 0x57d0
cmpq $-0x1, %rax
je 0x5f90d
movq 0x88(%rsp), %rdi
leaq 0x1ce58(%rip), %rsi     # 0x7c756
xorl %eax, %eax
movl %eax, %edx
callq 0x57d0
cmpq $-0x1, %rax
jne 0x5f982
movq 0x3db6dc(%rip), %rdi    # 0x43aff0
movq 0x3db68d(%rip), %rsi    # 0x43afa8
callq 0x5460
movq %rax, 0x60(%rsp)
jmp 0x5f927
movq 0x60(%rsp), %rdi
leaq 0x1ce2d(%rip), %rsi     # 0x7c760
callq 0x53f0
jmp 0x5f93a
movq 0x3db6af(%rip), %rdi    # 0x43aff0
leaq 0x1ce4b(%rip), %rsi     # 0x7c793
callq 0x53f0
movq %rax, 0x58(%rsp)
jmp 0x5f954
movq 0x58(%rsp), %rdi
movq 0x3db648(%rip), %rsi    # 0x43afa8
callq 0x5460
jmp 0x5f967
jmp 0x5f982
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x148(%rsp)
movl %eax, 0x144(%rsp)
jmp 0x5fcda
movq 0x138(%rsp), %rax
movq %rax, 0x48(%rsp)
leaq 0xd7(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0x5730
movq 0x50(%rsp), %rdx
leaq 0x1ba05(%rip), %rsi     # 0x7b3b2
leaq 0xd8(%rsp), %rdi
callq 0x7900
jmp 0x5f9bc
movq 0x88(%rsp), %rdx
movq 0x48(%rsp), %rsi
leaq 0xf8(%rsp), %rdi
leaq 0x178(%rsp), %rcx
leaq 0xd8(%rsp), %r8
callq 0x68110
jmp 0x5f9e8
leaq 0xd8(%rsp), %rdi
callq 0x5250
leaq 0xd7(%rsp), %rdi
callq 0x5480
leaq 0xf8(%rsp), %rdi
callq 0x20600
cmpq $0x0, %rax
jne 0x5fbf9
movb 0x196(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x5fbdc
movq 0x3db5bb(%rip), %rdi    # 0x43aff0
movq 0x3db56c(%rip), %rsi    # 0x43afa8
callq 0x5460
movq %rax, 0x40(%rsp)
jmp 0x5fa48
movq 0x40(%rsp), %rdi
leaq 0x1cd75(%rip), %rsi     # 0x7c7c9
callq 0x53f0
jmp 0x5fa5b
movq 0x88(%rsp), %rsi
movq 0x3db586(%rip), %rdi    # 0x43aff0
callq 0x5390
movq %rax, 0x38(%rsp)
jmp 0x5fa76
movq 0x38(%rsp), %rdi
leaq 0x1cd5a(%rip), %rsi     # 0x7c7dc
callq 0x53f0
jmp 0x5fa89
movq 0x1a0(%rsp), %rsi
leaq 0xb0(%rsp), %rdi
callq 0x429a0
jmp 0x5faa0
leaq 0xb0(%rsp), %rdi
callq 0x5630
movq %rax, 0x30(%rsp)
leaq 0xb0(%rsp), %rdi
callq 0x5250
movq 0x30(%rsp), %rax
cmpq $0x0, %rax
jbe 0x5fbad
movq 0x3db51b(%rip), %rdi    # 0x43aff0
leaq 0x1cd1a(%rip), %rsi     # 0x7c7f6
callq 0x53f0
movq %rax, 0x28(%rsp)
jmp 0x5fae8
movq 0x1a0(%rsp), %rsi
leaq 0x90(%rsp), %rdi
callq 0x429a0
jmp 0x5faff
movq 0x28(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x5390
jmp 0x5fb13
leaq 0x90(%rsp), %rdi
callq 0x5250
jmp 0x5fbad
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x148(%rsp)
movl %eax, 0x144(%rsp)
jmp 0x5fb5c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x148(%rsp)
movl %eax, 0x144(%rsp)
leaq 0xd8(%rsp), %rdi
callq 0x5250
leaq 0xd7(%rsp), %rdi
callq 0x5480
jmp 0x5fcda
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x148(%rsp)
movl %eax, 0x144(%rsp)
jmp 0x5fccd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x148(%rsp)
movl %eax, 0x144(%rsp)
leaq 0x90(%rsp), %rdi
callq 0x5250
jmp 0x5fccd
movq 0x3db43c(%rip), %rdi    # 0x43aff0
movq 0x3db3ed(%rip), %rsi    # 0x43afa8
callq 0x5460
movq %rax, 0x20(%rsp)
jmp 0x5fbc7
movq 0x20(%rsp), %rdi
movq 0x3db3d5(%rip), %rsi    # 0x43afa8
callq 0x5460
jmp 0x5fbda
jmp 0x5fbdc
movb 0x197(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x5fbf7
movl $0x1, %edi
callq 0x5500
jmp 0x5fbf9
movq 0x1a0(%rsp), %rdi
callq 0x44aa0
jmp 0x5fc08
movl $0x0, 0x174(%rsp)
movl 0x174(%rsp), %eax
movq %rax, 0x18(%rsp)
leaq 0xf8(%rsp), %rdi
callq 0x20600
movq %rax, %rcx
movq 0x18(%rsp), %rax
cmpq %rcx, %rax
jae 0x5fc7f
movl 0x174(%rsp), %eax
movl %eax, %esi
leaq 0xf8(%rsp), %rdi
callq 0x20620
movq %rax, 0x10(%rsp)
jmp 0x5fc56
movq 0x10(%rsp), %rax
movq (%rax), %rdi
movl $0x1, %esi
callq 0x200f0
jmp 0x5fc6a
jmp 0x5fc6c
movl 0x174(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x174(%rsp)
jmp 0x5fc13
movq 0x138(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x5fcab
movq 0x8(%rsp), %rdi
callq 0x6bcd0
movq 0x8(%rsp), %rdi
movl $0x60, %esi
callq 0x5420
leaq 0xf8(%rsp), %rdi
callq 0x202e0
leaq 0x178(%rsp), %rdi
callq 0x202e0
addq $0x1a8, %rsp            # imm = 0x1A8
retq
leaq 0xf8(%rsp), %rdi
callq 0x202e0
leaq 0x178(%rsp), %rdi
callq 0x202e0
movq 0x148(%rsp), %rdi
callq 0x5720
nopw %cs:(%rax,%rax)