#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_new(int /*<<< orphan*/);
int /*<<< orphan*/ BIO_s_mem();
int /*<<< orphan*/ BIO_write(int /*<<< orphan*/ *, void const *, unsigned int);
int /*<<< orphan*/ *PEM_read_bio_X509(int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *, int /*<<< orphan*/,
                                      int /*<<< orphan*/ *);
int /*<<< orphan*/ X509_print_fp(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ stdout;
int print_x509_cert(const unsigned char *data, unsigned length) {
  BIO *bio;
  X509 *certificate = NULL;
  bio = BIO_new(BIO_s_mem());
  BIO_write(bio, (const void *)data, length);
  certificate = PEM_read_bio_X509(bio, NULL, 0, NULL);
  if (certificate != NULL) {
    X509_print_fp(stdout, certificate);
    return 1;
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<print_x509_cert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movq   $0x0,-0x28(%rbp)
mov    $0x0,%al
call   1070 <BIO_s_mem@plt>
mov    %eax,%edi
call   1040 <BIO_new@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1060 <BIO_write@plt>
mov    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%ecx
xor    %edx,%edx
mov    %rcx,%rsi
call   1050 <PEM_read_bio_X509@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11c8 <print_x509_cert+0x78>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rsi
call   1030 <X509_print_fp@plt>
movl   $0x1,-0x4(%rbp)
jmp    11cf <print_x509_cert+0x7f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_x509_cert>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%rbx
xor    %r14d,%r14d
xor    %eax,%eax
call   1070 <BIO_s_mem@plt>
mov    %eax,%edi
call   1040 <BIO_new@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1060 <BIO_write@plt>
mov    %rbp,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <PEM_read_bio_X509@plt>
test   %rax,%rax
je     11a9 <print_x509_cert+0x59>
mov    0x2e47(%rip),%rcx
mov    (%rcx),%edi
mov    %rax,%rsi
call   1030 <X509_print_fp@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
define i32 @print_x509_cert(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** %7
%8 = call i32 (...) @BIO_s_mem()
%9 = call i32* @BIO_new(i32 %8)
store i32* %9, i32** %6
%10 = load i32*, i32** %6
%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** %6
%15 = call i32* @PEM_read_bio_X509(i32* %14, i32* null, i32 0, i32* null)
store i32* %15, i32** %7
%16 = load i32*, i32** %7
%17 = icmp ne i32* %16, null
br i1 %17, label %18, label %22
18: ; preds = %2
%19 = load i32, i32* @stdout
%20 = load i32*, i32** %7
%21 = call i32 @X509_print_fp(i32 %19, i32* %20)
store i32 1, i32* %3
br label %23
22: ; preds = %2
store i32 0, i32* %3
br label %23
23: ; preds = %22, %18
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
@stdout = global i32 0
define i32 @print_x509_cert(i8* %0, i32 %1) {
%3 = tail call i32 (...) @BIO_s_mem()
%4 = tail call i32* @BIO_new(i32 %3)
%5 = tail call i32 @BIO_write(i32* %4, i8* %0, i32 %1)
%6 = tail call i32* @PEM_read_bio_X509(i32* %4, i32* null, i32 0, i32* null)
%7 = icmp eq i32* %6, null
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load i32, i32* @stdout
%10 = tail call i32 @X509_print_fp(i32 %9, i32* %6)
br label %11
11: ; preds = %2, %8
%12 = phi i32 [ 1, %8 ], [ 0, %2 ]
ret i32 %12
}