// File: /workspace/github_cpp_makefile_star2_O3/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 %rbx
subq $0xd0, %rsp
movsd %xmm5, 0x78(%rsp)
movsd %xmm2, 0x68(%rsp)
divsd %xmm6, %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x60(%rsp)
movsd %xmm4, 0x70(%rsp)
movsd %xmm6, 0x28(%rsp)
divsd %xmm6, %xmm4
movsd %xmm4, 0x58(%rsp)
movsd 0x2dd9(%rip), %xmm0     # 0x6010
movsd %xmm3, 0x8(%rsp)
addsd %xmm3, %xmm0
movsd %xmm0, 0x50(%rsp)
movsd 0x2de9(%rip), %xmm1     # 0x6038
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movapd %xmm1, 0x10(%rsp)
movapd %xmm1, 0x40(%rsp)
movsd 0x28(%rsp), %xmm0
callq 0x20f0
mulsd 0x68(%rsp), %xmm0
addsd 0x60(%rsp), %xmm0
callq 0x2220
movapd %xmm0, 0xc0(%rsp)
movapd 0x10(%rsp), %xmm0
mulsd 0x70(%rsp), %xmm0
divsd 0x28(%rsp), %xmm0
movapd %xmm0, 0x30(%rsp)
callq 0x2220
movapd %xmm0, 0xb0(%rsp)
movapd 0x10(%rsp), %xmm0
addsd 0x78(%rsp), %xmm0
movapd %xmm0, 0x80(%rsp)
movsd 0x8(%rsp), %xmm1
callq 0x2200
movapd %xmm0, 0xa0(%rsp)
movaps 0x30(%rsp), %xmm0
callq 0x2220
movaps %xmm0, 0x30(%rsp)
movaps 0x80(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
callq 0x2200
movaps %xmm0, 0x90(%rsp)
movapd 0x80(%rsp), %xmm0
movsd 0x50(%rsp), %xmm1
callq 0x2200
mulsd 0x8(%rsp), %xmm0
movapd 0x90(%rsp), %xmm1
mulsd 0x58(%rsp), %xmm1
addsd %xmm0, %xmm1
movapd %xmm1, %xmm2
movapd 0xb0(%rsp), %xmm1
unpcklpd 0x30(%rsp), %xmm1       # xmm1 = xmm1[0],mem[0]
movapd 0xc0(%rsp), %xmm0
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
mulpd %xmm1, %xmm0
movapd 0xa0(%rsp), %xmm1
unpcklpd %xmm2, %xmm1            # xmm1 = xmm1[0],xmm2[0]
mulpd %xmm0, %xmm1
movapd 0x2d28(%rip), %xmm0     # 0x6090
movlpd 0x10(%rsp), %xmm0       # xmm0 = mem[0],xmm0[1]
subpd %xmm1, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
divsd %xmm1, %xmm0
movapd 0x40(%rsp), %xmm1
subsd %xmm0, %xmm1
incl %ebx
cmpl $0x31, %ebx
jae 0x33cb
movapd %xmm1, %xmm0
movapd 0x10(%rsp), %xmm2
subsd %xmm2, %xmm0
andpd 0x2cdb(%rip), %xmm0     # 0x6080
addsd %xmm1, %xmm2
mulsd 0x2c7f(%rip), %xmm2     # 0x6030
divsd %xmm2, %xmm0
ucomisd 0x2c6b(%rip), %xmm0     # 0x6028
movapd %xmm1, 0x10(%rsp)
ja 0x325a
jmp 0x33ef
movq 0x5c06(%rip), %rdi      # 0x8fd8
leaq 0x2cfd(%rip), %rsi      # 0x60d6
movl $0x3b, %edx
movapd %xmm1, 0x40(%rsp)
callq 0x2180
movapd 0x40(%rsp), %xmm1
movapd %xmm1, %xmm0
cmpltsd 0x2c44(%rip), %xmm0     # 0x6040
andnpd %xmm1, %xmm0
addq $0xd0, %rsp
popq %rbx
retq