// File: /workspace/github_c_makefile_star2_O3/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)
movq %rbx, %rdi
callq 0x9a21
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 0xcd7d(%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 0x16c32(%rip), %esi     # 0x1b8f8
movq %r14, %rdi
callq 0x40a2
testb $0x1, %r13b
movl $0x0, %edx
cmovel %r12d, %edx
movq %r14, %rdi
movl $0xff, %esi
callq 0xa035
movl %eax, 0x80(%rsp,%r13,4)
movl $0x0, %ebp
testl %eax, %eax
je 0x4d0f
leaq 0xcd19(%rip), %rdi      # 0x11a19
movq %r13, %rsi
xorl %eax, %eax
callq 0x9b03
movl %eax, %ebp
andb %bl, %bpl
incq %r13
movl %ebp, %ebx
cmpq $0x10, %r13
jne 0x4c91
leaq 0xccfd(%rip), %rdi      # 0x11a22
xorl %eax, %eax
callq 0x9b03
movl %eax, %ebx
leaq 0xccfc(%rip), %rdi      # 0x11a31
movl $0xff, %esi
movl $0x7f00, %edx           # imm = 0x7F00
callq 0xa035
testl %eax, %eax
sete %al
andb %bpl, %bl
andb %al, %bl
je 0x4d5f
movl $0x1, %edi
movl $0x1, %esi
callq 0x3b6d
leaq 0xccbc(%rip), %rdi      # 0x11a22
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x9b03
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 0xcc9c(%rip), %rsi      # 0x11a48
movl $0x1, %edi
xorl %eax, %eax
callq 0x3400
movl $0x10, %edi
callq 0x408e
movl %eax, %eax
xorl %ecx, %ecx
cmpq %rax, (%rsp,%rcx,8)
je 0x4db8
incq %rcx
cmpq $0x10, %rcx
jne 0x4dc6
movq %rax, (%rsp,%r14,8)
incq %r14
cmpq $0x10, %r14
jne 0x4db8
leaq 0xcc82(%rip), %rsi      # 0x11a6b
movl $0x1, %edi
xorl %eax, %eax
callq 0x3400
leaq 0xc4cb(%rip), %r15      # 0x112c7
leaq 0xcc80(%rip), %r12      # 0x11a83
leaq 0xcc72(%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 0x4e0d
andb %bpl, %bl
leaq 0xcc47(%rip), %rsi      # 0x11a85
movl $0x1, %edi
xorl %eax, %eax
callq 0x3400
leaq 0x1d0(%rsp), %r14
leaq 0xcbac(%rip), %r15      # 0x11a05
xorl %r13d, %r13d
movq (%rsp,%r13,8), %r12
movl 0x80(%rsp,%r12,4), %edi
callq 0xa03a
andb %al, %bl
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 %r12, %r9
xorl %eax, %eax
callq 0x3040
movzbl 0x16a54(%rip), %esi     # 0x1b8f8
movq %r14, %rdi
callq 0x40a2
incq %r13
cmpq $0x10, %r13
jne 0x4e5c
leaq 0xcb66(%rip), %rdi      # 0x11a22
xorl %eax, %eax
callq 0x9b03
movl %eax, %ebp
callq 0x9a26
andb %bpl, %al
andb %bl, %al
movzbl %al, %edi
xorl %esi, %esi
callq 0x3b6d
addq $0x11d8, %rsp           # imm = 0x11D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq