int convert_rgb_to_yuv_pixel(int r, int g, int b) {
  unsigned int pixel32 = 0;
  unsigned char *pixel = (unsigned char *)&pixel32;
  int y, u, v;
  y = 0.299 * (r - 128) + 0.587 * (g - 128) + 0.114 * (b - 128) + 128;
  u = -0.147 * (r - 128) - 0.289 * (g - 128) + 0.436 * (b - 128) + 128;
  v = 0.615 * (r - 128) - 0.515 * (g - 128) - 0.100 * (b - 128) + 128;
  if (y > 255)
    y = 255;
  if (u > 255)
    u = 255;
  if (v > 255)
    v = 255;
  if (y < 0)
    y = 0;
  if (u < 0)
    u = 0;
  if (v < 0)
    v = 0;
  pixel[0] = y;
  pixel[1] = u;
  pixel[2] = v;
  return pixel32;
}


x86 assembly (clang, -O0):
<convert_rgb_to_yuv_pixel>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
lea    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%eax
sub    $0x80,%eax
cvtsi2sd %eax,%xmm1
mov    -0x8(%rbp),%eax
sub    $0x80,%eax
cvtsi2sd %eax,%xmm2
movsd  0xf0c(%rip),%xmm0
mulsd  %xmm2,%xmm0
movsd  0xef8(%rip),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0xc(%rbp),%eax
sub    $0x80,%eax
cvtsi2sd %eax,%xmm0
movsd  0xed4(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe8c(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%eax
sub    $0x80,%eax
cvtsi2sd %eax,%xmm1
mov    -0x8(%rbp),%eax
sub    $0x80,%eax
cvtsi2sd %eax,%xmm2
movsd  0xe91(%rip),%xmm0
mulsd  %xmm2,%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xe66(%rip),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0xc(%rbp),%eax
sub    $0x80,%eax
cvtsi2sd %eax,%xmm0
movsd  0xe42(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe12(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x20(%rbp)
mov    -0x4(%rbp),%eax
sub    $0x80,%eax
cvtsi2sd %eax,%xmm1
mov    -0x8(%rbp),%eax
sub    $0x80,%eax
cvtsi2sd %eax,%xmm2
movsd  0xdff(%rip),%xmm0
mulsd  %xmm2,%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xdd4(%rip),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0xc(%rbp),%eax
sub    $0x80,%eax
cvtsi2sd %eax,%xmm0
movsd  0xdb0(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xd98(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x24(%rbp)
cmpl   $0xff,-0x1c(%rbp)
jle    1287 <convert_rgb_to_yuv_pixel+0x187>
movl   $0xff,-0x1c(%rbp)
cmpl   $0xff,-0x20(%rbp)
jle    129b <convert_rgb_to_yuv_pixel+0x19b>
movl   $0xff,-0x20(%rbp)
cmpl   $0xff,-0x24(%rbp)
jle    12af <convert_rgb_to_yuv_pixel+0x1af>
movl   $0xff,-0x24(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    12c0 <convert_rgb_to_yuv_pixel+0x1c0>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    12d1 <convert_rgb_to_yuv_pixel+0x1d1>
movl   $0x0,-0x20(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    12e2 <convert_rgb_to_yuv_pixel+0x1e2>
movl   $0x0,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x20(%rbp),%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x24(%rbp),%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x10(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert_rgb_to_yuv_pixel>:
add    $0xffffff80,%edi
cvtsi2sd %edi,%xmm0
add    $0xffffff80,%esi
cvtsi2sd %esi,%xmm1
movsd  0xeea(%rip),%xmm2
mulsd  %xmm1,%xmm2
movsd  0xee6(%rip),%xmm3
mulsd  %xmm0,%xmm3
add    $0xffffff80,%edx
cvtsi2sd %edx,%xmm4
addsd  %xmm2,%xmm3
movsd  0xed7(%rip),%xmm2
mulsd  %xmm4,%xmm2
addsd  %xmm3,%xmm2
addsd  0xecf(%rip),%xmm2
cvttsd2si %xmm2,%eax
unpcklpd %xmm1,%xmm1
mulpd  0xec7(%rip),%xmm1
unpcklpd %xmm0,%xmm0
mulpd  0xecb(%rip),%xmm0
addpd  %xmm1,%xmm0
unpcklpd %xmm4,%xmm4
mulpd  0xecb(%rip),%xmm4
addpd  %xmm0,%xmm4
addpd  0xecf(%rip),%xmm4
cvttpd2dq %xmm4,%xmm0
cmp    $0xff,%eax
mov    $0xff,%ecx
cmovl  %eax,%ecx
movdqa 0xec6(%rip),%xmm1
movdqa %xmm1,%xmm2
pcmpgtd %xmm0,%xmm2
pand   %xmm2,%xmm0
pandn  %xmm1,%xmm2
por    %xmm0,%xmm2
xor    %eax,%eax
test   %ecx,%ecx
cmovns %ecx,%eax
pxor   %xmm0,%xmm0
movdqa %xmm2,%xmm1
pcmpgtd %xmm0,%xmm1
pand   %xmm2,%xmm1
movdqa %xmm1,%xmm0
pslld  $0x10,%xmm0
pslld  $0x8,%xmm1
movd   %xmm1,%ecx
or     %eax,%ecx
pshufd $0x55,%xmm0,%xmm0
movd   %xmm0,%eax
or     %ecx,%eax
ret

LLVM IR (-O0):
define i32 @convert_rgb_to_yuv_pixel(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %7
%12 = bitcast i32* %7 to i8*
store i8* %12, i8** %8
%13 = load i32, i32* %4
%14 = sub nsw i32 %13, 128
%15 = sitofp i32 %14 to double
%16 = load i32, i32* %5
%17 = sub nsw i32 %16, 128
%18 = sitofp i32 %17 to double
%19 = fmul double 5.870000e-01, %18
%20 = call double @llvm.fmuladd.f64(double 2.990000e-01, double %15, double %19)
%21 = load i32, i32* %6
%22 = sub nsw i32 %21, 128
%23 = sitofp i32 %22 to double
%24 = call double @llvm.fmuladd.f64(double 1.140000e-01, double %23, double %20)
%25 = fadd double %24, 1.280000e+02
%26 = fptosi double %25 to i32
store i32 %26, i32* %9
%27 = load i32, i32* %4
%28 = sub nsw i32 %27, 128
%29 = sitofp i32 %28 to double
%30 = load i32, i32* %5
%31 = sub nsw i32 %30, 128
%32 = sitofp i32 %31 to double
%33 = fmul double 2.890000e-01, %32
%34 = fneg double %33
%35 = call double @llvm.fmuladd.f64(double -1.470000e-01, double %29, double %34)
%36 = load i32, i32* %6
%37 = sub nsw i32 %36, 128
%38 = sitofp i32 %37 to double
%39 = call double @llvm.fmuladd.f64(double 4.360000e-01, double %38, double %35)
%40 = fadd double %39, 1.280000e+02
%41 = fptosi double %40 to i32
store i32 %41, i32* %10
%42 = load i32, i32* %4
%43 = sub nsw i32 %42, 128
%44 = sitofp i32 %43 to double
%45 = load i32, i32* %5
%46 = sub nsw i32 %45, 128
%47 = sitofp i32 %46 to double
%48 = fmul double 5.150000e-01, %47
%49 = fneg double %48
%50 = call double @llvm.fmuladd.f64(double 0x3FE3AE147AE147AE, double %44, double %49)
%51 = load i32, i32* %6
%52 = sub nsw i32 %51, 128
%53 = sitofp i32 %52 to double
%54 = call double @llvm.fmuladd.f64(double -1.000000e-01, double %53, double %50)
%55 = fadd double %54, 1.280000e+02
%56 = fptosi double %55 to i32
store i32 %56, i32* %11
%57 = load i32, i32* %9
%58 = icmp sgt i32 %57, 255
br i1 %58, label %59, label %60
59: ; preds = %3
store i32 255, i32* %9
br label %60
60: ; preds = %59, %3
%61 = load i32, i32* %10
%62 = icmp sgt i32 %61, 255
br i1 %62, label %63, label %64
63: ; preds = %60
store i32 255, i32* %10
br label %64
64: ; preds = %63, %60
%65 = load i32, i32* %11
%66 = icmp sgt i32 %65, 255
br i1 %66, label %67, label %68
67: ; preds = %64
store i32 255, i32* %11
br label %68
68: ; preds = %67, %64
%69 = load i32, i32* %9
%70 = icmp slt i32 %69, 0
br i1 %70, label %71, label %72
71: ; preds = %68
store i32 0, i32* %9
br label %72
72: ; preds = %71, %68
%73 = load i32, i32* %10
%74 = icmp slt i32 %73, 0
br i1 %74, label %75, label %76
75: ; preds = %72
store i32 0, i32* %10
br label %76
76: ; preds = %75, %72
%77 = load i32, i32* %11
%78 = icmp slt i32 %77, 0
br i1 %78, label %79, label %80
79: ; preds = %76
store i32 0, i32* %11
br label %80
80: ; preds = %79, %76
%81 = load i32, i32* %9
%82 = trunc i32 %81 to i8
%83 = load i8*, i8** %8
%84 = getelementptr inbounds i8, i8* %83, i64 0
store i8 %82, i8* %84
%85 = load i32, i32* %10
%86 = trunc i32 %85 to i8
%87 = load i8*, i8** %8
%88 = getelementptr inbounds i8, i8* %87, i64 1
store i8 %86, i8* %88
%89 = load i32, i32* %11
%90 = trunc i32 %89 to i8
%91 = load i8*, i8** %8
%92 = getelementptr inbounds i8, i8* %91, i64 2
store i8 %90, i8* %92
%93 = load i32, i32* %7
ret i32 %93
}

LLVM IR (-O2):
define i32 @convert_rgb_to_yuv_pixel(i32 %0, i32 %1, i32 %2) {
%4 = add nsw i32 %0, -128
%5 = sitofp i32 %4 to double
%6 = add nsw i32 %1, -128
%7 = sitofp i32 %6 to double
%8 = fmul double %7, 5.870000e-01
%9 = tail call double @llvm.fmuladd.f64(double %5, double 2.990000e-01, double %8)
%10 = add nsw i32 %2, -128
%11 = sitofp i32 %10 to double
%12 = tail call double @llvm.fmuladd.f64(double %11, double 1.140000e-01, double %9)
%13 = fadd double %12, 1.280000e+02
%14 = fptosi double %13 to i32
%15 = insertelement <2 x double> poison, double %7, i64 0
%16 = shufflevector <2 x double> %15, <2 x double> poison, <2 x i32> zeroinitializer
%17 = fmul <2 x double> %16, <double -2.890000e-01, double -5.150000e-01>
%18 = insertelement <2 x double> poison, double %5, i64 0
%19 = shufflevector <2 x double> %18, <2 x double> poison, <2 x i32> zeroinitializer
%20 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %19, <2 x double> <double -1.470000e-01, double 0x3FE3AE147AE147AE>, <2 x double> %17)
%21 = insertelement <2 x double> poison, double %11, i64 0
%22 = shufflevector <2 x double> %21, <2 x double> poison, <2 x i32> zeroinitializer
%23 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %22, <2 x double> <double 4.360000e-01, double -1.000000e-01>, <2 x double> %20)
%24 = fadd <2 x double> %23, <double 1.280000e+02, double 1.280000e+02>
%25 = fptosi <2 x double> %24 to <2 x i32>
%26 = icmp slt i32 %14, 255
%27 = select i1 %26, i32 %14, i32 255
%28 = icmp slt <2 x i32> %25, <i32 255, i32 255>
%29 = select <2 x i1> %28, <2 x i32> %25, <2 x i32> <i32 255, i32 255>
%30 = icmp sgt i32 %27, 0
%31 = select i1 %30, i32 %27, i32 0
%32 = icmp sgt <2 x i32> %29, zeroinitializer
%33 = select <2 x i1> %32, <2 x i32> %29, <2 x i32> zeroinitializer
%34 = shl nuw nsw <2 x i32> %33, <i32 8, i32 16>
%35 = and <2 x i32> %34, <i32 65280, i32 16711680>
%36 = extractelement <2 x i32> %35, i64 0
%37 = or i32 %36, %31
%38 = extractelement <2 x i32> %35, i64 1
%39 = or i32 %37, %38
ret i32 %39
}