#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 unsigned char uint16_t;

/* Variables and functions */
void transfer_YUVA8888_to_YUV101010(unsigned char *(*output),
                                    unsigned char *input) {
  uint16_t y_i = ((uint16_t)input[0] * input[3]) + 0x1fe;
  uint16_t u_i = ((uint16_t)input[1] * input[3]) + 0x1fe;
  uint16_t v_i = ((uint16_t)input[2] * input[3]) + 0x1fe;
  {
    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_YUVA8888_to_YUV101010>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
mov    -0x10(%rbp),%rcx
movzbl 0x3(%rcx),%ecx
imul   %ecx,%eax
add    $0x1fe,%eax
mov    %al,-0x11(%rbp)
mov    -0x10(%rbp),%rax
movzbl 0x1(%rax),%eax
mov    -0x10(%rbp),%rcx
movzbl 0x3(%rcx),%ecx
imul   %ecx,%eax
add    $0x1fe,%eax
mov    %al,-0x12(%rbp)
mov    -0x10(%rbp),%rax
movzbl 0x2(%rax),%eax
mov    -0x10(%rbp),%rcx
movzbl 0x3(%rcx),%ecx
imul   %ecx,%eax
add    $0x1fe,%eax
mov    %al,-0x13(%rbp)
movzbl -0x11(%rbp),%eax
and    $0xffc0,%eax
shl    $0x10,%eax
movzbl -0x12(%rbp),%ecx
and    $0xffc0,%ecx
shl    $0x6,%ecx
or     %ecx,%eax
movzbl -0x13(%rbp),%ecx
and    $0xffc0,%ecx
sar    $0x4,%ecx
or     %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%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    -0x18(%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    -0x18(%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    -0x18(%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_YUVA8888_to_YUV101010>:
mov    0x3(%rsi),%dl
mov    %edx,%eax
mulb   (%rsi)
mov    %eax,%r8d
add    $0xfe,%r8b
mov    0x1(%rsi),%al
mov    0x2(%rsi),%sil
mul    %dl
mov    %eax,%ecx
add    $0xfe,%cl
mov    %esi,%eax
mul    %dl
add    $0xfe,%al
and    $0xc0,%r8b
shr    $0x4,%al
and    $0xc,%al
mov    (%rdi),%rdx
lea    0x1(%rdx),%rsi
mov    %rsi,(%rdi)
mov    %al,(%rdx)
shr    $0x2,%cl
and    $0x30,%cl
mov    (%rdi),%rax
lea    0x1(%rax),%rdx
mov    %rdx,(%rdi)
mov    %cl,(%rax)
mov    (%rdi),%rax
lea    0x1(%rax),%rcx
mov    %rcx,(%rdi)
mov    %r8b,(%rax)
mov    (%rdi),%rax
lea    0x1(%rax),%rcx
mov    %rcx,(%rdi)
movb   $0x0,(%rax)
ret

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

LLVM IR (-O2):
define void @transfer_YUVA8888_to_YUV101010(i8** nocapture %0, i8* nocapture %1) {
%3 = load i8, i8* %1
%4 = getelementptr inbounds i8, i8* %1, i64 3
%5 = load i8, i8* %4
%6 = mul i8 %5, %3
%7 = add i8 %6, -2
%8 = getelementptr inbounds i8, i8* %1, i64 1
%9 = load i8, i8* %8
%10 = mul i8 %9, %5
%11 = add i8 %10, -2
%12 = getelementptr inbounds i8, i8* %1, i64 2
%13 = load i8, i8* %12
%14 = mul i8 %13, %5
%15 = add i8 %14, -2
%16 = and i8 %7, -64
%17 = lshr i8 %15, 4
%18 = and i8 %17, 12
%19 = load i8*, i8** %0
%20 = getelementptr inbounds i8, i8* %19, i64 1
store i8* %20, i8** %0
store i8 %18, i8* %19
%21 = lshr i8 %11, 2
%22 = and i8 %21, 48
%23 = load i8*, i8** %0
%24 = getelementptr inbounds i8, i8* %23, i64 1
store i8* %24, i8** %0
store i8 %22, i8* %23
%25 = load i8*, i8** %0
%26 = getelementptr inbounds i8, i8* %25, i64 1
store i8* %26, i8** %0
store i8 %16, i8* %25
%27 = load i8*, i8** %0
%28 = getelementptr inbounds i8, i8* %27, i64 1
store i8* %28, i8** %0
store i8 0, i8* %27
ret void
}