// File: /workspace/github_cpp_makefile_star2_O1/zeeev[P]DASVC/bamtools/src/utils/bamtools_pileup_engine.cpp
// Function: BamTools::PileupEngine::PileupEnginePrivate::AddAlignment(BamTools::BamAlignment const&)
bool PileupEngine::PileupEnginePrivate::AddAlignment(const BamAlignment& al) {
  
    // if first time
    if ( IsFirstAlignment ) {
      
        // set initial markers 
        CurrentId       = al.RefID;
        CurrentPosition = al.Position;
        
        // store first entry
        CurrentAlignments.clear();
        CurrentAlignments.push_back(al);
        
        // set flag & return
        IsFirstAlignment = false;
        return true;
    }
  
    // if same reference
    if ( al.RefID == CurrentId ) {
      
        // if same position, store and move on
        if ( al.Position == CurrentPosition )
            CurrentAlignments.push_back(al);
        
        // if less than CurrentPosition - sorting error => ABORT
        else if ( al.Position < CurrentPosition ) {
            cerr << "Pileup::Run() : Data not sorted correctly!" << endl;
            return false;
        }
        
        // else print pileup data until 'catching up' to CurrentPosition
        else {
            while ( al.Position > CurrentPosition ) {
                ApplyVisitors();
                ++CurrentPosition;
            }
            CurrentAlignments.push_back(al);
        }
    } 

    // if reference ID less than CurrentId - sorting error => ABORT
    else if ( al.RefID < CurrentId ) {
        cerr << "Pileup::Run() : Data not sorted correctly!" << endl;
        return false;
    }

    // else moved forward onto next reference
    else {
        
        // print any remaining pileup data from previous reference
        while ( !CurrentAlignments.empty() ) {
            ApplyVisitors();
            ++CurrentPosition;
        }
        
        // store first entry on this new reference, update markers
        CurrentAlignments.clear();
        CurrentAlignments.push_back(al);
        CurrentId = al.RefID;
        CurrentPosition = al.Position;
    }
  
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
movl 0xa8(%rsi), %eax
cmpb $0x1, 0x40(%rdi)
jne 0x651bd
movl %eax, (%rbx)
movl 0xac(%r14), %eax
movl %eax, 0x4(%rbx)
leaq 0x8(%rbx), %r15
movq 0x8(%rbx), %r13
movq 0x10(%rbx), %rbp
cmpq %r13, %rbp
je 0x651a9
movq %r13, %r12
movq %r12, %rdi
callq 0x27930
addq $0x158, %r12            # imm = 0x158
cmpq %rbp, %r12
jne 0x65191
movq %r13, 0x10(%rbx)
movq %r15, %rdi
movq %r14, %rsi
callq 0x4f1ec
movb $0x0, 0x40(%rbx)
jmp 0x65255
cmpl (%rbx), %eax
jne 0x651de
movl 0x4(%rbx), %eax
cmpl %eax, 0xac(%r14)
jne 0x651f7
addq $0x8, %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4f1ec
jmp 0x65255
jl 0x651f9
movq 0x8(%rbx), %rax
cmpq 0x10(%rbx), %rax
je 0x6523f
movq %rbx, %rdi
callq 0x65294
incl 0x4(%rbx)
jmp 0x651e0
jge 0x65266
movq 0x2ade0(%rip), %rbx     # 0x8ffe0
leaq 0x11f17(%rip), %rsi     # 0x7711e
movl $0x2a, %edx
movq %rbx, %rdi
callq 0x276c0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x27590
movsbl %al, %esi
movq %rbx, %rdi
callq 0x27040
movq %rax, %rdi
callq 0x27410
xorl %eax, %eax
jmp 0x65257
leaq 0x8(%rbx), %rdi
movq %r14, %rsi
callq 0x4f1ec
movq 0xa8(%r14), %rax
movq %rax, (%rbx)
movb $0x1, %al
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0xac(%r14), %eax
cmpl 0x4(%rbx), %eax
jle 0x651cd
movq %rbx, %rdi
callq 0x65294
movl 0x4(%rbx), %eax
incl %eax
movl %eax, 0x4(%rbx)
cmpl %eax, 0xac(%r14)
jg 0x65276
jmp 0x651cd