// File: /workspace/github_cpp_makefile_star2_O3/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, 0x108(%rsp)
movq %rdx, %r13
movq %rsi, %r12
movq %rdi, %rsi
movq %rsp, %rdx
movb $0x3a, (%rdx)
leaq 0xe0(%rsp), %rbx
movq %rbx, %rdi
callq 0x367c0
movq (%rbx), %rdi
cmpq %rdi, 0x8(%rbx)
je 0x1ed6a
xorl %r15d, %r15d
leaq 0x1ddf5(%rip), %rbx     # 0x3cb2a
xorl %r14d, %r14d
addq %r15, %rdi
movq %rbx, %rsi
callq 0x4100
testl %eax, %eax
je 0x1edb7
incq %r14
movq 0xe0(%rsp), %rdi
movq 0xe8(%rsp), %rax
subq %rdi, %rax
sarq $0x5, %rax
addq $0x20, %r15
cmpq %r14, %rax
ja 0x1ed38
movq 0x2d257(%rip), %rbx     # 0x4bfc8
leaq 0x1ddb5(%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 0x2d225(%rip), %rdi     # 0x4bfc8
callq 0x4030
movq %rax, %rdi
callq 0x4220
xorl %ebp, %ebp
jmp 0x1f46b
movq %rsp, %rdx
movb $0x3a, (%rdx)
leaq 0x140(%rsp), %rdi
movq %r12, %rsi
callq 0x367c0
movq 0x140(%rsp), %rax
movq 0x148(%rsp), %rcx
subq %rax, %rcx
movq 0xe8(%rsp), %rdx
subq 0xe0(%rsp), %rdx
cmpq %rdx, %rcx
sete %bpl
jne 0x1efad
movl %r14d, %ecx
shlq $0x5, %rcx
leaq 0xd0(%rsp), %rdx
movq %rdx, -0x10(%rdx)
movq (%rax,%rcx), %rsi
movq 0x8(%rax,%rcx), %rdx
addq %rsi, %rdx
leaq 0xc0(%rsp), %rdi
callq 0xd940
leaq 0x1c088(%rip), %rsi     # 0x3aeb8
leaq 0xc0(%rsp), %rdi
movl $0x1, %ecx
xorl %edx, %edx
callq 0x4590
cmpq $-0x1, %rax
je 0x1f48c
movq %rax, %rbx
leaq 0x1(%rax), %rdx
leaq 0x120(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
movq $-0x1, %rcx
callq 0x4360
cmpq $0x10, 0x128(%rsp)
movq %r12, 0x100(%rsp)
movl %ebp, 0x4c(%rsp)
movq %rbx, 0xf8(%rsp)
jb 0x1eff8
leaq 0x50(%rsp), %rdx
movb $0x3b, (%rdx)
leaq 0x70(%rsp), %rdi
leaq 0x120(%rsp), %rsi
callq 0x367c0
movq 0x10(%r13), %rax
leaq 0x70(%rsp), %rbx
movaps (%rbx), %xmm0
movq 0x10(%rbx), %rcx
movq %rcx, 0x10(%r13)
movups (%r13), %xmm1
movups %xmm0, (%r13)
movq %rsp, %rdi
movaps %xmm1, (%rdi)
movq %rax, 0x10(%rdi)
xorps %xmm0, %xmm0
movaps %xmm0, (%rbx)
movq $0x0, 0x10(%rbx)
callq 0x6aac
movq %rbx, %rdi
callq 0x6aac
movq (%r13), %r15
movq 0x8(%r13), %rbx
cmpq %rbx, %r15
je 0x1f004
leaq 0x10(%rsp), %r14
movq %rsp, %rbp
leaq 0x70(%rsp), %r12
movq %r14, (%rsp)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
movq %rbp, %rdi
callq 0xd940
movl $0x1, %ecx
movq %rbp, %rdi
leaq 0x1b67a(%rip), %rsi     # 0x3a5ae
xorl %edx, %edx
callq 0x4590
cmpq $-0x1, %rax
jne 0x1ef46
movq 0x8(%rsp), %rax
testq %rax, %rax
je 0x1ef88
movq %r12, %rdi
movq %rbp, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x4360
movq %r15, %rdi
movq %r12, %rsi
callq 0x43e0
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0x1ef88
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x4340
movq (%rsp), %rdi
cmpq %r14, %rdi
je 0x1ef9e
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x4340
addq $0x20, %r15
cmpq %rbx, %r15
jne 0x1ef0f
jmp 0x1f004
movq 0x2d014(%rip), %rbx     # 0x4bfc8
leaq 0x1db94(%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 0x2cfe2(%rip), %rdi     # 0x4bfc8
callq 0x4030
movq %rax, %rdi
callq 0x4220
jmp 0x1f45e
movq (%r13), %rsi
movq %r13, %rdi
callq 0x2228c
leaq 0x70(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
xorl %edx, %edx
movq 0xf8(%rsp), %rcx
callq 0x4360
cmpq $0x10, 0x78(%rsp)
movq 0x108(%rsp), %r14
jb 0x1f3e8
leaq 0x28(%rsp), %rdx
movb $0x3b, (%rdx)
leaq 0x50(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x367c0
movq 0x10(%r14), %rax
leaq 0x50(%rsp), %rbx
movaps (%rbx), %xmm0
movq 0x10(%rbx), %rcx
movq %rcx, 0x10(%r14)
movups (%r14), %xmm1
movups %xmm0, (%r14)
movq %rsp, %rdi
movaps %xmm1, (%rdi)
movq %rax, 0x10(%rdi)
xorps %xmm0, %xmm0
movaps %xmm0, (%rbx)
movq $0x0, 0x10(%rbx)
callq 0x6aac
movq %rbx, %rdi
callq 0x6aac
movq (%r14), %rbx
cmpq 0x8(%r14), %rbx
je 0x1f3f3
leaq 0x50(%rsp), %r15
movq %rsp, %rbp
movq %r13, 0x98(%rsp)
leaq 0x60(%rsp), %rax
movq %rax, 0x50(%rsp)
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
movq %r15, %rdi
callq 0xd940
movl $0x1, %ecx
movq %r15, %rdi
leaq 0x1b4da(%rip), %rsi     # 0x3a5ae
xorl %edx, %edx
callq 0x4590
cmpq $-0x1, %rax
jne 0x1f0e6
movq 0x58(%rsp), %rax
testq %rax, %rax
je 0x1f121
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
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x1f121
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x4340
movq (%r13), %rdi
movq 0x8(%r13), %rsi
movq %rbx, %rdx
callq 0x222de
cmpq 0x8(%r13), %rax
je 0x1f3bc
movq 0x2d20e(%rip), %rax     # 0x4c350
testq %rax, %rax
jne 0x1f234
movl $0x11, %edx
movq 0x2ce71(%rip), %rdi     # 0x4bfc8
leaq 0x1dabf(%rip), %rsi     # 0x3cc1d
callq 0x43a0
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq 0x2ce57(%rip), %rdi     # 0x4bfc8
callq 0x43a0
movq %rax, %r12
movl $0x4, %edx
movq %rax, %rdi
leaq 0x1dd6e(%rip), %rsi     # 0x3cef6
callq 0x43a0
movq 0x100(%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq %r12, %rdi
callq 0x43a0
movq %rax, %r12
movl $0x28, %edx
movq %rax, %rdi
leaq 0x1da79(%rip), %rsi     # 0x3cc2f
callq 0x43a0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x4310
movsbl %al, %esi
movq %r12, %rdi
callq 0x4030
movq %rax, %rdi
callq 0x4220
movl $0x54, %edx
movq 0x2cdd9(%rip), %rdi     # 0x4bfc8
leaq 0x1da62(%rip), %rsi     # 0x3cc58
callq 0x43a0
movq 0x2cdc6(%rip), %rcx     # 0x4bfc8
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x4310
movsbl %al, %esi
movq 0x2cda8(%rip), %rdi     # 0x4bfc8
callq 0x4030
movq %rax, %rdi
callq 0x4220
movq 0x2d11c(%rip), %rax     # 0x4c350
movq %rbp, %r13
movq %r14, %rbp
movq %r15, %r14
incq %rax
movq %rax, 0x2d109(%rip)     # 0x4c350
movq 0x118(%rsp), %rax
movq (%rax), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4130
movq %rax, %r12
leaq 0xb0(%rsp), %rax
movq %rax, 0xa0(%rsp)
movq 0x110(%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0xa0(%rsp), %r15
movq %r15, %rdi
callq 0xd940
movq %r15, %rdi
leaq 0x1fd38(%rip), %rsi     # 0x3efd2
callq 0x45e0
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq %r15, %rdi
callq 0x4120
leaq 0x38(%rsp), %rdi
movq %rdi, 0x28(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
leaq 0x10(%rsp), %rsi
movq %r14, %r15
je 0x1f2de
movq %rdx, 0x28(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x38(%rsp)
jmp 0x1f2e4
movups (%rcx), %xmm0
movups %xmm0, (%rdi)
movq %rbp, %r14
movq 0x8(%rax), %rdx
movq %rdx, 0x30(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq %rsi, (%rsp)
movq 0x28(%rsp), %rax
cmpq %rdi, %rax
movq %r13, %rbp
je 0x1f320
movq %rax, (%rsp)
movq 0x38(%rsp), %rax
movq %rax, 0x10(%rsp)
jmp 0x1f326
movups (%rdi), %xmm0
movups %xmm0, (%rsi)
movq 0x98(%rsp), %r13
movq 0x30(%rsp), %rax
movq %rax, 0x8(%rsp)
movq %rdi, 0x28(%rsp)
movq $0x0, 0x30(%rsp)
movb $0x0, 0x38(%rsp)
movq %r12, 0x20(%rsp)
movq 0x190(%rsp), %rdi
movq %rbp, %rsi
callq 0x22406
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x1f37b
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x4340
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x1f397
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x4340
movq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rax
cmpq %rax, %rdi
je 0x1f3bc
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x4340
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x1f3d8
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x4340
addq $0x20, %rbx
cmpq 0x8(%r14), %rbx
jne 0x1f0a9
jmp 0x1f3f3
movq (%r14), %rsi
movq %r14, %rdi
callq 0x2228c
leaq 0x80(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1f414
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x4340
leaq 0x130(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
leaq 0xd0(%rsp), %rbx
movl 0x4c(%rsp), %ebp
je 0x1f441
movq 0x130(%rsp), %rsi
incq %rsi
callq 0x4340
movq 0xc0(%rsp), %rdi
cmpq %rbx, %rdi
je 0x1f45e
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x4340
leaq 0x140(%rsp), %rdi
callq 0x6aac
leaq 0xe0(%rsp), %rdi
callq 0x6aac
movl %ebp, %eax
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1d6ec(%rip), %rdi     # 0x3cb7f
leaq 0x1ca87(%rip), %rsi     # 0x3bf21
leaq 0x1d6fc(%rip), %rcx     # 0x3cb9d
movl $0x6c8, %edx            # imm = 0x6C8
callq 0x41f0
jmp 0x1f556
jmp 0x1f55b
jmp 0x1f55b
movq %rax, %rbx
jmp 0x1f5c9
jmp 0x1f4c9
jmp 0x1f560
movq %rax, %rbx
jmp 0x1f5ee
jmp 0x1f568
jmp 0x1f4d8
movq %rax, %rbx
jmp 0x1f51c
jmp 0x1f568
movq %rax, %rbx
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x1f500
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x4340
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x1f51c
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x4340
movq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rax
cmpq %rax, %rdi
je 0x1f56b
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x4340
jmp 0x1f56b
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r14, %rdi
je 0x1f5a8
movq 0x10(%rsp), %rsi
jmp 0x1f5a0
movq %rax, %rbx
jmp 0x1f587
movq %rax, %rbx
jmp 0x1f5a8
movq %rax, %rbx
jmp 0x1f5fb
movq %rax, %rbx
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x1f587
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x4340
leaq 0x80(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1f5a8
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x4340
leaq 0x130(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1f5c9
movq 0x130(%rsp), %rsi
incq %rsi
callq 0x4340
movq 0xc0(%rsp), %rdi
leaq 0xd0(%rsp), %rax
cmpq %rax, %rdi
je 0x1f5ee
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x4340
leaq 0x140(%rsp), %rdi
callq 0x6aac
leaq 0xe0(%rsp), %rdi
callq 0x6aac
movq %rbx, %rdi
callq 0x45a0