#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 errno;
int /*<<< orphan*/ load_fn_from_shared_object(void *, char const *, void **);
int /*<<< orphan*/ load_shared_object(char const *, void **);
int /*<<< orphan*/ unload_shared_object(void **);
int exec_dynamic_function(const char *so_name, const char *fn_name, void *args,
                          void *result) {
  void *handle = NULL;
  int ret_code;
  int (*fn)(void *, void *) = NULL;
  errno = 0;
  load_shared_object(so_name, &handle);
  load_fn_from_shared_object(handle, fn_name, (void **)&fn);
  ret_code = fn(args, result);
  unload_shared_object(&handle);
  return errno | ret_code ? 1 : 0;
}


x86 assembly (clang, -O0):
<exec_dynamic_function>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x38(%rbp)
mov    0x2e81(%rip),%rax
movl   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1040 <load_shared_object@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x38(%rbp),%rdx
call   1030 <load_fn_from_shared_object@plt>
mov    -0x38(%rbp),%rax
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   *%rax
mov    %eax,-0x2c(%rbp)
lea    -0x28(%rbp),%rdi
call   1050 <unload_shared_object@plt>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edx
or     -0x2c(%rbp),%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exec_dynamic_function>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbx
movq   $0x0,0x8(%rsp)
movq   $0x0,(%rsp)
mov    0x2e82(%rip),%r13
movl   $0x0,0x0(%r13)
lea    0x8(%rsp),%r12
mov    %r12,%rsi
call   1040 <load_shared_object@plt>
mov    0x8(%rsp),%rdi
mov    %rsp,%rdx
mov    %rbx,%rsi
call   1030 <load_fn_from_shared_object@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   *(%rsp)
mov    %eax,%ebx
mov    %r12,%rdi
call   1050 <unload_shared_object@plt>
xor    %eax,%eax
or     0x0(%r13),%ebx
setne  %al
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i32 0
define i32 @exec_dynamic_function(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32 (i8*, i8*)*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i8* %3, i8** %8
store i8* null, i8** %9
store i32 (i8*, i8*)* null, i32 (i8*, i8*)** %11
store i32 0, i32* @errno
%12 = load i8*, i8** %5
%13 = call i32 @load_shared_object(i8* %12, i8** %9)
%14 = load i8*, i8** %9
%15 = load i8*, i8** %6
%16 = bitcast i32 (i8*, i8*)** %11 to i8**
%17 = call i32 @load_fn_from_shared_object(i8* %14, i8* %15, i8** %16)
%18 = load i32 (i8*, i8*)*, i32 (i8*, i8*)** %11
%19 = load i8*, i8** %7
%20 = load i8*, i8** %8
%21 = call i32 %18(i8* %19, i8* %20)
store i32 %21, i32* %10
%22 = call i32 @unload_shared_object(i8** %9)
%23 = load i32, i32* @errno
%24 = load i32, i32* %10
%25 = or i32 %23, %24
%26 = icmp ne i32 %25, 0
%27 = zext i1 %26 to i64
%28 = select i1 %26, i32 1, i32 0
ret i32 %28
}

LLVM IR (-O2):
@errno = global i32 0
define i32 @exec_dynamic_function(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i32 (i8*, i8*)*
%7 = bitcast i8** %5 to i8*
store i8* null, i8** %5
%8 = bitcast i32 (i8*, i8*)** %6 to i8*
store i32 (i8*, i8*)* null, i32 (i8*, i8*)** %6
store i32 0, i32* @errno
%9 = call i32 @load_shared_object(i8* %0, i8** %5)
%10 = load i8*, i8** %5
%11 = bitcast i32 (i8*, i8*)** %6 to i8**
%12 = call i32 @load_fn_from_shared_object(i8* %10, i8* %1, i8** %11)
%13 = load i32 (i8*, i8*)*, i32 (i8*, i8*)** %6
%14 = call i32 %13(i8* %2, i8* %3)
%15 = call i32 @unload_shared_object(i8** %5)
%16 = load i32, i32* @errno
%17 = or i32 %16, %14
%18 = icmp ne i32 %17, 0
%19 = zext i1 %18 to i32
ret i32 %19
}