// File: millanek[P]evo/process_vcf_stats_functions.cpp
// Function: diffs_between_individuals_with_multialleleics(std::vector<std::vector<double, std::allocator<double>>, std::allocator<std::vector<double, std::allocator<double>>>>&, std::vector<std::vector<int, std::allocator<int>>, std::allocator<std::vector<int, std::allocator<int>>>>&, std::vector<std::vector<double, std::allocator<double>>, std::allocator<std::vector<double, std::allocator<double>>>>&, std::vector<std::vector<int, std::allocator<int>>, std::allocator<std::vector<int, std::allocator<int>>>>&, FilterResult&)
void diffs_between_individuals_with_multialleleics(std::vector<std::vector<double> >& diffs_me, std::vector<std::vector<int> >& pairwise_missingness, std::vector<std::vector<double> >& diffs_me_bootstrap, std::vector<std::vector<int> >& pairwise_missingness_bootstrap, FilterResult& result) {
    for (std::vector<std::vector<int> >::size_type i = 0; i < diffs_me.size(); i++) {
        const int ind_i = result.counts.haplotypesWithVariant[2*i];
        const int ind_i2 = result.counts.haplotypesWithVariant[2*i+1];
        const bool ind_i_missing = result.counts.missingGenotypesPerIndividual[i];
        for (int j = 0; j <= i; j++) {
            double diff_measure_Me;
            if (ind_i_missing) {
                diff_measure_Me = 0;
                pairwise_missingness[i][j]++;
                pairwise_missingness_bootstrap[i][j]++;
            } else {
                const bool ind_j_missing = result.counts.missingGenotypesPerIndividual[j];
                if (ind_j_missing) {
                    diff_measure_Me = 0;
                    pairwise_missingness[i][j]++;
                    pairwise_missingness_bootstrap[i][j]++;
                } else {
                    const int ind_j = result.counts.haplotypesWithVariant[2*j];
                    const int ind_j2 = result.counts.haplotypesWithVariant[2*j+1];
                    if (j < i) {
                        double totalD = 0; const double numComparisons = 4;
                        if (ind_i != ind_j) totalD++;
                        if (ind_i != ind_j2) totalD++;
                        if (ind_i2 != ind_j) totalD++;
                        if (ind_i2 != ind_j2) totalD++;
                        diff_measure_Me = totalD/numComparisons;
                        if (diff_measure_Me != 0 && diff_measure_Me != 0.5 && diff_measure_Me != 0.75 && diff_measure_Me != 1) {
                            std::cerr << "diff_measure_Me: " << diff_measure_Me << std::endl;
                            std::cerr << "ind_i: " << ind_i << std::endl;
                            std::cerr << "ind_i2: " << ind_i2 << std::endl;
                            std::cerr << "ind_j: " << ind_j << std::endl;
                            std::cerr << "ind_j2: " << ind_j2 << std::endl;
                        }
                        diffs_me[i][j] = diffs_me[i][j] + diff_measure_Me;
                        diffs_me_bootstrap[i][j] = diffs_me_bootstrap[i][j] + diff_measure_Me;
                    } else if (j == i) { // Fill in the diagonal, the number of hets
                        if (ind_i != ind_i2) {
                            diffs_me[i][j]++;
                            diffs_me_bootstrap[i][j]++;
                        }
                    }
                }
            }
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x8(%rbp), %rdi
callq 0x651b0
movq %rax, %rcx
movq -0x98(%rbp), %rax
cmpq %rcx, %rax
jae 0x9d265
movq -0x28(%rbp), %rdi
addq $0x8, %rdi
addq $0xb8, %rdi
movq -0x30(%rbp), %rsi
shlq %rsi
callq 0x4d100
movl (%rax), %eax
movl %eax, -0x34(%rbp)
movq -0x28(%rbp), %rdi
addq $0x8, %rdi
addq $0xb8, %rdi
movq -0x30(%rbp), %rsi
shlq %rsi
addq $0x1, %rsi
callq 0x4d100
movl (%rax), %eax
movl %eax, -0x38(%rbp)
movq -0x28(%rbp), %rdi
addq $0x8, %rdi
addq $0xd0, %rdi
movq -0x30(%rbp), %rsi
callq 0x83940
movq %rax, -0x50(%rbp)
movq %rdx, -0x48(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x481b0
andb $0x1, %al
movb %al, -0x39(%rbp)
movl $0x0, -0x54(%rbp)
movslq -0x54(%rbp), %rax
cmpq -0x30(%rbp), %rax
ja 0x9d252
testb $0x1, -0x39(%rbp)
je 0x9ce68
xorps %xmm0, %xmm0
movsd %xmm0, -0x60(%rbp)
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x705d0
movq %rax, %rdi
movslq -0x54(%rbp), %rsi
callq 0x4d100
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq -0x20(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x705d0
movq %rax, %rdi
movslq -0x54(%rbp), %rsi
callq 0x4d100
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x9d242
movq -0x28(%rbp), %rdi
addq $0x8, %rdi
addq $0xd0, %rdi
movslq -0x54(%rbp), %rsi
callq 0x83940
movq %rax, -0x78(%rbp)
movq %rdx, -0x70(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x481b0
andb $0x1, %al
movb %al, -0x61(%rbp)
testb $0x1, -0x61(%rbp)
je 0x9cee9
xorps %xmm0, %xmm0
movsd %xmm0, -0x60(%rbp)
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x705d0
movq %rax, %rdi
movslq -0x54(%rbp), %rsi
callq 0x4d100
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq -0x20(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x705d0
movq %rax, %rdi
movslq -0x54(%rbp), %rsi
callq 0x4d100
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x9d240
movq -0x28(%rbp), %rdi
addq $0x8, %rdi
addq $0xb8, %rdi
movl -0x54(%rbp), %eax
shll %eax
movslq %eax, %rsi
callq 0x4d100
movl (%rax), %eax
movl %eax, -0x7c(%rbp)
movq -0x28(%rbp), %rdi
addq $0x8, %rdi
addq $0xb8, %rdi
movl -0x54(%rbp), %eax
shll %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0x4d100
movl (%rax), %eax
movl %eax, -0x80(%rbp)
movslq -0x54(%rbp), %rax
cmpq -0x30(%rbp), %rax
jae 0x9d1d6
xorps %xmm0, %xmm0
movsd %xmm0, -0x88(%rbp)
movsd 0xa06e1(%rip), %xmm0    # 0x13d630
movsd %xmm0, -0x90(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x7c(%rbp), %eax
je 0x9cf77
movsd 0x95351(%rip), %xmm0    # 0x1322b8
addsd -0x88(%rbp), %xmm0
movsd %xmm0, -0x88(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x80(%rbp), %eax
je 0x9cf97
movsd 0x95331(%rip), %xmm0    # 0x1322b8
addsd -0x88(%rbp), %xmm0
movsd %xmm0, -0x88(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x7c(%rbp), %eax
je 0x9cfb7
movsd 0x95311(%rip), %xmm0    # 0x1322b8
addsd -0x88(%rbp), %xmm0
movsd %xmm0, -0x88(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x80(%rbp), %eax
je 0x9cfd7
movsd 0x952f1(%rip), %xmm0    # 0x1322b8
addsd -0x88(%rbp), %xmm0
movsd %xmm0, -0x88(%rbp)
movsd -0x88(%rbp), %xmm0
movsd 0xa0649(%rip), %xmm1    # 0x13d630
divsd %xmm1, %xmm0
movsd %xmm0, -0x60(%rbp)
movsd -0x60(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x9d005
jp 0x9d005
jmp 0x9d136
movsd -0x60(%rbp), %xmm0
movsd 0x910f6(%rip), %xmm1    # 0x12e108
ucomisd %xmm1, %xmm0
jne 0x9d01f
jp 0x9d01f
jmp 0x9d136
movsd -0x60(%rbp), %xmm0
movsd 0xa060c(%rip), %xmm1    # 0x13d638
ucomisd %xmm1, %xmm0
jne 0x9d039
jp 0x9d039
jmp 0x9d136
movsd -0x60(%rbp), %xmm0
movsd 0x95272(%rip), %xmm1    # 0x1322b8
ucomisd %xmm1, %xmm0
jne 0x9d053
jp 0x9d053
jmp 0x9d136
movq 0xfbf96(%rip), %rdi     # 0x198ff0
leaq 0xa06ca(%rip), %rsi     # 0x13d72b
callq 0xa5c0
movq %rax, %rdi
movsd -0x60(%rbp), %xmm0
callq 0xabd0
movq %rax, %rdi
movq 0xfbf0b(%rip), %rsi     # 0x198f88
callq 0xa610
movq 0xfbf67(%rip), %rdi     # 0x198ff0
leaq 0xa06ad(%rip), %rsi     # 0x13d73d
callq 0xa5c0
movq %rax, %rdi
movl -0x34(%rbp), %esi
callq 0xab20
movq %rax, %rdi
movq 0xfbede(%rip), %rsi     # 0x198f88
callq 0xa610
movq 0xfbf3a(%rip), %rdi     # 0x198ff0
leaq 0xa0688(%rip), %rsi     # 0x13d745
callq 0xa5c0
movq %rax, %rdi
movl -0x38(%rbp), %esi
callq 0xab20
movq %rax, %rdi
movq 0xfbeb1(%rip), %rsi     # 0x198f88
callq 0xa610
movq 0xfbf0d(%rip), %rdi     # 0x198ff0
leaq 0xa0664(%rip), %rsi     # 0x13d74e
callq 0xa5c0
movq %rax, %rdi
movl -0x7c(%rbp), %esi
callq 0xab20
movq %rax, %rdi
movq 0xfbe84(%rip), %rsi     # 0x198f88
callq 0xa610
movq 0xfbee0(%rip), %rdi     # 0x198ff0
leaq 0xa063f(%rip), %rsi     # 0x13d756
callq 0xa5c0
movq %rax, %rdi
movl -0x80(%rbp), %esi
callq 0xab20
movq %rax, %rdi
movq 0xfbe57(%rip), %rsi     # 0x198f88
callq 0xa610
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x651e0
movq %rax, %rdi
movslq -0x54(%rbp), %rsi
callq 0x3ec30
movsd (%rax), %xmm0
addsd -0x60(%rbp), %xmm0
movsd %xmm0, -0xa8(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x651e0
movq %rax, %rdi
movslq -0x54(%rbp), %rsi
callq 0x3ec30
movsd -0xa8(%rbp), %xmm0
movsd %xmm0, (%rax)
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x651e0
movq %rax, %rdi
movslq -0x54(%rbp), %rsi
callq 0x3ec30
movsd (%rax), %xmm0
addsd -0x60(%rbp), %xmm0
movsd %xmm0, -0xa0(%rbp)
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x651e0
movq %rax, %rdi
movslq -0x54(%rbp), %rsi
callq 0x3ec30
movsd -0xa0(%rbp), %xmm0
movsd %xmm0, (%rax)
jmp 0x9d23e
movslq -0x54(%rbp), %rax
cmpq -0x30(%rbp), %rax
jne 0x9d23c
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
je 0x9d23a
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x651e0
movq %rax, %rdi
movslq -0x54(%rbp), %rsi
callq 0x3ec30
movsd 0x950af(%rip), %xmm0    # 0x1322b8
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x651e0
movq %rax, %rdi
movslq -0x54(%rbp), %rsi
callq 0x3ec30
movsd 0x95086(%rip), %xmm0    # 0x1322b8
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
jmp 0x9d23c
jmp 0x9d23e
jmp 0x9d240
jmp 0x9d242
jmp 0x9d244
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x9ce07
jmp 0x9d254
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x9cd67
addq $0xb0, %rsp
popq %rbp
retq
nop