#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_LAZY;
int answer_to_everything();
void *dlopen(char *, int /*<<< orphan*/);
void *dlsym(void *, char *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  void *handle;
  int (*bbb_answer)(void);
  int *my_variable_sym;
  printf("*aaa*\n");
  int soAnswer = answer_to_everything();
  printf("Answer = %d\n\n", soAnswer);
  printf("*bbb*\n");
  handle = dlopen("./libbbb.so", RTLD_LAZY);
  *(void **)(&bbb_answer) = dlsym(handle, "ImportantAnswer");
  printf("Answer = %d\n\n", bbb_answer());
  void *obj = dlsym(handle, "my_variable");
  my_variable_sym = (int *)obj;
  printf("my_variable = %d\n\n", *my_variable_sym);
  *my_variable_sym = 119191919;
  printf("my_variable = %d\n\n", *my_variable_sym);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1060 <answer_to_everything@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e53(%rip),%rax
mov    (%rax),%esi
lea    0xe86(%rip),%rdi
call   1040 <dlopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe7e(%rip),%rsi
call   1050 <dlsym@plt>
mov    %rax,-0x18(%rbp)
call   *-0x18(%rbp)
mov    %eax,%esi
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    0xe67(%rip),%rsi
call   1050 <dlsym@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
movl   $0x71ab96f,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xeee(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1070 <answer_to_everything@plt>
lea    0xe92(%rip),%r14
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xece(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e53(%rip),%rax
mov    (%rax),%esi
lea    0xe78(%rip),%rdi
call   1050 <dlopen@plt>
mov    %rax,%rbx
lea    0xe75(%rip),%rsi
mov    %rax,%rdi
call   1060 <dlsym@plt>
call   *%rax
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe68(%rip),%rsi
mov    %rbx,%rdi
call   1060 <dlsym@plt>
mov    %rax,%rbx
mov    (%rax),%esi
lea    0xe60(%rip),%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movl   $0x71ab96f,(%rbx)
mov    %r14,%rdi
mov    $0x71ab96f,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [7 x i8] c"*aaa*\0A\00"
@.str.1 = [14 x i8] c"Answer = %d\0A\0A\00"
@.str.2 = [7 x i8] c"*bbb*\0A\00"
@.str.3 = [12 x i8] c"./libbbb.so\00"
@RTLD_LAZY = global i32 0
@.str.4 = [16 x i8] c"ImportantAnswer\00"
@.str.5 = [12 x i8] c"my_variable\00"
@.str.6 = [19 x i8] c"my_variable = %d\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32 ()*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8*
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (...) @answer_to_everything()
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%12 = load i32, i32* @RTLD_LAZY
%13 = call i8* @dlopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %12)
store i8* %13, i8** %2
%14 = load i8*, i8** %2
%15 = call i8* @dlsym(i8* %14, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%16 = bitcast i32 ()** %3 to i8**
store i8* %15, i8** %16
%17 = load i32 ()*, i32 ()** %3
%18 = call i32 %17()
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = load i8*, i8** %2
%21 = call i8* @dlsym(i8* %20, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
store i8* %21, i8** %6
%22 = load i8*, i8** %6
%23 = bitcast i8* %22 to i32*
store i32* %23, i32** %4
%24 = load i32*, i32** %4
%25 = load i32, i32* %24
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i32 %25)
%27 = load i32*, i32** %4
store i32 119191919, i32* %27
%28 = load i32*, i32** %4
%29 = load i32, i32* %28
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i32 %29)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [14 x i8] c"Answer = %d\0A\0A\00"
@.str.3 = [12 x i8] c"./libbbb.so\00"
@RTLD_LAZY = global i32 0
@.str.4 = [16 x i8] c"ImportantAnswer\00"
@.str.5 = [12 x i8] c"my_variable\00"
@.str.6 = [19 x i8] c"my_variable = %d\0A\0A\00"
@str = [6 x i8] c"*aaa*\00"
@str.7 = [6 x i8] c"*bbb*\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 (...) @answer_to_everything()
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %2)
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.7, i64 0, i64 0))
%5 = load i32, i32* @RTLD_LAZY
%6 = tail call i8* @dlopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %5)
%7 = tail call i8* @dlsym(i8* %6, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%8 = bitcast i8* %7 to i32 ()*
%9 = tail call i32 %8()
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = tail call i8* @dlsym(i8* %6, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%12 = bitcast i8* %11 to i32*
%13 = load i32, i32* %12
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i32 %13)
store i32 119191919, i32* %12
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i32 119191919)
ret i32 0
}