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

    static const size_t iterations = 10;

    /* these should all be valid. */
    TEST_MSG_0(SIR_WHITEB("--- individual valid levels ---"));
    _sir_eqland(pass, _sir_validlevel(SIRL_INFO) && _sir_validlevels(SIRL_INFO));
    (void)printf(INDENT_ITEM SIR_WHITE("valid level: %04x") SIR_EOL, SIRL_INFO);
    _sir_eqland(pass, _sir_validlevel(SIRL_DEBUG) && _sir_validlevels(SIRL_DEBUG));
    (void)printf(INDENT_ITEM SIR_WHITE("valid level: %04x") SIR_EOL, SIRL_DEBUG);
    _sir_eqland(pass, _sir_validlevel(SIRL_NOTICE) && _sir_validlevels(SIRL_NOTICE));
    (void)printf(INDENT_ITEM SIR_WHITE("valid level: %04x") SIR_EOL, SIRL_NOTICE);
    _sir_eqland(pass, _sir_validlevel(SIRL_WARN) && _sir_validlevels(SIRL_WARN));
    (void)printf(INDENT_ITEM SIR_WHITE("valid level: %04x") SIR_EOL, SIRL_WARN);
    _sir_eqland(pass, _sir_validlevel(SIRL_ERROR) && _sir_validlevels(SIRL_ERROR));
    (void)printf(INDENT_ITEM SIR_WHITE("valid level: %04x") SIR_EOL, SIRL_ERROR);
    _sir_eqland(pass, _sir_validlevel(SIRL_CRIT) && _sir_validlevels(SIRL_CRIT));
    (void)printf(INDENT_ITEM SIR_WHITE("valid level: %04x") SIR_EOL, SIRL_CRIT);
    _sir_eqland(pass, _sir_validlevel(SIRL_ALERT) && _sir_validlevels(SIRL_ALERT));
    (void)printf(INDENT_ITEM SIR_WHITE("valid level: %04x") SIR_EOL, SIRL_ALERT);
    _sir_eqland(pass, _sir_validlevel(SIRL_EMERG) && _sir_validlevels(SIRL_EMERG));
    (void)printf(INDENT_ITEM SIR_WHITE("valid level: %04x") SIR_EOL, SIRL_EMERG);
    _sir_eqland(pass, _sir_validlevels(SIRL_ALL));
    (void)printf(INDENT_ITEM SIR_WHITE("valid levels: %04x") SIR_EOL, SIRL_ALL);
    _sir_eqland(pass, _sir_validlevels(SIRL_NONE));
    (void)printf(INDENT_ITEM SIR_WHITE("valid levels: %04x") SIR_EOL, SIRL_NONE);
    PASSFAIL_MSG(pass, "\t--- individual valid levels: %s ---" SIR_EOL SIR_EOL, PRN_PASS(pass));

    /* any combination these bitwise OR'd together
     * to form a bitmask should also be valid. */
    static const sir_levels levels_arr[SIR_NUMLEVELS] = {
        SIRL_EMERG,
        SIRL_ALERT,
        SIRL_CRIT,
        SIRL_ERROR,
        SIRL_WARN,
        SIRL_NOTICE,
        SIRL_INFO,
        SIRL_DEBUG
    };

    TEST_MSG_0(SIR_WHITEB("--- random bitmask of valid levels ---"));
    uint32_t last_count = SIR_NUMLEVELS;
    for (size_t n = 0; n < iterations; n++) {
        sir_levels levels   = 0U;
        uint32_t rand_count = 0U;
        size_t last_idx     = 0UL;

        do {
            rand_count = getrand(SIR_NUMLEVELS);
        } while (rand_count == last_count || rand_count <= 1U);

        last_count = rand_count;

        for (size_t i = 0; i < rand_count; i++) {
            size_t rand_idx = 0;
            size_t tries    = 0;

            do {
                if (++tries > SIR_NUMLEVELS - 2)
                    break;
                rand_idx = (size_t)getrand(SIR_NUMLEVELS);
            } while (rand_idx == last_idx || _sir_bittest(levels, levels_arr[rand_idx]));

            last_idx = rand_idx;
            levels |= levels_arr[rand_idx];
        }

        _sir_eqland(pass, _sir_validlevels(levels));
        (void)printf(INDENT_ITEM SIR_WHITE("(%zu/%zu): random valid (count: %"PRIu32", levels:"
                                 " %04"PRIx16) ")" SIR_EOL, n + 1, iterations, rand_count, levels);
    }
    PASSFAIL_MSG(pass, "\t--- random bitmask of valid levels: %s ---" SIR_EOL SIR_EOL, PRN_PASS(pass));

    TEST_MSG_0(SIR_WHITEB("--- invalid values ---"));

    /* greater than SIRL_ALL. */
    sir_levels invalid = (0xffffU & ~SIRL_ALL);
    _sir_eqland(pass, !_sir_validlevels(invalid));
    (void)printf(INDENT_ITEM SIR_WHITE("greater than SIRL_ALL: %04"PRIx16) SIR_EOL, invalid);

    /* individual invalid level. */
    sir_level invalid2 = 0x1337U;
    _sir_eqland(pass, !_sir_validlevel(invalid2));
    (void)printf(INDENT_ITEM SIR_WHITE("individual invalid level: %04"PRIx16) SIR_EOL, invalid2);

    PASSFAIL_MSG(pass, "\t--- invalid values: %s ---" SIR_EOL, PRN_PASS(pass));

    _sir_eqland(pass, sir_cleanup());
    return PRINT_RESULT_RETURN(pass);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
