#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(char *, int /*<<< orphan*/);
void *dlsym(void *, char *);
int fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int stub1(int, char **);
int main(int argc, char **argv) {
  void *h =
      dlopen("/data/data/org.servalproject/lib/libiwstatus.so", RTLD_LAZY);
  int (*themain)(int, char **) = dlsym(h, "main_iwconfig");
  char *msg = dlsym(h, "msg_out");
  if (!themain)
    return fprintf(stderr, "Could not load libiwstatus.so\n");
  (*themain)(argc, argv);
  printf("completed:\n[%s]\n", msg);
  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    0x2e7b(%rip),%rax
mov    (%rax),%esi
lea    0xe9a(%rip),%rdi
call   1040 <dlopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xeb6(%rip),%rsi
call   1060 <dlsym@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xeb0(%rip),%rsi
call   1060 <dlsym@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11bf <main+0x7f>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
lea    0xe94(%rip),%rsi
call   1050 <fprintf@plt>
mov    %eax,-0x4(%rbp)
jmp    11e3 <main+0xa3>
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   *%rax
mov    -0x28(%rbp),%rsi
lea    0xe8e(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%r15d
mov    0x2e84(%rip),%rax
mov    (%rax),%esi
lea    0xea3(%rip),%rdi
call   1040 <dlopen@plt>
mov    %rax,%rbp
lea    0xec4(%rip),%rsi
mov    %rax,%rdi
call   1060 <dlsym@plt>
mov    %rax,%rbx
lea    0xec0(%rip),%rsi
mov    %rbp,%rdi
call   1060 <dlsym@plt>
test   %rbx,%rbx
je     11b2 <main+0x72>
mov    %rax,%rbp
mov    %r15d,%edi
mov    %r14,%rsi
call   *%rbx
lea    0xec8(%rip),%rdi
mov    %rbp,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
lea    0xe84(%rip),%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <fprintf@plt>

LLVM IR (-O0):
@.str = [48 x i8] c"/data/data/org.servalproject/lib/libiwstatus.so\00"
@RTLD_LAZY = global i32 0
@.str.1 = [14 x i8] c"main_iwconfig\00"
@.str.2 = [8 x i8] c"msg_out\00"
@stderr = global i32 0
@.str.3 = [31 x i8] c"Could not load libiwstatus.so\0A\00"
@.str.4 = [17 x i8] c"completed:\0A[%s]\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32 (i32, i8**)*
%8 = alloca 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(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i32 %9)
store i8* %10, i8** %6
%11 = load i8*, i8** %6
%12 = call i8* @dlsym(i8* %11, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%13 = bitcast i8* %12 to i32 (i32, i8**)*
store i32 (i32, i8**)* %13, i32 (i32, i8**)** %7
%14 = load i8*, i8** %6
%15 = call i8* @dlsym(i8* %14, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
store i8* %15, i8** %8
%16 = load i32 (i32, i8**)*, i32 (i32, i8**)** %7
%17 = icmp ne i32 (i32, i8**)* %16, null
br i1 %17, label %21, label %18
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
store i32 %20, i32* %3
br label %28
21: ; preds = %2
%22 = load i32 (i32, i8**)*, i32 (i32, i8**)** %7
%23 = load i32, i32* %4
%24 = load i8**, i8*** %5
%25 = call i32 %22(i32 %23, i8** %24)
%26 = load i8*, i8** %8
%27 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %26)
store i32 0, i32* %3
br label %28
28: ; preds = %21, %18
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
@.str = [48 x i8] c"/data/data/org.servalproject/lib/libiwstatus.so\00"
@RTLD_LAZY = global i32 0
@.str.1 = [14 x i8] c"main_iwconfig\00"
@.str.2 = [8 x i8] c"msg_out\00"
@stderr = global i32 0
@.str.3 = [31 x i8] c"Could not load libiwstatus.so\0A\00"
@.str.4 = [17 x i8] c"completed:\0A[%s]\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = load i32, i32* @RTLD_LAZY
%4 = tail call i8* @dlopen(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = tail call i8* @dlsym(i8* %4, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i8* @dlsym(i8* %4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%7 = icmp eq i8* %5, null
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
br label %15
11: ; preds = %2
%12 = bitcast i8* %5 to i32 (i32, i8**)*
%13 = tail call i32 %12(i32 %0, i8** %1)
%14 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %6)
br label %15
15: ; preds = %11, %8
%16 = phi i32 [ 0, %11 ], [ %10, %8 ]
ret i32 %16
}