// File: /workspace/github_cpp_makefile_star2_O1/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 $0x48, %rsp
movq %rcx, %r13
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r14
cmpb $0x1, 0x130(%rdi)
jne 0xb653
movq %r14, %rdi
callq 0x16380
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x1729c
testb %al, %al
je 0xb786
movq 0x8(%r15), %rdx
testq %rdx, %rdx
je 0xb799
movq (%r15), %rax
cmpb $0x69, (%rax)
jne 0xb786
movq 0x88(%r14), %rax
leaq 0x40(%rsp), %rdx
movq %rax, (%rdx)
movl 0x90(%r14), %eax
leaq 0x4(%rsp), %rcx
movl %eax, (%rcx)
leaq 0x1c(%rsp), %r8
movl $0x0, (%r8)
movq %r14, %rdi
movq %r12, %rsi
callq 0x1693a
movl %eax, %ebx
testb %al, %al
jne 0xb781
movl (%r13), %eax
movl %eax, (%rsp)
leaq 0x20(%rsp), %rbp
movq %rbp, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0xc1eb
movl 0x4(%rsp), %r13d
movq 0x8(%rbp), %rax
movq %rax, 0x10(%rsp)
leaq (%rax,%r13), %r12
addq $0x4, %r12
movq %r12, %rdi
callq 0x5030
movq %rax, %r15
leaq 0x88(%r14), %rax
movq %rax, 0x8(%rsp)
movq %r15, %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x5240
movq 0x88(%r14), %rsi
leal 0x1(%r13), %edx
movq %r15, %rdi
callq 0x5380
movq %r15, %rbp
addq %r13, %rbp
movq 0x20(%rsp), %rsi
movq %rbp, %rdi
callq 0x57c0
movl (%rsp), %eax
movq 0x10(%rsp), %rcx
movl %eax, (%rcx,%rbp)
movq 0x90(%r14), %rdx
movq 0x8(%rsp), %rdi
xorl %esi, %esi
movq %r15, %rcx
movq %r12, %r8
callq 0x5690
movq %r15, %rdi
callq 0x5590
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xb781
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x5470
xorb $0x1, %bl
jmp 0xb788
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2d99a(%rip), %rdi     # 0x3913a
xorl %esi, %esi
xorl %eax, %eax
callq 0x5650
movq %rax, %rbx
movq %r15, %rdi
callq 0x5590
jmp 0xb7b9
movq %rax, %rbx
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xb7d4
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x5470
movq %rbx, %rdi
callq 0x57b0