// File: /workspace/github_cpp_makefile_star2_O3/zeeev[P]DASVC/bamtools/src/toolkit/bamtools_convert.cpp
// Function: BamTools::ConvertTool::ConvertToolPrivate::PrintSam(BamTools::BamAlignment const&)
void ConvertTool::ConvertToolPrivate::PrintSam(const BamAlignment& a) {
  
    // tab-delimited
    // <QNAME> <FLAG> <RNAME> <POS> <MAPQ> <CIGAR> <MRNM> <MPOS> <ISIZE> <SEQ> <QUAL> [ <TAG>:<VTYPE>:<VALUE> [...] ]
  
    // write name & alignment flag
   m_out << a.Name << "\t" << a.AlignmentFlag << "\t";

    // write reference name
    if ( (a.RefID >= 0) && (a.RefID < (int)m_references.size()) ) 
        m_out << m_references[a.RefID].RefName << "\t";
    else 
        m_out << "*\t";
    
    // write position & map quality
    m_out << a.Position+1 << "\t" << a.MapQuality << "\t";
    
    // write CIGAR
    const vector<CigarOp>& cigarData = a.CigarData;
    if ( cigarData.empty() ) m_out << "*\t";
    else {
        vector<CigarOp>::const_iterator cigarIter = cigarData.begin();
        vector<CigarOp>::const_iterator cigarEnd  = cigarData.end();
        for ( ; cigarIter != cigarEnd; ++cigarIter ) {
            const CigarOp& op = (*cigarIter);
            m_out << op.Length << op.Type;
        }
        m_out << "\t";
    }
    
    // write mate reference name, mate position, & insert size
    if ( a.IsPaired() && (a.MateRefID >= 0) && (a.MateRefID < (int)m_references.size()) ) {
        if ( a.MateRefID == a.RefID )
            m_out << "=\t";
        else
           m_out << m_references[a.MateRefID].RefName << "\t";
        m_out << a.MatePosition+1 << "\t" << a.InsertSize << "\t";
    } 
    else
        m_out << "*\t0\t0\t";
    
    // write sequence
    if ( a.QueryBases.empty() )
        m_out << "*\t";
    else
        m_out << a.QueryBases << "\t";
    
    // write qualities
    if ( a.Qualities.empty() || (a.Qualities.at(0) == (char)0xFF) )
        m_out << "*";
    else
        m_out << a.Qualities;
    
    // write tag data
    const char* tagData = a.TagData.c_str();
    const size_t tagDataLength = a.TagData.length();
    
    size_t index = 0;
    while ( index < tagDataLength ) {

        // write tag name   
        string tagName = a.TagData.substr(index, 2);
        m_out << "\t" << tagName << ":";
        index += 2;
        
        // get data type
        char type = a.TagData.at(index);
        ++index;
        switch ( type ) {
            case (Constants::BAM_TAG_TYPE_ASCII) :
                m_out << "A:" << tagData[index];
                ++index;
                break;

            case (Constants::BAM_TAG_TYPE_INT8) :
                // force value into integer-type (instead of char value)
                m_out << "i:" << static_cast<int16_t>(tagData[index]);
                ++index;
                break;

            case (Constants::BAM_TAG_TYPE_UINT8) :
                // force value into integer-type (instead of char value)
                m_out << "i:" << static_cast<uint16_t>(tagData[index]);
                ++index;
                break;

            case (Constants::BAM_TAG_TYPE_INT16) :
                m_out << "i:" << BamTools::UnpackSignedShort(&tagData[index]);
                index += sizeof(int16_t);
                break;

            case (Constants::BAM_TAG_TYPE_UINT16) :
                m_out << "i:" << BamTools::UnpackUnsignedShort(&tagData[index]);
                index += sizeof(uint16_t);
                break;

            case (Constants::BAM_TAG_TYPE_INT32) :
                m_out << "i:" << BamTools::UnpackSignedInt(&tagData[index]);
                index += sizeof(int32_t);
                break;

            case (Constants::BAM_TAG_TYPE_UINT32) :
                m_out << "i:" << BamTools::UnpackUnsignedInt(&tagData[index]);
                index += sizeof(uint32_t);
                break;

            case (Constants::BAM_TAG_TYPE_FLOAT) :
                m_out << "f:" << BamTools::UnpackFloat(&tagData[index]);
                index += sizeof(float);
                break;

            case (Constants::BAM_TAG_TYPE_HEX)    : // fall-through
            case (Constants::BAM_TAG_TYPE_STRING) :
                m_out << type << ":";
                while (tagData[index]) {
                    m_out << tagData[index];
                    ++index;
                }
                ++index;
                break;
        }

        if ( tagData[index] == '\0' )
            break;
    }

    m_out << endl;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %rbp
movq %rdi, %r15
leaq 0x20(%rdi), %rbx
movq (%rsi), %rsi
movq 0x8(%rbp), %rdx
movq %rbx, %rdi
callq 0x276b0
movq %rax, %r12
leaq 0x4a8f3(%rip), %r13     # 0x76816
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x276b0
movl 0xb4(%rbp), %esi
movq %r12, %rdi
callq 0x27400
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x276b0
movslq 0xa8(%rbp), %rax
testq %rax, %rax
js 0x2bf9c
movq 0x8(%r15), %rcx
movq 0x10(%r15), %rdx
subq %rcx, %rdx
shrq $0x3, %rdx
imull $0xcccccccd, %edx, %edx # imm = 0xCCCCCCCD
cmpl %edx, %eax
jge 0x2bf9c
leaq (%rax,%rax,4), %rax
movq (%rcx,%rax,8), %rsi
movq 0x8(%rcx,%rax,8), %rdx
movq %rbx, %rdi
callq 0x276b0
leaq 0x4a884(%rip), %rsi     # 0x76816
movl $0x1, %edx
movq %rax, %rdi
jmp 0x2bfab
leaq 0x453ff(%rip), %rsi     # 0x713a2
movl $0x2, %edx
movq %rbx, %rdi
callq 0x276b0
movl 0xac(%rbp), %esi
incl %esi
movq %rbx, %rdi
callq 0x27ab0
movq %rax, %r12
leaq 0x4a84c(%rip), %r13     # 0x76816
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x276b0
movzwl 0xb2(%rbp), %esi
movq %r12, %rdi
callq 0x27400
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x276b0
movq 0xb8(%rbp), %r14
movq 0xc0(%rbp), %r13
cmpq %r13, %r14
je 0x2c04b
leaq 0x8(%rsp), %r12
movl 0x4(%r14), %esi
movq %rbx, %rdi
callq 0x27400
movb (%r14), %cl
movb %cl, 0x8(%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x276b0
addq $0x8, %r14
cmpq %r13, %r14
jne 0x2c011
leaq 0x4a7d2(%rip), %rsi     # 0x76816
movl $0x1, %edx
jmp 0x2c057
leaq 0x45350(%rip), %rsi     # 0x713a2
movl $0x2, %edx
movq %rbx, %rdi
callq 0x276b0
movq %rbp, %rdi
callq 0x27330
testb %al, %al
je 0x2c0b0
movslq 0xd0(%rbp), %rax
testq %rax, %rax
js 0x2c0b0
movq 0x8(%r15), %rcx
movq 0x10(%r15), %rdx
subq %rcx, %rdx
shrq $0x3, %rdx
imull $0xcccccccd, %edx, %edx # imm = 0xCCCCCCCD
cmpl %edx, %eax
jge 0x2c0b0
cmpl 0xa8(%rbp), %eax
jne 0x2c418
leaq 0x45302(%rip), %rsi     # 0x713a5
movl $0x2, %edx
movq %rbx, %rdi
jmp 0x2c43c
leaq 0x452f1(%rip), %rsi     # 0x713a8
movl $0x6, %edx
movq %rbx, %rdi
callq 0x276b0
movq 0x30(%rbp), %rdx
testq %rdx, %rdx
je 0x2c0ea
movq 0x28(%rbp), %rsi
movq %rbx, %rdi
callq 0x276b0
leaq 0x4a736(%rip), %rsi     # 0x76816
movl $0x1, %edx
movq %rax, %rdi
jmp 0x2c0f9
leaq 0x452b1(%rip), %rsi     # 0x713a2
movl $0x2, %edx
movq %rbx, %rdi
callq 0x276b0
movq 0x70(%rbp), %rdx
testq %rdx, %rdx
je 0x2c110
movq 0x68(%rbp), %rsi
cmpb $-0x1, (%rsi)
jne 0x2c11c
leaq 0x492f6(%rip), %rsi     # 0x7540d
movl $0x1, %edx
movq %rbx, %rdi
callq 0x276b0
leaq 0x88(%rbp), %r15
movq %rbp, %rax
movq 0x88(%rbp), %rbp
movq %rax, 0x28(%rsp)
movq 0x90(%rax), %rax
movq %rax, 0x30(%rsp)
xorl %r14d, %r14d
leaq 0x7(%rsp), %r12
cmpq 0x30(%rsp), %r14
jae 0x2c3e2
movl $0x2, %ecx
leaq 0x8(%rsp), %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x27600
movl $0x1, %edx
movq %rbx, %rdi
leaq 0x4a699(%rip), %rsi     # 0x76816
callq 0x276b0
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq %rbx, %rdi
callq 0x276b0
movl $0x1, %edx
movq %rax, %rdi
leaq 0x451c4(%rip), %rsi     # 0x71367
callq 0x276b0
leaq 0x2(%r14), %rsi
movq 0x28(%rsp), %rax
movq 0x90(%rax), %rdx
cmpq %rsi, %rdx
jbe 0x2c489
movq (%r15), %rax
movb 0x2(%rax,%r14), %cl
leaq 0x3(%r14), %r13
movzbl %cl, %eax
cmpl $0x59, %eax
jg 0x2c223
leal -0x41(%rax), %edx
cmpl $0x8, %edx
ja 0x2c2f5
leaq 0x44e40(%rip), %rsi     # 0x71028
movslq (%rsi,%rdx,4), %rax
addq %rsi, %rax
jmpq *%rax
movl $0x2, %edx
movq %rbx, %rdi
leaq 0x451af(%rip), %rsi     # 0x713af
callq 0x276b0
movb (%rbp,%r13), %al
movb %al, 0x7(%rsp)
movl $0x1, %edx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x276b0
jmp 0x2c34a
cmpl $0x65, %eax
jle 0x2c26a
cmpl $0x66, %eax
je 0x2c373
cmpl $0x69, %eax
je 0x2c39b
cmpl $0x73, %eax
jne 0x2c2ed
movl $0x2, %edx
movq %rbx, %rdi
leaq 0x45160(%rip), %rsi     # 0x713b2
callq 0x276b0
movswl (%rbp,%r13), %esi
movq %rbx, %rdi
callq 0x27510
jmp 0x2c31c
cmpl $0x5a, %eax
je 0x2c29b
cmpl $0x63, %eax
jne 0x2c2ed
movl $0x2, %edx
movq %rbx, %rdi
leaq 0x4512f(%rip), %rsi     # 0x713b2
callq 0x276b0
movsbl (%rbp,%r13), %esi
movq %rbx, %rdi
callq 0x27510
jmp 0x2c34a
movb %cl, 0x7(%rsp)
movl $0x1, %edx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x276b0
movl $0x1, %edx
movq %rax, %rdi
leaq 0x450a9(%rip), %rsi     # 0x71367
callq 0x276b0
movb (%rbp,%r13), %al
testb %al, %al
je 0x2c2ea
movb %al, 0x7(%rsp)
movl $0x1, %edx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x276b0
movb 0x1(%rbp,%r13), %al
incq %r13
jmp 0x2c2c8
incq %r13
movq %r13, %r14
jmp 0x2c3c0
cmpl $0x53, %eax
jne 0x2c2ed
movl $0x2, %edx
movq %rbx, %rdi
leaq 0x450a9(%rip), %rsi     # 0x713b2
callq 0x276b0
movzwl (%rbp,%r13), %esi
movq %rbx, %rdi
callq 0x27400
addq $0x5, %r14
jmp 0x2c3c0
movl $0x2, %edx
movq %rbx, %rdi
leaq 0x4507e(%rip), %rsi     # 0x713b2
callq 0x276b0
movsbq (%rbp,%r13), %rax
movzwl %ax, %esi
movq %rbx, %rdi
callq 0x27400
addq $0x4, %r14
jmp 0x2c3c0
movl $0x2, %edx
movq %rbx, %rdi
leaq 0x45053(%rip), %rsi     # 0x713b2
callq 0x276b0
movl (%rbp,%r13), %esi
movq %rbx, %rdi
callq 0x27400
jmp 0x2c3bc
movl $0x2, %edx
movq %rbx, %rdi
leaq 0x45033(%rip), %rsi     # 0x713b5
callq 0x276b0
xorps %xmm0, %xmm0
cvtss2sd (%rbp,%r13), %xmm0
movq %rbx, %rdi
callq 0x279d0
jmp 0x2c3bc
movl $0x2, %edx
movq %rbx, %rdi
leaq 0x45008(%rip), %rsi     # 0x713b2
callq 0x276b0
movl (%rbp,%r13), %esi
movq %rbx, %rdi
callq 0x27ab0
addq $0x7, %r14
movb (%rbp,%r14), %r13b
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x2c3d9
callq 0x27560
testb %r13b, %r13b
jne 0x2c14e
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x27590
movsbl %al, %esi
movq %rbx, %rdi
callq 0x27040
movq %rax, %rdi
callq 0x27410
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq (%rax,%rax,4), %rax
movq (%rcx,%rax,8), %rsi
movq 0x8(%rcx,%rax,8), %rdx
movq %rbx, %rdi
callq 0x276b0
leaq 0x4a3e2(%rip), %rsi     # 0x76816
movl $0x1, %edx
movq %rax, %rdi
callq 0x276b0
movl 0xd4(%rbp), %esi
incl %esi
movq %rbx, %rdi
callq 0x27ab0
movq %rax, %r15
leaq 0x4a3bb(%rip), %r12     # 0x76816
movl $0x1, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x276b0
movl 0xd8(%rbp), %esi
movq %r15, %rdi
callq 0x27ab0
movl $0x1, %edx
movq %rax, %rdi
movq %r12, %rsi
jmp 0x2c0bf
leaq 0x45278(%rip), %rdi     # 0x71708
xorl %eax, %eax
callq 0x278b0
jmp 0x2c49d
jmp 0x2c49d
jmp 0x2c49d
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x2c4b4
callq 0x27560
movq %rbx, %rdi
callq 0x27b10