// File: /workspace/github_cpp_makefile_star2_O2/zeeev[P]DASVC/bamtools/src/toolkit/bamtools_filter.cpp
// Function: BamTools::BamAlignmentChecker::checkAlignmentTag(BamTools::PropertyFilterValue const&, BamTools::BamAlignment const&)
bool checkAlignmentTag(const PropertyFilterValue& valueFilter, const BamAlignment& al) {
     
        // ensure filter contains string data
        Variant entireTagFilter = valueFilter.Value;
        if ( !entireTagFilter.is_type<string>() ) return false;

        // localize string from variant
        const string& entireTagFilterString = entireTagFilter.get<string>();

        // ensure we have at least "XX:x"
        if ( entireTagFilterString.length() < 4 ) return false;

        // get tagName & lookup in alignment
        // if found, set tagType to tag type character
        // if not found, return false
        const string& tagName = entireTagFilterString.substr(0,2);
        char tagType = '\0';
        if ( !al.GetTagType(tagName, tagType) ) return false;

        // remove tagName & ":" from beginning tagFilter
        string tagFilterString = entireTagFilterString.substr(3);

        // switch on tag type to set tag query value & parse filter token
        int8_t   asciiFilterValue,   asciiQueryValue;
        int32_t  intFilterValue,    intQueryValue;
        uint32_t uintFilterValue,   uintQueryValue;
        float    realFilterValue,   realQueryValue;
        string   stringFilterValue, stringQueryValue;

        PropertyFilterValue tagFilter;
        PropertyFilterValue::ValueCompareType compareType;
        bool keepAlignment = false;
        switch (tagType) {

            // ASCII tag type
            case 'A':
                if ( al.GetTag(tagName, asciiQueryValue) ) {
                    if ( FilterEngine<BamAlignmentChecker>::parseToken(tagFilterString, asciiFilterValue, compareType) ) {
                        tagFilter.Value = asciiFilterValue;
                        tagFilter.Type  = compareType;
                        keepAlignment   = tagFilter.check(asciiQueryValue);
                    }
                }
                break;

            // signed int tag type
            case 'c' :
            case 's' :
            case 'i' :
                if ( al.GetTag(tagName, intQueryValue) ) {
                    if ( FilterEngine<BamAlignmentChecker>::parseToken(tagFilterString, intFilterValue, compareType) ) {
                        tagFilter.Value = intFilterValue;
                        tagFilter.Type  = compareType;
                        keepAlignment   = tagFilter.check(intQueryValue);
                    }
                }
                break;

            // unsigned int tag type
            case 'C' :
            case 'S' :
            case 'I' :
                if ( al.GetTag(tagName, uintQueryValue) ) {
                    if ( FilterEngine<BamAlignmentChecker>::parseToken(tagFilterString, uintFilterValue, compareType) ) {
                        tagFilter.Value = uintFilterValue;
                        tagFilter.Type  = compareType;
                        keepAlignment   = tagFilter.check(uintQueryValue);
                    }
                }
                break;

            // 'real' tag type
            case 'f' :
                if ( al.GetTag(tagName, realQueryValue) ) {
                    if ( FilterEngine<BamAlignmentChecker>::parseToken(tagFilterString, realFilterValue, compareType) ) {
                        tagFilter.Value = realFilterValue;
                        tagFilter.Type  = compareType;
                        keepAlignment   = tagFilter.check(realQueryValue);
                    }
                }
                break;

            // string tag type

            case 'Z':
            case 'H':
                if ( al.GetTag(tagName, stringQueryValue) ) {
                    if ( FilterEngine<BamAlignmentChecker>::parseToken(tagFilterString, stringFilterValue, compareType) ) {
                        tagFilter.Value = stringFilterValue;
                        tagFilter.Type  = compareType;
                        keepAlignment   = tagFilter.check(stringQueryValue);
                    }
                }
                break;

            // unknown tag type
            default :
                keepAlignment = false;
        }

        return keepAlignment;
    }

