#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 *, ...);
char *dlerror();
void *dlsym(void *, char const *);
void *mepinta_solve_symbol(const void *handle, const char *symbol) {
  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/solve_symbol.c",
              35, "Solving symbol '%s' for handle at %p\n", symbol, handle);
  if (handle != NULL && symbol != NULL) {
    dlerror();
    void *sym_p = dlsym((void *)handle, symbol);
    char *error_str = dlerror();
    if (error_str != 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/solve_symbol.c",
                  41, "Failed to find the requested symbol '%s'. Reason: %s.\n",
                  symbol, error_str);
    } else {
      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/solve_symbol.c",
                  44, "Successfully found the symbol at %p\n", sym_p);
    }
    return sym_p;
  } else {
    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/solve_symbol.c",
                  50,
                  "Failed to find the requested symbol for handle at %p. "
                  "Symbol is NULL.\n",
                  handle);
    } else if (symbol != 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/solve_symbol.c",
                  53,
                  "Failed to find the requested symbol '%s'. Handle is NULL.\n",
                  symbol);
    } 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/solve_symbol.c",
          56,
          "Failed to find the requested symbol. Handle and symbol are NULL.\n");
    }
    return NULL;
  }
}


x86 assembly (clang, -O0):
<mepinta_solve_symbol>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%r9
mov    -0x10(%rbp),%rax
lea    0xeb1(%rip),%rdi
mov    $0x32,%esi
lea    0xeb7(%rip),%rdx
mov    $0x23,%ecx
lea    0xf55(%rip),%r8
mov    %rax,(%rsp)
mov    $0x0,%al
call   1040 <MP_printLog@plt>
cmpq   $0x0,-0x10(%rbp)
je     1224 <mepinta_solve_symbol+0xf4>
cmpq   $0x0,-0x18(%rbp)
je     1224 <mepinta_solve_symbol+0xf4>
mov    $0x0,%al
call   1030 <dlerror@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <dlsym@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <dlerror@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11ed <mepinta_solve_symbol+0xbd>
mov    -0x18(%rbp),%r9
mov    -0x28(%rbp),%rax
lea    0xf1d(%rip),%rdi
mov    $0xa,%esi
lea    0xe41(%rip),%rdx
mov    $0x29,%ecx
lea    0xf17(%rip),%r8
mov    %rax,(%rsp)
mov    $0x0,%al
call   1040 <MP_printLog@plt>
jmp    1217 <mepinta_solve_symbol+0xe7>
mov    -0x20(%rbp),%r9
lea    0xe08(%rip),%rdi
mov    $0x32,%esi
lea    0xe0e(%rip),%rdx
mov    $0x2c,%ecx
lea    0xf1b(%rip),%r8
mov    $0x0,%al
call   1040 <MP_printLog@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12cb <mepinta_solve_symbol+0x19b>
cmpq   $0x0,-0x10(%rbp)
je     125e <mepinta_solve_symbol+0x12e>
mov    -0x10(%rbp),%r9
lea    0xea8(%rip),%rdi
mov    $0xa,%esi
lea    0xdcc(%rip),%rdx
mov    $0x32,%ecx
lea    0xefe(%rip),%r8
mov    $0x0,%al
call   1040 <MP_printLog@plt>
jmp    12c3 <mepinta_solve_symbol+0x193>
cmpq   $0x0,-0x18(%rbp)
je     1298 <mepinta_solve_symbol+0x168>
mov    -0x18(%rbp),%r9
lea    0xe6e(%rip),%rdi
mov    $0xa,%esi
lea    0xd92(%rip),%rdx
mov    $0x35,%ecx
lea    0xf0b(%rip),%r8
mov    $0x0,%al
call   1040 <MP_printLog@plt>
jmp    12be <mepinta_solve_symbol+0x18e>
lea    0xe43(%rip),%rdi
mov    $0xa,%esi
lea    0xd67(%rip),%rdx
mov    $0x38,%ecx
lea    0xf1b(%rip),%r8
mov    $0x0,%al
call   1040 <MP_printLog@plt>
jmp    12c3 <mepinta_solve_symbol+0x193>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mepinta_solve_symbol>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %rdi,(%rsp)
lea    0xeb6(%rip),%rdi
lea    0xec1(%rip),%rdx
lea    0xf64(%rip),%r8
mov    $0x32,%esi
mov    $0x23,%ecx
mov    %r15,%r9
xor    %eax,%eax
call   1040 <MP_printLog@plt>
test   %rbx,%rbx
je     11bc <mepinta_solve_symbol+0x8c>
test   %r15,%r15
je     11bc <mepinta_solve_symbol+0x8c>
xor    %eax,%eax
call   1030 <dlerror@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <dlsym@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1030 <dlerror@plt>
test   %rax,%rax
je     11e8 <mepinta_solve_symbol+0xb8>
mov    %rax,(%rsp)
lea    0xf40(%rip),%rdi
lea    0xe69(%rip),%rdx
lea    0xf44(%rip),%r8
mov    $0xa,%esi
mov    $0x29,%ecx
jmp    1225 <mepinta_solve_symbol+0xf5>
lea    0xf1f(%rip),%rdi
lea    0xe48(%rip),%rdx
test   %rbx,%rbx
je     120c <mepinta_solve_symbol+0xdc>
lea    0xf7a(%rip),%r8
xor    %r14d,%r14d
mov    $0xa,%esi
mov    $0x32,%ecx
mov    %rbx,%r9
jmp    1228 <mepinta_solve_symbol+0xf8>
lea    0xe11(%rip),%rdi
lea    0xe1c(%rip),%rdx
lea    0xf2e(%rip),%r8
mov    $0x32,%esi
mov    $0x2c,%ecx
mov    %r14,%r9
jmp    1228 <mepinta_solve_symbol+0xf8>
test   %r15,%r15
je     123c <mepinta_solve_symbol+0x10c>
lea    0xf7f(%rip),%r8
xor    %r14d,%r14d
mov    $0xa,%esi
mov    $0x35,%ecx
mov    %r15,%r9
xor    %eax,%eax
call   1040 <MP_printLog@plt>
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xf8f(%rip),%r8
xor    %r14d,%r14d
mov    $0xa,%esi
mov    $0x38,%ecx
xor    %eax,%eax
call   1040 <MP_printLog@plt>
jmp    122f <mepinta_solve_symbol+0xff>

