static int vnc_update_client(VncState *vs, int has_dirty, bool sync)

{

    vs->has_dirty += has_dirty;

    if (vs->need_update && vs->ioc != NULL) {

        VncDisplay *vd = vs->vd;

        VncJob *job;

        int y;

        int height, width;

        int n = 0;



        if (vs->output.offset && !vs->audio_cap && !vs->force_update)

            /* kernel send buffers are full -> drop frames to throttle */

            return 0;



        if (!vs->has_dirty && !vs->audio_cap && !vs->force_update)

            return 0;



        /*

         * Send screen updates to the vnc client using the server

         * surface and server dirty map.  guest surface updates

         * happening in parallel don't disturb us, the next pass will

         * send them to the client.

         */

        job = vnc_job_new(vs);



        height = pixman_image_get_height(vd->server);

        width = pixman_image_get_width(vd->server);



        y = 0;

        for (;;) {

            int x, h;

            unsigned long x2;

            unsigned long offset = find_next_bit((unsigned long *) &vs->dirty,

                                                 height * VNC_DIRTY_BPL(vs),

                                                 y * VNC_DIRTY_BPL(vs));

            if (offset == height * VNC_DIRTY_BPL(vs)) {

                /* no more dirty bits */

                break;

            }

            y = offset / VNC_DIRTY_BPL(vs);

            x = offset % VNC_DIRTY_BPL(vs);

            x2 = find_next_zero_bit((unsigned long *) &vs->dirty[y],

                                    VNC_DIRTY_BPL(vs), x);

            bitmap_clear(vs->dirty[y], x, x2 - x);

            h = find_and_clear_dirty_height(vs, y, x, x2, height);

            x2 = MIN(x2, width / VNC_DIRTY_PIXELS_PER_BIT);

            if (x2 > x) {

                n += vnc_job_add_rect(job, x * VNC_DIRTY_PIXELS_PER_BIT, y,

                                      (x2 - x) * VNC_DIRTY_PIXELS_PER_BIT, h);

            }

            if (!x && x2 == width / VNC_DIRTY_PIXELS_PER_BIT) {

                y += h;

                if (y == height) {

                    break;

                }

            }

        }



        vnc_job_push(job);

        if (sync) {

            vnc_jobs_join(vs);

        }

        vs->force_update = 0;

        vs->has_dirty = 0;

        return n;

    }



    if (vs->disconnecting) {

        vnc_disconnect_finish(vs);

    } else if (sync) {

        vnc_jobs_join(vs);

    }



    return 0;

}

static int vnc_update_client(VncState *vs, int has_dirty, bool sync)

