// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1008, %rsp           # imm = 0x1008
movq %rsi, %r12
movl %edi, %ebx
movq %rsp, %r13
movl $0x1000, %edx           # imm = 0x1000
movq %r13, %rdi
xorl %esi, %esi
callq 0x20b0
movq %r12, %rdi
callq 0x2250
movq %rax, %r14
movq %r12, %rdi
callq 0x2130
movl %eax, %r15d
movq %r12, %rdi
callq 0x2100
movl %eax, %ebp
movq %r14, %rdi
callq 0x21a0
movq %rax, %rdi
movq %r13, %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x2120
leaq 0xa84(%rip), %rdi       # 0x3491
movl %ebp, %esi
movq %r13, %rdx
xorl %eax, %eax
callq 0x2030
movq 0x2cc8(%rip), %rdi      # 0x56e8
callq 0x2230
cmpl %eax, %ebp
jle 0x2a64
movl $0x16, %ebx
movq %r12, %rdi
movl $0x16, %esi
callq 0x2210
movl $0x16, %edi
callq 0x2110
leaq 0xa6b(%rip), %rdi       # 0x34b7
movl $0x16, %esi
movq %rax, %rdx
xorl %eax, %eax
callq 0x2030
leaq 0xa78(%rip), %rdi       # 0x34da
jmp 0x2a6f
testl %ebx, %ebx
je 0x2a8c
leaq 0xb54(%rip), %rdi       # 0x35c3
movl %ebp, %esi
xorl %eax, %eax
callq 0x2030
movl %ebx, %eax
addq $0x1008, %rsp           # imm = 0x1008
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x2c3d(%rip), %rdi      # 0x56d0
leaq 0xa40(%rip), %rsi       # 0x34da
xorl %ebx, %ebx
movl %ebp, %edx
xorl %eax, %eax
callq 0x22b0
movq 0x2c24(%rip), %r12      # 0x56d0
movslq %r15d, %r13
movq %r13, %rdi
callq 0x2110
leaq 0xa43(%rip), %rsi       # 0x3501
movq %r12, %rdi
movl %ebp, %edx
movq %rax, %rcx
movl %r15d, %r8d
xorl %eax, %eax
callq 0x22b0
cmpl $0x14, %r13d
jne 0x2a78
callq 0x2170
movq %r14, %rdi
callq 0x2190
movq %rax, %r14
movq 0x2be3(%rip), %rdi      # 0x56d0
leaq 0xa41(%rip), %rsi       # 0x3535
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x22b0
movq 0x2bcc(%rip), %rdi      # 0x56d0
movl $0x2a40006, %ecx        # imm = 0x2A40006
movq %r14, %rsi
xorl %edx, %edx
callq 0x2040
movq 0x2bb6(%rip), %rdi      # 0x56d0
leaq 0xa5b(%rip), %rsi       # 0x357c
xorl %eax, %eax
callq 0x22b0
jmp 0x2a78