// File: tedsharpe[P]ORFCall/ORFCall.cc
// Function: (anonymous namespace)::ORFCaller::findIndels((anonymous namespace)::Alignment const&, std::vector<unsigned char, std::allocator<unsigned char>> const&, std::vector<unsigned char, std::allocator<unsigned char>> const&)
ReadReport ORFCaller::findIndels( Alignment const& aln,
                                  Sequence const& seq,
                                  Quals const& quals )
{
    Sequence const& ref = mRef.getRef();
    Offset refStart = aln.getRefStart()-std::min(aln.getRefStart(),SW_REF_PAD);
    Sequence::const_iterator refItr(ref.begin()+refStart);
    Sequence::const_iterator refEnd(ref.begin()+
                std::min(aln.getRefEnd()+SW_REF_PAD,ref.size()));
    Sequence::const_iterator seqItr, seqEnd;
    Quals::const_iterator qualItr;

    if ( !aln.isReadRC() )
    {
        seqItr = seq.begin() + aln.getReadStart();
        seqEnd = seq.begin() + aln.getReadEnd();
        qualItr = seq.begin() + aln.getReadStart();
    }
    else
    {
        mSeqTmp.clear();
        mSeqTmp.reserve(seq.size());
        for ( auto itr = seq.rbegin(), end = seq.rend(); itr != end; ++itr )
            mSeqTmp.push_back(complement(*itr));
        seqItr = mSeqTmp.begin() + aln.getReadStart();
        seqEnd = mSeqTmp.begin() + aln.getReadEnd();
        mQualsTmp = quals;
        std::reverse(mQualsTmp.begin(),mQualsTmp.end());
        qualItr = mQualsTmp.begin() + aln.getReadStart();
    }

    auto const& blocks = mSW.align(seqItr,seqEnd,refItr,refEnd);
    auto blkItr = blocks.begin();
    if ( blkItr->mDir == SmithWatermanizer::Trace::UP )
    {
        refStart += blkItr->mLen;
        refItr += blkItr->mLen;
        ++blkItr;
    }

    AlignmentScorer alignmentScorer(mRef,refStart,mMinQ);
    std::vector<Variation> indels;
    for ( auto blkEnd(blocks.end()); blkItr != blkEnd; ++blkItr )
    {
        unsigned nnn = blkItr->mLen;
        switch ( blkItr->mDir )
        {
        case SmithWatermanizer::Trace::UP:
            if ( alignmentScorer.inORF() &&
                    qualItr[-1] >= mMinQ && qualItr[0] >= mMinQ )
                indels.push_back(Variation{VariationType::DELETION,
                                            alignmentScorer.getCodonIdx(),
                                            nnn});
            while ( nnn-- )
            {
                alignmentScorer(*refItr,NCALL,0);
                ++refItr;
            }
            break;
        case SmithWatermanizer::Trace::LEFT:
            {
                bool loQ = false;
                while ( nnn-- )
                {
                    if ( *qualItr < mMinQ )
                        loQ = true;
                    ++seqItr; ++qualItr;
                }
                if ( !loQ && alignmentScorer.inORF() )
                    indels.push_back(Variation{VariationType::INSERTION,
                                                alignmentScorer.getCodonIdx(),
                                                blkItr->mLen});
            }
            break;
        case SmithWatermanizer::Trace::DIAG:
            while ( nnn-- )
            {
                alignmentScorer(*refItr,*seqItr,*qualItr);
                ++refItr; ++seqItr; ++qualItr;
            }
            break;
        case SmithWatermanizer::Trace::DONE:
            FatalErr("found DONE block in traceback");
        }
    }
    ReadReport report = alignmentScorer.getReport();
    report.mVariations.insert(report.mVariations.end(),
                                    indels.begin(),indels.end());
    return report;
}

