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


x86 assembly (clang, -O0):
<convert_bgr_to_yuv>:
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    1227 <convert_bgr_to_yuv+0x117>
mov    -0x10(%rbp),%rax
mov    (%rax),%dl
mov    -0x10(%rbp),%rax
mov    0x1(%rax),%cl
mov    -0x10(%rbp),%rax
movzbl %dl,%edi
movzbl %cl,%esi
movzbl 0x2(%rax),%edx
call   1030 <BGR_to_YUV@plt>
mov    %rax,-0x20(%rbp)
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
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    0x4(%rax),%cl
mov    -0x10(%rbp),%rax
movzbl %dl,%edi
movzbl %cl,%esi
movzbl 0x5(%rax),%edx
call   1030 <BGR_to_YUV@plt>
mov    %rax,-0x20(%rbp)
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    -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    -0x10(%rbp),%rax
add    $0x6,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    112a <convert_bgr_to_yuv+0x1a>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert_bgr_to_yuv>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edx
jl     1188 <convert_bgr_to_yuv+0x78>
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %edx,%eax
shr    $0x1f,%eax
add    %edx,%eax
sar    %eax
mov    %eax,%r15d
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%rbx),%edi
movzbl 0x1(%rbx),%esi
movzbl 0x2(%rbx),%edx
call   1030 <BGR_to_YUV@plt>
rol    $0x8,%ax
mov    %ax,(%r14,%r12,4)
movzbl 0x3(%rbx),%edi
movzbl 0x4(%rbx),%esi
movzbl 0x5(%rbx),%edx
call   1030 <BGR_to_YUV@plt>
mov    %rax,%rcx
shr    $0x10,%rcx
mov    %cl,0x2(%r14,%r12,4)
mov    %al,0x3(%r14,%r12,4)
add    $0x1,%r12
add    $0x6,%rbx
cmp    %r12d,%r15d
jne    1140 <convert_bgr_to_yuv+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @convert_bgr_to_yuv(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 = %59, %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 %62
14: ; preds = %9
%15 = load i8*, i8** %5
%16 = getelementptr inbounds i8, i8* %15, i64 0
%17 = load i8, i8* %16
%18 = load i8*, i8** %5
%19 = getelementptr inbounds i8, i8* %18, i64 1
%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 @BGR_to_YUV(i8 zeroext %17, i8 zeroext %20, i8 zeroext %23)
store i64 %24, i64* %8
%25 = load i64, i64* %8
%26 = lshr i64 %25, 8
%27 = and i64 255, %26
%28 = trunc i64 %27 to i8
%29 = load i8*, i8** %4
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %4
store i8 %28, i8* %29
%31 = load i64, i64* %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 i8*, i8** %5
%37 = getelementptr inbounds i8, i8* %36, i64 3
%38 = load i8, i8* %37
%39 = load i8*, i8** %5
%40 = getelementptr inbounds i8, i8* %39, i64 4
%41 = load i8, i8* %40
%42 = load i8*, i8** %5
%43 = getelementptr inbounds i8, i8* %42, i64 5
%44 = load i8, i8* %43
%45 = call i64 @BGR_to_YUV(i8 zeroext %38, i8 zeroext %41, i8 zeroext %44)
store i64 %45, i64* %8
%46 = load i64, i64* %8
%47 = lshr i64 %46, 16
%48 = and i64 255, %47
%49 = trunc i64 %48 to i8
%50 = load i8*, i8** %4
%51 = getelementptr inbounds i8, i8* %50, i32 1
store i8* %51, i8** %4
store i8 %49, i8* %50
%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 i8*, i8** %5
%58 = getelementptr inbounds i8, i8* %57, i64 6
store i8* %58, i8** %5
br label %59
59: ; preds = %14
%60 = load i32, i32* %7
%61 = add nsw i32 %60, 1
store i32 %61, i32* %7
br label %9
62: ; preds = %9
ret void
}

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