#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*/);
void *dlsym(void *, char *);
int /*<<< orphan*/ printf(char *, void *);
int main(int ac, char **av) {
  void *h = dlopen("/usr/lib32/libc-2.13.so", RTLD_LAZY);
  void *p;
  p = dlsym(h, "printf");
  printf("%p\n", p);
  p = dlsym(h, "sprintf");
  printf("%p\n", p);
  dlclose(h);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e83(%rip),%rax
mov    (%rax),%esi
lea    0xe9a(%rip),%rdi
call   1040 <dlopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xea3(%rip),%rsi
call   1050 <dlsym@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe8a(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
lea    0xe7e(%rip),%rsi
call   1050 <dlsym@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe66(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1060 <dlclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x2e95(%rip),%rax
mov    (%rax),%esi
lea    0xeac(%rip),%rdi
call   1040 <dlopen@plt>
mov    %rax,%rbx
lea    0xeba(%rip),%rsi
mov    %rax,%rdi
call   1050 <dlsym@plt>
lea    0xea6(%rip),%r14
mov    %r14,%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
lea    0xe98(%rip),%rsi
mov    %rbx,%rdi
call   1050 <dlsym@plt>
mov    %r14,%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
mov    %rbx,%rdi
call   1060 <dlclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [24 x i8] c"/usr/lib32/libc-2.13.so\00"
@RTLD_LAZY = global i32 0
@.str.1 = [7 x i8] c"printf\00"
@.str.2 = [4 x i8] c"%p\0A\00"
@.str.3 = [8 x i8] c"sprintf\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* @RTLD_LAZY
%9 = call i8* @dlopen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %8)
store i8* %9, i8** %6
%10 = load i8*, i8** %6
%11 = call i8* @dlsym(i8* %10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i8* %11, i8** %7
%12 = load i8*, i8** %7
%13 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %12)
%14 = load i8*, i8** %6
%15 = call i8* @dlsym(i8* %14, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
store i8* %15, i8** %7
%16 = load i8*, i8** %7
%17 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %16)
%18 = load i8*, i8** %6
%19 = call i32 @dlclose(i8* %18)
ret i32 0
}

LLVM IR (-O2):
@.str = [24 x i8] c"/usr/lib32/libc-2.13.so\00"
@RTLD_LAZY = global i32 0
@.str.1 = [7 x i8] c"printf\00"
@.str.2 = [4 x i8] c"%p\0A\00"
@.str.3 = [8 x i8] c"sprintf\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @RTLD_LAZY
%4 = tail call i8* @dlopen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = tail call i8* @dlsym(i8* %4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%7 = tail call i8* @dlsym(i8* %4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%8 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %7)
%9 = tail call i32 @dlclose(i8* %4)
ret i32 0
}