// File: 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:
subq $0x78, %rsp
movq %rdi, 0x70(%rsp)
movq %rsi, 0x68(%rsp)
movq 0x70(%rsp), %rax
movq %rax, 0x8(%rsp)
testb $0x1, 0x130(%rax)
je 0x8893b
movq 0x8(%rsp), %rdi
callq 0x76980
movq 0x8(%rsp), %rdi
addq $0x88, %rdi
callq 0x7aba0
testb $0x1, %al
jne 0x88952
jmp 0x88957
jmp 0x88af2
movq 0x8(%rsp), %rdi
addq $0x88, %rdi
callq 0x785e0
movq 0x8(%rsp), %rdi
movq %rax, 0x60(%rsp)
movq 0x60(%rsp), %rax
movq %rax, 0x58(%rsp)
addq $0x88, %rdi
callq 0x74cd0
movq 0x8(%rsp), %rdi
movl %eax, 0x54(%rsp)
movl $0x0, 0x50(%rsp)
movl $0x0, 0x4c(%rsp)
movq 0x68(%rsp), %rsi
leaq 0x58(%rsp), %rdx
leaq 0x54(%rsp), %rcx
leaq 0x4c(%rsp), %r8
callq 0x77c80
testb $0x1, %al
jne 0x889c3
jmp 0x88af2
movl 0x54(%rsp), %eax
movl %eax, %esi
leaq 0x38(%rsp), %rdi
callq 0x76550
movq 0x58(%rsp), %rax
addq $-0x3, %rax
movq %rax, 0x58(%rsp)
movl 0x4c(%rsp), %eax
addl $-0x3, %eax
movl %eax, 0x4c(%rsp)
movl 0x4c(%rsp), %eax
movl %eax, 0x34(%rsp)
movl 0x34(%rsp), %ecx
movl 0x50(%rsp), %eax
addl %ecx, %eax
movl %eax, 0x50(%rsp)
movq 0x38(%rsp), %rdi
movq 0x60(%rsp), %rsi
movl 0x4c(%rsp), %eax
movl %eax, %edx
callq 0x757c0
movq 0x8(%rsp), %rdi
movq 0x58(%rsp), %rax
addq $0x2, %rax
movq %rax, 0x28(%rsp)
movq 0x58(%rsp), %rax
addq $0x3, %rax
movq %rax, 0x58(%rsp)
movl 0x4c(%rsp), %eax
addl $0x3, %eax
movl %eax, 0x4c(%rsp)
movq 0x28(%rsp), %rax
movsbl (%rax), %esi
leaq 0x58(%rsp), %rdx
leaq 0x4c(%rsp), %rcx
callq 0x741e0
movb %al, 0x7(%rsp)
jmp 0x88a60
movb 0x7(%rsp), %al
testb $0x1, %al
jne 0x88a6a
jmp 0x88ae8
movl 0x4c(%rsp), %eax
movl 0x34(%rsp), %ecx
subl %ecx, %eax
movl %eax, 0x18(%rsp)
movl 0x54(%rsp), %eax
movl 0x34(%rsp), %ecx
subl %ecx, %eax
movl 0x18(%rsp), %ecx
subl %ecx, %eax
movl %eax, 0x14(%rsp)
movq 0x38(%rsp), %rdi
movl 0x34(%rsp), %eax
addq %rax, %rdi
movq 0x58(%rsp), %rsi
movl 0x14(%rsp), %eax
movl %eax, %edx
callq 0x757c0
movq 0x8(%rsp), %rdi
addq $0x88, %rdi
movq 0x38(%rsp), %rsi
movl 0x34(%rsp), %eax
movl 0x14(%rsp), %ecx
addl %ecx, %eax
movl %eax, %edx
callq 0x78b50
jmp 0x88acc
jmp 0x88ae8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x20(%rsp)
movl %eax, 0x1c(%rsp)
leaq 0x38(%rsp), %rdi
callq 0x7a450
jmp 0x88af7
leaq 0x38(%rsp), %rdi
callq 0x7a450
addq $0x78, %rsp
retq
jmp 0x88af9
movq 0x20(%rsp), %rdi
callq 0x7b550
movq %rax, %rdi
callq 0x88ef0
nopl (%rax,%rax)