static unsigned int BN_STACK_pop(BN_STACK *st)
	{
	return st->indexes[--(st->depth)];
	}
['int test_gf2m_mod_div(BIO *bp,BN_CTX *ctx)\n\t{\n\tBIGNUM *a,*b[2],*c,*d,*e,*f;\n\tint i, j, ret = 0;\n\tint p0[] = {163,7,6,3,0,-1};\n\tint p1[] = {193,15,0,-1};\n\ta=BN_new();\n\tb[0]=BN_new();\n\tb[1]=BN_new();\n\tc=BN_new();\n\td=BN_new();\n\te=BN_new();\n\tf=BN_new();\n\tBN_GF2m_arr2poly(p0, b[0]);\n\tBN_GF2m_arr2poly(p1, b[1]);\n\tfor (i=0; i<num0; i++)\n\t\t{\n\t\tBN_bntest_rand(a, 512, 0, 0);\n\t\tBN_bntest_rand(c, 512, 0, 0);\n\t\tfor (j=0; j < 2; j++)\n\t\t\t{\n\t\t\tBN_GF2m_mod_div(d, a, c, b[j], ctx);\n\t\t\tBN_GF2m_mod_mul(e, d, c, b[j], ctx);\n\t\t\tBN_GF2m_mod_div(f, a, e, b[j], ctx);\n#if 0\n\t\t\tif (bp != NULL)\n\t\t\t\t{\n\t\t\t\tif (!results)\n\t\t\t\t\t{\n\t\t\t\t\tBN_print(bp,a);\n\t\t\t\t\tBIO_puts(bp, " = ");\n\t\t\t\t\tBN_print(bp,c);\n\t\t\t\t\tBIO_puts(bp," * ");\n\t\t\t\t\tBN_print(bp,d);\n\t\t\t\t\tBIO_puts(bp, " % ");\n\t\t\t\t\tBN_print(bp,b[j]);\n\t\t\t\t\tBIO_puts(bp,"\\n");\n\t\t\t\t\t}\n\t\t\t\t}\n#endif\n\t\t\tif(!BN_is_one(f))\n\t\t\t\t{\n\t\t\t\tfprintf(stderr,"GF(2^m) modular division test failed!\\n");\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tret = 1;\n  err:\n\tBN_free(a);\n\tBN_free(b[0]);\n\tBN_free(b[1]);\n\tBN_free(c);\n\tBN_free(d);\n\tBN_free(e);\n\tBN_free(f);\n\treturn ret;\n\t}', 'int BN_GF2m_mod_div(BIGNUM *r, const BIGNUM *y, const BIGNUM *x, const BIGNUM *p, BN_CTX *ctx)\n\t{\n\tBIGNUM *xinv = NULL;\n\tint ret = 0;\n\tbn_check_top(y);\n\tbn_check_top(x);\n\tbn_check_top(p);\n\tBN_CTX_start(ctx);\n\txinv = BN_CTX_get(ctx);\n\tif (xinv == NULL) goto err;\n\tif (!BN_GF2m_mod_inv(xinv, x, p, ctx)) goto err;\n\tif (!BN_GF2m_mod_mul(r, y, xinv, p, ctx)) goto err;\n\tbn_check_top(r);\n\tret = 1;\nerr:\n\tBN_CTX_end(ctx);\n\treturn ret;\n\t}', 'void BN_CTX_start(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_start", ctx);\n\tif(ctx->err_stack || ctx->too_many)\n\t\tctx->err_stack++;\n\telse if(!BN_STACK_push(&ctx->stack, ctx->used))\n\t\t{\n\t\tBNerr(BN_F_BN_CTX_START,BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n\t\tctx->err_stack++;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'int BN_GF2m_mod_inv(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)\n\t{\n\tBIGNUM *b, *c, *u, *v, *tmp;\n\tint ret = 0;\n\tbn_check_top(a);\n\tbn_check_top(p);\n\tBN_CTX_start(ctx);\n\tif ((b = BN_CTX_get(ctx))==NULL) goto err;\n\tif ((c = BN_CTX_get(ctx))==NULL) goto err;\n\tif ((u = BN_CTX_get(ctx))==NULL) goto err;\n\tif ((v = BN_CTX_get(ctx))==NULL) goto err;\n\tif (!BN_GF2m_mod(u, a, p)) goto err;\n\tif (BN_is_zero(u)) goto err;\n\tif (!BN_copy(v, p)) goto err;\n#if 0\n\tif (!BN_one(b)) goto err;\n\twhile (1)\n\t\t{\n\t\twhile (!BN_is_odd(u))\n\t\t\t{\n\t\t\tif (!BN_rshift1(u, u)) goto err;\n\t\t\tif (BN_is_odd(b))\n\t\t\t\t{\n\t\t\t\tif (!BN_GF2m_add(b, b, p)) goto err;\n\t\t\t\t}\n\t\t\tif (!BN_rshift1(b, b)) goto err;\n\t\t\t}\n\t\tif (BN_abs_is_word(u, 1)) break;\n\t\tif (BN_num_bits(u) < BN_num_bits(v))\n\t\t\t{\n\t\t\ttmp = u; u = v; v = tmp;\n\t\t\ttmp = b; b = c; c = tmp;\n\t\t\t}\n\t\tif (!BN_GF2m_add(u, u, v)) goto err;\n\t\tif (!BN_GF2m_add(b, b, c)) goto err;\n\t\t}\n#else\n\t{\n\tint i,\tubits = BN_num_bits(u),\n\t\tvbits = BN_num_bits(v),\n\t\ttop = p->top;\n\tBN_ULONG *udp,*bdp,*vdp,*cdp;\n\tbn_wexpand(u,top);\tudp = u->d;\n\t\t\t\tfor (i=u->top;i<top;i++) udp[i] = 0;\n\t\t\t\tu->top = top;\n\tbn_wexpand(b,top);\tbdp = b->d;\n\t\t\t\tbdp[0] = 1;\n\t\t\t\tfor (i=1;i<top;i++) bdp[i] = 0;\n\t\t\t\tb->top = top;\n\tbn_wexpand(c,top);\tcdp = c->d;\n\t\t\t\tfor (i=0;i<top;i++) cdp[i] = 0;\n\t\t\t\tc->top = top;\n\tvdp = v->d;\n\twhile (1)\n\t\t{\n\t\twhile (ubits && !(udp[0]&1))\n\t\t\t{\n\t\t\tBN_ULONG u0,u1,b0,b1,mask;\n\t\t\tu0   = udp[0];\n\t\t\tb0   = bdp[0];\n\t\t\tmask = (BN_ULONG)0-(b0&1);\n\t\t\tb0  ^= p->d[0]&mask;\n\t\t\tfor (i=0;i<top-1;i++)\n\t\t\t\t{\n\t\t\t\tu1 = udp[i+1];\n\t\t\t\tudp[i] = ((u0>>1)|(u1<<(BN_BITS2-1)))&BN_MASK2;\n\t\t\t\tu0 = u1;\n\t\t\t\tb1 = bdp[i+1]^(p->d[i+1]&mask);\n\t\t\t\tbdp[i] = ((b0>>1)|(b1<<(BN_BITS2-1)))&BN_MASK2;\n\t\t\t\tb0 = b1;\n\t\t\t\t}\n\t\t\tudp[i] = u0>>1;\n\t\t\tbdp[i] = b0>>1;\n\t\t\tubits--;\n\t\t\t}\n\t\tif (ubits<=BN_BITS2 && udp[0]==1) break;\n\t\tif (ubits<vbits)\n\t\t\t{\n\t\t\ti = ubits; ubits = vbits; vbits = i;\n\t\t\ttmp = u; u = v; v = tmp;\n\t\t\ttmp = b; b = c; c = tmp;\n\t\t\tudp = vdp; vdp = v->d;\n\t\t\tbdp = cdp; cdp = c->d;\n\t\t\t}\n\t\tfor(i=0;i<top;i++)\n\t\t\t{\n\t\t\tudp[i] ^= vdp[i];\n\t\t\tbdp[i] ^= cdp[i];\n\t\t\t}\n\t\tif (ubits==vbits)\n\t\t\t{\n\t\t\tbn_fix_top(u);\n\t\t\tubits = BN_num_bits(u);\n\t\t\t}\n\t\t}\n\tbn_fix_top(b);\n\t}\n#endif\n\tif (!BN_copy(r, b)) goto err;\n\tbn_check_top(r);\n\tret = 1;\nerr:\n  \tBN_CTX_end(ctx);\n\treturn ret;\n\t}', 'void BN_CTX_end(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_end", ctx);\n\tif(ctx->err_stack)\n\t\tctx->err_stack--;\n\telse\n\t\t{\n\t\tunsigned int fp = BN_STACK_pop(&ctx->stack);\n\t\tif(fp < ctx->used)\n\t\t\tBN_POOL_release(&ctx->pool, ctx->used - fp);\n\t\tctx->used = fp;\n\t\tctx->too_many = 0;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n\t{\n\treturn st->indexes[--(st->depth)];\n\t}']