#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 dlclose(void *);
char *dlerror();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ stderr;
void release_handle(void *handle) {
  int ret;
  dlerror();
  ret = dlclose(handle);
  if (ret != 0) {
    fprintf(stderr, "Error closing handle %p (%d)\n", handle, ret);
    fprintf(stderr, "%s\n", dlerror());
  }
  return;
}


x86 assembly (clang, -O0):
<release_handle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1030 <dlerror@plt>
mov    -0x8(%rbp),%rdi
call   1050 <dlclose@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     119e <release_handle+0x6e>
mov    0x2e80(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0xc(%rbp),%ecx
lea    0xe90(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2e62(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1030 <dlerror@plt>
mov    -0x10(%rbp),%edi
mov    %rax,%rdx
lea    0xe87(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<release_handle>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %eax,%eax
call   1030 <dlerror@plt>
mov    %rbx,%rdi
call   1050 <dlclose@plt>
test   %eax,%eax
je     118b <release_handle+0x5b>
mov    0x2e8f(%rip),%r14
mov    (%r14),%edi
lea    0xea5(%rip),%rsi
mov    %rbx,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r14),%ebx
xor    %eax,%eax
call   1030 <dlerror@plt>
lea    0xea6(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <fprintf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [30 x i8] c"Error closing handle %p (%d)\0A\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define void @release_handle(i8* %0) {
%2 = tail call i8* (...) @dlerror()
%3 = tail call i32 @dlclose(i8* %0)
%4 = icmp eq i32 %3, 0
br i1 %4, label %11, label %5
5: ; preds = %1
%6 = load i32, i32* @stderr
%7 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %3)
%8 = load i32, i32* @stderr
%9 = tail call i8* (...) @dlerror()
%10 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %9)
br label %11
11: ; preds = %5, %1
ret void
}