// File: /workspace/github_c_makefile_star2_O3/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 0x7af(%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 0x796(%rip), %xmm0      # 0x2188
jbe 0x1a31
addsd 0x79c(%rip), %xmm0      # 0x2198
divsd 0x79c(%rip), %xmm0      # 0x21a0
movsd 0x79c(%rip), %xmm1      # 0x21a8
movapd %xmm2, 0x10(%rsp)
movsd %xmm4, (%rsp)
callq 0x1040
movsd 0x75c(%rip), %xmm1      # 0x2180
movsd (%rsp), %xmm4
movapd 0x10(%rsp), %xmm2
jmp 0x1a39
divsd 0x757(%rip), %xmm0      # 0x2190
divsd %xmm1, %xmm2
ucomisd 0x743(%rip), %xmm4      # 0x2188
movsd %xmm0, 0x20(%rsp)
jbe 0x1a80
addsd 0x743(%rip), %xmm4      # 0x2198
divsd 0x743(%rip), %xmm4      # 0x21a0
movsd 0x743(%rip), %xmm1      # 0x21a8
movapd %xmm4, %xmm0
movapd %xmm2, 0x10(%rsp)
callq 0x1040
movapd 0x10(%rsp), %xmm2
movapd %xmm0, %xmm4
jmp 0x1a88
divsd 0x708(%rip), %xmm4      # 0x2190
ucomisd 0x6f8(%rip), %xmm2      # 0x2188
jbe 0x1ac3
addsd 0x6fe(%rip), %xmm2      # 0x2198
divsd 0x6fe(%rip), %xmm2      # 0x21a0
movsd 0x6fe(%rip), %xmm1      # 0x21a8
movapd %xmm2, %xmm0
movsd %xmm4, (%rsp)
callq 0x1040
movsd (%rsp), %xmm4
movapd %xmm0, %xmm2
jmp 0x1acb
divsd 0x6c5(%rip), %xmm2      # 0x2190
movsd 0x6dd(%rip), %xmm0      # 0x21b0
mulsd %xmm4, %xmm0
movsd 0x6d9(%rip), %xmm1      # 0x21b8
movsd 0x20(%rsp), %xmm3
mulsd %xmm3, %xmm1
addsd %xmm0, %xmm1
movsd 0x6cb(%rip), %xmm0      # 0x21c0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
divsd 0x6c3(%rip), %xmm0      # 0x21c8
movsd 0x6c3(%rip), %xmm5      # 0x21d0
mulsd %xmm4, %xmm5
movsd 0x6bf(%rip), %xmm1      # 0x21d8
mulsd %xmm3, %xmm1
addsd %xmm5, %xmm1
movsd 0x6b7(%rip), %xmm5      # 0x21e0
mulsd %xmm2, %xmm5
mulsd 0x6b3(%rip), %xmm4      # 0x21e8
mulsd 0x6b3(%rip), %xmm3      # 0x21f0
addsd %xmm1, %xmm5
addsd %xmm4, %xmm3
mulsd 0x6ab(%rip), %xmm2      # 0x21f8
addsd %xmm3, %xmm2
ucomisd 0x6af(%rip), %xmm0      # 0x2208
jbe 0x1b80
movsd 0x6bd(%rip), %xmm1      # 0x2220
movapd %xmm2, 0x10(%rsp)
movapd %xmm5, (%rsp)
callq 0x1040
movapd (%rsp), %xmm5
movapd 0x10(%rsp), %xmm2
jmp 0x1b90
mulsd 0x688(%rip), %xmm0      # 0x2210
addsd 0x688(%rip), %xmm0      # 0x2218
divsd 0x668(%rip), %xmm2      # 0x2200
ucomisd 0x668(%rip), %xmm5      # 0x2208
movapd %xmm0, 0x20(%rsp)
jbe 0x1bcb
movsd 0x670(%rip), %xmm1      # 0x2220
movapd %xmm5, %xmm0
movapd %xmm2, 0x10(%rsp)
callq 0x1040
movapd 0x10(%rsp), %xmm2
movapd %xmm0, %xmm5
jmp 0x1bdb
mulsd 0x63d(%rip), %xmm5      # 0x2210
addsd 0x63d(%rip), %xmm5      # 0x2218
ucomisd 0x625(%rip), %xmm2      # 0x2208
jbe 0x1c06
movsd 0x633(%rip), %xmm1      # 0x2220
movapd %xmm2, %xmm0
movapd %xmm5, (%rsp)
callq 0x1040
movapd (%rsp), %xmm5
movapd %xmm0, %xmm2
jmp 0x1c16
mulsd 0x602(%rip), %xmm2      # 0x2210
addsd 0x602(%rip), %xmm2      # 0x2218
movapd 0x20(%rsp), %xmm1
movsd 0x604(%rip), %xmm0      # 0x2228
mulsd %xmm5, %xmm0
addsd 0x600(%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 0x618(%rip), %xmm1      # 0x2260
movupd %xmm1, 0x8(%rbx)
addq $0x30, %rsp
popq %rbx
retq