// File: /workspace/github_c_makefile_star2_O1/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)
movw $0x0, 0x8(%r14)
movq %r14, %rdi
callq 0x9a31
movl %eax, %ebp
leaq 0xbedb(%rip), %rsi      # 0x12918
movl $0x1, %edi
xorl %eax, %eax
callq 0x3400
leaq 0xbeb3(%rip), %rsi      # 0x12903
leaq 0xaaf7(%rip), %rdx      # 0x1154e
movl $0x40, %edi
movl $0x3f3, %ecx            # imm = 0x3F3
callq 0xc87f
testb %al, %al
je 0x6a8c
leaq 0xbe92(%rip), %rsi      # 0x12903
leaq 0xaad6(%rip), %rdx      # 0x1154e
movl $0x40, %edi
movl $0x3f3, %ecx            # imm = 0x3F3
callq 0xc813
movl %eax, %ebx
andb %bpl, %bl
leaq 0xbebb(%rip), %rsi      # 0x1294e
xorl %ebp, %ebp
movl $0x1, %edi
movl $0x40, %edx
xorl %eax, %eax
callq 0x3400
leaq 0xbe56(%rip), %rsi      # 0x12903
leaq 0xaa9a(%rip), %rdx      # 0x1154e
movl $0x80, %edi
movl $0x3f5, %ecx            # imm = 0x3F5
callq 0xc87f
testb %al, %al
je 0x6ae9
leaq 0xbe35(%rip), %rsi      # 0x12903
leaq 0xaa79(%rip), %rdx      # 0x1154e
movl $0x80, %edi
movl $0x3f5, %ecx            # imm = 0x3F5
callq 0xc813
movl %eax, %ebp
andb %bl, %bpl
leaq 0xbe5e(%rip), %rsi      # 0x1294e
xorl %ebx, %ebx
movl $0x1, %edi
movl $0x80, %edx
xorl %eax, %eax
callq 0x3400
leaq 0xbdf9(%rip), %rsi      # 0x12903
leaq 0xaa3d(%rip), %rdx      # 0x1154e
movl $0x20, %edi
movl $0x3f7, %ecx            # imm = 0x3F7
callq 0xc87f
testb %al, %al
je 0x6b46
leaq 0xbdd8(%rip), %rsi      # 0x12903
leaq 0xaa1c(%rip), %rdx      # 0x1154e
movl $0x20, %edi
movl $0x3f7, %ecx            # imm = 0x3F7
callq 0xc813
movl %eax, %ebx
andb %bpl, %bl
leaq 0xbe01(%rip), %rsi      # 0x1294e
xorl %ebp, %ebp
movl $0x1, %edi
movl $0x20, %edx
xorl %eax, %eax
callq 0x3400
leaq 0xbd9c(%rip), %rsi      # 0x12903
leaq 0xa9e0(%rip), %rdx      # 0x1154e
movl $0x10, %edi
movl $0x3f9, %ecx            # imm = 0x3F9
callq 0xc87f
testb %al, %al
je 0x6ba3
leaq 0xbd7b(%rip), %rsi      # 0x12903
leaq 0xa9bf(%rip), %rdx      # 0x1154e
movl $0x10, %edi
movl $0x3f9, %ecx            # imm = 0x3F9
callq 0xc813
movl %eax, %ebp
andb %bl, %bpl
leaq 0xbda4(%rip), %rsi      # 0x1294e
xorl %ebx, %ebx
movl $0x1, %edi
movl $0x10, %edx
xorl %eax, %eax
callq 0x3400
leaq 0xbd3f(%rip), %rsi      # 0x12903
leaq 0xa983(%rip), %rdx      # 0x1154e
movl $0x8, %edi
movl $0x3fb, %ecx            # imm = 0x3FB
callq 0xc87f
testb %al, %al
je 0x6c00
leaq 0xbd1e(%rip), %rsi      # 0x12903
leaq 0xa962(%rip), %rdx      # 0x1154e
movl $0x8, %edi
movl $0x3fb, %ecx            # imm = 0x3FB
callq 0xc813
movl %eax, %ebx
andb %bpl, %bl
leaq 0xbd47(%rip), %rsi      # 0x1294e
xorl %r14d, %r14d
movl $0x1, %edi
movl $0x8, %edx
xorl %eax, %eax
callq 0x3400
leaq 0xbce1(%rip), %rsi      # 0x12903
leaq 0xa925(%rip), %rdx      # 0x1154e
movl $0x4, %edi
movl $0x3fd, %ecx            # imm = 0x3FD
callq 0xc87f
testb %al, %al
je 0x6c5f
leaq 0xbcc0(%rip), %rsi      # 0x12903
leaq 0xa904(%rip), %rdx      # 0x1154e
movl $0x4, %edi
movl $0x3fd, %ecx            # imm = 0x3FD
callq 0xc813
movl %eax, %r14d
andb %bl, %r14b
leaq 0xbce8(%rip), %rsi      # 0x1294e
xorl %ebp, %ebp
movl $0x1, %edi
movl $0x4, %edx
xorl %eax, %eax
callq 0x3400
leaq 0xbc83(%rip), %rsi      # 0x12903
leaq 0xa8c7(%rip), %rdx      # 0x1154e
movl $0x2, %edi
movl $0x3ff, %ecx            # imm = 0x3FF
callq 0xc87f
testb %al, %al
je 0x6cbc
leaq 0xbc62(%rip), %rsi      # 0x12903
leaq 0xa8a6(%rip), %rdx      # 0x1154e
movl $0x2, %edi
movl $0x3ff, %ecx            # imm = 0x3FF
callq 0xc813
movl %eax, %ebp
andb %r14b, %bpl
leaq 0xbc8b(%rip), %rsi      # 0x1294e
xorl %ebx, %ebx
movl $0x1, %edi
movl $0x2, %edx
xorl %eax, %eax
callq 0x3400
leaq 0xbc26(%rip), %rsi      # 0x12903
leaq 0xa86a(%rip), %rdx      # 0x1154e
movl $0x1, %edi
movl $0x401, %ecx            # imm = 0x401
callq 0xc87f
testb %al, %al
je 0x6d19
leaq 0xbc05(%rip), %rsi      # 0x12903
leaq 0xa849(%rip), %rdx      # 0x1154e
movl $0x1, %edi
movl $0x401, %ecx            # imm = 0x401
callq 0xc813
movl %eax, %ebx
andb %bpl, %bl
leaq 0xbc2e(%rip), %rsi      # 0x1294e
movl $0x1, %edi
movl $0x1, %edx
xorl %eax, %eax
callq 0x3400
leaq 0xbbcb(%rip), %r14      # 0x12903
leaq 0xa80f(%rip), %r15      # 0x1154e
movl $0xff, %edi
movq %r14, %rsi
movq %r15, %rdx
movl $0x403, %ecx            # imm = 0x403
callq 0xc813
movl %eax, %r12d
leaq 0xbc1e(%rip), %r13      # 0x1297c
movl $0x1, %edi
movq %r13, %rsi
movl $0xff, %edx
xorl %eax, %eax
callq 0x3400
xorl %edi, %edi
movq %r14, %rsi
movq %r15, %rdx
movl $0x405, %ecx            # imm = 0x405
callq 0xc813
movl %eax, %ebp
andb %r12b, %bpl
andb %bl, %bpl
movl $0x1, %edi
movq %r13, %rsi
xorl %edx, %edx
xorl %eax, %eax
callq 0x3400
leaq 0xbc07(%rip), %rax      # 0x129ab
leaq 0xbc3b(%rip), %rsi      # 0x129e6
testb %bpl, %bpl
cmovneq %rax, %rsi
leaq 0xa2fd(%rip), %rax      # 0x110b6
leaq 0xa30f(%rip), %rdx      # 0x110cf
cmovneq %rax, %rdx
movl $0x1, %edi
xorl %eax, %eax
callq 0x3400
leaq 0xbc4a(%rip), %rsi      # 0x12a21
movl $0x1, %edi
xorl %eax, %eax
callq 0x3400
movl $0x8, %ebx
leaq 0xa701(%rip), %r15      # 0x114f0
xorl %r12d, %r12d
movq %r12, 0x10(%rsp)
movb %bpl, 0xb(%rsp)
movl $0x8, %edi
callq 0x403f
cmpl %ebx, %eax
sete %cl
cmpl $0x2, %eax
setb %dl
orb %cl, %dl
jne 0x6dfc
movl %eax, 0xc(%rsp)
movl %eax, %eax
movq %rax, 0x18(%rsp)
xorl %r13d, %r13d
xorl %eax, %eax
xorl %r14d, %r14d
movq %rax, %rbx
movl $0x1, %r12d
movl %r14d, %ebp
notl %ebp
movl $0x8, %edi
callq 0x403f
movl %eax, %eax
cmpq %rax, %rbx
jne 0x6e52
incq %r12
cmpq $0x7, %r12
jb 0x6e36
jmp 0x6e62
testw %bp, (%r15,%rax,2)
jne 0x6e62
incq %r12
cmpq $0x6, %r12
jbe 0x6e36
orw (%r15,%rax,2), %r14w
incq %r13
cmpq 0x18(%rsp), %r13
jne 0x6e28
movzwl %r14w, %r14d
movl %r14d, %edi
leaq 0xba84(%rip), %rsi      # 0x12903
leaq 0xa6c8(%rip), %rdx      # 0x1154e
movl $0x431, %ecx            # imm = 0x431
callq 0xc813
movb 0xb(%rsp), %bpl
andb %al, %bpl
movq 0x10(%rsp), %r12
incq %r12
movl $0xa, %ecx
movl $0x1, %edi
leaq 0xbbad(%rip), %rsi      # 0x12a5e
movq %r12, %rdx
movl 0xc(%rsp), %ebx
movl %ebx, %r8d
movl %r14d, %r9d
xorl %eax, %eax
callq 0x3400
cmpq $0xa, %r12
jne 0x6df2
leaq 0xbbd6(%rip), %rax      # 0x12aac
leaq 0xbc11(%rip), %rsi      # 0x12aee
testb %bpl, %bpl
cmovneq %rax, %rsi
leaq 0xa1e4(%rip), %r12      # 0x110cf
movq %r12, %rdx
leaq 0xa1c1(%rip), %r13      # 0x110b6
cmovneq %r13, %rdx
movl $0x1, %edi
xorl %eax, %eax
callq 0x3400
leaq 0xb88c(%rip), %rsi      # 0x12798
movl $0x1, %edi
xorl %eax, %eax
callq 0x3400
leaq 0xb9e4(%rip), %rbx      # 0x12903
leaq 0xa628(%rip), %r14      # 0x1154e
movl $0xff00, %edi           # imm = 0xFF00
movq %rbx, %rsi
movq %r14, %rdx
movl $0x43b, %ecx            # imm = 0x43B
callq 0xc813
movl %eax, %r15d
leaq 0xbbeb(%rip), %rsi      # 0x12b30
movl $0x1, %edi
movl $0xff00, %edx           # imm = 0xFF00
xorl %eax, %eax
callq 0x3400
movl $0x1337, %edi           # imm = 0x1337
movq %rbx, %rsi
movq %r14, %rdx
movl $0x440, %ecx            # imm = 0x440
callq 0xc87f
movl %eax, %ebx
orb %r15b, %bl
xorb $0x1, %bl
andb %bpl, %bl
leaq 0xbbeb(%rip), %rsi      # 0x12b68
movl $0x1, %edi
movl $0x1337, %edx           # imm = 0x1337
xorl %eax, %eax
callq 0x3400
leaq 0xbc0e(%rip), %rax      # 0x12ba3
leaq 0xbc38(%rip), %rsi      # 0x12bd4
testb $0x1, %bl
cmovneq %rax, %rsi
cmovneq %r13, %r12
movl $0x1, %edi
movq %r12, %rdx
xorl %eax, %eax
callq 0x3400
callq 0x9a36
andb %bl, %al
movzbl %al, %edi
xorl %esi, %esi
callq 0x3b04
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq