// File: /workspace/github_cpp_makefile_star2_O2/millanek[P]evo/process_vcf_fst.cpp
// Function: summariseEigensoft()
void summariseEigensoft() {
    std::ifstream* eigenFile = new std::ifstream(opt::eigensoftFile.c_str());
    string fileRoot = stripExtension(opt::eigensoftFile);
    string FstResultsFileName = fileRoot + "_" + opt::runName + "_fst_matrix.forR";
    std::ofstream* pFst = new std::ofstream(FstResultsFileName.c_str());
    std::vector<std::vector<std::string> > fst_matrix;
    
    string line;
    getline(*eigenFile, line); // Get the first description line
    short type;
    if (line == "##") {
        type = 1;
    } else {
        type = 2;
    }
    std::cerr << "It is type: " << type << std::endl;
    if (type == 1) {
        getline(*eigenFile, line);
        std::vector<std::string> fields = split(line, '\t');
        std::vector<std::string> this_indiv_fst;
        std::vector<std::string> all_indiv;
        string this_indiv = fields[0];
        this_indiv_fst.push_back(fields[2]);
        while (getline(*eigenFile, line)) {
            fields = split(line, '\t');
            std::cerr << "Indiv: " << fields[0] << std::endl;
            if (this_indiv == fields[0]) {
                this_indiv_fst.push_back(fields[2]);
            } else {
                fst_matrix.push_back(this_indiv_fst);
                all_indiv.push_back(this_indiv);
                this_indiv = fields[0];
                this_indiv_fst.clear();
                this_indiv_fst.push_back(fields[2]);
            }
        }
        all_indiv.push_back(this_indiv);
        fst_matrix.push_back(this_indiv_fst);
        this_indiv_fst.clear(); this_indiv_fst.push_back("0"); all_indiv.push_back(fields[1]);
        fst_matrix.push_back(this_indiv_fst);
        
        for (std::vector<std::vector<std::string> >::size_type i = 0; i != fst_matrix.size(); i++) {
            std::reverse(fst_matrix[i].begin(), fst_matrix[i].end());
            fst_matrix[i].insert(fst_matrix[i].end(), "0");
            while (fst_matrix[i].size() != fst_matrix[0].size()) {
                fst_matrix[i].insert(fst_matrix[i].end(), "0");
            }
        }
        std::reverse(fst_matrix.begin(), fst_matrix.end());
        std::reverse(all_indiv.begin(), all_indiv.end());
        
        print_vector(all_indiv, *pFst);
        print_matrix(fst_matrix, *pFst);
    } else if (type == 2) {
        std::cerr << "type2" << std::endl;
        std::vector<std::string> fields = split(line, '\t');
        std::vector<std::string> all_indiv(fields.begin()+1,fields.end());
        getline(*eigenFile, line); getline(*eigenFile, line);
        std::vector<std::string> this_indiv_fst;
        while (getline(*eigenFile, line)) {
            fields = split(line, '\t');
            std::copy(fields.begin()+1,fields.end(),std::back_inserter(this_indiv_fst));
            for (std::vector<std::string>::size_type i = 0; i != this_indiv_fst.size(); i++) {
                double fst = convertToDouble(this_indiv_fst[i]) / 1000;
                this_indiv_fst[i] = numToString(fst);
            }
            fst_matrix.push_back(this_indiv_fst);
            this_indiv_fst.clear();
        }
        print_vector(all_indiv, *pFst);
        print_matrix(fst_matrix, *pFst);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x188, %rsp            # imm = 0x188
movl $0x208, %edi            # imm = 0x208
callq 0x8490
movq %rax, %r14
movq 0x6e9a5(%rip), %rsi     # 0xdea88
pushq $0x8
popq %rdx
movq %rax, %rdi
callq 0x8890
leaq 0x6e993(%rip), %rsi     # 0xdea88
leaq 0x168(%rsp), %rbx
movq %rbx, %rdi
callq 0x404d7
leaq 0x336b0(%rip), %rdx     # 0xa37bc
leaq 0xa0(%rsp), %rdi
movq %rbx, %rsi
callq 0x28806
leaq 0x6e9a5(%rip), %rdx     # 0xdeac8
leaq 0x80(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x287e7
leaq 0x3b685(%rip), %rdx     # 0xab7c4
leaq 0x148(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x28a29
leaq 0x80(%rsp), %rdi
callq 0x8978
leaq 0xa0(%rsp), %rdi
callq 0x8978
movl $0x200, %edi            # imm = 0x200
callq 0x8490
movq 0x148(%rsp), %rsi
pushq $0x10
popq %rdx
movq %rax, 0x8(%rsp)
movq %rax, %rdi
callq 0x84e0
andq $0x0, 0x50(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x40(%rsp)
leaq 0x90(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x80(%rsp), %rsi
movq %r14, %rdi
callq 0x80a0
leaq 0x3b60a(%rip), %rsi     # 0xab7d5
leaq 0x80(%rsp), %rdi
callq 0x2193f
movl %eax, %ebx
movq 0x6ce07(%rip), %rdi     # 0xdcfe8
leaq 0x3b5f0(%rip), %rsi     # 0xab7d8
callq 0x8480
movzbl %bl, %ecx
pushq $0x2
popq %rsi
subl %ecx, %esi
movq %rax, %rdi
callq 0x8440
movq %rax, %rdi
callq 0x8230
testb %bl, %bl
je 0x70357
leaq 0x80(%rsp), %rsi
movq %r14, %rdi
callq 0x80a0
leaq 0x28(%rsp), %rdi
leaq 0x80(%rsp), %rsi
pushq $0x9
popq %rdx
callq 0x40349
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
andq $0x0, 0x20(%rsp)
movapd %xmm0, 0xc0(%rsp)
andq $0x0, 0xd0(%rsp)
movq 0x28(%rsp), %rsi
leaq 0xa0(%rsp), %rdi
callq 0x8600
movq 0x28(%rsp), %rsi
addq $0x40, %rsi
leaq 0x10(%rsp), %rdi
callq 0x2b0a4
leaq 0x80(%rsp), %r15
leaq 0x60(%rsp), %r12
leaq 0x3b558(%rip), %rbp     # 0xab7e5
leaq 0xa0(%rsp), %r13
leaq 0x10(%rsp), %rbx
movq %r14, %rdi
movq %r15, %rsi
callq 0x80a0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x704ad
movq %r12, %rdi
movq %r15, %rsi
pushq $0x9
popq %rdx
callq 0x40349
leaq 0x28(%rsp), %rdi
movq %r12, %rsi
callq 0x2f6c0
movq %r12, %rdi
callq 0x28a08
movq 0x6cd07(%rip), %rdi     # 0xdcfe8
movq %rbp, %rsi
callq 0x8480
movq 0x28(%rsp), %rsi
movq %rax, %rdi
callq 0x8430
movq %rax, %rdi
callq 0x8230
movq 0x28(%rsp), %rsi
movq %r13, %rdi
callq 0x26b06
testb %al, %al
jne 0x70341
leaq 0x40(%rsp), %rdi
movq %rbx, %rsi
callq 0x29502
leaq 0xc0(%rsp), %rdi
movq %r13, %rsi
callq 0x2b0a4
movq 0x28(%rsp), %rsi
movq %r13, %rdi
callq 0x82a0
movq %rbx, %rdi
callq 0x32680
movq 0x28(%rsp), %rsi
addq $0x40, %rsi
movq %rbx, %rdi
callq 0x2b0a4
jmp 0x7029a
movq 0x6cc8a(%rip), %rdi     # 0xdcfe8
leaq 0x3b488(%rip), %rsi     # 0xab7ed
callq 0x8480
movq %rax, %rdi
callq 0x8230
leaq 0x60(%rsp), %rdi
leaq 0x80(%rsp), %rsi
pushq $0x9
popq %rdx
callq 0x40349
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rdx
addq $0x20, %rsi
leaq 0x28(%rsp), %rdi
leaq 0xa0(%rsp), %rcx
callq 0x613fe
leaq 0x80(%rsp), %rsi
movq %r14, %rdi
callq 0x80a0
leaq 0x80(%rsp), %rsi
movq %r14, %rdi
callq 0x80a0
leaq 0x10(%rsp), %r15
andq $0x0, 0x10(%r15)
xorpd %xmm0, %xmm0
movapd %xmm0, (%r15)
leaq 0x80(%rsp), %r12
leaq 0xa0(%rsp), %r13
movq %r14, %rdi
movq %r12, %rsi
callq 0x80a0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x705fe
movq %r13, %rdi
movq %r12, %rsi
pushq $0x9
popq %rdx
callq 0x40349
leaq 0x60(%rsp), %rdi
movq %r13, %rsi
callq 0x2f6c0
movq %r13, %rdi
callq 0x28a08
movq 0x60(%rsp), %rdi
movq 0x68(%rsp), %rsi
addq $0x20, %rdi
movq %r15, %rdx
callq 0x725f0
xorl %ebp, %ebp
xorl %ebx, %ebx
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rax
subq %rdi, %rax
sarq $0x5, %rax
cmpq %rax, %rbx
je 0x70493
addq %rbp, %rdi
callq 0x5a2ff
divsd 0x3a376(%rip), %xmm0    # 0xaa7e0
movq %r13, %rdi
callq 0x37bd4
movq 0x10(%rsp), %rdi
addq %rbp, %rdi
movq %r13, %rsi
callq 0x8550
movq %r13, %rdi
callq 0x8978
incq %rbx
addq $0x20, %rbp
jmp 0x70444
leaq 0x40(%rsp), %rdi
movq %r15, %rsi
callq 0x29502
movq %r15, %rdi
callq 0x32680
jmp 0x703ea
leaq 0xc0(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x2b0a4
leaq 0x40(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x29502
leaq 0x10(%rsp), %rdi
callq 0x32680
leaq 0x27143(%rip), %rsi     # 0x97625
leaq 0x60(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x21904
leaq 0x10(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x3490e
leaq 0x60(%rsp), %rdi
callq 0x8978
movq 0x28(%rsp), %rsi
addq $0x20, %rsi
leaq 0xc0(%rsp), %rdi
callq 0x2b0a4
leaq 0x40(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x29502
movq 0x40(%rsp), %r12
xorl %ecx, %ecx
leaq 0x270e8(%rip), %rbx     # 0x97625
leaq 0x60(%rsp), %r14
leaq 0x7(%rsp), %r15
movq 0x48(%rsp), %rsi
movq %rsi, %rax
subq %r12, %rax
cqto
pushq $0x18
popq %rdi
idivq %rdi
cmpq %rax, %rcx
je 0x70684
movq %rcx, 0xe0(%rsp)
imulq $0x18, %rcx, %rbp
movq (%r12,%rbp), %rdi
movq 0x8(%r12,%rbp), %rsi
callq 0x724f2
movq 0x40(%rsp), %r12
movq 0x8(%r12,%rbp), %r13
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x21904
addq %rbp, %r12
movq %r12, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x72524
movq %r14, %rdi
callq 0x8978
movq 0x40(%rsp), %r12
movq 0x8(%r12,%rbp), %r13
movq %r13, %rax
subq (%r12,%rbp), %rax
movq 0x8(%r12), %rcx
subq (%r12), %rcx
cmpq %rcx, %rax
je 0x705ee
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x21904
addq %rbp, %r12
movq %r12, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x72524
jmp 0x705a6
movq 0xe0(%rsp), %rcx
incq %rcx
jmp 0x70547
leaq 0x100(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x297dc
leaq 0x100(%rsp), %rdi
pushq $0x9
popq %rdx
pushq $0x1
popq %rcx
movq 0x8(%rsp), %rsi
callq 0x2ea24
leaq 0x100(%rsp), %rdi
callq 0x28a08
leaq 0xe8(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x2a906
leaq 0xe8(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x3afbc
leaq 0xe8(%rsp), %rdi
callq 0x29054
leaq 0x10(%rsp), %rdi
callq 0x28a08
leaq 0x28(%rsp), %rdi
callq 0x28a08
leaq 0x60(%rsp), %rdi
jmp 0x7072f
movq %r12, %rdi
callq 0x725bf
leaq 0xc0(%rsp), %rbx
movq (%rbx), %rdi
movq 0x8(%rbx), %rsi
callq 0x724f2
leaq 0x130(%rsp), %rdi
movq %rbx, %rsi
callq 0x297dc
leaq 0x130(%rsp), %rdi
pushq $0x9
popq %rdx
pushq $0x1
popq %rcx
movq 0x8(%rsp), %rsi
callq 0x2ea24
leaq 0x130(%rsp), %rdi
callq 0x28a08
leaq 0x118(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x2a906
leaq 0x118(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x3afbc
leaq 0x118(%rsp), %rdi
callq 0x29054
leaq 0xa0(%rsp), %rdi
callq 0x8978
leaq 0xc0(%rsp), %rdi
callq 0x28a08
leaq 0x10(%rsp), %rdi
callq 0x28a08
leaq 0x28(%rsp), %rdi
callq 0x28a08
leaq 0x80(%rsp), %rdi
callq 0x8978
leaq 0x40(%rsp), %rdi
callq 0x29054
leaq 0x148(%rsp), %rdi
callq 0x8978
leaq 0x168(%rsp), %rdi
callq 0x8978
addq $0x188, %rsp            # imm = 0x188
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r15
leaq 0x118(%rsp), %rdi
callq 0x29054
jmp 0x7087d
movq %rax, %r15
leaq 0x130(%rsp), %rdi
callq 0x28a08
jmp 0x7087d
movq %rax, %r15
leaq 0xe8(%rsp), %rdi
callq 0x29054
jmp 0x708ad
movq %rax, %r15
leaq 0x100(%rsp), %rdi
callq 0x28a08
jmp 0x708ad
jmp 0x70870
jmp 0x7086b
movq %rax, %r15
jmp 0x708c1
jmp 0x70858
movq %rax, %r15
jmp 0x7088a
jmp 0x70858
jmp 0x708aa
movq %rax, %r15
jmp 0x708b7
jmp 0x70858
movq %rax, %r15
movl $0x200, %esi            # imm = 0x200
movq 0x8(%rsp), %rdi
callq 0x84a0
jmp 0x708e2
movq %rax, %r15
jmp 0x708e2
movq %rax, %r15
leaq 0x80(%rsp), %rdi
callq 0x8978
jmp 0x7082c
movq %rax, %r15
leaq 0xa0(%rsp), %rdi
jmp 0x708ea
movq %rax, %r15
jmp 0x708ef
movq %rax, %r15
movl $0x208, %esi            # imm = 0x208
movq %r14, %rdi
callq 0x84a0
jmp 0x708fc
jmp 0x7086b
movq %rax, %r15
jmp 0x708cb
jmp 0x7086b
jmp 0x70870
jmp 0x708aa
jmp 0x708aa
jmp 0x7086b
jmp 0x708aa
jmp 0x7086b
movq %rax, %r15
jmp 0x7087d
movq %rax, %r15
leaq 0x60(%rsp), %rdi
callq 0x8978
leaq 0xa0(%rsp), %rdi
callq 0x8978
leaq 0xc0(%rsp), %rdi
callq 0x28a08
leaq 0x10(%rsp), %rdi
callq 0x28a08
leaq 0x28(%rsp), %rdi
jmp 0x708c6
jmp 0x708aa
movq %rax, %r15
leaq 0x10(%rsp), %rdi
callq 0x28a08
leaq 0x28(%rsp), %rdi
callq 0x28a08
leaq 0x60(%rsp), %rdi
callq 0x28a08
leaq 0x80(%rsp), %rdi
callq 0x8978
leaq 0x40(%rsp), %rdi
callq 0x29054
leaq 0x148(%rsp), %rdi
callq 0x8978
leaq 0x168(%rsp), %rdi
callq 0x8978
movq %r15, %rdi
callq 0x8870