void yuv_to_rgb_16(unsigned char y, unsigned char u, unsigned char v,
                   unsigned char *rg, unsigned char *gb) {
  double R, G, B;
  R = 31 * (0.004565 * y + 0.000001 * u + 0.006250 * v - 0.872);
  G = 63 * (0.004565 * y - 0.001542 * u - 0.003183 * v + 0.531);
  B = 31 * (0.004565 * y + 0.007935 * u - 1.088);
  if (R < 0)
    R = 0;
  if (G < 0)
    G = 0;
  if (B < 0)
    B = 0;
  if (R > 31)
    R = 31;
  if (G > 63)
    G = 63;
  if (B > 31)
    B = 31;
  *rg = (((unsigned char)(R)) << 3) + (((unsigned char)(G) >> 3));
  *gb = (((unsigned char)(G)&0x1f) << 5) + (unsigned char)(B);
}


x86 assembly (clang, -O0):
<yuv_to_rgb_16>:
push   %rbp
mov    %rsp,%rbp
mov    %dl,%al
mov    %sil,%dl
mov    %dil,%sil
mov    %sil,-0x1(%rbp)
mov    %dl,-0x2(%rbp)
mov    %al,-0x3(%rbp)
mov    %rcx,-0x10(%rbp)
mov    %r8,-0x18(%rbp)
movzbl -0x1(%rbp),%eax
cvtsi2sd %eax,%xmm0
movzbl -0x2(%rbp),%eax
cvtsi2sd %eax,%xmm2
movsd  0xf1a(%rip),%xmm1
mulsd  %xmm2,%xmm1
movsd  0xece(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movzbl -0x3(%rbp),%eax
cvtsi2sd %eax,%xmm1
movsd  0xeee(%rip),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  0xed6(%rip),%xmm0
subsd  %xmm0,%xmm1
movsd  0xe8a(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movzbl -0x1(%rbp),%eax
cvtsi2sd %eax,%xmm0
movzbl -0x2(%rbp),%eax
cvtsi2sd %eax,%xmm2
movsd  0xea1(%rip),%xmm1
mulsd  %xmm2,%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
movsd  0xe56(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movzbl -0x3(%rbp),%eax
cvtsi2sd %eax,%xmm1
movsd  0xe5e(%rip),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe46(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  0xe32(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movzbl -0x1(%rbp),%eax
cvtsi2sd %eax,%xmm1
movzbl -0x2(%rbp),%eax
cvtsi2sd %eax,%xmm2
movsd  0xe09(%rip),%xmm0
mulsd  %xmm2,%xmm0
movsd  0xdf5(%rip),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  0xddd(%rip),%xmm0
subsd  %xmm0,%xmm1
movsd  0xdc9(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    1256 <yuv_to_rgb_16+0x156>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    126c <yuv_to_rgb_16+0x16c>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x30(%rbp),%xmm0
jbe    1282 <yuv_to_rgb_16+0x182>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xd71(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    12a6 <yuv_to_rgb_16+0x1a6>
movsd  0xd5f(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  0xd6d(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    12ca <yuv_to_rgb_16+0x1ca>
movsd  0xd5b(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xd29(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    12ee <yuv_to_rgb_16+0x1ee>
movsd  0xd17(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
cvttsd2si -0x20(%rbp),%eax
cvttsd2si -0x28(%rbp),%ecx
movzbl %cl,%edx
shr    $0x3,%edx
mov    %eax,%ecx
mov    %edx,%eax
lea    (%rax,%rcx,8),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
cvttsd2si -0x28(%rbp),%eax
and    $0x1f,%eax
shl    $0x5,%eax
cvttsd2si -0x30(%rbp),%ecx
movzbl %cl,%ecx
add    %ecx,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<yuv_to_rgb_16>:
cvtsi2sd %esi,%xmm3
movsd  0xef4(%rip),%xmm0
mulsd  %xmm3,%xmm0
movd   %edi,%xmm1
pinsrw $0x2,%edx,%xmm1
cvtdq2pd %xmm1,%xmm1
movsd  0xee3(%rip),%xmm4
mulsd  %xmm1,%xmm4
addsd  %xmm4,%xmm0
movapd %xmm1,%xmm2
unpckhpd %xmm1,%xmm2
mulsd  0xed3(%rip),%xmm2
addsd  %xmm0,%xmm2
addsd  0xecf(%rip),%xmm2
movsd  0xecf(%rip),%xmm0
mulsd  %xmm0,%xmm2
movsd  0xecb(%rip),%xmm5
mulsd  %xmm3,%xmm5
addsd  %xmm4,%xmm5
mulsd  0xec3(%rip),%xmm3
mulpd  0xecb(%rip),%xmm1
unpcklpd %xmm5,%xmm3
addpd  %xmm3,%xmm1
addpd  0xecb(%rip),%xmm1
mulpd  0xed3(%rip),%xmm1
xorpd  %xmm3,%xmm3
xorpd  %xmm4,%xmm4
movapd %xmm1,%xmm5
cmpltpd %xmm4,%xmm5
movmskpd %xmm5,%eax
xorpd  %xmm4,%xmm4
test   $0x2,%al
jne    11b2 <yuv_to_rgb_16+0xb2>
movapd %xmm1,%xmm4
unpckhpd %xmm1,%xmm4
xorpd  %xmm5,%xmm5
maxsd  %xmm2,%xmm5
test   $0x1,%al
jne    11c2 <yuv_to_rgb_16+0xc2>
movapd %xmm1,%xmm3
movapd %xmm0,%xmm1
minsd  %xmm5,%xmm1
movsd  0xe66(%rip),%xmm2
minsd  %xmm4,%xmm2
cvttsd2si %xmm1,%esi
minsd  %xmm3,%xmm0
shl    $0x3,%sil
cvttsd2si %xmm2,%edx
mov    %edx,%eax
shr    $0x3,%al
add    %sil,%al
mov    %al,(%rcx)
shl    $0x5,%dl
cvttsd2si %xmm0,%eax
add    %dl,%al
mov    %al,(%r8)
ret

LLVM IR (-O0):
define void @yuv_to_rgb_16(i8 zeroext %0, i8 zeroext %1, i8 zeroext %2, i8* %3, i8* %4) {
%6 = alloca i8
%7 = alloca i8
%8 = alloca i8
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca double
%12 = alloca double
%13 = alloca double
store i8 %0, i8* %6
store i8 %1, i8* %7
store i8 %2, i8* %8
store i8* %3, i8** %9
store i8* %4, i8** %10
%14 = load i8, i8* %6
%15 = zext i8 %14 to i32
%16 = sitofp i32 %15 to double
%17 = load i8, i8* %7
%18 = zext i8 %17 to i32
%19 = sitofp i32 %18 to double
%20 = fmul double 0x3EB0C6F7A0B5ED8D, %19
%21 = call double @llvm.fmuladd.f64(double 4.565000e-03, double %16, double %20)
%22 = load i8, i8* %8
%23 = zext i8 %22 to i32
%24 = sitofp i32 %23 to double
%25 = call double @llvm.fmuladd.f64(double 6.250000e-03, double %24, double %21)
%26 = fsub double %25, 8.720000e-01
%27 = fmul double 3.100000e+01, %26
store double %27, double* %11
%28 = load i8, i8* %6
%29 = zext i8 %28 to i32
%30 = sitofp i32 %29 to double
%31 = load i8, i8* %7
%32 = zext i8 %31 to i32
%33 = sitofp i32 %32 to double
%34 = fmul double 1.542000e-03, %33
%35 = fneg double %34
%36 = call double @llvm.fmuladd.f64(double 4.565000e-03, double %30, double %35)
%37 = load i8, i8* %8
%38 = zext i8 %37 to i32
%39 = sitofp i32 %38 to double
%40 = call double @llvm.fmuladd.f64(double -3.183000e-03, double %39, double %36)
%41 = fadd double %40, 5.310000e-01
%42 = fmul double 6.300000e+01, %41
store double %42, double* %12
%43 = load i8, i8* %6
%44 = zext i8 %43 to i32
%45 = sitofp i32 %44 to double
%46 = load i8, i8* %7
%47 = zext i8 %46 to i32
%48 = sitofp i32 %47 to double
%49 = fmul double 0x3F804039ABF33871, %48
%50 = call double @llvm.fmuladd.f64(double 4.565000e-03, double %45, double %49)
%51 = fsub double %50, 1.088000e+00
%52 = fmul double 3.100000e+01, %51
store double %52, double* %13
%53 = load double, double* %11
%54 = fcmp olt double %53, 0.000000e+00
br i1 %54, label %55, label %56
55: ; preds = %5
store double 0.000000e+00, double* %11
br label %56
56: ; preds = %55, %5
%57 = load double, double* %12
%58 = fcmp olt double %57, 0.000000e+00
br i1 %58, label %59, label %60
59: ; preds = %56
store double 0.000000e+00, double* %12
br label %60
60: ; preds = %59, %56
%61 = load double, double* %13
%62 = fcmp olt double %61, 0.000000e+00
br i1 %62, label %63, label %64
63: ; preds = %60
store double 0.000000e+00, double* %13
br label %64
64: ; preds = %63, %60
%65 = load double, double* %11
%66 = fcmp ogt double %65, 3.100000e+01
br i1 %66, label %67, label %68
67: ; preds = %64
store double 3.100000e+01, double* %11
br label %68
68: ; preds = %67, %64
%69 = load double, double* %12
%70 = fcmp ogt double %69, 6.300000e+01
br i1 %70, label %71, label %72
71: ; preds = %68
store double 6.300000e+01, double* %12
br label %72
72: ; preds = %71, %68
%73 = load double, double* %13
%74 = fcmp ogt double %73, 3.100000e+01
br i1 %74, label %75, label %76
75: ; preds = %72
store double 3.100000e+01, double* %13
br label %76
76: ; preds = %75, %72
%77 = load double, double* %11
%78 = fptoui double %77 to i8
%79 = zext i8 %78 to i32
%80 = shl i32 %79, 3
%81 = load double, double* %12
%82 = fptoui double %81 to i8
%83 = zext i8 %82 to i32
%84 = ashr i32 %83, 3
%85 = add nsw i32 %80, %84
%86 = trunc i32 %85 to i8
%87 = load i8*, i8** %9
store i8 %86, i8* %87
%88 = load double, double* %12
%89 = fptoui double %88 to i8
%90 = zext i8 %89 to i32
%91 = and i32 %90, 31
%92 = shl i32 %91, 5
%93 = load double, double* %13
%94 = fptoui double %93 to i8
%95 = zext i8 %94 to i32
%96 = add nsw i32 %92, %95
%97 = trunc i32 %96 to i8
%98 = load i8*, i8** %10
store i8 %97, i8* %98
ret void
}

LLVM IR (-O2):
define void @yuv_to_rgb_16(i8 zeroext %0, i8 zeroext %1, i8 zeroext %2, i8* nocapture writeonly %3, i8* nocapture writeonly %4) {
%6 = uitofp i8 %1 to double
%7 = fmul double %6, 0x3EB0C6F7A0B5ED8D
%8 = insertelement <2 x i8> poison, i8 %0, i64 0
%9 = insertelement <2 x i8> %8, i8 %2, i64 1
%10 = uitofp <2 x i8> %9 to <2 x double>
%11 = extractelement <2 x double> %10, i64 0
%12 = tail call double @llvm.fmuladd.f64(double %11, double 4.565000e-03, double %7)
%13 = extractelement <2 x double> %10, i64 1
%14 = tail call double @llvm.fmuladd.f64(double %13, double 6.250000e-03, double %12)
%15 = fadd double %14, -8.720000e-01
%16 = fmul double %15, 3.100000e+01
%17 = fmul double %6, -1.542000e-03
%18 = tail call double @llvm.fmuladd.f64(double %11, double 4.565000e-03, double %17)
%19 = fmul double %6, 0x3F804039ABF33871
%20 = insertelement <2 x double> poison, double %19, i64 0
%21 = insertelement <2 x double> %20, double %18, i64 1
%22 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %10, <2 x double> <double 4.565000e-03, double -3.183000e-03>, <2 x double> %21)
%23 = fadd <2 x double> %22, <double -1.088000e+00, double 5.310000e-01>
%24 = fmul <2 x double> %23, <double 3.100000e+01, double 6.300000e+01>
%25 = fcmp olt double %16, 0.000000e+00
%26 = select i1 %25, double 0.000000e+00, double %16
%27 = fcmp olt <2 x double> %24, zeroinitializer
%28 = extractelement <2 x i1> %27, i64 1
%29 = extractelement <2 x double> %24, i64 1
%30 = select i1 %28, double 0.000000e+00, double %29
%31 = extractelement <2 x i1> %27, i64 0
%32 = extractelement <2 x double> %24, i64 0
%33 = select i1 %31, double 0.000000e+00, double %32
%34 = fcmp ogt double %26, 3.100000e+01
%35 = select i1 %34, double 3.100000e+01, double %26
%36 = fcmp ogt double %30, 6.300000e+01
%37 = select i1 %36, double 6.300000e+01, double %30
%38 = fcmp ogt double %33, 3.100000e+01
%39 = select i1 %38, double 3.100000e+01, double %33
%40 = fptoui double %35 to i8
%41 = shl i8 %40, 3
%42 = fptoui double %37 to i8
%43 = lshr i8 %42, 3
%44 = add i8 %41, %43
store i8 %44, i8* %3
%45 = shl i8 %42, 5
%46 = fptoui double %39 to i8
%47 = add i8 %45, %46
store i8 %47, i8* %4
ret void
}