// File: /workspace/github_cpp_makefile_star2_O2/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 %r15
pushq %r14
pushq %rbx
movq %rsi, %r14
movq %rdi, %rbx
movl 0xa8(%rsi), %eax
cmpb $0x1, 0x40(%rdi)
jne 0x666cf
movl %eax, (%rbx)
movl 0xac(%r14), %eax
movl %eax, 0x4(%rbx)
leaq 0x8(%rbx), %r15
movq %r15, %rdi
callq 0x5586e
movq %r15, %rdi
movq %r14, %rsi
callq 0x55800
movb $0x0, 0x40(%rbx)
jmp 0x6676a
cmpl (%rbx), %eax
jne 0x666f2
movl 0xac(%r14), %ecx
movl 0x4(%rbx), %eax
cmpl %eax, %ecx
jne 0x6670f
addq $0x8, %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x55800
jmp 0x6676a
jl 0x66711
leaq 0x8(%rbx), %r15
movq 0x8(%rbx), %rax
cmpq 0x10(%rbx), %rax
je 0x6674d
movq %rbx, %rdi
callq 0x66772
incl 0x4(%rbx)
jmp 0x666f8
jge 0x66730
movq 0x2e8c8(%rip), %rdi     # 0x94fe0
leaq 0xf9bc(%rip), %rsi      # 0x760db
callq 0x355b0
movq %rax, %rdi
callq 0x35300
xorl %eax, %eax
jmp 0x6676c
cmpl %eax, %ecx
jle 0x666e1
movq %rbx, %rdi
callq 0x66772
movl 0x4(%rbx), %eax
incl %eax
movl %eax, 0x4(%rbx)
movl 0xac(%r14), %ecx
jmp 0x66730
movq %r15, %rdi
callq 0x5586e
movq %r15, %rdi
movq %r14, %rsi
callq 0x55800
movq 0xa8(%r14), %rax
movq %rax, (%rbx)
movb $0x1, %al
popq %rbx
popq %r14
popq %r15
retq