#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 */
scalar_t__ DebugModeOn();
int /*<<< orphan*/ *dlerror();
scalar_t__ dlsym(void *, char const *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *,
                           char const *);
int /*<<< orphan*/ stderr;
void *LoadFunction(void *handle, char const *name) {
  dlerror();
  void *symbol;
  symbol = (void *)dlsym(handle, name);
  if (DebugModeOn() && (symbol == NULL || dlerror() != NULL))
    fprintf(stderr, "Failed loading %s : %s\n", name, (char const *)dlerror());
  return symbol;
}


x86 assembly (clang, -O0):
<LoadFunction>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1030 <dlerror@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <dlsym@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1040 <DebugModeOn@plt>
cmp    $0x0,%rax
je     11c6 <LoadFunction+0x86>
cmpq   $0x0,-0x18(%rbp)
je     1195 <LoadFunction+0x55>
mov    $0x0,%al
call   1030 <dlerror@plt>
cmp    $0x0,%rax
je     11c6 <LoadFunction+0x86>
mov    0x2e44(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <dlerror@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rdx
mov    %rax,%rcx
lea    0xe3f(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<LoadFunction>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %eax,%eax
call   1030 <dlerror@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <dlsym@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1040 <DebugModeOn@plt>
test   %rax,%rax
je     11a0 <LoadFunction+0x60>
test   %rbx,%rbx
je     117c <LoadFunction+0x3c>
xor    %eax,%eax
call   1030 <dlerror@plt>
test   %rax,%rax
je     11a0 <LoadFunction+0x60>
mov    0x2e5d(%rip),%rax
mov    (%rax),%ebp
xor    %eax,%eax
call   1030 <dlerror@plt>
lea    0xe6d(%rip),%rsi
mov    %ebp,%edi
mov    %r14,%rdx
mov    %rax,%rcx
call   1050 <fprintf@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [24 x i8] c"Failed loading %s : %s\0A\00"
define i8* @LoadFunction(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = call i32* (...) @dlerror()
%7 = load i8*, i8** %3
%8 = load i8*, i8** %4
%9 = call i64 @dlsym(i8* %7, i8* %8)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %5
%11 = call i64 (...) @DebugModeOn()
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %25
13: ; preds = %2
%14 = load i8*, i8** %5
%15 = icmp eq i8* %14, null
br i1 %15, label %19, label %16
16: ; preds = %13
%17 = call i32* (...) @dlerror()
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %25
19: ; preds = %16, %13
%20 = load i32, i32* @stderr
%21 = load i8*, i8** %4
%22 = call i32* (...) @dlerror()
%23 = bitcast i32* %22 to i8*
%24 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %21, i8* %23)
br label %25
25: ; preds = %19, %16, %2
%26 = load i8*, i8** %5
ret i8* %26
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [24 x i8] c"Failed loading %s : %s\0A\00"
define i8* @LoadFunction(i8* %0, i8* %1) {
%3 = tail call i32* (...) @dlerror()
%4 = tail call i64 @dlsym(i8* %0, i8* %1)
%5 = tail call i64 (...) @DebugModeOn()
%6 = icmp eq i64 %5, 0
br i1 %6, label %17, label %7
7: ; preds = %2
%8 = icmp eq i64 %4, 0
br i1 %8, label %12, label %9
9: ; preds = %7
%10 = tail call i32* (...) @dlerror()
%11 = icmp eq i32* %10, null
br i1 %11, label %17, label %12
12: ; preds = %9, %7
%13 = load i32, i32* @stderr
%14 = tail call i32* (...) @dlerror()
%15 = bitcast i32* %14 to i8*
%16 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %15)
br label %17
17: ; preds = %12, %9, %2
%18 = inttoptr i64 %4 to i8*
ret i8* %18
}