// File: /workspace/github_cpp_makefile_star2_O1/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 0x20e08(%rip), %xmm15   # 0xcf440
movapd %xmm15, %xmm11
subsd %xmm0, %xmm11
movapd %xmm11, %xmm12
mulsd %xmm0, %xmm12
movsd 0x20df4(%rip), %xmm7    # 0xcf448
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 0xae6b5
jp 0xae6b5
xorpd %xmm13, %xmm13
ucomisd %xmm13, %xmm1
jne 0xae6b5
jnp 0xae701
ucomisd 0x20d83(%rip), %xmm0    # 0xcf440
jne 0xae6cd
jp 0xae6cd
ucomisd 0x20d77(%rip), %xmm1    # 0xcf440
jne 0xae6cd
jnp 0xae701
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 0xae720
jp 0xae720
xorpd %xmm13, %xmm13
ucomisd %xmm13, %xmm2
jne 0xae720
jnp 0xae761
ucomisd 0x20d18(%rip), %xmm0    # 0xcf440
jne 0xae738
jp 0xae738
ucomisd 0x20d0c(%rip), %xmm2    # 0xcf440
jne 0xae738
jnp 0xae761
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 0xae77b
jp 0xae77b
xorpd %xmm11, %xmm11
ucomisd %xmm11, %xmm2
jne 0xae77b
jnp 0xae7bc
ucomisd 0x20cbd(%rip), %xmm1    # 0xcf440
jne 0xae793
jp 0xae793
ucomisd 0x20cb1(%rip), %xmm2    # 0xcf440
jne 0xae793
jnp 0xae7bc
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 0x83b0
movsd %xmm0, 0x38(%rsp)
movsd 0x20bcf(%rip), %xmm0    # 0xcf440
subsd 0x20(%rsp), %xmm0
callq 0x83b0
movapd %xmm0, 0x20(%rsp)
xorpd 0x20bd6(%rip), %xmm0    # 0xcf460
movapd %xmm0, 0x40(%rsp)
movsd 0x20ba8(%rip), %xmm0    # 0xcf440
subsd 0x50(%rsp), %xmm0
callq 0x83b0
movapd 0x20bb5(%rip), %xmm2    # 0xcf460
xorpd %xmm0, %xmm2
movsd 0x38(%rsp), %xmm3
movapd 0x40(%rsp), %xmm4
subsd %xmm3, %xmm4
addsd %xmm0, %xmm4
movsd 0x20b85(%rip), %xmm1    # 0xcf450
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 0xae916
movq $0x0, 0x18(%rsp)
ucomisd %xmm0, %xmm1
jbe 0xae925
movq $0x0, 0x10(%rsp)
xorpd %xmm0, %xmm0
ucomisd %xmm2, %xmm0
jbe 0xae938
movq $0x0, 0x8(%rsp)
xorpd %xmm0, %xmm0
movupd %xmm0, (%rbx)
movq $0x0, 0x10(%rbx)
movq 0x8(%rbx), %rsi
testq %rsi, %rsi
je 0xae965
movsd 0x18(%rsp), %xmm0
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rbx)
jmp 0xae972
leaq 0x18(%rsp), %rdx
movq %rbx, %rdi
callq 0x79f34
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0xae990
movsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rbx)
jmp 0xae99d
leaq 0x10(%rsp), %rdx
movq %rbx, %rdi
callq 0x79f34
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0xae9bb
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rbx)
jmp 0xae9c8
leaq 0x8(%rsp), %rdx
movq %rbx, %rdi
callq 0x79f34
movq %rbx, %rax
addq $0x68, %rsp
popq %rbx
popq %r14
retq
movq %rax, %r14
movq (%rbx), %rdi
testq %rdi, %rdi
je 0xae9ea
movq 0x10(%rbx), %rsi
subq %rdi, %rsi
callq 0x8480
movq %r14, %rdi
callq 0x8840