// File: /workspace/github_c_makefile_star2_O0/fm4dd[P]learn-ssl/certrenewal.c
// Function: main
int main() {

  const char cert_filestr[] = "./demo/cert-file.pem";
  const char pkey_filestr[] = "./demo/cert-file.key";
  BIO              *certbio = NULL;
  BIO              *pkeybio = NULL;
  BIO               *outbio = NULL;
  X509                *cert = NULL;
  X509_REQ         *certreq = NULL;
  EVP_PKEY            *pkey = NULL;
  EVP_MD      const *digest = EVP_sha1();
  int ret;

  /* ---------------------------------------------------------- *
   * Create the Input/Output BIO's.                             *
   * ---------------------------------------------------------- */
  certbio = BIO_new(BIO_s_file());
  pkeybio = BIO_new(BIO_s_file());
  outbio  = BIO_new_fp(stdout, BIO_NOCLOSE);

  /* ---------------------------------------------------------- *
   * Load the old certificate from file (PEM).                  *
   * ---------------------------------------------------------- */
  ret = BIO_read_filename(certbio, cert_filestr);
  if (! (cert = PEM_read_bio_X509(certbio, NULL, 0, NULL))) {
    BIO_printf(outbio, "Error loading cert into memory: %s\n", cert_filestr);
    exit(1);
  }

  /* ---------------------------------------------------------- *
   * Load the original private key from file (PEM).             *
   * ---------------------------------------------------------- */
  ret = BIO_read_filename(pkeybio, pkey_filestr);
  if(ret == 0) {
    BIO_printf(outbio, "Error loading private key into BIO: %s\n", pkey_filestr);
    exit(1);
  }

  if (! (pkey = PEM_read_bio_PrivateKey(pkeybio, NULL, 0, NULL))) {
    BIO_printf(outbio, "Error loading private key into memory: %s\n", pkey_filestr);
    exit(1);
  }

  /* ---------------------------------------------------------- *
   * Convert the old certificate into a new request             *
   * Returns NULL on error                                      *
   * ---------------------------------------------------------- */
  if ((certreq = X509_to_X509_REQ(cert, pkey, digest)) == NULL) {
    BIO_printf(outbio, "Error converting certificate into request.\n");
    exit(1);
  }

  /* ---------------------------------------------------------- *
   * Print the new certificate request (PEM)                    *
   * ---------------------------------------------------------- */
  PEM_write_bio_X509_REQ(outbio, certreq);

  X509_free(cert);
  X509_REQ_free(certreq);
  EVP_PKEY_free(pkey);
  BIO_free_all(certbio);
  BIO_free_all(pkeybio);
  BIO_free_all(outbio);
  exit(0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movl $0x0, -0x4(%rbp)
movq 0xdd7(%rip), %rax       # 0x2010
movq %rax, -0x20(%rbp)
movq 0xdd4(%rip), %rax       # 0x2018
movq %rax, -0x18(%rbp)
movl 0xdd2(%rip), %eax       # 0x2020
movl %eax, -0x10(%rbp)
movb 0xdcd(%rip), %al        # 0x2024
movb %al, -0xc(%rbp)
movq 0xdcf(%rip), %rax       # 0x2030
movq %rax, -0x40(%rbp)
movq 0xdcc(%rip), %rax       # 0x2038
movq %rax, -0x38(%rbp)
movl 0xdca(%rip), %eax       # 0x2040
movl %eax, -0x30(%rbp)
movb 0xdc5(%rip), %al        # 0x2044
movb %al, -0x2c(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
movq $0x0, -0x68(%rbp)
movq $0x0, -0x70(%rbp)
callq 0x10b0
movq %rax, -0x78(%rbp)
callq 0x1050
movq %rax, %rdi
callq 0x10f0
movq %rax, -0x48(%rbp)
callq 0x1050
movq %rax, %rdi
callq 0x10f0
movq %rax, -0x50(%rbp)
movq 0x2cec(%rip), %rax      # 0x3fd0
movq (%rax), %rdi
xorl %esi, %esi
callq 0x10a0
movq %rax, -0x58(%rbp)
movq -0x48(%rbp), %rdi
leaq -0x20(%rbp), %rcx
movl $0x6c, %esi
movl $0x3, %edx
callq 0x1030
movl %eax, -0x7c(%rbp)
movq -0x48(%rbp), %rdi
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rsi
movq %rcx, %rdx
callq 0x1100
movq %rax, -0x60(%rbp)
cmpq $0x0, %rax
jne 0x1349
movq -0x58(%rbp), %rdi
leaq -0x20(%rbp), %rdx
leaq 0xd0d(%rip), %rsi       # 0x2045
movb $0x0, %al
callq 0x1110
movl $0x1, %edi
callq 0x10c0
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rcx
movl $0x6c, %esi
movl $0x3, %edx
callq 0x1030
movl %eax, -0x7c(%rbp)
cmpl $0x0, -0x7c(%rbp)
jne 0x1389
movq -0x58(%rbp), %rdi
leaq -0x40(%rbp), %rdx
leaq 0xcf1(%rip), %rsi       # 0x2069
movb $0x0, %al
callq 0x1110
movl $0x1, %edi
callq 0x10c0
movq -0x50(%rbp), %rdi
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rsi
movq %rcx, %rdx
callq 0x1090
movq %rax, -0x70(%rbp)
cmpq $0x0, %rax
jne 0x13c6
movq -0x58(%rbp), %rdi
leaq -0x40(%rbp), %rdx
leaq 0xcdc(%rip), %rsi       # 0x2091
movb $0x0, %al
callq 0x1110
movl $0x1, %edi
callq 0x10c0
movq -0x60(%rbp), %rdi
movq -0x70(%rbp), %rsi
movq -0x78(%rbp), %rdx
callq 0x10e0
movq %rax, -0x68(%rbp)
cmpq $0x0, %rax
jne 0x13fd
movq -0x58(%rbp), %rdi
leaq 0xcd0(%rip), %rsi       # 0x20bc
movb $0x0, %al
callq 0x1110
movl $0x1, %edi
callq 0x10c0
movq -0x58(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x1040
movq -0x60(%rbp), %rdi
callq 0x1070
movq -0x68(%rbp), %rdi
callq 0x10d0
movq -0x70(%rbp), %rdi
callq 0x1080
movq -0x48(%rbp), %rdi
callq 0x1060
movq -0x50(%rbp), %rdi
callq 0x1060
movq -0x58(%rbp), %rdi
callq 0x1060
xorl %edi, %edi
callq 0x10c0