// File: /workspace/github_cpp_makefile_star2_O3/JorisCaze[P]NASG-EOS_Calibration/src/calib_liq-vap.cpp
// Function: computePinfL(std::vector<double, std::allocator<double>> const&, std::vector<double, std::allocator<double>> const&, std::vector<double, std::allocator<double>> const&, std::vector<double, std::allocator<double>> const&, double, double, double)
double computePinfL(vector<double> const& psatExp, vector<double> const& Texp, vector<double> const& vLexp, vector<double> const& hLexp, double p0, double ro0, double c0)
{
    // Purpose : compute pinfL parameter of liquid phase using the Newton-Raphson procedure
    // More : liquid reference state and experimental data are used
    // See eq. (68)
    double fp, dfp, dfp1, dfp2, pinf1(2.e5), pinf2(0.), err(1.);
    double mp, mT, mvL, mhL, mTp, mTp2;
    double diffC, bL, cpL, dDiffC, dbL, dcpL;
    int count(0);

    mp = meanValue(psatExp);
    mT = meanValue(Texp);
    mvL = meanValue(vLexp);
    mhL = meanValue(hLexp);

    while (err > 1.e-5 && count < 50) {
        mTp = computeMeanTp(psatExp,Texp,pinf1);
        mTp2 = computeMeanTp2(psatExp,Texp,pinf1);

        diffC = computeHeatCapDiffL(psatExp,Texp,vLexp,mvL,mTp,pinf1);
        bL = computebL(mvL,mTp,diffC);
        cpL = computeCpL(Texp,hLexp,psatExp,mhL,mp,mT,bL);
        
        dDiffC = computeDHeatCapDiffL(psatExp,Texp,vLexp,mvL,mTp,mTp2,pinf1);
        dbL = computeDbL(mTp,mTp2,diffC,dDiffC); 
        dcpL = computeDcpL(Texp,psatExp,mp,mT,dbL); 
        
        dfp1 = -ro0*dbL;
        dfp2 = (dDiffC*cpL-diffC*dcpL)/(cpL*cpL);

        fp = p0 + pinf1 - (1.-diffC/cpL)*ro0*c0*c0*(1.-bL*ro0);
        dfp = 1. - ro0*c0*c0*dfp1 + dfp2*ro0*c0*c0*(1.-bL*ro0) + (diffC/cpL)*ro0*c0*c0*dfp1;

        pinf2 = pinf1 - fp/dfp;
        err = fabs(pinf2-pinf1)/(0.5*(pinf1+pinf2));
        pinf1 = pinf2;
        count++;
        if (count >= 50) {
            cout << "Warning : newton-raphson of Psat(T) function not converged\n"; exit(0);
        }
    }
    // cout << "Number of iteration NR pinfL : " << count << endl;
    return pinf1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x158, %rsp            # imm = 0x158
movaps %xmm2, 0xb0(%rsp)
movapd %xmm1, 0xa0(%rsp)
movsd %xmm0, 0x70(%rsp)
movq %rcx, %rbx
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %r12
callq 0x5284
movaps %xmm0, 0x90(%rsp)
movq %r14, %rdi
callq 0x5284
movaps %xmm0, 0x80(%rsp)
movq %r15, %rdi
callq 0x5284
movaps %xmm0, 0x20(%rsp)
movq %rbx, 0x68(%rsp)
movq %rbx, %rdi
callq 0x5284
movsd %xmm0, 0x48(%rsp)
movq (%r14), %r13
movq %r14, 0x58(%rsp)
movq 0x8(%r14), %rdx
movq %rdx, %rbp
subq %r13, %rbp
sarq $0x3, %rbp
movapd 0x32d8(%rip), %xmm0     # 0x6050
movapd 0xa0(%rsp), %xmm3
xorpd %xmm3, %xmm0
movapd %xmm0, 0x120(%rsp)
movapd 0xb0(%rsp), %xmm2
mulsd %xmm2, %xmm0
mulsd %xmm2, %xmm0
movapd %xmm0, 0x110(%rsp)
movq %r12, 0x50(%rsp)
movq (%r12), %r14
xorps %xmm0, %xmm0
cvtsi2sd %rbp, %xmm0
movq %r15, 0x60(%rsp)
movq (%r15), %r12
xorpd %xmm1, %xmm1
movsd %xmm0, 0x8(%rsp)
divsd %xmm0, %xmm1
movsd %xmm1, 0x38(%rsp)
movapd %xmm3, %xmm0
unpcklpd %xmm3, %xmm0            # xmm0 = xmm0[0],xmm3[0]
movapd %xmm0, 0x100(%rsp)
movapd %xmm2, %xmm0
unpcklpd %xmm2, %xmm0            # xmm0 = xmm0[0],xmm2[0]
movapd %xmm0, 0xf0(%rsp)
movapd 0x80(%rsp), %xmm5
unpcklpd 0x90(%rsp), %xmm5       # xmm5 = xmm5[0],mem[0]
xorl %eax, %eax
movsd 0x3205(%rip), %xmm4     # 0x6018
movsd 0x3205(%rip), %xmm0     # 0x6020
movsd 0x31e5(%rip), %xmm6     # 0x6008
movq %rdx, 0x40(%rsp)
movapd %xmm5, 0xe0(%rsp)
movq 0x58(%rsp), %rbx
movq 0x50(%rsp), %r15
ucomisd 0x31e5(%rip), %xmm0     # 0x6028
jbe 0x317e
movq %rax, 0x10(%rsp)
movsd 0x38(%rsp), %xmm0
movapd %xmm0, %xmm5
movapd %xmm0, %xmm7
cmpq %r13, %rdx
je 0x2f1c
xorpd %xmm7, %xmm7
xorl %eax, %eax
movsd (%r13,%rax,8), %xmm0
movsd (%r14,%rax,8), %xmm1
addsd %xmm4, %xmm1
divsd %xmm1, %xmm0
addsd %xmm0, %xmm7
incq %rax
movl %eax, %ecx
cmpq %rcx, %rbp
ja 0x2e6b
divsd 0x8(%rsp), %xmm7
xorpd %xmm5, %xmm5
xorl %eax, %eax
movsd (%r13,%rax,8), %xmm0
movsd (%r14,%rax,8), %xmm1
addsd %xmm4, %xmm1
mulsd %xmm1, %xmm1
divsd %xmm1, %xmm0
addsd %xmm0, %xmm5
incq %rax
movl %eax, %ecx
cmpq %rcx, %rbp
ja 0x2e9a
divsd 0x8(%rsp), %xmm5
movapd %xmm7, %xmm1
unpcklpd 0x20(%rsp), %xmm1       # xmm1 = xmm1[0],mem[0]
xorpd %xmm0, %xmm0
xorl %eax, %eax
movsd (%r13,%rax,8), %xmm2
movsd (%r14,%rax,8), %xmm3
addsd %xmm4, %xmm3
divsd %xmm3, %xmm2
movapd %xmm2, %xmm3
movhpd (%r12,%rax,8), %xmm3    # xmm3 = xmm3[0],mem[0]
subpd %xmm1, %xmm3
unpcklpd %xmm2, %xmm2            # xmm2 = xmm2[0,0]
mulpd %xmm3, %xmm2
addpd %xmm2, %xmm0
incq %rax
movl %eax, %ecx
cmpq %rcx, %rbp
ja 0x2ed7
movapd %xmm0, %xmm6
unpckhpd %xmm0, %xmm6            # xmm6 = xmm6[1],xmm0[1]
divsd %xmm0, %xmm6
movapd %xmm7, 0xc0(%rsp)
movapd %xmm6, 0x140(%rsp)
movapd %xmm5, 0xd0(%rsp)
movapd %xmm6, %xmm0
mulsd %xmm7, %xmm0
movapd 0x20(%rsp), %xmm3
subsd %xmm0, %xmm3
movq %rbx, %rdi
movq 0x68(%rsp), %rsi
movq %r15, %rdx
movsd 0x48(%rsp), %xmm0
movaps 0x90(%rsp), %xmm1
movaps 0x80(%rsp), %xmm2
movapd %xmm3, 0x130(%rsp)
movsd %xmm4, 0x18(%rsp)
callq 0x2beb
movsd %xmm0, 0x78(%rsp)
movq %r15, %rdi
movq %rbx, %rsi
movq 0x60(%rsp), %rdx
movapd 0x20(%rsp), %xmm0
movaps 0xc0(%rsp), %xmm1
movaps 0xd0(%rsp), %xmm2
movsd 0x18(%rsp), %xmm3
callq 0x2aac
movapd 0x140(%rsp), %xmm10
movapd 0xd0(%rsp), %xmm9
movapd %xmm10, %xmm1
movapd 0x307e(%rip), %xmm8     # 0x6050
xorpd %xmm8, %xmm1
mulsd %xmm10, %xmm9
movapd 0xc0(%rsp), %xmm2
mulsd %xmm0, %xmm2
subsd %xmm2, %xmm9
movsd 0x3012(%rip), %xmm6     # 0x6008
movapd %xmm6, %xmm3
movq 0x40(%rsp), %rdx
cmpq %r13, %rdx
movapd 0xe0(%rsp), %xmm5
movq 0x10(%rsp), %rax
je 0x3054
xorpd %xmm2, %xmm2
xorl %eax, %eax
movsd (%r13,%rax,8), %xmm3
movapd %xmm3, %xmm4
movhpd (%r14,%rax,8), %xmm4    # xmm4 = xmm4[0],mem[0]
subpd %xmm5, %xmm4
unpcklpd %xmm3, %xmm3            # xmm3 = xmm3[0,0]
mulpd %xmm4, %xmm3
addpd %xmm3, %xmm2
incq %rax
movl %eax, %ecx
cmpq %rcx, %rbp
ja 0x3018
movapd %xmm2, %xmm3
unpckhpd %xmm2, %xmm3            # xmm3 = xmm3[1],xmm2[1]
divsd %xmm2, %xmm3
movq 0x10(%rsp), %rax
mulsd %xmm9, %xmm3
mulsd %xmm1, %xmm3
movsd 0x78(%rsp), %xmm1
mulsd %xmm1, %xmm0
subsd %xmm3, %xmm0
mulsd 0x120(%rsp), %xmm9
divsd %xmm1, %xmm10
mulsd %xmm1, %xmm1
divsd %xmm1, %xmm0
movapd 0xa0(%rsp), %xmm3
movapd 0x130(%rsp), %xmm2
mulsd %xmm3, %xmm2
movsd 0x2f80(%rip), %xmm4     # 0x6020
movapd %xmm4, %xmm1
subsd %xmm2, %xmm1
movapd 0x110(%rsp), %xmm2
mulsd %xmm9, %xmm2
addsd %xmm4, %xmm2
mulsd %xmm3, %xmm0
movapd 0xb0(%rsp), %xmm3
mulsd %xmm3, %xmm0
mulsd %xmm3, %xmm0
mulsd %xmm1, %xmm0
addsd %xmm2, %xmm0
movsd 0x18(%rsp), %xmm7
movapd %xmm7, %xmm2
addsd 0x70(%rsp), %xmm2
unpcklpd %xmm0, %xmm2            # xmm2 = xmm2[0],xmm0[0]
movapd %xmm4, %xmm0
subsd %xmm10, %xmm0
xorpd %xmm8, %xmm0
unpcklpd %xmm10, %xmm0           # xmm0 = xmm0[0],xmm10[0]
unpcklpd %xmm9, %xmm1            # xmm1 = xmm1[0],xmm9[0]
mulpd 0x100(%rsp), %xmm0
movapd 0xf0(%rsp), %xmm3
mulpd %xmm3, %xmm0
mulpd %xmm3, %xmm0
mulpd %xmm0, %xmm1
addpd %xmm2, %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
divsd %xmm0, %xmm1
movapd %xmm7, %xmm4
subsd %xmm1, %xmm4
movapd %xmm4, %xmm0
subsd %xmm7, %xmm0
andpd 0x2f37(%rip), %xmm0     # 0x6080
addsd %xmm4, %xmm7
mulsd 0x2edb(%rip), %xmm7     # 0x6030
divsd %xmm7, %xmm0
incl %eax
cmpl $0x32, %eax
jne 0x2e3b
movq 0x5e6d(%rip), %rdi      # 0x8fd8
leaq 0x2f64(%rip), %rsi      # 0x60d6
callq 0x2140
xorl %edi, %edi
callq 0x2190
movapd %xmm4, %xmm0
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq