// File: schneebergerlab[P]DrLink/output_co.cpp
// Function: output_co(std::multimap<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::multimap<unsigned long, BPINFO, std::less<unsigned long>, std::allocator<std::pair<unsigned long const, BPINFO>>>, 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, std::multimap<unsigned long, BPINFO, std::less<unsigned long>, std::allocator<std::pair<unsigned long const, BPINFO>>>>>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
bool output_co(multimap<string, multimap<unsigned long, BPINFO> > rawbpmap, string rawbpfile)
{
    // output chr:left-coordinate-sorted raw break points: 
    // left-coordinate sorted raw break points
    fstream sortedrawfp;
    sortedrawfp.open(rawbpfile.c_str(), ios::out);
    if(!sortedrawfp.good())
    {
        cout << "   Error: cannot open file " << rawbpfile << " for collecting break point predictions. " << endl;
        return false;
    }
    sortedrawfp << "#chr\t"
                << "left_pos(sorted)\t"
                << "right_pos\t"
                << "score\t"
                << "left_alleles\t"
                << "right_alleles\t"
                << "barcode\t"
                << "vcf_mole_len\t"
                << "left_span\t"
                << "right_span\t"
                << "read_density\t"
                << "co_boundary_same_fragment\t"
                << "min_mole_RR_dist\t"
                << "max_mole_RR_dist\t"
                << "bam_mole_len\t"
                << "bam_mole_readNum\t"
                << "bam_mole_base_cov\t"          
                << "af_at_markers\t"
                << "cov_at_markers\t"
                << "co_size\t"
                << "readnum_left\t"
                << "readnum_right\t"
                << "maxium_RR_distance_in_CO\n";
                
    multimap<string, multimap<unsigned long, BPINFO> >::iterator chritr;
    multimap<string, multimap<unsigned long, BPINFO> >::iterator chritr_end;
    chritr = rawbpmap.begin();
    chritr_end = rawbpmap.end();
    while(chritr != chritr_end)
    {
        multimap<unsigned long, BPINFO> tmp;
        tmp = (*chritr).second;
        multimap<unsigned long, BPINFO>::iterator litr;
        multimap<unsigned long, BPINFO>::iterator litr_end;
        litr = tmp.begin();
        litr_end = tmp.end();
        while(litr != litr_end)
        {
            sortedrawfp << ((*litr).second).bpline << endl;
            litr ++;
        }
        chritr ++;
    }  
    sortedrawfp.close();     
    return true;
}

