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

/* Variables and functions */
void transfer_YUV161616_to_YUV422(unsigned char *(*output), uint16_t *input,
                                  int j) {
  if (!(j & 1)) {
    (*output)[1] = input[1] >> 8;
    (*output)[3] = input[2] >> 8;
    (*output)[0] = input[0] >> 8;
  } else {
    (*output)[2] = input[0] >> 8;
    (*output) += 4;
  }
}


x86 assembly (clang, -O0):
<transfer_YUV161616_to_YUV422>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
jne    1163 <transfer_YUV161616_to_YUV422+0x63>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
sar    $0x8,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %cl,0x1(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%eax
sar    $0x8,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %cl,0x3(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
sar    $0x8,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %cl,(%rax)
jmp    1186 <transfer_YUV161616_to_YUV422+0x86>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
sar    $0x8,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %cl,0x2(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0x4,%rcx
mov    %rcx,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<transfer_YUV161616_to_YUV422>:
test   $0x1,%dl
jne    1120 <transfer_YUV161616_to_YUV422+0x20>
mov    0x5(%rsi),%al
mov    (%rdi),%rcx
mov    %al,0x1(%rcx)
mov    0x9(%rsi),%al
mov    (%rdi),%rcx
mov    %al,0x3(%rcx)
mov    0x1(%rsi),%al
mov    (%rdi),%rcx
mov    %al,(%rcx)
ret
mov    0x1(%rsi),%al
mov    (%rdi),%rcx
mov    %al,0x2(%rcx)
addq   $0x4,(%rdi)
ret

LLVM IR (-O0):
define void @transfer_YUV161616_to_YUV422(i8** %0, i32* %1, i32 %2) {
%4 = alloca i8**
%5 = alloca i32*
%6 = alloca i32
store i8** %0, i8*** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%7 = load i32, i32* %6
%8 = and i32 %7, 1
%9 = icmp ne i32 %8, 0
br i1 %9, label %35, label %10
10: ; preds = %3
%11 = load i32*, i32** %5
%12 = getelementptr inbounds i32, i32* %11, i64 1
%13 = load i32, i32* %12
%14 = ashr i32 %13, 8
%15 = trunc i32 %14 to i8
%16 = load i8**, i8*** %4
%17 = load i8*, i8** %16
%18 = getelementptr inbounds i8, i8* %17, i64 1
store i8 %15, i8* %18
%19 = load i32*, i32** %5
%20 = getelementptr inbounds i32, i32* %19, i64 2
%21 = load i32, i32* %20
%22 = ashr i32 %21, 8
%23 = trunc i32 %22 to i8
%24 = load i8**, i8*** %4
%25 = load i8*, i8** %24
%26 = getelementptr inbounds i8, i8* %25, i64 3
store i8 %23, i8* %26
%27 = load i32*, i32** %5
%28 = getelementptr inbounds i32, i32* %27, i64 0
%29 = load i32, i32* %28
%30 = ashr i32 %29, 8
%31 = trunc i32 %30 to i8
%32 = load i8**, i8*** %4
%33 = load i8*, i8** %32
%34 = getelementptr inbounds i8, i8* %33, i64 0
store i8 %31, i8* %34
br label %47
35: ; preds = %3
%36 = load i32*, i32** %5
%37 = getelementptr inbounds i32, i32* %36, i64 0
%38 = load i32, i32* %37
%39 = ashr i32 %38, 8
%40 = trunc i32 %39 to i8
%41 = load i8**, i8*** %4
%42 = load i8*, i8** %41
%43 = getelementptr inbounds i8, i8* %42, i64 2
store i8 %40, i8* %43
%44 = load i8**, i8*** %4
%45 = load i8*, i8** %44
%46 = getelementptr inbounds i8, i8* %45, i64 4
store i8* %46, i8** %44
br label %47
47: ; preds = %35, %10
ret void
}

LLVM IR (-O2):
define void @transfer_YUV161616_to_YUV422(i8** nocapture %0, i32* nocapture %1, i32 %2) {
%4 = and i32 %2, 1
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %23
6: ; preds = %3
%7 = getelementptr inbounds i32, i32* %1, i64 1
%8 = load i32, i32* %7
%9 = lshr i32 %8, 8
%10 = trunc i32 %9 to i8
%11 = load i8*, i8** %0
%12 = getelementptr inbounds i8, i8* %11, i64 1
store i8 %10, i8* %12
%13 = getelementptr inbounds i32, i32* %1, i64 2
%14 = load i32, i32* %13
%15 = lshr i32 %14, 8
%16 = trunc i32 %15 to i8
%17 = load i8*, i8** %0
%18 = getelementptr inbounds i8, i8* %17, i64 3
store i8 %16, i8* %18
%19 = load i32, i32* %1
%20 = lshr i32 %19, 8
%21 = trunc i32 %20 to i8
%22 = load i8*, i8** %0
store i8 %21, i8* %22
br label %31
23: ; preds = %3
%24 = load i32, i32* %1
%25 = lshr i32 %24, 8
%26 = trunc i32 %25 to i8
%27 = load i8*, i8** %0
%28 = getelementptr inbounds i8, i8* %27, i64 2
store i8 %26, i8* %28
%29 = load i8*, i8** %0
%30 = getelementptr inbounds i8, i8* %29, i64 4
store i8* %30, i8** %0
br label %31
31: ; preds = %23, %6
ret void
}