#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_NOW;
char *dlerror();
void *dlopen(char *, int /*<<< orphan*/);
void *dlsym(void *, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, char *);
void load_dimensions(int *n_config_ptr, int *nx_ptr, int *nu_ptr,
                     char *lib_string) {
  void *lib = dlopen(lib_string, RTLD_NOW);
  if (lib == NULL) {
    printf("dlopen failed: %s\n", dlerror());
    exit(1);
  }
  void *fun;
  int (*fun_ptr)();
  fun = dlsym(lib, "get_number_of_realizations");
  if (fun == NULL) {
    printf("dlsym failed: %s\n", dlerror());
    exit(1);
  }
  fun_ptr = fun;
  *n_config_ptr = fun_ptr();
  fun = dlsym(lib, "get_nx");
  if (fun == NULL) {
    printf("dlsym failed: %s\n", dlerror());
    exit(1);
  }
  fun_ptr = fun;
  *nx_ptr = fun_ptr();
  fun = dlsym(lib, "get_nu");
  if (fun == NULL) {
    printf("dlsym failed: %s\n", dlerror());
    exit(1);
  }
  fun_ptr = fun;
  *nu_ptr = fun_ptr();
}


x86 assembly (clang, -O0):
<load_dimensions>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2e75(%rip),%rax
mov    (%rax),%esi
call   1050 <dlopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11a9 <load_dimensions+0x59>
mov    $0x0,%al
call   1030 <dlerror@plt>
mov    %rax,%rsi
lea    0xe66(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x28(%rbp),%rdi
lea    0xe5f(%rip),%rsi
call   1060 <dlsym@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11e8 <load_dimensions+0x98>
mov    $0x0,%al
call   1030 <dlerror@plt>
mov    %rax,%rsi
lea    0xe55(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   *-0x38(%rbp)
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rdi
lea    0xe38(%rip),%rsi
call   1060 <dlsym@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    123c <load_dimensions+0xec>
mov    $0x0,%al
call   1030 <dlerror@plt>
mov    %rax,%rsi
lea    0xe01(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   *-0x38(%rbp)
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rdi
lea    0xdeb(%rip),%rsi
call   1060 <dlsym@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1290 <load_dimensions+0x140>
mov    $0x0,%al
call   1030 <dlerror@plt>
mov    %rax,%rsi
lea    0xdad(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   *-0x38(%rbp)
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_dimensions>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
mov    %rcx,%rdi
call   1050 <dlopen@plt>
test   %rax,%rax
je     11f1 <load_dimensions+0xa1>
mov    %rax,%rbx
lea    0xe92(%rip),%rsi
mov    %rax,%rdi
call   1060 <dlsym@plt>
test   %rax,%rax
je     11e1 <load_dimensions+0x91>
mov    %rax,%rcx
xor    %eax,%eax
call   *%rcx
mov    %eax,(%r12)
lea    0xea0(%rip),%rsi
mov    %rbx,%rdi
call   1060 <dlsym@plt>
test   %rax,%rax
je     11e1 <load_dimensions+0x91>
mov    %rax,%rcx
xor    %eax,%eax
call   *%rcx
mov    %eax,(%r15)
lea    0xe89(%rip),%rsi
mov    %rbx,%rdi
call   1060 <dlsym@plt>
test   %rax,%rax
je     11e1 <load_dimensions+0x91>
mov    %rax,%rcx
xor    %eax,%eax
call   *%rcx
mov    %eax,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
xor    %eax,%eax
call   1030 <dlerror@plt>
lea    0xe3f(%rip),%rdi
jmp    11ff <load_dimensions+0xaf>
xor    %eax,%eax
call   1030 <dlerror@plt>
lea    0xe01(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@RTLD_NOW = global i32 0
@.str = [19 x i8] c"dlopen failed: %s\0A\00"
@.str.1 = [27 x i8] c"get_number_of_realizations\00"
@.str.2 = [18 x i8] c"dlsym failed: %s\0A\00"
@.str.3 = [7 x i8] c"get_nx\00"
@.str.4 = [7 x i8] c"get_nu\00"
define void @load_dimensions(i32* %0, i32* %1, i32* %2, i8* %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32 (...)*
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
store i8* %3, i8** %8
%12 = load i8*, i8** %8
%13 = load i32, i32* @RTLD_NOW
%14 = call i8* @dlopen(i8* %12, i32 %13)
store i8* %14, i8** %9
%15 = load i8*, i8** %9
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %21
17: ; preds = %4
%18 = call i8* (...) @dlerror()
%19 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %4
%22 = load i8*, i8** %9
%23 = call i8* @dlsym(i8* %22, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
store i8* %23, i8** %10
%24 = load i8*, i8** %10
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %30
26: ; preds = %21
%27 = call i8* (...) @dlerror()
%28 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %27)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %21
%31 = load i8*, i8** %10
%32 = bitcast i8* %31 to i32 (...)*
store i32 (...)* %32, i32 (...)** %11
%33 = load i32 (...)*, i32 (...)** %11
%34 = call i32 (...) %33()
%35 = load i32*, i32** %5
store i32 %34, i32* %35
%36 = load i8*, i8** %9
%37 = call i8* @dlsym(i8* %36, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
store i8* %37, i8** %10
%38 = load i8*, i8** %10
%39 = icmp eq i8* %38, null
br i1 %39, label %40, label %44
40: ; preds = %30
%41 = call i8* (...) @dlerror()
%42 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %41)
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %30
%45 = load i8*, i8** %10
%46 = bitcast i8* %45 to i32 (...)*
store i32 (...)* %46, i32 (...)** %11
%47 = load i32 (...)*, i32 (...)** %11
%48 = call i32 (...) %47()
%49 = load i32*, i32** %6
store i32 %48, i32* %49
%50 = load i8*, i8** %9
%51 = call i8* @dlsym(i8* %50, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
store i8* %51, i8** %10
%52 = load i8*, i8** %10
%53 = icmp eq i8* %52, null
br i1 %53, label %54, label %58
54: ; preds = %44
%55 = call i8* (...) @dlerror()
%56 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %55)
%57 = call i32 @exit(i32 1)
unreachable
58: ; preds = %44
%59 = load i8*, i8** %10
%60 = bitcast i8* %59 to i32 (...)*
store i32 (...)* %60, i32 (...)** %11
%61 = load i32 (...)*, i32 (...)** %11
%62 = call i32 (...) %61()
%63 = load i32*, i32** %7
store i32 %62, i32* %63
ret void
}

LLVM IR (-O2):
@RTLD_NOW = global i32 0
@.str = [19 x i8] c"dlopen failed: %s\0A\00"
@.str.1 = [27 x i8] c"get_number_of_realizations\00"
@.str.2 = [18 x i8] c"dlsym failed: %s\0A\00"
@.str.3 = [7 x i8] c"get_nx\00"
@.str.4 = [7 x i8] c"get_nu\00"
define void @load_dimensions(i32* nocapture writeonly %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2, i8* %3) {
%5 = load i32, i32* @RTLD_NOW
%6 = tail call i8* @dlopen(i8* %3, i32 %5)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %12
8: ; preds = %4
%9 = tail call i8* (...) @dlerror()
%10 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %4
%13 = tail call i8* @dlsym(i8* %6, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %19
15: ; preds = %12
%16 = tail call i8* (...) @dlerror()
%17 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %16)
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %12
%20 = bitcast i8* %13 to i32 (...)*
%21 = tail call i32 (...) %20()
store i32 %21, i32* %0
%22 = tail call i8* @dlsym(i8* %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %28
24: ; preds = %19
%25 = tail call i8* (...) @dlerror()
%26 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %25)
%27 = tail call i32 @exit(i32 1)
unreachable
28: ; preds = %19
%29 = bitcast i8* %22 to i32 (...)*
%30 = tail call i32 (...) %29()
store i32 %30, i32* %1
%31 = tail call i8* @dlsym(i8* %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %37
33: ; preds = %28
%34 = tail call i8* (...) @dlerror()
%35 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %34)
%36 = tail call i32 @exit(i32 1)
unreachable
37: ; preds = %28
%38 = bitcast i8* %31 to i32 (...)*
%39 = tail call i32 (...) %38()
store i32 %39, i32* %2
ret void
}