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

/* Variables and functions */
void transfer_YUV161616_to_YUV420P_YUV422P(unsigned char *output_y,
                                           unsigned char *output_u,
                                           unsigned char *output_v,
                                           uint16_t *input, int output_column) {
  output_y[output_column] = input[0] >> 8;
  output_u[output_column / 2] = input[1] >> 8;
  output_v[output_column / 2] = input[2] >> 8;
}


x86 assembly (clang, -O0):
<transfer_YUV161616_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    (%rax),%eax
sar    $0x8,%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%eax
sar    $0x8,%eax
mov    %al,-0x41(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x24(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x41(%rbp),%dl
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%eax
sar    $0x8,%eax
mov    %al,-0x31(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x24(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x31(%rbp),%dl
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
pop    %rbp
ret

x86 assembly (clang, -O2):
<transfer_YUV161616_to_YUV420P_YUV422P>:
mov    0x1(%rcx),%r9b
movslq %r8d,%rax
mov    %r9b,(%rdi,%rax,1)
mov    0x5(%rcx),%r8b
mov    %eax,%edi
shr    $0x1f,%edi
add    %eax,%edi
sar    %edi
movslq %edi,%rax
mov    %r8b,(%rsi,%rax,1)
mov    0x9(%rcx),%cl
mov    %cl,(%rdx,%rax,1)
ret

LLVM IR (-O0):
define void @transfer_YUV161616_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
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
%11 = load i32*, i32** %9
%12 = getelementptr inbounds i32, i32* %11, i64 0
%13 = load i32, i32* %12
%14 = ashr i32 %13, 8
%15 = trunc i32 %14 to i8
%16 = load i8*, i8** %6
%17 = load i32, i32* %10
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
store i8 %15, i8* %19
%20 = load i32*, i32** %9
%21 = getelementptr inbounds i32, i32* %20, i64 1
%22 = load i32, i32* %21
%23 = ashr i32 %22, 8
%24 = trunc i32 %23 to i8
%25 = load i8*, i8** %7
%26 = load i32, i32* %10
%27 = sdiv i32 %26, 2
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %25, i64 %28
store i8 %24, i8* %29
%30 = load i32*, i32** %9
%31 = getelementptr inbounds i32, i32* %30, i64 2
%32 = load i32, i32* %31
%33 = ashr i32 %32, 8
%34 = trunc i32 %33 to i8
%35 = load i8*, i8** %8
%36 = load i32, i32* %10
%37 = sdiv i32 %36, 2
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %35, i64 %38
store i8 %34, i8* %39
ret void
}

LLVM IR (-O2):
define void @transfer_YUV161616_to_YUV420P_YUV422P(i8* nocapture writeonly %0, i8* nocapture writeonly %1, i8* nocapture writeonly %2, i32* nocapture %3, i32 %4) {
%6 = load i32, i32* %3
%7 = lshr i32 %6, 8
%8 = trunc i32 %7 to i8
%9 = sext i32 %4 to i64
%10 = getelementptr inbounds i8, i8* %0, i64 %9
store i8 %8, i8* %10
%11 = getelementptr inbounds i32, i32* %3, i64 1
%12 = load i32, i32* %11
%13 = lshr i32 %12, 8
%14 = trunc i32 %13 to i8
%15 = sdiv i32 %4, 2
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %1, i64 %16
store i8 %14, i8* %17
%18 = getelementptr inbounds i32, i32* %3, i64 2
%19 = load i32, i32* %18
%20 = lshr i32 %19, 8
%21 = trunc i32 %20 to i8
%22 = getelementptr inbounds i8, i8* %2, i64 %16
store i8 %21, i8* %22
ret void
}