// File: 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
movq %rsp, %rbp
subq $0x400, %rsp            # imm = 0x400
movq %rsi, -0x330(%rbp)
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x328(%rbp)
leaq -0x220(%rbp), %rdi
movl $0x8, %edx
callq 0x66a0
movq -0x220(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x220(%rbp,%rax), %rdi
callq 0x6700
movb %al, -0x319(%rbp)
jmp 0x1b7b6
movb -0x319(%rbp), %al
testb $0x1, %al
jne 0x1b859
jmp 0x1b7c6
movq 0x58823(%rip), %rdi     # 0x73ff0
leaq 0x39aee(%rip), %rsi     # 0x552c2
callq 0x6420
movq %rax, -0x338(%rbp)
jmp 0x1b7e2
movq -0x330(%rbp), %rsi
movq -0x338(%rbp), %rdi
callq 0x63e0
movq %rax, -0x340(%rbp)
jmp 0x1b7fe
movq -0x340(%rbp), %rdi
leaq 0x39ac6(%rip), %rsi     # 0x552d2
callq 0x6420
movq %rax, -0x348(%rbp)
jmp 0x1b81a
movq -0x348(%rbp), %rdi
movq 0x58758(%rip), %rsi     # 0x73f80
callq 0x6480
jmp 0x1b82f
movb $0x0, -0x1(%rbp)
movl $0x1, -0x230(%rbp)
jmp 0x1bf79
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x228(%rbp)
movl %eax, -0x22c(%rbp)
jmp 0x1bf93
leaq -0x250(%rbp), %rdi
callq 0x65e0
leaq -0x270(%rbp), %rdi
callq 0x65e0
leaq -0x290(%rbp), %rdi
callq 0x65e0
movl $0x0, -0x294(%rbp)
movl $0x0, -0x298(%rbp)
movl $0xffffffff, -0x29c(%rbp) # imm = 0xFFFFFFFF
leaq -0x220(%rbp), %rdi
leaq -0x250(%rbp), %rsi
callq 0x60d0
movq %rax, -0x350(%rbp)
jmp 0x1b8b7
movq -0x350(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x6700
movb %al, -0x351(%rbp)
jmp 0x1b8d5
movb -0x351(%rbp), %al
testb $0x1, %al
jne 0x1b8e4
jmp 0x1bcba
leaq -0x250(%rbp), %rdi
callq 0x66e0
testb $0x1, %al
jne 0x1b920
xorl %eax, %eax
movl %eax, %esi
leaq -0x250(%rbp), %rdi
callq 0x6810
movq %rax, -0x360(%rbp)
jmp 0x1b90d
movq -0x360(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x3e, %eax
jne 0x1bc55
leaq -0x270(%rbp), %rdi
callq 0x66e0
testb $0x1, %al
jne 0x1bb9c
movq -0x328(%rbp), %rdi
addq $0xe8, %rdi
leaq -0x270(%rbp), %rsi
callq 0x32710
movq %rax, -0x368(%rbp)
jmp 0x1b957
movq -0x328(%rbp), %rdi
movq -0x368(%rbp), %rax
movq %rax, -0x2a8(%rbp)
addq $0xe8, %rdi
callq 0x32740
movq %rax, -0x2b0(%rbp)
leaq -0x2a8(%rbp), %rdi
leaq -0x2b0(%rbp), %rsi
callq 0x326e0
testb $0x1, %al
jne 0x1b99b
jmp 0x1ba2e
movq 0x58616(%rip), %rdi     # 0x73fb8
leaq 0x39939(%rip), %rsi     # 0x552e2
callq 0x6420
movq %rax, -0x370(%rbp)
jmp 0x1b9b7
movq -0x370(%rbp), %rdi
leaq -0x270(%rbp), %rsi
callq 0x63e0
movq %rax, -0x378(%rbp)
jmp 0x1b9d3
movq -0x378(%rbp), %rdi
leaq 0x3992e(%rip), %rsi     # 0x5530f
callq 0x6420
movq %rax, -0x380(%rbp)
jmp 0x1b9ef
movq -0x380(%rbp), %rdi
movq 0x58583(%rip), %rsi     # 0x73f80
callq 0x6480
jmp 0x1ba04
movb $0x0, -0x1(%rbp)
movl $0x1, -0x230(%rbp)
jmp 0x1bf2d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x228(%rbp)
movl %eax, -0x22c(%rbp)
jmp 0x1bf53
movq -0x328(%rbp), %rdi
addq $0x88, %rdi
leaq -0x270(%rbp), %rsi
callq 0x32710
movq %rax, -0x388(%rbp)
jmp 0x1ba51
movq -0x328(%rbp), %rdi
movq -0x388(%rbp), %rax
movq %rax, -0x2b8(%rbp)
addq $0x88, %rdi
callq 0x32740
movq %rax, -0x2c0(%rbp)
leaq -0x2b8(%rbp), %rdi
leaq -0x2c0(%rbp), %rsi
callq 0x326e0
testb $0x1, %al
jne 0x1ba92
jmp 0x1badf
movq -0x328(%rbp), %rdi
movl -0x298(%rbp), %eax
movl %eax, -0x394(%rbp)
addq $0x88, %rdi
leaq -0x270(%rbp), %rsi
callq 0x322f0
movq %rax, -0x390(%rbp)
jmp 0x1bac1
movq -0x390(%rbp), %rax
movl -0x394(%rbp), %ecx
movl %ecx, (%rax)
movl -0x298(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x298(%rbp)
movq -0x328(%rbp), %rdi
addq $0x88, %rdi
leaq -0x270(%rbp), %rsi
callq 0x322f0
movq %rax, -0x3a0(%rbp)
jmp 0x1bb02
movq -0x328(%rbp), %rdi
movq -0x3a0(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x29c(%rbp)
addq $0xb8, %rdi
leaq -0x29c(%rbp), %rsi
callq 0x32770
movq %rax, -0x3a8(%rbp)
jmp 0x1bb34
movq -0x3a8(%rbp), %rdi
leaq -0x270(%rbp), %rsi
callq 0x6070
jmp 0x1bb49
movq -0x328(%rbp), %rdi
addq $0x118, %rdi            # imm = 0x118
leaq -0x29c(%rbp), %rsi
callq 0x32770
movq %rax, -0x3b0(%rbp)
jmp 0x1bb6c
movq -0x3b0(%rbp), %rdi
leaq -0x290(%rbp), %rsi
callq 0x6070
jmp 0x1bb81
movl -0x294(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x294(%rbp)
leaq -0x270(%rbp), %rdi
callq 0x65a0
leaq -0x250(%rbp), %rdi
callq 0x66e0
testb $0x1, %al
jne 0x1bc47
leaq -0x2f8(%rbp), %rdi
leaq -0x250(%rbp), %rsi
movl $0x20, %edx
callq 0x53e70
jmp 0x1bbca
xorl %eax, %eax
movl %eax, %esi
leaq -0x2f8(%rbp), %rdi
callq 0x9080
movq %rax, %rsi
leaq -0x2e0(%rbp), %rdi
movl $0x1, %edx
movq $-0x1, %rcx
callq 0x6460
jmp 0x1bbf7
leaq -0x270(%rbp), %rdi
leaq -0x2e0(%rbp), %rsi
callq 0x6530
leaq -0x2e0(%rbp), %rdi
callq 0x6828
leaq -0x2f8(%rbp), %rdi
callq 0x13370
jmp 0x1bc47
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x228(%rbp)
movl %eax, -0x22c(%rbp)
leaq -0x2f8(%rbp), %rdi
callq 0x13370
jmp 0x1bf53
leaq -0x290(%rbp), %rdi
callq 0x65a0
jmp 0x1bcb5
leaq -0x270(%rbp), %rdi
callq 0x66e0
testb $0x1, %al
jne 0x1bcb3
leaq -0x250(%rbp), %rdi
movl $0x20, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x6590
cmpq $-0x1, %rax
je 0x1bc9a
leaq -0x270(%rbp), %rdi
callq 0x65a0
leaq -0x290(%rbp), %rdi
callq 0x65a0
jmp 0x1bcb1
leaq -0x290(%rbp), %rdi
leaq -0x250(%rbp), %rsi
callq 0x6560
jmp 0x1bcaf
jmp 0x1bcb1
jmp 0x1bcb3
jmp 0x1bcb5
jmp 0x1b89b
leaq -0x270(%rbp), %rdi
callq 0x66e0
testb $0x1, %al
jne 0x1bf10
movq -0x328(%rbp), %rdi
addq $0xe8, %rdi
leaq -0x270(%rbp), %rsi
callq 0x32710
movq %rax, -0x3b8(%rbp)
jmp 0x1bcf1
movq -0x328(%rbp), %rdi
movq -0x3b8(%rbp), %rax
movq %rax, -0x300(%rbp)
addq $0xe8, %rdi
callq 0x32740
movq %rax, -0x308(%rbp)
leaq -0x300(%rbp), %rdi
leaq -0x308(%rbp), %rsi
callq 0x326e0
testb $0x1, %al
jne 0x1bd32
jmp 0x1bdae
movq 0x5827f(%rip), %rdi     # 0x73fb8
leaq 0x395a2(%rip), %rsi     # 0x552e2
callq 0x6420
movq %rax, -0x3c0(%rbp)
jmp 0x1bd4e
movq -0x3c0(%rbp), %rdi
leaq -0x270(%rbp), %rsi
callq 0x63e0
movq %rax, -0x3c8(%rbp)
jmp 0x1bd6a
movq -0x3c8(%rbp), %rdi
leaq 0x39597(%rip), %rsi     # 0x5530f
callq 0x6420
movq %rax, -0x3d0(%rbp)
jmp 0x1bd86
movq -0x3d0(%rbp), %rdi
movq 0x581ec(%rip), %rsi     # 0x73f80
callq 0x6480
jmp 0x1bd9b
movb $0x0, -0x1(%rbp)
movl $0x1, -0x230(%rbp)
jmp 0x1bf2d
movq -0x328(%rbp), %rdi
addq $0x88, %rdi
leaq -0x270(%rbp), %rsi
callq 0x32710
movq %rax, -0x3d8(%rbp)
jmp 0x1bdd1
movq -0x328(%rbp), %rdi
movq -0x3d8(%rbp), %rax
movq %rax, -0x310(%rbp)
addq $0x88, %rdi
callq 0x32740
movq %rax, -0x318(%rbp)
leaq -0x310(%rbp), %rdi
leaq -0x318(%rbp), %rsi
callq 0x326e0
testb $0x1, %al
jne 0x1be12
jmp 0x1be5f
movq -0x328(%rbp), %rdi
movl -0x298(%rbp), %eax
movl %eax, -0x3e4(%rbp)
addq $0x88, %rdi
leaq -0x270(%rbp), %rsi
callq 0x322f0
movq %rax, -0x3e0(%rbp)
jmp 0x1be41
movq -0x3e0(%rbp), %rax
movl -0x3e4(%rbp), %ecx
movl %ecx, (%rax)
movl -0x298(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x298(%rbp)
movq -0x328(%rbp), %rdi
addq $0x88, %rdi
leaq -0x270(%rbp), %rsi
callq 0x322f0
movq %rax, -0x3f0(%rbp)
jmp 0x1be82
movq -0x328(%rbp), %rdi
movq -0x3f0(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x29c(%rbp)
addq $0xb8, %rdi
leaq -0x29c(%rbp), %rsi
callq 0x32770
movq %rax, -0x3f8(%rbp)
jmp 0x1beb4
movq -0x3f8(%rbp), %rdi
leaq -0x270(%rbp), %rsi
callq 0x6070
jmp 0x1bec9
movq -0x328(%rbp), %rdi
addq $0x118, %rdi            # imm = 0x118
leaq -0x29c(%rbp), %rsi
callq 0x32770
movq %rax, -0x400(%rbp)
jmp 0x1beec
movq -0x400(%rbp), %rdi
leaq -0x290(%rbp), %rsi
callq 0x6070
jmp 0x1bf01
movl -0x294(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x294(%rbp)
movq -0x328(%rbp), %rax
movl -0x294(%rbp), %ecx
movl %ecx, (%rax)
movb $0x1, -0x1(%rbp)
movl $0x1, -0x230(%rbp)
leaq -0x290(%rbp), %rdi
callq 0x6828
leaq -0x270(%rbp), %rdi
callq 0x6828
leaq -0x250(%rbp), %rdi
callq 0x6828
jmp 0x1bf79
leaq -0x290(%rbp), %rdi
callq 0x6828
leaq -0x270(%rbp), %rdi
callq 0x6828
leaq -0x250(%rbp), %rdi
callq 0x6828
jmp 0x1bf93
leaq -0x220(%rbp), %rdi
callq 0x6120
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x400, %rsp            # imm = 0x400
popq %rbp
retq
leaq -0x220(%rbp), %rdi
callq 0x6120
movq -0x228(%rbp), %rdi
callq 0x6750
nopl (%rax,%rax)