int av_parse_time(int64_t *timeval, const char *timestr, int duration)

{

    const char *p;

    int64_t t;

    struct tm dt = { 0 };

    int i;

    static const char * const date_fmt[] = {

        "%Y-%m-%d",

        "%Y%m%d",

    };

    static const char * const time_fmt[] = {

        "%H:%M:%S",

        "%H%M%S",

    };

    const char *q;

    int is_utc, len;

    char lastch;

    int negative = 0;



#undef time

    time_t now = time(0);



    len = strlen(timestr);

    if (len > 0)

        lastch = timestr[len - 1];

    else

        lastch = '\0';

    is_utc = (lastch == 'z' || lastch == 'Z');



    p = timestr;

    q = NULL;

    if (!duration) {

        if (!av_strncasecmp(timestr, "now", len)) {

            *timeval = (int64_t) now * 1000000;

            return 0;

        }



        /* parse the year-month-day part */

        for (i = 0; i < FF_ARRAY_ELEMS(date_fmt); i++) {

            q = small_strptime(p, date_fmt[i], &dt);

            if (q) {

                break;

            }

        }



        /* if the year-month-day part is missing, then take the

         * current year-month-day time */

        if (!q) {

            if (is_utc) {

                dt = *gmtime(&now);

            } else {

                dt = *localtime(&now);

            }

            dt.tm_hour = dt.tm_min = dt.tm_sec = 0;

        } else {

            p = q;

        }



        if (*p == 'T' || *p == 't' || *p == ' ')

            p++;



        /* parse the hour-minute-second part */

        for (i = 0; i < FF_ARRAY_ELEMS(time_fmt); i++) {

            q = small_strptime(p, time_fmt[i], &dt);

            if (q) {

                break;

            }

        }

    } else {

        /* parse timestr as a duration */

        if (p[0] == '-') {

            negative = 1;

            ++p;

        }

        /* parse timestr as HH:MM:SS */

        q = small_strptime(p, time_fmt[0], &dt);

        if (!q) {

            /* parse timestr as S+ */

            dt.tm_sec = strtol(p, (void *)&q, 10);

            if (q == p) {

                /* the parsing didn't succeed */

                *timeval = INT64_MIN;

                return AVERROR(EINVAL);

            }

            dt.tm_min = 0;

            dt.tm_hour = 0;

        }

    }



    /* Now we have all the fields that we can get */

    if (!q) {

        *timeval = INT64_MIN;

        return AVERROR(EINVAL);

    }



    if (duration) {

        t = dt.tm_hour * 3600 + dt.tm_min * 60 + dt.tm_sec;

    } else {

        dt.tm_isdst = -1;       /* unknown */

        if (is_utc) {

            t = av_timegm(&dt);

        } else {

            t = mktime(&dt);

        }

    }



    t *= 1000000;



    /* parse the .m... part */

    if (*q == '.') {

        int val, n;

        q++;

        for (val = 0, n = 100000; n >= 1; n /= 10, q++) {

            if (!isdigit(*q))

                break;

            val += n * (*q - '0');

        }

        t += val;

    }

    *timeval = negative ? -t : t;

    return 0;

}

int av_parse_time(int64_t *timeval, const char *timestr, int duration)

