// File: /workspace/github_cpp_makefile_star2_O1/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %edx, 0x18(%rsp)
movq %rsi, %rbx
movq %rdi, %r12
movq (%rsi), %rax
movq -0x18(%rax), %rdi
addq %rsi, %rdi
xorl %esi, %esi
callq 0x44f0
movl $0x0, 0x10(%rsp)
movq %r12, %rdi
callq 0x237a6
testl %eax, %eax
je 0x2a568
movl $0x0, 0x14(%rsp)
movl $0xffffff4f, %r15d      # imm = 0xFFFFFF4F
movq %r12, 0x20(%rsp)
movq %r12, %rdi
leaq 0x10(%rsp), %rsi
callq 0x237b4
movq %rax, %r13
movl $0x0, 0xc(%rsp)
movq %rax, %rdi
callq 0x20664
xorl %ebp, %ebp
testl %eax, %eax
je 0x2a4c8
movq %r13, 0x28(%rsp)
movq %r13, %rdi
leaq 0xc(%rsp), %rsi
callq 0x2060a
movq %rax, %r14
movl $0x0, 0x8(%rsp)
movq %rax, %rdi
callq 0x2f884
testl %eax, %eax
movq %r14, 0x30(%rsp)
je 0x2a49a
movq %r14, %rdi
leaq 0x8(%rsp), %rsi
callq 0x2f7ae
movq %rax, %r13
cmpb $0x0, 0x18(%rsp)
je 0x29f72
movq %r13, %rdi
callq 0x14ae6
cmpb $0x0, (%rax)
je 0x2a47c
movq %r13, %rdi
callq 0x14a6c
xorl %ecx, %ecx
cmpl $0x186a0, (%rax)        # imm = 0x186A0
setl %cl
movq (%rbx), %rax
movq -0x18(%rax), %rdx
movl $0x6, %r12d
subq %rcx, %r12
addq $0x5, %rcx
movq %rcx, 0x10(%rbx,%rdx)
movq -0x18(%rax), %rax
movl 0x18(%rbx,%rax), %ecx
andl %r15d, %ecx
orl $0x20, %ecx
movl %ecx, 0x18(%rbx,%rax)
movq %r13, %rdi
callq 0x14a66
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq %rbx, %rdi
callq 0x4340
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movq %r12, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rax
movl 0x18(%rbx,%rax), %ecx
andl %r15d, %ecx
orl $0x80, %ecx
movl %ecx, 0x18(%rbx,%rax)
movq %r13, %rdi
callq 0x14a6c
movl (%rax), %esi
movq %rbx, %rdi
callq 0x4500
movl $0x1, %edx
movq %rbx, %rdi
leaq 0x13697(%rip), %r12     # 0x3d6a0
movq %r12, %rsi
callq 0x4340
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movq $0x4, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rax
movl 0x18(%rbx,%rax), %ecx
andl %r15d, %ecx
orl $0x20, %ecx
movl %ecx, 0x18(%rbx,%rax)
movq %r13, %rdi
callq 0x14a72
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq %rbx, %rdi
callq 0x4340
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movq $0x1, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rax
movl 0x18(%rbx,%rax), %ecx
andl %r15d, %ecx
orl $0x20, %ecx
movl %ecx, 0x18(%rbx,%rax)
movq %r13, %rdi
callq 0x14a7e
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq %rbx, %rdi
callq 0x4340
movq %r13, %rdi
callq 0x14a8e
cmpq $0x3, 0x8(%rax)
movq (%rbx), %rax
movq -0x18(%rax), %rcx
ja 0x2a0d8
movq $0x3, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rax
movl 0x18(%rbx,%rax), %ecx
andl %r15d, %ecx
orl $0x20, %ecx
movl %ecx, 0x18(%rbx,%rax)
movq %r13, %rdi
callq 0x14a8e
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq %rbx, %rdi
callq 0x4340
movl $0x1, %edx
movq %rbx, %rdi
movq %r12, %rsi
jmp 0x2a105
movq $0x4, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rax
movl 0x18(%rbx,%rax), %ecx
andl %r15d, %ecx
orl $0x20, %ecx
movl %ecx, 0x18(%rbx,%rax)
movq %r13, %rdi
callq 0x14a8e
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq %rbx, %rdi
callq 0x4340
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movq $0x1, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rax
movl 0x18(%rbx,%rax), %ecx
andl %r15d, %ecx
orl $0x20, %ecx
movl %ecx, 0x18(%rbx,%rax)
movq %r13, %rdi
callq 0x14a9e
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq %rbx, %rdi
callq 0x4340
movq %r13, %rdi
callq 0x14aae
cmpl $0x3e7, (%rax)          # imm = 0x3E7
movl %ebp, 0x1c(%rsp)
jg 0x2a1c9
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movq $0x4, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rax
movl 0x18(%rbx,%rax), %ecx
andl %r15d, %ecx
orl $0x80, %ecx
movl %ecx, 0x18(%rbx,%rax)
movq %r13, %rdi
callq 0x14aae
movl (%rax), %esi
movq %rbx, %rdi
callq 0x4500
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movq $0x1, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rax
movl 0x18(%rbx,%rax), %ecx
andl %r15d, %ecx
orl $0x20, %ecx
movl %ecx, 0x18(%rbx,%rax)
movq %r13, %rdi
callq 0x14ab6
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq %rbx, %rdi
callq 0x4340
jmp 0x2a210
movq %r13, %rdi
callq 0x14aae
cmpl $0x1869f, (%rax)        # imm = 0x1869F
movq (%rbx), %rax
movq -0x18(%rax), %rcx
jg 0x2a226
movq $0x5, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rax
movl 0x18(%rbx,%rax), %ecx
andl %r15d, %ecx
orl $0x80, %ecx
movl %ecx, 0x18(%rbx,%rax)
movq %r13, %rdi
callq 0x14aae
movl (%rax), %esi
movq %rbx, %rdi
callq 0x4500
movl $0x3, %edx
movq %rbx, %rdi
leaq 0x1347f(%rip), %rsi     # 0x3d69e
callq 0x4340
jmp 0x2a253
movq $0x6, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rax
movl 0x18(%rbx,%rax), %ecx
andl %r15d, %ecx
orl $0x20, %ecx
movl %ecx, 0x18(%rbx,%rax)
movq %r13, %rdi
callq 0x14aae
movl (%rax), %esi
movq %rbx, %rdi
callq 0x4500
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movl 0x18(%rbx,%rcx), %edx
movl $0xfffffefb, %esi       # imm = 0xFFFFFEFB
andl %esi, %edx
orl $0x4, %edx
movl %edx, 0x18(%rbx,%rcx)
movq -0x18(%rax), %rcx
movl $0x8, %ebp
movq %rbp, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rcx
movl 0x18(%rbx,%rcx), %edx
andl %r15d, %edx
movl $0x80, %r14d
orl %r14d, %edx
movl %edx, 0x18(%rbx,%rcx)
movq -0x18(%rax), %rax
movl $0x3, %r12d
movq %r12, 0x8(%rbx,%rax)
movq %r13, %rdi
callq 0x14d4e
movsd (%rax), %xmm0
movq %rbx, %rdi
callq 0x44a0
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movq %rbp, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rcx
movl 0x18(%rbx,%rcx), %edx
andl %r15d, %edx
orl %r14d, %edx
movl %edx, 0x18(%rbx,%rcx)
movq -0x18(%rax), %rax
movq %r12, 0x8(%rbx,%rax)
movq %r13, %rdi
callq 0x14d56
movsd (%rax), %xmm0
movq %rbx, %rdi
callq 0x44a0
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movq %rbp, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rcx
movl 0x18(%rbx,%rcx), %edx
andl %r15d, %edx
orl %r14d, %edx
movl %edx, 0x18(%rbx,%rcx)
movq -0x18(%rax), %rax
movq %r12, 0x8(%rbx,%rax)
movq %r13, %rdi
callq 0x14d5e
movsd (%rax), %xmm0
movq %rbx, %rdi
callq 0x44a0
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movl $0x6, %r12d
movq %r12, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rcx
movl 0x18(%rbx,%rcx), %edx
andl %r15d, %edx
orl %r14d, %edx
movl %edx, 0x18(%rbx,%rcx)
movq -0x18(%rax), %rax
movl $0x2, %ebp
movq %rbp, 0x8(%rbx,%rax)
movq %r13, %rdi
callq 0x14ac6
movsd (%rax), %xmm0
movq %rbx, %rdi
callq 0x44a0
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movq %r12, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rcx
movl 0x18(%rbx,%rcx), %edx
andl %r15d, %edx
orl %r14d, %edx
movl %edx, 0x18(%rbx,%rcx)
movq -0x18(%rax), %rax
movq %rbp, 0x8(%rbx,%rax)
movq %r13, %rdi
callq 0x14ace
movsd (%rax), %xmm0
movq %rbx, %rdi
callq 0x44a0
movl $0x6, %edx
movq %rbx, %rdi
leaq 0x132e0(%rip), %rsi     # 0x3d69b
callq 0x4340
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movq $0x4, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rax
movl 0x18(%rbx,%rax), %ecx
andl %r15d, %ecx
orl $0x20, %ecx
movl %ecx, 0x18(%rbx,%rax)
movq %r13, %rdi
callq 0x14ade
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq %rbx, %rdi
callq 0x4340
movl $0x1, %edx
movq %rbx, %rdi
leaq 0x13298(%rip), %rsi     # 0x3d6a0
callq 0x4340
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movq $0x1, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rax
movl 0x18(%rbx,%rax), %ecx
andl %r15d, %ecx
orl $0x20, %ecx
movl %ecx, 0x18(%rbx,%rax)
movq %r13, %rdi
callq 0x14ad6
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq %rbx, %rdi
callq 0x4340
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x42a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41f0
incl 0x14(%rsp)
movl 0x1c(%rsp), %ebp
incl %ebp
movq 0x30(%rsp), %r14
movl 0x8(%rsp), %r12d
incl %r12d
movl %r12d, 0x8(%rsp)
movq %r14, %rdi
callq 0x2f884
cmpl %eax, %r12d
jb 0x29f4a
movl 0xc(%rsp), %r14d
incl %r14d
movl %r14d, 0xc(%rsp)
movq 0x28(%rsp), %r13
movq %r13, %rdi
callq 0x20664
cmpl %eax, %r14d
jb 0x29f1d
testl %ebp, %ebp
setg %bpl
movq 0x20(%rsp), %r12
testb %bpl, %bpl
je 0x2a508
movl $0x3, %edx
movq %rbx, %rdi
leaq 0x139e7(%rip), %rsi     # 0x3dec3
callq 0x4340
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x42a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41f0
movl 0x10(%rsp), %r14d
incl %r14d
movl %r14d, 0x10(%rsp)
movq %r12, %rdi
callq 0x237a6
cmpl %eax, %r14d
jb 0x29eee
cmpl $0x0, 0x14(%rsp)
jle 0x2a568
leaq 0x1316e(%rip), %rsi     # 0x3d6a2
movl $0x3, %edx
movq %rbx, %rdi
callq 0x4340
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x42a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41f0
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop