static int read_f(int argc, char **argv)

{

    struct timeval t1, t2;

    int Cflag = 0, pflag = 0, qflag = 0, vflag = 0;

    int Pflag = 0, sflag = 0, lflag = 0, bflag = 0;

    int c, cnt;

    char *buf;

    int64_t offset;

    int count;

    /* Some compilers get confused and warn if this is not initialized.  */

    int total = 0;

    int pattern = 0, pattern_offset = 0, pattern_count = 0;



    while ((c = getopt(argc, argv, "bCl:pP:qs:v")) != EOF) {

        switch (c) {

        case 'b':

            bflag = 1;

            break;

        case 'C':

            Cflag = 1;

            break;

        case 'l':

            lflag = 1;

            pattern_count = cvtnum(optarg);

            if (pattern_count < 0) {

                printf("non-numeric length argument -- %s\n", optarg);

                return 0;

            }

            break;

        case 'p':

            pflag = 1;

            break;

        case 'P':

            Pflag = 1;

            pattern = parse_pattern(optarg);

            if (pattern < 0) {

                return 0;

            }

            break;

        case 'q':

            qflag = 1;

            break;

        case 's':

            sflag = 1;

            pattern_offset = cvtnum(optarg);

            if (pattern_offset < 0) {

                printf("non-numeric length argument -- %s\n", optarg);

                return 0;

            }

            break;

        case 'v':

            vflag = 1;

            break;

        default:

            return command_usage(&read_cmd);

        }

    }



    if (optind != argc - 2) {

        return command_usage(&read_cmd);

    }



    if (bflag && pflag) {

        printf("-b and -p cannot be specified at the same time\n");

        return 0;

    }



    offset = cvtnum(argv[optind]);

    if (offset < 0) {

        printf("non-numeric length argument -- %s\n", argv[optind]);

        return 0;

    }



    optind++;

    count = cvtnum(argv[optind]);

    if (count < 0) {

        printf("non-numeric length argument -- %s\n", argv[optind]);

        return 0;

    }



    if (!Pflag && (lflag || sflag)) {

        return command_usage(&read_cmd);

    }



    if (!lflag) {

        pattern_count = count - pattern_offset;

    }



    if ((pattern_count < 0) || (pattern_count + pattern_offset > count))  {

        printf("pattern verification range exceeds end of read data\n");

        return 0;

    }



    if (!pflag) {

        if (offset & 0x1ff) {

            printf("offset %" PRId64 " is not sector aligned\n",

                   offset);

            return 0;

        }

        if (count & 0x1ff) {

            printf("count %d is not sector aligned\n",

                   count);

            return 0;

        }

    }



    buf = qemu_io_alloc(count, 0xab);



    gettimeofday(&t1, NULL);

    if (pflag) {

        cnt = do_pread(buf, offset, count, &total);

    } else if (bflag) {

        cnt = do_load_vmstate(buf, offset, count, &total);

    } else {

        cnt = do_read(buf, offset, count, &total);

    }

    gettimeofday(&t2, NULL);



    if (cnt < 0) {

        printf("read failed: %s\n", strerror(-cnt));

        goto out;

    }



    if (Pflag) {

        void *cmp_buf = malloc(pattern_count);

        memset(cmp_buf, pattern, pattern_count);

        if (memcmp(buf + pattern_offset, cmp_buf, pattern_count)) {

            printf("Pattern verification failed at offset %"

                   PRId64 ", %d bytes\n",

                   offset + pattern_offset, pattern_count);

        }

        free(cmp_buf);

    }



    if (qflag) {

        goto out;

    }



    if (vflag) {

        dump_buffer(buf, offset, count);

    }



    /* Finally, report back -- -C gives a parsable format */

    t2 = tsub(t2, t1);

    print_report("read", &t2, offset, count, total, cnt, Cflag);



out:

    qemu_io_free(buf);



    return 0;

}

static int read_f(int argc, char **argv)

