#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*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *, ...);
int /*<<< orphan*/ stderr;
FILE *fopen_clean(const char *filename, char *mode, char *function,
                  char *disposition) {
  FILE *exitstatus;
  if (*filename) {
    if (exitstatus = fopen(filename, mode))
      return exitstatus;
    fprintf(stderr, "%s ERROR: can't open %sfile \"%s\" !\n", function,
            disposition, filename);
  } else
    fprintf(stderr, "%s ERROR: no name given for %sfile!\n", function,
            disposition);
  return NULL;
}


x86 assembly (clang, -O0):
<fopen_clean>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1195 <fopen_clean+0x75>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     116d <fopen_clean+0x4d>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11bc <fopen_clean+0x9c>
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%r8
lea    0xe77(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11b4 <fopen_clean+0x94>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
lea    0xe77(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fopen_clean>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
cmpb   $0x0,(%rdi)
je     1168 <fopen_clean+0x48>
mov    %rdi,%rbx
call   1040 <fopen@plt>
mov    %rax,%r12
test   %rax,%rax
jne    1188 <fopen_clean+0x68>
mov    0x2e96(%rip),%rax
mov    (%rax),%edi
lea    0xead(%rip),%rsi
xor    %r12d,%r12d
mov    %r15,%rdx
mov    %r14,%rcx
mov    %rbx,%r8
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    1188 <fopen_clean+0x68>
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
lea    0xeac(%rip),%rsi
xor    %r12d,%r12d
mov    %r15,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [36 x i8] c"%s ERROR: can't open %sfile \22%s\22 !\0A\00"
@.str.1 = [37 x i8] c"%s ERROR: no name given for %sfile!\0A\00"
define i32* @fopen_clean(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%11 = load i8*, i8** %6
%12 = load i8, i8* %11
%13 = icmp ne i8 %12, 0
br i1 %13, label %14, label %27
14: ; preds = %4
%15 = load i8*, i8** %6
%16 = load i8*, i8** %7
%17 = call i32* @fopen(i8* %15, i8* %16)
store i32* %17, i32** %10
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = load i32*, i32** %10
store i32* %20, i32** %5
br label %33
21: ; preds = %14
%22 = load i32, i32* @stderr
%23 = load i8*, i8** %8
%24 = load i8*, i8** %9
%25 = load i8*, i8** %6
%26 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %23, i8* %24, i8* %25)
br label %32
27: ; preds = %4
%28 = load i32, i32* @stderr
%29 = load i8*, i8** %8
%30 = load i8*, i8** %9
%31 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %29, i8* %30)
br label %32
32: ; preds = %27, %21
store i32* null, i32** %5
br label %33
33: ; preds = %32, %19
%34 = load i32*, i32** %5
ret i32* %34
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [36 x i8] c"%s ERROR: can't open %sfile \22%s\22 !\0A\00"
@.str.1 = [37 x i8] c"%s ERROR: no name given for %sfile!\0A\00"
define noalias i32* @fopen_clean(i8* %0, i8* nocapture %1, i8* %2, i8* %3) {
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %13, label %7
7: ; preds = %4
%8 = tail call i32* @fopen(i8* %0, i8* %1)
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %16
10: ; preds = %7
%11 = load i32, i32* @stderr
%12 = tail call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %2, i8* %3, i8* %0)
br label %16
13: ; preds = %4
%14 = load i32, i32* @stderr
%15 = tail call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %2, i8* %3)
br label %16
16: ; preds = %10, %13, %7
%17 = phi i32* [ %8, %7 ], [ null, %13 ], [ null, %10 ]
ret i32* %17
}