// File: /workspace/github_c_makefile_star2_O1/kilobyte[P]colormatch/color_distance.c
// Function: deltaE2000
double deltaE2000(double *lab1, double *lab2)
{
    double Lstd = *lab1;
    double astd = *(lab1+1);
    double bstd = *(lab1+2);

    double Lsample = *lab2;
    double asample = *(lab2+1);
    double bsample = *(lab2+2);

    double Cabstd= sqrt(astd*astd+bstd*bstd);
    double Cabsample= sqrt(asample*asample+bsample*bsample);

    double Cabarithmean= (Cabstd + Cabsample)/2.0;

    double G= 0.5*( 1.0 - sqrt( pow(Cabarithmean,7.0)/(pow(Cabarithmean,7.0) + pow(25.0,7.0))));

    double apstd= (1.0+G)*astd; // aprime in paper
    double apsample= (1.0+G)*asample; // aprime in paper
    double Cpsample= sqrt(apsample*apsample+bsample*bsample);

    double Cpstd= sqrt(apstd*apstd+bstd*bstd);
    // Compute product of chromas
    double Cpprod= (Cpsample*Cpstd);


    // Ensure hue is between 0 and 2pi
    double hpstd= atan2(bstd,apstd);
    if (hpstd<0) hpstd+= 2.0*pi;  // rollover ones that come -ve

    double hpsample= atan2(bsample,apsample);
    if (hpsample<0) hpsample+= 2.0*pi;
    if ( (fabs(apsample)+fabs(bsample))==0.0)  hpsample= 0.0;

    double dL= (Lsample-Lstd);
    double dC= (Cpsample-Cpstd);

    // Computation of hue difference
    double dhp= (hpsample-hpstd);
    if (dhp>pi)  dhp-= 2.0*pi;
    if (dhp<-pi) dhp+= 2.0*pi;
    // set chroma difference to zero if the product of chromas is zero
    if (Cpprod == 0.0) dhp= 0.0;

    // Note that the defining equations actually need
    // signed Hue and chroma differences which is different
    // from prior color difference formulae

    double dH= 2.0*sqrt(Cpprod)*sin(dhp/2.0);
    //%dH2 = 4*Cpprod.*(sin(dhp/2)).^2;

    // weighting functions
    double Lp= (Lsample+Lstd)/2.0;
    double Cp= (Cpstd+Cpsample)/2.0;

    // Average Hue Computation
    // This is equivalent to that in the paper but simpler programmatically.
    // Note average hue is computed in radians and converted to degrees only
    // where needed
    double hp= (hpstd+hpsample)/2.0;
    // Identify positions for which abs hue diff exceeds 180 degrees
    if ( fabs(hpstd-hpsample)  > pi ) hp-= pi;
    // rollover ones that come -ve
    if (hp<0) hp+= 2.0*pi;

    // Check if one of the chroma values is zero, in which case set
    // mean hue to the sum which is equivalent to other value
    if (Cpprod==0.0) hp= hpsample+hpstd;

    double Lpm502= (Lp-50.0)*(Lp-50.0);;
    double Sl= 1.0+0.015*Lpm502/sqrt(20.0+Lpm502);
    double Sc= 1.0+0.045*Cp;
    double T= 1.0 - 0.17*cos(hp - pi/6.0) + 0.24*cos(2.0*hp) + 0.32*cos(3.0*hp+pi/30.0) - 0.20*cos(4.0*hp-63.0*pi/180.0);
    double Sh= 1.0 + 0.015*Cp*T;
    double delthetarad= (30.0*pi/180.0)*exp(- pow(( (180.0/pi*hp-275.0)/25.0),2.0));
    double Rc=  2.0*sqrt(pow(Cp,7.0)/(pow(Cp,7.0) + pow(25.0,7.0)));
    double RT= -sin(2.0*delthetarad)*Rc;

    // The CIE 00 color difference
    return sqrt( pow((dL/Sl),2.0) + pow((dC/Sc),2.0) + pow((dH/Sh),2.0) + RT*(dC/Sc)*(dH/Sh) );
}

