static unsigned int BN_STACK_pop(BN_STACK *st)
{
    return st->indexes[--(st->depth)];
}
['int RSA_X931_derive_ex(RSA *rsa, BIGNUM *p1, BIGNUM *p2, BIGNUM *q1,\n                       BIGNUM *q2, const BIGNUM *Xp1, const BIGNUM *Xp2,\n                       const BIGNUM *Xp, const BIGNUM *Xq1, const BIGNUM *Xq2,\n                       const BIGNUM *Xq, const BIGNUM *e, BN_GENCB *cb)\n{\n    BIGNUM *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL;\n    BN_CTX *ctx = NULL, *ctx2 = NULL;\n    int ret = 0;\n    if (!rsa)\n        goto err;\n    ctx = BN_CTX_new();\n    if (ctx == NULL)\n        goto err;\n    BN_CTX_start(ctx);\n    r0 = BN_CTX_get(ctx);\n    r1 = BN_CTX_get(ctx);\n    r2 = BN_CTX_get(ctx);\n    r3 = BN_CTX_get(ctx);\n    if (r3 == NULL)\n        goto err;\n    if (!rsa->e) {\n        rsa->e = BN_dup(e);\n        if (!rsa->e)\n            goto err;\n    } else {\n        e = rsa->e;\n    }\n    if (Xp && rsa->p == NULL) {\n        rsa->p = BN_new();\n        if (rsa->p == NULL)\n            goto err;\n        if (!BN_X931_derive_prime_ex(rsa->p, p1, p2,\n                                     Xp, Xp1, Xp2, e, ctx, cb))\n            goto err;\n    }\n    if (Xq && rsa->q == NULL) {\n        rsa->q = BN_new();\n        if (rsa->q == NULL)\n            goto err;\n        if (!BN_X931_derive_prime_ex(rsa->q, q1, q2,\n                                     Xq, Xq1, Xq2, e, ctx, cb))\n            goto err;\n    }\n    if (rsa->p == NULL || rsa->q == NULL) {\n        BN_CTX_end(ctx);\n        BN_CTX_free(ctx);\n        return 2;\n    }\n    rsa->n = BN_new();\n    if (rsa->n == NULL)\n        goto err;\n    if (!BN_mul(rsa->n, rsa->p, rsa->q, ctx))\n        goto err;\n    if (!BN_sub(r1, rsa->p, BN_value_one()))\n        goto err;\n    if (!BN_sub(r2, rsa->q, BN_value_one()))\n        goto err;\n    if (!BN_mul(r0, r1, r2, ctx))\n        goto err;\n    if (!BN_gcd(r3, r1, r2, ctx))\n        goto err;\n    if (!BN_div(r0, NULL, r0, r3, ctx))\n        goto err;\n    ctx2 = BN_CTX_new();\n    if (ctx2 == NULL)\n        goto err;\n    rsa->d = BN_mod_inverse(NULL, rsa->e, r0, ctx2);\n    if (rsa->d == NULL)\n        goto err;\n    rsa->dmp1 = BN_new();\n    if (rsa->dmp1 == NULL)\n        goto err;\n    if (!BN_mod(rsa->dmp1, rsa->d, r1, ctx))\n        goto err;\n    rsa->dmq1 = BN_new();\n    if (rsa->dmq1 == NULL)\n        goto err;\n    if (!BN_mod(rsa->dmq1, rsa->d, r2, ctx))\n        goto err;\n    rsa->iqmp = BN_mod_inverse(NULL, rsa->q, rsa->p, ctx2);\n    if (rsa->iqmp == NULL)\n        goto err;\n    ret = 1;\n err:\n    if (ctx)\n        BN_CTX_end(ctx);\n    BN_CTX_free(ctx);\n    BN_CTX_free(ctx2);\n    return ret;\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n    CTXDBG("ENTER BN_CTX_start()", ctx);\n    if (ctx->err_stack || ctx->too_many)\n        ctx->err_stack++;\n    else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n        BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n        ctx->err_stack++;\n    }\n    CTXDBG("LEAVE BN_CTX_start()", ctx);\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n    CTXDBG("ENTER BN_CTX_end()", ctx);\n    if (ctx->err_stack)\n        ctx->err_stack--;\n    else {\n        unsigned int fp = BN_STACK_pop(&ctx->stack);\n        if (fp < ctx->used)\n            BN_POOL_release(&ctx->pool, ctx->used - fp);\n        ctx->used = fp;\n        ctx->too_many = 0;\n    }\n    CTXDBG("LEAVE BN_CTX_end()", ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n    return st->indexes[--(st->depth)];\n}']