void *sk_value(const _STACK *st, int i)
{
    if (!st || (i < 0) || (i >= st->num))
        return NULL;
    return st->data[i];
}
['ASN1_VALUE *SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it)\n{\n    BIO *asnin;\n    STACK_OF(MIME_HEADER) *headers = NULL;\n    STACK_OF(BIO) *parts = NULL;\n    MIME_HEADER *hdr;\n    MIME_PARAM *prm;\n    ASN1_VALUE *val;\n    int ret;\n    if (bcont)\n        *bcont = NULL;\n    if ((headers = mime_parse_hdr(bio)) == NULL) {\n        ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_MIME_PARSE_ERROR);\n        return NULL;\n    }\n    if ((hdr = mime_hdr_find(headers, "content-type")) == NULL\n        || hdr->value == NULL) {\n        sk_MIME_HEADER_pop_free(headers, mime_hdr_free);\n        ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_NO_CONTENT_TYPE);\n        return NULL;\n    }\n    if (strcmp(hdr->value, "multipart/signed") == 0) {\n        prm = mime_param_find(hdr, "boundary");\n        if (!prm || !prm->param_value) {\n            sk_MIME_HEADER_pop_free(headers, mime_hdr_free);\n            ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_NO_MULTIPART_BOUNDARY);\n            return NULL;\n        }\n        ret = multi_split(bio, prm->param_value, &parts);\n        sk_MIME_HEADER_pop_free(headers, mime_hdr_free);\n        if (!ret || (sk_BIO_num(parts) != 2)) {\n            ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_NO_MULTIPART_BODY_FAILURE);\n            sk_BIO_pop_free(parts, BIO_vfree);\n            return NULL;\n        }\n        asnin = sk_BIO_value(parts, 1);\n        if ((headers = mime_parse_hdr(asnin)) == NULL) {\n            ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_MIME_SIG_PARSE_ERROR);\n            sk_BIO_pop_free(parts, BIO_vfree);\n            return NULL;\n        }\n        if ((hdr = mime_hdr_find(headers, "content-type")) == NULL\n            || hdr->value == NULL) {\n            sk_MIME_HEADER_pop_free(headers, mime_hdr_free);\n            ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_NO_SIG_CONTENT_TYPE);\n            return NULL;\n        }\n        if (strcmp(hdr->value, "application/x-pkcs7-signature") &&\n            strcmp(hdr->value, "application/pkcs7-signature")) {\n            ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_SIG_INVALID_MIME_TYPE);\n            ERR_add_error_data(2, "type: ", hdr->value);\n            sk_MIME_HEADER_pop_free(headers, mime_hdr_free);\n            sk_BIO_pop_free(parts, BIO_vfree);\n            return NULL;\n        }\n        sk_MIME_HEADER_pop_free(headers, mime_hdr_free);\n        if ((val = b64_read_asn1(asnin, it)) == NULL) {\n            ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_ASN1_SIG_PARSE_ERROR);\n            sk_BIO_pop_free(parts, BIO_vfree);\n            return NULL;\n        }\n        if (bcont) {\n            *bcont = sk_BIO_value(parts, 0);\n            BIO_free(asnin);\n            sk_BIO_free(parts);\n        } else\n            sk_BIO_pop_free(parts, BIO_vfree);\n        return val;\n    }\n    if (strcmp(hdr->value, "application/x-pkcs7-mime") &&\n        strcmp(hdr->value, "application/pkcs7-mime")) {\n        ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_INVALID_MIME_TYPE);\n        ERR_add_error_data(2, "type: ", hdr->value);\n        sk_MIME_HEADER_pop_free(headers, mime_hdr_free);\n        return NULL;\n    }\n    sk_MIME_HEADER_pop_free(headers, mime_hdr_free);\n    if ((val = b64_read_asn1(bio, it)) == NULL) {\n        ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_ASN1_PARSE_ERROR);\n        return NULL;\n    }\n    return val;\n}', 'static STACK_OF(MIME_HEADER) *mime_parse_hdr(BIO *bio)\n{\n    char *p, *q, c;\n    char *ntmp;\n    char linebuf[MAX_SMLEN];\n    MIME_HEADER *mhdr = NULL;\n    STACK_OF(MIME_HEADER) *headers;\n    int len, state, save_state = 0;\n    headers = sk_MIME_HEADER_new(mime_hdr_cmp);\n    if (headers == NULL)\n        return NULL;\n    while ((len = BIO_gets(bio, linebuf, MAX_SMLEN)) > 0) {\n        if (mhdr && isspace((unsigned char)linebuf[0]))\n            state = MIME_NAME;\n        else\n            state = MIME_START;\n        ntmp = NULL;\n        for (p = linebuf, q = linebuf; (c = *p) && (c != \'\\r\') && (c != \'\\n\');\n             p++) {\n            switch (state) {\n            case MIME_START:\n                if (c == \':\') {\n                    state = MIME_TYPE;\n                    *p = 0;\n                    ntmp = strip_ends(q);\n                    q = p + 1;\n                }\n                break;\n            case MIME_TYPE:\n                if (c == \';\') {\n                    mime_debug("Found End Value\\n");\n                    *p = 0;\n                    mhdr = mime_hdr_new(ntmp, strip_ends(q));\n                    sk_MIME_HEADER_push(headers, mhdr);\n                    ntmp = NULL;\n                    q = p + 1;\n                    state = MIME_NAME;\n                } else if (c == \'(\') {\n                    save_state = state;\n                    state = MIME_COMMENT;\n                }\n                break;\n            case MIME_COMMENT:\n                if (c == \')\') {\n                    state = save_state;\n                }\n                break;\n            case MIME_NAME:\n                if (c == \'=\') {\n                    state = MIME_VALUE;\n                    *p = 0;\n                    ntmp = strip_ends(q);\n                    q = p + 1;\n                }\n                break;\n            case MIME_VALUE:\n                if (c == \';\') {\n                    state = MIME_NAME;\n                    *p = 0;\n                    mime_hdr_addparam(mhdr, ntmp, strip_ends(q));\n                    ntmp = NULL;\n                    q = p + 1;\n                } else if (c == \'"\') {\n                    mime_debug("Found Quote\\n");\n                    state = MIME_QUOTE;\n                } else if (c == \'(\') {\n                    save_state = state;\n                    state = MIME_COMMENT;\n                }\n                break;\n            case MIME_QUOTE:\n                if (c == \'"\') {\n                    mime_debug("Found Match Quote\\n");\n                    state = MIME_VALUE;\n                }\n                break;\n            }\n        }\n        if (state == MIME_TYPE) {\n            mhdr = mime_hdr_new(ntmp, strip_ends(q));\n            sk_MIME_HEADER_push(headers, mhdr);\n        } else if (state == MIME_VALUE)\n            mime_hdr_addparam(mhdr, ntmp, strip_ends(q));\n        if (p == linebuf)\n            break;\n    }\n    return headers;\n}', 'DEFINE_STACK_OF(MIME_HEADER)', 'int sk_push(_STACK *st, void *data)\n{\n    return (sk_insert(st, data, st->num));\n}', 'int sk_insert(_STACK *st, void *data, int loc)\n{\n    char **s;\n    if (st == NULL)\n        return 0;\n    if (st->num_alloc <= st->num + 1) {\n        s = OPENSSL_realloc((char *)st->data,\n                            (unsigned int)sizeof(char *) * st->num_alloc * 2);\n        if (s == NULL)\n            return (0);\n        st->data = s;\n        st->num_alloc *= 2;\n    }\n    if ((loc >= (int)st->num) || (loc < 0))\n        st->data[st->num] = data;\n    else {\n        memmove(&(st->data[loc + 1]),\n                &(st->data[loc]), sizeof(char *) * (st->num - loc));\n        st->data[loc] = data;\n    }\n    st->num++;\n    st->sorted = 0;\n    return (st->num);\n}', 'void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)\n{\n    if (str == NULL)\n        return CRYPTO_malloc(num, file, line);\n    if (num == 0) {\n        CRYPTO_free(str);\n        return NULL;\n    }\n    allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n    if (call_malloc_debug) {\n        void *ret;\n        CRYPTO_mem_debug_realloc(str, NULL, num, 0, file, line);\n        ret = realloc(str, num);\n        CRYPTO_mem_debug_realloc(str, ret, num, 1, file, line);\n        return ret;\n    }\n#else\n    (void)file;\n    (void)line;\n#endif\n    return realloc(str, num);\n}', 'void CRYPTO_free(void *str)\n{\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n    if (call_malloc_debug) {\n        CRYPTO_mem_debug_free(str, 0);\n        free(str);\n        CRYPTO_mem_debug_free(str, 1);\n    } else {\n        free(str);\n    }\n#else\n    free(str);\n#endif\n}', 'static MIME_HEADER *mime_hdr_find(STACK_OF(MIME_HEADER) *hdrs, char *name)\n{\n    MIME_HEADER htmp;\n    int idx;\n    htmp.name = name;\n    idx = sk_MIME_HEADER_find(hdrs, &htmp);\n    if (idx < 0)\n        return NULL;\n    return sk_MIME_HEADER_value(hdrs, idx);\n}', 'void *sk_value(const _STACK *st, int i)\n{\n    if (!st || (i < 0) || (i >= st->num))\n        return NULL;\n    return st->data[i];\n}']