// File: /workspace/github_cpp_makefile_star2_O1/schneebergerlab[P]DrLink/detect_recombsite.cpp
// Function: get_var_ref_barcode(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>*, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::multimap<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, unsigned long, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, unsigned long>>>*)
bool get_var_ref_barcode(string                formatInfo, 
                         string                barcodeString, 
                         vector<string>*       vbc, 
                         vector<string>*       rbc,
                         string                this_chr,
                         string                this_pos,
                         multimap<string, unsigned long>* HeteroBarcode)
{
    //    2017-10-30: filter interleaving reads
    //                check if there are same barcode-reads covering the same allele at some variants!!!
    //                more possibly, these reads are from molecules with the same chr#barcode but from different plants.
    
    // formatInfo   : GT:DP:RO:QR:AO:QA:GL:BX:PS - can be different but must contain 'BX' flag
    // barcodeString: real values corresponding to the above format
    // vbc          : barcodes related to variant   allele
    // rbc          : barcodes related to reference allele
    vector<string> fmt = split_string(formatInfo, ':');
    int pos = -1;
    for(int i = 0; i < fmt.size(); i ++)
    {
        if(fmt[i].compare("BX") == 0)
        {
            pos = i;
            break;
        }
    }
    if(pos < 0)
    {
        cout << "   Error: no BX found in FORMAT. " << endl;
        return false;
    }
    vector<string> bcode = split_string(barcodeString, ':');
    if(bcode.size() != fmt.size())
    {
        cout << "   Error: sizes of FORMAT and VALUE mismatched." << endl;
        return false;
    }
    // find barcodes related to all alleles
    string b_all     = bcode[pos];
    // find barcodes related to alternative allele, after ',': "bcr1-;bcr2-,bcv1-;bcv2-;bcv3-"
    size_t seRefAlt  = b_all.find(",");
    assert(seRefAlt != std::string::npos);    
    //
    string b_var     = b_all.substr(seRefAlt+1);
    if(b_var.size()>15)
    {
        (*vbc)           = split_string(b_var, ';');
        // remove redundant info
        vector<string>::iterator itr;
        vector<string>::iterator itr_end;
        itr        = (*vbc).begin();
        itr_end    = (*vbc).end();  
        while(itr != itr_end)
        {
            string tmp      = *itr;
            size_t trashpos = tmp.find("-");
            if(trashpos == std::string::npos)
            {
                trashpos = tmp.size();
            }
            if(trashpos > 0)
            (*itr)          = tmp.substr(0, trashpos);
            itr             ++;
        }
    }
    else
    {
        (*vbc).clear(); // possibly no variant barcode? no!
    }
    // find barcodes related to reference allele, before ',': "bcr1-;bcr2-,bcv1-;bcv2-;bcv3-"
    string b_ref     = b_all.substr(0, seRefAlt);
    if(b_ref.size()>15)
    {
        (*rbc)           = split_string(b_ref, ';');
        // remove redundant info
        vector<string>::iterator itr;
        vector<string>::iterator itr_end;        
        itr        = (*rbc).begin();
        itr_end    = (*rbc).end();
        while(itr != (*rbc).end()) // note that (*rbc).end() is changing, so itr_end cannot be used here!!!
        {
            string tmp      = *itr;
            size_t trashpos = tmp.find("-");
            if(trashpos == std::string::npos)
            {
                trashpos = tmp.size();
            }
            if(trashpos > 0)
            (*itr)          = tmp.substr(0, trashpos);
            vector<string>::iterator overlapitr = std::find((*vbc).begin(), (*vbc).end(), *itr);
            if(overlapitr != (*vbc).end())
            {
                if(badBarcodeCov == 0)
                {
                    cout << "   Info: barcode " <<  *itr << " of "     << barcodeString 
                         << " covers both reference and alternative. " << endl;
                    cout << "   Warning: molecules with such barcodes removed (a total number given in the end). " 
                         << endl;
                }
                else
                {
                    if(false)
                    {
                        cout << "   Info: barcode " <<  *itr << " of " 
                             << barcodeString << " covers both reference and alternative. " << endl;
                    }
                }
                // count
                badBarcodeCov ++;
                // this is the barcode for removing falsely merged molecule covering the heterozgous mkr pos
                //(*vbc).erase(overlapitr);
                //itr = (*rbc).erase(itr);
                unsigned long mkrposwithbadbc = strtoul(this_pos.c_str(), NULL, 0);
                (*HeteroBarcode).insert(std::pair<string, unsigned long>(this_chr+"#"+(*itr), mkrposwithbadbc));
            }
            // next barcode
            itr ++;
        }
    }
    else
    {
        (*rbc).clear(); // possibly no variant barcode? yes!
    }
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x158, %rsp            # imm = 0x158
movq %r9, 0x118(%rsp)
movq %r8, 0x110(%rsp)
movq %rcx, 0x50(%rsp)
movq %rdx, %r13
movq %rsi, %r12
movq %rdi, %rsi
movq %rsp, %rdx
movb $0x3a, (%rdx)
leaq 0xe8(%rsp), %rbx
movq %rbx, %rdi
callq 0x36b7c
movq (%rbx), %rdi
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpq %rdi, 0x8(%rbx)
je 0x1ee2b
xorl %r14d, %r14d
leaq 0x1dd39(%rip), %rbx     # 0x3cb2a
xorl %r15d, %r15d
addq %r14, %rdi
movq %rbx, %rsi
callq 0x4100
testl %eax, %eax
je 0x1ee28
incq %r15
movq 0xe8(%rsp), %rdi
movq 0xf0(%rsp), %rax
subq %rdi, %rax
sarq $0x5, %rax
addq $0x20, %r14
cmpq %r15, %rax
ja 0x1edf4
jmp 0x1ee2b
movl %r15d, %ebp
testl %ebp, %ebp
js 0x1f046
movq %rsp, %rdx
movb $0x3a, (%rdx)
leaq 0x140(%rsp), %rdi
movq %r12, %rsi
callq 0x36b7c
movq 0x140(%rsp), %rax
movq 0x148(%rsp), %rcx
subq %rax, %rcx
movq 0xf0(%rsp), %rdx
subq 0xe8(%rsp), %rdx
cmpq %rdx, %rcx
sete %r14b
jne 0x1f094
movl %ebp, %ecx
shlq $0x5, %rcx
leaq 0xd8(%rsp), %rdx
movq %rdx, -0x10(%rdx)
movq (%rax,%rcx), %rsi
movq 0x8(%rax,%rcx), %rdx
addq %rsi, %rdx
leaq 0xc8(%rsp), %rdi
callq 0xda32
leaq 0x1c00d(%rip), %rsi     # 0x3aeb8
leaq 0xc8(%rsp), %rdi
movl $0x1, %ecx
xorl %edx, %edx
callq 0x4590
cmpq $-0x1, %rax
je 0x1f57b
movq %rax, %rbx
leaq 0x1(%rax), %rdx
leaq 0x120(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
movq $-0x1, %rcx
callq 0x4360
cmpq $0x10, 0x128(%rsp)
movl %r14d, 0x5c(%rsp)
movq %r12, 0x108(%rsp)
movq %rbx, 0x100(%rsp)
jb 0x1f0df
leaq 0x60(%rsp), %rdx
movb $0x3b, (%rdx)
leaq 0x80(%rsp), %rdi
leaq 0x120(%rsp), %rsi
callq 0x36b7c
xorps %xmm0, %xmm0
movq %rsp, %rdi
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movups (%r13), %xmm0
movq 0x10(%r13), %rax
leaq 0x80(%rsp), %rbx
movaps (%rbx), %xmm1
movups %xmm1, (%r13)
movq 0x10(%rbx), %rcx
movq %rcx, 0x10(%r13)
movq 0x10(%rdi), %rcx
movq %rax, 0x10(%rdi)
movaps (%rdi), %xmm1
movaps %xmm0, (%rdi)
movaps %xmm1, (%rbx)
movq %rcx, 0x10(%rbx)
callq 0x6aa2
movq %rbx, %rdi
callq 0x6aa2
movq (%r13), %r15
movq 0x8(%r13), %rbp
cmpq %rbp, %r15
je 0x1f0eb
leaq 0x10(%rsp), %r14
movq %rsp, %r12
leaq 0x80(%rsp), %rbx
movq %r14, (%rsp)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
movq %r12, %rdi
callq 0xda32
movl $0x1, %ecx
movq %r12, %rdi
leaq 0x1b5e7(%rip), %rsi     # 0x3a5ae
xorl %edx, %edx
callq 0x4590
cmpq $-0x1, %rax
jne 0x1efd9
movq 0x8(%rsp), %rax
testq %rax, %rax
je 0x1f01e
movq %rbx, %rdi
movq %r12, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x4360
movq %r15, %rdi
movq %rbx, %rsi
callq 0x43e0
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x1f01e
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x4340
movq (%rsp), %rdi
cmpq %r14, %rdi
je 0x1f034
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x4340
addq $0x20, %r15
cmpq %rbp, %r15
jne 0x1efa2
jmp 0x1f0eb
movq 0x2cf7b(%rip), %rbx     # 0x4bfc8
leaq 0x1dad9(%rip), %rsi     # 0x3cb2d
movl $0x21, %edx
movq %rbx, %rdi
callq 0x43a0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x4310
movsbl %al, %esi
movq 0x2cf49(%rip), %rdi     # 0x4bfc8
callq 0x4030
movq %rax, %rdi
callq 0x4220
xorl %r14d, %r14d
jmp 0x1f559
movq 0x2cf2d(%rip), %rbx     # 0x4bfc8
leaq 0x1daad(%rip), %rsi     # 0x3cb4f
movl $0x2f, %edx
movq %rbx, %rdi
callq 0x43a0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x4310
movsbl %al, %esi
movq 0x2cefb(%rip), %rdi     # 0x4bfc8
callq 0x4030
movq %rax, %rdi
callq 0x4220
jmp 0x1f54c
movq (%r13), %rsi
movq %r13, %rdi
callq 0x223cc
leaq 0x80(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
xorl %edx, %edx
movq 0x100(%rsp), %rcx
callq 0x4360
cmpq $0x10, 0x88(%rsp)
jb 0x1f4d3
leaq 0x30(%rsp), %rdx
movb $0x3b, (%rdx)
leaq 0x60(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x36b7c
xorps %xmm0, %xmm0
movq %rsp, %rdi
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movq 0x50(%rsp), %r14
movups (%r14), %xmm0
movq 0x10(%r14), %rax
leaq 0x60(%rsp), %rbx
movaps (%rbx), %xmm1
movups %xmm1, (%r14)
movq 0x10(%rbx), %rcx
movq %rcx, 0x10(%r14)
movq 0x10(%rdi), %rcx
movq %rax, 0x10(%rdi)
movaps (%rdi), %xmm1
movaps %xmm0, (%rdi)
movaps %xmm1, (%rbx)
movq %rcx, 0x10(%rbx)
callq 0x6aa2
movq %rbx, %rdi
callq 0x6aa2
movq (%r14), %rbx
cmpq 0x8(%r14), %rbx
je 0x1f4e0
leaq 0x10(%rsp), %r12
leaq 0x60(%rsp), %r15
movq %rsp, %rbp
movq %r13, 0xa0(%rsp)
leaq 0x70(%rsp), %rax
movq %rax, 0x60(%rsp)
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
movq %r15, %rdi
callq 0xda32
movl $0x1, %ecx
movq %r15, %rdi
leaq 0x1b3da(%rip), %rsi     # 0x3a5ae
xorl %edx, %edx
callq 0x4590
cmpq $-0x1, %rax
jne 0x1f1e6
movq 0x68(%rsp), %rax
testq %rax, %rax
je 0x1f21c
movq %rbp, %rdi
movq %r15, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x4360
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x43e0
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0x1f21c
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x4340
movq (%r13), %rdi
movq 0x8(%r13), %rsi
movq %rbx, %rdx
callq 0x2241e
cmpq 0x8(%r13), %rax
je 0x1f4a2
cmpq $0x0, 0x2d112(%rip)     # 0x4c350
jne 0x1f325
movl $0x11, %edx
movq 0x2cd78(%rip), %rdi     # 0x4bfc8
leaq 0x1d9c6(%rip), %rsi     # 0x3cc1d
callq 0x43a0
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq 0x2cd5e(%rip), %rdi     # 0x4bfc8
callq 0x43a0
movq %rax, %r14
movl $0x4, %edx
movq %rax, %rdi
leaq 0x1dc75(%rip), %rsi     # 0x3cef6
callq 0x43a0
movq 0x108(%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq %r14, %rdi
callq 0x43a0
movq %rax, %r14
movl $0x28, %edx
movq %rax, %rdi
leaq 0x1d980(%rip), %rsi     # 0x3cc2f
callq 0x43a0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x4310
movsbl %al, %esi
movq %r14, %rdi
callq 0x4030
movq %rax, %rdi
callq 0x4220
movl $0x54, %edx
movq 0x2cce1(%rip), %rdi     # 0x4bfc8
leaq 0x1d96a(%rip), %rsi     # 0x3cc58
callq 0x43a0
movq 0x2ccce(%rip), %rcx     # 0x4bfc8
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x4310
movsbl %al, %esi
movq 0x2ccb0(%rip), %rdi     # 0x4bfc8
callq 0x4030
movq %rax, %rdi
callq 0x4220
movq %rbp, %r13
movq %r15, %rbp
movq %r12, %r15
incq 0x2d01b(%rip)           # 0x4c350
movq 0x118(%rsp), %rax
movq (%rax), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4130
movq %rax, %r14
leaq 0xb8(%rsp), %rax
movq %rax, 0xa8(%rsp)
movq 0x110(%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0xa8(%rsp), %r12
movq %r12, %rdi
callq 0xda32
movq %r12, %rdi
leaq 0x1fc6a(%rip), %rsi     # 0x3eff2
callq 0x45e0
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq %r12, %rdi
callq 0x4120
leaq 0x40(%rsp), %rsi
movq %rsi, 0x30(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
movq %r15, %r12
je 0x1f3c7
movq %rdx, 0x30(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x40(%rsp)
jmp 0x1f3cd
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq %rbp, %r15
movq 0x8(%rax), %rdx
movq %rdx, 0x38(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq %r12, (%rsp)
movq 0x30(%rsp), %rax
cmpq %rsi, %rax
movq %r13, %rbp
je 0x1f409
movq %rax, (%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
jmp 0x1f411
movups (%rsi), %xmm0
movups %xmm0, (%r12)
movq 0xa0(%rsp), %r13
movq 0x38(%rsp), %rax
movq %rax, 0x8(%rsp)
movq %rsi, 0x30(%rsp)
movq $0x0, 0x38(%rsp)
movb $0x0, 0x40(%rsp)
movq %r14, 0x20(%rsp)
movq 0x190(%rsp), %rdi
movq %rbp, %rsi
callq 0x22552
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0x1f461
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x4340
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x1f47d
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x4340
movq 0xa8(%rsp), %rdi
leaq 0xb8(%rsp), %rax
cmpq %rax, %rdi
je 0x1f4a2
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x4340
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x1f4be
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x4340
addq $0x20, %rbx
movq 0x50(%rsp), %rax
cmpq 0x8(%rax), %rbx
jne 0x1f1a9
jmp 0x1f4e0
movq 0x50(%rsp), %rdi
movq (%rdi), %rsi
callq 0x223cc
leaq 0x90(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1f501
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x4340
leaq 0x130(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
leaq 0xd8(%rsp), %rbx
movl 0x5c(%rsp), %r14d
je 0x1f52f
movq 0x130(%rsp), %rsi
incq %rsi
callq 0x4340
movq 0xc8(%rsp), %rdi
cmpq %rbx, %rdi
je 0x1f54c
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x4340
leaq 0x140(%rsp), %rdi
callq 0x6aa2
leaq 0xe8(%rsp), %rdi
callq 0x6aa2
movl %r14d, %eax
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1d5fd(%rip), %rdi     # 0x3cb7f
leaq 0x1c998(%rip), %rsi     # 0x3bf21
leaq 0x1d60d(%rip), %rcx     # 0x3cb9d
movl $0x6c8, %edx            # imm = 0x6C8
callq 0x41f0
jmp 0x1f642
jmp 0x1f647
jmp 0x1f647
movq %rax, %rbx
jmp 0x1f6ad
jmp 0x1f5b5
jmp 0x1f5bd
movq %rax, %rbx
jmp 0x1f6d2
movq %rax, %rbx
jmp 0x1f6df
jmp 0x1f64c
jmp 0x1f5cc
movq %rax, %rbx
jmp 0x1f608
jmp 0x1f64c
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0x1f5ec
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x4340
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x1f608
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x4340
movq 0xa8(%rsp), %rdi
leaq 0xb8(%rsp), %rax
cmpq %rax, %rdi
je 0x1f64f
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x4340
jmp 0x1f64f
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r14, %rdi
je 0x1f68c
movq 0x10(%rsp), %rsi
jmp 0x1f684
movq %rax, %rbx
jmp 0x1f66b
movq %rax, %rbx
jmp 0x1f68c
movq %rax, %rbx
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x1f66b
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x4340
leaq 0x90(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1f68c
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x4340
leaq 0x130(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1f6ad
movq 0x130(%rsp), %rsi
incq %rsi
callq 0x4340
movq 0xc8(%rsp), %rdi
leaq 0xd8(%rsp), %rax
cmpq %rax, %rdi
je 0x1f6d2
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x4340
leaq 0x140(%rsp), %rdi
callq 0x6aa2
leaq 0xe8(%rsp), %rdi
callq 0x6aa2
movq %rbx, %rdi
callq 0x45a0