static int vnc_update_stats(VncDisplay *vd,  struct timeval * tv)

{

    int width = pixman_image_get_width(vd->guest.fb);

    int height = pixman_image_get_height(vd->guest.fb);

    int x, y;

    struct timeval res;

    int has_dirty = 0;



    for (y = 0; y < height; y += VNC_STAT_RECT) {

        for (x = 0; x < width; x += VNC_STAT_RECT) {

            VncRectStat *rect = vnc_stat_rect(vd, x, y);



            rect->updated = false;

        }

    }



    qemu_timersub(tv, &VNC_REFRESH_STATS, &res);



    if (timercmp(&vd->guest.last_freq_check, &res, >)) {

        return has_dirty;

    }

    vd->guest.last_freq_check = *tv;



    for (y = 0; y < height; y += VNC_STAT_RECT) {

        for (x = 0; x < width; x += VNC_STAT_RECT) {

            VncRectStat *rect= vnc_stat_rect(vd, x, y);

            int count = ARRAY_SIZE(rect->times);

            struct timeval min, max;



            if (!timerisset(&rect->times[count - 1])) {

                continue ;

            }



            max = rect->times[(rect->idx + count - 1) % count];

            qemu_timersub(tv, &max, &res);



            if (timercmp(&res, &VNC_REFRESH_LOSSY, >)) {

                rect->freq = 0;

                has_dirty += vnc_refresh_lossy_rect(vd, x, y);

                memset(rect->times, 0, sizeof (rect->times));

                continue ;

            }



            min = rect->times[rect->idx];

            max = rect->times[(rect->idx + count - 1) % count];

            qemu_timersub(&max, &min, &res);



            rect->freq = res.tv_sec + res.tv_usec / 1000000.;

            rect->freq /= count;

            rect->freq = 1. / rect->freq;

        }

    }

    return has_dirty;

}

static int vnc_update_stats(VncDisplay *vd,  struct timeval * tv)

{

    int width = pixman_image_get_width(vd->guest.fb);

    int height = pixman_image_get_height(vd->guest.fb);

    int x, y;

    struct timeval res;

    int has_dirty = 0;



    for (y = 0; y < height; y += VNC_STAT_RECT) {

        for (x = 0; x < width; x += VNC_STAT_RECT) {

            VncRectStat *rect = vnc_stat_rect(vd, x, y);



            rect->updated = false;

        }

    }



    qemu_timersub(tv, &VNC_REFRESH_STATS, &res);



    if (timercmp(&vd->guest.last_freq_check, &res, >)) {

        return has_dirty;

    }

    vd->guest.last_freq_check = *tv;



    for (y = 0; y < height; y += VNC_STAT_RECT) {

        for (x = 0; x < width; x += VNC_STAT_RECT) {

            VncRectStat *rect= vnc_stat_rect(vd, x, y);

            int count = ARRAY_SIZE(rect->times);

            struct timeval min, max;



            if (!timerisset(&rect->times[count - 1])) {

                continue ;

            }



            max = rect->times[(rect->idx + count - 1) % count];

            qemu_timersub(tv, &max, &res);



            if (timercmp(&res, &VNC_REFRESH_LOSSY, >)) {

                rect->freq = 0;

                has_dirty += vnc_refresh_lossy_rect(vd, x, y);

                memset(rect->times, 0, sizeof (rect->times));

                continue ;

            }



            min = rect->times[rect->idx];

            max = rect->times[(rect->idx + count - 1) % count];

            qemu_timersub(&max, &min, &res);



            rect->freq = res.tv_sec + res.tv_usec / 1000000.;

            rect->freq /= count;

            rect->freq = 1. / rect->freq;

        }

    }

    return has_dirty;

}

    int width = pixman_image_get_width(vd->guest.fb);     int height = pixman_image_get_height(vd->guest.fb);
static int FUNC_0(VncDisplay *VAR_0,  struct timeval * VAR_1)

