static int real_seek(AVFormatContext *avf, int stream,

                     int64_t min_ts, int64_t ts, int64_t max_ts, int flags)

{

    ConcatContext *cat = avf->priv_data;

    int ret, left, right;



    if (stream >= 0) {

        if (stream >= avf->nb_streams)

            return AVERROR(EINVAL);

        rescale_interval(avf->streams[stream]->time_base, AV_TIME_BASE_Q,

                         &min_ts, &ts, &max_ts);

    }



    left  = 0;

    right = cat->nb_files;

    while (right - left > 1) {

        int mid = (left + right) / 2;

        if (ts < cat->files[mid].start_time)

            right = mid;

        else

            left  = mid;

    }



    if ((ret = open_file(avf, left)) < 0)

        return ret;



    ret = try_seek(avf, stream, min_ts, ts, max_ts, flags);

    if (ret < 0 && !(flags & AVSEEK_FLAG_BACKWARD) &&

        left < cat->nb_files - 1 &&

        cat->files[left + 1].start_time < max_ts) {

        if ((ret = open_file(avf, left + 1)) < 0)

            return ret;

        ret = try_seek(avf, stream, min_ts, ts, max_ts, flags);

    }

    return ret;

}

static int real_seek(AVFormatContext *avf, int stream,

                     int64_t min_ts, int64_t ts, int64_t max_ts, int flags)

{

    ConcatContext *cat = avf->priv_data;

    int ret, left, right;



    if (stream >= 0) {

        if (stream >= avf->nb_streams)

            return AVERROR(EINVAL);

        rescale_interval(avf->streams[stream]->time_base, AV_TIME_BASE_Q,

                         &min_ts, &ts, &max_ts);

    }



    left  = 0;

    right = cat->nb_files;

    while (right - left > 1) {

        int mid = (left + right) / 2;

        if (ts < cat->files[mid].start_time)

            right = mid;

        else

            left  = mid;

    }



    if ((ret = open_file(avf, left)) < 0)

        return ret;



    ret = try_seek(avf, stream, min_ts, ts, max_ts, flags);

    if (ret < 0 && !(flags & AVSEEK_FLAG_BACKWARD) &&

        left < cat->nb_files - 1 &&

        cat->files[left + 1].start_time < max_ts) {

        if ((ret = open_file(avf, left + 1)) < 0)

            return ret;

        ret = try_seek(avf, stream, min_ts, ts, max_ts, flags);

    }

    return ret;

}

static int FUNC_0(AVFormatContext *VAR_0, int VAR_1,

                     int64_t VAR_2, int64_t VAR_3, int64_t VAR_4, int VAR_5)

{

    ConcatContext *cat = VAR_0->priv_data;

    int VAR_6, VAR_7, VAR_8;



    if (VAR_1 >= 0) {

        if (VAR_1 >= VAR_0->nb_streams)

            return AVERROR(EINVAL);

        rescale_interval(VAR_0->streams[VAR_1]->time_base, AV_TIME_BASE_Q,

                         &VAR_2, &VAR_3, &VAR_4);

    }



    VAR_7  = 0;

    VAR_8 = cat->nb_files;

    while (VAR_8 - VAR_7 > 1) {

        int VAR_9 = (VAR_7 + VAR_8) / 2;

        if (VAR_3 < cat->files[VAR_9].start_time)

            VAR_8 = VAR_9;

        else

            VAR_7  = VAR_9;

    }



    if ((VAR_6 = open_file(VAR_0, VAR_7)) < 0)

        return VAR_6;



    VAR_6 = try_seek(VAR_0, VAR_1, VAR_2, VAR_3, VAR_4, VAR_5);

    if (VAR_6 < 0 && !(VAR_5 & AVSEEK_FLAG_BACKWARD) &&

        VAR_7 < cat->nb_files - 1 &&

        cat->files[VAR_7 + 1].start_time < VAR_4) {

        if ((VAR_6 = open_file(VAR_0, VAR_7 + 1)) < 0)

            return VAR_6;

        VAR_6 = try_seek(VAR_0, VAR_1, VAR_2, VAR_3, VAR_4, VAR_5);

    }

    return VAR_6;

}

static int FUNC_0(AVFormatContext *VAR_0, int VAR_1,
int64_t VAR_2, int64_t VAR_3, int64_t VAR_4, int VAR_5)
{ ConcatContext *cat = VAR_0->priv_data; int VAR_6, VAR_7, VAR_8; if (VAR_1 >= 0) { if (VAR_1 >= VAR_0->nb_streams)
return AVERROR(EINVAL); rescale_interval(VAR_0->streams[VAR_1]->time_base, AV_TIME_BASE_Q,
&VAR_2, &VAR_3, &VAR_4); } VAR_7  = 0; VAR_8 = cat->nb_files; while (VAR_8 - VAR_7 > 1) { int VAR_9 = (VAR_7 + VAR_8) / 2; if (VAR_3 < cat->files[VAR_9].start_time)
VAR_8 = VAR_9; else
VAR_7  = VAR_9; } if ((VAR_6 = open_file(VAR_0, VAR_7)) < 0)
return VAR_6; VAR_6 = try_seek(VAR_0, VAR_1, VAR_2, VAR_3, VAR_4, VAR_5); if (VAR_6 < 0 && !(VAR_5 & AVSEEK_FLAG_BACKWARD) &&
VAR_7 < cat->nb_files - 1 &&
cat->files[VAR_7 + 1].start_time < VAR_4) { if ((VAR_6 = open_file(VAR_0, VAR_7 + 1)) < 0)
return VAR_6; VAR_6 = try_seek(VAR_0, VAR_1, VAR_2, VAR_3, VAR_4, VAR_5); } return VAR_6; }