// File: /workspace/github_cpp_makefile_star2_O2/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 %rbp
pushq %r14
pushq %rbx
subq $0xc0, %rsp
movsd %xmm5, 0x88(%rsp)
movsd %xmm2, 0x78(%rsp)
divsd %xmm6, %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x70(%rsp)
movsd %xmm4, 0x80(%rsp)
movsd %xmm6, 0x28(%rsp)
divsd %xmm6, %xmm4
movsd %xmm4, 0x68(%rsp)
movsd 0x2214(%rip), %xmm0     # 0x5060
movsd %xmm3, 0x8(%rsp)
addsd %xmm3, %xmm0
movsd %xmm0, 0x60(%rsp)
xorl %ebp, %ebp
movsd 0x220a(%rip), %xmm0     # 0x5070
xorpd %xmm3, %xmm3
movsd 0x2216(%rip), %xmm1     # 0x5088
movapd %xmm1, 0x10(%rsp)
movq 0x5159(%rip), %rbx      # 0x7fd8
leaq 0x2248(%rip), %r14      # 0x50ce
ucomisd 0x21ea(%rip), %xmm0     # 0x5078
jbe 0x3015
cmpl $0x31, %ebp
ja 0x3015
movsd 0x28(%rsp), %xmm0
callq 0x2110
mulsd 0x78(%rsp), %xmm0
addsd 0x70(%rsp), %xmm0
callq 0x2220
movapd %xmm0, 0x50(%rsp)
movapd 0x10(%rsp), %xmm0
mulsd 0x80(%rsp), %xmm0
divsd 0x28(%rsp), %xmm0
movapd %xmm0, 0x40(%rsp)
callq 0x2220
movapd %xmm0, 0xb0(%rsp)
movapd 0x10(%rsp), %xmm0
addsd 0x88(%rsp), %xmm0
movapd %xmm0, 0x30(%rsp)
movsd 0x8(%rsp), %xmm1
callq 0x2200
movapd %xmm0, 0xa0(%rsp)
movaps 0x40(%rsp), %xmm0
callq 0x2220
movaps %xmm0, 0x40(%rsp)
movaps 0x30(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
callq 0x2200
movaps %xmm0, 0x90(%rsp)
movapd 0x30(%rsp), %xmm0
movsd 0x60(%rsp), %xmm1
callq 0x2200
mulsd 0x8(%rsp), %xmm0
movapd 0x90(%rsp), %xmm1
mulsd 0x68(%rsp), %xmm1
addsd %xmm0, %xmm1
movapd %xmm1, %xmm2
movapd 0xb0(%rsp), %xmm1
unpcklpd 0x40(%rsp), %xmm1       # xmm1 = xmm1[0],mem[0]
movapd 0x50(%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 0x20b4(%rip), %xmm0     # 0x5050
movapd 0x10(%rsp), %xmm2
movsd %xmm2, %xmm0            # xmm0 = xmm2[0],xmm0[1]
subpd %xmm1, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
divsd %xmm1, %xmm0
movapd %xmm2, %xmm3
subsd %xmm0, %xmm3
addsd %xmm3, %xmm2
mulsd 0x20b6(%rip), %xmm2     # 0x5080
cmpl $0x31, %ebp
jb 0x2ff2
movq %rbx, %rdi
movq %r14, %rsi
movapd %xmm3, 0x30(%rsp)
movapd %xmm2, 0x50(%rsp)
callq 0x2150
movapd 0x50(%rsp), %xmm2
movapd 0x30(%rsp), %xmm3
movapd %xmm3, %xmm0
subsd 0x10(%rsp), %xmm0
andpd 0x203c(%rip), %xmm0     # 0x5040
divsd %xmm2, %xmm0
incl %ebp
movapd %xmm3, 0x10(%rsp)
jmp 0x2e86
movapd %xmm3, %xmm0
cmpltsd 0x206e(%rip), %xmm0     # 0x5090
andnpd %xmm3, %xmm0
addq $0xc0, %rsp
popq %rbx
popq %r14
popq %rbp
retq