// File: /workspace/github_c_makefile_star2_O3/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 $0x128, %rsp            # imm = 0x128
leaq 0x20(%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 0x9a21
movb %al, 0x18(%rsp)
leaq 0xc096(%rip), %rsi      # 0x125a7
movl $0x1, %edi
xorl %eax, %eax
callq 0x3400
leaq 0xc06d(%rip), %r15      # 0x12591
leaq 0xb023(%rip), %r13      # 0x1154e
xorl %edi, %edi
movq %r15, %rsi
movq %r13, %rdx
movl $0x38b, %ecx            # imm = 0x38B
callq 0xc775
movb %al, 0xa(%rsp)
leaq 0xc096(%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 0xc775
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 0xc775
movb %al, 0xc(%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 0xc775
movb %al, 0x10(%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 0xc775
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 0xc775
movb %al, 0xb(%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 0xc775
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 0xaed7(%rip), %rdx      # 0x1154e
movl $0x399, %ecx            # imm = 0x399
callq 0xc775
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 0xaea7(%rip), %rdx      # 0x1154e
movl $0x39b, %ecx            # imm = 0x39B
callq 0xc775
andb %r14b, %al
andb 0xb(%rsp), %r13b
andb %al, %r13b
andb 0x10(%rsp), %bpl
andb 0xc(%rsp), %bpl
andb %r13b, %bpl
andb 0xa(%rsp), %bl
andb 0x18(%rsp), %bl
andb %bpl, %bl
movl $0x1, %edi
movq %r15, %rsi
movl $0x7f00, %edx           # imm = 0x7F00
xorl %eax, %eax
callq 0x3400
leaq 0xbf1e(%rip), %rax      # 0x1260d
leaq 0xbf53(%rip), %rsi      # 0x12649
testb $0x1, %bl
cmovneq %rax, %rsi
leaq 0xa9b2(%rip), %rax      # 0x110b6
leaq 0xa9c4(%rip), %rdx      # 0x110cf
cmovneq %rax, %rdx
movl $0x1, %edi
xorl %eax, %eax
callq 0x3400
leaq 0xbf63(%rip), %rsi      # 0x12685
movl $0x1, %edi
xorl %eax, %eax
callq 0x3400
movl $0x8, %ebp
leaq 0xe696(%rip), %r15      # 0x14dd0
xorl %r12d, %r12d
movq %r12, 0x10(%rsp)
movb %bl, 0xa(%rsp)
movl $0x8, %edi
callq 0x408e
cmpl %ebp, %eax
sete %cl
cmpl $0x2, %eax
setb %dl
orb %cl, %dl
jne 0x6746
movl %eax, 0xc(%rsp)
movl %eax, %eax
movq %rax, 0x18(%rsp)
xorl %ebx, %ebx
xorl %ebp, %ebp
xorl %r14d, %r14d
movl %r14d, %r12d
movl $0x1, %r13d
movl $0x8, %edi
callq 0x408e
movl %eax, %eax
cmpq %rax, %rbp
jne 0x6796
incq %r13
cmpq $0x7, %r13
jb 0x677a
jmp 0x67af
movl (%r15,%rax,4), %r14d
movl %r12d, %ecx
notl %ecx
testl %ecx, %r14d
jne 0x67b6
incq %r13
cmpq $0x6, %r13
jbe 0x677a
jmp 0x67b6
movl (%r15,%rbp,4), %r14d
movq %rbp, %rax
orl %r12d, %r14d
incq %rbx
movq %rax, %rbp
cmpq 0x18(%rsp), %rbx
jne 0x6771
movl %r14d, %edi
leaq 0xbdc1(%rip), %rsi      # 0x12591
leaq 0xad77(%rip), %rdx      # 0x1154e
movl $0x3c7, %ecx            # imm = 0x3C7
callq 0xc775
movb 0xa(%rsp), %bl
andb %al, %bl
movq 0x10(%rsp), %r12
incq %r12
movl $0xa, %ecx
movl $0x1, %edi
leaq 0xbec3(%rip), %rsi      # 0x126c3
movq %r12, %rdx
movl 0xc(%rsp), %ebp
movl %ebp, %r8d
movl %r14d, %r9d
xorl %eax, %eax
callq 0x3400
cmpq $0xa, %r12
jne 0x673d
leaq 0xbeed(%rip), %rax      # 0x12712
leaq 0xbf29(%rip), %rsi      # 0x12755
testb %bl, %bl
cmovneq %rax, %rsi
leaq 0xa896(%rip), %r13      # 0x110cf
movq %r13, %rdx
leaq 0xa873(%rip), %rax      # 0x110b6
cmovneq %rax, %rdx
movl $0x1, %edi
xorl %eax, %eax
callq 0x3400
leaq 0xbf3e(%rip), %rsi      # 0x12798
movl $0x1, %edi
xorl %eax, %eax
callq 0x3400
leaq 0xbd24(%rip), %r14      # 0x12591
leaq 0xacda(%rip), %r15      # 0x1154e
movl $0xff, %edi
movq %r14, %rsi
movq %r15, %rdx
movl $0x3d1, %ecx            # imm = 0x3D1
callq 0xc775
movl %eax, %r12d
leaq 0xbf32(%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 0xc775
movl %eax, %ebp
orb %r12b, %bpl
xorb $0x1, %bpl
andb %bl, %bpl
leaq 0xbf27(%rip), %rsi      # 0x127f3
movl $0x1, %edi
movl $0x8000, %edx           # imm = 0x8000
xorl %eax, %eax
callq 0x3400
movl $0x7f00, %ebx           # imm = 0x7F00
leaq 0xbf3f(%rip), %r12      # 0x12828
addl $0x1000, %ebx           # imm = 0x1000
movl %ebx, %edi
movq %r14, %rsi
movq %r15, %rdx
movl $0x3dc, %ecx            # imm = 0x3DC
callq 0xc775
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 0x68e9
leaq 0xbc6b(%rip), %rsi      # 0x12591
leaq 0xac21(%rip), %rdx      # 0x1154e
movl $0xfffe0000, %edi       # imm = 0xFFFE0000
movl $0x3e2, %ecx            # imm = 0x3E2
callq 0xc775
movl %eax, %ebx
xorb $0x1, %bl
andb %bpl, %bl
leaq 0xbf1a(%rip), %rsi      # 0x12865
movl $0x1, %edi
movl $0xfffe0000, %edx       # imm = 0xFFFE0000
xorl %eax, %eax
callq 0x3400
leaq 0xbf3c(%rip), %rax      # 0x1289f
leaq 0xbf67(%rip), %rsi      # 0x128d1
testb %bl, %bl
cmovneq %rax, %rsi
leaq 0xa73f(%rip), %rax      # 0x110b6
cmovneq %rax, %r13
movl $0x1, %edi
movq %r13, %rdx
xorl %eax, %eax
callq 0x3400
callq 0x9a26
andb %bl, %al
movzbl %al, %edi
xorl %esi, %esi
callq 0x3b6d
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq