// File: zeeev[P]DASVC/bamtools/src/toolkit/bamtools_split.cpp
// Function: BamTools::SplitTool::SplitToolPrivate::SplitTag()
bool SplitTool::SplitToolPrivate::SplitTag(void) {  
  
    // iterate through alignments, until we hit TAG
    BamAlignment al;
    while ( m_reader.GetNextAlignment(al) ) {
      
        // look for tag in this alignment and get tag type
        char tagType(0);
        if ( !al.GetTagType(m_settings->TagToSplit, tagType) )
            continue;
        
        // request split method based on tag type
        // pass it the current alignment found
        switch ( tagType ) {
          
            case (Constants::BAM_TAG_TYPE_INT8)   : return SplitTagImpl<int8_t>(al);
            case (Constants::BAM_TAG_TYPE_INT16)  : return SplitTagImpl<int16_t>(al);
            case (Constants::BAM_TAG_TYPE_INT32)  : return SplitTagImpl<int32_t>(al);
            case (Constants::BAM_TAG_TYPE_UINT8)  : return SplitTagImpl<uint8_t>(al);
            case (Constants::BAM_TAG_TYPE_UINT16) : return SplitTagImpl<uint16_t>(al);
            case (Constants::BAM_TAG_TYPE_UINT32) : return SplitTagImpl<uint32_t>(al);
            case (Constants::BAM_TAG_TYPE_FLOAT)  : return SplitTagImpl<float>(al);
            
            case (Constants::BAM_TAG_TYPE_ASCII)  :
            case (Constants::BAM_TAG_TYPE_STRING) :
            case (Constants::BAM_TAG_TYPE_HEX)    :
                return SplitTagImpl<string>(al);

            case (Constants::BAM_TAG_TYPE_ARRAY) : {

                char arrayTagType(0);
                if (!al.GetArrayTagType(m_settings->TagToSplit, arrayTagType))
                    continue;
                switch(arrayTagType) {
                    case (Constants::BAM_TAG_TYPE_INT8)   : return SplitListTagImpl<int8_t>(al);
                    case (Constants::BAM_TAG_TYPE_INT16)  : return SplitListTagImpl<int16_t>(al);
                    case (Constants::BAM_TAG_TYPE_INT32)  : return SplitListTagImpl<int32_t>(al);
                    case (Constants::BAM_TAG_TYPE_UINT8)  : return SplitListTagImpl<uint8_t>(al);
                    case (Constants::BAM_TAG_TYPE_UINT16) : return SplitListTagImpl<uint16_t>(al);
                    case (Constants::BAM_TAG_TYPE_UINT32) : return SplitListTagImpl<uint32_t>(al);
                    case (Constants::BAM_TAG_TYPE_FLOAT)  : return SplitListTagImpl<float>(al);
                    default:
                        cerr << "bamtools split ERROR: array tag has unsupported element type: " << arrayTagType << endl;
                        return false;
                }
            }
          
            default:
                cerr << "bamtools split ERROR: unknown tag type encountered: " << tagType << endl;
                return false;
        }
    }
    
    // tag not found, but that's not an error - return success
    return true;
}