{

    const char *p;

    int64_t t;

    struct tm dt = { 0 };

    int i;

    static const char * const date_fmt[] = {

        "%Y-%m-%d",

        "%Y%m%d",

    };

    static const char * const time_fmt[] = {

        "%H:%M:%S",

        "%H%M%S",

    };

    const char *q;

    int is_utc, len;

    char lastch;

    int negative = 0;



#undef time

    time_t now = time(0);



    len = strlen(timestr);

    if (len > 0)

        lastch = timestr[len - 1];

    else

        lastch = '\0';

    is_utc = (lastch == 'z' || lastch == 'Z');



    p = timestr;

    q = NULL;

    if (!duration) {

        if (!av_strncasecmp(timestr, "now", len)) {

            *timeval = (int64_t) now * 1000000;

            return 0;

        }



        

        for (i = 0; i < FF_ARRAY_ELEMS(date_fmt); i++) {

            q = small_strptime(p, date_fmt[i], &dt);

            if (q) {

                break;

            }

        }



        



        if (!q) {

            if (is_utc) {

                dt = *gmtime(&now);

            } else {

                dt = *localtime(&now);

            }

            dt.tm_hour = dt.tm_min = dt.tm_sec = 0;

        } else {

            p = q;

        }



        if (*p == 'T' || *p == 't' || *p == ' ')

            p++;



        

        for (i = 0; i < FF_ARRAY_ELEMS(time_fmt); i++) {

            q = small_strptime(p, time_fmt[i], &dt);

            if (q) {

                break;

            }

        }

    } else {

        

        if (p[0] == '-') {

            negative = 1;

            ++p;

        }

        

        q = small_strptime(p, time_fmt[0], &dt);

        if (!q) {

            

            dt.tm_sec = strtol(p, (void *)&q, 10);

            if (q == p) {

                

                *timeval = INT64_MIN;

                return AVERROR(EINVAL);

            }

            dt.tm_min = 0;

            dt.tm_hour = 0;

        }

    }



    

    if (!q) {

        *timeval = INT64_MIN;

        return AVERROR(EINVAL);

    }



    if (duration) {

        t = dt.tm_hour * 3600 + dt.tm_min * 60 + dt.tm_sec;

    } else {

        dt.tm_isdst = -1;       

        if (is_utc) {

            t = av_timegm(&dt);

        } else {

            t = mktime(&dt);

        }

    }



    t *= 1000000;



    

    if (*q == '.') {

        int val, n;

        q++;

        for (val = 0, n = 100000; n >= 1; n /= 10, q++) {

            if (!isdigit(*q))

                break;

            val += n * (*q - '0');

        }

        t += val;

    }

    *timeval = negative ? -t : t;

    return 0;

}

    const char *p;     const char *q;     int is_utc, len;     char lastch;     int negative = 0; #undef time     time_t now = time(0);     len = strlen(timestr);     if (len > 0)         lastch = timestr[len - 1];         lastch = '\0';     is_utc = (lastch == 'z' || lastch == 'Z');         if (!av_strncasecmp(timestr, "now", len)) {             if (q) {             if (is_utc) {                 dt = *gmtime(&now);             } else {                 dt = *localtime(&now);             dt.tm_hour = dt.tm_min = dt.tm_sec = 0;         } else {             p = q;             if (q) {             if (q == p) {                 *timeval = INT64_MIN;     if (!q) {         *timeval = INT64_MIN;         if (is_utc) {             t = av_timegm(&dt);         } else {             t = mktime(&dt);     t *= 1000000;     if (*q == '.') {         int val, n;         q++;         for (val = 0, n = 100000; n >= 1; n /= 10, q++) {             if (!isdigit(*q))                 break;             val += n * (*q - '0');         t += val;
int FUNC_0(int64_t *VAR_0, const char *VAR_1, int VAR_2)

{

    const char *VAR_3;

    int64_t t;

    struct tm VAR_4 = { 0 };

    int VAR_5;

    static const char * const VAR_6[] = {

        "%Y-%m-%d",

        "%Y%m%d",

    };

    static const char * const VAR_7[] = {

        "%H:%M:%S",

        "%H%M%S",

    };

    const char *VAR_8;

    int VAR_9, VAR_10;

    char VAR_11;

    int VAR_12 = 0;



#undef time

    time_t now = time(0);



    VAR_10 = strlen(VAR_1);

    if (VAR_10 > 0)

        VAR_11 = VAR_1[VAR_10 - 1];

    else

        VAR_11 = '\0';

    VAR_9 = (VAR_11 == 'z' || VAR_11 == 'Z');



    VAR_3 = VAR_1;

    VAR_8 = NULL;

    if (!VAR_2) {

        if (!av_strncasecmp(VAR_1, "now", VAR_10)) {

            *VAR_0 = (int64_t) now * 1000000;

            return 0;

        }



        

        for (VAR_5 = 0; VAR_5 < FF_ARRAY_ELEMS(VAR_6); VAR_5++) {

            VAR_8 = small_strptime(VAR_3, VAR_6[VAR_5], &VAR_4);

            if (VAR_8) {

                break;

            }

        }



        



        if (!VAR_8) {

            if (VAR_9) {

                VAR_4 = *gmtime(&now);

            } else {

                VAR_4 = *localtime(&now);

            }

            VAR_4.tm_hour = VAR_4.tm_min = VAR_4.tm_sec = 0;

        } else {

            VAR_3 = VAR_8;

        }



        if (*VAR_3 == 'T' || *VAR_3 == 't' || *VAR_3 == ' ')

            VAR_3++;



        

        for (VAR_5 = 0; VAR_5 < FF_ARRAY_ELEMS(VAR_7); VAR_5++) {

            VAR_8 = small_strptime(VAR_3, VAR_7[VAR_5], &VAR_4);

            if (VAR_8) {

                break;

            }

        }

    } else {

        

        if (VAR_3[0] == '-') {

            VAR_12 = 1;

            ++VAR_3;

        }

        

        VAR_8 = small_strptime(VAR_3, VAR_7[0], &VAR_4);

        if (!VAR_8) {

            

            VAR_4.tm_sec = strtol(VAR_3, (void *)&VAR_8, 10);

            if (VAR_8 == VAR_3) {

                

                *VAR_0 = INT64_MIN;

                return AVERROR(EINVAL);

            }

            VAR_4.tm_min = 0;

            VAR_4.tm_hour = 0;

        }

    }



    

    if (!VAR_8) {

        *VAR_0 = INT64_MIN;

        return AVERROR(EINVAL);

    }



    if (VAR_2) {

        t = VAR_4.tm_hour * 3600 + VAR_4.tm_min * 60 + VAR_4.tm_sec;

    } else {

        VAR_4.tm_isdst = -1;       

        if (VAR_9) {

            t = av_timegm(&VAR_4);

        } else {

            t = mktime(&VAR_4);

        }

    }



    t *= 1000000;



    

    if (*VAR_8 == '.') {

        int VAR_13, VAR_14;

        VAR_8++;

        for (VAR_13 = 0, VAR_14 = 100000; VAR_14 >= 1; VAR_14 /= 10, VAR_8++) {

            if (!isdigit(*VAR_8))

                break;

            VAR_13 += VAR_14 * (*VAR_8 - '0');

        }

        t += VAR_13;

    }

    *VAR_0 = VAR_12 ? -t : t;

    return 0;

}

