// File: /workspace/github_c_makefile_star2_O0/fm4dd[P]learn-ssl/certfprint.c
// Function: main
int main() {
  const char cert_filestr[] = "./demo/cert-file.pem";
  BIO              *certbio = NULL;
  BIO               *outbio = NULL;
  X509                *cert = NULL;
  const EVP_MD *fprint_type = NULL;
  int j;
  unsigned int fprint_size;
  unsigned char fprint[EVP_MAX_MD_SIZE];

  /* ---------------------------------------------------------- *
   * 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);
  }

  /* ---------------------------------------------------------- *
   * Set the digest method and calculate the cert fingerprint   *
   * SHA-1 creates a 160bit hash, displayed as a 20 byte string *
   * ---------------------------------------------------------- */
  fprint_type = EVP_sha1();

  if (!X509_digest(cert, fprint_type, fprint, &fprint_size))
    BIO_printf(outbio,"Error creating the certificate fingerprint.\n");

  /* ---------------------------------------------------------- *
   * Print the certificate fingerprint method, length and value *
   * ---------------------------------------------------------- */
  BIO_printf(outbio,"Fingerprint Method: %s\n", 
    OBJ_nid2sn(EVP_MD_type(fprint_type)));

  BIO_printf(outbio,"Fingerprint Length: %d\n", fprint_size);

  /* Microsoft Thumbprint-style: lowercase hex bytes with space */
  BIO_printf(outbio,"Fingerprint String: ");
  for (j=0; j<fprint_size; ++j) BIO_printf(outbio, "%02x ", fprint[j]);
  BIO_printf(outbio,"\n");

  /* OpenSSL fingerprint-style: uppercase hex bytes with colon */
  //for (j=0; j<fprint_size; j++) {
  //  BIO_printf(outbio,"%02X%c", fprint[j], (j+1 == fprint_size) ?'\n':':');
  //}

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movl $0x0, -0x4(%rbp)
movq 0xdf7(%rip), %rax       # 0x2010
movq %rax, -0x20(%rbp)
movq 0xdf4(%rip), %rax       # 0x2018
movq %rax, -0x18(%rbp)
movl 0xdf2(%rip), %eax       # 0x2020
movl %eax, -0x10(%rbp)
movb 0xded(%rip), %al        # 0x2024
movb %al, -0xc(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
callq 0x1040
movq %rax, %rdi
callq 0x10d0
movq %rax, -0x28(%rbp)
movq 0x2d5e(%rip), %rax      # 0x3fd0
movq (%rax), %rdi
xorl %esi, %esi
callq 0x1070
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 0x10e0
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
jne 0x12d4
movq -0x30(%rbp), %rdi
leaq -0x20(%rbp), %rdx
leaq 0xd62(%rip), %rsi       # 0x2025
movb $0x0, %al
callq 0x10f0
movl $0x1, %edi
callq 0x10a0
callq 0x1090
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rsi
leaq -0x90(%rbp), %rdx
leaq -0x48(%rbp), %rcx
callq 0x10b0
cmpl $0x0, %eax
jne 0x130c
movq -0x30(%rbp), %rdi
leaq 0xd44(%rip), %rsi       # 0x2049
movb $0x0, %al
callq 0x10f0
movq -0x30(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x40(%rbp), %rdi
callq 0x10c0
movl %eax, %edi
callq 0x1080
movq -0x98(%rbp), %rdi
movq %rax, %rdx
leaq 0xd3e(%rip), %rsi       # 0x2076
movb $0x0, %al
callq 0x10f0
movq -0x30(%rbp), %rdi
movl -0x48(%rbp), %edx
leaq 0xd41(%rip), %rsi       # 0x208e
movb $0x0, %al
callq 0x10f0
movq -0x30(%rbp), %rdi
leaq 0xd47(%rip), %rsi       # 0x20a6
movb $0x0, %al
callq 0x10f0
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x48(%rbp), %eax
jae 0x139e
movq -0x30(%rbp), %rdi
movslq -0x44(%rbp), %rax
movzbl -0x90(%rbp,%rax), %edx
leaq 0xd2f(%rip), %rsi       # 0x20bb
movb $0x0, %al
callq 0x10f0
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x136d
movq -0x30(%rbp), %rdi
leaq 0xccb(%rip), %rsi       # 0x2074
movb $0x0, %al
callq 0x10f0
movq -0x38(%rbp), %rdi
callq 0x1060
movq -0x28(%rbp), %rdi
callq 0x1050
movq -0x30(%rbp), %rdi
callq 0x1050
xorl %edi, %edi
callq 0x10a0