void XYZ2RGB(double X, double Y, double Z, unsigned char *B, unsigned char *G,
             unsigned char *R) {
  double RR, GG, BB;
  RR = 3.240479 * X - 1.537150 * Y - 0.498535 * Z;
  GG = -0.969256 * X + 1.875992 * Y + 0.041556 * Z;
  BB = 0.055648 * X - 0.204043 * Y + 1.057311 * Z;
  *R = (unsigned char)(RR < 0 ? 0 : RR > 255 ? 255 : RR);
  *G = (unsigned char)(GG < 0 ? 0 : GG > 255 ? 255 : GG);
  *B = (unsigned char)(BB < 0 ? 0 : BB > 255 ? 255 : BB);
}


x86 assembly (clang, -O0):
<XYZ2RGB>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
mov    %rdi,-0x20(%rbp)
mov    %rsi,-0x28(%rbp)
mov    %rdx,-0x30(%rbp)
movsd  -0x8(%rbp),%xmm1
movsd  0xf14(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xee8(%rip),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
movsd  0xecb(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x8(%rbp),%xmm1
movsd  0xea9(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  0xe94(%rip),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
movsd  0xe77(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x8(%rbp),%xmm1
movsd  0xe55(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xe29(%rip),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
movsd  0xe0c(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x38(%rbp),%xmm0
jbe    121c <XYZ2RGB+0x11c>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x50(%rbp)
jmp    1259 <XYZ2RGB+0x159>
movsd  -0x38(%rbp),%xmm0
movsd  0xe1f(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1245 <XYZ2RGB+0x145>
movsd  0xe0d(%rip),%xmm0
movsd  %xmm0,-0x58(%rbp)
jmp    124f <XYZ2RGB+0x14f>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
cvttsd2si %xmm0,%eax
mov    %al,%cl
mov    -0x30(%rbp),%rax
mov    %cl,(%rax)
xorps  %xmm0,%xmm0
ucomisd -0x40(%rbp),%xmm0
jbe    1285 <XYZ2RGB+0x185>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x60(%rbp)
jmp    12c2 <XYZ2RGB+0x1c2>
movsd  -0x40(%rbp),%xmm0
movsd  0xdb6(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    12ae <XYZ2RGB+0x1ae>
movsd  0xda4(%rip),%xmm0
movsd  %xmm0,-0x68(%rbp)
jmp    12b8 <XYZ2RGB+0x1b8>
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
cvttsd2si %xmm0,%eax
mov    %al,%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
xorps  %xmm0,%xmm0
ucomisd -0x48(%rbp),%xmm0
jbe    12ee <XYZ2RGB+0x1ee>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x70(%rbp)
jmp    132b <XYZ2RGB+0x22b>
movsd  -0x48(%rbp),%xmm0
movsd  0xd4d(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1317 <XYZ2RGB+0x217>
movsd  0xd3b(%rip),%xmm0
movsd  %xmm0,-0x78(%rbp)
jmp    1321 <XYZ2RGB+0x221>
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x78(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x70(%rbp),%xmm0
cvttsd2si %xmm0,%eax
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<XYZ2RGB>:
movsd  0xef8(%rip),%xmm3
mulsd  %xmm1,%xmm3
movsd  0xef4(%rip),%xmm4
mulsd  %xmm0,%xmm4
addsd  %xmm3,%xmm4
movsd  0xeec(%rip),%xmm3
mulsd  %xmm2,%xmm3
unpcklpd %xmm1,%xmm1
mulpd  0xeec(%rip),%xmm1
addsd  %xmm4,%xmm3
unpcklpd %xmm0,%xmm0
mulpd  0xeec(%rip),%xmm0
addpd  %xmm1,%xmm0
unpcklpd %xmm2,%xmm2
mulpd  0xeec(%rip),%xmm2
addpd  %xmm0,%xmm2
movsd  0xeb8(%rip),%xmm0
movapd %xmm0,%xmm1
minsd  %xmm3,%xmm1
xorpd  %xmm4,%xmm4
cmpltsd %xmm4,%xmm3
andnpd %xmm1,%xmm3
cvttsd2si %xmm3,%r8d
movapd %xmm2,%xmm1
unpckhpd %xmm2,%xmm1
movapd %xmm0,%xmm3
minsd  %xmm1,%xmm3
xorpd  %xmm1,%xmm1
minsd  %xmm2,%xmm0
cmpltpd %xmm1,%xmm2
movmskpd %xmm2,%ecx
cvttsd2si %xmm3,%eax
xor    %r9d,%r9d
test   $0x2,%cl
cmovne %r9d,%eax
mov    %r8b,(%rdx)
mov    %al,(%rsi)
cvttsd2si %xmm0,%eax
test   $0x1,%cl
cmovne %r9d,%eax
mov    %al,(%rdi)
ret

LLVM IR (-O0):
define void @XYZ2RGB(double %0, double %1, double %2, i8* %3, i8* %4, i8* %5) {
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca double
%14 = alloca double
%15 = alloca double
store double %0, double* %7
store double %1, double* %8
store double %2, double* %9
store i8* %3, i8** %10
store i8* %4, i8** %11
store i8* %5, i8** %12
%16 = load double, double* %7
%17 = load double, double* %8
%18 = fmul double 1.537150e+00, %17
%19 = fneg double %18
%20 = call double @llvm.fmuladd.f64(double 0x4009EC804102FF8F, double %16, double %19)
%21 = load double, double* %9
%22 = call double @llvm.fmuladd.f64(double -4.985350e-01, double %21, double %20)
store double %22, double* %13
%23 = load double, double* %7
%24 = load double, double* %8
%25 = fmul double 0x3FFE04102FF8EC10, %24
%26 = call double @llvm.fmuladd.f64(double -9.692560e-01, double %23, double %25)
%27 = load double, double* %9
%28 = call double @llvm.fmuladd.f64(double 4.155600e-02, double %27, double %26)
store double %28, double* %14
%29 = load double, double* %7
%30 = load double, double* %8
%31 = fmul double 2.040430e-01, %30
%32 = fneg double %31
%33 = call double @llvm.fmuladd.f64(double 5.564800e-02, double %29, double %32)
%34 = load double, double* %9
%35 = call double @llvm.fmuladd.f64(double 0x3FF0EABEF06B3786, double %34, double %33)
store double %35, double* %15
%36 = load double, double* %13
%37 = fcmp olt double %36, 0.000000e+00
br i1 %37, label %38, label %39
38: ; preds = %6
br label %47
39: ; preds = %6
%40 = load double, double* %13
%41 = fcmp ogt double %40, 2.550000e+02
br i1 %41, label %42, label %43
42: ; preds = %39
br label %45
43: ; preds = %39
%44 = load double, double* %13
br label %45
45: ; preds = %43, %42
%46 = phi double [ 2.550000e+02, %42 ], [ %44, %43 ]
br label %47
47: ; preds = %45, %38
%48 = phi double [ 0.000000e+00, %38 ], [ %46, %45 ]
%49 = fptoui double %48 to i8
%50 = load i8*, i8** %12
store i8 %49, i8* %50
%51 = load double, double* %14
%52 = fcmp olt double %51, 0.000000e+00
br i1 %52, label %53, label %54
53: ; preds = %47
br label %62
54: ; preds = %47
%55 = load double, double* %14
%56 = fcmp ogt double %55, 2.550000e+02
br i1 %56, label %57, label %58
57: ; preds = %54
br label %60
58: ; preds = %54
%59 = load double, double* %14
br label %60
60: ; preds = %58, %57
%61 = phi double [ 2.550000e+02, %57 ], [ %59, %58 ]
br label %62
62: ; preds = %60, %53
%63 = phi double [ 0.000000e+00, %53 ], [ %61, %60 ]
%64 = fptoui double %63 to i8
%65 = load i8*, i8** %11
store i8 %64, i8* %65
%66 = load double, double* %15
%67 = fcmp olt double %66, 0.000000e+00
br i1 %67, label %68, label %69
68: ; preds = %62
br label %77
69: ; preds = %62
%70 = load double, double* %15
%71 = fcmp ogt double %70, 2.550000e+02
br i1 %71, label %72, label %73
72: ; preds = %69
br label %75
73: ; preds = %69
%74 = load double, double* %15
br label %75
75: ; preds = %73, %72
%76 = phi double [ 2.550000e+02, %72 ], [ %74, %73 ]
br label %77
77: ; preds = %75, %68
%78 = phi double [ 0.000000e+00, %68 ], [ %76, %75 ]
%79 = fptoui double %78 to i8
%80 = load i8*, i8** %10
store i8 %79, i8* %80
ret void
}

LLVM IR (-O2):
define void @XYZ2RGB(double %0, double %1, double %2, i8* nocapture writeonly %3, i8* nocapture writeonly %4, i8* nocapture writeonly %5) {
%7 = fmul double %1, -1.537150e+00
%8 = tail call double @llvm.fmuladd.f64(double %0, double 0x4009EC804102FF8F, double %7)
%9 = tail call double @llvm.fmuladd.f64(double %2, double -4.985350e-01, double %8)
%10 = insertelement <2 x double> poison, double %1, i64 0
%11 = shufflevector <2 x double> %10, <2 x double> poison, <2 x i32> zeroinitializer
%12 = fmul <2 x double> %11, <double -2.040430e-01, double 0x3FFE04102FF8EC10>
%13 = insertelement <2 x double> poison, double %0, i64 0
%14 = shufflevector <2 x double> %13, <2 x double> poison, <2 x i32> zeroinitializer
%15 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %14, <2 x double> <double 5.564800e-02, double -9.692560e-01>, <2 x double> %12)
%16 = insertelement <2 x double> poison, double %2, i64 0
%17 = shufflevector <2 x double> %16, <2 x double> poison, <2 x i32> zeroinitializer
%18 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %17, <2 x double> <double 0x3FF0EABEF06B3786, double 4.155600e-02>, <2 x double> %15)
%19 = fcmp olt double %9, 0.000000e+00
%20 = fcmp ogt double %9, 2.550000e+02
%21 = select i1 %20, double 2.550000e+02, double %9
%22 = select i1 %19, double 0.000000e+00, double %21
%23 = fptoui double %22 to i8
store i8 %23, i8* %5
%24 = extractelement <2 x double> %18, i64 1
%25 = fcmp ogt double %24, 2.550000e+02
%26 = select i1 %25, double 2.550000e+02, double %24
%27 = fcmp olt <2 x double> %18, zeroinitializer
%28 = extractelement <2 x i1> %27, i64 1
%29 = fptoui double %26 to i8
%30 = select i1 %28, i8 0, i8 %29
store i8 %30, i8* %4
%31 = extractelement <2 x double> %18, i64 0
%32 = fcmp ogt double %31, 2.550000e+02
%33 = select i1 %32, double 2.550000e+02, double %31
%34 = extractelement <2 x i1> %27, i64 0
%35 = fptoui double %33 to i8
%36 = select i1 %34, i8 0, i8 %35
store i8 %36, i8* %3
ret void
}