#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 */

/* Variables and functions */
int av_clip_uint8_c(double);
unsigned int vobsub_palette_to_yuv(unsigned int pal) {
  int r, g, b, y, u, v;
  r = pal >> 16 & 0xff;
  g = pal >> 8 & 0xff;
  b = pal & 0xff;
  y = av_clip_uint8_c(0.1494 * r + 0.6061 * g + 0.2445 * b);
  u = av_clip_uint8_c(0.6066 * r - 0.4322 * g - 0.1744 * b + 128);
  v = av_clip_uint8_c(-0.08435 * r - 0.3422 * g + 0.4266 * b + 128);
  y = y * 219 / 255 + 16;
  return y << 16 | u << 8 | v;
}


x86 assembly (clang, -O0):
<vobsub_palette_to_yuv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
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  0xef4(%rip),%xmm0
mulsd  %xmm2,%xmm0
movsd  0xee0(%rip),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
cvtsi2sdl -0x10(%rbp),%xmm0
movsd  0xec3(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1030 <av_clip_uint8_c@plt>
mov    %eax,-0x14(%rbp)
cvtsi2sdl -0x8(%rbp),%xmm1
cvtsi2sdl -0xc(%rbp),%xmm2
movsd  0xe99(%rip),%xmm0
mulsd  %xmm2,%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xe6e(%rip),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
cvtsi2sdl -0x10(%rbp),%xmm0
movsd  0xe51(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe21(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1030 <av_clip_uint8_c@plt>
mov    %eax,-0x18(%rbp)
cvtsi2sdl -0x8(%rbp),%xmm1
cvtsi2sdl -0xc(%rbp),%xmm2
movsd  0xe1b(%rip),%xmm0
mulsd  %xmm2,%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xdf0(%rip),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
cvtsi2sdl -0x10(%rbp),%xmm0
movsd  0xdd3(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xdbb(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1030 <av_clip_uint8_c@plt>
mov    %eax,-0x1c(%rbp)
imul   $0xdb,-0x14(%rbp),%eax
mov    $0xff,%ecx
cltd
idiv   %ecx
add    $0x10,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x10,%eax
mov    -0x18(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
or     -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vobsub_palette_to_yuv>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %edi,%eax
movzbl %ah,%ecx
movzbl %al,%edx
shr    $0x10,%eax
movzbl %al,%eax
cvtsi2sd %eax,%xmm2
movsd  %xmm2,0x8(%rsp)
cvtsi2sd %ecx,%xmm1
movsd  %xmm1,0x10(%rsp)
movsd  0xec0(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  0xebc(%rip),%xmm1
mulsd  %xmm2,%xmm1
xorps  %xmm2,%xmm2
cvtsi2sd %edx,%xmm2
movsd  %xmm2,(%rsp)
addsd  %xmm0,%xmm1
movsd  0xea8(%rip),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1030 <av_clip_uint8_c@plt>
mov    %eax,%ebx
movsd  0xe99(%rip),%xmm0
mulsd  0x10(%rsp),%xmm0
movsd  0xe93(%rip),%xmm1
mulsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  0xe89(%rip),%xmm0
mulsd  (%rsp),%xmm0
addsd  %xmm1,%xmm0
addsd  0xe80(%rip),%xmm0
call   1030 <av_clip_uint8_c@plt>
movsd  0x10(%rsp),%xmm1
mulsd  0xe75(%rip),%xmm1
mov    %eax,%ebp
movsd  0x8(%rsp),%xmm0
mulsd  0xe6d(%rip),%xmm0
addsd  %xmm1,%xmm0
movsd  (%rsp),%xmm1
mulsd  0xe64(%rip),%xmm1
addsd  %xmm0,%xmm1
addsd  0xe40(%rip),%xmm1
movapd %xmm1,%xmm0
call   1030 <av_clip_uint8_c@plt>
imul   $0xdb,%ebx,%ecx
movslq %ecx,%rcx
imul   $0xffffffff80808081,%rcx,%rdx
shr    $0x20,%rdx
add    %edx,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
shr    $0x7,%ecx
add    %edx,%ecx
shl    $0x10,%ecx
add    $0x100000,%ecx
shl    $0x8,%ebp
or     %ebp,%eax
or     %ecx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @vobsub_palette_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 6.061000e-01, %20
%22 = call double @llvm.fmuladd.f64(double 1.494000e-01, double %18, double %21)
%23 = load i32, i32* %5
%24 = sitofp i32 %23 to double
%25 = call double @llvm.fmuladd.f64(double 2.445000e-01, double %24, double %22)
%26 = call i32 @av_clip_uint8_c(double %25)
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 4.322000e-01, %30
%32 = fneg double %31
%33 = call double @llvm.fmuladd.f64(double 6.066000e-01, double %28, double %32)
%34 = load i32, i32* %5
%35 = sitofp i32 %34 to double
%36 = call double @llvm.fmuladd.f64(double -1.744000e-01, double %35, double %33)
%37 = fadd double %36, 1.280000e+02
%38 = call i32 @av_clip_uint8_c(double %37)
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 3.422000e-01, %42
%44 = fneg double %43
%45 = call double @llvm.fmuladd.f64(double 0xBFB597F62B6AE7D5, double %40, double %44)
%46 = load i32, i32* %5
%47 = sitofp i32 %46 to double
%48 = call double @llvm.fmuladd.f64(double 4.266000e-01, double %47, double %45)
%49 = fadd double %48, 1.280000e+02
%50 = call i32 @av_clip_uint8_c(double %49)
store i32 %50, i32* %8
%51 = load i32, i32* %6
%52 = mul nsw i32 %51, 219
%53 = sdiv i32 %52, 255
%54 = add nsw i32 %53, 16
store i32 %54, i32* %6
%55 = load i32, i32* %6
%56 = shl i32 %55, 16
%57 = load i32, i32* %7
%58 = shl i32 %57, 8
%59 = or i32 %56, %58
%60 = load i32, i32* %8
%61 = or i32 %59, %60
ret i32 %61
}

LLVM IR (-O2):
define i32 @vobsub_palette_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 = fmul double %8, 6.061000e-01
%10 = tail call double @llvm.fmuladd.f64(double %7, double 1.494000e-01, double %9)
%11 = sitofp i32 %6 to double
%12 = tail call double @llvm.fmuladd.f64(double %11, double 2.445000e-01, double %10)
%13 = tail call i32 @av_clip_uint8_c(double %12)
%14 = fmul double %8, -4.322000e-01
%15 = tail call double @llvm.fmuladd.f64(double %7, double 6.066000e-01, double %14)
%16 = tail call double @llvm.fmuladd.f64(double %11, double -1.744000e-01, double %15)
%17 = fadd double %16, 1.280000e+02
%18 = tail call i32 @av_clip_uint8_c(double %17)
%19 = fmul double %8, -3.422000e-01
%20 = tail call double @llvm.fmuladd.f64(double %7, double 0xBFB597F62B6AE7D5, double %19)
%21 = tail call double @llvm.fmuladd.f64(double %11, double 4.266000e-01, double %20)
%22 = fadd double %21, 1.280000e+02
%23 = tail call i32 @av_clip_uint8_c(double %22)
%24 = mul nsw i32 %13, 219
%25 = sdiv i32 %24, 255
%26 = shl i32 %25, 16
%27 = add i32 %26, 1048576
%28 = shl i32 %18, 8
%29 = or i32 %23, %28
%30 = or i32 %29, %27
ret i32 %30
}