#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*/ EXIT_FAILURE;
int RTLD_GLOBAL;
int RTLD_LAZY;
void *dlopen(char const *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ error(int /*<<< orphan*/, int /*<<< orphan*/, char *,
                         char const *);
void *load(const char *name) {
  void *d = dlopen(name, RTLD_LAZY | RTLD_GLOBAL);
  if (d == NULL)
    error(EXIT_FAILURE, errno, "cannot load `%s'", name);
  return d;
}


x86 assembly (clang, -O0):
<load>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e91(%rip),%rax
mov    (%rax),%esi
mov    0x2ea8(%rip),%rax
or     (%rax),%esi
call   1030 <dlopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1178 <load+0x58>
mov    0x2e73(%rip),%rax
mov    (%rax),%edi
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%rcx
lea    0xe8d(%rip),%rdx
call   1040 <error@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2e9a(%rip),%rax
mov    0x2eb3(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1030 <dlopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1167 <load+0x47>
mov    0x2e83(%rip),%rax
mov    (%rax),%edi
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
lea    0xea1(%rip),%rdx
mov    %r14,%rcx
call   1040 <error@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@RTLD_LAZY = global i32 0
@RTLD_GLOBAL = global i32 0
@EXIT_FAILURE = global i32 0
@errno = global i32 0
@.str = [17 x i8] c"cannot load `%s'\00"
define i8* @load(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = load i32, i32* @RTLD_LAZY
%6 = load i32, i32* @RTLD_GLOBAL
%7 = or i32 %5, %6
%8 = call i8* @dlopen(i8* %4, i32 %7)
store i8* %8, i8** %3
%9 = load i8*, i8** %3
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %16
11: ; preds = %1
%12 = load i32, i32* @EXIT_FAILURE
%13 = load i32, i32* @errno
%14 = load i8*, i8** %2
%15 = call i32 @error(i32 %12, i32 %13, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %14)
br label %16
16: ; preds = %11, %1
%17 = load i8*, i8** %3
ret i8* %17
}

LLVM IR (-O2):
@RTLD_LAZY = global i32 0
@RTLD_GLOBAL = global i32 0
@EXIT_FAILURE = global i32 0
@errno = global i32 0
@.str = [17 x i8] c"cannot load `%s'\00"
define i8* @load(i8* %0) {
%2 = load i32, i32* @RTLD_LAZY
%3 = load i32, i32* @RTLD_GLOBAL
%4 = or i32 %3, %2
%5 = tail call i8* @dlopen(i8* %0, i32 %4)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = load i32, i32* @EXIT_FAILURE
%9 = load i32, i32* @errno
%10 = tail call i32 @error(i32 %8, i32 %9, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %11
11: ; preds = %7, %1
ret i8* %5
}