// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x1168, %rsp           # imm = 0x1168
movq %rdi, 0x1158(%rsp)
movq %rsi, 0x1150(%rsp)
movq $0x4ffc00, 0x1148(%rsp) # imm = 0x4FFC00
leaq 0x140(%rsp), %rdi
xorl %esi, %esi
movl $0x1000, %edx           # imm = 0x1000
callq 0x4210
leaq 0x140(%rsp), %rdi
movq 0x1158(%rsp), %rcx
movq 0x1150(%rsp), %r8
movl $0x1000, %esi           # imm = 0x1000
leaq 0x17802(%rip), %rdx     # 0x1f1ad
movb $0x0, %al
callq 0x41b0
leaq 0x18d43(%rip), %rdi     # 0x206fc
movb $0x0, %al
callq 0x4180
movl $0x0, 0x13c(%rsp)
movq 0x1158(%rsp), %rsi
movb 0x20fdf(%rip), %al      # 0x289b8
xorb $-0x1, %al
movzbl %al, %edx
andl $0x1, %edx
leaq 0x1795f(%rip), %rdi     # 0x1f347
leaq 0x13c(%rsp), %rcx
callq 0x5660
testb $0x1, %al
jne 0x7a46
jmp 0x79fb
callq 0x4070
movl (%rax), %edi
leaq 0x18d24(%rip), %rsi     # 0x2072d
leaq 0x15b1d(%rip), %rdx     # 0x1d52d
movl $0x99a, %ecx            # imm = 0x99A
callq 0x10780
movq 0x1158(%rsp), %rsi
leaq 0x18d15(%rip), %rdi     # 0x2073e
movb $0x0, %al
callq 0x4180
xorl %esi, %esi
movl %esi, %edi
callq 0x4da0
movb $0x0, 0x1167(%rsp)
jmp 0x7f28
cmpl $0x0, 0x13c(%rsp)
jbe 0x7a65
movl 0x13c(%rsp), %esi
leaq 0x18d29(%rip), %rdi     # 0x20787
movb $0x0, %al
callq 0x4180
movq $0x0, 0x130(%rsp)
leaq 0x140(%rsp), %rsi
leaq 0x130(%rsp), %rdi
leaq 0x18d22(%rip), %rdx     # 0x207aa
callq 0x152b0
xorl %eax, %eax
cmpq 0x130(%rsp), %rax
jne 0x7ab0
xorl %esi, %esi
movl %esi, %edi
callq 0x4da0
andb $0x1, %al
movb %al, 0x1167(%rsp)
jmp 0x7f28
leaq 0x140(%rsp), %rsi
leaq 0x18ced(%rip), %rdi     # 0x207ac
movb $0x0, %al
callq 0x4180
movq 0x130(%rsp), %rdi
movl $0x4ffc00, %esi         # imm = 0x4FFC00
xorl %edx, %edx
callq 0x4420
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x7b3c
jmp 0x7ae4
callq 0x4070
movl (%rax), %edi
leaq 0x18c3b(%rip), %rsi     # 0x2072d
leaq 0x15a34(%rip), %rdx     # 0x1d52d
movl $0x9aa, %ecx            # imm = 0x9AA
callq 0x10780
leaq 0x140(%rsp), %rsi
leaq 0x18cc2(%rip), %rdi     # 0x207d4
movb $0x0, %al
callq 0x4180
xorl %esi, %esi
movl %esi, %edi
callq 0x4da0
leaq 0x130(%rsp), %rdi
callq 0x14530
movb $0x0, 0x1167(%rsp)
jmp 0x7f28
movq 0x130(%rsp), %rsi
xorl %edi, %edi
callq 0x4270
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %eax
jne 0x7bb0
jmp 0x7b58
callq 0x4070
movl (%rax), %edi
leaq 0x18bc7(%rip), %rsi     # 0x2072d
leaq 0x159c0(%rip), %rdx     # 0x1d52d
movl $0x9b0, %ecx            # imm = 0x9B0
callq 0x10780
leaq 0x140(%rsp), %rsi
leaq 0x18c7e(%rip), %rdi     # 0x20804
movb $0x0, %al
callq 0x4180
xorl %esi, %esi
movl %esi, %edi
callq 0x4da0
leaq 0x130(%rsp), %rdi
callq 0x14530
movb $0x0, 0x1167(%rsp)
jmp 0x7f28
leaq 0x130(%rsp), %rdi
callq 0x14530
leaq 0x28(%rsp), %rdi
xorl %esi, %esi
movl $0x108, %edx            # imm = 0x108
callq 0x4210
movl $0x100000, 0x2c(%rsp)   # imm = 0x100000
movw $0x0, 0x28(%rsp)
movl $0x100000, 0x34(%rsp)   # imm = 0x100000
movw $0x0, 0x30(%rsp)
leaq 0x156d4(%rip), %rdi     # 0x1d2c7
xorl %esi, %esi
leaq 0x18b31(%rip), %rdx     # 0x2072d
leaq 0x1592a(%rip), %rcx     # 0x1d52d
movl $0x9b7, %r8d            # imm = 0x9B7
callq 0x5ce0
testb $0x1, %al
jne 0x7c14
jmp 0x7c34
leaq 0x28(%rsp), %rdi
addq $0xe8, %rdi
movl $0x20, %ecx
leaq 0x1569b(%rip), %rdx     # 0x1d2c7
movq %rcx, %rsi
callq 0x14f50
movb $0x0, 0x27(%rsp)
leaq 0x28(%rsp), %rdi
callq 0xf560
andb $0x1, %al
movb %al, 0x27(%rsp)
movb 0x27(%rsp), %al
andb $0x1, %al
movb %al, 0x26(%rsp)
leaq 0x140(%rsp), %rsi
leaq 0x18bd2(%rip), %rdi     # 0x20834
movb $0x0, %al
callq 0x4180
leaq 0x140(%rsp), %rdi
movl $0x80, %esi
movl $0x17f00, %edx          # imm = 0x17F00
callq 0xfee0
movl %eax, 0x20(%rsp)
xorl %eax, %eax
xorl %ecx, %ecx
cmpl 0x20(%rsp), %ecx
movb %al, 0xb(%rsp)
je 0x7c9a
movb 0x26(%rsp), %al
movb %al, 0xb(%rsp)
movb 0xb(%rsp), %al
andb $0x1, %al
movb %al, 0x26(%rsp)
movb 0x26(%rsp), %al
xorl %esi, %esi
andb $0x1, %al
movzbl %al, %edi
callq 0x4da0
testb $0x1, 0x26(%rsp)
je 0x7e22
leaq 0x140(%rsp), %rsi
leaq 0x18ba8(%rip), %rdi     # 0x20876
movb $0x0, %al
callq 0x4180
movq $0x0, 0x18(%rsp)
movq 0x20a4b(%rip), %rdi     # 0x28730
movl $0x1000, %esi           # imm = 0x1000
callq 0x4230
movq %rax, 0x10(%rsp)
movq 0x18(%rsp), %rsi
movq 0x20a30(%rip), %rdx     # 0x28730
leaq 0x18ba8(%rip), %rdi     # 0x208af
movb $0x0, %al
callq 0xf5f0
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, 0xa(%rsp)
jne 0x7d1d
jmp 0x7d25
movb 0x26(%rsp), %al
movb %al, 0xa(%rsp)
movb 0xa(%rsp), %al
andb $0x1, %al
movb %al, 0x26(%rsp)
movq 0x10(%rsp), %rax
addq 0x18(%rsp), %rax
movq %rax, 0x18(%rsp)
xorl %eax, %eax
testb $0x1, 0x26(%rsp)
movb %al, 0x9(%rsp)
je 0x7d67
movq 0x18(%rsp), %rax
imulq $0x32, 0x10(%rsp), %rcx
addq $0x400, %rcx            # imm = 0x400
cmpq %rcx, %rax
setb %al
movb %al, 0x9(%rsp)
movb 0x9(%rsp), %al
testb $0x1, %al
jne 0x7cf4
leaq 0x18b40(%rip), %rdi     # 0x208b6
movb $0x0, %al
callq 0x4180
movl $0x0, 0xc(%rsp)
movq 0x1158(%rsp), %rsi
leaq 0x175b3(%rip), %rdi     # 0x1f347
xorl %edx, %edx
leaq 0xc(%rsp), %rcx
callq 0x5660
testb $0x1, %al
jne 0x7de9
jmp 0x7da6
callq 0x4070
movl (%rax), %edi
leaq 0x18979(%rip), %rsi     # 0x2072d
leaq 0x15772(%rip), %rdx     # 0x1d52d
movl $0x9d3, %ecx            # imm = 0x9D3
callq 0x10780
movq 0x1158(%rsp), %rsi
leaq 0x1896a(%rip), %rdi     # 0x2073e
movb $0x0, %al
callq 0x4180
xorl %esi, %esi
movl %esi, %edi
callq 0x4da0
movb $0x0, 0x26(%rsp)
movl 0xc(%rsp), %esi
movq 0x1158(%rsp), %rdx
leaq 0x18afb(%rip), %rdi     # 0x208f7
movb $0x0, %al
callq 0x4180
xorl %eax, %eax
cmpl $0x2, 0xc(%rsp)
movb %al, 0x8(%rsp)
jb 0x7e18
movb 0x26(%rsp), %al
movb %al, 0x8(%rsp)
movb 0x8(%rsp), %al
andb $0x1, %al
movb %al, 0x26(%rsp)
movl 0x20(%rsp), %edi
callq 0xff10
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, 0x7(%rsp)
jne 0x7e3a
jmp 0x7e42
movb 0x26(%rsp), %al
movb %al, 0x7(%rsp)
movb 0x7(%rsp), %al
andb $0x1, %al
movb %al, 0x26(%rsp)
movl $0x0, 0x13c(%rsp)
movq 0x1158(%rsp), %rsi
movb 0x20b53(%rip), %al      # 0x289b8
xorb $-0x1, %al
movzbl %al, %edx
andl $0x1, %edx
leaq 0x174d3(%rip), %rdi     # 0x1f347
leaq 0x13c(%rsp), %rcx
callq 0x5660
testb $0x1, %al
jne 0x7eca
jmp 0x7e87
callq 0x4070
movl (%rax), %edi
leaq 0x18898(%rip), %rsi     # 0x2072d
leaq 0x15691(%rip), %rdx     # 0x1d52d
movl $0x9e0, %ecx            # imm = 0x9E0
callq 0x10780
movq 0x1158(%rsp), %rsi
leaq 0x18889(%rip), %rdi     # 0x2073e
movb $0x0, %al
callq 0x4180
xorl %esi, %esi
movl %esi, %edi
callq 0x4da0
movb $0x0, 0x26(%rsp)
cmpl $0x0, 0x13c(%rsp)
jbe 0x7ee9
movl 0x13c(%rsp), %esi
leaq 0x188a5(%rip), %rdi     # 0x20787
movb $0x0, %al
callq 0x4180
callq 0xf580
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, 0x6(%rsp)
jne 0x7efd
jmp 0x7f05
movb 0x26(%rsp), %al
movb %al, 0x6(%rsp)
movb 0x6(%rsp), %al
andb $0x1, %al
movb %al, 0x26(%rsp)
movb 0x26(%rsp), %al
xorl %esi, %esi
andb $0x1, %al
movzbl %al, %edi
callq 0x4da0
andb $0x1, %al
movb %al, 0x1167(%rsp)
movb 0x1167(%rsp), %al
andb $0x1, %al
addq $0x1168, %rsp           # imm = 0x1168
retq
nopl (%rax)