static int get_refcount(BlockDriverState *bs, int64_t cluster_index)

{

    BDRVQcowState *s = bs->opaque;

    int refcount_table_index, block_index;

    int64_t refcount_block_offset;

    int ret;

    uint16_t *refcount_block;

    uint16_t refcount;



    refcount_table_index = cluster_index >> (s->cluster_bits - REFCOUNT_SHIFT);

    if (refcount_table_index >= s->refcount_table_size)

        return 0;

    refcount_block_offset =

        s->refcount_table[refcount_table_index] & REFT_OFFSET_MASK;

    if (!refcount_block_offset)

        return 0;



    ret = qcow2_cache_get(bs, s->refcount_block_cache, refcount_block_offset,

        (void**) &refcount_block);

    if (ret < 0) {

        return ret;

    }



    block_index = cluster_index &

        ((1 << (s->cluster_bits - REFCOUNT_SHIFT)) - 1);

    refcount = be16_to_cpu(refcount_block[block_index]);



    ret = qcow2_cache_put(bs, s->refcount_block_cache,

        (void**) &refcount_block);

    if (ret < 0) {

        return ret;

    }



    return refcount;

}

static int get_refcount(BlockDriverState *bs, int64_t cluster_index)

{

    BDRVQcowState *s = bs->opaque;

    int refcount_table_index, block_index;

    int64_t refcount_block_offset;

    int ret;

    uint16_t *refcount_block;

    uint16_t refcount;



    refcount_table_index = cluster_index >> (s->cluster_bits - REFCOUNT_SHIFT);

    if (refcount_table_index >= s->refcount_table_size)

        return 0;

    refcount_block_offset =

        s->refcount_table[refcount_table_index] & REFT_OFFSET_MASK;

    if (!refcount_block_offset)

        return 0;



    ret = qcow2_cache_get(bs, s->refcount_block_cache, refcount_block_offset,

        (void**) &refcount_block);

    if (ret < 0) {

        return ret;

    }



    block_index = cluster_index &

        ((1 << (s->cluster_bits - REFCOUNT_SHIFT)) - 1);

    refcount = be16_to_cpu(refcount_block[block_index]);



    ret = qcow2_cache_put(bs, s->refcount_block_cache,

        (void**) &refcount_block);

    if (ret < 0) {

        return ret;

    }



    return refcount;

}

    int refcount_table_index, block_index;
static int FUNC_0(BlockDriverState *VAR_0, int64_t VAR_1)

{

    BDRVQcowState *s = VAR_0->opaque;

    int VAR_2, VAR_3;

    int64_t refcount_block_offset;

    int VAR_4;

    uint16_t *refcount_block;

    uint16_t refcount;



    VAR_2 = VAR_1 >> (s->cluster_bits - REFCOUNT_SHIFT);

    if (VAR_2 >= s->refcount_table_size)

        return 0;

    refcount_block_offset =

        s->refcount_table[VAR_2] & REFT_OFFSET_MASK;

    if (!refcount_block_offset)

        return 0;



    VAR_4 = qcow2_cache_get(VAR_0, s->refcount_block_cache, refcount_block_offset,

        (void**) &refcount_block);

    if (VAR_4 < 0) {

        return VAR_4;

    }



    VAR_3 = VAR_1 &

        ((1 << (s->cluster_bits - REFCOUNT_SHIFT)) - 1);

    refcount = be16_to_cpu(refcount_block[VAR_3]);



    VAR_4 = qcow2_cache_put(VAR_0, s->refcount_block_cache,

        (void**) &refcount_block);

    if (VAR_4 < 0) {

        return VAR_4;

    }



    return refcount;

}

static int FUNC_0(BlockDriverState *VAR_0, int64_t VAR_1)
{ BDRVQcowState *s = VAR_0->opaque; int VAR_2, VAR_3; int64_t refcount_block_offset; int VAR_4; uint16_t *refcount_block; uint16_t refcount; VAR_2 = VAR_1 >> (s->cluster_bits - REFCOUNT_SHIFT); if (VAR_2 >= s->refcount_table_size)
return 0; refcount_block_offset =
s->refcount_table[VAR_2] & REFT_OFFSET_MASK; if (!refcount_block_offset)
return 0; VAR_4 = qcow2_cache_get(VAR_0, s->refcount_block_cache, refcount_block_offset,
(void**) &refcount_block); if (VAR_4 < 0) { return VAR_4; } VAR_3 = VAR_1 &
((1 << (s->cluster_bits - REFCOUNT_SHIFT)) - 1); refcount = be16_to_cpu(refcount_block[VAR_3]); VAR_4 = qcow2_cache_put(VAR_0, s->refcount_block_cache,
(void**) &refcount_block); if (VAR_4 < 0) { return VAR_4; } return refcount; }