// File: /workspace/github_cpp_makefile_star2_O1/zeeev[P]DASVC/bamtools/src/api/BamAlignment.h
// Function: bool BamTools::BamAlignment::GetTag<unsigned char>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::vector<unsigned char, std::allocator<unsigned char>>&) const
inline bool BamAlignment::GetTag(const std::string& tag, std::vector<T>& destination) const {

    // skip if alignment is core-only
    if ( SupportData.HasCoreOnly ) {
        // TODO: set error string?
        return false;
    }

    // skip if no tags present
    if ( TagData.empty() ) {
        // TODO: set error string?
        return false;
    }

    // localize the tag data
    char* pTagData = (char*)TagData.data();
    const unsigned int tagDataLength = TagData.size();
    unsigned int numBytesParsed = 0;

    // return false if tag not found
    if ( !FindTag(tag, pTagData, tagDataLength, numBytesParsed) ) {
        // TODO: set error string?
        return false;
    }

    // check that tag is array type
    const char tagType = *(pTagData - 1);
    if ( tagType != Constants::BAM_TAG_TYPE_ARRAY ) {
        SetErrorString("BamAlignment::GetTag", "cannot store a non-array tag in array destination");
        return false;
    }

    // fetch element type
    const char elementType = *pTagData;
    if ( !TagTypeHelper<T>::CanConvertFrom(elementType) ) {
        // TODO: set error string ?
        return false;
    }
    ++pTagData;

    // calculate length of each element in tag's array
    int elementLength = 0;
    switch ( elementType ) {
        case (Constants::BAM_TAG_TYPE_ASCII) :
        case (Constants::BAM_TAG_TYPE_INT8)  :
        case (Constants::BAM_TAG_TYPE_UINT8) :
            elementLength = sizeof(uint8_t);
            break;

        case (Constants::BAM_TAG_TYPE_INT16)  :
        case (Constants::BAM_TAG_TYPE_UINT16) :
            elementLength = sizeof(uint16_t);
            break;

        case (Constants::BAM_TAG_TYPE_INT32)  :
        case (Constants::BAM_TAG_TYPE_UINT32) :
        case (Constants::BAM_TAG_TYPE_FLOAT)  :
            elementLength = sizeof(uint32_t);
            break;

        // var-length types not supported for numeric destination
        case (Constants::BAM_TAG_TYPE_STRING) :
        case (Constants::BAM_TAG_TYPE_HEX)    :
        case (Constants::BAM_TAG_TYPE_ARRAY)  :
            SetErrorString("BamAlignment::GetTag",
                           "invalid array data, variable-length elements are not allowed");
            return false;

        // unknown tag type
        default:
            const std::string message = std::string("invalid array element type: ") + elementType;
            SetErrorString("BamAlignment::GetTag", message);
            return false;
    }

    // get number of elements
    int32_t numElements;
    memcpy(&numElements, pTagData, sizeof(int32_t));
    pTagData += 4;
    destination.clear();
    destination.reserve(numElements);

    // read in elements
    T value;
    for ( int i = 0 ; i < numElements; ++i ) {
        memcpy(&value, pTagData, sizeof(T));
        pTagData += sizeof(T);
        destination.push_back(value);
    }

    // return success
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x58, %rsp
cmpb $0x0, 0x130(%rdi)
jne 0x5eb59
movq %rdi, %rbx
movq 0x90(%rdi), %rax
testq %rax, %rax
je 0x5eb59
movq %rdx, %r14
movq 0x88(%rbx), %rcx
leaq 0x8(%rsp), %rdx
movq %rcx, (%rdx)
leaq 0x54(%rsp), %rcx
movl %eax, (%rcx)
leaq 0x50(%rsp), %r8
movl $0x0, (%r8)
movq %rbx, %rdi
callq 0x27710
testb %al, %al
je 0x5eb59
movq 0x8(%rsp), %rax
cmpb $0x42, -0x1(%rax)
jne 0x5eae7
movzbl (%rax), %r15d
movl %r15d, %ecx
andb $-0x3, %cl
cmpb $0x41, %cl
jne 0x5eb59
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rsp)
leal -0x41(%r15), %ecx
cmpl $0x32, %ecx
ja 0x5ebca
movabsq $0x4012400040105, %rdx  # imm = 0x4012400040105
btq %rcx, %rdx
jae 0x5eb66
movl 0x1(%rax), %ebp
movslq %ebp, %rbx
addq $0x5, %rax
movq %rax, 0x8(%rsp)
movq (%r14), %rax
cmpq %rax, 0x8(%r14)
je 0x5ea9b
movq %rax, 0x8(%r14)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x5eccc
testl %ebx, %ebx
jle 0x5eae3
leaq 0x30(%rsp), %rbx
movq 0x8(%rsp), %rcx
movb (%rcx), %al
movb %al, 0x30(%rsp)
incq %rcx
movq %rcx, 0x8(%rsp)
movq 0x8(%r14), %rsi
cmpq 0x10(%r14), %rsi
je 0x5ead4
movb %al, (%rsi)
incq 0x8(%r14)
jmp 0x5eadf
movq %r14, %rdi
movq %rbx, %rdx
callq 0x5ed80
decl %ebp
jne 0x5eaaf
movb $0x1, %al
jmp 0x5eb5b
leaq 0x40(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x14b84(%rip), %rsi     # 0x7367b
leaq 0x14b91(%rip), %rdx     # 0x7368f
leaq 0x30(%rsp), %rdi
callq 0x2f1b2
leaq 0x20(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x17817(%rip), %rsi     # 0x7632f
leaq 0x17841(%rip), %rdx     # 0x76360
leaq 0x10(%rsp), %rdi
callq 0x2f1b2
leaq 0x30(%rsp), %rsi
leaq 0x10(%rsp), %rdx
movq %rbx, %rdi
callq 0x27060
movq 0x10(%rsp), %rdi
cmpq %r15, %rdi
je 0x5eb4a
callq 0x27560
movq 0x30(%rsp), %rdi
cmpq %r14, %rdi
je 0x5eb59
callq 0x27560
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movl $0x2000082, %eax        # imm = 0x2000082
btq %rcx, %rax
jae 0x5ebca
leaq 0x40(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x14afa(%rip), %rsi     # 0x7367b
leaq 0x14b07(%rip), %rdx     # 0x7368f
leaq 0x30(%rsp), %rdi
callq 0x2f1b2
leaq 0x20(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x177bf(%rip), %rsi     # 0x76361
leaq 0x177f4(%rip), %rdx     # 0x7639d
leaq 0x10(%rsp), %rdi
callq 0x2f1b2
leaq 0x30(%rsp), %rsi
leaq 0x10(%rsp), %rdx
movq %rbx, %rdi
callq 0x27060
jmp 0x5eb3b
leaq 0x20(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x177c4(%rip), %rsi     # 0x7639e
leaq 0x177d9(%rip), %rdx     # 0x763ba
leaq 0x10(%rsp), %rdi
callq 0x2f1b2
movsbl %r15b, %edx
leaq 0x30(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x4203c
movq 0x10(%rsp), %rdi
cmpq %r14, %rdi
je 0x5ec0d
callq 0x27560
leaq 0x10(%rsp), %rdi
movq %r14, (%rdi)
leaq 0x14a5f(%rip), %rsi     # 0x7367b
leaq 0x14a6c(%rip), %rdx     # 0x7368f
callq 0x2f1b2
leaq 0x10(%rsp), %rsi
leaq 0x30(%rsp), %rdx
movq %rbx, %rdi
callq 0x27060
movq 0x10(%rsp), %rdi
cmpq %r14, %rdi
je 0x5ec49
callq 0x27560
leaq 0x40(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0x5eb54
jmp 0x5eb59
movq %rax, %rbx
movq 0x10(%rsp), %rdi
cmpq %r14, %rdi
je 0x5ec77
callq 0x27560
jmp 0x5ec77
movq %rax, %rbx
leaq 0x40(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0x5ecba
jmp 0x5ecc4
movq %rax, %rbx
movq 0x10(%rsp), %rdi
jmp 0x5ecb5
jmp 0x5ecc1
jmp 0x5ec99
jmp 0x5ecad
jmp 0x5ecc1
movq %rax, %rbx
movq 0x10(%rsp), %rdi
cmpq %r15, %rdi
je 0x5ecb0
callq 0x27560
jmp 0x5ecb0
movq %rax, %rbx
movq 0x30(%rsp), %rdi
cmpq %r14, %rdi
je 0x5ecc4
callq 0x27560
jmp 0x5ecc4
movq %rax, %rbx
movq %rbx, %rdi
callq 0x27b20