#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 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    14cc <set_keygen_ctx+0x20c>
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    14c7 <set_keygen_ctx+0x207>
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    14c2 <set_keygen_ctx+0x202>
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    1809 <set_keygen_ctx+0x549>
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    14a1 <set_keygen_ctx+0x1e1>
cmpq   $0x0,-0x68(%rbp)
je     149c <set_keygen_ctx+0x1dc>
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    14bd <set_keygen_ctx+0x1fd>
cmpq   $0x0,-0x68(%rbp)
je     14b8 <set_keygen_ctx+0x1f8>
mov    -0x68(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x60(%rbp)
jmp    14bd <set_keygen_ctx+0x1fd>
jmp    14c2 <set_keygen_ctx+0x202>
jmp    14c7 <set_keygen_ctx+0x207>
jmp    14cc <set_keygen_ctx+0x20c>
cmpq   $0x0,-0x60(%rbp)
je     1638 <set_keygen_ctx+0x378>
mov    -0x60(%rbp),%rdi
lea    0xb3d(%rip),%rsi
call   11d0 <BIO_new_file@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    1519 <set_keygen_ctx+0x259>
mov    -0x10(%rbp),%rdi
mov    -0x60(%rbp),%rdx
lea    0xb1c(%rip),%rsi
mov    $0x0,%al
call   10a0 <BIO_printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1809 <set_keygen_ctx+0x549>
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    1587 <set_keygen_ctx+0x2c7>
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     1582 <set_keygen_ctx+0x2c2>
mov    -0x88(%rbp),%rdi
call   10d0 <X509_get_pubkey@plt>
mov    %rax,-0x48(%rbp)
mov    -0x88(%rbp),%rdi
call   1130 <X509_free@plt>
jmp    1587 <set_keygen_ctx+0x2c7>
mov    -0x58(%rbp),%rdi
call   10f0 <BIO_free@plt>
cmpq   $0x0,-0x48(%rbp)
jne    15be <set_keygen_ctx+0x2fe>
mov    -0x10(%rbp),%rdi
mov    -0x60(%rbp),%rdx
lea    0xa95(%rip),%rsi
mov    $0x0,%al
call   10a0 <BIO_printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1809 <set_keygen_ctx+0x549>
mov    -0x20(%rbp),%rax
cmpl   $0xffffffff,(%rax)
jne    15e1 <set_keygen_ctx+0x321>
mov    -0x48(%rbp),%rdi
call   11c0 <EVP_PKEY_id@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
jmp    1633 <set_keygen_ctx+0x373>
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     162e <set_keygen_ctx+0x36e>
mov    -0x10(%rbp),%rdi
lea    0xa4f(%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    1809 <set_keygen_ctx+0x549>
jmp    1633 <set_keygen_ctx+0x373>
jmp    1638 <set_keygen_ctx+0x378>
cmpq   $0x0,-0x30(%rbp)
je     16dc <set_keygen_ctx+0x41c>
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    1687 <set_keygen_ctx+0x3c7>
mov    -0x10(%rbp),%rdi
lea    0xa0f(%rip),%rsi
call   1190 <BIO_puts@plt>
movq   $0x0,-0x8(%rbp)
jmp    1809 <set_keygen_ctx+0x549>
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     16d7 <set_keygen_ctx+0x417>
mov    -0x98(%rbp),%rdi
call   1140 <ENGINE_finish@plt>
jmp    16dc <set_keygen_ctx+0x41c>
cmpq   $0x0,-0x48(%rbp)
je     1719 <set_keygen_ctx+0x459>
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    172c <set_keygen_ctx+0x46c>
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    175d <set_keygen_ctx+0x49d>
mov    -0x10(%rbp),%rdi
lea    0x96c(%rip),%rsi
call   1190 <BIO_puts@plt>
mov    -0x10(%rbp),%rdi
call   1060 <ERR_print_errors@plt>
movq   $0x0,-0x8(%rbp)
jmp    1809 <set_keygen_ctx+0x549>
mov    -0x40(%rbp),%rdi
call   1170 <EVP_PKEY_keygen_init@plt>
cmp    $0x0,%rax
jg     1796 <set_keygen_ctx+0x4d6>
mov    -0x10(%rbp),%rdi
lea    0x954(%rip),%rsi
call   1190 <BIO_puts@plt>
mov    -0x10(%rbp),%rdi
call   1060 <ERR_print_errors@plt>
movq   $0x0,-0x8(%rbp)
jmp    1809 <set_keygen_ctx+0x549>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    0x2845(%rip),%rcx
cmp    (%rcx),%eax
jne    1801 <set_keygen_ctx+0x541>
cmpq   $0xffffffffffffffff,-0x50(%rbp)
je     1801 <set_keygen_ctx+0x541>
mov    -0x40(%rbp),%rdi
mov    -0x50(%rbp),%rsi
call   10c0 <EVP_PKEY_CTX_set_rsa_keygen_bits@plt>
cmp    $0x0,%rax
jg     17fc <set_keygen_ctx+0x53c>
mov    -0x10(%rbp),%rdi
lea    0x91a(%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    1809 <set_keygen_ctx+0x549>
jmp    1801 <set_keygen_ctx+0x541>
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     1668 <set_keygen_ctx+0x3a8>
add    $0x1,%rbp
mov    %rbp,%rdi
call   1150 <atol@plt>
mov    %rax,%r15
mov    %rax,(%rbx)
jmp    166f <set_keygen_ctx+0x3af>
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     1663 <set_keygen_ctx+0x3a3>
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     168a <set_keygen_ctx+0x3ca>
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,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    0x9a6(%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 %120
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 %119
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 %118
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 %261
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 %110
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 %109
109: ; preds = %103, %100
br label %117
110: ; preds = %95
%111 = load i8*, i8** %19
%112 = icmp ne i8* %111, null
br i1 %112, label %113, label %116
113: ; preds = %110
%114 = load i8*, i8** %19
%115 = getelementptr inbounds i8, i8* %114, i64 1
store i8* %115, i8** %18
br label %116
116: ; preds = %113, %110
br label %117
117: ; preds = %116, %109
br label %118
118: ; preds = %117, %57
br label %119
119: ; preds = %118, %46
br label %120
120: ; preds = %119, %29
%121 = load i8*, i8** %18
%122 = icmp ne i8* %121, null
br i1 %122, label %123, label %180
123: ; preds = %120
%124 = load i8*, i8** %18
%125 = call i32* @BIO_new_file(i8* %124, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %125, i32** %17
%126 = load i32*, i32** %17
%127 = icmp ne i32* %126, null
br i1 %127, label %132, label %128
128: ; preds = %123
%129 = load i32*, i32** %8
%130 = load i8*, i8** %18
%131 = call i32 (i32*, i8*, ...) @BIO_printf(i32* %129, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %130)
store i32* null, i32** %7
br label %261
132: ; preds = %123
%133 = load i32*, i32** %17
%134 = call i32* @PEM_read_bio_Parameters(i32* %133, i32* null)
store i32* %134, i32** %15
%135 = load i32*, i32** %15
%136 = icmp ne i32* %135, null
br i1 %136, label %150, label %137
137: ; preds = %132
%138 = load i32*, i32** %17
%139 = call i32 @BIO_reset(i32* %138)
%140 = load i32*, i32** %17
%141 = call i32* @PEM_read_bio_X509(i32* %140, i32* null, i32* null, i32* null)
store i32* %141, i32** %23
%142 = load i32*, i32** %23
%143 = icmp ne i32* %142, null
br i1 %143, label %144, label %149
144: ; preds = %137
%145 = load i32*, i32** %23
%146 = call i32* @X509_get_pubkey(i32* %145)
store i32* %146, i32** %15
%147 = load i32*, i32** %23
%148 = call i32 @X509_free(i32* %147)
br label %149
149: ; preds = %144, %137
br label %150
150: ; preds = %149, %132
%151 = load i32*, i32** %17
%152 = call i32 @BIO_free(i32* %151)
%153 = load i32*, i32** %15
%154 = icmp ne i32* %153, null
br i1 %154, label %159, label %155
155: ; preds = %150
%156 = load i32*, i32** %8
%157 = load i8*, i8** %18
%158 = call i32 (i32*, i8*, ...) @BIO_printf(i32* %156, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* %157)
store i32* null, i32** %7
br label %261
159: ; preds = %150
%160 = load i32*, i32** %10
%161 = load i32, i32* %160
%162 = icmp eq i32 %161, -1
br i1 %162, label %163, label %167
163: ; preds = %159
%164 = load i32*, i32** %15
%165 = call i32 @EVP_PKEY_id(i32* %164)
%166 = load i32*, i32** %10
store i32 %165, i32* %166
br label %179
167: ; preds = %159
%168 = load i32*, i32** %10
%169 = load i32, i32* %168
%170 = load i32*, i32** %15
%171 = call i32 @EVP_PKEY_base_id(i32* %170)
%172 = icmp ne i32 %169, %171
br i1 %172, label %173, label %178
173: ; preds = %167
%174 = load i32*, i32** %8
%175 = call i32 (i32*, i8*, ...) @BIO_printf(i32* %174, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0))
%176 = load i32*, i32** %15
%177 = call i32 @EVP_PKEY_free(i32* %176)
store i32* null, i32** %7
br label %261
178: ; preds = %167
br label %179
179: ; preds = %178, %163
br label %180
180: ; preds = %179, %120
%181 = load i8**, i8*** %12
%182 = icmp ne i8** %181, null
br i1 %182, label %183, label %204
183: ; preds = %180
%184 = load i32*, i32** %10
%185 = load i32, i32* %184
%186 = call i32* @EVP_PKEY_asn1_find(i32** %25, i32 %185)
store i32* %186, i32** %24
%187 = load i32*, i32** %24
%188 = icmp ne i32* %187, null
br i1 %188, label %192, label %189
189: ; preds = %183
%190 = load i32*, i32** %8
%191 = call i32 @BIO_puts(i32* %190, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0))
store i32* null, i32** %7
br label %261
192: ; preds = %183
%193 = load i32*, i32** %24
%194 = call i32 @EVP_PKEY_asn1_get0_info(i32* null, i32* null, i32* null, i32* null, i8** %26, i32* %193)
%195 = load i8*, i8** %26
%196 = call i8* @BUF_strdup(i8* %195)
%197 = load i8**, i8*** %12
store i8* %196, i8** %197
%198 = load i32*, i32** %25
%199 = icmp ne i32* %198, null
br i1 %199, label %200, label %203
200: ; preds = %192
%201 = load i32*, i32** %25
%202 = call i32 @ENGINE_finish(i32* %201)
br label %203
203: ; preds = %200, %192
br label %204
204: ; preds = %203, %180
%205 = load i32*, i32** %15
%206 = icmp ne i32* %205, null
br i1 %206, label %207, label %216
207: ; preds = %204
%208 = load i32*, i32** %15
%209 = load i32*, i32** %13
%210 = call i32* @EVP_PKEY_CTX_new(i32* %208, i32* %209)
store i32* %210, i32** %14
%211 = load i32*, i32** %15
%212 = call i64 @EVP_PKEY_bits(i32* %211)
%213 = load i64*, i64** %11
store i64 %212, i64* %213
%214 = load i32*, i32** %15
%215 = call i32 @EVP_PKEY_free(i32* %214)
br label %221
216: ; preds = %204
%217 = load i32*, i32** %10
%218 = load i32, i32* %217
%219 = load i32*, i32** %13
%220 = call i32* @EVP_PKEY_CTX_new_id(i32 %218, i32* %219)
store i32* %220, i32** %14
br label %221
221: ; preds = %216, %207
%222 = load i32*, i32** %14
%223 = icmp ne i32* %222, null
br i1 %223, label %229, label %224
224: ; preds = %221
%225 = load i32*, i32** %8
%226 = call i32 @BIO_puts(i32* %225, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0))
%227 = load i32*, i32** %8
%228 = call i32 @ERR_print_errors(i32* %227)
store i32* null, i32** %7
br label %261
229: ; preds = %221
%230 = load i32*, i32** %14
%231 = call i64 @EVP_PKEY_keygen_init(i32* %230)
%232 = icmp sle i64 %231, 0
br i1 %232, label %233, label %238
233: ; preds = %229
%234 = load i32*, i32** %8
%235 = call i32 @BIO_puts(i32* %234, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0))
%236 = load i32*, i32** %8
%237 = call i32 @ERR_print_errors(i32* %236)
store i32* null, i32** %7
br label %261
238: ; preds = %229
%239 = load i32*, i32** %10
%240 = load i32, i32* %239
%241 = load i32, i32* @EVP_PKEY_RSA
%242 = icmp eq i32 %240, %241
br i1 %242, label %243, label %259
243: ; preds = %238
%244 = load i64, i64* %16
%245 = icmp ne i64 %244, -1
br i1 %245, label %246, label %259
246: ; preds = %243
%247 = load i32*, i32** %14
%248 = load i64, i64* %16
%249 = call i64 @EVP_PKEY_CTX_set_rsa_keygen_bits(i32* %247, i64 %248)
%250 = icmp sle i64 %249, 0
br i1 %250, label %251, label %258
251: ; preds = %246
%252 = load i32*, i32** %8
%253 = call i32 @BIO_puts(i32* %252, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0))
%254 = load i32*, i32** %8
%255 = call i32 @ERR_print_errors(i32* %254)
%256 = load i32*, i32** %14
%257 = call i32 @EVP_PKEY_CTX_free(i32* %256)
store i32* null, i32** %7
br label %261
258: ; preds = %246
br label %259
259: ; preds = %258, %243, %238
%260 = load i32*, i32** %14
store i32* %260, i32** %7
br label %261
261: ; preds = %259, %251, %233, %224, %189, %173, %155, %128, %81
%262 = load i32*, i32** %7
ret i32* %262
}

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 %98
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 %98
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 %62
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 %56, 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 %55
51: ; preds = %47
br i1 %29, label %58, 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 %58
55: ; preds = %47
br i1 %29, label %58, label %60
56: ; preds = %37
%57 = 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 %153
58: ; preds = %51, %52, %55
%59 = phi i64 [ %54, %52 ], [ -1, %51 ], [ -1, %55 ]
br label %98
60: ; preds = %55
%61 = getelementptr inbounds i8, i8* %27, i64 1
br label %62
62: ; preds = %60, %24
%63 = phi i8* [ %25, %24 ], [ %61, %60 ]
%64 = call i32* @BIO_new_file(i8* %63, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%65 = icmp eq i32* %64, null
br i1 %65, label %66, label %68
66: ; preds = %62
%67 = call i32 (i32*, i8*, ...) @BIO_printf(i32* %0, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %63)
br label %153
68: ; preds = %62
%69 = call i32* @PEM_read_bio_Parameters(i32* %64, i32* null)
%70 = icmp eq i32* %69, null
br i1 %70, label %73, label %71
71: ; preds = %68
%72 = call i32 @BIO_free(i32* %64)
br label %86
73: ; preds = %68
%74 = call i32 @BIO_reset(i32* %64)
%75 = call i32* @PEM_read_bio_X509(i32* %64, i32* null, i32* null, i32* null)
%76 = icmp eq i32* %75, null
br i1 %76, label %77, label %79
77: ; preds = %73
%78 = call i32 @BIO_free(i32* %64)
br label %84
79: ; preds = %73
%80 = call i32* @X509_get_pubkey(i32* %75)
%81 = call i32 @X509_free(i32* %75)
%82 = call i32 @BIO_free(i32* %64)
%83 = icmp eq i32* %80, null
br i1 %83, label %84, label %86
84: ; preds = %77, %79
%85 = call i32 (i32*, i8*, ...) @BIO_printf(i32* %0, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* %63)
br label %153
86: ; preds = %71, %79
%87 = phi i32* [ %69, %71 ], [ %80, %79 ]
%88 = load i32, i32* %2
%89 = icmp eq i32 %88, -1
br i1 %89, label %90, label %92
90: ; preds = %86
%91 = call i32 @EVP_PKEY_id(i32* %87)
store i32 %91, i32* %2
br label %98
92: ; preds = %86
%93 = call i32 @EVP_PKEY_base_id(i32* %87)
%94 = icmp eq i32 %88, %93
br i1 %94, label %98, label %95
95: ; preds = %92
%96 = call i32 (i32*, i8*, ...) @BIO_printf(i32* %0, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0))
%97 = call i32 @EVP_PKEY_free(i32* %87)
br label %153
98: ; preds = %18, %11, %58, %90, %92
%99 = phi i64 [ -1, %90 ], [ -1, %92 ], [ %59, %58 ], [ %20, %18 ], [ %13, %11 ]
%100 = phi i32* [ %87, %90 ], [ %87, %92 ], [ null, %58 ], [ null, %18 ], [ null, %11 ]
%101 = icmp eq i8** %4, null
br i1 %101, label %119, label %102
102: ; preds = %98
%103 = bitcast i32** %8 to i8*
%104 = bitcast i8** %9 to i8*
%105 = load i32, i32* %2
%106 = call i32* @EVP_PKEY_asn1_find(i32** %8, i32 %105)
%107 = icmp eq i32* %106, null
br i1 %107, label %117, label %108
108: ; preds = %102
%109 = call i32 @EVP_PKEY_asn1_get0_info(i32* null, i32* null, i32* null, i32* null, i8** %9, i32* %106)
%110 = load i8*, i8** %9
%111 = call i8* @BUF_strdup(i8* %110)
store i8* %111, i8** %4
%112 = load i32*, i32** %8
%113 = icmp eq i32* %112, null
br i1 %113, label %116, label %114
114: ; preds = %108
%115 = call i32 @ENGINE_finish(i32* %112)
br label %116
116: ; preds = %108, %114
br label %119
117: ; preds = %102
%118 = call i32 @BIO_puts(i32* %0, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0))
br label %153
119: ; preds = %116, %98
%120 = icmp eq i32* %100, null
br i1 %120, label %125, label %121
121: ; preds = %119
%122 = call i32* @EVP_PKEY_CTX_new(i32* %100, i32* %5)
%123 = call i64 @EVP_PKEY_bits(i32* %100)
store i64 %123, i64* %3
%124 = call i32 @EVP_PKEY_free(i32* %100)
br label %128
125: ; preds = %119
%126 = load i32, i32* %2
%127 = call i32* @EVP_PKEY_CTX_new_id(i32 %126, i32* %5)
br label %128
128: ; preds = %125, %121
%129 = phi i32* [ %122, %121 ], [ %127, %125 ]
%130 = icmp eq i32* %129, null
br i1 %130, label %131, label %134
131: ; preds = %128
%132 = call i32 @BIO_puts(i32* %0, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0))
%133 = call i32 @ERR_print_errors(i32* %0)
br label %153
134: ; preds = %128
%135 = call i64 @EVP_PKEY_keygen_init(i32* %129)
%136 = icmp slt i64 %135, 1
br i1 %136, label %137, label %140
137: ; preds = %134
%138 = call i32 @BIO_puts(i32* %0, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0))
%139 = call i32 @ERR_print_errors(i32* %0)
br label %153
140: ; preds = %134
%141 = load i32, i32* %2
%142 = load i32, i32* @EVP_PKEY_RSA
%143 = icmp eq i32 %141, %142
%144 = icmp ne i64 %99, -1
%145 = select i1 %143, i1 %144, i1 false
br i1 %145, label %146, label %153
146: ; preds = %140
%147 = call i64 @EVP_PKEY_CTX_set_rsa_keygen_bits(i32* %129, i64 %99)
%148 = icmp slt i64 %147, 1
br i1 %148, label %149, label %153
149: ; preds = %146
%150 = call i32 @BIO_puts(i32* %0, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0))
%151 = call i32 @ERR_print_errors(i32* %0)
%152 = call i32 @EVP_PKEY_CTX_free(i32* %129)
br label %153
153: ; preds = %117, %56, %140, %146, %149, %137, %131, %95, %84, %66
%154 = phi i32* [ null, %137 ], [ null, %149 ], [ null, %131 ], [ null, %117 ], [ null, %95 ], [ null, %84 ], [ null, %66 ], [ null, %56 ], [ %129, %146 ], [ %129, %140 ]
ret i32* %154
}