// File: schneebergerlab[P]DrLink/read_chrsize.cpp
// Function: read_chrsize(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::map<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::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::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>>*)
bool read_chrsize(string chrSizeFile, map<string, string>* chrSizes)
{
    ifstream fp;
    fp.open(chrSizeFile.c_str(), ios::in);
    if(!fp.good())
    {
        cout << "   Error: cannot open chr size file " << chrSizeFile << endl;
        return false;
    }
    bool verbose = true;
    // Chr15	1091291
    cout << "\n   Info: reading sizes of chromosomes..." << endl;
    while(fp.good())
    {
        string line("");
        getline(fp, line);
        if(line.size()==0 || line[0]=='#') continue;
        
        vector<string> lineinfo = split_string(line, '\t');
        if(lineinfo.size() < 2) continue;
        
        map<string, string>::iterator itr;
        itr = (*chrSizes).find(lineinfo[0]);
        if(itr == (*chrSizes).end())
        {
            (*chrSizes).insert(std::pair<string, string>(lineinfo[0], lineinfo[1]));
            if(verbose)
            cout << "   Info: " << lineinfo[0] << " with size " << lineinfo[1]    << endl;
        }
        else
        {
            cout << "   Warning: repeated info " <<  line << endl;
        }        
    }
    fp.close();
    cout << "   Info: " << (*chrSizes).size() << " chrs recorded with size info." << endl << endl;
    return true;
}

