// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x70, %rsp
movl $0x0, -0x4(%rbp)
movq 0xdba(%rip), %rax       # 0x2010
movq %rax, -0x20(%rbp)
movq 0xdb7(%rip), %rax       # 0x2018
movq %rax, -0x18(%rbp)
movl 0xdb5(%rip), %eax       # 0x2020
movl %eax, -0x10(%rbp)
movb 0xdb0(%rip), %al        # 0x2024
movb %al, -0xc(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
callq 0x1040
movq %rax, %rdi
callq 0x1110
movq %rax, -0x28(%rbp)
movq 0x2d29(%rip), %rax      # 0x3fd0
movq (%rax), %rdi
xorl %esi, %esi
callq 0x10a0
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rdi
leaq -0x20(%rbp), %rcx
movl $0x6c, %esi
movl $0x3, %edx
callq 0x1030
movq -0x28(%rbp), %rdi
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rsi
movq %rcx, %rdx
callq 0x1120
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
jne 0x1309
movq -0x30(%rbp), %rdi
leaq -0x20(%rbp), %rdx
leaq 0xd2d(%rip), %rsi       # 0x2025
movb $0x0, %al
callq 0x1130
movl $0x1, %edi
callq 0x10c0
movq -0x38(%rbp), %rdi
callq 0x10b0
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
callq 0x1470
movq %rax, %rdi
callq 0x1070
cmpl $0x0, %eax
jg 0x1337
movl $0x1, %eax
addq $0x70, %rsp
popq %rbp
retq
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0x5c(%rbp)
movq -0x40(%rbp), %rdi
callq 0x1470
movq %rax, %rdi
callq 0x1070
movl %eax, %ecx
movl -0x5c(%rbp), %eax
cmpl %ecx, %eax
jge 0x1443
movq -0x40(%rbp), %rdi
callq 0x1470
movq %rax, %rdi
movl -0x44(%rbp), %esi
callq 0x10d0
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
callq 0x1060
movq %rax, -0x50(%rbp)
movq -0x30(%rbp), %rdi
leaq 0xcb5(%rip), %rsi       # 0x2047
movb $0x0, %al
callq 0x1130
movq -0x30(%rbp), %rdi
movl -0x44(%rbp), %edx
leaq 0xca2(%rip), %rsi       # 0x2049
movb $0x0, %al
callq 0x1130
movq -0x30(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x1090
movq -0x30(%rbp), %rdi
leaq 0xc81(%rip), %rsi       # 0x2047
movb $0x0, %al
callq 0x1130
movq -0x30(%rbp), %rdi
movq -0x58(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
movl $0x2, %ecx
callq 0x10e0
cmpl $0x0, %eax
jne 0x1423
movq -0x30(%rbp), %rdi
leaq 0xc64(%rip), %rsi       # 0x2057
movl $0x2, %edx
leaq 0xc49(%rip), %rcx       # 0x2048
movb $0x0, %al
callq 0x1130
movq -0x28(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x58(%rbp), %rdi
callq 0x10f0
movq -0x68(%rbp), %rdi
movq %rax, %rsi
callq 0x1100
movq -0x30(%rbp), %rdi
leaq 0xc19(%rip), %rsi       # 0x2047
movb $0x0, %al
callq 0x1130
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x133e
movq -0x38(%rbp), %rdi
callq 0x1080
movq -0x28(%rbp), %rdi
callq 0x1050
movq -0x30(%rbp), %rdi
callq 0x1050
xorl %edi, %edi
callq 0x10c0
nopw %cs:(%rax,%rax)