#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 uint32_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fill_volume(unsigned char *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int, int, int);
int main(int argc, char **argv) {
  uint32_t num_elements = 352 * 288 * 25;
  uint32_t pixels_per_frame = 352 * 288;
  unsigned char y[num_elements];
  unsigned char u[num_elements / 4];
  unsigned char v[num_elements / 4];
  uint32_t i = 0;
  for (; i < num_elements; ++i) {
    y[i] = 0;
  }
  fill_volume(y);
  i = 0;
  for (; i < num_elements / 4; ++i) {
    u[i] = 128;
    v[i] = 128;
  }
  unsigned int z = 0;
  FILE *out = fopen("yuv420p_25f_352x288.bin", "wb");
  for (; z < 25; ++z) {
    fwrite(&y[z * pixels_per_frame], 1, pixels_per_frame, out);
    fwrite(&u[z * pixels_per_frame / 4], 1, pixels_per_frame / 4, out);
    fwrite(&v[z * pixels_per_frame / 4], 1, pixels_per_frame / 4, out);
  }
  fclose(out);
  printf("%i frames (%ix%i) written to yuv420p_25f_352x288.bin\n", 25, 352,
         288);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x26ac00,-0x14(%rbp)
movl   $0x18c00,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x60(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0x3,%ecx
test   %eax,%eax
cmovs  %ecx,%eax
sar    $0x2,%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0x3,%ecx
test   %eax,%eax
cmovs  %ecx,%eax
sar    $0x2,%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    121f <main+0xcf>
mov    -0x60(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11f9 <main+0xa9>
mov    -0x60(%rbp),%rdi
call   1030 <fill_volume@plt>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x64(%rbp),%eax
cmp    %ecx,%eax
jge    1273 <main+0x123>
mov    -0x50(%rbp),%rax
mov    -0x58(%rbp),%rcx
movslq -0x3c(%rbp),%rdx
movb   $0x80,(%rcx,%rdx,1)
movslq -0x3c(%rbp),%rcx
movb   $0x80,(%rax,%rcx,1)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    122f <main+0xdf>
movl   $0x0,-0x40(%rbp)
lea    0xd7f(%rip),%rdi
lea    0xd90(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmpl   $0x19,-0x40(%rbp)
jae    1326 <main+0x1d6>
mov    -0x60(%rbp),%rdi
mov    -0x40(%rbp),%eax
imul   -0x18(%rbp),%eax
mov    %eax,%eax
add    %rax,%rdi
mov    -0x18(%rbp),%edx
mov    -0x48(%rbp),%rcx
mov    $0x1,%esi
call   1070 <fwrite@plt>
mov    -0x58(%rbp),%rdi
mov    -0x40(%rbp),%eax
imul   -0x18(%rbp),%eax
shr    $0x2,%eax
mov    %eax,%eax
add    %rax,%rdi
mov    -0x18(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
mov    -0x48(%rbp),%rcx
mov    $0x1,%esi
call   1070 <fwrite@plt>
mov    -0x50(%rbp),%rdi
mov    -0x40(%rbp),%eax
imul   -0x18(%rbp),%eax
shr    $0x2,%eax
mov    %eax,%eax
add    %rax,%rdi
mov    -0x18(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
mov    -0x48(%rbp),%rcx
mov    $0x1,%esi
call   1070 <fwrite@plt>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    1291 <main+0x141>
mov    -0x48(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xce5(%rip),%rdi
mov    $0x19,%esi
mov    $0x160,%edx
mov    $0x120,%ecx
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x3a0200,%rsp
lea    0x135600(%rsp),%r15
xor    %ebx,%ebx
mov    $0x26ac00,%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
mov    %r15,%rdi
call   1030 <fill_volume@plt>
lea    0x9ab00(%rsp),%rdi
mov    $0x9ab00,%edx
mov    $0x80,%esi
call   1060 <memset@plt>
mov    %rsp,%rdi
mov    $0x9ab00,%edx
mov    $0x80,%esi
call   1060 <memset@plt>
lea    0xe43(%rip),%rdi
lea    0xe54(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r14
nopl   0x0(%rax)
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x18c00,%edx
mov    %r14,%rcx
call   1080 <fwrite@plt>
lea    (%rsp,%rbx,1),%rdi
add    $0x9ab00,%rdi
mov    $0x1,%esi
mov    $0x6300,%edx
mov    %r14,%rcx
call   1080 <fwrite@plt>
lea    (%rsp,%rbx,1),%rdi
mov    $0x1,%esi
mov    $0x6300,%edx
mov    %r14,%rcx
call   1080 <fwrite@plt>
add    $0x6300,%rbx
add    $0x18c00,%r15
cmp    $0x9ab00,%rbx
jne    11d0 <main+0x70>
mov    %r14,%rdi
call   1040 <fclose@plt>
lea    0xddd(%rip),%rdi
mov    $0x19,%esi
mov    $0x160,%edx
mov    $0x120,%ecx
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x3a0200,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [24 x i8] c"yuv420p_25f_352x288.bin\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [54 x i8] c"%i frames (%ix%i) written to yuv420p_25f_352x288.bin\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 2534400, i32* %6
store i32 101376, i32* %7
%15 = load i32, i32* %6
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %8
%18 = alloca i8, i64 %16
store i64 %16, i64* %9
%19 = load i32, i32* %6
%20 = sdiv i32 %19, 4
%21 = zext i32 %20 to i64
%22 = alloca i8, i64 %21
store i64 %21, i64* %10
%23 = load i32, i32* %6
%24 = sdiv i32 %23, 4
%25 = zext i32 %24 to i64
%26 = alloca i8, i64 %25
store i64 %25, i64* %11
store i32 0, i32* %12
br label %27
27: ; preds = %35, %2
%28 = load i32, i32* %12
%29 = load i32, i32* %6
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %38
31: ; preds = %27
%32 = load i32, i32* %12
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %18, i64 %33
store i8 0, i8* %34
br label %35
35: ; preds = %31
%36 = load i32, i32* %12
%37 = add nsw i32 %36, 1
store i32 %37, i32* %12
br label %27
38: ; preds = %27
%39 = call i32 @fill_volume(i8* %18)
store i32 0, i32* %12
br label %40
40: ; preds = %52, %38
%41 = load i32, i32* %12
%42 = load i32, i32* %6
%43 = sdiv i32 %42, 4
%44 = icmp slt i32 %41, %43
br i1 %44, label %45, label %55
45: ; preds = %40
%46 = load i32, i32* %12
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %22, i64 %47
store i8 -128, i8* %48
%49 = load i32, i32* %12
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %26, i64 %50
store i8 -128, i8* %51
br label %52
52: ; preds = %45
%53 = load i32, i32* %12
%54 = add nsw i32 %53, 1
store i32 %54, i32* %12
br label %40
55: ; preds = %40
store i32 0, i32* %13
%56 = call i32* @fopen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %56, i32** %14
br label %57
57: ; preds = %89, %55
%58 = load i32, i32* %13
%59 = icmp ult i32 %58, 25
br i1 %59, label %60, label %92
60: ; preds = %57
%61 = load i32, i32* %13
%62 = load i32, i32* %7
%63 = mul i32 %61, %62
%64 = zext i32 %63 to i64
%65 = getelementptr inbounds i8, i8* %18, i64 %64
%66 = load i32, i32* %7
%67 = load i32*, i32** %14
%68 = call i32 @fwrite(i8* %65, i32 1, i32 %66, i32* %67)
%69 = load i32, i32* %13
%70 = load i32, i32* %7
%71 = mul i32 %69, %70
%72 = udiv i32 %71, 4
%73 = zext i32 %72 to i64
%74 = getelementptr inbounds i8, i8* %22, i64 %73
%75 = load i32, i32* %7
%76 = sdiv i32 %75, 4
%77 = load i32*, i32** %14
%78 = call i32 @fwrite(i8* %74, i32 1, i32 %76, i32* %77)
%79 = load i32, i32* %13
%80 = load i32, i32* %7
%81 = mul i32 %79, %80
%82 = udiv i32 %81, 4
%83 = zext i32 %82 to i64
%84 = getelementptr inbounds i8, i8* %26, i64 %83
%85 = load i32, i32* %7
%86 = sdiv i32 %85, 4
%87 = load i32*, i32** %14
%88 = call i32 @fwrite(i8* %84, i32 1, i32 %86, i32* %87)
br label %89
89: ; preds = %60
%90 = load i32, i32* %13
%91 = add i32 %90, 1
store i32 %91, i32* %13
br label %57
92: ; preds = %57
%93 = load i32*, i32** %14
%94 = call i32 @fclose(i32* %93)
%95 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i32 25, i32 352, i32 288)
store i32 0, i32* %3
%96 = load i8*, i8** %8
%97 = load i32, i32* %3
ret i32 %97
}

LLVM IR (-O2):
@.str = [24 x i8] c"yuv420p_25f_352x288.bin\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [54 x i8] c"%i frames (%ix%i) written to yuv420p_25f_352x288.bin\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [2534400 x i8]
%4 = getelementptr inbounds [2534400 x i8], [2534400 x i8]* %3, i64 0, i64 0
%5 = alloca [633600 x i8]
%6 = getelementptr inbounds [633600 x i8], [633600 x i8]* %5, i64 0, i64 0
%7 = alloca [633600 x i8]
%8 = getelementptr inbounds [633600 x i8], [633600 x i8]* %7, i64 0, i64 0
%9 = getelementptr inbounds [2534400 x i8], [2534400 x i8]* %3, i64 0, i64 0
%10 = call i32 @fill_volume(i8* %9)
%11 = call i32* @fopen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %2, %12
%13 = phi i64 [ 0, %2 ], [ %22, %12 ]
%14 = mul nuw nsw i64 %13, 101376
%15 = getelementptr inbounds [2534400 x i8], [2534400 x i8]* %3, i64 0, i64 %14
%16 = call i32 @fwrite(i8* %15, i32 1, i32 101376, i32* %11)
%17 = lshr exact i64 %14, 2
%18 = getelementptr inbounds [633600 x i8], [633600 x i8]* %5, i64 0, i64 %17
%19 = call i32 @fwrite(i8* %18, i32 1, i32 25344, i32* %11)
%20 = getelementptr inbounds [633600 x i8], [633600 x i8]* %7, i64 0, i64 %17
%21 = call i32 @fwrite(i8* %20, i32 1, i32 25344, i32* %11)
%22 = add nuw nsw i64 %13, 1
%23 = icmp eq i64 %22, 25
br i1 %23, label %24, label %12
24: ; preds = %12
%25 = call i32 @fclose(i32* %11)
%26 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i32 25, i32 352, i32 288)
ret i32 0
}