// File: /workspace/github_cpp_makefile_star2_O1/JorisCaze[P]NASG-EOS_Calibration/src/calib_liq-vap.cpp
// Function: computePsatTh(double, double, double, double, double, double, double)
double computePsatTh(double A, double B, double C, double D, double E, double pinfL, double T)
{
    // Purpose : compute saturated pressure Psat at a given temperature
    // See eq. (41), fp is obtained with exp((41))
    // More : Newton-Raphson algo. is used
    double fp, dfp, p1(1.e5), p2(0.), err(1.), k(0.);
    int count(0);

    while (err > 1.e-5 && count < 50) {
        k = exp(A+B/T+C*log(T));
        fp = p1 - k*exp(E*p1/T)*pow((p1+pinfL),D);
        dfp = 1. - k*exp(E*p1/T)*((E/T)*pow((p1+pinfL),D) + D*pow((p1+pinfL),(D-1.)));
        p2 = p1 - fp/dfp;
        err = fabs(p2-p1)/(0.5*(p1+p2));
        p1 = p2;
        count++;
        if (count >= 50) 
            cout << "Warning : newton-raphson of Psat(T) function not converged\n";
    }
    if (p2 < 1.e-6)
        return 0.;
    else
        return p2;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x90, %rsp
movsd %xmm5, 0x80(%rsp)
movsd %xmm2, 0x70(%rsp)
divsd %xmm6, %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x68(%rsp)
movsd %xmm4, 0x78(%rsp)
movsd %xmm6, 0x30(%rsp)
divsd %xmm6, %xmm4
movsd %xmm4, 0x60(%rsp)
movsd 0x2dba(%rip), %xmm0     # 0x6010
movsd %xmm3, 0x28(%rsp)
addsd %xmm3, %xmm0
movsd %xmm0, 0x58(%rsp)
movsd 0x2dca(%rip), %xmm0     # 0x6038
xorl %r15d, %r15d
movq 0x5d60(%rip), %rbx      # 0x8fd8
leaq 0x2e47(%rip), %r14      # 0x60c6
movapd %xmm0, %xmm1
movsd %xmm0, 0x8(%rsp)
movapd %xmm1, 0x40(%rsp)
movsd 0x30(%rsp), %xmm0
callq 0x20f0
mulsd 0x70(%rsp), %xmm0
addsd 0x68(%rsp), %xmm0
callq 0x2220
movsd %xmm0, 0x10(%rsp)
movsd 0x8(%rsp), %xmm0
mulsd 0x78(%rsp), %xmm0
divsd 0x30(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
callq 0x2220
movsd %xmm0, 0x20(%rsp)
movsd 0x8(%rsp), %xmm0
addsd 0x80(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
movsd 0x28(%rsp), %xmm1
callq 0x2200
movsd 0x20(%rsp), %xmm1
mulsd 0x10(%rsp), %xmm1
mulsd %xmm0, %xmm1
movsd 0x8(%rsp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x18(%rsp), %xmm0
callq 0x2220
movsd %xmm0, 0x18(%rsp)
movsd 0x38(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
callq 0x2200
movsd %xmm0, 0x88(%rsp)
movsd 0x38(%rsp), %xmm0
movsd 0x58(%rsp), %xmm1
callq 0x2200
movsd 0x8(%rsp), %xmm2
movapd 0x40(%rsp), %xmm1
mulsd 0x28(%rsp), %xmm0
movsd 0x88(%rsp), %xmm3
mulsd 0x60(%rsp), %xmm3
addsd %xmm0, %xmm3
movsd 0x18(%rsp), %xmm0
mulsd 0x10(%rsp), %xmm0
mulsd %xmm3, %xmm0
movapd %xmm0, %xmm3
movsd 0x2c8f(%rip), %xmm0     # 0x6020
subsd %xmm3, %xmm0
movsd 0x20(%rsp), %xmm3
divsd %xmm0, %xmm3
subsd %xmm3, %xmm1
movapd %xmm2, %xmm3
addsd %xmm1, %xmm3
mulsd 0x2c7d(%rip), %xmm3     # 0x6030
cmpl $0x31, %r15d
jb 0x33e7
movl $0x3b, %edx
movq %rbx, %rdi
movq %r14, %rsi
movapd %xmm1, 0x40(%rsp)
movsd %xmm3, 0x10(%rsp)
callq 0x2180
movsd 0x10(%rsp), %xmm3
movsd 0x8(%rsp), %xmm2
movapd 0x40(%rsp), %xmm1
movapd %xmm1, %xmm0
subsd %xmm2, %xmm0
andpd 0x2c89(%rip), %xmm0     # 0x6080
divsd %xmm3, %xmm0
ucomisd 0x2c25(%rip), %xmm0     # 0x6028
jbe 0x341a
leal 0x1(%r15), %eax
movapd %xmm1, %xmm0
cmpl $0x31, %r15d
movl %eax, %r15d
jb 0x3283
movapd %xmm1, %xmm0
cmpltsd 0x2c19(%rip), %xmm0     # 0x6040
andnpd %xmm1, %xmm0
addq $0x90, %rsp
popq %rbx
popq %r14
popq %r15
retq