// Assembly:
subq $0x1d8, %rsp            # imm = 0x1D8
movq %rdi, 0x1c8(%rsp)
movq 0x1c8(%rsp), %rax
movq %rax, 0x50(%rsp)
leaq 0x70(%rsp), %rdi
callq 0x86260
movq 0x50(%rsp), %rdi
addq $0x28, %rdi
leaq 0x70(%rsp), %rsi
callq 0x86bb0
movb %al, 0x4f(%rsp)
jmp 0xe637f
movb 0x4f(%rsp), %al
testb $0x1, %al
jne 0xe638c
jmp 0xe67d9
movq 0x50(%rsp), %rax
movb $0x0, 0x63(%rsp)
movq (%rax), %rsi
addq $0x90, %rsi
leaq 0x70(%rsp), %rdi
leaq 0x63(%rsp), %rdx
callq 0x86a10
movb %al, 0x4e(%rsp)
jmp 0xe63b5
movb 0x4e(%rsp), %al
testb $0x1, %al
jne 0xe63de
jmp 0xe63bf
jmp 0xe6366
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x68(%rsp)
movl %eax, 0x64(%rsp)
leaq 0x70(%rsp), %rdi
callq 0x86b30
jmp 0xe6804
movsbl 0x63(%rsp), %eax
addl $-0x41, %eax
movl %eax, %ecx
movq %rcx, 0x40(%rsp)
subl $0x32, %eax
ja 0xe6786
movq 0x40(%rsp), %rax
leaq 0x4c09a(%rip), %rcx     # 0x13249c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x50(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0xe8630
movb %al, 0x3f(%rsp)
jmp 0xe6420
movb 0x3f(%rsp), %al
andb $0x1, %al
movb %al, 0x1d7(%rsp)
movl $0x1, 0x5c(%rsp)
jmp 0xe67e9
movq 0x50(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0xe9320
movb %al, 0x3e(%rsp)
jmp 0xe644f
movb 0x3e(%rsp), %al
andb $0x1, %al
movb %al, 0x1d7(%rsp)
movl $0x1, 0x5c(%rsp)
jmp 0xe67e9
movq 0x50(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0xea020
movb %al, 0x3d(%rsp)
jmp 0xe647e
movb 0x3d(%rsp), %al
andb $0x1, %al
movb %al, 0x1d7(%rsp)
movl $0x1, 0x5c(%rsp)
jmp 0xe67e9
movq 0x50(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0xeacf0
movb %al, 0x3c(%rsp)
jmp 0xe64ad
movb 0x3c(%rsp), %al
andb $0x1, %al
movb %al, 0x1d7(%rsp)
movl $0x1, 0x5c(%rsp)
jmp 0xe67e9
movq 0x50(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0xeb9e0
movb %al, 0x3b(%rsp)
jmp 0xe64dc
movb 0x3b(%rsp), %al
andb $0x1, %al
movb %al, 0x1d7(%rsp)
movl $0x1, 0x5c(%rsp)
jmp 0xe67e9
movq 0x50(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0xec6e0
movb %al, 0x3a(%rsp)
jmp 0xe650b
movb 0x3a(%rsp), %al
andb $0x1, %al
movb %al, 0x1d7(%rsp)
movl $0x1, 0x5c(%rsp)
jmp 0xe67e9
movq 0x50(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0xed3d0
movb %al, 0x39(%rsp)
jmp 0xe653a
movb 0x39(%rsp), %al
andb $0x1, %al
movb %al, 0x1d7(%rsp)
movl $0x1, 0x5c(%rsp)
jmp 0xe67e9
movq 0x50(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0xee0d0
movb %al, 0x38(%rsp)
jmp 0xe6569
movb 0x38(%rsp), %al
andb $0x1, %al
movb %al, 0x1d7(%rsp)
movl $0x1, 0x5c(%rsp)
jmp 0xe67e9
movq 0x50(%rsp), %rax
movb $0x0, 0x5b(%rsp)
movq (%rax), %rsi
addq $0x90, %rsi
leaq 0x70(%rsp), %rdi
leaq 0x5b(%rsp), %rdx
callq 0x86920
movb %al, 0x37(%rsp)
jmp 0xe65ac
movb 0x37(%rsp), %al
testb $0x1, %al
jne 0xe65bb
jmp 0xe65b6
jmp 0xe6366
movsbl 0x5b(%rsp), %eax
addl $-0x43, %eax
movl %eax, %ecx
movq %rcx, 0x28(%rsp)
subl $0x30, %eax
ja 0xe6731
movq 0x28(%rsp), %rax
leaq 0x4bf89(%rip), %rcx     # 0x132568
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x50(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0xeef40
movb %al, 0x27(%rsp)
jmp 0xe65fd
movb 0x27(%rsp), %al
andb $0x1, %al
movb %al, 0x1d7(%rsp)
movl $0x1, 0x5c(%rsp)
jmp 0xe67e9
movq 0x50(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0xefaa0
movb %al, 0x26(%rsp)
jmp 0xe662c
movb 0x26(%rsp), %al
andb $0x1, %al
movb %al, 0x1d7(%rsp)
movl $0x1, 0x5c(%rsp)
jmp 0xe67e9
movq 0x50(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0xf0600
movb %al, 0x25(%rsp)
jmp 0xe665b
movb 0x25(%rsp), %al
andb $0x1, %al
movb %al, 0x1d7(%rsp)
movl $0x1, 0x5c(%rsp)
jmp 0xe67e9
movq 0x50(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0xf1160
movb %al, 0x24(%rsp)
jmp 0xe668a
movb 0x24(%rsp), %al
andb $0x1, %al
movb %al, 0x1d7(%rsp)
movl $0x1, 0x5c(%rsp)
jmp 0xe67e9
movq 0x50(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0xf1cc0
movb %al, 0x23(%rsp)
jmp 0xe66b9
movb 0x23(%rsp), %al
andb $0x1, %al
movb %al, 0x1d7(%rsp)
movl $0x1, 0x5c(%rsp)
jmp 0xe67e9
movq 0x50(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0xf2820
movb %al, 0x22(%rsp)
jmp 0xe66e8
movb 0x22(%rsp), %al
andb $0x1, %al
movb %al, 0x1d7(%rsp)
movl $0x1, 0x5c(%rsp)
jmp 0xe67e9
movq 0x50(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0xf3380
movb %al, 0x21(%rsp)
jmp 0xe6717
movb 0x21(%rsp), %al
andb $0x1, %al
movb %al, 0x1d7(%rsp)
movl $0x1, 0x5c(%rsp)
jmp 0xe67e9
movq 0x7e8a8(%rip), %rdi     # 0x164fe0
leaq 0x4c847(%rip), %rsi     # 0x132f86
callq 0x86700
movq %rax, 0x18(%rsp)
jmp 0xe674b
movq 0x18(%rsp), %rdi
movsbl 0x5b(%rsp), %esi
callq 0x86890
movq %rax, 0x10(%rsp)
jmp 0xe6761
movq 0x10(%rsp), %rdi
movq 0x7e803(%rip), %rsi     # 0x164f70
callq 0x86770
jmp 0xe6774
movb $0x0, 0x1d7(%rsp)
movl $0x1, 0x5c(%rsp)
jmp 0xe67e9
movq 0x7e853(%rip), %rdi     # 0x164fe0
leaq 0x4c831(%rip), %rsi     # 0x132fc5
callq 0x86700
movq %rax, 0x8(%rsp)
jmp 0xe67a0
movq 0x8(%rsp), %rdi
movsbl 0x63(%rsp), %esi
callq 0x86890
movq %rax, (%rsp)
jmp 0xe67b5
movq (%rsp), %rdi
movq 0x7e7b0(%rip), %rsi     # 0x164f70
callq 0x86770
jmp 0xe67c7
movb $0x0, 0x1d7(%rsp)
movl $0x1, 0x5c(%rsp)
jmp 0xe67e9
movb $0x1, 0x1d7(%rsp)
movl $0x1, 0x5c(%rsp)
leaq 0x70(%rsp), %rdi
callq 0x86b30
movb 0x1d7(%rsp), %al
andb $0x1, %al
addq $0x1d8, %rsp            # imm = 0x1D8
retq
jmp 0xe6806
movq 0x68(%rsp), %rdi
callq 0x86d80
movq %rax, %rdi
callq 0x91290
nopl (%rax,%rax)