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


x86 assembly (clang, -O0):
<pgmReadHeaderFile>:
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    %r8,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe99(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    118a <pgmReadHeaderFile+0x4a>
mov    -0x8(%rbp),%rsi
lea    0xe7e(%rip),%rdi
call   1050 <error@plt>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
call   1040 <pgmReadHeader@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pgmReadHeaderFile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%r13
mov    %rdi,%rbp
lea    0xe9f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    117d <pgmReadHeaderFile+0x3d>
lea    0xe8e(%rip),%rdi
mov    %rbp,%rsi
call   1050 <error@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
mov    %r15,%rcx
mov    %r14,%r8
call   1040 <pgmReadHeader@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>

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

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [60 x i8] c"(pgmReadHeaderFile) Can't open file named '%s' for reading\0A\00"
define void @pgmReadHeaderFile(i8* %0, i32* %1, i32* %2, i32* %3, i32* %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 %8, label %10
8: ; preds = %5
%9 = tail call i32 @error(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %10
10: ; preds = %8, %5
%11 = tail call i32 @pgmReadHeader(i32* %6, i32* %1, i32* %2, i32* %3, i32* %4)
%12 = tail call i32 @fclose(i32* %6)
ret void
}