#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*/ av_free(char *);
int /*<<< orphan*/ av_log(int, char *, int /*<<< orphan*/);
char *av_stradd(void *, char const *, char *, char const *, void *);
int /*<<< orphan*/ dlerror();
void *dlopen(char *, int /*<<< orphan*/);
void *load_module(const char *modname, const char *moduledir) {
  char *modpath;
  void *lib_handle;
  modpath = av_stradd(((void *)0), moduledir, "/", modname, ((void *)0));
  lib_handle = dlopen(modpath, RTLD_NOW);
  if (lib_handle == ((void *)0))
    av_log(001, "load_module: %s", dlerror());
  av_free(modpath);
  return lib_handle;
}


x86 assembly (clang, -O0):
<load_module>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
lea    0xe8c(%rip),%rdx
mov    %r8,%rdi
call   1040 <av_stradd@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e5d(%rip),%rax
mov    (%rax),%esi
call   1050 <dlopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11bb <load_module+0x6b>
mov    $0x0,%al
call   1030 <dlerror@plt>
mov    %eax,%edx
mov    $0x1,%edi
lea    0xe4c(%rip),%rsi
call   1070 <av_log@plt>
mov    -0x18(%rbp),%rdi
call   1060 <av_free@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_module>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rcx
lea    0xea2(%rip),%rdx
xor    %edi,%edi
xor    %r8d,%r8d
call   1040 <av_stradd@plt>
mov    %rax,%r14
mov    0x2e76(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1050 <dlopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    119e <load_module+0x4e>
xor    %eax,%eax
call   1030 <dlerror@plt>
lea    0xe70(%rip),%rsi
mov    $0x1,%edi
mov    %eax,%edx
call   1070 <av_log@plt>
mov    %r14,%rdi
call   1060 <av_free@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
@RTLD_NOW = global i32 0
@.str.1 = [16 x i8] c"load_module: %s\00"
define i8* @load_module(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
%8 = load i8*, i8** %3
%9 = call i8* @av_stradd(i8* null, i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %8, i8* null)
store i8* %9, i8** %5
%10 = load i8*, i8** %5
%11 = load i32, i32* @RTLD_NOW
%12 = call i8* @dlopen(i8* %10, i32 %11)
store i8* %12, i8** %6
%13 = load i8*, i8** %6
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = call i32 (...) @dlerror()
%17 = call i32 @av_log(i32 1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %16)
br label %18
18: ; preds = %15, %2
%19 = load i8*, i8** %5
%20 = call i32 @av_free(i8* %19)
%21 = load i8*, i8** %6
ret i8* %21
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@RTLD_NOW = global i32 0
@.str.1 = [16 x i8] c"load_module: %s\00"
define i8* @load_module(i8* %0, i8* %1) {
%3 = tail call i8* @av_stradd(i8* null, i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %0, i8* null)
%4 = load i32, i32* @RTLD_NOW
%5 = tail call i8* @dlopen(i8* %3, i32 %4)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = tail call i32 (...) @dlerror()
%9 = tail call i32 @av_log(i32 1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %8)
br label %10
10: ; preds = %7, %2
%11 = tail call i32 @av_free(i8* %3)
ret i8* %5
}