#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_mem_buf(char const *, int);
int /*<<< orphan*/ *PEM_read_bio_X509(int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *, int /*<<< orphan*/,
                                      int /*<<< orphan*/ *);
int PICA_id_from_X509(int /*<<< orphan*/ *, unsigned char *);
int PICA_get_id_from_cert_string(const char *cert_pem, unsigned char *id) {
  X509 *x;
  BIO *biomem;
  biomem = BIO_new_mem_buf(cert_pem, -1);
  x = PEM_read_bio_X509(biomem, NULL, 0, NULL);
  if (!x) {
    return 0;
  }
  return PICA_id_from_X509(x, id);
}


x86 assembly (clang, -O0):
<PICA_get_id_from_cert_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0xffffffff,%esi
call   1040 <BIO_new_mem_buf@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%ecx
xor    %edx,%edx
mov    %rcx,%rsi
call   1050 <PEM_read_bio_X509@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    117f <PICA_get_id_from_cert_string+0x4f>
movl   $0x0,-0x4(%rbp)
jmp    118f <PICA_get_id_from_cert_string+0x5f>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <PICA_id_from_X509@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PICA_get_id_from_cert_string>:
push   %rbx
mov    %rsi,%rbx
mov    $0xffffffff,%esi
call   1040 <BIO_new_mem_buf@plt>
mov    %rax,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <PEM_read_bio_X509@plt>
test   %rax,%rax
je     115d <PICA_get_id_from_cert_string+0x2d>
mov    %rax,%rdi
mov    %rbx,%rsi
pop    %rbx
jmp    1030 <PICA_id_from_X509@plt>
xor    %eax,%eax
pop    %rbx
ret

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

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