{

    struct timeval t1, t2;

    int Cflag = 0, pflag = 0, qflag = 0, vflag = 0;

    int Pflag = 0, sflag = 0, lflag = 0, bflag = 0;

    int c, cnt;

    char *buf;

    int64_t offset;

    int count;

    

    int total = 0;

    int pattern = 0, pattern_offset = 0, pattern_count = 0;



    while ((c = getopt(argc, argv, "bCl:pP:qs:v")) != EOF) {

        switch (c) {

        case 'b':

            bflag = 1;

            break;

        case 'C':

            Cflag = 1;

            break;

        case 'l':

            lflag = 1;

            pattern_count = cvtnum(optarg);

            if (pattern_count < 0) {

                printf("non-numeric length argument -- %s\n", optarg);

                return 0;

            }

            break;

        case 'p':

            pflag = 1;

            break;

        case 'P':

            Pflag = 1;

            pattern = parse_pattern(optarg);

            if (pattern < 0) {

                return 0;

            }

            break;

        case 'q':

            qflag = 1;

            break;

        case 's':

            sflag = 1;

            pattern_offset = cvtnum(optarg);

            if (pattern_offset < 0) {

                printf("non-numeric length argument -- %s\n", optarg);

                return 0;

            }

            break;

        case 'v':

            vflag = 1;

            break;

        default:

            return command_usage(&read_cmd);

        }

    }



    if (optind != argc - 2) {

        return command_usage(&read_cmd);

    }



    if (bflag && pflag) {

        printf("-b and -p cannot be specified at the same time\n");

        return 0;

    }



    offset = cvtnum(argv[optind]);

    if (offset < 0) {

        printf("non-numeric length argument -- %s\n", argv[optind]);

        return 0;

    }



    optind++;

    count = cvtnum(argv[optind]);

    if (count < 0) {

        printf("non-numeric length argument -- %s\n", argv[optind]);

        return 0;

    }



    if (!Pflag && (lflag || sflag)) {

        return command_usage(&read_cmd);

    }



    if (!lflag) {

        pattern_count = count - pattern_offset;

    }



    if ((pattern_count < 0) || (pattern_count + pattern_offset > count))  {

        printf("pattern verification range exceeds end of read data\n");

        return 0;

    }



    if (!pflag) {

        if (offset & 0x1ff) {

            printf("offset %" PRId64 " is not sector aligned\n",

                   offset);

            return 0;

        }

        if (count & 0x1ff) {

            printf("count %d is not sector aligned\n",

                   count);

            return 0;

        }

    }



    buf = qemu_io_alloc(count, 0xab);



    gettimeofday(&t1, NULL);

    if (pflag) {

        cnt = do_pread(buf, offset, count, &total);

    } else if (bflag) {

        cnt = do_load_vmstate(buf, offset, count, &total);

    } else {

        cnt = do_read(buf, offset, count, &total);

    }

    gettimeofday(&t2, NULL);



    if (cnt < 0) {

        printf("read failed: %s\n", strerror(-cnt));

        goto out;

    }



    if (Pflag) {

        void *cmp_buf = malloc(pattern_count);

        memset(cmp_buf, pattern, pattern_count);

        if (memcmp(buf + pattern_offset, cmp_buf, pattern_count)) {

            printf("Pattern verification failed at offset %"

                   PRId64 ", %d bytes\n",

                   offset + pattern_offset, pattern_count);

        }

        free(cmp_buf);

    }



    if (qflag) {

        goto out;

    }



    if (vflag) {

        dump_buffer(buf, offset, count);

    }



    

    t2 = tsub(t2, t1);

    print_report("read", &t2, offset, count, total, cnt, Cflag);



out:

    qemu_io_free(buf);



    return 0;

}

static int FUNC_0(int VAR_0, char **VAR_1)

{

    struct timeval VAR_2, VAR_3;

    int VAR_4 = 0, VAR_5 = 0, VAR_6 = 0, VAR_7 = 0;

    int VAR_8 = 0, VAR_9 = 0, VAR_10 = 0, VAR_11 = 0;

    int VAR_12, VAR_13;

    char *VAR_14;

    int64_t offset;

    int VAR_15;

    

    int VAR_16 = 0;

    int VAR_17 = 0, VAR_18 = 0, VAR_19 = 0;



    while ((VAR_12 = getopt(VAR_0, VAR_1, "bCl:pP:qs:v")) != EOF) {

        switch (VAR_12) {

        case 'b':

            VAR_11 = 1;

            break;

        case 'C':

            VAR_4 = 1;

            break;

        case 'l':

            VAR_10 = 1;

            VAR_19 = cvtnum(optarg);

            if (VAR_19 < 0) {

                printf("non-numeric length argument -- %s\n", optarg);

                return 0;

            }

            break;

        case 'p':

            VAR_5 = 1;

            break;

        case 'P':

            VAR_8 = 1;

            VAR_17 = parse_pattern(optarg);

            if (VAR_17 < 0) {

                return 0;

            }

            break;

        case 'q':

            VAR_6 = 1;

            break;

        case 's':

            VAR_9 = 1;

            VAR_18 = cvtnum(optarg);

            if (VAR_18 < 0) {

                printf("non-numeric length argument -- %s\n", optarg);

                return 0;

            }

            break;

        case 'v':

            VAR_7 = 1;

            break;

        default:

            return command_usage(&read_cmd);

        }

    }



    if (optind != VAR_0 - 2) {

        return command_usage(&read_cmd);

    }



    if (VAR_11 && VAR_5) {

        printf("-b and -p cannot be specified at the same time\n");

        return 0;

    }



    offset = cvtnum(VAR_1[optind]);

    if (offset < 0) {

        printf("non-numeric length argument -- %s\n", VAR_1[optind]);

        return 0;

    }



    optind++;

    VAR_15 = cvtnum(VAR_1[optind]);

    if (VAR_15 < 0) {

        printf("non-numeric length argument -- %s\n", VAR_1[optind]);

        return 0;

    }



    if (!VAR_8 && (VAR_10 || VAR_9)) {

        return command_usage(&read_cmd);

    }



    if (!VAR_10) {

        VAR_19 = VAR_15 - VAR_18;

    }



    if ((VAR_19 < 0) || (VAR_19 + VAR_18 > VAR_15))  {

        printf("VAR_17 verification range exceeds end of read data\n");

        return 0;

    }



    if (!VAR_5) {

        if (offset & 0x1ff) {

            printf("offset %" PRId64 " is not sector aligned\n",

                   offset);

            return 0;

        }

        if (VAR_15 & 0x1ff) {

            printf("VAR_15 %d is not sector aligned\n",

                   VAR_15);

            return 0;

        }

    }



    VAR_14 = qemu_io_alloc(VAR_15, 0xab);



    gettimeofday(&VAR_2, NULL);

    if (VAR_5) {

        VAR_13 = do_pread(VAR_14, offset, VAR_15, &VAR_16);

    } else if (VAR_11) {

        VAR_13 = do_load_vmstate(VAR_14, offset, VAR_15, &VAR_16);

    } else {

        VAR_13 = do_read(VAR_14, offset, VAR_15, &VAR_16);

    }

    gettimeofday(&VAR_3, NULL);



    if (VAR_13 < 0) {

        printf("read failed: %s\n", strerror(-VAR_13));

        goto out;

    }



    if (VAR_8) {

        void *VAR_20 = malloc(VAR_19);

        memset(VAR_20, VAR_17, VAR_19);

        if (memcmp(VAR_14 + VAR_18, VAR_20, VAR_19)) {

            printf("Pattern verification failed at offset %"

                   PRId64 ", %d bytes\n",

                   offset + VAR_18, VAR_19);

        }

        free(VAR_20);

    }



    if (VAR_6) {

        goto out;

    }



    if (VAR_7) {

        dump_buffer(VAR_14, offset, VAR_15);

    }



    

    VAR_3 = tsub(VAR_3, VAR_2);

    print_report("read", &VAR_3, offset, VAR_15, VAR_16, VAR_13, VAR_4);



out:

    qemu_io_free(VAR_14);



    return 0;

}

