// File: /workspace/github_c_makefile_star2_O2/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 0x7727
movq %rdi, %rbx
movq 0x8(%rdi), %rdi
leaq 0x27a6(%rip), %rsi      # 0x9e3e
callq 0x7890
movq %rax, 0x40(%rbx)
movq 0x8(%rbx), %rdi
leaq 0x27a3(%rip), %rsi      # 0x9e4f
callq 0x7890
movq %rax, 0x48(%rbx)
movq 0x8(%rbx), %rdi
leaq 0x279f(%rip), %rsi      # 0x9e5f
callq 0x7890
movq %rax, 0x50(%rbx)
movq 0x8(%rbx), %rdi
leaq 0x279c(%rip), %rsi      # 0x9e70
callq 0x7890
movq %rax, 0x58(%rbx)
movq 0x40(%rbx), %rcx
testq %rcx, %rcx
je 0x7701
cmpq $0x0, 0x48(%rbx)
je 0x7701
cmpq $0x0, 0x50(%rbx)
sete %dl
testq %rax, %rax
sete %al
orb %dl, %al
cmpb $0x1, %al
jne 0x7732
movq %rsp, %rdi
callq 0x7625
leaq 0x2773(%rip), %rsi      # 0x9e83
leaq 0x271a(%rip), %rdx      # 0x9e31
pushq $0x74
popq %rcx
movl $0x80130000, %edi       # imm = 0x80130000
callq 0x3138
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 0x77df
cmpb $0x1, (%r14)
jne 0x77ff
movzwl 0x14(%rbx), %edi
leaq 0x272b(%rip), %r14      # 0x9e83
leaq 0x26d2(%rip), %r15      # 0x9e31
movq %r14, %rsi
movq %r15, %rdx
movl $0x8f, %ecx
callq 0x528f
movl %eax, %ebp
movl 0x18(%rbx), %edi
movq %r14, %rsi
movq %r15, %rdx
movl $0x96, %ecx
callq 0x52c2
movq 0x20(%rbx), %rcx
testq %rcx, %rcx
je 0x7821
cmpb $0x0, (%rcx)
je 0x7821
movq 0x28(%rbx), %rcx
testq %rcx, %rcx
je 0x7821
andb %al, %bpl
cmpb $0x0, (%rcx)
setne %al
testb %bpl, %al
je 0x7821
callq *0x48(%rbx)
testb %al, %al
je 0x784d
movl $0x811c9dc5, %eax       # imm = 0x811C9DC5
pushq $0x40
popq %rcx
cmpq $0x60, %rcx
je 0x786f
movzbl (%rbx,%rcx), %edx
xorl %edx, %eax
imull $0x1000193, %eax, %eax  # imm = 0x1000193
incq %rcx
jmp 0x77c4
movq %rsp, %rdi
callq 0x7625
leaq 0x2695(%rip), %rsi      # 0x9e83
leaq 0x263c(%rip), %rdx      # 0x9e31
pushq $0x7e
popq %rcx
movl $0x80160000, %edi       # imm = 0x80160000
jmp 0x7841
movq %rsp, %rdi
callq 0x7625
leaq 0x2675(%rip), %rsi      # 0x9e83
leaq 0x261c(%rip), %rdx      # 0x9e31
movl $0x80150000, %edi       # imm = 0x80150000
movl $0x88, %ecx
jmp 0x7841
movq %rsp, %rdi
callq 0x7625
leaq 0x2653(%rip), %rsi      # 0x9e83
leaq 0x25fa(%rip), %rdx      # 0x9e31
movl $0x80140000, %edi       # imm = 0x80140000
movl $0xa7, %ecx
callq 0x3138
xorl %eax, %eax
jmp 0x7727
movq %rsp, %rdi
callq 0x7625
leaq 0x2627(%rip), %rsi      # 0x9e83
leaq 0x25ce(%rip), %rdx      # 0x9e31
movl $0x80160000, %edi       # imm = 0x80160000
movl $0xb1, %ecx
jmp 0x7841
movl %eax, 0x60(%rbx)
movb $0x1, 0x39(%rbx)
movq %rbx, %rdi
callq 0x790b
testl %eax, %eax
jne 0x7727
movq %rsp, %rdi
callq 0x7625
jmp 0x7846