#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*/ RTLD_NOW;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ load_and_sym(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  if (argc < 2) {
    fprintf(stderr, "Usage error: must pass in path to library to load\n");
    return 1;
  }
  load_and_sym(NULL, "my_export", RTLD_LAZY);
  load_and_sym("libm.so.6", "cos", RTLD_NOW);
  load_and_sym("libgcc_s.so.1", "__gcc_personality_v0", RTLD_LAZY);
  load_and_sym(argv[1], NULL, RTLD_NOW);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1161 <main+0x41>
mov    0x2e91(%rip),%rax
mov    (%rax),%edi
lea    0xeb0(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11d3 <main+0xb3>
mov    0x2e68(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%edi
lea    0xebe(%rip),%rsi
call   1040 <load_and_sym@plt>
mov    0x2e67(%rip),%rax
mov    (%rax),%edx
lea    0xeb3(%rip),%rdi
lea    0xeb6(%rip),%rsi
call   1040 <load_and_sym@plt>
mov    0x2e33(%rip),%rax
mov    (%rax),%edx
lea    0xea5(%rip),%rdi
lea    0xeac(%rip),%rsi
call   1040 <load_and_sym@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e27(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1040 <load_and_sym@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    $0x1,%edi
jg     1149 <main+0x29>
mov    0x2ea4(%rip),%rax
mov    (%rax),%edi
lea    0xec3(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%ebx
jmp    11a9 <main+0x89>
mov    %rsi,%r14
mov    0x2e7d(%rip),%r15
mov    (%r15),%edx
lea    0xed6(%rip),%rsi
xor    %ebx,%ebx
xor    %edi,%edi
call   1040 <load_and_sym@plt>
mov    0x2e7b(%rip),%r12
mov    (%r12),%edx
lea    0xec5(%rip),%rdi
lea    0xec8(%rip),%rsi
call   1040 <load_and_sym@plt>
mov    (%r15),%edx
lea    0xebd(%rip),%rdi
lea    0xec4(%rip),%rsi
call   1040 <load_and_sym@plt>
mov    0x8(%r14),%rdi
mov    (%r12),%edx
xor    %esi,%esi
call   1040 <load_and_sym@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [51 x i8] c"Usage error: must pass in path to library to load\0A\00"
@.str.1 = [10 x i8] c"my_export\00"
@RTLD_LAZY = global i32 0
@.str.2 = [10 x i8] c"libm.so.6\00"
@.str.3 = [4 x i8] c"cos\00"
@RTLD_NOW = global i32 0
@.str.4 = [14 x i8] c"libgcc_s.so.1\00"
@.str.5 = [21 x i8] c"__gcc_personality_v0\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = load i32, i32* %4
%7 = icmp slt i32 %6, 2
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %23
11: ; preds = %2
%12 = load i32, i32* @RTLD_LAZY
%13 = call i32 @load_and_sym(i8* null, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = load i32, i32* @RTLD_NOW
%15 = call i32 @load_and_sym(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %14)
%16 = load i32, i32* @RTLD_LAZY
%17 = call i32 @load_and_sym(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %16)
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = load i32, i32* @RTLD_NOW
%22 = call i32 @load_and_sym(i8* %20, i8* null, i32 %21)
store i32 0, i32* %3
br label %23
23: ; preds = %11, %8
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [51 x i8] c"Usage error: must pass in path to library to load\0A\00"
@.str.1 = [10 x i8] c"my_export\00"
@RTLD_LAZY = global i32 0
@.str.2 = [10 x i8] c"libm.so.6\00"
@.str.3 = [4 x i8] c"cos\00"
@RTLD_NOW = global i32 0
@.str.4 = [14 x i8] c"libgcc_s.so.1\00"
@.str.5 = [21 x i8] c"__gcc_personality_v0\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
br label %18
7: ; preds = %2
%8 = load i32, i32* @RTLD_LAZY
%9 = tail call i32 @load_and_sym(i8* null, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = load i32, i32* @RTLD_NOW
%11 = tail call i32 @load_and_sym(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %10)
%12 = load i32, i32* @RTLD_LAZY
%13 = tail call i32 @load_and_sym(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %12)
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = load i32, i32* @RTLD_NOW
%17 = tail call i32 @load_and_sym(i8* %15, i8* null, i32 %16)
br label %18
18: ; preds = %7, %4
%19 = phi i32 [ 1, %4 ], [ 0, %7 ]
ret i32 %19
}