// File: /workspace/github_cpp_makefile_star2_O2/zeeev[P]DASVC/bamtools/include/api/BamAlignment.h
// Function: bool BamTools::BamAlignment::AddTag<int>(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>> const&, int const&)
inline bool BamAlignment::AddTag(const std::string& tag, const std::string& type, const T& value) {

    // if char data not populated, do that first
    if ( SupportData.HasCoreOnly )
        BuildCharData();

    // check tag/type size
    if ( !IsValidSize(tag, type) ) {
        // TODO: set error string?
        return false;
    }

    // check that storage type code is OK for T
    if ( !TagTypeHelper<T>::CanConvertTo(type.at(0)) ) {
        // 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;

    // if tag already exists, return false
    // use EditTag explicitly instead
    if ( FindTag(tag, pTagData, tagDataLength, numBytesParsed) ) {
        // TODO: set error string?
        return false;
    }

    // otherwise, convert value to string
    union { T value; char valueBuffer[sizeof(T)]; } un;
    un.value = value;

    // copy original tag data to temp buffer
    const std::string newTag = tag + type;
    const size_t newTagDataLength = tagDataLength + newTag.size() + sizeof(T); // leave room for new T
    RaiiBuffer originalTagData(newTagDataLength);
    memcpy(originalTagData.Buffer, TagData.c_str(), tagDataLength + 1);    // '+1' for TagData null-term

    // append newTag
    strcat(originalTagData.Buffer + tagDataLength, newTag.data());
    memcpy(originalTagData.Buffer + tagDataLength + newTag.size(), un.valueBuffer, sizeof(T));

    // store temp buffer back in TagData
    const char* newTagData = (const char*)originalTagData.Buffer;
    TagData.assign(newTagData, newTagDataLength);
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rcx, %r13
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %rbx
cmpb $0x1, 0x130(%rdi)
jne 0x9759
movq %rbx, %rdi
callq 0x11614
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x12248
xorl %r14d, %r14d
testb %al, %al
je 0x986d
movq %r15, %rdi
xorl %esi, %esi
callq 0x5530
cmpb $0x69, (%rax)
jne 0x986d
movq 0x88(%rbx), %rax
leaq 0x50(%rsp), %rdx
movq %rax, (%rdx)
movl 0x90(%rbx), %eax
leaq 0xc(%rsp), %rcx
movl %eax, (%rcx)
leaq 0x2c(%rsp), %r8
andl $0x0, (%r8)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x11aa0
movl %eax, %r14d
testb %al, %al
jne 0x9869
movl (%r13), %eax
movl %eax, 0x8(%rsp)
leaq 0x30(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0xa243
movl 0xc(%rsp), %ebp
movq 0x8(%r13), %rax
movq %rax, 0x10(%rsp)
leaq (%rax,%rbp), %r15
addq $0x4, %r15
movq %r15, %rdi
callq 0x5030
movq %rax, %r12
addq $0x88, %rbx
movq %rax, %rdi
xorl %esi, %esi
movq %r15, %rdx
callq 0x5230
movq %r12, 0x18(%rsp)
movq %r15, 0x20(%rsp)
movq (%rbx), %rsi
leal 0x1(%rbp), %edx
movq %r12, %rdi
callq 0x5360
movq %r12, %r13
addq %rbp, %r13
movq 0x30(%rsp), %rsi
movq %r13, %rdi
callq 0x57e0
movl 0x8(%rsp), %eax
movq 0x10(%rsp), %rcx
movl %eax, (%rcx,%r13)
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x55f0
leaq 0x18(%rsp), %rdi
callq 0xa27c
leaq 0x30(%rsp), %rdi
callq 0x58f8
xorb $0x1, %r14b
movl %r14d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0xa27c
jmp 0x9891
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x58f8
movq %rbx, %rdi
callq 0x57d0
nop