// File: /workspace/github_c_makefile_star2_O2/aremmell[P]libsir/tests/tests.c
// Function: sirtest_pluginloader
bool sirtest_pluginloader(void) {
    INIT(si, SIRL_ALL, 0, 0, 0);
    bool pass = si_init;

#if !defined(__WIN__)
# define PLUGIN_EXT "so"
#else
# define PLUGIN_EXT "dll"
#endif

    static const char* plugin1 = "build/lib/plugin_dummy."PLUGIN_EXT;
    static const char* plugin2 = "build/lib/plugin_dummy_bad1."PLUGIN_EXT;
    static const char* plugin3 = "build/lib/plugin_dummy_bad2."PLUGIN_EXT;
    static const char* plugin4 = "build/lib/plugin_dummy_bad3."PLUGIN_EXT;
    static const char* plugin5 = "build/lib/plugin_dummy_bad4."PLUGIN_EXT;
    static const char* plugin6 = "build/lib/plugin_dummy_bad5."PLUGIN_EXT;
    static const char* plugin7 = "build/lib/plugin_dummy_bad6."PLUGIN_EXT;
    static const char* plugin8 = "build/lib/i_dont_exist."PLUGIN_EXT;

#if defined(SIR_NO_PLUGINS)
    SIR_UNUSED(plugin2);
    SIR_UNUSED(plugin3);
    SIR_UNUSED(plugin4);
    SIR_UNUSED(plugin5);
    SIR_UNUSED(plugin6);
    SIR_UNUSED(plugin7);
    SIR_UNUSED(plugin8);

    TEST_MSG_0("SIR_NO_PLUGINS is defined; expecting calls to fail");

    TEST_MSG("loading good plugin: '%s'...", plugin1);
    /* load a valid, well-behaved plugin. */
    sirpluginid id = sir_loadplugin(plugin1);
    _sir_eqland(pass, 0 == id);

    if (pass)
        PRINT_EXPECTED_ERROR();

    TEST_MSG("unloading good plugin: '%s'...", plugin1);
    /* also try the unload function. */
    _sir_eqland(pass, !sir_unloadplugin(id));

    if (pass)
        PRINT_EXPECTED_ERROR();
#else
    /* load a valid, well-behaved plugin. */
    TEST_MSG("loading good plugin: '%s'...", plugin1);
    sirpluginid id = sir_loadplugin(plugin1);
    _sir_eqland(pass, 0 != id);

    (void)print_test_error(pass, pass);

    _sir_eqland(pass, sir_info("this message will be dispatched to the plugin."));
    _sir_eqland(pass, sir_warn("this message will *not* be dispatched to the plugin."));

    /* re-loading the same plugin should fail. */
    TEST_MSG("loading duplicate plugin: '%s'...", plugin1);
    sirpluginid badid = sir_loadplugin(plugin1);
    _sir_eqland(pass, 0 == badid);

    (void)print_test_error(pass, pass);

    /* the following are all invalid or misbehaved, and should all fail. */
    TEST_MSG("loading bad plugin: '%s'...", plugin2);
    badid = sir_loadplugin(plugin2);
    _sir_eqland(pass, 0 == badid);

    (void)print_test_error(pass, pass);

    TEST_MSG("loading bad plugin: '%s'...", plugin3);
    badid = sir_loadplugin(plugin3);
    _sir_eqland(pass, 0 == badid);

    (void)print_test_error(pass, pass);

    TEST_MSG("loading bad plugin: '%s'...", plugin4);
    badid = sir_loadplugin(plugin4);
    _sir_eqland(pass, 0 == badid);

    (void)print_test_error(pass, pass);

    TEST_MSG("loading bad plugin: '%s'...", plugin5);
    badid = sir_loadplugin(plugin5);
    _sir_eqland(pass, 0 == badid);

    (void)print_test_error(pass, pass);

    TEST_MSG("loading bad plugin: '%s'...", plugin6);
    badid = sir_loadplugin(plugin6);
    _sir_eqland(pass, 0 == badid);

    (void)print_test_error(pass, pass);

    TEST_MSG("loading bad plugin: '%s'...", plugin7);
    badid = sir_loadplugin(plugin7);
    _sir_eqland(pass, 0 != badid); /* this one should load, just return false from write */

    _sir_eqland(pass, !sir_info("should fail; a plugin failed to process the message."));

    (void)print_test_error(pass, pass);

    TEST_MSG("loading nonexistent plugin: '%s'...", plugin8);
    badid = sir_loadplugin(plugin8);
    _sir_eqland(pass, 0 == badid);

    (void)print_test_error(pass, pass);

    /* unload the good plugin manually. */
    TEST_MSG("unloading good plugin: '%s'...", plugin1);
    _sir_eqland(pass, sir_unloadplugin(id));

    (void)print_test_error(pass, pass);

    /* try to unload the plugin again. */
    TEST_MSG("unloading already unloaded plugin '%s'...", plugin1);
    _sir_eqland(pass, !sir_unloadplugin(id));

    (void)print_test_error(pass, pass);

    /* test bad paths. */
    TEST_MSG_0("trying to load plugin with NULL path...");
    badid = sir_loadplugin(NULL);
    _sir_eqland(pass, 0 == badid);

    (void)print_test_error(pass, pass);
#endif
    _sir_eqland(pass, sir_cleanup());
    return PRINT_RESULT_RETURN(pass);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %rsp, %rbx
movl $0x108, %edx            # imm = 0x108
movq %rbx, %rdi
xorl %esi, %esi
callq 0x31f0
movl $0x100000, %eax         # imm = 0x100000
movl %eax, 0x4(%rbx)
movw $0xff, (%rbx)
movl %eax, 0xc(%rbx)
movq %rbx, %rdi
callq 0x94a9
movl %eax, %r15d
leaq 0xa6f1(%rip), %rsi      # 0x12b08
leaq 0xa5fc(%rip), %r14      # 0x12a1a
pushq $0x1
popq %rbx
movl %ebx, %edi
movq %r14, %rdx
xorl %eax, %eax
callq 0x3410
movq %r14, %rdi
callq 0x9a75
movl %eax, %ebp
testl %eax, %eax
setne %al
andb %r15b, %al
movzbl %al, %r15d
movl %r15d, %edi
movl %r15d, %esi
callq 0x3ac9
leaq 0xa6d2(%rip), %rdi      # 0x12b27
xorl %eax, %eax
callq 0x95a2
andb %al, %r15b
leaq 0xa6f0(%rip), %rdi      # 0x12b56
xorl %eax, %eax
callq 0x9700
movl %eax, %r12d
leaq 0xa714(%rip), %rsi      # 0x12b8b
movl %ebx, %edi
movq %r14, %rdx
xorl %eax, %eax
callq 0x3410
movq %r14, %rdi
callq 0x9a75
testl %eax, %eax
sete %al
andb %r12b, %al
andb %r15b, %al
movzbl %al, %r12d
movl %r12d, %edi
movl %r12d, %esi
callq 0x3ac9
leaq 0xa703(%rip), %r15      # 0x12baf
leaq 0xa581(%rip), %r13      # 0x12a34
movl %ebx, %edi
movq %r15, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x3410
movq %r13, %rdi
callq 0x9a75
testl %eax, %eax
sete %al
andb %al, %r12b
movzbl %r12b, %r12d
movl %r12d, %edi
movl %r12d, %esi
callq 0x3ac9
leaq 0xa56b(%rip), %r13      # 0x12a53
movl %ebx, %edi
movq %r15, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x3410
movq %r13, %rdi
callq 0x9a75
testl %eax, %eax
sete %al
andb %al, %r12b
movzbl %r12b, %r12d
movl %r12d, %edi
movl %r12d, %esi
callq 0x3ac9
leaq 0xa555(%rip), %r13      # 0x12a72
movl %ebx, %edi
movq %r15, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x3410
movq %r13, %rdi
callq 0x9a75
testl %eax, %eax
sete %al
andb %al, %r12b
movzbl %r12b, %r12d
movl %r12d, %edi
movl %r12d, %esi
callq 0x3ac9
leaq 0xa53f(%rip), %r13      # 0x12a91
movl %ebx, %edi
movq %r15, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x3410
movq %r13, %rdi
callq 0x9a75
testl %eax, %eax
sete %al
andb %al, %r12b
movzbl %r12b, %r12d
movl %r12d, %edi
movl %r12d, %esi
callq 0x3ac9
leaq 0xa529(%rip), %r13      # 0x12ab0
movl %ebx, %edi
movq %r15, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x3410
movq %r13, %rdi
callq 0x9a75
testl %eax, %eax
sete %al
andb %al, %r12b
movzbl %r12b, %r12d
movl %r12d, %edi
movl %r12d, %esi
callq 0x3ac9
leaq 0xa513(%rip), %r13      # 0x12acf
movl %ebx, %edi
movq %r15, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x3410
movq %r13, %rdi
callq 0x9a75
testl %eax, %eax
setne %r15b
leaq 0xa5ed(%rip), %rdi      # 0x12bcd
xorl %eax, %eax
callq 0x95a2
notb %al
andb %r15b, %al
andb %al, %r12b
movzbl %r12b, %r15d
movl %r15d, %edi
movl %r15d, %esi
callq 0x3ac9
leaq 0xa5fd(%rip), %rsi      # 0x12c02
leaq 0xa4e2(%rip), %r12      # 0x12aee
movl %ebx, %edi
movq %r12, %rdx
xorl %eax, %eax
callq 0x3410
movq %r12, %rdi
callq 0x9a75
testl %eax, %eax
sete %al
andb %al, %r15b
movzbl %r15b, %r15d
movl %r15d, %edi
movl %r15d, %esi
callq 0x3ac9
leaq 0xa5ea(%rip), %rsi      # 0x12c28
movl %ebx, %edi
movq %r14, %rdx
xorl %eax, %eax
callq 0x3410
movl %ebp, %edi
callq 0x9a7a
andb %al, %r15b
movzbl %r15b, %r15d
movl %r15d, %edi
movl %r15d, %esi
callq 0x3ac9
leaq 0xa5df(%rip), %rsi      # 0x12c49
movl %ebx, %edi
movq %r14, %rdx
xorl %eax, %eax
callq 0x3410
movl %ebp, %edi
callq 0x9a7a
xorb $0x1, %al
andb %al, %r15b
movzbl %r15b, %ebp
movl %ebp, %edi
movl %ebp, %esi
callq 0x3ac9
leaq 0xa5df(%rip), %rsi      # 0x12c75
movl %ebx, %edi
xorl %eax, %eax
callq 0x3410
xorl %edi, %edi
callq 0x9a75
testl %eax, %eax
sete %al
andb %al, %bpl
movzbl %bpl, %ebx
movl %ebx, %edi
movl %ebx, %esi
callq 0x3ac9
callq 0x94ae
andb %al, %bl
movzbl %bl, %edi
xorl %esi, %esi
callq 0x3ac9
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq