#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;
void *dlopen(int /*<<< orphan*/ *, int /*<<< orphan*/);
void *dlsym(void *, char *);
int main(int argc, char **argv) {
  void *a = dlopen(NULL, RTLD_LAZY);
  void *m = dlsym(a, "r_main_radare2");
  if (m) {
    int (*r2main)(int argc, char **argv) = m;
    return r2main(argc, argv);
  }
  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)
mov    0x2ea3(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edi
call   1030 <dlopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1040 <dlsym@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1188 <main+0x68>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   *%rax
mov    %eax,-0x4(%rbp)
jmp    118f <main+0x6f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2eb1(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
call   1030 <dlopen@plt>
lea    0xec1(%rip),%rsi
mov    %rax,%rdi
call   1040 <dlsym@plt>
test   %rax,%rax
je     1159 <main+0x39>
mov    %ebp,%edi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    *%rax
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@RTLD_LAZY = global i32 0
@.str = [15 x i8] c"r_main_radare2\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 (i32, i8**)*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @RTLD_LAZY
%10 = call i8* @dlopen(i32* null, i32 %9)
store i8* %10, i8** %6
%11 = load i8*, i8** %6
%12 = call i8* @dlsym(i8* %11, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i8* %12, i8** %7
%13 = load i8*, i8** %7
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %22
15: ; preds = %2
%16 = load i8*, i8** %7
%17 = bitcast i8* %16 to i32 (i32, i8**)*
store i32 (i32, i8**)* %17, i32 (i32, i8**)** %8
%18 = load i32 (i32, i8**)*, i32 (i32, i8**)** %8
%19 = load i32, i32* %4
%20 = load i8**, i8*** %5
%21 = call i32 %18(i32 %19, i8** %20)
store i32 %21, i32* %3
br label %23
22: ; preds = %2
store i32 0, i32* %3
br label %23
23: ; preds = %22, %15
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
@RTLD_LAZY = global i32 0
@.str = [15 x i8] c"r_main_radare2\00"
define i32 @main(i32 %0, i8** %1) {
%3 = load i32, i32* @RTLD_LAZY
%4 = tail call i8* @dlopen(i32* null, i32 %3)
%5 = tail call i8* @dlsym(i8* %4, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = bitcast i8* %5 to i32 (i32, i8**)*
%9 = tail call i32 %8(i32 %0, i8** %1)
br label %10
10: ; preds = %2, %7
%11 = phi i32 [ %9, %7 ], [ 0, %2 ]
ret i32 %11
}