// File: /workspace/github_cpp_makefile_star2_O1/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, %r14
movq %rdi, %rbx
leaq 0xd0(%rsp), %r13
movq %r13, %rdi
movl $0x8, %edx
callq 0x5500
movq (%r13), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0xf0(%rsp,%rax)
je 0x12154
movq 0x29f05(%rip), %rdi     # 0x3bff0
leaq 0x1f1f4(%rip), %rsi     # 0x312e6
movl $0xf, %edx
callq 0x53a0
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq 0x29ee6(%rip), %rdi     # 0x3bff0
callq 0x53a0
movq %rax, %rbx
leaq 0x1f1dd(%rip), %rsi     # 0x312f6
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 0x1253a
leaq 0x38(%rsp), %rax
movq %rax, -0x10(%rax)
xorl %r14d, %r14d
movq %r14, -0x8(%rax)
movb %r14b, (%rax)
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
movq %r14, -0x8(%rax)
movb %r14b, (%rax)
leaq 0x88(%rsp), %rax
movq %rax, -0x10(%rax)
movq %r14, -0x8(%rax)
movb %r14b, (%rax)
movq %rsp, %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
leaq 0xe8(%rbx), %rax
movq %rax, 0x70(%rsp)
leaq 0xf0(%rbx), %rax
movq %rax, 0x68(%rsp)
leaq 0x88(%rbx), %r12
leaq 0x90(%rbx), %rax
movq %rax, 0x60(%rsp)
leaq 0xb8(%rbx), %rax
movq %rax, 0x58(%rsp)
movq %rbx, 0x48(%rsp)
leaq 0x118(%rbx), %rax
movq %rax, 0x50(%rsp)
leaq 0x28(%rsp), %r15
leaq 0x78(%rsp), %rbp
movl $0x0, 0x4(%rsp)
movq 0xd0(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x5310
movsbl %al, %edx
movq %r13, %rdi
movq %r15, %rsi
callq 0x5600
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
cmpl $0x0, 0x20(%rax,%rcx)
jne 0x123ce
cmpq $0x0, 0x30(%rsp)
je 0x1226d
movq 0x28(%rsp), %rax
cmpb $0x3e, (%rax)
je 0x1226d
cmpq $0x0, 0x10(%rsp)
je 0x121ed
movq %r15, %rdi
movl $0x20, %esi
xorl %edx, %edx
callq 0x5400
cmpq $-0x1, %rax
jne 0x123a4
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
movq %rbp, %rdi
callq 0x50f0
jmp 0x121ed
cmpq $0x0, 0x10(%rsp)
je 0x12318
movq 0x70(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x2b6fe
cmpq 0x68(%rsp), %rax
je 0x1255b
movq %r12, %rdi
leaq 0x8(%rsp), %rsi
callq 0x2b6fe
cmpq 0x60(%rsp), %rax
jne 0x122c0
movq %r12, %rdi
leaq 0x8(%rsp), %rsi
callq 0x28812
movl 0x4(%rsp), %ecx
movl %ecx, (%rax)
incl %ecx
movl %ecx, 0x4(%rsp)
movq %r12, %rdi
leaq 0x8(%rsp), %rsi
callq 0x28812
movl (%rax), %eax
movl %eax, (%rsp)
movq 0x58(%rsp), %rdi
movq %rsp, %rsi
callq 0x28988
movq %rax, %rdi
leaq 0x8(%rsp), %rsi
callq 0x51c0
movq 0x50(%rsp), %rdi
movq %rsp, %rsi
callq 0x28988
movq %rax, %rdi
movq %rbp, %rsi
callq 0x51c0
incl %r14d
movq $0x0, 0x10(%rsp)
movq 0x8(%rsp), %rax
movb $0x0, (%rax)
cmpq $0x0, 0x30(%rsp)
je 0x123b5
movq %r12, %rbx
leaq 0x98(%rsp), %rdi
movq %r15, %rsi
movl $0x20, %edx
callq 0x2f46e
movq 0x98(%rsp), %rsi
movl $0x1, %edx
leaq 0xb0(%rsp), %r12
movq %r12, %rdi
movq $-0x1, %rcx
callq 0x5360
leaq 0x8(%rsp), %rdi
movq %r12, %rsi
callq 0x53e0
movq 0xb0(%rsp), %rdi
leaq 0xc0(%rsp), %rax
cmpq %rax, %rdi
je 0x12392
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x5340
leaq 0x98(%rsp), %rdi
callq 0xe7ca
movq %rbx, %r12
jmp 0x123b5
movq $0x0, 0x10(%rsp)
movq 0x8(%rsp), %rax
movb $0x0, (%rax)
movq $0x0, 0x80(%rsp)
movq 0x78(%rsp), %rax
movb $0x0, (%rax)
jmp 0x121ed
cmpq $0x0, 0x10(%rsp)
je 0x12466
leaq 0x8(%rsp), %rsi
movq 0x70(%rsp), %rdi
callq 0x2b6fe
movq 0x48(%rsp), %rbx
cmpq 0x68(%rsp), %rax
je 0x12472
leaq 0x8(%rsp), %rsi
movq %r12, %rdi
callq 0x2b6fe
cmpq 0x60(%rsp), %rax
jne 0x1241c
leaq 0x8(%rsp), %rsi
movq %r12, %rdi
callq 0x28812
movl 0x4(%rsp), %ecx
movl %ecx, (%rax)
leaq 0x8(%rsp), %rsi
movq %r12, %rdi
callq 0x28812
movl (%rax), %eax
movq %rsp, %rsi
movl %eax, (%rsi)
movq 0x58(%rsp), %rdi
callq 0x28988
leaq 0x8(%rsp), %rsi
movq %rax, %rdi
callq 0x51c0
movq %rsp, %rsi
movq 0x50(%rsp), %rdi
callq 0x28988
leaq 0x78(%rsp), %rsi
movq %rax, %rdi
callq 0x51c0
incl %r14d
jmp 0x1246b
movq 0x48(%rsp), %rbx
movl %r14d, (%rbx)
movb $0x1, %bl
jmp 0x124e0
movq 0x29b57(%rip), %rdi     # 0x3bfd0
leaq 0x1ee86(%rip), %rsi     # 0x31306
movl $0x2c, %edx
callq 0x53a0
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq 0x29b35(%rip), %rdi     # 0x3bfd0
callq 0x53a0
movq %rax, %rbx
leaq 0x1ee89(%rip), %rsi     # 0x31333
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 0x12502
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x5340
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x1251e
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x5340
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x1253a
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
movq 0x29a6e(%rip), %rdi     # 0x3bfd0
leaq 0x1ed9d(%rip), %rsi     # 0x31306
movl $0x2c, %edx
callq 0x53a0
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq 0x29a4c(%rip), %rdi     # 0x3bfd0
callq 0x53a0
movq %rax, %rbx
leaq 0x1eda0(%rip), %rsi     # 0x31333
movl $0x20, %edx
movq %rax, %rdi
callq 0x53a0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x5310
jmp 0x124cb
jmp 0x125de
jmp 0x125de
jmp 0x125de
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0xe7ca
jmp 0x125e1
jmp 0x125de
jmp 0x125de
jmp 0x125de
jmp 0x125de
movq %rax, %rbx
jmp 0x1263b
movq %rax, %rbx
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x12603
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x5340
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x1261f
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x5340
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x1263b
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x5340
leaq 0xd0(%rsp), %rdi
callq 0x50c0
movq %rbx, %rdi
callq 0x55c0