// File: atfrank[P]PCASA/lib/PDB.cpp
// Function: PDB::writePDBFormat(Molecule*, std::__cxx11::basic_ostringstream<char, std::char_traits<char>, std::allocator<char>>&, bool)
void PDB::writePDBFormat (Molecule* mol, std::ostringstream &out, bool selFlag){
  Chain *chn;
  Residue *res;
  Atom *atm;
  int natom=0;
  int catom=0;
  unsigned int i;

  out.clear();

  for (i=0; i< mol->getChnVecSize(); i++){
    chn=mol->getChain(i);
    catom=0;
    //if(!chn->getSel()){continue;}
    for (unsigned int j=0; j< chn->getResVecSize(); j++){
      res=chn->getResidue(j);
      //if(!res->getSel()){continue;}
      for (unsigned int k=0; k< res->getAtmVecSize(); k++){
        atm=res->getAtom(k);
        if (selFlag == true && atm->getSel() == false){
          continue;
        }
        if (atm->getAtmNum() <= 99999){
          out << std::setw(6) << std::left << atm->getRecName();
          out << std::setw(5) << std::right << atm->getAtmNum(); //PDB format
          out << " "; //PDB format
        }
        else{
          out << std::setw(5) << std::left << atm->getRecName();
          out << std::setw(6) << std::right << atm->getAtmNum();
          out << " ";
        }
        out << std::setw(4) << std::left << atm->getAtmName();
        out << std::setw(1) << std::left << atm->getAlt();
        if (atm->getResName().length() < 4){
          out << std::setw(3) << std::left << atm->getResName(); //PDB format
          out << " "; //PDB format
        }
        else{
          out << std::setw(4) << std::left << atm->getResName();
        }
        out << std::setw(1) << std::left << atm->getChainId();
        if (atm->getResId() <= 999){
          out << std::setw(4) << std::right << atm->getResId(); //PDB format
          out << std::setw(1) << std::left << atm->getICode(); //PDB format
          out << "   "; //PDB format
        }
//        else if (atm->getResId() <= 9999){
//          out << std::setw(5) << std::right << atm->getResId();
//          out << "   ";
//        }
        else if (atm->getResId() <= 99999){
          out << std::setw(5) << std::right << atm->getResId();
          out << "   ";
        }
        else{
          out << std::setw(6) << std::left << atm->getResId();
        }
        out << std::fixed; //For setting precision
        out << std::setw(8) << std::right << std::setprecision(3) << atm->getX();
        out << std::setw(8) << std::right << std::setprecision(3) << atm->getY();
        out << std::setw(8) << std::right << std::setprecision(3) << atm->getZ();
        out << std::setw(6) << std::right << std::setprecision(2) << atm->getOccu();
        out << std::setw(6) << std::right << std::setprecision(2) << atm->getBFac();
        out << "      ";
        out << std::setw(4) << std::left << atm->getSegId();
        out << " ";
        out << std::setw(1) << std::left << atm->getElem();
        out << std::endl;
        natom++;
        catom++;
      }
    }
    if (catom>0){
      out << "TER" << std::endl;
    }
  }

  if (natom > 0){
    out << "END" << std::endl;
  }

}