{

    int VAR_2 = pixman_image_get_width(VAR_0->guest.fb);

    int VAR_3 = pixman_image_get_height(VAR_0->guest.fb);

    int VAR_4, VAR_5;

    struct timeval VAR_6;

    int VAR_7 = 0;



    for (VAR_5 = 0; VAR_5 < VAR_3; VAR_5 += VNC_STAT_RECT) {

        for (VAR_4 = 0; VAR_4 < VAR_2; VAR_4 += VNC_STAT_RECT) {

            VncRectStat *rect = vnc_stat_rect(VAR_0, VAR_4, VAR_5);



            rect->updated = false;

        }

    }



    qemu_timersub(VAR_1, &VNC_REFRESH_STATS, &VAR_6);



    if (timercmp(&VAR_0->guest.last_freq_check, &VAR_6, >)) {

        return VAR_7;

    }

    VAR_0->guest.last_freq_check = *VAR_1;



    for (VAR_5 = 0; VAR_5 < VAR_3; VAR_5 += VNC_STAT_RECT) {

        for (VAR_4 = 0; VAR_4 < VAR_2; VAR_4 += VNC_STAT_RECT) {

            VncRectStat *rect= vnc_stat_rect(VAR_0, VAR_4, VAR_5);

            int VAR_8 = ARRAY_SIZE(rect->times);

            struct timeval VAR_9, VAR_10;



            if (!timerisset(&rect->times[VAR_8 - 1])) {

                continue ;

            }



            VAR_10 = rect->times[(rect->idx + VAR_8 - 1) % VAR_8];

            qemu_timersub(VAR_1, &VAR_10, &VAR_6);



            if (timercmp(&VAR_6, &VNC_REFRESH_LOSSY, >)) {

                rect->freq = 0;

                VAR_7 += vnc_refresh_lossy_rect(VAR_0, VAR_4, VAR_5);

                memset(rect->times, 0, sizeof (rect->times));

                continue ;

            }



            VAR_9 = rect->times[rect->idx];

            VAR_10 = rect->times[(rect->idx + VAR_8 - 1) % VAR_8];

            qemu_timersub(&VAR_10, &VAR_9, &VAR_6);



            rect->freq = VAR_6.tv_sec + VAR_6.tv_usec / 1000000.;

            rect->freq /= VAR_8;

            rect->freq = 1. / rect->freq;

        }

    }

    return VAR_7;

}

static int FUNC_0(VncDisplay *VAR_0,  struct timeval * VAR_1)
{ int VAR_2 = pixman_image_get_width(VAR_0->guest.fb); int VAR_3 = pixman_image_get_height(VAR_0->guest.fb); int VAR_4, VAR_5; struct timeval VAR_6; int VAR_7 = 0; for (VAR_5 = 0; VAR_5 < VAR_3; VAR_5 += VNC_STAT_RECT) { for (VAR_4 = 0; VAR_4 < VAR_2; VAR_4 += VNC_STAT_RECT) { VncRectStat *rect = vnc_stat_rect(VAR_0, VAR_4, VAR_5); rect->updated = false; } } qemu_timersub(VAR_1, &VNC_REFRESH_STATS, &VAR_6); if (timercmp(&VAR_0->guest.last_freq_check, &VAR_6, >)) { return VAR_7; } VAR_0->guest.last_freq_check = *VAR_1; for (VAR_5 = 0; VAR_5 < VAR_3; VAR_5 += VNC_STAT_RECT) { for (VAR_4 = 0; VAR_4 < VAR_2; VAR_4 += VNC_STAT_RECT) { VncRectStat *rect= vnc_stat_rect(VAR_0, VAR_4, VAR_5); int VAR_8 = ARRAY_SIZE(rect->times); struct timeval VAR_9, VAR_10; if (!timerisset(&rect->times[VAR_8 - 1])) { continue ; } VAR_10 = rect->times[(rect->idx + VAR_8 - 1) % VAR_8]; qemu_timersub(VAR_1, &VAR_10, &VAR_6); if (timercmp(&VAR_6, &VNC_REFRESH_LOSSY, >)) { rect->freq = 0; VAR_7 += vnc_refresh_lossy_rect(VAR_0, VAR_4, VAR_5); memset(rect->times, 0, sizeof (rect->times)); continue ; } VAR_9 = rect->times[rect->idx]; VAR_10 = rect->times[(rect->idx + VAR_8 - 1) % VAR_8]; qemu_timersub(&VAR_10, &VAR_9, &VAR_6); rect->freq = VAR_6.tv_sec + VAR_6.tv_usec / 1000000.; rect->freq /= VAR_8; rect->freq = 1. / rect->freq; } } return VAR_7; }