#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;
typedef int int64_t;

/* Variables and functions */
void transfer_YUVA16161616_to_YUV101010(unsigned char *(*output),
                                        uint16_t *input) {
  int64_t opacity = input[3];
  int64_t transparency = 0xffff - opacity;
  uint16_t y_i =
      ((int64_t)input[0] * opacity + (int64_t)0x8000 * transparency) / 0xffff;
  uint16_t u_i =
      ((int64_t)input[1] * opacity + (int64_t)0x8000 * transparency) / 0xffff;
  uint16_t v_i =
      ((int64_t)input[2] * opacity + (int64_t)0x8000 * transparency) / 0xffff;
  {
    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_YUVA16161616_to_YUV101010>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0xc(%rax),%eax
mov    %eax,-0x14(%rbp)
mov    $0xffff,%eax
sub    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
imul   -0x14(%rbp),%eax
mov    -0x18(%rbp),%ecx
shl    $0xf,%ecx
add    %ecx,%eax
mov    $0xffff,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
imul   -0x14(%rbp),%eax
mov    -0x18(%rbp),%ecx
shl    $0xf,%ecx
add    %ecx,%eax
mov    $0xffff,%ecx
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%eax
imul   -0x14(%rbp),%eax
mov    -0x18(%rbp),%ecx
shl    $0xf,%ecx
add    %ecx,%eax
mov    $0xffff,%ecx
cltd
idiv   %ecx
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
and    $0xffc0,%eax
shl    $0x10,%eax
mov    -0x20(%rbp),%ecx
and    $0xffc0,%ecx
shl    $0x6,%ecx
or     %ecx,%eax
mov    -0x24(%rbp),%ecx
and    $0xffc0,%ecx
sar    $0x4,%ecx
or     %ecx,%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%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    -0x28(%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    -0x28(%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    -0x28(%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_YUVA16161616_to_YUV101010>:
push   %rbx
mov    0xc(%rsi),%ecx
mov    (%rsi),%eax
imul   %ecx,%eax
mov    %ecx,%edx
shl    $0xf,%edx
mov    $0x7fff8000,%r8d
sub    %edx,%r8d
add    %r8d,%eax
cltq
imul   $0xffffffff80008001,%rax,%rdx
shr    $0x20,%rdx
add    %edx,%eax
mov    %eax,%edx
shr    $0x1f,%edx
sar    $0xf,%eax
add    %edx,%eax
mov    0x4(%rsi),%edx
imul   %ecx,%edx
add    %r8d,%edx
movslq %edx,%rdx
imul   $0xffffffff80008001,%rdx,%rbx
shr    $0x20,%rbx
add    %ebx,%edx
mov    %edx,%ebx
shr    $0x1f,%ebx
shr    $0xf,%edx
add    %ebx,%edx
imul   0x8(%rsi),%ecx
add    %r8d,%ecx
movslq %ecx,%rcx
imul   $0xffffffff80008001,%rcx,%rsi
shr    $0x20,%rsi
add    %esi,%ecx
mov    %ecx,%esi
shr    $0x1f,%esi
sar    $0xf,%ecx
add    %esi,%ecx
mov    %eax,%esi
mov    %rax,%r8
shl    $0x10,%esi
and    $0xc00000,%esi
shl    $0x6,%edx
and    $0x3ff000,%edx
or     %edx,%esi
shr    $0x4,%ecx
mov    %ecx,%ebx
and    $0xf00,%ebx
or     %edx,%ebx
and    $0xfc,%cl
mov    (%rdi),%rdx
lea    0x1(%rdx),%rax
mov    %rax,(%rdi)
mov    %cl,(%rdx)
mov    (%rdi),%rax
lea    0x1(%rax),%rcx
mov    %rcx,(%rdi)
mov    %bh,(%rax)
shr    $0x10,%esi
mov    (%rdi),%rax
lea    0x1(%rax),%rcx
mov    %rcx,(%rdi)
mov    %sil,(%rax)
mov    (%rdi),%rax
lea    0x1(%rax),%rcx
mov    %rcx,(%rdi)
mov    %r8,%rcx
mov    %ch,(%rax)
pop    %rbx
ret

LLVM IR (-O0):
define void @transfer_YUVA16161616_to_YUV101010(i8** %0, i32* %1) {
%3 = alloca i8**
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8** %0, i8*** %3
store i32* %1, i32** %4
%11 = load i32*, i32** %4
%12 = getelementptr inbounds i32, i32* %11, i64 3
%13 = load i32, i32* %12
store i32 %13, i32* %5
%14 = load i32, i32* %5
%15 = sub nsw i32 65535, %14
store i32 %15, i32* %6
%16 = load i32*, i32** %4
%17 = getelementptr inbounds i32, i32* %16, i64 0
%18 = load i32, i32* %17
%19 = load i32, i32* %5
%20 = mul nsw i32 %18, %19
%21 = load i32, i32* %6
%22 = mul nsw i32 32768, %21
%23 = add nsw i32 %20, %22
%24 = sdiv i32 %23, 65535
store i32 %24, i32* %7
%25 = load i32*, i32** %4
%26 = getelementptr inbounds i32, i32* %25, i64 1
%27 = load i32, i32* %26
%28 = load i32, i32* %5
%29 = mul nsw i32 %27, %28
%30 = load i32, i32* %6
%31 = mul nsw i32 32768, %30
%32 = add nsw i32 %29, %31
%33 = sdiv i32 %32, 65535
store i32 %33, i32* %8
%34 = load i32*, i32** %4
%35 = getelementptr inbounds i32, i32* %34, i64 2
%36 = load i32, i32* %35
%37 = load i32, i32* %5
%38 = mul nsw i32 %36, %37
%39 = load i32, i32* %6
%40 = mul nsw i32 32768, %39
%41 = add nsw i32 %38, %40
%42 = sdiv i32 %41, 65535
store i32 %42, i32* %9
%43 = load i32, i32* %7
%44 = and i32 %43, 65472
%45 = shl i32 %44, 16
%46 = load i32, i32* %8
%47 = and i32 %46, 65472
%48 = shl i32 %47, 6
%49 = or i32 %45, %48
%50 = load i32, i32* %9
%51 = and i32 %50, 65472
%52 = ashr i32 %51, 4
%53 = or i32 %49, %52
store i32 %53, i32* %10
%54 = load i32, i32* %10
%55 = and i32 %54, 255
%56 = trunc i32 %55 to i8
%57 = load i8**, i8*** %3
%58 = load i8*, i8** %57
%59 = getelementptr inbounds i8, i8* %58, i32 1
store i8* %59, i8** %57
store i8 %56, i8* %58
%60 = load i32, i32* %10
%61 = and i32 %60, 65280
%62 = ashr i32 %61, 8
%63 = trunc i32 %62 to i8
%64 = load i8**, i8*** %3
%65 = load i8*, i8** %64
%66 = getelementptr inbounds i8, i8* %65, i32 1
store i8* %66, i8** %64
store i8 %63, i8* %65
%67 = load i32, i32* %10
%68 = and i32 %67, 16711680
%69 = ashr i32 %68, 16
%70 = trunc i32 %69 to i8
%71 = load i8**, i8*** %3
%72 = load i8*, i8** %71
%73 = getelementptr inbounds i8, i8* %72, i32 1
store i8* %73, i8** %71
store i8 %70, i8* %72
%74 = load i32, i32* %10
%75 = and i32 %74, -16777216
%76 = lshr i32 %75, 24
%77 = trunc i32 %76 to i8
%78 = load i8**, i8*** %3
%79 = load i8*, i8** %78
%80 = getelementptr inbounds i8, i8* %79, i32 1
store i8* %80, i8** %78
store i8 %77, i8* %79
ret void
}

LLVM IR (-O2):
define void @transfer_YUVA16161616_to_YUV101010(i8** nocapture %0, i32* nocapture %1) {
%3 = getelementptr inbounds i32, i32* %1, i64 3
%4 = load i32, i32* %3
%5 = load i32, i32* %1
%6 = mul nsw i32 %5, %4
%7 = mul i32 %4, -32768
%8 = add i32 %7, 2147450880
%9 = add nsw i32 %6, %8
%10 = sdiv i32 %9, 65535
%11 = getelementptr inbounds i32, i32* %1, i64 1
%12 = load i32, i32* %11
%13 = mul nsw i32 %12, %4
%14 = add nsw i32 %13, %8
%15 = sdiv i32 %14, 65535
%16 = getelementptr inbounds i32, i32* %1, i64 2
%17 = load i32, i32* %16
%18 = mul nsw i32 %17, %4
%19 = add nsw i32 %18, %8
%20 = sdiv i32 %19, 65535
%21 = shl i32 %10, 16
%22 = and i32 %21, 12582912
%23 = shl nsw i32 %15, 6
%24 = and i32 %23, 4190208
%25 = or i32 %24, %22
%26 = lshr i32 %20, 4
%27 = and i32 %26, 3840
%28 = or i32 %27, %24
%29 = trunc i32 %26 to i8
%30 = and i8 %29, -4
%31 = load i8*, i8** %0
%32 = getelementptr inbounds i8, i8* %31, i64 1
store i8* %32, i8** %0
store i8 %30, i8* %31
%33 = lshr exact i32 %28, 8
%34 = trunc i32 %33 to i8
%35 = load i8*, i8** %0
%36 = getelementptr inbounds i8, i8* %35, i64 1
store i8* %36, i8** %0
store i8 %34, i8* %35
%37 = lshr i32 %25, 16
%38 = trunc i32 %37 to i8
%39 = load i8*, i8** %0
%40 = getelementptr inbounds i8, i8* %39, i64 1
store i8* %40, i8** %0
store i8 %38, i8* %39
%41 = lshr i32 %21, 24
%42 = trunc i32 %41 to i8
%43 = load i8*, i8** %0
%44 = getelementptr inbounds i8, i8* %43, i64 1
store i8* %44, i8** %0
store i8 %42, i8* %43
ret void
}