// File: /workspace/github_cpp_makefile_star2_O3/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 $0x2d8, %rsp            # imm = 0x2D8
movq %rsi, %rbx
movq %rdi, %rbp
leaq 0xd0(%rsp), %r14
movq %r14, %rdi
movl $0x8, %edx
callq 0x5500
movq (%r14), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0xf0(%rsp,%rax)
je 0x120c7
movq 0x2af92(%rip), %rdi     # 0x3cff0
leaq 0x1f2b1(%rip), %rsi     # 0x31316
movl $0xf, %edx
callq 0x53a0
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq 0x2af73(%rip), %rdi     # 0x3cff0
callq 0x53a0
movq %rax, %rbx
leaq 0x1f29a(%rip), %rsi     # 0x31326
movl $0xf, %edx
movq %rax, %rdi
callq 0x53a0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x5310
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5040
movq %rax, %rdi
callq 0x5240
xorl %ebx, %ebx
jmp 0x12512
leaq 0x38(%rsp), %rcx
movq %rcx, -0x10(%rcx)
xorl %r15d, %r15d
movq %r15, -0x8(%rcx)
movb %r15b, (%rcx)
leaq 0x18(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq %r15, -0x8(%rcx)
movb %r15b, (%rcx)
leaq 0x88(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq %r15, -0x8(%rcx)
movb %r15b, (%rcx)
movq %rsp, %rcx
movl $0xffffffff, (%rcx)     # imm = 0xFFFFFFFF
leaq 0xe8(%rbp), %rcx
movq %rcx, 0x70(%rsp)
leaq 0xf0(%rbp), %rcx
movq %rcx, 0x68(%rsp)
leaq 0x88(%rbp), %r12
leaq 0x90(%rbp), %rcx
movq %rcx, 0x60(%rsp)
leaq 0xb8(%rbp), %rcx
movq %rcx, 0x58(%rsp)
movq %rbp, 0x48(%rsp)
leaq 0x118(%rbp), %rcx
movq %rcx, 0x50(%rsp)
leaq 0xd0(%rsp), %rbx
leaq 0x28(%rsp), %r14
leaq 0x8(%rsp), %rbp
movl $0x0, 0x4(%rsp)
leaq (%rsp,%rax), %rdi
addq $0xd0, %rdi
movl $0xa, %esi
callq 0x5310
movsbl %al, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5600
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
cmpl $0x0, 0x20(%rax,%rcx)
jne 0x12347
movq 0x30(%rsp), %rax
testq %rax, %rax
je 0x121b5
movq 0x28(%rsp), %rcx
cmpb $0x3e, (%rcx)
jne 0x122de
cmpq $0x0, 0x10(%rsp)
je 0x1225d
movq 0x70(%rsp), %rdi
movq %rbp, %rsi
callq 0x2b218
cmpq 0x68(%rsp), %rax
je 0x123e3
movq %r12, %rdi
movq %rbp, %rsi
callq 0x2b218
cmpq 0x60(%rsp), %rax
jne 0x12202
movq %r12, %rdi
movq %rbp, %rsi
callq 0x283a0
movl 0x4(%rsp), %ecx
movl %ecx, (%rax)
incl %ecx
movl %ecx, 0x4(%rsp)
movq %r12, %rdi
movq %rbp, %rsi
callq 0x283a0
movl (%rax), %eax
movl %eax, (%rsp)
movq 0x58(%rsp), %rdi
movq %rsp, %rsi
callq 0x2851c
movq %rax, %rdi
movq %rbp, %rsi
callq 0x51c0
movq 0x50(%rsp), %rdi
movq %rsp, %rsi
callq 0x2851c
movq %rax, %rdi
leaq 0x78(%rsp), %rsi
callq 0x51c0
incl %r15d
movq $0x0, 0x10(%rsp)
movq 0x8(%rsp), %rax
movb $0x0, (%rax)
movq 0x30(%rsp), %rax
testq %rax, %rax
je 0x1230c
leaq 0x98(%rsp), %rdi
movq %r14, %rsi
movl $0x20, %edx
callq 0x2f36e
movq 0x98(%rsp), %rsi
movl $0x1, %edx
leaq 0xb0(%rsp), %r13
movq %r13, %rdi
movq $-0x1, %rcx
callq 0x5360
movq %rbp, %rdi
movq %r13, %rsi
callq 0x53e0
movq 0xb0(%rsp), %rdi
leaq 0xc0(%rsp), %rax
cmpq %rax, %rdi
je 0x122cf
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x5340
leaq 0x98(%rsp), %rdi
callq 0xe71c
jmp 0x1230c
cmpq $0x0, 0x10(%rsp)
je 0x12320
movq %r14, %rdi
movl $0x20, %esi
xorl %edx, %edx
callq 0x5400
cmpq $-0x1, %rax
je 0x12331
movq $0x0, 0x10(%rsp)
movq 0x8(%rsp), %rax
movb $0x0, (%rax)
movq $0x0, 0x80(%rsp)
movq 0x78(%rsp), %rax
movb $0x0, (%rax)
movq 0xd0(%rsp), %rax
movq -0x18(%rax), %rax
jmp 0x12168
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
leaq 0x78(%rsp), %rdi
callq 0x50f0
jmp 0x12320
cmpq $0x0, 0x10(%rsp)
je 0x1243e
leaq 0x8(%rsp), %rsi
movq 0x70(%rsp), %rdi
callq 0x2b218
movq 0x48(%rsp), %rbx
cmpq 0x68(%rsp), %rax
je 0x1244a
leaq 0x8(%rsp), %rsi
movq %r12, %rdi
callq 0x2b218
cmpq 0x60(%rsp), %rax
jne 0x12399
leaq 0x8(%rsp), %rsi
movq %r12, %rdi
callq 0x283a0
movl 0x4(%rsp), %ecx
movl %ecx, (%rax)
leaq 0x8(%rsp), %rsi
movq %r12, %rdi
callq 0x283a0
movl (%rax), %eax
movq %rsp, %rsi
movl %eax, (%rsi)
movq 0x58(%rsp), %rdi
callq 0x2851c
leaq 0x8(%rsp), %rsi
movq %rax, %rdi
callq 0x51c0
movq %rsp, %rsi
movq 0x50(%rsp), %rdi
callq 0x2851c
leaq 0x78(%rsp), %rsi
movq %rax, %rdi
callq 0x51c0
incl %r15d
jmp 0x12443
movq 0x2abe6(%rip), %rdi     # 0x3cfd0
leaq 0x1ef45(%rip), %rsi     # 0x31336
movl $0x2c, %edx
callq 0x53a0
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq 0x2abc4(%rip), %rdi     # 0x3cfd0
callq 0x53a0
movq %rax, %rbx
leaq 0x1ef48(%rip), %rsi     # 0x31363
movl $0x20, %edx
movq %rax, %rdi
callq 0x53a0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x5310
jmp 0x124a3
movq 0x48(%rsp), %rbx
movl %r15d, (%rbx)
movb $0x1, %bl
jmp 0x124b8
movq 0x2ab7f(%rip), %rdi     # 0x3cfd0
leaq 0x1eede(%rip), %rsi     # 0x31336
movl $0x2c, %edx
callq 0x53a0
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq 0x2ab5d(%rip), %rdi     # 0x3cfd0
callq 0x53a0
movq %rax, %rbx
leaq 0x1eee1(%rip), %rsi     # 0x31363
movl $0x20, %edx
movq %rax, %rdi
callq 0x53a0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x5310
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5040
movq %rax, %rdi
callq 0x5240
xorl %ebx, %ebx
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x124da
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x5340
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x124f6
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x5340
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x12512
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x5340
leaq 0xd0(%rsp), %rdi
callq 0x50c0
movl %ebx, %eax
addq $0x2d8, %rsp            # imm = 0x2D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x12556
jmp 0x12556
jmp 0x12556
jmp 0x12556
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0xe71c
jmp 0x12559
jmp 0x12556
jmp 0x12556
movq %rax, %rbx
jmp 0x125b3
movq %rax, %rbx
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x1257b
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x5340
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x12597
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x5340
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x125b3
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x5340
leaq 0xd0(%rsp), %rdi
callq 0x50c0
movq %rbx, %rdi
callq 0x55c0