// File: /workspace/github_c_makefile_star2_O3/aremmell[P]libsir/tests/tests.c
// Function: roll_and_archive
bool roll_and_archive(const char* filename, const char* extension) {
    /* roll size minus 1KiB so we can write until it maxes. */
    static const long deltasize = 1024L;
    const long fillsize         = SIR_FROLLSIZE - deltasize;

    char logfilename[SIR_MAXPATH] = {0};
    (void)snprintf(logfilename, SIR_MAXPATH, MAKE_LOG_NAME("%s%s"), filename, extension);

    TEST_MSG_0("deleting any stale logs from a previous run...");

    unsigned delcount = 0U;
    if (!enumfiles(SIR_TESTLOGDIR, filename, !cl_cfg.leave_logs, &delcount)) {
        HANDLE_OS_ERROR(false, "failed to enumerate log files with base name: %s!", filename);
        return false;
    }

    if (delcount > 0U)
        TEST_MSG("found and removed %u log file(s)", delcount);

    FILE* f = NULL;
    _sir_fopen(&f, logfilename, "w");

    if (NULL == f)
        return print_test_error(false, false);

    TEST_MSG("filling %s nearly to SIR_FROLLSIZE...", logfilename);

    if (0 != fseek(f, fillsize, SEEK_SET)) {
        HANDLE_OS_ERROR(true, "fseek in file %s failed!", logfilename);
        _sir_safefclose(&f);
        return false;
    }

    if (EOF == fputc('\0', f)) {
        HANDLE_OS_ERROR(true, "fputc in file %s failed!", logfilename);
        _sir_safefclose(&f);
        return false;
    }

    _sir_safefclose(&f);

    INIT(si, 0, 0, 0, 0);
    bool pass = si_init;

    TEST_MSG("adding %s to libsir...", logfilename);

    sirfileid fileid = sir_addfile(logfilename, SIRL_DEBUG, SIRO_MSGONLY | SIRO_NOHDR);
    _sir_eqland(pass, 0U != fileid);

    (void)print_test_error(pass, false);

    if (pass) {
        static const char* line = "hello, i am some data. nice to meet you.";
        TEST_MSG("writing to %s until SIR_FROLLSIZE has been exceeded...", logfilename);

        /* write an (approximately) known quantity until we should have rolled */
        size_t written  = 0;
        size_t linesize = strnlen(line, SIR_MAXMESSAGE);

        do {
            _sir_eqland(pass, sir_debug("%zu %s", written, line));
            written += linesize;
        } while (pass && (written < deltasize + (linesize * 50)));

        TEST_MSG_0("looking for two log files, since it should have been rolled...");

        /* look for files matching the original name. */
        unsigned foundlogs = 0U;
        if (!enumfiles(SIR_TESTLOGDIR, filename, false, &foundlogs)) {
            HANDLE_OS_ERROR(false, "failed to enumerate log files with base name: %s!", filename);
            pass = false;
        }

        /* if two (or more) are present, the test is a pass. */
        TEST_MSG("found %u log files with base name: %s", foundlogs, filename);
        _sir_eqland(pass, foundlogs >= 2U);
    }

    _sir_eqland(pass, sir_remfile(fileid));

    delcount = 0U;
    if (!enumfiles(SIR_TESTLOGDIR, filename, !cl_cfg.leave_logs, &delcount)) {
        HANDLE_OS_ERROR(false, "failed to enumerate log files with base name: %s!", filename);
        pass = false;
    }

    if (delcount > 0U)
        TEST_MSG("found and removed %u log file(s)", delcount);

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1138, %rsp           # imm = 0x1138
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x130(%rsp), %r15
movl $0x1000, %edx           # imm = 0x1000
movq %r15, %rdi
xorl %esi, %esi
callq 0x31f0
movq %r14, (%rsp)
leaq 0xdd59(%rip), %r8       # 0x13048
movl $0x1000, %esi           # imm = 0x1000
movl $0x1000, %ecx           # imm = 0x1000
movq %r15, %rdi
movl $0x1, %edx
movq %rbx, %r9
xorl %eax, %eax
callq 0x3040
leaq 0xf1f5(%rip), %rsi      # 0x14507
movl $0x1, %edi
xorl %eax, %eax
callq 0x3400
leaq 0x14(%rsp), %rcx
movl $0x0, (%rcx)
movzbl 0x165c8(%rip), %edx     # 0x1b8f8
xorl $0x1, %edx
leaq 0xdea8(%rip), %rdi      # 0x131e2
movq %rbx, %rsi
callq 0x417b
testb %al, %al
je 0x541a
movl 0x14(%rsp), %edx
testl %edx, %edx
je 0x5365
leaq 0xf239(%rip), %rsi      # 0x14592
movl $0x1, %edi
xorl %eax, %eax
callq 0x3400
leaq 0x18(%rsp), %r14
movq $0x0, (%r14)
leaq 0xf23d(%rip), %rdx      # 0x145b5
leaq 0x130(%rsp), %rsi
movq %r14, %rdi
callq 0xc98c
cmpq $0x0, (%r14)
je 0x545f
leaq 0xf21e(%rip), %rsi      # 0x145b7
leaq 0x130(%rsp), %rdx
movl $0x1, %edi
xorl %eax, %eax
callq 0x3400
movq 0x18(%rsp), %rdi
movl $0x4ffc00, %esi         # imm = 0x4FFC00
xorl %edx, %edx
callq 0x33e0
testl %eax, %eax
je 0x5466
callq 0x3080
movl (%rax), %edi
leaq 0xf164(%rip), %rsi      # 0x14538
leaq 0xc173(%rip), %rdx      # 0x1154e
movl $0x9aa, %ecx            # imm = 0x9AA
callq 0xa434
leaq 0xf1f3(%rip), %rsi      # 0x145df
xorl %ebp, %ebp
leaq 0x130(%rsp), %rdx
movl $0x1, %edi
xorl %eax, %eax
callq 0x3400
xorl %edi, %edi
xorl %esi, %esi
callq 0x3b6d
leaq 0x18(%rsp), %rdi
callq 0xc5b7
jmp 0x56c1
callq 0x3080
movl (%rax), %edi
leaq 0xf110(%rip), %rsi      # 0x14538
leaq 0xc11f(%rip), %rdx      # 0x1154e
movl $0x99a, %ecx            # imm = 0x99A
callq 0xa434
leaq 0xf109(%rip), %rsi      # 0x14549
xorl %ebp, %ebp
movl $0x1, %edi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3400
xorl %edi, %edi
xorl %esi, %esi
callq 0x3b6d
jmp 0x56c1
xorl %edi, %edi
jmp 0x56b8
movq 0x18(%rsp), %rsi
xorl %edi, %edi
callq 0x3250
cmpl $-0x1, %eax
je 0x5627
leaq 0x18(%rsp), %rdi
callq 0xc5b7
leaq 0x28(%rsp), %r14
xorl %r12d, %r12d
movl $0x108, %edx            # imm = 0x108
movq %r14, %rdi
xorl %esi, %esi
callq 0x31f0
movl $0x100000, %eax         # imm = 0x100000
movl %eax, 0x4(%r14)
movl %eax, 0xc(%r14)
movq %r14, %rdi
callq 0x9a21
movl %eax, %r14d
leaq 0xf184(%rip), %rsi      # 0x1463f
leaq 0x130(%rsp), %r15
movl $0x1, %edi
movq %r15, %rdx
xorl %eax, %eax
callq 0x3400
movq %r15, %rdi
movl $0x80, %esi
movl $0x17f00, %edx          # imm = 0x17F00
callq 0xa035
movl %eax, %ebp
testl %eax, %eax
setne %al
andb %r14b, %al
movzbl %al, %r14d
movl %r14d, %edi
xorl %esi, %esi
callq 0x3b6d
cmpb $0x1, %r14b
jne 0x55f1
leaq 0xf174(%rip), %rsi      # 0x14681
leaq 0x130(%rsp), %rdx
movl $0x1, %edi
xorl %eax, %eax
callq 0x3400
leaq 0xf192(%rip), %r15      # 0x146ba
leaq 0xf129(%rip), %r12      # 0x14658
xorl %r13d, %r13d
movq %r15, %rdi
movq %r13, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x9a45
movl %eax, %r14d
cmpq $0xba7, %r13            # imm = 0xBA7
ja 0x5557
addq $0x28, %r13
testb %r14b, %r14b
jne 0x5532
leaq 0xf163(%rip), %rsi      # 0x146c1
movl $0x1, %edi
xorl %eax, %eax
callq 0x3400
leaq 0x24(%rsp), %rcx
movl $0x0, (%rcx)
leaq 0xdc66(%rip), %rdi      # 0x131e2
movq %rbx, %rsi
xorl %edx, %edx
callq 0x417b
testb %al, %al
jne 0x55cb
callq 0x3080
movl (%rax), %edi
leaq 0xefa0(%rip), %rsi      # 0x14538
leaq 0xbfaf(%rip), %rdx      # 0x1154e
movl $0x9d3, %ecx            # imm = 0x9D3
callq 0xa434
leaq 0xef99(%rip), %rsi      # 0x14549
xorl %r14d, %r14d
movl $0x1, %edi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3400
xorl %edi, %edi
xorl %esi, %esi
callq 0x3b6d
movl 0x24(%rsp), %edx
leaq 0xf12c(%rip), %rsi      # 0x14702
movl $0x1, %edi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x3400
cmpl $0x2, 0x24(%rsp)
setae %r12b
andb %r14b, %r12b
movl %ebp, %edi
callq 0xa03a
movl %eax, %ebp
leaq 0x14(%rsp), %rcx
movl $0x0, (%rcx)
movzbl 0x162ec(%rip), %edx     # 0x1b8f8
xorl $0x1, %edx
leaq 0xdbcc(%rip), %rdi      # 0x131e2
movq %rbx, %rsi
callq 0x417b
testb %al, %al
je 0x5652
andb %r12b, %bpl
jmp 0x5692
callq 0x3080
movl (%rax), %edi
leaq 0xef03(%rip), %rsi      # 0x14538
leaq 0xbf12(%rip), %rdx      # 0x1154e
movl $0x9b0, %ecx            # imm = 0x9B0
callq 0xa434
leaq 0xefc2(%rip), %rsi      # 0x1460f
jmp 0x53ec
callq 0x3080
movl (%rax), %edi
leaq 0xeed8(%rip), %rsi      # 0x14538
leaq 0xbee7(%rip), %rdx      # 0x1154e
movl $0x9e0, %ecx            # imm = 0x9E0
callq 0xa434
leaq 0xeed1(%rip), %rsi      # 0x14549
xorl %ebp, %ebp
movl $0x1, %edi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3400
xorl %edi, %edi
xorl %esi, %esi
callq 0x3b6d
movl 0x14(%rsp), %edx
testl %edx, %edx
je 0x56ad
leaq 0xeef1(%rip), %rsi      # 0x14592
movl $0x1, %edi
xorl %eax, %eax
callq 0x3400
callq 0x9a26
andb %bpl, %al
movzbl %al, %edi
xorl %esi, %esi
callq 0x3b6d
movl %eax, %ebp
movl %ebp, %eax
addq $0x1138, %rsp           # imm = 0x1138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq