int qcow2_alloc_clusters_at(BlockDriverState *bs, uint64_t offset,

    int nb_clusters)

{

    BDRVQcowState *s = bs->opaque;

    uint64_t cluster_index;

    uint64_t old_free_cluster_index;

    uint64_t i;

    int refcount, ret;



    assert(nb_clusters >= 0);

    if (nb_clusters == 0) {

        return 0;

    }



    /* Check how many clusters there are free */

    cluster_index = offset >> s->cluster_bits;

    for(i = 0; i < nb_clusters; i++) {

        refcount = get_refcount(bs, cluster_index++);



        if (refcount < 0) {

            return refcount;

        } else if (refcount != 0) {

            break;

        }

    }



    /* And then allocate them */

    old_free_cluster_index = s->free_cluster_index;

    s->free_cluster_index = cluster_index + i;



    ret = update_refcount(bs, offset, i << s->cluster_bits, 1,

                          QCOW2_DISCARD_NEVER);

    if (ret < 0) {

        return ret;

    }



    s->free_cluster_index = old_free_cluster_index;



    return i;

}

int qcow2_alloc_clusters_at(BlockDriverState *bs, uint64_t offset,

    int nb_clusters)

{

    BDRVQcowState *s = bs->opaque;

    uint64_t cluster_index;

    uint64_t old_free_cluster_index;

    uint64_t i;

    int refcount, ret;



    assert(nb_clusters >= 0);

    if (nb_clusters == 0) {

        return 0;

    }



    

    cluster_index = offset >> s->cluster_bits;

    for(i = 0; i < nb_clusters; i++) {

        refcount = get_refcount(bs, cluster_index++);



        if (refcount < 0) {

            return refcount;

        } else if (refcount != 0) {

            break;

        }

    }



    

    old_free_cluster_index = s->free_cluster_index;

    s->free_cluster_index = cluster_index + i;



    ret = update_refcount(bs, offset, i << s->cluster_bits, 1,

                          QCOW2_DISCARD_NEVER);

    if (ret < 0) {

        return ret;

    }



    s->free_cluster_index = old_free_cluster_index;



    return i;

}

        return 0;     s->free_cluster_index = old_free_cluster_index;     uint64_t old_free_cluster_index;     cluster_index = offset >> s->cluster_bits;     for(i = 0; i < nb_clusters; i++) {         refcount = get_refcount(bs, cluster_index++);         if (refcount < 0) {             return refcount;         } else if (refcount != 0) {             break;     old_free_cluster_index = s->free_cluster_index;     s->free_cluster_index = cluster_index + i;     ret = update_refcount(bs, offset, i << s->cluster_bits, 1,                           QCOW2_DISCARD_NEVER);     s->free_cluster_index = old_free_cluster_index;
int FUNC_0(BlockDriverState *VAR_0, uint64_t VAR_1,

    int VAR_2)

{

    BDRVQcowState *s = VAR_0->opaque;

    uint64_t cluster_index;

    uint64_t old_free_cluster_index;

    uint64_t i;

    int VAR_3, VAR_4;



    assert(VAR_2 >= 0);

    if (VAR_2 == 0) {

        return 0;

    }



    

    cluster_index = VAR_1 >> s->cluster_bits;

    for(i = 0; i < VAR_2; i++) {

        VAR_3 = get_refcount(VAR_0, cluster_index++);



        if (VAR_3 < 0) {

            return VAR_3;

        } else if (VAR_3 != 0) {

            break;

        }

    }



    

    old_free_cluster_index = s->free_cluster_index;

    s->free_cluster_index = cluster_index + i;



    VAR_4 = update_refcount(VAR_0, VAR_1, i << s->cluster_bits, 1,

                          QCOW2_DISCARD_NEVER);

    if (VAR_4 < 0) {

        return VAR_4;

    }



    s->free_cluster_index = old_free_cluster_index;



    return i;

}

int FUNC_0(BlockDriverState *VAR_0, uint64_t VAR_1,
int VAR_2)
{ BDRVQcowState *s = VAR_0->opaque; uint64_t cluster_index; uint64_t old_free_cluster_index; uint64_t i; int VAR_3, VAR_4; assert(VAR_2 >= 0); if (VAR_2 == 0) { return 0; } cluster_index = VAR_1 >> s->cluster_bits; for(i = 0; i < VAR_2; i++) { VAR_3 = get_refcount(VAR_0, cluster_index++); if (VAR_3 < 0) { return VAR_3; } else if (VAR_3 != 0) { break; } } old_free_cluster_index = s->free_cluster_index; s->free_cluster_index = cluster_index + i; VAR_4 = update_refcount(VAR_0, VAR_1, i << s->cluster_bits, 1,
QCOW2_DISCARD_NEVER); if (VAR_4 < 0) { return VAR_4; } s->free_cluster_index = old_free_cluster_index; return i; }