#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*/ MP_printLog(char *, int, char *, int, char *, ...);
int RTLD_DEEPBIND;
int RTLD_GLOBAL;
int RTLD_LAZY;
int RTLD_LOCAL;
int /*<<< orphan*/ dlerror();
void *dlopen(char const *, int);
scalar_t__ strcmp(char const *, char *);
void *mepinta_load_library(const char *path, const char *symbol) {
  int flag = RTLD_LAZY;
  if (path != NULL || symbol != NULL) {
    if (strcmp(symbol, "global") == 0) {
      flag = flag | RTLD_GLOBAL;
    } else if (strcmp(symbol, "local") == 0) {
      flag = flag | RTLD_LOCAL;
    } else if (strcmp(symbol, "deep") == 0) {
      flag = flag | RTLD_GLOBAL | RTLD_DEEPBIND;
    } else {
      MP_printLog(
          "LOG_MEPINTA_ERROR", 10,
          "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
          "2022-01-22/02-19-57/repos/joaduo/mepinta/refs/heads/master/backend/"
          "c_and_cpp/backend_api_c/load_unload_library.c",
          60, "Loading symbols in that '%s' way is not supported.\n", symbol);
      return NULL;
    }
    MP_printLog("LOG_MEPINTA_DEBUG", 50,
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/joaduo/mepinta/refs/heads/"
                "master/backend/c_and_cpp/backend_api_c/load_unload_library.c",
                63, "Loading %s with %s symbols. flag=0x%x.\n", path, symbol,
                flag);
    dlerror();
    void *handle = dlopen(path, flag);
    if (handle == NULL) {
      MP_printLog(
          "LOG_MEPINTA_ERROR", 10,
          "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
          "2022-01-22/02-19-57/repos/joaduo/mepinta/refs/heads/master/backend/"
          "c_and_cpp/backend_api_c/load_unload_library.c",
          68, "Failed to load the requested library. Reason: %s\n", dlerror());
    }
    return handle;
  } else {
    MP_printLog("LOG_MEPINTA_ERROR", 10,
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/joaduo/mepinta/refs/heads/"
                "master/backend/c_and_cpp/backend_api_c/load_unload_library.c",
                73, "Path or symbol are NULL pointer.\n");
    return NULL;
  }
}


