void transfer_YUV_PLANAR_to_YUV420P(unsigned char *input_y,
                                    unsigned char *input_u,
                                    unsigned char *input_v,
                                    unsigned char *output_y,
                                    unsigned char *output_u,
                                    unsigned char *output_v, int j) {
  output_y[j] = *input_y;
  output_u[j / 2] = *input_u;
  output_v[j / 2] = *input_v;
}


x86 assembly (clang, -O0):
<transfer_YUV_PLANAR_to_YUV420P>:
push   %rbp
mov    %rsp,%rbp
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%dl
mov    -0x20(%rbp),%rax
movslq 0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x49(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x10(%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    -0x18(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x39(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    0x10(%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_YUV_PLANAR_to_YUV420P>:
movslq 0x8(%rsp),%r10
mov    (%rdi),%al
mov    %al,(%rcx,%r10,1)
mov    (%rsi),%al
mov    %r10d,%ecx
shr    $0x1f,%ecx
add    %r10d,%ecx
sar    %ecx
movslq %ecx,%rcx
mov    %al,(%r8,%rcx,1)
mov    (%rdx),%al
mov    %al,(%r9,%rcx,1)
ret

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

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