#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 */
typedef void (*function_type)();

/* Variables and functions */
int /*<<< orphan*/ RTLD_NOW;
int /*<<< orphan*/ dlclose(void *);
void *dlopen(char *, int /*<<< orphan*/);
scalar_t__ dlsym(void *, char *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ printf(char *, char *);
char *strerror(int /*<<< orphan*/);
void *run(void *arg) {
  typedef void (*function_type)(void);
  void *lib;
  void (*cb)();
  lib = dlopen("./testsuite_shared.so", RTLD_NOW);
  if (lib == NULL) {
    printf("dlopen failed: %s\n", strerror(errno));
    return NULL;
  }
  cb = (function_type)dlsym(lib, "try_throw_exception");
  if (cb == NULL) {
    printf("dlsym failed: %s\n", strerror(errno));
    return NULL;
  }
  cb();
  dlclose(lib);
  return NULL;
}


x86 assembly (clang, -O0):
<run>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e85(%rip),%rax
mov    (%rax),%esi
lea    0xe94(%rip),%rdi
call   1040 <dlopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11aa <run+0x5a>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %rax,%rsi
lea    0xe7e(%rip),%rdi
call   1030 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1209 <run+0xb9>
mov    -0x18(%rbp),%rdi
lea    0xe74(%rip),%rsi
call   1050 <dlsym@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11f3 <run+0xa3>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %rax,%rsi
lea    0xe5c(%rip),%rdi
call   1030 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1209 <run+0xb9>
mov    $0x0,%al
call   *-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <dlclose@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run>:
push   %rbx
mov    0x2e90(%rip),%rax
mov    (%rax),%esi
lea    0xe9f(%rip),%rdi
call   1040 <dlopen@plt>
test   %rax,%rax
je     1193 <run+0x43>
mov    %rax,%rbx
lea    0xeb4(%rip),%rsi
mov    %rax,%rdi
call   1050 <dlsym@plt>
test   %rax,%rax
je     11aa <run+0x5a>
mov    %rax,%rcx
xor    %eax,%eax
call   *%rcx
mov    %rbx,%rdi
call   1070 <dlclose@plt>
jmp    11c7 <run+0x77>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe6e(%rip),%rdi
jmp    11bf <run+0x6f>
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe7e(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [22 x i8] c"./testsuite_shared.so\00"
@RTLD_NOW = global i32 0
@.str.1 = [19 x i8] c"dlopen failed: %s\0A\00"
@errno = global i32 0
@.str.2 = [20 x i8] c"try_throw_exception\00"
@.str.3 = [18 x i8] c"dlsym failed: %s\0A\00"
define i8* @run(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca void (...)*
store i8* %0, i8** %3
%6 = load i32, i32* @RTLD_NOW
%7 = call i8* @dlopen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %6)
store i8* %7, i8** %4
%8 = load i8*, i8** %4
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %14
10: ; preds = %1
%11 = load i32, i32* @errno
%12 = call i8* @strerror(i32 %11)
%13 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %12)
store i8* null, i8** %2
br label %29
14: ; preds = %1
%15 = load i8*, i8** %4
%16 = call i64 @dlsym(i8* %15, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%17 = inttoptr i64 %16 to void ()*
%18 = bitcast void ()* %17 to void (...)*
store void (...)* %18, void (...)** %5
%19 = load void (...)*, void (...)** %5
%20 = icmp eq void (...)* %19, null
br i1 %20, label %21, label %25
21: ; preds = %14
%22 = load i32, i32* @errno
%23 = call i8* @strerror(i32 %22)
%24 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %23)
store i8* null, i8** %2
br label %29
25: ; preds = %14
%26 = load void (...)*, void (...)** %5
%27 = load i8*, i8** %4
%28 = call i32 @dlclose(i8* %27)
store i8* null, i8** %2
br label %29
29: ; preds = %25, %21, %10
%30 = load i8*, i8** %2
ret i8* %30
}

LLVM IR (-O2):
@.str = [22 x i8] c"./testsuite_shared.so\00"
@RTLD_NOW = global i32 0
@.str.1 = [19 x i8] c"dlopen failed: %s\0A\00"
@errno = global i32 0
@.str.2 = [20 x i8] c"try_throw_exception\00"
@.str.3 = [18 x i8] c"dlsym failed: %s\0A\00"
define i8* @run(i8* nocapture readnone %0) {
%2 = load i32, i32* @RTLD_NOW
%3 = tail call i8* @dlopen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %9
5: ; preds = %1
%6 = load i32, i32* @errno
%7 = tail call i8* @strerror(i32 %6)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %7)
br label %19
9: ; preds = %1
%10 = tail call i64 @dlsym(i8* %3, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = load i32, i32* @errno
%14 = tail call i8* @strerror(i32 %13)
%15 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %14)
br label %19
16: ; preds = %9
%17 = inttoptr i64 %10 to void (...)*
tail call void (...) %17()
%18 = tail call i32 @dlclose(i8* %3)
br label %19
19: ; preds = %16, %12, %5
ret i8* null
}