LLVM IR (-O0):
@.str = [18 x i8] c"LOG_MEPINTA_DEBUG\00"
@.str.1 = [170 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/solve_symbol.c\00"
@.str.2 = [38 x i8] c"Solving symbol '%s' for handle at %p\0A\00"
@.str.3 = [18 x i8] c"LOG_MEPINTA_ERROR\00"
@.str.4 = [55 x i8] c"Failed to find the requested symbol '%s'. Reason: %s.\0A\00"
@.str.5 = [37 x i8] c"Successfully found the symbol at %p\0A\00"
@.str.6 = [71 x i8] c"Failed to find the requested symbol for handle at %p. Symbol is NULL.\0A\00"
@.str.7 = [59 x i8] c"Failed to find the requested symbol '%s'. Handle is NULL.\0A\00"
@.str.8 = [66 x i8] c"Failed to find the requested symbol. Handle and symbol are NULL.\0A\00"
define i8* @mepinta_solve_symbol(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %5
%9 = load i8*, i8** %4
%10 = call i32 (i8*, i32, i8*, i32, i8*, ...) @MP_printLog(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 50, i8* getelementptr inbounds ([170 x i8], [170 x i8]* @.str.1, i64 0, i64 0), i32 35, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* %8, i8* %9)
%11 = load i8*, i8** %4
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %33
13: ; preds = %2
%14 = load i8*, i8** %5
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %33
16: ; preds = %13
%17 = call i8* (...) @dlerror()
%18 = load i8*, i8** %4
%19 = load i8*, i8** %5
%20 = call i8* @dlsym(i8* %18, i8* %19)
store i8* %20, i8** %6
%21 = call i8* (...) @dlerror()
store i8* %21, i8** %7
%22 = load i8*, i8** %7
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %28
24: ; preds = %16
%25 = load i8*, i8** %5
%26 = load i8*, i8** %7
%27 = 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 ([170 x i8], [170 x i8]* @.str.1, i64 0, i64 0), i32 41, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.4, i64 0, i64 0), i8* %25, i8* %26)
br label %31
28: ; preds = %16
%29 = load i8*, i8** %6
%30 = call i32 (i8*, i32, i8*, i32, i8*, ...) @MP_printLog(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 50, i8* getelementptr inbounds ([170 x i8], [170 x i8]* @.str.1, i64 0, i64 0), i32 44, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i8* %29)
br label %31
31: ; preds = %28, %24
%32 = load i8*, i8** %6
store i8* %32, i8** %3
br label %49
33: ; preds = %13, %2
%34 = load i8*, i8** %4
%35 = icmp ne i8* %34, null
br i1 %35, label %36, label %39
36: ; preds = %33
%37 = load i8*, i8** %4
%38 = 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 ([170 x i8], [170 x i8]* @.str.1, i64 0, i64 0), i32 50, i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.6, i64 0, i64 0), i8* %37)
br label %48
39: ; preds = %33
%40 = load i8*, i8** %5
%41 = icmp ne i8* %40, null
br i1 %41, label %42, label %45
42: ; preds = %39
%43 = load i8*, i8** %5
%44 = 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 ([170 x i8], [170 x i8]* @.str.1, i64 0, i64 0), i32 53, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.7, i64 0, i64 0), i8* %43)
br label %47
45: ; preds = %39
%46 = 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 ([170 x i8], [170 x i8]* @.str.1, i64 0, i64 0), i32 56, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.8, i64 0, i64 0))
br label %47
47: ; preds = %45, %42
br label %48
48: ; preds = %47, %36
store i8* null, i8** %3
br label %49
49: ; preds = %48, %31
%50 = load i8*, i8** %3
ret i8* %50
}

