// File: /workspace/github_cpp_makefile_star2_O2/zeeev[P]DASVC/bamtools/src/api/BamAlignment.cpp
// Function: BamTools::BamAlignment::SkipToNextTag(char, char*&, unsigned int&) const
bool BamAlignment::SkipToNextTag(const char storageType,
                                 char*& pTagData,
                                 unsigned int& numBytesParsed) const
{
    switch (storageType) {

        case (Constants::BAM_TAG_TYPE_ASCII) :
        case (Constants::BAM_TAG_TYPE_INT8)  :
        case (Constants::BAM_TAG_TYPE_UINT8) :
            ++numBytesParsed;
            ++pTagData;
            break;

        case (Constants::BAM_TAG_TYPE_INT16)  :
        case (Constants::BAM_TAG_TYPE_UINT16) :
            numBytesParsed += sizeof(uint16_t);
            pTagData       += sizeof(uint16_t);
            break;

        case (Constants::BAM_TAG_TYPE_FLOAT)  :
        case (Constants::BAM_TAG_TYPE_INT32)  :
        case (Constants::BAM_TAG_TYPE_UINT32) :
            numBytesParsed += sizeof(uint32_t);
            pTagData       += sizeof(uint32_t);
            break;

        case (Constants::BAM_TAG_TYPE_STRING) :
        case (Constants::BAM_TAG_TYPE_HEX)    :
            while( *pTagData ) {
                ++numBytesParsed;
                ++pTagData;
            }
            // increment for null-terminator
            ++numBytesParsed;
            ++pTagData;
            break;

        case (Constants::BAM_TAG_TYPE_ARRAY) :

        {
            // read array type
            const char arrayType = *pTagData;
            ++numBytesParsed;
            ++pTagData;

            // read number of elements
            int32_t numElements;
            memcpy(&numElements, pTagData, sizeof(uint32_t)); // already endian-swapped, if needed
            numBytesParsed += sizeof(uint32_t);
            pTagData       += sizeof(uint32_t);

            // calculate number of bytes to skip
            int bytesToSkip = 0;
            switch (arrayType) {
                case (Constants::BAM_TAG_TYPE_INT8)  :
                case (Constants::BAM_TAG_TYPE_UINT8) :
                    bytesToSkip = numElements;
                    break;
                case (Constants::BAM_TAG_TYPE_INT16)  :
                case (Constants::BAM_TAG_TYPE_UINT16) :
                    bytesToSkip = numElements*sizeof(uint16_t);
                    break;
                case (Constants::BAM_TAG_TYPE_FLOAT)  :
                case (Constants::BAM_TAG_TYPE_INT32)  :
                case (Constants::BAM_TAG_TYPE_UINT32) :
                    bytesToSkip = numElements*sizeof(uint32_t);
                    break;
                default:
                    const string message = string("invalid binary array type: ") + arrayType;
                    SetErrorString("BamAlignment::SkipToNextTag", message);
                    return false;
            }

            // skip binary array contents
            numBytesParsed += bytesToSkip;
            pTagData       += bytesToSkip;
            break;
        }

        default:
            const string message = string("invalid tag type: ") + storageType;
            SetErrorString("BamAlignment::SkipToNextTag", message);
            return false;
    }

    // if we get here, tag skipped OK - return success
    return true;
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x48, %rsp
movl %esi, %r14d
movq %rdi, %rbx
leal -0x41(%r14), %eax
cmpl $0x8, %eax
jbe 0x391e4
cmpl $0x53, %r14d
je 0x3922b
cmpl $0x5a, %r14d
je 0x3920a
cmpl $0x73, %r14d
je 0x3922b
cmpl $0x66, %r14d
je 0x391fe
cmpl $0x69, %r14d
je 0x391fe
cmpl $0x63, %r14d
je 0x391f4
jmp 0x39237
leaq 0x21e59(%rip), %rsi     # 0x5b044
movslq (%rsi,%rax,4), %rax
addq %rsi, %rax
jmpq *%rax
incl (%rcx)
incq (%rdx)
jmp 0x3931c
addl $0x4, (%rcx)
addq $0x4, (%rdx)
jmp 0x3931c
movq (%rdx), %rax
movl (%rcx), %esi
incl %esi
incq %rax
cmpb $0x0, -0x1(%rax)
movl %esi, (%rcx)
leal 0x1(%rsi), %esi
movq %rax, (%rdx)
leaq 0x1(%rax), %rax
jne 0x39214
jmp 0x3931c
addl $0x2, (%rcx)
addq $0x2, (%rdx)
jmp 0x3931c
leaq 0x21e94(%rip), %rsi     # 0x5b0d2
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x31b30
movsbl %r14b, %edx
leaq 0x28(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x32560
leaq 0x8(%rsp), %rdi
callq 0x33a00
leaq 0x21e8d(%rip), %rsi     # 0x5b0fe
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x31b30
leaq 0x8(%rsp), %rsi
leaq 0x28(%rsp), %rdx
movq %rbx, %rdi
callq 0x31120
leaq 0x8(%rsp), %rdi
callq 0x33a00
leaq 0x28(%rsp), %rdi
callq 0x33a00
xorl %eax, %eax
jmp 0x3931e
movq (%rdx), %rax
movzbl (%rax), %r14d
movl (%rcx), %esi
leal 0x1(%rsi), %edi
movl %edi, (%rcx)
leaq 0x1(%rax), %rdi
movq %rdi, (%rdx)
movl 0x1(%rax), %edi
addl $0x5, %esi
movl %esi, (%rcx)
addq $0x5, %rax
movq %rax, (%rdx)
leal -0x43(%r14), %r8d
cmpl $0x30, %r8d
ja 0x39326
movabsq $0x4800000040, %r9      # imm = 0x4800000040
btq %r8, %r9
jb 0x3930c
movabsq $0x100000001, %r9       # imm = 0x100000001
btq %r8, %r9
jb 0x3930f
movabsq $0x1000000010000, %r9   # imm = 0x1000000010000
btq %r8, %r9
jae 0x39326
addl %edi, %edi
jmp 0x3930f
shll $0x2, %edi
addl %edi, %esi
movl %esi, (%rcx)
movslq %edi, %rcx
addq %rcx, %rax
movq %rax, (%rdx)
movb $0x1, %al
addq $0x48, %rsp
popq %rbx
popq %r14
retq
leaq 0x21d89(%rip), %rsi     # 0x5b0b6
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x31b30
movsbl %r14b, %edx
leaq 0x28(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x32560
leaq 0x8(%rsp), %rdi
callq 0x33a00
leaq 0x21d9e(%rip), %rsi     # 0x5b0fe
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x31b30
leaq 0x8(%rsp), %rsi
leaq 0x28(%rsp), %rdx
movq %rbx, %rdi
callq 0x31120
leaq 0x8(%rsp), %rdi
callq 0x33a00
jmp 0x3929c
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x33a00
jmp 0x393b1
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x33a00
jmp 0x393ef
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x33a00
jmp 0x393ef
jmp 0x393ec
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x33a00
jmp 0x393e0
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x33a00
jmp 0x393ef
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x33a00
jmp 0x393ef
movq %rax, %rbx
movq %rbx, %rdi
callq 0x34ed0
movq %rax, %rdi
callq 0x39b2f
nop