// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x6c
popq %rsi
pushq $0x3
popq %rdx
movq %r14, %rdi
movq %r15, %rcx
callq 0x1030
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1120
testq %rax, %rax
je 0x12dc
movq %rax, %r15
movq %rax, %rdi
callq 0x10b0
movq %rax, %r12
movq %rax, %rdi
callq 0x1070
testl %eax, %eax
jg 0x12fa
pushq $0x1
popq %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xd42(%rip), %rsi       # 0x2025
leaq 0x10(%rsp), %rdx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x1130
pushq $0x1
popq %rdi
callq 0x10c0
movq %r15, 0x8(%rsp)
movq %r14, (%rsp)
leaq 0xd3d(%rip), %r14       # 0x2047
xorl %ebp, %ebp
movq %r12, %rdi
callq 0x1070
cmpl %eax, %ebp
jge 0x13c3
movq %r12, %rdi
movl %ebp, %esi
callq 0x10d0
movq %rax, %r13
movq %rax, %rdi
callq 0x1060
movq %rax, %r15
movq %rbx, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x1130
movq %rbx, %rdi
leaq 0xcfe(%rip), %rsi       # 0x2049
movl %ebp, %edx
xorl %eax, %eax
callq 0x1130
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1090
movq %rbx, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x1130
movq %rbx, %rdi
movq %r13, %rsi
xorl %edx, %edx
pushq $0x2
popq %rcx
callq 0x10e0
testl %eax, %eax
jne 0x13af
movq %rbx, %rdi
leaq 0xccd(%rip), %rsi       # 0x2057
pushq $0x2
popq %rdx
leaq 0xcb4(%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 %r14, %rsi
xorl %eax, %eax
callq 0x1130
incl %ebp
jmp 0x130c
movq 0x8(%rsp), %rdi
callq 0x1080
movq (%rsp), %rdi
callq 0x1050
movq %rbx, %rdi
callq 0x1050
xorl %edi, %edi
callq 0x10c0