int bdrv_is_allocated_above(BlockDriverState *top,

                            BlockDriverState *base,

                            int64_t sector_num,

                            int nb_sectors, int *pnum)

{

    BlockDriverState *intermediate;

    int ret, n = nb_sectors;



    intermediate = top;

    while (intermediate && intermediate != base) {

        int pnum_inter;

        ret = bdrv_is_allocated(intermediate, sector_num, nb_sectors,

                                &pnum_inter);

        if (ret < 0) {

            return ret;

        } else if (ret) {

            *pnum = pnum_inter;

            return 1;

        }



        /*

         * [sector_num, nb_sectors] is unallocated on top but intermediate

         * might have

         *

         * [sector_num+x, nr_sectors] allocated.

         */

        if (n > pnum_inter &&

            (intermediate == top ||

             sector_num + pnum_inter < intermediate->total_sectors)) {

            n = pnum_inter;

        }



        intermediate = intermediate->backing_hd;

    }



    *pnum = n;

    return 0;

}

int bdrv_is_allocated_above(BlockDriverState *top,

                            BlockDriverState *base,

                            int64_t sector_num,

                            int nb_sectors, int *pnum)

{

    BlockDriverState *intermediate;

    int ret, n = nb_sectors;



    intermediate = top;

    while (intermediate && intermediate != base) {

        int pnum_inter;

        ret = bdrv_is_allocated(intermediate, sector_num, nb_sectors,

                                &pnum_inter);

        if (ret < 0) {

            return ret;

        } else if (ret) {

            *pnum = pnum_inter;

            return 1;

        }



        











        if (n > pnum_inter &&

            (intermediate == top ||

             sector_num + pnum_inter < intermediate->total_sectors)) {

            n = pnum_inter;

        }



        intermediate = intermediate->backing_hd;

    }



    *pnum = n;

    return 0;

}

int FUNC_0(BlockDriverState *VAR_0,

                            BlockDriverState *VAR_1,

                            int64_t VAR_2,

                            int VAR_3, int *VAR_4)

{

    BlockDriverState *intermediate;

    int VAR_5, VAR_6 = VAR_3;



    intermediate = VAR_0;

    while (intermediate && intermediate != VAR_1) {

        int VAR_7;

        VAR_5 = bdrv_is_allocated(intermediate, VAR_2, VAR_3,

                                &VAR_7);

        if (VAR_5 < 0) {

            return VAR_5;

        } else if (VAR_5) {

            *VAR_4 = VAR_7;

            return 1;

        }



        











        if (VAR_6 > VAR_7 &&

            (intermediate == VAR_0 ||

             VAR_2 + VAR_7 < intermediate->total_sectors)) {

            VAR_6 = VAR_7;

        }



        intermediate = intermediate->backing_hd;

    }



    *VAR_4 = VAR_6;

    return 0;

}

int FUNC_0(BlockDriverState *VAR_0,
BlockDriverState *VAR_1,
int64_t VAR_2,
int VAR_3, int *VAR_4)
{ BlockDriverState *intermediate; int VAR_5, VAR_6 = VAR_3; intermediate = VAR_0; while (intermediate && intermediate != VAR_1) { int VAR_7; VAR_5 = bdrv_is_allocated(intermediate, VAR_2, VAR_3,
&VAR_7); if (VAR_5 < 0) { return VAR_5; } else if (VAR_5) { *VAR_4 = VAR_7; return 1; } if (VAR_6 > VAR_7 &&
(intermediate == VAR_0 ||
VAR_2 + VAR_7 < intermediate->total_sectors)) { VAR_6 = VAR_7; } intermediate = intermediate->backing_hd; } *VAR_4 = VAR_6; return 0; }