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

/* Variables and functions */
void transfer_YUVA16161616_to_YUV420P_YUV422P(unsigned char *output_y,
                                              unsigned char *output_u,
                                              unsigned char *output_v,
                                              uint16_t *input,
                                              int output_column) {
  int64_t opacity = input[3];
  int64_t transparency = 0xffff - opacity;
  output_y[output_column] = ((int64_t)input[0] * opacity) / 0xffff00;
  output_u[output_column / 2] =
      ((int64_t)input[1] * opacity + 0x8000 * transparency) / 0xffff00;
  output_v[output_column / 2] =
      ((int64_t)input[2] * opacity + 0x8000 * transparency) / 0xffff00;
}


x86 assembly (clang, -O0):
<transfer_YUVA16161616_to_YUV420P_YUV422P>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    -0x20(%rbp),%rax
mov    0xc(%rax),%eax
mov    %eax,-0x28(%rbp)
mov    $0xffff,%eax
sub    -0x28(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
imul   -0x28(%rbp),%eax
mov    $0xffff00,%ecx
cltd
idiv   %ecx
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%eax
imul   -0x28(%rbp),%eax
mov    -0x2c(%rbp),%ecx
shl    $0xf,%ecx
add    %ecx,%eax
mov    $0xffff00,%ecx
cltd
idiv   %ecx
mov    %al,-0x49(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x24(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x49(%rbp),%dl
mov    %eax,%ecx
mov    -0x48(%rbp),%rax
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%eax
imul   -0x28(%rbp),%eax
mov    -0x2c(%rbp),%ecx
shl    $0xf,%ecx
add    %ecx,%eax
mov    $0xffff00,%ecx
cltd
idiv   %ecx
mov    %al,-0x39(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x24(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x39(%rbp),%dl
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
pop    %rbp
ret

x86 assembly (clang, -O2):
<transfer_YUVA16161616_to_YUV420P_YUV422P>:
mov    0xc(%rcx),%r9d
mov    (%rcx),%eax
imul   %r9d,%eax
movslq %eax,%r10
imul   $0xffffffff80008001,%r10,%rax
shr    $0x20,%rax
add    %eax,%r10d
mov    %r10d,%eax
shr    $0x1f,%eax
shr    $0x17,%r10d
add    %eax,%r10d
movslq %r8d,%r8
mov    %r10b,(%rdi,%r8,1)
mov    0x4(%rcx),%eax
imul   %r9d,%eax
mov    %r9d,%edi
shl    $0xf,%edi
mov    $0x7fff8000,%r10d
sub    %edi,%r10d
add    %r10d,%eax
cltq
imul   $0xffffffff80008001,%rax,%rdi
shr    $0x20,%rdi
add    %edi,%eax
mov    %eax,%edi
shr    $0x1f,%edi
shr    $0x17,%eax
add    %edi,%eax
mov    %r8d,%edi
shr    $0x1f,%edi
add    %r8d,%edi
sar    %edi
movslq %edi,%rdi
mov    %al,(%rsi,%rdi,1)
imul   0x8(%rcx),%r9d
add    %r10d,%r9d
movslq %r9d,%rax
imul   $0xffffffff80008001,%rax,%rcx
shr    $0x20,%rcx
add    %ecx,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
shr    $0x17,%eax
add    %ecx,%eax
mov    %al,(%rdx,%rdi,1)
ret

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

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