// File: millanek[P]evo/evo_PBS.cpp
// Function: calculatePBSfromAFs(double, double, double, double, double, double)
inline std::vector<double> calculatePBSfromAFs(double p1, double p2, double p3, double p1AlleleCount, double p2AlleleCount, double p3AlleleCount) {
    // std::cerr << "p:\t" << p1 << "\t" << p2 << "\t" << p3 <<  std::endl;
    double Fst12; double Fst13; double Fst23;
    double power12 = pow(p1-p2, 2);
    double power13 = pow(p1-p3, 2);
    double power23 = pow(p2-p3, 2);
    double fraction1 = (p1*(1-p1))/(p1AlleleCount-1);
    double fraction2 = (p2*(1-p2))/(p2AlleleCount-1);
    double fraction3 = (p3*(1-p3))/(p3AlleleCount-1);
    double numerator12 = power12 - fraction1 - fraction2;
    double numerator13 = power13 - fraction1 - fraction3;
    double numerator23 = power23 - fraction2 - fraction3;
    double denominator12 = (p1*(1-p2))+(p2*(1-p1));
    double denominator13 = (p1*(1-p3))+(p3*(1-p1));
    double denominator23 = (p2*(1-p3))+(p3*(1-p2));
    if ((p1 == 0 && p2 == 0) || (p1 == 1 && p2 == 1)) { Fst12 = 0.0; } else { Fst12 = numerator12/denominator12; }
    if ((p1 == 0 && p3 == 0) || (p1 == 1 && p3 == 1)) { Fst13 = 0.0; } else { Fst13 = numerator13/denominator13; }
    if ((p2 == 0 && p3 == 0) || (p2 == 1 && p3 == 1)) { Fst23 = 0.0; } else { Fst23 = numerator23/denominator23; }
    // std::cerr << Fst12 << "\t" << Fst13 << "\t" << Fst23 <<  std::endl;
    if (Fst12 < 0) Fst12 = 0; if (Fst13 < 0) Fst13 = 0; if (Fst23 < 0) Fst23 = 0;
    if (Fst12 == 1) Fst12 = 1 - (Fst12/p1AlleleCount); if (Fst13 == 1) Fst13 = 1 - (Fst13/p1AlleleCount); if (Fst23 == 1) Fst23 = 1 - (Fst23/p2AlleleCount);
    double T12 = -log(1-Fst12); double T13 = -log(1-Fst13); double T23 = -log(1-Fst23);
    double PBS1 = (T12+T13-T23)/2.0;
    double PBS2 = (T12+T23-T13)/2.0;
    double PBS3 = (T13+T23-T12)/2.0;
    if (PBS1 < 0) PBS1 = 0; if (PBS2 < 0) PBS2 = 0; if (PBS3 < 0) PBS3 = 0;
    //std::cerr << PBS1 << "\t" << PBS2 << "\t" << PBS3 <<  std::endl;
    std::vector<double> PBS; PBS.push_back(PBS1); PBS.push_back(PBS2); PBS.push_back(PBS3);
    return PBS;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0x108(%rbp)
movq %rdi, %rax
movq %rax, -0x100(%rbp)
movq %rdi, -0x8(%rbp)
movsd %xmm0, -0x10(%rbp)
movsd %xmm1, -0x18(%rbp)
movsd %xmm2, -0x20(%rbp)
movsd %xmm3, -0x28(%rbp)
movsd %xmm4, -0x30(%rbp)
movsd %xmm5, -0x38(%rbp)
movsd -0x10(%rbp), %xmm0
subsd -0x18(%rbp), %xmm0
movl $0x2, %edi
callq 0x835c0
movsd %xmm0, -0x58(%rbp)
movsd -0x10(%rbp), %xmm0
subsd -0x20(%rbp), %xmm0
movl $0x2, %edi
callq 0x835c0
movsd %xmm0, -0x60(%rbp)
movsd -0x18(%rbp), %xmm0
subsd -0x20(%rbp), %xmm0
movl $0x2, %edi
callq 0x835c0
movsd %xmm0, -0x68(%rbp)
movsd -0x10(%rbp), %xmm0
movsd 0x32502(%rip), %xmm1    # 0x1322b8
subsd -0x10(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd -0x28(%rbp), %xmm1
movsd 0x324ec(%rip), %xmm2    # 0x1322b8
subsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x70(%rbp)
movsd -0x18(%rbp), %xmm0
movsd 0x324d2(%rip), %xmm1    # 0x1322b8
subsd -0x18(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd -0x30(%rbp), %xmm1
movsd 0x324bc(%rip), %xmm2    # 0x1322b8
subsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x78(%rbp)
movsd -0x20(%rbp), %xmm0
movsd 0x324a2(%rip), %xmm1    # 0x1322b8
subsd -0x20(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd -0x38(%rbp), %xmm1
movsd 0x3248c(%rip), %xmm2    # 0x1322b8
subsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x80(%rbp)
movsd -0x58(%rbp), %xmm0
subsd -0x70(%rbp), %xmm0
subsd -0x78(%rbp), %xmm0
movsd %xmm0, -0x88(%rbp)
movsd -0x60(%rbp), %xmm0
subsd -0x70(%rbp), %xmm0
subsd -0x80(%rbp), %xmm0
movsd %xmm0, -0x90(%rbp)
movsd -0x68(%rbp), %xmm0
subsd -0x78(%rbp), %xmm0
subsd -0x80(%rbp), %xmm0
movsd %xmm0, -0x98(%rbp)
movsd -0x10(%rbp), %xmm0
movsd 0x3242d(%rip), %xmm2    # 0x1322b8
subsd -0x18(%rbp), %xmm2
movsd -0x18(%rbp), %xmm1
movsd 0x3241b(%rip), %xmm3    # 0x1322b8
subsd -0x10(%rbp), %xmm3
mulsd %xmm3, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xa0(%rbp)
movsd -0x10(%rbp), %xmm0
movsd 0x323f5(%rip), %xmm2    # 0x1322b8
subsd -0x20(%rbp), %xmm2
movsd -0x20(%rbp), %xmm1
movsd 0x323e3(%rip), %xmm3    # 0x1322b8
subsd -0x10(%rbp), %xmm3
mulsd %xmm3, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xa8(%rbp)
movsd -0x18(%rbp), %xmm0
movsd 0x323bd(%rip), %xmm2    # 0x1322b8
subsd -0x20(%rbp), %xmm2
movsd -0x20(%rbp), %xmm1
movsd 0x323ab(%rip), %xmm3    # 0x1322b8
subsd -0x18(%rbp), %xmm3
mulsd %xmm3, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xb0(%rbp)
movsd -0x10(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xfff48
jp 0xfff48
movsd -0x18(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xfff48
jp 0xfff48
jmp 0xfff72
movsd -0x10(%rbp), %xmm0
movsd 0x32363(%rip), %xmm1    # 0x1322b8
ucomisd %xmm1, %xmm0
jne 0xfff7c
jp 0xfff7c
movsd -0x18(%rbp), %xmm0
movsd 0x3234e(%rip), %xmm1    # 0x1322b8
ucomisd %xmm1, %xmm0
jne 0xfff7c
jp 0xfff7c
xorps %xmm0, %xmm0
movsd %xmm0, -0x40(%rbp)
jmp 0xfff91
movsd -0x88(%rbp), %xmm0
divsd -0xa0(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x10(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xfffb3
jp 0xfffb3
movsd -0x20(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xfffb3
jp 0xfffb3
jmp 0xfffdd
movsd -0x10(%rbp), %xmm0
movsd 0x322f8(%rip), %xmm1    # 0x1322b8
ucomisd %xmm1, %xmm0
jne 0xfffe7
jp 0xfffe7
movsd -0x20(%rbp), %xmm0
movsd 0x322e3(%rip), %xmm1    # 0x1322b8
ucomisd %xmm1, %xmm0
jne 0xfffe7
jp 0xfffe7
xorps %xmm0, %xmm0
movsd %xmm0, -0x48(%rbp)
jmp 0xffffc
movsd -0x90(%rbp), %xmm0
divsd -0xa8(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x18(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x10001e
jp 0x10001e
movsd -0x20(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x10001e
jp 0x10001e
jmp 0x100048
movsd -0x18(%rbp), %xmm0
movsd 0x3228d(%rip), %xmm1    # 0x1322b8
ucomisd %xmm1, %xmm0
jne 0x100052
jp 0x100052
movsd -0x20(%rbp), %xmm0
movsd 0x32278(%rip), %xmm1    # 0x1322b8
ucomisd %xmm1, %xmm0
jne 0x100052
jp 0x100052
xorps %xmm0, %xmm0
movsd %xmm0, -0x50(%rbp)
jmp 0x100067
movsd -0x98(%rbp), %xmm0
divsd -0xb0(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
xorps %xmm0, %xmm0
ucomisd -0x40(%rbp), %xmm0
jbe 0x100079
xorps %xmm0, %xmm0
movsd %xmm0, -0x40(%rbp)
xorps %xmm0, %xmm0
ucomisd -0x48(%rbp), %xmm0
jbe 0x10008b
xorps %xmm0, %xmm0
movsd %xmm0, -0x48(%rbp)
xorps %xmm0, %xmm0
ucomisd -0x50(%rbp), %xmm0
jbe 0x10009d
xorps %xmm0, %xmm0
movsd %xmm0, -0x50(%rbp)
movsd -0x40(%rbp), %xmm0
movsd 0x3220e(%rip), %xmm1    # 0x1322b8
ucomisd %xmm1, %xmm0
jne 0x1000cd
jp 0x1000cd
movsd -0x40(%rbp), %xmm1
divsd -0x28(%rbp), %xmm1
movsd 0x321f4(%rip), %xmm0    # 0x1322b8
subsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x48(%rbp), %xmm0
movsd 0x321de(%rip), %xmm1    # 0x1322b8
ucomisd %xmm1, %xmm0
jne 0x1000fd
jp 0x1000fd
movsd -0x48(%rbp), %xmm1
divsd -0x28(%rbp), %xmm1
movsd 0x321c4(%rip), %xmm0    # 0x1322b8
subsd %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x50(%rbp), %xmm0
movsd 0x321ae(%rip), %xmm1    # 0x1322b8
ucomisd %xmm1, %xmm0
jne 0x10012d
jp 0x10012d
movsd -0x50(%rbp), %xmm1
divsd -0x30(%rbp), %xmm1
movsd 0x32194(%rip), %xmm0    # 0x1322b8
subsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
movsd 0x32183(%rip), %xmm0    # 0x1322b8
subsd -0x40(%rbp), %xmm0
callq 0xa4a0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0xb8(%rbp)
movsd 0x32152(%rip), %xmm0    # 0x1322b8
subsd -0x48(%rbp), %xmm0
callq 0xa4a0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0xc0(%rbp)
movsd 0x32121(%rip), %xmm0    # 0x1322b8
subsd -0x50(%rbp), %xmm0
callq 0xa4a0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0xc8(%rbp)
movsd -0xb8(%rbp), %xmm0
addsd -0xc0(%rbp), %xmm0
subsd -0xc8(%rbp), %xmm0
movsd 0x334e8(%rip), %xmm1    # 0x1336c8
divsd %xmm1, %xmm0
movsd %xmm0, -0xd0(%rbp)
movsd -0xb8(%rbp), %xmm0
addsd -0xc8(%rbp), %xmm0
subsd -0xc0(%rbp), %xmm0
movsd 0x334bc(%rip), %xmm1    # 0x1336c8
divsd %xmm1, %xmm0
movsd %xmm0, -0xd8(%rbp)
movsd -0xc0(%rbp), %xmm0
addsd -0xc8(%rbp), %xmm0
subsd -0xb8(%rbp), %xmm0
movsd 0x33490(%rip), %xmm1    # 0x1336c8
divsd %xmm1, %xmm0
movsd %xmm0, -0xe0(%rbp)
xorps %xmm0, %xmm0
ucomisd -0xd0(%rbp), %xmm0
jbe 0x10025c
xorps %xmm0, %xmm0
movsd %xmm0, -0xd0(%rbp)
xorps %xmm0, %xmm0
ucomisd -0xd8(%rbp), %xmm0
jbe 0x100274
xorps %xmm0, %xmm0
movsd %xmm0, -0xd8(%rbp)
xorps %xmm0, %xmm0
ucomisd -0xe0(%rbp), %xmm0
jbe 0x10028c
xorps %xmm0, %xmm0
movsd %xmm0, -0xe0(%rbp)
movq -0x108(%rbp), %rdi
movb $0x0, -0xe1(%rbp)
callq 0x48410
movq -0x108(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0xb77b0
jmp 0x1002b4
movq -0x108(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0xb77b0
jmp 0x1002c9
movq -0x108(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0xb77b0
jmp 0x1002de
movb $0x1, -0xe1(%rbp)
testb $0x1, -0xe1(%rbp)
jne 0x10031c
jmp 0x100310
movq -0x108(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf0(%rbp)
movl %eax, -0xf4(%rbp)
callq 0x3ecb0
jmp 0x10032c
movq -0x108(%rbp), %rdi
callq 0x3ecb0
movq -0x100(%rbp), %rax
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
movq -0xf0(%rbp), %rdi
callq 0xab50
nopl (%rax,%rax)