LLVM IR (-O2):
@.str = [18 x i8] c"LOG_MEPINTA_DEBUG\00"
@.str.1 = [170 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/solve_symbol.c\00"
@.str.2 = [38 x i8] c"Solving symbol '%s' for handle at %p\0A\00"
@.str.3 = [18 x i8] c"LOG_MEPINTA_ERROR\00"
@.str.4 = [55 x i8] c"Failed to find the requested symbol '%s'. Reason: %s.\0A\00"
@.str.5 = [37 x i8] c"Successfully found the symbol at %p\0A\00"
@.str.6 = [71 x i8] c"Failed to find the requested symbol for handle at %p. Symbol is NULL.\0A\00"
@.str.7 = [59 x i8] c"Failed to find the requested symbol '%s'. Handle is NULL.\0A\00"
@.str.8 = [66 x i8] c"Failed to find the requested symbol. Handle and symbol are NULL.\0A\00"
define i8* @mepinta_solve_symbol(i8* %0, i8* %1) {
%3 = tail call i32 (i8*, i32, i8*, i32, i8*, ...) @MP_printLog(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 50, i8* getelementptr inbounds ([170 x i8], [170 x i8]* @.str.1, i64 0, i64 0), i32 35, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* %1, i8* %0)
%4 = icmp ne i8* %0, null
%5 = icmp ne i8* %1, null
%6 = and i1 %4, %5
br i1 %6, label %7, label %16
7: ; preds = %2
%8 = tail call i8* (...) @dlerror()
%9 = tail call i8* @dlsym(i8* %0, i8* %1)
%10 = tail call i8* (...) @dlerror()
%11 = icmp eq i8* %10, null
br i1 %11, label %14, label %12
12: ; preds = %7
%13 = 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 ([170 x i8], [170 x i8]* @.str.1, i64 0, i64 0), i32 41, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.4, i64 0, i64 0), i8* %1, i8* %10)
br label %24
14: ; preds = %7
%15 = tail call i32 (i8*, i32, i8*, i32, i8*, ...) @MP_printLog(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 50, i8* getelementptr inbounds ([170 x i8], [170 x i8]* @.str.1, i64 0, i64 0), i32 44, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i8* %9)
br label %24
16: ; preds = %2
br i1 %4, label %17, label %19
17: ; preds = %16
%18 = 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 ([170 x i8], [170 x i8]* @.str.1, i64 0, i64 0), i32 50, i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.6, i64 0, i64 0), i8* %0)
br label %24
19: ; preds = %16
br i1 %5, label %20, label %22
20: ; preds = %19
%21 = 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 ([170 x i8], [170 x i8]* @.str.1, i64 0, i64 0), i32 53, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.7, i64 0, i64 0), i8* %1)
br label %24
22: ; preds = %19
%23 = 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 ([170 x i8], [170 x i8]* @.str.1, i64 0, i64 0), i32 56, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.8, i64 0, i64 0))
br label %24
24: ; preds = %17, %22, %20, %12, %14
%25 = phi i8* [ %9, %14 ], [ %9, %12 ], [ null, %20 ], [ null, %22 ], [ null, %17 ]
ret i8* %25
}