#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*/ uint64_t;
typedef int /*<<< orphan*/ ct_log_entry_type_t;
typedef int /*<<< orphan*/ SCT;

/* Variables and functions */
int /*<<< orphan*/ CT_F_SCT_NEW_FROM_BASE64;
int /*<<< orphan*/ CT_R_SCT_UNSUPPORTED_VERSION;
int /*<<< orphan*/ CTerr(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ ERR_R_MALLOC_FAILURE;
int /*<<< orphan*/ OPENSSL_free(unsigned char *);
int /*<<< orphan*/ SCT_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *SCT_new();
int /*<<< orphan*/ SCT_set0_extensions(int /*<<< orphan*/ *, unsigned char *,
                                       int);
int /*<<< orphan*/ SCT_set0_log_id(int /*<<< orphan*/ *, unsigned char *, int);
int /*<<< orphan*/ SCT_set_log_entry_type(int /*<<< orphan*/ *,
                                          int /*<<< orphan*/);
int /*<<< orphan*/ SCT_set_timestamp(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ SCT_set_version(int /*<<< orphan*/ *, unsigned char);
int /*<<< orphan*/ X509_R_BASE64_DECODE_ERROR;
int ct_base64_decode(char const *, unsigned char **);
scalar_t__ o2i_SCT_signature(int /*<<< orphan*/ *, unsigned char const **, int);
SCT *SCT_new_from_base64(unsigned char version, const char *logid_base64,
                         ct_log_entry_type_t entry_type, uint64_t timestamp,
                         const char *extensions_base64,
                         const char *signature_base64) {
  SCT *sct = SCT_new();
  unsigned char *dec = NULL;
  int declen;
  if (sct == NULL) {
    CTerr(CT_F_SCT_NEW_FROM_BASE64, ERR_R_MALLOC_FAILURE);
    return NULL;
  }
  if (!SCT_set_version(sct, version)) {
    CTerr(CT_F_SCT_NEW_FROM_BASE64, CT_R_SCT_UNSUPPORTED_VERSION);
    goto err;
  }
  declen = ct_base64_decode(logid_base64, &dec);
  if (declen < 0) {
    CTerr(CT_F_SCT_NEW_FROM_BASE64, X509_R_BASE64_DECODE_ERROR);
    goto err;
  }
  if (!SCT_set0_log_id(sct, dec, declen))
    goto err;
  dec = NULL;
  declen = ct_base64_decode(extensions_base64, &dec);
  if (declen < 0) {
    CTerr(CT_F_SCT_NEW_FROM_BASE64, X509_R_BASE64_DECODE_ERROR);
    goto err;
  }
  SCT_set0_extensions(sct, dec, declen);
  dec = NULL;
  declen = ct_base64_decode(signature_base64, &dec);
  if (declen < 0) {
    CTerr(CT_F_SCT_NEW_FROM_BASE64, X509_R_BASE64_DECODE_ERROR);
    goto err;
  }
  if (o2i_SCT_signature(sct, (const unsigned char **)&dec, declen) <= 0)
    goto err;
  OPENSSL_free(dec);
  dec = NULL;
  SCT_set_timestamp(sct, timestamp);
  if (!SCT_set_log_entry_type(sct, entry_type))
    goto err;
  return sct;
err:
  OPENSSL_free(dec);
  SCT_free(sct);
  return NULL;
}


x86 assembly (clang, -O0):
<SCT_new_from_base64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %dil,%al
mov    %al,-0x9(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    $0x0,%al
call   1030 <SCT_new@plt>
mov    %rax,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1212 <SCT_new_from_base64+0x62>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
mov    0x2dda(%rip),%rax
mov    (%rax),%esi
call   1060 <CTerr@plt>
movq   $0x0,-0x8(%rbp)
jmp    13a1 <SCT_new_from_base64+0x1f1>
mov    -0x38(%rbp),%rdi
movzbl -0x9(%rbp),%esi
call   1040 <SCT_set_version@plt>
cmp    $0x0,%eax
jne    1244 <SCT_new_from_base64+0x94>
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
mov    0x2d90(%rip),%rax
mov    (%rax),%esi
call   1060 <CTerr@plt>
jmp    1387 <SCT_new_from_base64+0x1d7>
mov    -0x18(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1090 <ct_base64_decode@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jge    127a <SCT_new_from_base64+0xca>
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
mov    0x2d72(%rip),%rax
mov    (%rax),%esi
call   1060 <CTerr@plt>
jmp    1387 <SCT_new_from_base64+0x1d7>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x44(%rbp),%edx
call   10a0 <SCT_set0_log_id@plt>
cmp    $0x0,%eax
jne    1298 <SCT_new_from_base64+0xe8>
jmp    1387 <SCT_new_from_base64+0x1d7>
movq   $0x0,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1090 <ct_base64_decode@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jge    12d6 <SCT_new_from_base64+0x126>
mov    0x2d37(%rip),%rax
mov    (%rax),%edi
mov    0x2d16(%rip),%rax
mov    (%rax),%esi
call   1060 <CTerr@plt>
jmp    1387 <SCT_new_from_base64+0x1d7>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x44(%rbp),%edx
call   10b0 <SCT_set0_extensions@plt>
movq   $0x0,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1090 <ct_base64_decode@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jge    1324 <SCT_new_from_base64+0x174>
mov    0x2ce9(%rip),%rax
mov    (%rax),%edi
mov    0x2cc8(%rip),%rax
mov    (%rax),%esi
call   1060 <CTerr@plt>
jmp    1387 <SCT_new_from_base64+0x1d7>
mov    -0x38(%rbp),%rdi
mov    -0x44(%rbp),%edx
lea    -0x40(%rbp),%rsi
call   10d0 <o2i_SCT_signature@plt>
cmp    $0x0,%rax
jg     1343 <SCT_new_from_base64+0x193>
jmp    1387 <SCT_new_from_base64+0x1d7>
mov    -0x40(%rbp),%rdi
call   10c0 <OPENSSL_free@plt>
movq   $0x0,-0x40(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1050 <SCT_set_timestamp@plt>
mov    -0x38(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1080 <SCT_set_log_entry_type@plt>
cmp    $0x0,%eax
jne    137a <SCT_new_from_base64+0x1ca>
jmp    1387 <SCT_new_from_base64+0x1d7>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    13a1 <SCT_new_from_base64+0x1f1>
mov    -0x40(%rbp),%rdi
call   10c0 <OPENSSL_free@plt>
mov    -0x38(%rbp),%rdi
call   1070 <SCT_free@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SCT_new_from_base64>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,%r12
mov    %r8,%r13
mov    %ecx,%r15d
mov    %edx,0x14(%rsp)
mov    %rsi,%rbp
mov    %edi,%r14d
xor    %eax,%eax
call   1030 <SCT_new@plt>
movq   $0x0,0x8(%rsp)
test   %rax,%rax
je     12b8 <SCT_new_from_base64+0x108>
mov    %rax,%rbx
movzbl %r14b,%esi
mov    %rax,%rdi
call   1040 <SCT_set_version@plt>
test   %eax,%eax
je     12e3 <SCT_new_from_base64+0x133>
lea    0x8(%rsp),%rsi
mov    %rbp,%rdi
call   1090 <ct_base64_decode@plt>
test   %eax,%eax
js     12d1 <SCT_new_from_base64+0x121>
mov    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   10a0 <SCT_set0_log_id@plt>
test   %eax,%eax
je     12fa <SCT_new_from_base64+0x14a>
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %r13,%rdi
call   1090 <ct_base64_decode@plt>
test   %eax,%eax
js     12d1 <SCT_new_from_base64+0x121>
mov    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   10b0 <SCT_set0_extensions@plt>
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %r12,%rdi
call   1090 <ct_base64_decode@plt>
test   %eax,%eax
js     12d1 <SCT_new_from_base64+0x121>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   10d0 <o2i_SCT_signature@plt>
test   %rax,%rax
jle    12fa <SCT_new_from_base64+0x14a>
mov    0x8(%rsp),%rdi
call   10c0 <OPENSSL_free@plt>
movq   $0x0,0x8(%rsp)
mov    %rbx,%rdi
mov    %r15d,%esi
call   1050 <SCT_set_timestamp@plt>
mov    %rbx,%rdi
mov    0x14(%rsp),%esi
call   1080 <SCT_set_log_entry_type@plt>
test   %eax,%eax
jne    130e <SCT_new_from_base64+0x15e>
jmp    12fa <SCT_new_from_base64+0x14a>
mov    0x2d39(%rip),%rax
mov    (%rax),%edi
mov    0x2d10(%rip),%rax
mov    (%rax),%esi
call   1060 <CTerr@plt>
jmp    130c <SCT_new_from_base64+0x15c>
mov    0x2d20(%rip),%rax
mov    (%rax),%edi
mov    0x2cff(%rip),%rax
jmp    12f3 <SCT_new_from_base64+0x143>
mov    0x2d0e(%rip),%rax
mov    (%rax),%edi
mov    0x2cd5(%rip),%rax
mov    (%rax),%esi
call   1060 <CTerr@plt>
mov    0x8(%rsp),%rdi
call   10c0 <OPENSSL_free@plt>
mov    %rbx,%rdi
call   1070 <SCT_free@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@CT_F_SCT_NEW_FROM_BASE64 = global i32 0
@ERR_R_MALLOC_FAILURE = global i32 0
@CT_R_SCT_UNSUPPORTED_VERSION = global i32 0
@X509_R_BASE64_DECODE_ERROR = global i32 0
define i32* @SCT_new_from_base64(i8 zeroext %0, i8* %1, i32 %2, i32 %3, i8* %4, i8* %5) {
%7 = alloca i32*
%8 = alloca i8
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i32*
%15 = alloca i8*
%16 = alloca i32
store i8 %0, i8* %8
store i8* %1, i8** %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i8* %4, i8** %12
store i8* %5, i8** %13
%17 = call i32* (...) @SCT_new()
store i32* %17, i32** %14
store i8* null, i8** %15
%18 = load i32*, i32** %14
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %24
20: ; preds = %6
%21 = load i32, i32* @CT_F_SCT_NEW_FROM_BASE64
%22 = load i32, i32* @ERR_R_MALLOC_FAILURE
%23 = call i32 @CTerr(i32 %21, i32 %22)
store i32* null, i32** %7
br label %95
24: ; preds = %6
%25 = load i32*, i32** %14
%26 = load i8, i8* %8
%27 = call i32 @SCT_set_version(i32* %25, i8 zeroext %26)
%28 = icmp ne i32 %27, 0
br i1 %28, label %33, label %29
29: ; preds = %24
%30 = load i32, i32* @CT_F_SCT_NEW_FROM_BASE64
%31 = load i32, i32* @CT_R_SCT_UNSUPPORTED_VERSION
%32 = call i32 @CTerr(i32 %30, i32 %31)
br label %90
33: ; preds = %24
%34 = load i8*, i8** %9
%35 = call i32 @ct_base64_decode(i8* %34, i8** %15)
store i32 %35, i32* %16
%36 = load i32, i32* %16
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %33
%39 = load i32, i32* @CT_F_SCT_NEW_FROM_BASE64
%40 = load i32, i32* @X509_R_BASE64_DECODE_ERROR
%41 = call i32 @CTerr(i32 %39, i32 %40)
br label %90
42: ; preds = %33
%43 = load i32*, i32** %14
%44 = load i8*, i8** %15
%45 = load i32, i32* %16
%46 = call i32 @SCT_set0_log_id(i32* %43, i8* %44, i32 %45)
%47 = icmp ne i32 %46, 0
br i1 %47, label %49, label %48
48: ; preds = %42
br label %90
49: ; preds = %42
store i8* null, i8** %15
%50 = load i8*, i8** %12
%51 = call i32 @ct_base64_decode(i8* %50, i8** %15)
store i32 %51, i32* %16
%52 = load i32, i32* %16
%53 = icmp slt i32 %52, 0
br i1 %53, label %54, label %58
54: ; preds = %49
%55 = load i32, i32* @CT_F_SCT_NEW_FROM_BASE64
%56 = load i32, i32* @X509_R_BASE64_DECODE_ERROR
%57 = call i32 @CTerr(i32 %55, i32 %56)
br label %90
58: ; preds = %49
%59 = load i32*, i32** %14
%60 = load i8*, i8** %15
%61 = load i32, i32* %16
%62 = call i32 @SCT_set0_extensions(i32* %59, i8* %60, i32 %61)
store i8* null, i8** %15
%63 = load i8*, i8** %13
%64 = call i32 @ct_base64_decode(i8* %63, i8** %15)
store i32 %64, i32* %16
%65 = load i32, i32* %16
%66 = icmp slt i32 %65, 0
br i1 %66, label %67, label %71
67: ; preds = %58
%68 = load i32, i32* @CT_F_SCT_NEW_FROM_BASE64
%69 = load i32, i32* @X509_R_BASE64_DECODE_ERROR
%70 = call i32 @CTerr(i32 %68, i32 %69)
br label %90
71: ; preds = %58
%72 = load i32*, i32** %14
%73 = load i32, i32* %16
%74 = call i64 @o2i_SCT_signature(i32* %72, i8** %15, i32 %73)
%75 = icmp sle i64 %74, 0
br i1 %75, label %76, label %77
76: ; preds = %71
br label %90
77: ; preds = %71
%78 = load i8*, i8** %15
%79 = call i32 @OPENSSL_free(i8* %78)
store i8* null, i8** %15
%80 = load i32*, i32** %14
%81 = load i32, i32* %11
%82 = call i32 @SCT_set_timestamp(i32* %80, i32 %81)
%83 = load i32*, i32** %14
%84 = load i32, i32* %10
%85 = call i32 @SCT_set_log_entry_type(i32* %83, i32 %84)
%86 = icmp ne i32 %85, 0
br i1 %86, label %88, label %87
87: ; preds = %77
br label %90
88: ; preds = %77
%89 = load i32*, i32** %14
store i32* %89, i32** %7
br label %95
90: ; preds = %87, %76, %67, %54, %48, %38, %29
%91 = load i8*, i8** %15
%92 = call i32 @OPENSSL_free(i8* %91)
%93 = load i32*, i32** %14
%94 = call i32 @SCT_free(i32* %93)
store i32* null, i32** %7
br label %95
95: ; preds = %90, %88, %20
%96 = load i32*, i32** %7
ret i32* %96
}

LLVM IR (-O2):
@CT_F_SCT_NEW_FROM_BASE64 = global i32 0
@ERR_R_MALLOC_FAILURE = global i32 0
@CT_R_SCT_UNSUPPORTED_VERSION = global i32 0
@X509_R_BASE64_DECODE_ERROR = global i32 0
define i32* @SCT_new_from_base64(i8 zeroext %0, i8* %1, i32 %2, i32 %3, i8* %4, i8* %5) {
%7 = alloca i8*
%8 = tail call i32* (...) @SCT_new()
%9 = bitcast i8** %7 to i8*
store i8* null, i8** %7
%10 = icmp eq i32* %8, null
br i1 %10, label %11, label %15
11: ; preds = %6
%12 = load i32, i32* @CT_F_SCT_NEW_FROM_BASE64
%13 = load i32, i32* @ERR_R_MALLOC_FAILURE
%14 = tail call i32 @CTerr(i32 %12, i32 %13)
br label %62
15: ; preds = %6
%16 = tail call i32 @SCT_set_version(i32* %8, i8 zeroext %0)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %15
%19 = load i32, i32* @CT_F_SCT_NEW_FROM_BASE64
%20 = load i32, i32* @CT_R_SCT_UNSUPPORTED_VERSION
%21 = tail call i32 @CTerr(i32 %19, i32 %20)
br label %58
22: ; preds = %15
%23 = call i32 @ct_base64_decode(i8* %1, i8** %7)
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = load i32, i32* @CT_F_SCT_NEW_FROM_BASE64
%27 = load i32, i32* @X509_R_BASE64_DECODE_ERROR
%28 = call i32 @CTerr(i32 %26, i32 %27)
br label %58
29: ; preds = %22
%30 = load i8*, i8** %7
%31 = call i32 @SCT_set0_log_id(i32* %8, i8* %30, i32 %23)
%32 = icmp eq i32 %31, 0
br i1 %32, label %58, label %33
33: ; preds = %29
store i8* null, i8** %7
%34 = call i32 @ct_base64_decode(i8* %4, i8** %7)
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %33
%37 = load i32, i32* @CT_F_SCT_NEW_FROM_BASE64
%38 = load i32, i32* @X509_R_BASE64_DECODE_ERROR
%39 = call i32 @CTerr(i32 %37, i32 %38)
br label %58
40: ; preds = %33
%41 = load i8*, i8** %7
%42 = call i32 @SCT_set0_extensions(i32* %8, i8* %41, i32 %34)
store i8* null, i8** %7
%43 = call i32 @ct_base64_decode(i8* %5, i8** %7)
%44 = icmp slt i32 %43, 0
br i1 %44, label %45, label %49
45: ; preds = %40
%46 = load i32, i32* @CT_F_SCT_NEW_FROM_BASE64
%47 = load i32, i32* @X509_R_BASE64_DECODE_ERROR
%48 = call i32 @CTerr(i32 %46, i32 %47)
br label %58
49: ; preds = %40
%50 = call i64 @o2i_SCT_signature(i32* %8, i8** %7, i32 %43)
%51 = icmp slt i64 %50, 1
br i1 %51, label %58, label %52
52: ; preds = %49
%53 = load i8*, i8** %7
%54 = call i32 @OPENSSL_free(i8* %53)
store i8* null, i8** %7
%55 = call i32 @SCT_set_timestamp(i32* %8, i32 %3)
%56 = call i32 @SCT_set_log_entry_type(i32* %8, i32 %2)
%57 = icmp eq i32 %56, 0
br i1 %57, label %58, label %62
58: ; preds = %52, %49, %29, %45, %36, %25, %18
%59 = load i8*, i8** %7
%60 = call i32 @OPENSSL_free(i8* %59)
%61 = call i32 @SCT_free(i32* %8)
br label %62
62: ; preds = %52, %58, %11
%63 = phi i32* [ null, %11 ], [ null, %58 ], [ %8, %52 ]
ret i32* %63
}