// File: /workspace/github_c_makefile_star2_O2/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 0xce65(%rip), %r8       # 0x12008
pushq $0x1
popq %rbp
movl $0x1000, %esi           # imm = 0x1000
movl $0x1000, %ecx           # imm = 0x1000
movq %r15, %rdi
movl %ebp, %edx
movq %rbx, %r9
xorl %eax, %eax
callq 0x3040
leaq 0xe301(%rip), %rsi      # 0x134c7
movl %ebp, %edi
xorl %eax, %eax
callq 0x3410
leaq 0x14(%rsp), %rcx
andl $0x0, (%rcx)
movzbl 0x1672a(%rip), %edx     # 0x1b908
xorl $0x1, %edx
leaq 0xcfba(%rip), %rdi      # 0x121a2
movq %rbx, %rsi
callq 0x4094
testb %al, %al
je 0x52bf
movl 0x14(%rsp), %edx
testl %edx, %edx
je 0x5211
leaq 0xe34b(%rip), %rsi      # 0x13552
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x3410
leaq 0x18(%rsp), %r14
andq $0x0, (%r14)
leaq 0xe354(%rip), %rdx      # 0x13575
leaq 0x130(%rsp), %rsi
movq %r14, %rdi
callq 0xc132
cmpq $0x0, (%r14)
je 0x5302
leaq 0xe335(%rip), %rsi      # 0x13577
pushq $0x1
popq %rdi
leaq 0x130(%rsp), %rdx
xorl %eax, %eax
callq 0x3410
movq 0x18(%rsp), %rdi
movl $0x4ffc00, %esi         # imm = 0x4FFC00
xorl %edx, %edx
callq 0x33f0
testl %eax, %eax
je 0x5309
callq 0x3080
movl (%rax), %edi
leaq 0xe27d(%rip), %rsi      # 0x134f8
leaq 0xb28c(%rip), %rdx      # 0x1050e
movl $0x9aa, %ecx            # imm = 0x9AA
callq 0x9e45
leaq 0xe30c(%rip), %rsi      # 0x1359f
xorl %ebp, %ebp
pushq $0x1
popq %rdi
leaq 0x130(%rsp), %rdx
xorl %eax, %eax
callq 0x3410
xorl %edi, %edi
xorl %esi, %esi
callq 0x3ac9
leaq 0x18(%rsp), %rdi
callq 0xbd03
jmp 0x5550
callq 0x3080
movl (%rax), %edi
leaq 0xe22b(%rip), %rsi      # 0x134f8
leaq 0xb23a(%rip), %rdx      # 0x1050e
movl $0x99a, %ecx            # imm = 0x99A
callq 0x9e45
leaq 0xe224(%rip), %rsi      # 0x13509
xorl %ebp, %ebp
pushq $0x1
popq %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3410
xorl %edi, %edi
xorl %esi, %esi
callq 0x3ac9
jmp 0x5550
xorl %edi, %edi
jmp 0x5547
movq 0x18(%rsp), %rsi
xorl %edi, %edi
callq 0x3250
cmpl $-0x1, %eax
je 0x54ba
leaq 0x18(%rsp), %rdi
callq 0xbd03
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 0x94a9
movl %eax, %r14d
leaq 0xe2a1(%rip), %rsi      # 0x135ff
pushq $0x1
popq %rdi
leaq 0x130(%rsp), %r15
movq %r15, %rdx
xorl %eax, %eax
callq 0x3410
movq %r15, %rdi
movl $0x80, %esi
movl $0x17f00, %edx          # imm = 0x17F00
callq 0x9a6b
movl %eax, %ebp
testl %eax, %eax
setne %al
andb %r14b, %al
movzbl %al, %r14d
movl %r14d, %edi
xorl %esi, %esi
callq 0x3ac9
cmpb $0x1, %r14b
jne 0x5487
leaq 0xe293(%rip), %rsi      # 0x13641
pushq $0x1
popq %rdi
leaq 0x130(%rsp), %rdx
xorl %eax, %eax
callq 0x3410
leaq 0xe2b3(%rip), %r15      # 0x1367a
leaq 0xe24a(%rip), %r12      # 0x13618
xorl %r13d, %r13d
movq %r15, %rdi
movq %r13, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x94cd
movl %eax, %r14d
cmpq $0xba7, %r13            # imm = 0xBA7
ja 0x53f6
addq $0x28, %r13
testb %r14b, %r14b
jne 0x53d1
leaq 0xe284(%rip), %rsi      # 0x13681
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x3410
leaq 0x24(%rsp), %rcx
andl $0x0, (%rcx)
leaq 0xcd8c(%rip), %rdi      # 0x121a2
movq %rbx, %rsi
xorl %edx, %edx
callq 0x4094
testb %al, %al
jne 0x5463
callq 0x3080
movl (%rax), %edi
leaq 0xe0c6(%rip), %rsi      # 0x134f8
leaq 0xb0d5(%rip), %rdx      # 0x1050e
movl $0x9d3, %ecx            # imm = 0x9D3
callq 0x9e45
leaq 0xe0bf(%rip), %rsi      # 0x13509
xorl %r14d, %r14d
pushq $0x1
popq %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3410
xorl %edi, %edi
xorl %esi, %esi
callq 0x3ac9
movl 0x24(%rsp), %edx
leaq 0xe254(%rip), %rsi      # 0x136c2
pushq $0x1
popq %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x3410
cmpl $0x2, 0x24(%rsp)
setae %r12b
andb %r14b, %r12b
movl %ebp, %edi
callq 0x9a70
movl %eax, %ebp
leaq 0x14(%rsp), %rcx
andl $0x0, (%rcx)
movzbl 0x16469(%rip), %edx     # 0x1b908
xorl $0x1, %edx
leaq 0xccf9(%rip), %rdi      # 0x121a2
movq %rbx, %rsi
callq 0x4094
testb %al, %al
je 0x54e5
andb %r12b, %bpl
jmp 0x5523
callq 0x3080
movl (%rax), %edi
leaq 0xe030(%rip), %rsi      # 0x134f8
leaq 0xb03f(%rip), %rdx      # 0x1050e
movl $0x9b0, %ecx            # imm = 0x9B0
callq 0x9e45
leaq 0xe0ef(%rip), %rsi      # 0x135cf
jmp 0x5293
callq 0x3080
movl (%rax), %edi
leaq 0xe005(%rip), %rsi      # 0x134f8
leaq 0xb014(%rip), %rdx      # 0x1050e
movl $0x9e0, %ecx            # imm = 0x9E0
callq 0x9e45
leaq 0xdffe(%rip), %rsi      # 0x13509
xorl %ebp, %ebp
pushq $0x1
popq %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3410
xorl %edi, %edi
xorl %esi, %esi
callq 0x3ac9
movl 0x14(%rsp), %edx
testl %edx, %edx
je 0x553c
leaq 0xe020(%rip), %rsi      # 0x13552
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x3410
callq 0x94ae
andb %bpl, %al
movzbl %al, %edi
xorl %esi, %esi
callq 0x3ac9
movl %eax, %ebp
movl %ebp, %eax
addq $0x1138, %rsp           # imm = 0x1138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq