#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*/ fwrite(unsigned char *, int, int, void *);
int /*<<< orphan*/ printf(char *, void *, int, int, ...);
int /*<<< orphan*/ yuv420_to_yuv420_crop(unsigned char *, unsigned char *,
                                         unsigned char *, int, int, int, int,
                                         int, int, int, unsigned char *, int *,
                                         int *);
int /*<<< orphan*/ yuvi_to_yuv420(unsigned char **, unsigned char **,
                                  unsigned char **, unsigned char *, int, int,
                                  int);
int save_yuv_image(void *yuvFp, unsigned char *pOutYuv, unsigned char *pInpY,
                   unsigned char *pInpCb, unsigned char *pInpCr, int picWidth,
                   int picHeight, int stride, int CropLeft, int CropRight,
                   int CropTop, int CropBottom, unsigned int uiCbCrInterleave) {
  int dest_width = 0;
  int dest_height = 0;
  if (!pInpY || !pInpCb || !pInpCr)
    return 1;
  if (uiCbCrInterleave) {
    yuvi_to_yuv420(&pInpY, &pInpCb, &pInpCr, pOutYuv, picWidth, picHeight,
                   stride);
    if (!CropLeft && !CropRight && !CropTop && !CropBottom) {
      dest_width = stride;
      dest_height = picHeight;
      goto SAVE_YUV_END;
    }
  }
  yuv420_to_yuv420_crop(pInpY, pInpCb, pInpCr, picWidth, picHeight, stride,
                        CropLeft, CropRight, CropTop, CropBottom, pOutYuv,
                        &dest_width, &dest_height);
SAVE_YUV_END:
  if (!fwrite(pOutYuv, sizeof(unsigned char), dest_width * dest_height * 3 / 2,
              yuvFp)) {
    printf("picWidth = %d, picHeight = %d, stride = %d \n", picWidth, picHeight,
           stride);
    printf(
        "rcCrop.left %d|| rcCrop.top %d|| rcCrop.bottom %d|| rcCrop.right %d\n",
        CropLeft, CropTop, CropBottom, CropRight);
    printf("Frame Data fwrite failed file handle is 0x%x, width = %d, height = "
           "%d \n",
           yuvFp, dest_width, dest_height);
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<save_yuv_image>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x80,%rsp
mov    0x40(%rbp),%eax
mov    0x38(%rbp),%eax
mov    0x30(%rbp),%eax
mov    0x28(%rbp),%eax
mov    0x20(%rbp),%eax
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %rdi,-0x30(%rbp)
mov    %rsi,-0x38(%rbp)
mov    %rdx,-0x40(%rbp)
mov    %rcx,-0x48(%rbp)
mov    %r8,-0x50(%rbp)
mov    %r9d,-0x54(%rbp)
movl   $0x0,-0x58(%rbp)
movl   $0x0,-0x5c(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     11ae <save_yuv_image+0x6e>
cmpq   $0x0,-0x48(%rbp)
je     11ae <save_yuv_image+0x6e>
cmpq   $0x0,-0x50(%rbp)
jne    11ba <save_yuv_image+0x7a>
movl   $0x1,-0x24(%rbp)
jmp    130b <save_yuv_image+0x1cb>
cmpl   $0x0,0x40(%rbp)
je     1225 <save_yuv_image+0xe5>
mov    -0x38(%rbp),%rcx
mov    -0x54(%rbp),%r8d
mov    0x10(%rbp),%r9d
mov    0x18(%rbp),%eax
lea    -0x40(%rbp),%rdi
lea    -0x48(%rbp),%rsi
lea    -0x50(%rbp),%rdx
mov    %eax,(%rsp)
call   1050 <yuvi_to_yuv420@plt>
cmpl   $0x0,0x20(%rbp)
jne    1220 <save_yuv_image+0xe0>
cmpl   $0x0,0x28(%rbp)
jne    1220 <save_yuv_image+0xe0>
cmpl   $0x0,0x30(%rbp)
jne    1220 <save_yuv_image+0xe0>
cmpl   $0x0,0x38(%rbp)
jne    1220 <save_yuv_image+0xe0>
mov    0x18(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    0x10(%rbp),%eax
mov    %eax,-0x5c(%rbp)
jmp    127d <save_yuv_image+0x13d>
jmp    1225 <save_yuv_image+0xe5>
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x50(%rbp),%rdx
mov    -0x54(%rbp),%ecx
mov    0x10(%rbp),%r8d
mov    0x18(%rbp),%r9d
mov    0x20(%rbp),%r12d
mov    0x28(%rbp),%r15d
mov    0x30(%rbp),%r14d
mov    0x38(%rbp),%ebx
mov    -0x38(%rbp),%r11
lea    -0x58(%rbp),%r10
lea    -0x5c(%rbp),%rax
mov    %r12d,(%rsp)
mov    %r15d,0x8(%rsp)
mov    %r14d,0x10(%rsp)
mov    %ebx,0x18(%rsp)
mov    %r11,0x20(%rsp)
mov    %r10,0x28(%rsp)
mov    %rax,0x30(%rsp)
call   1040 <yuv420_to_yuv420_crop@plt>
mov    -0x38(%rbp),%rdi
mov    -0x58(%rbp),%eax
imul   -0x5c(%rbp),%eax
imul   $0x3,%eax,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
call   1060 <fwrite@plt>
cmp    $0x0,%eax
jne    1304 <save_yuv_image+0x1c4>
movslq -0x54(%rbp),%rsi
mov    0x10(%rbp),%edx
mov    0x18(%rbp),%ecx
lea    0xd43(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movslq 0x20(%rbp),%rsi
mov    0x30(%rbp),%edx
mov    0x38(%rbp),%ecx
mov    0x28(%rbp),%r8d
lea    0xd54(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%rsi
mov    -0x58(%rbp),%edx
mov    -0x5c(%rbp),%ecx
lea    0xd81(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x24(%rbp)
jmp    130b <save_yuv_image+0x1cb>
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x80,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<save_yuv_image>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,0x20(%rsp)
mov    %rcx,0x18(%rsp)
mov    %r8,0x10(%rsp)
movl   $0x0,0x4(%rsp)
movl   $0x0,(%rsp)
mov    $0x1,%r12d
test   %rdx,%rdx
je     1300 <save_yuv_image+0x1c0>
test   %rcx,%rcx
je     1300 <save_yuv_image+0x1c0>
test   %r8,%r8
je     1300 <save_yuv_image+0x1c0>
mov    %r9d,%r15d
mov    %rsi,%r14
mov    %rdi,%r13
mov    0x88(%rsp),%r12d
mov    0x80(%rsp),%ebx
mov    0x78(%rsp),%ebp
mov    0x70(%rsp),%r11d
mov    0x68(%rsp),%r9d
mov    0x60(%rsp),%eax
cmpl   $0x0,0x90(%rsp)
je     122d <save_yuv_image+0xed>
mov    %r13,0x8(%rsp)
sub    $0x8,%rsp
lea    0x28(%rsp),%rdi
lea    0x20(%rsp),%rsi
lea    0x18(%rsp),%rdx
mov    %r14,%rcx
mov    %r15d,%r8d
mov    %r9,%r13
mov    %eax,%r9d
push   %r13
call   1050 <yuvi_to_yuv420@plt>
mov    0x80(%rsp),%r11d
mov    0x90(%rsp),%ebx
mov    0x88(%rsp),%ebp
add    $0x10,%rsp
mov    %ebp,%eax
or     %r11d,%eax
or     %ebx,%eax
or     %r12d,%eax
je     1267 <save_yuv_image+0x127>
mov    0x20(%rsp),%rdx
mov    0x18(%rsp),%rcx
mov    0x10(%rsp),%r8
mov    %r13,%r9
mov    0x8(%rsp),%r13
mov    0x60(%rsp),%eax
sub    $0x8,%rsp
lea    0x8(%rsp),%r10
mov    %rdx,%rdi
mov    %rcx,%rsi
mov    %r8,%rdx
mov    %r15d,%ecx
mov    %eax,%r8d
push   %r10
lea    0x14(%rsp),%rax
push   %rax
push   %r14
push   %r12
push   %rbx
push   %rbp
push   %r11
call   1040 <yuv420_to_yuv420_crop@plt>
add    $0x40,%rsp
mov    0x4(%rsp),%ecx
mov    (%rsp),%eax
jmp    127b <save_yuv_image+0x13b>
mov    %r13d,0x4(%rsp)
mov    0x60(%rsp),%eax
mov    %eax,(%rsp)
mov    %r13d,%ecx
mov    0x8(%rsp),%r13
imul   %ecx,%eax
lea    (%rax,%rax,2),%eax
mov    %eax,%edx
shr    $0x1f,%edx
add    %eax,%edx
sar    %edx
mov    $0x1,%r12d
mov    %r14,%rdi
mov    $0x1,%esi
mov    %r13,%rcx
call   1060 <fwrite@plt>
test   %eax,%eax
jne    1300 <save_yuv_image+0x1c0>
movslq %r15d,%rsi
lea    0xd52(%rip),%rdi
xor    %r12d,%r12d
mov    0x60(%rsp),%edx
mov    0x68(%rsp),%ecx
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x70(%rsp),%eax
movslq %eax,%rsi
lea    0xd5f(%rip),%rdi
mov    0x80(%rsp),%edx
mov    0x88(%rsp),%ecx
mov    0x78(%rsp),%r8d
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x4(%rsp),%edx
mov    (%rsp),%ecx
lea    0xd7c(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r12d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [45 x i8] c"picWidth = %d, picHeight = %d, stride = %d \0A\00"
@.str.1 = [69 x i8] c"rcCrop.left %d|| rcCrop.top %d|| rcCrop.bottom %d|| rcCrop.right %d\0A\00"
@.str.2 = [72 x i8] c"Frame Data fwrite failed file handle is 0x%x, width = %d, height = %d \0A\00"
define i32 @save_yuv_image(i8* %0, i8* %1, i8* %2, i8* %3, i8* %4, i32 %5, i32 %6, i32 %7, i32 %8, i32 %9, i32 %10, i32 %11, i32 %12) {
%14 = alloca i32
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca i8*
%18 = alloca i8*
%19 = alloca i8*
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
%24 = alloca i32
%25 = alloca i32
%26 = alloca i32
%27 = alloca i32
%28 = alloca i32
%29 = alloca i32
store i8* %0, i8** %15
store i8* %1, i8** %16
store i8* %2, i8** %17
store i8* %3, i8** %18
store i8* %4, i8** %19
store i32 %5, i32* %20
store i32 %6, i32* %21
store i32 %7, i32* %22
store i32 %8, i32* %23
store i32 %9, i32* %24
store i32 %10, i32* %25
store i32 %11, i32* %26
store i32 %12, i32* %27
store i32 0, i32* %28
store i32 0, i32* %29
%30 = load i8*, i8** %17
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %38
32: ; preds = %13
%33 = load i8*, i8** %18
%34 = icmp ne i8* %33, null
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = load i8*, i8** %19
%37 = icmp ne i8* %36, null
br i1 %37, label %39, label %38
38: ; preds = %35, %32, %13
store i32 1, i32* %14
br label %105
39: ; preds = %35
%40 = load i32, i32* %27
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %63
42: ; preds = %39
%43 = load i8*, i8** %16
%44 = load i32, i32* %20
%45 = load i32, i32* %21
%46 = load i32, i32* %22
%47 = call i32 @yuvi_to_yuv420(i8** %17, i8** %18, i8** %19, i8* %43, i32 %44, i32 %45, i32 %46)
%48 = load i32, i32* %23
%49 = icmp ne i32 %48, 0
br i1 %49, label %62, label %50
50: ; preds = %42
%51 = load i32, i32* %24
%52 = icmp ne i32 %51, 0
br i1 %52, label %62, label %53
53: ; preds = %50
%54 = load i32, i32* %25
%55 = icmp ne i32 %54, 0
br i1 %55, label %62, label %56
56: ; preds = %53
%57 = load i32, i32* %26
%58 = icmp ne i32 %57, 0
br i1 %58, label %62, label %59
59: ; preds = %56
%60 = load i32, i32* %22
store i32 %60, i32* %28
%61 = load i32, i32* %21
store i32 %61, i32* %29
br label %76
62: ; preds = %56, %53, %50, %42
br label %63
63: ; preds = %62, %39
%64 = load i8*, i8** %17
%65 = load i8*, i8** %18
%66 = load i8*, i8** %19
%67 = load i32, i32* %20
%68 = load i32, i32* %21
%69 = load i32, i32* %22
%70 = load i32, i32* %23
%71 = load i32, i32* %24
%72 = load i32, i32* %25
%73 = load i32, i32* %26
%74 = load i8*, i8** %16
%75 = call i32 @yuv420_to_yuv420_crop(i8* %64, i8* %65, i8* %66, i32 %67, i32 %68, i32 %69, i32 %70, i32 %71, i32 %72, i32 %73, i8* %74, i32* %28, i32* %29)
br label %76
76: ; preds = %63, %59
%77 = load i8*, i8** %16
%78 = load i32, i32* %28
%79 = load i32, i32* %29
%80 = mul nsw i32 %78, %79
%81 = mul nsw i32 %80, 3
%82 = sdiv i32 %81, 2
%83 = load i8*, i8** %15
%84 = call i32 @fwrite(i8* %77, i32 1, i32 %82, i8* %83)
%85 = icmp ne i32 %84, 0
br i1 %85, label %104, label %86
86: ; preds = %76
%87 = load i32, i32* %20
%88 = sext i32 %87 to i64
%89 = inttoptr i64 %88 to i8*
%90 = load i32, i32* %21
%91 = load i32, i32* %22
%92 = call i32 (i8*, i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %89, i32 %90, i32 %91)
%93 = load i32, i32* %23
%94 = sext i32 %93 to i64
%95 = inttoptr i64 %94 to i8*
%96 = load i32, i32* %25
%97 = load i32, i32* %26
%98 = load i32, i32* %24
%99 = call i32 (i8*, i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.1, i64 0, i64 0), i8* %95, i32 %96, i32 %97, i32 %98)
%100 = load i8*, i8** %15
%101 = load i32, i32* %28
%102 = load i32, i32* %29
%103 = call i32 (i8*, i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.2, i64 0, i64 0), i8* %100, i32 %101, i32 %102)
store i32 0, i32* %14
br label %105
104: ; preds = %76
store i32 1, i32* %14
br label %105
105: ; preds = %104, %86, %38
%106 = load i32, i32* %14
ret i32 %106
}

LLVM IR (-O2):
@.str = [45 x i8] c"picWidth = %d, picHeight = %d, stride = %d \0A\00"
@.str.1 = [69 x i8] c"rcCrop.left %d|| rcCrop.top %d|| rcCrop.bottom %d|| rcCrop.right %d\0A\00"
@.str.2 = [72 x i8] c"Frame Data fwrite failed file handle is 0x%x, width = %d, height = %d \0A\00"
define i32 @save_yuv_image(i8* %0, i8* %1, i8* %2, i8* %3, i8* %4, i32 %5, i32 %6, i32 %7, i32 %8, i32 %9, i32 %10, i32 %11, i32 %12) {
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca i32
%18 = alloca i32
store i8* %2, i8** %14
store i8* %3, i8** %15
store i8* %4, i8** %16
%19 = bitcast i32* %17 to i8*
store i32 0, i32* %17
%20 = bitcast i32* %18 to i8*
store i32 0, i32* %18
%21 = icmp ne i8* %2, null
%22 = icmp ne i8* %3, null
%23 = and i1 %21, %22
%24 = icmp ne i8* %4, null
%25 = and i1 %23, %24
br i1 %25, label %26, label %64
26: ; preds = %13
%27 = icmp eq i32 %12, 0
br i1 %27, label %39, label %28
28: ; preds = %26
%29 = call i32 @yuvi_to_yuv420(i8** %14, i8** %15, i8** %16, i8* %1, i32 %5, i32 %6, i32 %7)
%30 = or i32 %9, %8
%31 = or i32 %30, %10
%32 = or i32 %31, %11
%33 = icmp eq i32 %32, 0
br i1 %33, label %38, label %34
34: ; preds = %28
%35 = load i8*, i8** %14
%36 = load i8*, i8** %15
%37 = load i8*, i8** %16
br label %39
38: ; preds = %28
store i32 %7, i32* %17
store i32 %6, i32* %18
br label %46
39: ; preds = %34, %26
%40 = phi i8* [ %37, %34 ], [ %4, %26 ]
%41 = phi i8* [ %36, %34 ], [ %3, %26 ]
%42 = phi i8* [ %35, %34 ], [ %2, %26 ]
%43 = call i32 @yuv420_to_yuv420_crop(i8* %42, i8* %41, i8* %40, i32 %5, i32 %6, i32 %7, i32 %8, i32 %9, i32 %10, i32 %11, i8* %1, i32* %17, i32* %18)
%44 = load i32, i32* %17
%45 = load i32, i32* %18
br label %46
46: ; preds = %39, %38
%47 = phi i32 [ %45, %39 ], [ %6, %38 ]
%48 = phi i32 [ %44, %39 ], [ %7, %38 ]
%49 = mul i32 %48, 3
%50 = mul i32 %49, %47
%51 = sdiv i32 %50, 2
%52 = call i32 @fwrite(i8* %1, i32 1, i32 %51, i8* %0)
%53 = icmp eq i32 %52, 0
br i1 %53, label %54, label %64
54: ; preds = %46
%55 = sext i32 %5 to i64
%56 = inttoptr i64 %55 to i8*
%57 = call i32 (i8*, i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %56, i32 %6, i32 %7)
%58 = sext i32 %8 to i64
%59 = inttoptr i64 %58 to i8*
%60 = call i32 (i8*, i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.1, i64 0, i64 0), i8* %59, i32 %10, i32 %11, i32 %9)
%61 = load i32, i32* %17
%62 = load i32, i32* %18
%63 = call i32 (i8*, i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.2, i64 0, i64 0), i8* %0, i32 %61, i32 %62)
br label %64
64: ; preds = %46, %13, %54
%65 = phi i32 [ 0, %54 ], [ 1, %13 ], [ 1, %46 ]
ret i32 %65
}