#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 EXIT_FAILURE;
int /*<<< orphan*/ MP_printLog(char *, int, char *, int, char *, ...);
int dlclose(void *);
int /*<<< orphan*/ dlerror();
int mepinta_unload_library(void *handle) {
  dlerror();
  if (handle != NULL) {
    int rtrn_v = dlclose(handle);
    if (rtrn_v != 0) {
      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",
          83, "Failed to unload the requested library. Reason: %s\n",
          dlerror());
    }
    return rtrn_v;
  } 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",
        88,
        "Failed to unload the requested library. Handle is a NULL pointer.\n");
    return EXIT_FAILURE;
  }
}


x86 assembly (clang, -O0):
<mepinta_unload_library>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1030 <dlerror@plt>
cmpq   $0x0,-0x10(%rbp)
je     119f <mepinta_unload_library+0x6f>
mov    -0x10(%rbp),%rdi
call   1050 <dlclose@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1194 <mepinta_unload_library+0x64>
mov    $0x0,%al
call   1030 <dlerror@plt>
mov    %eax,%r9d
lea    0xe8b(%rip),%rdi
mov    $0xa,%esi
lea    0xe91(%rip),%rdx
mov    $0x53,%ecx
lea    0xf36(%rip),%r8
mov    $0x0,%al
call   1040 <MP_printLog@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d1 <mepinta_unload_library+0xa1>
lea    0xe5a(%rip),%rdi
mov    $0xa,%esi
lea    0xe60(%rip),%rdx
mov    $0x58,%ecx
lea    0xf39(%rip),%r8
mov    $0x0,%al
call   1040 <MP_printLog@plt>
mov    0x2e14(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mepinta_unload_library>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <dlerror@plt>
test   %rbx,%rbx
je     1186 <mepinta_unload_library+0x56>
mov    %rbx,%rdi
call   1050 <dlclose@plt>
test   %eax,%eax
je     11b5 <mepinta_unload_library+0x85>
mov    %eax,%ebx
xor    %eax,%eax
call   1030 <dlerror@plt>
lea    0xea0(%rip),%rdi
lea    0xeab(%rip),%rdx
lea    0xf55(%rip),%r8
mov    $0xa,%esi
mov    $0x53,%ecx
mov    %eax,%r9d
xor    %eax,%eax
call   1040 <MP_printLog@plt>
mov    %ebx,%ebp
jmp    11b5 <mepinta_unload_library+0x85>
lea    0xe73(%rip),%rdi
lea    0xe7e(%rip),%rdx
lea    0xf5c(%rip),%r8
mov    $0xa,%esi
mov    $0x58,%ecx
xor    %eax,%eax
call   1040 <MP_printLog@plt>
mov    0x2e2d(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"LOG_MEPINTA_ERROR\00"
@.str.1 = [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.2 = [52 x i8] c"Failed to unload the requested library. Reason: %s\0A\00"
@.str.3 = [67 x i8] c"Failed to unload the requested library. Handle is a NULL pointer.\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @mepinta_unload_library(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = call i32 (...) @dlerror()
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %18
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = call i32 @dlclose(i8* %9)
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = call i32 (...) @dlerror()
%15 = call i32 (i8*, i32, i8*, i32, i8*, ...) @MP_printLog(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 10, i8* getelementptr inbounds ([177 x i8], [177 x i8]* @.str.1, i64 0, i64 0), i32 83, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0), i32 %14)
br label %16
16: ; preds = %13, %8
%17 = load i32, i32* %4
store i32 %17, i32* %2
br label %21
18: ; preds = %1
%19 = call i32 (i8*, i32, i8*, i32, i8*, ...) @MP_printLog(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 10, i8* getelementptr inbounds ([177 x i8], [177 x i8]* @.str.1, i64 0, i64 0), i32 88, i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.3, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
store i32 %20, i32* %2
br label %21
21: ; preds = %18, %16
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
@.str = [18 x i8] c"LOG_MEPINTA_ERROR\00"
@.str.1 = [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.2 = [52 x i8] c"Failed to unload the requested library. Reason: %s\0A\00"
@.str.3 = [67 x i8] c"Failed to unload the requested library. Handle is a NULL pointer.\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @mepinta_unload_library(i8* %0) {
%2 = tail call i32 (...) @dlerror()
%3 = icmp eq i8* %0, null
br i1 %3, label %10, label %4
4: ; preds = %1
%5 = tail call i32 @dlclose(i8* %0)
%6 = icmp eq i32 %5, 0
br i1 %6, label %13, label %7
7: ; preds = %4
%8 = tail call i32 (...) @dlerror()
%9 = 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 10, i8* getelementptr inbounds ([177 x i8], [177 x i8]* @.str.1, i64 0, i64 0), i32 83, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0), i32 %8)
br label %13
10: ; preds = %1
%11 = 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 10, i8* getelementptr inbounds ([177 x i8], [177 x i8]* @.str.1, i64 0, i64 0), i32 88, i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.3, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
br label %13
13: ; preds = %4, %7, %10
%14 = phi i32 [ %12, %10 ], [ %5, %7 ], [ 0, %4 ]
ret i32 %14
}