#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*/ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ *generate_32bit_scaled_data_write(
    int /*<<< orphan*/ *, int, int, int, int /*<<< orphan*/, int, scalar_t__,
    int, int, int, int /*<<< orphan*/, int, int, int, int, int);
int generate_yuv420p_to_yuyv422_line_scaler(uint32_t *cmdbuffer,
                                            int maxcmdcount, int orig_w,
                                            int dest_w, int quality) {
  int i, p1, p2, cmdcount;
  int type_y1, type_y2, type_u, type_v;
  uint32_t *p = cmdbuffer;
  *p++ = 0xE92D4FF0;
  for (i = 0; i < dest_w; i += 2) {
    p = generate_32bit_scaled_data_write(p, quality, orig_w, dest_w, 0, 1,
                                         i + 0, 1, 2, i, 0, 1, i + 1, 2, 2, i);
  }
  *p++ = 0xE8BD8FF0;
  cmdcount = p - cmdbuffer;
  return cmdcount;
}


x86 assembly (clang, -O0):
<generate_yuv420p_to_yuyv422_line_scaler>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x98,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x48(%rbp)
movl   $0xe92d4ff0,(%rax)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11e4 <generate_yuv420p_to_yuyv422_line_scaler+0xd4>
mov    -0x48(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x24(%rbp),%eax
add    $0x0,%eax
movslq %eax,%rbx
mov    -0x24(%rbp),%r11d
mov    -0x24(%rbp),%r10d
add    $0x1,%r10d
mov    -0x24(%rbp),%eax
xor    %r8d,%r8d
mov    $0x1,%r9d
mov    %rbx,(%rsp)
movl   $0x1,0x8(%rsp)
movl   $0x2,0x10(%rsp)
mov    %r11d,0x18(%rsp)
movl   $0x0,0x20(%rsp)
movl   $0x1,0x28(%rsp)
mov    %r10d,0x30(%rsp)
movl   $0x2,0x38(%rsp)
movl   $0x2,0x40(%rsp)
mov    %eax,0x48(%rsp)
call   1030 <generate_32bit_scaled_data_write@plt>
mov    %rax,-0x48(%rbp)
mov    -0x24(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x24(%rbp)
jmp    1151 <generate_yuv420p_to_yuyv422_line_scaler+0x41>
mov    -0x48(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x48(%rbp)
movl   $0xe8bd8ff0,(%rax)
mov    -0x48(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
sar    $0x2,%rax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
add    $0x98,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_yuv420p_to_yuyv422_line_scaler>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0x4(%rdi),%rax
movl   $0xe92d4ff0,(%rdi)
test   %ecx,%ecx
jle    117a <generate_yuv420p_to_yuyv422_line_scaler+0x6a>
mov    %r8d,%r15d
mov    %ecx,%r13d
mov    %edx,%r12d
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
lea    0x1(%rbp),%ebx
mov    %rax,%rdi
mov    %r15d,%esi
mov    %r12d,%edx
mov    %r13d,%ecx
xor    %r8d,%r8d
mov    $0x1,%r9d
push   %rbp
push   $0x2
push   $0x2
push   %rbx
push   $0x1
push   $0x0
push   %rbp
push   $0x2
push   $0x1
push   %rbp
call   1030 <generate_32bit_scaled_data_write@plt>
add    $0x50,%rsp
add    $0x2,%rbp
cmp    %r13d,%ebp
jl     1140 <generate_yuv420p_to_yuyv422_line_scaler+0x30>
movl   $0xe8bd8ff0,(%rax)
sub    %r14,%rax
add    $0x4,%rax
shr    $0x2,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @generate_yuv420p_to_yuyv422_line_scaler(i32* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32*
store i32* %0, i32** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%20 = load i32*, i32** %6
store i32* %20, i32** %19
%21 = load i32*, i32** %19
%22 = getelementptr inbounds i32, i32* %21, i32 1
store i32* %22, i32** %19
store i32 -382906384, i32* %21
store i32 0, i32* %11
br label %23
23: ; preds = %40, %5
%24 = load i32, i32* %11
%25 = load i32, i32* %9
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %43
27: ; preds = %23
%28 = load i32*, i32** %19
%29 = load i32, i32* %10
%30 = load i32, i32* %8
%31 = load i32, i32* %9
%32 = load i32, i32* %11
%33 = add nsw i32 %32, 0
%34 = sext i32 %33 to i64
%35 = load i32, i32* %11
%36 = load i32, i32* %11
%37 = add nsw i32 %36, 1
%38 = load i32, i32* %11
%39 = call i32* @generate_32bit_scaled_data_write(i32* %28, i32 %29, i32 %30, i32 %31, i32 0, i32 1, i64 %34, i32 1, i32 2, i32 %35, i32 0, i32 1, i32 %37, i32 2, i32 2, i32 %38)
store i32* %39, i32** %19
br label %40
40: ; preds = %27
%41 = load i32, i32* %11
%42 = add nsw i32 %41, 2
store i32 %42, i32* %11
br label %23
43: ; preds = %23
%44 = load i32*, i32** %19
%45 = getelementptr inbounds i32, i32* %44, i32 1
store i32* %45, i32** %19
store i32 -390230032, i32* %44
%46 = load i32*, i32** %19
%47 = load i32*, i32** %6
%48 = ptrtoint i32* %46 to i64
%49 = ptrtoint i32* %47 to i64
%50 = sub i64 %48, %49
%51 = sdiv exact i64 %50, 4
%52 = trunc i64 %51 to i32
store i32 %52, i32* %14
%53 = load i32, i32* %14
ret i32 %53
}

LLVM IR (-O2):
define i32 @generate_yuv420p_to_yuyv422_line_scaler(i32* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = getelementptr inbounds i32, i32* %0, i64 1
store i32 -382906384, i32* %0
%7 = icmp sgt i32 %3, 0
br i1 %7, label %8, label %17
8: ; preds = %5, %8
%9 = phi i64 [ %14, %8 ], [ 0, %5 ]
%10 = phi i32* [ %13, %8 ], [ %6, %5 ]
%11 = trunc i64 %9 to i32
%12 = or i32 %11, 1
%13 = tail call i32* @generate_32bit_scaled_data_write(i32* %10, i32 %4, i32 %2, i32 %3, i32 0, i32 1, i64 %9, i32 1, i32 2, i32 %11, i32 0, i32 1, i32 %12, i32 2, i32 2, i32 %11)
%14 = add nuw i64 %9, 2
%15 = trunc i64 %14 to i32
%16 = icmp slt i32 %15, %3
br i1 %16, label %8, label %17
17: ; preds = %8, %5
%18 = phi i32* [ %6, %5 ], [ %13, %8 ]
%19 = getelementptr inbounds i32, i32* %18, i64 1
store i32 -390230032, i32* %18
%20 = ptrtoint i32* %19 to i64
%21 = ptrtoint i32* %0 to i64
%22 = sub i64 %20, %21
%23 = lshr exact i64 %22, 2
%24 = trunc i64 %23 to i32
ret i32 %24
}