static int tpm_passthrough_test_tpmdev(int fd)

{

    struct tpm_req_hdr req = {

        .tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),

        .len = cpu_to_be32(sizeof(req)),

        .ordinal = cpu_to_be32(TPM_ORD_GetTicks),

    };

    struct tpm_resp_hdr *resp;

    fd_set readfds;

    int n;

    struct timeval tv = {

        .tv_sec = 1,

        .tv_usec = 0,

    };

    unsigned char buf[1024];



    n = write(fd, &req, sizeof(req));

    if (n < 0) {

        return errno;

    }

    if (n != sizeof(req)) {

        return EFAULT;

    }



    FD_ZERO(&readfds);

    FD_SET(fd, &readfds);



    /* wait for a second */

    n = select(fd + 1, &readfds, NULL, NULL, &tv);

    if (n != 1) {

        return errno;

    }



    n = read(fd, &buf, sizeof(buf));

    if (n < sizeof(struct tpm_resp_hdr)) {

        return EFAULT;

    }



    resp = (struct tpm_resp_hdr *)buf;

    /* check the header */

    if (be16_to_cpu(resp->tag) != TPM_TAG_RSP_COMMAND ||

        be32_to_cpu(resp->len) != n) {

        return EBADMSG;

    }



    return 0;

}

static int tpm_passthrough_test_tpmdev(int fd)

{

    struct tpm_req_hdr req = {

        .tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),

        .len = cpu_to_be32(sizeof(req)),

        .ordinal = cpu_to_be32(TPM_ORD_GetTicks),

    };

    struct tpm_resp_hdr *resp;

    fd_set readfds;

    int n;

    struct timeval tv = {

        .tv_sec = 1,

        .tv_usec = 0,

    };

    unsigned char buf[1024];



    n = write(fd, &req, sizeof(req));

    if (n < 0) {

        return errno;

    }

    if (n != sizeof(req)) {

        return EFAULT;

    }



    FD_ZERO(&readfds);

    FD_SET(fd, &readfds);



    

    n = select(fd + 1, &readfds, NULL, NULL, &tv);

    if (n != 1) {

        return errno;

    }



    n = read(fd, &buf, sizeof(buf));

    if (n < sizeof(struct tpm_resp_hdr)) {

        return EFAULT;

    }



    resp = (struct tpm_resp_hdr *)buf;

    

    if (be16_to_cpu(resp->tag) != TPM_TAG_RSP_COMMAND ||

        be32_to_cpu(resp->len) != n) {

        return EBADMSG;

    }



    return 0;

}

static int FUNC_0(int VAR_0)

{

    struct tpm_req_hdr VAR_1 = {

        .tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),

        .len = cpu_to_be32(sizeof(VAR_1)),

        .ordinal = cpu_to_be32(TPM_ORD_GetTicks),

    };

    struct tpm_resp_hdr *VAR_2;

    fd_set readfds;

    int VAR_3;

    struct timeval VAR_4 = {

        .tv_sec = 1,

        .tv_usec = 0,

    };

    unsigned char VAR_5[1024];



    VAR_3 = write(VAR_0, &VAR_1, sizeof(VAR_1));

    if (VAR_3 < 0) {

        return errno;

    }

    if (VAR_3 != sizeof(VAR_1)) {

        return EFAULT;

    }



    FD_ZERO(&readfds);

    FD_SET(VAR_0, &readfds);



    

    VAR_3 = select(VAR_0 + 1, &readfds, NULL, NULL, &VAR_4);

    if (VAR_3 != 1) {

        return errno;

    }



    VAR_3 = read(VAR_0, &VAR_5, sizeof(VAR_5));

    if (VAR_3 < sizeof(struct tpm_resp_hdr)) {

        return EFAULT;

    }



    VAR_2 = (struct tpm_resp_hdr *)VAR_5;

    

    if (be16_to_cpu(VAR_2->tag) != TPM_TAG_RSP_COMMAND ||

        be32_to_cpu(VAR_2->len) != VAR_3) {

        return EBADMSG;

    }



    return 0;

}

static int FUNC_0(int VAR_0)
{ struct tpm_req_hdr VAR_1 = { .tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
.len = cpu_to_be32(sizeof(VAR_1)),
.ordinal = cpu_to_be32(TPM_ORD_GetTicks),
}; struct tpm_resp_hdr *VAR_2; fd_set readfds; int VAR_3; struct timeval VAR_4 = { .tv_sec = 1,
.tv_usec = 0,
}; unsigned char VAR_5[1024]; VAR_3 = write(VAR_0, &VAR_1, sizeof(VAR_1)); if (VAR_3 < 0) { return errno; } if (VAR_3 != sizeof(VAR_1)) { return EFAULT; } FD_ZERO(&readfds); FD_SET(VAR_0, &readfds); VAR_3 = select(VAR_0 + 1, &readfds, NULL, NULL, &VAR_4); if (VAR_3 != 1) { return errno; } VAR_3 = read(VAR_0, &VAR_5, sizeof(VAR_5)); if (VAR_3 < sizeof(struct tpm_resp_hdr)) { return EFAULT; } VAR_2 = (struct tpm_resp_hdr *)VAR_5; if (be16_to_cpu(VAR_2->tag) != TPM_TAG_RSP_COMMAND ||
be32_to_cpu(VAR_2->len) != VAR_3) { return EBADMSG; } return 0; }