// File: /workspace/github_cpp_makefile_star2_O1/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 0x2ee85
movq %rbx, %rdi
callq 0x276c0
movq 0x90(%rbx), %rbp
testq %rbp, %rbp
je 0x2ef8f
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 0x27c10
testb %al, %al
je 0x2ef8f
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), %rcx
movq (%rcx), %r13
leaq -0x3(%r13), %rax
movq %rax, (%rcx)
leaq 0xc(%rsp), %rcx
movl (%rcx), %eax
leal -0x3(%rax), %r12d
movl %r12d, (%rcx)
movq %r14, 0x10(%rsp)
movq %r14, %rdi
movq %rax, %r14
movq %r15, %rsi
movq %r12, %rdx
callq 0x27260
leaq 0x18(%rsp), %rdx
movq %r13, (%rdx)
leaq 0xc(%rsp), %rcx
movl %r14d, (%rcx)
movsbl -0x1(%r13), %esi
movq %rbx, %rdi
callq 0x26ca0
testb %al, %al
je 0x2ef85
leaq 0x88(%rbx), %r15
movl 0xc(%rsp), %eax
movl %r12d, %r13d
subl %eax, %r13d
movl %ebp, %eax
subl %r14d, %eax
leal (%rax,%r13), %edx
addl $0x3, %edx
movq 0x10(%rsp), %r14
movq %r14, %rdi
addq %r12, %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 0x285b0
movq 0x10(%rsp), %rdi
callq 0x27e70
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2efa0
movq %rax, %rbx
movq 0x10(%rsp), %rdi
callq 0x27e70
movq %rbx, %rdi
callq 0x28c20
nop