x86 assembly (clang, -O0):
<mepinta_load_library>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2e79(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1172 <mepinta_load_library+0x32>
cmpq   $0x0,-0x18(%rbp)
je     12de <mepinta_load_library+0x19e>
mov    -0x18(%rbp),%rdi
lea    0xe83(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11a0 <mepinta_load_library+0x60>
mov    -0x1c(%rbp),%eax
mov    0x2e4a(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x1c(%rbp)
jmp    1246 <mepinta_load_library+0x106>
mov    -0x18(%rbp),%rdi
lea    0xe5c(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11ce <mepinta_load_library+0x8e>
mov    -0x1c(%rbp),%eax
mov    0x2dfc(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x1c(%rbp)
jmp    1241 <mepinta_load_library+0x101>
mov    -0x18(%rbp),%rdi
lea    0xe34(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1205 <mepinta_load_library+0xc5>
mov    -0x1c(%rbp),%eax
mov    0x2dee(%rip),%rcx
or     (%rcx),%eax
mov    0x2ded(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x1c(%rbp)
jmp    123c <mepinta_load_library+0xfc>
mov    -0x18(%rbp),%r9
lea    0xe02(%rip),%rdi
mov    $0xa,%esi
lea    0xe08(%rip),%rdx
mov    $0x3c,%ecx
lea    0xead(%rip),%r8
mov    $0x0,%al
call   1040 <MP_printLog@plt>
movq   $0x0,-0x8(%rbp)
jmp    130c <mepinta_load_library+0x1cc>
jmp    1241 <mepinta_load_library+0x101>
jmp    1246 <mepinta_load_library+0x106>
mov    -0x10(%rbp),%r9
mov    -0x18(%rbp),%r10
mov    -0x1c(%rbp),%eax
lea    0xeb1(%rip),%rdi
mov    $0x32,%esi
lea    0xdc0(%rip),%rdx
mov    $0x3f,%ecx
lea    0xeab(%rip),%r8
mov    %r10,(%rsp)
mov    %eax,0x8(%rsp)
mov    $0x0,%al
call   1040 <MP_printLog@plt>
mov    $0x0,%al
call   1030 <dlerror@plt>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1060 <dlopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    12d1 <mepinta_load_library+0x191>
mov    $0x0,%al
call   1030 <dlerror@plt>
mov    %eax,%r9d
lea    0xd60(%rip),%rdi
mov    $0xa,%esi
lea    0xd66(%rip),%rdx
mov    $0x44,%ecx
lea    0xe79(%rip),%r8
mov    $0x0,%al
call   1040 <MP_printLog@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    130c <mepinta_load_library+0x1cc>
lea    0xd2d(%rip),%rdi
mov    $0xa,%esi
lea    0xd33(%rip),%rdx
mov    $0x49,%ecx
lea    0xe78(%rip),%r8
mov    $0x0,%al
call   1040 <MP_printLog@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mepinta_load_library>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rax
or     %rsi,%rax
je     11d4 <mepinta_load_library+0x94>
mov    %rsi,%r12
mov    %rdi,%r14
mov    0x2e6f(%rip),%rax
mov    (%rax),%r15d
lea    0xe95(%rip),%rsi
mov    %r12,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1201 <mepinta_load_library+0xc1>
lea    0xe84(%rip),%rsi
mov    %r12,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     120c <mepinta_load_library+0xcc>
lea    0xe76(%rip),%rsi
mov    %r12,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1217 <mepinta_load_library+0xd7>
lea    0xe67(%rip),%rdi
lea    0xe72(%rip),%rdx
lea    0xf1c(%rip),%r8
xor    %ebx,%ebx
mov    $0xa,%esi
mov    $0x3c,%ecx
mov    %r12,%r9
xor    %eax,%eax
call   1040 <MP_printLog@plt>
jmp    12ad <mepinta_load_library+0x16d>
lea    0xe37(%rip),%rdi
lea    0xe42(%rip),%rdx
lea    0xf8c(%rip),%r8
xor    %ebx,%ebx
mov    $0xa,%esi
mov    $0x49,%ecx
xor    %eax,%eax
call   1040 <MP_printLog@plt>
jmp    12ad <mepinta_load_library+0x16d>
mov    0x2dd8(%rip),%rax
mov    (%rax),%eax
jmp    122d <mepinta_load_library+0xed>
mov    0x2dad(%rip),%rax
mov    (%rax),%eax
jmp    122d <mepinta_load_library+0xed>
mov    0x2dc2(%rip),%rcx
mov    %r15d,%eax
or     (%rcx),%eax
mov    0x2dbe(%rip),%rcx
mov    (%rcx),%r15d
or     %eax,%r15d
lea    0xed2(%rip),%rdi
lea    0xde6(%rip),%rdx
lea    0xed6(%rip),%r8
mov    $0x32,%esi
mov    $0x3f,%ecx
mov    %r14,%r9
xor    %eax,%eax
push   %r15
push   %r12
call   1040 <MP_printLog@plt>
add    $0x10,%rsp
xor    %eax,%eax
call   1030 <dlerror@plt>
mov    %r14,%rdi
mov    %r15d,%esi
call   1060 <dlopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    12ad <mepinta_load_library+0x16d>
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <dlerror@plt>
lea    0xd87(%rip),%rdi
lea    0xd92(%rip),%rdx
lea    0xeaa(%rip),%r8
mov    $0xa,%esi
mov    $0x44,%ecx
mov    %eax,%r9d
xor    %eax,%eax
call   1040 <MP_printLog@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@RTLD_LAZY = global i32 0
@.str = [7 x i8] c"global\00"
@RTLD_GLOBAL = global i32 0
@.str.1 = [6 x i8] c"local\00"
@RTLD_LOCAL = global i32 0
@.str.2 = [5 x i8] c"deep\00"
@RTLD_DEEPBIND = global i32 0
@.str.3 = [18 x i8] c"LOG_MEPINTA_ERROR\00"
@.str.4 = [177 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/joaduo/mepinta/refs/heads/master/backend/c_and_cpp/backend_api_c/load_unload_library.c\00"
@.str.5 = [52 x i8] c"Loading symbols in that '%s' way is not supported.\0A\00"
@.str.6 = [18 x i8] c"LOG_MEPINTA_DEBUG\00"
@.str.7 = [40 x i8] c"Loading %s with %s symbols. flag=0x%x.\0A\00"
@.str.8 = [50 x i8] c"Failed to load the requested library. Reason: %s\0A\00"
@.str.9 = [34 x i8] c"Path or symbol are NULL pointer.\0A\00"
define i8* @mepinta_load_library(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i32, i32* @RTLD_LAZY
store i32 %8, i32* %6
%9 = load i8*, i8** %4
%10 = icmp ne i8* %9, null
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = load i8*, i8** %5
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %61
14: ; preds = %11, %2
%15 = load i8*, i8** %5
%16 = call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %14
%19 = load i32, i32* %6
%20 = load i32, i32* @RTLD_GLOBAL
%21 = or i32 %19, %20
store i32 %21, i32* %6
br label %45
22: ; preds = %14
%23 = load i8*, i8** %5
%24 = call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %22
%27 = load i32, i32* %6
%28 = load i32, i32* @RTLD_LOCAL
%29 = or i32 %27, %28
store i32 %29, i32* %6
br label %44
30: ; preds = %22
%31 = load i8*, i8** %5
%32 = call i64 @strcmp(i8* %31, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %40
34: ; preds = %30
%35 = load i32, i32* %6
%36 = load i32, i32* @RTLD_GLOBAL
%37 = or i32 %35, %36
%38 = load i32, i32* @RTLD_DEEPBIND
%39 = or i32 %37, %38
store i32 %39, i32* %6
br label %43
40: ; preds = %30
%41 = load i8*, i8** %5
%42 = call i32 (i8*, i32, i8*, i32, i8*, ...) @MP_printLog(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 10, i8* getelementptr inbounds ([177 x i8], [177 x i8]* @.str.4, i64 0, i64 0), i32 60, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.5, i64 0, i64 0), i8* %41)
store i8* null, i8** %3
br label %63
43: ; preds = %34
br label %44
44: ; preds = %43, %26
br label %45
45: ; preds = %44, %18
%46 = load i8*, i8** %4
%47 = load i8*, i8** %5
%48 = load i32, i32* %6
%49 = call i32 (i8*, i32, i8*, i32, i8*, ...) @MP_printLog(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i32 50, i8* getelementptr inbounds ([177 x i8], [177 x i8]* @.str.4, i64 0, i64 0), i32 63, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.7, i64 0, i64 0), i8* %46, i8* %47, i32 %48)
%50 = call i32 (...) @dlerror()
%51 = load i8*, i8** %4
%52 = load i32, i32* %6
%53 = call i8* @dlopen(i8* %51, i32 %52)
store i8* %53, i8** %7
%54 = load i8*, i8** %7
%55 = icmp eq i8* %54, null
br i1 %55, label %56, label %59
56: ; preds = %45
%57 = call i32 (...) @dlerror()
%58 = call i32 (i8*, i32, i8*, i32, i8*, ...) @MP_printLog(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 10, i8* getelementptr inbounds ([177 x i8], [177 x i8]* @.str.4, i64 0, i64 0), i32 68, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.8, i64 0, i64 0), i32 %57)
br label %59
59: ; preds = %56, %45
%60 = load i8*, i8** %7
store i8* %60, i8** %3
br label %63
61: ; preds = %11
%62 = call i32 (i8*, i32, i8*, i32, i8*, ...) @MP_printLog(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 10, i8* getelementptr inbounds ([177 x i8], [177 x i8]* @.str.4, i64 0, i64 0), i32 73, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.9, i64 0, i64 0))
store i8* null, i8** %3
br label %63
63: ; preds = %61, %59, %40
%64 = load i8*, i8** %3
ret i8* %64
}

LLVM IR (-O2):
@RTLD_LAZY = global i32 0
@.str = [7 x i8] c"global\00"
@RTLD_GLOBAL = global i32 0
@.str.1 = [6 x i8] c"local\00"
@RTLD_LOCAL = global i32 0
@.str.2 = [5 x i8] c"deep\00"
@RTLD_DEEPBIND = global i32 0
@.str.3 = [18 x i8] c"LOG_MEPINTA_ERROR\00"
@.str.4 = [177 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/joaduo/mepinta/refs/heads/master/backend/c_and_cpp/backend_api_c/load_unload_library.c\00"
@.str.5 = [52 x i8] c"Loading symbols in that '%s' way is not supported.\0A\00"
@.str.6 = [18 x i8] c"LOG_MEPINTA_DEBUG\00"
@.str.7 = [40 x i8] c"Loading %s with %s symbols. flag=0x%x.\0A\00"
@.str.8 = [50 x i8] c"Failed to load the requested library. Reason: %s\0A\00"
@.str.9 = [34 x i8] c"Path or symbol are NULL pointer.\0A\00"
define i8* @mepinta_load_library(i8* %0, i8* %1) {
%3 = load i32, i32* @RTLD_LAZY
%4 = icmp ne i8* %0, null
%5 = icmp ne i8* %1, null
%6 = or i1 %4, %5
br i1 %6, label %7, label %37
7: ; preds = %2
%8 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = load i32, i32* @RTLD_GLOBAL
br label %26
12: ; preds = %7
%13 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = load i32, i32* @RTLD_LOCAL
br label %26
17: ; preds = %12
%18 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = load i32, i32* @RTLD_GLOBAL
%22 = or i32 %21, %3
%23 = load i32, i32* @RTLD_DEEPBIND
br label %26
24: ; preds = %17
%25 = tail call i32 (i8*, i32, i8*, i32, i8*, ...) @MP_printLog(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 10, i8* getelementptr inbounds ([177 x i8], [177 x i8]* @.str.4, i64 0, i64 0), i32 60, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.5, i64 0, i64 0), i8* %1)
br label %39
26: ; preds = %15, %20, %10
%27 = phi i32 [ %3, %15 ], [ %23, %20 ], [ %3, %10 ]
%28 = phi i32 [ %16, %15 ], [ %22, %20 ], [ %11, %10 ]
%29 = or i32 %28, %27
%30 = tail call i32 (i8*, i32, i8*, i32, i8*, ...) @MP_printLog(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i32 50, i8* getelementptr inbounds ([177 x i8], [177 x i8]* @.str.4, i64 0, i64 0), i32 63, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.7, i64 0, i64 0), i8* %0, i8* %1, i32 %29)
%31 = tail call i32 (...) @dlerror()
%32 = tail call i8* @dlopen(i8* %0, i32 %29)
%33 = icmp eq i8* %32, null
br i1 %33, label %34, label %39
34: ; preds = %26
%35 = tail call i32 (...) @dlerror()
%36 = tail call i32 (i8*, i32, i8*, i32, i8*, ...) @MP_printLog(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 10, i8* getelementptr inbounds ([177 x i8], [177 x i8]* @.str.4, i64 0, i64 0), i32 68, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.8, i64 0, i64 0), i32 %35)
br label %39
37: ; preds = %2
%38 = tail call i32 (i8*, i32, i8*, i32, i8*, ...) @MP_printLog(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 10, i8* getelementptr inbounds ([177 x i8], [177 x i8]* @.str.4, i64 0, i64 0), i32 73, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.9, i64 0, i64 0))
br label %39
39: ; preds = %26, %34, %37, %24
%40 = phi i8* [ null, %24 ], [ null, %37 ], [ null, %34 ], [ %32, %26 ]
ret i8* %40
}