#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 EXIT_SUCCESS;
int /*<<< orphan*/ RTLD_LAZY;
int /*<<< orphan*/ dlclose(void *);
char *dlerror();
void *dlopen(char *, int /*<<< orphan*/);
scalar_t__ dlsym(void *, char *);
char *op1();
int /*<<< orphan*/ printf(char *, char *);
int main(int argc, char **argv) {
  void *dlhandle = NULL;
  if (argc > 1) {
    char *(*dlop1)(void) = NULL;
    dlhandle = dlopen(argv[1], RTLD_LAZY);
    if (dlhandle == NULL)
      printf("dlopen error : %s\n", dlerror());
    else {
      dlop1 = (char *(*)(void))dlsym(dlhandle, "dlop1");
      if (dlop1 == NULL)
        printf("dlopen error : %s\n", dlerror());
      else
        printf("Result DL  = %s\n", dlop1());
      dlclose(dlhandle);
    }
  }
  printf("Result Shared = %s\n", op1());
  return EXIT_SUCCESS;
}


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)
movq   $0x0,-0x18(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    122a <main+0xca>
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
call   1060 <dlopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d0 <main+0x70>
mov    $0x0,%al
call   1030 <dlerror@plt>
mov    %rax,%rsi
lea    0xe3a(%rip),%rdi
call   1040 <printf@plt>
jmp    1225 <main+0xc5>
mov    -0x18(%rbp),%rdi
lea    0xe38(%rip),%rsi
call   1070 <dlsym@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    120a <main+0xaa>
mov    $0x0,%al
call   1030 <dlerror@plt>
mov    %rax,%rsi
lea    0xe00(%rip),%rdi
call   1040 <printf@plt>
jmp    121c <main+0xbc>
call   *-0x20(%rbp)
mov    %rax,%rsi
lea    0xe02(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1080 <dlclose@plt>
jmp    122a <main+0xca>
mov    $0x0,%al
call   1050 <op1@plt>
mov    %rax,%rsi
lea    0xdef(%rip),%rdi
call   1040 <printf@plt>
mov    0x2d99(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x2,%edi
jl     11d5 <main+0x75>
mov    0x8(%rsi),%rdi
mov    0x2e67(%rip),%rax
mov    (%rax),%esi
call   1060 <dlopen@plt>
test   %rax,%rax
je     119f <main+0x3f>
mov    %rax,%rbx
lea    0xe8c(%rip),%rsi
mov    %rax,%rdi
call   1070 <dlsym@plt>
test   %rax,%rax
je     11b7 <main+0x57>
call   *%rax
lea    0xe7c(%rip),%rdi
jmp    11c5 <main+0x65>
xor    %eax,%eax
call   1030 <dlerror@plt>
lea    0xe53(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
jmp    11d5 <main+0x75>
xor    %eax,%eax
call   1030 <dlerror@plt>
lea    0xe3b(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1080 <dlclose@plt>
xor    %eax,%eax
call   1050 <op1@plt>
lea    0xe47(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    0x2dee(%rip),%rax
mov    (%rax),%eax
pop    %rbx
ret

LLVM IR (-O0):
@RTLD_LAZY = global i32 0
@.str = [19 x i8] c"dlopen error : %s\0A\00"
@.str.1 = [6 x i8] c"dlop1\00"
@.str.2 = [17 x i8] c"Result DL = %s\0A\00"
@.str.3 = [20 x i8] c"Result Shared = %s\0A\00"
@EXIT_SUCCESS = global i32 0
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
store i8* null, i8** %6
%8 = load i32, i32* %4
%9 = icmp sgt i32 %8, 1
br i1 %9, label %10, label %38
10: ; preds = %2
store i8* ()* null, i8* ()** %7
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = load i32, i32* @RTLD_LAZY
%15 = call i8* @dlopen(i8* %13, i32 %14)
store i8* %15, i8** %6
%16 = load i8*, i8** %6
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %21
18: ; preds = %10
%19 = call i8* (...) @dlerror()
%20 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %19)
br label %37
21: ; preds = %10
%22 = load i8*, i8** %6
%23 = call i64 @dlsym(i8* %22, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%24 = inttoptr i64 %23 to i8* ()*
store i8* ()* %24, i8* ()** %7
%25 = load i8* ()*, i8* ()** %7
%26 = icmp eq i8* ()* %25, null
br i1 %26, label %27, label %30
27: ; preds = %21
%28 = call i8* (...) @dlerror()
%29 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %28)
br label %34
30: ; preds = %21
%31 = load i8* ()*, i8* ()** %7
%32 = call i8* %31()
%33 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %32)
br label %34
34: ; preds = %30, %27
%35 = load i8*, i8** %6
%36 = call i32 @dlclose(i8* %35)
br label %37
37: ; preds = %34, %18
br label %38
38: ; preds = %37, %2
%39 = call i8* (...) @op1()
%40 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %39)
%41 = load i32, i32* @EXIT_SUCCESS
ret i32 %41
}

LLVM IR (-O2):
@RTLD_LAZY = global i32 0
@.str = [19 x i8] c"dlopen error : %s\0A\00"
@.str.1 = [6 x i8] c"dlop1\00"
@.str.2 = [17 x i8] c"Result DL = %s\0A\00"
@.str.3 = [20 x i8] c"Result Shared = %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %25
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = load i32, i32* @RTLD_LAZY
%8 = tail call i8* @dlopen(i8* %6, i32 %7)
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %4
%11 = tail call i8* (...) @dlerror()
%12 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %11)
br label %25
13: ; preds = %4
%14 = tail call i64 @dlsym(i8* %8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = tail call i8* (...) @dlerror()
%18 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %17)
br label %23
19: ; preds = %13
%20 = inttoptr i64 %14 to i8* ()*
%21 = tail call i8* %20()
%22 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %19, %16
%24 = tail call i32 @dlclose(i8* %8)
br label %25
25: ; preds = %10, %23, %2
%26 = tail call i8* (...) @op1()
%27 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %26)
%28 = load i32, i32* @EXIT_SUCCESS
ret i32 %28
}