static int FUNC_0(int VAR_0, char **VAR_1)
{ struct timeval VAR_2, VAR_3; int VAR_4 = 0, VAR_5 = 0, VAR_6 = 0, VAR_7 = 0; int VAR_8 = 0, VAR_9 = 0, VAR_10 = 0, VAR_11 = 0; int VAR_12, VAR_13; char *VAR_14; int64_t offset; int VAR_15; int VAR_16 = 0; int VAR_17 = 0, VAR_18 = 0, VAR_19 = 0; while ((VAR_12 = getopt(VAR_0, VAR_1, "bCl:pP:qs:v")) != EOF) { switch (VAR_12) { case 'b':
VAR_11 = 1; break; case 'C':
VAR_4 = 1; break; case 'l':
VAR_10 = 1; VAR_19 = cvtnum(optarg); if (VAR_19 < 0) { printf("non-numeric length argument -- %s\n", optarg); return 0; } break; case 'p':
VAR_5 = 1; break; case 'P':
VAR_8 = 1; VAR_17 = parse_pattern(optarg); if (VAR_17 < 0) { return 0; } break; case 'q':
VAR_6 = 1; break; case 's':
VAR_9 = 1; VAR_18 = cvtnum(optarg); if (VAR_18 < 0) { printf("non-numeric length argument -- %s\n", optarg); return 0; } break; case 'v':
VAR_7 = 1; break; default:
return command_usage(&read_cmd); } } if (optind != VAR_0 - 2) { return command_usage(&read_cmd); } if (VAR_11 && VAR_5) { printf("-b and -p cannot be specified at the same time\n"); return 0; } offset = cvtnum(VAR_1[optind]); if (offset < 0) { printf("non-numeric length argument -- %s\n", VAR_1[optind]); return 0; } optind++; VAR_15 = cvtnum(VAR_1[optind]); if (VAR_15 < 0) { printf("non-numeric length argument -- %s\n", VAR_1[optind]); return 0; } if (!VAR_8 && (VAR_10 || VAR_9)) { return command_usage(&read_cmd); } if (!VAR_10) { VAR_19 = VAR_15 - VAR_18; } if ((VAR_19 < 0) || (VAR_19 + VAR_18 > VAR_15))  { printf("VAR_17 verification range exceeds end of read data\n"); return 0; } if (!VAR_5) { if (offset & 0x1ff) { printf("offset %" PRId64 " is not sector aligned\n",
offset); return 0; } if (VAR_15 & 0x1ff) { printf("VAR_15 %d is not sector aligned\n",
VAR_15); return 0; } } VAR_14 = qemu_io_alloc(VAR_15, 0xab); gettimeofday(&VAR_2, NULL); if (VAR_5) { VAR_13 = do_pread(VAR_14, offset, VAR_15, &VAR_16); } else if (VAR_11) { VAR_13 = do_load_vmstate(VAR_14, offset, VAR_15, &VAR_16); } else { VAR_13 = do_read(VAR_14, offset, VAR_15, &VAR_16); } gettimeofday(&VAR_3, NULL); if (VAR_13 < 0) { printf("read failed: %s\n", strerror(-VAR_13)); goto out; } if (VAR_8) { void *VAR_20 = malloc(VAR_19); memset(VAR_20, VAR_17, VAR_19); if (memcmp(VAR_14 + VAR_18, VAR_20, VAR_19)) { printf("Pattern verification failed at offset %"
PRId64 ", %d bytes\n",
offset + VAR_18, VAR_19); } free(VAR_20); } if (VAR_6) { goto out; } if (VAR_7) { dump_buffer(VAR_14, offset, VAR_15); } VAR_3 = tsub(VAR_3, VAR_2); print_report("read", &VAR_3, offset, VAR_15, VAR_16, VAR_13, VAR_4); out:
qemu_io_free(VAR_14); return 0; }