#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, int, int,
                                                     int, int, int, int, int,
                                                     int, int, int, int);
int generate_yuv420p_to_yuv420_line_scaler(uint32_t *cmdbuffer, int maxcmdcount,
                                           int orig_w, int dest_w,
                                           int quality) {
  int i = 0, p1, p2, cmdcount;
  int type_y1, type_y2, type_u, type_v;
  uint32_t *p = cmdbuffer;
  *p++ = 0xE92D4FF0;
  while (i + 8 <= dest_w) {
    p = generate_32bit_scaled_data_write(p, quality, orig_w, dest_w, 0, 1,
                                         i + 0 * 1, 1, 2, i + 0 * 2, 1, 2,
                                         i + 1 * 2, 0, 1, i + 1 * 1);
    p = generate_32bit_scaled_data_write(p, quality, orig_w, dest_w, 0, 1,
                                         i + 3 * 1, 0, 1, i + 2 * 1, 0, 1,
                                         i + 4 * 1, 1, 2, i + 2 * 2);
    p = generate_32bit_scaled_data_write(p, quality, orig_w, dest_w, 1, 2,
                                         i + 3 * 2, 0, 1, i + 5 * 1, 0, 1,
                                         i + 7 * 1, 0, 1, i + 6 * 1);
    i += 8;
  }
  *p++ = 0xE8BD8FF0;
  cmdcount = p - cmdbuffer;
  return cmdcount;
}