leaq 0x20(%rsp), %r14
xorl %ebx, %ebx
movl $0x108, %edx            # imm = 0x108
movq %r14, %rdi
xorl %esi, %esi
callq 0x31f0
movl $0x100000, %eax         # imm = 0x100000
movl %eax, 0x4(%r14)
movw $0xff, (%r14)
movl %eax, 0xc(%r14)
movq %r14, %rdi
callq 0x94a9
movl %eax, %ebp
leaq 0xb097(%rip), %rsi      # 0x118d8
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x3410
leaq 0xb071(%rip), %rsi      # 0x118c3
leaq 0x9cb5(%rip), %rdx      # 0x1050e
pushq $0x40
popq %rdi
movl $0x3f3, %ecx            # imm = 0x3F3
callq 0xbf3f
testb %al, %al
je 0x688a
leaq 0xb052(%rip), %rsi      # 0x118c3
leaq 0x9c96(%rip), %rdx      # 0x1050e
pushq $0x40
popq %rdi
movl $0x3f3, %ecx            # imm = 0x3F3
callq 0xbea3
movl %eax, %ebx
andb %bpl, %bl
leaq 0xb07d(%rip), %rsi      # 0x1190e
xorl %r14d, %r14d
pushq $0x1
popq %rdi
pushq $0x40
popq %rdx
xorl %eax, %eax
callq 0x3410
leaq 0xb01b(%rip), %rsi      # 0x118c3
leaq 0x9c5f(%rip), %rdx      # 0x1050e
movl $0x80, %edi
movl $0x3f5, %ecx            # imm = 0x3F5
callq 0xbf3f
testb %al, %al
je 0x68e5
leaq 0xaffa(%rip), %rsi      # 0x118c3
leaq 0x9c3e(%rip), %rdx      # 0x1050e
movl $0x80, %edi
movl $0x3f5, %ecx            # imm = 0x3F5
callq 0xbea3
movl %eax, %r14d
andb %bl, %r14b
leaq 0xb022(%rip), %rsi      # 0x1190e
xorl %ebp, %ebp
pushq $0x1
popq %rdi
movl $0x80, %edx
xorl %eax, %eax
callq 0x3410
leaq 0xafbf(%rip), %rsi      # 0x118c3
leaq 0x9c03(%rip), %rdx      # 0x1050e
pushq $0x20
popq %rdi
movl $0x3f7, %ecx            # imm = 0x3F7
callq 0xbf3f
testb %al, %al
je 0x693c
leaq 0xafa0(%rip), %rsi      # 0x118c3
leaq 0x9be4(%rip), %rdx      # 0x1050e
pushq $0x20
popq %rdi
movl $0x3f7, %ecx            # imm = 0x3F7
callq 0xbea3
movl %eax, %ebp
andb %r14b, %bpl
leaq 0xafcb(%rip), %rsi      # 0x1190e
xorl %ebx, %ebx
pushq $0x1
popq %rdi
pushq $0x20
popq %rdx
xorl %eax, %eax
callq 0x3410
leaq 0xaf6a(%rip), %rsi      # 0x118c3
leaq 0x9bae(%rip), %rdx      # 0x1050e
pushq $0x10
popq %rdi
movl $0x3f9, %ecx            # imm = 0x3F9
callq 0xbf3f
testb %al, %al
je 0x6991
leaq 0xaf4b(%rip), %rsi      # 0x118c3
leaq 0x9b8f(%rip), %rdx      # 0x1050e
pushq $0x10
popq %rdi
movl $0x3f9, %ecx            # imm = 0x3F9
callq 0xbea3
movl %eax, %ebx
andb %bpl, %bl
leaq 0xaf76(%rip), %rsi      # 0x1190e
xorl %ebp, %ebp
pushq $0x1
popq %rdi
pushq $0x10
popq %rdx
xorl %eax, %eax
callq 0x3410
leaq 0xaf15(%rip), %rsi      # 0x118c3
leaq 0x9b59(%rip), %rdx      # 0x1050e
pushq $0x8
popq %rdi
movl $0x3fb, %ecx            # imm = 0x3FB
callq 0xbf3f
testb %al, %al
je 0x69e6
leaq 0xaef6(%rip), %rsi      # 0x118c3
leaq 0x9b3a(%rip), %rdx      # 0x1050e
pushq $0x8
popq %rdi
movl $0x3fb, %ecx            # imm = 0x3FB
callq 0xbea3
movl %eax, %ebp
andb %bl, %bpl
leaq 0xaf21(%rip), %rsi      # 0x1190e
xorl %r14d, %r14d
pushq $0x1
popq %rdi
pushq $0x8
popq %rdx
xorl %eax, %eax
callq 0x3410
leaq 0xaebf(%rip), %rsi      # 0x118c3
leaq 0x9b03(%rip), %rdx      # 0x1050e
pushq $0x4
popq %rdi
movl $0x3fd, %ecx            # imm = 0x3FD
callq 0xbf3f
testb %al, %al
je 0x6a3d
leaq 0xaea0(%rip), %rsi      # 0x118c3
leaq 0x9ae4(%rip), %rdx      # 0x1050e
pushq $0x4
popq %rdi
movl $0x3fd, %ecx            # imm = 0x3FD
callq 0xbea3
movl %eax, %r14d
andb %bpl, %r14b
leaq 0xaeca(%rip), %rsi      # 0x1190e
xorl %ebp, %ebp
pushq $0x1
popq %rdi
pushq $0x4
popq %rdx
xorl %eax, %eax
callq 0x3410
leaq 0xae69(%rip), %rsi      # 0x118c3
leaq 0x9aad(%rip), %rdx      # 0x1050e
pushq $0x2
popq %rdi
movl $0x3ff, %ecx            # imm = 0x3FF
callq 0xbf3f
testb %al, %al
je 0x6a92
leaq 0xae4a(%rip), %rsi      # 0x118c3
leaq 0x9a8e(%rip), %rdx      # 0x1050e
pushq $0x2
popq %rdi
movl $0x3ff, %ecx            # imm = 0x3FF
callq 0xbea3
movl %eax, %ebp
andb %r14b, %bpl
leaq 0xae75(%rip), %rsi      # 0x1190e
xorl %r14d, %r14d
pushq $0x1
popq %r15
pushq $0x2
popq %rdx
movl %r15d, %edi
xorl %eax, %eax
callq 0x3410
leaq 0xae0f(%rip), %rsi      # 0x118c3
leaq 0x9a53(%rip), %rdx      # 0x1050e
movl %r15d, %edi
movl $0x401, %ecx            # imm = 0x401
callq 0xbf3f
testb %al, %al
je 0x6aed
leaq 0xadf0(%rip), %rsi      # 0x118c3
leaq 0x9a34(%rip), %rdx      # 0x1050e
pushq $0x1
popq %rdi
movl $0x401, %ecx            # imm = 0x401
callq 0xbea3
movl %eax, %r14d
andb %bpl, %r14b
leaq 0xae1a(%rip), %rsi      # 0x1190e
pushq $0x1
popq %rbp
movl %ebp, %edi
movl %ebp, %edx
xorl %eax, %eax
callq 0x3410
leaq 0xadba(%rip), %rbx      # 0x118c3
leaq 0x99fe(%rip), %r13      # 0x1050e
movl $0xff, %edi
movq %rbx, %rsi
movq %r13, %rdx
movl $0x403, %ecx            # imm = 0x403
callq 0xbea3
movl %eax, %r15d
leaq 0xae0d(%rip), %r12      # 0x1193c
movl %ebp, %edi
movq %r12, %rsi
movl $0xff, %edx
xorl %eax, %eax
callq 0x3410
xorl %edi, %edi
movq %rbx, %rsi
movq %r13, %rdx
movl $0x405, %ecx            # imm = 0x405
callq 0xbea3
movl %eax, %ebx
andb %r15b, %bl
andb %r14b, %bl
movl %ebp, %edi
movq %r12, %rsi
xorl %edx, %edx
xorl %eax, %eax
callq 0x3410
leaq 0xadfc(%rip), %rax      # 0x1196b
leaq 0xae30(%rip), %rsi      # 0x119a6
movb %bl, 0x7(%rsp)
testb %bl, %bl
cmovneq %rax, %rsi
leaq 0x952f(%rip), %rax      # 0x100b6
leaq 0x9541(%rip), %rdx      # 0x100cf
cmovneq %rax, %rdx
movl %ebp, %edi
xorl %eax, %eax
callq 0x3410
leaq 0xae3f(%rip), %rsi      # 0x119e1
movl %ebp, %edi
xorl %eax, %eax
callq 0x3410
leaq 0x98fe(%rip), %rbp      # 0x104b0
xorl %r12d, %r12d
pushq $0x8
popq %r14
movl %r14d, %ebx
cmpq $0xa, %r12
je 0x6c92
movl %r14d, %edi
callq 0x3fab
movl %eax, %r15d
cmpl %ebx, %eax
sete %al
cmpl $0x2, %r15d
setb %cl
orb %al, %cl
jne 0x6bc6
movq %r12, 0x8(%rsp)
movl %r15d, %eax
movq %rax, 0x10(%rsp)
xorl %ecx, %ecx
xorl %r14d, %r14d
xorl %r12d, %r12d
cmpq 0x10(%rsp), %r12
je 0x6c3e
movq %rcx, 0x18(%rsp)
movl %ecx, %ebx
notl %ebx
pushq $0x6
popq %r13
xorl %eax, %eax
subq $0x1, %r13
jb 0x6c2d
pushq $0x8
popq %rdi
callq 0x3fab
movl %eax, %eax
cmpq %rax, %r14
je 0x6c0c
movzwl (%rbp,%rax,2), %ecx
testw %bx, %cx
je 0x6c0c
jmp 0x6c32
movzwl (%rbp,%rax,2), %ecx
orl 0x18(%rsp), %ecx
incq %r12
movq %rax, %r14
jmp 0x6bf6
movzwl %cx, %r14d
movl %r14d, %edi
leaq 0xac77(%rip), %rsi      # 0x118c3
leaq 0x98bb(%rip), %rdx      # 0x1050e
movl $0x431, %ecx            # imm = 0x431
callq 0xbea3
andb %al, 0x7(%rsp)
movq 0x8(%rsp), %r12
incq %r12
pushq $0x1
popq %rdi
leaq 0xadab(%rip), %rsi      # 0x11a1e
movq %r12, %rdx
pushq $0xa
popq %rcx
movl %r15d, %r8d
movl %r14d, %r9d
xorl %eax, %eax
callq 0x3410
movl %r15d, %ebx
pushq $0x8
popq %r14
jmp 0x6bbc
leaq 0xadd3(%rip), %rax      # 0x11a6c
leaq 0xae0e(%rip), %rsi      # 0x11aae
movb 0x7(%rsp), %bpl
testb $0x1, %bpl
cmovneq %rax, %rsi
leaq 0x941b(%rip), %r13      # 0x100cf
movq %r13, %rdx
leaq 0x93f8(%rip), %rax      # 0x100b6
cmovneq %rax, %rdx
pushq $0x1
popq %rbx
movl %ebx, %edi
xorl %eax, %eax
callq 0x3410
leaq 0xaa83(%rip), %rsi      # 0x11758
movl %ebx, %edi
xorl %eax, %eax
callq 0x3410
leaq 0xabde(%rip), %r14      # 0x118c3
leaq 0x9822(%rip), %r15      # 0x1050e
movl $0xff00, %edi           # imm = 0xFF00
movq %r14, %rsi
movq %r15, %rdx
movl $0x43b, %ecx            # imm = 0x43B
callq 0xbea3
movl %eax, %r12d
leaq 0xade5(%rip), %rsi      # 0x11af0
movl %ebx, %edi
movl $0xff00, %edx           # imm = 0xFF00
xorl %eax, %eax
callq 0x3410
movl $0x1337, %edi           # imm = 0x1337
movq %r14, %rsi
movq %r15, %rdx
movl $0x440, %ecx            # imm = 0x440
callq 0xbf3f
movl %eax, %r14d
orb %r12b, %r14b
xorb $0x1, %r14b
andb %bpl, %r14b
leaq 0xade6(%rip), %rsi      # 0x11b28
movl %ebx, %edi
movl $0x1337, %edx           # imm = 0x1337
xorl %eax, %eax
callq 0x3410
leaq 0xae0c(%rip), %rax      # 0x11b63
leaq 0xae36(%rip), %rsi      # 0x11b94
testb $0x1, %r14b
cmovneq %rax, %rsi
leaq 0x9349(%rip), %rax      # 0x100b6
cmovneq %rax, %r13
movl %ebx, %edi
movq %r13, %rdx
xorl %eax, %eax
callq 0x3410
callq 0x94ae
andb %r14b, %al
movzbl %al, %edi
xorl %esi, %esi
callq 0x3ac9
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq