#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 errno;
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  void *handle;
  handle =
      dlopen("/usr/lib/vmware-vmca/lib64/libvmcaclient.so.0.0.0", RTLD_LAZY);
  if (handle == NULL) {
    printf("errno[%d], errmsg[%s]\n", errno, dlerror());
    return -1;
  } else {
    printf("\nvmca Lib loaded successfully");
  }
  dlclose(handle);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
lea    0xea1(%rip),%rdi
call   1050 <dlopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a6 <main+0x66>
mov    0x2e66(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1030 <dlerror@plt>
mov    -0x14(%rbp),%esi
mov    %rax,%rdx
lea    0xe9f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c4 <main+0x84>
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1060 <dlclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e8e(%rip),%rax
mov    (%rax),%esi
lea    0xead(%rip),%rdi
call   1050 <dlopen@plt>
test   %rax,%rax
je     117a <main+0x3a>
mov    %rax,%rbx
lea    0xee2(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1060 <dlclose@plt>
jmp    11a2 <main+0x62>
mov    0x2e5f(%rip),%rax
mov    (%rax),%ebx
xor    %eax,%eax
call   1030 <dlerror@plt>
lea    0xea1(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [50 x i8] c"/usr/lib/vmware-vmca/lib64/libvmcaclient.so.0.0.0\00"
@RTLD_LAZY = global i32 0
@.str.1 = [23 x i8] c"errno[%d], errmsg[%s]\0A\00"
@errno = global i32 0
@.str.2 = [30 x i8] c"\0Avmca Lib loaded successfully\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
store i32 0, i32* %1
%3 = load i32, i32* @RTLD_LAZY
%4 = call i8* @dlopen(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i32 %3)
store i8* %4, i8** %2
%5 = load i8*, i8** %2
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %11
7: ; preds = %0
%8 = load i32, i32* @errno
%9 = call i8* (...) @dlerror()
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %8, i8* %9)
store i32 -1, i32* %1
br label %16
11: ; preds = %0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %13
13: ; preds = %11
%14 = load i8*, i8** %2
%15 = call i32 @dlclose(i8* %14)
store i32 0, i32* %1
br label %16
16: ; preds = %13, %7
%17 = load i32, i32* %1
ret i32 %17
}

LLVM IR (-O2):
@.str = [50 x i8] c"/usr/lib/vmware-vmca/lib64/libvmcaclient.so.0.0.0\00"
@RTLD_LAZY = global i32 0
@.str.1 = [23 x i8] c"errno[%d], errmsg[%s]\0A\00"
@errno = global i32 0
@.str.2 = [30 x i8] c"\0Avmca Lib loaded successfully\00"
define i32 @main() {
%1 = load i32, i32* @RTLD_LAZY
%2 = tail call i8* @dlopen(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %8
4: ; preds = %0
%5 = load i32, i32* @errno
%6 = tail call i8* (...) @dlerror()
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %5, i8* %6)
br label %11
8: ; preds = %0
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%10 = tail call i32 @dlclose(i8* %2)
br label %11
11: ; preds = %8, %4
%12 = phi i32 [ -1, %4 ], [ 0, %8 ]
ret i32 %12
}