// File: zeeev[P]DASVC/bamtools/src/api/internal/bam/BamWriter_p.cpp
// Function: BamTools::Internal::BamWriterPrivate::CreatePackedCigar(std::vector<BamTools::CigarOp, std::allocator<BamTools::CigarOp>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&)
void BamWriterPrivate::CreatePackedCigar(const vector<CigarOp>& cigarOperations, string& packedCigar) {

    // initialize
    const size_t numCigarOperations = cigarOperations.size();
    packedCigar.resize(numCigarOperations * Constants::BAM_SIZEOF_INT);

    // pack the cigar data into the string
    unsigned int* pPackedCigar = (unsigned int*)packedCigar.data();

    // iterate over cigar operations
    vector<CigarOp>::const_iterator coIter = cigarOperations.begin();
    vector<CigarOp>::const_iterator coEnd  = cigarOperations.end();
    for ( ; coIter != coEnd; ++coIter ) {

        // store op in packedCigar
        uint8_t cigarOp;
        switch ( coIter->Type ) {
            case (Constants::BAM_CIGAR_MATCH_CHAR)    : cigarOp = Constants::BAM_CIGAR_MATCH;    break;
            case (Constants::BAM_CIGAR_INS_CHAR)      : cigarOp = Constants::BAM_CIGAR_INS;      break;
            case (Constants::BAM_CIGAR_DEL_CHAR)      : cigarOp = Constants::BAM_CIGAR_DEL;      break;
            case (Constants::BAM_CIGAR_REFSKIP_CHAR)  : cigarOp = Constants::BAM_CIGAR_REFSKIP;  break;
            case (Constants::BAM_CIGAR_SOFTCLIP_CHAR) : cigarOp = Constants::BAM_CIGAR_SOFTCLIP; break;
            case (Constants::BAM_CIGAR_HARDCLIP_CHAR) : cigarOp = Constants::BAM_CIGAR_HARDCLIP; break;
            case (Constants::BAM_CIGAR_PAD_CHAR)      : cigarOp = Constants::BAM_CIGAR_PAD;      break;
            case (Constants::BAM_CIGAR_SEQMATCH_CHAR) : cigarOp = Constants::BAM_CIGAR_SEQMATCH; break;
            case (Constants::BAM_CIGAR_MISMATCH_CHAR) : cigarOp = Constants::BAM_CIGAR_MISMATCH; break;
            default:
                const string message = string("invalid CIGAR operation type") + coIter->Type;
                throw BamException("BamWriter::CreatePackedCigar", message);
        }

        *pPackedCigar = coIter->Length << Constants::BAM_CIGAR_SHIFT | cigarOp;
        pPackedCigar++;
    }
}

// Assembly:
subq $0xe8, %rsp
movq %rdi, 0xe0(%rsp)
movq %rsi, 0xd8(%rsp)
movq %rdx, 0xd0(%rsp)
movq 0xd8(%rsp), %rdi
callq 0x73970
movq %rax, 0xc8(%rsp)
movq 0xd0(%rsp), %rdi
movq 0xc8(%rsp), %rsi
shlq $0x2, %rsi
callq 0x79090
movq 0xd0(%rsp), %rdi
callq 0x785e0
movq %rax, 0xc0(%rsp)
movq 0xd8(%rsp), %rdi
callq 0x75e20
movq %rax, 0xb8(%rsp)
movq 0xd8(%rsp), %rdi
callq 0x76450
movq %rax, 0xb0(%rsp)
leaq 0xb8(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x75bf0
testb $0x1, %al
jne 0xae4ea
jmp 0xae755
leaq 0xb8(%rsp), %rdi
callq 0x72e10
movsbl (%rax), %eax
addl $-0x3d, %eax
movl %eax, %ecx
movq %rcx, 0x20(%rsp)
subl $0x1b, %eax
ja 0xae597
movq 0x20(%rsp), %rax
leaq 0x3c94b(%rip), %rcx     # 0xeae64
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movb $0x0, 0xaf(%rsp)
jmp 0xae677
movb $0x1, 0xaf(%rsp)
jmp 0xae677
movb $0x2, 0xaf(%rsp)
jmp 0xae677
movb $0x3, 0xaf(%rsp)
jmp 0xae677
movb $0x4, 0xaf(%rsp)
jmp 0xae677
movb $0x5, 0xaf(%rsp)
jmp 0xae677
movb $0x6, 0xaf(%rsp)
jmp 0xae677
movb $0x7, 0xaf(%rsp)
jmp 0xae677
movb $0x8, 0xaf(%rsp)
jmp 0xae677
leaq 0x67(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x7b5f0
movq 0x18(%rsp), %rdx
leaq 0x3ca62(%rip), %rsi     # 0xeb014
leaq 0x68(%rsp), %rdi
callq 0x78e70
jmp 0xae5be
leaq 0xb8(%rsp), %rdi
callq 0x72e10
movq %rax, 0x10(%rsp)
jmp 0xae5d2
movq 0x10(%rsp), %rax
movsbl (%rax), %edx
leaq 0x88(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x74830
jmp 0xae5ee
leaq 0x68(%rsp), %rdi
callq 0x7cce8
jmp 0xae5fa
leaq 0x67(%rsp), %rdi
callq 0x76f80
movb $0x1, 0x2e(%rsp)
movl $0x28, %edi
callq 0x737c0
movq %rax, (%rsp)
leaq 0x2f(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x7b5f0
movq 0x8(%rsp), %rdx
leaq 0x3c9ff(%rip), %rsi     # 0xeb031
leaq 0x30(%rsp), %rdi
callq 0x78e70
jmp 0xae63e
movq (%rsp), %rdi
leaq 0x30(%rsp), %rsi
leaq 0x88(%rsp), %rdx
callq 0x79cd0
jmp 0xae656
movq (%rsp), %rdi
movb $0x0, 0x2e(%rsp)
movq 0x638aa(%rip), %rsi     # 0x111f10
movq 0x638f3(%rip), %rdx     # 0x111f60
callq 0x7b010
jmp 0xae76f
leaq 0xb8(%rsp), %rdi
callq 0x72e10
movl 0x4(%rax), %ecx
shll $0x4, %ecx
movzbl 0xaf(%rsp), %eax
orl %eax, %ecx
movq 0xc0(%rsp), %rax
movl %ecx, (%rax)
movq 0xc0(%rsp), %rax
addq $0x4, %rax
movq %rax, 0xc0(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0x72bc0
jmp 0xae4cc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x58(%rsp)
movl %eax, 0x54(%rsp)
jmp 0xae6f0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x58(%rsp)
movl %eax, 0x54(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x7cce8
jmp 0xae6ee
jmp 0xae6f0
leaq 0x67(%rsp), %rdi
callq 0x76f80
jmp 0xae75d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x58(%rsp)
movl %eax, 0x54(%rsp)
jmp 0xae728
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x58(%rsp)
movl %eax, 0x54(%rsp)
leaq 0x30(%rsp), %rdi
callq 0x7cce8
jmp 0xae726
jmp 0xae728
leaq 0x2f(%rsp), %rdi
callq 0x76f80
testb $0x1, 0x2e(%rsp)
jne 0xae73b
jmp 0xae744
movq (%rsp), %rdi
callq 0x74e00
leaq 0x88(%rsp), %rdi
callq 0x7cce8
jmp 0xae753
jmp 0xae75d
addq $0xe8, %rsp
retq
movq 0x58(%rsp), %rdi
callq 0x7b550
movq %rax, %rdi
callq 0x88ef0
nop