{

    vs->has_dirty += has_dirty;

    if (vs->need_update && vs->ioc != NULL) {

        VncDisplay *vd = vs->vd;

        VncJob *job;

        int y;

        int height, width;

        int n = 0;



        if (vs->output.offset && !vs->audio_cap && !vs->force_update)

            

            return 0;



        if (!vs->has_dirty && !vs->audio_cap && !vs->force_update)

            return 0;



        











        job = vnc_job_new(vs);



        height = pixman_image_get_height(vd->server);

        width = pixman_image_get_width(vd->server);



        y = 0;

        for (;;) {

            int x, h;

            unsigned long x2;

            unsigned long offset = find_next_bit((unsigned long *) &vs->dirty,

                                                 height * VNC_DIRTY_BPL(vs),

                                                 y * VNC_DIRTY_BPL(vs));

            if (offset == height * VNC_DIRTY_BPL(vs)) {

                

                break;

            }

            y = offset / VNC_DIRTY_BPL(vs);

            x = offset % VNC_DIRTY_BPL(vs);

            x2 = find_next_zero_bit((unsigned long *) &vs->dirty[y],

                                    VNC_DIRTY_BPL(vs), x);

            bitmap_clear(vs->dirty[y], x, x2 - x);

            h = find_and_clear_dirty_height(vs, y, x, x2, height);

            x2 = MIN(x2, width / VNC_DIRTY_PIXELS_PER_BIT);

            if (x2 > x) {

                n += vnc_job_add_rect(job, x * VNC_DIRTY_PIXELS_PER_BIT, y,

                                      (x2 - x) * VNC_DIRTY_PIXELS_PER_BIT, h);

            }

            if (!x && x2 == width / VNC_DIRTY_PIXELS_PER_BIT) {

                y += h;

                if (y == height) {

                    break;

                }

            }

        }



        vnc_job_push(job);

        if (sync) {

            vnc_jobs_join(vs);

        }

        vs->force_update = 0;

        vs->has_dirty = 0;

        return n;

    }



    if (vs->disconnecting) {

        vnc_disconnect_finish(vs);

    } else if (sync) {

        vnc_jobs_join(vs);

    }



    return 0;

}

    if (vs->need_update && vs->ioc != NULL) {
static int FUNC_0(VncState *VAR_0, int VAR_1, bool VAR_2)

{

    VAR_0->VAR_1 += VAR_1;

    if (VAR_0->need_update && VAR_0->ioc != NULL) {

        VncDisplay *vd = VAR_0->vd;

        VncJob *job;

        int VAR_3;

        int VAR_4, VAR_5;

        int VAR_6 = 0;



        if (VAR_0->output.VAR_10 && !VAR_0->audio_cap && !VAR_0->force_update)

            

            return 0;



        if (!VAR_0->VAR_1 && !VAR_0->audio_cap && !VAR_0->force_update)

            return 0;



        











        job = vnc_job_new(VAR_0);



        VAR_4 = pixman_image_get_height(vd->server);

        VAR_5 = pixman_image_get_width(vd->server);



        VAR_3 = 0;

        for (;;) {

            int VAR_7, VAR_8;

            unsigned long VAR_9;

            unsigned long VAR_10 = find_next_bit((unsigned long *) &VAR_0->dirty,

                                                 VAR_4 * VNC_DIRTY_BPL(VAR_0),

                                                 VAR_3 * VNC_DIRTY_BPL(VAR_0));

            if (VAR_10 == VAR_4 * VNC_DIRTY_BPL(VAR_0)) {

                

                break;

            }

            VAR_3 = VAR_10 / VNC_DIRTY_BPL(VAR_0);

            VAR_7 = VAR_10 % VNC_DIRTY_BPL(VAR_0);

            VAR_9 = find_next_zero_bit((unsigned long *) &VAR_0->dirty[VAR_3],

                                    VNC_DIRTY_BPL(VAR_0), VAR_7);

            bitmap_clear(VAR_0->dirty[VAR_3], VAR_7, VAR_9 - VAR_7);

            VAR_8 = find_and_clear_dirty_height(VAR_0, VAR_3, VAR_7, VAR_9, VAR_4);

            VAR_9 = MIN(VAR_9, VAR_5 / VNC_DIRTY_PIXELS_PER_BIT);

            if (VAR_9 > VAR_7) {

                VAR_6 += vnc_job_add_rect(job, VAR_7 * VNC_DIRTY_PIXELS_PER_BIT, VAR_3,

                                      (VAR_9 - VAR_7) * VNC_DIRTY_PIXELS_PER_BIT, VAR_8);

            }

            if (!VAR_7 && VAR_9 == VAR_5 / VNC_DIRTY_PIXELS_PER_BIT) {

                VAR_3 += VAR_8;

                if (VAR_3 == VAR_4) {

                    break;

                }

            }

        }



        vnc_job_push(job);

        if (VAR_2) {

            vnc_jobs_join(VAR_0);

        }

        VAR_0->force_update = 0;

        VAR_0->VAR_1 = 0;

        return VAR_6;

    }



    if (VAR_0->disconnecting) {

        vnc_disconnect_finish(VAR_0);

    } else if (VAR_2) {

        vnc_jobs_join(VAR_0);

    }



    return 0;

}

static int FUNC_0(VncState *VAR_0, int VAR_1, bool VAR_2)
{ VAR_0->VAR_1 += VAR_1; if (VAR_0->need_update && VAR_0->ioc != NULL) { VncDisplay *vd = VAR_0->vd; VncJob *job; int VAR_3; int VAR_4, VAR_5; int VAR_6 = 0; if (VAR_0->output.VAR_10 && !VAR_0->audio_cap && !VAR_0->force_update)
return 0; if (!VAR_0->VAR_1 && !VAR_0->audio_cap && !VAR_0->force_update)
return 0; job = vnc_job_new(VAR_0); VAR_4 = pixman_image_get_height(vd->server); VAR_5 = pixman_image_get_width(vd->server); VAR_3 = 0; for (;;) { int VAR_7, VAR_8; unsigned long VAR_9; unsigned long VAR_10 = find_next_bit((unsigned long *) &VAR_0->dirty,
VAR_4 * VNC_DIRTY_BPL(VAR_0),
VAR_3 * VNC_DIRTY_BPL(VAR_0)); if (VAR_10 == VAR_4 * VNC_DIRTY_BPL(VAR_0)) { break; } VAR_3 = VAR_10 / VNC_DIRTY_BPL(VAR_0); VAR_7 = VAR_10 % VNC_DIRTY_BPL(VAR_0); VAR_9 = find_next_zero_bit((unsigned long *) &VAR_0->dirty[VAR_3],
VNC_DIRTY_BPL(VAR_0), VAR_7); bitmap_clear(VAR_0->dirty[VAR_3], VAR_7, VAR_9 - VAR_7); VAR_8 = find_and_clear_dirty_height(VAR_0, VAR_3, VAR_7, VAR_9, VAR_4); VAR_9 = MIN(VAR_9, VAR_5 / VNC_DIRTY_PIXELS_PER_BIT); if (VAR_9 > VAR_7) { VAR_6 += vnc_job_add_rect(job, VAR_7 * VNC_DIRTY_PIXELS_PER_BIT, VAR_3,
(VAR_9 - VAR_7) * VNC_DIRTY_PIXELS_PER_BIT, VAR_8); } if (!VAR_7 && VAR_9 == VAR_5 / VNC_DIRTY_PIXELS_PER_BIT) { VAR_3 += VAR_8; if (VAR_3 == VAR_4) { break; } } } vnc_job_push(job); if (VAR_2) { vnc_jobs_join(VAR_0); } VAR_0->force_update = 0; VAR_0->VAR_1 = 0; return VAR_6; } if (VAR_0->disconnecting) { vnc_disconnect_finish(VAR_0); } else if (VAR_2) { vnc_jobs_join(VAR_0); } return 0; }