int av_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts, int flags){

    AVInputFormat *avif= s->iformat;

    int64_t av_uninit(pos_min), av_uninit(pos_max), pos, pos_limit;

    int64_t ts_min, ts_max, ts;

    int index;

    AVStream *st;



    if (stream_index < 0)

        return -1;



#ifdef DEBUG_SEEK

    av_log(s, AV_LOG_DEBUG, "read_seek: %d %"PRId64"\n", stream_index, target_ts);

#endif



    ts_max=

    ts_min= AV_NOPTS_VALUE;

    pos_limit= -1; //gcc falsely says it may be uninitialized



    st= s->streams[stream_index];

    if(st->index_entries){

        AVIndexEntry *e;



        index= av_index_search_timestamp(st, target_ts, flags | AVSEEK_FLAG_BACKWARD); //FIXME whole func must be checked for non-keyframe entries in index case, especially read_timestamp()

        index= FFMAX(index, 0);

        e= &st->index_entries[index];



        if(e->timestamp <= target_ts || e->pos == e->min_distance){

            pos_min= e->pos;

            ts_min= e->timestamp;

#ifdef DEBUG_SEEK

            av_log(s, AV_LOG_DEBUG, "using cached pos_min=0x%"PRIx64" dts_min=%"PRId64"\n",

                   pos_min,ts_min);

#endif

        }else{

            assert(index==0);

        }



        index= av_index_search_timestamp(st, target_ts, flags & ~AVSEEK_FLAG_BACKWARD);

        assert(index < st->nb_index_entries);

        if(index >= 0){

            e= &st->index_entries[index];

            assert(e->timestamp >= target_ts);

            pos_max= e->pos;

            ts_max= e->timestamp;

            pos_limit= pos_max - e->min_distance;

#ifdef DEBUG_SEEK

            av_log(s, AV_LOG_DEBUG, "using cached pos_max=0x%"PRIx64" pos_limit=0x%"PRIx64" dts_max=%"PRId64"\n",

                   pos_max,pos_limit, ts_max);

#endif

        }

    }



    pos= av_gen_search(s, stream_index, target_ts, pos_min, pos_max, pos_limit, ts_min, ts_max, flags, &ts, avif->read_timestamp);

    if(pos<0)

        return -1;



    /* do the seek */

    url_fseek(s->pb, pos, SEEK_SET);



    av_update_cur_dts(s, st, ts);



    return 0;

}

int av_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts, int flags){

    AVInputFormat *avif= s->iformat;

    int64_t av_uninit(pos_min), av_uninit(pos_max), pos, pos_limit;

    int64_t ts_min, ts_max, ts;

    int index;

    AVStream *st;



    if (stream_index < 0)

        return -1;



#ifdef DEBUG_SEEK

    av_log(s, AV_LOG_DEBUG, "read_seek: %d %"PRId64"\n", stream_index, target_ts);

#endif



    ts_max=

    ts_min= AV_NOPTS_VALUE;

    pos_limit= -1; 



    st= s->streams[stream_index];

    if(st->index_entries){

        AVIndexEntry *e;



        index= av_index_search_timestamp(st, target_ts, flags | AVSEEK_FLAG_BACKWARD); 

        index= FFMAX(index, 0);

        e= &st->index_entries[index];



        if(e->timestamp <= target_ts || e->pos == e->min_distance){

            pos_min= e->pos;

            ts_min= e->timestamp;

#ifdef DEBUG_SEEK

            av_log(s, AV_LOG_DEBUG, "using cached pos_min=0x%"PRIx64" dts_min=%"PRId64"\n",

                   pos_min,ts_min);

#endif

        }else{

            assert(index==0);

        }



        index= av_index_search_timestamp(st, target_ts, flags & ~AVSEEK_FLAG_BACKWARD);

        assert(index < st->nb_index_entries);

        if(index >= 0){

            e= &st->index_entries[index];

            assert(e->timestamp >= target_ts);

            pos_max= e->pos;

            ts_max= e->timestamp;

            pos_limit= pos_max - e->min_distance;

#ifdef DEBUG_SEEK

            av_log(s, AV_LOG_DEBUG, "using cached pos_max=0x%"PRIx64" pos_limit=0x%"PRIx64" dts_max=%"PRId64"\n",

                   pos_max,pos_limit, ts_max);

#endif

        }

    }



    pos= av_gen_search(s, stream_index, target_ts, pos_min, pos_max, pos_limit, ts_min, ts_max, flags, &ts, avif->read_timestamp);

    if(pos<0)

        return -1;



    

    url_fseek(s->pb, pos, SEEK_SET);



    av_update_cur_dts(s, st, ts);



    return 0;

}

    url_fseek(s->pb, pos, SEEK_SET);
