static int replace_int_data_in_filename(char *buf, int buf_size, const char *filename, char placeholder, int64_t number)

{

    const char *p;

    char *q, buf1[20], c;

    int nd, len, addchar_count;

    int found_count = 0;



    q = buf;

    p = filename;

    for (;;) {

        c = *p;

        if (c == '\0')

            break;

        if (c == '%' && *(p+1) == '%')  // %%

            addchar_count = 2;

        else if (c == '%' && (av_isdigit(*(p+1)) || *(p+1) == placeholder)) {

            nd = 0;

            addchar_count = 1;

            while (av_isdigit(*(p + addchar_count))) {

                nd = nd * 10 + *(p + addchar_count) - '0';

                addchar_count++;

            }



            if (*(p + addchar_count) == placeholder) {

                len = snprintf(buf1, sizeof(buf1), "%0*"PRId64, (number < 0) ? nd : nd++, number);

                if (len < 1)  // returned error or empty buf1

                    goto fail;

                if ((q - buf + len) > buf_size - 1)

                    goto fail;

                memcpy(q, buf1, len);

                q += len;

                p += (addchar_count + 1);

                addchar_count = 0;

                found_count++;

            }



        } else

            addchar_count = 1;



        while (addchar_count--)

            if ((q - buf) < buf_size - 1)

                *q++ = *p++;

            else

                goto fail;

    }

    *q = '\0';

    return found_count;

fail:

    *q = '\0';

    return -1;

}

static int replace_int_data_in_filename(char *buf, int buf_size, const char *filename, char placeholder, int64_t number)

{

    const char *p;

    char *q, buf1[20], c;

    int nd, len, addchar_count;

    int found_count = 0;



    q = buf;

    p = filename;

    for (;;) {

        c = *p;

        if (c == '\0')

            break;

        if (c == '%' && *(p+1) == '%')  

            addchar_count = 2;

        else if (c == '%' && (av_isdigit(*(p+1)) || *(p+1) == placeholder)) {

            nd = 0;

            addchar_count = 1;

            while (av_isdigit(*(p + addchar_count))) {

                nd = nd * 10 + *(p + addchar_count) - '0';

                addchar_count++;

            }



            if (*(p + addchar_count) == placeholder) {

                len = snprintf(buf1, sizeof(buf1), "%0*"PRId64, (number < 0) ? nd : nd++, number);

                if (len < 1)  

                    goto fail;

                if ((q - buf + len) > buf_size - 1)

                    goto fail;

                memcpy(q, buf1, len);

                q += len;

                p += (addchar_count + 1);

                addchar_count = 0;

                found_count++;

            }



        } else

            addchar_count = 1;



        while (addchar_count--)

            if ((q - buf) < buf_size - 1)

                *q++ = *p++;

            else

                goto fail;

    }

    *q = '\0';

    return found_count;

fail:

    *q = '\0';

    return -1;

}

static int FUNC_0(char *VAR_0, int VAR_1, const char *VAR_2, char VAR_3, int64_t VAR_4)

{

    const char *VAR_5;

    char *VAR_6, VAR_7[20], VAR_8;

    int VAR_9, VAR_10, VAR_11;

    int VAR_12 = 0;



    VAR_6 = VAR_0;

    VAR_5 = VAR_2;

    for (;;) {

        VAR_8 = *VAR_5;

        if (VAR_8 == '\0')

            break;

        if (VAR_8 == '%' && *(VAR_5+1) == '%')  

            VAR_11 = 2;

        else if (VAR_8 == '%' && (av_isdigit(*(VAR_5+1)) || *(VAR_5+1) == VAR_3)) {

            VAR_9 = 0;

            VAR_11 = 1;

            while (av_isdigit(*(VAR_5 + VAR_11))) {

                VAR_9 = VAR_9 * 10 + *(VAR_5 + VAR_11) - '0';

                VAR_11++;

            }



            if (*(VAR_5 + VAR_11) == VAR_3) {

                VAR_10 = snprintf(VAR_7, sizeof(VAR_7), "%0*"PRId64, (VAR_4 < 0) ? VAR_9 : VAR_9++, VAR_4);

                if (VAR_10 < 1)  

                    goto fail;

                if ((VAR_6 - VAR_0 + VAR_10) > VAR_1 - 1)

                    goto fail;

                memcpy(VAR_6, VAR_7, VAR_10);

                VAR_6 += VAR_10;

                VAR_5 += (VAR_11 + 1);

                VAR_11 = 0;

                VAR_12++;

            }



        } else

            VAR_11 = 1;



        while (VAR_11--)

            if ((VAR_6 - VAR_0) < VAR_1 - 1)

                *VAR_6++ = *VAR_5++;

            else

                goto fail;

    }

    *VAR_6 = '\0';

    return VAR_12;

fail:

    *VAR_6 = '\0';

    return -1;

}

static int FUNC_0(char *VAR_0, int VAR_1, const char *VAR_2, char VAR_3, int64_t VAR_4)
{ const char *VAR_5; char *VAR_6, VAR_7[20], VAR_8; int VAR_9, VAR_10, VAR_11; int VAR_12 = 0; VAR_6 = VAR_0; VAR_5 = VAR_2; for (;;) { VAR_8 = *VAR_5; if (VAR_8 == '\0')
break; if (VAR_8 == '%' && *(VAR_5+1) == '%')
VAR_11 = 2; else if (VAR_8 == '%' && (av_isdigit(*(VAR_5+1)) || *(VAR_5+1) == VAR_3)) { VAR_9 = 0; VAR_11 = 1; while (av_isdigit(*(VAR_5 + VAR_11))) { VAR_9 = VAR_9 * 10 + *(VAR_5 + VAR_11) - '0'; VAR_11++; } if (*(VAR_5 + VAR_11) == VAR_3) { VAR_10 = snprintf(VAR_7, sizeof(VAR_7), "%0*"PRId64, (VAR_4 < 0) ? VAR_9 : VAR_9++, VAR_4); if (VAR_10 < 1)
goto fail; if ((VAR_6 - VAR_0 + VAR_10) > VAR_1 - 1)
goto fail; memcpy(VAR_6, VAR_7, VAR_10); VAR_6 += VAR_10; VAR_5 += (VAR_11 + 1); VAR_11 = 0; VAR_12++; } } else VAR_11 = 1; while (VAR_11--)
if ((VAR_6 - VAR_0) < VAR_1 - 1)
*VAR_6++ = *VAR_5++; else
goto fail; } *VAR_6 = '\0'; return VAR_12; fail:
*VAR_6 = '\0'; return -1; }