// Assembly:
subq $0x308, %rsp            # imm = 0x308
movq %rdi, 0x78(%rsp)
movq %rdi, %rax
movq %rax, 0x80(%rsp)
movq %rdi, 0x300(%rsp)
movq %rsi, 0x2f8(%rsp)
movq %rdx, 0x2f0(%rsp)
movq %rcx, 0x2e8(%rsp)
movq %r8, 0x2e0(%rsp)
movq 0x2f8(%rsp), %rax
movq %rax, 0x88(%rsp)
movq (%rax), %rdi
callq 0xf250
movq %rax, 0x2d8(%rsp)
movq 0x2f0(%rsp), %rdi
callq 0xef90
movq %rax, 0x90(%rsp)
movq 0x2f0(%rsp), %rdi
callq 0xef90
movq %rax, 0x2c8(%rsp)
leaq 0x2c8(%rsp), %rdi
leaq 0x12fb8(%rip), %rsi     # 0x212a0
callq 0x17a30
movq %rax, %rcx
movq 0x90(%rsp), %rax
subq (%rcx), %rax
movq %rax, 0x2d0(%rsp)
movq 0x2d8(%rsp), %rdi
callq 0x1dc60
movq %rax, 0x2b8(%rsp)
movq 0x2d0(%rsp), %rsi
leaq 0x2b8(%rsp), %rdi
callq 0x1a140
movq %rax, 0x2c0(%rsp)
movq 0x2d8(%rsp), %rdi
callq 0x1dc60
movq %rax, 0x2a8(%rsp)
movq 0x2f0(%rsp), %rdi
callq 0xf260
addq $0x5, %rax
movq %rax, 0x2a0(%rsp)
movq 0x2d8(%rsp), %rdi
callq 0x17530
movq %rax, 0x298(%rsp)
leaq 0x2a0(%rsp), %rdi
leaq 0x298(%rsp), %rsi
callq 0x17a30
movq (%rax), %rsi
leaq 0x2a8(%rsp), %rdi
callq 0x1a140
movq %rax, 0x2b0(%rsp)
leaq 0x290(%rsp), %rdi
callq 0x1e610
leaq 0x288(%rsp), %rdi
callq 0x1e610
leaq 0x280(%rsp), %rdi
callq 0x1e610
movq 0x2f0(%rsp), %rdi
callq 0xf270
testb $0x1, %al
jne 0xe4c4
movq 0x2e8(%rsp), %rdi
callq 0x1dc60
movq %rax, 0x270(%rsp)
movq 0x2f0(%rsp), %rdi
callq 0xf280
movq %rax, %rsi
leaq 0x270(%rsp), %rdi
callq 0x1a140
movq %rax, 0x278(%rsp)
movq 0x278(%rsp), %rax
movq %rax, 0x290(%rsp)
movq 0x2e8(%rsp), %rdi
callq 0x1dc60
movq %rax, 0x260(%rsp)
movq 0x2f0(%rsp), %rdi
callq 0x105d0
movq %rax, %rsi
leaq 0x260(%rsp), %rdi
callq 0x1a140
movq %rax, 0x268(%rsp)
movq 0x268(%rsp), %rax
movq %rax, 0x288(%rsp)
movq 0x2e8(%rsp), %rdi
callq 0x1dc60
movq %rax, 0x250(%rsp)
movq 0x2f0(%rsp), %rdi
callq 0xf280
movq %rax, %rsi
leaq 0x250(%rsp), %rdi
callq 0x1a140
movq %rax, 0x258(%rsp)
movq 0x258(%rsp), %rax
movq %rax, 0x280(%rsp)
jmp 0xe71c
movq 0x88(%rsp), %rdi
addq $0x58, %rdi
callq 0x1cf00
movq 0x88(%rsp), %rax
addq $0x58, %rax
movq %rax, 0x70(%rsp)
movq 0x2e8(%rsp), %rdi
callq 0x17530
movq 0x70(%rsp), %rdi
movq %rax, %rsi
callq 0x17370
movq 0x2e8(%rsp), %rsi
leaq 0x248(%rsp), %rdi
callq 0x1e2c0
movq 0x2e8(%rsp), %rsi
leaq 0x240(%rsp), %rdi
callq 0x1e630
leaq 0x248(%rsp), %rdi
leaq 0x240(%rsp), %rsi
callq 0x1e680
testb $0x1, %al
jne 0xe545
jmp 0xe593
movq 0x88(%rsp), %rax
addq $0x58, %rax
movq %rax, 0x68(%rsp)
leaq 0x248(%rsp), %rdi
callq 0x1e360
movzbl (%rax), %edi
callq 0xa980
movq 0x68(%rsp), %rdi
movb %al, 0x23f(%rsp)
leaq 0x23f(%rsp), %rsi
callq 0x17500
leaq 0x248(%rsp), %rdi
callq 0x1e390
jmp 0xe52a
movq 0x88(%rsp), %rdi
addq $0x58, %rdi
callq 0x175e0
movq %rax, 0x220(%rsp)
movq 0x2f0(%rsp), %rdi
callq 0xf280
movq %rax, %rsi
leaq 0x220(%rsp), %rdi
callq 0x17610
movq %rax, 0x228(%rsp)
leaq 0x230(%rsp), %rdi
leaq 0x228(%rsp), %rsi
callq 0x17790
movq 0x88(%rsp), %rdi
movq 0x230(%rsp), %rax
movq %rax, 0x290(%rsp)
addq $0x58, %rdi
callq 0x175e0
movq %rax, 0x208(%rsp)
movq 0x2f0(%rsp), %rdi
callq 0x105d0
movq %rax, %rsi
leaq 0x208(%rsp), %rdi
callq 0x17610
movq %rax, 0x210(%rsp)
leaq 0x218(%rsp), %rdi
leaq 0x210(%rsp), %rsi
callq 0x17790
movq 0x88(%rsp), %rdi
movq 0x218(%rsp), %rax
movq %rax, 0x288(%rsp)
movq 0x2e0(%rsp), %rsi
addq $0x70, %rdi
callq 0x1e6b0
movq 0x88(%rsp), %rdi
addq $0x70, %rdi
callq 0x175e0
movq 0x88(%rsp), %rdi
movq %rax, 0x200(%rsp)
addq $0x70, %rdi
callq 0x177d0
movq %rax, 0x1f8(%rsp)
movq 0x200(%rsp), %rdi
movq 0x1f8(%rsp), %rsi
callq 0x1e950
movq 0x88(%rsp), %rdi
addq $0x70, %rdi
callq 0x175e0
movq %rax, 0x1e0(%rsp)
movq 0x2f0(%rsp), %rdi
callq 0xf280
movq %rax, %rsi
leaq 0x1e0(%rsp), %rdi
callq 0x17610
movq %rax, 0x1e8(%rsp)
leaq 0x1f0(%rsp), %rdi
leaq 0x1e8(%rsp), %rsi
callq 0x17790
movq 0x1f0(%rsp), %rax
movq %rax, 0x280(%rsp)
movq 0x88(%rsp), %rdi
addq $0x88, %rdi
movq 0x290(%rsp), %rax
movq %rax, 0x1d0(%rsp)
movq 0x288(%rsp), %rax
movq %rax, 0x1c8(%rsp)
movq 0x2c0(%rsp), %rax
movq %rax, 0x1c0(%rsp)
movq 0x2b0(%rsp), %rax
movq %rax, 0x1b8(%rsp)
movq 0x1d0(%rsp), %rsi
movq 0x1c8(%rsp), %rdx
movq 0x1c0(%rsp), %rcx
movq 0x1b8(%rsp), %r8
xorl %eax, %eax
movl %eax, %r9d
callq 0x105f0
movq %rax, 0x1d8(%rsp)
movq 0x1d8(%rsp), %rdi
callq 0x106c0
movq %rax, 0x1b0(%rsp)
leaq 0x1b0(%rsp), %rdi
callq 0x106f0
cmpb $0x1, (%rax)
jne 0xe810
leaq 0x1b0(%rsp), %rdi
callq 0x106f0
movl 0x4(%rax), %eax
addq 0x2d0(%rsp), %rax
movq %rax, 0x2d0(%rsp)
leaq 0x1b0(%rsp), %rdi
callq 0x106f0
movl 0x4(%rax), %eax
movl %eax, %esi
leaq 0x2c0(%rsp), %rdi
callq 0x17870
leaq 0x1b0(%rsp), %rdi
callq 0x10700
movq 0x88(%rsp), %rax
movq (%rax), %rsi
movq 0x2d0(%rsp), %rdx
leaq 0x138(%rsp), %rdi
movzbl 0x8(%rax), %ecx
callq 0xefa0
leaq 0x120(%rsp), %rdi
callq 0xf560
movq 0x1d8(%rsp), %rdi
callq 0x10720
movq %rax, 0x118(%rsp)
leaq 0x1b0(%rsp), %rdi
leaq 0x118(%rsp), %rsi
callq 0x10750
testb $0x1, %al
jne 0xe874
jmp 0xebdc
leaq 0x1b0(%rsp), %rdi
movq %rdi, 0x58(%rsp)
callq 0x106f0
movq 0x58(%rsp), %rdi
movl 0x4(%rax), %eax
movl %eax, 0x114(%rsp)
callq 0x106f0
movzbl (%rax), %eax
movq %rax, 0x60(%rsp)
subq $0x3, %rax
ja 0xebc8
movq 0x60(%rsp), %rax
leaq 0x129d0(%rip), %rcx     # 0x21288
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x138(%rsp), %rdi
callq 0x10790
movb %al, 0x57(%rsp)
jmp 0xe8d4
movb 0x57(%rsp), %al
testb $0x1, %al
jne 0xe8e1
jmp 0xe9a9
leaq 0x280(%rsp), %rdi
movq $-0x1, %rsi
callq 0x18de0
movq 0x88(%rsp), %rcx
movzbl (%rax), %eax
movzbl 0x8(%rcx), %ecx
cmpl %ecx, %eax
jl 0xe9a9
leaq 0x280(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x18de0
movq 0x88(%rsp), %rcx
movzbl (%rax), %eax
movzbl 0x8(%rcx), %ecx
cmpl %ecx, %eax
jl 0xe9a9
movl $0x2, 0xe8(%rsp)
leaq 0xf0(%rsp), %rax
movq %rax, 0x40(%rsp)
leaq 0x138(%rsp), %rdi
callq 0x107b0
movq %rax, 0x48(%rsp)
jmp 0xe95c
movq 0x40(%rsp), %rax
movq 0x48(%rsp), %rcx
movq %rcx, (%rax)
movl 0x114(%rsp), %eax
movl %eax, 0xf8(%rsp)
leaq 0x120(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
callq 0xf840
jmp 0xe98e
jmp 0xe9a9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x108(%rsp)
movl %eax, 0x104(%rsp)
jmp 0xecf0
jmp 0xe9ab
movl 0x114(%rsp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, 0x114(%rsp)
cmpl $0x0, %eax
je 0xe9f8
leaq 0x2c0(%rsp), %rdi
callq 0x1a180
movzbl (%rax), %esi
leaq 0x138(%rsp), %rdi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0xf290
jmp 0xe9e9
leaq 0x2c0(%rsp), %rdi
callq 0x19f60
jmp 0xe9ab
jmp 0xebc8
movb $0x0, 0xe7(%rsp)
movl 0x114(%rsp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, 0x114(%rsp)
cmpl $0x0, %eax
je 0xea61
leaq 0x280(%rsp), %rdi
callq 0x1a180
movq 0x88(%rsp), %rcx
movzbl (%rax), %eax
movzbl 0x8(%rcx), %ecx
cmpl %ecx, %eax
jge 0xea45
movb $0x1, 0xe7(%rsp)
leaq 0x290(%rsp), %rdi
callq 0x19f60
leaq 0x280(%rsp), %rdi
callq 0x19f60
jmp 0xea05
testb $0x1, 0xe7(%rsp)
jne 0xeaf5
leaq 0x138(%rsp), %rdi
callq 0x10790
movb %al, 0x3f(%rsp)
jmp 0xea82
movb 0x3f(%rsp), %al
testb $0x1, %al
jne 0xea8c
jmp 0xeaf5
movl $0x1, 0xc8(%rsp)
leaq 0xd0(%rsp), %rax
movq %rax, 0x28(%rsp)
leaq 0x138(%rsp), %rdi
callq 0x107b0
movq %rax, 0x30(%rsp)
jmp 0xeab8
movq 0x28(%rsp), %rax
movq 0x30(%rsp), %rcx
movq %rcx, (%rax)
leaq 0x1b0(%rsp), %rdi
callq 0x106f0
movl 0x4(%rax), %eax
movl %eax, 0xd8(%rsp)
leaq 0x120(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0xf840
jmp 0xeaf3
jmp 0xeaf5
jmp 0xebc8
jmp 0xeafc
movl 0x114(%rsp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, 0x114(%rsp)
cmpl $0x0, %eax
je 0xeb8f
leaq 0x2c0(%rsp), %rdi
callq 0x1a180
movzbl (%rax), %eax
movl %eax, 0x20(%rsp)
leaq 0x290(%rsp), %rdi
callq 0x1a180
movzbl (%rax), %eax
movl %eax, 0x24(%rsp)
leaq 0x280(%rsp), %rdi
callq 0x1a180
movl 0x20(%rsp), %esi
movl 0x24(%rsp), %edx
movzbl (%rax), %ecx
leaq 0x138(%rsp), %rdi
callq 0xf290
jmp 0xeb63
leaq 0x2c0(%rsp), %rdi
callq 0x19f60
leaq 0x290(%rsp), %rdi
callq 0x19f60
leaq 0x280(%rsp), %rdi
callq 0x19f60
jmp 0xeafc
jmp 0xebc8
movq 0x1e458(%rip), %rdi     # 0x2cff0
leaq 0x12fe0(%rip), %rsi     # 0x21b7f
callq 0x4290
movq %rax, 0x18(%rsp)
jmp 0xebab
movq 0x18(%rsp), %rdi
movq 0x1e3f1(%rip), %rsi     # 0x2cfa8
callq 0x42b0
jmp 0xebbe
movl $0x1, %edi
callq 0x42f0
jmp 0xebca
leaq 0x1b0(%rsp), %rdi
callq 0x10700
jmp 0xe856
movq 0x78(%rsp), %rdi
movb $0x0, 0xc7(%rsp)
leaq 0x138(%rsp), %rsi
callq 0xf4c0
jmp 0xebf8
movq 0x78(%rsp), %rdi
addq $0x18, %rdi
movq %rdi, 0x8(%rsp)
callq 0xfba0
movq %rax, 0xb0(%rsp)
leaq 0xb8(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x10890
leaq 0x120(%rsp), %rdi
movq %rdi, (%rsp)
callq 0xfd40
movq (%rsp), %rdi
movq %rax, 0xa8(%rsp)
callq 0xfba0
movq 0x8(%rsp), %rdi
movq %rax, 0xa0(%rsp)
movq 0xb8(%rsp), %rsi
movq 0xa8(%rsp), %rdx
movq 0xa0(%rsp), %rcx
callq 0x107d0
movq %rax, 0x10(%rsp)
jmp 0xec7b
movq 0x10(%rsp), %rax
movq %rax, 0x98(%rsp)
movb $0x1, 0xc7(%rsp)
testb $0x1, 0xc7(%rsp)
jne 0xecc6
jmp 0xecbc
movq 0x78(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x108(%rsp)
movl %eax, 0x104(%rsp)
callq 0xed70
jmp 0xecf0
movq 0x78(%rsp), %rdi
callq 0xed70
leaq 0x120(%rsp), %rdi
callq 0xf5a0
leaq 0x138(%rsp), %rdi
callq 0xf530
movq 0x80(%rsp), %rax
addq $0x308, %rsp            # imm = 0x308
retq
leaq 0x120(%rsp), %rdi
callq 0xf5a0
leaq 0x138(%rsp), %rdi
callq 0xf530
movq 0x108(%rsp), %rdi
callq 0x4510
nopw (%rax,%rax)