static int mirror_cow_align(MirrorBlockJob *s, int64_t *offset,

                            uint64_t *bytes)

{

    bool need_cow;

    int ret = 0;

    int64_t align_offset = *offset;

    unsigned int align_bytes = *bytes;

    int max_bytes = s->granularity * s->max_iov;



    assert(*bytes < INT_MAX);

    need_cow = !test_bit(*offset / s->granularity, s->cow_bitmap);

    need_cow |= !test_bit((*offset + *bytes - 1) / s->granularity,

                          s->cow_bitmap);

    if (need_cow) {

        bdrv_round_to_clusters(blk_bs(s->target), *offset, *bytes,

                               &align_offset, &align_bytes);

    }



    if (align_bytes > max_bytes) {

        align_bytes = max_bytes;

        if (need_cow) {

            align_bytes = QEMU_ALIGN_DOWN(align_bytes, s->target_cluster_size);

        }

    }

    /* Clipping may result in align_bytes unaligned to chunk boundary, but

     * that doesn't matter because it's already the end of source image. */

    align_bytes = mirror_clip_bytes(s, align_offset, align_bytes);



    ret = align_offset + align_bytes - (*offset + *bytes);

    *offset = align_offset;

    *bytes = align_bytes;

    assert(ret >= 0);

    return ret;

}

static int mirror_cow_align(MirrorBlockJob *s, int64_t *offset,

                            uint64_t *bytes)

{

    bool need_cow;

    int ret = 0;

    int64_t align_offset = *offset;

    unsigned int align_bytes = *bytes;

    int max_bytes = s->granularity * s->max_iov;



    assert(*bytes < INT_MAX);

    need_cow = !test_bit(*offset / s->granularity, s->cow_bitmap);

    need_cow |= !test_bit((*offset + *bytes - 1) / s->granularity,

                          s->cow_bitmap);

    if (need_cow) {

        bdrv_round_to_clusters(blk_bs(s->target), *offset, *bytes,

                               &align_offset, &align_bytes);

    }



    if (align_bytes > max_bytes) {

        align_bytes = max_bytes;

        if (need_cow) {

            align_bytes = QEMU_ALIGN_DOWN(align_bytes, s->target_cluster_size);

        }

    }

    



    align_bytes = mirror_clip_bytes(s, align_offset, align_bytes);



    ret = align_offset + align_bytes - (*offset + *bytes);

    *offset = align_offset;

    *bytes = align_bytes;

    assert(ret >= 0);

    return ret;

}

    unsigned int align_bytes = *bytes;     assert(*bytes < INT_MAX);
static int FUNC_0(MirrorBlockJob *VAR_0, int64_t *VAR_1,

                            uint64_t *VAR_2)

{

    bool need_cow;

    int VAR_3 = 0;

    int64_t align_offset = *VAR_1;

    unsigned int VAR_4 = *VAR_2;

    int VAR_5 = VAR_0->granularity * VAR_0->max_iov;



    assert(*VAR_2 < INT_MAX);

    need_cow = !test_bit(*VAR_1 / VAR_0->granularity, VAR_0->cow_bitmap);

    need_cow |= !test_bit((*VAR_1 + *VAR_2 - 1) / VAR_0->granularity,

                          VAR_0->cow_bitmap);

    if (need_cow) {

        bdrv_round_to_clusters(blk_bs(VAR_0->target), *VAR_1, *VAR_2,

                               &align_offset, &VAR_4);

    }



    if (VAR_4 > VAR_5) {

        VAR_4 = VAR_5;

        if (need_cow) {

            VAR_4 = QEMU_ALIGN_DOWN(VAR_4, VAR_0->target_cluster_size);

        }

    }

    



    VAR_4 = mirror_clip_bytes(VAR_0, align_offset, VAR_4);



    VAR_3 = align_offset + VAR_4 - (*VAR_1 + *VAR_2);

    *VAR_1 = align_offset;

    *VAR_2 = VAR_4;

    assert(VAR_3 >= 0);

    return VAR_3;

}

static int FUNC_0(MirrorBlockJob *VAR_0, int64_t *VAR_1,
uint64_t *VAR_2)
{ bool need_cow; int VAR_3 = 0; int64_t align_offset = *VAR_1; unsigned int VAR_4 = *VAR_2; int VAR_5 = VAR_0->granularity * VAR_0->max_iov; assert(*VAR_2 < INT_MAX); need_cow = !test_bit(*VAR_1 / VAR_0->granularity, VAR_0->cow_bitmap); need_cow |= !test_bit((*VAR_1 + *VAR_2 - 1) / VAR_0->granularity,
VAR_0->cow_bitmap); if (need_cow) { bdrv_round_to_clusters(blk_bs(VAR_0->target), *VAR_1, *VAR_2,
&align_offset, &VAR_4); } if (VAR_4 > VAR_5) { VAR_4 = VAR_5; if (need_cow) { VAR_4 = QEMU_ALIGN_DOWN(VAR_4, VAR_0->target_cluster_size); } } VAR_4 = mirror_clip_bytes(VAR_0, align_offset, VAR_4); VAR_3 = align_offset + VAR_4 - (*VAR_1 + *VAR_2); *VAR_1 = align_offset; *VAR_2 = VAR_4; assert(VAR_3 >= 0); return VAR_3; }