#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*/ *);
char *BUF_strdup(char const *);
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*/ *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*/ *);
long atol(char const *);
char *strchr(char const *, char);
int strlen(char const *);
int /*<<< orphan*/ strncmp(char const *, char *, int);
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;
  if (gstr == NULL) {
    *pkey_type = EVP_PKEY_RSA;
    keylen = *pkeylen;
  } else if (gstr[0] >= '0' && gstr[0] <= '9') {
    *pkey_type = EVP_PKEY_RSA;
    keylen = atol(gstr);
    *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 = atol(p + 1);
        *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 = BUF_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    14dc <set_keygen_ctx+0x21c>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jl     1381 <set_keygen_ctx+0xc1>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x39,%eax
jg     1381 <set_keygen_ctx+0xc1>
mov    0x2c8c(%rip),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rdi
call   1150 <atol@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
jmp    14d7 <set_keygen_ctx+0x217>
mov    -0x18(%rbp),%rdi
lea    0xc74(%rip),%rsi
mov    $0x6,%edx
call   1050 <strncmp@plt>
cmp    $0x0,%eax
jne    13b0 <set_keygen_ctx+0xf0>
mov    -0x18(%rbp),%rax
add    $0x6,%rax
mov    %rax,-0x60(%rbp)
jmp    14d2 <set_keygen_ctx+0x212>
mov    -0x18(%rbp),%rdi
mov    $0x3a,%esi
call   1090 <strchr@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
je     13e0 <set_keygen_ctx+0x120>
mov    -0x68(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x6c(%rbp)
jmp    13ec <set_keygen_ctx+0x12c>
mov    -0x18(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,-0x6c(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x6c(%rbp),%edx
lea    -0x78(%rbp),%rdi
call   1080 <EVP_PKEY_asn1_find_str@plt>
mov    %rax,-0x80(%rbp)
cmpq   $0x0,-0x80(%rbp)
jne    1431 <set_keygen_ctx+0x171>
mov    -0x10(%rbp),%rdi
mov    -0x6c(%rbp),%edx
mov    -0x18(%rbp),%rcx
lea    0xbea(%rip),%rsi
mov    $0x0,%al
call   10a0 <BIO_printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1819 <set_keygen_ctx+0x559>
mov    -0x20(%rbp),%rsi
mov    -0x80(%rbp),%r9
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdi
mov    %r8,%rdx
mov    %r8,%rcx
call   1120 <EVP_PKEY_asn1_get0_info@plt>
cmpq   $0x0,-0x78(%rbp)
je     1460 <set_keygen_ctx+0x1a0>
mov    -0x78(%rbp),%rdi
call   1140 <ENGINE_finish@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    0x2b7b(%rip),%rcx
cmp    (%rcx),%eax
jne    14b1 <set_keygen_ctx+0x1f1>
cmpq   $0x0,-0x68(%rbp)
je     14a1 <set_keygen_ctx+0x1e1>
mov    -0x68(%rbp),%rdi
add    $0x1,%rdi
call   1150 <atol@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
jmp    14ac <set_keygen_ctx+0x1ec>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x50(%rbp)
jmp    14cd <set_keygen_ctx+0x20d>
cmpq   $0x0,-0x68(%rbp)
je     14c8 <set_keygen_ctx+0x208>
mov    -0x68(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x60(%rbp)
jmp    14cd <set_keygen_ctx+0x20d>
jmp    14d2 <set_keygen_ctx+0x212>
jmp    14d7 <set_keygen_ctx+0x217>
jmp    14dc <set_keygen_ctx+0x21c>
cmpq   $0x0,-0x60(%rbp)
je     1648 <set_keygen_ctx+0x388>
mov    -0x60(%rbp),%rdi
lea    0xb2d(%rip),%rsi
call   11d0 <BIO_new_file@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    1529 <set_keygen_ctx+0x269>
mov    -0x10(%rbp),%rdi
mov    -0x60(%rbp),%rdx
lea    0xb0c(%rip),%rsi
mov    $0x0,%al
call   10a0 <BIO_printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1819 <set_keygen_ctx+0x559>
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    1597 <set_keygen_ctx+0x2d7>
mov    -0x58(%rbp),%rdi
call   11a0 <BIO_reset@plt>
mov    -0x58(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rsi
mov    %rcx,%rdx
call   11b0 <PEM_read_bio_X509@plt>
mov    %rax,-0x88(%rbp)
cmpq   $0x0,-0x88(%rbp)
je     1592 <set_keygen_ctx+0x2d2>
mov    -0x88(%rbp),%rdi
call   10d0 <X509_get_pubkey@plt>
mov    %rax,-0x48(%rbp)
mov    -0x88(%rbp),%rdi
call   1130 <X509_free@plt>
jmp    1597 <set_keygen_ctx+0x2d7>
mov    -0x58(%rbp),%rdi
call   10f0 <BIO_free@plt>
cmpq   $0x0,-0x48(%rbp)
jne    15ce <set_keygen_ctx+0x30e>
mov    -0x10(%rbp),%rdi
mov    -0x60(%rbp),%rdx
lea    0xa85(%rip),%rsi
mov    $0x0,%al
call   10a0 <BIO_printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1819 <set_keygen_ctx+0x559>
mov    -0x20(%rbp),%rax
cmpl   $0xffffffff,(%rax)
jne    15f1 <set_keygen_ctx+0x331>
mov    -0x48(%rbp),%rdi
call   11c0 <EVP_PKEY_id@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
jmp    1643 <set_keygen_ctx+0x383>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0xa4(%rbp)
mov    -0x48(%rbp),%rdi
call   1040 <EVP_PKEY_base_id@plt>
mov    %eax,%ecx
mov    -0xa4(%rbp),%eax
cmp    %ecx,%eax
je     163e <set_keygen_ctx+0x37e>
mov    -0x10(%rbp),%rdi
lea    0xa3f(%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    1819 <set_keygen_ctx+0x559>
jmp    1643 <set_keygen_ctx+0x383>
jmp    1648 <set_keygen_ctx+0x388>
cmpq   $0x0,-0x30(%rbp)
je     16ec <set_keygen_ctx+0x42c>
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
lea    -0x98(%rbp),%rdi
call   1100 <EVP_PKEY_asn1_find@plt>
mov    %rax,-0x90(%rbp)
cmpq   $0x0,-0x90(%rbp)
jne    1697 <set_keygen_ctx+0x3d7>
mov    -0x10(%rbp),%rdi
lea    0x9ff(%rip),%rsi
call   1190 <BIO_puts@plt>
movq   $0x0,-0x8(%rbp)
jmp    1819 <set_keygen_ctx+0x559>
mov    -0x90(%rbp),%r9
xor    %eax,%eax
mov    %eax,%ecx
lea    -0xa0(%rbp),%r8
mov    %rcx,%rdi
mov    %rcx,%rsi
mov    %rcx,%rdx
call   1120 <EVP_PKEY_asn1_get0_info@plt>
mov    -0xa0(%rbp),%rdi
call   1160 <BUF_strdup@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x98(%rbp)
je     16e7 <set_keygen_ctx+0x427>
mov    -0x98(%rbp),%rdi
call   1140 <ENGINE_finish@plt>
jmp    16ec <set_keygen_ctx+0x42c>
cmpq   $0x0,-0x48(%rbp)
je     1729 <set_keygen_ctx+0x469>
mov    -0x48(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1030 <EVP_PKEY_CTX_new@plt>
mov    %rax,-0x40(%rbp)
mov    -0x48(%rbp),%rdi
call   1180 <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    173c <set_keygen_ctx+0x47c>
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    176d <set_keygen_ctx+0x4ad>
mov    -0x10(%rbp),%rdi
lea    0x95c(%rip),%rsi
call   1190 <BIO_puts@plt>
mov    -0x10(%rbp),%rdi
call   1060 <ERR_print_errors@plt>
movq   $0x0,-0x8(%rbp)
jmp    1819 <set_keygen_ctx+0x559>
mov    -0x40(%rbp),%rdi
call   1170 <EVP_PKEY_keygen_init@plt>
cmp    $0x0,%rax
jg     17a6 <set_keygen_ctx+0x4e6>
mov    -0x10(%rbp),%rdi
lea    0x944(%rip),%rsi
call   1190 <BIO_puts@plt>
mov    -0x10(%rbp),%rdi
call   1060 <ERR_print_errors@plt>
movq   $0x0,-0x8(%rbp)
jmp    1819 <set_keygen_ctx+0x559>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    0x2835(%rip),%rcx
cmp    (%rcx),%eax
jne    1811 <set_keygen_ctx+0x551>
cmpq   $0xffffffffffffffff,-0x50(%rbp)
je     1811 <set_keygen_ctx+0x551>
mov    -0x40(%rbp),%rdi
mov    -0x50(%rbp),%rsi
call   10c0 <EVP_PKEY_CTX_set_rsa_keygen_bits@plt>
cmp    $0x0,%rax
jg     180c <set_keygen_ctx+0x54c>
mov    -0x10(%rbp),%rdi
lea    0x90a(%rip),%rsi
call   1190 <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    1819 <set_keygen_ctx+0x559>
jmp    1811 <set_keygen_ctx+0x551>
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,%rbp
mov    %r8,0x10(%rsp)
mov    %rcx,%rbx
mov    %rdx,%r14
mov    %rdi,%r13
test   %rsi,%rsi
mov    %r9,0x28(%rsp)
je     1319 <set_keygen_ctx+0x59>
mov    %rsi,%r15
mov    (%rsi),%al
add    $0xd0,%al
cmp    $0x9,%al
ja     1420 <set_keygen_ctx+0x160>
mov    0x2ce9(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%r14)
mov    %r15,%rdi
call   1150 <atol@plt>
mov    %rax,%r15
mov    %rbx,0x18(%rsp)
mov    %rax,(%rbx)
jmp    132d <set_keygen_ctx+0x6d>
mov    0x2cc8(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%r14)
mov    %rbx,0x18(%rsp)
mov    (%rbx),%r15
xor    %r12d,%r12d
mov    0x10(%rsp),%rbx
test   %rbx,%rbx
je     1381 <set_keygen_ctx+0xc1>
mov    (%r14),%esi
lea    0x20(%rsp),%rdi
call   1100 <EVP_PKEY_asn1_find@plt>
test   %rax,%rax
je     147c <set_keygen_ctx+0x1bc>
lea    0x30(%rsp),%r8
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %rax,%r9
call   1120 <EVP_PKEY_asn1_get0_info@plt>
mov    0x30(%rsp),%rdi
call   1160 <BUF_strdup@plt>
mov    %rax,(%rbx)
mov    0x20(%rsp),%rdi
test   %rdi,%rdi
je     1381 <set_keygen_ctx+0xc1>
call   1140 <ENGINE_finish@plt>
test   %r12,%r12
je     145a <set_keygen_ctx+0x19a>
mov    %r12,%rdi
mov    0x28(%rsp),%rsi
call   1030 <EVP_PKEY_CTX_new@plt>
mov    %rax,%rbx
mov    %r12,%rdi
call   1180 <EVP_PKEY_bits@plt>
mov    0x18(%rsp),%rcx
mov    %rax,(%rcx)
mov    %r12,%rdi
call   10b0 <EVP_PKEY_free@plt>
test   %rbx,%rbx
je     1473 <set_keygen_ctx+0x1b3>
mov    %rbx,%rdi
call   1170 <EVP_PKEY_keygen_init@plt>
test   %rax,%rax
jle    148d <set_keygen_ctx+0x1cd>
mov    (%r14),%eax
mov    0x2c12(%rip),%rcx
cmp    (%rcx),%eax
jne    14a6 <set_keygen_ctx+0x1e6>
cmp    $0xffffffffffffffff,%r15
je     14a6 <set_keygen_ctx+0x1e6>
mov    %rbx,%rdi
mov    %r15,%rsi
call   10c0 <EVP_PKEY_CTX_set_rsa_keygen_bits@plt>
test   %rax,%rax
jg     14a6 <set_keygen_ctx+0x1e6>
lea    0xcef(%rip),%rsi
mov    %r13,%rdi
call   1190 <BIO_puts@plt>
mov    %r13,%rdi
call   1060 <ERR_print_errors@plt>
mov    %rbx,%rdi
call   11e0 <EVP_PKEY_CTX_free@plt>
jmp    14a4 <set_keygen_ctx+0x1e4>
lea    0xbd9(%rip),%rsi
mov    %r15,%rdi
mov    $0x6,%edx
call   1050 <strncmp@plt>
test   %eax,%eax
mov    %r13,0x8(%rsp)
je     14b8 <set_keygen_ctx+0x1f8>
mov    %r15,%rdi
mov    $0x3a,%esi
call   1090 <strchr@plt>
mov    %rax,%rbp
test   %rax,%rax
je     14c1 <set_keygen_ctx+0x201>
mov    %ebp,%r12d
sub    %r15d,%r12d
jmp    14cc <set_keygen_ctx+0x20c>
mov    (%r14),%edi
mov    0x28(%rsp),%rsi
call   10e0 <EVP_PKEY_CTX_new_id@plt>
mov    %rax,%rbx
test   %rbx,%rbx
jne    13bb <set_keygen_ctx+0xfb>
lea    0xc34(%rip),%rsi
jmp    1494 <set_keygen_ctx+0x1d4>
lea    0xc01(%rip),%rsi
mov    %r13,%rdi
call   1190 <BIO_puts@plt>
jmp    14a4 <set_keygen_ctx+0x1e4>
lea    0xc3b(%rip),%rsi
mov    %r13,%rdi
call   1190 <BIO_puts@plt>
mov    %r13,%rdi
call   1060 <ERR_print_errors@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
add    $0x6,%r15
jmp    1567 <set_keygen_ctx+0x2a7>
mov    %r15,%rdi
call   1070 <strlen@plt>
mov    %eax,%r12d
lea    0x20(%rsp),%rdi
mov    %r15,%rsi
mov    %r12d,%edx
call   1080 <EVP_PKEY_asn1_find_str@plt>
test   %rax,%rax
je     1537 <set_keygen_ctx+0x277>
xor    %edi,%edi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
mov    %rax,%r9
call   1120 <EVP_PKEY_asn1_get0_info@plt>
mov    0x20(%rsp),%rdi
test   %rdi,%rdi
je     1504 <set_keygen_ctx+0x244>
call   1140 <ENGINE_finish@plt>
mov    (%r14),%eax
mov    0x2ada(%rip),%rcx
cmp    (%rcx),%eax
jne    1557 <set_keygen_ctx+0x297>
test   %rbp,%rbp
mov    %rbx,0x18(%rsp)
je     1663 <set_keygen_ctx+0x3a3>
add    $0x1,%rbp
mov    %rbp,%rdi
call   1150 <atol@plt>
mov    %rax,%r15
mov    %rax,(%rbx)
jmp    1674 <set_keygen_ctx+0x3b4>
lea    0xac9(%rip),%rsi
xor    %ebx,%ebx
mov    0x8(%rsp),%rdi
mov    %r12d,%edx
mov    %r15,%rcx
xor    %eax,%eax
call   10a0 <BIO_printf@plt>
jmp    14a6 <set_keygen_ctx+0x1e6>
test   %rbp,%rbp
je     1668 <set_keygen_ctx+0x3a8>
add    $0x1,%rbp
mov    %rbp,%r15
lea    0xab1(%rip),%rsi
mov    %r15,%rdi
call   11d0 <BIO_new_file@plt>
test   %rax,%rax
je     15e2 <set_keygen_ctx+0x322>
mov    %rax,%rbp
mov    %rbx,0x18(%rsp)
mov    %rax,%rdi
xor    %esi,%esi
call   1110 <PEM_read_bio_Parameters@plt>
test   %rax,%rax
je     15ff <set_keygen_ctx+0x33f>
mov    %rax,%r12
mov    %rbp,%rdi
call   10f0 <BIO_free@plt>
mov    (%r14),%ebx
mov    %r12,%rdi
cmp    $0xffffffff,%ebx
je     164a <set_keygen_ctx+0x38a>
call   1040 <EVP_PKEY_base_id@plt>
mov    $0xffffffffffffffff,%r15
cmp    %eax,%ebx
je     1659 <set_keygen_ctx+0x399>
lea    0xa99(%rip),%rsi
xor    %ebx,%ebx
mov    0x8(%rsp),%rdi
xor    %eax,%eax
call   10a0 <BIO_printf@plt>
mov    %r12,%rdi
call   10b0 <EVP_PKEY_free@plt>
jmp    14a6 <set_keygen_ctx+0x1e6>
lea    0xa38(%rip),%rsi
xor    %ebx,%ebx
mov    0x8(%rsp),%rdi
mov    %r15,%rdx
xor    %eax,%eax
call   10a0 <BIO_printf@plt>
jmp    14a6 <set_keygen_ctx+0x1e6>
mov    %rbp,%rdi
call   11a0 <BIO_reset@plt>
mov    %rbp,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   11b0 <PEM_read_bio_X509@plt>
test   %rax,%rax
je     168f <set_keygen_ctx+0x3cf>
mov    %rax,%rbx
mov    %rax,%rdi
call   10d0 <X509_get_pubkey@plt>
mov    %rax,%r12
mov    %rbx,%rdi
call   1130 <X509_free@plt>
mov    %rbp,%rdi
call   10f0 <BIO_free@plt>
test   %r12,%r12
jne    159d <set_keygen_ctx+0x2dd>
lea    0x9f7(%rip),%rsi
jmp    15e9 <set_keygen_ctx+0x329>
call   11c0 <EVP_PKEY_id@plt>
mov    %eax,(%r14)
mov    $0xffffffffffffffff,%r15
mov    0x8(%rsp),%r13
jmp    1330 <set_keygen_ctx+0x70>
mov    (%rbx),%r15
jmp    1674 <set_keygen_ctx+0x3b4>
mov    %rbx,0x18(%rsp)
mov    $0xffffffffffffffff,%r15
mov    0x8(%rsp),%r13
mov    0x10(%rsp),%rbx
xor    %r12d,%r12d
test   %rbx,%rbx
jne    133a <set_keygen_ctx+0x7a>
jmp    1381 <set_keygen_ctx+0xc1>
mov    %rbp,%rdi
call   10f0 <BIO_free@plt>
lea    0x9a1(%rip),%rsi
jmp    15e9 <set_keygen_ctx+0x329>

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

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