#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 uint8_t;

/* Variables and functions */
void rgb2yuv(uint8_t r, uint8_t g, uint8_t b, uint8_t *y, uint8_t *cr,
             uint8_t *cb) {
  *y = (257 * r + 504 * g + 98 * b + 16500) / 1000;
  *cr = (439 * r - 368 * g - 71 * b + 128500) / 1000;
  *cb = (-148 * r - 291 * g + 439 * b + 128500) / 1000;
}


x86 assembly (clang, -O0):
<rgb2yuv>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
imul   $0x101,-0x4(%rbp),%eax
imul   $0x1f8,-0x8(%rbp),%ecx
add    %ecx,%eax
imul   $0x62,-0xc(%rbp),%ecx
add    %ecx,%eax
add    $0x4074,%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
imul   $0x1b7,-0x4(%rbp),%eax
imul   $0x170,-0x8(%rbp),%ecx
sub    %ecx,%eax
imul   $0x47,-0xc(%rbp),%ecx
sub    %ecx,%eax
add    $0x1f5f4,%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
imul   $0xffffff6c,-0x4(%rbp),%eax
imul   $0x123,-0x8(%rbp),%ecx
sub    %ecx,%eax
imul   $0x1b7,-0xc(%rbp),%ecx
add    %ecx,%eax
add    $0x1f5f4,%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<rgb2yuv>:
mov    %edi,%eax
shl    $0x8,%eax
add    %edi,%eax
imul   $0x1f8,%esi,%r10d
add    %eax,%r10d
imul   $0x62,%edx,%eax
add    %r10d,%eax
add    $0x4074,%eax
cltq
imul   $0x10624dd3,%rax,%rax
mov    %rax,%r10
shr    $0x3f,%r10
sar    $0x26,%rax
add    %r10d,%eax
mov    %eax,(%rcx)
imul   $0x1b7,%edi,%eax
imul   $0xfffffe90,%esi,%ecx
add    %eax,%ecx
imul   $0xffffffb9,%edx,%eax
add    %ecx,%eax
add    $0x1f5f4,%eax
cltq
imul   $0x10624dd3,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
mov    %eax,(%r8)
imul   $0xffffff6c,%edi,%eax
imul   $0xfffffedd,%esi,%ecx
add    %eax,%ecx
imul   $0x1b7,%edx,%eax
add    %ecx,%eax
add    $0x1f5f4,%eax
cltq
imul   $0x10624dd3,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
mov    %eax,(%r9)
ret

LLVM IR (-O0):
define void @rgb2yuv(i32 %0, i32 %1, i32 %2, i32* %3, i32* %4, i32* %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32*
store i32 %0, i32* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32* %3, i32** %10
store i32* %4, i32** %11
store i32* %5, i32** %12
%13 = load i32, i32* %7
%14 = mul nsw i32 257, %13
%15 = load i32, i32* %8
%16 = mul nsw i32 504, %15
%17 = add nsw i32 %14, %16
%18 = load i32, i32* %9
%19 = mul nsw i32 98, %18
%20 = add nsw i32 %17, %19
%21 = add nsw i32 %20, 16500
%22 = sdiv i32 %21, 1000
%23 = load i32*, i32** %10
store i32 %22, i32* %23
%24 = load i32, i32* %7
%25 = mul nsw i32 439, %24
%26 = load i32, i32* %8
%27 = mul nsw i32 368, %26
%28 = sub nsw i32 %25, %27
%29 = load i32, i32* %9
%30 = mul nsw i32 71, %29
%31 = sub nsw i32 %28, %30
%32 = add nsw i32 %31, 128500
%33 = sdiv i32 %32, 1000
%34 = load i32*, i32** %11
store i32 %33, i32* %34
%35 = load i32, i32* %7
%36 = mul nsw i32 -148, %35
%37 = load i32, i32* %8
%38 = mul nsw i32 291, %37
%39 = sub nsw i32 %36, %38
%40 = load i32, i32* %9
%41 = mul nsw i32 439, %40
%42 = add nsw i32 %39, %41
%43 = add nsw i32 %42, 128500
%44 = sdiv i32 %43, 1000
%45 = load i32*, i32** %12
store i32 %44, i32* %45
ret void
}

LLVM IR (-O2):
define void @rgb2yuv(i32 %0, i32 %1, i32 %2, i32* nocapture writeonly %3, i32* nocapture writeonly %4, i32* nocapture writeonly %5) {
%7 = mul nsw i32 %0, 257
%8 = mul nsw i32 %1, 504
%9 = mul nsw i32 %2, 98
%10 = add i32 %7, 16500
%11 = add i32 %10, %8
%12 = add i32 %11, %9
%13 = sdiv i32 %12, 1000
store i32 %13, i32* %3
%14 = mul nsw i32 %0, 439
%15 = mul i32 %1, -368
%16 = mul i32 %2, -71
%17 = add i32 %14, 128500
%18 = add i32 %17, %15
%19 = add i32 %18, %16
%20 = sdiv i32 %19, 1000
store i32 %20, i32* %4
%21 = mul nsw i32 %0, -148
%22 = mul i32 %1, -291
%23 = mul nsw i32 %2, 439
%24 = add i32 %21, 128500
%25 = add i32 %24, %22
%26 = add i32 %25, %23
%27 = sdiv i32 %26, 1000
store i32 %27, i32* %5
ret void
}