#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 *);
unsigned char *ppmRead(int /*<<< orphan*/ *, int *, int *);
unsigned char *ppmReadFile(char *fname, int *ncols, int *nrows) {
  unsigned char *ptr;
  FILE *fp;
  if ((fp = fopen(fname, "rb")) == NULL)
    error("(ppmReadFile) Can't open file named '%s' for reading\n", fname);
  ptr = ppmRead(fp, ncols, nrows);
  fclose(fp);
  return ptr;
}


x86 assembly (clang, -O0):
<ppmReadFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea1(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1182 <ppmReadFile+0x42>
mov    -0x8(%rbp),%rsi
lea    0xe86(%rip),%rdi
call   1050 <error@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <ppmRead@plt>
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ppmReadFile>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
lea    0xea8(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1174 <ppmReadFile+0x34>
lea    0xe97(%rip),%rdi
mov    %r12,%rsi
call   1050 <error@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1040 <ppmRead@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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