static int raw_pread(BlockDriverState *bs, int64_t offset,

                     uint8_t *buf, int count)

{

    BDRVRawState *s = bs->opaque;

    int size, ret, shift, sum;



    sum = 0;



    if (s->aligned_buf != NULL)  {



        if (offset & 0x1ff) {

            /* align offset on a 512 bytes boundary */



            shift = offset & 0x1ff;

            size = (shift + count + 0x1ff) & ~0x1ff;

            if (size > ALIGNED_BUFFER_SIZE)

                size = ALIGNED_BUFFER_SIZE;

            ret = raw_pread_aligned(bs, offset - shift, s->aligned_buf, size);

            if (ret < 0)

                return ret;



            size = 512 - shift;

            if (size > count)

                size = count;

            memcpy(buf, s->aligned_buf + shift, size);



            buf += size;

            offset += size;

            count -= size;

            sum += size;



            if (count == 0)

                return sum;

        }

        if (count & 0x1ff || (uintptr_t) buf & 0x1ff) {



            /* read on aligned buffer */



            while (count) {



                size = (count + 0x1ff) & ~0x1ff;

                if (size > ALIGNED_BUFFER_SIZE)

                    size = ALIGNED_BUFFER_SIZE;



                ret = raw_pread_aligned(bs, offset, s->aligned_buf, size);

                if (ret < 0)

                    return ret;



                size = ret;

                if (size > count)

                    size = count;



                memcpy(buf, s->aligned_buf, size);



                buf += size;

                offset += size;

                count -= size;

                sum += size;

            }



            return sum;

        }

    }



    return raw_pread_aligned(bs, offset, buf, count) + sum;

}

static int raw_pread(BlockDriverState *bs, int64_t offset,

                     uint8_t *buf, int count)

{

    BDRVRawState *s = bs->opaque;

    int size, ret, shift, sum;



    sum = 0;



    if (s->aligned_buf != NULL)  {



        if (offset & 0x1ff) {

            



            shift = offset & 0x1ff;

            size = (shift + count + 0x1ff) & ~0x1ff;

            if (size > ALIGNED_BUFFER_SIZE)

                size = ALIGNED_BUFFER_SIZE;

            ret = raw_pread_aligned(bs, offset - shift, s->aligned_buf, size);

            if (ret < 0)

                return ret;



            size = 512 - shift;

            if (size > count)

                size = count;

            memcpy(buf, s->aligned_buf + shift, size);



            buf += size;

            offset += size;

            count -= size;

            sum += size;



            if (count == 0)

                return sum;

        }

        if (count & 0x1ff || (uintptr_t) buf & 0x1ff) {



            



            while (count) {



                size = (count + 0x1ff) & ~0x1ff;

                if (size > ALIGNED_BUFFER_SIZE)

                    size = ALIGNED_BUFFER_SIZE;



                ret = raw_pread_aligned(bs, offset, s->aligned_buf, size);

                if (ret < 0)

                    return ret;



                size = ret;

                if (size > count)

                    size = count;



                memcpy(buf, s->aligned_buf, size);



                buf += size;

                offset += size;

                count -= size;

                sum += size;

            }



            return sum;

        }

    }



    return raw_pread_aligned(bs, offset, buf, count) + sum;

}

                if (ret < 0)
static int FUNC_0(BlockDriverState *VAR_0, int64_t VAR_1,

                     uint8_t *VAR_2, int VAR_3)

