#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*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char const *);
void write_yuv(const char *filename, int width, int height,
               unsigned char **components) {
  FILE *F;
  char temp[1024];
  sprintf(temp, "%s.Y", filename);
  F = fopen(temp, "wb");
  fwrite(components[0], width, height, F);
  fclose(F);
  sprintf(temp, "%s.U", filename);
  F = fopen(temp, "wb");
  fwrite(components[1], width * height / 4, 1, F);
  fclose(F);
  sprintf(temp, "%s.V", filename);
  F = fopen(temp, "wb");
  fwrite(components[2], width * height / 4, 1, F);
  fclose(F);
}


x86 assembly (clang, -O0):
<write_yuv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe95(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x420(%rbp),%rdi
lea    0xe87(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x20(%rbp),%rcx
call   1060 <fwrite@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0x420(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe50(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x420(%rbp),%rdi
lea    0xe3a(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0xc(%rbp),%eax
imul   -0x10(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
mov    -0x20(%rbp),%rcx
mov    $0x1,%edx
call   1060 <fwrite@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0x420(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xdf7(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x420(%rbp),%rdi
lea    0xddc(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rdi
mov    -0xc(%rbp),%eax
imul   -0x10(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
mov    -0x20(%rbp),%rcx
mov    $0x1,%edx
call   1060 <fwrite@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_yuv>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rcx,%r15
mov    %edx,%ebx
mov    %esi,%ebp
mov    %rdi,%r13
lea    0xe9e(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
mov    %r13,%rdx
call   1050 <sprintf@plt>
lea    0xe8e(%rip),%rsi
mov    %r14,%rdi
call   1040 <fopen@plt>
mov    %rax,%r12
mov    (%r15),%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %rax,%rcx
call   1060 <fwrite@plt>
mov    %r12,%rdi
call   1030 <fclose@plt>
lea    0xe68(%rip),%rsi
mov    %r14,%rdi
mov    %r13,%rdx
call   1050 <sprintf@plt>
mov    %r14,%rdi
lea    0xe50(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,%r12
mov    0x8(%r15),%rdi
imul   %ebp,%ebx
lea    0x3(%rbx),%ebp
test   %ebx,%ebx
cmovns %ebx,%ebp
sar    $0x2,%ebp
mov    %ebp,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1060 <fwrite@plt>
mov    %r12,%rdi
call   1030 <fclose@plt>
lea    0xe20(%rip),%rsi
mov    %r14,%rdi
mov    %r13,%rdx
call   1050 <sprintf@plt>
mov    %r14,%rdi
lea    0xe03(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,%rbx
mov    0x10(%r15),%rdi
mov    %ebp,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1060 <fwrite@plt>
mov    %rbx,%rdi
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"%s.Y\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [5 x i8] c"%s.U\00"
@.str.3 = [5 x i8] c"%s.V\00"
define void @write_yuv(i8* %0, i32 %1, i32 %2, i8** %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8**
%9 = alloca i32*
%10 = alloca [1024 x i8]
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i8** %3, i8*** %8
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%12 = load i8*, i8** %5
%13 = call i32 @sprintf(i8* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %15, i32** %9
%16 = load i8**, i8*** %8
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = load i32, i32* %6
%20 = load i32, i32* %7
%21 = load i32*, i32** %9
%22 = call i32 @fwrite(i8* %18, i32 %19, i32 %20, i32* %21)
%23 = load i32*, i32** %9
%24 = call i32 @fclose(i32* %23)
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%26 = load i8*, i8** %5
%27 = call i32 @sprintf(i8* %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %26)
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%29 = call i32* @fopen(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %29, i32** %9
%30 = load i8**, i8*** %8
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = load i32, i32* %6
%34 = load i32, i32* %7
%35 = mul nsw i32 %33, %34
%36 = sdiv i32 %35, 4
%37 = load i32*, i32** %9
%38 = call i32 @fwrite(i8* %32, i32 %36, i32 1, i32* %37)
%39 = load i32*, i32** %9
%40 = call i32 @fclose(i32* %39)
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%42 = load i8*, i8** %5
%43 = call i32 @sprintf(i8* %41, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %42)
%44 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%45 = call i32* @fopen(i8* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %45, i32** %9
%46 = load i8**, i8*** %8
%47 = getelementptr inbounds i8*, i8** %46, i64 2
%48 = load i8*, i8** %47
%49 = load i32, i32* %6
%50 = load i32, i32* %7
%51 = mul nsw i32 %49, %50
%52 = sdiv i32 %51, 4
%53 = load i32*, i32** %9
%54 = call i32 @fwrite(i8* %48, i32 %52, i32 1, i32* %53)
%55 = load i32*, i32** %9
%56 = call i32 @fclose(i32* %55)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s.Y\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [5 x i8] c"%s.U\00"
@.str.3 = [5 x i8] c"%s.V\00"
define void @write_yuv(i8* %0, i32 %1, i32 %2, i8** nocapture %3) {
%5 = alloca [1024 x i8]
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%7 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0)
%8 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%9 = load i8*, i8** %3
%10 = tail call i32 @fwrite(i8* %9, i32 %1, i32 %2, i32* %8)
%11 = tail call i32 @fclose(i32* %8)
%12 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%13 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%14 = getelementptr inbounds i8*, i8** %3, i64 1
%15 = load i8*, i8** %14
%16 = mul nsw i32 %2, %1
%17 = sdiv i32 %16, 4
%18 = tail call i32 @fwrite(i8* %15, i32 %17, i32 1, i32* %13)
%19 = tail call i32 @fclose(i32* %13)
%20 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%21 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%22 = getelementptr inbounds i8*, i8** %3, i64 2
%23 = load i8*, i8** %22
%24 = tail call i32 @fwrite(i8* %23, i32 %17, i32 1, i32* %21)
%25 = tail call i32 @fclose(i32* %21)
ret void
}