x86 assembly (clang, -O0):
<generate_yuv420p_to_yuv420_line_scaler>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0x90,%rsp
mov    %rdi,-0x18(%rbp)
mov    %esi,-0x1c(%rbp)
mov    %edx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8d,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x50(%rbp)
movl   $0xe92d4ff0,(%rax)
mov    -0x2c(%rbp),%eax
add    $0x8,%eax
cmp    -0x24(%rbp),%eax
jg     12ea <generate_yuv420p_to_yuv420_line_scaler+0x1da>
mov    -0x50(%rbp),%rdi
mov    -0x28(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    -0x2c(%rbp),%ebx
add    $0x0,%ebx
mov    -0x2c(%rbp),%r11d
add    $0x0,%r11d
mov    -0x2c(%rbp),%r10d
add    $0x2,%r10d
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
xor    %r8d,%r8d
mov    $0x1,%r9d
mov    %ebx,(%rsp)
movl   $0x1,0x8(%rsp)
movl   $0x2,0x10(%rsp)
mov    %r11d,0x18(%rsp)
movl   $0x1,0x20(%rsp)
movl   $0x2,0x28(%rsp)
mov    %r10d,0x30(%rsp)
movl   $0x0,0x38(%rsp)
movl   $0x1,0x40(%rsp)
mov    %eax,0x48(%rsp)
call   1030 <generate_32bit_scaled_data_write@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x28(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    -0x2c(%rbp),%ebx
add    $0x3,%ebx
mov    -0x2c(%rbp),%r11d
add    $0x2,%r11d
mov    -0x2c(%rbp),%r10d
add    $0x4,%r10d
mov    -0x2c(%rbp),%eax
add    $0x4,%eax
xor    %r8d,%r8d
mov    $0x1,%r9d
mov    %ebx,(%rsp)
movl   $0x0,0x8(%rsp)
movl   $0x1,0x10(%rsp)
mov    %r11d,0x18(%rsp)
movl   $0x0,0x20(%rsp)
movl   $0x1,0x28(%rsp)
mov    %r10d,0x30(%rsp)
movl   $0x1,0x38(%rsp)
movl   $0x2,0x40(%rsp)
mov    %eax,0x48(%rsp)
call   1030 <generate_32bit_scaled_data_write@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x28(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    -0x2c(%rbp),%ebx
add    $0x6,%ebx
mov    -0x2c(%rbp),%r11d
add    $0x5,%r11d
mov    -0x2c(%rbp),%r10d
add    $0x7,%r10d
mov    -0x2c(%rbp),%eax
add    $0x6,%eax
mov    $0x1,%r8d
mov    $0x2,%r9d
xor    %r14d,%r14d
mov    %ebx,(%rsp)
movl   $0x0,0x8(%rsp)
movl   $0x1,0x10(%rsp)
mov    %r11d,0x18(%rsp)
movl   $0x0,0x20(%rsp)
movl   $0x1,0x28(%rsp)
mov    %r10d,0x30(%rsp)
movl   $0x0,0x38(%rsp)
movl   $0x1,0x40(%rsp)
mov    %eax,0x48(%rsp)
call   1030 <generate_32bit_scaled_data_write@plt>
mov    %rax,-0x50(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0x2c(%rbp)
jmp    1153 <generate_yuv420p_to_yuv420_line_scaler+0x43>
mov    -0x50(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x50(%rbp)
movl   $0xe8bd8ff0,(%rax)
mov    -0x50(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
sar    $0x2,%rax
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
add    $0x90,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_yuv420p_to_yuv420_line_scaler>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0x4(%rdi),%rax
mov    %rdi,(%rsp)
movl   $0xe92d4ff0,(%rdi)
cmp    $0x8,%ecx
jl     11fc <generate_yuv420p_to_yuv420_line_scaler+0xec>
mov    %r8d,%r15d
mov    %ecx,%r13d
mov    %edx,%r12d
xor    %ebp,%ebp
nopl   (%rax)
lea    0x2(%rbp),%r14d
lea    0x1(%rbp),%ebx
mov    %rax,%rdi
mov    %r15d,%esi
mov    %r12d,%edx
mov    %r13d,%ecx
xor    %r8d,%r8d
mov    $0x1,%r9d
push   %rbx
push   $0x1
push   $0x0
push   %r14
push   $0x2
push   $0x1
push   %rbp
push   $0x2
push   $0x1
push   %rbp
call   1030 <generate_32bit_scaled_data_write@plt>
add    $0x50,%rsp
lea    0x3(%rbp),%r10d
lea    0x4(%rbp),%ebx
mov    %rax,%rdi
mov    %r15d,%esi
mov    %r12d,%edx
mov    %r13d,%ecx
xor    %r8d,%r8d
mov    $0x1,%r9d
push   %rbx
push   $0x2
push   $0x1
push   %rbx
push   $0x1
push   $0x0
push   %r14
push   $0x1
push   $0x0
push   %r10
call   1030 <generate_32bit_scaled_data_write@plt>
add    $0x50,%rsp
lea    0x6(%rbp),%ebx
lea    0x5(%rbp),%r10d
lea    0x7(%rbp),%r11d
mov    %rax,%rdi
mov    %r15d,%esi
mov    %r12d,%edx
mov    %r13d,%ecx
mov    $0x1,%r8d
mov    $0x2,%r9d
push   %rbx
push   $0x1
push   $0x0
push   %r11
push   $0x1
push   $0x0
push   %r10
push   $0x1
push   $0x0
push   %rbx
call   1030 <generate_32bit_scaled_data_write@plt>
add    $0x50,%rsp
lea    0x8(%rbp),%ecx
add    $0x10,%ebp
cmp    %r13d,%ebp
mov    %ecx,%ebp
jle    1140 <generate_yuv420p_to_yuv420_line_scaler+0x30>
movl   $0xe8bd8ff0,(%rax)
sub    (%rsp),%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_yuv420_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
store i32 0, i32* %11
%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
br label %23
23: ; preds = %28, %5
%24 = load i32, i32* %11
%25 = add nsw i32 %24, 8
%26 = load i32, i32* %9
%27 = icmp sle i32 %25, %26
br i1 %27, label %28, label %70
28: ; preds = %23
%29 = load i32*, i32** %19
%30 = load i32, i32* %10
%31 = load i32, i32* %8
%32 = load i32, i32* %9
%33 = load i32, i32* %11
%34 = add nsw i32 %33, 0
%35 = load i32, i32* %11
%36 = add nsw i32 %35, 0
%37 = load i32, i32* %11
%38 = add nsw i32 %37, 2
%39 = load i32, i32* %11
%40 = add nsw i32 %39, 1
%41 = call i32* @generate_32bit_scaled_data_write(i32* %29, i32 %30, i32 %31, i32 %32, i32 0, i32 1, i32 %34, i32 1, i32 2, i32 %36, i32 1, i32 2, i32 %38, i32 0, i32 1, i32 %40)
store i32* %41, i32** %19
%42 = load i32*, i32** %19
%43 = load i32, i32* %10
%44 = load i32, i32* %8
%45 = load i32, i32* %9
%46 = load i32, i32* %11
%47 = add nsw i32 %46, 3
%48 = load i32, i32* %11
%49 = add nsw i32 %48, 2
%50 = load i32, i32* %11
%51 = add nsw i32 %50, 4
%52 = load i32, i32* %11
%53 = add nsw i32 %52, 4
%54 = call i32* @generate_32bit_scaled_data_write(i32* %42, i32 %43, i32 %44, i32 %45, i32 0, i32 1, i32 %47, i32 0, i32 1, i32 %49, i32 0, i32 1, i32 %51, i32 1, i32 2, i32 %53)
store i32* %54, i32** %19
%55 = load i32*, i32** %19
%56 = load i32, i32* %10
%57 = load i32, i32* %8
%58 = load i32, i32* %9
%59 = load i32, i32* %11
%60 = add nsw i32 %59, 6
%61 = load i32, i32* %11
%62 = add nsw i32 %61, 5
%63 = load i32, i32* %11
%64 = add nsw i32 %63, 7
%65 = load i32, i32* %11
%66 = add nsw i32 %65, 6
%67 = call i32* @generate_32bit_scaled_data_write(i32* %55, i32 %56, i32 %57, i32 %58, i32 1, i32 2, i32 %60, i32 0, i32 1, i32 %62, i32 0, i32 1, i32 %64, i32 0, i32 1, i32 %66)
store i32* %67, i32** %19
%68 = load i32, i32* %11
%69 = add nsw i32 %68, 8
store i32 %69, i32* %11
br label %23
70: ; preds = %23
%71 = load i32*, i32** %19
%72 = getelementptr inbounds i32, i32* %71, i32 1
store i32* %72, i32** %19
store i32 -390230032, i32* %71
%73 = load i32*, i32** %19
%74 = load i32*, i32** %6
%75 = ptrtoint i32* %73 to i64
%76 = ptrtoint i32* %74 to i64
%77 = sub i64 %75, %76
%78 = sdiv exact i64 %77, 4
%79 = trunc i64 %78 to i32
store i32 %79, i32* %14
%80 = load i32, i32* %14
ret i32 %80
}

LLVM IR (-O2):
define i32 @generate_yuv420p_to_yuv420_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 slt i32 %3, 8
br i1 %7, label %24, label %8
8: ; preds = %5, %8
%9 = phi i32 [ %22, %8 ], [ 8, %5 ]
%10 = phi i32* [ %21, %8 ], [ %6, %5 ]
%11 = phi i32 [ %9, %8 ], [ 0, %5 ]
%12 = or i32 %11, 2
%13 = or i32 %11, 1
%14 = tail call i32* @generate_32bit_scaled_data_write(i32* %10, i32 %4, i32 %2, i32 %3, i32 0, i32 1, i32 %11, i32 1, i32 2, i32 %11, i32 1, i32 2, i32 %12, i32 0, i32 1, i32 %13)
%15 = or i32 %11, 3
%16 = or i32 %11, 4
%17 = tail call i32* @generate_32bit_scaled_data_write(i32* %14, i32 %4, i32 %2, i32 %3, i32 0, i32 1, i32 %15, i32 0, i32 1, i32 %12, i32 0, i32 1, i32 %16, i32 1, i32 2, i32 %16)
%18 = or i32 %11, 6
%19 = or i32 %11, 5
%20 = or i32 %11, 7
%21 = tail call i32* @generate_32bit_scaled_data_write(i32* %17, i32 %4, i32 %2, i32 %3, i32 1, i32 2, i32 %18, i32 0, i32 1, i32 %19, i32 0, i32 1, i32 %20, i32 0, i32 1, i32 %18)
%22 = add nuw nsw i32 %9, 8
%23 = icmp sgt i32 %22, %3
br i1 %23, label %24, label %8
24: ; preds = %8, %5
%25 = phi i32* [ %6, %5 ], [ %21, %8 ]
%26 = getelementptr inbounds i32, i32* %25, i64 1
store i32 -390230032, i32* %25
%27 = ptrtoint i32* %26 to i64
%28 = ptrtoint i32* %0 to i64
%29 = sub i64 %27, %28
%30 = lshr exact i64 %29, 2
%31 = trunc i64 %30 to i32
ret i32 %31
}