#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 /*<<< orphan*/ dlclose(void *);
char *dlerror();
void *dlopen(char *, int /*<<< orphan*/);
void *dlsym(void *, char *);
int /*<<< orphan*/ printf(char *, char *);
void *initDrone(char *soName, int showinfo) {
  char *mid[100] = {0};
  void *(*init)(char *);
  char *error;
  void *droneExec = 0;
  void *handle = dlopen(soName, RTLD_LAZY);
  if (handle) {
    init = dlsym(handle, "init");
    if ((error = dlerror()) != NULL) {
      ;
      dlclose(handle);
    } else {
      void *funcExec = dlsym(handle, "exec");
      if ((error = dlerror()) != NULL) {
        ;
        dlclose(handle);
      } else {
        void *j = init((char *)mid);
        if (0 == j) {
          ;
        } else if ((void *)-1 == j) {
          ;
        } else {
          droneExec = funcExec;
        }
      }
    }
  } else {
    ;
    if (showinfo) {
      printf("dlopen - %s \n", dlerror());
    }
  }
  return droneExec;
}


x86 assembly (clang, -O0):
<initDrone>:
push   %rbp
mov    %rsp,%rbp
sub    $0x360,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x330(%rbp),%rdi
xor    %esi,%esi
mov    $0x320,%edx
call   1050 <memset@plt>
movq   $0x0,-0x348(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e45(%rip),%rax
mov    (%rax),%esi
call   1060 <dlopen@plt>
mov    %rax,-0x350(%rbp)
cmpq   $0x0,-0x350(%rbp)
je     12a3 <initDrone+0x143>
mov    -0x350(%rbp),%rdi
lea    0xe3b(%rip),%rsi
call   1070 <dlsym@plt>
mov    %rax,-0x338(%rbp)
mov    $0x0,%al
call   1030 <dlerror@plt>
mov    %rax,-0x340(%rbp)
cmp    $0x0,%rax
je     11fa <initDrone+0x9a>
mov    -0x350(%rbp),%rdi
call   1080 <dlclose@plt>
jmp    129e <initDrone+0x13e>
mov    -0x350(%rbp),%rdi
lea    0xdfd(%rip),%rsi
call   1070 <dlsym@plt>
mov    %rax,-0x358(%rbp)
mov    $0x0,%al
call   1030 <dlerror@plt>
mov    %rax,-0x340(%rbp)
cmp    $0x0,%rax
je     123d <initDrone+0xdd>
mov    -0x350(%rbp),%rdi
call   1080 <dlclose@plt>
jmp    1299 <initDrone+0x139>
mov    -0x338(%rbp),%rax
lea    -0x330(%rbp),%rdi
call   *%rax
mov    %rax,-0x360(%rbp)
xor    %eax,%eax
cmp    -0x360(%rbp),%rax
jne    1268 <initDrone+0x108>
jmp    1294 <initDrone+0x134>
mov    $0xffffffffffffffff,%rax
cmp    -0x360(%rbp),%rax
jne    1281 <initDrone+0x121>
jmp    128f <initDrone+0x12f>
mov    -0x358(%rbp),%rax
mov    %rax,-0x348(%rbp)
jmp    1294 <initDrone+0x134>
jmp    1299 <initDrone+0x139>
jmp    129e <initDrone+0x13e>
jmp    12c8 <initDrone+0x168>
cmpl   $0x0,-0xc(%rbp)
je     12c3 <initDrone+0x163>
mov    $0x0,%al
call   1030 <dlerror@plt>
mov    %rax,%rsi
lea    0xd4c(%rip),%rdi
call   1040 <printf@plt>
jmp    12c8 <initDrone+0x168>
mov    -0x348(%rbp),%rax
add    $0x360,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<initDrone>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x328,%rsp
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %rsp,%rdi
mov    $0x320,%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    0x2e58(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1060 <dlopen@plt>
test   %rax,%rax
je     11e3 <initDrone+0x83>
mov    %rax,%rbx
lea    0xe5f(%rip),%rsi
mov    %rax,%rdi
call   1070 <dlsym@plt>
mov    %rax,%r15
xor    %eax,%eax
call   1030 <dlerror@plt>
test   %rax,%rax
jne    11d6 <initDrone+0x76>
lea    0xe46(%rip),%rsi
mov    %rbx,%rdi
call   1070 <dlsym@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1030 <dlerror@plt>
test   %rax,%rax
je     1211 <initDrone+0xb1>
mov    %rbx,%rdi
call   1080 <dlclose@plt>
xor    %r14d,%r14d
jmp    1200 <initDrone+0xa0>
xor    %r14d,%r14d
test   %ebp,%ebp
je     1200 <initDrone+0xa0>
xor    %eax,%eax
call   1030 <dlerror@plt>
lea    0xe12(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    %r14,%rax
add    $0x328,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rsp,%rdi
call   *%r15
add    $0x1,%rax
cmp    $0x2,%rax
jae    1200 <initDrone+0xa0>
xor    %r14d,%r14d
jmp    1200 <initDrone+0xa0>

LLVM IR (-O0):
@RTLD_LAZY = global i32 0
@.str = [5 x i8] c"init\00"
@.str.1 = [5 x i8] c"exec\00"
@.str.2 = [14 x i8] c"dlopen - %s \0A\00"
define i8* @initDrone(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [100 x i8*]
%6 = alloca i8* (i8*)*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%12 = bitcast [100 x i8*]* %5 to i8*
store i8* null, i8** %8
%13 = load i8*, i8** %3
%14 = load i32, i32* @RTLD_LAZY
%15 = call i8* @dlopen(i8* %13, i32 %14)
store i8* %15, i8** %9
%16 = load i8*, i8** %9
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %53
18: ; preds = %2
%19 = load i8*, i8** %9
%20 = call i8* @dlsym(i8* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%21 = bitcast i8* %20 to i8* (i8*)*
store i8* (i8*)* %21, i8* (i8*)** %6
%22 = call i8* (...) @dlerror()
store i8* %22, i8** %7
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %27
24: ; preds = %18
%25 = load i8*, i8** %9
%26 = call i32 @dlclose(i8* %25)
br label %52
27: ; preds = %18
%28 = load i8*, i8** %9
%29 = call i8* @dlsym(i8* %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i8* %29, i8** %10
%30 = call i8* (...) @dlerror()
store i8* %30, i8** %7
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = load i8*, i8** %9
%34 = call i32 @dlclose(i8* %33)
br label %51
35: ; preds = %27
%36 = load i8* (i8*)*, i8* (i8*)** %6
%37 = getelementptr inbounds [100 x i8*], [100 x i8*]* %5, i64 0, i64 0
%38 = bitcast i8** %37 to i8*
%39 = call i8* %36(i8* %38)
store i8* %39, i8** %11
%40 = load i8*, i8** %11
%41 = icmp eq i8* null, %40
br i1 %41, label %42, label %43
42: ; preds = %35
br label %50
43: ; preds = %35
%44 = load i8*, i8** %11
%45 = icmp eq i8* inttoptr (i64 -1 to i8*), %44
br i1 %45, label %46, label %47
46: ; preds = %43
br label %49
47: ; preds = %43
%48 = load i8*, i8** %10
store i8* %48, i8** %8
br label %49
49: ; preds = %47, %46
br label %50
50: ; preds = %49, %42
br label %51
51: ; preds = %50, %32
br label %52
52: ; preds = %51, %24
br label %60
53: ; preds = %2
%54 = load i32, i32* %4
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %59
56: ; preds = %53
%57 = call i8* (...) @dlerror()
%58 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %57)
br label %59
59: ; preds = %56, %53
br label %60
60: ; preds = %59, %52
%61 = load i8*, i8** %8
ret i8* %61
}

LLVM IR (-O2):
@RTLD_LAZY = global i32 0
@.str = [5 x i8] c"init\00"
@.str.1 = [5 x i8] c"exec\00"
@.str.2 = [14 x i8] c"dlopen - %s \0A\00"
define i8* @initDrone(i8* %0, i32 %1) {
%3 = alloca [100 x i8*]
%4 = bitcast [100 x i8*]* %3 to i8*
%5 = load i32, i32* @RTLD_LAZY
%6 = tail call i8* @dlopen(i8* %0, i32 %5)
%7 = icmp eq i8* %6, null
br i1 %7, label %25, label %8
8: ; preds = %2
%9 = tail call i8* @dlsym(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%10 = bitcast i8* %9 to i8* (i8*)*
%11 = tail call i8* (...) @dlerror()
%12 = icmp eq i8* %11, null
br i1 %12, label %15, label %13
13: ; preds = %8
%14 = tail call i32 @dlclose(i8* %6)
br label %30
15: ; preds = %8
%16 = tail call i8* @dlsym(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%17 = tail call i8* (...) @dlerror()
%18 = icmp eq i8* %17, null
br i1 %18, label %21, label %19
19: ; preds = %15
%20 = tail call i32 @dlclose(i8* %6)
br label %30
21: ; preds = %15
%22 = call i8* %10(i8* %4)
%23 = ptrtoint i8* %22 to i64
switch i64 %23, label %24 [
i64 -1, label %30
i64 0, label %30
]
24: ; preds = %21
br label %30
25: ; preds = %2
%26 = icmp eq i32 %1, 0
br i1 %26, label %30, label %27
27: ; preds = %25
%28 = tail call i8* (...) @dlerror()
%29 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %28)
br label %30
30: ; preds = %19, %21, %21, %24, %25, %27, %13
%31 = phi i8* [ null, %13 ], [ null, %27 ], [ null, %25 ], [ null, %19 ], [ null, %21 ], [ %16, %24 ], [ null, %21 ]
ret i8* %31
}