// File: /workspace/github_cpp_makefile_star2_O2/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 %r14
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
movsd 0x18b6f(%rip), %xmm15   # 0x975f0
movapd %xmm15, %xmm11
subsd %xmm0, %xmm11
movapd %xmm11, %xmm12
mulsd %xmm0, %xmm12
movsd 0x18b5b(%rip), %xmm7    # 0x975f8
movapd %xmm3, %xmm6
addsd %xmm7, %xmm6
divsd %xmm6, %xmm12
movapd %xmm15, %xmm6
subsd %xmm1, %xmm6
movapd %xmm6, %xmm9
mulsd %xmm1, %xmm9
movapd %xmm4, %xmm8
addsd %xmm7, %xmm8
divsd %xmm8, %xmm9
movapd %xmm15, %xmm8
subsd %xmm2, %xmm8
movapd %xmm8, %xmm10
mulsd %xmm2, %xmm10
addsd %xmm7, %xmm5
xorpd %xmm7, %xmm7
ucomisd %xmm7, %xmm0
jne 0x7eafe
jp 0x7eafe
xorpd %xmm13, %xmm13
ucomisd %xmm13, %xmm1
jne 0x7eafe
jnp 0x7eb4a
ucomisd 0x18aea(%rip), %xmm0    # 0x975f0
jne 0x7eb16
jp 0x7eb16
ucomisd 0x18ade(%rip), %xmm1    # 0x975f0
jne 0x7eb16
jnp 0x7eb4a
movapd %xmm0, %xmm7
subsd %xmm1, %xmm7
mulsd %xmm7, %xmm7
subsd %xmm12, %xmm7
subsd %xmm9, %xmm7
movapd %xmm11, %xmm13
mulsd %xmm1, %xmm13
movapd %xmm0, %xmm14
mulsd %xmm6, %xmm14
addsd %xmm13, %xmm14
divsd %xmm14, %xmm7
divsd %xmm5, %xmm10
xorpd %xmm5, %xmm5
ucomisd %xmm5, %xmm0
jne 0x7eb69
jp 0x7eb69
xorpd %xmm13, %xmm13
ucomisd %xmm13, %xmm2
jne 0x7eb69
jnp 0x7ebaa
ucomisd 0x18a7f(%rip), %xmm0    # 0x975f0
jne 0x7eb81
jp 0x7eb81
ucomisd 0x18a73(%rip), %xmm2    # 0x975f0
jne 0x7eb81
jnp 0x7ebaa
movapd %xmm0, %xmm5
subsd %xmm2, %xmm5
mulsd %xmm5, %xmm5
subsd %xmm12, %xmm5
mulsd %xmm2, %xmm11
mulsd %xmm8, %xmm0
addsd %xmm11, %xmm0
subsd %xmm10, %xmm5
divsd %xmm0, %xmm5
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jne 0x7ebc4
jp 0x7ebc4
xorpd %xmm11, %xmm11
ucomisd %xmm11, %xmm2
jne 0x7ebc4
jnp 0x7ec05
ucomisd 0x18a24(%rip), %xmm1    # 0x975f0
jne 0x7ebdc
jp 0x7ebdc
ucomisd 0x18a18(%rip), %xmm2    # 0x975f0
jne 0x7ebdc
jnp 0x7ec05
movapd %xmm1, %xmm0
subsd %xmm2, %xmm0
mulsd %xmm0, %xmm0
subsd %xmm9, %xmm0
mulsd %xmm2, %xmm6
mulsd %xmm1, %xmm8
addsd %xmm6, %xmm8
subsd %xmm10, %xmm0
divsd %xmm8, %xmm0
xorpd %xmm6, %xmm6
maxsd %xmm7, %xmm6
xorpd %xmm7, %xmm7
maxsd %xmm5, %xmm7
xorpd %xmm2, %xmm2
maxsd %xmm0, %xmm2
movapd %xmm6, %xmm1
cmpeqsd %xmm15, %xmm1
movapd %xmm1, %xmm0
andnpd %xmm6, %xmm0
divsd %xmm3, %xmm6
movapd %xmm15, %xmm5
subsd %xmm6, %xmm5
andpd %xmm5, %xmm1
orpd %xmm0, %xmm1
movapd %xmm7, %xmm5
cmpeqsd %xmm15, %xmm5
movapd %xmm5, %xmm0
andnpd %xmm7, %xmm0
divsd %xmm3, %xmm7
movapd %xmm15, %xmm3
subsd %xmm7, %xmm3
andpd %xmm3, %xmm5
orpd %xmm0, %xmm5
movapd %xmm5, 0x20(%rsp)
movapd %xmm2, %xmm5
cmpeqsd %xmm15, %xmm5
movapd %xmm5, %xmm0
andnpd %xmm2, %xmm0
divsd %xmm4, %xmm2
movapd %xmm15, %xmm3
subsd %xmm2, %xmm3
andpd %xmm3, %xmm5
orpd %xmm0, %xmm5
movapd %xmm5, 0x50(%rsp)
movapd %xmm15, %xmm0
subsd %xmm1, %xmm0
callq 0x83e0
movsd %xmm0, 0x38(%rsp)
movsd 0x18936(%rip), %xmm0    # 0x975f0
subsd 0x20(%rsp), %xmm0
callq 0x83e0
movapd %xmm0, 0x20(%rsp)
xorpd 0x188ed(%rip), %xmm0    # 0x975c0
movapd %xmm0, 0x40(%rsp)
movsd 0x1890f(%rip), %xmm0    # 0x975f0
subsd 0x50(%rsp), %xmm0
callq 0x83e0
movapd 0x188cc(%rip), %xmm2    # 0x975c0
xorpd %xmm0, %xmm2
movsd 0x38(%rsp), %xmm3
movapd 0x40(%rsp), %xmm4
subsd %xmm3, %xmm4
addsd %xmm0, %xmm4
movsd 0x188ec(%rip), %xmm1    # 0x97600
mulsd %xmm1, %xmm4
movsd %xmm4, 0x18(%rsp)
movapd %xmm2, %xmm0
subsd %xmm3, %xmm0
movapd 0x20(%rsp), %xmm5
addsd %xmm5, %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x10(%rsp)
subsd %xmm5, %xmm2
addsd %xmm3, %xmm2
mulsd %xmm1, %xmm2
xorpd %xmm1, %xmm1
movsd %xmm2, 0x8(%rsp)
ucomisd %xmm4, %xmm1
jbe 0x7ed5c
andq $0x0, 0x18(%rsp)
ucomisd %xmm0, %xmm1
jbe 0x7ed68
andq $0x0, 0x10(%rsp)
xorpd %xmm0, %xmm0
ucomisd %xmm2, %xmm0
jbe 0x7ed78
andq $0x0, 0x8(%rsp)
xorpd %xmm0, %xmm0
movupd %xmm0, (%rbx)
andq $0x0, 0x10(%rbx)
leaq 0x18(%rsp), %rsi
movq %rbx, %rdi
callq 0x5a406
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0x5a406
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x5a406
movq %rbx, %rax
addq $0x68, %rsp
popq %rbx
popq %r14
retq
movq %rax, %r14
movq %rbx, %rdi
callq 0x2b43c
movq %r14, %rdi
callq 0x8870