#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*/ yuv_to_rgb16(unsigned char, unsigned char, unsigned char,
                                unsigned char *);
void convertYUYVtoRGB565(unsigned char *buf, unsigned char *rgb, int width,
                         int height) {
  int x, y, z = 0;
  int blocks;
  blocks = (width * height) * 2;
  for (y = 0; y < blocks; y += 4) {
    unsigned char Y1, Y2, U, V;
    Y1 = buf[y + 0];
    U = buf[y + 1];
    Y2 = buf[y + 2];
    V = buf[y + 3];
    yuv_to_rgb16(Y1, U, V, &rgb[y]);
    yuv_to_rgb16(Y2, U, V, &rgb[y + 2]);
  }
}


x86 assembly (clang, -O0):
<convertYUYVtoRGB565>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x14(%rbp),%eax
imul   -0x18(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x28(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    11f4 <convertYUYVtoRGB565+0xe4>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    $0x0,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x29(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x2b(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x2a(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    $0x3,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x2c(%rbp)
mov    -0x29(%rbp),%sil
mov    -0x2b(%rbp),%dl
mov    -0x2c(%rbp),%al
mov    -0x10(%rbp),%rcx
movslq -0x20(%rbp),%rdi
add    %rdi,%rcx
movzbl %sil,%edi
movzbl %dl,%esi
movzbl %al,%edx
call   1030 <yuv_to_rgb16@plt>
mov    -0x2a(%rbp),%sil
mov    -0x2b(%rbp),%dl
mov    -0x2c(%rbp),%al
mov    -0x10(%rbp),%rcx
mov    -0x20(%rbp),%edi
add    $0x2,%edi
movslq %edi,%rdi
add    %rdi,%rcx
movzbl %sil,%edi
movzbl %dl,%esi
movzbl %al,%edx
call   1030 <yuv_to_rgb16@plt>
mov    -0x20(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x20(%rbp)
jmp    1141 <convertYUYVtoRGB565+0x31>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convertYUYVtoRGB565>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
imul   %ecx,%edx
add    %edx,%edx
test   %edx,%edx
jle    1186 <convertYUYVtoRGB565+0x76>
mov    %rsi,%rbx
mov    %rdi,%r15
xor    %r14d,%r14d
mov    %edx,0x4(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%r15,%r14,1),%edi
movzbl 0x1(%r15,%r14,1),%r13d
movzbl 0x2(%r15,%r14,1),%r12d
movzbl 0x3(%r15,%r14,1),%ebp
mov    %r13d,%esi
mov    %ebp,%edx
mov    %rbx,%rcx
call   1030 <yuv_to_rgb16@plt>
lea    0x2(%rbx),%rcx
mov    %r12d,%edi
mov    %r13d,%esi
mov    %ebp,%edx
call   1030 <yuv_to_rgb16@plt>
mov    0x4(%rsp),%edx
add    $0x4,%r14
add    $0x4,%rbx
cmp    %r14d,%edx
jg     1140 <convertYUYVtoRGB565+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @convertYUYVtoRGB565(i8* nocapture %0, i8* %1, i32 %2, i32 %3) {
%5 = shl i32 %2, 1
%6 = mul i32 %5, %3
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %28
8: ; preds = %4, %8
%9 = phi i64 [ %25, %8 ], [ 0, %4 ]
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = or i64 %9, 1
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = load i8, i8* %13
%15 = or i64 %9, 2
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = load i8, i8* %16
%18 = or i64 %9, 3
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = load i8, i8* %19
%21 = getelementptr inbounds i8, i8* %1, i64 %9
%22 = tail call i32 @yuv_to_rgb16(i8 zeroext %11, i8 zeroext %14, i8 zeroext %20, i8* %21)
%23 = getelementptr inbounds i8, i8* %1, i64 %15
%24 = tail call i32 @yuv_to_rgb16(i8 zeroext %17, i8 zeroext %14, i8 zeroext %20, i8* %23)
%25 = add nuw i64 %9, 4
%26 = trunc i64 %25 to i32
%27 = icmp sgt i32 %6, %26
br i1 %27, label %8, label %28
28: ; preds = %8, %4
ret void
}