// File: /workspace/github_cpp_makefile_star2_O2/medvedevgroup[P]varmatch/src/wholegenome.cpp
// Function: WholeGenome::ReadWholeGenomeSequence(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
bool WholeGenome::ReadWholeGenomeSequence(string filename){
    std::ifstream input(filename);
    if(!input.good()){
        std::cerr << "Error opening '"<<filename<<"'. Bailing out." << std::endl;
        return false;
    }

    std::string line, name, content;
    int real_chrom_num = 0;
    int chr_id = 0;
    int current_id = -1;
    while( std::getline( input, line ).good() ){
        if( line.empty() || line[0] == '>' ){ // Identifier marker
            if( !name.empty() ){ // Print out what we read from the last entry
                //std::cout << name << " : " << content << std::endl;
                if(chrname_dict.find(name) == chrname_dict.end()){
                    cout << "[VarMatch] Error: detected chromosome name: " << name <<" does not exist in human genome." << endl;
                    return false;
                }
                //int chr_id = chrname_dict[name];
                if(chrid_by_chrname.find(name) == chrid_by_chrname.end()){
                    chrid_by_chrname[name] = chr_id;
                    chr_id++;
                }
                current_id = chrid_by_chrname[name];
                chrname_by_chrid[current_id] = name;
                genome_sequences[current_id] = content;
                real_chrom_num++;
                name.clear();
            }
            if( !line.empty() ){
                name = split(line, ' ')[0].substr(1);
            }
            content.clear();
        } else if( !name.empty() ){
            if( line.find(' ') != std::string::npos ){ // Invalid sequence--no spaces allowed
                name.clear();
                content.clear();
            } else {
                content += line;
            }
        }
    }
    if( !name.empty() ){ // Print out what we read from the last entry
        //std::cout << name << " : " << content << std::endl;
        if(chrname_dict.find(name) == chrname_dict.end()){
            cout << "[VarMatch] Error: detected chromosome name: " << name <<" does not exist in human genome." << endl;
            return false;
        }
        if(chrid_by_chrname.find(name) == chrid_by_chrname.end()){
            chrid_by_chrname[name] = chr_id;
            chr_id++;
        }
        current_id = chrid_by_chrname[name];
        chrname_by_chrid[current_id] = name;
        genome_sequences[current_id] = content;
        real_chrom_num++;
    }
    // test

    chrom_num = real_chrom_num;
    //dout << "detected chromosome num: " << chrom_num << endl;
//    for(auto it = genome_sequences.begin(); it != genome_sequences.end(); ++it){
//        cout << it->first << ":" << (it->second).length();
//    }
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2e8, %rsp            # imm = 0x2E8
movq %rsi, %r14
movq %rdi, %rbx
leaq 0xe0(%rsp), %r15
pushq $0x8
popq %rdx
movq %r15, %rdi
callq 0x54b0
movq (%r15), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x100(%rsp,%rax)
je 0xd99f
movq 0x22686(%rip), %rdi     # 0x2fff0
leaq 0x1495d(%rip), %rsi     # 0x222ce
callq 0x52f0
movq %rax, %rdi
movq %r14, %rsi
callq 0x52c0
leaq 0x14956(%rip), %rsi     # 0x222de
movq %rax, %rdi
callq 0x52f0
movq %rax, %rdi
callq 0x5190
xorl %ebx, %ebx
jmp 0xdcef
leaq 0x98(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %r12d, %r12d
leaq 0x28(%rsp), %rcx
movq %rcx, -0x10(%rcx)
andq $0x0, -0x8(%rcx)
movb %r12b, (%rax)
movb %r12b, (%rcx)
leaq 0x78(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %r12b, (%rax)
leaq 0x8(%rsp), %rax
orl $-0x1, (%rax)
leaq 0xe8(%rbx), %rax
movq %rax, 0x58(%rsp)
leaq 0xf0(%rbx), %rax
movq %rax, 0x50(%rsp)
leaq 0x88(%rbx), %rax
movq %rax, 0x10(%rsp)
leaq 0x90(%rbx), %rax
movq %rax, 0x48(%rsp)
leaq 0xb8(%rbx), %rax
movq %rax, 0x40(%rsp)
movq %rbx, 0x60(%rsp)
leaq 0x118(%rbx), %rax
movq %rax, 0x38(%rsp)
leaq 0xe0(%rsp), %r14
leaq 0x88(%rsp), %r15
pushq $0x20
popq %rbp
leaq 0x68(%rsp), %r13
movl $0x0, 0xc(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x5090
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
cmpl $0x0, 0x20(%rax,%rcx)
jne 0xdbea
movq 0x90(%rsp), %rax
testq %rax, %rax
je 0xdaaf
movq 0x88(%rsp), %rcx
cmpb $0x3e, (%rcx)
je 0xdaaf
cmpq $0x0, 0x20(%rsp)
je 0xda4d
movq %r15, %rdi
movl %ebp, %esi
xorl %edx, %edx
callq 0x53c0
cmpq $-0x1, %rax
jne 0xdbc9
movq %r13, %rdi
movq %r15, %rsi
callq 0x55c0
jmp 0xda4d
cmpq $0x0, 0x20(%rsp)
je 0xdb6a
movq 0x58(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x1caec
cmpq 0x50(%rsp), %rax
je 0xdc95
movq 0x10(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x1caec
cmpq 0x48(%rsp), %rax
jne 0xdb06
movq 0x10(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x19942
movl 0xc(%rsp), %ecx
movl %ecx, (%rax)
incl %ecx
movl %ecx, 0xc(%rsp)
movq 0x10(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x19942
movl (%rax), %eax
movl %eax, 0x8(%rsp)
movq 0x40(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x19a5a
movq %rax, %rdi
leaq 0x18(%rsp), %rsi
callq 0x51d0
movq 0x38(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x19a5a
movq %rax, %rdi
movq %r13, %rsi
callq 0x51d0
andq $0x0, 0x20(%rsp)
incl %r12d
movq 0x18(%rsp), %rax
movb $0x0, (%rax)
movq 0x90(%rsp), %rax
testq %rax, %rax
je 0xdbd7
movq %r12, %rbx
leaq 0xa8(%rsp), %rdi
movq %r15, %rsi
movl %ebp, %edx
callq 0x2061d
movq 0xa8(%rsp), %rsi
leaq 0xc0(%rsp), %r12
movq %r12, %rdi
pushq $0x1
popq %rdx
pushq $-0x1
popq %rcx
callq 0x5320
leaq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0x5390
movq %r12, %rdi
callq 0x55e8
leaq 0xa8(%rsp), %rdi
callq 0xadcc
movq %rbx, %r12
jmp 0xdbd7
andq $0x0, 0x20(%rsp)
movq 0x18(%rsp), %rax
movb $0x0, (%rax)
andq $0x0, 0x70(%rsp)
movq 0x68(%rsp), %rax
movb $0x0, (%rax)
jmp 0xda4d
cmpq $0x0, 0x20(%rsp)
je 0xdc89
leaq 0x18(%rsp), %rsi
movq 0x58(%rsp), %rdi
callq 0x1caec
cmpq 0x50(%rsp), %rax
je 0xdc95
leaq 0x18(%rsp), %rsi
movq 0x10(%rsp), %rdi
callq 0x1caec
cmpq 0x48(%rsp), %rax
jne 0xdc3b
leaq 0x18(%rsp), %rsi
movq 0x10(%rsp), %rdi
callq 0x19942
movl 0xc(%rsp), %ecx
movl %ecx, (%rax)
leaq 0x18(%rsp), %rsi
movq 0x10(%rsp), %rdi
callq 0x19942
movl (%rax), %eax
leaq 0x8(%rsp), %rsi
movl %eax, (%rsi)
movq 0x40(%rsp), %rdi
callq 0x19a5a
leaq 0x18(%rsp), %rsi
movq %rax, %rdi
callq 0x51d0
leaq 0x8(%rsp), %rsi
movq 0x38(%rsp), %rdi
callq 0x19a5a
leaq 0x68(%rsp), %rsi
movq %rax, %rdi
callq 0x51d0
incl %r12d
movq 0x60(%rsp), %rax
movl %r12d, (%rax)
movb $0x1, %bl
jmp 0xdcce
movq 0x22324(%rip), %rdi     # 0x2ffc0
leaq 0x1464b(%rip), %rsi     # 0x222ee
callq 0x52f0
leaq 0x18(%rsp), %rsi
movq %rax, %rdi
callq 0x52c0
leaq 0x1465f(%rip), %rsi     # 0x2231b
movq %rax, %rdi
callq 0x52f0
movq %rax, %rdi
callq 0x5190
xorl %ebx, %ebx
leaq 0x68(%rsp), %rdi
callq 0x55e8
leaq 0x18(%rsp), %rdi
callq 0x55e8
leaq 0x88(%rsp), %rdi
callq 0x55e8
leaq 0xe0(%rsp), %rdi
callq 0x50e0
movl %ebx, %eax
addq $0x2e8, %rsp            # imm = 0x2E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xdd35
jmp 0xdd35
jmp 0xdd35
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0xadcc
jmp 0xdd38
jmp 0xdd35
jmp 0xdd35
jmp 0xdd35
jmp 0xdd35
movq %rax, %rbx
jmp 0xdd59
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x55e8
leaq 0x18(%rsp), %rdi
callq 0x55e8
leaq 0x88(%rsp), %rdi
callq 0x55e8
leaq 0xe0(%rsp), %rdi
callq 0x50e0
movq %rbx, %rdi
callq 0x5540