#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 */
void *B_FROMYU(unsigned char, unsigned char);
void *G_FROMYUV(unsigned char, unsigned char, unsigned char);
void *R_FROMYV(unsigned char, unsigned char);
unsigned int Pyuv422torgb24(unsigned char *input_ptr, unsigned char *output_ptr,
                            unsigned int image_width,
                            unsigned int image_height) {
  unsigned int i, size;
  unsigned char Y, Y1, U, V;
  unsigned char *buff = input_ptr;
  unsigned char *output_pt = output_ptr;
  size = image_width * image_height / 2;
  for (i = size; i > 0; i--) {
    Y = buff[0];
    U = buff[1];
    Y1 = buff[2];
    V = buff[3];
    buff += 4;
    *output_pt++ = R_FROMYV(Y, V);
    *output_pt++ = G_FROMYUV(Y, U, V);
    *output_pt++ = B_FROMYU(Y, U);
    *output_pt++ = R_FROMYV(Y1, V);
    *output_pt++ = G_FROMYUV(Y1, U, V);
    *output_pt++ = B_FROMYU(Y1, U);
  }
  return 2;
}


x86 assembly (clang, -O0):
<Pyuv422torgb24>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x14(%rbp),%eax
imul   -0x18(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jbe    128c <Pyuv422torgb24+0x15c>
mov    -0x30(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x21(%rbp)
mov    -0x30(%rbp),%rax
mov    0x1(%rax),%al
mov    %al,-0x23(%rbp)
mov    -0x30(%rbp),%rax
mov    0x2(%rax),%al
mov    %al,-0x22(%rbp)
mov    -0x30(%rbp),%rax
mov    0x3(%rax),%al
mov    %al,-0x24(%rbp)
mov    -0x30(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x30(%rbp)
mov    -0x21(%rbp),%al
movzbl %al,%edi
movzbl -0x24(%rbp),%esi
call   1040 <R_FROMYV@plt>
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x38(%rbp)
mov    %cl,(%rax)
mov    -0x21(%rbp),%cl
mov    -0x23(%rbp),%al
movzbl %cl,%edi
movzbl %al,%esi
movzbl -0x24(%rbp),%edx
call   1050 <G_FROMYUV@plt>
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x38(%rbp)
mov    %cl,(%rax)
mov    -0x21(%rbp),%al
movzbl %al,%edi
movzbl -0x23(%rbp),%esi
call   1030 <B_FROMYU@plt>
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x38(%rbp)
mov    %cl,(%rax)
mov    -0x22(%rbp),%al
movzbl %al,%edi
movzbl -0x24(%rbp),%esi
call   1040 <R_FROMYV@plt>
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x38(%rbp)
mov    %cl,(%rax)
mov    -0x22(%rbp),%cl
mov    -0x23(%rbp),%al
movzbl %cl,%edi
movzbl %al,%esi
movzbl -0x24(%rbp),%edx
call   1050 <G_FROMYUV@plt>
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x38(%rbp)
mov    %cl,(%rax)
mov    -0x22(%rbp),%al
movzbl %al,%edi
movzbl -0x23(%rbp),%esi
call   1030 <B_FROMYU@plt>
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x38(%rbp)
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1169 <Pyuv422torgb24+0x39>
mov    $0x2,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Pyuv422torgb24>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
imul   %ecx,%edx
cmp    $0x2,%edx
jb     11e5 <Pyuv422torgb24+0xb5>
mov    %rsi,%rbx
mov    %edx,%eax
shr    %rax
mov    %rax,0x8(%rsp)
xor    %r14d,%r14d
mov    %rdi,0x10(%rsp)
nop
movzbl (%rdi,%r14,4),%ebp
movzbl 0x1(%rdi,%r14,4),%r12d
movzbl 0x2(%rdi,%r14,4),%r15d
movzbl 0x3(%rdi,%r14,4),%r13d
mov    %ebp,%edi
mov    %r13d,%esi
call   1040 <R_FROMYV@plt>
mov    %al,(%rbx)
mov    %ebp,%edi
mov    %r12d,%esi
mov    %r13d,%edx
call   1050 <G_FROMYUV@plt>
mov    %al,0x1(%rbx)
mov    %ebp,%edi
mov    %r12d,%esi
call   1030 <B_FROMYU@plt>
mov    %al,0x2(%rbx)
mov    %r15d,%edi
mov    %r13d,%esi
call   1040 <R_FROMYV@plt>
mov    %al,0x3(%rbx)
mov    %r15d,%edi
mov    %r12d,%esi
mov    %r13d,%edx
call   1050 <G_FROMYUV@plt>
mov    %al,0x4(%rbx)
mov    %r15d,%edi
mov    %r12d,%esi
call   1030 <B_FROMYU@plt>
mov    0x10(%rsp),%rdi
mov    %al,0x5(%rbx)
add    $0x1,%r14
add    $0x6,%rbx
cmp    %r14d,0x8(%rsp)
jne    1160 <Pyuv422torgb24+0x30>
mov    $0x2,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @Pyuv422torgb24(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8
%12 = alloca i8
%13 = alloca i8
%14 = alloca i8
%15 = alloca i8*
%16 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%17 = load i8*, i8** %5
store i8* %17, i8** %15
%18 = load i8*, i8** %6
store i8* %18, i8** %16
%19 = load i32, i32* %7
%20 = load i32, i32* %8
%21 = mul i32 %19, %20
%22 = udiv i32 %21, 2
store i32 %22, i32* %10
%23 = load i32, i32* %10
store i32 %23, i32* %9
br label %24
24: ; preds = %80, %4
%25 = load i32, i32* %9
%26 = icmp ugt i32 %25, 0
br i1 %26, label %27, label %83
27: ; preds = %24
%28 = load i8*, i8** %15
%29 = getelementptr inbounds i8, i8* %28, i64 0
%30 = load i8, i8* %29
store i8 %30, i8* %11
%31 = load i8*, i8** %15
%32 = getelementptr inbounds i8, i8* %31, i64 1
%33 = load i8, i8* %32
store i8 %33, i8* %13
%34 = load i8*, i8** %15
%35 = getelementptr inbounds i8, i8* %34, i64 2
%36 = load i8, i8* %35
store i8 %36, i8* %12
%37 = load i8*, i8** %15
%38 = getelementptr inbounds i8, i8* %37, i64 3
%39 = load i8, i8* %38
store i8 %39, i8* %14
%40 = load i8*, i8** %15
%41 = getelementptr inbounds i8, i8* %40, i64 4
store i8* %41, i8** %15
%42 = load i8, i8* %11
%43 = load i8, i8* %14
%44 = call i8* @R_FROMYV(i8 zeroext %42, i8 zeroext %43)
%45 = ptrtoint i8* %44 to i8
%46 = load i8*, i8** %16
%47 = getelementptr inbounds i8, i8* %46, i32 1
store i8* %47, i8** %16
store i8 %45, i8* %46
%48 = load i8, i8* %11
%49 = load i8, i8* %13
%50 = load i8, i8* %14
%51 = call i8* @G_FROMYUV(i8 zeroext %48, i8 zeroext %49, i8 zeroext %50)
%52 = ptrtoint i8* %51 to i8
%53 = load i8*, i8** %16
%54 = getelementptr inbounds i8, i8* %53, i32 1
store i8* %54, i8** %16
store i8 %52, i8* %53
%55 = load i8, i8* %11
%56 = load i8, i8* %13
%57 = call i8* @B_FROMYU(i8 zeroext %55, i8 zeroext %56)
%58 = ptrtoint i8* %57 to i8
%59 = load i8*, i8** %16
%60 = getelementptr inbounds i8, i8* %59, i32 1
store i8* %60, i8** %16
store i8 %58, i8* %59
%61 = load i8, i8* %12
%62 = load i8, i8* %14
%63 = call i8* @R_FROMYV(i8 zeroext %61, i8 zeroext %62)
%64 = ptrtoint i8* %63 to i8
%65 = load i8*, i8** %16
%66 = getelementptr inbounds i8, i8* %65, i32 1
store i8* %66, i8** %16
store i8 %64, i8* %65
%67 = load i8, i8* %12
%68 = load i8, i8* %13
%69 = load i8, i8* %14
%70 = call i8* @G_FROMYUV(i8 zeroext %67, i8 zeroext %68, i8 zeroext %69)
%71 = ptrtoint i8* %70 to i8
%72 = load i8*, i8** %16
%73 = getelementptr inbounds i8, i8* %72, i32 1
store i8* %73, i8** %16
store i8 %71, i8* %72
%74 = load i8, i8* %12
%75 = load i8, i8* %13
%76 = call i8* @B_FROMYU(i8 zeroext %74, i8 zeroext %75)
%77 = ptrtoint i8* %76 to i8
%78 = load i8*, i8** %16
%79 = getelementptr inbounds i8, i8* %78, i32 1
store i8* %79, i8** %16
store i8 %77, i8* %78
br label %80
80: ; preds = %27
%81 = load i32, i32* %9
%82 = add i32 %81, -1
store i32 %82, i32* %9
br label %24
83: ; preds = %24
ret i32 2
}

LLVM IR (-O2):
define i32 @Pyuv422torgb24(i8* nocapture %0, i8* nocapture writeonly %1, i32 %2, i32 %3) {
%5 = mul i32 %3, %2
%6 = icmp ult i32 %5, 2
br i1 %6, label %47, label %7
7: ; preds = %4
%8 = lshr i32 %5, 1
br label %9
9: ; preds = %7, %9
%10 = phi i8* [ %44, %9 ], [ %1, %7 ]
%11 = phi i8* [ %20, %9 ], [ %0, %7 ]
%12 = phi i32 [ %45, %9 ], [ %8, %7 ]
%13 = load i8, i8* %11
%14 = getelementptr inbounds i8, i8* %11, i64 1
%15 = load i8, i8* %14
%16 = getelementptr inbounds i8, i8* %11, i64 2
%17 = load i8, i8* %16
%18 = getelementptr inbounds i8, i8* %11, i64 3
%19 = load i8, i8* %18
%20 = getelementptr inbounds i8, i8* %11, i64 4
%21 = tail call i8* @R_FROMYV(i8 zeroext %13, i8 zeroext %19)
%22 = ptrtoint i8* %21 to i64
%23 = trunc i64 %22 to i8
%24 = getelementptr inbounds i8, i8* %10, i64 1
store i8 %23, i8* %10
%25 = tail call i8* @G_FROMYUV(i8 zeroext %13, i8 zeroext %15, i8 zeroext %19)
%26 = ptrtoint i8* %25 to i64
%27 = trunc i64 %26 to i8
%28 = getelementptr inbounds i8, i8* %10, i64 2
store i8 %27, i8* %24
%29 = tail call i8* @B_FROMYU(i8 zeroext %13, i8 zeroext %15)
%30 = ptrtoint i8* %29 to i64
%31 = trunc i64 %30 to i8
%32 = getelementptr inbounds i8, i8* %10, i64 3
store i8 %31, i8* %28
%33 = tail call i8* @R_FROMYV(i8 zeroext %17, i8 zeroext %19)
%34 = ptrtoint i8* %33 to i64
%35 = trunc i64 %34 to i8
%36 = getelementptr inbounds i8, i8* %10, i64 4
store i8 %35, i8* %32
%37 = tail call i8* @G_FROMYUV(i8 zeroext %17, i8 zeroext %15, i8 zeroext %19)
%38 = ptrtoint i8* %37 to i64
%39 = trunc i64 %38 to i8
%40 = getelementptr inbounds i8, i8* %10, i64 5
store i8 %39, i8* %36
%41 = tail call i8* @B_FROMYU(i8 zeroext %17, i8 zeroext %15)
%42 = ptrtoint i8* %41 to i64
%43 = trunc i64 %42 to i8
%44 = getelementptr inbounds i8, i8* %10, i64 6
store i8 %43, i8* %40
%45 = add i32 %12, -1
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %9
47: ; preds = %9, %4
ret i32 2
}