// File: /workspace/github_cpp_makefile_star2_O3/zeeev[P]DASVC/bamtools/src/toolkit/bamtools_convert.cpp
// Function: BamTools::ConvertPileupFormatVisitor::Visit(BamTools::PileupPosition const&)
void ConvertPileupFormatVisitor::Visit(const PileupPosition& pileupData ) {
  
    // skip if no alignments at this position
    if ( pileupData.PileupAlignments.empty() ) return;
  
    // retrieve reference name
    const string& referenceName = m_references[pileupData.RefId].RefName;
    const int& position   = pileupData.Position;
    
    // retrieve reference base from FASTA file, if one provided; otherwise default to 'N'
    char referenceBase('N');
    if ( m_hasFasta && (pileupData.Position < m_references[pileupData.RefId].RefLength) ) {
        if ( !m_fasta.GetBase(pileupData.RefId, pileupData.Position, referenceBase ) ) {
            cerr << "bamtools convert ERROR: pileup conversion - could not read reference base from FASTA file" << endl;
            return;
        }
    }
    
    // get count of alleles at this position
    const int numberAlleles = pileupData.PileupAlignments.size();
    
    // -----------------------------------------------------------
    // build strings based on alleles at this positionInAlignment
    
    stringstream bases("");
    stringstream baseQualities("");
    stringstream mapQualities("");
    
    // iterate over alignments at this pileup position
    vector<PileupAlignment>::const_iterator pileupIter = pileupData.PileupAlignments.begin();
    vector<PileupAlignment>::const_iterator pileupEnd  = pileupData.PileupAlignments.end();
    for ( ; pileupIter != pileupEnd; ++pileupIter ) {
        const PileupAlignment pa = (*pileupIter);
        const BamAlignment& ba = pa.Alignment;
        
        // if beginning of read segment
        if ( pa.IsSegmentBegin )
            bases << '^' << ( ((int)ba.MapQuality > 93) ? (char)126 : (char)((int)ba.MapQuality+33) );
        
        // if current base is not a DELETION
        if ( !pa.IsCurrentDeletion ) {
          
            // get base at current position
            char base = ba.QueryBases.at(pa.PositionInAlignment);
            
            // if base matches reference
            if ( base == '=' || 
                 toupper(base) == toupper(referenceBase) ||
                 tolower(base) == tolower(referenceBase) ) 
            {
                base = ( ba.IsReverseStrand() ? ',' : '.' );
            }
            
            // mismatches reference
            else base = ( ba.IsReverseStrand() ? tolower(base) : toupper(base) );
            
            // store base
            bases << base;
          
            // if next position contains insertion
            if ( pa.IsNextInsertion ) {
                bases << '+' << pa.InsertionLength;
                for (int i = 1; i <= pa.InsertionLength; ++i) {
                    char insertedBase = (char)ba.QueryBases.at(pa.PositionInAlignment + i);
                    bases << (ba.IsReverseStrand() ? (char)tolower(insertedBase) : (char)toupper(insertedBase) );
                }
            }
            
            // if next position contains DELETION
            else if ( pa.IsNextDeletion ) {
                bases << '-' << pa.DeletionLength;
                for (int i = 1; i <= pa.DeletionLength; ++i) {
                    char deletedBase('N');
                    if ( m_hasFasta && (pileupData.Position+i < m_references[pileupData.RefId].RefLength) ) {
                        if ( !m_fasta.GetBase(pileupData.RefId, pileupData.Position+i, deletedBase ) ) {
                            cerr << "bamtools convert ERROR: pileup conversion - could not read reference base from FASTA file" << endl;
                            return;
                        }
                    }
                    bases << (ba.IsReverseStrand() ? (char)tolower(deletedBase) : (char)toupper(deletedBase) );
                }
            }
        }
        
        // otherwise, DELETION
        else bases << '*';
        
        // if end of read segment
        if ( pa.IsSegmentEnd )
            bases << '$';
        
        // store current base quality
        baseQualities << ba.Qualities.at(pa.PositionInAlignment);
        
        // save alignment map quality if desired
        if ( m_isPrintingMapQualities )
            mapQualities << ( ((int)ba.MapQuality > 93) ? (char)126 : (char)((int)ba.MapQuality+33) );
    }
    
    // ----------------------
    // print results 
    
    // tab-delimited
    // <refName> <1-based pos> <refBase> <numberAlleles> <bases> <qualities> [mapQuals]
    
    const string TAB = "\t";
    *m_out << referenceName       << TAB 
           << position + 1        << TAB 
           << referenceBase       << TAB 
           << numberAlleles       << TAB 
           << bases.str()         << TAB 
           << baseQualities.str() << TAB
           << mapQualities.str()  << endl;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x6a8, %rsp            # imm = 0x6A8
movq %rsi, %rbx
movq 0x8(%rsi), %rsi
movq 0x10(%rbx), %rcx
cmpq %rcx, %rsi
je 0x2dfb5
movq %rdi, %r13
movslq (%rbx), %rax
leaq (%rax,%rax,4), %rdi
shlq $0x3, %rdi
leaq 0x4(%rbx), %rdx
addq 0x20(%r13), %rdi
movb $0x4e, 0xf(%rsp)
cmpb $0x1, 0x10(%r13)
movq %rdi, 0x50(%rsp)
jne 0x2d820
movl (%rdx), %eax
cmpl 0x20(%rdi), %eax
jge 0x2d820
leaq 0x8(%r13), %rdi
leaq 0xf(%rsp), %rcx
movq %rbx, %rsi
movq %rbx, %r14
movq %rdx, %rbx
callq 0x62eee
testb %al, %al
je 0x2dfc7
movq 0x8(%r14), %rsi
movq 0x10(%r14), %rcx
movq %rbx, %rdx
movq %r14, %rbx
movq %rdx, 0x48(%rsp)
movq %rsi, 0x38(%rsp)
movq %rcx, 0x40(%rsp)
leaq 0x530(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x48fd5(%rip), %rdx     # 0x76817
leaq 0x520(%rsp), %rdi
movq %rdx, %rsi
callq 0x2f1a0
leaq 0x210(%rsp), %rdi
leaq 0x520(%rsp), %rsi
movl $0x18, %edx
callq 0x279b0
movq 0x520(%rsp), %rdi
cmpq %r14, %rdi
je 0x2d87e
callq 0x27560
leaq 0x3a8(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x48f86(%rip), %rdx     # 0x76817
leaq 0x398(%rsp), %rdi
movq %rdx, %rsi
callq 0x2f1a0
leaq 0x520(%rsp), %rdi
leaq 0x398(%rsp), %rsi
movl $0x18, %edx
callq 0x279b0
movq 0x398(%rsp), %rdi
cmpq %r14, %rdi
je 0x2d8cd
callq 0x27560
leaq 0xb0(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x48f37(%rip), %rdx     # 0x76817
leaq 0xa0(%rsp), %rdi
movq %rdx, %rsi
callq 0x2f1a0
leaq 0x398(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
movl $0x18, %edx
callq 0x279b0
movq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rax
cmpq %rax, %rdi
je 0x2d924
callq 0x27560
movq 0x8(%rbx), %r12
movq 0x10(%rbx), %rbp
cmpq %rbp, %r12
je 0x2dd80
leaq 0x8(%r13), %rax
movq %rax, 0x58(%rsp)
movq %r13, 0x30(%rsp)
leaq 0xa0(%rsp), %rdi
movq %r12, %rsi
callq 0x272b0
movzwl 0x168(%r12), %eax
leaq 0x1f8(%rsp), %rcx
movw %ax, 0x10(%rcx)
movups 0x158(%r12), %xmm0
movups %xmm0, (%rcx)
cmpb $0x1, 0x208(%rsp)
jne 0x2d9ca
movb $0x5e, 0x10(%rsp)
movl $0x1, %edx
leaq 0x220(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x276b0
movzwl 0x152(%rsp), %ecx
leal 0x21(%rcx), %edx
cmpw $0x5e, %cx
movzbl %dl, %ecx
movl $0x7e, %edx
cmovael %edx, %ecx
movb %cl, 0x10(%rsp)
movl $0x1, %edx
movq %rax, %rdi
leaq 0x10(%rsp), %rsi
callq 0x276b0
cmpb $0x0, 0x1fc(%rsp)
je 0x2d9f5
movb $0x2a, 0x10(%rsp)
movl $0x1, %edx
leaq 0x220(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x276b0
jmp 0x2dc3a
movslq 0x1f8(%rsp), %rsi
movq 0xd0(%rsp), %rdx
cmpq %rsi, %rdx
jbe 0x2e027
movq 0xc8(%rsp), %rax
movsbl (%rax,%rsi), %r15d
cmpl $0x3d, %r15d
je 0x2da65
movl %r15d, %edi
callq 0x27bb0
movl %eax, %r13d
movsbl 0xf(%rsp), %r14d
movl %r14d, %edi
callq 0x27bb0
cmpl %eax, %r13d
movq 0x30(%rsp), %r13
je 0x2da65
movl %r15d, %edi
callq 0x27860
movl %eax, %r13d
movl %r14d, %edi
callq 0x27860
cmpl %eax, %r13d
movq 0x30(%rsp), %r13
jne 0x2dd06
leaq 0xa0(%rsp), %rdi
callq 0x277f0
xorb $0x1, %al
addb %al, %al
orb $0x2c, %al
movb %al, 0x10(%rsp)
movl $0x1, %edx
leaq 0x220(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x276b0
cmpb $0x1, 0x1fe(%rsp)
jne 0x2db5a
movb $0x2b, 0x10(%rsp)
movl $0x1, %edx
leaq 0x220(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x276b0
movl 0x204(%rsp), %esi
movq %rax, %rdi
callq 0x27ab0
cmpl $0x0, 0x204(%rsp)
jle 0x2dc3a
movl $0x1, %r14d
movslq 0x1f8(%rsp), %rax
leaq (%r14,%rax), %rsi
movq 0xd0(%rsp), %rdx
cmpq %rsi, %rdx
jbe 0x2e00b
addq 0xc8(%rsp), %rax
movsbl (%r14,%rax), %r15d
leaq 0xa0(%rsp), %rdi
callq 0x277f0
movl %r15d, %edi
testb %al, %al
je 0x2db25
callq 0x27860
jmp 0x2db2a
callq 0x27bb0
movb %al, 0x10(%rsp)
movl $0x1, %edx
leaq 0x220(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x276b0
incq %r14
leal -0x1(%r14), %eax
cmpl 0x204(%rsp), %eax
jl 0x2dae0
jmp 0x2dc3a
cmpb $0x1, 0x1fd(%rsp)
jne 0x2dc3a
movb $0x2d, 0x10(%rsp)
movl $0x1, %edx
leaq 0x220(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x276b0
movl 0x200(%rsp), %esi
movq %rax, %rdi
callq 0x27ab0
cmpl $0x0, 0x200(%rsp)
jle 0x2dc3a
xorl %r14d, %r14d
movb $0x4e, 0x60(%rsp)
cmpb $0x1, 0x10(%r13)
jne 0x2dbec
movl 0x4(%rbx), %eax
addl %r14d, %eax
incl %eax
movslq (%rbx), %rcx
movq 0x20(%r13), %rdx
leaq (%rcx,%rcx,4), %rcx
cmpl 0x20(%rdx,%rcx,8), %eax
jge 0x2dbec
movl %eax, 0x10(%rsp)
movq 0x58(%rsp), %rdi
movq %rbx, %rsi
leaq 0x10(%rsp), %rdx
leaq 0x60(%rsp), %rcx
callq 0x62eee
testb %al, %al
je 0x2dd2e
leaq 0xa0(%rsp), %rdi
callq 0x277f0
movsbl 0x60(%rsp), %edi
testb %al, %al
je 0x2dc09
callq 0x27860
jmp 0x2dc0e
callq 0x27bb0
movb %al, 0x10(%rsp)
movl $0x1, %edx
leaq 0x220(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x276b0
incl %r14d
cmpl 0x200(%rsp), %r14d
jl 0x2dba4
cmpb $0x1, 0x209(%rsp)
jne 0x2dc60
movb $0x24, 0x10(%rsp)
movl $0x1, %edx
leaq 0x220(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x276b0
movslq 0x1f8(%rsp), %rsi
movq 0x110(%rsp), %rdx
cmpq %rsi, %rdx
jbe 0x2e019
movq 0x108(%rsp), %rax
movb (%rax,%rsi), %al
movb %al, 0x10(%rsp)
movl $0x1, %edx
leaq 0x530(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x276b0
movb $0x1, %r14b
cmpb $0x1, 0x11(%r13)
jne 0x2dcde
movzwl 0x152(%rsp), %eax
leal 0x21(%rax), %ecx
cmpw $0x5e, %ax
movzbl %cl, %eax
movl $0x7e, %ecx
cmovael %ecx, %eax
movb %al, 0x10(%rsp)
movl $0x1, %edx
leaq 0x3a8(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x276b0
leaq 0xa0(%rsp), %rdi
callq 0x27920
testb %r14b, %r14b
je 0x2df8e
addq $0x170, %r12            # imm = 0x170
cmpq %rbp, %r12
jne 0x2d943
jmp 0x2dd80
leaq 0xa0(%rsp), %rdi
callq 0x277f0
movl %r15d, %edi
testb %al, %al
je 0x2dd24
callq 0x27860
jmp 0x2da78
callq 0x27bb0
jmp 0x2da78
movl $0x59, %edx
movq 0x612a6(%rip), %rdi     # 0x8efe0
leaq 0x43943(%rip), %rsi     # 0x71684
callq 0x276b0
movq 0x61293(%rip), %rcx     # 0x8efe0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x27590
movsbl %al, %esi
movq 0x61275(%rip), %rdi     # 0x8efe0
callq 0x27040
movq %rax, %rdi
callq 0x27410
xorl %r14d, %r14d
jmp 0x2dcde
leaq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rax
movq %rax, (%rdi)
leaq 0x48a7c(%rip), %rsi     # 0x76816
leaq 0x48a76(%rip), %rdx     # 0x76817
callq 0x2f1a0
movq 0x18(%r13), %rdi
movq 0x50(%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
callq 0x276b0
movq 0xa0(%rsp), %rsi
movq 0xa8(%rsp), %rdx
movq %rax, %rdi
callq 0x276b0
movq 0x48(%rsp), %rcx
movl (%rcx), %esi
incl %esi
movq %rax, %rdi
callq 0x27ab0
movq 0xa0(%rsp), %rsi
movq 0xa8(%rsp), %rdx
movq %rax, %rdi
callq 0x276b0
movb 0xf(%rsp), %cl
leaq 0x10(%rsp), %rsi
movb %cl, (%rsi)
movl $0x1, %edx
movq %rax, %rdi
callq 0x276b0
movq 0xa0(%rsp), %rsi
movq 0xa8(%rsp), %rdx
movq %rax, %rdi
callq 0x276b0
movq 0x40(%rsp), %rcx
subq 0x38(%rsp), %rcx
shrq $0x4, %rcx
imull $0xe9bd37a7, %ecx, %esi # imm = 0xE9BD37A7
movq %rax, %rdi
callq 0x27ab0
movq 0xa0(%rsp), %rsi
movq 0xa8(%rsp), %rdx
movq %rax, %rdi
callq 0x276b0
movq %rax, %rbx
leaq 0x228(%rsp), %rsi
leaq 0x10(%rsp), %rdi
callq 0x27990
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq %rbx, %rdi
callq 0x276b0
movq 0xa0(%rsp), %rsi
movq 0xa8(%rsp), %rdx
movq %rax, %rdi
callq 0x276b0
movq %rax, %rbx
leaq 0x538(%rsp), %rsi
leaq 0x60(%rsp), %rdi
callq 0x27990
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rdx
movq %rbx, %rdi
callq 0x276b0
movq 0xa0(%rsp), %rsi
movq 0xa8(%rsp), %rdx
movq %rax, %rdi
callq 0x276b0
movq %rax, %rbx
leaq 0x3b0(%rsp), %rsi
leaq 0x80(%rsp), %rdi
callq 0x27990
movq 0x80(%rsp), %rsi
movq 0x88(%rsp), %rdx
movq %rbx, %rdi
callq 0x276b0
movq %rax, %rbx
movq (%rax), %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
leaq 0x90(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2df4e
callq 0x27560
leaq 0x70(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2df61
callq 0x27560
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2df74
callq 0x27560
movq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rax
cmpq %rax, %rdi
je 0x2df8e
callq 0x27560
leaq 0x398(%rsp), %rdi
callq 0x27490
leaq 0x520(%rsp), %rdi
callq 0x27490
leaq 0x210(%rsp), %rdi
callq 0x27490
addq $0x6a8, %rsp            # imm = 0x6A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x61012(%rip), %rbx     # 0x8efe0
leaq 0x436af(%rip), %rsi     # 0x71684
movl $0x59, %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
jmp 0x2dfb5
leaq 0x436f6(%rip), %rdi     # 0x71708
xorl %eax, %eax
callq 0x278b0
leaq 0x436e8(%rip), %rdi     # 0x71708
xorl %eax, %eax
callq 0x278b0
leaq 0x436da(%rip), %rdi     # 0x71708
xorl %eax, %eax
callq 0x278b0
jmp 0x2e149
jmp 0x2e0cc
jmp 0x2e0d1
jmp 0x2e11b
jmp 0x2e13e
jmp 0x2e09e
jmp 0x2e078
movq %rax, %rbx
movq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rax
cmpq %rax, %rdi
je 0x2e166
callq 0x27560
jmp 0x2e166
movq %rax, %rbx
jmp 0x2e166
movq %rax, %rbx
movq 0x398(%rsp), %rdi
cmpq %r14, %rdi
je 0x2e173
callq 0x27560
jmp 0x2e173
movq %rax, %rbx
jmp 0x2e173
movq %rax, %rbx
movq 0x520(%rsp), %rdi
cmpq %r14, %rdi
je 0x2e180
callq 0x27560
jmp 0x2e180
movq %rax, %rbx
jmp 0x2e180
movq %rax, %rbx
jmp 0x2e0ef
movq %rax, %rbx
jmp 0x2e102
movq %rax, %rbx
leaq 0x90(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2e0ef
callq 0x27560
leaq 0x70(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2e102
callq 0x27560
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2e11e
callq 0x27560
jmp 0x2e11e
jmp 0x2e149
jmp 0x2e149
movq %rax, %rbx
movq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rax
cmpq %rax, %rdi
je 0x2e159
callq 0x27560
jmp 0x2e159
jmp 0x2e149
jmp 0x2e149
movq %rax, %rbx
jmp 0x2e159
jmp 0x2e149
jmp 0x2e149
jmp 0x2e149
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0x27920
leaq 0x398(%rsp), %rdi
callq 0x27490
leaq 0x520(%rsp), %rdi
callq 0x27490
leaq 0x210(%rsp), %rdi
callq 0x27490
movq %rbx, %rdi
callq 0x27b10
movq %rax, %rdi
callq 0x2e1cd