#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ X509;
typedef int /*<<< orphan*/ EVP_PKEY_CTX;
typedef int /*<<< orphan*/ EVP_PKEY_ASN1_METHOD;
typedef int /*<<< orphan*/ EVP_PKEY;
typedef int /*<<< orphan*/ ENGINE;
typedef int /*<<< orphan*/ BIO;

/* Variables and functions */
int /*<<< orphan*/ BIO_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BIO_new_file(char const *, char *);
int /*<<< orphan*/ BIO_printf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ BIO_puts(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ BIO_reset(int /*<<< orphan*/ *);
int /*<<< orphan*/ ENGINE_finish(int /*<<< orphan*/ *);
int /*<<< orphan*/ ERR_print_errors(int /*<<< orphan*/ *);
int /*<<< orphan*/ EVP_PKEY_CTX_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *EVP_PKEY_CTX_new(int /*<<< orphan*/ *,
                                     int /*<<< orphan*/ *);
int /*<<< orphan*/ *EVP_PKEY_CTX_new_id(int, int /*<<< orphan*/ *);
scalar_t__ EVP_PKEY_CTX_set_rsa_keygen_bits(int /*<<< orphan*/ *, long);
int EVP_PKEY_RSA;
int /*<<< orphan*/ *EVP_PKEY_asn1_find(int /*<<< orphan*/ **, int);
int /*<<< orphan*/ *EVP_PKEY_asn1_find_str(int /*<<< orphan*/ **, char const *,
                                           int);
int /*<<< orphan*/ EVP_PKEY_asn1_get0_info(int /*<<< orphan*/ *, int *,
                                           int /*<<< orphan*/ *,
                                           int /*<<< orphan*/ *, char const **,
                                           int /*<<< orphan*/ const *);
int EVP_PKEY_base_id(int /*<<< orphan*/ *);
long EVP_PKEY_bits(int /*<<< orphan*/ *);
int /*<<< orphan*/ EVP_PKEY_free(int /*<<< orphan*/ *);
int EVP_PKEY_id(int /*<<< orphan*/ *);
scalar_t__ EVP_PKEY_keygen_init(int /*<<< orphan*/ *);
int /*<<< orphan*/ LONG_MAX;
int /*<<< orphan*/ *PEM_read_bio_Parameters(int /*<<< orphan*/ *,
                                            int /*<<< orphan*/ *);
int /*<<< orphan*/ *PEM_read_bio_X509(int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *);
int /*<<< orphan*/ X509_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *X509_get_pubkey(int /*<<< orphan*/ *);
char *strchr(char const *, char);
char *strdup(char const *);
int strlen(char const *);
int /*<<< orphan*/ strncmp(char const *, char *, int);
long strtonum(char const *, int /*<<< orphan*/, int /*<<< orphan*/,
              char const **);
EVP_PKEY_CTX *set_keygen_ctx(BIO *err, const char *gstr, int *pkey_type,
                             long *pkeylen, char **palgnam,
                             ENGINE *keygen_engine) {
  EVP_PKEY_CTX *gctx = NULL;
  EVP_PKEY *param = NULL;
  long keylen = -1;
  BIO *pbio = NULL;
  const char *paramfile = NULL;
  const char *errstr;
  if (gstr == NULL) {
    *pkey_type = EVP_PKEY_RSA;
    keylen = *pkeylen;
  } else if (gstr[0] >= '0' && gstr[0] <= '9') {
    *pkey_type = EVP_PKEY_RSA;
    keylen = strtonum(gstr, 0, LONG_MAX, &errstr);
    if (errstr) {
      BIO_printf(err, "bad algorithm %s: %s\n", gstr, errstr);
      return NULL;
    }
    *pkeylen = keylen;
  } else if (!strncmp(gstr, "param:", 6))
    paramfile = gstr + 6;
  else {
    const char *p = strchr(gstr, ':');
    int len;
    ENGINE *tmpeng;
    const EVP_PKEY_ASN1_METHOD *ameth;
    if (p)
      len = p - gstr;
    else
      len = strlen(gstr);
    ameth = EVP_PKEY_asn1_find_str(&tmpeng, gstr, len);
    if (!ameth) {
      BIO_printf(err, "Unknown algorithm %.*s\n", len, gstr);
      return NULL;
    }
    EVP_PKEY_asn1_get0_info(NULL, pkey_type, NULL, NULL, NULL, ameth);
    if (tmpeng)
      ENGINE_finish(tmpeng);
    if (*pkey_type == EVP_PKEY_RSA) {
      if (p) {
        keylen = strtonum(p + 1, 0, LONG_MAX, &errstr);
        if (errstr) {
          BIO_printf(err, "bad algorithm %s: %s\n", p + 1, errstr);
          return NULL;
        }
        *pkeylen = keylen;
      } else
        keylen = *pkeylen;
    } else if (p)
      paramfile = p + 1;
  }
  if (paramfile) {
    pbio = BIO_new_file(paramfile, "r");
    if (!pbio) {
      BIO_printf(err, "Can't open parameter file %s\n", paramfile);
      return NULL;
    }
    param = PEM_read_bio_Parameters(pbio, NULL);
    if (!param) {
      X509 *x;
      (void)BIO_reset(pbio);
      x = PEM_read_bio_X509(pbio, NULL, NULL, NULL);
      if (x) {
        param = X509_get_pubkey(x);
        X509_free(x);
      }
    }
    BIO_free(pbio);
    if (!param) {
      BIO_printf(err, "Error reading parameter file %s\n", paramfile);
      return NULL;
    }
    if (*pkey_type == -1)
      *pkey_type = EVP_PKEY_id(param);
    else if (*pkey_type != EVP_PKEY_base_id(param)) {
      BIO_printf(err, "Key Type does not match parameters\n");
      EVP_PKEY_free(param);
      return NULL;
    }
  }
  if (palgnam) {
    const EVP_PKEY_ASN1_METHOD *ameth;
    ENGINE *tmpeng;
    const char *anam;
    ameth = EVP_PKEY_asn1_find(&tmpeng, *pkey_type);
    if (!ameth) {
      BIO_puts(err, "Internal error: can't find key algorithm\n");
      return NULL;
    }
    EVP_PKEY_asn1_get0_info(NULL, NULL, NULL, NULL, &anam, ameth);
    *palgnam = strdup(anam);
    if (tmpeng)
      ENGINE_finish(tmpeng);
  }
  if (param) {
    gctx = EVP_PKEY_CTX_new(param, keygen_engine);
    *pkeylen = EVP_PKEY_bits(param);
    EVP_PKEY_free(param);
  } else
    gctx = EVP_PKEY_CTX_new_id(*pkey_type, keygen_engine);
  if (!gctx) {
    BIO_puts(err, "Error allocating keygen context\n");
    ERR_print_errors(err);
    return NULL;
  }
  if (EVP_PKEY_keygen_init(gctx) <= 0) {
    BIO_puts(err, "Error initializing keygen context\n");
    ERR_print_errors(err);
    return NULL;
  }
  if ((*pkey_type == EVP_PKEY_RSA) && (keylen != -1)) {
    if (EVP_PKEY_CTX_set_rsa_keygen_bits(gctx, keylen) <= 0) {
      BIO_puts(err, "Error setting RSA keysize\n");
      ERR_print_errors(err);
      EVP_PKEY_CTX_free(gctx);
      return NULL;
    }
  }
  return gctx;
}


x86 assembly (clang, -O0):
<set_keygen_ctx>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
movq   $0xffffffffffffffff,-0x50(%rbp)
ff
movq   $0x0,-0x58(%rbp)
movq   $0x0,-0x60(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1335 <set_keygen_ctx+0x75>
mov    0x2ccb(%rip),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x50(%rbp)
jmp    156b <set_keygen_ctx+0x2ab>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jl     13c2 <set_keygen_ctx+0x102>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x39,%eax
jg     13c2 <set_keygen_ctx+0x102>
mov    0x2c8c(%rip),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rdi
mov    0x2c69(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
lea    -0x68(%rbp),%rcx
call   1120 <strtonum@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x68(%rbp)
je     13b2 <set_keygen_ctx+0xf2>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x68(%rbp),%rcx
lea    0xc62(%rip),%rsi
mov    $0x0,%al
call   10a0 <BIO_printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    18a8 <set_keygen_ctx+0x5e8>
mov    -0x50(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
jmp    1566 <set_keygen_ctx+0x2a6>
mov    -0x18(%rbp),%rdi
lea    0xc49(%rip),%rsi
mov    $0x6,%edx
call   1050 <strncmp@plt>
cmp    $0x0,%eax
jne    13f1 <set_keygen_ctx+0x131>
mov    -0x18(%rbp),%rax
add    $0x6,%rax
mov    %rax,-0x60(%rbp)
jmp    1561 <set_keygen_ctx+0x2a1>
mov    -0x18(%rbp),%rdi
mov    $0x3a,%esi
call   1090 <strchr@plt>
mov    %rax,-0x70(%rbp)
cmpq   $0x0,-0x70(%rbp)
je     1421 <set_keygen_ctx+0x161>
mov    -0x70(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x74(%rbp)
jmp    142d <set_keygen_ctx+0x16d>
mov    -0x18(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,-0x74(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x74(%rbp),%edx
lea    -0x80(%rbp),%rdi
call   1080 <EVP_PKEY_asn1_find_str@plt>
mov    %rax,-0x88(%rbp)
cmpq   $0x0,-0x88(%rbp)
jne    1478 <set_keygen_ctx+0x1b8>
mov    -0x10(%rbp),%rdi
mov    -0x74(%rbp),%edx
mov    -0x18(%rbp),%rcx
lea    0xbb9(%rip),%rsi
mov    $0x0,%al
call   10a0 <BIO_printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    18a8 <set_keygen_ctx+0x5e8>
mov    -0x20(%rbp),%rsi
mov    -0x88(%rbp),%r9
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdi
mov    %r8,%rdx
mov    %r8,%rcx
call   1130 <EVP_PKEY_asn1_get0_info@plt>
cmpq   $0x0,-0x80(%rbp)
je     14aa <set_keygen_ctx+0x1ea>
mov    -0x80(%rbp),%rdi
call   1150 <ENGINE_finish@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    0x2b31(%rip),%rcx
cmp    (%rcx),%eax
jne    1540 <set_keygen_ctx+0x280>
cmpq   $0x0,-0x70(%rbp)
je     1530 <set_keygen_ctx+0x270>
mov    -0x70(%rbp),%rdi
add    $0x1,%rdi
mov    0x2aff(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
lea    -0x68(%rbp),%rcx
call   1120 <strtonum@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x68(%rbp)
je     1520 <set_keygen_ctx+0x260>
mov    -0x10(%rbp),%rdi
mov    -0x70(%rbp),%rdx
add    $0x1,%rdx
mov    -0x68(%rbp),%rcx
lea    0xaf4(%rip),%rsi
mov    $0x0,%al
call   10a0 <BIO_printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    18a8 <set_keygen_ctx+0x5e8>
mov    -0x50(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
jmp    153b <set_keygen_ctx+0x27b>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x50(%rbp)
jmp    155c <set_keygen_ctx+0x29c>
cmpq   $0x0,-0x70(%rbp)
je     1557 <set_keygen_ctx+0x297>
mov    -0x70(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x60(%rbp)
jmp    155c <set_keygen_ctx+0x29c>
jmp    1561 <set_keygen_ctx+0x2a1>
jmp    1566 <set_keygen_ctx+0x2a6>
jmp    156b <set_keygen_ctx+0x2ab>
cmpq   $0x0,-0x60(%rbp)
je     16d7 <set_keygen_ctx+0x417>
mov    -0x60(%rbp),%rdi
lea    0xab4(%rip),%rsi
call   11d0 <BIO_new_file@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    15b8 <set_keygen_ctx+0x2f8>
mov    -0x10(%rbp),%rdi
mov    -0x60(%rbp),%rdx
lea    0xa93(%rip),%rsi
mov    $0x0,%al
call   10a0 <BIO_printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    18a8 <set_keygen_ctx+0x5e8>
mov    -0x58(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1110 <PEM_read_bio_Parameters@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    1626 <set_keygen_ctx+0x366>
mov    -0x58(%rbp),%rdi
call   1190 <BIO_reset@plt>
mov    -0x58(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rsi
mov    %rcx,%rdx
call   11a0 <PEM_read_bio_X509@plt>
mov    %rax,-0x90(%rbp)
cmpq   $0x0,-0x90(%rbp)
je     1621 <set_keygen_ctx+0x361>
mov    -0x90(%rbp),%rdi
call   10d0 <X509_get_pubkey@plt>
mov    %rax,-0x48(%rbp)
mov    -0x90(%rbp),%rdi
call   1140 <X509_free@plt>
jmp    1626 <set_keygen_ctx+0x366>
mov    -0x58(%rbp),%rdi
call   10f0 <BIO_free@plt>
cmpq   $0x0,-0x48(%rbp)
jne    165d <set_keygen_ctx+0x39d>
mov    -0x10(%rbp),%rdi
mov    -0x60(%rbp),%rdx
lea    0xa0c(%rip),%rsi
mov    $0x0,%al
call   10a0 <BIO_printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    18a8 <set_keygen_ctx+0x5e8>
mov    -0x20(%rbp),%rax
cmpl   $0xffffffff,(%rax)
jne    1680 <set_keygen_ctx+0x3c0>
mov    -0x48(%rbp),%rdi
call   11c0 <EVP_PKEY_id@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
jmp    16d2 <set_keygen_ctx+0x412>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0xac(%rbp)
mov    -0x48(%rbp),%rdi
call   1040 <EVP_PKEY_base_id@plt>
mov    %eax,%ecx
mov    -0xac(%rbp),%eax
cmp    %ecx,%eax
je     16cd <set_keygen_ctx+0x40d>
mov    -0x10(%rbp),%rdi
lea    0x9c6(%rip),%rsi
mov    $0x0,%al
call   10a0 <BIO_printf@plt>
mov    -0x48(%rbp),%rdi
call   10b0 <EVP_PKEY_free@plt>
movq   $0x0,-0x8(%rbp)
jmp    18a8 <set_keygen_ctx+0x5e8>
jmp    16d2 <set_keygen_ctx+0x412>
jmp    16d7 <set_keygen_ctx+0x417>
cmpq   $0x0,-0x30(%rbp)
je     177b <set_keygen_ctx+0x4bb>
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
lea    -0xa0(%rbp),%rdi
call   1100 <EVP_PKEY_asn1_find@plt>
mov    %rax,-0x98(%rbp)
cmpq   $0x0,-0x98(%rbp)
jne    1726 <set_keygen_ctx+0x466>
mov    -0x10(%rbp),%rdi
lea    0x986(%rip),%rsi
call   1180 <BIO_puts@plt>
movq   $0x0,-0x8(%rbp)
jmp    18a8 <set_keygen_ctx+0x5e8>
mov    -0x98(%rbp),%r9
xor    %eax,%eax
mov    %eax,%ecx
lea    -0xa8(%rbp),%r8
mov    %rcx,%rdi
mov    %rcx,%rsi
mov    %rcx,%rdx
call   1130 <EVP_PKEY_asn1_get0_info@plt>
mov    -0xa8(%rbp),%rdi
call   11b0 <strdup@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0xa0(%rbp)
je     1776 <set_keygen_ctx+0x4b6>
mov    -0xa0(%rbp),%rdi
call   1150 <ENGINE_finish@plt>
jmp    177b <set_keygen_ctx+0x4bb>
cmpq   $0x0,-0x48(%rbp)
je     17b8 <set_keygen_ctx+0x4f8>
mov    -0x48(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1030 <EVP_PKEY_CTX_new@plt>
mov    %rax,-0x40(%rbp)
mov    -0x48(%rbp),%rdi
call   1170 <EVP_PKEY_bits@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x48(%rbp),%rdi
call   10b0 <EVP_PKEY_free@plt>
jmp    17cb <set_keygen_ctx+0x50b>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rsi
call   10e0 <EVP_PKEY_CTX_new_id@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    17fc <set_keygen_ctx+0x53c>
mov    -0x10(%rbp),%rdi
lea    0x8e3(%rip),%rsi
call   1180 <BIO_puts@plt>
mov    -0x10(%rbp),%rdi
call   1060 <ERR_print_errors@plt>
movq   $0x0,-0x8(%rbp)
jmp    18a8 <set_keygen_ctx+0x5e8>
mov    -0x40(%rbp),%rdi
call   1160 <EVP_PKEY_keygen_init@plt>
cmp    $0x0,%rax
jg     1835 <set_keygen_ctx+0x575>
mov    -0x10(%rbp),%rdi
lea    0x8cb(%rip),%rsi
call   1180 <BIO_puts@plt>
mov    -0x10(%rbp),%rdi
call   1060 <ERR_print_errors@plt>
movq   $0x0,-0x8(%rbp)
jmp    18a8 <set_keygen_ctx+0x5e8>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    0x27a6(%rip),%rcx
cmp    (%rcx),%eax
jne    18a0 <set_keygen_ctx+0x5e0>
cmpq   $0xffffffffffffffff,-0x50(%rbp)
je     18a0 <set_keygen_ctx+0x5e0>
mov    -0x40(%rbp),%rdi
mov    -0x50(%rbp),%rsi
call   10c0 <EVP_PKEY_CTX_set_rsa_keygen_bits@plt>
cmp    $0x0,%rax
jg     189b <set_keygen_ctx+0x5db>
mov    -0x10(%rbp),%rdi
lea    0x891(%rip),%rsi
call   1180 <BIO_puts@plt>
mov    -0x10(%rbp),%rdi
call   1060 <ERR_print_errors@plt>
mov    -0x40(%rbp),%rdi
call   11e0 <EVP_PKEY_CTX_free@plt>
movq   $0x0,-0x8(%rbp)
jmp    18a8 <set_keygen_ctx+0x5e8>
jmp    18a0 <set_keygen_ctx+0x5e0>
mov    -0x40(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_keygen_ctx>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r9,%r12
mov    %r8,%r13
mov    %rcx,%rbx
mov    %rdx,%r15
mov    %rdi,%r14
test   %rsi,%rsi
mov    %r9,0x28(%rsp)
je     1340 <set_keygen_ctx+0x80>
mov    %rsi,%rbp
mov    (%rsi),%al
add    $0xd0,%al
cmp    $0x9,%al
ja     135b <set_keygen_ctx+0x9b>
mov    0x2cef(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%r15)
mov    0x2cd3(%rip),%rax
mov    (%rax),%edx
lea    0x20(%rsp),%rcx
mov    %rbp,%rdi
xor    %esi,%esi
call   1120 <strtonum@plt>
mov    0x20(%rsp),%rcx
test   %rcx,%rcx
je     13a4 <set_keygen_ctx+0xe4>
lea    0xcd5(%rip),%rsi
xor    %r13d,%r13d
mov    %r14,%rdi
mov    %rbp,%rdx
xor    %eax,%eax
call   10a0 <BIO_printf@plt>
jmp    15a7 <set_keygen_ctx+0x2e7>
mov    %r14,0x8(%rsp)
mov    0x2c9c(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%r15)
mov    %rbx,0x10(%rsp)
mov    (%rbx),%r12
jmp    13b4 <set_keygen_ctx+0xf4>
lea    0xcb4(%rip),%rsi
mov    %rbp,%rdi
mov    $0x6,%edx
call   1050 <strncmp@plt>
test   %eax,%eax
mov    %r14,0x8(%rsp)
mov    %rbx,0x10(%rsp)
je     14cd <set_keygen_ctx+0x20d>
mov    %rbp,%rdi
mov    $0x3a,%esi
call   1090 <strchr@plt>
mov    %rax,%r14
test   %rax,%rax
je     14f2 <set_keygen_ctx+0x232>
mov    %r14d,%ebx
sub    %ebp,%ebx
jmp    14fc <set_keygen_ctx+0x23c>
mov    %rax,%r12
mov    %r14,0x8(%rsp)
mov    %rbx,0x10(%rsp)
mov    %rax,(%rbx)
xor    %r14d,%r14d
test   %r13,%r13
je     1404 <set_keygen_ctx+0x144>
mov    (%r15),%esi
lea    0x18(%rsp),%rdi
call   1100 <EVP_PKEY_asn1_find@plt>
test   %rax,%rax
je     14b7 <set_keygen_ctx+0x1f7>
lea    0x30(%rsp),%r8
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %rax,%r9
call   1130 <EVP_PKEY_asn1_get0_info@plt>
mov    0x30(%rsp),%rdi
call   11b0 <strdup@plt>
mov    %rax,0x0(%r13)
mov    0x18(%rsp),%rdi
test   %rdi,%rdi
je     1404 <set_keygen_ctx+0x144>
call   1150 <ENGINE_finish@plt>
test   %r14,%r14
je     1433 <set_keygen_ctx+0x173>
mov    %r14,%rdi
mov    0x28(%rsp),%rsi
call   1030 <EVP_PKEY_CTX_new@plt>
mov    %rax,%r13
mov    %r14,%rdi
call   1170 <EVP_PKEY_bits@plt>
mov    0x10(%rsp),%rcx
mov    %rax,(%rcx)
mov    %r14,%rdi
call   10b0 <EVP_PKEY_free@plt>
jmp    1443 <set_keygen_ctx+0x183>
mov    (%r15),%edi
mov    0x28(%rsp),%rsi
call   10e0 <EVP_PKEY_CTX_new_id@plt>
mov    %rax,%r13
mov    0x8(%rsp),%rbx
test   %r13,%r13
je     14ae <set_keygen_ctx+0x1ee>
mov    %r13,%rdi
call   1160 <EVP_PKEY_keygen_init@plt>
test   %rax,%rax
jle    14d6 <set_keygen_ctx+0x216>
mov    (%r15),%eax
mov    0x2b84(%rip),%rcx
cmp    (%rcx),%eax
jne    15a7 <set_keygen_ctx+0x2e7>
cmp    $0xffffffffffffffff,%r12
je     15a7 <set_keygen_ctx+0x2e7>
mov    %r13,%rdi
mov    %r12,%rsi
call   10c0 <EVP_PKEY_CTX_set_rsa_keygen_bits@plt>
test   %rax,%rax
jg     15a7 <set_keygen_ctx+0x2e7>
lea    0xc77(%rip),%rsi
mov    %rbx,%rdi
call   1180 <BIO_puts@plt>
mov    %rbx,%rdi
call   1060 <ERR_print_errors@plt>
mov    %r13,%rdi
call   11e0 <EVP_PKEY_CTX_free@plt>
jmp    15a4 <set_keygen_ctx+0x2e4>
lea    0xc0f(%rip),%rsi
jmp    14dd <set_keygen_ctx+0x21d>
lea    0xbdc(%rip),%rsi
mov    0x8(%rsp),%rdi
call   1180 <BIO_puts@plt>
jmp    15a4 <set_keygen_ctx+0x2e4>
add    $0x6,%rbp
jmp    15ce <set_keygen_ctx+0x30e>
lea    0xc08(%rip),%rsi
mov    %rbx,%rdi
call   1180 <BIO_puts@plt>
mov    %rbx,%rdi
call   1060 <ERR_print_errors@plt>
jmp    15a4 <set_keygen_ctx+0x2e4>
mov    %rbp,%rdi
call   1070 <strlen@plt>
mov    %eax,%ebx
lea    0x18(%rsp),%rdi
mov    %rbp,%rsi
mov    %ebx,%edx
call   1080 <EVP_PKEY_asn1_find_str@plt>
test   %rax,%rax
je     158c <set_keygen_ctx+0x2cc>
xor    %edi,%edi
mov    %r15,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
mov    %rax,%r9
call   1130 <EVP_PKEY_asn1_get0_info@plt>
mov    0x18(%rsp),%rdi
test   %rdi,%rdi
je     1533 <set_keygen_ctx+0x273>
call   1150 <ENGINE_finish@plt>
mov    (%r15),%eax
mov    0x2aab(%rip),%rcx
cmp    (%rcx),%eax
jne    15b9 <set_keygen_ctx+0x2f9>
test   %r14,%r14
je     16af <set_keygen_ctx+0x3ef>
add    $0x1,%r14
mov    0x2a83(%rip),%rax
mov    (%rax),%edx
lea    0x20(%rsp),%rcx
mov    %r14,%rdi
xor    %esi,%esi
call   1120 <strtonum@plt>
mov    0x20(%rsp),%rcx
test   %rcx,%rcx
je     16c8 <set_keygen_ctx+0x408>
lea    0xa85(%rip),%rsi
mov    0x8(%rsp),%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   10a0 <BIO_printf@plt>
jmp    15a4 <set_keygen_ctx+0x2e4>
lea    0xa8a(%rip),%rsi
mov    0x8(%rsp),%rdi
mov    %ebx,%edx
mov    %rbp,%rcx
xor    %eax,%eax
call   10a0 <BIO_printf@plt>
xor    %r13d,%r13d
mov    %r13,%rax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
test   %r14,%r14
je     16bc <set_keygen_ctx+0x3fc>
add    $0x1,%r14
mov    %r14,%rbp
mov    0x8(%rsp),%r14
lea    0xa60(%rip),%rsi
mov    %rbp,%rdi
call   11d0 <BIO_new_file@plt>
test   %rax,%rax
je     1645 <set_keygen_ctx+0x385>
mov    %rax,%r12
mov    %rax,%rdi
xor    %esi,%esi
call   1110 <PEM_read_bio_Parameters@plt>
test   %rax,%rax
je     1657 <set_keygen_ctx+0x397>
mov    %rax,%r14
mov    %r12,%rdi
call   10f0 <BIO_free@plt>
mov    (%r15),%ebx
mov    %r14,%rdi
cmp    $0xffffffff,%ebx
je     169b <set_keygen_ctx+0x3db>
call   1040 <EVP_PKEY_base_id@plt>
mov    $0xffffffffffffffff,%r12
cmp    %eax,%ebx
je     13b7 <set_keygen_ctx+0xf7>
lea    0xa4d(%rip),%rsi
xor    %r13d,%r13d
mov    0x8(%rsp),%rdi
xor    %eax,%eax
call   10a0 <BIO_printf@plt>
mov    %r14,%rdi
call   10b0 <EVP_PKEY_free@plt>
jmp    15a7 <set_keygen_ctx+0x2e7>
lea    0x9eb(%rip),%rsi
xor    %r13d,%r13d
mov    %r14,%rdi
jmp    16ef <set_keygen_ctx+0x42f>
mov    %r12,%rdi
call   1190 <BIO_reset@plt>
mov    %r12,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   11a0 <PEM_read_bio_X509@plt>
test   %rax,%rax
je     16d8 <set_keygen_ctx+0x418>
mov    %rax,%rbx
mov    %rax,%rdi
call   10d0 <X509_get_pubkey@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1140 <X509_free@plt>
mov    %r12,%rdi
call   10f0 <BIO_free@plt>
test   %r14,%r14
jne    15ff <set_keygen_ctx+0x33f>
jmp    16e0 <set_keygen_ctx+0x420>
call   11c0 <EVP_PKEY_id@plt>
mov    %eax,(%r15)
mov    $0xffffffffffffffff,%r12
jmp    13b7 <set_keygen_ctx+0xf7>
mov    0x10(%rsp),%rax
mov    (%rax),%r12
jmp    13b4 <set_keygen_ctx+0xf4>
mov    $0xffffffffffffffff,%r12
jmp    13b4 <set_keygen_ctx+0xf4>
mov    %rax,%r12
mov    0x10(%rsp),%rax
mov    %r12,(%rax)
jmp    13b4 <set_keygen_ctx+0xf4>
mov    %r12,%rdi
call   10f0 <BIO_free@plt>
lea    0x96e(%rip),%rsi
xor    %r13d,%r13d
mov    0x8(%rsp),%rdi
mov    %rbp,%rdx
xor    %eax,%eax
call   10a0 <BIO_printf@plt>
jmp    15a7 <set_keygen_ctx+0x2e7>

LLVM IR (-O0):
@EVP_PKEY_RSA = global i32 0
@LONG_MAX = global i32 0
@.str = [22 x i8] c"bad algorithm %s: %s\0A\00"
@.str.1 = [7 x i8] c"param:\00"
@.str.2 = [24 x i8] c"Unknown algorithm %.*s\0A\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [30 x i8] c"Can't open parameter file %s\0A\00"
@.str.5 = [33 x i8] c"Error reading parameter file %s\0A\00"
@.str.6 = [36 x i8] c"Key Type does not match parameters\0A\00"
@.str.7 = [42 x i8] c"Internal error: can't find key algorithm\0A\00"
@.str.8 = [33 x i8] c"Error allocating keygen context\0A\00"
@.str.9 = [35 x i8] c"Error initializing keygen context\0A\00"
@.str.10 = [27 x i8] c"Error setting RSA keysize\0A\00"
define i32* @set_keygen_ctx(i32* %0, i8* %1, i32* %2, i64* %3, i8** %4, i32* %5) {
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i32*
%11 = alloca i64*
%12 = alloca i8**
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca i32*
%16 = alloca i64
%17 = alloca i32*
%18 = alloca i8*
%19 = alloca i8*
%20 = alloca i8*
%21 = alloca i32
%22 = alloca i32*
%23 = alloca i32*
%24 = alloca i32*
%25 = alloca i32*
%26 = alloca i32*
%27 = alloca i8*
store i32* %0, i32** %8
store i8* %1, i8** %9
store i32* %2, i32** %10
store i64* %3, i64** %11
store i8** %4, i8*** %12
store i32* %5, i32** %13
store i32* null, i32** %14
store i32* null, i32** %15
store i64 -1, i64* %16
store i32* null, i32** %17
store i8* null, i8** %18
%28 = load i8*, i8** %9
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %35
30: ; preds = %6
%31 = load i32, i32* @EVP_PKEY_RSA
%32 = load i32*, i32** %10
store i32 %31, i32* %32
%33 = load i64*, i64** %11
%34 = load i64, i64* %33
store i64 %34, i64* %16
br label %143
35: ; preds = %6
%36 = load i8*, i8** %9
%37 = getelementptr inbounds i8, i8* %36, i64 0
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp sge i32 %39, 48
br i1 %40, label %41, label %63
41: ; preds = %35
%42 = load i8*, i8** %9
%43 = getelementptr inbounds i8, i8* %42, i64 0
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp sle i32 %45, 57
br i1 %46, label %47, label %63
47: ; preds = %41
%48 = load i32, i32* @EVP_PKEY_RSA
%49 = load i32*, i32** %10
store i32 %48, i32* %49
%50 = load i8*, i8** %9
%51 = load i32, i32* @LONG_MAX
%52 = call i64 @strtonum(i8* %50, i32 0, i32 %51, i8** %19)
store i64 %52, i64* %16
%53 = load i8*, i8** %19
%54 = icmp ne i8* %53, null
br i1 %54, label %55, label %60
55: ; preds = %47
%56 = load i32*, i32** %8
%57 = load i8*, i8** %9
%58 = load i8*, i8** %19
%59 = call i32 (i32*, i8*, ...) @BIO_printf(i32* %56, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %57, i8* %58)
store i32* null, i32** %7
br label %284
60: ; preds = %47
%61 = load i64, i64* %16
%62 = load i64*, i64** %11
store i64 %61, i64* %62
br label %142
63: ; preds = %41, %35
%64 = load i8*, i8** %9
%65 = call i32 @strncmp(i8* %64, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 6)
%66 = icmp ne i32 %65, 0
br i1 %66, label %70, label %67
67: ; preds = %63
%68 = load i8*, i8** %9
%69 = getelementptr inbounds i8, i8* %68, i64 6
store i8* %69, i8** %18
br label %141
70: ; preds = %63
%71 = load i8*, i8** %9
%72 = call i8* @strchr(i8* %71, i8 signext 58)
store i8* %72, i8** %20
%73 = load i8*, i8** %20
%74 = icmp ne i8* %73, null
br i1 %74, label %75, label %82
75: ; preds = %70
%76 = load i8*, i8** %20
%77 = load i8*, i8** %9
%78 = ptrtoint i8* %76 to i64
%79 = ptrtoint i8* %77 to i64
%80 = sub i64 %78, %79
%81 = trunc i64 %80 to i32
store i32 %81, i32* %21
br label %85
82: ; preds = %70
%83 = load i8*, i8** %9
%84 = call i32 @strlen(i8* %83)
store i32 %84, i32* %21
br label %85
85: ; preds = %82, %75
%86 = load i8*, i8** %9
%87 = load i32, i32* %21
%88 = call i32* @EVP_PKEY_asn1_find_str(i32** %22, i8* %86, i32 %87)
store i32* %88, i32** %23
%89 = load i32*, i32** %23
%90 = icmp ne i32* %89, null
br i1 %90, label %96, label %91
91: ; preds = %85
%92 = load i32*, i32** %8
%93 = load i32, i32* %21
%94 = load i8*, i8** %9
%95 = call i32 (i32*, i8*, ...) @BIO_printf(i32* %92, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %93, i8* %94)
store i32* null, i32** %7
br label %284
96: ; preds = %85
%97 = load i32*, i32** %10
%98 = load i32*, i32** %23
%99 = call i32 @EVP_PKEY_asn1_get0_info(i32* null, i32* %97, i32* null, i32* null, i8** null, i32* %98)
%100 = load i32*, i32** %22
%101 = icmp ne i32* %100, null
br i1 %101, label %102, label %105
102: ; preds = %96
%103 = load i32*, i32** %22
%104 = call i32 @ENGINE_finish(i32* %103)
br label %105
105: ; preds = %102, %96
%106 = load i32*, i32** %10
%107 = load i32, i32* %106
%108 = load i32, i32* @EVP_PKEY_RSA
%109 = icmp eq i32 %107, %108
br i1 %109, label %110, label %133
110: ; preds = %105
%111 = load i8*, i8** %20
%112 = icmp ne i8* %111, null
br i1 %112, label %113, label %129
113: ; preds = %110
%114 = load i8*, i8** %20
%115 = getelementptr inbounds i8, i8* %114, i64 1
%116 = load i32, i32* @LONG_MAX
%117 = call i64 @strtonum(i8* %115, i32 0, i32 %116, i8** %19)
store i64 %117, i64* %16
%118 = load i8*, i8** %19
%119 = icmp ne i8* %118, null
br i1 %119, label %120, label %126
120: ; preds = %113
%121 = load i32*, i32** %8
%122 = load i8*, i8** %20
%123 = getelementptr inbounds i8, i8* %122, i64 1
%124 = load i8*, i8** %19
%125 = call i32 (i32*, i8*, ...) @BIO_printf(i32* %121, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %123, i8* %124)
store i32* null, i32** %7
br label %284
126: ; preds = %113
%127 = load i64, i64* %16
%128 = load i64*, i64** %11
store i64 %127, i64* %128
br label %132
129: ; preds = %110
%130 = load i64*, i64** %11
%131 = load i64, i64* %130
store i64 %131, i64* %16
br label %132
132: ; preds = %129, %126
br label %140
133: ; preds = %105
%134 = load i8*, i8** %20
%135 = icmp ne i8* %134, null
br i1 %135, label %136, label %139
136: ; preds = %133
%137 = load i8*, i8** %20
%138 = getelementptr inbounds i8, i8* %137, i64 1
store i8* %138, i8** %18
br label %139
139: ; preds = %136, %133
br label %140
140: ; preds = %139, %132
br label %141
141: ; preds = %140, %67
br label %142
142: ; preds = %141, %60
br label %143
143: ; preds = %142, %30
%144 = load i8*, i8** %18
%145 = icmp ne i8* %144, null
br i1 %145, label %146, label %203
146: ; preds = %143
%147 = load i8*, i8** %18
%148 = call i32* @BIO_new_file(i8* %147, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %148, i32** %17
%149 = load i32*, i32** %17
%150 = icmp ne i32* %149, null
br i1 %150, label %155, label %151
151: ; preds = %146
%152 = load i32*, i32** %8
%153 = load i8*, i8** %18
%154 = call i32 (i32*, i8*, ...) @BIO_printf(i32* %152, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* %153)
store i32* null, i32** %7
br label %284
155: ; preds = %146
%156 = load i32*, i32** %17
%157 = call i32* @PEM_read_bio_Parameters(i32* %156, i32* null)
store i32* %157, i32** %15
%158 = load i32*, i32** %15
%159 = icmp ne i32* %158, null
br i1 %159, label %173, label %160
160: ; preds = %155
%161 = load i32*, i32** %17
%162 = call i32 @BIO_reset(i32* %161)
%163 = load i32*, i32** %17
%164 = call i32* @PEM_read_bio_X509(i32* %163, i32* null, i32* null, i32* null)
store i32* %164, i32** %24
%165 = load i32*, i32** %24
%166 = icmp ne i32* %165, null
br i1 %166, label %167, label %172
167: ; preds = %160
%168 = load i32*, i32** %24
%169 = call i32* @X509_get_pubkey(i32* %168)
store i32* %169, i32** %15
%170 = load i32*, i32** %24
%171 = call i32 @X509_free(i32* %170)
br label %172
172: ; preds = %167, %160
br label %173
173: ; preds = %172, %155
%174 = load i32*, i32** %17
%175 = call i32 @BIO_free(i32* %174)
%176 = load i32*, i32** %15
%177 = icmp ne i32* %176, null
br i1 %177, label %182, label %178
178: ; preds = %173
%179 = load i32*, i32** %8
%180 = load i8*, i8** %18
%181 = call i32 (i32*, i8*, ...) @BIO_printf(i32* %179, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i8* %180)
store i32* null, i32** %7
br label %284
182: ; preds = %173
%183 = load i32*, i32** %10
%184 = load i32, i32* %183
%185 = icmp eq i32 %184, -1
br i1 %185, label %186, label %190
186: ; preds = %182
%187 = load i32*, i32** %15
%188 = call i32 @EVP_PKEY_id(i32* %187)
%189 = load i32*, i32** %10
store i32 %188, i32* %189
br label %202
190: ; preds = %182
%191 = load i32*, i32** %10
%192 = load i32, i32* %191
%193 = load i32*, i32** %15
%194 = call i32 @EVP_PKEY_base_id(i32* %193)
%195 = icmp ne i32 %192, %194
br i1 %195, label %196, label %201
196: ; preds = %190
%197 = load i32*, i32** %8
%198 = call i32 (i32*, i8*, ...) @BIO_printf(i32* %197, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0))
%199 = load i32*, i32** %15
%200 = call i32 @EVP_PKEY_free(i32* %199)
store i32* null, i32** %7
br label %284
201: ; preds = %190
br label %202
202: ; preds = %201, %186
br label %203
203: ; preds = %202, %143
%204 = load i8**, i8*** %12
%205 = icmp ne i8** %204, null
br i1 %205, label %206, label %227
206: ; preds = %203
%207 = load i32*, i32** %10
%208 = load i32, i32* %207
%209 = call i32* @EVP_PKEY_asn1_find(i32** %26, i32 %208)
store i32* %209, i32** %25
%210 = load i32*, i32** %25
%211 = icmp ne i32* %210, null
br i1 %211, label %215, label %212
212: ; preds = %206
%213 = load i32*, i32** %8
%214 = call i32 @BIO_puts(i32* %213, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0))
store i32* null, i32** %7
br label %284
215: ; preds = %206
%216 = load i32*, i32** %25
%217 = call i32 @EVP_PKEY_asn1_get0_info(i32* null, i32* null, i32* null, i32* null, i8** %27, i32* %216)
%218 = load i8*, i8** %27
%219 = call i8* @strdup(i8* %218)
%220 = load i8**, i8*** %12
store i8* %219, i8** %220
%221 = load i32*, i32** %26
%222 = icmp ne i32* %221, null
br i1 %222, label %223, label %226
223: ; preds = %215
%224 = load i32*, i32** %26
%225 = call i32 @ENGINE_finish(i32* %224)
br label %226
226: ; preds = %223, %215
br label %227
227: ; preds = %226, %203
%228 = load i32*, i32** %15
%229 = icmp ne i32* %228, null
br i1 %229, label %230, label %239
230: ; preds = %227
%231 = load i32*, i32** %15
%232 = load i32*, i32** %13
%233 = call i32* @EVP_PKEY_CTX_new(i32* %231, i32* %232)
store i32* %233, i32** %14
%234 = load i32*, i32** %15
%235 = call i64 @EVP_PKEY_bits(i32* %234)
%236 = load i64*, i64** %11
store i64 %235, i64* %236
%237 = load i32*, i32** %15
%238 = call i32 @EVP_PKEY_free(i32* %237)
br label %244
239: ; preds = %227
%240 = load i32*, i32** %10
%241 = load i32, i32* %240
%242 = load i32*, i32** %13
%243 = call i32* @EVP_PKEY_CTX_new_id(i32 %241, i32* %242)
store i32* %243, i32** %14
br label %244
244: ; preds = %239, %230
%245 = load i32*, i32** %14
%246 = icmp ne i32* %245, null
br i1 %246, label %252, label %247
247: ; preds = %244
%248 = load i32*, i32** %8
%249 = call i32 @BIO_puts(i32* %248, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0))
%250 = load i32*, i32** %8
%251 = call i32 @ERR_print_errors(i32* %250)
store i32* null, i32** %7
br label %284
252: ; preds = %244
%253 = load i32*, i32** %14
%254 = call i64 @EVP_PKEY_keygen_init(i32* %253)
%255 = icmp sle i64 %254, 0
br i1 %255, label %256, label %261
256: ; preds = %252
%257 = load i32*, i32** %8
%258 = call i32 @BIO_puts(i32* %257, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.9, i64 0, i64 0))
%259 = load i32*, i32** %8
%260 = call i32 @ERR_print_errors(i32* %259)
store i32* null, i32** %7
br label %284
261: ; preds = %252
%262 = load i32*, i32** %10
%263 = load i32, i32* %262
%264 = load i32, i32* @EVP_PKEY_RSA
%265 = icmp eq i32 %263, %264
br i1 %265, label %266, label %282
266: ; preds = %261
%267 = load i64, i64* %16
%268 = icmp ne i64 %267, -1
br i1 %268, label %269, label %282
269: ; preds = %266
%270 = load i32*, i32** %14
%271 = load i64, i64* %16
%272 = call i64 @EVP_PKEY_CTX_set_rsa_keygen_bits(i32* %270, i64 %271)
%273 = icmp sle i64 %272, 0
br i1 %273, label %274, label %281
274: ; preds = %269
%275 = load i32*, i32** %8
%276 = call i32 @BIO_puts(i32* %275, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0))
%277 = load i32*, i32** %8
%278 = call i32 @ERR_print_errors(i32* %277)
%279 = load i32*, i32** %14
%280 = call i32 @EVP_PKEY_CTX_free(i32* %279)
store i32* null, i32** %7
br label %284
281: ; preds = %269
br label %282
282: ; preds = %281, %266, %261
%283 = load i32*, i32** %14
store i32* %283, i32** %7
br label %284
284: ; preds = %282, %274, %256, %247, %212, %196, %178, %151, %120, %91, %55
%285 = load i32*, i32** %7
ret i32* %285
}

LLVM IR (-O2):
@EVP_PKEY_RSA = global i32 0
@LONG_MAX = global i32 0
@.str = [22 x i8] c"bad algorithm %s: %s\0A\00"
@.str.1 = [7 x i8] c"param:\00"
@.str.2 = [24 x i8] c"Unknown algorithm %.*s\0A\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [30 x i8] c"Can't open parameter file %s\0A\00"
@.str.5 = [33 x i8] c"Error reading parameter file %s\0A\00"
@.str.6 = [36 x i8] c"Key Type does not match parameters\0A\00"
@.str.7 = [42 x i8] c"Internal error: can't find key algorithm\0A\00"
@.str.8 = [33 x i8] c"Error allocating keygen context\0A\00"
@.str.9 = [35 x i8] c"Error initializing keygen context\0A\00"
@.str.10 = [27 x i8] c"Error setting RSA keysize\0A\00"
define i32* @set_keygen_ctx(i32* %0, i8* %1, i32* %2, i64* nocapture %3, i8** writeonly %4, i32* %5) {
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i8*
%11 = bitcast i8** %7 to i8*
%12 = icmp eq i8* %1, null
br i1 %12, label %13, label %16
13: ; preds = %6
%14 = load i32, i32* @EVP_PKEY_RSA
store i32 %14, i32* %2
%15 = load i64, i64* %3
br label %115
16: ; preds = %6
%17 = load i8, i8* %1
%18 = add i8 %17, -48
%19 = icmp ult i8 %18, 10
br i1 %19, label %20, label %29
20: ; preds = %16
%21 = load i32, i32* @EVP_PKEY_RSA
store i32 %21, i32* %2
%22 = load i32, i32* @LONG_MAX
%23 = call i64 @strtonum(i8* %1, i32 0, i32 %22, i8** %7)
%24 = load i8*, i8** %7
%25 = icmp eq i8* %24, null
br i1 %25, label %28, label %26
26: ; preds = %20
%27 = call i32 (i32*, i8*, ...) @BIO_printf(i32* %0, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %24)
br label %170
28: ; preds = %20
store i64 %23, i64* %3
br label %115
29: ; preds = %16
%30 = tail call i32 @strncmp(i8* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 6)
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = getelementptr inbounds i8, i8* %1, i64 6
br label %79
34: ; preds = %29
%35 = tail call i8* @strchr(i8* %1, i8 signext 58)
%36 = bitcast i32** %8 to i8*
%37 = icmp eq i8* %35, null
br i1 %37, label %43, label %38
38: ; preds = %34
%39 = ptrtoint i8* %35 to i64
%40 = ptrtoint i8* %1 to i64
%41 = sub i64 %39, %40
%42 = trunc i64 %41 to i32
br label %45
43: ; preds = %34
%44 = tail call i32 @strlen(i8* %1)
br label %45
45: ; preds = %43, %38
%46 = phi i32 [ %42, %38 ], [ %44, %43 ]
%47 = call i32* @EVP_PKEY_asn1_find_str(i32** %8, i8* %1, i32 %46)
%48 = icmp eq i32* %47, null
br i1 %48, label %49, label %51
49: ; preds = %45
%50 = call i32 (i32*, i8*, ...) @BIO_printf(i32* %0, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %46, i8* %1)
br label %74
51: ; preds = %45
%52 = call i32 @EVP_PKEY_asn1_get0_info(i32* null, i32* %2, i32* null, i32* null, i8** null, i32* %47)
%53 = load i32*, i32** %8
%54 = icmp eq i32* %53, null
br i1 %54, label %57, label %55
55: ; preds = %51
%56 = call i32 @ENGINE_finish(i32* %53)
br label %57
57: ; preds = %55, %51
%58 = load i32, i32* %2
%59 = load i32, i32* @EVP_PKEY_RSA
%60 = icmp eq i32 %58, %59
br i1 %60, label %61, label %73
61: ; preds = %57
br i1 %37, label %71, label %62
62: ; preds = %61
%63 = getelementptr inbounds i8, i8* %35, i64 1
%64 = load i32, i32* @LONG_MAX
%65 = call i64 @strtonum(i8* %63, i32 0, i32 %64, i8** %7)
%66 = load i8*, i8** %7
%67 = icmp eq i8* %66, null
br i1 %67, label %70, label %68
68: ; preds = %62
%69 = call i32 (i32*, i8*, ...) @BIO_printf(i32* %0, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %63, i8* %66)
br label %74
70: ; preds = %62
store i64 %65, i64* %3
br label %75
71: ; preds = %61
%72 = load i64, i64* %3
br label %75
73: ; preds = %57
br i1 %37, label %75, label %77
74: ; preds = %68, %49
br label %170
75: ; preds = %71, %70, %73
%76 = phi i64 [ %65, %70 ], [ %72, %71 ], [ -1, %73 ]
br label %115
77: ; preds = %73
%78 = getelementptr inbounds i8, i8* %35, i64 1
br label %79
79: ; preds = %77, %32
%80 = phi i8* [ %33, %32 ], [ %78, %77 ]
%81 = call i32* @BIO_new_file(i8* %80, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%82 = icmp eq i32* %81, null
br i1 %82, label %83, label %85
83: ; preds = %79
%84 = call i32 (i32*, i8*, ...) @BIO_printf(i32* %0, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* %80)
br label %170
85: ; preds = %79
%86 = call i32* @PEM_read_bio_Parameters(i32* %81, i32* null)
%87 = icmp eq i32* %86, null
br i1 %87, label %90, label %88
88: ; preds = %85
%89 = call i32 @BIO_free(i32* %81)
br label %103
90: ; preds = %85
%91 = call i32 @BIO_reset(i32* %81)
%92 = call i32* @PEM_read_bio_X509(i32* %81, i32* null, i32* null, i32* null)
%93 = icmp eq i32* %92, null
br i1 %93, label %94, label %96
94: ; preds = %90
%95 = call i32 @BIO_free(i32* %81)
br label %101
96: ; preds = %90
%97 = call i32* @X509_get_pubkey(i32* %92)
%98 = call i32 @X509_free(i32* %92)
%99 = call i32 @BIO_free(i32* %81)
%100 = icmp eq i32* %97, null
br i1 %100, label %101, label %103
101: ; preds = %94, %96
%102 = call i32 (i32*, i8*, ...) @BIO_printf(i32* %0, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i8* %80)
br label %170
103: ; preds = %88, %96
%104 = phi i32* [ %86, %88 ], [ %97, %96 ]
%105 = load i32, i32* %2
%106 = icmp eq i32 %105, -1
br i1 %106, label %107, label %109
107: ; preds = %103
%108 = call i32 @EVP_PKEY_id(i32* %104)
store i32 %108, i32* %2
br label %115
109: ; preds = %103
%110 = call i32 @EVP_PKEY_base_id(i32* %104)
%111 = icmp eq i32 %105, %110
br i1 %111, label %115, label %112
112: ; preds = %109
%113 = call i32 (i32*, i8*, ...) @BIO_printf(i32* %0, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0))
%114 = call i32 @EVP_PKEY_free(i32* %104)
br label %170
115: ; preds = %28, %13, %75, %107, %109
%116 = phi i64 [ -1, %107 ], [ -1, %109 ], [ %76, %75 ], [ %23, %28 ], [ %15, %13 ]
%117 = phi i32* [ %104, %107 ], [ %104, %109 ], [ null, %75 ], [ null, %28 ], [ null, %13 ]
%118 = icmp eq i8** %4, null
br i1 %118, label %136, label %119
119: ; preds = %115
%120 = bitcast i32** %9 to i8*
%121 = bitcast i8** %10 to i8*
%122 = load i32, i32* %2
%123 = call i32* @EVP_PKEY_asn1_find(i32** %9, i32 %122)
%124 = icmp eq i32* %123, null
br i1 %124, label %134, label %125
125: ; preds = %119
%126 = call i32 @EVP_PKEY_asn1_get0_info(i32* null, i32* null, i32* null, i32* null, i8** %10, i32* %123)
%127 = load i8*, i8** %10
%128 = call i8* @strdup(i8* %127)
store i8* %128, i8** %4
%129 = load i32*, i32** %9
%130 = icmp eq i32* %129, null
br i1 %130, label %133, label %131
131: ; preds = %125
%132 = call i32 @ENGINE_finish(i32* %129)
br label %133
133: ; preds = %125, %131
br label %136
134: ; preds = %119
%135 = call i32 @BIO_puts(i32* %0, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0))
br label %170
136: ; preds = %133, %115
%137 = icmp eq i32* %117, null
br i1 %137, label %142, label %138
138: ; preds = %136
%139 = call i32* @EVP_PKEY_CTX_new(i32* %117, i32* %5)
%140 = call i64 @EVP_PKEY_bits(i32* %117)
store i64 %140, i64* %3
%141 = call i32 @EVP_PKEY_free(i32* %117)
br label %145
142: ; preds = %136
%143 = load i32, i32* %2
%144 = call i32* @EVP_PKEY_CTX_new_id(i32 %143, i32* %5)
br label %145
145: ; preds = %142, %138
%146 = phi i32* [ %139, %138 ], [ %144, %142 ]
%147 = icmp eq i32* %146, null
br i1 %147, label %148, label %151
148: ; preds = %145
%149 = call i32 @BIO_puts(i32* %0, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0))
%150 = call i32 @ERR_print_errors(i32* %0)
br label %170
151: ; preds = %145
%152 = call i64 @EVP_PKEY_keygen_init(i32* %146)
%153 = icmp slt i64 %152, 1
br i1 %153, label %154, label %157
154: ; preds = %151
%155 = call i32 @BIO_puts(i32* %0, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.9, i64 0, i64 0))
%156 = call i32 @ERR_print_errors(i32* %0)
br label %170
157: ; preds = %151
%158 = load i32, i32* %2
%159 = load i32, i32* @EVP_PKEY_RSA
%160 = icmp eq i32 %158, %159
%161 = icmp ne i64 %116, -1
%162 = select i1 %160, i1 %161, i1 false
br i1 %162, label %163, label %170
163: ; preds = %157
%164 = call i64 @EVP_PKEY_CTX_set_rsa_keygen_bits(i32* %146, i64 %116)
%165 = icmp slt i64 %164, 1
br i1 %165, label %166, label %170
166: ; preds = %163
%167 = call i32 @BIO_puts(i32* %0, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0))
%168 = call i32 @ERR_print_errors(i32* %0)
%169 = call i32 @EVP_PKEY_CTX_free(i32* %146)
br label %170
170: ; preds = %134, %74, %157, %163, %166, %154, %148, %112, %101, %83, %26
%171 = phi i32* [ null, %154 ], [ null, %166 ], [ null, %148 ], [ null, %134 ], [ null, %112 ], [ null, %101 ], [ null, %83 ], [ null, %26 ], [ null, %74 ], [ %146, %163 ], [ %146, %157 ]
ret i32* %171
}