#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*/ EVP_PKEY;
typedef int /*<<< orphan*/ CTLOG;

/* Variables and functions */
int /*<<< orphan*/ *CTLOG_new(int /*<<< orphan*/ *, char const *);
int /*<<< orphan*/ CT_F_CTLOG_NEW_FROM_BASE64;
int /*<<< orphan*/ CT_R_LOG_CONF_INVALID_KEY;
int /*<<< orphan*/ CTerr(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ ERR_R_PASSED_INVALID_ARGUMENT;
int /*<<< orphan*/ EVP_PKEY_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ OPENSSL_free(unsigned char *);
int ct_base64_decode(char const *, unsigned char **);
int /*<<< orphan*/ *d2i_PUBKEY(int /*<<< orphan*/ *, unsigned char const **,
                               int);
int CTLOG_new_from_base64(CTLOG **ct_log, const char *pkey_base64,
                          const char *name) {
  unsigned char *pkey_der = NULL;
  int pkey_der_len;
  const unsigned char *p;
  EVP_PKEY *pkey = NULL;
  if (ct_log == NULL) {
    CTerr(CT_F_CTLOG_NEW_FROM_BASE64, ERR_R_PASSED_INVALID_ARGUMENT);
    return 0;
  }
  pkey_der_len = ct_base64_decode(pkey_base64, &pkey_der);
  if (pkey_der_len < 0) {
    CTerr(CT_F_CTLOG_NEW_FROM_BASE64, CT_R_LOG_CONF_INVALID_KEY);
    return 0;
  }
  p = pkey_der;
  pkey = d2i_PUBKEY(NULL, &p, pkey_der_len);
  OPENSSL_free(pkey_der);
  if (pkey == NULL) {
    CTerr(CT_F_CTLOG_NEW_FROM_BASE64, CT_R_LOG_CONF_INVALID_KEY);
    return 0;
  }
  *ct_log = CTLOG_new(pkey, name);
  if (*ct_log == NULL) {
    EVP_PKEY_free(pkey);
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<CTLOG_new_from_base64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x40(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b2 <CTLOG_new_from_base64+0x52>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
call   1050 <CTerr@plt>
movl   $0x0,-0x4(%rbp)
jmp    1283 <CTLOG_new_from_base64+0x123>
mov    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1060 <ct_base64_decode@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    11ef <CTLOG_new_from_base64+0x8f>
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
mov    0x2e1c(%rip),%rax
mov    (%rax),%esi
call   1050 <CTerr@plt>
movl   $0x0,-0x4(%rbp)
jmp    1283 <CTLOG_new_from_base64+0x123>
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x2c(%rbp),%edx
xor    %eax,%eax
mov    %eax,%edi
lea    -0x38(%rbp),%rsi
call   1040 <d2i_PUBKEY@plt>
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
call   1080 <OPENSSL_free@plt>
cmpq   $0x0,-0x40(%rbp)
jne    1242 <CTLOG_new_from_base64+0xe2>
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
mov    0x2dc9(%rip),%rax
mov    (%rax),%esi
call   1050 <CTerr@plt>
movl   $0x0,-0x4(%rbp)
jmp    1283 <CTLOG_new_from_base64+0x123>
mov    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <CTLOG_new@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    127c <CTLOG_new_from_base64+0x11c>
mov    -0x40(%rbp),%rdi
call   1030 <EVP_PKEY_free@plt>
movl   $0x0,-0x4(%rbp)
jmp    1283 <CTLOG_new_from_base64+0x123>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CTLOG_new_from_base64>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
movq   $0x0,0x8(%rsp)
test   %rdi,%rdi
je     11e1 <CTLOG_new_from_base64+0x81>
mov    %rdx,%r14
mov    %rdi,%r15
lea    0x8(%rsp),%rax
mov    %rsi,%rdi
mov    %rax,%rsi
call   1060 <ct_base64_decode@plt>
test   %eax,%eax
js     11f3 <CTLOG_new_from_base64+0x93>
mov    0x8(%rsp),%rcx
mov    %rcx,0x10(%rsp)
xor    %ebx,%ebx
lea    0x10(%rsp),%rsi
xor    %edi,%edi
mov    %eax,%edx
call   1040 <d2i_PUBKEY@plt>
mov    %rax,%r12
mov    0x8(%rsp),%rdi
call   1080 <OPENSSL_free@plt>
test   %r12,%r12
je     121a <CTLOG_new_from_base64+0xba>
mov    %r12,%rdi
mov    %r14,%rsi
call   1070 <CTLOG_new@plt>
mov    %rax,(%r15)
mov    $0x1,%ebx
test   %rax,%rax
jne    120c <CTLOG_new_from_base64+0xac>
mov    %r12,%rdi
call   1030 <EVP_PKEY_free@plt>
jmp    120a <CTLOG_new_from_base64+0xaa>
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
mov    0x2de7(%rip),%rax
jmp    1203 <CTLOG_new_from_base64+0xa3>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
mov    0x2df5(%rip),%rax
mov    (%rax),%esi
call   1050 <CTerr@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
mov    0x2dce(%rip),%rax
mov    (%rax),%esi
call   1050 <CTerr@plt>
jmp    120c <CTLOG_new_from_base64+0xac>

LLVM IR (-O0):
@CT_F_CTLOG_NEW_FROM_BASE64 = global i32 0
@ERR_R_PASSED_INVALID_ARGUMENT = global i32 0
@CT_R_LOG_CONF_INVALID_KEY = global i32 0
define i32 @CTLOG_new_from_base64(i32** %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32*
store i32** %0, i32*** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i8* null, i8** %8
store i32* null, i32** %11
%12 = load i32**, i32*** %5
%13 = icmp eq i32** %12, null
br i1 %13, label %14, label %18
14: ; preds = %3
%15 = load i32, i32* @CT_F_CTLOG_NEW_FROM_BASE64
%16 = load i32, i32* @ERR_R_PASSED_INVALID_ARGUMENT
%17 = call i32 @CTerr(i32 %15, i32 %16)
store i32 0, i32* %4
br label %51
18: ; preds = %3
%19 = load i8*, i8** %6
%20 = call i32 @ct_base64_decode(i8* %19, i8** %8)
store i32 %20, i32* %9
%21 = load i32, i32* %9
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %18
%24 = load i32, i32* @CT_F_CTLOG_NEW_FROM_BASE64
%25 = load i32, i32* @CT_R_LOG_CONF_INVALID_KEY
%26 = call i32 @CTerr(i32 %24, i32 %25)
store i32 0, i32* %4
br label %51
27: ; preds = %18
%28 = load i8*, i8** %8
store i8* %28, i8** %10
%29 = load i32, i32* %9
%30 = call i32* @d2i_PUBKEY(i32* null, i8** %10, i32 %29)
store i32* %30, i32** %11
%31 = load i8*, i8** %8
%32 = call i32 @OPENSSL_free(i8* %31)
%33 = load i32*, i32** %11
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %39
35: ; preds = %27
%36 = load i32, i32* @CT_F_CTLOG_NEW_FROM_BASE64
%37 = load i32, i32* @CT_R_LOG_CONF_INVALID_KEY
%38 = call i32 @CTerr(i32 %36, i32 %37)
store i32 0, i32* %4
br label %51
39: ; preds = %27
%40 = load i32*, i32** %11
%41 = load i8*, i8** %7
%42 = call i32* @CTLOG_new(i32* %40, i8* %41)
%43 = load i32**, i32*** %5
store i32* %42, i32** %43
%44 = load i32**, i32*** %5
%45 = load i32*, i32** %44
%46 = icmp eq i32* %45, null
br i1 %46, label %47, label %50
47: ; preds = %39
%48 = load i32*, i32** %11
%49 = call i32 @EVP_PKEY_free(i32* %48)
store i32 0, i32* %4
br label %51
50: ; preds = %39
store i32 1, i32* %4
br label %51
51: ; preds = %50, %47, %35, %23, %14
%52 = load i32, i32* %4
ret i32 %52
}

LLVM IR (-O2):
@CT_F_CTLOG_NEW_FROM_BASE64 = global i32 0
@ERR_R_PASSED_INVALID_ARGUMENT = global i32 0
@CT_R_LOG_CONF_INVALID_KEY = global i32 0
define i32 @CTLOG_new_from_base64(i32** writeonly %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%7 = bitcast i8** %5 to i8*
%8 = icmp eq i32** %0, null
br i1 %8, label %9, label %13
9: ; preds = %3
%10 = load i32, i32* @CT_F_CTLOG_NEW_FROM_BASE64
%11 = load i32, i32* @ERR_R_PASSED_INVALID_ARGUMENT
%12 = tail call i32 @CTerr(i32 %10, i32 %11)
br label %35
13: ; preds = %3
%14 = call i32 @ct_base64_decode(i8* %1, i8** %4)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = load i32, i32* @CT_F_CTLOG_NEW_FROM_BASE64
%18 = load i32, i32* @CT_R_LOG_CONF_INVALID_KEY
%19 = call i32 @CTerr(i32 %17, i32 %18)
br label %35
20: ; preds = %13
%21 = load i8*, i8** %4
store i8* %21, i8** %5
%22 = call i32* @d2i_PUBKEY(i32* null, i8** %5, i32 %14)
%23 = load i8*, i8** %4
%24 = call i32 @OPENSSL_free(i8* %23)
%25 = icmp eq i32* %22, null
br i1 %25, label %26, label %30
26: ; preds = %20
%27 = load i32, i32* @CT_F_CTLOG_NEW_FROM_BASE64
%28 = load i32, i32* @CT_R_LOG_CONF_INVALID_KEY
%29 = call i32 @CTerr(i32 %27, i32 %28)
br label %35
30: ; preds = %20
%31 = call i32* @CTLOG_new(i32* %22, i8* %2)
store i32* %31, i32** %0
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = call i32 @EVP_PKEY_free(i32* %22)
br label %35
35: ; preds = %30, %33, %26, %16, %9
%36 = phi i32 [ 0, %9 ], [ 0, %16 ], [ 0, %26 ], [ 0, %33 ], [ 1, %30 ]
ret i32 %36
}