void transfer_YUV888_to_YUV420P_YUV422P(unsigned char *output_y,
                                        unsigned char *output_u,
                                        unsigned char *output_v,
                                        unsigned char *input,
                                        int output_column) {
  output_y[output_column] = input[0];
  output_u[output_column / 2] = input[1];
  output_v[output_column / 2] = input[2];
}


x86 assembly (clang, -O0):
<transfer_YUV888_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),%dl
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    0x1(%rax),%al
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    0x2(%rax),%al
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_YUV888_to_YUV420P_YUV422P>:
mov    (%rcx),%r9b
movslq %r8d,%rax
mov    %r9b,(%rdi,%rax,1)
mov    0x1(%rcx),%r8b
mov    %eax,%edi
shr    $0x1f,%edi
add    %eax,%edi
sar    %edi
movslq %edi,%rax
mov    %r8b,(%rsi,%rax,1)
mov    0x2(%rcx),%cl
mov    %cl,(%rdx,%rax,1)
ret

LLVM IR (-O0):
define void @transfer_YUV888_to_YUV420P_YUV422P(i8* %0, i8* %1, i8* %2, i8* %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i32 %4, i32* %10
%11 = load i8*, i8** %9
%12 = getelementptr inbounds i8, i8* %11, i64 0
%13 = load i8, i8* %12
%14 = load i8*, i8** %6
%15 = load i32, i32* %10
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
store i8 %13, i8* %17
%18 = load i8*, i8** %9
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = load i8, i8* %19
%21 = load i8*, i8** %7
%22 = load i32, i32* %10
%23 = sdiv i32 %22, 2
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %21, i64 %24
store i8 %20, i8* %25
%26 = load i8*, i8** %9
%27 = getelementptr inbounds i8, i8* %26, i64 2
%28 = load i8, i8* %27
%29 = load i8*, i8** %8
%30 = load i32, i32* %10
%31 = sdiv i32 %30, 2
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %29, i64 %32
store i8 %28, i8* %33
ret void
}

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