// File: 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:
subq $0xe8, %rsp
movq %rdi, 0xe0(%rsp)
movq %rsi, 0xd8(%rsp)
movq %rdx, 0xd0(%rsp)
movq 0xd8(%rsp), %rdi
callq 0x74cd0
movq %rax, 0xc8(%rsp)
movq 0xc8(%rsp), %rax
addq $0x1, %rax
shrq %rax
movq %rax, 0xc0(%rsp)
movq 0xd0(%rsp), %rdi
movq 0xc0(%rsp), %rsi
callq 0x79090
movq 0xd0(%rsp), %rdi
callq 0x785e0
movq %rax, 0xb8(%rsp)
movq 0xd8(%rsp), %rdi
callq 0x785e0
movq %rax, 0xb0(%rsp)
movb $0x1, 0xae(%rsp)
movq 0xb0(%rsp), %rax
cmpb $0x0, (%rax)
je 0xaeafb
movq 0xb0(%rsp), %rax
movsbl (%rax), %eax
addl $-0x3d, %eax
movl %eax, %ecx
movq %rcx, 0x20(%rsp)
subl $0x1c, %eax
ja 0xae916
movq 0x20(%rsp), %rax
leaq 0x3c697(%rip), %rcx     # 0xeaed4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movb $0x0, 0xaf(%rsp)
jmp 0xae9e8
movb $0x1, 0xaf(%rsp)
jmp 0xae9e8
movb $0x2, 0xaf(%rsp)
jmp 0xae9e8
movb $0x3, 0xaf(%rsp)
jmp 0xae9e8
movb $0x4, 0xaf(%rsp)
jmp 0xae9e8
movb $0x5, 0xaf(%rsp)
jmp 0xae9e8
movb $0x6, 0xaf(%rsp)
jmp 0xae9e8
movb $0x7, 0xaf(%rsp)
jmp 0xae9e8
movb $0x8, 0xaf(%rsp)
jmp 0xae9e8
movb $0x9, 0xaf(%rsp)
jmp 0xae9e8
movb $0xa, 0xaf(%rsp)
jmp 0xae9e8
movb $0xb, 0xaf(%rsp)
jmp 0xae9e8
movb $0xc, 0xaf(%rsp)
jmp 0xae9e8
movb $0xd, 0xaf(%rsp)
jmp 0xae9e8
movb $0xe, 0xaf(%rsp)
jmp 0xae9e8
movb $0xf, 0xaf(%rsp)
jmp 0xae9e8
leaq 0x67(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x7b5f0
movq 0x18(%rsp), %rdx
leaq 0x3c71d(%rip), %rsi     # 0xeb04e
leaq 0x68(%rsp), %rdi
callq 0x78e70
jmp 0xae93d
movq 0xb0(%rsp), %rax
movsbl (%rax), %edx
leaq 0x88(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x74830
jmp 0xae95c
leaq 0x68(%rsp), %rdi
callq 0x7cce8
jmp 0xae968
leaq 0x67(%rsp), %rdi
callq 0x76f80
movb $0x1, 0x2e(%rsp)
movl $0x28, %edi
callq 0x737c0
movq %rax, 0x8(%rsp)
leaq 0x2f(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x7b5f0
movq 0x10(%rsp), %rdx
leaq 0x3c6bc(%rip), %rsi     # 0xeb05d
leaq 0x30(%rsp), %rdi
callq 0x78e70
jmp 0xae9ad
movq 0x8(%rsp), %rdi
leaq 0x30(%rsp), %rsi
leaq 0x88(%rsp), %rdx
callq 0x79cd0
jmp 0xae9c6
movq 0x8(%rsp), %rdi
movb $0x0, 0x2e(%rsp)
movq 0x63539(%rip), %rsi     # 0x111f10
movq 0x63582(%rip), %rdx     # 0x111f60
callq 0x7b010
jmp 0xaeb15
testb $0x1, 0xae(%rsp)
je 0xaeaaf
movzbl 0xaf(%rsp), %eax
shll $0x4, %eax
movb %al, %cl
movq 0xb8(%rsp), %rax
movb %cl, (%rax)
movb $0x0, 0xae(%rsp)
jmp 0xaeae2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x58(%rsp)
movl %eax, 0x54(%rsp)
jmp 0xaea46
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x58(%rsp)
movl %eax, 0x54(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x7cce8
jmp 0xaea44
jmp 0xaea46
leaq 0x67(%rsp), %rdi
callq 0x76f80
jmp 0xaeb03
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x58(%rsp)
movl %eax, 0x54(%rsp)
jmp 0xaea81
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x58(%rsp)
movl %eax, 0x54(%rsp)
leaq 0x30(%rsp), %rdi
callq 0x7cce8
jmp 0xaea7f
jmp 0xaea81
leaq 0x2f(%rsp), %rdi
callq 0x76f80
testb $0x1, 0x2e(%rsp)
jne 0xaea94
jmp 0xaea9e
movq 0x8(%rsp), %rdi
callq 0x74e00
leaq 0x88(%rsp), %rdi
callq 0x7cce8
jmp 0xaeaad
jmp 0xaeb03
movzbl 0xaf(%rsp), %edx
movq 0xb8(%rsp), %rax
movsbl (%rax), %ecx
orl %edx, %ecx
movb %cl, (%rax)
movq 0xb8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xb8(%rsp)
movb $0x1, 0xae(%rsp)
movq 0xb0(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xb0(%rsp)
jmp 0xae802
addq $0xe8, %rsp
retq
movq 0x58(%rsp), %rdi
callq 0x7b550
movq %rax, %rdi
callq 0x88ef0
nopw %cs:(%rax,%rax)