// File: /workspace/github_c_makefile_star2_O2/kilobyte[P]colormatch/color_distance.c
// Function: rgb2lab
void rgb2lab(int rgb, double lab[3])
{
    double r = ((rgb>>16)&0xff)/255.0;
    double g = ((rgb>> 8)&0xff)/255.0;
    double b = ((rgb    )&0xff)/255.0;
    double x,y,z;

    r = (r > 0.04045) ? pow((r + 0.055) / 1.055, 2.4) : r / 12.92;
    g = (g > 0.04045) ? pow((g + 0.055) / 1.055, 2.4) : g / 12.92;
    b = (b > 0.04045) ? pow((b + 0.055) / 1.055, 2.4) : b / 12.92;

    // at D65
    x = (r * 0.4124 + g * 0.3576 + b * 0.1805) / 0.95047;
    y = (r * 0.2126 + g * 0.7152 + b * 0.0722) / 1.00000;
    z = (r * 0.0193 + g * 0.1192 + b * 0.9505) / 1.08883;

    x = (x > 0.008856) ? pow(x, 1.0/3) : (7.787 * x) + 16.0/116;
    y = (y > 0.008856) ? pow(y, 1.0/3) : (7.787 * y) + 16.0/116;
    z = (z > 0.008856) ? pow(z, 1.0/3) : (7.787 * z) + 16.0/116;

    lab[0] = 116 * y - 16;
    lab[1] = 500 * (x - y);
    lab[2] = 200 * (y - z);
}

// Assembly:
pushq %rbx
subq $0x30, %rsp
movq %rsi, %rbx
movl %edi, %eax
shrl $0x10, %eax
movl $0xff, %ecx
andl %ecx, %eax
cvtsi2sd %eax, %xmm0
movsd 0x7ca(%rip), %xmm1      # 0x2180
movl %edi, %eax
shrl $0x8, %eax
andl %ecx, %eax
cvtsi2sd %eax, %xmm4
divsd %xmm1, %xmm0
andl %ecx, %edi
cvtsi2sd %edi, %xmm2
divsd %xmm1, %xmm4
ucomisd 0x7b1(%rip), %xmm0      # 0x2188
jbe 0x1a16
addsd 0x7b7(%rip), %xmm0      # 0x2198
divsd 0x7b7(%rip), %xmm0      # 0x21a0
movsd 0x7b7(%rip), %xmm1      # 0x21a8
movapd %xmm2, 0x10(%rsp)
movsd %xmm4, (%rsp)
callq 0x1040
movsd 0x777(%rip), %xmm1      # 0x2180
movsd (%rsp), %xmm4
movapd 0x10(%rsp), %xmm2
jmp 0x1a1e
divsd 0x772(%rip), %xmm0      # 0x2190
divsd %xmm1, %xmm2
ucomisd 0x75e(%rip), %xmm4      # 0x2188
movsd %xmm0, 0x20(%rsp)
jbe 0x1a65
addsd 0x75e(%rip), %xmm4      # 0x2198
divsd 0x75e(%rip), %xmm4      # 0x21a0
movsd 0x75e(%rip), %xmm1      # 0x21a8
movapd %xmm4, %xmm0
movapd %xmm2, 0x10(%rsp)
callq 0x1040
movapd 0x10(%rsp), %xmm2
movapd %xmm0, %xmm4
jmp 0x1a6d
divsd 0x723(%rip), %xmm4      # 0x2190
ucomisd 0x713(%rip), %xmm2      # 0x2188
jbe 0x1aa8
addsd 0x719(%rip), %xmm2      # 0x2198
divsd 0x719(%rip), %xmm2      # 0x21a0
movsd 0x719(%rip), %xmm1      # 0x21a8
movapd %xmm2, %xmm0
movsd %xmm4, (%rsp)
callq 0x1040
movsd (%rsp), %xmm4
movapd %xmm0, %xmm2
jmp 0x1ab0
divsd 0x6e0(%rip), %xmm2      # 0x2190
movsd 0x6f8(%rip), %xmm0      # 0x21b0
mulsd %xmm4, %xmm0
movsd 0x6f4(%rip), %xmm1      # 0x21b8
movsd 0x20(%rsp), %xmm3
mulsd %xmm3, %xmm1
addsd %xmm0, %xmm1
movsd 0x6e6(%rip), %xmm0      # 0x21c0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
divsd 0x6de(%rip), %xmm0      # 0x21c8
movsd 0x6de(%rip), %xmm5      # 0x21d0
mulsd %xmm4, %xmm5
movsd 0x6da(%rip), %xmm1      # 0x21d8
mulsd %xmm3, %xmm1
addsd %xmm5, %xmm1
movsd 0x6d2(%rip), %xmm5      # 0x21e0
mulsd %xmm2, %xmm5
mulsd 0x6ce(%rip), %xmm4      # 0x21e8
mulsd 0x6ce(%rip), %xmm3      # 0x21f0
addsd %xmm1, %xmm5
addsd %xmm4, %xmm3
mulsd 0x6c6(%rip), %xmm2      # 0x21f8
addsd %xmm3, %xmm2
ucomisd 0x6ca(%rip), %xmm0      # 0x2208
jbe 0x1b65
movsd 0x6d8(%rip), %xmm1      # 0x2220
movapd %xmm2, 0x10(%rsp)
movapd %xmm5, (%rsp)
callq 0x1040
movapd (%rsp), %xmm5
movapd 0x10(%rsp), %xmm2
jmp 0x1b75
mulsd 0x6a3(%rip), %xmm0      # 0x2210
addsd 0x6a3(%rip), %xmm0      # 0x2218
divsd 0x683(%rip), %xmm2      # 0x2200
ucomisd 0x683(%rip), %xmm5      # 0x2208
movapd %xmm0, 0x20(%rsp)
jbe 0x1bb0
movsd 0x68b(%rip), %xmm1      # 0x2220
movapd %xmm5, %xmm0
movapd %xmm2, 0x10(%rsp)
callq 0x1040
movapd 0x10(%rsp), %xmm2
movapd %xmm0, %xmm5
jmp 0x1bc0
mulsd 0x658(%rip), %xmm5      # 0x2210
addsd 0x658(%rip), %xmm5      # 0x2218
ucomisd 0x640(%rip), %xmm2      # 0x2208
jbe 0x1beb
movsd 0x64e(%rip), %xmm1      # 0x2220
movapd %xmm2, %xmm0
movapd %xmm5, (%rsp)
callq 0x1040
movapd (%rsp), %xmm5
movapd %xmm0, %xmm2
jmp 0x1bfb
mulsd 0x61d(%rip), %xmm2      # 0x2210
addsd 0x61d(%rip), %xmm2      # 0x2218
movapd 0x20(%rsp), %xmm1
movsd 0x61f(%rip), %xmm0      # 0x2228
mulsd %xmm5, %xmm0
addsd 0x61b(%rip), %xmm0      # 0x2230
movsd %xmm0, (%rbx)
unpcklpd %xmm5, %xmm1            # xmm1 = xmm1[0],xmm5[0]
unpcklpd %xmm2, %xmm5            # xmm5 = xmm5[0],xmm2[0]
subpd %xmm5, %xmm1
mulpd 0x633(%rip), %xmm1      # 0x2260
movupd %xmm1, 0x8(%rbx)
addq $0x30, %rsp
popq %rbx
retq