// Assembly:
subq $0x3b8, %rsp            # imm = 0x3B8
movq %rdi, 0xe8(%rsp)
movq %rsi, 0xf0(%rsp)
movq %rdi, 0x3a8(%rsp)
movq %rsi, 0x3a0(%rsp)
leaq 0x190(%rsp), %rdi
movq %rdi, 0xf8(%rsp)
callq 0x5530
movq 0xf0(%rsp), %rdi
callq 0x51d0
movq 0xf8(%rsp), %rdi
movq %rax, %rsi
movl $0x10, %edx
callq 0x53f0
jmp 0x64730
movq 0x190(%rsp), %rax
movq -0x18(%rax), %rax
leaq 0x190(%rsp,%rax), %rdi
callq 0x5760
movb %al, 0xe7(%rsp)
jmp 0x64752
movb 0xe7(%rsp), %al
testb $0x1, %al
jne 0x64804
jmp 0x64763
movq 0x2085e(%rip), %rdi     # 0x84fc8
leaq 0x23e5(%rip), %rsi      # 0x66b56
callq 0x5460
movq %rax, 0xd8(%rsp)
jmp 0x64780
movq 0xf0(%rsp), %rsi
movq 0xd8(%rsp), %rdi
callq 0x53e0
movq %rax, 0xd0(%rsp)
jmp 0x6479f
movq 0xd0(%rsp), %rdi
leaq 0x68b6(%rip), %rsi      # 0x6b064
callq 0x5460
movq %rax, 0xc8(%rsp)
jmp 0x647bd
movq 0xc8(%rsp), %rdi
movq 0x207e4(%rip), %rsi     # 0x84fb0
callq 0x54b0
jmp 0x647d3
movb $0x0, 0x3b7(%rsp)
movl $0x1, 0x180(%rsp)
jmp 0x64c5d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x188(%rsp)
movl %eax, 0x184(%rsp)
jmp 0x64c7b
leaq 0x1a0(%rsp), %rdi
leaq 0x3415(%rip), %rsi      # 0x67c28
callq 0x5460
movq %rax, 0xc0(%rsp)
jmp 0x64822
movq 0xc0(%rsp), %rdi
leaq 0x685d(%rip), %rsi      # 0x6b08e
callq 0x5460
movq %rax, 0xb8(%rsp)
jmp 0x64840
movq 0xb8(%rsp), %rdi
leaq 0x33e9(%rip), %rsi      # 0x67c38
callq 0x5460
movq %rax, 0xb0(%rsp)
jmp 0x6485e
movq 0xb0(%rsp), %rdi
leaq 0x33d6(%rip), %rsi      # 0x67c43
callq 0x5460
movq %rax, 0xa8(%rsp)
jmp 0x6487c
movq 0xa8(%rsp), %rdi
leaq 0x33bf(%rip), %rsi      # 0x67c4a
callq 0x5460
movq %rax, 0xa0(%rsp)
jmp 0x6489a
movq 0xa0(%rsp), %rdi
leaq 0x33af(%rip), %rsi      # 0x67c58
callq 0x5460
movq %rax, 0x98(%rsp)
jmp 0x648b8
movq 0x98(%rsp), %rdi
leaq 0x33a0(%rip), %rsi      # 0x67c67
callq 0x5460
movq %rax, 0x90(%rsp)
jmp 0x648d6
movq 0x90(%rsp), %rdi
leaq 0x338b(%rip), %rsi      # 0x67c70
callq 0x5460
movq %rax, 0x88(%rsp)
jmp 0x648f4
movq 0x88(%rsp), %rdi
leaq 0x337b(%rip), %rsi      # 0x67c7e
callq 0x5460
movq %rax, 0x80(%rsp)
jmp 0x64912
movq 0x80(%rsp), %rdi
leaq 0x3368(%rip), %rsi      # 0x67c89
callq 0x5460
movq %rax, 0x78(%rsp)
jmp 0x6492d
movq 0x78(%rsp), %rdi
leaq 0x335c(%rip), %rsi      # 0x67c95
callq 0x5460
movq %rax, 0x70(%rsp)
jmp 0x64945
movq 0x70(%rsp), %rdi
leaq 0x3352(%rip), %rsi      # 0x67ca3
callq 0x5460
movq %rax, 0x68(%rsp)
jmp 0x6495d
movq 0x68(%rsp), %rdi
leaq 0x3355(%rip), %rsi      # 0x67cbe
callq 0x5460
movq %rax, 0x60(%rsp)
jmp 0x64975
movq 0x60(%rsp), %rdi
leaq 0x334f(%rip), %rsi      # 0x67cd0
callq 0x5460
movq %rax, 0x58(%rsp)
jmp 0x6498d
movq 0x58(%rsp), %rdi
leaq 0x3349(%rip), %rsi      # 0x67ce2
callq 0x5460
movq %rax, 0x50(%rsp)
jmp 0x649a5
movq 0x50(%rsp), %rdi
leaq 0x333f(%rip), %rsi      # 0x67cf0
callq 0x5460
movq %rax, 0x48(%rsp)
jmp 0x649bd
movq 0x48(%rsp), %rdi
leaq 0x3339(%rip), %rsi      # 0x67d02
callq 0x5460
movq %rax, 0x40(%rsp)
jmp 0x649d5
movq 0x40(%rsp), %rdi
leaq 0x3334(%rip), %rsi      # 0x67d15
callq 0x5460
movq %rax, 0x38(%rsp)
jmp 0x649ed
movq 0x38(%rsp), %rdi
leaq 0x332b(%rip), %rsi      # 0x67d24
callq 0x5460
movq %rax, 0x30(%rsp)
jmp 0x64a05
movq 0x30(%rsp), %rdi
leaq 0x3323(%rip), %rsi      # 0x67d34
callq 0x5460
movq %rax, 0x28(%rsp)
jmp 0x64a1d
movq 0x28(%rsp), %rdi
leaq 0x6677(%rip), %rsi      # 0x6b0a0
callq 0x5460
movq %rax, 0x20(%rsp)
jmp 0x64a35
movq 0x20(%rsp), %rdi
leaq 0x666d(%rip), %rsi      # 0x6b0ae
callq 0x5460
movq %rax, 0x18(%rsp)
jmp 0x64a4d
movq 0x18(%rsp), %rdi
leaq 0x6664(%rip), %rsi      # 0x6b0bd
callq 0x5460
jmp 0x64a60
leaq 0x178(%rsp), %rdi
callq 0x615e0
leaq 0x170(%rsp), %rdi
callq 0x615e0
movq 0xe8(%rsp), %rdi
callq 0x63c30
movq 0xe8(%rsp), %rdi
movq %rax, 0x168(%rsp)
movq 0x168(%rsp), %rax
movq %rax, 0x178(%rsp)
callq 0x61650
movq %rax, 0x160(%rsp)
movq 0x160(%rsp), %rax
movq %rax, 0x170(%rsp)
leaq 0x178(%rsp), %rdi
leaq 0x170(%rsp), %rsi
callq 0x63c60
testb $0x1, %al
jne 0x64ae2
jmp 0x64c3b
leaq 0x130(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x61680
leaq 0x178(%rsp), %rdi
callq 0x617f0
movq 0x10(%rsp), %rdi
movq %rax, %rsi
addq $0x20, %rsi
callq 0x63c80
jmp 0x64b14
leaq 0x128(%rsp), %rdi
callq 0x63cb0
leaq 0x120(%rsp), %rdi
callq 0x63cb0
leaq 0x130(%rsp), %rdi
callq 0x63cd0
movq %rax, 0x118(%rsp)
movq 0x118(%rsp), %rax
movq %rax, 0x128(%rsp)
leaq 0x130(%rsp), %rdi
callq 0x63d00
movq %rax, 0x110(%rsp)
movq 0x110(%rsp), %rax
movq %rax, 0x120(%rsp)
leaq 0x128(%rsp), %rdi
leaq 0x120(%rsp), %rsi
callq 0x63d90
testb $0x1, %al
jne 0x64b93
jmp 0x64c12
leaq 0x1a0(%rsp), %rax
movq %rax, (%rsp)
leaq 0x128(%rsp), %rdi
callq 0x63d30
movq (%rsp), %rdi
movq %rax, %rsi
addq $0x70, %rsi
callq 0x53e0
movq %rax, 0x8(%rsp)
jmp 0x64bc3
movq 0x8(%rsp), %rdi
movq 0x203e1(%rip), %rsi     # 0x84fb0
callq 0x54b0
jmp 0x64bd6
leaq 0x128(%rsp), %rdi
xorl %esi, %esi
callq 0x63d50
movq %rax, 0x108(%rsp)
jmp 0x64b78
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x188(%rsp)
movl %eax, 0x184(%rsp)
leaq 0x130(%rsp), %rdi
callq 0x31e50
jmp 0x64c7b
leaq 0x178(%rsp), %rdi
xorl %esi, %esi
callq 0x63f00
movq %rax, 0x100(%rsp)
leaq 0x130(%rsp), %rdi
callq 0x31e50
jmp 0x64ac4
leaq 0x190(%rsp), %rdi
callq 0x5080
jmp 0x64c4a
movb $0x1, 0x3b7(%rsp)
movl $0x1, 0x180(%rsp)
leaq 0x190(%rsp), %rdi
callq 0x50e0
movb 0x3b7(%rsp), %al
andb $0x1, %al
addq $0x3b8, %rsp            # imm = 0x3B8
retq
leaq 0x190(%rsp), %rdi
callq 0x50e0
movq 0x188(%rsp), %rdi
callq 0x57b0
nop