// File: 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
movq %rsp, %rbp
subq $0x330, %rsp            # imm = 0x330
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rsi
leaq 0x11e606(%rip), %rdi    # 0x1e60f8
callq 0xc9b40
movq %rax, -0x20(%rbp)
leaq 0x11e5f6(%rip), %rdi    # 0x1e60f8
callq 0xc9b70
movq %rax, -0x28(%rbp)
leaq -0x20(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0xc9b10
testb $0x1, %al
jne 0xc7b21
jmp 0xc81fc
movq -0x10(%rbp), %rsi
leaq 0x8b727(%rip), %rdx     # 0x153253
leaq -0x48(%rbp), %rdi
movq %rdi, -0x280(%rbp)
callq 0x24ec0
movq -0x280(%rbp), %rdx
movq -0x8(%rbp), %rsi
movq -0x18(%rbp), %rcx
leaq -0x98(%rbp), %rdi
callq 0xc75a0
jmp 0xc7b59
leaq -0x70(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x2d3f0
jmp 0xc7b6b
leaq -0x70(%rbp), %rdi
callq 0x11230
movq %rax, %rdi
movl $0x1, %esi
callq 0x117d0
movq %rax, -0x288(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x11360
leaq -0x98(%rbp), %rdi
callq 0x24b40
movq -0x288(%rbp), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0xc7e6d
leaq -0xc0(%rbp), %rdi
callq 0x24b80
movb $0x1, -0x15a(%rbp)
movl $0xa8, %edi
callq 0x112b0
movq %rax, -0x298(%rbp)
leaq -0x101(%rbp), %rdi
movq %rdi, -0x290(%rbp)
callq 0x119d0
movq -0x290(%rbp), %rdx
leaq 0x8b65f(%rip), %rsi     # 0x153257
leaq -0x100(%rbp), %rdi
callq 0x24740
jmp 0xc7c06
leaq -0x150(%rbp), %rdi
movq %rdi, -0x158(%rbp)
leaq -0x48(%rbp), %rsi
callq 0x11250
jmp 0xc7c1f
leaq -0x150(%rbp), %rax
movq %rax, -0x130(%rbp)
movq $0x1, -0x128(%rbp)
leaq -0x159(%rbp), %rdi
movq %rdi, -0x2a0(%rbp)
callq 0x26e30
movq -0x2a0(%rbp), %rcx
movq -0x130(%rbp), %rsi
movq -0x128(%rbp), %rdx
leaq -0x120(%rbp), %rdi
callq 0x2d6a0
jmp 0xc7c6e
leaq -0xe0(%rbp), %rdi
leaq -0x100(%rbp), %rsi
leaq -0x120(%rbp), %rdx
callq 0x9e250
jmp 0xc7c8a
movq -0x298(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq -0xe0(%rbp), %rsi
leaq -0xc0(%rbp), %rcx
callq 0x9c360
jmp 0xc7caa
movq -0x298(%rbp), %rdi
movb $0x0, -0x15a(%rbp)
leaq 0x118fc1(%rip), %rsi    # 0x1e0c80
leaq -0x6d326(%rip), %rdx    # 0x5a9a0
callq 0x11970
jmp 0xc8211
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0xc81f1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x24b40
jmp 0xc81f1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0xc7e39
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
movq -0x158(%rbp), %rax
leaq -0x150(%rbp), %rcx
cmpq %rax, %rcx
movq %rax, -0x2a8(%rbp)
je 0xc7d7e
movq -0x2a8(%rbp), %rdi
addq $-0x20, %rdi
movq %rdi, -0x2b0(%rbp)
callq 0x11360
movq -0x2b0(%rbp), %rax
leaq -0x150(%rbp), %rcx
cmpq %rcx, %rax
movq %rax, -0x2a8(%rbp)
jne 0xc7d4d
jmp 0xc7e2d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0xc7dd5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0xc7dc9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x11360
leaq -0x120(%rbp), %rdi
callq 0x25b00
leaq -0x159(%rbp), %rdi
callq 0x279c0
leaq -0x150(%rbp), %rax
movq %rax, -0x2c0(%rbp)
addq $0x20, %rax
movq %rax, -0x2b8(%rbp)
movq -0x2b8(%rbp), %rdi
addq $-0x20, %rdi
movq %rdi, -0x2c8(%rbp)
callq 0x11360
movq -0x2c0(%rbp), %rcx
movq -0x2c8(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x2b8(%rbp)
jne 0xc7dfa
jmp 0xc7e2d
leaq -0x100(%rbp), %rdi
callq 0x11360
leaq -0x101(%rbp), %rdi
callq 0x11600
testb $0x1, -0x15a(%rbp)
jne 0xc7e50
jmp 0xc7e5c
movq -0x298(%rbp), %rdi
callq 0x11420
leaq -0xc0(%rbp), %rdi
callq 0x24e60
jmp 0xc81f1
movq -0x50(%rbp), %rax
movq %rax, -0x2d0(%rbp)
movq -0x10(%rbp), %rsi
leaq 0x8b3fb(%rip), %rdx     # 0x15327e
leaq -0x188(%rbp), %rdi
callq 0x24ec0
jmp 0xc7e91
leaq -0x188(%rbp), %rdi
callq 0x11230
movq -0x2d0(%rbp), %rdi
movq %rax, %rsi
callq 0x11520
movq %rax, -0x2d8(%rbp)
leaq -0x188(%rbp), %rdi
callq 0x11360
movq -0x2d8(%rbp), %rax
movq %rax, -0x168(%rbp)
cmpq $0x0, -0x168(%rbp)
jne 0xc815b
leaq -0x1a0(%rbp), %rdi
callq 0x24b80
movb $0x1, -0x23a(%rbp)
movl $0xa8, %edi
callq 0x112b0
movq %rax, -0x2e8(%rbp)
leaq -0x1e1(%rbp), %rdi
movq %rdi, -0x2e0(%rbp)
callq 0x119d0
movq -0x2e0(%rbp), %rdx
leaq 0x8b374(%rip), %rsi     # 0x153294
leaq -0x1e0(%rbp), %rdi
callq 0x24740
jmp 0xc7f2e
leaq -0x230(%rbp), %rdi
movq %rdi, -0x238(%rbp)
leaq -0x48(%rbp), %rsi
callq 0x11250
jmp 0xc7f47
leaq -0x230(%rbp), %rax
movq %rax, -0x210(%rbp)
movq $0x1, -0x208(%rbp)
leaq -0x239(%rbp), %rdi
movq %rdi, -0x2f0(%rbp)
callq 0x26e30
movq -0x2f0(%rbp), %rcx
movq -0x210(%rbp), %rsi
movq -0x208(%rbp), %rdx
leaq -0x200(%rbp), %rdi
callq 0x2d6a0
jmp 0xc7f96
leaq -0x1c0(%rbp), %rdi
leaq -0x1e0(%rbp), %rsi
leaq -0x200(%rbp), %rdx
callq 0x9e250
jmp 0xc7fb2
movq -0x2e8(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq -0x1c0(%rbp), %rsi
leaq -0x1a0(%rbp), %rcx
callq 0x9c360
jmp 0xc7fd2
movq -0x2e8(%rbp), %rdi
movb $0x0, -0x23a(%rbp)
leaq 0x118c99(%rip), %rsi    # 0x1e0c80
leaq -0x6d64e(%rip), %rdx    # 0x5a9a0
callq 0x11970
jmp 0xc8211
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0xc8127
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
movq -0x238(%rbp), %rax
leaq -0x230(%rbp), %rcx
cmpq %rax, %rcx
movq %rax, -0x2f8(%rbp)
je 0xc806c
movq -0x2f8(%rbp), %rdi
addq $-0x20, %rdi
movq %rdi, -0x300(%rbp)
callq 0x11360
movq -0x300(%rbp), %rax
leaq -0x230(%rbp), %rcx
cmpq %rcx, %rax
movq %rax, -0x2f8(%rbp)
jne 0xc803b
jmp 0xc811b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0xc80c3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0xc80b7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x1c0(%rbp), %rdi
callq 0x11360
leaq -0x200(%rbp), %rdi
callq 0x25b00
leaq -0x239(%rbp), %rdi
callq 0x279c0
leaq -0x230(%rbp), %rax
movq %rax, -0x310(%rbp)
addq $0x20, %rax
movq %rax, -0x308(%rbp)
movq -0x308(%rbp), %rdi
addq $-0x20, %rdi
movq %rdi, -0x318(%rbp)
callq 0x11360
movq -0x310(%rbp), %rcx
movq -0x318(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x308(%rbp)
jne 0xc80e8
jmp 0xc811b
leaq -0x1e0(%rbp), %rdi
callq 0x11360
leaq -0x1e1(%rbp), %rdi
callq 0x11600
testb $0x1, -0x23a(%rbp)
jne 0xc813e
jmp 0xc814a
movq -0x2e8(%rbp), %rdi
callq 0x11420
leaq -0x1a0(%rbp), %rdi
callq 0x24e60
jmp 0xc81f1
leaq -0x270(%rbp), %rdi
movq %rdi, -0x320(%rbp)
callq 0xc9ba0
movq -0x320(%rbp), %rdi
movq -0x168(%rbp), %rax
movq %rax, -0x278(%rbp)
movq -0x278(%rbp), %rax
callq *%rax
jmp 0xc818e
movq -0x10(%rbp), %rsi
leaq 0x11df5f(%rip), %rdi    # 0x1e60f8
callq 0xc9bc0
movq %rax, -0x328(%rbp)
jmp 0xc81a7
movq -0x328(%rbp), %rdi
leaq -0x270(%rbp), %rsi
callq 0xc9ca0
jmp 0xc81bc
leaq -0x270(%rbp), %rdi
callq 0xc9cd0
leaq -0x48(%rbp), %rdi
callq 0x11360
jmp 0xc81fc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x270(%rbp), %rdi
callq 0xc9cd0
leaq -0x48(%rbp), %rdi
callq 0x11360
jmp 0xc8205
addq $0x330, %rsp            # imm = 0x330
popq %rbp
retq
movq -0xa0(%rbp), %rdi
callq 0x119c0
nopw %cs:(%rax,%rax)