#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 */

/* Variables and functions */
int /*<<< orphan*/ matrix(unsigned char, unsigned char, unsigned char,
                          unsigned char *, unsigned char *, unsigned char *);
void yuv2rgb(unsigned char *in, unsigned char *out, int length) {
  unsigned char r, g, b, y1, y2, u, v;
  length >>= 2;
  while (length--) {
    y1 = *in++;
    u = *in++;
    y2 = *in++;
    v = *in++;
    matrix(y1, u, v, &r, &g, &b);
    *out++ = r;
    *out++ = g;
    *out++ = b;
    matrix(y2, u, v, &r, &g, &b);
    *out++ = r;
    *out++ = g;
    *out++ = b;
  }
}


x86 assembly (clang, -O0):
<yuv2rgb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
sar    $0x2,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
je     124f <yuv2rgb+0x13f>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%al
mov    %al,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%al
mov    %al,-0x1a(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%al
mov    %al,-0x19(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%al
mov    %al,-0x1b(%rbp)
mov    -0x18(%rbp),%dl
mov    -0x1a(%rbp),%al
lea    -0x15(%rbp),%rcx
lea    -0x16(%rbp),%r8
lea    -0x17(%rbp),%r9
movzbl %dl,%edi
movzbl %al,%esi
movzbl -0x1b(%rbp),%edx
call   1030 <matrix@plt>
mov    -0x15(%rbp),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x16(%rbp),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x17(%rbp),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x19(%rbp),%dl
mov    -0x1a(%rbp),%al
lea    -0x15(%rbp),%rcx
lea    -0x16(%rbp),%r8
lea    -0x17(%rbp),%r9
movzbl %dl,%edi
movzbl %al,%esi
movzbl -0x1b(%rbp),%edx
call   1030 <matrix@plt>
mov    -0x15(%rbp),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x16(%rbp),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x17(%rbp),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
jmp    112c <yuv2rgb+0x1c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<yuv2rgb>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,0x10(%rsp)
cmp    $0x4,%edx
jb     11df <yuv2rgb+0xcf>
mov    %rsi,%rbx
mov    %rdi,%r15
mov    0x10(%rsp),%rax
sar    $0x2,%eax
mov    %rax,0x10(%rsp)
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%r15,%rbp,4),%edi
movzbl 0x1(%r15,%rbp,4),%r12d
movzbl 0x2(%r15,%rbp,4),%r13d
movzbl 0x3(%r15,%rbp,4),%r14d
mov    %r12d,%esi
mov    %r14d,%edx
lea    0xf(%rsp),%rcx
lea    0xe(%rsp),%r8
lea    0xd(%rsp),%r9
call   1030 <matrix@plt>
movzbl 0xf(%rsp),%eax
mov    %al,(%rbx)
movzbl 0xe(%rsp),%eax
mov    %al,0x1(%rbx)
movzbl 0xd(%rsp),%eax
mov    %al,0x2(%rbx)
mov    %r13d,%edi
mov    %r12d,%esi
mov    %r14d,%edx
lea    0xf(%rsp),%rcx
lea    0xe(%rsp),%r8
lea    0xd(%rsp),%r9
call   1030 <matrix@plt>
movzbl 0xf(%rsp),%eax
mov    %al,0x3(%rbx)
movzbl 0xe(%rsp),%eax
mov    %al,0x4(%rbx)
movzbl 0xd(%rsp),%eax
mov    %al,0x5(%rbx)
add    $0x1,%rbp
add    $0x6,%rbx
cmp    %ebp,0x10(%rsp)
jne    1150 <yuv2rgb+0x40>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @yuv2rgb(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8
%8 = alloca i8
%9 = alloca i8
%10 = alloca i8
%11 = alloca i8
%12 = alloca i8
%13 = alloca i8
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%14 = load i32, i32* %6
%15 = ashr i32 %14, 2
store i32 %15, i32* %6
br label %16
16: ; preds = %20, %3
%17 = load i32, i32* %6
%18 = add nsw i32 %17, -1
store i32 %18, i32* %6
%19 = icmp ne i32 %17, 0
br i1 %19, label %20, label %59
20: ; preds = %16
%21 = load i8*, i8** %4
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %4
%23 = load i8, i8* %21
store i8 %23, i8* %10
%24 = load i8*, i8** %4
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %4
%26 = load i8, i8* %24
store i8 %26, i8* %12
%27 = load i8*, i8** %4
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %4
%29 = load i8, i8* %27
store i8 %29, i8* %11
%30 = load i8*, i8** %4
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %4
%32 = load i8, i8* %30
store i8 %32, i8* %13
%33 = load i8, i8* %10
%34 = load i8, i8* %12
%35 = load i8, i8* %13
%36 = call i32 @matrix(i8 zeroext %33, i8 zeroext %34, i8 zeroext %35, i8* %7, i8* %8, i8* %9)
%37 = load i8, i8* %7
%38 = load i8*, i8** %5
%39 = getelementptr inbounds i8, i8* %38, i32 1
store i8* %39, i8** %5
store i8 %37, i8* %38
%40 = load i8, i8* %8
%41 = load i8*, i8** %5
%42 = getelementptr inbounds i8, i8* %41, i32 1
store i8* %42, i8** %5
store i8 %40, i8* %41
%43 = load i8, i8* %9
%44 = load i8*, i8** %5
%45 = getelementptr inbounds i8, i8* %44, i32 1
store i8* %45, i8** %5
store i8 %43, i8* %44
%46 = load i8, i8* %11
%47 = load i8, i8* %12
%48 = load i8, i8* %13
%49 = call i32 @matrix(i8 zeroext %46, i8 zeroext %47, i8 zeroext %48, i8* %7, i8* %8, i8* %9)
%50 = load i8, i8* %7
%51 = load i8*, i8** %5
%52 = getelementptr inbounds i8, i8* %51, i32 1
store i8* %52, i8** %5
store i8 %50, i8* %51
%53 = load i8, i8* %8
%54 = load i8*, i8** %5
%55 = getelementptr inbounds i8, i8* %54, i32 1
store i8* %55, i8** %5
store i8 %53, i8* %54
%56 = load i8, i8* %9
%57 = load i8*, i8** %5
%58 = getelementptr inbounds i8, i8* %57, i32 1
store i8* %58, i8** %5
store i8 %56, i8* %57
br label %16
59: ; preds = %16
ret void
}

LLVM IR (-O2):
define void @yuv2rgb(i8* nocapture %0, i8* nocapture writeonly %1, i32 %2) {
%4 = alloca i8
%5 = alloca i8
%6 = alloca i8
%7 = icmp ult i32 %2, 4
br i1 %7, label %38, label %8
8: ; preds = %3
%9 = ashr i32 %2, 2
br label %10
10: ; preds = %8, %10
%11 = phi i8* [ %21, %10 ], [ %0, %8 ]
%12 = phi i8* [ %36, %10 ], [ %1, %8 ]
%13 = phi i32 [ %14, %10 ], [ %9, %8 ]
%14 = add nsw i32 %13, -1
%15 = getelementptr inbounds i8, i8* %11, i64 1
%16 = load i8, i8* %11
%17 = getelementptr inbounds i8, i8* %11, i64 2
%18 = load i8, i8* %15
%19 = getelementptr inbounds i8, i8* %11, i64 3
%20 = load i8, i8* %17
%21 = getelementptr inbounds i8, i8* %11, i64 4
%22 = load i8, i8* %19
%23 = call i32 @matrix(i8 zeroext %16, i8 zeroext %18, i8 zeroext %22, i8* %4, i8* %5, i8* %6)
%24 = load i8, i8* %4
%25 = getelementptr inbounds i8, i8* %12, i64 1
store i8 %24, i8* %12
%26 = load i8, i8* %5
%27 = getelementptr inbounds i8, i8* %12, i64 2
store i8 %26, i8* %25
%28 = load i8, i8* %6
%29 = getelementptr inbounds i8, i8* %12, i64 3
store i8 %28, i8* %27
%30 = call i32 @matrix(i8 zeroext %20, i8 zeroext %18, i8 zeroext %22, i8* %4, i8* %5, i8* %6)
%31 = load i8, i8* %4
%32 = getelementptr inbounds i8, i8* %12, i64 4
store i8 %31, i8* %29
%33 = load i8, i8* %5
%34 = getelementptr inbounds i8, i8* %12, i64 5
store i8 %33, i8* %32
%35 = load i8, i8* %6
%36 = getelementptr inbounds i8, i8* %12, i64 6
store i8 %35, i8* %34
%37 = icmp eq i32 %14, 0
br i1 %37, label %38, label %10
38: ; preds = %10, %3
ret void
}