#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*/ EXIT_FAILURE;
int /*<<< orphan*/ RTLD_LAZY;
int /*<<< orphan*/ dlclose(void *);
char *dlerror();
void *dlopen(char *, int /*<<< orphan*/);
void *dlsym(void *, char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
int stub1(int, void *);
int bandsol_obsolete(double *a, double *b, long *k, long *n) {
  void *handle;
  char *error;
  int (*cosine)(int, void *);
  int rr = 1;
  void *argv[4];
  argv[0] = a;
  argv[1] = b;
  argv[2] = k;
  argv[3] = n;
  handle = dlopen("/home/san0/zechmeister/idl/test_load_shared_lib/"
                  "bandsol.so.linux.x86_64.64",
                  RTLD_LAZY);
  if (!handle) {
    fprintf(stderr, "%s\n", dlerror());
    exit(EXIT_FAILURE);
  }
  dlerror();
  *(void **)(&cosine) = dlsym(handle, "bandsol");
  if ((error = dlerror()) != NULL) {
    fprintf(stderr, "%s\n", error);
  }
  rr = ((*cosine)(1, argv));
  dlclose(handle);
  return rr;
}


x86 assembly (clang, -O0):
<bandsol_obsolete>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x2e2a(%rip),%rax
mov    (%rax),%esi
lea    0xe51(%rip),%rdi
call   1040 <dlopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11f6 <bandsol_obsolete+0x96>
mov    0x2e16(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    $0x0,%al
call   1030 <dlerror@plt>
mov    -0x64(%rbp),%edi
mov    %rax,%rdx
lea    0xe68(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    $0x0,%al
call   1030 <dlerror@plt>
mov    -0x28(%rbp),%rdi
lea    0xe47(%rip),%rsi
call   1060 <dlsym@plt>
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   1030 <dlerror@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     123f <bandsol_obsolete+0xdf>
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rdx
lea    0xe11(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x38(%rbp),%rax
lea    -0x60(%rbp),%rsi
mov    $0x1,%edi
call   *%rax
mov    %eax,-0x3c(%rbp)
mov    -0x28(%rbp),%rdi
call   1080 <dlclose@plt>
mov    -0x3c(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bandsol_obsolete>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdi,(%rsp)
mov    %rsi,0x8(%rsp)
mov    %rdx,0x10(%rsp)
mov    %rcx,0x18(%rsp)
mov    0x2e4e(%rip),%rax
mov    (%rax),%esi
lea    0xe75(%rip),%rdi
call   1040 <dlopen@plt>
test   %rax,%rax
je     11f5 <bandsol_obsolete+0x95>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <dlerror@plt>
lea    0xea9(%rip),%rsi
mov    %rbx,%rdi
call   1060 <dlsym@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1030 <dlerror@plt>
test   %rax,%rax
je     11d5 <bandsol_obsolete+0x75>
mov    0x2e1c(%rip),%rcx
mov    (%rcx),%edi
lea    0xe7e(%rip),%rsi
mov    %rax,%rdx
call   1050 <fprintf@plt>
mov    %rsp,%rsi
mov    $0x1,%edi
call   *%r14
mov    %eax,%ebp
mov    %rbx,%rdi
call   1080 <dlclose@plt>
mov    %ebp,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2de4(%rip),%rax
mov    (%rax),%ebx
xor    %eax,%eax
call   1030 <dlerror@plt>
lea    0xe3f(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1050 <fprintf@plt>
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [75 x i8] c"/home/san0/zechmeister/idl/test_load_shared_lib/bandsol.so.linux.x86_64.64\00"
@RTLD_LAZY = global i32 0
@stderr = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [8 x i8] c"bandsol\00"
define i32 @bandsol_obsolete(double* %0, double* %1, i64* %2, i64* %3) {
%5 = alloca double*
%6 = alloca double*
%7 = alloca i64*
%8 = alloca i64*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32 (i32, i8*)*
%12 = alloca i32
%13 = alloca [4 x i8*]
store double* %0, double** %5
store double* %1, double** %6
store i64* %2, i64** %7
store i64* %3, i64** %8
store i32 1, i32* %12
%14 = load double*, double** %5
%15 = bitcast double* %14 to i8*
%16 = getelementptr inbounds [4 x i8*], [4 x i8*]* %13, i64 0, i64 0
store i8* %15, i8** %16
%17 = load double*, double** %6
%18 = bitcast double* %17 to i8*
%19 = getelementptr inbounds [4 x i8*], [4 x i8*]* %13, i64 0, i64 1
store i8* %18, i8** %19
%20 = load i64*, i64** %7
%21 = bitcast i64* %20 to i8*
%22 = getelementptr inbounds [4 x i8*], [4 x i8*]* %13, i64 0, i64 2
store i8* %21, i8** %22
%23 = load i64*, i64** %8
%24 = bitcast i64* %23 to i8*
%25 = getelementptr inbounds [4 x i8*], [4 x i8*]* %13, i64 0, i64 3
store i8* %24, i8** %25
%26 = load i32, i32* @RTLD_LAZY
%27 = call i8* @dlopen(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str, i64 0, i64 0), i32 %26)
store i8* %27, i8** %9
%28 = load i8*, i8** %9
%29 = icmp ne i8* %28, null
br i1 %29, label %36, label %30
30: ; preds = %4
%31 = load i32, i32* @stderr
%32 = call i8* (...) @dlerror()
%33 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %32)
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %4
%37 = call i8* (...) @dlerror()
%38 = load i8*, i8** %9
%39 = call i8* @dlsym(i8* %38, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%40 = bitcast i32 (i32, i8*)** %11 to i8**
store i8* %39, i8** %40
%41 = call i8* (...) @dlerror()
store i8* %41, i8** %10
%42 = icmp ne i8* %41, null
br i1 %42, label %43, label %47
43: ; preds = %36
%44 = load i32, i32* @stderr
%45 = load i8*, i8** %10
%46 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %45)
br label %47
47: ; preds = %43, %36
%48 = load i32 (i32, i8*)*, i32 (i32, i8*)** %11
%49 = getelementptr inbounds [4 x i8*], [4 x i8*]* %13, i64 0, i64 0
%50 = bitcast i8** %49 to i8*
%51 = call i32 %48(i32 1, i8* %50)
store i32 %51, i32* %12
%52 = load i8*, i8** %9
%53 = call i32 @dlclose(i8* %52)
%54 = load i32, i32* %12
ret i32 %54
}

LLVM IR (-O2):
@.str = [75 x i8] c"/home/san0/zechmeister/idl/test_load_shared_lib/bandsol.so.linux.x86_64.64\00"
@RTLD_LAZY = global i32 0
@stderr = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [8 x i8] c"bandsol\00"
define i32 @bandsol_obsolete(double* %0, double* %1, i64* %2, i64* %3) {
%5 = alloca [4 x i8*]
%6 = bitcast [4 x i8*]* %5 to i8*
%7 = bitcast [4 x i8*]* %5 to double**
store double* %0, double** %7
%8 = getelementptr inbounds [4 x i8*], [4 x i8*]* %5, i64 0, i64 1
%9 = bitcast i8** %8 to double**
store double* %1, double** %9
%10 = getelementptr inbounds [4 x i8*], [4 x i8*]* %5, i64 0, i64 2
%11 = bitcast i8** %10 to i64**
store i64* %2, i64** %11
%12 = getelementptr inbounds [4 x i8*], [4 x i8*]* %5, i64 0, i64 3
%13 = bitcast i8** %12 to i64**
store i64* %3, i64** %13
%14 = load i32, i32* @RTLD_LAZY
%15 = tail call i8* @dlopen(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %23
17: ; preds = %4
%18 = load i32, i32* @stderr
%19 = tail call i8* (...) @dlerror()
%20 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = load i32, i32* @EXIT_FAILURE
%22 = tail call i32 @exit(i32 %21)
unreachable
23: ; preds = %4
%24 = tail call i8* (...) @dlerror()
%25 = tail call i8* @dlsym(i8* %15, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%26 = tail call i8* (...) @dlerror()
%27 = icmp eq i8* %26, null
br i1 %27, label %31, label %28
28: ; preds = %23
%29 = load i32, i32* @stderr
%30 = tail call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %26)
br label %31
31: ; preds = %28, %23
%32 = bitcast i8* %25 to i32 (i32, i8*)*
%33 = call i32 %32(i32 1, i8* %6)
%34 = call i32 @dlclose(i8* %15)
ret i32 %33
}