#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_YUV161616_to_YUV101010(unsigned char *(*output),
                                     uint16_t *input) {
  uint16_t y_i = input[0];
  uint16_t u_i = input[1];
  uint16_t v_i = input[2];
  {
    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_YUV161616_to_YUV101010>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%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_YUV161616_to_YUV101010>:
push   %rbx
mov    (%rsi),%edx
mov    0x4(%rsi),%eax
mov    0x8(%rsi),%esi
mov    %edx,%ecx
mov    %edx,%r8d
shl    $0x10,%ecx
and    $0xc00000,%ecx
shl    $0x6,%eax
and    $0x3ff000,%eax
or     %eax,%ecx
shr    $0x4,%esi
mov    %esi,%edx
and    $0xf00,%edx
or     %eax,%edx
and    $0xfc,%sil
mov    (%rdi),%rax
lea    0x1(%rax),%rbx
mov    %rbx,(%rdi)
mov    %sil,(%rax)
mov    (%rdi),%rax
lea    0x1(%rax),%rsi
mov    %rsi,(%rdi)
mov    %dh,(%rax)
shr    $0x10,%ecx
mov    (%rdi),%rax
lea    0x1(%rax),%rdx
mov    %rdx,(%rdi)
mov    %cl,(%rax)
mov    (%rdi),%rax
lea    0x1(%rax),%rcx
mov    %rcx,(%rdi)
mov    %r8d,%ecx
mov    %ch,(%rax)
pop    %rbx
ret

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

LLVM IR (-O2):
define void @transfer_YUV161616_to_YUV101010(i8** nocapture %0, i32* nocapture %1) {
%3 = load i32, i32* %1
%4 = getelementptr inbounds i32, i32* %1, i64 1
%5 = load i32, i32* %4
%6 = getelementptr inbounds i32, i32* %1, i64 2
%7 = load i32, i32* %6
%8 = shl i32 %3, 16
%9 = and i32 %8, 12582912
%10 = shl i32 %5, 6
%11 = and i32 %10, 4190208
%12 = or i32 %11, %9
%13 = lshr i32 %7, 4
%14 = and i32 %13, 3840
%15 = or i32 %14, %11
%16 = trunc i32 %13 to i8
%17 = and i8 %16, -4
%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 exact i32 %15, 8
%21 = trunc i32 %20 to i8
%22 = load i8*, i8** %0
%23 = getelementptr inbounds i8, i8* %22, i64 1
store i8* %23, i8** %0
store i8 %21, i8* %22
%24 = lshr i32 %12, 16
%25 = trunc i32 %24 to i8
%26 = load i8*, i8** %0
%27 = getelementptr inbounds i8, i8* %26, i64 1
store i8* %27, i8** %0
store i8 %25, i8* %26
%28 = lshr i32 %8, 24
%29 = trunc i32 %28 to i8
%30 = load i8*, i8** %0
%31 = getelementptr inbounds i8, i8* %30, i64 1
store i8* %31, i8** %0
store i8 %29, i8* %30
ret void
}