#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*/ plane_copy(unsigned char *, int, unsigned char *, int, int,
                              int);
void yuv420_to_yuv420_crop(unsigned char *pInpY, unsigned char *pInpCb,
                           unsigned char *pInpCr, int picWidth, int picHeight,
                           int stride, int CropLeft, int CropRight, int CropTop,
                           int CropBottom, unsigned char *pDest,
                           int *pDestWidth, int *pDestHeight) {
  unsigned char *p_sour[3];
  unsigned char *p_dest[3];
  int inp_width = picWidth;
  int inp_height = picHeight;
  int out_width = picWidth;
  int out_height = picHeight;
  p_sour[0] = pInpY;
  p_sour[1] = pInpCb;
  p_sour[2] = pInpCr;
  if (CropLeft || CropRight || CropTop || CropBottom) {
    p_sour[0] = pInpY + (CropTop * stride + CropLeft);
    p_sour[1] = pInpCb + (CropTop / 2 * stride / 2 + CropLeft / 2);
    p_sour[2] = pInpCr + (CropTop / 2 * stride / 2 + CropLeft / 2);
    inp_width = inp_width - (CropLeft + CropRight);
    inp_height = inp_height - (CropTop + CropBottom);
    out_width = inp_width;
    out_height = inp_height;
  }
  *pDestWidth = out_width;
  *pDestHeight = out_height;
  p_dest[0] = pDest;
  p_dest[1] = p_dest[0] + out_width * out_height;
  p_dest[2] = p_dest[1] + out_width / 2 * out_height / 2;
  plane_copy(p_dest[0], out_width, p_sour[0], stride, inp_width, inp_height);
  plane_copy(p_dest[1], out_width / 2, p_sour[1], stride / 2, inp_width / 2,
             inp_height / 2);
  plane_copy(p_dest[2], out_width / 2, p_sour[2], stride / 2, inp_width / 2,
             inp_height / 2);
}


