// File: /workspace/github_cpp_makefile_star2_O1/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 $0x118, %rsp            # imm = 0x118
callq 0xc03b0
leaq 0xb0(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0x4d628(%rip), %rsi     # 0x10d270
leaq 0xe0(%rsp), %rdi
leaq 0x60(%rsp), %rdx
callq 0x286de
leaq 0xe0(%rsp), %r14
movq %r14, %rdi
movl $0x8, %esi
callq 0x53224
movq %rax, %r15
leaq 0xf0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xbfc93
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x8480
movl $0x208, %edi            # imm = 0x208
callq 0x8470
movq %rax, %rbx
movq 0x4d5e9(%rip), %rsi     # 0x10d290
movq %rax, %rdi
movl $0x8, %edx
callq 0x8860
leaq 0x110(%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, 0x4d5ef(%rip)     # 0x10d2d0
je 0xbfda6
leaq 0xa0(%rsp), %r12
leaq 0x299d9(%rip), %r13     # 0xe96cf
leaq 0x60(%rsp), %rbp
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x8450
movsbl %al, %edx
movq %r15, %rdi
movq %r12, %rsi
callq 0x8870
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0xbfe35
movq %r12, %rdi
movq %r13, %rsi
callq 0x8160
testl %eax, %eax
je 0xbfcfb
movq 0xa0(%rsp), %rax
cmpb $0x42, (%rax)
jne 0xbfd51
cmpb $0x4c, 0x1(%rax)
je 0xbfcfb
movq %rbp, %rdi
movq %r12, %rsi
movl $0x9, %edx
callq 0x50624
movq 0x60(%rsp), %rax
movq 0x80(%rax), %rdi
callq 0x86e0
movl %eax, 0xc0(%rsp)
movq %r14, 0x80(%rsp)
movq %r14, %rdi
leaq 0xc0(%rsp), %rsi
leaq 0x80(%rsp), %rdx
callq 0xc06d4
movq %rbp, %rdi
callq 0x3123c
jmp 0xbfcfb
leaq 0xa0(%rsp), %r12
leaq 0x60(%rsp), %r13
leaq 0x80(%rsp), %rbp
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x8450
movsbl %al, %edx
movq %r15, %rdi
movq %r12, %rsi
callq 0x8870
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0xbfe35
movq %r13, %rdi
movq %r12, %rsi
movl $0x9, %edx
callq 0x50624
movq 0x60(%rsp), %rax
movq 0x20(%rax), %rdi
callq 0x86e0
movl %eax, 0xc0(%rsp)
movq %r14, 0x80(%rsp)
movq %r14, %rdi
leaq 0xc0(%rsp), %rsi
movq %rbp, %rdx
callq 0xc06d4
movq %r13, %rdi
callq 0x3123c
jmp 0xbfdbb
leaq 0xa0(%rsp), %r14
leaq 0xc0(%rsp), %r12
leaq 0xe0(%rsp), %r15
movq %rbx, 0xd8(%rsp)
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x8450
movsbl %al, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x8870
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0xc01f9
movq %r12, %rdi
movq %r14, %rsi
movl $0x9, %edx
callq 0x50624
movq %r14, %rbx
movq 0xc0(%rsp), %r14
movq 0xc8(%rsp), %rax
subq %r14, %rax
cmpq $0x100, %rax            # imm = 0x100
jne 0xc023f
movq 0x40(%r14), %rdi
callq 0x86e0
movl %eax, %ebp
movq 0x80(%r14), %rdi
callq 0x86e0
movl %eax, %r13d
leaq 0x70(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0xa0(%r14), %rsi
movq 0xa8(%r14), %rdx
addq %rsi, %rdx
leaq 0x60(%rsp), %r14
movq %r14, %rdi
callq 0x2e45c
movq 0xc0(%rsp), %rax
leaq 0x90(%rsp), %rcx
movq %rcx, 0x80(%rsp)
movq 0xc0(%rax), %rsi
movq 0xc8(%rax), %rdx
addq %rsi, %rdx
leaq 0x80(%rsp), %rdi
callq 0x2e45c
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
movl $0x96, %esi
leaq 0x20(%rsp), %rdi
callq 0x54d18
movq %r14, %rdi
leaq 0x10946(%rip), %rsi     # 0xd08a3
callq 0x8160
movq 0x20(%rsp), %rcx
testl %eax, %eax
je 0xc0071
movq 0x28(%rsp), %rax
cmpq %rax, %rcx
je 0xbff8c
addl $0xffffff6a, %ebp       # imm = 0xFFFFFF6A
movl %ebp, (%rcx)
incl %ebp
addq $0x4, %rcx
cmpq %rax, %rcx
jne 0xbff7f
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movl $0x96, %esi
movq %rsp, %rdi
callq 0x54d18
leaq 0x80(%rsp), %rdi
leaq 0x108eb(%rip), %rsi     # 0xd08a3
callq 0x8160
movq (%rsp), %rcx
testl %eax, %eax
je 0xc0089
movq 0x8(%rsp), %rax
cmpq %rax, %rcx
je 0xbffe9
addl $0xffffff6a, %r13d      # imm = 0xFFFFFF6A
movl %r13d, (%rcx)
incl %r13d
addq $0x4, %rcx
cmpq %rax, %rcx
jne 0xbffda
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movq $0x0, 0x50(%rsp)
movq 0x20(%rsp), %rsi
cmpq %rsi, 0x28(%rsp)
je 0xc00a3
xorl %r13d, %r13d
xorl %r14d, %r14d
xorl %ebp, %ebp
addq %r13, %rsi
movq %r15, %rdi
callq 0xc0998
cmpq $0x1, %rax
jne 0xc0052
incl %ebp
movq 0x20(%rsp), %rdx
addq %r13, %rdx
movq 0x48(%rsp), %rsi
cmpq 0x50(%rsp), %rsi
je 0xc0048
movl (%rdx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x48(%rsp)
jmp 0xc0052
leaq 0x40(%rsp), %rdi
callq 0x4bc3a
incq %r14
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rax
subq %rsi, %rax
sarq $0x2, %rax
addq $0x4, %r13
cmpq %r14, %rax
ja 0xc0012
jmp 0xc00a5
movq 0x28(%rsp), %rax
cmpq %rax, %rcx
je 0xbff8c
movl %ebp, (%rcx)
incl %ebp
addq $0x4, %rcx
jmp 0xc0076
movq 0x8(%rsp), %rax
cmpq %rax, %rcx
je 0xbffe9
movl %r13d, (%rcx)
incl %r13d
addq $0x4, %rcx
jmp 0xc008e
xorl %ebp, %ebp
movq (%rsp), %rsi
cmpq %rsi, 0x8(%rsp)
je 0xc0111
xorl %r13d, %r13d
xorl %r14d, %r14d
addq %r13, %rsi
movq %r15, %rdi
callq 0xc0998
cmpq $0x1, %rax
jne 0xc00f5
incl %ebp
movq (%rsp), %rdx
addq %r13, %rdx
movq 0x48(%rsp), %rsi
cmpq 0x50(%rsp), %rsi
je 0xc00eb
movl (%rdx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x48(%rsp)
jmp 0xc00f5
leaq 0x40(%rsp), %rdi
callq 0x4bc3a
incq %r14
movq (%rsp), %rsi
movq 0x8(%rsp), %rax
subq %rsi, %rax
sarq $0x2, %rax
addq $0x4, %r13
cmpq %r14, %rax
ja 0xc00b6
cmpl $0x1, %ebp
jle 0xc015c
movq 0xa0(%rsp), %rsi
movq 0xa8(%rsp), %rdx
movq 0x4ae8b(%rip), %rdi     # 0x10afb8
callq 0x84e0
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x8450
movsbl %al, %esi
movq %r13, %rdi
callq 0x8040
movq %rax, %rdi
callq 0x8300
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
movq %rbx, %r14
je 0xc0176
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x8480
movq (%rsp), %rdi
testq %rdi, %rdi
movq 0xd8(%rsp), %rbx
je 0xc0194
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x8480
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0xc01ab
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x8480
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0xc01d0
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x8480
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0xc01ec
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x8480
movq %r12, %rdi
callq 0x3123c
jmp 0xbfe55
leaq 0xe0(%rsp), %rdi
callq 0xc0664
movq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rax
cmpq %rax, %rdi
je 0xc022b
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x8480
xorl %eax, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x29492(%rip), %rdi     # 0xe96d8
leaq 0x2949f(%rip), %rsi     # 0xe96ec
leaq 0x294b4(%rip), %rcx     # 0xe9708
movl $0x51, %edx
callq 0x82c0
movq %rax, %r14
movl $0x208, %esi            # imm = 0x208
movq %rbx, %rdi
jmp 0xc0290
jmp 0xc029a
movq %rax, %r14
leaq 0xf0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xc0383
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x8480
jmp 0xc0383
movq %rax, %r14
jmp 0xc0383
jmp 0xc02a8
jmp 0xc02d7
jmp 0xc02d7
movq %rax, %r14
leaq 0x60(%rsp), %rdi
jmp 0xc0371
movq %rax, %r14
jmp 0xc0311
movq %rax, %r14
jmp 0xc02fb
jmp 0xc02d7
movq %rax, %r14
jmp 0xc034d
movq %rax, %r14
jmp 0xc0369
jmp 0xc02d7
jmp 0xc02d7
jmp 0xc02e1
movq %rax, %r14
jmp 0xc0376
jmp 0xc02e1
movq %rax, %r14
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0xc02fb
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x8480
movq (%rsp), %rdi
testq %rdi, %rdi
je 0xc0311
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x8480
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0xc0328
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x8480
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0xc034d
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x8480
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0xc0369
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x8480
leaq 0xc0(%rsp), %rdi
callq 0x3123c
leaq 0xe0(%rsp), %rdi
callq 0xc0664
movq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rax
cmpq %rax, %rdi
je 0xc03a8
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x8480
movq %r14, %rdi
callq 0x8840