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

  const char cert_filestr[] = "./demo/cert-file.pem";
  BIO              *certbio = NULL;
  BIO               *outbio = NULL;
  X509                *cert = NULL;
  const STACK_OF(X509_EXTENSION) *ext_list;
  int i;

  /* ---------------------------------------------------------- *
   * 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 extensions                       *
   * ---------------------------------------------------------- */
  ext_list = X509_get0_extensions(cert);
  if(sk_X509_EXTENSION_num(ext_list) <= 0) return 1;

  /* ---------------------------------------------------------- *
   * Print the extension value                                  *
   * ---------------------------------------------------------- */
  for (i=0; i<sk_X509_EXTENSION_num(ext_list); i++) {
    ASN1_OBJECT *obj;
    X509_EXTENSION *ext;

    ext = sk_X509_EXTENSION_value(ext_list, i);

    obj = X509_EXTENSION_get_object(ext);
    BIO_printf(outbio, "\n");
    BIO_printf(outbio, "Object %.2d: ", i);
    i2a_ASN1_OBJECT(outbio, obj);
    BIO_printf(outbio, "\n");

    if (!X509V3_EXT_print(outbio, ext, 0, 2)) {
    /* Some extensions (i.e. LogoType) have no handling    *
     * defined, we need to print their content as hex data */
      BIO_printf(outbio, "%*s", 2, "");
      ASN1_STRING_print(certbio,(ASN1_STRING *)X509_EXTENSION_get_data(ext));
    }

    BIO_printf(outbio, "\n");
  }

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movaps 0xdbf(%rip), %xmm0      # 0x2010
leaq 0x10(%rsp), %r15
movaps %xmm0, (%r15)
movabsq $0x6d65702e656c69, %rax # imm = 0x6D65702E656C69
movq %rax, 0xd(%r15)
callq 0x1040
movq %rax, %rdi
callq 0x1110
movq %rax, %r14
movq 0x2d51(%rip), %rax      # 0x3fd0
movq (%rax), %rdi
xorl %esi, %esi
callq 0x10a0
movq %rax, %rbx
movl $0x3, %edx
movq %r14, %rdi
movl $0x6c, %esi
movq %r15, %rcx
callq 0x1030
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1120
testq %rax, %rax
je 0x12e2
movq %rax, %r15
movq %rax, %rdi
callq 0x10b0
movq %rax, %r12
movq %rax, %rdi
callq 0x1070
testl %eax, %eax
jg 0x1302
movl $0x1, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xd3c(%rip), %rsi       # 0x2025
leaq 0x10(%rsp), %rdx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x1130
movl $0x1, %edi
callq 0x10c0
movq %r15, 0x8(%rsp)
movq %r14, (%rsp)
movq %r12, %rdi
callq 0x1070
testl %eax, %eax
jle 0x13da
leaq 0xd25(%rip), %r15       # 0x2047
xorl %ebp, %ebp
movq %r12, %rdi
movl %ebp, %esi
callq 0x10d0
movq %rax, %r13
movq %rax, %rdi
callq 0x1060
movq %rax, %r14
movq %rbx, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x1130
movq %rbx, %rdi
leaq 0xcf6(%rip), %rsi       # 0x2049
movl %ebp, %edx
xorl %eax, %eax
callq 0x1130
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1090
movq %rbx, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x1130
movq %rbx, %rdi
movq %r13, %rsi
xorl %edx, %edx
movl $0x2, %ecx
callq 0x10e0
testl %eax, %eax
jne 0x13bb
movq %rbx, %rdi
leaq 0xcc3(%rip), %rsi       # 0x2057
movl $0x2, %edx
leaq 0xca8(%rip), %rcx       # 0x2048
xorl %eax, %eax
callq 0x1130
movq %r13, %rdi
callq 0x10f0
movq (%rsp), %rdi
movq %rax, %rsi
callq 0x1100
movq %rbx, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x1130
incl %ebp
movq %r12, %rdi
callq 0x1070
cmpl %eax, %ebp
jl 0x1324
movq 0x8(%rsp), %rdi
callq 0x1080
movq (%rsp), %rdi
callq 0x1050
movq %rbx, %rdi
callq 0x1050
xorl %edi, %edi
callq 0x10c0