// Assembly:
subq $0x78, %rsp
movsd (%rdi), %xmm0
movsd %xmm0, 0x60(%rsp)
movsd 0x8(%rdi), %xmm1
movsd 0x10(%rdi), %xmm2
movsd (%rsi), %xmm0
movsd %xmm0, 0x68(%rsp)
movsd 0x8(%rsi), %xmm0
movaps %xmm0, 0x20(%rsp)
movsd 0x10(%rsi), %xmm0
movaps %xmm0, 0x30(%rsp)
movsd %xmm2, 0x58(%rsp)
mulsd %xmm2, %xmm2
movapd %xmm1, %xmm0
mulsd %xmm1, %xmm0
movsd %xmm2, 0x8(%rsp)
addsd %xmm2, %xmm0
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm0
movsd %xmm1, 0x10(%rsp)
jb 0x1448
sqrtsd %xmm0, %xmm0
jmp 0x1451
callq 0x10f0
xorpd %xmm2, %xmm2
movsd %xmm0, (%rsp)
movapd 0x30(%rsp), %xmm1
mulsd %xmm1, %xmm1
movapd 0x20(%rsp), %xmm0
mulsd %xmm0, %xmm0
movapd %xmm1, 0x40(%rsp)
addsd %xmm1, %xmm0
ucomisd %xmm2, %xmm0
jb 0x1480
sqrtsd %xmm0, %xmm0
jmp 0x1485
callq 0x10f0
movsd (%rsp), %xmm2
addsd %xmm0, %xmm2
mulsd 0xc1a(%rip), %xmm2      # 0x20b0
movsd %xmm2, (%rsp)
movsd 0xc15(%rip), %xmm1      # 0x20b8
movapd %xmm2, %xmm0
callq 0x1040
movsd %xmm0, 0x70(%rsp)
movsd (%rsp), %xmm0
movsd 0xbf9(%rip), %xmm1      # 0x20b8
callq 0x1040
addsd 0xbf4(%rip), %xmm0      # 0x20c0
movsd 0x70(%rsp), %xmm1
divsd %xmm0, %xmm1
movapd %xmm1, %xmm0
xorpd %xmm4, %xmm4
ucomisd %xmm4, %xmm1
jb 0x14ea
sqrtsd %xmm0, %xmm0
jmp 0x14f3
callq 0x10f0
xorpd %xmm4, %xmm4
movsd 0xbcd(%rip), %xmm2      # 0x20c8
movapd %xmm2, %xmm3
subsd %xmm0, %xmm3
mulsd 0xba5(%rip), %xmm3      # 0x20b0
addsd %xmm2, %xmm3
movsd 0x10(%rsp), %xmm1
mulsd %xmm3, %xmm1
movapd 0x20(%rsp), %xmm0
mulsd %xmm3, %xmm0
movapd %xmm0, 0x20(%rsp)
mulsd %xmm0, %xmm0
addsd 0x40(%rsp), %xmm0
ucomisd %xmm4, %xmm0
movsd %xmm1, 0x10(%rsp)
jb 0x1545
sqrtsd %xmm0, %xmm0
jmp 0x1550
callq 0x10f0
movsd 0x10(%rsp), %xmm1
movsd %xmm0, (%rsp)
movapd %xmm1, %xmm0
mulsd %xmm1, %xmm0
addsd 0x8(%rsp), %xmm0
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm0
jb 0x1573
sqrtsd %xmm0, %xmm0
jmp 0x157e
callq 0x10f0
movsd 0x10(%rsp), %xmm1
movsd (%rsp), %xmm2
movsd %xmm0, 0x40(%rsp)
mulsd %xmm0, %xmm2
movsd %xmm2, 0x8(%rsp)
movsd 0x58(%rsp), %xmm0
callq 0x1090
movsd 0xb2a(%rip), %xmm2      # 0x20d0
movapd %xmm0, %xmm1
addsd %xmm2, %xmm1
movapd %xmm0, %xmm3
xorpd %xmm2, %xmm2
cmpltsd %xmm2, %xmm3
andpd %xmm3, %xmm1
andnpd %xmm0, %xmm3
orpd %xmm1, %xmm3
movapd %xmm3, 0x10(%rsp)
movapd 0x30(%rsp), %xmm0
movaps 0x20(%rsp), %xmm1
callq 0x1090
movapd %xmm0, %xmm1
movsd 0xae7(%rip), %xmm4      # 0x20d0
addsd %xmm4, %xmm1
movapd %xmm0, %xmm2
xorpd %xmm3, %xmm3
cmpltsd %xmm3, %xmm2
andpd %xmm2, %xmm1
andnpd %xmm0, %xmm2
orpd %xmm1, %xmm2
movapd 0xc42(%rip), %xmm0      # 0x2250
movapd 0x20(%rsp), %xmm5
andpd %xmm0, %xmm5
movapd 0x30(%rsp), %xmm1
andpd %xmm0, %xmm1
addsd %xmm5, %xmm1
cmpeqsd %xmm3, %xmm1
andnpd %xmm2, %xmm1
movapd %xmm1, 0x30(%rsp)
movapd %xmm1, %xmm0
subsd 0x10(%rsp), %xmm0
movsd 0xa91(%rip), %xmm1      # 0x20d8
addsd %xmm0, %xmm1
movsd 0xa8d(%rip), %xmm5      # 0x20e0
movapd %xmm5, %xmm2
cmpltsd %xmm0, %xmm2
andpd %xmm2, %xmm1
andnpd %xmm0, %xmm2
orpd %xmm1, %xmm2
movsd 0x8(%rsp), %xmm1
movapd %xmm4, %xmm0
addsd %xmm2, %xmm0
movapd %xmm2, %xmm4
cmpltsd 0xa65(%rip), %xmm4      # 0x20e8
andpd %xmm4, %xmm0
andnpd %xmm2, %xmm4
orpd %xmm0, %xmm4
ucomisd %xmm3, %xmm1
jb 0x169e
xorps %xmm0, %xmm0
sqrtsd %xmm1, %xmm0
jmp 0x16c1
movapd %xmm1, %xmm0
movapd %xmm4, 0x20(%rsp)
callq 0x10f0
movsd 0xa2b(%rip), %xmm5      # 0x20e0
movapd 0x20(%rsp), %xmm4
movsd 0x8(%rsp), %xmm1
mulsd 0x9e7(%rip), %xmm4      # 0x20b0
xorpd %xmm6, %xmm6
ucomisd %xmm6, %xmm1
movsd %xmm0, 0x20(%rsp)
jne 0x16df
jp 0x16df
xorpd %xmm4, %xmm4
movapd 0x10(%rsp), %xmm3
movapd %xmm3, %xmm0
movapd 0x30(%rsp), %xmm2
addsd %xmm2, %xmm0
movapd %xmm0, %xmm1
mulsd 0x9b1(%rip), %xmm1      # 0x20b0
subsd %xmm2, %xmm3
andpd 0xb45(%rip), %xmm3      # 0x2250
movsd 0x9d5(%rip), %xmm2      # 0x20e8
addsd %xmm1, %xmm2
cmpltsd %xmm3, %xmm5
andpd %xmm5, %xmm2
andnpd %xmm1, %xmm5
orpd %xmm2, %xmm5
movsd 0x9a0(%rip), %xmm1      # 0x20d0
addsd %xmm5, %xmm1
movapd %xmm5, %xmm2
cmpltsd %xmm6, %xmm2
andpd %xmm2, %xmm1
andnpd %xmm5, %xmm2
orpd %xmm1, %xmm2
jne 0x1751
jp 0x1751
movapd %xmm0, %xmm2
movapd %xmm2, 0x30(%rsp)
movapd %xmm4, %xmm0
callq 0x10c0
movapd %xmm0, %xmm4
movsd (%rsp), %xmm0
movsd 0x40(%rsp), %xmm2
addsd %xmm2, %xmm0
movsd 0x935(%rip), %xmm1      # 0x20b0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0x60(%rsp), %xmm0
addsd 0x68(%rsp), %xmm0
mulsd %xmm1, %xmm0
addsd 0x953(%rip), %xmm0      # 0x20f0
movsd 0x20(%rsp), %xmm1
addsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
movsd 0x945(%rip), %xmm3      # 0x20f8
mulsd %xmm0, %xmm3
addsd 0x941(%rip), %xmm0      # 0x2100
ucomisd 0x9b1(%rip), %xmm0      # 0x2178
jb 0x17cf
sqrtsd %xmm0, %xmm0
jmp 0x17fe
movsd %xmm1, 0x20(%rsp)
movsd %xmm3, 0x8(%rsp)
movsd %xmm4, 0x58(%rsp)
callq 0x10f0
movsd 0x58(%rsp), %xmm4
movsd 0x8(%rsp), %xmm3
movsd 0x40(%rsp), %xmm2
movsd 0x20(%rsp), %xmm1
divsd %xmm0, %xmm3
mulsd %xmm4, %xmm1
movsd %xmm1, 0x20(%rsp)
movsd (%rsp), %xmm0
subsd %xmm2, %xmm0
movsd %xmm0, (%rsp)
movsd 0x68(%rsp), %xmm0
subsd 0x60(%rsp), %xmm0
movsd %xmm0, 0x68(%rsp)
movsd 0x894(%rip), %xmm1      # 0x20c8
addsd %xmm1, %xmm3
movsd %xmm3, 0x8(%rsp)
movsd 0x8c2(%rip), %xmm0      # 0x2108
mulsd 0x10(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x60(%rsp)
movsd 0x8b2(%rip), %xmm0      # 0x2110
addsd 0x30(%rsp), %xmm0
callq 0x1070
mulsd 0x8a7(%rip), %xmm0      # 0x2118
addsd 0x84f(%rip), %xmm0      # 0x20c8
movsd %xmm0, 0x40(%rsp)
movapd 0x30(%rsp), %xmm0
addsd %xmm0, %xmm0
callq 0x1070
mulsd 0x88a(%rip), %xmm0      # 0x2120
addsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
movsd 0x87e(%rip), %xmm0      # 0x2128
mulsd 0x30(%rsp), %xmm0
addsd 0x878(%rip), %xmm0      # 0x2130
callq 0x1070
mulsd 0x873(%rip), %xmm0      # 0x2138
addsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
movsd 0x867(%rip), %xmm0      # 0x2140
mulsd 0x30(%rsp), %xmm0
addsd 0x861(%rip), %xmm0      # 0x2148
callq 0x1070
mulsd 0x85c(%rip), %xmm0      # 0x2150
addsd 0x40(%rsp), %xmm0
movsd 0x7f6(%rip), %xmm1      # 0x20f8
mulsd 0x10(%rsp), %xmm1
mulsd %xmm0, %xmm1
movapd 0x30(%rsp), %xmm2
mulsd 0x83e(%rip), %xmm2      # 0x2158
addsd 0x83e(%rip), %xmm2      # 0x2160
divsd 0x83e(%rip), %xmm2      # 0x2168
addsd 0x796(%rip), %xmm1      # 0x20c8
movsd %xmm1, 0x30(%rsp)
movapd 0x920(%rip), %xmm0      # 0x2260
xorpd %xmm2, %xmm0
mulsd %xmm2, %xmm0
callq 0x1100
mulsd 0x81b(%rip), %xmm0      # 0x2170
movsd %xmm0, 0x40(%rsp)
movsd 0x755(%rip), %xmm1      # 0x20b8
movsd 0x10(%rsp), %xmm0
callq 0x1040
movsd %xmm0, 0x58(%rsp)
movsd 0x10(%rsp), %xmm0
movsd 0x736(%rip), %xmm1      # 0x20b8
callq 0x1040
addsd 0x731(%rip), %xmm0      # 0x20c0
movsd 0x58(%rsp), %xmm1
divsd %xmm0, %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
movapd %xmm1, %xmm0
jb 0x19ad
sqrtsd %xmm0, %xmm0
jmp 0x19b2
callq 0x10f0
addsd %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0x40(%rsp), %xmm0
addsd %xmm0, %xmm0
callq 0x10c0
movapd %xmm0, %xmm1
mulsd 0x10(%rsp), %xmm1
movsd 0x68(%rsp), %xmm0
divsd 0x8(%rsp), %xmm0
mulsd %xmm0, %xmm0
movsd (%rsp), %xmm3
divsd 0x60(%rsp), %xmm3
movapd %xmm3, %xmm2
mulsd %xmm3, %xmm2
addsd %xmm0, %xmm2
movsd 0x20(%rsp), %xmm4
divsd 0x30(%rsp), %xmm4
movapd %xmm4, %xmm0
mulsd %xmm4, %xmm0
addsd %xmm2, %xmm0
mulsd %xmm1, %xmm3
mulsd %xmm4, %xmm3
subsd %xmm3, %xmm0
ucomisd 0x750(%rip), %xmm0      # 0x2178
jb 0x1a33
sqrtsd %xmm0, %xmm0
addq $0x78, %rsp
retq
addq $0x78, %rsp
jmp 0x10f0