// Assembly:
pushq %r14
pushq %rbx
subq $0xe8, %rsp
movq %rdx, %r14
movq (%rsi), %rax
testq %rax, %rax
je 0x492d3
incq 0x8(%rax)
leaq 0x28(%rsp), %rdi
movq %rax, (%rdi)
callq 0x43ec6
testb %al, %al
je 0x492f8
movq 0x28(%rsp), %rdi
callq 0x49966
movq %rax, %rbx
cmpq $0x4, 0x18(%rax)
jae 0x492ff
xorl %ebx, %ebx
jmp 0x49699
addq $0x10, %rbx
leaq 0x48(%rsp), %rdi
pushq $0x2
popq %rcx
movq %rbx, %rsi
xorl %edx, %edx
callq 0x35600
leaq 0x17(%rsp), %rdx
movb $0x0, (%rdx)
leaq 0x48(%rsp), %rsi
movq %r14, %rdi
callq 0x35800
testb %al, %al
je 0x49442
leaq 0x68(%rsp), %rdi
pushq $0x3
popq %rdx
pushq $-0x1
popq %rcx
movq %rbx, %rsi
callq 0x35600
leaq 0xb8(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
movb %cl, (%rax)
leaq 0x98(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
leaq 0x8(%rsp), %rdi
andq $0x0, (%rdi)
andq $0x0, 0x18(%rsp)
movl $0x2, 0x20(%rsp)
callq 0x3b1ea
movzbl 0x17(%rsp), %eax
xorl %ebx, %ebx
leal -0x41(%rax), %ecx
cmpl $0x8, %ecx
jbe 0x49449
cmpl $0x53, %eax
je 0x49459
cmpl $0x5a, %eax
je 0x494d1
cmpl $0x63, %eax
je 0x493ca
cmpl $0x66, %eax
je 0x495ee
cmpl $0x69, %eax
je 0x493ca
cmpl $0x73, %eax
jne 0x49661
leaq 0x48(%rsp), %rsi
leaq 0x40(%rsp), %rdx
movq %r14, %rdi
callq 0x4a342
testb %al, %al
je 0x4965f
leaq 0x68(%rsp), %rdi
leaq 0x44(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x418d0
testb %al, %al
je 0x4965f
movl 0x44(%rsp), %esi
leaq 0x8(%rsp), %rdi
callq 0x43e94
leaq 0x18(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x3b1b6
leaq 0x8(%rsp), %rdi
callq 0x3b1ea
movl 0x10(%rsp), %eax
leaq 0x18(%rsp), %rdi
movl %eax, 0x8(%rdi)
leaq 0x40(%rsp), %rsi
callq 0x49012
jmp 0x4965b
xorl %ebx, %ebx
jmp 0x4968f
leaq 0x2875c(%rip), %rax     # 0x71bac
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
leaq 0x48(%rsp), %rsi
leaq 0x38(%rsp), %rdx
movq %r14, %rdi
callq 0x4a3c6
testb %al, %al
je 0x4965f
leaq 0x68(%rsp), %rdi
leaq 0x3c(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x4258e
testb %al, %al
je 0x4965f
movl 0x3c(%rsp), %esi
leaq 0x8(%rsp), %rdi
callq 0x43f16
leaq 0x18(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x3b1b6
leaq 0x8(%rsp), %rdi
callq 0x3b1ea
movl 0x10(%rsp), %eax
leaq 0x18(%rsp), %rdi
movl %eax, 0x8(%rdi)
leaq 0x38(%rsp), %rsi
callq 0x48e32
jmp 0x4965b
leaq 0x48(%rsp), %rsi
leaq 0x88(%rsp), %rdx
movq %r14, %rdi
callq 0x4ac46
testb %al, %al
je 0x4965f
leaq 0x68(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x42bec
testb %al, %al
je 0x4965f
leaq 0xc8(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x35810
leaq 0x8(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0x3b144
leaq 0x18(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x3b1b6
leaq 0x8(%rsp), %rdi
callq 0x3b1ea
leaq 0xc8(%rsp), %rdi
callq 0x35730
movl 0x10(%rsp), %eax
leaq 0x18(%rsp), %rdi
movl %eax, 0x8(%rdi)
leaq 0x88(%rsp), %rsi
callq 0x48f0e
jmp 0x4965b
leaq 0x48(%rsp), %rsi
leaq 0x15(%rsp), %rdx
movq %r14, %rdi
callq 0x49d7e
testb %al, %al
je 0x4965f
leaq 0x68(%rsp), %rdi
leaq 0x16(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x49dea
testb %al, %al
je 0x4965f
movsbl 0x16(%rsp), %esi
leaq 0x8(%rsp), %rdi
callq 0x4a22e
leaq 0x18(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x3b1b6
leaq 0x8(%rsp), %rdi
callq 0x3b1ea
movl 0x10(%rsp), %eax
leaq 0x18(%rsp), %rdi
movl %eax, 0x8(%rdi)
leaq 0x15(%rsp), %rsi
callq 0x4a260
jmp 0x4965b
leaq 0x48(%rsp), %rsi
leaq 0x30(%rsp), %rdx
movq %r14, %rdi
callq 0x4a5da
testb %al, %al
je 0x4965f
leaq 0x68(%rsp), %rdi
leaq 0x34(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x4a684
testb %al, %al
je 0x4965f
movss 0x34(%rsp), %xmm0
leaq 0x8(%rsp), %rdi
callq 0x4aaca
leaq 0x18(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x3b1b6
leaq 0x8(%rsp), %rdi
callq 0x3b1ea
movl 0x10(%rsp), %eax
leaq 0x18(%rsp), %rdi
movl %eax, 0x8(%rdi)
leaq 0x30(%rsp), %rsi
callq 0x4ab06
movl %eax, %ebx
jmp 0x49661
xorl %ebx, %ebx
leaq 0x18(%rsp), %rdi
callq 0x3b1ea
leaq 0x88(%rsp), %rdi
callq 0x35730
leaq 0xa8(%rsp), %rdi
callq 0x35730
leaq 0x68(%rsp), %rdi
callq 0x35730
leaq 0x48(%rsp), %rdi
callq 0x35730
leaq 0x28(%rsp), %rdi
callq 0x3b1ea
movl %ebx, %eax
addq $0xe8, %rsp
popq %rbx
popq %r14
retq
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x3b1ea
jmp 0x4972b
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x3b1ea
jmp 0x4972b
jmp 0x49728
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x3b1ea
jmp 0x49704
jmp 0x49728
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x3b1ea
jmp 0x4972b
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x3b1ea
jmp 0x4972b
jmp 0x49728
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
callq 0x35730
jmp 0x4972b
jmp 0x49728
jmp 0x49728
movq %rax, %rbx
jmp 0x4974f
movq %rax, %rbx
jmp 0x49742
jmp 0x49723
movq %rax, %rbx
jmp 0x49735
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x3b1ea
leaq 0x88(%rsp), %rdi
callq 0x35730
leaq 0xa8(%rsp), %rdi
callq 0x35730
leaq 0x68(%rsp), %rdi
callq 0x35730
jmp 0x49762
jmp 0x49772
jmp 0x4975f
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x35730
jmp 0x49775
jmp 0x49772
jmp 0x49772
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x3b1ea
movq %rbx, %rdi
callq 0x35b50
movq %rax, %rdi
callq 0x3a198
nop