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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(unsigned char *, int, int const, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ fwrite(unsigned char *, int, int const,
                          int /*<<< orphan*/ *);
scalar_t__ malloc(int const);
int /*<<< orphan*/ nv12_border(unsigned char *, int const, int const, int, int,
                               int, int, int /*<<< orphan*/, int /*<<< orphan*/,
                               int);
int main() {
  const int pic_w = 1920;
  const int pic_h = 1080;
  char *input = "videotestsrc_1920x1080.nv12";
  char *output = "outputFile.nv12";
  FILE *fin = fopen(input, "rb+");
  FILE *fout = fopen(output, "wb+");
  unsigned char *buf = (unsigned char *)malloc(pic_w * pic_h * 3 / 2);
  fread(buf, 1, pic_w * pic_h * 3 / 2, fin);
  nv12_border(buf, pic_w, pic_h, 500, 500, 300, 400, 0, 0, 255);
  fwrite(buf, 1, pic_w * pic_h * 3 / 2, fout);
  free(buf);
  fclose(fin);
  fclose(fout);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x780,-0x8(%rbp)
movl   $0x438,-0xc(%rbp)
lea    0xe6c(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe7d(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe7e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe6e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x30(%rbp)
mov    $0x2f7600,%edi
call   1060 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
mov    $0x2f7600,%edx
call   1040 <fread@plt>
mov    -0x38(%rbp),%rdi
mov    $0x780,%esi
mov    $0x438,%edx
mov    $0x1f4,%r8d
mov    $0x12c,%r9d
xor    %eax,%eax
mov    %r8d,%ecx
movl   $0x190,(%rsp)
movl   $0x0,0x8(%rsp)
movl   $0x0,0x10(%rsp)
movl   $0xff,0x18(%rsp)
call   1070 <nv12_border@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
mov    $0x2f7600,%edx
call   1090 <fwrite@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
lea    0xe84(%rip),%rdi
lea    0xea9(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r14
lea    0xe8a(%rip),%rdi
lea    0xe97(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r15
mov    $0x2f7600,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x1,%esi
mov    $0x2f7600,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
mov    %rbx,%rdi
mov    $0x780,%esi
mov    $0x438,%edx
mov    $0x1f4,%ecx
mov    $0x1f4,%r8d
mov    $0x12c,%r9d
push   $0xff
push   $0x0
push   $0x0
push   $0x190
call   1070 <nv12_border@plt>
add    $0x20,%rsp
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x2f7600,%edx
mov    %r15,%rcx
call   1090 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [28 x i8] c"videotestsrc_1920x1080.nv12\00"
@.str.1 = [16 x i8] c"outputFile.nv12\00"
@.str.2 = [4 x i8] c"rb+\00"
@.str.3 = [4 x i8] c"wb+\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8*
store i32 0, i32* %1
store i32 1920, i32* %2
store i32 1080, i32* %3
store i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8** %4
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8** %5
%9 = load i8*, i8** %4
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
store i32* %10, i32** %6
%11 = load i8*, i8** %5
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
store i32* %12, i32** %7
%13 = call i64 @malloc(i32 3110400)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %8
%15 = load i8*, i8** %8
%16 = load i32*, i32** %6
%17 = call i32 @fread(i8* %15, i32 1, i32 3110400, i32* %16)
%18 = load i8*, i8** %8
%19 = call i32 @nv12_border(i8* %18, i32 1920, i32 1080, i32 500, i32 500, i32 300, i32 400, i32 0, i32 0, i32 255)
%20 = load i8*, i8** %8
%21 = load i32*, i32** %7
%22 = call i32 @fwrite(i8* %20, i32 1, i32 3110400, i32* %21)
%23 = load i8*, i8** %8
%24 = call i32 @free(i8* %23)
%25 = load i32*, i32** %6
%26 = call i32 @fclose(i32* %25)
%27 = load i32*, i32** %7
%28 = call i32 @fclose(i32* %27)
ret i32 0
}

LLVM IR (-O2):
@.str = [28 x i8] c"videotestsrc_1920x1080.nv12\00"
@.str.1 = [16 x i8] c"outputFile.nv12\00"
@.str.2 = [4 x i8] c"rb+\00"
@.str.3 = [4 x i8] c"wb+\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%3 = tail call i64 @malloc(i32 3110400)
%4 = inttoptr i64 %3 to i8*
%5 = tail call i32 @fread(i8* %4, i32 1, i32 3110400, i32* %1)
%6 = tail call i32 @nv12_border(i8* %4, i32 1920, i32 1080, i32 500, i32 500, i32 300, i32 400, i32 0, i32 0, i32 255)
%7 = tail call i32 @fwrite(i8* %4, i32 1, i32 3110400, i32* %2)
%8 = tail call i32 @free(i8* %4)
%9 = tail call i32 @fclose(i32* %1)
%10 = tail call i32 @fclose(i32* %2)
ret i32 0
}