#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ X509;
typedef int /*<<< orphan*/ BIO;

/* Variables and functions */
int /*<<< orphan*/ BIO_flush(int /*<<< orphan*/ *);
int /*<<< orphan*/ BIO_free_all(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BIO_new(int /*<<< orphan*/);
int /*<<< orphan*/ BIO_s_mem();
int /*<<< orphan*/ BIO_write(int /*<<< orphan*/ *, unsigned char *, int);
int /*<<< orphan*/ ERR_print_errors_fp(int /*<<< orphan*/);
int /*<<< orphan*/ PEM_read_bio_X509(int /*<<< orphan*/ *,
                                     int /*<<< orphan*/ **,
                                     int /*<<< orphan*/ *,
                                     int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
X509 *abac_load_id_from_chunk(unsigned char *chunk_ptr, int chunk_len) {
  X509 *n509 = NULL;
  BIO *mbio = BIO_new(BIO_s_mem());
  BIO_write(mbio, chunk_ptr, chunk_len);
  BIO_flush(mbio);
  PEM_read_bio_X509(mbio, &n509, NULL, NULL);
  BIO_free_all(mbio);
  if (n509 == NULL) {
    ERR_print_errors_fp(stderr);
    return NULL;
  }
  return n509;
}


x86 assembly (clang, -O0):
<abac_load_id_from_chunk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
mov    $0x0,%al
call   1080 <BIO_s_mem@plt>
mov    %eax,%edi
call   1030 <BIO_new@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1060 <BIO_write@plt>
mov    -0x28(%rbp),%rdi
call   1090 <BIO_flush@plt>
mov    -0x28(%rbp),%rdi
lea    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
call   1050 <PEM_read_bio_X509@plt>
mov    -0x28(%rbp),%rdi
call   1040 <BIO_free_all@plt>
cmpq   $0x0,-0x20(%rbp)
jne    11f5 <abac_load_id_from_chunk+0x85>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
call   1070 <ERR_print_errors_fp@plt>
movq   $0x0,-0x8(%rbp)
jmp    11fd <abac_load_id_from_chunk+0x8d>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<abac_load_id_from_chunk>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r14d
mov    %rdi,%rbx
movq   $0x0,0x8(%rsp)
xor    %eax,%eax
call   1080 <BIO_s_mem@plt>
mov    %eax,%edi
call   1030 <BIO_new@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1060 <BIO_write@plt>
mov    %rbp,%rdi
call   1090 <BIO_flush@plt>
lea    0x8(%rsp),%rsi
mov    %rbp,%rdi
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <PEM_read_bio_X509@plt>
mov    %rbp,%rdi
call   1040 <BIO_free_all@plt>
mov    0x8(%rsp),%rbx
test   %rbx,%rbx
jne    11df <abac_load_id_from_chunk+0x6f>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
call   1070 <ERR_print_errors_fp@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
define i32* @abac_load_id_from_chunk(i8* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32* null, i32** %6
%8 = call i32 (...) @BIO_s_mem()
%9 = call i32* @BIO_new(i32 %8)
store i32* %9, i32** %7
%10 = load i32*, i32** %7
%11 = load i8*, i8** %4
%12 = load i32, i32* %5
%13 = call i32 @BIO_write(i32* %10, i8* %11, i32 %12)
%14 = load i32*, i32** %7
%15 = call i32 @BIO_flush(i32* %14)
%16 = load i32*, i32** %7
%17 = call i32 @PEM_read_bio_X509(i32* %16, i32** %6, i32* null, i32* null)
%18 = load i32*, i32** %7
%19 = call i32 @BIO_free_all(i32* %18)
%20 = load i32*, i32** %6
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %25
22: ; preds = %2
%23 = load i32, i32* @stderr
%24 = call i32 @ERR_print_errors_fp(i32 %23)
store i32* null, i32** %3
br label %27
25: ; preds = %2
%26 = load i32*, i32** %6
store i32* %26, i32** %3
br label %27
27: ; preds = %25, %22
%28 = load i32*, i32** %3
ret i32* %28
}

LLVM IR (-O2):
@stderr = global i32 0
define i32* @abac_load_id_from_chunk(i8* %0, i32 %1) {
%3 = alloca i32*
%4 = bitcast i32** %3 to i8*
store i32* null, i32** %3
%5 = tail call i32 (...) @BIO_s_mem()
%6 = tail call i32* @BIO_new(i32 %5)
%7 = tail call i32 @BIO_write(i32* %6, i8* %0, i32 %1)
%8 = tail call i32 @BIO_flush(i32* %6)
%9 = call i32 @PEM_read_bio_X509(i32* %6, i32** %3, i32* null, i32* null)
%10 = call i32 @BIO_free_all(i32* %6)
%11 = load i32*, i32** %3
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 @ERR_print_errors_fp(i32 %14)
br label %16
16: ; preds = %2, %13
ret i32* %11
}