static unsigned int BN_STACK_pop(BN_STACK *st)
{
    return st->indexes[--(st->depth)];
}
['static int test_check_prime_factor_range(void)\n{\n    int ret = 0;\n    BN_CTX *ctx = NULL;\n    BIGNUM *p = NULL;\n    BIGNUM *bn_p1 = NULL, *bn_p2 = NULL, *bn_p3 = NULL, *bn_p4 = NULL;\n    static const unsigned char p1[] = { 0x0B, 0x50, 0x4F, 0x33, 0x3F };\n    static const unsigned char p2[] = { 0x10, 0x00, 0x00, 0x00, 0x00 };\n    static const unsigned char p3[] = { 0x0B, 0x50, 0x4F, 0x33, 0x40 };\n    static const unsigned char p4[] = { 0x0F, 0xFF, 0xFF, 0xFF, 0xFF };\n    ret = TEST_ptr(p = BN_new())\n          && TEST_ptr(bn_p1 = bn_load_new(p1, sizeof(p1)))\n          && TEST_ptr(bn_p2 = bn_load_new(p2, sizeof(p2)))\n          && TEST_ptr(bn_p3 = bn_load_new(p3, sizeof(p3)))\n          && TEST_ptr(bn_p4 = bn_load_new(p4, sizeof(p4)))\n          && TEST_ptr(ctx = BN_CTX_new())\n          && TEST_true(BN_set_word(p, 0xA))\n          && TEST_false(rsa_check_prime_factor_range(p, 8, ctx))\n          && TEST_true(BN_set_word(p, 0x10))\n          && TEST_false(rsa_check_prime_factor_range(p, 8, ctx))\n          && TEST_true(BN_set_word(p, 0xB))\n          && TEST_true(rsa_check_prime_factor_range(p, 8, ctx))\n          && TEST_true(BN_set_word(p, 0xF))\n          && TEST_true(rsa_check_prime_factor_range(p, 8, ctx))\n          && TEST_false(rsa_check_prime_factor_range(bn_p1, 72, ctx))\n          && TEST_false(rsa_check_prime_factor_range(bn_p2, 72, ctx))\n          && TEST_true(rsa_check_prime_factor_range(bn_p3, 72, ctx))\n          && TEST_true(rsa_check_prime_factor_range(bn_p4, 72, ctx));\n    BN_free(bn_p4);\n    BN_free(bn_p3);\n    BN_free(bn_p2);\n    BN_free(bn_p1);\n    BN_free(p);\n    BN_CTX_free(ctx);\n    return ret;\n}', 'int rsa_check_prime_factor_range(const BIGNUM *p, int nbits, BN_CTX *ctx)\n{\n    int ret = 0;\n    BIGNUM *tmp, *low;\n    nbits >>= 1;\n    if (BN_num_bits(p) != nbits)\n        return 0;\n    BN_CTX_start(ctx);\n    tmp = BN_CTX_get(ctx);\n    low = BN_CTX_get(ctx);\n    if (low == NULL || !BN_set_word(tmp, 0xB504F334))\n        goto err;\n    if (nbits >= 32) {\n        if (!BN_lshift(low, tmp, nbits - 32))\n            goto err;\n    } else if (!BN_rshift(low, tmp, 32 - nbits)) {\n        goto err;\n    }\n    if (BN_cmp(p, low) < 0)\n        goto err;\n    ret = 1;\nerr:\n    BN_CTX_end(ctx);\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}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n    BIGNUM *ret;\n    CTXDBG("ENTER BN_CTX_get()", ctx);\n    if (ctx->err_stack || ctx->too_many)\n        return NULL;\n    if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n        ctx->too_many = 1;\n        BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n        return NULL;\n    }\n    BN_zero(ret);\n    ret->flags &= (~BN_FLG_CONSTTIME);\n    ctx->used++;\n    CTXDBG("LEAVE BN_CTX_get()", ctx);\n    return ret;\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}']