static int tree_evaluate(X509_POLICY_TREE *tree)
{
    int ret, i;
    X509_POLICY_LEVEL *curr = tree->levels + 1;
    const X509_POLICY_CACHE *cache;
    for (i = 1; i < tree->nlevel; i++, curr++) {
        cache = policy_cache_set(curr->cert);
        if (!tree_link_nodes(curr, cache))
            return X509_PCY_TREE_INTERNAL;
        if (!(curr->flags & X509_V_FLAG_INHIBIT_ANY)
            && !tree_link_any(curr, cache, tree))
            return X509_PCY_TREE_INTERNAL;
#ifdef OPENSSL_POLICY_DEBUG
        tree_print("before tree_prune()", tree, curr);
#endif
        ret = tree_prune(tree, curr);
        if (ret != X509_PCY_TREE_VALID)
            return ret;
    }
    return X509_PCY_TREE_VALID;
}
['static int tree_evaluate(X509_POLICY_TREE *tree)\n{\n    int ret, i;\n    X509_POLICY_LEVEL *curr = tree->levels + 1;\n    const X509_POLICY_CACHE *cache;\n    for (i = 1; i < tree->nlevel; i++, curr++) {\n        cache = policy_cache_set(curr->cert);\n        if (!tree_link_nodes(curr, cache))\n            return X509_PCY_TREE_INTERNAL;\n        if (!(curr->flags & X509_V_FLAG_INHIBIT_ANY)\n            && !tree_link_any(curr, cache, tree))\n            return X509_PCY_TREE_INTERNAL;\n#ifdef OPENSSL_POLICY_DEBUG\n        tree_print("before tree_prune()", tree, curr);\n#endif\n        ret = tree_prune(tree, curr);\n        if (ret != X509_PCY_TREE_VALID)\n            return ret;\n    }\n    return X509_PCY_TREE_VALID;\n}', 'const X509_POLICY_CACHE *policy_cache_set(X509 *x)\n{\n    if (x->policy_cache == NULL) {\n        CRYPTO_w_lock(CRYPTO_LOCK_X509);\n        policy_cache_new(x);\n        CRYPTO_w_unlock(CRYPTO_LOCK_X509);\n    }\n    return x->policy_cache;\n}', 'void CRYPTO_lock(int mode, int type, const char *file, int line)\n{\n#ifdef LOCK_DEBUG\n    {\n        CRYPTO_THREADID id;\n        char *rw_text, *operation_text;\n        if (mode & CRYPTO_LOCK)\n            operation_text = "lock  ";\n        else if (mode & CRYPTO_UNLOCK)\n            operation_text = "unlock";\n        else\n            operation_text = "ERROR ";\n        if (mode & CRYPTO_READ)\n            rw_text = "r";\n        else if (mode & CRYPTO_WRITE)\n            rw_text = "w";\n        else\n            rw_text = "ERROR";\n        CRYPTO_THREADID_current(&id);\n        fprintf(stderr, "lock:%08lx:(%s)%s %-18s %s:%d\\n",\n                CRYPTO_THREADID_hash(&id), rw_text, operation_text,\n                CRYPTO_get_lock_name(type), file, line);\n    }\n#endif\n    if (type < 0) {\n        if (dynlock_lock_callback != NULL) {\n            struct CRYPTO_dynlock_value *pointer\n                = CRYPTO_get_dynlock_value(type);\n            OPENSSL_assert(pointer != NULL);\n            dynlock_lock_callback(mode, pointer, file, line);\n            CRYPTO_destroy_dynlockid(type);\n        }\n    } else if (locking_callback != NULL)\n        locking_callback(mode, type, file, line);\n}', 'static int policy_cache_new(X509 *x)\n{\n    X509_POLICY_CACHE *cache;\n    ASN1_INTEGER *ext_any = NULL;\n    POLICY_CONSTRAINTS *ext_pcons = NULL;\n    CERTIFICATEPOLICIES *ext_cpols = NULL;\n    POLICY_MAPPINGS *ext_pmaps = NULL;\n    int i;\n    cache = OPENSSL_malloc(sizeof(*cache));\n    if (cache == NULL)\n        return 0;\n    cache->anyPolicy = NULL;\n    cache->data = NULL;\n    cache->any_skip = -1;\n    cache->explicit_skip = -1;\n    cache->map_skip = -1;\n    x->policy_cache = cache;\n    ext_pcons = X509_get_ext_d2i(x, NID_policy_constraints, &i, NULL);\n    if (!ext_pcons) {\n        if (i != -1)\n            goto bad_cache;\n    } else {\n        if (!ext_pcons->requireExplicitPolicy\n            && !ext_pcons->inhibitPolicyMapping)\n            goto bad_cache;\n        if (!policy_cache_set_int(&cache->explicit_skip,\n                                  ext_pcons->requireExplicitPolicy))\n            goto bad_cache;\n        if (!policy_cache_set_int(&cache->map_skip,\n                                  ext_pcons->inhibitPolicyMapping))\n            goto bad_cache;\n    }\n    ext_cpols = X509_get_ext_d2i(x, NID_certificate_policies, &i, NULL);\n    if (!ext_cpols) {\n        if (i != -1)\n            goto bad_cache;\n        return 1;\n    }\n    i = policy_cache_create(x, ext_cpols, i);\n    if (i <= 0)\n        return i;\n    ext_pmaps = X509_get_ext_d2i(x, NID_policy_mappings, &i, NULL);\n    if (!ext_pmaps) {\n        if (i != -1)\n            goto bad_cache;\n    } else {\n        i = policy_cache_set_mapping(x, ext_pmaps);\n        if (i <= 0)\n            goto bad_cache;\n    }\n    ext_any = X509_get_ext_d2i(x, NID_inhibit_any_policy, &i, NULL);\n    if (!ext_any) {\n        if (i != -1)\n            goto bad_cache;\n    } else if (!policy_cache_set_int(&cache->any_skip, ext_any))\n        goto bad_cache;\n    goto just_cleanup;\n bad_cache:\n    x->ex_flags |= EXFLAG_INVALID_POLICY;\n just_cleanup:\n    POLICY_CONSTRAINTS_free(ext_pcons);\n    ASN1_INTEGER_free(ext_any);\n    return 1;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n    void *ret = NULL;\n    if (num <= 0)\n        return NULL;\n    allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n    if (call_malloc_debug) {\n        CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n        ret = malloc(num);\n        CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n    } else {\n        ret = malloc(num);\n    }\n#else\n    (void)file;\n    (void)line;\n    ret = malloc(num);\n#endif\n#ifndef OPENSSL_CPUID_OBJ\n    if (ret && (num > 2048)) {\n        extern unsigned char cleanse_ctr;\n        ((unsigned char *)ret)[0] = cleanse_ctr;\n    }\n#endif\n    return ret;\n}', 'static int tree_link_nodes(X509_POLICY_LEVEL *curr,\n                           const X509_POLICY_CACHE *cache)\n{\n    int i;\n    for (i = 0; i < sk_X509_POLICY_DATA_num(cache->data); i++) {\n        X509_POLICY_DATA *data = sk_X509_POLICY_DATA_value(cache->data, i);\n        if (!tree_link_matching_nodes(curr, data))\n            return 0;\n    }\n    return 1;\n}']