// File: /workspace/github_cpp_makefile_star2_O2/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 %r14
pushq %rbx
subq $0x50, %rsp
movq %rdx, %rbx
movq %rsi, %r14
movq 0x8(%rsi), %rsi
incq %rsi
shrq %rsi
movq %rdx, %rdi
callq 0x34000
movq (%rbx), %rdx
movq (%r14), %rbx
movb $0x1, %al
leaq 0x162dd(%rip), %rcx     # 0x5bd04
movzbl (%rbx), %esi
leal -0x3d(%rsi), %edi
cmpl $0x1c, %edi
ja 0x45aac
movslq (%rcx,%rdi,4), %rsi
addq %rcx, %rsi
jmpq *%rsi
xorl %esi, %esi
jmp 0x45a88
movb $0x6, %sil
jmp 0x45a88
movb $0xf, %sil
jmp 0x45a88
movb $0x8, %sil
jmp 0x45a88
movb $0x5, %sil
jmp 0x45a88
movb $0x3, %sil
jmp 0x45a88
movb $0x7, %sil
jmp 0x45a88
movb $0x9, %sil
jmp 0x45a88
movb $0xd, %sil
jmp 0x45a88
movb $0xa, %sil
jmp 0x45a88
movb $0x4, %sil
jmp 0x45a88
movb $0xe, %sil
jmp 0x45a88
movb $0xc, %sil
jmp 0x45a88
movb $0x2, %sil
jmp 0x45a88
movb $0x1, %sil
jmp 0x45a88
movb $0xb, %sil
testb $0x1, %al
je 0x45a95
shlb $0x4, %sil
movq %rdx, %rdi
jmp 0x45a9c
orb (%rdx), %sil
leaq 0x1(%rdx), %rdi
movb %sil, (%rdx)
xorb $0x1, %al
incq %rbx
movq %rdi, %rdx
jmp 0x45a27
testl %esi, %esi
jne 0x45ab9
addq $0x50, %rsp
popq %rbx
popq %r14
popq %rbp
retq
leaq 0x16316(%rip), %rsi     # 0x5bdd6
leaq 0x10(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x31b30
movsbl (%rbx), %edx
leaq 0x30(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x32560
leaq 0x10(%rsp), %rdi
callq 0x33a00
pushq $0x28
popq %rdi
callq 0x31e70
movq %rax, %rbx
leaq 0x162e8(%rip), %rsi     # 0x5bde5
leaq 0x10(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x31b30
movb $0x1, %bpl
leaq 0x10(%rsp), %rsi
leaq 0x30(%rsp), %rdx
movq %rbx, %rdi
callq 0x344c0
xorl %ebp, %ebp
movq 0x2f40e(%rip), %rsi     # 0x74f38
movq 0x2f447(%rip), %rdx     # 0x74f78
movq %rbx, %rdi
callq 0x34c90
movq %rax, %r14
leaq 0x10(%rsp), %rdi
callq 0x33a00
testb %bpl, %bpl
jne 0x45b50
jmp 0x45b58
movq %rax, %r14
movq %rbx, %rdi
callq 0x327c0
leaq 0x30(%rsp), %rdi
callq 0x33a00
jmp 0x45b7e
movq %rax, %r14
leaq 0x10(%rsp), %rdi
callq 0x33a00
jmp 0x45b7e
movq %rax, %rdi
callq 0x39b2f
movq %rax, %r14
movq %r14, %rdi
callq 0x34ed0