// File: JorisCaze[P]NASG-EOS_Calibration/src/calib_liq-vap.cpp
// Function: computeQprimG(std::vector<double, std::allocator<double>>, std::vector<double, std::allocator<double>>, double, double, double, double, double, double, double, double)
double computeQprimG(vector<double> p, vector<double> T, double cpL, double cpG, double cvL, double cvG, double qL, double qG, double pinfL, double bL)
{
    // Purpose : compute the vapor entropy constant qPrimG with LSM
    // See equation (72) 
    double A,B,C,D,E,sum(0.);
    B = (qL-qG)/(cpG-cvG);
    C = (cpG-cpL)/(cpG-cvG);
    D = (cpL-cvL)/(cpG-cvG);
    E = bL/(cpG-cvG);
    for (unsigned int i = 0; i < p.size(); i++) {
        sum += log(p[i])-(B+E*p[i])/T[i] - C*log(T[i]) - D*log(p[i]+pinfL);
    }
    A = sum/p.size();
    return (A*(cpG-cvG)+cpG-cpL);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x98(%rbp)
movq %rsi, -0x90(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movsd %xmm0, -0x18(%rbp)
movsd %xmm1, -0x20(%rbp)
movsd %xmm2, -0x28(%rbp)
movsd %xmm3, -0x30(%rbp)
movsd %xmm4, -0x38(%rbp)
movsd %xmm5, -0x40(%rbp)
movsd %xmm6, -0x48(%rbp)
movsd %xmm7, -0x50(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x80(%rbp)
movsd -0x38(%rbp), %xmm0
subsd -0x40(%rbp), %xmm0
movsd -0x20(%rbp), %xmm1
subsd -0x30(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x60(%rbp)
movsd -0x20(%rbp), %xmm0
subsd -0x18(%rbp), %xmm0
movsd -0x20(%rbp), %xmm1
subsd -0x30(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0x18(%rbp), %xmm0
subsd -0x28(%rbp), %xmm0
movsd -0x20(%rbp), %xmm1
subsd -0x30(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x70(%rbp)
movsd -0x50(%rbp), %xmm0
movsd -0x20(%rbp), %xmm1
subsd -0x30(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x78(%rbp)
movl $0x0, -0x84(%rbp)
movq -0x98(%rbp), %rdi
movl -0x84(%rbp), %eax
movq %rax, -0xa0(%rbp)
callq 0x40f0
movq %rax, %rcx
movq -0xa0(%rbp), %rax
cmpq %rcx, %rax
jae 0x2ca4
movq -0x98(%rbp), %rdi
movl -0x84(%rbp), %eax
movl %eax, %esi
callq 0x4130
movsd (%rax), %xmm0
callq 0x2130
movq -0x98(%rbp), %rdi
movsd %xmm0, -0xc8(%rbp)
movsd -0x60(%rbp), %xmm0
movsd %xmm0, -0xd8(%rbp)
movsd -0x78(%rbp), %xmm0
movsd %xmm0, -0xe0(%rbp)
movl -0x84(%rbp), %eax
movl %eax, %esi
callq 0x4130
movsd -0xe0(%rbp), %xmm0
movsd -0xd8(%rbp), %xmm1
movq -0x90(%rbp), %rdi
movsd (%rax), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xd0(%rbp)
movl -0x84(%rbp), %eax
movl %eax, %esi
callq 0x4130
movsd -0xd0(%rbp), %xmm1
movsd -0xc8(%rbp), %xmm0
movq -0x90(%rbp), %rdi
divsd (%rax), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, -0xc0(%rbp)
movsd -0x68(%rbp), %xmm0
movsd %xmm0, -0xb8(%rbp)
movl -0x84(%rbp), %eax
movl %eax, %esi
callq 0x4130
movsd (%rax), %xmm0
callq 0x2130
movsd -0xc0(%rbp), %xmm1
movq -0x98(%rbp), %rdi
movaps %xmm0, %xmm2
movsd -0xb8(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xb0(%rbp)
movsd -0x70(%rbp), %xmm0
movsd %xmm0, -0xa8(%rbp)
movl -0x84(%rbp), %eax
movl %eax, %esi
callq 0x4130
movsd (%rax), %xmm0
addsd -0x48(%rbp), %xmm0
callq 0x2130
movsd -0xb0(%rbp), %xmm1
movaps %xmm0, %xmm2
movsd -0xa8(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
addsd -0x80(%rbp), %xmm0
movsd %xmm0, -0x80(%rbp)
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0x2aea
movq -0x98(%rbp), %rdi
movsd -0x80(%rbp), %xmm0
movsd %xmm0, -0xe8(%rbp)
callq 0x40f0
movsd -0xe8(%rbp), %xmm0
movq %rax, %xmm1
movaps 0x533f(%rip), %xmm2     # 0x8010
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x5343(%rip), %xmm2     # 0x8020
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x58(%rbp), %xmm0
movsd -0x20(%rbp), %xmm2
subsd -0x30(%rbp), %xmm2
movsd -0x20(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
subsd -0x18(%rbp), %xmm0
addq $0xf0, %rsp
popq %rbp
retq
nop