unsigned int vobsub_rgb_to_yuv(unsigned int rgb) {
  int r, g, b, y, u, v;
  r = rgb >> 16 & 0xff;
  g = rgb >> 8 & 0xff;
  b = rgb & 0xff;
  y = (0.299 * r + 0.587 * g + 0.114 * b) * 219 / 255 + 16.5;
  u = (-0.16874 * r - 0.33126 * g + 0.5 * b) * 224 / 255 + 128.5;
  v = (0.5 * r - 0.41869 * g - 0.08131 * b) * 224 / 255 + 128.5;
  return y << 16 | u << 8 | v;
}


x86 assembly (clang, -O0):
<vobsub_rgb_to_yuv>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
shr    $0x10,%eax
and    $0xff,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
shr    $0x8,%eax
and    $0xff,%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x10(%rbp)
cvtsi2sdl -0x8(%rbp),%xmm1
cvtsi2sdl -0xc(%rbp),%xmm2
movsd  0xf20(%rip),%xmm0
mulsd  %xmm2,%xmm0
movsd  0xf0c(%rip),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
cvtsi2sdl -0x10(%rbp),%xmm0
movsd  0xeef(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xed7(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe8b(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xeb7(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x14(%rbp)
cvtsi2sdl -0x8(%rbp),%xmm1
cvtsi2sdl -0xc(%rbp),%xmm2
movsd  0xe92(%rip),%xmm0
mulsd  %xmm2,%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xe67(%rip),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
cvtsi2sdl -0x10(%rbp),%xmm0
movsd  0xe42(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe22(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe0e(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xdfa(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x18(%rbp)
cvtsi2sdl -0x8(%rbp),%xmm1
cvtsi2sdl -0xc(%rbp),%xmm2
movsd  0xe05(%rip),%xmm0
mulsd  %xmm2,%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xdda(%rip),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
cvtsi2sdl -0x10(%rbp),%xmm0
movsd  0xdbd(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xda5(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xd91(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xd7d(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x10,%eax
mov    -0x18(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
or     -0x1c(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<vobsub_rgb_to_yuv>:
mov    %edi,%eax
movzbl %ah,%ecx
movzbl %al,%edx
shr    $0x10,%eax
movzbl %al,%eax
cvtsi2sd %eax,%xmm1
cvtsi2sd %ecx,%xmm2
cvtsi2sd %edx,%xmm0
movapd %xmm2,%xmm3
unpcklpd %xmm2,%xmm3
mulpd  0xed6(%rip),%xmm3
movapd %xmm1,%xmm4
unpcklpd %xmm1,%xmm4
mulpd  0xed6(%rip),%xmm4
addpd  %xmm3,%xmm4
movapd %xmm0,%xmm3
unpcklpd %xmm0,%xmm3
mulpd  0xed2(%rip),%xmm3
addpd  %xmm4,%xmm3
mulpd  0xed6(%rip),%xmm3
divpd  0xede(%rip),%xmm3
addpd  0xee6(%rip),%xmm3
cvttpd2dq %xmm3,%xmm3
mulsd  0xeea(%rip),%xmm2
mulsd  0xeea(%rip),%xmm1
addsd  %xmm2,%xmm1
mulsd  0xee6(%rip),%xmm0
addsd  %xmm1,%xmm0
mulsd  0xee2(%rip),%xmm0
divsd  0xee2(%rip),%xmm0
addsd  0xee2(%rip),%xmm0
cvttsd2si %xmm0,%eax
movapd %xmm3,%xmm0
pslld  $0x10,%xmm0
pslld  $0x8,%xmm3
movd   %xmm3,%ecx
or     %eax,%ecx
pshufd $0x55,%xmm0,%xmm0
movd   %xmm0,%eax
or     %ecx,%eax
ret

LLVM IR (-O0):
define i32 @vobsub_rgb_to_yuv(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %2
%9 = load i32, i32* %2
%10 = lshr i32 %9, 16
%11 = and i32 %10, 255
store i32 %11, i32* %3
%12 = load i32, i32* %2
%13 = lshr i32 %12, 8
%14 = and i32 %13, 255
store i32 %14, i32* %4
%15 = load i32, i32* %2
%16 = and i32 %15, 255
store i32 %16, i32* %5
%17 = load i32, i32* %3
%18 = sitofp i32 %17 to double
%19 = load i32, i32* %4
%20 = sitofp i32 %19 to double
%21 = fmul double 5.870000e-01, %20
%22 = call double @llvm.fmuladd.f64(double 2.990000e-01, double %18, double %21)
%23 = load i32, i32* %5
%24 = sitofp i32 %23 to double
%25 = call double @llvm.fmuladd.f64(double 1.140000e-01, double %24, double %22)
%26 = fmul double %25, 2.190000e+02
%27 = fdiv double %26, 2.550000e+02
%28 = fadd double %27, 1.650000e+01
%29 = fptosi double %28 to i32
store i32 %29, i32* %6
%30 = load i32, i32* %3
%31 = sitofp i32 %30 to double
%32 = load i32, i32* %4
%33 = sitofp i32 %32 to double
%34 = fmul double 3.312600e-01, %33
%35 = fneg double %34
%36 = call double @llvm.fmuladd.f64(double -1.687400e-01, double %31, double %35)
%37 = load i32, i32* %5
%38 = sitofp i32 %37 to double
%39 = call double @llvm.fmuladd.f64(double 5.000000e-01, double %38, double %36)
%40 = fmul double %39, 2.240000e+02
%41 = fdiv double %40, 2.550000e+02
%42 = fadd double %41, 1.285000e+02
%43 = fptosi double %42 to i32
store i32 %43, i32* %7
%44 = load i32, i32* %3
%45 = sitofp i32 %44 to double
%46 = load i32, i32* %4
%47 = sitofp i32 %46 to double
%48 = fmul double 4.186900e-01, %47
%49 = fneg double %48
%50 = call double @llvm.fmuladd.f64(double 5.000000e-01, double %45, double %49)
%51 = load i32, i32* %5
%52 = sitofp i32 %51 to double
%53 = call double @llvm.fmuladd.f64(double 0xBFB4D0BB6ED67770, double %52, double %50)
%54 = fmul double %53, 2.240000e+02
%55 = fdiv double %54, 2.550000e+02
%56 = fadd double %55, 1.285000e+02
%57 = fptosi double %56 to i32
store i32 %57, i32* %8
%58 = load i32, i32* %6
%59 = shl i32 %58, 16
%60 = load i32, i32* %7
%61 = shl i32 %60, 8
%62 = or i32 %59, %61
%63 = load i32, i32* %8
%64 = or i32 %62, %63
ret i32 %64
}

LLVM IR (-O2):
define i32 @vobsub_rgb_to_yuv(i32 %0) {
%2 = lshr i32 %0, 16
%3 = and i32 %2, 255
%4 = lshr i32 %0, 8
%5 = and i32 %4, 255
%6 = and i32 %0, 255
%7 = sitofp i32 %3 to double
%8 = sitofp i32 %5 to double
%9 = sitofp i32 %6 to double
%10 = insertelement <2 x double> poison, double %8, i64 0
%11 = shufflevector <2 x double> %10, <2 x double> poison, <2 x i32> zeroinitializer
%12 = fmul <2 x double> %11, <double -3.312600e-01, double 5.870000e-01>
%13 = insertelement <2 x double> poison, double %7, 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 -1.687400e-01, double 2.990000e-01>, <2 x double> %12)
%16 = insertelement <2 x double> poison, double %9, 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 5.000000e-01, double 1.140000e-01>, <2 x double> %15)
%19 = fmul <2 x double> %18, <double 2.240000e+02, double 2.190000e+02>
%20 = fdiv <2 x double> %19, <double 2.550000e+02, double 2.550000e+02>
%21 = fadd <2 x double> %20, <double 1.285000e+02, double 1.650000e+01>
%22 = fptosi <2 x double> %21 to <2 x i32>
%23 = fmul double %8, -4.186900e-01
%24 = tail call double @llvm.fmuladd.f64(double %7, double 5.000000e-01, double %23)
%25 = tail call double @llvm.fmuladd.f64(double %9, double 0xBFB4D0BB6ED67770, double %24)
%26 = fmul double %25, 2.240000e+02
%27 = fdiv double %26, 2.550000e+02
%28 = fadd double %27, 1.285000e+02
%29 = fptosi double %28 to i32
%30 = shl <2 x i32> %22, <i32 8, i32 16>
%31 = extractelement <2 x i32> %30, i64 0
%32 = or i32 %31, %29
%33 = extractelement <2 x i32> %30, i64 1
%34 = or i32 %32, %33
ret i32 %34
}