int test_sqr(BIO *bp, BN_CTX *ctx)
{
    BIGNUM *a, *c, *d, *e;
    int i, ret = 0;
    a = BN_new();
    c = BN_new();
    d = BN_new();
    e = BN_new();
    if (a == NULL || c == NULL || d == NULL || e == NULL) {
        goto err;
    }
    for (i = 0; i < num0; i++) {
        BN_bntest_rand(a, 40 + i * 10, 0, 0);
        a->neg = rand_neg();
        BN_sqr(c, a, ctx);
        if (bp != NULL) {
            if (!results) {
                BN_print(bp, a);
                BIO_puts(bp, " * ");
                BN_print(bp, a);
                BIO_puts(bp, " - ");
            }
            BN_print(bp, c);
            BIO_puts(bp, "\n");
        }
        BN_div(d, e, c, a, ctx);
        BN_sub(d, d, a);
        if (!BN_is_zero(d) || !BN_is_zero(e)) {
            fprintf(stderr, "Square test failed!\n");
            goto err;
        }
    }
    BN_hex2bn(&a,
              "80000000000000008000000000000001"
              "FFFFFFFFFFFFFFFE0000000000000000");
    BN_sqr(c, a, ctx);
    if (bp != NULL) {
        if (!results) {
            BN_print(bp, a);
            BIO_puts(bp, " * ");
            BN_print(bp, a);
            BIO_puts(bp, " - ");
        }
        BN_print(bp, c);
        BIO_puts(bp, "\n");
    }
    BN_mul(d, a, a, ctx);
    if (BN_cmp(c, d)) {
        fprintf(stderr, "Square test failed: BN_sqr and BN_mul produce "
                "different results!\n");
        goto err;
    }
    BN_hex2bn(&a,
              "80000000000000000000000080000001"
              "FFFFFFFE000000000000000000000000");
    BN_sqr(c, a, ctx);
    if (bp != NULL) {
        if (!results) {
            BN_print(bp, a);
            BIO_puts(bp, " * ");
            BN_print(bp, a);
            BIO_puts(bp, " - ");
        }
        BN_print(bp, c);
        BIO_puts(bp, "\n");
    }
    BN_mul(d, a, a, ctx);
    if (BN_cmp(c, d)) {
        fprintf(stderr, "Square test failed: BN_sqr and BN_mul produce "
                "different results!\n");
        goto err;
    }
    ret = 1;
 err:
    BN_free(a);
    BN_free(c);
    BN_free(d);
    BN_free(e);
    return ret;
}
['int test_sqr(BIO *bp, BN_CTX *ctx)\n{\n    BIGNUM *a, *c, *d, *e;\n    int i, ret = 0;\n    a = BN_new();\n    c = BN_new();\n    d = BN_new();\n    e = BN_new();\n    if (a == NULL || c == NULL || d == NULL || e == NULL) {\n        goto err;\n    }\n    for (i = 0; i < num0; i++) {\n        BN_bntest_rand(a, 40 + i * 10, 0, 0);\n        a->neg = rand_neg();\n        BN_sqr(c, a, ctx);\n        if (bp != NULL) {\n            if (!results) {\n                BN_print(bp, a);\n                BIO_puts(bp, " * ");\n                BN_print(bp, a);\n                BIO_puts(bp, " - ");\n            }\n            BN_print(bp, c);\n            BIO_puts(bp, "\\n");\n        }\n        BN_div(d, e, c, a, ctx);\n        BN_sub(d, d, a);\n        if (!BN_is_zero(d) || !BN_is_zero(e)) {\n            fprintf(stderr, "Square test failed!\\n");\n            goto err;\n        }\n    }\n    BN_hex2bn(&a,\n              "80000000000000008000000000000001"\n              "FFFFFFFFFFFFFFFE0000000000000000");\n    BN_sqr(c, a, ctx);\n    if (bp != NULL) {\n        if (!results) {\n            BN_print(bp, a);\n            BIO_puts(bp, " * ");\n            BN_print(bp, a);\n            BIO_puts(bp, " - ");\n        }\n        BN_print(bp, c);\n        BIO_puts(bp, "\\n");\n    }\n    BN_mul(d, a, a, ctx);\n    if (BN_cmp(c, d)) {\n        fprintf(stderr, "Square test failed: BN_sqr and BN_mul produce "\n                "different results!\\n");\n        goto err;\n    }\n    BN_hex2bn(&a,\n              "80000000000000000000000080000001"\n              "FFFFFFFE000000000000000000000000");\n    BN_sqr(c, a, ctx);\n    if (bp != NULL) {\n        if (!results) {\n            BN_print(bp, a);\n            BIO_puts(bp, " * ");\n            BN_print(bp, a);\n            BIO_puts(bp, " - ");\n        }\n        BN_print(bp, c);\n        BIO_puts(bp, "\\n");\n    }\n    BN_mul(d, a, a, ctx);\n    if (BN_cmp(c, d)) {\n        fprintf(stderr, "Square test failed: BN_sqr and BN_mul produce "\n                "different results!\\n");\n        goto err;\n    }\n    ret = 1;\n err:\n    BN_free(a);\n    BN_free(c);\n    BN_free(d);\n    BN_free(e);\n    return ret;\n}', 'BIGNUM *BN_new(void)\n{\n    BIGNUM *ret;\n    if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) {\n        BNerr(BN_F_BN_NEW, ERR_R_MALLOC_FAILURE);\n        return (NULL);\n    }\n    ret->flags = BN_FLG_MALLOCED;\n    bn_check_top(ret);\n    return (ret);\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n    void *ret = CRYPTO_malloc(num, file, line);\n    if (ret != NULL)\n        memset(ret, 0, num);\n    return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n    void *ret = NULL;\n    if (num <= 0)\n        return NULL;\n    allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n    if (call_malloc_debug) {\n        CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n        ret = malloc(num);\n        CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n    } else {\n        ret = malloc(num);\n    }\n#else\n    (void)file;\n    (void)line;\n    ret = malloc(num);\n#endif\n#ifndef OPENSSL_CPUID_OBJ\n    if (ret && (num > 2048)) {\n        extern unsigned char cleanse_ctr;\n        ((unsigned char *)ret)[0] = cleanse_ctr;\n    }\n#endif\n    return ret;\n}']