#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 *);
void *dlopen(char *, int /*<<< orphan*/);
scalar_t__ dlsym(void *, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
void Load(char *name, int expect) {
  int val;
  double dval;
  void *handle;
  int (*sym)();
  double (*fsin)(double);
  handle = dlopen(name, RTLD_LAZY);
  if (handle == 0) {
    fprintf(stderr, "Load of %s failed\n", name);
    exit(1);
  }
  sym = (int (*)())dlsym(handle, "one");
  if (sym == 0) {
    fprintf(stderr, "Dlsym of %s failed\n", name);
    exit(1);
  }
  val = sym();
  if (val != expect)
    exit(1);
  dlclose(handle);
}


x86 assembly (clang, -O0):
<Load>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e6e(%rip),%rax
mov    (%rax),%esi
call   1030 <dlopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a3 <Load+0x53>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe6c(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x20(%rbp),%rdi
lea    0xe65(%rip),%rsi
call   1050 <dlsym@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11e5 <Load+0x95>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe41(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    $0x0,%al
call   *-0x28(%rbp)
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
je     1203 <Load+0xb3>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x20(%rbp),%rdi
call   1070 <dlclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Load>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
mov    0x2e78(%rip),%rax
mov    (%rax),%esi
call   1030 <dlopen@plt>
test   %rax,%rax
je     119a <Load+0x4a>
mov    %rax,%rbx
lea    0xe9d(%rip),%rsi
mov    %rax,%rdi
call   1050 <dlsym@plt>
test   %rax,%rax
je     11ac <Load+0x5c>
mov    %rax,%rcx
xor    %eax,%eax
call   *%rcx
cmp    %ebp,%eax
jne    11c4 <Load+0x74>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1070 <dlclose@plt>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
lea    0xe56(%rip),%rsi
jmp    11bc <Load+0x6c>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
lea    0xe5b(%rip),%rsi
mov    %r14,%rdx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@RTLD_LAZY = global i32 0
@stderr = global i32 0
@.str = [19 x i8] c"Load of %s failed\0A\00"
@.str.1 = [4 x i8] c"one\00"
@.str.2 = [20 x i8] c"Dlsym of %s failed\0A\00"
define void @Load(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca double
%7 = alloca i8*
%8 = alloca i32 (...)*
%9 = alloca double (double)*
store i8* %0, i8** %3
store i32 %1, i32* %4
%10 = load i8*, i8** %3
%11 = load i32, i32* @RTLD_LAZY
%12 = call i8* @dlopen(i8* %10, i32 %11)
store i8* %12, i8** %7
%13 = load i8*, i8** %7
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %20
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %3
%18 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = load i8*, i8** %7
%22 = call i64 @dlsym(i8* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%23 = inttoptr i64 %22 to i32 (...)*
store i32 (...)* %23, i32 (...)** %8
%24 = load i32 (...)*, i32 (...)** %8
%25 = icmp eq i32 (...)* %24, null
br i1 %25, label %26, label %31
26: ; preds = %20
%27 = load i32, i32* @stderr
%28 = load i8*, i8** %3
%29 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %28)
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %20
%32 = load i32 (...)*, i32 (...)** %8
%33 = call i32 (...) %32()
store i32 %33, i32* %5
%34 = load i32, i32* %5
%35 = load i32, i32* %4
%36 = icmp ne i32 %34, %35
br i1 %36, label %37, label %39
37: ; preds = %31
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %31
%40 = load i8*, i8** %7
%41 = call i32 @dlclose(i8* %40)
ret void
}

LLVM IR (-O2):
@RTLD_LAZY = global i32 0
@stderr = global i32 0
@.str = [19 x i8] c"Load of %s failed\0A\00"
@.str.1 = [4 x i8] c"one\00"
@.str.2 = [20 x i8] c"Dlsym of %s failed\0A\00"
define void @Load(i8* %0, i32 %1) {
%3 = load i32, i32* @RTLD_LAZY
%4 = tail call i8* @dlopen(i8* %0, i32 %3)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %0)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = tail call i64 @dlsym(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %10
%18 = inttoptr i64 %11 to i32 (...)*
%19 = tail call i32 (...) %18()
%20 = icmp eq i32 %19, %1
br i1 %20, label %23, label %21
21: ; preds = %17
%22 = tail call i32 @exit(i32 1)
unreachable
23: ; preds = %17
%24 = tail call i32 @dlclose(i8* %4)
ret void
}