#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_R_SCT_UNSUPPORTED_VERSION;
int /*<<< orphan*/ ERR_LIB_CT;
int /*<<< orphan*/ ERR_R_MALLOC_FAILURE;
int /*<<< orphan*/ ERR_raise(int /*<<< orphan*/, int /*<<< orphan*/);
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;
  const unsigned char *p = NULL;
  int declen;
  if (sct == NULL) {
    ERR_raise(ERR_LIB_CT, ERR_R_MALLOC_FAILURE);
    return NULL;
  }
  if (!SCT_set_version(sct, version)) {
    ERR_raise(ERR_LIB_CT, CT_R_SCT_UNSUPPORTED_VERSION);
    goto err;
  }
  declen = ct_base64_decode(logid_base64, &dec);
  if (declen < 0) {
    ERR_raise(ERR_LIB_CT, 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) {
    ERR_raise(ERR_LIB_CT, 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) {
    ERR_raise(ERR_LIB_CT, X509_R_BASE64_DECODE_ERROR);
    goto err;
  }
  p = dec;
  if (o2i_SCT_signature(sct, &p, 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)
movq   $0x0,-0x48(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    121a <SCT_new_from_base64+0x6a>
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
mov    0x2dd2(%rip),%rax
mov    (%rax),%esi
call   10a0 <ERR_raise@plt>
movq   $0x0,-0x8(%rbp)
jmp    13b1 <SCT_new_from_base64+0x201>
mov    -0x38(%rbp),%rdi
movzbl -0x9(%rbp),%esi
call   1040 <SCT_set_version@plt>
cmp    $0x0,%eax
jne    124c <SCT_new_from_base64+0x9c>
mov    0x2da9(%rip),%rax
mov    (%rax),%edi
mov    0x2d88(%rip),%rax
mov    (%rax),%esi
call   10a0 <ERR_raise@plt>
jmp    1397 <SCT_new_from_base64+0x1e7>
mov    -0x18(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1080 <ct_base64_decode@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
jge    1282 <SCT_new_from_base64+0xd2>
mov    0x2d73(%rip),%rax
mov    (%rax),%edi
mov    0x2d72(%rip),%rax
mov    (%rax),%esi
call   10a0 <ERR_raise@plt>
jmp    1397 <SCT_new_from_base64+0x1e7>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x4c(%rbp),%edx
call   1090 <SCT_set0_log_id@plt>
cmp    $0x0,%eax
jne    12a0 <SCT_new_from_base64+0xf0>
jmp    1397 <SCT_new_from_base64+0x1e7>
movq   $0x0,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1080 <ct_base64_decode@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
jge    12de <SCT_new_from_base64+0x12e>
mov    0x2d17(%rip),%rax
mov    (%rax),%edi
mov    0x2d16(%rip),%rax
mov    (%rax),%esi
call   10a0 <ERR_raise@plt>
jmp    1397 <SCT_new_from_base64+0x1e7>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x4c(%rbp),%edx
call   10b0 <SCT_set0_extensions@plt>
movq   $0x0,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1080 <ct_base64_decode@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
jge    132c <SCT_new_from_base64+0x17c>
mov    0x2cc9(%rip),%rax
mov    (%rax),%edi
mov    0x2cc8(%rip),%rax
mov    (%rax),%esi
call   10a0 <ERR_raise@plt>
jmp    1397 <SCT_new_from_base64+0x1e7>
mov    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x4c(%rbp),%edx
lea    -0x48(%rbp),%rsi
call   10d0 <o2i_SCT_signature@plt>
cmp    $0x0,%rax
jg     1353 <SCT_new_from_base64+0x1a3>
jmp    1397 <SCT_new_from_base64+0x1e7>
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   1070 <SCT_set_log_entry_type@plt>
cmp    $0x0,%eax
jne    138a <SCT_new_from_base64+0x1da>
jmp    1397 <SCT_new_from_base64+0x1e7>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    13b1 <SCT_new_from_base64+0x201>
mov    -0x40(%rbp),%rdi
call   10c0 <OPENSSL_free@plt>
mov    -0x38(%rbp),%rdi
call   1060 <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,0xc(%rsp)
mov    %rsi,%rbp
mov    %edi,%r14d
xor    %eax,%eax
call   1030 <SCT_new@plt>
movq   $0x0,(%rsp)
movq   $0x0,0x10(%rsp)
test   %rax,%rax
je     12bd <SCT_new_from_base64+0x10d>
mov    %rax,%rbx
movzbl %r14b,%esi
mov    %rax,%rdi
call   1040 <SCT_set_version@plt>
test   %eax,%eax
je     12e8 <SCT_new_from_base64+0x138>
mov    %rsp,%rsi
mov    %rbp,%rdi
call   1080 <ct_base64_decode@plt>
test   %eax,%eax
js     12d6 <SCT_new_from_base64+0x126>
mov    (%rsp),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1090 <SCT_set0_log_id@plt>
test   %eax,%eax
je     12ff <SCT_new_from_base64+0x14f>
movq   $0x0,(%rsp)
mov    %rsp,%rsi
mov    %r13,%rdi
call   1080 <ct_base64_decode@plt>
test   %eax,%eax
js     12d6 <SCT_new_from_base64+0x126>
mov    (%rsp),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   10b0 <SCT_set0_extensions@plt>
movq   $0x0,(%rsp)
mov    %rsp,%rsi
mov    %r12,%rdi
call   1080 <ct_base64_decode@plt>
test   %eax,%eax
js     12d6 <SCT_new_from_base64+0x126>
mov    (%rsp),%rcx
mov    %rcx,0x10(%rsp)
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   10d0 <o2i_SCT_signature@plt>
test   %rax,%rax
jle    12ff <SCT_new_from_base64+0x14f>
mov    (%rsp),%rdi
call   10c0 <OPENSSL_free@plt>
movq   $0x0,(%rsp)
mov    %rbx,%rdi
mov    %r15d,%esi
call   1050 <SCT_set_timestamp@plt>
mov    %rbx,%rdi
mov    0xc(%rsp),%esi
call   1070 <SCT_set_log_entry_type@plt>
test   %eax,%eax
jne    1312 <SCT_new_from_base64+0x162>
jmp    12ff <SCT_new_from_base64+0x14f>
mov    0x2d1c(%rip),%rax
mov    (%rax),%edi
mov    0x2d0b(%rip),%rax
mov    (%rax),%esi
call   10a0 <ERR_raise@plt>
jmp    1310 <SCT_new_from_base64+0x160>
mov    0x2d03(%rip),%rax
mov    (%rax),%edi
mov    0x2d02(%rip),%rax
jmp    12f8 <SCT_new_from_base64+0x148>
mov    0x2cf1(%rip),%rax
mov    (%rax),%edi
mov    0x2cd0(%rip),%rax
mov    (%rax),%esi
call   10a0 <ERR_raise@plt>
mov    (%rsp),%rdi
call   10c0 <OPENSSL_free@plt>
mov    %rbx,%rdi
call   1060 <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):
@ERR_LIB_CT = 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 i8*
%17 = 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
%18 = call i32* (...) @SCT_new()
store i32* %18, i32** %14
store i8* null, i8** %15
store i8* null, i8** %16
%19 = load i32*, i32** %14
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %25
21: ; preds = %6
%22 = load i32, i32* @ERR_LIB_CT
%23 = load i32, i32* @ERR_R_MALLOC_FAILURE
%24 = call i32 @ERR_raise(i32 %22, i32 %23)
store i32* null, i32** %7
br label %97
25: ; preds = %6
%26 = load i32*, i32** %14
%27 = load i8, i8* %8
%28 = call i32 @SCT_set_version(i32* %26, i8 zeroext %27)
%29 = icmp ne i32 %28, 0
br i1 %29, label %34, label %30
30: ; preds = %25
%31 = load i32, i32* @ERR_LIB_CT
%32 = load i32, i32* @CT_R_SCT_UNSUPPORTED_VERSION
%33 = call i32 @ERR_raise(i32 %31, i32 %32)
br label %92
34: ; preds = %25
%35 = load i8*, i8** %9
%36 = call i32 @ct_base64_decode(i8* %35, i8** %15)
store i32 %36, i32* %17
%37 = load i32, i32* %17
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %34
%40 = load i32, i32* @ERR_LIB_CT
%41 = load i32, i32* @X509_R_BASE64_DECODE_ERROR
%42 = call i32 @ERR_raise(i32 %40, i32 %41)
br label %92
43: ; preds = %34
%44 = load i32*, i32** %14
%45 = load i8*, i8** %15
%46 = load i32, i32* %17
%47 = call i32 @SCT_set0_log_id(i32* %44, i8* %45, i32 %46)
%48 = icmp ne i32 %47, 0
br i1 %48, label %50, label %49
49: ; preds = %43
br label %92
50: ; preds = %43
store i8* null, i8** %15
%51 = load i8*, i8** %12
%52 = call i32 @ct_base64_decode(i8* %51, i8** %15)
store i32 %52, i32* %17
%53 = load i32, i32* %17
%54 = icmp slt i32 %53, 0
br i1 %54, label %55, label %59
55: ; preds = %50
%56 = load i32, i32* @ERR_LIB_CT
%57 = load i32, i32* @X509_R_BASE64_DECODE_ERROR
%58 = call i32 @ERR_raise(i32 %56, i32 %57)
br label %92
59: ; preds = %50
%60 = load i32*, i32** %14
%61 = load i8*, i8** %15
%62 = load i32, i32* %17
%63 = call i32 @SCT_set0_extensions(i32* %60, i8* %61, i32 %62)
store i8* null, i8** %15
%64 = load i8*, i8** %13
%65 = call i32 @ct_base64_decode(i8* %64, i8** %15)
store i32 %65, i32* %17
%66 = load i32, i32* %17
%67 = icmp slt i32 %66, 0
br i1 %67, label %68, label %72
68: ; preds = %59
%69 = load i32, i32* @ERR_LIB_CT
%70 = load i32, i32* @X509_R_BASE64_DECODE_ERROR
%71 = call i32 @ERR_raise(i32 %69, i32 %70)
br label %92
72: ; preds = %59
%73 = load i8*, i8** %15
store i8* %73, i8** %16
%74 = load i32*, i32** %14
%75 = load i32, i32* %17
%76 = call i64 @o2i_SCT_signature(i32* %74, i8** %16, i32 %75)
%77 = icmp sle i64 %76, 0
br i1 %77, label %78, label %79
78: ; preds = %72
br label %92
79: ; preds = %72
%80 = load i8*, i8** %15
%81 = call i32 @OPENSSL_free(i8* %80)
store i8* null, i8** %15
%82 = load i32*, i32** %14
%83 = load i32, i32* %11
%84 = call i32 @SCT_set_timestamp(i32* %82, i32 %83)
%85 = load i32*, i32** %14
%86 = load i32, i32* %10
%87 = call i32 @SCT_set_log_entry_type(i32* %85, i32 %86)
%88 = icmp ne i32 %87, 0
br i1 %88, label %90, label %89
89: ; preds = %79
br label %92
90: ; preds = %79
%91 = load i32*, i32** %14
store i32* %91, i32** %7
br label %97
92: ; preds = %89, %78, %68, %55, %49, %39, %30
%93 = load i8*, i8** %15
%94 = call i32 @OPENSSL_free(i8* %93)
%95 = load i32*, i32** %14
%96 = call i32 @SCT_free(i32* %95)
store i32* null, i32** %7
br label %97
97: ; preds = %92, %90, %21
%98 = load i32*, i32** %7
ret i32* %98
}

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