#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int uint32_t;

/* Variables and functions */
uint32_t rgb2yuv(uint32_t c) {
  int r, g, b, y, u, v;
  r = (c & 0xFF0000) >> 16;
  g = (c & 0x00FF00) >> 8;
  b = c & 0x0000FF;
  y = (uint32_t)(0.299 * r + 0.587 * g + 0.114 * b);
  u = (uint32_t)(-0.169 * r - 0.331 * g + 0.5 * b) + 128;
  v = (uint32_t)(0.5 * r - 0.419 * g - 0.081 * b) + 128;
  return (y << 16) + (u << 8) + v;
}


x86 assembly (clang, -O0):
<rgb2yuv>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
and    $0xff0000,%eax
sar    $0x10,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    $0xff00,%eax
sar    $0x8,%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  0xef8(%rip),%xmm0
mulsd  %xmm2,%xmm0
movsd  0xee4(%rip),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
cvtsi2sdl -0x10(%rbp),%xmm0
movsd  0xec7(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x14(%rbp)
cvtsi2sdl -0x8(%rbp),%xmm1
cvtsi2sdl -0xc(%rbp),%xmm2
movsd  0xe9e(%rip),%xmm0
mulsd  %xmm2,%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xe73(%rip),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
cvtsi2sdl -0x10(%rbp),%xmm0
movsd  0xe4e(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
add    $0x80,%eax
mov    %eax,-0x18(%rbp)
cvtsi2sdl -0x8(%rbp),%xmm1
cvtsi2sdl -0xc(%rbp),%xmm2
movsd  0xe30(%rip),%xmm0
mulsd  %xmm2,%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xe05(%rip),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
cvtsi2sdl -0x10(%rbp),%xmm0
movsd  0xde8(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
add    $0x80,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x10,%eax
mov    -0x18(%rbp),%ecx
shl    $0x8,%ecx
add    %ecx,%eax
add    -0x1c(%rbp),%eax
pop    %rbp
ret

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

LLVM IR (-O0):
define i32 @rgb2yuv(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 = and i32 %9, 16711680
%11 = ashr i32 %10, 16
store i32 %11, i32* %3
%12 = load i32, i32* %2
%13 = and i32 %12, 65280
%14 = ashr i32 %13, 8
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 = fptosi double %25 to i32
store i32 %26, i32* %6
%27 = load i32, i32* %3
%28 = sitofp i32 %27 to double
%29 = load i32, i32* %4
%30 = sitofp i32 %29 to double
%31 = fmul double 3.310000e-01, %30
%32 = fneg double %31
%33 = call double @llvm.fmuladd.f64(double -1.690000e-01, double %28, double %32)
%34 = load i32, i32* %5
%35 = sitofp i32 %34 to double
%36 = call double @llvm.fmuladd.f64(double 5.000000e-01, double %35, double %33)
%37 = fptosi double %36 to i32
%38 = add nsw i32 %37, 128
store i32 %38, i32* %7
%39 = load i32, i32* %3
%40 = sitofp i32 %39 to double
%41 = load i32, i32* %4
%42 = sitofp i32 %41 to double
%43 = fmul double 4.190000e-01, %42
%44 = fneg double %43
%45 = call double @llvm.fmuladd.f64(double 5.000000e-01, double %40, double %44)
%46 = load i32, i32* %5
%47 = sitofp i32 %46 to double
%48 = call double @llvm.fmuladd.f64(double -8.100000e-02, double %47, double %45)
%49 = fptosi double %48 to i32
%50 = add nsw i32 %49, 128
store i32 %50, i32* %8
%51 = load i32, i32* %6
%52 = shl i32 %51, 16
%53 = load i32, i32* %7
%54 = shl i32 %53, 8
%55 = add nsw i32 %52, %54
%56 = load i32, i32* %8
%57 = add nsw i32 %55, %56
ret i32 %57
}

LLVM IR (-O2):
define i32 @rgb2yuv(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.310000e-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.690000e-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 = fptosi <2 x double> %18 to <2 x i32>
%20 = fmul double %8, -4.190000e-01
%21 = tail call double @llvm.fmuladd.f64(double %7, double 5.000000e-01, double %20)
%22 = tail call double @llvm.fmuladd.f64(double %9, double -8.100000e-02, double %21)
%23 = fptosi double %22 to i32
%24 = shl <2 x i32> %19, <i32 8, i32 16>
%25 = add i32 %23, 32896
%26 = extractelement <2 x i32> %24, i64 0
%27 = add i32 %25, %26
%28 = extractelement <2 x i32> %24, i64 1
%29 = add i32 %27, %28
ret i32 %29
}