// File: /workspace/github_c_makefile_star2_O2/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 $0x11e8, %rsp           # imm = 0x11E8
leaq 0xd8(%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
movl %eax, %ebp
pxor %xmm0, %xmm0
movdqa %xmm0, 0xc0(%rsp)
movdqa %xmm0, 0xb0(%rsp)
movdqa %xmm0, 0xa0(%rsp)
movdqa %xmm0, 0x90(%rsp)
leaq 0x1e0(%rsp), %rbx
pushq $0x1
popq %r15
movl $0x7f00, %r14d          # imm = 0x7F00
xorl %r13d, %r13d
cmpq $0x10, %r13
je 0x4be8
xorl %r12d, %r12d
movl $0x1000, %edx           # imm = 0x1000
movq %rbx, %rdi
xorl %esi, %esi
callq 0x31f0
movl $0x1000, %esi           # imm = 0x1000
movl $0x1000, %ecx           # imm = 0x1000
movq %rbx, %rdi
movl %r15d, %edx
leaq 0xbe3e(%rip), %r8       # 0x109c5
movq %r13, %r9
xorl %eax, %eax
callq 0x3040
movzbl 0x16d70(%rip), %esi     # 0x1b908
movq %rbx, %rdi
callq 0x3fbf
testb $0x1, %r13b
movl $0x0, %edx
cmovel %r14d, %edx
movq %rbx, %rdi
movl $0xff, %esi
callq 0x9a6b
movl %eax, 0x90(%rsp,%r13,4)
testl %eax, %eax
je 0x4bdd
leaq 0xbe0c(%rip), %rdi      # 0x109d9
movq %r13, %rsi
xorl %eax, %eax
callq 0x95a2
movl %eax, %r12d
andb %bpl, %r12b
incq %r13
movl %r12d, %ebp
jmp 0x4b54
leaq 0xbdf3(%rip), %rdi      # 0x109e2
xorl %eax, %eax
callq 0x95a2
movl %eax, %ebx
leaq 0xbdf2(%rip), %rdi      # 0x109f1
movl $0xff, %esi
movl $0x7f00, %edx           # imm = 0x7F00
callq 0x9a6b
testl %eax, %eax
sete %al
andb %bpl, %bl
andb %al, %bl
je 0x4c24
pushq $0x1
popq %rdi
movl %edi, %esi
callq 0x3ac9
leaq 0xbdb7(%rip), %rdi      # 0x109e2
xorl %r15d, %r15d
xorl %eax, %eax
callq 0x95a2
movb %al, 0xf(%rsp)
pcmpeqd %xmm0, %xmm0
movdqa %xmm0, 0x80(%rsp)
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)
leaq 0xbd91(%rip), %rsi      # 0x10a08
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x3410
pushq $0x10
popq %r14
movl %r14d, %edi
callq 0x3fab
movl %eax, %eax
xorl %ecx, %ecx
cmpq $0x10, %rcx
je 0x4ca7
leaq 0x1(%rcx), %rdx
cmpq %rax, 0x10(%rsp,%rcx,8)
movq %rdx, %rcx
jne 0x4c91
jmp 0x4c85
movq %rax, 0x10(%rsp,%r15,8)
incq %r15
cmpq $0x10, %r15
jne 0x4c85
leaq 0xbd6f(%rip), %rsi      # 0x10a2b
pushq $0x1
popq %r14
movl %r14d, %edi
xorl %eax, %eax
callq 0x3410
leaq 0xb5f6(%rip), %r12      # 0x102c7
leaq 0xbd6b(%rip), %r13      # 0x10a43
leaq 0xbd5d(%rip), %r15      # 0x10a3c
xorl %ebp, %ebp
cmpq $0x10, %rbp
je 0x4d09
movq 0x10(%rsp,%rbp,8), %rdx
cmpq $0xf, %rbp
movq %r13, %rcx
cmoveq %r12, %rcx
movl %r14d, %edi
movq %r15, %rsi
xorl %eax, %eax
callq 0x3410
incq %rbp
jmp 0x4ce1
andb 0xf(%rsp), %bl
leaq 0xbd31(%rip), %rsi      # 0x10a45
pushq $0x1
popq %rbp
movl %ebp, %edi
xorl %eax, %eax
callq 0x3410
leaq 0x1e0(%rsp), %r14
leaq 0xbc96(%rip), %r15      # 0x109c5
xorl %r13d, %r13d
cmpq $0x10, %r13
je 0x4d8b
movq 0x10(%rsp,%r13,8), %r12
movl 0x90(%rsp,%r12,4), %edi
callq 0x9a70
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 %ebp, %edx
movq %r15, %r8
movq %r12, %r9
xorl %eax, %eax
callq 0x3040
movzbl 0x16b8a(%rip), %esi     # 0x1b908
movq %r14, %rdi
callq 0x3fbf
incq %r13
jmp 0x4d32
leaq 0xbc50(%rip), %rdi      # 0x109e2
xorl %eax, %eax
callq 0x95a2
movl %eax, %ebp
callq 0x94ae
andb %bl, %al
andb %bpl, %al
movzbl %al, %edi
xorl %esi, %esi
callq 0x3ac9
addq $0x11e8, %rsp           # imm = 0x11E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq