// File: /workspace/github_c_makefile_star2_O1/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 0xdd61(%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 0xf1fd(%rip), %rsi      # 0x14507
movl $0x1, %edi
xorl %eax, %eax
callq 0x3400
leaq 0x14(%rsp), %rcx
movl $0x0, (%rcx)
movzbl 0x165d0(%rip), %edx     # 0x1b8f8
xorl $0x1, %edx
leaq 0xdeb0(%rip), %rdi      # 0x131e2
movq %rbx, %rsi
callq 0x412c
testb %al, %al
je 0x5412
movl 0x14(%rsp), %edx
testl %edx, %edx
je 0x535d
leaq 0xf241(%rip), %rsi      # 0x14592
movl $0x1, %edi
xorl %eax, %eax
callq 0x3400
leaq 0x18(%rsp), %r14
movq $0x0, (%r14)
leaq 0xf245(%rip), %rdx      # 0x145b5
leaq 0x130(%rsp), %rsi
movq %r14, %rdi
callq 0xca8b
cmpq $0x0, (%r14)
je 0x5457
leaq 0xf226(%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 0x545e
callq 0x3080
movl (%rax), %edi
leaq 0xf16c(%rip), %rsi      # 0x14538
leaq 0xc17b(%rip), %rdx      # 0x1154e
movl $0x9aa, %ecx            # imm = 0x9AA
callq 0xa444
leaq 0xf1fb(%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 0x3b04
leaq 0x18(%rsp), %rdi
callq 0xc677
jmp 0x56d7
callq 0x3080
movl (%rax), %edi
leaq 0xf118(%rip), %rsi      # 0x14538
leaq 0xc127(%rip), %rdx      # 0x1154e
movl $0x99a, %ecx            # imm = 0x99A
callq 0xa444
leaq 0xf111(%rip), %rsi      # 0x14549
xorl %ebp, %ebp
movl $0x1, %edi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3400
xorl %edi, %edi
xorl %esi, %esi
callq 0x3b04
jmp 0x56d7
xorl %edi, %edi
jmp 0x56ce
movq 0x18(%rsp), %rsi
xorl %edi, %edi
callq 0x3250
cmpl $-0x1, %eax
je 0x563d
leaq 0x18(%rsp), %rdi
callq 0xc677
leaq 0x28(%rsp), %r14
xorl %ebp, %ebp
movl $0x108, %edx            # imm = 0x108
movq %r14, %rdi
xorl %esi, %esi
callq 0x31f0
movl $0x100000, %eax         # imm = 0x100000
movl %eax, 0x4(%r14)
movw %bp, (%r14)
movl %eax, 0xc(%r14)
movw %bp, 0x8(%r14)
movq %r14, %rdi
callq 0x9a31
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 0xa045
movl %eax, %ebp
testl %eax, %eax
setne %r15b
andb %r14b, %r15b
movzbl %r15b, %r14d
movl %r14d, %edi
xorl %esi, %esi
callq 0x3b04
cmpb $0x1, %r14b
jne 0x5607
movl %ebp, 0x24(%rsp)
leaq 0xf16f(%rip), %rsi      # 0x14681
leaq 0x130(%rsp), %rdx
movl $0x1, %edi
xorl %eax, %eax
callq 0x3400
movb $0x1, %r14b
leaq 0xf18a(%rip), %r15      # 0x146ba
leaq 0xf121(%rip), %r12      # 0x14658
xorl %r13d, %r13d
movl %r14d, %ebp
movq %r15, %rdi
movq %r13, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x9a55
movl %eax, %r14d
andb %bpl, %r14b
cmpb $0x1, %r14b
jne 0x5569
leaq 0x28(%r13), %rax
cmpq $0xba8, %r13            # imm = 0xBA8
movq %rax, %r13
jb 0x553a
leaq 0xf151(%rip), %rsi      # 0x146c1
movl $0x1, %edi
xorl %eax, %eax
callq 0x3400
leaq 0x20(%rsp), %rcx
movl $0x0, (%rcx)
leaq 0xdc54(%rip), %rdi      # 0x131e2
movq %rbx, %rsi
xorl %edx, %edx
callq 0x412c
testb %al, %al
jne 0x55dd
callq 0x3080
movl (%rax), %edi
leaq 0xef8e(%rip), %rsi      # 0x14538
leaq 0xbf9d(%rip), %rdx      # 0x1154e
movl $0x9d3, %ecx            # imm = 0x9D3
callq 0xa444
leaq 0xef87(%rip), %rsi      # 0x14549
xorl %r14d, %r14d
movl $0x1, %edi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3400
xorl %edi, %edi
xorl %esi, %esi
callq 0x3b04
movl 0x20(%rsp), %edx
leaq 0xf11a(%rip), %rsi      # 0x14702
movl $0x1, %edi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x3400
cmpl $0x2, 0x20(%rsp)
setae %r15b
andb %r14b, %r15b
movl 0x24(%rsp), %ebp
movl %ebp, %edi
callq 0xa04a
movl %eax, %ebp
leaq 0x14(%rsp), %rcx
movl $0x0, (%rcx)
movzbl 0x162d6(%rip), %edx     # 0x1b8f8
xorl $0x1, %edx
leaq 0xdbb6(%rip), %rdi      # 0x131e2
movq %rbx, %rsi
callq 0x412c
testb %al, %al
je 0x5668
andb %r15b, %bpl
jmp 0x56a8
callq 0x3080
movl (%rax), %edi
leaq 0xeeed(%rip), %rsi      # 0x14538
leaq 0xbefc(%rip), %rdx      # 0x1154e
movl $0x9b0, %ecx            # imm = 0x9B0
callq 0xa444
leaq 0xefac(%rip), %rsi      # 0x1460f
jmp 0x53e4
callq 0x3080
movl (%rax), %edi
leaq 0xeec2(%rip), %rsi      # 0x14538
leaq 0xbed1(%rip), %rdx      # 0x1154e
movl $0x9e0, %ecx            # imm = 0x9E0
callq 0xa444
leaq 0xeebb(%rip), %rsi      # 0x14549
xorl %ebp, %ebp
movl $0x1, %edi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3400
xorl %edi, %edi
xorl %esi, %esi
callq 0x3b04
movl 0x14(%rsp), %edx
testl %edx, %edx
je 0x56c3
leaq 0xeedb(%rip), %rsi      # 0x14592
movl $0x1, %edi
xorl %eax, %eax
callq 0x3400
callq 0x9a36
andb %bpl, %al
movzbl %al, %edi
xorl %esi, %esi
callq 0x3b04
movl %eax, %ebp
movl %ebp, %eax
addq $0x1138, %rsp           # imm = 0x1138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq