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

  /* ---------------------------------------------------------- *
   * Initialize the global certificate validation store object. *
   * ---------------------------------------------------------- */
  if (!(store=X509_STORE_new()))
     BIO_printf(outbio, "Error creating X509_STORE_CTX object\n");

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

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

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

  /* ---------------------------------------------------------- *
   * 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, store, cert, NULL);

  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)
callq 0x21b0
movq %rax, -0x10(%rbp)
cmpq $0x0, %rax
jne 0x2af6
movq 0x3be8(%rip), %rdi      # 0x66d0
leaq 0x11ba(%rip), %rsi      # 0x3ca9
movb $0x0, %al
callq 0x22b0
callq 0x2160
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
callq 0x2e70
movq %rax, %rdi
callq 0x20a0
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jg 0x2b38
movq 0x3bb0(%rip), %rdi      # 0x66d0
leaq 0x129c(%rip), %rsi      # 0x3dc3
movb $0x0, %al
callq 0x22b0
movl $0x1, %edi
callq 0x21c0
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x2b7a
movq -0x8(%rbp), %rdi
callq 0x2e70
movq %rax, %rdi
movl -0x28(%rbp), %esi
callq 0x21e0
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rax
movq (%rax), %rsi
callq 0x20c0
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x2b3f
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq 0x3b57(%rip), %rdx      # 0x66e0
xorl %eax, %eax
movl %eax, %ecx
callq 0x20d0
movq -0x18(%rbp), %rax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)