#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_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BIO_new_mem_buf(char *, int /*<<< orphan*/);
int /*<<< orphan*/ *PEM_read_bio_X509(int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *, int /*<<< orphan*/,
                                      int /*<<< orphan*/ *);
int /*<<< orphan*/ strlen(char *);
X509 *get_certificate(char *cert) {
  BIO *bio = NULL;
  X509 *ret = NULL;
  if (cert == NULL)
    return NULL;
  if ((bio = BIO_new_mem_buf(cert, strlen(cert))) == NULL)
    return NULL;
  ret = PEM_read_bio_X509(bio, NULL, 0, NULL);
  BIO_free(bio);
  return ret;
}


x86 assembly (clang, -O0):
<get_certificate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1174 <get_certificate+0x34>
movq   $0x0,-0x8(%rbp)
jmp    11d2 <get_certificate+0x92>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%esi
call   1040 <BIO_new_mem_buf@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11ab <get_certificate+0x6b>
movq   $0x0,-0x8(%rbp)
jmp    11d2 <get_certificate+0x92>
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%ecx
xor    %edx,%edx
mov    %rcx,%rsi
call   1060 <PEM_read_bio_X509@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <BIO_free@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_certificate>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1181 <get_certificate+0x41>
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <BIO_new_mem_buf@plt>
test   %rax,%rax
je     1181 <get_certificate+0x41>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1060 <PEM_read_bio_X509@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1050 <BIO_free@plt>
mov    %r14,%rax
jmp    1183 <get_certificate+0x43>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32* @get_certificate(i8* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32*
store i8* %0, i8** %3
store i32* null, i32** %4
store i32* null, i32** %5
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %9
8: ; preds = %1
store i32* null, i32** %2
br label %22
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = load i8*, i8** %3
%12 = call i32 @strlen(i8* %11)
%13 = call i32* @BIO_new_mem_buf(i8* %10, i32 %12)
store i32* %13, i32** %4
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %16
15: ; preds = %9
store i32* null, i32** %2
br label %22
16: ; preds = %9
%17 = load i32*, i32** %4
%18 = call i32* @PEM_read_bio_X509(i32* %17, i32* null, i32 0, i32* null)
store i32* %18, i32** %5
%19 = load i32*, i32** %4
%20 = call i32 @BIO_free(i32* %19)
%21 = load i32*, i32** %5
store i32* %21, i32** %2
br label %22
22: ; preds = %16, %15, %8
%23 = load i32*, i32** %2
ret i32* %23
}

LLVM IR (-O2):
define i32* @get_certificate(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %10, label %3
3: ; preds = %1
%4 = tail call i32 @strlen(i8* %0)
%5 = tail call i32* @BIO_new_mem_buf(i8* %0, i32 %4)
%6 = icmp eq i32* %5, null
br i1 %6, label %10, label %7
7: ; preds = %3
%8 = tail call i32* @PEM_read_bio_X509(i32* %5, i32* null, i32 0, i32* null)
%9 = tail call i32 @BIO_free(i32* %5)
br label %10
10: ; preds = %3, %1, %7
%11 = phi i32* [ %8, %7 ], [ null, %1 ], [ null, %3 ]
ret i32* %11
}