// File: /workspace/github_cpp_makefile_star2_O3/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 0x2ee17
movq %rbx, %rdi
callq 0x276c0
movq 0x90(%rbx), %rbp
testq %rbp, %rbp
je 0x2ef19
movq 0x88(%rbx), %r15
leaq 0x18(%rsp), %rdx
movq %r15, (%rdx)
leaq 0x24(%rsp), %rcx
movl %ebp, (%rcx)
leaq 0xc(%rsp), %r8
movl $0x0, (%r8)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x27c00
testb %al, %al
je 0x2ef19
movl %ebp, %r12d
movq %r12, %rdi
callq 0x26070
movq %rax, %r14
movq %rax, %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x26bc0
leaq 0x18(%rsp), %rax
movq (%rax), %r13
leaq 0xc(%rsp), %rax
movl (%rax), %r12d
leal -0x3(%r12), %edx
movq %r14, 0x10(%rsp)
movq %r14, %rdi
movq %r15, %rsi
movq %rdx, %r14
callq 0x27260
leaq 0x18(%rsp), %rdx
movq %r13, (%rdx)
leaq 0xc(%rsp), %rcx
movl %r12d, (%rcx)
movsbl -0x1(%r13), %esi
movq %rbx, %rdi
callq 0x26ca0
testb %al, %al
je 0x2ef0f
leaq 0x88(%rbx), %r15
movl 0xc(%rsp), %eax
movq %r14, %rcx
movl %ecx, %r13d
subl %eax, %r13d
movl %ebp, %eax
subl %r12d, %eax
leal (%rax,%r13), %edx
addl $0x3, %edx
movq 0x10(%rsp), %r14
movq %r14, %rdi
addq %rcx, %rdi
movq 0x18(%rsp), %rsi
callq 0x27260
addl %ebp, %r13d
movq 0x90(%rbx), %rdx
movq %r15, %rdi
xorl %esi, %esi
movq %r14, %rcx
movq %r13, %r8
callq 0x285a0
movq 0x10(%rsp), %rdi
callq 0x27e60
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2ef2a
movq %rax, %rbx
movq 0x10(%rsp), %rdi
callq 0x27e60
movq %rbx, %rdi
callq 0x28c10
nop