// File: /workspace/github_c_makefile_star2_O0/fm4dd[P]learn-ssl/certverify-adv.c
// Function: verify_mem_stack
X509_STORE_CTX  *verify_mem_stack(STACK_OF(X509_INFO) *st) {
  X509_STORE_CTX       *ctx = NULL;
  STACK_OF(X509)  *ca_stack = NULL;
  X509_INFO      *list_item = NULL;
  int cert_count            = 0;
  int i                     = 0;

  /* ---------------------------------------------------------- *
   * Get the number of certs on the stack                       *
   * ---------------------------------------------------------- */
  cert_count = sk_X509_INFO_num(st);

  /* ---------------------------------------------------------- *
   * Complain if there is no cert                               *
   * ---------------------------------------------------------- */
  if (! (cert_count > 0)) {
    BIO_printf(outbio, "Error no certs on stack.\n");
    exit(1);
  }

  /* ---------------------------------------------------------- *
   * Initialize the X509 stack ca_stack                         *
   * ---------------------------------------------------------- */
  ca_stack = sk_X509_new_null();

  /* ---------------------------------------------------------- *
   * Cycle through all info stack items, extract the X509 cert  *
   * and put it on the X509 stack.                              *
   * ---------------------------------------------------------- */
  for (i = 0; i < cert_count; i++) {
    list_item = sk_X509_INFO_value(st, i);
    sk_X509_push(ca_stack, list_item->x509);
  }

  /* ---------------------------------------------------------- *
   * Create the context structure for the validation operation. *
   * ---------------------------------------------------------- */
  ctx = X509_STORE_CTX_new();

  /* ---------------------------------------------------------- *
   * Initialize the ctx structure for a verification operation: *
   * Set the trusted cert store, the unvalidated cert, and any  *
   * potential certs that could be needed (here we set it NULL) *
   * ---------------------------------------------------------- */
  X509_STORE_CTX_init(ctx, NULL, cert, NULL);

  /* ---------------------------------------------------------- *
   * Add the list of CA certs to the ctx verification structure *
   * ---------------------------------------------------------- */
  X509_STORE_CTX_trusted_stack(ctx, ca_stack);

  return ctx;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq $0x0, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movq -0x8(%rbp), %rdi
callq 0x2e70
movq %rax, %rdi
callq 0x20a0
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jg 0x2eeb
movq 0x37fd(%rip), %rdi      # 0x66d0
leaq 0xee9(%rip), %rsi       # 0x3dc3
movb $0x0, %al
callq 0x22b0
movl $0x1, %edi
callq 0x21c0
callq 0x2290
movq %rax, -0x18(%rbp)
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x2f4b
movq -0x8(%rbp), %rdi
callq 0x2e70
movq %rax, %rdi
movl -0x28(%rbp), %esi
callq 0x21e0
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
callq 0x2f90
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rdi
callq 0x2fa0
movq -0x30(%rbp), %rdi
movq %rax, %rsi
callq 0x2150
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x2efb
callq 0x2160
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
movq 0x3781(%rip), %rdx      # 0x66e0
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rsi
callq 0x20d0
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x20f0
movq -0x10(%rbp), %rax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)