// Assembly:
subq $0x228, %rsp            # imm = 0x228
movb %dl, %al
movq %rdi, 0x220(%rsp)
movq %rsi, 0x218(%rsp)
andb $0x1, %al
movb %al, 0x217(%rsp)
movl $0x0, 0x1f4(%rsp)
movl $0x0, 0x1f0(%rsp)
movq 0x218(%rsp), %rdi
movq (%rdi), %rax
addq -0x18(%rax), %rdi
xorl %esi, %esi
callq 0x56d0
movl $0x0, 0x1ec(%rsp)
movl 0x1ec(%rsp), %eax
movl %eax, 0x17c(%rsp)
movq 0x220(%rsp), %rdi
callq 0x41e20
movl %eax, %ecx
movl 0x17c(%rsp), %eax
cmpl %ecx, %eax
jae 0x53c4a
movq 0x220(%rsp), %rdi
leaq 0x1ec(%rsp), %rsi
callq 0x41e40
movq %rax, 0x208(%rsp)
movl $0x0, 0x1f0(%rsp)
movl $0x0, 0x1e8(%rsp)
movl 0x1e8(%rsp), %eax
movl %eax, 0x178(%rsp)
movq 0x208(%rsp), %rdi
callq 0x3a570
movl %eax, %ecx
movl 0x178(%rsp), %eax
cmpl %ecx, %eax
jae 0x53c05
movq 0x208(%rsp), %rdi
leaq 0x1e8(%rsp), %rsi
callq 0x3a490
movq %rax, 0x200(%rsp)
movl $0x0, 0x1e4(%rsp)
movl 0x1e4(%rsp), %eax
movl %eax, 0x174(%rsp)
movq 0x200(%rsp), %rdi
callq 0x5e110
movl %eax, %ecx
movl 0x174(%rsp), %eax
cmpl %ecx, %eax
jae 0x53bed
movq 0x200(%rsp), %rdi
leaq 0x1e4(%rsp), %rsi
callq 0x5df30
movq %rax, 0x1f8(%rsp)
movb 0x217(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x531d4
movq 0x1f8(%rsp), %rdi
callq 0x1f780
movb (%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x531d4
jmp 0x53bd7
movq 0x1f8(%rsp), %rdi
callq 0x1f5b0
cmpl $0x1869f, (%rax)        # imm = 0x1869F
jg 0x532d7
movq 0x218(%rsp), %rax
movq %rax, 0x150(%rsp)
movl $0x6, %edi
callq 0x16ec0
movq 0x150(%rsp), %rdi
movl %eax, 0x1e0(%rsp)
movl 0x1e0(%rsp), %esi
callq 0x54e0
movq %rax, %rdi
leaq 0x39c4(%rip), %rsi      # 0x56bf0
callq 0x5160
movq %rax, 0x158(%rsp)
movq 0x1f8(%rsp), %rdi
callq 0x1f5a0
movq 0x158(%rsp), %rdi
movq %rax, %rsi
callq 0x5390
movq 0x218(%rsp), %rax
movq %rax, 0x160(%rsp)
movl $0x5, %edi
callq 0x16ec0
movq 0x160(%rsp), %rdi
movl %eax, 0x1dc(%rsp)
movl 0x1dc(%rsp), %esi
callq 0x54e0
movq %rax, %rdi
leaq -0x3c3b5(%rip), %rsi    # 0x16ee0
callq 0x5160
movq %rax, 0x168(%rsp)
movq 0x1f8(%rsp), %rdi
callq 0x1f5b0
movq 0x168(%rsp), %rdi
movl (%rax), %esi
callq 0x56f0
movq 0x218(%rsp), %rdi
leaq 0x292cb(%rip), %rsi     # 0x7c598
callq 0x53f0
jmp 0x533bc
movq 0x218(%rsp), %rax
movq %rax, 0x130(%rsp)
movl $0x5, %edi
callq 0x16ec0
movq 0x130(%rsp), %rdi
movl %eax, 0x1d8(%rsp)
movl 0x1d8(%rsp), %esi
callq 0x54e0
movq %rax, %rdi
leaq 0x38da(%rip), %rsi      # 0x56bf0
callq 0x5160
movq %rax, 0x138(%rsp)
movq 0x1f8(%rsp), %rdi
callq 0x1f5a0
movq 0x138(%rsp), %rdi
movq %rax, %rsi
callq 0x5390
movq 0x218(%rsp), %rax
movq %rax, 0x140(%rsp)
movl $0x6, %edi
callq 0x16ec0
movq 0x140(%rsp), %rdi
movl %eax, 0x1d4(%rsp)
movl 0x1d4(%rsp), %esi
callq 0x54e0
movq %rax, %rdi
leaq -0x3c49f(%rip), %rsi    # 0x16ee0
callq 0x5160
movq %rax, 0x148(%rsp)
movq 0x1f8(%rsp), %rdi
callq 0x1f5b0
movq 0x148(%rsp), %rdi
movl (%rax), %esi
callq 0x56f0
movq 0x218(%rsp), %rdi
leaq 0x291e1(%rip), %rsi     # 0x7c598
callq 0x53f0
movq 0x218(%rsp), %rax
movq %rax, 0x110(%rsp)
movl $0x4, %edi
callq 0x16ec0
movq 0x110(%rsp), %rdi
movl %eax, 0x1d0(%rsp)
movl 0x1d0(%rsp), %esi
callq 0x54e0
movq %rax, %rdi
leaq 0x37f5(%rip), %rsi      # 0x56bf0
callq 0x5160
movq %rax, 0x118(%rsp)
movq 0x1f8(%rsp), %rdi
callq 0x1f5c0
movq 0x118(%rsp), %rdi
movq %rax, %rsi
callq 0x5390
movq 0x218(%rsp), %rax
movq %rax, 0x120(%rsp)
movl $0x1, %edi
callq 0x16ec0
movq 0x120(%rsp), %rdi
movl %eax, 0x1cc(%rsp)
movl 0x1cc(%rsp), %esi
callq 0x54e0
movq %rax, %rdi
leaq 0x378c(%rip), %rsi      # 0x56bf0
callq 0x5160
movq %rax, 0x128(%rsp)
movq 0x1f8(%rsp), %rdi
callq 0x1f5e0
movq 0x128(%rsp), %rdi
movq %rax, %rsi
callq 0x5390
movq 0x1f8(%rsp), %rdi
callq 0x1f620
movq %rax, %rdi
callq 0x5630
cmpq $0x4, %rax
jae 0x53528
movq 0x218(%rsp), %rax
movq %rax, 0x100(%rsp)
movl $0x3, %edi
callq 0x16ec0
movq 0x100(%rsp), %rdi
movl %eax, 0x1c8(%rsp)
movl 0x1c8(%rsp), %esi
callq 0x54e0
movq %rax, %rdi
leaq 0x3708(%rip), %rsi      # 0x56bf0
callq 0x5160
movq %rax, 0x108(%rsp)
movq 0x1f8(%rsp), %rdi
callq 0x1f620
movq 0x108(%rsp), %rdi
movq %rax, %rsi
callq 0x5390
movq 0x218(%rsp), %rdi
leaq 0x29077(%rip), %rsi     # 0x7c598
callq 0x53f0
jmp 0x53591
movq 0x218(%rsp), %rax
movq %rax, 0xf0(%rsp)
movl $0x4, %edi
callq 0x16ec0
movq 0xf0(%rsp), %rdi
movl %eax, 0x1c4(%rsp)
movl 0x1c4(%rsp), %esi
callq 0x54e0
movq %rax, %rdi
leaq 0x3689(%rip), %rsi      # 0x56bf0
callq 0x5160
movq %rax, 0xf8(%rsp)
movq 0x1f8(%rsp), %rdi
callq 0x1f620
movq 0xf8(%rsp), %rdi
movq %rax, %rsi
callq 0x5390
movq 0x218(%rsp), %rax
movq %rax, 0xe0(%rsp)
movl $0x1, %edi
callq 0x16ec0
movq 0xe0(%rsp), %rdi
movl %eax, 0x1c0(%rsp)
movl 0x1c0(%rsp), %esi
callq 0x54e0
movq %rax, %rdi
leaq 0x3620(%rip), %rsi      # 0x56bf0
callq 0x5160
movq %rax, 0xe8(%rsp)
movq 0x1f8(%rsp), %rdi
callq 0x1f660
movq 0xe8(%rsp), %rdi
movq %rax, %rsi
callq 0x5390
movq 0x1f8(%rsp), %rdi
callq 0x1f6a0
cmpl $0x3e7, (%rax)          # imm = 0x3E7
jg 0x536fd
movq 0x218(%rsp), %rax
movq %rax, 0xc0(%rsp)
movl $0x4, %edi
callq 0x16ec0
movq 0xc0(%rsp), %rdi
movl %eax, 0x1bc(%rsp)
movl 0x1bc(%rsp), %esi
callq 0x54e0
movq %rax, %rdi
leaq -0x3c772(%rip), %rsi    # 0x16ee0
callq 0x5160
movq %rax, 0xc8(%rsp)
movq 0x1f8(%rsp), %rdi
callq 0x1f6a0
movq 0xc8(%rsp), %rdi
movl (%rax), %esi
callq 0x56f0
movq 0x218(%rsp), %rax
movq %rax, 0xd0(%rsp)
movl $0x1, %edi
callq 0x16ec0
movq 0xd0(%rsp), %rdi
movl %eax, 0x1b8(%rsp)
movl 0x1b8(%rsp), %esi
callq 0x54e0
movq %rax, %rdi
leaq 0x3536(%rip), %rsi      # 0x56bf0
callq 0x5160
movq %rax, 0xd8(%rsp)
movq 0x1f8(%rsp), %rdi
callq 0x1f6c0
movq 0xd8(%rsp), %rdi
movq %rax, %rsi
callq 0x5390
movq 0x218(%rsp), %rdi
leaq 0x28ea3(%rip), %rsi     # 0x7c596
callq 0x53f0
jmp 0x537fa
movq 0x1f8(%rsp), %rdi
callq 0x1f6a0
cmpl $0x1869f, (%rax)        # imm = 0x1869F
jg 0x53790
movq 0x218(%rsp), %rax
movq %rax, 0xb0(%rsp)
movl $0x5, %edi
callq 0x16ec0
movq 0xb0(%rsp), %rdi
movl %eax, 0x1b4(%rsp)
movl 0x1b4(%rsp), %esi
callq 0x54e0
movq %rax, %rdi
leaq -0x3c871(%rip), %rsi    # 0x16ee0
callq 0x5160
movq %rax, 0xb8(%rsp)
movq 0x1f8(%rsp), %rdi
callq 0x1f6a0
movq 0xb8(%rsp), %rdi
movl (%rax), %esi
callq 0x56f0
movq 0x218(%rsp), %rdi
leaq 0x28e0d(%rip), %rsi     # 0x7c596
callq 0x53f0
jmp 0x537f8
movq 0x218(%rsp), %rax
movq %rax, 0xa0(%rsp)
movl $0x6, %edi
callq 0x16ec0
movq 0xa0(%rsp), %rdi
movl %eax, 0x1b0(%rsp)
movl 0x1b0(%rsp), %esi
callq 0x54e0
movq %rax, %rdi
leaq 0x3421(%rip), %rsi      # 0x56bf0
callq 0x5160
movq %rax, 0xa8(%rsp)
movq 0x1f8(%rsp), %rdi
callq 0x1f6a0
movq 0xa8(%rsp), %rdi
movl (%rax), %esi
callq 0x56f0
jmp 0x537fa
movq 0x218(%rsp), %rdi
leaq -0x3c969(%rip), %rsi    # 0x16ea0
callq 0x5160
movq 0x218(%rsp), %rax
movq %rax, 0x8(%rsp)
movl $0x8, %edi
callq 0x16ec0
movq 0x8(%rsp), %rdi
movl %eax, 0x1ac(%rsp)
movl 0x1ac(%rsp), %esi
callq 0x54e0
movq %rax, %rdi
leaq -0x3c967(%rip), %rsi    # 0x16ee0
callq 0x5160
movq %rax, 0x10(%rsp)
movl $0x3, %edi
callq 0x16f00
movq 0x10(%rsp), %rdi
movl %eax, 0x1a8(%rsp)
movl 0x1a8(%rsp), %esi
callq 0x5660
movq %rax, 0x18(%rsp)
movq 0x1f8(%rsp), %rdi
callq 0x1fa60
movq 0x18(%rsp), %rdi
movsd (%rax), %xmm0
callq 0x5780
movq 0x218(%rsp), %rax
movq %rax, 0x20(%rsp)
movl $0x8, %edi
callq 0x16ec0
movq 0x20(%rsp), %rdi
movl %eax, 0x1a4(%rsp)
movl 0x1a4(%rsp), %esi
callq 0x54e0
movq %rax, %rdi
leaq -0x3c9ec(%rip), %rsi    # 0x16ee0
callq 0x5160
movq %rax, 0x28(%rsp)
movl $0x3, %edi
callq 0x16f00
movq 0x28(%rsp), %rdi
movl %eax, 0x1a0(%rsp)
movl 0x1a0(%rsp), %esi
callq 0x5660
movq %rax, 0x30(%rsp)
movq 0x1f8(%rsp), %rdi
callq 0x1fa80
movq 0x30(%rsp), %rdi
movsd (%rax), %xmm0
callq 0x5780
movq 0x218(%rsp), %rax
movq %rax, 0x38(%rsp)
movl $0x8, %edi
callq 0x16ec0
movq 0x38(%rsp), %rdi
movl %eax, 0x19c(%rsp)
movl 0x19c(%rsp), %esi
callq 0x54e0
movq %rax, %rdi
leaq -0x3ca71(%rip), %rsi    # 0x16ee0
callq 0x5160
movq %rax, 0x40(%rsp)
movl $0x3, %edi
callq 0x16f00
movq 0x40(%rsp), %rdi
movl %eax, 0x198(%rsp)
movl 0x198(%rsp), %esi
callq 0x5660
movq %rax, 0x48(%rsp)
movq 0x1f8(%rsp), %rdi
callq 0x1faa0
movq 0x48(%rsp), %rdi
movsd (%rax), %xmm0
callq 0x5780
movq 0x218(%rsp), %rax
movq %rax, 0x50(%rsp)
movl $0x6, %edi
callq 0x16ec0
movq 0x50(%rsp), %rdi
movl %eax, 0x194(%rsp)
movl 0x194(%rsp), %esi
callq 0x54e0
movq %rax, %rdi
leaq -0x3caf6(%rip), %rsi    # 0x16ee0
callq 0x5160
movq %rax, 0x58(%rsp)
movl $0x2, %edi
callq 0x16f00
movq 0x58(%rsp), %rdi
movl %eax, 0x190(%rsp)
movl 0x190(%rsp), %esi
callq 0x5660
movq %rax, 0x60(%rsp)
movq 0x1f8(%rsp), %rdi
callq 0x1f700
movq 0x60(%rsp), %rdi
movsd (%rax), %xmm0
callq 0x5780
movq 0x218(%rsp), %rax
movq %rax, 0x68(%rsp)
movl $0x6, %edi
callq 0x16ec0
movq 0x68(%rsp), %rdi
movl %eax, 0x18c(%rsp)
movl 0x18c(%rsp), %esi
callq 0x54e0
movq %rax, %rdi
leaq -0x3cb7b(%rip), %rsi    # 0x16ee0
callq 0x5160
movq %rax, 0x70(%rsp)
movl $0x2, %edi
callq 0x16f00
movq 0x70(%rsp), %rdi
movl %eax, 0x188(%rsp)
movl 0x188(%rsp), %esi
callq 0x5660
movq %rax, 0x78(%rsp)
movq 0x1f8(%rsp), %rdi
callq 0x1f720
movq 0x78(%rsp), %rdi
movsd (%rax), %xmm0
callq 0x5780
movq 0x218(%rsp), %rdi
leaq 0x28add(%rip), %rsi     # 0x7c593
callq 0x53f0
movq 0x218(%rsp), %rax
movq %rax, 0x80(%rsp)
movl $0x4, %edi
callq 0x16ec0
movq 0x80(%rsp), %rdi
movl %eax, 0x184(%rsp)
movl 0x184(%rsp), %esi
callq 0x54e0
movq %rax, %rdi
leaq 0x30f6(%rip), %rsi      # 0x56bf0
callq 0x5160
movq %rax, 0x88(%rsp)
movq 0x1f8(%rsp), %rdi
callq 0x1f760
movq 0x88(%rsp), %rdi
movq %rax, %rsi
callq 0x5390
movq 0x218(%rsp), %rdi
leaq 0x28a65(%rip), %rsi     # 0x7c598
callq 0x53f0
movq 0x218(%rsp), %rax
movq %rax, 0x90(%rsp)
movl $0x1, %edi
callq 0x16ec0
movq 0x90(%rsp), %rdi
movl %eax, 0x180(%rsp)
movl 0x180(%rsp), %esi
callq 0x54e0
movq %rax, %rdi
leaq 0x3079(%rip), %rsi      # 0x56bf0
callq 0x5160
movq %rax, 0x98(%rsp)
movq 0x1f8(%rsp), %rdi
callq 0x1f740
movq 0x98(%rsp), %rdi
movq %rax, %rsi
callq 0x5390
movq 0x218(%rsp), %rdi
movq 0x3e73f8(%rip), %rsi    # 0x43afa8
callq 0x5460
movl 0x1f4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1f4(%rsp)
movl 0x1f0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1f0(%rsp)
movl 0x1e4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1e4(%rsp)
jmp 0x5315c
jmp 0x53bef
movl 0x1e8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1e8(%rsp)
jmp 0x53108
cmpl $0x0, 0x1f0(%rsp)
jle 0x53c32
movq 0x218(%rsp), %rdi
leaq 0x2919d(%rip), %rsi     # 0x7cdbb
callq 0x53f0
movq %rax, %rdi
movq 0x3e737b(%rip), %rsi    # 0x43afa8
callq 0x5460
jmp 0x53c34
movl 0x1ec(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1ec(%rsp)
jmp 0x530a9
cmpl $0x0, 0x1f4(%rsp)
jle 0x53c77
movq 0x218(%rsp), %rdi
leaq 0x28937(%rip), %rsi     # 0x7c59a
callq 0x53f0
movq %rax, %rdi
movq 0x3e7336(%rip), %rsi    # 0x43afa8
callq 0x5460
addq $0x228, %rsp            # imm = 0x228
retq
nop