// File: /workspace/github_cpp_makefile_star2_O2/zeeev[P]DASVC/bamtools/src/api/BamAlignment.cpp
// Function: BamTools::BamAlignment::RemoveTag(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
void BamAlignment::RemoveTag(const std::string& tag) {
  
    // if char data not populated, do that first
    if ( SupportData.HasCoreOnly )
        BuildCharData();

    // skip if no tags available
    if ( TagData.empty() )
        return;
  
    // localize the tag data
    char* pOriginalTagData = (char*)TagData.data();
    char* pTagData = pOriginalTagData;
    const unsigned int originalTagDataLength = TagData.size();
    unsigned int newTagDataLength = 0;
    unsigned int numBytesParsed = 0;

    // skip if tag not found
    if  ( !FindTag(tag, pTagData, originalTagDataLength, numBytesParsed) )
        return;

    // otherwise, remove it
    RaiiBuffer newTagData(originalTagDataLength);

    // copy original tag data up til desired tag
    pTagData       -= 3;
    numBytesParsed -= 3;
    const unsigned int beginningTagDataLength = numBytesParsed;
    newTagDataLength += beginningTagDataLength;
    memcpy(newTagData.Buffer, pOriginalTagData, numBytesParsed);

    // attemp to skip to next tag
    const char* pTagStorageType = pTagData + 2;
    pTagData       += 3;
    numBytesParsed += 3;
    if ( SkipToNextTag(*pTagStorageType, pTagData, numBytesParsed) ) {

        // squeeze remaining tag data
        const unsigned int skippedDataLength = (numBytesParsed - beginningTagDataLength);
        const unsigned int endTagDataLength = originalTagDataLength - beginningTagDataLength - skippedDataLength;
        memcpy(newTagData.Buffer + beginningTagDataLength, pTagData, endTagDataLength );

        // save modified tag data in alignment
        TagData.assign(newTagData.Buffer, beginningTagDataLength + endTagDataLength);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r14
movq %rdi, %rbx
cmpb $0x1, 0x130(%rdi)
jne 0x39911
movq %rbx, %rdi
callq 0x33140
movq 0x90(%rbx), %r13
testq %r13, %r13
je 0x39a02
movq 0x88(%rbx), %r15
leaq 0x8(%rsp), %rdx
movq %r15, (%rdx)
leaq 0x24(%rsp), %rcx
movl %r13d, (%rcx)
leaq 0x4(%rsp), %r8
andl $0x0, (%r8)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x33910
testb %al, %al
je 0x39a02
movl %r13d, %r12d
movq %r12, %rdi
callq 0x31080
movq %rax, %r14
movq %rax, %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x320d0
movq %r14, 0x10(%rsp)
movq %r12, 0x18(%rsp)
leaq 0x8(%rsp), %rax
movq (%rax), %r12
leaq 0x4(%rsp), %rax
movl (%rax), %ebp
leal -0x3(%rbp), %edx
movq %r14, %rdi
movq %r15, %rsi
movq %rdx, %r15
callq 0x32b40
leaq 0x8(%rsp), %rdx
movq %r12, (%rdx)
leaq 0x4(%rsp), %rcx
movl %ebp, (%rcx)
movsbl -0x1(%r12), %esi
movq %rbx, %rdi
callq 0x32260
testb %al, %al
je 0x399f8
addq $0x88, %rbx
movl 0x4(%rsp), %eax
movq %r15, %rcx
subl %eax, %r15d
movl %r13d, %eax
subl %ebp, %eax
leal (%rax,%r15), %edx
addl $0x3, %edx
movq %r14, %rdi
addq %rcx, %rdi
movq 0x8(%rsp), %rsi
callq 0x32b40
addl %r13d, %r15d
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x33e30
leaq 0x10(%rsp), %rdi
callq 0x34850
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x39a13
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x34850
movq %rbx, %rdi
callq 0x34ed0