int X509_TRUST_add(int id, int flags, int (*ck) (X509_TRUST *, X509 *, int),
                   const char *name, int arg1, void *arg2)
{
    int idx;
    X509_TRUST *trtmp;
    flags &= ~X509_TRUST_DYNAMIC;
    flags |= X509_TRUST_DYNAMIC_NAME;
    idx = X509_TRUST_get_by_id(id);
    if (idx == -1) {
        if ((trtmp = OPENSSL_malloc(sizeof(*trtmp))) == NULL) {
            X509err(X509_F_X509_TRUST_ADD, ERR_R_MALLOC_FAILURE);
            return 0;
        }
        trtmp->flags = X509_TRUST_DYNAMIC;
    } else
        trtmp = X509_TRUST_get0(idx);
    if (trtmp->flags & X509_TRUST_DYNAMIC_NAME)
        OPENSSL_free(trtmp->name);
    if ((trtmp->name = OPENSSL_strdup(name)) == NULL) {
        X509err(X509_F_X509_TRUST_ADD, ERR_R_MALLOC_FAILURE);
        goto err;
    }
    trtmp->flags &= X509_TRUST_DYNAMIC;
    trtmp->flags |= flags;
    trtmp->trust = id;
    trtmp->check_trust = ck;
    trtmp->arg1 = arg1;
    trtmp->arg2 = arg2;
    if (idx == -1) {
        if (trtable == NULL
            && (trtable = sk_X509_TRUST_new(tr_cmp)) == NULL) {
            X509err(X509_F_X509_TRUST_ADD, ERR_R_MALLOC_FAILURE);
            goto err;;
        }
        if (!sk_X509_TRUST_push(trtable, trtmp)) {
            X509err(X509_F_X509_TRUST_ADD, ERR_R_MALLOC_FAILURE);
            goto err;
        }
    }
    return 1;
 err:
    if (idx == -1) {
        OPENSSL_free(trtmp->name);
        OPENSSL_free(trtmp);
    }
    return 0;
}
['int X509_TRUST_add(int id, int flags, int (*ck) (X509_TRUST *, X509 *, int),\n                   const char *name, int arg1, void *arg2)\n{\n    int idx;\n    X509_TRUST *trtmp;\n    flags &= ~X509_TRUST_DYNAMIC;\n    flags |= X509_TRUST_DYNAMIC_NAME;\n    idx = X509_TRUST_get_by_id(id);\n    if (idx == -1) {\n        if ((trtmp = OPENSSL_malloc(sizeof(*trtmp))) == NULL) {\n            X509err(X509_F_X509_TRUST_ADD, ERR_R_MALLOC_FAILURE);\n            return 0;\n        }\n        trtmp->flags = X509_TRUST_DYNAMIC;\n    } else\n        trtmp = X509_TRUST_get0(idx);\n    if (trtmp->flags & X509_TRUST_DYNAMIC_NAME)\n        OPENSSL_free(trtmp->name);\n    if ((trtmp->name = OPENSSL_strdup(name)) == NULL) {\n        X509err(X509_F_X509_TRUST_ADD, ERR_R_MALLOC_FAILURE);\n        goto err;\n    }\n    trtmp->flags &= X509_TRUST_DYNAMIC;\n    trtmp->flags |= flags;\n    trtmp->trust = id;\n    trtmp->check_trust = ck;\n    trtmp->arg1 = arg1;\n    trtmp->arg2 = arg2;\n    if (idx == -1) {\n        if (trtable == NULL\n            && (trtable = sk_X509_TRUST_new(tr_cmp)) == NULL) {\n            X509err(X509_F_X509_TRUST_ADD, ERR_R_MALLOC_FAILURE);\n            goto err;;\n        }\n        if (!sk_X509_TRUST_push(trtable, trtmp)) {\n            X509err(X509_F_X509_TRUST_ADD, ERR_R_MALLOC_FAILURE);\n            goto err;\n        }\n    }\n    return 1;\n err:\n    if (idx == -1) {\n        OPENSSL_free(trtmp->name);\n        OPENSSL_free(trtmp);\n    }\n    return 0;\n}', 'int X509_TRUST_get_by_id(int id)\n{\n    X509_TRUST tmp;\n    int idx;\n    if ((id >= X509_TRUST_MIN) && (id <= X509_TRUST_MAX))\n        return id - X509_TRUST_MIN;\n    tmp.trust = id;\n    if (!trtable)\n        return -1;\n    idx = sk_X509_TRUST_find(trtable, &tmp);\n    if (idx == -1)\n        return -1;\n    return idx + X509_TRUST_COUNT;\n}', 'int OPENSSL_sk_find(OPENSSL_STACK *st, const void *data)\n{\n    return internal_find(st, data, OBJ_BSEARCH_FIRST_VALUE_ON_MATCH);\n}', 'static int internal_find(OPENSSL_STACK *st, const void *data,\n                         int ret_val_options)\n{\n    const void *r;\n    int i;\n    if (st == NULL)\n        return -1;\n    if (st->comp == NULL) {\n        for (i = 0; i < st->num; i++)\n            if (st->data[i] == data)\n                return (i);\n        return (-1);\n    }\n    OPENSSL_sk_sort(st);\n    if (data == NULL)\n        return (-1);\n    r = OBJ_bsearch_ex_(&data, st->data, st->num, sizeof(void *), st->comp,\n                        ret_val_options);\n    if (r == NULL)\n        return (-1);\n    return (int)((const void **)r - st->data);\n}', 'X509_TRUST *X509_TRUST_get0(int idx)\n{\n    if (idx < 0)\n        return NULL;\n    if (idx < (int)X509_TRUST_COUNT)\n        return trstandard + idx;\n    return sk_X509_TRUST_value(trtable, idx - X509_TRUST_COUNT);\n}']