// File: /workspace/github_cpp_makefile_star2_O3/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, 0x14(%rsp)
movq %rsi, %rbx
movq %rdi, %r12
movq (%rsi), %rax
movq -0x18(%rax), %rdi
addq %rsi, %rdi
xorl %r13d, %r13d
xorl %esi, %esi
callq 0x44f0
movl $0x0, 0x10(%rsp)
movq %r12, %rdi
callq 0x235b6
testl %eax, %eax
je 0x2a2eb
movl $0xffffff4f, %r15d      # imm = 0xFFFFFF4F
movq %r12, 0x20(%rsp)
movq %r12, %rdi
leaq 0x10(%rsp), %rsi
callq 0x235c4
movl $0x0, 0xc(%rsp)
movq %rax, 0x28(%rsp)
movq %rax, %rdi
callq 0x204e0
testl %eax, %eax
je 0x2a28d
xorl %ebp, %ebp
movq 0x28(%rsp), %r12
movq %r12, %rdi
leaq 0xc(%rsp), %rsi
callq 0x20486
movq %rax, %r14
movl $0x0, 0x8(%rsp)
movq %rax, %rdi
callq 0x2f5c2
testl %eax, %eax
movq %r14, 0x30(%rsp)
je 0x2a226
movq %r14, %rdi
leaq 0x8(%rsp), %rsi
callq 0x2f4ec
movq %rax, %r12
cmpb $0x0, 0x14(%rsp)
je 0x29cf3
movq %r12, %rdi
callq 0x1496e
cmpb $0x0, (%rax)
je 0x2a208
movl %ebp, 0x1c(%rsp)
movl %r13d, %ebp
movq %r12, %rdi
callq 0x148f4
xorl %ecx, %ecx
cmpl $0x186a0, (%rax)        # imm = 0x186A0
setl %cl
movq (%rbx), %rax
movq -0x18(%rax), %rdx
movl $0x6, %r13d
subq %rcx, %r13
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 %r12, %rdi
callq 0x148ee
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq %rbx, %rdi
callq 0x4340
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movq %r13, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rax
movl 0x18(%rbx,%rax), %ecx
andl %r15d, %ecx
orl $0x80, %ecx
movl %ecx, 0x18(%rbx,%rax)
movq %r12, %rdi
callq 0x148f4
movl (%rax), %esi
movq %rbx, %rdi
callq 0x4500
movl $0x1, %edx
movq %rbx, %rdi
leaq 0x128ef(%rip), %r13     # 0x3c680
movq %r13, %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 %r12, %rdi
callq 0x148fa
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 %r12, %rdi
callq 0x14906
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq %rbx, %rdi
callq 0x4340
movq %r12, %rdi
callq 0x14916
cmpq $0x3, 0x8(%rax)
movq (%rbx), %rax
movq -0x18(%rax), %rcx
ja 0x29e60
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 %r12, %rdi
callq 0x14916
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq %rbx, %rdi
callq 0x4340
movl $0x1, %edx
movq %rbx, %rdi
movq %r13, %rsi
jmp 0x29e8d
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 %r12, %rdi
callq 0x14916
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 %r12, %rdi
callq 0x14926
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq %rbx, %rdi
callq 0x4340
movq %r12, %rdi
callq 0x14936
cmpl $0x3e7, (%rax)          # imm = 0x3E7
movl %ebp, 0x18(%rsp)
jg 0x29f51
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 %r12, %rdi
callq 0x14936
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 %r12, %rdi
callq 0x1493e
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq %rbx, %rdi
callq 0x4340
jmp 0x29f98
movq %r12, %rdi
callq 0x14936
cmpl $0x1869f, (%rax)        # imm = 0x1869F
movq (%rbx), %rax
movq -0x18(%rax), %rcx
jg 0x29fae
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 %r12, %rdi
callq 0x14936
movl (%rax), %esi
movq %rbx, %rdi
callq 0x4500
movl $0x3, %edx
movq %rbx, %rdi
leaq 0x126d7(%rip), %rsi     # 0x3c67e
callq 0x4340
jmp 0x29fdb
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 %r12, %rdi
callq 0x14936
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, %r14d
movq %r14, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rcx
movl 0x18(%rbx,%rcx), %edx
andl %r15d, %edx
movl $0x80, %r13d
orl %r13d, %edx
movl %edx, 0x18(%rbx,%rcx)
movq -0x18(%rax), %rax
movl $0x3, %ebp
movq %rbp, 0x8(%rbx,%rax)
movq %r12, %rdi
callq 0x14bd6
movsd (%rax), %xmm0
movq %rbx, %rdi
callq 0x44a0
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movq %r14, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rcx
movl 0x18(%rbx,%rcx), %edx
andl %r15d, %edx
orl %r13d, %edx
movl %edx, 0x18(%rbx,%rcx)
movq -0x18(%rax), %rax
movq %rbp, 0x8(%rbx,%rax)
movq %r12, %rdi
callq 0x14bde
movsd (%rax), %xmm0
movq %rbx, %rdi
callq 0x44a0
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movq %r14, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rcx
movl 0x18(%rbx,%rcx), %edx
andl %r15d, %edx
orl %r13d, %edx
movl %edx, 0x18(%rbx,%rcx)
movq -0x18(%rax), %rax
movq %rbp, 0x8(%rbx,%rax)
movq %r12, %rdi
callq 0x14be6
movsd (%rax), %xmm0
movq %rbx, %rdi
callq 0x44a0
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movl $0x6, %ebp
movq %rbp, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rcx
movl 0x18(%rbx,%rcx), %edx
andl %r15d, %edx
orl %r13d, %edx
movl %edx, 0x18(%rbx,%rcx)
movq -0x18(%rax), %rax
movl $0x2, %r14d
movq %r14, 0x8(%rbx,%rax)
movq %r12, %rdi
callq 0x1494e
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 %r13d, %edx
movl %edx, 0x18(%rbx,%rcx)
movq -0x18(%rax), %rax
movq %r14, 0x8(%rbx,%rax)
movq %r12, %rdi
callq 0x14956
movsd (%rax), %xmm0
movq %rbx, %rdi
callq 0x44a0
movl $0x6, %edx
movq %rbx, %rdi
leaq 0x12538(%rip), %rsi     # 0x3c67b
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 %r12, %rdi
callq 0x14966
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq %rbx, %rdi
callq 0x4340
movl $0x1, %edx
movq %rbx, %rdi
leaq 0x124f0(%rip), %rsi     # 0x3c680
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 %r12, %rdi
callq 0x1495e
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
movl 0x18(%rsp), %r13d
incl %r13d
movl 0x1c(%rsp), %ebp
incl %ebp
movq 0x30(%rsp), %r14
movl 0x8(%rsp), %r12d
incl %r12d
movl %r12d, 0x8(%rsp)
movq %r14, %rdi
callq 0x2f5c2
cmpl %eax, %r12d
jb 0x29ccb
movl 0xc(%rsp), %r14d
incl %r14d
movl %r14d, 0xc(%rsp)
movq 0x28(%rsp), %r12
movq %r12, %rdi
callq 0x204e0
cmpl %eax, %r14d
jb 0x29c9e
testl %ebp, %ebp
jle 0x2a288
movl $0x3, %edx
movq %rbx, %rdi
leaq 0x12c47(%rip), %rsi     # 0x3cea3
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
movq 0x20(%rsp), %r12
movl 0x10(%rsp), %r14d
incl %r14d
movl %r14d, 0x10(%rsp)
movq %r12, %rdi
callq 0x235b6
cmpl %eax, %r14d
jb 0x29c6d
testl %r13d, %r13d
jle 0x2a2eb
leaq 0x123cb(%rip), %rsi     # 0x3c682
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