#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*/ NETSCAPE_SPKI;

/* Variables and functions */
int /*<<< orphan*/ ERR_R_MALLOC_FAILURE;
int EVP_DecodeBlock(unsigned char *, unsigned char const *, int);
int /*<<< orphan*/ X509_F_NETSCAPE_SPKI_B64_DECODE;
int /*<<< orphan*/ X509_R_BASE64_DECODE_ERROR;
int /*<<< orphan*/ X509err(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ *d2i_NETSCAPE_SPKI(int /*<<< orphan*/ *,
                                      unsigned char const **, int);
int /*<<< orphan*/ free(unsigned char *);
unsigned char *malloc(int);
int strlen(char const *);
NETSCAPE_SPKI *NETSCAPE_SPKI_b64_decode(const char *str, int len) {
  unsigned char *spki_der;
  const unsigned char *p;
  int spki_len;
  NETSCAPE_SPKI *spki;
  if (len <= 0)
    len = strlen(str);
  if (!(spki_der = malloc(len + 1))) {
    X509err(X509_F_NETSCAPE_SPKI_B64_DECODE, ERR_R_MALLOC_FAILURE);
    return NULL;
  }
  spki_len = EVP_DecodeBlock(spki_der, (const unsigned char *)str, len);
  if (spki_len < 0) {
    X509err(X509_F_NETSCAPE_SPKI_B64_DECODE, X509_R_BASE64_DECODE_ERROR);
    free(spki_der);
    return NULL;
  }
  p = spki_der;
  spki = d2i_NETSCAPE_SPKI(NULL, &p, spki_len);
  free(spki_der);
  return spki;
}


x86 assembly (clang, -O0):
<NETSCAPE_SPKI_b64_decode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jg     1185 <NETSCAPE_SPKI_b64_decode+0x25>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
add    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11c2 <NETSCAPE_SPKI_b64_decode+0x62>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
call   1080 <X509err@plt>
movq   $0x0,-0x8(%rbp)
jmp    1239 <NETSCAPE_SPKI_b64_decode+0xd9>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <EVP_DecodeBlock@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    120c <NETSCAPE_SPKI_b64_decode+0xac>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
mov    0x2df9(%rip),%rax
mov    (%rax),%esi
call   1080 <X509err@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1239 <NETSCAPE_SPKI_b64_decode+0xd9>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x2c(%rbp),%edx
xor    %eax,%eax
mov    %eax,%edi
lea    -0x28(%rbp),%rsi
call   1060 <d2i_NETSCAPE_SPKI@plt>
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<NETSCAPE_SPKI_b64_decode>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
mov    %rdi,%r14
test   %esi,%esi
jg     117c <NETSCAPE_SPKI_b64_decode+0x1c>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
lea    0x1(%rbx),%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     11bd <NETSCAPE_SPKI_b64_decode+0x5d>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1040 <EVP_DecodeBlock@plt>
test   %eax,%eax
js     11d6 <NETSCAPE_SPKI_b64_decode+0x76>
mov    %r15,0x8(%rsp)
lea    0x8(%rsp),%rsi
xor    %edi,%edi
mov    %eax,%edx
call   1060 <d2i_NETSCAPE_SPKI@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1030 <free@plt>
jmp    11f7 <NETSCAPE_SPKI_b64_decode+0x97>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
mov    0x2e13(%rip),%rax
mov    (%rax),%esi
call   1080 <X509err@plt>
jmp    11f5 <NETSCAPE_SPKI_b64_decode+0x95>
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
mov    0x2e02(%rip),%rax
mov    (%rax),%esi
call   1080 <X509err@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@X509_F_NETSCAPE_SPKI_B64_DECODE = global i32 0
@ERR_R_MALLOC_FAILURE = global i32 0
@X509_R_BASE64_DECODE_ERROR = global i32 0
define i32* @NETSCAPE_SPKI_b64_decode(i8* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32*
store i8* %0, i8** %4
store i32 %1, i32* %5
%10 = load i32, i32* %5
%11 = icmp sle i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = call i32 @strlen(i8* %13)
store i32 %14, i32* %5
br label %15
15: ; preds = %12, %2
%16 = load i32, i32* %5
%17 = add nsw i32 %16, 1
%18 = call i8* @malloc(i32 %17)
store i8* %18, i8** %6
%19 = icmp ne i8* %18, null
br i1 %19, label %24, label %20
20: ; preds = %15
%21 = load i32, i32* @X509_F_NETSCAPE_SPKI_B64_DECODE
%22 = load i32, i32* @ERR_R_MALLOC_FAILURE
%23 = call i32 @X509err(i32 %21, i32 %22)
store i32* null, i32** %3
br label %44
24: ; preds = %15
%25 = load i8*, i8** %6
%26 = load i8*, i8** %4
%27 = load i32, i32* %5
%28 = call i32 @EVP_DecodeBlock(i8* %25, i8* %26, i32 %27)
store i32 %28, i32* %8
%29 = load i32, i32* %8
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %37
31: ; preds = %24
%32 = load i32, i32* @X509_F_NETSCAPE_SPKI_B64_DECODE
%33 = load i32, i32* @X509_R_BASE64_DECODE_ERROR
%34 = call i32 @X509err(i32 %32, i32 %33)
%35 = load i8*, i8** %6
%36 = call i32 @free(i8* %35)
store i32* null, i32** %3
br label %44
37: ; preds = %24
%38 = load i8*, i8** %6
store i8* %38, i8** %7
%39 = load i32, i32* %8
%40 = call i32* @d2i_NETSCAPE_SPKI(i32* null, i8** %7, i32 %39)
store i32* %40, i32** %9
%41 = load i8*, i8** %6
%42 = call i32 @free(i8* %41)
%43 = load i32*, i32** %9
store i32* %43, i32** %3
br label %44
44: ; preds = %37, %31, %20
%45 = load i32*, i32** %3
ret i32* %45
}

LLVM IR (-O2):
@X509_F_NETSCAPE_SPKI_B64_DECODE = global i32 0
@ERR_R_MALLOC_FAILURE = global i32 0
@X509_R_BASE64_DECODE_ERROR = global i32 0
define i32* @NETSCAPE_SPKI_b64_decode(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = icmp slt i32 %1, 1
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @strlen(i8* %0)
br label %8
8: ; preds = %6, %2
%9 = phi i32 [ %7, %6 ], [ %1, %2 ]
%10 = add nsw i32 %9, 1
%11 = tail call i8* @malloc(i32 %10)
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %17
13: ; preds = %8
%14 = load i32, i32* @X509_F_NETSCAPE_SPKI_B64_DECODE
%15 = load i32, i32* @ERR_R_MALLOC_FAILURE
%16 = tail call i32 @X509err(i32 %14, i32 %15)
br label %28
17: ; preds = %8
%18 = tail call i32 @EVP_DecodeBlock(i8* %11, i8* %0, i32 %9)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %17
%21 = load i32, i32* @X509_F_NETSCAPE_SPKI_B64_DECODE
%22 = load i32, i32* @X509_R_BASE64_DECODE_ERROR
%23 = tail call i32 @X509err(i32 %21, i32 %22)
%24 = tail call i32 @free(i8* %11)
br label %28
25: ; preds = %17
store i8* %11, i8** %3
%26 = call i32* @d2i_NETSCAPE_SPKI(i32* null, i8** %3, i32 %18)
%27 = call i32 @free(i8* %11)
br label %28
28: ; preds = %25, %20, %13
%29 = phi i32* [ null, %20 ], [ %26, %25 ], [ null, %13 ]
ret i32* %29
}