#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 */
scalar_t__ EOF;
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ *stderr;
int /*<<< orphan*/ *stdout;
void safe_fclose(FILE *fp) {
  if (fp && fp != stdout && fp != stderr) {
    if (fclose(fp) == EOF) {
      perror("fclose()");
    }
    fp = NULL;
  }
}


x86 assembly (clang, -O0):
<safe_fclose>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     118c <safe_fclose+0x6c>
mov    -0x8(%rbp),%rax
mov    0x2e8e(%rip),%rcx
cmp    (%rcx),%rax
je     118c <safe_fclose+0x6c>
mov    -0x8(%rbp),%rax
mov    0x2e82(%rip),%rcx
cmp    (%rcx),%rax
je     118c <safe_fclose+0x6c>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2e79(%rip),%rcx
cmp    (%rcx),%rax
jne    1184 <safe_fclose+0x64>
lea    0xe81(%rip),%rdi
call   1040 <perror@plt>
movq   $0x0,-0x8(%rbp)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<safe_fclose>:
push   %rax
test   %rdi,%rdi
je     114f <safe_fclose+0x2f>
mov    0x2ea3(%rip),%rax
cmp    %rdi,(%rax)
je     114f <safe_fclose+0x2f>
mov    0x2e9f(%rip),%rax
cmp    %rdi,(%rax)
je     114f <safe_fclose+0x2f>
call   1030 <fclose@plt>
mov    0x2e9e(%rip),%rcx
cmp    (%rcx),%rax
je     1151 <safe_fclose+0x31>
pop    %rax
ret
lea    0xea8(%rip),%rdi
pop    %rax
jmp    1040 <perror@plt>

LLVM IR (-O0):
@stdout = global i32* null
@stderr = global i32* null
@EOF = global i64 0
@.str = [9 x i8] c"fclose()\00"
define void @safe_fclose(i32* %0) {
%2 = alloca i32*
store i32* %0, i32** %2
%3 = load i32*, i32** %2
%4 = icmp ne i32* %3, null
br i1 %4, label %5, label %21
5: ; preds = %1
%6 = load i32*, i32** %2
%7 = load i32*, i32** @stdout
%8 = icmp ne i32* %6, %7
br i1 %8, label %9, label %21
9: ; preds = %5
%10 = load i32*, i32** %2
%11 = load i32*, i32** @stderr
%12 = icmp ne i32* %10, %11
br i1 %12, label %13, label %21
13: ; preds = %9
%14 = load i32*, i32** %2
%15 = call i64 @fclose(i32* %14)
%16 = load i64, i64* @EOF
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %18, %13
store i32* null, i32** %2
br label %21
21: ; preds = %20, %9, %5, %1
ret void
}

LLVM IR (-O2):
@stdout = global i32* null
@stderr = global i32* null
@EOF = global i64 0
@.str = [9 x i8] c"fclose()\00"
define void @safe_fclose(i32* %0) {
%2 = icmp eq i32* %0, null
%3 = load i32*, i32** @stdout
%4 = icmp eq i32* %3, %0
%5 = select i1 %2, i1 true, i1 %4
%6 = load i32*, i32** @stderr
%7 = icmp eq i32* %6, %0
%8 = select i1 %5, i1 true, i1 %7
br i1 %8, label %15, label %9
9: ; preds = %1
%10 = tail call i64 @fclose(i32* %0)
%11 = load i64, i64* @EOF
%12 = icmp eq i64 %10, %11
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %9, %13, %1
ret void
}