// File: /workspace/github_cpp_makefile_star2_O1/zeeev[P]DASVC/bamtools/src/api/BamAlignment.cpp
// Function: BamTools::BamAlignment::GetSoftClips(std::vector<int, std::allocator<int>>&, std::vector<int, std::allocator<int>>&, std::vector<int, std::allocator<int>>&, bool) const
bool BamAlignment::GetSoftClips(vector<int>& clipSizes,
                                vector<int>& readPositions,
                                vector<int>& genomePositions,
                                bool usePadded) const
{
    // initialize positions & flags
    int refPosition  = Position;
    int readPosition = 0;
    bool softClipFound = false;
    bool firstCigarOp  = true;

    // iterate over cigar operations
    vector<CigarOp>::const_iterator cigarIter = CigarData.begin();
    vector<CigarOp>::const_iterator cigarEnd  = CigarData.end();
    for ( ; cigarIter != cigarEnd; ++cigarIter) {
        const CigarOp& op = (*cigarIter);

        switch ( op.Type ) {

            // increase both read & genome positions on CIGAR chars [DMXN=]
            case Constants::BAM_CIGAR_DEL_CHAR      :
            case Constants::BAM_CIGAR_MATCH_CHAR    :
            case Constants::BAM_CIGAR_MISMATCH_CHAR :
            case Constants::BAM_CIGAR_REFSKIP_CHAR  :
            case Constants::BAM_CIGAR_SEQMATCH_CHAR :
                refPosition  += op.Length;
                readPosition += op.Length;
                break;

            // increase read position on insertion, genome position only if @usePadded is true
            case Constants::BAM_CIGAR_INS_CHAR :
                readPosition += op.Length;
                if ( usePadded )
                    refPosition += op.Length;
                break;

            case Constants::BAM_CIGAR_SOFTCLIP_CHAR :

                softClipFound = true;

                //////////////////////////////////////////////////////////////////////////////
                // if we are dealing with the *first* CIGAR operation
                // for this alignment, we increment the read position so that
                // the read and genome position of the clip are referring to the same base.
                // For example, in the alignment below, the ref position would be 4, yet
                //              the read position would be 0. Thus, to "sync" the two,
                //              we need to increment the read position by the length of the
                //              soft clip.
                // Read:  ATCGTTTCGTCCCTGC
                // Ref:   GGGATTTCGTCCCTGC
                // Cigar: SSSSMMMMMMMMMMMM
                //
                // NOTE: This only needs to be done if the soft clip is the _first_ CIGAR op.
                //////////////////////////////////////////////////////////////////////////////
                if ( firstCigarOp )
                    readPosition += op.Length;

                // track the soft clip's size, read position, and genome position
                clipSizes.push_back(op.Length);
                readPositions.push_back(readPosition);
                genomePositions.push_back(refPosition);

            // any other CIGAR operations have no effect
            default :
                break;
        }

        // clear our "first pass" flag
        firstCigarOp = false;
    }

    // return whether any soft clips found
    return softClipFound;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %r8d, 0x10(%rsp)
movl 0xac(%rdi), %eax
movl %eax, 0xc(%rsp)
movl $0x0, 0x8(%rsp)
movq 0xb8(%rdi), %rbp
movq 0xc0(%rdi), %r13
cmpq %r13, %rbp
je 0x2eac4
movq %rcx, %r14
movq %rdx, %r15
movq %rsi, %r12
movb $0x1, %cl
xorl %eax, %eax
movl $0x8030081, %ebx        # imm = 0x8030081
movzbl (%rbp), %edx
addl $-0x3d, %edx
cmpl $0x1b, %edx
ja 0x2ea08
btl %edx, %ebx
jae 0x2ea18
movl 0x4(%rbp), %ecx
addl %ecx, 0xc(%rsp)
addl %ecx, 0x8(%rsp)
addq $0x8, %rbp
xorl %ecx, %ecx
cmpq %r13, %rbp
jne 0x2e9ec
jmp 0x2eac6
cmpl $0xc, %edx
je 0x2ea4e
cmpl $0x16, %edx
jne 0x2ea08
testb $0x1, %cl
je 0x2ea2e
movl 0x4(%rbp), %eax
addl %eax, 0x8(%rsp)
movl 0x4(%rbp), %eax
movl %eax, 0x14(%rsp)
movq 0x8(%r12), %rsi
cmpq 0x10(%r12), %rsi
je 0x2ea62
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%r12)
jmp 0x2ea6f
movl 0x4(%rbp), %ecx
addl %ecx, 0x8(%rsp)
cmpb $0x0, 0x10(%rsp)
je 0x2ea08
addl %ecx, 0xc(%rsp)
jmp 0x2ea08
movq %r12, %rdi
leaq 0x14(%rsp), %rdx
callq 0x26040
movq 0x8(%r15), %rsi
cmpq 0x10(%r15), %rsi
je 0x2ea89
movl 0x8(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%r15)
jmp 0x2ea96
movq %r15, %rdi
leaq 0x8(%rsp), %rdx
callq 0x26040
movq 0x8(%r14), %rsi
cmpq 0x10(%r14), %rsi
je 0x2eab0
movl 0xc(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%r14)
jmp 0x2eabd
movq %r14, %rdi
leaq 0xc(%rsp), %rdx
callq 0x26040
movb $0x1, %al
jmp 0x2ea08
xorl %eax, %eax
andb $0x1, %al
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop