#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_NOW;
int /*<<< orphan*/ dlclose(void *);
char *dlerror();
void *dlopen(char const *, int /*<<< orphan*/);
void *dlsym(void *, char *);
int /*<<< orphan*/ printf(char *, char *);
int main(int argc, char *argv[]) {
  char const *moduleName = "H:\\Publishing\\Books\\ImpC++\\Drafting\\Pt5_"
                           "Resource_Management\\Ch5.4_Arrays.doc";
  void *module = dlopen(moduleName, RTLD_NOW);
  if (NULL == module) {
    printf("Failed to open module: %s\n", dlerror());
  } else {
    void *symbol = dlsym(module, "DllGetVersion");
    if (NULL == symbol) {
      printf("Failed to retrive symbol: %s\n", dlerror());
    }
    dlclose(module);
  }
  ((void)argc);
  ((void)argv);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe93(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e6c(%rip),%rax
mov    (%rax),%esi
call   1050 <dlopen@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
jne    11ae <main+0x5e>
mov    $0x0,%al
call   1030 <dlerror@plt>
mov    %rax,%rsi
lea    0xea9(%rip),%rdi
call   1040 <printf@plt>
jmp    11ed <main+0x9d>
mov    -0x20(%rbp),%rdi
lea    0xeaf(%rip),%rsi
call   1060 <dlsym@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
cmp    -0x28(%rbp),%rax
jne    11e4 <main+0x94>
mov    $0x0,%al
call   1030 <dlerror@plt>
mov    %rax,%rsi
lea    0xe97(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1070 <dlclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e90(%rip),%rax
mov    (%rax),%esi
lea    0xe9f(%rip),%rdi
call   1050 <dlopen@plt>
test   %rax,%rax
je     11a2 <main+0x52>
mov    %rax,%rbx
lea    0xef3(%rip),%rsi
mov    %rax,%rdi
call   1060 <dlsym@plt>
test   %rax,%rax
jne    1198 <main+0x48>
xor    %eax,%eax
call   1030 <dlerror@plt>
lea    0xee6(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1070 <dlclose@plt>
jmp    11b8 <main+0x68>
xor    %eax,%eax
call   1030 <dlerror@plt>
lea    0xe9d(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [77 x i8] c"H:\\Publishing\\Books\\ImpC++\\Drafting\\Pt5_Resource_Management\\Ch5.4_Arrays.doc\00"
@RTLD_NOW = global i32 0
@.str.1 = [27 x i8] c"Failed to open module: %s\0A\00"
@.str.2 = [14 x i8] c"DllGetVersion\00"
@.str.3 = [30 x i8] c"Failed to retrive symbol: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str, i64 0, i64 0), i8** %6
%9 = load i8*, i8** %6
%10 = load i32, i32* @RTLD_NOW
%11 = call i8* @dlopen(i8* %9, i32 %10)
store i8* %11, i8** %7
%12 = load i8*, i8** %7
%13 = icmp eq i8* null, %12
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = call i8* (...) @dlerror()
%16 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %15)
br label %28
17: ; preds = %2
%18 = load i8*, i8** %7
%19 = call i8* @dlsym(i8* %18, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
store i8* %19, i8** %8
%20 = load i8*, i8** %8
%21 = icmp eq i8* null, %20
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = call i8* (...) @dlerror()
%24 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %22, %17
%26 = load i8*, i8** %7
%27 = call i32 @dlclose(i8* %26)
br label %28
28: ; preds = %25, %14
%29 = load i32, i32* %4
%30 = load i8**, i8*** %5
ret i32 0
}

LLVM IR (-O2):
@.str = [77 x i8] c"H:\\Publishing\\Books\\ImpC++\\Drafting\\Pt5_Resource_Management\\Ch5.4_Arrays.doc\00"
@RTLD_NOW = global i32 0
@.str.1 = [27 x i8] c"Failed to open module: %s\0A\00"
@.str.2 = [14 x i8] c"DllGetVersion\00"
@.str.3 = [30 x i8] c"Failed to retrive symbol: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @RTLD_NOW
%4 = tail call i8* @dlopen(i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i8* (...) @dlerror()
%8 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %7)
br label %17
9: ; preds = %2
%10 = tail call i8* @dlsym(i8* %4, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = tail call i8* (...) @dlerror()
%14 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %13)
br label %15
15: ; preds = %12, %9
%16 = tail call i32 @dlclose(i8* %4)
br label %17
17: ; preds = %15, %6
ret i32 0
}