// File: /workspace/github_c_makefile_star2_O3/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 %eax, %eax
testq %rdi, %rdi
je 0x7b13
movq %rdi, %rbx
movq 0x8(%rdi), %rdi
leaq 0x23bc(%rip), %rsi      # 0x9e3e
callq 0x7c82
movq %rax, 0x40(%rbx)
movq 0x8(%rbx), %rdi
leaq 0x23b9(%rip), %rsi      # 0x9e4f
callq 0x7c82
movq %rax, 0x48(%rbx)
movq 0x8(%rbx), %rdi
leaq 0x23b5(%rip), %rsi      # 0x9e5f
callq 0x7c82
movq %rax, 0x50(%rbx)
movq 0x8(%rbx), %rdi
leaq 0x23b2(%rip), %rsi      # 0x9e70
callq 0x7c82
movq %rax, 0x58(%rbx)
movq 0x40(%rbx), %rcx
testq %rcx, %rcx
je 0x7aeb
cmpq $0x0, 0x48(%rbx)
je 0x7aeb
cmpq $0x0, 0x50(%rbx)
sete %dl
testq %rax, %rax
sete %al
orb %dl, %al
cmpb $0x1, %al
jne 0x7b1e
movq %rsp, %rdi
callq 0x7a19
leaq 0x2389(%rip), %rsi      # 0x9e83
leaq 0x2330(%rip), %rdx      # 0x9e31
movl $0x80130000, %edi       # imm = 0x80130000
movl $0x74, %ecx
callq 0x31c0
movzbl %al, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x10(%rbx), %r14
movq %r14, %rdi
callq *%rcx
testb %al, %al
je 0x7bf0
cmpb $0x1, (%r14)
jne 0x7c12
movzwl 0x14(%rbx), %edi
leaq 0x233f(%rip), %r14      # 0x9e83
leaq 0x22e6(%rip), %r15      # 0x9e31
movq %r14, %rsi
movq %r15, %rdx
movl $0x8f, %ecx
callq 0x55c4
movl %eax, %ebp
movl 0x18(%rbx), %edi
movq %r14, %rsi
movq %r15, %rdx
movl $0x96, %ecx
callq 0x55fd
movq 0x20(%rbx), %rcx
testq %rcx, %rcx
je 0x7c34
cmpb $0x0, (%rcx)
je 0x7c34
movq 0x28(%rbx), %rcx
testq %rcx, %rcx
je 0x7c34
andb %al, %bpl
cmpb $0x0, (%rcx)
setne %al
testb %bpl, %al
je 0x7c34
callq *0x48(%rbx)
testb %al, %al
je 0x7c60
movl $0x811c9dc5, %eax       # imm = 0x811C9DC5
movl $0x40, %ecx
movzbl (%rbx,%rcx), %edx
xorl %eax, %edx
imull $0x1000193, %edx, %eax  # imm = 0x1000193
incq %rcx
cmpq $0x60, %rcx
jne 0x7bba
movl %eax, 0x60(%rbx)
movb $0x1, 0x39(%rbx)
movq %rbx, %rdi
callq 0x7cf8
testl %eax, %eax
jne 0x7b13
movq %rsp, %rdi
callq 0x7a19
jmp 0x7c59
movq %rsp, %rdi
callq 0x7a19
leaq 0x2284(%rip), %rsi      # 0x9e83
leaq 0x222b(%rip), %rdx      # 0x9e31
movl $0x80160000, %edi       # imm = 0x80160000
movl $0x7e, %ecx
jmp 0x7c54
movq %rsp, %rdi
callq 0x7a19
leaq 0x2262(%rip), %rsi      # 0x9e83
leaq 0x2209(%rip), %rdx      # 0x9e31
movl $0x80150000, %edi       # imm = 0x80150000
movl $0x88, %ecx
jmp 0x7c54
movq %rsp, %rdi
callq 0x7a19
leaq 0x2240(%rip), %rsi      # 0x9e83
leaq 0x21e7(%rip), %rdx      # 0x9e31
movl $0x80140000, %edi       # imm = 0x80140000
movl $0xa7, %ecx
callq 0x31c0
xorl %eax, %eax
jmp 0x7b13
movq %rsp, %rdi
callq 0x7a19
leaq 0x2214(%rip), %rsi      # 0x9e83
leaq 0x21bb(%rip), %rdx      # 0x9e31
movl $0x80160000, %edi       # imm = 0x80160000
movl $0xb1, %ecx
jmp 0x7c54