// File: /workspace/github_cpp_makefile_star2_O3/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), %rdx
movq (%r14), %rbx
movb $0x1, %al
leaq 0x19199(%rip), %rcx     # 0x55cc0
movzbl (%rbx), %esi
leal -0x3d(%rsi), %edi
cmpl $0x1c, %edi
ja 0x3cbac
movslq (%rcx,%rdi,4), %rsi
addq %rcx, %rsi
jmpq *%rsi
xorl %esi, %esi
jmp 0x3cb88
movb $0x6, %sil
jmp 0x3cb88
movb $0xf, %sil
jmp 0x3cb88
movb $0x8, %sil
jmp 0x3cb88
movb $0x5, %sil
jmp 0x3cb88
movb $0x3, %sil
jmp 0x3cb88
movb $0x7, %sil
jmp 0x3cb88
movb $0x9, %sil
jmp 0x3cb88
movb $0xd, %sil
jmp 0x3cb88
movb $0xa, %sil
jmp 0x3cb88
movb $0x4, %sil
jmp 0x3cb88
movb $0xe, %sil
jmp 0x3cb88
movb $0xc, %sil
jmp 0x3cb88
movb $0x2, %sil
jmp 0x3cb88
movb $0x1, %sil
jmp 0x3cb88
movb $0xb, %sil
testb $0x1, %al
je 0x3cb95
shlb $0x4, %sil
movq %rdx, %rdi
jmp 0x3cb9c
orb (%rdx), %sil
leaq 0x1(%rdx), %rdi
movb %sil, (%rdx)
xorb $0x1, %al
incq %rbx
movq %rdi, %rdx
jmp 0x3cb27
testl %esi, %esi
jne 0x3cbbb
addq $0x48, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x191d7(%rip), %rsi     # 0x55da2
leaq 0x191de(%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 0x3cbfd
callq 0x27560
movl $0x28, %edi
callq 0x269d0
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
movq %r15, (%rdi)
leaq 0x19198(%rip), %rsi     # 0x55db1
leaq 0x191af(%rip), %rdx     # 0x55dcf
callq 0x26750
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
leaq 0x28(%rsp), %rdx
movq %rbx, %rdi
callq 0x28480
xorl %ebp, %ebp
movq 0x2e2f5(%rip), %rsi     # 0x6af38
movq 0x2e32e(%rip), %rdx     # 0x6af78
movq %rbx, %rdi
callq 0x28a20
movq %rax, %r14
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0x3cc64
callq 0x27560
testb %bpl, %bpl
jne 0x3cc6e
jmp 0x3cc76
movq %rax, %r14
movq %rbx, %rdi
callq 0x27070
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0x3cc93
jmp 0x3cc9d
movq %rax, %r14
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0x3cc9d
callq 0x27560
jmp 0x3cc9d
movq %rax, %r14
movq %r14, %rdi
callq 0x28c10
nop