#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 */

/* Variables and functions */
int STDIN_FILENO;
int close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprint_err(char *, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
extern int close_file(int filedes) {
  int err;
  if (filedes == -1 || filedes == STDIN_FILENO)
    return 0;
  err = close(filedes);
  if (err) {
    fprint_err("### Error closing file: %s\n", strerror(errno));
    return 1;
  } else
    return 0;
}


x86 assembly (clang, -O0):
<close_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
je     1157 <close_file+0x27>
mov    -0x8(%rbp),%eax
mov    0x2e89(%rip),%rcx
cmp    (%rcx),%eax
jne    1163 <close_file+0x33>
movl   $0x0,-0x4(%rbp)
jmp    11a7 <close_file+0x77>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11a0 <close_file+0x70>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %eax,%esi
lea    0xe71(%rip),%rdi
call   1030 <fprint_err@plt>
movl   $0x1,-0x4(%rbp)
jmp    11a7 <close_file+0x77>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<close_file>:
push   %rbx
xor    %ebx,%ebx
cmp    $0xffffffff,%edi
je     116d <close_file+0x3d>
mov    0x2e99(%rip),%rax
cmp    %edi,(%rax)
je     116d <close_file+0x3d>
call   1040 <close@plt>
test   %eax,%eax
je     116d <close_file+0x3d>
mov    0x2e8d(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe9f(%rip),%rdi
mov    %eax,%esi
call   1030 <fprint_err@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
@STDIN_FILENO = global i32 0
@.str = [28 x i8] c"### Error closing file: %s\0A\00"
@errno = global i32 0
define i32 @close_file(i32 %0) {
%2 = icmp eq i32 %0, -1
%3 = load i32, i32* @STDIN_FILENO
%4 = icmp eq i32 %3, %0
%5 = select i1 %2, i1 true, i1 %4
br i1 %5, label %13, label %6
6: ; preds = %1
%7 = tail call i32 @close(i32 %0)
%8 = icmp eq i32 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %6
%10 = load i32, i32* @errno
%11 = tail call i32 @strerror(i32 %10)
%12 = tail call i32 @fprint_err(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %11)
br label %13
13: ; preds = %6, %1, %9
%14 = phi i32 [ 1, %9 ], [ 0, %1 ], [ 0, %6 ]
ret i32 %14
}