// File: /workspace/github_cpp_makefile_star2_O1/zeeev[P]DASVC/bamtools/src/api/internal/bam/BamWriter_p.cpp
// Function: BamTools::Internal::BamWriterPrivate::EncodeQuerySequence(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&)
void BamWriterPrivate::EncodeQuerySequence(const string& query, string& encodedQuery) {

    // prepare the encoded query string
    const size_t queryLength = query.size();
    const size_t encodedQueryLength = static_cast<size_t>((queryLength+1)/2);
    encodedQuery.resize(encodedQueryLength);
    char* pEncodedQuery = (char*)encodedQuery.data();
    const char* pQuery = (const char*)query.data();

    // walk through original query sequence, encoding its bases
    unsigned char nucleotideCode;
    bool useHighWord = true;
    while ( *pQuery ) {
        switch ( *pQuery ) {
            case (Constants::BAM_DNA_EQUAL) : nucleotideCode = Constants::BAM_BASECODE_EQUAL; break;
            case (Constants::BAM_DNA_A)     : nucleotideCode = Constants::BAM_BASECODE_A;     break;
            case (Constants::BAM_DNA_C)     : nucleotideCode = Constants::BAM_BASECODE_C;     break;
            case (Constants::BAM_DNA_M)     : nucleotideCode = Constants::BAM_BASECODE_M;     break;
            case (Constants::BAM_DNA_G)     : nucleotideCode = Constants::BAM_BASECODE_G;     break;
            case (Constants::BAM_DNA_R)     : nucleotideCode = Constants::BAM_BASECODE_R;     break;
            case (Constants::BAM_DNA_S)     : nucleotideCode = Constants::BAM_BASECODE_S;     break;
            case (Constants::BAM_DNA_V)     : nucleotideCode = Constants::BAM_BASECODE_V;     break;
            case (Constants::BAM_DNA_T)     : nucleotideCode = Constants::BAM_BASECODE_T;     break;
            case (Constants::BAM_DNA_W)     : nucleotideCode = Constants::BAM_BASECODE_W;     break;
            case (Constants::BAM_DNA_Y)     : nucleotideCode = Constants::BAM_BASECODE_Y;     break;
            case (Constants::BAM_DNA_H)     : nucleotideCode = Constants::BAM_BASECODE_H;     break;
            case (Constants::BAM_DNA_K)     : nucleotideCode = Constants::BAM_BASECODE_K;     break;
            case (Constants::BAM_DNA_D)     : nucleotideCode = Constants::BAM_BASECODE_D;     break;
            case (Constants::BAM_DNA_B)     : nucleotideCode = Constants::BAM_BASECODE_B;     break;
            case (Constants::BAM_DNA_N)     : nucleotideCode = Constants::BAM_BASECODE_N;     break;
            default:
                const string message = string("invalid base: ") + *pQuery;
                throw BamException("BamWriter::EncodeQuerySequence", message);
        }

        // pack the nucleotide code
        if ( useHighWord ) {
            *pEncodedQuery = nucleotideCode << 4;
            useHighWord = false;
        } else {
            *pEncodedQuery |= nucleotideCode;
            ++pEncodedQuery;
            useHighWord = true;
        }

        // increment the query position
        ++pQuery;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x48, %rsp
movq %rdx, %rbx
movq %rsi, %r14
movq 0x8(%rsi), %rsi
incq %rsi
shrq %rsi
movq %rdx, %rdi
xorl %edx, %edx
callq 0x26590
movq (%rbx), %rax
movq (%r14), %rbx
movb $0x1, %cl
leaq 0x190d3(%rip), %rdx     # 0x55cc0
movzbl (%rbx), %esi
leal -0x3d(%rsi), %edi
cmpl $0x1c, %edi
ja 0x3cc6a
movslq (%rdx,%rdi,4), %rsi
addq %rdx, %rsi
jmpq *%rsi
xorl %esi, %esi
jmp 0x3cc4e
movb $0x6, %sil
jmp 0x3cc4e
movb $0xf, %sil
jmp 0x3cc4e
movb $0x8, %sil
jmp 0x3cc4e
movb $0x5, %sil
jmp 0x3cc4e
movb $0x3, %sil
jmp 0x3cc4e
movb $0x7, %sil
jmp 0x3cc4e
movb $0x9, %sil
jmp 0x3cc4e
movb $0xd, %sil
jmp 0x3cc4e
movb $0xa, %sil
jmp 0x3cc4e
movb $0x4, %sil
jmp 0x3cc4e
movb $0xe, %sil
jmp 0x3cc4e
movb $0xc, %sil
jmp 0x3cc4e
movb $0x2, %sil
jmp 0x3cc4e
movb $0x1, %sil
jmp 0x3cc4e
movb $0xb, %sil
testb $0x1, %cl
je 0x3cc5c
shlb $0x4, %sil
movb %sil, (%rax)
jmp 0x3cc62
orb %sil, (%rax)
incq %rax
xorb $0x1, %cl
incq %rbx
jmp 0x3cbed
testl %esi, %esi
jne 0x3cc79
addq $0x48, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x19119(%rip), %rsi     # 0x55da2
leaq 0x19120(%rip), %rdx     # 0x55db0
leaq 0x8(%rsp), %rdi
callq 0x26750
movsbl (%rbx), %edx
leaq 0x28(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x26e90
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0x3ccbb
callq 0x27560
movl $0x28, %edi
callq 0x269d0
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
movq %r15, (%rdi)
leaq 0x190da(%rip), %rsi     # 0x55db1
leaq 0x190f1(%rip), %rdx     # 0x55dcf
callq 0x26750
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
leaq 0x28(%rsp), %rdx
movq %rbx, %rdi
callq 0x28490
xorl %ebp, %ebp
movq 0x2e237(%rip), %rsi     # 0x6af38
movq 0x2e270(%rip), %rdx     # 0x6af78
movq %rbx, %rdi
callq 0x28a30
movq %rax, %r14
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0x3cd2a
callq 0x27560
jmp 0x3cd2a
movq %rax, %r14
movb $0x1, %bpl
testb %bpl, %bpl
je 0x3cd37
movq %rbx, %rdi
callq 0x27070
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0x3cd54
jmp 0x3cd5e
movq %rax, %r14
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0x3cd5e
callq 0x27560
jmp 0x3cd5e
movq %rax, %r14
movq %r14, %rdi
callq 0x28c20