// File: /workspace/github_c_makefile_star2_O0/fm4dd[P]learn-ssl/certverify-adv.c
// Function: verify_callback
static int verify_callback(int preverify_ok, X509_STORE_CTX *ctx) {
  X509_NAME    *certissuer = NULL;
  char    buf[4096] = "";
  X509   *err_cert;
  int     err, depth;

  err_cert = X509_STORE_CTX_get_current_cert(ctx);
  err = X509_STORE_CTX_get_error(ctx);
  depth = X509_STORE_CTX_get_error_depth(ctx);

  /* ---------------------------------------------------------- *
   * Show the subject info at certification depth level         *
   * ---------------------------------------------------------- */
  X509_NAME_oneline(X509_get_subject_name(err_cert), buf, 256);
  printf("Verification check depth: %d - %.49s\n", depth, buf);

  /* ---------------------------------------------------------- *
   * Catch a too long certificate chain. The depth limit with   *
   * SSL_CTX_set_verify_depth() is on purpose set to "limit+1". *
   * ---------------------------------------------------------- */
  if (depth > X509_VERIFY_PARAM_get_depth(param)) {
      preverify_ok = 0;
      err = X509_V_ERR_CERT_CHAIN_TOO_LONG;
      X509_STORE_CTX_set_error(ctx, err);
      printf("Verification fail detail: %d - %s\n", err, X509_verify_cert_error_string(err)); 
      printf("Verification result text: %d - FAILED\n", depth);
      return err;
  }

  if (!preverify_ok) {
      BIO_printf(outbio, "Verification result text: %d - FAILED\n", depth);
      BIO_printf(outbio, "Verification fail reason: %d - %s [error code: %d]\n", depth, X509_verify_cert_error_string(err), err); 
  }

  /* ---------------------------------------------------------- *
   * At this point, err contains the last verification error.   *
   * We can use it for something special                        *
   * ---------------------------------------------------------- */
  if (!preverify_ok && (err == X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY)) {
      certissuer = X509_NAME_new();
      certissuer = X509_get_issuer_name(err_cert);
      BIO_printf(outbio, "\nVerification fail issuer: ---------------start----------------------\n");
      X509_NAME_print_ex(outbio, certissuer, 0, XN_FLAG_MULTILINE);
      BIO_printf(outbio, "\nVerification fail issuer: ----------------End-----------------------\n");
  }

  if (preverify_ok) printf("Verification result text: %d - PASSED\n", depth);
  return preverify_ok;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1050, %rsp           # imm = 0x1050
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
leaq -0x1020(%rbp), %rdi
xorl %esi, %esi
movl $0x1000, %edx           # imm = 0x1000
callq 0x20b0
movq -0x10(%rbp), %rdi
callq 0x2250
movq %rax, -0x1028(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2130
movl %eax, -0x102c(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2100
movl %eax, -0x1030(%rbp)
movq -0x1028(%rbp), %rdi
callq 0x21a0
movq %rax, %rdi
leaq -0x1020(%rbp), %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x2120
movl -0x1030(%rbp), %esi
leaq -0x1020(%rbp), %rdx
leaq 0x11ae(%rip), %rdi      # 0x3ddd
movb $0x0, %al
callq 0x2030
movl -0x1030(%rbp), %eax
movl %eax, -0x1034(%rbp)
movq 0x3a9f(%rip), %rdi      # 0x66e8
callq 0x2230
movl %eax, %ecx
movl -0x1034(%rbp), %eax
cmpl %ecx, %eax
jle 0x2ccb
movl $0x0, -0x8(%rbp)
movl $0x16, -0x102c(%rbp)
movq -0x10(%rbp), %rdi
movl -0x102c(%rbp), %esi
callq 0x2210
movl -0x102c(%rbp), %eax
movl %eax, -0x1038(%rbp)
movslq -0x102c(%rbp), %rdi
callq 0x2110
movl -0x1038(%rbp), %esi
movq %rax, %rdx
leaq 0x1161(%rip), %rdi      # 0x3e03
movb $0x0, %al
callq 0x2030
movl -0x1030(%rbp), %esi
leaq 0x1170(%rip), %rdi      # 0x3e26
movb $0x0, %al
callq 0x2030
movl -0x102c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x2dc0
cmpl $0x0, -0x8(%rbp)
jne 0x2d37
movq 0x39f8(%rip), %rdi      # 0x66d0
movl -0x1030(%rbp), %edx
leaq 0x1141(%rip), %rsi      # 0x3e26
movb $0x0, %al
callq 0x22b0
movq 0x39dd(%rip), %rax      # 0x66d0
movq %rax, -0x1048(%rbp)
movl -0x1030(%rbp), %eax
movl %eax, -0x103c(%rbp)
movslq -0x102c(%rbp), %rdi
callq 0x2110
movq -0x1048(%rbp), %rdi
movl -0x103c(%rbp), %edx
movq %rax, %rcx
movl -0x102c(%rbp), %r8d
leaq 0x111d(%rip), %rsi      # 0x3e4d
movb $0x0, %al
callq 0x22b0
cmpl $0x0, -0x8(%rbp)
jne 0x2da0
cmpl $0x14, -0x102c(%rbp)
jne 0x2da0
callq 0x2170
movq %rax, -0x18(%rbp)
movq -0x1028(%rbp), %rdi
callq 0x2190
movq %rax, -0x18(%rbp)
movq 0x396a(%rip), %rdi      # 0x66d0
leaq 0x1114(%rip), %rsi      # 0x3e81
movb $0x0, %al
callq 0x22b0
movq 0x3955(%rip), %rdi      # 0x66d0
movq -0x18(%rbp), %rsi
xorl %edx, %edx
movl $0x2a40006, %ecx        # imm = 0x2A40006
callq 0x2040
movq 0x393e(%rip), %rdi      # 0x66d0
leaq 0x112f(%rip), %rsi      # 0x3ec8
movb $0x0, %al
callq 0x22b0
cmpl $0x0, -0x8(%rbp)
je 0x2dba
movl -0x1030(%rbp), %esi
leaq 0x115c(%rip), %rdi      # 0x3f0f
movb $0x0, %al
callq 0x2030
movl -0x8(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x1050, %rsp           # imm = 0x1050
popq %rbp
retq
nopl (%rax)