// File: /workspace/github_c_makefile_star2_O2/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 0x94a9
movb %al, 0x18(%rsp)
leaq 0xb1e9(%rip), %rsi      # 0x11567
pushq $0x1
popq %rbp
movl %ebp, %edi
xorl %eax, %eax
callq 0x3410
leaq 0xb1c0(%rip), %r13      # 0x11551
leaq 0xa176(%rip), %r15      # 0x1050e
xorl %edi, %edi
movq %r13, %rsi
movq %r15, %rdx
movl $0x38b, %ecx            # imm = 0x38B
callq 0xbed6
movb %al, 0x10(%rsp)
leaq 0xb1e9(%rip), %r14      # 0x1159e
movl %ebp, %edi
movq %r14, %rsi
xorl %edx, %edx
xorl %eax, %eax
callq 0x3410
movl $0x100, %edi            # imm = 0x100
movq %r13, %rsi
movq %r15, %rdx
movl $0x38d, %ecx            # imm = 0x38D
callq 0xbed6
movl %eax, %ebx
movl %ebp, %edi
movq %r14, %rsi
movl $0x100, %edx            # imm = 0x100
xorl %eax, %eax
callq 0x3410
movl $0x400, %edi            # imm = 0x400
movq %r13, %rsi
movq %r15, %rdx
movl $0x38f, %ecx            # imm = 0x38F
callq 0xbed6
movb %al, 0x8(%rsp)
movl %ebp, %edi
movq %r14, %rsi
movl $0x400, %edx            # imm = 0x400
xorl %eax, %eax
callq 0x3410
movl $0x800, %edi            # imm = 0x800
movq %r13, %rsi
movq %r15, %rdx
movl $0x391, %ecx            # imm = 0x391
callq 0xbed6
movb %al, 0x6(%rsp)
movl %ebp, %edi
movq %r14, %rsi
movl $0x800, %edx            # imm = 0x800
xorl %eax, %eax
callq 0x3410
movl $0x1000, %edi           # imm = 0x1000
movq %r13, %rsi
movq %r15, %rdx
movq %r15, %r12
movl $0x393, %ecx            # imm = 0x393
callq 0xbed6
movl %eax, %r15d
movl %ebp, %edi
movq %r14, %rsi
movl $0x1000, %edx           # imm = 0x1000
xorl %eax, %eax
callq 0x3410
movl $0x2000, %edi           # imm = 0x2000
movq %r13, %rsi
movq %r12, %rdx
movq %r12, %r13
movl $0x395, %ecx            # imm = 0x395
callq 0xbed6
movb %al, 0x7(%rsp)
movl %ebp, %edi
movq %r14, %rsi
movq %r14, %rbp
movl $0x2000, %edx           # imm = 0x2000
xorl %eax, %eax
callq 0x3410
movl $0x4000, %edi           # imm = 0x4000
leaq 0xb0aa(%rip), %rsi      # 0x11551
movq %rsi, %r12
movq %r13, %rdx
movl $0x397, %ecx            # imm = 0x397
callq 0xbed6
movl %eax, %r14d
pushq $0x1
popq %rdi
movq %rbp, %rsi
movq %rbp, %r13
movl $0x4000, %edx           # imm = 0x4000
xorl %eax, %eax
callq 0x3410
movl $0x10000, %edi          # imm = 0x10000
movq %r12, %rsi
leaq 0xa030(%rip), %rdx      # 0x1050e
movl $0x399, %ecx            # imm = 0x399
callq 0xbed6
movl %eax, %ebp
pushq $0x1
popq %rdi
movq %r13, %rsi
movl $0x10000, %edx          # imm = 0x10000
xorl %eax, %eax
callq 0x3410
movl $0x7f00, %edi           # imm = 0x7F00
movq %r12, %rsi
leaq 0xa003(%rip), %rdx      # 0x1050e
movl $0x39b, %ecx            # imm = 0x39B
callq 0xbed6
andb %bpl, %al
andb 0x7(%rsp), %r14b
andb %al, %r14b
andb 0x6(%rsp), %r15b
andb 0x8(%rsp), %r15b
andb %r14b, %r15b
andb 0x10(%rsp), %bl
andb 0x18(%rsp), %bl
andb %r15b, %bl
pushq $0x1
popq %rbp
movl %ebp, %edi
movq %r13, %rsi
movl $0x7f00, %edx           # imm = 0x7F00
xorl %eax, %eax
callq 0x3410
leaq 0xb07a(%rip), %rax      # 0x115cd
leaq 0xb0af(%rip), %rsi      # 0x11609
movb %bl, 0x6(%rsp)
testb $0x1, %bl
cmovneq %rax, %rsi
leaq 0x9b4a(%rip), %rax      # 0x100b6
leaq 0x9b5c(%rip), %rdx      # 0x100cf
cmovneq %rax, %rdx
movl %ebp, %edi
xorl %eax, %eax
callq 0x3410
leaq 0xb0be(%rip), %rsi      # 0x11645
movl %ebp, %edi
xorl %eax, %eax
callq 0x3410
pushq $0x8
popq %r13
leaq 0xd7f5(%rip), %rbx      # 0x13d90
movl %r13d, %r14d
xorl %r15d, %r15d
cmpq $0xa, %r15
je 0x666d
movl %r13d, %edi
callq 0x3fab
movl %eax, %ebp
cmpl %r14d, %eax
sete %al
cmpl $0x2, %ebp
setb %cl
orb %al, %cl
jne 0x65ab
movq %r15, 0x8(%rsp)
movl %ebp, %eax
movq %rax, 0x10(%rsp)
xorl %r12d, %r12d
xorl %r15d, %r15d
xorl %ecx, %ecx
cmpq 0x10(%rsp), %rcx
je 0x6621
movq %rcx, 0x18(%rsp)
pushq $0x6
popq %r14
xorl %eax, %eax
subq $0x1, %r14
jb 0x660e
movl %r13d, %edi
callq 0x3fab
movl %eax, %eax
cmpq %rax, %r15
je 0x65eb
movl (%rbx,%rax,4), %ecx
movl %r12d, %edx
notl %edx
testl %edx, %ecx
je 0x65eb
jmp 0x6611
movl (%rbx,%rax,4), %ecx
orl %ecx, %r12d
movq 0x18(%rsp), %rcx
incq %rcx
movq %rax, %r15
jmp 0x65d9
movl %r12d, %edi
leaq 0xaf26(%rip), %rsi      # 0x11551
leaq 0x9edc(%rip), %rdx      # 0x1050e
movl $0x3c7, %ecx            # imm = 0x3C7
callq 0xbed6
andb %al, 0x6(%rsp)
movq 0x8(%rsp), %r15
incq %r15
pushq $0x1
popq %rdi
leaq 0xb031(%rip), %rsi      # 0x11683
movq %r15, %rdx
pushq $0xa
popq %rcx
movl %ebp, %r8d
movl %r12d, %r9d
xorl %eax, %eax
callq 0x3410
movl %ebp, %r14d
jmp 0x65a1
leaq 0xb05e(%rip), %rax      # 0x116d2
leaq 0xb09a(%rip), %rsi      # 0x11715
movb 0x6(%rsp), %bl
testb $0x1, %bl
cmovneq %rax, %rsi
leaq 0x9a42(%rip), %rdx      # 0x100cf
leaq 0x9a22(%rip), %rax      # 0x100b6
cmovneq %rax, %rdx
pushq $0x1
popq %rbp
movl %ebp, %edi
xorl %eax, %eax
callq 0x3410
leaq 0xb0ad(%rip), %rsi      # 0x11758
movl %ebp, %edi
xorl %eax, %eax
callq 0x3410
leaq 0xae96(%rip), %r14      # 0x11551
leaq 0x9e4c(%rip), %r15      # 0x1050e
movl $0xff, %edi
movq %r14, %rsi
movq %r15, %rdx
movl $0x3d1, %ecx            # imm = 0x3D1
callq 0xbed6
movl %eax, %r13d
leaq 0xb0a4(%rip), %rsi      # 0x11785
movl %ebp, %edi
movl $0xff, %edx
xorl %eax, %eax
callq 0x3410
movl $0x8000, %edi           # imm = 0x8000
movq %r14, %rsi
movq %r15, %rdx
movl $0x3d7, %ecx            # imm = 0x3D7
callq 0xbed6
movl %eax, %r12d
orb %r13b, %r12b
xorb $0x1, %r12b
andb %bl, %r12b
leaq 0xb09b(%rip), %rsi      # 0x117b3
movl %ebp, %edi
movl $0x8000, %edx           # imm = 0x8000
xorl %eax, %eax
callq 0x3410
movl $0x8f00, %ebx           # imm = 0x8F00
leaq 0xb0b6(%rip), %r13      # 0x117e8
cmpl $0x10000, %ebx          # imm = 0x10000
jae 0x6767
movl %ebx, %edi
movq %r14, %rsi
movq %r15, %rdx
movl $0x3dc, %ecx            # imm = 0x3DC
callq 0xbed6
xorb $0x1, %al
andb %al, %r12b
movl %ebp, %edi
movq %r13, %rsi
movl %ebx, %edx
xorl %eax, %eax
callq 0x3410
addl $0x1000, %ebx           # imm = 0x1000
jmp 0x6732
leaq 0xade3(%rip), %rsi      # 0x11551
leaq 0x9d99(%rip), %rdx      # 0x1050e
movl $0xfffe0000, %edi       # imm = 0xFFFE0000
movl $0x3e2, %ecx            # imm = 0x3E2
callq 0xbed6
movl %eax, %ebx
xorb $0x1, %bl
andb %r12b, %bl
leaq 0xb092(%rip), %rsi      # 0x11825
pushq $0x1
popq %rbp
movl %ebp, %edi
movl $0xfffe0000, %edx       # imm = 0xFFFE0000
xorl %eax, %eax
callq 0x3410
leaq 0xb0b4(%rip), %rax      # 0x1185f
leaq 0xb0df(%rip), %rsi      # 0x11891
testb %bl, %bl
cmovneq %rax, %rsi
leaq 0x9910(%rip), %rdx      # 0x100cf
leaq 0x98f0(%rip), %rax      # 0x100b6
cmovneq %rax, %rdx
movl %ebp, %edi
xorl %eax, %eax
callq 0x3410
callq 0x94ae
andb %bl, %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