#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 writebmp(char *pathname, unsigned char *YBuffer, unsigned char *UBuffer,
             unsigned char *VBuffer, unsigned char *header) {
  FILE *fp = fopen(pathname, "wb");
  if (fp == 0)
    return 0;
  fwrite(header, sizeof(char), 54, fp);
  fwrite(YBuffer, sizeof(char), 768 * 1024, fp);
  fwrite(VBuffer, sizeof(char), 768 * 1024 / 2, fp);
  fwrite(UBuffer, sizeof(char), 768 * 1024 / 2, fp);
  fclose(fp);
  return 1;
}


x86 assembly (clang, -O0):
<writebmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1177 <writebmp+0x47>
movl   $0x0,-0x4(%rbp)
jmp    11e3 <writebmp+0xb3>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rcx
mov    $0x1,%esi
mov    $0x36,%edx
call   1050 <fwrite@plt>
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%rcx
mov    $0x1,%esi
mov    $0xc0000,%edx
call   1050 <fwrite@plt>
mov    -0x28(%rbp),%rdi
mov    -0x38(%rbp),%rcx
mov    $0x1,%esi
mov    $0x60000,%edx
call   1050 <fwrite@plt>
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rcx
mov    $0x1,%esi
mov    $0x60000,%edx
call   1050 <fwrite@plt>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writebmp>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%rbp
mov    %rcx,%r15
mov    %rdx,%r14
mov    %rsi,%r13
lea    0xeb2(%rip),%rsi
call   1040 <fopen@plt>
test   %rax,%rax
je     11bf <writebmp+0x8f>
mov    %rax,%rbx
mov    $0x1,%r12d
mov    %rbp,%rdi
mov    $0x1,%esi
mov    $0x36,%edx
mov    %rax,%rcx
call   1050 <fwrite@plt>
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0xc0000,%edx
mov    %rbx,%rcx
call   1050 <fwrite@plt>
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x60000,%edx
mov    %rbx,%rcx
call   1050 <fwrite@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x60000,%edx
mov    %rbx,%rcx
call   1050 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    11c2 <writebmp+0x92>
xor    %r12d,%r12d
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"wb\00"
define i32 @writebmp(i8* %0, i8* %1, i8* %2, i8* %3, i8* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32*
store i8* %0, i8** %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i8* %4, i8** %11
%13 = load i8*, i8** %7
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %12
%15 = load i32*, i32** %12
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %18
17: ; preds = %5
store i32 0, i32* %6
br label %33
18: ; preds = %5
%19 = load i8*, i8** %11
%20 = load i32*, i32** %12
%21 = call i32 @fwrite(i8* %19, i32 1, i32 54, i32* %20)
%22 = load i8*, i8** %8
%23 = load i32*, i32** %12
%24 = call i32 @fwrite(i8* %22, i32 1, i32 786432, i32* %23)
%25 = load i8*, i8** %10
%26 = load i32*, i32** %12
%27 = call i32 @fwrite(i8* %25, i32 1, i32 393216, i32* %26)
%28 = load i8*, i8** %9
%29 = load i32*, i32** %12
%30 = call i32 @fwrite(i8* %28, i32 1, i32 393216, i32* %29)
%31 = load i32*, i32** %12
%32 = call i32 @fclose(i32* %31)
store i32 1, i32* %6
br label %33
33: ; preds = %18, %17
%34 = load i32, i32* %6
ret i32 %34
}

LLVM IR (-O2):
@.str = [3 x i8] c"wb\00"
define i32 @writebmp(i8* nocapture %0, i8* nocapture %1, i8* nocapture %2, i8* nocapture %3, i8* nocapture %4) {
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %14, label %8
8: ; preds = %5
%9 = tail call i32 @fwrite(i8* %4, i32 1, i32 54, i32* %6)
%10 = tail call i32 @fwrite(i8* %1, i32 1, i32 786432, i32* %6)
%11 = tail call i32 @fwrite(i8* %3, i32 1, i32 393216, i32* %6)
%12 = tail call i32 @fwrite(i8* %2, i32 1, i32 393216, i32* %6)
%13 = tail call i32 @fclose(i32* %6)
br label %14
14: ; preds = %5, %8
%15 = phi i32 [ 1, %8 ], [ 0, %5 ]
ret i32 %15
}