static ossl_inline void packet_forward(PACKET *pkt, size_t len)
{
    pkt->curr += len;
    pkt->remaining -= len;
}
['static int async_write(BIO *bio, const char *in, int inl)\n{\n    struct async_ctrs *ctrs;\n    int ret = 0;\n    size_t written = 0;\n    BIO *next = BIO_next(bio);\n    if (inl <= 0)\n        return 0;\n    if (next == NULL)\n        return 0;\n    ctrs = BIO_get_data(bio);\n    BIO_clear_retry_flags(bio);\n    if (ctrs->wctr > 0) {\n        ctrs->wctr = 0;\n        if (fragment) {\n            PACKET pkt;\n            if (!PACKET_buf_init(&pkt, (const unsigned char *)in, inl))\n                return -1;\n            while (PACKET_remaining(&pkt) > 0) {\n                PACKET payload, wholebody, sessionid, extensions;\n                unsigned int contenttype, versionhi, versionlo, data;\n                unsigned int msgtype = 0, negversion = 0;\n                if (!PACKET_get_1(&pkt, &contenttype)\n                        || !PACKET_get_1(&pkt, &versionhi)\n                        || !PACKET_get_1(&pkt, &versionlo)\n                        || !PACKET_get_length_prefixed_2(&pkt, &payload))\n                    return -1;\n                written += SSL3_RT_HEADER_LENGTH;\n                wholebody = payload;\n                if (contenttype == SSL3_RT_HANDSHAKE\n                        && !PACKET_get_1(&wholebody, &msgtype))\n                    return -1;\n                if (msgtype == SSL3_MT_SERVER_HELLO) {\n                    if (!PACKET_forward(&wholebody,\n                                            SSL3_HM_HEADER_LENGTH - 1)\n                            || !PACKET_get_net_2(&wholebody, &negversion)\n                            || !PACKET_forward(&wholebody, 32)\n                            || !PACKET_get_length_prefixed_1(&wholebody,\n                                                             &sessionid)\n                            || !PACKET_forward(&wholebody, 2 + 1)\n                            || !PACKET_get_length_prefixed_2(&wholebody,\n                                                             &extensions))\n                        return -1;\n                    while (PACKET_remaining(&extensions)) {\n                        unsigned int type;\n                        PACKET extbody;\n                        if (!PACKET_get_net_2(&extensions, &type)\n                                || !PACKET_get_length_prefixed_2(&extensions,\n                                &extbody))\n                            return -1;\n                        if (type == TLSEXT_TYPE_supported_versions\n                                && (!PACKET_get_net_2(&extbody, &negversion)\n                                    || PACKET_remaining(&extbody) != 0))\n                            return -1;\n                    }\n                }\n                while (PACKET_get_1(&payload, &data)) {\n                    char smallrec[MIN_RECORD_LEN] = {\n                        0,\n                        0,\n                        0,\n                        0,\n                        1,\n                        0\n                    };\n                    smallrec[CONTENTTYPEPOS] = contenttype;\n                    smallrec[VERSIONHIPOS] = versionhi;\n                    smallrec[VERSIONLOPOS] = versionlo;\n                    smallrec[DATAPOS] = data;\n                    ret = BIO_write(next, smallrec, MIN_RECORD_LEN);\n                    if (ret <= 0)\n                        return -1;\n                    written++;\n                }\n                if (contenttype == SSL3_RT_CHANGE_CIPHER_SPEC\n                        || (negversion == TLS1_3_VERSION_DRAFT\n                            && msgtype == SSL3_MT_SERVER_HELLO)) {\n                    fragment = 0;\n                    break;\n                }\n            }\n        }\n        ret = 0;\n        if ((int)written < inl) {\n            ret = BIO_write(next, in + written, inl - written);\n        }\n        if (ret <= 0 && BIO_should_write(next))\n            BIO_set_retry_write(bio);\n        else\n            ret += written;\n    } else {\n        ctrs->wctr++;\n        BIO_set_retry_write(bio);\n    }\n    return ret;\n}', 'static ossl_inline int PACKET_get_1(PACKET *pkt, unsigned int *data)\n{\n    if (!PACKET_peek_1(pkt, data))\n        return 0;\n    packet_forward(pkt, 1);\n    return 1;\n}', 'static ossl_inline int PACKET_peek_1(const PACKET *pkt,\n                                            unsigned int *data)\n{\n    if (!PACKET_remaining(pkt))\n        return 0;\n    *data = *pkt->curr;\n    return 1;\n}', 'static ossl_inline int PACKET_forward(PACKET *pkt, size_t len)\n{\n    if (PACKET_remaining(pkt) < len)\n        return 0;\n    packet_forward(pkt, len);\n    return 1;\n}', 'static ossl_inline int PACKET_get_net_2(PACKET *pkt, unsigned int *data)\n{\n    if (!PACKET_peek_net_2(pkt, data))\n        return 0;\n    packet_forward(pkt, 2);\n    return 1;\n}', 'static ossl_inline int PACKET_peek_net_2(const PACKET *pkt,\n                                                unsigned int *data)\n{\n    if (PACKET_remaining(pkt) < 2)\n        return 0;\n    *data = ((unsigned int)(*pkt->curr)) << 8;\n    *data |= *(pkt->curr + 1);\n    return 1;\n}', 'static ossl_inline void packet_forward(PACKET *pkt, size_t len)\n{\n    pkt->curr += len;\n    pkt->remaining -= len;\n}']