#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 unsigned char uint8_t;
typedef int /*<<< orphan*/ X509_REQ;
typedef int /*<<< orphan*/ X509_NAME;
typedef int /*<<< orphan*/ X509;
typedef int /*<<< orphan*/ FILE;
typedef int /*<<< orphan*/ EVP_PKEY;
typedef int /*<<< orphan*/ BIO;
typedef int /*<<< orphan*/ BIGNUM;
typedef int /*<<< orphan*/ ASN1_INTEGER;

/* Variables and functions */
int /*<<< orphan*/ ASN1_INTEGER_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *ASN1_INTEGER_new();
int /*<<< orphan*/ BIO_NOCLOSE;
int /*<<< orphan*/ BIO_free_all(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BIO_new(int /*<<< orphan*/);
int /*<<< orphan*/ *BIO_new_fp(int /*<<< orphan*/, int /*<<< orphan*/);
size_t BIO_pending(int /*<<< orphan*/ *);
int /*<<< orphan*/ BIO_read(int /*<<< orphan*/ *, unsigned char *, size_t);
int /*<<< orphan*/ BIO_read_filename(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ BIO_s_file();
int /*<<< orphan*/ BIO_s_mem();
int /*<<< orphan*/ BN_bin2bn(unsigned char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BN_new();
int /*<<< orphan*/ BN_to_ASN1_INTEGER(int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *);
int /*<<< orphan*/ CRYPTO_cleanup_all_ex_data();
int /*<<< orphan*/ EVP_PKEY_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *EVP_PKEY_new();
int /*<<< orphan*/ EVP_PKEY_print_private(int /*<<< orphan*/ *,
                                          int /*<<< orphan*/ *,
                                          int /*<<< orphan*/,
                                          int /*<<< orphan*/ *);
int /*<<< orphan*/ EVP_sha256();
int /*<<< orphan*/ MBSTRING_ASC;
int /*<<< orphan*/ OpenSSL_add_all_algorithms();
int /*<<< orphan*/ PEM_read_PrivateKey(int /*<<< orphan*/ *,
                                       int /*<<< orphan*/ **,
                                       int /*<<< orphan*/ *,
                                       int /*<<< orphan*/ *);
int /*<<< orphan*/ *PEM_read_bio_PrivateKey(int /*<<< orphan*/ *,
                                            int /*<<< orphan*/ *,
                                            int /*<<< orphan*/ *,
                                            int /*<<< orphan*/ *);
int /*<<< orphan*/ *PEM_read_bio_X509(int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *);
int /*<<< orphan*/
PEM_write_PrivateKey(int /*<<< orphan*/, int /*<<< orphan*/ *,
                     int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                     int /*<<< orphan*/, int /*<<< orphan*/ *,
                     int /*<<< orphan*/ *);
int /*<<< orphan*/ PEM_write_bio_X509(int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *);
int /*<<< orphan*/ RAND_bytes(unsigned char *, int);
int /*<<< orphan*/ X509_NAME_add_entry_by_txt(int /*<<< orphan*/ *, char *,
                                              int /*<<< orphan*/,
                                              unsigned char const *, int, int,
                                              int /*<<< orphan*/);
int /*<<< orphan*/ X509_REQ_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *X509_REQ_get_pubkey(int /*<<< orphan*/ *);
int /*<<< orphan*/ *X509_REQ_get_subject_name(int /*<<< orphan*/ *);
int /*<<< orphan*/ *X509_REQ_new();
int /*<<< orphan*/ X509_REQ_set_pubkey(int /*<<< orphan*/ *,
                                       int /*<<< orphan*/ *);
int /*<<< orphan*/ X509_REQ_sign(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                 int /*<<< orphan*/);
int /*<<< orphan*/ X509_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ X509_get_notAfter(int /*<<< orphan*/ *);
int /*<<< orphan*/ X509_get_notBefore(int /*<<< orphan*/ *);
int /*<<< orphan*/ X509_get_subject_name(int /*<<< orphan*/ *);
int /*<<< orphan*/ X509_gmtime_adj(int /*<<< orphan*/, long);
int /*<<< orphan*/ *X509_new();
int /*<<< orphan*/ X509_set_issuer_name(int /*<<< orphan*/ *,
                                        int /*<<< orphan*/);
int /*<<< orphan*/ X509_set_pubkey(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ X509_set_serialNumber(int /*<<< orphan*/ *,
                                         int /*<<< orphan*/ *);
int /*<<< orphan*/ X509_set_subject_name(int /*<<< orphan*/ *,
                                         int /*<<< orphan*/ *);
int /*<<< orphan*/ X509_set_version(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ X509_sign(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                             int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ fwrite(unsigned char *, int, size_t, int /*<<< orphan*/ *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdout;
int main() {
  EVP_PKEY *device_privkey = NULL, *ca_key = NULL;
  X509 *ca_cert, *crt;
  X509_REQ *req;
  BIO *bio;
  FILE *file;
  size_t cert_size = 0;
  unsigned char *cert_bytes, serial_bytes[20];
  OpenSSL_add_all_algorithms();
  device_privkey = EVP_PKEY_new();
  ca_key = EVP_PKEY_new();
  file = fopen("server_private_key.pem", "r");
  PEM_read_PrivateKey(file, &device_privkey, NULL, NULL);
  fclose(file);
  printf("Device ed25519 private key\n");
  bio = BIO_new_fp(stdout, BIO_NOCLOSE);
  EVP_PKEY_print_private(bio, device_privkey, 0, NULL);
  BIO_free_all(bio);
  PEM_write_PrivateKey(stdout, device_privkey, NULL, NULL, 0, NULL, NULL);
  printf("\n");
  bio = BIO_new(BIO_s_file());
  BIO_read_filename(bio, "ca_key.pem");
  ca_key = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL);
  BIO_free_all(bio);
  bio = BIO_new(BIO_s_file());
  BIO_read_filename(bio, "ca_cert.pem");
  ca_cert = PEM_read_bio_X509(bio, NULL, NULL, NULL);
  BIO_free_all(bio);
  req = X509_REQ_new();
  X509_REQ_set_pubkey(req, device_privkey);
  X509_NAME *name = X509_REQ_get_subject_name(req);
  X509_NAME_add_entry_by_txt(name, "C", MBSTRING_ASC,
                             (const unsigned char *)("USA"), -1, -1, 0);
  X509_NAME_add_entry_by_txt(name, "ST", MBSTRING_ASC,
                             (const unsigned char *)("CO"), -1, -1, 0);
  X509_NAME_add_entry_by_txt(name, "L", MBSTRING_ASC,
                             (const unsigned char *)("Boulder"), -1, -1, 0);
  X509_NAME_add_entry_by_txt(name, "O", MBSTRING_ASC,
                             (const unsigned char *)("NSR"), -1, -1, 0);
  X509_NAME_add_entry_by_txt(
      name, "CN", MBSTRING_ASC,
      (const unsigned char *)("BYOSH Remote Attestation Certificate"), -1, -1,
      0);
  X509_REQ_sign(req, device_privkey, EVP_sha256());
  crt = X509_new();
  X509_set_version(crt, 2);
  RAND_bytes(serial_bytes, 20);
  serial_bytes[0] &= 0x7f;
  BIGNUM *bn = BN_new();
  BN_bin2bn(serial_bytes, 20, bn);
  ASN1_INTEGER *serial = ASN1_INTEGER_new();
  BN_to_ASN1_INTEGER(bn, serial);
  X509_set_serialNumber(crt, serial);
  ASN1_INTEGER_free(serial);
  BN_free(bn);
  X509_set_issuer_name(crt, X509_get_subject_name(ca_cert));
  X509_gmtime_adj(X509_get_notBefore(crt), 0);
  X509_gmtime_adj(X509_get_notAfter(crt), (long)2 * 365 * 3600);
  X509_set_subject_name(crt, X509_REQ_get_subject_name(req));
  EVP_PKEY *req_pubkey = X509_REQ_get_pubkey(req);
  X509_set_pubkey(crt, req_pubkey);
  EVP_PKEY_free(req_pubkey);
  X509_sign(crt, ca_key, EVP_sha256());
  X509_REQ_free(req);
  bio = BIO_new(BIO_s_mem());
  PEM_write_bio_X509(bio, crt);
  cert_size = BIO_pending(bio);
  cert_bytes = (uint8_t *)malloc(cert_size + 1);
  BIO_read(bio, cert_bytes, cert_size);
  BIO_free_all(bio);
  file = fopen("test.crt.pem", "w");
  fwrite(cert_bytes, sizeof(unsigned char), cert_size, file);
  fclose(file);
  EVP_PKEY_free(ca_key);
  EVP_PKEY_free(device_privkey);
  X509_free(ca_cert);
  X509_free(crt);
  free(cert_bytes);
  CRYPTO_cleanup_all_ex_data();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x48(%rbp)
mov    $0x0,%al
call   21c0 <OpenSSL_add_all_algorithms@plt>
mov    $0x0,%al
call   2220 <EVP_PKEY_new@plt>
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   2220 <EVP_PKEY_new@plt>
mov    %rax,-0x18(%rbp)
lea    0xb82(%rip),%rdi
lea    0xbd9(%rip),%rsi
call   2260 <fopen@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
lea    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
call   22a0 <PEM_read_PrivateKey@plt>
mov    -0x40(%rbp),%rdi
call   20c0 <fclose@plt>
lea    0xb65(%rip),%rdi
call   2140 <printf@plt>
mov    0x2b12(%rip),%rax
mov    (%rax),%edi
mov    0x2b21(%rip),%rax
mov    (%rax),%esi
call   2060 <BIO_new_fp@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
xor    %edx,%edx
xor    %eax,%eax
mov    %eax,%ecx
call   2170 <EVP_PKEY_print_private@plt>
mov    -0x38(%rbp),%rdi
call   22b0 <BIO_free_all@plt>
mov    0x2adb(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r9d
xor    %r8d,%r8d
mov    %r9,%rdx
mov    %r9,%rcx
movq   $0x0,(%rsp)
call   2280 <PEM_write_PrivateKey@plt>
lea    0xb14(%rip),%rdi
call   2140 <printf@plt>
mov    $0x0,%al
call   2320 <BIO_s_file@plt>
mov    %eax,%edi
call   2200 <BIO_new@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xaf4(%rip),%rsi
call   2230 <BIO_read_filename@plt>
mov    -0x38(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rsi
mov    %rcx,%rdx
call   22c0 <PEM_read_bio_PrivateKey@plt>
mov    %rax,-0x18(%rbp)
mov    -0x38(%rbp),%rdi
call   22b0 <BIO_free_all@plt>
mov    $0x0,%al
call   2320 <BIO_s_file@plt>
mov    %eax,%edi
call   2200 <BIO_new@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xabd(%rip),%rsi
call   2230 <BIO_read_filename@plt>
mov    -0x38(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rsi
mov    %rcx,%rdx
call   2300 <PEM_read_bio_X509@plt>
mov    %rax,-0x20(%rbp)
mov    -0x38(%rbp),%rdi
call   22b0 <BIO_free_all@plt>
mov    $0x0,%al
call   2110 <X509_REQ_new@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   2310 <X509_REQ_set_pubkey@plt>
mov    -0x30(%rbp),%rdi
call   2030 <X509_REQ_get_subject_name@plt>
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rdi
mov    0x2a0a(%rip),%rax
mov    (%rax),%edx
lea    0xa6b(%rip),%rsi
lea    0xa66(%rip),%rcx
mov    $0xffffffff,%r9d
xor    %eax,%eax
mov    %r9d,%r8d
movl   $0x0,(%rsp)
call   21f0 <X509_NAME_add_entry_by_txt@plt>
mov    -0x78(%rbp),%rdi
mov    0x29d8(%rip),%rax
mov    (%rax),%edx
lea    0xa3f(%rip),%rsi
lea    0xa3b(%rip),%rcx
mov    $0xffffffff,%r9d
xor    %eax,%eax
mov    %r9d,%r8d
movl   $0x0,(%rsp)
call   21f0 <X509_NAME_add_entry_by_txt@plt>
mov    -0x78(%rbp),%rdi
mov    0x29a6(%rip),%rax
mov    (%rax),%edx
lea    0xa13(%rip),%rsi
lea    0xa0e(%rip),%rcx
mov    $0xffffffff,%r9d
xor    %eax,%eax
mov    %r9d,%r8d
movl   $0x0,(%rsp)
call   21f0 <X509_NAME_add_entry_by_txt@plt>
mov    -0x78(%rbp),%rdi
mov    0x2974(%rip),%rax
mov    (%rax),%edx
lea    0x9df(%rip),%rsi
lea    0x9e4(%rip),%rcx
mov    $0xffffffff,%r9d
xor    %eax,%eax
mov    %r9d,%r8d
movl   $0x0,(%rsp)
call   21f0 <X509_NAME_add_entry_by_txt@plt>
mov    -0x78(%rbp),%rdi
mov    0x2942(%rip),%rax
mov    (%rax),%edx
lea    0x9bd(%rip),%rsi
lea    0x9b9(%rip),%rcx
mov    $0xffffffff,%r9d
xor    %eax,%eax
mov    %r9d,%r8d
movl   $0x0,(%rsp)
call   21f0 <X509_NAME_add_entry_by_txt@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0xc0(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0xb8(%rbp)
mov    $0x0,%al
call   2330 <EVP_sha256@plt>
mov    -0xc0(%rbp),%rdi
mov    -0xb8(%rbp),%rsi
mov    %eax,%edx
call   20b0 <X509_REQ_sign@plt>
mov    $0x0,%al
call   2350 <X509_new@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x2,%esi
call   20a0 <X509_set_version@plt>
lea    -0x70(%rbp),%rdi
mov    $0x14,%esi
call   2130 <RAND_bytes@plt>
movzbl -0x70(%rbp),%eax
and    $0x7f,%eax
mov    %al,-0x70(%rbp)
mov    $0x0,%al
call   2090 <BN_new@plt>
mov    %rax,-0x80(%rbp)
lea    -0x70(%rbp),%rdi
mov    -0x80(%rbp),%rdx
mov    $0x14,%esi
call   2120 <BN_bin2bn@plt>
mov    $0x0,%al
call   2100 <ASN1_INTEGER_new@plt>
mov    %rax,-0x88(%rbp)
mov    -0x80(%rbp),%rdi
mov    -0x88(%rbp),%rsi
call   2210 <BN_to_ASN1_INTEGER@plt>
mov    -0x28(%rbp),%rdi
mov    -0x88(%rbp),%rsi
call   20d0 <X509_set_serialNumber@plt>
mov    -0x88(%rbp),%rdi
call   22f0 <ASN1_INTEGER_free@plt>
mov    -0x80(%rbp),%rdi
call   2190 <BN_free@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0xb0(%rbp)
mov    -0x20(%rbp),%rdi
call   2150 <X509_get_subject_name@plt>
mov    -0xb0(%rbp),%rdi
mov    %eax,%esi
call   2180 <X509_set_issuer_name@plt>
mov    -0x28(%rbp),%rdi
call   21a0 <X509_get_notBefore@plt>
mov    %eax,%edi
xor    %eax,%eax
mov    %eax,%esi
call   2040 <X509_gmtime_adj@plt>
mov    -0x28(%rbp),%rdi
call   20e0 <X509_get_notAfter@plt>
mov    %eax,%edi
mov    $0x2819a0,%esi
call   2040 <X509_gmtime_adj@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0xa8(%rbp)
mov    -0x30(%rbp),%rdi
call   2030 <X509_REQ_get_subject_name@plt>
mov    -0xa8(%rbp),%rdi
mov    %rax,%rsi
call   2270 <X509_set_subject_name@plt>
mov    -0x30(%rbp),%rdi
call   2070 <X509_REQ_get_pubkey@plt>
mov    %rax,-0x90(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x90(%rbp),%rsi
call   2250 <X509_set_pubkey@plt>
mov    -0x90(%rbp),%rdi
call   2160 <EVP_PKEY_free@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0xa0(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x98(%rbp)
mov    $0x0,%al
call   2330 <EVP_sha256@plt>
mov    -0xa0(%rbp),%rdi
mov    -0x98(%rbp),%rsi
mov    %eax,%edx
call   2290 <X509_sign@plt>
mov    -0x30(%rbp),%rdi
call   22e0 <X509_REQ_free@plt>
mov    $0x0,%al
call   2340 <BIO_s_mem@plt>
mov    %eax,%edi
call   2200 <BIO_new@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   21d0 <PEM_write_bio_X509@plt>
mov    -0x38(%rbp),%rdi
call   21b0 <BIO_pending@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
add    $0x1,%rdi
call   21e0 <malloc@plt>
mov    %rax,-0x50(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    -0x48(%rbp),%rdx
call   20f0 <BIO_read@plt>
mov    -0x38(%rbp),%rdi
call   22b0 <BIO_free_all@plt>
lea    0x7d1(%rip),%rdi
lea    0x7d7(%rip),%rsi
call   2260 <fopen@plt>
mov    %rax,-0x40(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rdx
mov    -0x40(%rbp),%rcx
mov    $0x1,%esi
call   22d0 <fwrite@plt>
mov    -0x40(%rbp),%rdi
call   20c0 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   2160 <EVP_PKEY_free@plt>
mov    -0x10(%rbp),%rdi
call   2160 <EVP_PKEY_free@plt>
mov    -0x20(%rbp),%rdi
call   2240 <X509_free@plt>
mov    -0x28(%rbp),%rdi
call   2240 <X509_free@plt>
mov    -0x50(%rbp),%rdi
call   2050 <free@plt>
mov    $0x0,%al
call   2080 <CRYPTO_cleanup_all_ex_data@plt>
xor    %eax,%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
xor    %eax,%eax
call   21d0 <OpenSSL_add_all_algorithms@plt>
xor    %eax,%eax
call   2230 <EVP_PKEY_new@plt>
mov    %rax,0x8(%rsp)
xor    %eax,%eax
call   2230 <EVP_PKEY_new@plt>
lea    0xb91(%rip),%rdi
lea    0xbcc(%rip),%rsi
call   2270 <fopen@plt>
mov    %rax,%rbx
lea    0x8(%rsp),%rsi
mov    %rax,%rdi
xor    %edx,%edx
xor    %ecx,%ecx
call   22b0 <PEM_read_PrivateKey@plt>
mov    %rbx,%rdi
call   20e0 <fclose@plt>
lea    0xbe1(%rip),%rdi
call   2090 <puts@plt>
mov    0x2b26(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2b34(%rip),%rax
mov    (%rax),%esi
call   2060 <BIO_new_fp@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%rsi
mov    %rax,%rdi
xor    %edx,%edx
xor    %ecx,%ecx
call   2180 <EVP_PKEY_print_private@plt>
mov    %rbx,%rdi
call   22c0 <BIO_free_all@plt>
mov    0x0(%rbp),%edi
mov    0x8(%rsp),%rsi
movq   $0x0,(%rsp)
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   2290 <PEM_write_PrivateKey@plt>
mov    $0xa,%edi
call   2070 <putchar@plt>
xor    %eax,%eax
call   2330 <BIO_s_file@plt>
mov    %eax,%edi
call   2210 <BIO_new@plt>
mov    %rax,%rbx
lea    0xaff(%rip),%rsi
mov    %rax,%rdi
call   2240 <BIO_read_filename@plt>
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   22d0 <PEM_read_bio_PrivateKey@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   22c0 <BIO_free_all@plt>
xor    %eax,%eax
call   2330 <BIO_s_file@plt>
mov    %eax,%edi
call   2210 <BIO_new@plt>
mov    %rax,%rbx
lea    0xad1(%rip),%rsi
mov    %rax,%rdi
call   2240 <BIO_read_filename@plt>
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   2310 <PEM_read_bio_X509@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   22c0 <BIO_free_all@plt>
xor    %eax,%eax
call   2130 <X509_REQ_new@plt>
mov    %rax,%r12
mov    0x8(%rsp),%rsi
mov    %rax,%rdi
call   2320 <X509_REQ_set_pubkey@plt>
mov    %r12,%rdi
call   2030 <X509_REQ_get_subject_name@plt>
mov    %rax,%rbx
mov    0x2a45(%rip),%rbp
mov    0x0(%rbp),%edx
movl   $0x0,(%rsp)
lea    0xa82(%rip),%rsi
lea    0xa7d(%rip),%rcx
mov    %rax,%rdi
mov    $0xffffffff,%r8d
mov    $0xffffffff,%r9d
call   2200 <X509_NAME_add_entry_by_txt@plt>
mov    0x0(%rbp),%edx
movl   $0x0,(%rsp)
lea    0xa5c(%rip),%rsi
lea    0xa58(%rip),%rcx
mov    %rbx,%rdi
mov    $0xffffffff,%r8d
mov    $0xffffffff,%r9d
call   2200 <X509_NAME_add_entry_by_txt@plt>
mov    0x0(%rbp),%edx
movl   $0x0,(%rsp)
lea    0xa36(%rip),%rsi
lea    0xa31(%rip),%rcx
mov    %rbx,%rdi
mov    $0xffffffff,%r8d
mov    $0xffffffff,%r9d
call   2200 <X509_NAME_add_entry_by_txt@plt>
mov    0x0(%rbp),%edx
movl   $0x0,(%rsp)
lea    0xa08(%rip),%rsi
lea    0xa0d(%rip),%rcx
mov    %rbx,%rdi
mov    $0xffffffff,%r8d
mov    $0xffffffff,%r9d
call   2200 <X509_NAME_add_entry_by_txt@plt>
mov    0x0(%rbp),%edx
movl   $0x0,(%rsp)
lea    0x9ec(%rip),%rsi
lea    0x9e8(%rip),%rcx
mov    %rbx,%rdi
mov    $0xffffffff,%r8d
mov    $0xffffffff,%r9d
call   2200 <X509_NAME_add_entry_by_txt@plt>
mov    0x8(%rsp),%rbx
xor    %eax,%eax
call   2340 <EVP_sha256@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   20d0 <X509_REQ_sign@plt>
xor    %eax,%eax
call   2360 <X509_new@plt>
mov    %rax,%r13
mov    %rax,%rdi
mov    $0x2,%esi
call   20c0 <X509_set_version@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x14,%esi
call   2150 <RAND_bytes@plt>
andb   $0x7f,0x10(%rsp)
xor    %eax,%eax
call   20b0 <BN_new@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    $0x14,%esi
mov    %rax,%rdx
call   2140 <BN_bin2bn@plt>
xor    %eax,%eax
call   2120 <ASN1_INTEGER_new@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
mov    %rax,%rsi
call   2220 <BN_to_ASN1_INTEGER@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
call   20f0 <X509_set_serialNumber@plt>
mov    %rbx,%rdi
call   2300 <ASN1_INTEGER_free@plt>
mov    %rbp,%rdi
call   21a0 <BN_free@plt>
mov    %r15,%rdi
call   2160 <X509_get_subject_name@plt>
mov    %r13,%rdi
mov    %eax,%esi
call   2190 <X509_set_issuer_name@plt>
mov    %r13,%rdi
call   21b0 <X509_get_notBefore@plt>
mov    %eax,%edi
xor    %esi,%esi
call   2040 <X509_gmtime_adj@plt>
mov    %r13,%rdi
call   2100 <X509_get_notAfter@plt>
mov    $0x2819a0,%esi
mov    %eax,%edi
call   2040 <X509_gmtime_adj@plt>
mov    %r12,%rdi
call   2030 <X509_REQ_get_subject_name@plt>
mov    %r13,%rdi
mov    %rax,%rsi
call   2280 <X509_set_subject_name@plt>
mov    %r12,%rdi
call   2080 <X509_REQ_get_pubkey@plt>
mov    %rax,%rbx
mov    %r13,%rdi
mov    %rax,%rsi
call   2260 <X509_set_pubkey@plt>
mov    %rbx,%rdi
call   2170 <EVP_PKEY_free@plt>
xor    %eax,%eax
call   2340 <EVP_sha256@plt>
mov    %r13,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   22a0 <X509_sign@plt>
mov    %r12,%rdi
call   22f0 <X509_REQ_free@plt>
xor    %eax,%eax
call   2350 <BIO_s_mem@plt>
mov    %eax,%edi
call   2210 <BIO_new@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r13,%rsi
call   21e0 <PEM_write_bio_X509@plt>
mov    %rbp,%rdi
call   21c0 <BIO_pending@plt>
mov    %rax,%rbx
lea    0x1(%rax),%rdi
call   21f0 <malloc@plt>
mov    %rax,%r12
mov    %rbp,%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
call   2110 <BIO_read@plt>
mov    %rbp,%rdi
call   22c0 <BIO_free_all@plt>
lea    0x894(%rip),%rdi
lea    0x89a(%rip),%rsi
call   2270 <fopen@plt>
mov    %rax,%rbp
mov    %r12,%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
mov    %rax,%rcx
call   22e0 <fwrite@plt>
mov    %rbp,%rdi
call   20e0 <fclose@plt>
mov    %r14,%rdi
call   2170 <EVP_PKEY_free@plt>
mov    0x8(%rsp),%rdi
call   2170 <EVP_PKEY_free@plt>
mov    %r15,%rdi
call   2250 <X509_free@plt>
mov    %r13,%rdi
call   2250 <X509_free@plt>
mov    %r12,%rdi
call   2050 <free@plt>
xor    %eax,%eax
call   20a0 <CRYPTO_cleanup_all_ex_data@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"server_private_key.pem\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [28 x i8] c"Device ed25519 private key\0A\00"
@stdout = global i32 0
@BIO_NOCLOSE = global i32 0
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [11 x i8] c"ca_key.pem\00"
@.str.5 = [12 x i8] c"ca_cert.pem\00"
@.str.6 = [2 x i8] c"C\00"
@MBSTRING_ASC = global i32 0
@.str.7 = [4 x i8] c"USA\00"
@.str.8 = [3 x i8] c"ST\00"
@.str.9 = [3 x i8] c"CO\00"
@.str.10 = [2 x i8] c"L\00"
@.str.11 = [8 x i8] c"Boulder\00"
@.str.12 = [2 x i8] c"O\00"
@.str.13 = [4 x i8] c"NSR\00"
@.str.14 = [3 x i8] c"CN\00"
@.str.15 = [37 x i8] c"BYOSH Remote Attestation Certificate\00"
@.str.16 = [13 x i8] c"test.crt.pem\00"
@.str.17 = [2 x i8] c"w\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i64
%10 = alloca i8*
%11 = alloca [20 x i8]
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca i32*
store i32 0, i32* %1
store i32* null, i32** %2
store i32* null, i32** %3
store i64 0, i64* %9
%16 = call i32 (...) @OpenSSL_add_all_algorithms()
%17 = call i32* (...) @EVP_PKEY_new()
store i32* %17, i32** %2
%18 = call i32* (...) @EVP_PKEY_new()
store i32* %18, i32** %3
%19 = call i32* @fopen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %19, i32** %8
%20 = load i32*, i32** %8
%21 = call i32 @PEM_read_PrivateKey(i32* %20, i32** %2, i32* null, i32* null)
%22 = load i32*, i32** %8
%23 = call i32 @fclose(i32* %22)
%24 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%25 = load i32, i32* @stdout
%26 = load i32, i32* @BIO_NOCLOSE
%27 = call i32* @BIO_new_fp(i32 %25, i32 %26)
store i32* %27, i32** %7
%28 = load i32*, i32** %7
%29 = load i32*, i32** %2
%30 = call i32 @EVP_PKEY_print_private(i32* %28, i32* %29, i32 0, i32* null)
%31 = load i32*, i32** %7
%32 = call i32 @BIO_free_all(i32* %31)
%33 = load i32, i32* @stdout
%34 = load i32*, i32** %2
%35 = call i32 @PEM_write_PrivateKey(i32 %33, i32* %34, i32* null, i32* null, i32 0, i32* null, i32* null)
%36 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%37 = call i32 (...) @BIO_s_file()
%38 = call i32* @BIO_new(i32 %37)
store i32* %38, i32** %7
%39 = load i32*, i32** %7
%40 = call i32 @BIO_read_filename(i32* %39, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%41 = load i32*, i32** %7
%42 = call i32* @PEM_read_bio_PrivateKey(i32* %41, i32* null, i32* null, i32* null)
store i32* %42, i32** %3
%43 = load i32*, i32** %7
%44 = call i32 @BIO_free_all(i32* %43)
%45 = call i32 (...) @BIO_s_file()
%46 = call i32* @BIO_new(i32 %45)
store i32* %46, i32** %7
%47 = load i32*, i32** %7
%48 = call i32 @BIO_read_filename(i32* %47, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%49 = load i32*, i32** %7
%50 = call i32* @PEM_read_bio_X509(i32* %49, i32* null, i32* null, i32* null)
store i32* %50, i32** %4
%51 = load i32*, i32** %7
%52 = call i32 @BIO_free_all(i32* %51)
%53 = call i32* (...) @X509_REQ_new()
store i32* %53, i32** %6
%54 = load i32*, i32** %6
%55 = load i32*, i32** %2
%56 = call i32 @X509_REQ_set_pubkey(i32* %54, i32* %55)
%57 = load i32*, i32** %6
%58 = call i32* @X509_REQ_get_subject_name(i32* %57)
store i32* %58, i32** %12
%59 = load i32*, i32** %12
%60 = load i32, i32* @MBSTRING_ASC
%61 = call i32 @X509_NAME_add_entry_by_txt(i32* %59, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i32 %60, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i32 -1, i32 -1, i32 0)
%62 = load i32*, i32** %12
%63 = load i32, i32* @MBSTRING_ASC
%64 = call i32 @X509_NAME_add_entry_by_txt(i32* %62, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32 %63, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i32 -1, i32 -1, i32 0)
%65 = load i32*, i32** %12
%66 = load i32, i32* @MBSTRING_ASC
%67 = call i32 @X509_NAME_add_entry_by_txt(i32* %65, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0), i32 %66, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0), i32 -1, i32 -1, i32 0)
%68 = load i32*, i32** %12
%69 = load i32, i32* @MBSTRING_ASC
%70 = call i32 @X509_NAME_add_entry_by_txt(i32* %68, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i64 0, i64 0), i32 %69, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.13, i64 0, i64 0), i32 -1, i32 -1, i32 0)
%71 = load i32*, i32** %12
%72 = load i32, i32* @MBSTRING_ASC
%73 = call i32 @X509_NAME_add_entry_by_txt(i32* %71, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.14, i64 0, i64 0), i32 %72, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.15, i64 0, i64 0), i32 -1, i32 -1, i32 0)
%74 = load i32*, i32** %6
%75 = load i32*, i32** %2
%76 = call i32 (...) @EVP_sha256()
%77 = call i32 @X509_REQ_sign(i32* %74, i32* %75, i32 %76)
%78 = call i32* (...) @X509_new()
store i32* %78, i32** %5
%79 = load i32*, i32** %5
%80 = call i32 @X509_set_version(i32* %79, i32 2)
%81 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 0
%82 = call i32 @RAND_bytes(i8* %81, i32 20)
%83 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 0
%84 = load i8, i8* %83
%85 = zext i8 %84 to i32
%86 = and i32 %85, 127
%87 = trunc i32 %86 to i8
store i8 %87, i8* %83
%88 = call i32* (...) @BN_new()
store i32* %88, i32** %13
%89 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 0
%90 = load i32*, i32** %13
%91 = call i32 @BN_bin2bn(i8* %89, i32 20, i32* %90)
%92 = call i32* (...) @ASN1_INTEGER_new()
store i32* %92, i32** %14
%93 = load i32*, i32** %13
%94 = load i32*, i32** %14
%95 = call i32 @BN_to_ASN1_INTEGER(i32* %93, i32* %94)
%96 = load i32*, i32** %5
%97 = load i32*, i32** %14
%98 = call i32 @X509_set_serialNumber(i32* %96, i32* %97)
%99 = load i32*, i32** %14
%100 = call i32 @ASN1_INTEGER_free(i32* %99)
%101 = load i32*, i32** %13
%102 = call i32 @BN_free(i32* %101)
%103 = load i32*, i32** %5
%104 = load i32*, i32** %4
%105 = call i32 @X509_get_subject_name(i32* %104)
%106 = call i32 @X509_set_issuer_name(i32* %103, i32 %105)
%107 = load i32*, i32** %5
%108 = call i32 @X509_get_notBefore(i32* %107)
%109 = call i32 @X509_gmtime_adj(i32 %108, i64 0)
%110 = load i32*, i32** %5
%111 = call i32 @X509_get_notAfter(i32* %110)
%112 = call i32 @X509_gmtime_adj(i32 %111, i64 2628000)
%113 = load i32*, i32** %5
%114 = load i32*, i32** %6
%115 = call i32* @X509_REQ_get_subject_name(i32* %114)
%116 = call i32 @X509_set_subject_name(i32* %113, i32* %115)
%117 = load i32*, i32** %6
%118 = call i32* @X509_REQ_get_pubkey(i32* %117)
store i32* %118, i32** %15
%119 = load i32*, i32** %5
%120 = load i32*, i32** %15
%121 = call i32 @X509_set_pubkey(i32* %119, i32* %120)
%122 = load i32*, i32** %15
%123 = call i32 @EVP_PKEY_free(i32* %122)
%124 = load i32*, i32** %5
%125 = load i32*, i32** %3
%126 = call i32 (...) @EVP_sha256()
%127 = call i32 @X509_sign(i32* %124, i32* %125, i32 %126)
%128 = load i32*, i32** %6
%129 = call i32 @X509_REQ_free(i32* %128)
%130 = call i32 (...) @BIO_s_mem()
%131 = call i32* @BIO_new(i32 %130)
store i32* %131, i32** %7
%132 = load i32*, i32** %7
%133 = load i32*, i32** %5
%134 = call i32 @PEM_write_bio_X509(i32* %132, i32* %133)
%135 = load i32*, i32** %7
%136 = call i64 @BIO_pending(i32* %135)
store i64 %136, i64* %9
%137 = load i64, i64* %9
%138 = add i64 %137, 1
%139 = call i64 @malloc(i64 %138)
%140 = inttoptr i64 %139 to i8*
store i8* %140, i8** %10
%141 = load i32*, i32** %7
%142 = load i8*, i8** %10
%143 = load i64, i64* %9
%144 = call i32 @BIO_read(i32* %141, i8* %142, i64 %143)
%145 = load i32*, i32** %7
%146 = call i32 @BIO_free_all(i32* %145)
%147 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.16, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.17, i64 0, i64 0))
store i32* %147, i32** %8
%148 = load i8*, i8** %10
%149 = load i64, i64* %9
%150 = load i32*, i32** %8
%151 = call i32 @fwrite(i8* %148, i32 1, i64 %149, i32* %150)
%152 = load i32*, i32** %8
%153 = call i32 @fclose(i32* %152)
%154 = load i32*, i32** %3
%155 = call i32 @EVP_PKEY_free(i32* %154)
%156 = load i32*, i32** %2
%157 = call i32 @EVP_PKEY_free(i32* %156)
%158 = load i32*, i32** %4
%159 = call i32 @X509_free(i32* %158)
%160 = load i32*, i32** %5
%161 = call i32 @X509_free(i32* %160)
%162 = load i8*, i8** %10
%163 = call i32 @free(i8* %162)
%164 = call i32 (...) @CRYPTO_cleanup_all_ex_data()
ret i32 0
}

LLVM IR (-O2):
@.str = [23 x i8] c"server_private_key.pem\00"
@.str.1 = [2 x i8] c"r\00"
@stdout = global i32 0
@BIO_NOCLOSE = global i32 0
@.str.4 = [11 x i8] c"ca_key.pem\00"
@.str.5 = [12 x i8] c"ca_cert.pem\00"
@.str.6 = [2 x i8] c"C\00"
@MBSTRING_ASC = global i32 0
@.str.7 = [4 x i8] c"USA\00"
@.str.8 = [3 x i8] c"ST\00"
@.str.9 = [3 x i8] c"CO\00"
@.str.10 = [2 x i8] c"L\00"
@.str.11 = [8 x i8] c"Boulder\00"
@.str.12 = [2 x i8] c"O\00"
@.str.13 = [4 x i8] c"NSR\00"
@.str.14 = [3 x i8] c"CN\00"
@.str.15 = [37 x i8] c"BYOSH Remote Attestation Certificate\00"
@.str.16 = [13 x i8] c"test.crt.pem\00"
@.str.17 = [2 x i8] c"w\00"
@str = [27 x i8] c"Device ed25519 private key\00"
define i32 @main() {
%1 = alloca i32*
%2 = alloca [20 x i8]
%3 = bitcast i32** %1 to i8*
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%5 = tail call i32 (...) @OpenSSL_add_all_algorithms()
%6 = tail call i32* (...) @EVP_PKEY_new()
store i32* %6, i32** %1
%7 = tail call i32* (...) @EVP_PKEY_new()
%8 = tail call i32* @fopen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @PEM_read_PrivateKey(i32* %8, i32** %1, i32* null, i32* null)
%10 = call i32 @fclose(i32* %8)
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%12 = load i32, i32* @stdout
%13 = load i32, i32* @BIO_NOCLOSE
%14 = call i32* @BIO_new_fp(i32 %12, i32 %13)
%15 = load i32*, i32** %1
%16 = call i32 @EVP_PKEY_print_private(i32* %14, i32* %15, i32 0, i32* null)
%17 = call i32 @BIO_free_all(i32* %14)
%18 = load i32, i32* @stdout
%19 = load i32*, i32** %1
%20 = call i32 @PEM_write_PrivateKey(i32 %18, i32* %19, i32* null, i32* null, i32 0, i32* null, i32* null)
%21 = call i32 @putchar(i32 10)
%22 = call i32 (...) @BIO_s_file()
%23 = call i32* @BIO_new(i32 %22)
%24 = call i32 @BIO_read_filename(i32* %23, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%25 = call i32* @PEM_read_bio_PrivateKey(i32* %23, i32* null, i32* null, i32* null)
%26 = call i32 @BIO_free_all(i32* %23)
%27 = call i32 (...) @BIO_s_file()
%28 = call i32* @BIO_new(i32 %27)
%29 = call i32 @BIO_read_filename(i32* %28, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%30 = call i32* @PEM_read_bio_X509(i32* %28, i32* null, i32* null, i32* null)
%31 = call i32 @BIO_free_all(i32* %28)
%32 = call i32* (...) @X509_REQ_new()
%33 = load i32*, i32** %1
%34 = call i32 @X509_REQ_set_pubkey(i32* %32, i32* %33)
%35 = call i32* @X509_REQ_get_subject_name(i32* %32)
%36 = load i32, i32* @MBSTRING_ASC
%37 = call i32 @X509_NAME_add_entry_by_txt(i32* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i32 %36, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i32 -1, i32 -1, i32 0)
%38 = load i32, i32* @MBSTRING_ASC
%39 = call i32 @X509_NAME_add_entry_by_txt(i32* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32 %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i32 -1, i32 -1, i32 0)
%40 = load i32, i32* @MBSTRING_ASC
%41 = call i32 @X509_NAME_add_entry_by_txt(i32* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0), i32 %40, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0), i32 -1, i32 -1, i32 0)
%42 = load i32, i32* @MBSTRING_ASC
%43 = call i32 @X509_NAME_add_entry_by_txt(i32* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i64 0, i64 0), i32 %42, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.13, i64 0, i64 0), i32 -1, i32 -1, i32 0)
%44 = load i32, i32* @MBSTRING_ASC
%45 = call i32 @X509_NAME_add_entry_by_txt(i32* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.14, i64 0, i64 0), i32 %44, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.15, i64 0, i64 0), i32 -1, i32 -1, i32 0)
%46 = load i32*, i32** %1
%47 = call i32 (...) @EVP_sha256()
%48 = call i32 @X509_REQ_sign(i32* %32, i32* %46, i32 %47)
%49 = call i32* (...) @X509_new()
%50 = call i32 @X509_set_version(i32* %49, i32 2)
%51 = call i32 @RAND_bytes(i8* %4, i32 20)
%52 = load i8, i8* %4
%53 = and i8 %52, 127
store i8 %53, i8* %4
%54 = call i32* (...) @BN_new()
%55 = call i32 @BN_bin2bn(i8* %4, i32 20, i32* %54)
%56 = call i32* (...) @ASN1_INTEGER_new()
%57 = call i32 @BN_to_ASN1_INTEGER(i32* %54, i32* %56)
%58 = call i32 @X509_set_serialNumber(i32* %49, i32* %56)
%59 = call i32 @ASN1_INTEGER_free(i32* %56)
%60 = call i32 @BN_free(i32* %54)
%61 = call i32 @X509_get_subject_name(i32* %30)
%62 = call i32 @X509_set_issuer_name(i32* %49, i32 %61)
%63 = call i32 @X509_get_notBefore(i32* %49)
%64 = call i32 @X509_gmtime_adj(i32 %63, i64 0)
%65 = call i32 @X509_get_notAfter(i32* %49)
%66 = call i32 @X509_gmtime_adj(i32 %65, i64 2628000)
%67 = call i32* @X509_REQ_get_subject_name(i32* %32)
%68 = call i32 @X509_set_subject_name(i32* %49, i32* %67)
%69 = call i32* @X509_REQ_get_pubkey(i32* %32)
%70 = call i32 @X509_set_pubkey(i32* %49, i32* %69)
%71 = call i32 @EVP_PKEY_free(i32* %69)
%72 = call i32 (...) @EVP_sha256()
%73 = call i32 @X509_sign(i32* %49, i32* %25, i32 %72)
%74 = call i32 @X509_REQ_free(i32* %32)
%75 = call i32 (...) @BIO_s_mem()
%76 = call i32* @BIO_new(i32 %75)
%77 = call i32 @PEM_write_bio_X509(i32* %76, i32* %49)
%78 = call i64 @BIO_pending(i32* %76)
%79 = add i64 %78, 1
%80 = call i64 @malloc(i64 %79)
%81 = inttoptr i64 %80 to i8*
%82 = call i32 @BIO_read(i32* %76, i8* %81, i64 %78)
%83 = call i32 @BIO_free_all(i32* %76)
%84 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.16, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.17, i64 0, i64 0))
%85 = call i32 @fwrite(i8* %81, i32 1, i64 %78, i32* %84)
%86 = call i32 @fclose(i32* %84)
%87 = call i32 @EVP_PKEY_free(i32* %25)
%88 = load i32*, i32** %1
%89 = call i32 @EVP_PKEY_free(i32* %88)
%90 = call i32 @X509_free(i32* %30)
%91 = call i32 @X509_free(i32* %49)
%92 = call i32 @free(i8* %81)
%93 = call i32 (...) @CRYPTO_cleanup_all_ex_data()
ret i32 0
}