#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 /*<<< orphan*/ RTLD_LAZY;
int /*<<< orphan*/ dlclose(void *);
char *dlerror();
void *dlopen(char *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ stderr;
void Open(char *filename) {
  void *dlh = dlopen(filename, RTLD_LAZY);
  if (!dlh) {
    fprintf(stderr, " Failed to load: %s because: %s", filename, dlerror());
    exit(2);
  }
  dlclose(dlh);
}


x86 assembly (clang, -O0):
<Open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e71(%rip),%rax
mov    (%rax),%esi
call   1040 <dlopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b8 <Open+0x68>
mov    0x2e5c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1030 <dlerror@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rdx
mov    %rax,%rcx
lea    0xe57(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x2,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rdi
call   1070 <dlclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Open>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2e7b(%rip),%rax
mov    (%rax),%esi
call   1040 <dlopen@plt>
test   %rax,%rax
je     1177 <Open+0x27>
mov    %rax,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1070 <dlclose@plt>
mov    0x2e62(%rip),%rax
mov    (%rax),%ebp
xor    %eax,%eax
call   1030 <dlerror@plt>
lea    0xe72(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1050 <fprintf@plt>
mov    $0x2,%edi
call   1060 <exit@plt>

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

LLVM IR (-O2):
@RTLD_LAZY = global i32 0
@stderr = global i32 0
@.str = [32 x i8] c" Failed to load: %s because: %s\00"
define void @Open(i8* %0) {
%2 = load i32, i32* @RTLD_LAZY
%3 = tail call i8* @dlopen(i8* %0, i32 %2)
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %10
5: ; preds = %1
%6 = load i32, i32* @stderr
%7 = tail call i8* (...) @dlerror()
%8 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %7)
%9 = tail call i32 @exit(i32 2)
unreachable
10: ; preds = %1
%11 = tail call i32 @dlclose(i8* %3)
ret void
}