static unsigned int BN_STACK_pop(BN_STACK *st)
{
    return st->indexes[--(st->depth)];
}
['static int ec_GF2m_montgomery_point_multiply(const EC_GROUP *group,\n                                             EC_POINT *r,\n                                             const BIGNUM *scalar,\n                                             const EC_POINT *point,\n                                             BN_CTX *ctx)\n{\n    BIGNUM *x1, *x2, *z1, *z2;\n    int ret = 0, i, group_top;\n    BN_ULONG mask, word;\n    if (r == point) {\n        ECerr(EC_F_EC_GF2M_MONTGOMERY_POINT_MULTIPLY, EC_R_INVALID_ARGUMENT);\n        return 0;\n    }\n    if ((scalar == NULL) || BN_is_zero(scalar) || (point == NULL) ||\n        EC_POINT_is_at_infinity(group, point)) {\n        return EC_POINT_set_to_infinity(group, r);\n    }\n    if (!point->Z_is_one)\n        return 0;\n    BN_CTX_start(ctx);\n    x1 = BN_CTX_get(ctx);\n    z1 = BN_CTX_get(ctx);\n    if (z1 == NULL)\n        goto err;\n    x2 = r->X;\n    z2 = r->Y;\n    group_top = bn_get_top(group->field);\n    if (bn_wexpand(x1, group_top) == NULL\n        || bn_wexpand(z1, group_top) == NULL\n        || bn_wexpand(x2, group_top) == NULL\n        || bn_wexpand(z2, group_top) == NULL)\n        goto err;\n    if (!BN_GF2m_mod_arr(x1, point->X, group->poly))\n        goto err;\n    if (!BN_one(z1))\n        goto err;\n    if (!group->meth->field_sqr(group, z2, x1, ctx))\n        goto err;\n    if (!group->meth->field_sqr(group, x2, z2, ctx))\n        goto err;\n    if (!BN_GF2m_add(x2, x2, group->b))\n        goto err;\n    i = bn_get_top(scalar) - 1;\n    mask = BN_TBIT;\n    word = bn_get_words(scalar)[i];\n    while (!(word & mask))\n        mask >>= 1;\n    mask >>= 1;\n    if (!mask) {\n        i--;\n        mask = BN_TBIT;\n    }\n    for (; i >= 0; i--) {\n        word = bn_get_words(scalar)[i];\n        while (mask) {\n            BN_consttime_swap(word & mask, x1, x2, group_top);\n            BN_consttime_swap(word & mask, z1, z2, group_top);\n            if (!gf2m_Madd(group, point->X, x2, z2, x1, z1, ctx))\n                goto err;\n            if (!gf2m_Mdouble(group, x1, z1, ctx))\n                goto err;\n            BN_consttime_swap(word & mask, x1, x2, group_top);\n            BN_consttime_swap(word & mask, z1, z2, group_top);\n            mask >>= 1;\n        }\n        mask = BN_TBIT;\n    }\n    i = gf2m_Mxy(group, point->X, point->Y, x1, z1, x2, z2, ctx);\n    if (i == 0)\n        goto err;\n    else if (i == 1) {\n        if (!EC_POINT_set_to_infinity(group, r))\n            goto err;\n    } else {\n        if (!BN_one(r->Z))\n            goto err;\n        r->Z_is_one = 1;\n    }\n    BN_set_negative(r->X, 0);\n    BN_set_negative(r->Y, 0);\n    ret = 1;\n err:\n    BN_CTX_end(ctx);\n    return ret;\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n    CTXDBG_ENTRY("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_EXIT(ctx);\n}', 'static int gf2m_Madd(const EC_GROUP *group, const BIGNUM *x, BIGNUM *x1,\n                     BIGNUM *z1, const BIGNUM *x2, const BIGNUM *z2,\n                     BN_CTX *ctx)\n{\n    BIGNUM *t1, *t2;\n    int ret = 0;\n    BN_CTX_start(ctx);\n    t1 = BN_CTX_get(ctx);\n    t2 = BN_CTX_get(ctx);\n    if (t2 == NULL)\n        goto err;\n    if (!BN_copy(t1, x))\n        goto err;\n    if (!group->meth->field_mul(group, x1, x1, z2, ctx))\n        goto err;\n    if (!group->meth->field_mul(group, z1, z1, x2, ctx))\n        goto err;\n    if (!group->meth->field_mul(group, t2, x1, z1, ctx))\n        goto err;\n    if (!BN_GF2m_add(z1, z1, x1))\n        goto err;\n    if (!group->meth->field_sqr(group, z1, z1, ctx))\n        goto err;\n    if (!group->meth->field_mul(group, x1, z1, t1, ctx))\n        goto err;\n    if (!BN_GF2m_add(x1, x1, t2))\n        goto err;\n    ret = 1;\n err:\n    BN_CTX_end(ctx);\n    return ret;\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n    CTXDBG_ENTRY("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_EXIT(ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n    return st->indexes[--(st->depth)];\n}']