// Assembly:
subq $0x3b8, %rsp            # imm = 0x3B8
movq %rdi, 0xc0(%rsp)
movq %rdi, 0x3a8(%rsp)
movq %rsi, 0x3a0(%rsp)
leaq 0x198(%rsp), %rdi
movq %rdi, 0xc8(%rsp)
callq 0x5500
movq 0xc0(%rsp), %rdi
callq 0x51d0
movq 0xc8(%rsp), %rdi
movq %rax, %rsi
movl $0x8, %edx
callq 0x52c0
jmp 0x181a8
movq 0x198(%rsp), %rax
movq -0x18(%rax), %rax
leaq 0x198(%rsp,%rax), %rdi
callq 0x5760
movb %al, 0xbf(%rsp)
jmp 0x181ca
movb 0xbf(%rsp), %al
testb $0x1, %al
jne 0x1825e
jmp 0x181db
movq 0x6cde6(%rip), %rdi     # 0x84fc8
leaq 0x4ee1b(%rip), %rsi     # 0x67004
callq 0x5460
movq %rax, 0xb0(%rsp)
jmp 0x181f8
movq 0xc0(%rsp), %rsi
movq 0xb0(%rsp), %rdi
callq 0x53e0
movq %rax, 0xa8(%rsp)
jmp 0x18217
movq 0xa8(%rsp), %rdi
movq 0x6cd8a(%rip), %rsi     # 0x84fb0
callq 0x54b0
jmp 0x1822d
movb $0x0, 0x3b7(%rsp)
movl $0x1, 0x188(%rsp)
jmp 0x18742
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x190(%rsp)
movl %eax, 0x18c(%rsp)
jmp 0x18760
movb $0x1, 0x187(%rsp)
movq 0x6cd5b(%rip), %rdi     # 0x84fc8
leaq 0x4edb5(%rip), %rsi     # 0x67029
callq 0x5460
movq %rax, 0xa0(%rsp)
jmp 0x18283
movq 0xa0(%rsp), %rdi
movq 0x6cd1e(%rip), %rsi     # 0x84fb0
callq 0x54b0
jmp 0x18299
jmp 0x1829b
movq 0x198(%rsp), %rax
movq -0x18(%rax), %rax
leaq 0x198(%rsp,%rax), %rdi
callq 0x5760
movb %al, 0x9f(%rsp)
jmp 0x182bd
movb 0x9f(%rsp), %al
testb $0x1, %al
jne 0x182cd
jmp 0x186a4
leaq 0x15f(%rsp), %rdi
movq %rdi, 0x90(%rsp)
callq 0x57c0
movq 0x90(%rsp), %rdx
leaq 0x528a3(%rip), %rsi     # 0x6ab94
leaq 0x160(%rsp), %rdi
callq 0x6880
jmp 0x18300
leaq 0x15f(%rsp), %rdi
callq 0x54d0
leaq 0x198(%rsp), %rdi
leaq 0x160(%rsp), %rsi
callq 0x50c0
jmp 0x18324
leaq 0x160(%rsp), %rdi
callq 0x5310
cmpq $0x0, %rax
je 0x18362
xorl %eax, %eax
movl %eax, %esi
leaq 0x160(%rsp), %rdi
callq 0x5880
movq %rax, 0x88(%rsp)
jmp 0x18352
movq 0x88(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x23, %eax
jne 0x183b1
movl $0x2, 0x188(%rsp)
jmp 0x18661
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x190(%rsp)
movl %eax, 0x18c(%rsp)
leaq 0x15f(%rsp), %rdi
callq 0x54d0
jmp 0x18760
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x190(%rsp)
movl %eax, 0x18c(%rsp)
jmp 0x18692
movb $0x9, 0x13f(%rsp)
leaq 0x140(%rsp), %rdi
leaq 0x160(%rsp), %rsi
leaq 0x13f(%rsp), %rdx
callq 0x60790
jmp 0x183d8
leaq 0x140(%rsp), %rdi
callq 0xfbb0
cmpq $0x2, %rax
jae 0x183fb
movl $0x2, 0x188(%rsp)
jmp 0x18654
leaq 0x130(%rsp), %rdi
callq 0x18780
movq 0x3a0(%rsp), %rax
movq %rax, 0x78(%rsp)
xorl %eax, %eax
movl %eax, %esi
leaq 0x140(%rsp), %rdi
callq 0x88f0
movq 0x78(%rsp), %rdi
movq %rax, %rsi
callq 0x187a0
movq %rax, 0x80(%rsp)
jmp 0x1843d
movq 0x80(%rsp), %rax
movq %rax, 0x128(%rsp)
movq 0x128(%rsp), %rax
movq %rax, 0x130(%rsp)
movq 0x3a0(%rsp), %rdi
callq 0x187f0
movq %rax, 0x120(%rsp)
leaq 0x130(%rsp), %rdi
leaq 0x120(%rsp), %rsi
callq 0x187d0
testb $0x1, %al
jne 0x18490
jmp 0x18601
movq 0x3a0(%rsp), %rax
movq %rax, 0x60(%rsp)
xorl %eax, %eax
movl %eax, %esi
leaq 0x140(%rsp), %rdi
movq %rdi, 0x68(%rsp)
callq 0x88f0
movq 0x68(%rsp), %rdi
movq %rax, 0x70(%rsp)
movl $0x1, %esi
callq 0x88f0
movq 0x70(%rsp), %rsi
movq %rax, %rdx
leaq 0xe0(%rsp), %rdi
callq 0x18870
jmp 0x184de
movq 0x60(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
callq 0x18820
movb %dl, 0x57(%rsp)
movq %rax, 0x58(%rsp)
jmp 0x184fb
movb 0x57(%rsp), %al
movq 0x58(%rsp), %rcx
movq %rcx, 0xd0(%rsp)
movb %al, 0xd8(%rsp)
leaq 0xe0(%rsp), %rdi
callq 0x188e0
testb $0x1, 0x187(%rsp)
je 0x185ff
movq 0x6ca93(%rip), %rdi     # 0x84fc8
leaq 0x4e96a(%rip), %rsi     # 0x66ea6
callq 0x5460
movq %rax, 0x48(%rsp)
jmp 0x18548
xorl %eax, %eax
movl %eax, %esi
leaq 0x140(%rsp), %rdi
callq 0x88f0
movq 0x48(%rsp), %rdi
movq %rax, %rsi
callq 0x53e0
movq %rax, 0x40(%rsp)
jmp 0x1856d
movq 0x40(%rsp), %rdi
leaq 0x4eada(%rip), %rsi     # 0x67053
callq 0x5460
movq %rax, 0x38(%rsp)
jmp 0x18585
leaq 0x140(%rsp), %rdi
movl $0x1, %esi
callq 0x88f0
movq 0x38(%rsp), %rdi
movq %rax, %rsi
callq 0x53e0
movq %rax, 0x30(%rsp)
jmp 0x185ab
movq 0x30(%rsp), %rdi
movq 0x6c9f9(%rip), %rsi     # 0x84fb0
callq 0x54b0
jmp 0x185be
jmp 0x185ff
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x190(%rsp)
movl %eax, 0x18c(%rsp)
jmp 0x18685
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x190(%rsp)
movl %eax, 0x18c(%rsp)
leaq 0xe0(%rsp), %rdi
callq 0x188e0
jmp 0x18685
jmp 0x18649
movq 0x6c9c0(%rip), %rdi     # 0x84fc8
leaq 0x4ea50(%rip), %rsi     # 0x6705f
callq 0x5460
movq %rax, 0x28(%rsp)
jmp 0x1861b
movq 0x28(%rsp), %rdi
leaq 0x160(%rsp), %rsi
callq 0x53e0
movq %rax, 0x20(%rsp)
jmp 0x18634
movq 0x20(%rsp), %rdi
movq 0x6c970(%rip), %rsi     # 0x84fb0
callq 0x54b0
jmp 0x18647
jmp 0x18649
movl $0x0, 0x188(%rsp)
leaq 0x140(%rsp), %rdi
callq 0x8910
leaq 0x160(%rsp), %rdi
callq 0x58b8
movl 0x188(%rsp), %eax
testl %eax, %eax
je 0x18680
jmp 0x1867b
jmp 0x1829b
jmp 0x1829b
leaq 0x140(%rsp), %rdi
callq 0x8910
leaq 0x160(%rsp), %rdi
callq 0x58b8
jmp 0x18760
leaq 0x198(%rsp), %rdi
callq 0x50d0
jmp 0x186b3
movq 0x6c90e(%rip), %rdi     # 0x84fc8
leaq 0x4e7e5(%rip), %rsi     # 0x66ea6
callq 0x5460
movq %rax, 0x18(%rsp)
jmp 0x186cd
movq 0x3a0(%rsp), %rdi
callq 0x18910
movq 0x18(%rsp), %rdi
movq %rax, %rsi
callq 0x50f0
movq %rax, 0x10(%rsp)
jmp 0x186ee
movq 0x10(%rsp), %rdi
leaq 0x4e980(%rip), %rsi     # 0x6707a
callq 0x5460
movq %rax, 0x8(%rsp)
jmp 0x18706
movq 0x8(%rsp), %rdi
movq 0x6c89e(%rip), %rsi     # 0x84fb0
callq 0x54b0
movq %rax, (%rsp)
jmp 0x1871d
movq (%rsp), %rdi
movq 0x6c888(%rip), %rsi     # 0x84fb0
callq 0x54b0
jmp 0x1872f
movb $0x1, 0x3b7(%rsp)
movl $0x1, 0x188(%rsp)
leaq 0x198(%rsp), %rdi
callq 0x5100
movb 0x3b7(%rsp), %al
andb $0x1, %al
addq $0x3b8, %rsp            # imm = 0x3B8
retq
leaq 0x198(%rsp), %rdi
callq 0x5100
movq 0x190(%rsp), %rdi
callq 0x57b0
nopw (%rax,%rax)