#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_YUV888_to_YUV101010(unsigned char *(*output),
                                  unsigned char *input) {
  uint16_t y_i = ((uint16_t)input[0]) << 8;
  uint16_t u_i = ((uint16_t)input[1]) << 8;
  uint16_t v_i = ((uint16_t)input[2]) << 8;
  {
    uint32_t output_i =
        ((y_i & 0xffc0) << 16) | ((u_i & 0xffc0) << 6) | ((v_i & 0xffc0) >> 4);
    *(*output)++ = (output_i & 0xff);
    *(*output)++ = (output_i & 0xff00) >> 8;
    *(*output)++ = (output_i & 0xff0000) >> 16;
    *(*output)++ = (output_i & 0xff000000) >> 24;
  };
}


x86 assembly (clang, -O0):
<transfer_YUV888_to_YUV101010>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
shl    $0x8,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movzbl 0x1(%rax),%eax
shl    $0x8,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movzbl 0x2(%rax),%eax
shl    $0x8,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
and    $0xffc0,%eax
shl    $0x10,%eax
mov    -0x18(%rbp),%ecx
and    $0xffc0,%ecx
shl    $0x6,%ecx
or     %ecx,%eax
mov    -0x1c(%rbp),%ecx
and    $0xffc0,%ecx
sar    $0x4,%ecx
or     %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rdx
mov    (%rdx),%rax
mov    %rax,%rsi
add    $0x1,%rsi
mov    %rsi,(%rdx)
mov    %cl,(%rax)
mov    -0x20(%rbp),%eax
and    $0xff00,%eax
sar    $0x8,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rdx
mov    (%rdx),%rax
mov    %rax,%rsi
add    $0x1,%rsi
mov    %rsi,(%rdx)
mov    %cl,(%rax)
mov    -0x20(%rbp),%eax
and    $0xff0000,%eax
sar    $0x10,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rdx
mov    (%rdx),%rax
mov    %rax,%rsi
add    $0x1,%rsi
mov    %rsi,(%rdx)
mov    %cl,(%rax)
mov    -0x20(%rbp),%eax
and    $0xff000000,%eax
shr    $0x18,%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_YUV888_to_YUV101010>:
mov    (%rsi),%r8b
movzbl 0x1(%rsi),%r9d
mov    %r9d,%eax
shl    $0xe,%eax
movzbl 0x2(%rsi),%esi
shl    $0x4,%esi
or     %esi,%eax
mov    (%rdi),%rcx
lea    0x1(%rcx),%rdx
mov    %rdx,(%rdi)
mov    %sil,(%rcx)
mov    (%rdi),%rcx
lea    0x1(%rcx),%rdx
mov    %rdx,(%rdi)
mov    %ah,(%rcx)
shr    $0x2,%r9b
mov    (%rdi),%rax
lea    0x1(%rax),%rcx
mov    %rcx,(%rdi)
mov    %r9b,(%rax)
mov    (%rdi),%rax
lea    0x1(%rax),%rcx
mov    %rcx,(%rdi)
mov    %r8b,(%rax)
ret

LLVM IR (-O0):
define void @transfer_YUV888_to_YUV101010(i8** %0, i8* %1) {
%3 = alloca i8**
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8** %0, i8*** %3
store i8* %1, i8** %4
%9 = load i8*, i8** %4
%10 = getelementptr inbounds i8, i8* %9, i64 0
%11 = load i8, i8* %10
%12 = zext i8 %11 to i32
%13 = shl i32 %12, 8
store i32 %13, i32* %5
%14 = load i8*, i8** %4
%15 = getelementptr inbounds i8, i8* %14, i64 1
%16 = load i8, i8* %15
%17 = zext i8 %16 to i32
%18 = shl i32 %17, 8
store i32 %18, i32* %6
%19 = load i8*, i8** %4
%20 = getelementptr inbounds i8, i8* %19, i64 2
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = shl i32 %22, 8
store i32 %23, i32* %7
%24 = load i32, i32* %5
%25 = and i32 %24, 65472
%26 = shl i32 %25, 16
%27 = load i32, i32* %6
%28 = and i32 %27, 65472
%29 = shl i32 %28, 6
%30 = or i32 %26, %29
%31 = load i32, i32* %7
%32 = and i32 %31, 65472
%33 = ashr i32 %32, 4
%34 = or i32 %30, %33
store i32 %34, i32* %8
%35 = load i32, i32* %8
%36 = and i32 %35, 255
%37 = trunc i32 %36 to i8
%38 = load i8**, i8*** %3
%39 = load i8*, i8** %38
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %38
store i8 %37, i8* %39
%41 = load i32, i32* %8
%42 = and i32 %41, 65280
%43 = ashr i32 %42, 8
%44 = trunc i32 %43 to i8
%45 = load i8**, i8*** %3
%46 = load i8*, i8** %45
%47 = getelementptr inbounds i8, i8* %46, i32 1
store i8* %47, i8** %45
store i8 %44, i8* %46
%48 = load i32, i32* %8
%49 = and i32 %48, 16711680
%50 = ashr i32 %49, 16
%51 = trunc i32 %50 to i8
%52 = load i8**, i8*** %3
%53 = load i8*, i8** %52
%54 = getelementptr inbounds i8, i8* %53, i32 1
store i8* %54, i8** %52
store i8 %51, i8* %53
%55 = load i32, i32* %8
%56 = and i32 %55, -16777216
%57 = lshr i32 %56, 24
%58 = trunc i32 %57 to i8
%59 = load i8**, i8*** %3
%60 = load i8*, i8** %59
%61 = getelementptr inbounds i8, i8* %60, i32 1
store i8* %61, i8** %59
store i8 %58, i8* %60
ret void
}

LLVM IR (-O2):
define void @transfer_YUV888_to_YUV101010(i8** nocapture %0, i8* nocapture %1) {
%3 = load i8, i8* %1
%4 = getelementptr inbounds i8, i8* %1, i64 1
%5 = load i8, i8* %4
%6 = zext i8 %5 to i32
%7 = shl nuw nsw i32 %6, 14
%8 = getelementptr inbounds i8, i8* %1, i64 2
%9 = load i8, i8* %8
%10 = zext i8 %9 to i32
%11 = shl nuw nsw i32 %10, 4
%12 = or i32 %11, %7
%13 = trunc i32 %11 to i8
%14 = load i8*, i8** %0
%15 = getelementptr inbounds i8, i8* %14, i64 1
store i8* %15, i8** %0
store i8 %13, i8* %14
%16 = lshr i32 %12, 8
%17 = trunc i32 %16 to i8
%18 = load i8*, i8** %0
%19 = getelementptr inbounds i8, i8* %18, i64 1
store i8* %19, i8** %0
store i8 %17, i8* %18
%20 = lshr i8 %5, 2
%21 = load i8*, i8** %0
%22 = getelementptr inbounds i8, i8* %21, i64 1
store i8* %22, i8** %0
store i8 %20, i8* %21
%23 = load i8*, i8** %0
%24 = getelementptr inbounds i8, i8* %23, i64 1
store i8* %24, i8** %0
store i8 %3, i8* %23
ret void
}