#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 atoi(char *);
int /*<<< orphan*/ exec_dynamic_function(char const *, char const *, void *,
                                         void *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ sleep(int);
int main(int argc, char **argv) {
  const char *so_name = "./loaded_module.so";
  const char *fn_name = "__dynamic_fn_entry_point__";
  int args = atoi(argv[1]);
  int result = 0;
  while (1) {
    exec_dynamic_function(so_name, fn_name, (void *)&args, (void *)&result);
    printf("Result in main: %i\n", result);
    sleep(2);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea3(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xeab(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    -0x24(%rbp),%rdx
lea    -0x28(%rbp),%rcx
call   1040 <exec_dynamic_function@plt>
mov    -0x28(%rbp),%esi
lea    0xe8c(%rip),%rdi
call   1030 <printf@plt>
mov    $0x2,%edi
call   1060 <sleep@plt>
jmp    1183 <main+0x43>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    0x8(%rsi),%rdi
call   1050 <atoi@plt>
mov    %eax,0xc(%rsp)
movl   $0x0,0x8(%rsp)
lea    0xe97(%rip),%r14
lea    0xea3(%rip),%r15
lea    0xc(%rsp),%r12
lea    0x8(%rsp),%r13
lea    0xead(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
call   1040 <exec_dynamic_function@plt>
mov    0x8(%rsp),%esi
mov    %rbx,%rdi
call   1030 <printf@plt>
mov    $0x2,%edi
call   1060 <sleep@plt>
jmp    1190 <main+0x50>

LLVM IR (-O0):
@.str = [19 x i8] c"./loaded_module.so\00"
@.str.1 = [27 x i8] c"__dynamic_fn_entry_point__\00"
@.str.2 = [20 x i8] c"Result in main: %i\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8** %6
store i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8** %7
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = call i32 @atoi(i8* %12)
store i32 %13, i32* %8
store i32 0, i32* %9
br label %14
14: ; preds = %2, %14
%15 = load i8*, i8** %6
%16 = load i8*, i8** %7
%17 = bitcast i32* %8 to i8*
%18 = bitcast i32* %9 to i8*
%19 = call i32 @exec_dynamic_function(i8* %15, i8* %16, i8* %17, i8* %18)
%20 = load i32, i32* %9
%21 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%22 = call i32 @sleep(i32 2)
br label %14
}

LLVM IR (-O2):
@.str = [19 x i8] c"./loaded_module.so\00"
@.str.1 = [27 x i8] c"__dynamic_fn_entry_point__\00"
@.str.2 = [20 x i8] c"Result in main: %i\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32 @atoi(i8* %7)
store i32 %8, i32* %3
%9 = bitcast i32* %4 to i8*
store i32 0, i32* %4
br label %10
10: ; preds = %10, %2
%11 = call i32 @exec_dynamic_function(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %5, i8* %9)
%12 = load i32, i32* %4
%13 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %12)
%14 = call i32 @sleep(i32 2)
br label %10
}