{

    BDRVRawState *s = VAR_0->opaque;

    int VAR_4, VAR_5, VAR_6, VAR_7;



    VAR_7 = 0;



    if (s->aligned_buf != NULL)  {



        if (VAR_1 & 0x1ff) {

            



            VAR_6 = VAR_1 & 0x1ff;

            VAR_4 = (VAR_6 + VAR_3 + 0x1ff) & ~0x1ff;

            if (VAR_4 > ALIGNED_BUFFER_SIZE)

                VAR_4 = ALIGNED_BUFFER_SIZE;

            VAR_5 = raw_pread_aligned(VAR_0, VAR_1 - VAR_6, s->aligned_buf, VAR_4);

            if (VAR_5 < 0)

                return VAR_5;



            VAR_4 = 512 - VAR_6;

            if (VAR_4 > VAR_3)

                VAR_4 = VAR_3;

            memcpy(VAR_2, s->aligned_buf + VAR_6, VAR_4);



            VAR_2 += VAR_4;

            VAR_1 += VAR_4;

            VAR_3 -= VAR_4;

            VAR_7 += VAR_4;



            if (VAR_3 == 0)

                return VAR_7;

        }

        if (VAR_3 & 0x1ff || (uintptr_t) VAR_2 & 0x1ff) {



            



            while (VAR_3) {



                VAR_4 = (VAR_3 + 0x1ff) & ~0x1ff;

                if (VAR_4 > ALIGNED_BUFFER_SIZE)

                    VAR_4 = ALIGNED_BUFFER_SIZE;



                VAR_5 = raw_pread_aligned(VAR_0, VAR_1, s->aligned_buf, VAR_4);

                if (VAR_5 < 0)

                    return VAR_5;



                VAR_4 = VAR_5;

                if (VAR_4 > VAR_3)

                    VAR_4 = VAR_3;



                memcpy(VAR_2, s->aligned_buf, VAR_4);



                VAR_2 += VAR_4;

                VAR_1 += VAR_4;

                VAR_3 -= VAR_4;

                VAR_7 += VAR_4;

            }



            return VAR_7;

        }

    }



    return raw_pread_aligned(VAR_0, VAR_1, VAR_2, VAR_3) + VAR_7;

}

static int FUNC_0(BlockDriverState *VAR_0, int64_t VAR_1,
uint8_t *VAR_2, int VAR_3)
{ BDRVRawState *s = VAR_0->opaque; int VAR_4, VAR_5, VAR_6, VAR_7; VAR_7 = 0; if (s->aligned_buf != NULL)  { if (VAR_1 & 0x1ff) { VAR_6 = VAR_1 & 0x1ff; VAR_4 = (VAR_6 + VAR_3 + 0x1ff) & ~0x1ff; if (VAR_4 > ALIGNED_BUFFER_SIZE)
VAR_4 = ALIGNED_BUFFER_SIZE; VAR_5 = raw_pread_aligned(VAR_0, VAR_1 - VAR_6, s->aligned_buf, VAR_4); if (VAR_5 < 0)
return VAR_5; VAR_4 = 512 - VAR_6; if (VAR_4 > VAR_3)
VAR_4 = VAR_3; memcpy(VAR_2, s->aligned_buf + VAR_6, VAR_4); VAR_2 += VAR_4; VAR_1 += VAR_4; VAR_3 -= VAR_4; VAR_7 += VAR_4; if (VAR_3 == 0)
return VAR_7; } if (VAR_3 & 0x1ff || (uintptr_t) VAR_2 & 0x1ff) { while (VAR_3) { VAR_4 = (VAR_3 + 0x1ff) & ~0x1ff; if (VAR_4 > ALIGNED_BUFFER_SIZE)
VAR_4 = ALIGNED_BUFFER_SIZE; VAR_5 = raw_pread_aligned(VAR_0, VAR_1, s->aligned_buf, VAR_4); if (VAR_5 < 0)
return VAR_5; VAR_4 = VAR_5; if (VAR_4 > VAR_3)
VAR_4 = VAR_3; memcpy(VAR_2, s->aligned_buf, VAR_4); VAR_2 += VAR_4; VAR_1 += VAR_4; VAR_3 -= VAR_4; VAR_7 += VAR_4; } return VAR_7; } } return raw_pread_aligned(VAR_0, VAR_1, VAR_2, VAR_3) + VAR_7; }