// File: /workspace/github_cpp_makefile_star2_O3/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 0x64c9d
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 0x64c89
movq %r13, %r12
movq %r12, %rdi
callq 0x27920
addq $0x158, %r12            # imm = 0x158
cmpq %rbp, %r12
jne 0x64c71
movq %r13, 0x10(%rbx)
movq %r15, %rdi
movq %r14, %rsi
callq 0x4f07e
movb $0x0, 0x40(%rbx)
jmp 0x64d58
cmpl (%rbx), %eax
jne 0x64cc3
movl 0xac(%r14), %eax
movl 0x4(%rbx), %ecx
cmpl %ecx, %eax
jne 0x64ce0
addq $0x8, %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4f07e
jmp 0x64d58
jl 0x64ce2
leaq 0x8(%rbx), %r15
movq 0x8(%rbx), %rax
cmpq 0x10(%rbx), %rax
je 0x64d43
movq %rbx, %rdi
callq 0x64d6a
incl 0x4(%rbx)
jmp 0x64cc9
jge 0x64d28
movq 0x2a2f7(%rip), %rbx     # 0x8efe0
leaq 0x1142e(%rip), %rsi     # 0x7611e
movl $0x2a, %edx
movq %rbx, %rdi
callq 0x276b0
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 0x64d5a
jle 0x64caf
movq %rbx, %rdi
callq 0x64d6a
movl 0x4(%rbx), %eax
incl %eax
movl %eax, 0x4(%rbx)
cmpl %eax, 0xac(%r14)
jmp 0x64d28
movq %r15, %rdi
movq %r14, %rsi
callq 0x4f07e
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
nop