#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 */
typedef int /*<<< orphan*/ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/ const *,
                          int);
int pixel_convert_8u_yuv420p_to_8u_gray(uint8_t *dest, int dstride, int dwidth,
                                        int dheight, const uint8_t *src,
                                        int sstride) {
  int i;
  for (i = 0; i < dheight; i++) {
    memcpy(dest + i * dstride, src + i * sstride, dwidth);
  }
  return 0;
}


x86 assembly (clang, -O0):
<pixel_convert_8u_yuv420p_to_8u_gray>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    117e <pixel_convert_8u_yuv420p_to_8u_gray+0x6e>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%eax
imul   -0xc(%rbp),%eax
cltq
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%eax
imul   -0x24(%rbp),%eax
cltq
shl    $0x2,%rax
add    %rax,%rsi
mov    -0x10(%rbp),%edx
call   1030 <memcpy@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1134 <pixel_convert_8u_yuv420p_to_8u_gray+0x24>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pixel_convert_8u_yuv420p_to_8u_gray>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %ecx,%ecx
jle    115a <pixel_convert_8u_yuv420p_to_8u_gray+0x4a>
mov    %r8,%r13
mov    %edx,%r14d
mov    %rdi,%rbp
movslq %esi,%r15
movslq %r9d,%r12
mov    %ecx,%ebx
shl    $0x2,%r12
shl    $0x2,%r15
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %r14d,%edx
call   1030 <memcpy@plt>
add    %r12,%r13
add    %r15,%rbp
add    $0xffffffffffffffff,%rbx
jne    1140 <pixel_convert_8u_yuv420p_to_8u_gray+0x30>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @pixel_convert_8u_yuv420p_to_8u_gray(i32* %0, i32 %1, i32 %2, i32 %3, i32* %4, i32 %5) {
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i32
store i32* %0, i32** %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32* %4, i32** %11
store i32 %5, i32* %12
store i32 0, i32* %13
br label %14
14: ; preds = %33, %6
%15 = load i32, i32* %13
%16 = load i32, i32* %10
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %36
18: ; preds = %14
%19 = load i32*, i32** %7
%20 = load i32, i32* %13
%21 = load i32, i32* %8
%22 = mul nsw i32 %20, %21
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %19, i64 %23
%25 = load i32*, i32** %11
%26 = load i32, i32* %13
%27 = load i32, i32* %12
%28 = mul nsw i32 %26, %27
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32, i32* %25, i64 %29
%31 = load i32, i32* %9
%32 = call i32 @memcpy(i32* %24, i32* %30, i32 %31)
br label %33
33: ; preds = %18
%34 = load i32, i32* %13
%35 = add nsw i32 %34, 1
store i32 %35, i32* %13
br label %14
36: ; preds = %14
ret i32 0
}

LLVM IR (-O2):
define i32 @pixel_convert_8u_yuv420p_to_8u_gray(i32* %0, i32 %1, i32 %2, i32 %3, i32* %4, i32 %5) {
%7 = icmp sgt i32 %3, 0
br i1 %7, label %8, label %21
8: ; preds = %6
%9 = sext i32 %1 to i64
%10 = sext i32 %5 to i64
%11 = zext i32 %3 to i64
br label %12
12: ; preds = %8, %12
%13 = phi i64 [ 0, %8 ], [ %19, %12 ]
%14 = mul nsw i64 %13, %9
%15 = getelementptr inbounds i32, i32* %0, i64 %14
%16 = mul nsw i64 %13, %10
%17 = getelementptr inbounds i32, i32* %4, i64 %16
%18 = tail call i32 @memcpy(i32* %15, i32* %17, i32 %2)
%19 = add nuw nsw i64 %13, 1
%20 = icmp eq i64 %19, %11
br i1 %20, label %21, label %12
21: ; preds = %12, %6
ret i32 0
}