#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*/ *const);
scalar_t__ ferror(int /*<<< orphan*/ *const);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *const);
int /*<<< orphan*/ pm_error(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ pm_message(char *);
int /*<<< orphan*/ *const stdin;
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
void pm_close(FILE *const f) {
  fflush(f);
  if (ferror(f))
    pm_message("A file read or write error occurred at some point");
  if (f != stdin)
    if (fclose(f) != 0)
      pm_error("close of file failed with errno %d (%s)", errno,
               strerror(errno));
}


x86 assembly (clang, -O0):
<pm_close>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <fflush@plt>
mov    -0x8(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1194 <pm_close+0x34>
lea    0xe71(%rip),%rdi
call   1050 <pm_message@plt>
mov    -0x8(%rbp),%rax
mov    0x2e49(%rip),%rcx
cmp    (%rcx),%rax
je     11eb <pm_close+0x8b>
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
cmp    $0x0,%rax
je     11e6 <pm_close+0x86>
mov    0x2e16(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0xc(%rbp),%esi
mov    %eax,%edx
lea    0xe51(%rip),%rdi
call   1080 <pm_error@plt>
jmp    11eb <pm_close+0x8b>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pm_close>:
push   %rbx
mov    %rdi,%rbx
call   1060 <fflush@plt>
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
je     1182 <pm_close+0x22>
lea    0xe83(%rip),%rdi
call   1050 <pm_message@plt>
test   %rbx,%rbx
je     11b5 <pm_close+0x55>
mov    %rbx,%rdi
call   1040 <fclose@plt>
test   %rax,%rax
je     11b5 <pm_close+0x55>
mov    0x2e45(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   1070 <strerror@plt>
lea    0xe87(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
pop    %rbx
jmp    1080 <pm_error@plt>
pop    %rbx
ret

LLVM IR (-O0):
@.str = [50 x i8] c"A file read or write error occurred at some point\00"
@stdin = constant i32* null
@.str.1 = [40 x i8] c"close of file failed with errno %d (%s)\00"
@errno = global i32 0
define void @pm_close(i32* %0) {
%2 = alloca i32*
store i32* %0, i32** %2
%3 = load i32*, i32** %2
%4 = call i32 @fflush(i32* %3)
%5 = load i32*, i32** %2
%6 = call i64 @ferror(i32* %5)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @pm_message(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %1
%11 = load i32*, i32** %2
%12 = load i32*, i32** @stdin
%13 = icmp ne i32* %11, %12
br i1 %13, label %14, label %24
14: ; preds = %10
%15 = load i32*, i32** %2
%16 = call i64 @fclose(i32* %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %14
%19 = load i32, i32* @errno
%20 = load i32, i32* @errno
%21 = call i32 @strerror(i32 %20)
%22 = call i32 @pm_error(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32 %19, i32 %21)
br label %23
23: ; preds = %18, %14
br label %24
24: ; preds = %23, %10
ret void
}

LLVM IR (-O2):
@.str = [50 x i8] c"A file read or write error occurred at some point\00"
@stdin = constant i32* null
@.str.1 = [40 x i8] c"close of file failed with errno %d (%s)\00"
@errno = global i32 0
define void @pm_close(i32* %0) {
%2 = tail call i32 @fflush(i32* %0)
%3 = tail call i64 @ferror(i32* %0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %1
%6 = tail call i32 @pm_message(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %1
%8 = icmp eq i32* %0, null
br i1 %8, label %16, label %9
9: ; preds = %7
%10 = tail call i64 @fclose(i32* %0)
%11 = icmp eq i64 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %9
%13 = load i32, i32* @errno
%14 = tail call i32 @strerror(i32 %13)
%15 = tail call i32 @pm_error(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32 %13, i32 %14)
br label %16
16: ; preds = %9, %12, %7
ret void
}