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

    static const size_t iterations = 10;

    /*
     * TODO(aremmell): Update printf -> TEST_MSG,
     * rename INDENT_ITEM to BULLETED_ITEM.
     */

    /* these should all be valid. */
    TEST_MSG_0(SIR_WHITEB("--- individual valid options ---"));
    _sir_eqland(pass, _sir_validopts(SIRO_ALL));
    (void)printf(INDENT_ITEM SIR_WHITE("valid option: %08"PRIx32) SIR_EOL, SIRO_ALL);
    _sir_eqland(pass, _sir_validopts(SIRO_NOTIME));
    (void)printf(INDENT_ITEM SIR_WHITE("valid option: %08"PRIx32) SIR_EOL, SIRO_NOTIME);
    _sir_eqland(pass, _sir_validopts(SIRO_NOHOST));
    (void)printf(INDENT_ITEM SIR_WHITE("valid option: %08"PRIx32) SIR_EOL, SIRO_NOHOST);
    _sir_eqland(pass, _sir_validopts(SIRO_NOLEVEL));
    (void)printf(INDENT_ITEM SIR_WHITE("valid option: %08"PRIx32) SIR_EOL, SIRO_NOLEVEL);
    _sir_eqland(pass, _sir_validopts(SIRO_NONAME));
    (void)printf(INDENT_ITEM SIR_WHITE("valid option: %08"PRIx32) SIR_EOL, SIRO_NONAME);
    _sir_eqland(pass, _sir_validopts(SIRO_NOPID));
    (void)printf(INDENT_ITEM SIR_WHITE("valid option: %08"PRIx32) SIR_EOL, SIRO_NOPID);
    _sir_eqland(pass, _sir_validopts(SIRO_NOTID));
    (void)printf(INDENT_ITEM SIR_WHITE("valid option: %08"PRIx32) SIR_EOL, SIRO_NOTID);
    _sir_eqland(pass, _sir_validopts(SIRO_NOHDR));
    (void)printf(INDENT_ITEM SIR_WHITE("valid option: %08"PRIx32) SIR_EOL, SIRO_NOHDR);
    _sir_eqland(pass, _sir_validopts(SIRO_MSGONLY));
    (void)printf(INDENT_ITEM SIR_WHITE("valid option: %08"PRIx32) SIR_EOL, SIRO_MSGONLY);
    PASSFAIL_MSG(pass, "\t--- individual valid options: %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_option option_arr[SIR_NUMOPTIONS] = {
        SIRO_NOTIME,
        SIRO_NOHOST,
        SIRO_NOLEVEL,
        SIRO_NONAME,
        SIRO_NOMSEC,
        SIRO_NOPID,
        SIRO_NOTID,
        SIRO_NOHDR
    };

    TEST_MSG_0(SIR_WHITEB("--- random bitmask of valid options ---"));
    uint32_t last_count = SIR_NUMOPTIONS;
    for (size_t n = 0; n < iterations; n++) {
        sir_options opts    = 0;
        uint32_t rand_count = 0;
        size_t last_idx     = 0;

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

        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_NUMOPTIONS - 2)
                    break;
                rand_idx = (size_t)getrand(SIR_NUMOPTIONS);
            } while (rand_idx == last_idx || _sir_bittest(opts, option_arr[rand_idx]));

            last_idx = rand_idx;
            opts |= option_arr[rand_idx];
        }

        _sir_eqland(pass, _sir_validopts(opts));
        (void)printf(INDENT_ITEM SIR_WHITE("(%zu/%zu): random valid (count: %"PRIu32
            ", options: %08"PRIx32")") SIR_EOL, n + 1, iterations, rand_count, opts);
    }
    PASSFAIL_MSG(pass, "\t--- random bitmask of valid options: %s ---" SIR_EOL SIR_EOL, PRN_PASS(pass));

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

    /* the lowest byte is not valid. */
    sir_options invalid = 0x000000ff;
    _sir_eqland(pass, !_sir_validopts(invalid));
    (void)printf(INDENT_ITEM SIR_WHITE("lowest byte: %08"PRIx32) SIR_EOL, invalid);

    /* gaps in between valid options. */
    invalid = 0x0001ff00U & ~(SIRO_NOTIME | SIRO_NOHOST | SIRO_NOLEVEL | SIRO_NONAME |
                             SIRO_NOMSEC | SIRO_NOPID | SIRO_NOTID  | SIRO_NOHDR);
    _sir_eqland(pass, !_sir_validopts(invalid));
    (void)printf(INDENT_ITEM SIR_WHITE("gaps in 0x001ff00U: %08"PRIx32) SIR_EOL, invalid);

    /* greater than SIRO_MSGONLY and less than SIRO_NOHDR. */
    for (sir_option o = 0x00008f00U; o < SIRO_NOHDR; o += 0x1000U) {
        _sir_eqland(pass, !_sir_validopts(o));
        (void)printf(INDENT_ITEM SIR_WHITE("SIRO_MSGONLY >< SIRO_NOHDR: %08"PRIx32) SIR_EOL, o);
    }

    /* greater than SIRO_NOHDR. */
    invalid = (0xFFFF0000 & ~SIRO_NOHDR);
    _sir_eqland(pass, !_sir_validopts(invalid));
    (void)printf(INDENT_ITEM SIR_WHITE("greater than SIRO_NOHDR: %08"PRIx32) SIR_EOL, invalid);

    PASSFAIL_MSG(pass, "\t--- invalid values: %s ---" SIR_EOL 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 $0x118, %rsp            # imm = 0x118
leaq 0x10(%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
movb %al, 0x1(%rsp)
leaq 0xc043(%rip), %rsi      # 0x125a7
movl $0x1, %edi
xorl %eax, %eax
callq 0x3400
leaq 0xc01a(%rip), %r15      # 0x12591
leaq 0xafd0(%rip), %r13      # 0x1154e
xorl %edi, %edi
movq %r15, %rsi
movq %r13, %rdx
movl $0x38b, %ecx            # imm = 0x38B
callq 0xc84c
movb %al, 0x4(%rsp)
leaq 0xc043(%rip), %r14      # 0x125de
movl $0x1, %edi
movq %r14, %rsi
xorl %edx, %edx
xorl %eax, %eax
callq 0x3400
movl $0x100, %edi            # imm = 0x100
movq %r15, %rsi
movq %r13, %rdx
movl $0x38d, %ecx            # imm = 0x38D
callq 0xc84c
movl %eax, %ebx
movl $0x1, %edi
movq %r14, %rsi
movl $0x100, %edx            # imm = 0x100
xorl %eax, %eax
callq 0x3400
movl $0x400, %edi            # imm = 0x400
movq %r15, %rsi
movq %r13, %rdx
movl $0x38f, %ecx            # imm = 0x38F
callq 0xc84c
movb %al, 0x8(%rsp)
movl $0x1, %edi
movq %r14, %rsi
movl $0x400, %edx            # imm = 0x400
xorl %eax, %eax
callq 0x3400
movl $0x800, %edi            # imm = 0x800
movq %r15, %rsi
movq %r13, %rdx
movl $0x391, %ecx            # imm = 0x391
callq 0xc84c
movb %al, 0x3(%rsp)
movl $0x1, %edi
movq %r14, %rsi
movl $0x800, %edx            # imm = 0x800
xorl %eax, %eax
callq 0x3400
movl $0x1000, %edi           # imm = 0x1000
movq %r15, %rsi
movq %r13, %rdx
movl $0x393, %ecx            # imm = 0x393
callq 0xc84c
movl %eax, %ebp
movl $0x1, %edi
movq %r14, %rsi
movl $0x1000, %edx           # imm = 0x1000
xorl %eax, %eax
callq 0x3400
movl $0x2000, %edi           # imm = 0x2000
movq %r15, %rsi
movq %r13, %rdx
movl $0x395, %ecx            # imm = 0x395
callq 0xc84c
movb %al, 0x2(%rsp)
movl $0x1, %edi
movq %r14, %rsi
movl $0x2000, %edx           # imm = 0x2000
xorl %eax, %eax
callq 0x3400
movl $0x4000, %edi           # imm = 0x4000
movq %r15, %rsi
movq %r15, %r12
movq %r13, %rdx
movl $0x397, %ecx            # imm = 0x397
callq 0xc84c
movl %eax, %r13d
movl $0x1, %edi
movq %r14, %rsi
movq %r14, %r15
movl $0x4000, %edx           # imm = 0x4000
xorl %eax, %eax
callq 0x3400
movl $0x10000, %edi          # imm = 0x10000
movq %r12, %rsi
leaq 0xae84(%rip), %rdx      # 0x1154e
movl $0x399, %ecx            # imm = 0x399
callq 0xc84c
movl %eax, %r14d
movl $0x1, %edi
movq %r15, %rsi
movl $0x10000, %edx          # imm = 0x10000
xorl %eax, %eax
callq 0x3400
movl $0x7f00, %edi           # imm = 0x7F00
movq %r12, %rsi
leaq 0xae54(%rip), %rdx      # 0x1154e
movl $0x39b, %ecx            # imm = 0x39B
callq 0xc84c
andb %r14b, %al
andb 0x2(%rsp), %r13b
andb %al, %r13b
andb 0x3(%rsp), %bpl
andb 0x8(%rsp), %bpl
andb %r13b, %bpl
andb 0x4(%rsp), %bl
andb 0x1(%rsp), %bl
andb %bpl, %bl
movl $0x1, %edi
movq %r15, %rsi
movl $0x7f00, %edx           # imm = 0x7F00
xorl %eax, %eax
callq 0x3400
leaq 0xbecb(%rip), %rax      # 0x1260d
leaq 0xbf00(%rip), %rsi      # 0x12649
testb $0x1, %bl
cmovneq %rax, %rsi
leaq 0xa95f(%rip), %rax      # 0x110b6
leaq 0xa971(%rip), %rdx      # 0x110cf
cmovneq %rax, %rdx
movl $0x1, %edi
xorl %eax, %eax
callq 0x3400
leaq 0xbf10(%rip), %rsi      # 0x12685
movl $0x1, %edi
xorl %eax, %eax
callq 0x3400
movl $0x8, %ebp
leaq 0xe643(%rip), %r15      # 0x14dd0
xorl %r12d, %r12d
movq %r12, 0x8(%rsp)
movb %bl, 0x1(%rsp)
movl $0x8, %edi
callq 0x403f
cmpl %ebp, %eax
sete %cl
cmpl $0x2, %eax
setb %dl
orb %cl, %dl
jne 0x6799
movl %eax, 0x4(%rsp)
movl %eax, %r13d
xorl %ebx, %ebx
xorl %eax, %eax
xorl %r14d, %r14d
movq %rax, %r12
movl $0x1, %ebp
movl $0x8, %edi
callq 0x403f
movl %eax, %eax
cmpq %rax, %r12
jne 0x67e4
incq %rbp
cmpq $0x7, %rbp
jb 0x67c8
jmp 0x67f8
movl %r14d, %ecx
notl %ecx
testl %ecx, (%r15,%rax,4)
jne 0x67f8
incq %rbp
cmpq $0x6, %rbp
jbe 0x67c8
orl (%r15,%rax,4), %r14d
incq %rbx
cmpq %r13, %rbx
jne 0x67c0
movl %r14d, %edi
leaq 0xbd83(%rip), %rsi      # 0x12591
leaq 0xad39(%rip), %rdx      # 0x1154e
movl $0x3c7, %ecx            # imm = 0x3C7
callq 0xc84c
movb 0x1(%rsp), %bl
andb %al, %bl
movq 0x8(%rsp), %r12
incq %r12
movl $0xa, %ecx
movl $0x1, %edi
leaq 0xbe85(%rip), %rsi      # 0x126c3
movq %r12, %rdx
movl 0x4(%rsp), %ebp
movl %ebp, %r8d
movl %r14d, %r9d
xorl %eax, %eax
callq 0x3400
cmpq $0xa, %r12
jne 0x6790
leaq 0xbeaf(%rip), %rax      # 0x12712
leaq 0xbeeb(%rip), %rsi      # 0x12755
testb %bl, %bl
cmovneq %rax, %rsi
leaq 0xa858(%rip), %r13      # 0x110cf
movq %r13, %rdx
leaq 0xa835(%rip), %rax      # 0x110b6
cmovneq %rax, %rdx
movl $0x1, %edi
xorl %eax, %eax
callq 0x3400
leaq 0xbf00(%rip), %rsi      # 0x12798
movl $0x1, %edi
xorl %eax, %eax
callq 0x3400
leaq 0xbce6(%rip), %r14      # 0x12591
leaq 0xac9c(%rip), %r15      # 0x1154e
movl $0xff, %edi
movq %r14, %rsi
movq %r15, %rdx
movl $0x3d1, %ecx            # imm = 0x3D1
callq 0xc84c
movl %eax, %r12d
leaq 0xbef4(%rip), %rsi      # 0x127c5
movl $0x1, %edi
movl $0xff, %edx
xorl %eax, %eax
callq 0x3400
movl $0x8000, %edi           # imm = 0x8000
movq %r14, %rsi
movq %r15, %rdx
movl $0x3d7, %ecx            # imm = 0x3D7
callq 0xc84c
movl %eax, %ebp
orb %r12b, %bpl
xorb $0x1, %bpl
andb %bl, %bpl
leaq 0xbee9(%rip), %rsi      # 0x127f3
movl $0x1, %edi
movl $0x8000, %edx           # imm = 0x8000
xorl %eax, %eax
callq 0x3400
movl $0x7f00, %ebx           # imm = 0x7F00
leaq 0xbf01(%rip), %r12      # 0x12828
addl $0x1000, %ebx           # imm = 0x1000
movl %ebx, %edi
movq %r14, %rsi
movq %r15, %rdx
movl $0x3dc, %ecx            # imm = 0x3DC
callq 0xc84c
xorb $0x1, %al
andb %al, %bpl
movl $0x1, %edi
movq %r12, %rsi
movl %ebx, %edx
xorl %eax, %eax
callq 0x3400
cmpl $0xf000, %ebx           # imm = 0xF000
jb 0x6927
leaq 0xbc2d(%rip), %rsi      # 0x12591
leaq 0xabe3(%rip), %rdx      # 0x1154e
movl $0xfffe0000, %edi       # imm = 0xFFFE0000
movl $0x3e2, %ecx            # imm = 0x3E2
callq 0xc84c
movl %eax, %ebx
xorb $0x1, %bl
andb %bpl, %bl
leaq 0xbedc(%rip), %rsi      # 0x12865
movl $0x1, %edi
movl $0xfffe0000, %edx       # imm = 0xFFFE0000
xorl %eax, %eax
callq 0x3400
leaq 0xbefe(%rip), %rax      # 0x1289f
leaq 0xbf29(%rip), %rsi      # 0x128d1
testb %bl, %bl
cmovneq %rax, %rsi
leaq 0xa701(%rip), %rax      # 0x110b6
cmovneq %rax, %r13
movl $0x1, %edi
movq %r13, %rdx
xorl %eax, %eax
callq 0x3400
callq 0x9a36
andb %bl, %al
movzbl %al, %edi
xorl %esi, %esi
callq 0x3b04
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq