// File: /workspace/github_c_makefile_star2_O2/aremmell[P]libsir/src/sirfilecache.c
// Function: sirfile_roll
bool _sirfile_roll(sirfile* sf, char** newpath) {
    if (!_sirfile_validate(sf) || !_sir_validptrptr(newpath))
        return false;

    bool retval = false;
    char* name = NULL;
    char* ext  = NULL;

    bool split = _sirfile_splitpath(sf, &name, &ext);
    SIR_ASSERT(split);

    if (split) {
        time_t now = -1;

        (void)time(&now);
        SIR_ASSERT(-1 != now);

        if (-1 != now) {
            char timestamp[SIR_MAXTIME] = {0};
            bool fmttime = _sir_formattime(now, timestamp, SIR_FNAMETIMEFORMAT);
            SIR_ASSERT(fmttime);

            if (fmttime) {
                *newpath = (char*)calloc(SIR_MAXPATH, sizeof(char));

                if (_sir_validptr(*newpath)) {
                    char seqbuf[7] = {0};
                    bool exists = false;
                    bool resolved = false;
                    uint16_t sequence = 0U;

                    do {
                        (void)snprintf(*newpath, SIR_MAXPATH, SIR_FNAMEFORMAT, name,
                            timestamp, (sequence > 0U ? seqbuf : ""),
                            _sir_validstrnofail(ext) ? ext : "");

                        /* if less than one second has elapsed since the last roll
                         * operation, then we'll overwrite the last rolled log file,
                         * and that = data loss. make sure the target path does not
                         * already exist. */
                        if (!_sir_pathexists(*newpath, &exists, SIR_PATH_REL_TO_CWD)) {
                            /* failed to determine if the file already exists; it is better
                             * to continue logging to the same file than to possibly overwrite
                             * another (if it failed this time, it will again, so there's no
                             * way to definitively choose a good new path). */
                            break;
                        } else if (exists) {
                            /* the file already exists; add a number to the file name
                             * until one that does not exist is found. */
                            _sir_selflog("path: '%s' already exists; incrementing sequence", *newpath); //-V576
                            sequence++;
                        } else {
                            _sir_selflog("found good path: '%s'", *newpath);
                            resolved = true;
                            break;
                        }

                        if (sequence > 0)
                            (void)snprintf(seqbuf, 7, SIR_FNAMESEQFORMAT, sequence);

                    } while (sequence <= 999U);

                    if (!resolved)
                        _sir_selflog("error: unable to determine suitable path for '%s';"
                                        " not rolling!", sf->path);

                    retval = resolved && _sirfile_archive(sf, *newpath);
                }
            }
        }
    }

    _sir_safefree(&name);
    _sir_safefree(&ext);

    return retval;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rsi, %r14
movq %rdi, %rbx
callq 0x3c66
testb %al, %al
je 0x421d
leaq 0x581b(%rip), %rsi      # 0x98bf
movq %r14, %rdi
movl $0xc7, %edx
callq 0x4257
testb %al, %al
je 0x421d
leaq 0x20(%rsp), %rsi
andq $0x0, (%rsi)
leaq 0x18(%rsp), %rdx
andq $0x0, (%rdx)
movq %rbx, %rdi
callq 0x427b
testb %al, %al
je 0x4221
leaq 0x28(%rsp), %r15
orq $-0x1, (%r15)
movq %r15, %rdi
callq 0x22b0
movq (%r15), %rdi
cmpq $-0x1, %rdi
je 0x4221
xorps %xmm0, %xmm0
leaq 0x30(%rsp), %rsi
movaps %xmm0, 0x30(%rsi)
movaps %xmm0, 0x20(%rsi)
movaps %xmm0, 0x10(%rsi)
movaps %xmm0, (%rsi)
leaq 0x57b6(%rip), %rdx      # 0x98cd
callq 0x3f6e
testb %al, %al
je 0x4221
pushq $0x1
popq %rsi
movl $0x1000, %edi           # imm = 0x1000
callq 0x2220
movq %rax, (%r14)
leaq 0x5784(%rip), %rdx      # 0x98bf
pushq $0x1
popq %r13
movq %rax, %rdi
movl %r13d, %esi
movl $0xdf, %ecx
callq 0x3cb7
testb %al, %al
je 0x4221
leaq 0x10(%rsp), %rax
andl $0x0, 0x3(%rax)
andl $0x0, (%rax)
leaq 0xf(%rsp), %rax
movb $0x0, (%rax)
leaq 0x5739(%rip), %r15      # 0x98ab
movl %r13d, %r12d
cmpl $0x1, %r12d
leaq 0x10(%rsp), %r10
cmoveq %r15, %r10
movq 0x18(%rsp), %rax
movq %r15, %r11
testq %rax, %rax
je 0x4199
cmpb $0x0, (%rax)
cmoveq %r15, %rax
movq %rax, %r11
movq (%r14), %rdi
movq 0x20(%rsp), %r9
subq $0x8, %rsp
xorl %ebp, %ebp
movl $0x1000, %esi           # imm = 0x1000
movl %r13d, %edx
pushq $-0x1
popq %rcx
leaq 0x5724(%rip), %r8       # 0x98dd
xorl %eax, %eax
pushq %r11
pushq %r10
leaq 0x48(%rsp), %r10
pushq %r10
callq 0x2040
addq $0x20, %rsp
movq (%r14), %rdi
leaq 0xf(%rsp), %rsi
movl %r13d, %edx
callq 0x4ba8
testb %al, %al
je 0x4223
cmpb $0x0, 0xf(%rsp)
je 0x4248
xorl %ebp, %ebp
leaq 0x10(%rsp), %rdi
pushq $0x7
popq %rcx
movq %rcx, %rsi
movl %r13d, %edx
leaq 0x56e6(%rip), %r8       # 0x98e7
movl %r12d, %r9d
xorl %eax, %eax
callq 0x2040
incl %r12d
cmpl $0x3e9, %r12d           # imm = 0x3E9
jne 0x4175
jmp 0x4223
xorl %ebp, %ebp
jmp 0x4237
xorl %ebp, %ebp
leaq 0x20(%rsp), %rdi
callq 0x5098
leaq 0x18(%rsp), %rdi
callq 0x5098
movl %ebp, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r14), %rsi
movq %rbx, %rdi
callq 0x4442
movl %eax, %ebp
jmp 0x4223