#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;
typedef int uint32_t;

/* Variables and functions */
uint32_t YCbCr_to_RGBA(uint8_t Y, uint8_t Cb, uint8_t Cr) {
  int r, g, b;
  r = (int)(((double)Y * 0.582199097) + (0.701004028 * (double)(Cr - 128)));
  g = (int)(((double)Y * 0.582199097) - (0.357070923 * (double)(Cr - 128)) -
            (0.172073364 * (double)(Cb - 128)));
  b = (int)(((double)Y * 0.582199097) + (0.886001587 * (double)(Cb - 128)));
  r = ((unsigned int)r <= 255 ? r : (r < 0 ? 0 : 255));
  g = ((unsigned int)g <= 255 ? g : (g < 0 ? 0 : 255));
  b = ((unsigned int)b <= 255 ? b : (b < 0 ? 0 : 255));
  return (r << 24) | (g << 16) | (b << 8) | 0;
}


x86 assembly (clang, -O0):
<YCbCr_to_RGBA>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
cvtsi2sdl -0x4(%rbp),%xmm0
mov    -0xc(%rbp),%eax
sub    $0x80,%eax
cvtsi2sd %eax,%xmm2
movsd  0xefa(%rip),%xmm1
mulsd  %xmm2,%xmm1
movsd  0xece(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x10(%rbp)
cvtsi2sdl -0x4(%rbp),%xmm1
mov    -0xc(%rbp),%eax
sub    $0x80,%eax
cvtsi2sd %eax,%xmm2
movsd  0xebe(%rip),%xmm0
mulsd  %xmm2,%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xe83(%rip),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x8(%rbp),%eax
sub    $0x80,%eax
cvtsi2sd %eax,%xmm0
movsd  0xe77(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x14(%rbp)
cvtsi2sdl -0x4(%rbp),%xmm0
mov    -0x8(%rbp),%eax
sub    $0x80,%eax
cvtsi2sd %eax,%xmm2
movsd  0xe47(%rip),%xmm1
mulsd  %xmm2,%xmm1
movsd  0xe33(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0xff,-0x10(%rbp)
ja     11f4 <YCbCr_to_RGBA+0xf4>
mov    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1207 <YCbCr_to_RGBA+0x107>
mov    -0x10(%rbp),%edx
mov    $0xff,%eax
xor    %ecx,%ecx
cmp    $0x0,%edx
cmovl  %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0xff,-0x14(%rbp)
ja     1225 <YCbCr_to_RGBA+0x125>
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    1238 <YCbCr_to_RGBA+0x138>
mov    -0x14(%rbp),%edx
mov    $0xff,%eax
xor    %ecx,%ecx
cmp    $0x0,%edx
cmovl  %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0xff,-0x18(%rbp)
ja     1256 <YCbCr_to_RGBA+0x156>
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    1269 <YCbCr_to_RGBA+0x169>
mov    -0x18(%rbp),%edx
mov    $0xff,%eax
xor    %ecx,%ecx
cmp    $0x0,%edx
cmovl  %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
shl    $0x18,%eax
mov    -0x14(%rbp),%ecx
shl    $0x10,%ecx
or     %ecx,%eax
mov    -0x18(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
or     $0x0,%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<YCbCr_to_RGBA>:
cvtsi2sd %edi,%xmm0
movd   %esi,%xmm1
movd   %edx,%xmm2
punpckldq %xmm1,%xmm2
paddd  0xee8(%rip),%xmm2
cvtdq2pd %xmm2,%xmm1
movsd  0xf2c(%rip),%xmm2
mulsd  %xmm1,%xmm2
mulsd  0xf28(%rip),%xmm0
addsd  %xmm0,%xmm2
movapd %xmm1,%xmm3
unpckhpd %xmm1,%xmm3
mulsd  0xf1c(%rip),%xmm3
addsd  %xmm2,%xmm3
cvttsd2si %xmm3,%eax
mulpd  0xebc(%rip),%xmm1
unpcklpd %xmm0,%xmm0
addpd  %xmm1,%xmm0
cvttpd2dq %xmm0,%xmm0
xor    %ecx,%ecx
test   %eax,%eax
cmovns %eax,%ecx
cmp    $0xff,%ecx
mov    $0xff,%eax
cmovb  %ecx,%eax
xorpd  %xmm1,%xmm1
movapd %xmm0,%xmm2
pcmpgtd %xmm1,%xmm2
pand   %xmm0,%xmm2
movdqa 0xe93(%rip),%xmm0
pxor   %xmm2,%xmm0
movdqa 0xe97(%rip),%xmm1
pcmpgtd %xmm0,%xmm1
pand   %xmm1,%xmm2
pandn  0xe97(%rip),%xmm1
por    %xmm2,%xmm1
shl    $0x10,%eax
movdqa %xmm1,%xmm0
pslld  $0x8,%xmm0
pslld  $0x18,%xmm1
movd   %xmm1,%ecx
or     %eax,%ecx
pshufd $0x55,%xmm0,%xmm0
movd   %xmm0,%eax
or     %ecx,%eax
ret

LLVM IR (-O0):
define i32 @YCbCr_to_RGBA(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%10 = load i32, i32* %4
%11 = sitofp i32 %10 to double
%12 = load i32, i32* %6
%13 = sub nsw i32 %12, 128
%14 = sitofp i32 %13 to double
%15 = fmul double 0x3FE66E9FFFD3FA01, %14
%16 = call double @llvm.fmuladd.f64(double %11, double 0x3FE2A160002C05FF, double %15)
%17 = fptosi double %16 to i32
store i32 %17, i32* %7
%18 = load i32, i32* %4
%19 = sitofp i32 %18 to double
%20 = load i32, i32* %6
%21 = sub nsw i32 %20, 128
%22 = sitofp i32 %21 to double
%23 = fmul double 0x3FD6DA400028CD5C, %22
%24 = fneg double %23
%25 = call double @llvm.fmuladd.f64(double %19, double 0x3FE2A160002C05FF, double %24)
%26 = load i32, i32* %5
%27 = sub nsw i32 %26, 128
%28 = sitofp i32 %27 to double
%29 = call double @llvm.fmuladd.f64(double 0xBFC6067FFF72441E, double %28, double %25)
%30 = fptosi double %29 to i32
store i32 %30, i32* %8
%31 = load i32, i32* %4
%32 = sitofp i32 %31 to double
%33 = load i32, i32* %5
%34 = sub nsw i32 %33, 128
%35 = sitofp i32 %34 to double
%36 = fmul double 0x3FEC5A20000BCFA8, %35
%37 = call double @llvm.fmuladd.f64(double %32, double 0x3FE2A160002C05FF, double %36)
%38 = fptosi double %37 to i32
store i32 %38, i32* %9
%39 = load i32, i32* %7
%40 = icmp ule i32 %39, 255
br i1 %40, label %41, label %43
41: ; preds = %3
%42 = load i32, i32* %7
br label %48
43: ; preds = %3
%44 = load i32, i32* %7
%45 = icmp slt i32 %44, 0
%46 = zext i1 %45 to i64
%47 = select i1 %45, i32 0, i32 255
br label %48
48: ; preds = %43, %41
%49 = phi i32 [ %42, %41 ], [ %47, %43 ]
store i32 %49, i32* %7
%50 = load i32, i32* %8
%51 = icmp ule i32 %50, 255
br i1 %51, label %52, label %54
52: ; preds = %48
%53 = load i32, i32* %8
br label %59
54: ; preds = %48
%55 = load i32, i32* %8
%56 = icmp slt i32 %55, 0
%57 = zext i1 %56 to i64
%58 = select i1 %56, i32 0, i32 255
br label %59
59: ; preds = %54, %52
%60 = phi i32 [ %53, %52 ], [ %58, %54 ]
store i32 %60, i32* %8
%61 = load i32, i32* %9
%62 = icmp ule i32 %61, 255
br i1 %62, label %63, label %65
63: ; preds = %59
%64 = load i32, i32* %9
br label %70
65: ; preds = %59
%66 = load i32, i32* %9
%67 = icmp slt i32 %66, 0
%68 = zext i1 %67 to i64
%69 = select i1 %67, i32 0, i32 255
br label %70
70: ; preds = %65, %63
%71 = phi i32 [ %64, %63 ], [ %69, %65 ]
store i32 %71, i32* %9
%72 = load i32, i32* %7
%73 = shl i32 %72, 24
%74 = load i32, i32* %8
%75 = shl i32 %74, 16
%76 = or i32 %73, %75
%77 = load i32, i32* %9
%78 = shl i32 %77, 8
%79 = or i32 %76, %78
%80 = or i32 %79, 0
ret i32 %80
}

LLVM IR (-O2):
define i32 @YCbCr_to_RGBA(i32 %0, i32 %1, i32 %2) {
%4 = sitofp i32 %0 to double
%5 = insertelement <2 x i32> poison, i32 %2, i64 0
%6 = insertelement <2 x i32> %5, i32 %1, i64 1
%7 = add nsw <2 x i32> %6, <i32 -128, i32 -128>
%8 = sitofp <2 x i32> %7 to <2 x double>
%9 = extractelement <2 x double> %8, i64 0
%10 = fmul double %9, 0xBFD6DA400028CD5C
%11 = tail call double @llvm.fmuladd.f64(double %4, double 0x3FE2A160002C05FF, double %10)
%12 = extractelement <2 x double> %8, i64 1
%13 = tail call double @llvm.fmuladd.f64(double %12, double 0xBFC6067FFF72441E, double %11)
%14 = fptosi double %13 to i32
%15 = fmul <2 x double> %8, <double 0x3FE66E9FFFD3FA01, double 0x3FEC5A20000BCFA8>
%16 = insertelement <2 x double> poison, double %4, 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 0x3FE2A160002C05FF, double 0x3FE2A160002C05FF>, <2 x double> %15)
%19 = fptosi <2 x double> %18 to <2 x i32>
%20 = icmp sgt i32 %14, 0
%21 = select i1 %20, i32 %14, i32 0
%22 = icmp ult i32 %21, 255
%23 = select i1 %22, i32 %21, i32 255
%24 = icmp sgt <2 x i32> %19, zeroinitializer
%25 = select <2 x i1> %24, <2 x i32> %19, <2 x i32> zeroinitializer
%26 = icmp ult <2 x i32> %25, <i32 255, i32 255>
%27 = select <2 x i1> %26, <2 x i32> %25, <2 x i32> <i32 255, i32 255>
%28 = shl nuw nsw i32 %23, 16
%29 = shl nuw <2 x i32> %27, <i32 24, i32 8>
%30 = extractelement <2 x i32> %29, i64 0
%31 = or i32 %28, %30
%32 = extractelement <2 x i32> %29, i64 1
%33 = or i32 %31, %32
ret i32 %33
}