static int internal_verify(X509_STORE_CTX *ctx)
{
    int ok = 0, n;
    X509 *xs, *xi;
    EVP_PKEY *pkey = NULL;
    int (*cb) (int xok, X509_STORE_CTX *xctx);
    cb = ctx->verify_cb;
    n = sk_X509_num(ctx->chain) - 1;
    ctx->error_depth = n;
    xi = sk_X509_value(ctx->chain, n);
    if (ctx->check_issued(ctx, xi, xi))
        xs = xi;
    else {
        if (ctx->param->flags & X509_V_FLAG_PARTIAL_CHAIN) {
            xs = xi;
            goto check_cert;
        }
        if (n <= 0) {
            ctx->error = X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE;
            ctx->current_cert = xi;
            ok = cb(0, ctx);
            goto end;
        } else {
            n--;
            ctx->error_depth = n;
            xs = sk_X509_value(ctx->chain, n);
        }
    }
    while (n >= 0) {
        ctx->error_depth = n;
        if (!xs->valid
            && (xs != xi
                || (ctx->param->flags & X509_V_FLAG_CHECK_SS_SIGNATURE))) {
            if ((pkey = X509_get0_pubkey(xi)) == NULL) {
                ctx->error = X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY;
                ctx->current_cert = xi;
                ok = (*cb) (0, ctx);
                if (!ok)
                    goto end;
            } else if (X509_verify(xs, pkey) <= 0) {
                ctx->error = X509_V_ERR_CERT_SIGNATURE_FAILURE;
                ctx->current_cert = xs;
                ok = (*cb) (0, ctx);
                if (!ok)
                    goto end;
            }
        }
        xs->valid = 1;
 check_cert:
        ok = x509_check_cert_time(ctx, xs, 0);
        if (!ok)
            goto end;
        ctx->current_issuer = xi;
        ctx->current_cert = xs;
        ok = (*cb) (1, ctx);
        if (!ok)
            goto end;
        n--;
        if (n >= 0) {
            xi = xs;
            xs = sk_X509_value(ctx->chain, n);
        }
    }
    ok = 1;
 end:
    return ok;
}
['static int internal_verify(X509_STORE_CTX *ctx)\n{\n    int ok = 0, n;\n    X509 *xs, *xi;\n    EVP_PKEY *pkey = NULL;\n    int (*cb) (int xok, X509_STORE_CTX *xctx);\n    cb = ctx->verify_cb;\n    n = sk_X509_num(ctx->chain) - 1;\n    ctx->error_depth = n;\n    xi = sk_X509_value(ctx->chain, n);\n    if (ctx->check_issued(ctx, xi, xi))\n        xs = xi;\n    else {\n        if (ctx->param->flags & X509_V_FLAG_PARTIAL_CHAIN) {\n            xs = xi;\n            goto check_cert;\n        }\n        if (n <= 0) {\n            ctx->error = X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE;\n            ctx->current_cert = xi;\n            ok = cb(0, ctx);\n            goto end;\n        } else {\n            n--;\n            ctx->error_depth = n;\n            xs = sk_X509_value(ctx->chain, n);\n        }\n    }\n    while (n >= 0) {\n        ctx->error_depth = n;\n        if (!xs->valid\n            && (xs != xi\n                || (ctx->param->flags & X509_V_FLAG_CHECK_SS_SIGNATURE))) {\n            if ((pkey = X509_get0_pubkey(xi)) == NULL) {\n                ctx->error = X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY;\n                ctx->current_cert = xi;\n                ok = (*cb) (0, ctx);\n                if (!ok)\n                    goto end;\n            } else if (X509_verify(xs, pkey) <= 0) {\n                ctx->error = X509_V_ERR_CERT_SIGNATURE_FAILURE;\n                ctx->current_cert = xs;\n                ok = (*cb) (0, ctx);\n                if (!ok)\n                    goto end;\n            }\n        }\n        xs->valid = 1;\n check_cert:\n        ok = x509_check_cert_time(ctx, xs, 0);\n        if (!ok)\n            goto end;\n        ctx->current_issuer = xi;\n        ctx->current_cert = xs;\n        ok = (*cb) (1, ctx);\n        if (!ok)\n            goto end;\n        n--;\n        if (n >= 0) {\n            xi = xs;\n            xs = sk_X509_value(ctx->chain, n);\n        }\n    }\n    ok = 1;\n end:\n    return ok;\n}', 'int sk_num(const _STACK *st)\n{\n    if (st == NULL)\n        return -1;\n    return st->num;\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}']