// File: /workspace/github_c_makefile_star2_O1/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 %r12
pushq %rbx
subq $0x110, %rsp            # imm = 0x110
leaq 0x8(%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)
movw $0x0, 0x8(%rbx)
movq %rbx, %rdi
callq 0x9a31
movl %eax, %r14d
leaq 0xb2d4(%rip), %rsi      # 0x13b48
leaq 0xb1df(%rip), %rbx      # 0x13a5a
movl $0x1, %edi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3400
movq %rbx, %rdi
callq 0xa04f
movl %eax, %ebp
testl %eax, %eax
setne %al
andb %r14b, %al
movzbl %al, %r14d
movl %r14d, %edi
movl %r14d, %esi
callq 0x3b04
leaq 0xb2b5(%rip), %rdi      # 0x13b67
xorl %eax, %eax
callq 0x9b13
andb %al, %r14b
leaq 0xb2d3(%rip), %rdi      # 0x13b96
xorl %eax, %eax
callq 0x9c8f
movl %eax, %r15d
leaq 0xb2f7(%rip), %rsi      # 0x13bcb
movl $0x1, %edi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3400
movq %rbx, %rdi
callq 0xa04f
testl %eax, %eax
sete %al
andb %r15b, %al
andb %r14b, %al
movzbl %al, %r15d
movl %r15d, %edi
movl %r15d, %esi
callq 0x3b04
leaq 0xb2e3(%rip), %r14      # 0x13bef
leaq 0xb161(%rip), %r12      # 0x13a74
movl $0x1, %edi
movq %r14, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x3400
movq %r12, %rdi
callq 0xa04f
testl %eax, %eax
sete %al
andb %al, %r15b
movzbl %r15b, %r15d
movl %r15d, %edi
movl %r15d, %esi
callq 0x3b04
leaq 0xb148(%rip), %r12      # 0x13a93
movl $0x1, %edi
movq %r14, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x3400
movq %r12, %rdi
callq 0xa04f
testl %eax, %eax
sete %al
andb %al, %r15b
movzbl %r15b, %r15d
movl %r15d, %edi
movl %r15d, %esi
callq 0x3b04
leaq 0xb12f(%rip), %r12      # 0x13ab2
movl $0x1, %edi
movq %r14, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x3400
movq %r12, %rdi
callq 0xa04f
testl %eax, %eax
sete %al
andb %al, %r15b
movzbl %r15b, %r15d
movl %r15d, %edi
movl %r15d, %esi
callq 0x3b04
leaq 0xb116(%rip), %r12      # 0x13ad1
movl $0x1, %edi
movq %r14, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x3400
movq %r12, %rdi
callq 0xa04f
testl %eax, %eax
sete %al
andb %al, %r15b
movzbl %r15b, %r15d
movl %r15d, %edi
movl %r15d, %esi
callq 0x3b04
leaq 0xb0fd(%rip), %r12      # 0x13af0
movl $0x1, %edi
movq %r14, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x3400
movq %r12, %rdi
callq 0xa04f
testl %eax, %eax
sete %al
andb %al, %r15b
movzbl %r15b, %r15d
movl %r15d, %edi
movl %r15d, %esi
callq 0x3b04
leaq 0xb0e4(%rip), %r12      # 0x13b0f
movl $0x1, %edi
movq %r14, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x3400
movq %r12, %rdi
callq 0xa04f
testl %eax, %eax
setne %r14b
leaq 0xb1bb(%rip), %rdi      # 0x13c0d
xorl %eax, %eax
callq 0x9b13
notb %al
andb %r14b, %al
andb %al, %r15b
movzbl %r15b, %r14d
movl %r14d, %edi
movl %r14d, %esi
callq 0x3b04
leaq 0xb1cb(%rip), %rsi      # 0x13c42
leaq 0xb0b0(%rip), %r15      # 0x13b2e
movl $0x1, %edi
movq %r15, %rdx
xorl %eax, %eax
callq 0x3400
movq %r15, %rdi
callq 0xa04f
testl %eax, %eax
sete %al
andb %al, %r14b
movzbl %r14b, %r14d
movl %r14d, %edi
movl %r14d, %esi
callq 0x3b04
leaq 0xb1b5(%rip), %rsi      # 0x13c68
movl $0x1, %edi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3400
movl %ebp, %edi
callq 0xa054
andb %al, %r14b
movzbl %r14b, %r14d
movl %r14d, %edi
movl %r14d, %esi
callq 0x3b04
leaq 0xb1a7(%rip), %rsi      # 0x13c89
movl $0x1, %edi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3400
movl %ebp, %edi
callq 0xa054
xorb $0x1, %al
andb %al, %r14b
movzbl %r14b, %ebx
movl %ebx, %edi
movl %ebx, %esi
callq 0x3b04
leaq 0xb1a4(%rip), %rsi      # 0x13cb5
movl $0x1, %edi
xorl %eax, %eax
callq 0x3400
xorl %edi, %edi
callq 0xa04f
testl %eax, %eax
sete %al
andb %al, %bl
movzbl %bl, %ebx
movl %ebx, %edi
movl %ebx, %esi
callq 0x3b04
callq 0x9a36
andb %al, %bl
movzbl %bl, %edi
xorl %esi, %esi
callq 0x3b04
addq $0x110, %rsp            # imm = 0x110
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq