#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*/ error(char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ ppmWriteRGB(int /*<<< orphan*/ *, unsigned char *,
                               unsigned char *, unsigned char *, int, int);
void ppmWriteFileRGB(char *fname, unsigned char *redimg,
                     unsigned char *greenimg, unsigned char *blueimg, int ncols,
                     int nrows) {
  FILE *fp;
  if ((fp = fopen(fname, "wb")) == NULL)
    error("(ppmWriteFileRGB) Can't open file named '%s' for writing\n", fname);
  ppmWriteRGB(fp, redimg, greenimg, blueimg, ncols, nrows);
  fclose(fp);
}


x86 assembly (clang, -O0):
<ppmWriteFileRGB>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9d,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    118e <ppmWriteFileRGB+0x4e>
mov    -0x8(%rbp),%rsi
lea    0xe7a(%rip),%rdi
call   1050 <error@plt>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x24(%rbp),%r8d
mov    -0x28(%rbp),%r9d
call   1030 <ppmWriteRGB@plt>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ppmWriteFileRGB>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9d,0x4(%rsp)
mov    %r8d,%r15d
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xe9a(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1182 <ppmWriteFileRGB+0x42>
lea    0xe89(%rip),%rdi
mov    %r14,%rsi
call   1050 <error@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r13,%rdx
mov    %r12,%rcx
mov    %r15d,%r8d
mov    0x4(%rsp),%r9d
call   1030 <ppmWriteRGB@plt>
mov    %rbp,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fclose@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"wb\00"
@.str.1 = [58 x i8] c"(ppmWriteFileRGB) Can't open file named '%s' for writing\0A\00"
define void @ppmWriteFileRGB(i8* %0, i8* %1, i8* %2, i8* %3, i32 %4, i32 %5) {
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32*
store i8* %0, i8** %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i32 %4, i32* %11
store i32 %5, i32* %12
%14 = load i8*, i8** %7
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %13
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %20
17: ; preds = %6
%18 = load i8*, i8** %7
%19 = call i32 @error(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0), i8* %18)
br label %20
20: ; preds = %17, %6
%21 = load i32*, i32** %13
%22 = load i8*, i8** %8
%23 = load i8*, i8** %9
%24 = load i8*, i8** %10
%25 = load i32, i32* %11
%26 = load i32, i32* %12
%27 = call i32 @ppmWriteRGB(i32* %21, i8* %22, i8* %23, i8* %24, i32 %25, i32 %26)
%28 = load i32*, i32** %13
%29 = call i32 @fclose(i32* %28)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"wb\00"
@.str.1 = [58 x i8] c"(ppmWriteFileRGB) Can't open file named '%s' for writing\0A\00"
define void @ppmWriteFileRGB(i8* %0, i8* %1, i8* %2, i8* %3, i32 %4, i32 %5) {
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @error(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %11
11: ; preds = %9, %6
%12 = tail call i32 @ppmWriteRGB(i32* %7, i8* %1, i8* %2, i8* %3, i32 %4, i32 %5)
%13 = tail call i32 @fclose(i32* %7)
ret void
}