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

/* Variables and functions */
void *clip(int);
void yuv_to_rgb(uint8_t **dest, uint8_t y, int8_t u, int8_t v) {
  *((*dest)++) = clip(((y << 12) + v * 5743 + 2048) >> 12);
  *((*dest)++) = clip(((y << 12) - u * 1411 - v * 2925 + 2048) >> 12);
  *((*dest)++) = clip(((y << 12) + u * 7258 + 2048) >> 12);
}


x86 assembly (clang, -O0):
<yuv_to_rgb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0xc(%rbp),%edi
shl    $0xc,%edi
imul   $0x166f,-0x14(%rbp),%eax
add    %eax,%edi
add    $0x800,%edi
sar    $0xc,%edi
call   1030 <clip@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rdx
mov    (%rdx),%rax
mov    %rax,%rsi
add    $0x4,%rsi
mov    %rsi,(%rdx)
mov    %ecx,(%rax)
mov    -0xc(%rbp),%edi
shl    $0xc,%edi
imul   $0x583,-0x10(%rbp),%eax
sub    %eax,%edi
imul   $0xb6d,-0x14(%rbp),%eax
sub    %eax,%edi
add    $0x800,%edi
sar    $0xc,%edi
call   1030 <clip@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rdx
mov    (%rdx),%rax
mov    %rax,%rsi
add    $0x4,%rsi
mov    %rsi,(%rdx)
mov    %ecx,(%rax)
mov    -0xc(%rbp),%edi
shl    $0xc,%edi
imul   $0x1c5a,-0x10(%rbp),%eax
add    %eax,%edi
add    $0x800,%edi
sar    $0xc,%edi
call   1030 <clip@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rdx
mov    (%rdx),%rax
mov    %rax,%rsi
add    $0x4,%rsi
mov    %rsi,(%rdx)
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<yuv_to_rgb>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%ebp
mov    %edx,%r15d
mov    %esi,%r14d
mov    %rdi,%rbx
shl    $0xc,%r14d
imul   $0x166f,%ecx,%eax
lea    (%r14,%rax,1),%edi
add    $0x800,%edi
sar    $0xc,%edi
call   1030 <clip@plt>
mov    (%rbx),%rcx
lea    0x4(%rcx),%rdx
mov    %rdx,(%rbx)
mov    %eax,(%rcx)
imul   $0xfffffa7d,%r15d,%eax
imul   $0xfffff493,%ebp,%ecx
lea    (%r14,%rax,1),%edi
add    $0x800,%edi
add    %ecx,%edi
sar    $0xc,%edi
call   1030 <clip@plt>
mov    (%rbx),%rcx
lea    0x4(%rcx),%rdx
mov    %rdx,(%rbx)
mov    %eax,(%rcx)
imul   $0x1c5a,%r15d,%eax
lea    (%r14,%rax,1),%edi
add    $0x800,%edi
sar    $0xc,%edi
call   1030 <clip@plt>
mov    (%rbx),%rcx
lea    0x4(%rcx),%rdx
mov    %rdx,(%rbx)
mov    %eax,(%rcx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @yuv_to_rgb(i32** %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32** %0, i32*** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%9 = load i32, i32* %6
%10 = shl i32 %9, 12
%11 = load i32, i32* %8
%12 = mul nsw i32 %11, 5743
%13 = add nsw i32 %10, %12
%14 = add nsw i32 %13, 2048
%15 = ashr i32 %14, 12
%16 = call i8* @clip(i32 %15)
%17 = ptrtoint i8* %16 to i32
%18 = load i32**, i32*** %5
%19 = load i32*, i32** %18
%20 = getelementptr inbounds i32, i32* %19, i32 1
store i32* %20, i32** %18
store i32 %17, i32* %19
%21 = load i32, i32* %6
%22 = shl i32 %21, 12
%23 = load i32, i32* %7
%24 = mul nsw i32 %23, 1411
%25 = sub nsw i32 %22, %24
%26 = load i32, i32* %8
%27 = mul nsw i32 %26, 2925
%28 = sub nsw i32 %25, %27
%29 = add nsw i32 %28, 2048
%30 = ashr i32 %29, 12
%31 = call i8* @clip(i32 %30)
%32 = ptrtoint i8* %31 to i32
%33 = load i32**, i32*** %5
%34 = load i32*, i32** %33
%35 = getelementptr inbounds i32, i32* %34, i32 1
store i32* %35, i32** %33
store i32 %32, i32* %34
%36 = load i32, i32* %6
%37 = shl i32 %36, 12
%38 = load i32, i32* %7
%39 = mul nsw i32 %38, 7258
%40 = add nsw i32 %37, %39
%41 = add nsw i32 %40, 2048
%42 = ashr i32 %41, 12
%43 = call i8* @clip(i32 %42)
%44 = ptrtoint i8* %43 to i32
%45 = load i32**, i32*** %5
%46 = load i32*, i32** %45
%47 = getelementptr inbounds i32, i32* %46, i32 1
store i32* %47, i32** %45
store i32 %44, i32* %46
ret void
}

LLVM IR (-O2):
define void @yuv_to_rgb(i32** nocapture %0, i32 %1, i32 %2, i32 %3) {
%5 = shl i32 %1, 12
%6 = mul nsw i32 %3, 5743
%7 = or i32 %5, 2048
%8 = add i32 %7, %6
%9 = ashr i32 %8, 12
%10 = tail call i8* @clip(i32 %9)
%11 = ptrtoint i8* %10 to i64
%12 = trunc i64 %11 to i32
%13 = load i32*, i32** %0
%14 = getelementptr inbounds i32, i32* %13, i64 1
store i32* %14, i32** %0
store i32 %12, i32* %13
%15 = mul i32 %2, -1411
%16 = mul i32 %3, -2925
%17 = add i32 %7, %15
%18 = add i32 %17, %16
%19 = ashr i32 %18, 12
%20 = tail call i8* @clip(i32 %19)
%21 = ptrtoint i8* %20 to i64
%22 = trunc i64 %21 to i32
%23 = load i32*, i32** %0
%24 = getelementptr inbounds i32, i32* %23, i64 1
store i32* %24, i32** %0
store i32 %22, i32* %23
%25 = mul nsw i32 %2, 7258
%26 = add i32 %7, %25
%27 = ashr i32 %26, 12
%28 = tail call i8* @clip(i32 %27)
%29 = ptrtoint i8* %28 to i64
%30 = trunc i64 %29 to i32
%31 = load i32*, i32** %0
%32 = getelementptr inbounds i32, i32* %31, i64 1
store i32* %32, i32** %0
store i32 %30, i32* %31
ret void
}