// File: /workspace/github_cpp_makefile_star2_O2/millanek[P]evo/evo_getInformativePairs.cpp
// Function: InfoPairsMain(int, char**)
int InfoPairsMain(int argc, char** argv) {
    parseInfoPairsOptions(argc, argv);
    string line; // for reading the input files
    
    std::istream* hetFile = createReader(opt::hetFile.c_str());
    std::ifstream* pairtoolsFile = new std::ifstream(opt::pairtoolsFile.c_str());
    
    std::unordered_set<int> phasedHetsPos;
    
    
    if (opt::hapcutFormat) {
        // Parse the Hapcut blocks file
        while (getline(*hetFile, line)) {
            if (line == "********") continue;
            if (line[0] == 'B' && line[1] == 'L') { // New block - should in the future separate the hets by blocks
                
            } else {
                std::vector<string> phasedSNPdetails = split(line, '\t');
                int snpPos = atoi(phasedSNPdetails[4].c_str());
                phasedHetsPos.insert(snpPos);
            }
        }
    } else {
        while (getline(*hetFile, line)) {
            std::vector<string> phasedSNPdetails = split(line, '\t');
            int snpPos = atoi(phasedSNPdetails[1].c_str());
            phasedHetsPos.insert(snpPos);
        }
    }
    
    // Now parse the pairtools file to find read pairs that can be informative about the phasing and recombination
    while (getline(*pairtoolsFile,line)) {
        // std::cerr << line << std::endl;
        std::vector<string> pairVec = split(line, '\t'); assert(pairVec.size() == 8);
        
        int pair1pos = atoi(pairVec[2].c_str());
        int pair2pos = atoi(pairVec[4].c_str());
        string pair1strand = pairVec[5];
        string pair2strand = pairVec[6];
        
        std::vector<int> posCovered1; posCovered1.resize(150);
        if (pair1strand == "+") std::iota(posCovered1.begin(), posCovered1.end(), pair1pos);
        else std::iota(posCovered1.begin(), posCovered1.end(), pair1pos-150);
        
        std::vector<int> posCovered2; posCovered2.resize(150);
        if (pair2strand == "+") std::iota(posCovered2.begin(), posCovered2.end(), pair2pos);
        else std::iota(posCovered2.begin(), posCovered2.end(), pair2pos-150);
        
        int phasedHetsOnPair = 0;
        
        std::vector<int> hetPosVec;
        
        for (int i = 0; i < posCovered1.size(); i++) {
            if (phasedHetsPos.count(posCovered1[i]) == 1) {
                phasedHetsOnPair++;
                hetPosVec.push_back(posCovered1[i]);
            }
        }
        
        for (int i = 0; i < posCovered2.size(); i++) {
            if (phasedHetsPos.count(posCovered2[i]) == 1) {
                phasedHetsOnPair++;
                hetPosVec.push_back(posCovered2[i]);
            }
        }
        
        if (phasedHetsOnPair > 1) {
            std::cout << line << std::endl;
            //std::cerr << "pair1pos: " << pair1pos << " ; pair2pos: " << pair2pos << std::endl;
            //std::cerr << "pair1strand: " << pair1strand << " ; pair2strand: " << pair2strand << std::endl;
            //print_vector(hetPosVec, std::cerr);
        }
        
    }
    
    return 0;
    
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
callq 0x8add3
leaq 0xa8(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0x549fb(%rip), %rsi     # 0xdf2a8
leaq 0xb8(%rsp), %rdi
leaq 0x38(%rsp), %rdx
callq 0x21904
leaq 0xb8(%rsp), %rdi
pushq $0x8
popq %rsi
callq 0x42587
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
callq 0x8978
movl $0x208, %edi            # imm = 0x208
callq 0x8490
movq %rax, %r14
movq 0x549d5(%rip), %rsi     # 0xdf2c8
pushq $0x8
popq %rdx
movq %rax, %rdi
callq 0x8890
movq %r14, 0x58(%rsp)
leaq 0xe8(%rsp), %rax
movq %rax, -0x30(%rax)
movq $0x1, -0x28(%rax)
xorps %xmm0, %xmm0
movups %xmm0, -0x20(%rax)
movl $0x3f800000, -0x10(%rax) # imm = 0x3F800000
movups %xmm0, -0x8(%rax)
cmpb $0x0, 0x549d8(%rip)     # 0xdf308
je 0x8a9ce
leaq 0x98(%rsp), %r14
leaq 0x2705a(%rip), %r15     # 0xb199f
leaq 0x38(%rsp), %r12
leaq 0xb8(%rsp), %r13
leaq 0x60(%rsp), %rbp
movq %rbx, %rdi
movq %r14, %rsi
callq 0x80a0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x8aa38
movq %r14, %rdi
movq %r15, %rsi
callq 0x2193f
testb %al, %al
jne 0x8a957
movq 0x98(%rsp), %rax
cmpb $0x42, (%rax)
jne 0x8a996
cmpb $0x4c, 0x1(%rax)
je 0x8a957
movq %r12, %rdi
movq %r14, %rsi
pushq $0x9
popq %rdx
callq 0x40349
movq 0x38(%rsp), %rax
movq 0x80(%rax), %rdi
callq 0x86f0
movl %eax, 0x60(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
callq 0x8b044
movq %r12, %rdi
callq 0x28a08
jmp 0x8a957
leaq 0x98(%rsp), %r14
leaq 0x38(%rsp), %r15
pushq $0x9
popq %rbp
leaq 0xb8(%rsp), %r12
leaq 0x60(%rsp), %r13
movq %rbx, %rdi
movq %r14, %rsi
callq 0x80a0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x8aa38
movq %r15, %rdi
movq %r14, %rsi
movl %ebp, %edx
callq 0x40349
movq 0x38(%rsp), %rax
movq 0x20(%rax), %rdi
callq 0x86f0
movl %eax, 0x60(%rsp)
movq %r12, %rdi
movq %r13, %rsi
callq 0x8b044
movq %r15, %rdi
callq 0x28a08
jmp 0x8a9eb
leaq 0x98(%rsp), %r13
leaq 0x80(%rsp), %r15
leaq 0xb8(%rsp), %rbp
leaq 0xf0(%rsp), %rbx
movq 0x58(%rsp), %rdi
movq %r13, %rsi
callq 0x80a0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x8acbc
movq %r15, %rdi
movq %r13, %rsi
pushq $0x9
popq %rdx
callq 0x40349
movq 0x80(%rsp), %r12
movq 0x88(%rsp), %rax
subq %r12, %rax
cmpq $0x100, %rax            # imm = 0x100
jne 0x8acea
movq 0x40(%r12), %rdi
callq 0x86f0
movl %eax, %r14d
movq 0x80(%r12), %rdi
callq 0x86f0
movl %eax, %r15d
addq $0xa0, %r12
leaq 0x38(%rsp), %rdi
movq %r12, %rsi
callq 0x8600
movq 0x80(%rsp), %rsi
movl $0xc0, %eax
addq %rax, %rsi
leaq 0x60(%rsp), %rdi
callq 0x8600
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
andq $0x0, 0x30(%rsp)
movl $0x96, %esi
leaq 0x20(%rsp), %rdi
callq 0x43aec
leaq 0x38(%rsp), %rdi
leaq 0xdf2b(%rip), %rsi      # 0x98a43
callq 0x2193f
movq 0x20(%rsp), %rcx
movq 0x28(%rsp), %rdx
testb %al, %al
je 0x8ab3c
cmpq %rdx, %rcx
je 0x8ab54
movl %r14d, (%rcx)
incl %r14d
addq $0x4, %rcx
jmp 0x8ab2b
addl $0xffffff6a, %r14d      # imm = 0xFFFFFF6A
cmpq %rdx, %rcx
je 0x8ab54
movl %r14d, (%rcx)
incl %r14d
addq $0x4, %rcx
jmp 0x8ab43
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
andq $0x0, 0x10(%rsp)
movl $0x96, %esi
movq %rsp, %rdi
callq 0x43aec
leaq 0x60(%rsp), %rdi
leaq 0xdec9(%rip), %rsi      # 0x98a43
callq 0x2193f
movq (%rsp), %rcx
movq 0x8(%rsp), %rdx
testb %al, %al
je 0x8ab9d
cmpq %rdx, %rcx
je 0x8abb5
movl %r15d, (%rcx)
incl %r15d
addq $0x4, %rcx
jmp 0x8ab8c
addl $0xffffff6a, %r15d      # imm = 0xFFFFFF6A
cmpq %rdx, %rcx
je 0x8abb5
movl %r15d, (%rcx)
incl %r15d
addq $0x4, %rcx
jmp 0x8aba4
andq $0x0, 0x100(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0xf0(%rsp)
xorl %r15d, %r15d
xorl %r12d, %r12d
xorl %r14d, %r14d
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rax
subq %rsi, %rax
sarq $0x2, %rax
cmpq %r12, %rax
jbe 0x8ac15
addq %r15, %rsi
movq %rbp, %rdi
callq 0x8b388
cmpq $0x1, %rax
jne 0x8ac0c
movq 0x20(%rsp), %rsi
addq %r15, %rsi
movq %rbx, %rdi
callq 0x3aca4
incl %r14d
incq %r12
addq $0x4, %r15
jmp 0x8abd2
xorl %r15d, %r15d
xorl %r12d, %r12d
movq (%rsp), %rsi
movq 0x8(%rsp), %rax
subq %rsi, %rax
sarq $0x2, %rax
cmpq %r12, %rax
jbe 0x8ac5c
addq %r15, %rsi
movq %rbp, %rdi
callq 0x8b388
cmpq $0x1, %rax
jne 0x8ac53
movq (%rsp), %rsi
addq %r15, %rsi
movq %rbx, %rdi
callq 0x3aca4
incl %r14d
incq %r12
addq $0x4, %r15
jmp 0x8ac1b
cmpl $0x1, %r14d
jle 0x8ac79
movq 0x5234f(%rip), %rdi     # 0xdcfb8
movq %r13, %rsi
callq 0x8430
movq %rax, %rdi
callq 0x8230
movq %rbx, %rdi
callq 0x2aef2
movq %rsp, %rdi
callq 0x2aef2
leaq 0x20(%rsp), %rdi
callq 0x2aef2
leaq 0x60(%rsp), %rdi
callq 0x8978
leaq 0x38(%rsp), %rdi
callq 0x8978
leaq 0x80(%rsp), %r15
movq %r15, %rdi
callq 0x28a08
jmp 0x8aa58
leaq 0xb8(%rsp), %rdi
callq 0x8af9c
leaq 0x98(%rsp), %rdi
callq 0x8978
xorl %eax, %eax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x26cb7(%rip), %rdi     # 0xb19a8
leaq 0x26cc4(%rip), %rsi     # 0xb19bc
leaq 0x26cd9(%rip), %rcx     # 0xb19d8
pushq $0x51
popq %rdx
callq 0x82f0
movq %rax, %rbx
movl $0x208, %esi            # imm = 0x208
movq %r14, %rdi
callq 0x84a0
jmp 0x8adbe
jmp 0x8ad33
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
callq 0x8978
jmp 0x8adbe
movq %rax, %rbx
jmp 0x8adbe
jmp 0x8ad41
jmp 0x8ad67
jmp 0x8ad67
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
jmp 0x8adac
jmp 0x8ad67
jmp 0x8ad67
jmp 0x8ad6e
movq %rax, %rbx
jmp 0x8ad7e
movq %rax, %rbx
jmp 0x8ad9a
movq %rax, %rbx
jmp 0x8ada4
jmp 0x8ad67
movq %rax, %rbx
jmp 0x8ad86
movq %rax, %rbx
jmp 0x8adb1
jmp 0x8ad6e
movq %rax, %rbx
leaq 0xf0(%rsp), %rdi
callq 0x2aef2
movq %rsp, %rdi
callq 0x2aef2
leaq 0x20(%rsp), %rdi
callq 0x2aef2
leaq 0x60(%rsp), %rdi
callq 0x8978
leaq 0x38(%rsp), %rdi
callq 0x8978
leaq 0x80(%rsp), %rdi
callq 0x28a08
leaq 0xb8(%rsp), %rdi
callq 0x8af9c
leaq 0x98(%rsp), %rdi
callq 0x8978
movq %rbx, %rdi
callq 0x8870