x86 assembly (clang, -O0):
<yuv420_to_yuv420_crop>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    0x40(%rbp),%rax
mov    0x38(%rbp),%rax
mov    0x30(%rbp),%rax
mov    0x28(%rbp),%eax
mov    0x20(%rbp),%eax
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x68(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x70(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpl   $0x0,0x10(%rbp)
jne    11a2 <yuv420_to_yuv420_crop+0x92>
cmpl   $0x0,0x18(%rbp)
jne    11a2 <yuv420_to_yuv420_crop+0x92>
cmpl   $0x0,0x20(%rbp)
jne    11a2 <yuv420_to_yuv420_crop+0x92>
cmpl   $0x0,0x28(%rbp)
je     125e <yuv420_to_yuv420_crop+0x14e>
mov    -0x8(%rbp),%rax
mov    0x20(%rbp),%ecx
imul   -0x24(%rbp),%ecx
add    0x10(%rbp),%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    0x20(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
imul   -0x24(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    0x10(%rbp),%eax
mov    $0x2,%esi
cltd
idiv   %esi
mov    %eax,%edx
mov    -0x80(%rbp),%rax
add    %edx,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    0x20(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
imul   -0x24(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    0x10(%rbp),%eax
mov    $0x2,%esi
cltd
idiv   %esi
mov    %eax,%edx
mov    -0x78(%rbp),%rax
add    %edx,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x64(%rbp),%eax
mov    0x10(%rbp),%ecx
add    0x18(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x64(%rbp)
mov    -0x68(%rbp),%eax
mov    0x20(%rbp),%ecx
add    0x28(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x68(%rbp)
mov    -0x64(%rbp),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x68(%rbp),%eax
mov    %eax,-0x70(%rbp)
mov    -0x6c(%rbp),%ecx
mov    0x38(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x70(%rbp),%ecx
mov    0x40(%rbp),%rax
mov    %ecx,(%rax)
mov    0x30(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rax
mov    -0x6c(%rbp),%ecx
imul   -0x70(%rbp),%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,-0x98(%rbp)
mov    -0x6c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
imul   -0x70(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x98(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x50(%rbp)
mov    -0x60(%rbp),%rdi
mov    -0x6c(%rbp),%esi
mov    -0x40(%rbp),%rdx
mov    -0x24(%rbp),%ecx
mov    -0x64(%rbp),%r8d
mov    -0x68(%rbp),%r9d
call   1030 <plane_copy@plt>
mov    -0x58(%rbp),%rdi
mov    -0x6c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
mov    -0x38(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    -0x24(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x64(%rbp),%eax
mov    $0x2,%r8d
cltd
idiv   %r8d
mov    %eax,%r8d
mov    -0x68(%rbp),%eax
mov    $0x2,%r9d
cltd
idiv   %r9d
mov    -0x90(%rbp),%rdx
mov    %eax,%r9d
call   1030 <plane_copy@plt>
mov    -0x50(%rbp),%rdi
mov    -0x6c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
mov    -0x30(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x24(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x64(%rbp),%eax
mov    $0x2,%r8d
cltd
idiv   %r8d
mov    %eax,%r8d
mov    -0x68(%rbp),%eax
mov    $0x2,%r9d
cltd
idiv   %r9d
mov    -0x88(%rbp),%rdx
mov    %eax,%r9d
call   1030 <plane_copy@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<yuv420_to_yuv420_crop>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9d,%r12d
mov    %r8d,%r13d
mov    %ecx,%r8d
mov    %rdi,%r11
mov    0x80(%rsp),%r9
mov    0x78(%rsp),%r10
mov    0x70(%rsp),%rdi
mov    0x68(%rsp),%r14d
mov    0x60(%rsp),%ebx
mov    0x58(%rsp),%r15d
mov    0x50(%rsp),%ecx
mov    %r15d,%eax
or     %ecx,%eax
or     %ebx,%eax
or     %r14d,%eax
je     11a8 <yuv420_to_yuv420_crop+0x98>
mov    %ebx,%eax
imul   %r12d,%eax
add    %ecx,%eax
cltq
add    %rax,%r11
mov    %ebx,%eax
shr    $0x1f,%eax
add    %ebx,%eax
sar    %eax
imul   %r12d,%eax
mov    %eax,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
sar    %ebp
mov    %ecx,%eax
shr    $0x1f,%eax
add    %ecx,%eax
sar    %eax
add    %ebp,%eax
cltq
add    %rax,%rsi
mov    %rsi,0x8(%rsp)
add    %rax,%rdx
mov    %rdx,0x10(%rsp)
add    %ecx,%r15d
sub    %r15d,%r8d
add    %ebx,%r14d
sub    %r14d,%r13d
jmp    11b2 <yuv420_to_yuv420_crop+0xa2>
mov    %rdx,0x10(%rsp)
mov    %rsi,0x8(%rsp)
mov    %r8d,(%r10)
mov    %r13d,(%r9)
mov    %r13d,%eax
imul   %r8d,%eax
movslq %eax,%r15
add    %rdi,%r15
mov    %r8d,%ebx
shr    $0x1f,%ebx
add    %r8d,%ebx
sar    %ebx
mov    %ebx,%eax
imul   %r13d,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
movslq %ecx,%r14
add    %r15,%r14
mov    %r8d,%esi
mov    %r11,%rdx
mov    %r12d,%ecx
mov    %r13d,%r9d
call   1030 <plane_copy@plt>
mov    %r12d,%eax
shr    $0x1f,%r12d
add    %eax,%r12d
sar    %r12d
mov    %r13d,%ebp
shr    $0x1f,%ebp
add    %r13d,%ebp
sar    %ebp
mov    %r15,%rdi
mov    %ebx,%esi
mov    0x8(%rsp),%rdx
mov    %r12d,%ecx
mov    %ebx,%r8d
mov    %ebp,%r9d
call   1030 <plane_copy@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    0x10(%rsp),%rdx
mov    %r12d,%ecx
mov    %ebx,%r8d
mov    %ebp,%r9d
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <plane_copy@plt>

LLVM IR (-O0):
define void @yuv420_to_yuv420_crop(i8* %0, i8* %1, i8* %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7, i32 %8, i32 %9, i8* %10, i32* %11, i32* %12) {
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
%24 = alloca i8*
%25 = alloca i32*
%26 = alloca i32*
%27 = alloca [3 x i8*]
%28 = alloca [3 x i8*]
%29 = alloca i32
%30 = alloca i32
%31 = alloca i32
%32 = alloca i32
store i8* %0, i8** %14
store i8* %1, i8** %15
store i8* %2, i8** %16
store i32 %3, i32* %17
store i32 %4, i32* %18
store i32 %5, i32* %19
store i32 %6, i32* %20
store i32 %7, i32* %21
store i32 %8, i32* %22
store i32 %9, i32* %23
store i8* %10, i8** %24
store i32* %11, i32** %25
store i32* %12, i32** %26
%33 = load i32, i32* %17
store i32 %33, i32* %29
%34 = load i32, i32* %18
store i32 %34, i32* %30
%35 = load i32, i32* %17
store i32 %35, i32* %31
%36 = load i32, i32* %18
store i32 %36, i32* %32
%37 = load i8*, i8** %14
%38 = getelementptr inbounds [3 x i8*], [3 x i8*]* %27, i64 0, i64 0
store i8* %37, i8** %38
%39 = load i8*, i8** %15
%40 = getelementptr inbounds [3 x i8*], [3 x i8*]* %27, i64 0, i64 1
store i8* %39, i8** %40
%41 = load i8*, i8** %16
%42 = getelementptr inbounds [3 x i8*], [3 x i8*]* %27, i64 0, i64 2
store i8* %41, i8** %42
%43 = load i32, i32* %20
%44 = icmp ne i32 %43, 0
br i1 %44, label %54, label %45
45: ; preds = %13
%46 = load i32, i32* %21
%47 = icmp ne i32 %46, 0
br i1 %47, label %54, label %48
48: ; preds = %45
%49 = load i32, i32* %22
%50 = icmp ne i32 %49, 0
br i1 %50, label %54, label %51
51: ; preds = %48
%52 = load i32, i32* %23
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %100
54: ; preds = %51, %48, %45, %13
%55 = load i8*, i8** %14
%56 = load i32, i32* %22
%57 = load i32, i32* %19
%58 = mul nsw i32 %56, %57
%59 = load i32, i32* %20
%60 = add nsw i32 %58, %59
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %55, i64 %61
%63 = getelementptr inbounds [3 x i8*], [3 x i8*]* %27, i64 0, i64 0
store i8* %62, i8** %63
%64 = load i8*, i8** %15
%65 = load i32, i32* %22
%66 = sdiv i32 %65, 2
%67 = load i32, i32* %19
%68 = mul nsw i32 %66, %67
%69 = sdiv i32 %68, 2
%70 = load i32, i32* %20
%71 = sdiv i32 %70, 2
%72 = add nsw i32 %69, %71
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i8, i8* %64, i64 %73
%75 = getelementptr inbounds [3 x i8*], [3 x i8*]* %27, i64 0, i64 1
store i8* %74, i8** %75
%76 = load i8*, i8** %16
%77 = load i32, i32* %22
%78 = sdiv i32 %77, 2
%79 = load i32, i32* %19
%80 = mul nsw i32 %78, %79
%81 = sdiv i32 %80, 2
%82 = load i32, i32* %20
%83 = sdiv i32 %82, 2
%84 = add nsw i32 %81, %83
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds i8, i8* %76, i64 %85
%87 = getelementptr inbounds [3 x i8*], [3 x i8*]* %27, i64 0, i64 2
store i8* %86, i8** %87
%88 = load i32, i32* %29
%89 = load i32, i32* %20
%90 = load i32, i32* %21
%91 = add nsw i32 %89, %90
%92 = sub nsw i32 %88, %91
store i32 %92, i32* %29
%93 = load i32, i32* %30
%94 = load i32, i32* %22
%95 = load i32, i32* %23
%96 = add nsw i32 %94, %95
%97 = sub nsw i32 %93, %96
store i32 %97, i32* %30
%98 = load i32, i32* %29
store i32 %98, i32* %31
%99 = load i32, i32* %30
store i32 %99, i32* %32
br label %100
100: ; preds = %54, %51
%101 = load i32, i32* %31
%102 = load i32*, i32** %25
store i32 %101, i32* %102
%103 = load i32, i32* %32
%104 = load i32*, i32** %26
store i32 %103, i32* %104
%105 = load i8*, i8** %24
%106 = getelementptr inbounds [3 x i8*], [3 x i8*]* %28, i64 0, i64 0
store i8* %105, i8** %106
%107 = getelementptr inbounds [3 x i8*], [3 x i8*]* %28, i64 0, i64 0
%108 = load i8*, i8** %107
%109 = load i32, i32* %31
%110 = load i32, i32* %32
%111 = mul nsw i32 %109, %110
%112 = sext i32 %111 to i64
%113 = getelementptr inbounds i8, i8* %108, i64 %112
%114 = getelementptr inbounds [3 x i8*], [3 x i8*]* %28, i64 0, i64 1
store i8* %113, i8** %114
%115 = getelementptr inbounds [3 x i8*], [3 x i8*]* %28, i64 0, i64 1
%116 = load i8*, i8** %115
%117 = load i32, i32* %31
%118 = sdiv i32 %117, 2
%119 = load i32, i32* %32
%120 = mul nsw i32 %118, %119
%121 = sdiv i32 %120, 2
%122 = sext i32 %121 to i64
%123 = getelementptr inbounds i8, i8* %116, i64 %122
%124 = getelementptr inbounds [3 x i8*], [3 x i8*]* %28, i64 0, i64 2
store i8* %123, i8** %124
%125 = getelementptr inbounds [3 x i8*], [3 x i8*]* %28, i64 0, i64 0
%126 = load i8*, i8** %125
%127 = load i32, i32* %31
%128 = getelementptr inbounds [3 x i8*], [3 x i8*]* %27, i64 0, i64 0
%129 = load i8*, i8** %128
%130 = load i32, i32* %19
%131 = load i32, i32* %29
%132 = load i32, i32* %30
%133 = call i32 @plane_copy(i8* %126, i32 %127, i8* %129, i32 %130, i32 %131, i32 %132)
%134 = getelementptr inbounds [3 x i8*], [3 x i8*]* %28, i64 0, i64 1
%135 = load i8*, i8** %134
%136 = load i32, i32* %31
%137 = sdiv i32 %136, 2
%138 = getelementptr inbounds [3 x i8*], [3 x i8*]* %27, i64 0, i64 1
%139 = load i8*, i8** %138
%140 = load i32, i32* %19
%141 = sdiv i32 %140, 2
%142 = load i32, i32* %29
%143 = sdiv i32 %142, 2
%144 = load i32, i32* %30
%145 = sdiv i32 %144, 2
%146 = call i32 @plane_copy(i8* %135, i32 %137, i8* %139, i32 %141, i32 %143, i32 %145)
%147 = getelementptr inbounds [3 x i8*], [3 x i8*]* %28, i64 0, i64 2
%148 = load i8*, i8** %147
%149 = load i32, i32* %31
%150 = sdiv i32 %149, 2
%151 = getelementptr inbounds [3 x i8*], [3 x i8*]* %27, i64 0, i64 2
%152 = load i8*, i8** %151
%153 = load i32, i32* %19
%154 = sdiv i32 %153, 2
%155 = load i32, i32* %29
%156 = sdiv i32 %155, 2
%157 = load i32, i32* %30
%158 = sdiv i32 %157, 2
%159 = call i32 @plane_copy(i8* %148, i32 %150, i8* %152, i32 %154, i32 %156, i32 %158)
ret void
}

LLVM IR (-O2):
define void @yuv420_to_yuv420_crop(i8* %0, i8* %1, i8* %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7, i32 %8, i32 %9, i8* %10, i32* nocapture writeonly %11, i32* nocapture writeonly %12) {
%14 = or i32 %7, %6
%15 = or i32 %14, %8
%16 = or i32 %15, %9
%17 = icmp eq i32 %16, 0
br i1 %17, label %35, label %18
18: ; preds = %13
%19 = mul nsw i32 %8, %5
%20 = add nsw i32 %19, %6
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %0, i64 %21
%23 = sdiv i32 %8, 2
%24 = mul nsw i32 %23, %5
%25 = sdiv i32 %24, 2
%26 = sdiv i32 %6, 2
%27 = add nsw i32 %25, %26
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %1, i64 %28
%30 = getelementptr inbounds i8, i8* %2, i64 %28
%31 = add i32 %6, %7
%32 = sub i32 %3, %31
%33 = add i32 %8, %9
%34 = sub i32 %4, %33
br label %35
35: ; preds = %13, %18
%36 = phi i8* [ %22, %18 ], [ %0, %13 ]
%37 = phi i8* [ %29, %18 ], [ %1, %13 ]
%38 = phi i8* [ %30, %18 ], [ %2, %13 ]
%39 = phi i32 [ %32, %18 ], [ %3, %13 ]
%40 = phi i32 [ %34, %18 ], [ %4, %13 ]
store i32 %39, i32* %11
store i32 %40, i32* %12
%41 = mul nsw i32 %40, %39
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %10, i64 %42
%44 = sdiv i32 %39, 2
%45 = mul nsw i32 %44, %40
%46 = sdiv i32 %45, 2
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %43, i64 %47
%49 = tail call i32 @plane_copy(i8* %10, i32 %39, i8* %36, i32 %5, i32 %39, i32 %40)
%50 = sdiv i32 %5, 2
%51 = sdiv i32 %40, 2
%52 = tail call i32 @plane_copy(i8* %43, i32 %44, i8* %37, i32 %50, i32 %44, i32 %51)
%53 = tail call i32 @plane_copy(i8* %48, i32 %44, i8* %38, i32 %50, i32 %44, i32 %51)
ret void
}