#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 */
scalar_t__ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
void closeIfPossible(int fp, int printOnFailure) {
  if (fp >= 0) {
    if (close(fp) != 0 && printOnFailure != 0) {
      fprintf(stderr, "ERROR: File close failed.\n");
    }
  } else {
    if (printOnFailure != 0) {
      fprintf(stderr, "ERROR: Could not close invalid file pointer.\n");
    }
  }
}


x86 assembly (clang, -O0):
<closeIfPossible>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0x0,-0x4(%rbp)
jl     116e <closeIfPossible+0x4e>
mov    -0x4(%rbp),%edi
call   1030 <close@plt>
cmp    $0x0,%rax
je     1169 <closeIfPossible+0x49>
cmpl   $0x0,-0x8(%rbp)
je     1169 <closeIfPossible+0x49>
mov    0x2e85(%rip),%rax
mov    (%rax),%edi
lea    0xe9c(%rip),%rsi
call   1040 <fprintf@plt>
jmp    1192 <closeIfPossible+0x72>
cmpl   $0x0,-0x8(%rbp)
je     118d <closeIfPossible+0x6d>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
lea    0xe93(%rip),%rsi
call   1040 <fprintf@plt>
jmp    1192 <closeIfPossible+0x72>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<closeIfPossible>:
push   %rbx
mov    %esi,%ebx
test   %edi,%edi
js     113e <closeIfPossible+0x1e>
call   1030 <close@plt>
test   %ebx,%ebx
je     1158 <closeIfPossible+0x38>
test   %rax,%rax
je     1158 <closeIfPossible+0x38>
lea    0xec4(%rip),%rsi
jmp    1149 <closeIfPossible+0x29>
test   %ebx,%ebx
je     1158 <closeIfPossible+0x38>
lea    0xed2(%rip),%rsi
mov    0x2e90(%rip),%rax
mov    (%rax),%edi
pop    %rbx
jmp    1040 <fprintf@plt>
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [27 x i8] c"ERROR: File close failed.\0A\00"
@.str.1 = [46 x i8] c"ERROR: Could not close invalid file pointer.\0A\00"
define void @closeIfPossible(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%5 = load i32, i32* %3
%6 = icmp sge i32 %5, 0
br i1 %6, label %7, label %18
7: ; preds = %2
%8 = load i32, i32* %3
%9 = call i64 @close(i32 %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %7
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %14, %11, %7
br label %25
18: ; preds = %2
%19 = load i32, i32* %4
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %21, %18
br label %25
25: ; preds = %24, %17
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [27 x i8] c"ERROR: File close failed.\0A\00"
@.str.1 = [46 x i8] c"ERROR: Could not close invalid file pointer.\0A\00"
define void @closeIfPossible(i32 %0, i32 %1) {
%3 = icmp sgt i32 %0, -1
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = tail call i64 @close(i32 %0)
%6 = icmp ne i64 %5, 0
%7 = icmp ne i32 %1, 0
%8 = and i1 %7, %6
br i1 %8, label %11, label %15
9: ; preds = %2
%10 = icmp eq i32 %1, 0
br i1 %10, label %15, label %11
11: ; preds = %9, %4
%12 = phi i8* [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), %4 ], [ getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), %9 ]
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* %12)
br label %15
15: ; preds = %11, %9, %4
ret void
}