#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__ DebugModeOn();
int dlclose(void *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, void *);
int /*<<< orphan*/ stderr;
void CloseObject(void *handle) {
  if (handle != NULL) {
    int ret = dlclose(handle);
    if (DebugModeOn() && ret < 0)
      fprintf(stderr, "Failed to dlclose() handle: %p\n", (void *)handle);
  }
}


x86 assembly (clang, -O0):
<CloseObject>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     118c <CloseObject+0x5c>
mov    -0x8(%rbp),%rdi
call   1050 <dlclose@plt>
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1030 <DebugModeOn@plt>
cmp    $0x0,%rax
je     1187 <CloseObject+0x57>
cmpl   $0x0,-0xc(%rbp)
jge    1187 <CloseObject+0x57>
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe7e(%rip),%rsi
call   1040 <fprintf@plt>
jmp    118c <CloseObject+0x5c>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CloseObject>:
push   %rbp
push   %rbx
push   %rax
test   %rdi,%rdi
je     1170 <CloseObject+0x40>
mov    %rdi,%rbx
call   1050 <dlclose@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1030 <DebugModeOn@plt>
test   %rax,%rax
je     1170 <CloseObject+0x40>
test   %ebp,%ebp
jns    1170 <CloseObject+0x40>
mov    0x2e87(%rip),%rax
mov    (%rax),%edi
lea    0xe9e(%rip),%rsi
mov    %rbx,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <fprintf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [32 x i8] c"Failed to dlclose() handle: %p\0A\00"
define void @CloseObject(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = icmp ne i8* %4, null
br i1 %5, label %6, label %19
6: ; preds = %1
%7 = load i8*, i8** %2
%8 = call i32 @dlclose(i8* %7)
store i32 %8, i32* %3
%9 = call i64 (...) @DebugModeOn()
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %6
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %2
%17 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %16)
br label %18
18: ; preds = %14, %11, %6
br label %19
19: ; preds = %18, %1
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [32 x i8] c"Failed to dlclose() handle: %p\0A\00"
define void @CloseObject(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %12, label %3
3: ; preds = %1
%4 = tail call i32 @dlclose(i8* %0)
%5 = tail call i64 (...) @DebugModeOn()
%6 = icmp ne i64 %5, 0
%7 = icmp slt i32 %4, 0
%8 = select i1 %6, i1 %7, i1 false
br i1 %8, label %9, label %12
9: ; preds = %3
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %12
12: ; preds = %3, %9, %1
ret void
}