// File: /workspace/github_c_makefile_star2_O0/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:
subq $0xd8, %rsp
movq %rdi, 0xc8(%rsp)
movq %rsi, 0xc0(%rsp)
movq 0xc8(%rsp), %rdi
callq 0x5100
testb $0x1, %al
jne 0x58ba
jmp 0x58e4
movq 0xc0(%rsp), %rdi
movl $0x1, %esi
leaq 0xb06f(%rip), %rdx      # 0x1093d
leaq 0xafa8(%rip), %rcx      # 0x1087d
movl $0xc7, %r8d
callq 0x5c30
testb $0x1, %al
jne 0x58f1
movb $0x0, 0xd7(%rsp)
jmp 0x5c1e
movb $0x0, 0xbf(%rsp)
movq $0x0, 0xb0(%rsp)
movq $0x0, 0xa8(%rsp)
movq 0xc8(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
leaq 0xa8(%rsp), %rdx
callq 0x5ca0
andb $0x1, %al
movb %al, 0xa7(%rsp)
testb $0x1, 0xa7(%rsp)
je 0x5bf4
movq $-0x1, 0x98(%rsp)
leaq 0x98(%rsp), %rdi
callq 0x22d0
movq $-0x1, %rax
cmpq 0x98(%rsp), %rax
je 0x5bf2
leaq 0x50(%rsp), %rdi
xorl %esi, %esi
movl $0x40, %edx
callq 0x21c0
movq 0x98(%rsp), %rdi
leaq 0x50(%rsp), %rsi
leaq 0xafb3(%rip), %rdx      # 0x1094b
callq 0x56d0
andb $0x1, %al
movb %al, 0x4f(%rsp)
testb $0x1, 0x4f(%rsp)
je 0x5bf0
movl $0x1000, %edi           # imm = 0x1000
movl $0x1, %esi
callq 0x2230
movq %rax, %rcx
movq 0xc0(%rsp), %rax
movq %rcx, (%rax)
movq 0xc0(%rsp), %rax
movq (%rax), %rdi
movl $0x1, %esi
leaq 0xaf5b(%rip), %rdx      # 0x1093d
leaq 0xae94(%rip), %rcx      # 0x1087d
movl $0xdf, %r8d
callq 0x5200
testb $0x1, %al
jne 0x59fd
jmp 0x5bee
leaq 0x48(%rsp), %rdi
xorl %esi, %esi
movl $0x7, %edx
callq 0x21c0
movb $0x0, 0x47(%rsp)
movb $0x0, 0x46(%rsp)
movw $0x0, 0x44(%rsp)
movq 0xc0(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x28(%rsp)
movq 0xb0(%rsp), %rax
movq %rax, 0x30(%rsp)
leaq 0x50(%rsp), %rax
movq %rax, 0x38(%rsp)
movzwl 0x44(%rsp), %eax
cmpl $0x0, %eax
jbe 0x5a5c
leaq 0x48(%rsp), %rax
movq %rax, 0x20(%rsp)
jmp 0x5a6a
leaq 0xaec6(%rip), %rax      # 0x10929
movq %rax, 0x20(%rsp)
jmp 0x5a6a
movq 0x20(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0xa8(%rsp), %rdi
xorl %esi, %esi
leaq 0xaeb8(%rip), %rdx      # 0x1093d
leaq 0xadf1(%rip), %rcx      # 0x1087d
movl $0xe8, %r8d
callq 0x4f70
testb $0x1, %al
jne 0x5a9d
jmp 0x5aac
movq 0xa8(%rsp), %rax
movq %rax, 0x10(%rsp)
jmp 0x5aba
leaq 0xae76(%rip), %rax      # 0x10929
movq %rax, 0x10(%rsp)
jmp 0x5aba
movq 0x18(%rsp), %r9
movq 0x38(%rsp), %r8
movq 0x30(%rsp), %rcx
movq 0x28(%rsp), %rdi
movq 0x10(%rsp), %rax
movl $0x1000, %esi           # imm = 0x1000
leaq 0xae7c(%rip), %rdx      # 0x1095b
movq %rax, (%rsp)
movb $0x0, %al
callq 0x2170
movq 0xc0(%rsp), %rax
movq (%rax), %rdi
leaq 0x47(%rsp), %rsi
movl $0x1, %edx
callq 0x7010
testb $0x1, %al
jne 0x5b0d
jmp 0x5b98
testb $0x1, 0x47(%rsp)
je 0x5b3d
movq 0xc0(%rsp), %rax
movq (%rax), %rsi
leaq 0xae3f(%rip), %rdi      # 0x10965
movb $0x0, %al
callq 0x5ff0
movw 0x44(%rsp), %ax
addw $0x1, %ax
movw %ax, 0x44(%rsp)
jmp 0x5b5d
movq 0xc0(%rsp), %rax
movq (%rax), %rsi
leaq 0xae47(%rip), %rdi      # 0x10996
movb $0x0, %al
callq 0x5ff0
movb $0x1, 0x46(%rsp)
jmp 0x5b98
jmp 0x5b5f
movzwl 0x44(%rsp), %eax
cmpl $0x0, %eax
jle 0x5b86
leaq 0x48(%rsp), %rdi
movzwl 0x44(%rsp), %ecx
movl $0x7, %esi
leaq 0xae2d(%rip), %rdx      # 0x109ac
movb $0x0, %al
callq 0x2170
jmp 0x5b88
movzwl 0x44(%rsp), %eax
cmpl $0x3e7, %eax            # imm = 0x3E7
jbe 0x5a1f
testb $0x1, 0x46(%rsp)
jne 0x5bb8
movq 0xc8(%rsp), %rax
movq (%rax), %rsi
leaq 0xae00(%rip), %rdi      # 0x109b1
movb $0x0, %al
callq 0x5ff0
xorl %eax, %eax
testb $0x1, 0x46(%rsp)
movb %al, 0xf(%rsp)
je 0x5be1
movq 0xc8(%rsp), %rdi
movq 0xc0(%rsp), %rax
movq (%rax), %rsi
callq 0x6000
movb %al, 0xf(%rsp)
movb 0xf(%rsp), %al
andb $0x1, %al
movb %al, 0xbf(%rsp)
jmp 0x5bf0
jmp 0x5bf2
jmp 0x5bf4
leaq 0xb0(%rsp), %rdi
callq 0x7910
leaq 0xa8(%rsp), %rdi
callq 0x7910
movb 0xbf(%rsp), %al
andb $0x1, %al
movb %al, 0xd7(%rsp)
movb 0xd7(%rsp), %al
andb $0x1, %al
addq $0xd8, %rsp
retq
nop