static int find_image_range(int *pfirst_index, int *plast_index,

                            const char *path, int start_index, int start_index_range)

{

    char buf[1024];

    int range, last_index, range1, first_index;



    /* find the first image */

    for (first_index = start_index; first_index < start_index + start_index_range; first_index++) {

        if (av_get_frame_filename(buf, sizeof(buf), path, first_index) < 0) {

            *pfirst_index =

            *plast_index  = 1;

            if (avio_check(buf, AVIO_FLAG_READ) > 0)

                return 0;

            return -1;

        }

        if (avio_check(buf, AVIO_FLAG_READ) > 0)

            break;

    }

    if (first_index == start_index + start_index_range)

        goto fail;



    /* find the last image */

    last_index = first_index;

    for (;;) {

        range = 0;

        for (;;) {

            if (!range)

                range1 = 1;

            else

                range1 = 2 * range;

            if (av_get_frame_filename(buf, sizeof(buf), path,

                                      last_index + range1) < 0)

                goto fail;

            if (avio_check(buf, AVIO_FLAG_READ) <= 0)

                break;

            range = range1;

            /* just in case... */

            if (range >= (1 << 30))

                goto fail;

        }

        /* we are sure than image last_index + range exists */

        if (!range)

            break;

        last_index += range;

    }

    *pfirst_index = first_index;

    *plast_index  = last_index;

    return 0;



fail:

    return -1;

}

static int find_image_range(int *pfirst_index, int *plast_index,

                            const char *path, int start_index, int start_index_range)

{

    char buf[1024];

    int range, last_index, range1, first_index;



    

    for (first_index = start_index; first_index < start_index + start_index_range; first_index++) {

        if (av_get_frame_filename(buf, sizeof(buf), path, first_index) < 0) {

            *pfirst_index =

            *plast_index  = 1;

            if (avio_check(buf, AVIO_FLAG_READ) > 0)

                return 0;

            return -1;

        }

        if (avio_check(buf, AVIO_FLAG_READ) > 0)

            break;

    }

    if (first_index == start_index + start_index_range)

        goto fail;



    

    last_index = first_index;

    for (;;) {

        range = 0;

        for (;;) {

            if (!range)

                range1 = 1;

            else

                range1 = 2 * range;

            if (av_get_frame_filename(buf, sizeof(buf), path,

                                      last_index + range1) < 0)

                goto fail;

            if (avio_check(buf, AVIO_FLAG_READ) <= 0)

                break;

            range = range1;

            

            if (range >= (1 << 30))

                goto fail;

        }

        

        if (!range)

            break;

        last_index += range;

    }

    *pfirst_index = first_index;

    *plast_index  = last_index;

    return 0;



fail:

    return -1;

}

static int FUNC_0(int *VAR_0, int *VAR_1,

                            const char *VAR_2, int VAR_3, int VAR_4)

{

    char VAR_5[1024];

    int VAR_6, VAR_7, VAR_8, VAR_9;



    

    for (VAR_9 = VAR_3; VAR_9 < VAR_3 + VAR_4; VAR_9++) {

        if (av_get_frame_filename(VAR_5, sizeof(VAR_5), VAR_2, VAR_9) < 0) {

            *VAR_0 =

            *VAR_1  = 1;

            if (avio_check(VAR_5, AVIO_FLAG_READ) > 0)

                return 0;

            return -1;

        }

        if (avio_check(VAR_5, AVIO_FLAG_READ) > 0)

            break;

    }

    if (VAR_9 == VAR_3 + VAR_4)

        goto fail;



    

    VAR_7 = VAR_9;

    for (;;) {

        VAR_6 = 0;

        for (;;) {

            if (!VAR_6)

                VAR_8 = 1;

            else

                VAR_8 = 2 * VAR_6;

            if (av_get_frame_filename(VAR_5, sizeof(VAR_5), VAR_2,

                                      VAR_7 + VAR_8) < 0)

                goto fail;

            if (avio_check(VAR_5, AVIO_FLAG_READ) <= 0)

                break;

            VAR_6 = VAR_8;

            

            if (VAR_6 >= (1 << 30))

                goto fail;

        }

        

        if (!VAR_6)

            break;

        VAR_7 += VAR_6;

    }

    *VAR_0 = VAR_9;

    *VAR_1  = VAR_7;

    return 0;



fail:

    return -1;

}

static int FUNC_0(int *VAR_0, int *VAR_1,
const char *VAR_2, int VAR_3, int VAR_4)
{ char VAR_5[1024]; int VAR_6, VAR_7, VAR_8, VAR_9; for (VAR_9 = VAR_3; VAR_9 < VAR_3 + VAR_4; VAR_9++) { if (av_get_frame_filename(VAR_5, sizeof(VAR_5), VAR_2, VAR_9) < 0) { *VAR_0 =
*VAR_1  = 1; if (avio_check(VAR_5, AVIO_FLAG_READ) > 0)
return 0; return -1; } if (avio_check(VAR_5, AVIO_FLAG_READ) > 0)
break; } if (VAR_9 == VAR_3 + VAR_4)
goto fail; VAR_7 = VAR_9; for (;;) { VAR_6 = 0; for (;;) { if (!VAR_6)
VAR_8 = 1; else
VAR_8 = 2 * VAR_6; if (av_get_frame_filename(VAR_5, sizeof(VAR_5), VAR_2,
VAR_7 + VAR_8) < 0)
goto fail; if (avio_check(VAR_5, AVIO_FLAG_READ) <= 0)
break; VAR_6 = VAR_8; if (VAR_6 >= (1 << 30))
goto fail; } if (!VAR_6)
break; VAR_7 += VAR_6; } *VAR_0 = VAR_9; *VAR_1  = VAR_7; return 0; fail:
return -1; }