int FUNC_0(AVFormatContext *VAR_0, int VAR_1, int64_t VAR_2, int VAR_3){

    AVInputFormat *avif= VAR_0->iformat;

    int64_t av_uninit(pos_min), av_uninit(pos_max), pos, pos_limit;

    int64_t ts_min, ts_max, ts;

    int VAR_4;

    AVStream *st;



    if (VAR_1 < 0)

        return -1;



#ifdef DEBUG_SEEK

    av_log(VAR_0, AV_LOG_DEBUG, "read_seek: %d %"PRId64"\n", VAR_1, VAR_2);

#endif



    ts_max=

    ts_min= AV_NOPTS_VALUE;

    pos_limit= -1; 



    st= VAR_0->streams[VAR_1];

    if(st->index_entries){

        AVIndexEntry *e;



        VAR_4= av_index_search_timestamp(st, VAR_2, VAR_3 | AVSEEK_FLAG_BACKWARD); 

        VAR_4= FFMAX(VAR_4, 0);

        e= &st->index_entries[VAR_4];



        if(e->timestamp <= VAR_2 || e->pos == e->min_distance){

            pos_min= e->pos;

            ts_min= e->timestamp;

#ifdef DEBUG_SEEK

            av_log(VAR_0, AV_LOG_DEBUG, "using cached pos_min=0x%"PRIx64" dts_min=%"PRId64"\n",

                   pos_min,ts_min);

#endif

        }else{

            assert(VAR_4==0);

        }



        VAR_4= av_index_search_timestamp(st, VAR_2, VAR_3 & ~AVSEEK_FLAG_BACKWARD);

        assert(VAR_4 < st->nb_index_entries);

        if(VAR_4 >= 0){

            e= &st->index_entries[VAR_4];

            assert(e->timestamp >= VAR_2);

            pos_max= e->pos;

            ts_max= e->timestamp;

            pos_limit= pos_max - e->min_distance;

#ifdef DEBUG_SEEK

            av_log(VAR_0, AV_LOG_DEBUG, "using cached pos_max=0x%"PRIx64" pos_limit=0x%"PRIx64" dts_max=%"PRId64"\n",

                   pos_max,pos_limit, ts_max);

#endif

        }

    }



    pos= av_gen_search(VAR_0, VAR_1, VAR_2, pos_min, pos_max, pos_limit, ts_min, ts_max, VAR_3, &ts, avif->read_timestamp);

    if(pos<0)

        return -1;



    

    url_fseek(VAR_0->pb, pos, SEEK_SET);



    av_update_cur_dts(VAR_0, st, ts);



    return 0;

}

int FUNC_0(AVFormatContext *VAR_0, int VAR_1, int64_t VAR_2, int VAR_3){ AVInputFormat *avif= VAR_0->iformat; int64_t av_uninit(pos_min), av_uninit(pos_max), pos, pos_limit; int64_t ts_min, ts_max, ts; int VAR_4; AVStream *st; if (VAR_1 < 0)
return -1; #ifdef DEBUG_SEEK
av_log(VAR_0, AV_LOG_DEBUG, "read_seek: %d %"PRId64"\n", VAR_1, VAR_2); #endif
ts_max=
ts_min= AV_NOPTS_VALUE; pos_limit= -1; st= VAR_0->streams[VAR_1]; if(st->index_entries){ AVIndexEntry *e; VAR_4= av_index_search_timestamp(st, VAR_2, VAR_3 | AVSEEK_FLAG_BACKWARD); VAR_4= FFMAX(VAR_4, 0); e= &st->index_entries[VAR_4]; if(e->timestamp <= VAR_2 || e->pos == e->min_distance){ pos_min= e->pos; ts_min= e->timestamp; #ifdef DEBUG_SEEK
av_log(VAR_0, AV_LOG_DEBUG, "using cached pos_min=0x%"PRIx64" dts_min=%"PRId64"\n",
pos_min,ts_min); #endif
}else{ assert(VAR_4==0); } VAR_4= av_index_search_timestamp(st, VAR_2, VAR_3 & ~AVSEEK_FLAG_BACKWARD); assert(VAR_4 < st->nb_index_entries); if(VAR_4 >= 0){ e= &st->index_entries[VAR_4]; assert(e->timestamp >= VAR_2); pos_max= e->pos; ts_max= e->timestamp; pos_limit= pos_max - e->min_distance; #ifdef DEBUG_SEEK
av_log(VAR_0, AV_LOG_DEBUG, "using cached pos_max=0x%"PRIx64" pos_limit=0x%"PRIx64" dts_max=%"PRId64"\n",
pos_max,pos_limit, ts_max); #endif
} } pos= av_gen_search(VAR_0, VAR_1, VAR_2, pos_min, pos_max, pos_limit, ts_min, ts_max, VAR_3, &ts, avif->read_timestamp); if(pos<0)
return -1; url_fseek(VAR_0->pb, pos, SEEK_SET); av_update_cur_dts(VAR_0, st, ts); return 0; }