#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 *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  void *handle = NULL;
  printf(
      "========================================================================"
      "=\n"
      "MPV uses the LTDL library to load plugins.  Unfortunately, the LTDL "
      "library \n"
      "gives horrible, misleading error messages when a plugin fails to load.\n"
      "This utility will load the shared library file specified on the command "
      "line \n"
      "using the dlopen() mechanism.  Any errors will be printed to the "
      "console.\n"
      "These error messages are much more useful than those issued by LTDL.  "
      "This \n"
      "allows you to find errors in your plugin which are otherwise difficult "
      "\n"
      "to diagnose using the MPV.\n"
      "Note - Don't forget to set your LD_LIBRARY_PATH to include the "
      "directories \n"
      "where your MPV libraries are located (libmpvcommon, etc).  Also, you "
      "need \n"
      "to give the *full* path name of the plugin library.  Example:\n"
      "\t%s /junk/mpv/mpv/pluginEntityMgr/.libs/libpluginEntityMgr.so\n"
      "========================================================================"
      "=\n\n",
      argv[0]);
  if (argc != 2) {
    printf("usage: %s /path/to/pluginFileName.so\n", argv[0]);
    exit(1);
  }
  handle = dlopen(argv[1], RTLD_NOW);
  if (handle == NULL) {
    printf("dlopen of %s failed.\n", argv[1]);
    printf("the error, as reported by dlerror(), is:\n\t");
    printf("%s\n", dlerror());
  } else {
    printf("dlopen of %s succeeded.\n", argv[1]);
    dlclose(handle);
  }
  printf("exiting...\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x2,-0x8(%rbp)
je     11ac <main+0x5c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0x11e9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e2d(%rip),%rax
mov    (%rax),%esi
call   1050 <dlopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1212 <main+0xc2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0x11ca(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0x11d2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <dlerror@plt>
mov    %rax,%rsi
lea    0x11e5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1231 <main+0xe1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0x11ce(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1070 <dlclose@plt>
lea    0x11d0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %edi,%ebp
mov    (%rsi),%rsi
lea    0xe8d(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x2,%ebp
jne    11f3 <main+0x93>
mov    0x8(%rbx),%rdi
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
call   1060 <dlopen@plt>
mov    0x8(%rbx),%rsi
test   %rax,%rax
je     11b5 <main+0x55>
mov    %rax,%r14
lea    0x1247(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
call   1080 <dlclose@plt>
jmp    11e0 <main+0x80>
lea    0x11ee(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x11f6(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <dlerror@plt>
mov    %rax,%rdi
call   1040 <puts@plt>
lea    0x121d(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    (%rbx),%rsi
lea    0x1187(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [900 x i8] c"=========================================================================\0AMPV uses the LTDL library to load plugins. Unfortunately, the LTDL library \0Agives horrible, misleading error messages when a plugin fails to load.\0AThis utility will load the shared library file specified on the command line \0Ausing the dlopen() mechanism. Any errors will be printed to the console.\0AThese error messages are much more useful than those issued by LTDL. This \0Aallows you to find errors in your plugin which are otherwise difficult \0Ato diagnose using the MPV.\0ANote - Don't forget to set your LD_LIBRARY_PATH to include the directories \0Awhere your MPV libraries are located (libmpvcommon, etc). Also, you need \0Ato give the *full* path name of the plugin library. Example:\0A\09%s /junk/mpv/mpv/pluginEntityMgr/.libs/libpluginEntityMgr.so\0A=========================================================================\0A\0A\00"
@.str.1 = [38 x i8] c"usage: %s /path/to/pluginFileName.so\0A\00"
@RTLD_NOW = global i32 0
@.str.2 = [22 x i8] c"dlopen of %s failed.\0A\00"
@.str.3 = [43 x i8] c"the error, as reported by dlerror(), is:\0A\09\00"
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [25 x i8] c"dlopen of %s succeeded.\0A\00"
@.str.6 = [12 x i8] c"exiting...\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
%7 = load i8**, i8*** %5
%8 = getelementptr inbounds i8*, i8** %7, i64 0
%9 = load i8*, i8** %8
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([900 x i8], [900 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 2
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = load i32, i32* @RTLD_NOW
%24 = call i8* @dlopen(i8* %22, i32 %23)
store i8* %24, i8** %6
%25 = load i8*, i8** %6
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %35
27: ; preds = %19
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %30)
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0))
%33 = call i8* (...) @dlerror()
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %33)
br label %42
35: ; preds = %19
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = load i8*, i8** %37
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i8* %38)
%40 = load i8*, i8** %6
%41 = call i32 @dlclose(i8* %40)
br label %42
42: ; preds = %35, %27
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [900 x i8] c"=========================================================================\0AMPV uses the LTDL library to load plugins. Unfortunately, the LTDL library \0Agives horrible, misleading error messages when a plugin fails to load.\0AThis utility will load the shared library file specified on the command line \0Ausing the dlopen() mechanism. Any errors will be printed to the console.\0AThese error messages are much more useful than those issued by LTDL. This \0Aallows you to find errors in your plugin which are otherwise difficult \0Ato diagnose using the MPV.\0ANote - Don't forget to set your LD_LIBRARY_PATH to include the directories \0Awhere your MPV libraries are located (libmpvcommon, etc). Also, you need \0Ato give the *full* path name of the plugin library. Example:\0A\09%s /junk/mpv/mpv/pluginEntityMgr/.libs/libpluginEntityMgr.so\0A=========================================================================\0A\0A\00"
@.str.1 = [38 x i8] c"usage: %s /path/to/pluginFileName.so\0A\00"
@RTLD_NOW = global i32 0
@.str.2 = [22 x i8] c"dlopen of %s failed.\0A\00"
@.str.3 = [43 x i8] c"the error, as reported by dlerror(), is:\0A\09\00"
@.str.5 = [25 x i8] c"dlopen of %s succeeded.\0A\00"
@str = [11 x i8] c"exiting...\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i8*, i8** %1
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([900 x i8], [900 x i8]* @.str, i64 0, i64 0), i8* %3)
%5 = icmp eq i32 %0, 2
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @RTLD_NOW
%14 = tail call i8* @dlopen(i8* %12, i32 %13)
%15 = icmp eq i8* %14, null
%16 = load i8*, i8** %11
br i1 %15, label %17, label %22
17: ; preds = %10
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %16)
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0))
%20 = tail call i8* (...) @dlerror()
%21 = tail call i32 @puts(i8* dereferenceable(1) %20)
br label %25
22: ; preds = %10
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i8* %16)
%24 = tail call i32 @dlclose(i8* %14)
br label %25
25: ; preds = %22, %17
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
ret i32 0
}