#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*/ exit(int);
char *getMozLibPath();
void *loadLibrary(char *, char const *);
int /*<<< orphan*/ printf(char *, char const *);
int strlen(char *);
void initLib(const char *name, char *dir, void **libref, const char *lib) {
  if (!(*libref)) {
    if (dir == NULL || strlen(dir) < 1) {
      dir = getMozLibPath();
    }
    if (!((*libref) = loadLibrary(dir, lib))) {
      printf("[-] Failed to load %s library\n", name);
      exit(1);
    }
  }
}


x86 assembly (clang, -O0):
<initLib>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11db <initLib+0x8b>
cmpq   $0x0,-0x10(%rbp)
je     1193 <initLib+0x43>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x1,%eax
jge    119e <initLib+0x4e>
mov    $0x0,%al
call   1060 <getMozLibPath@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <loadLibrary@plt>
mov    -0x18(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    11d6 <initLib+0x86>
mov    -0x8(%rbp),%rsi
lea    0xe39(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    11db <initLib+0x8b>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<initLib>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmpq   $0x0,(%rdx)
jne    1199 <initLib+0x49>
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%rbx
mov    %rdi,%r14
test   %rsi,%rsi
je     117b <initLib+0x2b>
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jg     1185 <initLib+0x35>
xor    %eax,%eax
call   1060 <getMozLibPath@plt>
mov    %rax,%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <loadLibrary@plt>
mov    %rax,(%r12)
test   %rax,%rax
je     11a5 <initLib+0x55>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe54(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [31 x i8] c"[-] Failed to load %s library\0A\00"
define void @initLib(i8* %0, i8* %1, i8** %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8** %2, i8*** %7
store i8* %3, i8** %8
%9 = load i8**, i8*** %7
%10 = load i8*, i8** %9
%11 = icmp ne i8* %10, null
br i1 %11, label %32, label %12
12: ; preds = %4
%13 = load i8*, i8** %6
%14 = icmp eq i8* %13, null
br i1 %14, label %19, label %15
15: ; preds = %12
%16 = load i8*, i8** %6
%17 = call i32 @strlen(i8* %16)
%18 = icmp slt i32 %17, 1
br i1 %18, label %19, label %21
19: ; preds = %15, %12
%20 = call i8* (...) @getMozLibPath()
store i8* %20, i8** %6
br label %21
21: ; preds = %19, %15
%22 = load i8*, i8** %6
%23 = load i8*, i8** %8
%24 = call i8* @loadLibrary(i8* %22, i8* %23)
%25 = load i8**, i8*** %7
store i8* %24, i8** %25
%26 = icmp ne i8* %24, null
br i1 %26, label %31, label %27
27: ; preds = %21
%28 = load i8*, i8** %5
%29 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %28)
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %21
br label %32
32: ; preds = %31, %4
ret void
}

LLVM IR (-O2):
@.str = [31 x i8] c"[-] Failed to load %s library\0A\00"
define void @initLib(i8* %0, i8* %1, i8** nocapture %2, i8* %3) {
%5 = load i8*, i8** %2
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %21
7: ; preds = %4
%8 = icmp eq i8* %1, null
br i1 %8, label %12, label %9
9: ; preds = %7
%10 = tail call i32 @strlen(i8* %1)
%11 = icmp slt i32 %10, 1
br i1 %11, label %12, label %14
12: ; preds = %9, %7
%13 = tail call i8* (...) @getMozLibPath()
br label %14
14: ; preds = %12, %9
%15 = phi i8* [ %13, %12 ], [ %1, %9 ]
%16 = tail call i8* @loadLibrary(i8* %15, i8* %3)
store i8* %16, i8** %2
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %0)
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %14, %4
ret void
}