#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*/ errno;
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *,
                           char const *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int try_fclose(FILE **file, const char *name, const char *func) {
  FILE *to_close = *file;
  *file = NULL;
  if (fclose(to_close) != 0) {
    fprintf(stderr, "%s : Error on closing %s : %s\n", func, name,
            strerror(errno));
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<try_fclose>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
cmp    $0x0,%rax
je     11bd <try_fclose+0x8d>
mov    0x2e6c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    %rax,%r8
lea    0xe54(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c4 <try_fclose+0x94>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<try_fclose>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
mov    (%rdi),%rax
movq   $0x0,(%rdi)
mov    %rax,%rdi
call   1030 <fclose@plt>
test   %rax,%rax
je     1186 <try_fclose+0x56>
mov    0x2e88(%rip),%rax
mov    (%rax),%ebp
mov    0x2e77(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe91(%rip),%rsi
mov    %ebp,%edi
mov    %r14,%rdx
mov    %rbx,%rcx
mov    %rax,%r8
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    1188 <try_fclose+0x58>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [31 x i8] c"%s : Error on closing %s : %s\0A\00"
@errno = global i32 0
define i32 @try_fclose(i32** %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
store i32** %0, i32*** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%9 = load i32**, i32*** %5
%10 = load i32*, i32** %9
store i32* %10, i32** %8
%11 = load i32**, i32*** %5
store i32* null, i32** %11
%12 = load i32*, i32** %8
%13 = call i64 @fclose(i32* %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %22
15: ; preds = %3
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %7
%18 = load i8*, i8** %6
%19 = load i32, i32* @errno
%20 = call i8* @strerror(i32 %19)
%21 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %17, i8* %18, i8* %20)
store i32 -1, i32* %4
br label %23
22: ; preds = %3
store i32 0, i32* %4
br label %23
23: ; preds = %22, %15
%24 = load i32, i32* %4
ret i32 %24
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [31 x i8] c"%s : Error on closing %s : %s\0A\00"
@errno = global i32 0
define i32 @try_fclose(i32** nocapture %0, i8* %1, i8* %2) {
%4 = load i32*, i32** %0
store i32* null, i32** %0
%5 = tail call i64 @fclose(i32* %4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %12, label %7
7: ; preds = %3
%8 = load i32, i32* @stderr
%9 = load i32, i32* @errno
%10 = tail call i8* @strerror(i32 %9)
%11 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %2, i8* %1, i8* %10)
br label %12
12: ; preds = %3, %7
%13 = phi i32 [ -1, %7 ], [ 0, %3 ]
ret i32 %13
}