// File: /workspace/github_cpp_makefile_star2_O2/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 %r14d, %r14d
xorl %esi, %esi
callq 0x4510
movl $0xffffff4f, %ebp       # imm = 0xFFFFFF4F
xorl %r15d, %r15d
movq %r12, 0x20(%rsp)
movl %r14d, 0x14(%rsp)
movq %r12, %rdi
callq 0x19fa2
cmpl %eax, %r14d
jae 0x1fe9e
movq %r12, %rdi
leaq 0x14(%rsp), %rsi
callq 0x19fb0
movq %rax, %r13
xorl %r14d, %r14d
movl $0x0, 0x8(%rsp)
movq %rax, 0x28(%rsp)
movl %r14d, 0x10(%rsp)
movq %r13, %rdi
callq 0x1786c
cmpl %eax, %r14d
jae 0x1fe73
movq %r13, %rdi
leaq 0x10(%rsp), %rsi
callq 0x17802
movq %rax, %r14
xorl %r12d, %r12d
movq %rax, 0x30(%rsp)
pushq $0x6
popq %r13
movl %r12d, 0xc(%rsp)
movq %r14, %rdi
callq 0x23aee
cmpl %eax, %r12d
jae 0x1fe5c
movq %r14, %rdi
leaq 0xc(%rsp), %rsi
callq 0x239f2
movq %rax, %r12
cmpb $0x0, 0x18(%rsp)
je 0x1f9b7
movq %r12, %rdi
callq 0xea64
cmpb $0x0, (%rax)
je 0x1fe4f
movl %r15d, 0x1c(%rsp)
movq %r12, %rdi
callq 0xe9ea
xorl %ecx, %ecx
cmpl $0x186a0, (%rax)        # imm = 0x186A0
setl %cl
movq (%rbx), %rax
movq -0x18(%rax), %rdx
subq %rcx, %r13
addq $0x5, %rcx
movq %rcx, 0x10(%rbx,%rdx)
movq -0x18(%rax), %rax
movl 0x18(%rbx,%rax), %ecx
andl %ebp, %ecx
orl $0x20, %ecx
movl %ecx, 0x18(%rbx,%rax)
movq %r12, %rdi
callq 0xe9e4
movq %rbx, %rdi
movq %rax, %rsi
callq 0x42c0
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movq %r13, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rax
movl 0x18(%rbx,%rax), %ecx
andl %ebp, %ecx
orl $0x80, %ecx
movl %ecx, 0x18(%rbx,%rax)
movq %r12, %rdi
callq 0xe9ea
movl (%rax), %esi
movq %rbx, %rdi
callq 0x4520
movq %rbx, %rdi
leaq 0xeb82(%rip), %r13      # 0x2e5c4
movq %r13, %rsi
callq 0x4300
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movq $0x4, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rax
movl 0x18(%rbx,%rax), %ecx
andl %ebp, %ecx
orl $0x20, %ecx
movl %ecx, 0x18(%rbx,%rax)
movq %r12, %rdi
callq 0xe9f0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x42c0
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movq $0x1, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rax
movl 0x18(%rbx,%rax), %ecx
andl %ebp, %ecx
orl $0x20, %ecx
movl %ecx, 0x18(%rbx,%rax)
movq %r12, %rdi
callq 0xe9fc
movq %rbx, %rdi
movq %rax, %rsi
callq 0x42c0
movq %r12, %rdi
callq 0xea0c
cmpq $0x3, 0x8(%rax)
movq (%rbx), %rax
movq -0x18(%rax), %rcx
ja 0x1fb02
movq $0x3, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rax
movl 0x18(%rbx,%rax), %ecx
andl %ebp, %ecx
orl $0x20, %ecx
movl %ecx, 0x18(%rbx,%rax)
movq %r12, %rdi
callq 0xea0c
movq %rbx, %rdi
movq %rax, %rsi
callq 0x42c0
movq %rbx, %rdi
movq %r13, %rsi
callq 0x4300
jmp 0x1fb2f
movq $0x4, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rax
movl 0x18(%rbx,%rax), %ecx
andl %ebp, %ecx
orl $0x20, %ecx
movl %ecx, 0x18(%rbx,%rax)
movq %r12, %rdi
callq 0xea0c
movq %rbx, %rdi
movq %rax, %rsi
callq 0x42c0
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movq $0x1, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rax
movl 0x18(%rbx,%rax), %ecx
andl %ebp, %ecx
orl $0x20, %ecx
movl %ecx, 0x18(%rbx,%rax)
movq %r12, %rdi
callq 0xea1c
movq %rbx, %rdi
movq %rax, %rsi
callq 0x42c0
movq %r12, %rdi
callq 0xea2c
cmpl $0x3e7, (%rax)          # imm = 0x3E7
jg 0x1fbdf
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movq $0x4, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rax
movl 0x18(%rbx,%rax), %ecx
andl %ebp, %ecx
orl $0x80, %ecx
movl %ecx, 0x18(%rbx,%rax)
movq %r12, %rdi
callq 0xea2c
movl (%rax), %esi
movq %rbx, %rdi
callq 0x4520
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movq $0x1, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rax
movl 0x18(%rbx,%rax), %ecx
andl %ebp, %ecx
orl $0x20, %ecx
movl %ecx, 0x18(%rbx,%rax)
movq %r12, %rdi
callq 0xea34
movq %rbx, %rdi
movq %rax, %rsi
callq 0x42c0
jmp 0x1fc25
movq %r12, %rdi
callq 0xea2c
cmpl $0x1869f, (%rax)        # imm = 0x1869F
movq (%rbx), %rax
movq -0x18(%rax), %rcx
jg 0x1fc36
movq $0x5, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rax
movl 0x18(%rbx,%rax), %ecx
andl %ebp, %ecx
orl $0x80, %ecx
movl %ecx, 0x18(%rbx,%rax)
movq %r12, %rdi
callq 0xea2c
movl (%rax), %esi
movq %rbx, %rdi
callq 0x4520
movq %rbx, %rdi
leaq 0xe993(%rip), %rsi      # 0x2e5c2
callq 0x4300
jmp 0x1fc62
movq $0x6, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rax
movl 0x18(%rbx,%rax), %ecx
andl %ebp, %ecx
orl $0x20, %ecx
movl %ecx, 0x18(%rbx,%rax)
movq %r12, %rdi
callq 0xea2c
movl (%rax), %esi
movq %rbx, %rdi
callq 0x4520
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
pushq $0x8
popq %r15
movq %r15, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rcx
movl 0x18(%rbx,%rcx), %edx
andl %ebp, %edx
movl $0x80, %r14d
orl %r14d, %edx
movl %edx, 0x18(%rbx,%rcx)
movq -0x18(%rax), %rax
pushq $0x3
popq %r13
movq %r13, 0x8(%rbx,%rax)
movq %r12, %rdi
callq 0xec26
movsd (%rax), %xmm0
movq %rbx, %rdi
callq 0x44d0
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movq %r15, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rcx
movl 0x18(%rbx,%rcx), %edx
andl %ebp, %edx
orl %r14d, %edx
movl %edx, 0x18(%rbx,%rcx)
movq -0x18(%rax), %rax
movq %r13, 0x8(%rbx,%rax)
movq %r12, %rdi
callq 0xec2e
movsd (%rax), %xmm0
movq %rbx, %rdi
callq 0x44d0
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movq %r15, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rcx
movl 0x18(%rbx,%rcx), %edx
andl %ebp, %edx
orl %r14d, %edx
movl %edx, 0x18(%rbx,%rcx)
movq -0x18(%rax), %rax
movq %r13, 0x8(%rbx,%rax)
movq %r12, %rdi
callq 0xec36
movsd (%rax), %xmm0
movq %rbx, %rdi
callq 0x44d0
movq (%rbx), %rax
movq -0x18(%rax), %rcx
pushq $0x6
popq %r13
movq %r13, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rcx
movl 0x18(%rbx,%rcx), %edx
andl %ebp, %edx
orl %r14d, %edx
movl %edx, 0x18(%rbx,%rcx)
movq -0x18(%rax), %rax
pushq $0x2
popq %r15
movq %r15, 0x8(%rbx,%rax)
movq %r12, %rdi
callq 0xea44
movsd (%rax), %xmm0
movq %rbx, %rdi
callq 0x44d0
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movq %r13, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rcx
movl 0x18(%rbx,%rcx), %edx
andl %ebp, %edx
orl %r14d, %edx
movl %edx, 0x18(%rbx,%rcx)
movq -0x18(%rax), %rax
movq %r15, 0x8(%rbx,%rax)
movq %r12, %rdi
callq 0xea4c
movsd (%rax), %xmm0
movq %rbx, %rdi
callq 0x44d0
movq %rbx, %rdi
leaq 0xe805(%rip), %rsi      # 0x2e5bf
callq 0x4300
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movq $0x4, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rax
movl 0x18(%rbx,%rax), %ecx
andl %ebp, %ecx
orl $0x20, %ecx
movl %ecx, 0x18(%rbx,%rax)
movq %r12, %rdi
callq 0xea5c
movq %rbx, %rdi
movq %rax, %rsi
callq 0x42c0
movq %rbx, %rdi
leaq 0xe7c7(%rip), %rsi      # 0x2e5c4
callq 0x4300
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movq $0x1, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rax
movl 0x18(%rbx,%rax), %ecx
andl %ebp, %ecx
orl $0x20, %ecx
movl %ecx, 0x18(%rbx,%rax)
movq %r12, %rdi
callq 0xea54
movq %rbx, %rdi
movq %rax, %rsi
callq 0x42c0
movq %rbx, %rdi
callq 0x4180
movl 0x1c(%rsp), %r15d
incl %r15d
incl 0x8(%rsp)
movq 0x30(%rsp), %r14
movl 0xc(%rsp), %r12d
incl %r12d
jmp 0x1f979
movl 0x10(%rsp), %r14d
incl %r14d
movq 0x20(%rsp), %r12
movq 0x28(%rsp), %r13
jmp 0x1f947
cmpl $0x0, 0x8(%rsp)
jle 0x1fe91
movq %rbx, %rdi
leaq 0xef63(%rip), %rsi      # 0x2ede7
callq 0x4300
movq %rax, %rdi
callq 0x4180
movl 0x14(%rsp), %r14d
incl %r14d
jmp 0x1f911
testl %r15d, %r15d
jle 0x1feba
leaq 0xe71c(%rip), %rsi      # 0x2e5c6
movq %rbx, %rdi
callq 0x4300
movq %rax, %rdi
callq 0x4180
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop