// File: /workspace/github_c_makefile_star2_O1/aremmell[P]libsir/src/sirplugins.c
// Function: sir_plugin_probe
sirpluginid _sir_plugin_probe(sir_plugin* plugin) {
#if !defined(SIR_NO_PLUGINS)
    sirpluginid retval = 0U;
    if (plugin) {
# if SIR_PLUGIN_VCURRENT == SIR_PLUGIN_V1
       /* if/when new versions of plugin interfaces are introduced, we will need to
        * modify/extend the following code:
        *
        * - remove the enclosing #if
        * - get the v1 exports (all versions will have v1 exports), resolve them,
        * and call sir_plugin_query.
        * - switch on version returned to resolve additional exports. this will
        * necessitate additional versioned interface structures as members of the
        * sir_plugin struct, e.g. ifacev1, ifacev2). */
        plugin->iface.query   = (sir_plugin_queryfn)
            _sir_plugin_getexport(plugin->handle, SIR_PLUGIN_EXPORT_QUERY);
        plugin->iface.init    = (sir_plugin_initfn)
            _sir_plugin_getexport(plugin->handle, SIR_PLUGIN_EXPORT_INIT);
        plugin->iface.write   = (sir_plugin_writefn)
            _sir_plugin_getexport(plugin->handle, SIR_PLUGIN_EXPORT_WRITE);
        plugin->iface.cleanup = (sir_plugin_cleanupfn)
            _sir_plugin_getexport(plugin->handle, SIR_PLUGIN_EXPORT_CLEANUP);

        if (!plugin->iface.query || !plugin->iface.init ||
            !plugin->iface.write || !plugin->iface.cleanup) {
            _sir_selflog("error: export(s) not resolved for plugin (path:"
                         " '%s', addr: %p)!", plugin->path, plugin->handle);
            _sir_selflog("exports (query: %"PRIxPTR", init: %"PRIxPTR", write:"
                         " %"PRIxPTR", cleanup; %"PRIxPTR")",
                         (uintptr_t)plugin->iface.query, (uintptr_t)plugin->iface.init,
                         (uintptr_t)plugin->iface.write, (uintptr_t)plugin->iface.cleanup);
            _sir_plugin_destroy(&plugin);
            return _sir_seterror(_SIR_E_PLUGINBAD);
        }
# else
#  error "plugin version not implemented"
# endif
        /* query the plugin for information. */
        if (!plugin->iface.query(&plugin->info)) {
            _sir_selflog("error: plugin (path: '%s', addr: %p) returned false from"
                         " query fn!", plugin->path, plugin->handle);
            _sir_plugin_destroy(&plugin);
            (void)_sir_seterror(_SIR_E_PLUGINERR);
            return 0U;
        }

        /* verify version. */
        if (!plugin->info.iface_ver || plugin->info.iface_ver > SIR_PLUGIN_VCURRENT) {
            _sir_selflog("error: plugin (path: '%s', addr: %p) has version"
                         " %"PRIu8"; libsir has %d", plugin->path, plugin->handle,
                        plugin->info.iface_ver, SIR_PLUGIN_VCURRENT);
            _sir_plugin_destroy(&plugin);
            (void)_sir_seterror(_SIR_E_PLUGINVER);
            return 0U;
        }

        bool data_valid = true;

        /* verify level registration bitmask. */
        if (!_sir_validlevels(plugin->info.levels)) {
            _sir_selflog("error: plugin (path: '%s', addr: %p) has invalid levels"
                         " %04"PRIx16, plugin->path, plugin->handle, plugin->info.levels);
            data_valid = false;
        }

        /* verify formatting options bitmask. */
        if (!_sir_validopts(plugin->info.opts)) {
            _sir_selflog("error: plugin (path: '%s', addr: %p) has invalid opts"
                         " %08"PRIx32, plugin->path, plugin->handle, plugin->info.opts);
            data_valid = false;
        }

        /* verify strings */
        if (!_sir_validstrnofail(plugin->info.author) ||
            !_sir_validstrnofail(plugin->info.desc)) {
            _sir_selflog("error: plugin (path: '%s', addr: %p) has invalid author"
                         " or description", plugin->path, plugin->handle);
            data_valid = false;
        }

        /* if any category of data is invalid, fail and unload. */
        if (!data_valid) {
            _sir_plugin_destroy(&plugin);
            (void)_sir_seterror(_SIR_E_PLUGINDAT);
            return 0U;
        }

        /* plugin is valid; tell it to initialize, assign it an id,
         * print its information, and add to cache. */
        if (!plugin->iface.init()) {
            _sir_selflog("error: plugin (path: '%s', addr: %p) failed to initialize!",
                plugin->path, plugin->handle);
            _sir_plugin_destroy(&plugin);
            (void)_sir_seterror(_SIR_E_PLUGINERR);
            return 0U;
        }

        plugin->id    = FNV32_1a((const uint8_t*)&plugin->iface, sizeof(sir_pluginiface));
        plugin->valid = true;

        _sir_selflog("successfully validated plugin (path: '%s', id: %08"PRIx32"); properties:"
                     SIR_EOL "{"
                     SIR_EOL "\tversion = %"PRIu8".%"PRIu8".%"PRIu8
                     SIR_EOL "\tlevels = %04"PRIx16
                     SIR_EOL "\topts = %08"PRIx32
                     SIR_EOL "\tauthor = '%s'"
                     SIR_EOL "\tdesc = '%s'"
                     SIR_EOL "\tcaps = %016"PRIx64
                     SIR_EOL "}",
                     plugin->path, plugin->id, plugin->info.maj_ver, plugin->info.min_ver,
                     plugin->info.bld_ver, plugin->info.levels, plugin->info.opts,
                     _SIR_PRNSTR(plugin->info.author), _SIR_PRNSTR(plugin->info.desc),
                     plugin->info.caps);

        retval = _sir_plugin_add(plugin);
        if (0U == retval) {
            _sir_selflog("error: failed to add plugin (path: '%s', addr: %p) to"
                         " cache; unloading", plugin->path, plugin->handle);
            _sir_plugin_destroy(&plugin);
        }
    }

    return retval;
#else
    SIR_UNUSED(plugin);
    return 0U;
#endif
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, (%rsp)
xorl %ebx, %ebx
testq %rdi, %rdi
je 0x7d34
movq 0x8(%rdi), %rdi
leaq 0x21bb(%rip), %rsi      # 0x9e4e
callq 0x7eb2
movq (%rsp), %rcx
movq %rax, 0x40(%rcx)
movq 0x8(%rcx), %rdi
leaq 0x21b4(%rip), %rsi      # 0x9e5f
callq 0x7eb2
movq (%rsp), %rcx
movq %rax, 0x48(%rcx)
movq 0x8(%rcx), %rdi
leaq 0x21ac(%rip), %rsi      # 0x9e6f
callq 0x7eb2
movq (%rsp), %rcx
movq %rax, 0x50(%rcx)
movq 0x8(%rcx), %rdi
leaq 0x21a5(%rip), %rsi      # 0x9e80
callq 0x7eb2
movq (%rsp), %rdi
movq %rax, 0x58(%rdi)
movq 0x40(%rdi), %rcx
testq %rcx, %rcx
je 0x7d0c
cmpq $0x0, 0x48(%rdi)
je 0x7d0c
cmpq $0x0, 0x50(%rdi)
sete %dl
testq %rax, %rax
sete %al
orb %dl, %al
cmpb $0x1, %al
jne 0x7d41
movq %rsp, %rdi
callq 0x7c2c
leaq 0x2178(%rip), %rsi      # 0x9e93
leaq 0x211f(%rip), %rdx      # 0x9e41
movl $0x80130000, %edi       # imm = 0x80130000
movl $0x74, %ecx
callq 0x31c0
movzbl %al, %ebx
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
addq $0x10, %rdi
callq *%rcx
testb %al, %al
je 0x7e22
movq (%rsp), %rax
cmpb $0x1, 0x10(%rax)
jne 0x7e44
movzwl 0x14(%rax), %edi
leaq 0x212b(%rip), %r14      # 0x9e93
leaq 0x20d2(%rip), %r15      # 0x9e41
movq %r14, %rsi
movq %r15, %rdx
movl $0x8f, %ecx
callq 0x568b
movl %eax, %ebp
movq (%rsp), %rax
movl 0x18(%rax), %edi
movq %r14, %rsi
movq %r15, %rdx
movl $0x96, %ecx
callq 0x56c4
movq (%rsp), %rcx
movq 0x20(%rcx), %rdx
testq %rdx, %rdx
je 0x7e66
cmpb $0x0, (%rdx)
je 0x7e66
movq 0x28(%rcx), %rdx
testq %rdx, %rdx
je 0x7e66
andb %al, %bpl
cmpb $0x0, (%rdx)
setne %al
testb %bpl, %al
je 0x7e66
callq *0x48(%rcx)
testb %al, %al
je 0x7e90
movl $0x811c9dc5, %eax       # imm = 0x811C9DC5
movl $0x40, %ecx
movq (%rsp), %rdi
movzbl (%rdi,%rcx), %edx
xorl %eax, %edx
imull $0x1000193, %edx, %eax  # imm = 0x1000193
incq %rcx
cmpq $0x60, %rcx
jne 0x7dea
movl %eax, 0x60(%rdi)
movb $0x1, 0x39(%rdi)
callq 0x7f28
movl %eax, %ebx
testl %eax, %eax
jne 0x7d34
movq %rsp, %rdi
callq 0x7c2c
jmp 0x7d34
movq %rsp, %rdi
callq 0x7c2c
leaq 0x2062(%rip), %rsi      # 0x9e93
leaq 0x2009(%rip), %rdx      # 0x9e41
movl $0x80160000, %edi       # imm = 0x80160000
movl $0x7e, %ecx
jmp 0x7e86
movq %rsp, %rdi
callq 0x7c2c
leaq 0x2040(%rip), %rsi      # 0x9e93
leaq 0x1fe7(%rip), %rdx      # 0x9e41
movl $0x80150000, %edi       # imm = 0x80150000
movl $0x88, %ecx
jmp 0x7e86
movq %rsp, %rdi
callq 0x7c2c
leaq 0x201e(%rip), %rsi      # 0x9e93
leaq 0x1fc5(%rip), %rdx      # 0x9e41
movl $0x80140000, %edi       # imm = 0x80140000
movl $0xa7, %ecx
callq 0x31c0
jmp 0x7d34
movq %rsp, %rdi
callq 0x7c2c
leaq 0x1ff4(%rip), %rsi      # 0x9e93
leaq 0x1f9b(%rip), %rdx      # 0x9e41
movl $0x80160000, %edi       # imm = 0x80160000
movl $0xb1, %ecx
jmp 0x7e86