int FUNC_0(int64_t *VAR_0, const char *VAR_1, int VAR_2)
{ const char *VAR_3; int64_t t; struct tm VAR_4 = { 0 }; int VAR_5; static const char * const VAR_6[] = { "%Y-%m-%d",
"%Y%m%d",
}; static const char * const VAR_7[] = { "%H:%M:%S",
"%H%M%S",
}; const char *VAR_8; int VAR_9, VAR_10; char VAR_11; int VAR_12 = 0; #undef time
time_t now = time(0); VAR_10 = strlen(VAR_1); if (VAR_10 > 0)
VAR_11 = VAR_1[VAR_10 - 1]; else
VAR_11 = '\0'; VAR_9 = (VAR_11 == 'z' || VAR_11 == 'Z'); VAR_3 = VAR_1; VAR_8 = NULL; if (!VAR_2) { if (!av_strncasecmp(VAR_1, "now", VAR_10)) { *VAR_0 = (int64_t) now * 1000000; return 0; } for (VAR_5 = 0; VAR_5 < FF_ARRAY_ELEMS(VAR_6); VAR_5++) { VAR_8 = small_strptime(VAR_3, VAR_6[VAR_5], &VAR_4); if (VAR_8) { break; } } if (!VAR_8) { if (VAR_9) { VAR_4 = *gmtime(&now); } else { VAR_4 = *localtime(&now); } VAR_4.tm_hour = VAR_4.tm_min = VAR_4.tm_sec = 0; } else { VAR_3 = VAR_8; } if (*VAR_3 == 'T' || *VAR_3 == 't' || *VAR_3 == ' ')
VAR_3++; for (VAR_5 = 0; VAR_5 < FF_ARRAY_ELEMS(VAR_7); VAR_5++) { VAR_8 = small_strptime(VAR_3, VAR_7[VAR_5], &VAR_4); if (VAR_8) { break; } } } else { if (VAR_3[0] == '-') { VAR_12 = 1; ++VAR_3; } VAR_8 = small_strptime(VAR_3, VAR_7[0], &VAR_4); if (!VAR_8) { VAR_4.tm_sec = strtol(VAR_3, (void *)&VAR_8, 10); if (VAR_8 == VAR_3) { *VAR_0 = INT64_MIN; return AVERROR(EINVAL); } VAR_4.tm_min = 0; VAR_4.tm_hour = 0; } } if (!VAR_8) { *VAR_0 = INT64_MIN; return AVERROR(EINVAL); } if (VAR_2) { t = VAR_4.tm_hour * 3600 + VAR_4.tm_min * 60 + VAR_4.tm_sec; } else { VAR_4.tm_isdst = -1; if (VAR_9) { t = av_timegm(&VAR_4); } else { t = mktime(&VAR_4); } } t *= 1000000; if (*VAR_8 == '.') { int VAR_13, VAR_14; VAR_8++; for (VAR_13 = 0, VAR_14 = 100000; VAR_14 >= 1; VAR_14 /= 10, VAR_8++) { if (!isdigit(*VAR_8))
break; VAR_13 += VAR_14 * (*VAR_8 - '0'); } t += VAR_13; } *VAR_0 = VAR_12 ? -t : t; return 0; }