#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 */
unsigned long YUV_to_BGR(unsigned char, unsigned char, unsigned char);
void convert_yuv_to_bgr(unsigned char *p_bgr, unsigned char *p_yuv,
                        int pixels) {
  int x;
  unsigned long bgr;
  for (x = 0; x < pixels / 2; x++) {
    bgr = YUV_to_BGR(p_yuv[1], p_yuv[0], p_yuv[2]);
    *(p_bgr++) = (unsigned char)(0xFF & bgr);
    *(p_bgr++) = (unsigned char)(0xFF & (bgr >> 8));
    *(p_bgr++) = (unsigned char)(0xFF & (bgr >> 16));
    bgr = YUV_to_BGR(p_yuv[3], p_yuv[0], p_yuv[2]);
    *(p_bgr++) = (unsigned char)(0xFF & bgr);
    *(p_bgr++) = (unsigned char)(0xFF & (bgr >> 8));
    *(p_bgr++) = (unsigned char)(0xFF & (bgr >> 16));
    p_yuv += 4;
  }
}


x86 assembly (clang, -O0):
<convert_yuv_to_bgr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jge    1268 <convert_yuv_to_bgr+0x158>
mov    -0x10(%rbp),%rax
mov    0x1(%rax),%dl
mov    -0x10(%rbp),%rax
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
movzbl %dl,%edi
movzbl %cl,%esi
movzbl 0x2(%rax),%edx
call   1030 <YUV_to_BGR@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
and    $0xff,%rax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
shr    $0x8,%rax
and    $0xff,%rax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
shr    $0x10,%rax
and    $0xff,%rax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
mov    0x3(%rax),%dl
mov    -0x10(%rbp),%rax
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
movzbl %dl,%edi
movzbl %cl,%esi
movzbl 0x2(%rax),%edx
call   1030 <YUV_to_BGR@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
and    $0xff,%rax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
shr    $0x8,%rax
and    $0xff,%rax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
shr    $0x10,%rax
and    $0xff,%rax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    112a <convert_yuv_to_bgr+0x1a>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert_yuv_to_bgr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edx
jl     1183 <convert_yuv_to_bgr+0x73>
mov    %rsi,%r15
mov    %rdi,%rbp
mov    %edx,%eax
shr    $0x1f,%eax
add    %edx,%eax
sar    %eax
mov    %eax,%r14d
xor    %ebx,%ebx
movzbl 0x1(%r15,%rbx,4),%edi
movzbl (%r15,%rbx,4),%esi
movzbl 0x2(%r15,%rbx,4),%edx
call   1030 <YUV_to_BGR@plt>
mov    %al,0x0(%rbp)
mov    %ah,0x1(%rbp)
shr    $0x10,%rax
mov    %al,0x2(%rbp)
movzbl 0x3(%r15,%rbx,4),%edi
movzbl (%r15,%rbx,4),%esi
movzbl 0x2(%r15,%rbx,4),%edx
call   1030 <YUV_to_BGR@plt>
mov    %al,0x3(%rbp)
mov    %ah,0x4(%rbp)
shr    $0x10,%rax
mov    %al,0x5(%rbp)
add    $0x1,%rbx
add    $0x6,%rbp
cmp    %ebx,%r14d
jne    1130 <convert_yuv_to_bgr+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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