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

/* Variables and functions */
void transfer_YUVA16161616_to_VYU888(unsigned char *(*output),
                                     uint16_t *input) {
  int y, u, v, a, anti_a;
  a = input[3];
  anti_a = 0xffff - a;
  y = ((uint32_t)input[0] * a) / 0xffff00;
  u = ((uint32_t)input[1] * a + 0x8000 * anti_a) / 0xffff00;
  v = ((uint32_t)input[2] * a + 0x8000 * anti_a) / 0xffff00;
  *(*output)++ = v;
  *(*output)++ = y;
  *(*output)++ = u;
}


x86 assembly (clang, -O0):
<transfer_YUVA16161616_to_VYU888>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0xc(%rax),%eax
mov    %eax,-0x20(%rbp)
mov    $0xffff,%eax
sub    -0x20(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
imul   -0x20(%rbp),%eax
mov    $0xffff00,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
imul   -0x20(%rbp),%eax
mov    -0x24(%rbp),%ecx
shl    $0xf,%ecx
add    %ecx,%eax
mov    $0xffff00,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%eax
imul   -0x20(%rbp),%eax
mov    -0x24(%rbp),%ecx
shl    $0xf,%ecx
add    %ecx,%eax
mov    $0xffff00,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %al,%cl
mov    -0x8(%rbp),%rdx
mov    (%rdx),%rax
mov    %rax,%rsi
add    $0x1,%rsi
mov    %rsi,(%rdx)
mov    %cl,(%rax)
mov    -0x14(%rbp),%eax
mov    %al,%cl
mov    -0x8(%rbp),%rdx
mov    (%rdx),%rax
mov    %rax,%rsi
add    $0x1,%rsi
mov    %rsi,(%rdx)
mov    %cl,(%rax)
mov    -0x18(%rbp),%eax
mov    %al,%cl
mov    -0x8(%rbp),%rdx
mov    (%rdx),%rax
mov    %rax,%rsi
add    $0x1,%rsi
mov    %rsi,(%rdx)
mov    %cl,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<transfer_YUVA16161616_to_VYU888>:
mov    0xc(%rsi),%r8d
mov    (%rsi),%eax
imul   %r8d,%eax
cltq
imul   $0xffffffff80008001,%rax,%rcx
shr    $0x20,%rcx
add    %ecx,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
shr    $0x17,%eax
add    %ecx,%eax
mov    0x4(%rsi),%ecx
imul   %r8d,%ecx
mov    %r8d,%edx
shl    $0xf,%edx
mov    $0x7fff8000,%r9d
sub    %edx,%r9d
add    %r9d,%ecx
movslq %ecx,%rcx
imul   $0xffffffff80008001,%rcx,%rdx
shr    $0x20,%rdx
add    %edx,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
shr    $0x17,%ecx
add    %edx,%ecx
imul   0x8(%rsi),%r8d
add    %r9d,%r8d
movslq %r8d,%rdx
imul   $0xffffffff80008001,%rdx,%rsi
shr    $0x20,%rsi
add    %esi,%edx
mov    %edx,%esi
shr    $0x1f,%esi
shr    $0x17,%edx
add    %esi,%edx
mov    (%rdi),%r8
lea    0x1(%r8),%rsi
mov    %rsi,(%rdi)
mov    %dl,(%r8)
mov    (%rdi),%rdx
lea    0x1(%rdx),%rsi
mov    %rsi,(%rdi)
mov    %al,(%rdx)
mov    (%rdi),%rax
lea    0x1(%rax),%rdx
mov    %rdx,(%rdi)
mov    %cl,(%rax)
ret

LLVM IR (-O0):
define void @transfer_YUVA16161616_to_VYU888(i8** %0, i32* %1) {
%3 = alloca i8**
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8** %0, i8*** %3
store i32* %1, i32** %4
%10 = load i32*, i32** %4
%11 = getelementptr inbounds i32, i32* %10, i64 3
%12 = load i32, i32* %11
store i32 %12, i32* %8
%13 = load i32, i32* %8
%14 = sub nsw i32 65535, %13
store i32 %14, i32* %9
%15 = load i32*, i32** %4
%16 = getelementptr inbounds i32, i32* %15, i64 0
%17 = load i32, i32* %16
%18 = load i32, i32* %8
%19 = mul nsw i32 %17, %18
%20 = sdiv i32 %19, 16776960
store i32 %20, i32* %5
%21 = load i32*, i32** %4
%22 = getelementptr inbounds i32, i32* %21, i64 1
%23 = load i32, i32* %22
%24 = load i32, i32* %8
%25 = mul nsw i32 %23, %24
%26 = load i32, i32* %9
%27 = mul nsw i32 32768, %26
%28 = add nsw i32 %25, %27
%29 = sdiv i32 %28, 16776960
store i32 %29, i32* %6
%30 = load i32*, i32** %4
%31 = getelementptr inbounds i32, i32* %30, i64 2
%32 = load i32, i32* %31
%33 = load i32, i32* %8
%34 = mul nsw i32 %32, %33
%35 = load i32, i32* %9
%36 = mul nsw i32 32768, %35
%37 = add nsw i32 %34, %36
%38 = sdiv i32 %37, 16776960
store i32 %38, i32* %7
%39 = load i32, i32* %7
%40 = trunc i32 %39 to i8
%41 = load i8**, i8*** %3
%42 = load i8*, i8** %41
%43 = getelementptr inbounds i8, i8* %42, i32 1
store i8* %43, i8** %41
store i8 %40, i8* %42
%44 = load i32, i32* %5
%45 = trunc i32 %44 to i8
%46 = load i8**, i8*** %3
%47 = load i8*, i8** %46
%48 = getelementptr inbounds i8, i8* %47, i32 1
store i8* %48, i8** %46
store i8 %45, i8* %47
%49 = load i32, i32* %6
%50 = trunc i32 %49 to i8
%51 = load i8**, i8*** %3
%52 = load i8*, i8** %51
%53 = getelementptr inbounds i8, i8* %52, i32 1
store i8* %53, i8** %51
store i8 %50, i8* %52
ret void
}

LLVM IR (-O2):
define void @transfer_YUVA16161616_to_VYU888(i8** nocapture %0, i32* nocapture %1) {
%3 = getelementptr inbounds i32, i32* %1, i64 3
%4 = load i32, i32* %3
%5 = load i32, i32* %1
%6 = mul nsw i32 %5, %4
%7 = sdiv i32 %6, 16776960
%8 = getelementptr inbounds i32, i32* %1, i64 1
%9 = load i32, i32* %8
%10 = mul nsw i32 %9, %4
%11 = mul i32 %4, -32768
%12 = add i32 %11, 2147450880
%13 = add nsw i32 %10, %12
%14 = sdiv i32 %13, 16776960
%15 = getelementptr inbounds i32, i32* %1, i64 2
%16 = load i32, i32* %15
%17 = mul nsw i32 %16, %4
%18 = add nsw i32 %17, %12
%19 = sdiv i32 %18, 16776960
%20 = trunc i32 %19 to i8
%21 = load i8*, i8** %0
%22 = getelementptr inbounds i8, i8* %21, i64 1
store i8* %22, i8** %0
store i8 %20, i8* %21
%23 = trunc i32 %7 to i8
%24 = load i8*, i8** %0
%25 = getelementptr inbounds i8, i8* %24, i64 1
store i8* %25, i8** %0
store i8 %23, i8* %24
%26 = trunc i32 %14 to i8
%27 = load i8*, i8** %0
%28 = getelementptr inbounds i8, i8* %27, i64 1
store i8* %28, i8** %0
store i8 %26, i8* %27
ret void
}