// File: /workspace/github_cpp_makefile_star2_O3/Nallantli[P]Rossa/main/rossa/global/global.cpp
// Function: global::loadLibrary(std::filesystem::__cxx11::path const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, token_t const*)
void global::loadLibrary(const std::filesystem::path &currentDir, const std::string &rawlibname, const token_t *token)
{
	if (loaded.find(rawlibname) == loaded.end())
	{
#ifndef _WIN32
		std::string libname = rawlibname + ".so";
		auto library = dlopen(dir::findFile(currentDir, libname, token).string().c_str(), RTLD_LAZY);
		if (library == NULL)
		{
			trace_t stack_trace;
			throw rossa_error_t(util::format(_EXTERNAL_LIBRARY_NOT_EXIST_, {libname}), *token, stack_trace);
		}
		auto f = dlsym(library, (rawlibname + "_rossaExportFunctions").c_str());
#else
		std::string libname = rawlibname + ".dll";
		auto path = dir::findFile(currentDir, libname, token);
		auto library = LoadLibraryA(path.string().c_str());
		if (library == NULL)
		{
			trace_t stack_trace;
			throw rossa_error_t(util::format(_EXTERNAL_LIBRARY_NOT_EXIST_, {libname}), *token, stack_trace);
		}
		auto f = GetProcAddress(library, (rawlibname + "_rossaExportFunctions").c_str());
#endif
		if (f == NULL)
		{
			trace_t stack_trace;
			throw rossa_error_t(util::format(_EXPORT_FUNCTION_NOT_FOUND_, {libname}), *token, stack_trace);
		}
		std::map<std::string, extf_t> fns;
		auto ef = (export_fns_t)f;
		ef(fns);
		loaded[rawlibname] = fns;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
leaq 0x5fc68(%rip), %r12     # 0xb5f58
movq %r12, %rdi
callq 0x57f70
addq $0x8, %r12
cmpq %r12, %rax
jne 0x56466
leaq 0x70(%rsp), %r13
movq %r13, -0x10(%r13)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq 0x60(%rsp), %r12
movq %r12, %rdi
callq 0x1ded4
leaq 0x2f54f(%rip), %rsi     # 0x8587b
movq %r12, %rdi
callq 0x10770
leaq 0x10(%rsp), %rdi
leaq 0x60(%rsp), %rdx
movq %r15, %rsi
movq %rbx, %rcx
callq 0x55f7c
movq 0x10(%rsp), %rsi
leaq 0x50(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x18(%rsp), %rdx
addq %rsi, %rdx
leaq 0x40(%rsp), %rdi
callq 0x1e698
movq 0x40(%rsp), %rdi
movl $0x1, %esi
callq 0x10550
movq %rax, %r15
movq 0x40(%rsp), %rdi
cmpq %r12, %rdi
je 0x56393
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x103d0
leaq 0x10(%rsp), %rdi
callq 0x1d5ee
testq %r15, %r15
je 0x56478
leaq 0x20(%rsp), %rbp
movq %rbp, -0x10(%rbp)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq 0x10(%rsp), %rdi
callq 0x1ded4
leaq 0x2f4dc(%rip), %rsi     # 0x858a6
leaq 0x10(%rsp), %rdi
callq 0x10770
movq 0x10(%rsp), %rsi
movq %r15, %rdi
callq 0x10390
movq %rax, %r15
movq 0x10(%rsp), %rdi
cmpq %rbp, %rdi
je 0x563fb
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x103d0
testq %r15, %r15
je 0x5654b
leaq 0x18(%rsp), %rax
movl $0x0, (%rax)
xorl %ecx, %ecx
movq %rcx, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
movq %rcx, 0x20(%rax)
leaq 0x10(%rsp), %rdi
callq *%r15
leaq 0x5fb28(%rip), %rdi     # 0xb5f58
movq %r14, %rsi
callq 0x57826
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
callq 0x57b40
leaq 0x10(%rsp), %rdi
callq 0x57ed4
movq 0x60(%rsp), %rdi
cmpq %r13, %rdi
je 0x56466
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x103d0
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorps %xmm0, %xmm0
movaps %xmm0, 0xa0(%rsp)
movq $0x0, 0xb0(%rsp)
movl $0xa8, %edi
callq 0x101e0
movq %rax, %r14
leaq 0x40(%rsp), %rdi
movq %r12, (%rdi)
leaq 0x2f3d4(%rip), %rsi     # 0x8587f
leaq 0x2f3f3(%rip), %rdx     # 0x858a5
callq 0x1e698
leaq 0x90(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rdx
addq %rsi, %rdx
leaq 0x80(%rsp), %rdi
callq 0x1ded4
leaq 0xc0(%rsp), %rdi
leaq 0x80(%rsp), %rsi
leaq 0xf(%rsp), %rcx
movl $0x1, %edx
callq 0x20b38
leaq 0x10(%rsp), %rdi
leaq 0x40(%rsp), %rsi
leaq 0xc0(%rsp), %rdx
callq 0x47db4
movb $0x1, %bpl
leaq 0x10(%rsp), %rsi
leaq 0xa0(%rsp), %rcx
movq %r14, %rdi
movq %rbx, %rdx
callq 0x46e88
xorl %ebp, %ebp
leaq 0x5a7e9(%rip), %rsi     # 0xb0d20
leaq -0x1f29a(%rip), %rdx    # 0x372a4
movq %r14, %rdi
callq 0x106d0
jmp 0x5661a
xorps %xmm0, %xmm0
movaps %xmm0, 0xa0(%rsp)
movq $0x0, 0xb0(%rsp)
movl $0xa8, %edi
callq 0x101e0
movq %rax, %r14
leaq 0x40(%rsp), %rdi
movq %r12, (%rdi)
leaq 0x2f33e(%rip), %rsi     # 0x858bc
leaq 0x2f361(%rip), %rdx     # 0x858e6
callq 0x1e698
leaq 0x90(%rsp), %rax
movq %rax, -0x10(%rax)
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rdx
addq %rsi, %rdx
leaq 0x80(%rsp), %rdi
callq 0x1ded4
leaq 0xc0(%rsp), %rdi
leaq 0x80(%rsp), %rsi
leaq 0xf(%rsp), %rcx
movl $0x1, %edx
callq 0x20b38
leaq 0x10(%rsp), %rdi
leaq 0x40(%rsp), %rsi
leaq 0xc0(%rsp), %rdx
callq 0x47db4
movb $0x1, %r15b
leaq 0x10(%rsp), %rsi
leaq 0xa0(%rsp), %rcx
movq %r14, %rdi
movq %rbx, %rdx
callq 0x46e88
xorl %r15d, %r15d
leaq 0x5a715(%rip), %rsi     # 0xb0d20
leaq -0x1f36e(%rip), %rdx    # 0x372a4
movq %r14, %rdi
callq 0x106d0
movq %rax, %rbx
movq 0x10(%rsp), %rdi
cmpq %rbp, %rdi
je 0x5663c
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x103d0
jmp 0x5663c
movq %rax, %rbx
movb $0x1, %r15b
leaq 0xc0(%rsp), %rdi
callq 0x1db60
jmp 0x56686
movq %rax, %rbx
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x56671
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x103d0
jmp 0x56671
movq %rax, %rbx
movb $0x1, %bpl
leaq 0xc0(%rsp), %rdi
callq 0x1db60
jmp 0x566cf
movq %rax, %rbx
movb $0x1, %r15b
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x566ab
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x103d0
movq 0x40(%rsp), %rdi
cmpq %r12, %rdi
je 0x566c2
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x103d0
testb %r15b, %r15b
jne 0x5672d
jmp 0x56735
movq %rax, %rbx
movb $0x1, %bpl
movq 0x80(%rsp), %rdi
cmpq %r15, %rdi
je 0x566ec
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x103d0
movq 0x40(%rsp), %rdi
cmpq %r12, %rdi
je 0x56703
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x103d0
testb %bpl, %bpl
jne 0x5672d
jmp 0x56735
jmp 0x5670c
movq %rax, %rbx
movq 0x40(%rsp), %rdi
cmpq %r12, %rdi
je 0x5672d
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x103d0
jmp 0x5672d
jmp 0x5672a
movq %rax, %rbx
movq %r14, %rdi
callq 0x102d0
leaq 0xa0(%rsp), %rdi
callq 0x1d632
jmp 0x56785
movq %rax, %rbx
movq 0x10(%rsp), %rdi
cmpq %rbp, %rdi
je 0x56785
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x103d0
jmp 0x56785
jmp 0x56773
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x1d5ee
jmp 0x56785
jmp 0x56773
movq %rax, %rbx
jmp 0x56785
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x57ed4
movq 0x60(%rsp), %rdi
cmpq %r13, %rdi
je 0x5679c
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x103d0
movq %rbx, %rdi
callq 0x106f0