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

  const char cert_filestr[] = "./demo/cert-file.pem";
             EVP_PKEY *pkey = NULL;
  BIO              *certbio = NULL;
  BIO               *outbio = NULL;
  X509                *cert = NULL;

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

  /* ---------------------------------------------------------- *
   * Load the certificate from file (PEM).                      *
   * ---------------------------------------------------------- */
  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);
  }

  /* ---------------------------------------------------------- *
   * Extract the certificate's public key data.                 *
   * ---------------------------------------------------------- */
  if ((pkey = X509_get_pubkey(cert)) == NULL)
    BIO_printf(outbio, "Error getting public key from certificate");

  /* ---------------------------------------------------------- *
   * Print the public key information and the key in PEM format *
   * ---------------------------------------------------------- */
  /* display the key type and size here */
  if (pkey) {
    BIO_printf(outbio, "Retrieved %d bit %s key", EVP_PKEY_bits(pkey),
                                     EVP_PKEY_get0_type_name(pkey));
    if(EVP_PKEY_base_id(pkey) == EVP_PKEY_EC) {
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
        char curvestr[80];
        EVP_PKEY_get_utf8_string_param(pkey,
                            OSSL_PKEY_PARAM_GROUP_NAME,
                            curvestr,
                            sizeof(curvestr),
                            NULL);
        BIO_printf(outbio, ", type %s", curvestr);
#else
        EC_KEY *myecc = NULL;
        myecc = EVP_PKEY_get1_EC_KEY(pkey);
        const EC_GROUP *ecgrp = EC_KEY_get0_group(myecc);
        BIO_printf(outbio, ", type %s",
                OBJ_nid2sn(EC_GROUP_get_curve_name(ecgrp)));
#endif
    }
    BIO_printf(outbio, " from %s\n\n", cert_filestr);
  }
  else {
    BIO_printf(outbio, "Could not get public key from %s\n", cert_filestr);
    exit(1);
  }

  if(!PEM_write_bio_PUBKEY(outbio, pkey))
    BIO_printf(outbio, "Error writing public key data in PEM format");

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movl $0x0, -0x4(%rbp)
movq 0xdc7(%rip), %rax       # 0x2010
movq %rax, -0x20(%rbp)
movq 0xdc4(%rip), %rax       # 0x2018
movq %rax, -0x18(%rbp)
movl 0xdc2(%rip), %eax       # 0x2020
movl %eax, -0x10(%rbp)
movb 0xdbd(%rip), %al        # 0x2024
movb %al, -0xc(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
callq 0x1050
movq %rax, %rdi
callq 0x10f0
movq %rax, -0x30(%rbp)
movq 0x2d2e(%rip), %rax      # 0x3fd0
movq (%rax), %rdi
xorl %esi, %esi
callq 0x1090
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rdi
leaq -0x20(%rbp), %rcx
movl $0x6c, %esi
movl $0x3, %edx
callq 0x1040
movq -0x30(%rbp), %rdi
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rsi
movq %rcx, %rdx
callq 0x1110
movq %rax, -0x40(%rbp)
cmpq $0x0, %rax
jne 0x1304
movq -0x38(%rbp), %rdi
leaq -0x20(%rbp), %rdx
leaq 0xd32(%rip), %rsi       # 0x2025
movb $0x0, %al
callq 0x1120
movl $0x1, %edi
callq 0x10d0
movq -0x40(%rbp), %rdi
callq 0x10e0
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
jne 0x1329
movq -0x38(%rbp), %rdi
leaq 0xd27(%rip), %rsi       # 0x2049
movb $0x0, %al
callq 0x1120
cmpq $0x0, -0x28(%rbp)
je 0x13d7
movq -0x38(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x28(%rbp), %rdi
callq 0x10b0
movl %eax, -0x94(%rbp)
movq -0x28(%rbp), %rdi
callq 0x10a0
movq -0xa0(%rbp), %rdi
movl -0x94(%rbp), %edx
movq %rax, %rcx
leaq 0xd05(%rip), %rsi       # 0x2073
movb $0x0, %al
callq 0x1120
movq -0x28(%rbp), %rdi
callq 0x1030
cmpl $0x198, %eax            # imm = 0x198
jne 0x13bf
movq -0x28(%rbp), %rdi
leaq -0x90(%rbp), %rdx
leaq 0xcf4(%rip), %rsi       # 0x208b
movl $0x50, %ecx
xorl %eax, %eax
movl %eax, %r8d
callq 0x10c0
movq -0x38(%rbp), %rdi
leaq -0x90(%rbp), %rdx
leaq 0xcd9(%rip), %rsi       # 0x2091
movb $0x0, %al
callq 0x1120
movq -0x38(%rbp), %rdi
leaq -0x20(%rbp), %rdx
leaq 0xccd(%rip), %rsi       # 0x209b
movb $0x0, %al
callq 0x1120
jmp 0x13f7
movq -0x38(%rbp), %rdi
leaq -0x20(%rbp), %rdx
leaq 0xcc0(%rip), %rsi       # 0x20a6
movb $0x0, %al
callq 0x1120
movl $0x1, %edi
callq 0x10d0
movq -0x38(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x1100
cmpl $0x0, %eax
jne 0x141b
movq -0x38(%rbp), %rdi
leaq 0xcb4(%rip), %rsi       # 0x20c8
movb $0x0, %al
callq 0x1120
movq -0x40(%rbp), %rdi
callq 0x1070
movq -0x28(%rbp), %rdi
callq 0x1080
movq -0x30(%rbp), %rdi
callq 0x1060
movq -0x38(%rbp), %rdi
callq 0x1060
xorl %edi, %edi
callq 0x10d0