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

    size_t numfiles             = SIR_MAXFILES + 1;
    sirfileid ids[SIR_MAXFILES] = {0};

    sir_options even = SIRO_MSGONLY;
    sir_options odd  = SIRO_ALL;

    for (size_t n = 0; n < numfiles - 1; n++) {
        char path[SIR_MAXPATH] = {0};
        (void)snprintf(path, SIR_MAXPATH, MAKE_LOG_NAME("test-%zu.log"), n);
        rmfile(path, cl_cfg.leave_logs);
        ids[n] = sir_addfile(path, SIRL_ALL, (n % 2) ? odd : even);
        _sir_eqland(pass, 0U != ids[n] && sir_info("test %zu", n));
    }

    _sir_eqland(pass, sir_info("test test test"));

    /* this one should fail; max files already added. */
    _sir_eqland(pass, 0U == sir_addfile(MAKE_LOG_NAME("should-fail.log"),
        SIRL_ALL, SIRO_MSGONLY));

    if (pass)
        PRINT_EXPECTED_ERROR();

    _sir_eqland(pass, sir_info("test test test"));

    /* now remove previously added files in a different order. */
    size_t removeorder[SIR_MAXFILES];
    (void)memset(removeorder, -1, sizeof(removeorder));

    long processed = 0L;
    TEST_MSG_0("creating random file ID order...");

    do {
        size_t rnd = (size_t)getrand(SIR_MAXFILES);
        bool skip  = false;

        for (size_t n = 0; n < SIR_MAXFILES; n++)
            if (removeorder[n] == rnd) {
                skip = true;
                break;
            }

        if (skip)
            continue;

        removeorder[processed++] = rnd;

        if (processed == SIR_MAXFILES)
            break;
    } while (true);

    (void)printf("\tremove order: {");
    for (size_t n = 0; n < SIR_MAXFILES; n++)
        (void)printf(" %zu%s", removeorder[n], (n < SIR_MAXFILES - 1) ? "," : "");
    (void)printf(" }..." SIR_EOL);

    for (size_t n = 0; n < SIR_MAXFILES; n++) {
        _sir_eqland(pass, sir_remfile(ids[removeorder[n]]));

        char path[SIR_MAXPATH] = {0};
        (void)snprintf(path, SIR_MAXPATH, MAKE_LOG_NAME("test-%zu.log"), removeorder[n]);
        rmfile(path, cl_cfg.leave_logs);
    }

    _sir_eqland(pass, sir_info("test test test"));

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x11d8, %rsp           # imm = 0x11D8
leaq 0xc8(%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
movl %eax, %ebx
pxor %xmm0, %xmm0
movdqa %xmm0, 0xb0(%rsp)
movdqa %xmm0, 0xa0(%rsp)
movdqa %xmm0, 0x90(%rsp)
movdqa %xmm0, 0x80(%rsp)
leaq 0x1d0(%rsp), %r14
leaq 0xcda6(%rip), %r15      # 0x11a05
movl $0x7f00, %r12d          # imm = 0x7F00
xorl %r13d, %r13d
movl $0x1000, %edx           # imm = 0x1000
movq %r14, %rdi
xorl %esi, %esi
callq 0x31f0
movl $0x1000, %esi           # imm = 0x1000
movl $0x1000, %ecx           # imm = 0x1000
movq %r14, %rdi
movl $0x1, %edx
movq %r15, %r8
movq %r13, %r9
xorl %eax, %eax
callq 0x3040
movzbl 0x16c5b(%rip), %esi     # 0x1b8f8
movq %r14, %rdi
callq 0x4053
testb $0x1, %r13b
movl $0x0, %edx
cmovel %r12d, %edx
movq %r14, %rdi
movl $0xff, %esi
callq 0xa045
movl %eax, 0x80(%rsp,%r13,4)
movl $0x0, %ebp
testl %eax, %eax
je 0x4ce6
leaq 0xcd42(%rip), %rdi      # 0x11a19
movq %r13, %rsi
xorl %eax, %eax
callq 0x9b13
movl %eax, %ebp
andb %bl, %bpl
incq %r13
movl %ebp, %ebx
cmpq $0x10, %r13
jne 0x4c68
leaq 0xcd26(%rip), %rdi      # 0x11a22
xorl %eax, %eax
callq 0x9b13
movl %eax, %ebx
leaq 0xcd25(%rip), %rdi      # 0x11a31
movl $0xff, %esi
movl $0x7f00, %edx           # imm = 0x7F00
callq 0xa045
testl %eax, %eax
sete %al
andb %bpl, %bl
andb %al, %bl
je 0x4d36
movl $0x1, %edi
movl $0x1, %esi
callq 0x3b04
leaq 0xcce5(%rip), %rdi      # 0x11a22
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x9b13
movl %eax, %ebp
pcmpeqd %xmm0, %xmm0
movdqa %xmm0, 0x70(%rsp)
movdqa %xmm0, 0x60(%rsp)
movdqa %xmm0, 0x50(%rsp)
movdqa %xmm0, 0x40(%rsp)
movdqa %xmm0, 0x30(%rsp)
movdqa %xmm0, 0x20(%rsp)
movdqa %xmm0, 0x10(%rsp)
movdqa %xmm0, (%rsp)
leaq 0xccc5(%rip), %rsi      # 0x11a48
movl $0x1, %edi
xorl %eax, %eax
callq 0x3400
movl $0x10, %edi
callq 0x403f
movl %eax, %eax
xorl %ecx, %ecx
cmpq %rax, (%rsp,%rcx,8)
je 0x4dbc
incq %rcx
cmpq $0x10, %rcx
jne 0x4d9d
movq %rax, (%rsp,%r14,8)
incq %r14
cmpq $0x10, %r14
sete %al
jmp 0x4dbe
xorl %eax, %eax
testb %al, %al
je 0x4d8f
leaq 0xcca2(%rip), %rsi      # 0x11a6b
movl $0x1, %edi
xorl %eax, %eax
callq 0x3400
leaq 0xc4eb(%rip), %r15      # 0x112c7
leaq 0xcca0(%rip), %r12      # 0x11a83
leaq 0xcc92(%rip), %r14      # 0x11a7c
xorl %r13d, %r13d
movq (%rsp,%r13,8), %rdx
cmpq $0xf, %r13
movq %r12, %rcx
cmoveq %r15, %rcx
movl $0x1, %edi
movq %r14, %rsi
xorl %eax, %eax
callq 0x3400
incq %r13
cmpq $0x10, %r13
jne 0x4ded
andb %bpl, %bl
leaq 0xcc67(%rip), %rsi      # 0x11a85
movl $0x1, %edi
xorl %eax, %eax
callq 0x3400
leaq 0x1d0(%rsp), %r14
leaq 0xcbcc(%rip), %r15      # 0x11a05
xorl %r12d, %r12d
movq (%rsp,%r12,8), %rax
movl 0x80(%rsp,%rax,4), %edi
callq 0xa04a
andb %al, %bl
movl $0x1000, %edx           # imm = 0x1000
movq %r14, %rdi
xorl %esi, %esi
callq 0x31f0
movq (%rsp,%r12,8), %r9
movl $0x1000, %esi           # imm = 0x1000
movl $0x1000, %ecx           # imm = 0x1000
movq %r14, %rdi
movl $0x1, %edx
movq %r15, %r8
xorl %eax, %eax
callq 0x3040
movzbl 0x16a74(%rip), %esi     # 0x1b8f8
movq %r14, %rdi
callq 0x4053
incq %r12
cmpq $0x10, %r12
jne 0x4e3c
leaq 0xcb86(%rip), %rdi      # 0x11a22
xorl %eax, %eax
callq 0x9b13
movl %eax, %ebp
callq 0x9a36
andb %bpl, %al
andb %bl, %al
movzbl %al, %edi
xorl %esi, %esi
callq 0x3b04
addq $0x11d8, %rsp           # imm = 0x11D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq