#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 struct config config;
typedef void (*init_func)(struct config *);

/* Variables and functions */
int /*<<< orphan*/ RTLD_NOW;
void *dlopen(char const *, int /*<<< orphan*/);
scalar_t__ dlsym(void *, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
void stub1(struct config *);
int /*<<< orphan*/ system(char *);
void *load_config(const char *filename, struct config *conf) {
  system("make libconfig.so");
  void *libconfig = dlopen(filename, RTLD_NOW);
  if (libconfig == NULL) {
    fprintf(stderr, "Error opening user config shared library.\n");
    exit(1);
  }
  typedef void (*init_func)(struct config *);
  init_func dynconf_init = (init_func)dlsym(libconfig, "dynconf_init");
  if (dynconf_init == NULL) {
    fprintf(
        stderr,
        "Error loading user config shared library 'dynconf_init' function.\n");
    exit(1);
  }
  (*dynconf_init)(conf);
  return libconfig;
}


x86 assembly (clang, -O0):
<load_config>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe99(%rip),%rdi
call   1030 <system@plt>
mov    -0x8(%rbp),%rdi
mov    0x2e71(%rip),%rax
mov    (%rax),%esi
call   1040 <dlopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ac <load_config+0x5c>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
lea    0xe75(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%rdi
lea    0xe86(%rip),%rsi
call   1060 <dlsym@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ea <load_config+0x9a>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
lea    0xe6f(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rdi
call   *%rax
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_config>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xe9f(%rip),%rdi
call   1030 <system@plt>
mov    0x2e7b(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1040 <dlopen@plt>
test   %rax,%rax
je     11a3 <load_config+0x53>
mov    %rax,%rbx
lea    0xeb7(%rip),%rsi
mov    %rax,%rdi
call   1060 <dlsym@plt>
test   %rax,%rax
je     11b5 <load_config+0x65>
mov    %r14,%rdi
call   *%rax
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
lea    0xe5f(%rip),%rsi
jmp    11c5 <load_config+0x75>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
lea    0xe85(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.config = type opaque
@.str = [18 x i8] c"make libconfig.so\00"
@RTLD_NOW = global i32 0
@stderr = global i32 0
@.str.1 = [43 x i8] c"Error opening user config shared library.\0A\00"
@.str.2 = [13 x i8] c"dynconf_init\00"
@.str.3 = [67 x i8] c"Error loading user config shared library 'dynconf_init' function.\0A\00"
define i8* @load_config(i8* %0, %struct.config* %1) {
%3 = alloca i8*
%4 = alloca %struct.config*
%5 = alloca i8*
%6 = alloca void (%struct.config*)*
store i8* %0, i8** %3
store %struct.config* %1, %struct.config** %4
%7 = call i32 @system(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%8 = load i8*, i8** %3
%9 = load i32, i32* @RTLD_NOW
%10 = call i8* @dlopen(i8* %8, i32 %9)
store i8* %10, i8** %5
%11 = load i8*, i8** %5
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = load i8*, i8** %5
%19 = call i64 @dlsym(i8* %18, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%20 = inttoptr i64 %19 to void (%struct.config*)*
store void (%struct.config*)* %20, void (%struct.config*)** %6
%21 = load void (%struct.config*)*, void (%struct.config*)** %6
%22 = icmp eq void (%struct.config*)* %21, null
br i1 %22, label %23, label %27
23: ; preds = %17
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.3, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %17
%28 = load void (%struct.config*)*, void (%struct.config*)** %6
%29 = load %struct.config*, %struct.config** %4
%30 = load i8*, i8** %5
ret i8* %30
}

LLVM IR (-O2):
%struct.config = type opaque
@.str = [18 x i8] c"make libconfig.so\00"
@RTLD_NOW = global i32 0
@stderr = global i32 0
@.str.1 = [43 x i8] c"Error opening user config shared library.\0A\00"
@.str.2 = [13 x i8] c"dynconf_init\00"
@.str.3 = [67 x i8] c"Error loading user config shared library 'dynconf_init' function.\0A\00"
define i8* @load_config(i8* %0, %struct.config* %1) {
%3 = tail call i32 @system(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @RTLD_NOW
%5 = tail call i8* @dlopen(i8* %0, i32 %4)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = tail call i64 @dlsym(i8* %5, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.3, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %11
%19 = inttoptr i64 %12 to void (%struct.config*)*
tail call void %19(%struct.config* %1)
ret i8* %5
}