#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_indent(int /*<<< orphan*/ *, int, int);
int /*<<< orphan*/ BIO_printf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ BIO_puts(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ PEM_write_bio_X509(int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *);
int /*<<< orphan*/ X509_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ X509_print_ex(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                 int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ XN_FLAG_ONELINE;
int /*<<< orphan*/ *d2i_X509(int /*<<< orphan*/ *, unsigned char const **,
                             size_t);
int ssl_print_certificate(BIO *bio, int indent, const unsigned char **pmsg,
                          size_t *pmsglen) {
  size_t msglen = *pmsglen;
  size_t clen;
  X509 *x;
  const unsigned char *p = *pmsg, *q;
  if (msglen < 3)
    return 0;
  clen = (p[0] << 16) | (p[1] << 8) | p[2];
  if (msglen < clen + 3)
    return 0;
  q = p + 3;
  BIO_indent(bio, indent, 80);
  BIO_printf(bio, "ASN.1Cert, length=%d", (int)clen);
  x = d2i_X509(NULL, &q, clen);
  if (!x)
    BIO_puts(bio, "<UNPARSEABLE CERTIFICATE>\n");
  else {
    BIO_puts(bio, "\n------details-----\n");
    X509_print_ex(bio, x, XN_FLAG_ONELINE, 0);
    PEM_write_bio_X509(bio, x);
    BIO_puts(bio, "------------------\n");
    X509_free(x);
  }
  if (q != p + 3 + clen) {
    BIO_puts(bio, "<TRAILING GARBAGE AFTER CERTIFICATE>\n");
  }
  *pmsg += clen + 3;
  *pmsglen -= clen + 3;
  return 1;
}


x86 assembly (clang, -O0):
<ssl_print_certificate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x48(%rbp)
cmpq   $0x3,-0x30(%rbp)
jae    11b4 <ssl_print_certificate+0x44>
movl   $0x0,-0x4(%rbp)
jmp    1309 <ssl_print_certificate+0x199>
mov    -0x48(%rbp),%rax
movzbl (%rax),%eax
shl    $0x10,%eax
mov    -0x48(%rbp),%rcx
movzbl 0x1(%rcx),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    -0x48(%rbp),%rcx
movzbl 0x2(%rcx),%ecx
or     %ecx,%eax
cltq
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x38(%rbp),%rcx
add    $0x3,%rcx
cmp    %rcx,%rax
jae    11fc <ssl_print_certificate+0x8c>
movl   $0x0,-0x4(%rbp)
jmp    1309 <ssl_print_certificate+0x199>
mov    -0x48(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    $0x50,%edx
call   1030 <BIO_indent@plt>
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rax
mov    %eax,%edx
lea    0xdd6(%rip),%rsi
call   1040 <BIO_printf@plt>
mov    -0x38(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%edi
lea    -0x50(%rbp),%rsi
call   1080 <d2i_X509@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1264 <ssl_print_certificate+0xf4>
mov    -0x10(%rbp),%rdi
lea    0xdbb(%rip),%rsi
call   1090 <BIO_puts@plt>
jmp    12b2 <ssl_print_certificate+0x142>
mov    -0x10(%rbp),%rdi
lea    0xdc1(%rip),%rsi
call   1090 <BIO_puts@plt>
mov    -0x10(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    0x2d65(%rip),%rax
mov    (%rax),%edx
xor    %ecx,%ecx
call   1050 <X509_print_ex@plt>
mov    -0x10(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1060 <PEM_write_bio_X509@plt>
mov    -0x10(%rbp),%rdi
lea    0xda1(%rip),%rsi
call   1090 <BIO_puts@plt>
mov    -0x40(%rbp),%rdi
call   1070 <X509_free@plt>
mov    -0x50(%rbp),%rax
mov    -0x48(%rbp),%rcx
add    $0x3,%rcx
add    -0x38(%rbp),%rcx
cmp    %rcx,%rax
je     12db <ssl_print_certificate+0x16b>
mov    -0x10(%rbp),%rdi
lea    0xd83(%rip),%rsi
call   1090 <BIO_puts@plt>
mov    -0x38(%rbp),%rcx
add    $0x3,%rcx
mov    -0x20(%rbp),%rax
add    (%rax),%rcx
mov    %rcx,(%rax)
mov    -0x38(%rbp),%rdx
add    $0x3,%rdx
mov    -0x28(%rbp),%rax
mov    (%rax),%rcx
sub    %rdx,%rcx
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ssl_print_certificate>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r15
mov    (%rcx),%rcx
xor    %eax,%eax
cmp    $0x3,%rcx
jb     1288 <ssl_print_certificate+0x118>
mov    %rdx,%r14
mov    %rdi,%r12
mov    (%rdx),%rbp
movzbl 0x0(%rbp),%edx
shl    $0x10,%rdx
movzbl 0x1(%rbp),%ebx
shl    $0x8,%rbx
or     %rdx,%rbx
movzbl 0x2(%rbp),%edx
lea    (%rdx,%rbx,1),%rdi
add    $0x3,%rdi
cmp    %rdi,%rcx
jb     1288 <ssl_print_certificate+0x118>
mov    %rdi,0x10(%rsp)
or     %rdx,%rbx
add    $0x3,%rbp
mov    %rbp,0x8(%rsp)
mov    %r12,%rdi
mov    $0x50,%edx
call   1030 <BIO_indent@plt>
lea    0xe1a(%rip),%rsi
mov    %r12,%rdi
mov    %ebx,%edx
call   1040 <BIO_printf@plt>
lea    0x8(%rsp),%rsi
xor    %edi,%edi
mov    %rbx,%rdx
call   1080 <d2i_X509@plt>
test   %rax,%rax
je     1250 <ssl_print_certificate+0xe0>
mov    %rax,%r13
lea    0xe22(%rip),%rsi
mov    %r12,%rdi
call   1090 <BIO_puts@plt>
mov    0x2dcb(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
mov    %r13,%rsi
xor    %ecx,%ecx
call   1050 <X509_print_ex@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   1060 <PEM_write_bio_X509@plt>
lea    0xe07(%rip),%rsi
mov    %r12,%rdi
call   1090 <BIO_puts@plt>
mov    %r13,%rdi
call   1070 <X509_free@plt>
jmp    125f <ssl_print_certificate+0xef>
lea    0xdbe(%rip),%rsi
mov    %r12,%rdi
call   1090 <BIO_puts@plt>
add    %rbx,%rbp
cmp    %rbp,0x8(%rsp)
je     1278 <ssl_print_certificate+0x108>
lea    0xde9(%rip),%rsi
mov    %r12,%rdi
call   1090 <BIO_puts@plt>
mov    0x10(%rsp),%rax
add    %rax,(%r14)
sub    %rax,(%r15)
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"ASN.1Cert, length=%d\00"
@.str.1 = [27 x i8] c"<UNPARSEABLE CERTIFICATE>\0A\00"
@.str.2 = [21 x i8] c"\0A------details-----\0A\00"
@XN_FLAG_ONELINE = global i32 0
@.str.3 = [20 x i8] c"------------------\0A\00"
@.str.4 = [38 x i8] c"<TRAILING GARBAGE AFTER CERTIFICATE>\0A\00"
define i32 @ssl_print_certificate(i32* %0, i32 %1, i8** %2, i64* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i8**
%9 = alloca i64*
%10 = alloca i64
%11 = alloca i64
%12 = alloca i32*
%13 = alloca i8*
%14 = alloca i8*
store i32* %0, i32** %6
store i32 %1, i32* %7
store i8** %2, i8*** %8
store i64* %3, i64** %9
%15 = load i64*, i64** %9
%16 = load i64, i64* %15
store i64 %16, i64* %10
%17 = load i8**, i8*** %8
%18 = load i8*, i8** %17
store i8* %18, i8** %13
%19 = load i64, i64* %10
%20 = icmp ult i64 %19, 3
br i1 %20, label %21, label %22
21: ; preds = %4
store i32 0, i32* %5
br label %97
22: ; preds = %4
%23 = load i8*, i8** %13
%24 = getelementptr inbounds i8, i8* %23, i64 0
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = shl i32 %26, 16
%28 = load i8*, i8** %13
%29 = getelementptr inbounds i8, i8* %28, i64 1
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
%32 = shl i32 %31, 8
%33 = or i32 %27, %32
%34 = load i8*, i8** %13
%35 = getelementptr inbounds i8, i8* %34, i64 2
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = or i32 %33, %37
%39 = sext i32 %38 to i64
store i64 %39, i64* %11
%40 = load i64, i64* %10
%41 = load i64, i64* %11
%42 = add i64 %41, 3
%43 = icmp ult i64 %40, %42
br i1 %43, label %44, label %45
44: ; preds = %22
store i32 0, i32* %5
br label %97
45: ; preds = %22
%46 = load i8*, i8** %13
%47 = getelementptr inbounds i8, i8* %46, i64 3
store i8* %47, i8** %14
%48 = load i32*, i32** %6
%49 = load i32, i32* %7
%50 = call i32 @BIO_indent(i32* %48, i32 %49, i32 80)
%51 = load i32*, i32** %6
%52 = load i64, i64* %11
%53 = trunc i64 %52 to i32
%54 = call i32 @BIO_printf(i32* %51, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %53)
%55 = load i64, i64* %11
%56 = call i32* @d2i_X509(i32* null, i8** %14, i64 %55)
store i32* %56, i32** %12
%57 = load i32*, i32** %12
%58 = icmp ne i32* %57, null
br i1 %58, label %62, label %59
59: ; preds = %45
%60 = load i32*, i32** %6
%61 = call i32 @BIO_puts(i32* %60, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %76
62: ; preds = %45
%63 = load i32*, i32** %6
%64 = call i32 @BIO_puts(i32* %63, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%65 = load i32*, i32** %6
%66 = load i32*, i32** %12
%67 = load i32, i32* @XN_FLAG_ONELINE
%68 = call i32 @X509_print_ex(i32* %65, i32* %66, i32 %67, i32 0)
%69 = load i32*, i32** %6
%70 = load i32*, i32** %12
%71 = call i32 @PEM_write_bio_X509(i32* %69, i32* %70)
%72 = load i32*, i32** %6
%73 = call i32 @BIO_puts(i32* %72, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%74 = load i32*, i32** %12
%75 = call i32 @X509_free(i32* %74)
br label %76
76: ; preds = %62, %59
%77 = load i8*, i8** %14
%78 = load i8*, i8** %13
%79 = getelementptr inbounds i8, i8* %78, i64 3
%80 = load i64, i64* %11
%81 = getelementptr inbounds i8, i8* %79, i64 %80
%82 = icmp ne i8* %77, %81
br i1 %82, label %83, label %86
83: ; preds = %76
%84 = load i32*, i32** %6
%85 = call i32 @BIO_puts(i32* %84, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0))
br label %86
86: ; preds = %83, %76
%87 = load i64, i64* %11
%88 = add i64 %87, 3
%89 = load i8**, i8*** %8
%90 = load i8*, i8** %89
%91 = getelementptr inbounds i8, i8* %90, i64 %88
store i8* %91, i8** %89
%92 = load i64, i64* %11
%93 = add i64 %92, 3
%94 = load i64*, i64** %9
%95 = load i64, i64* %94
%96 = sub i64 %95, %93
store i64 %96, i64* %94
store i32 1, i32* %5
br label %97
97: ; preds = %86, %44, %21
%98 = load i32, i32* %5
ret i32 %98
}

LLVM IR (-O2):
@.str = [21 x i8] c"ASN.1Cert, length=%d\00"
@.str.1 = [27 x i8] c"<UNPARSEABLE CERTIFICATE>\0A\00"
@.str.2 = [21 x i8] c"\0A------details-----\0A\00"
@XN_FLAG_ONELINE = global i32 0
@.str.3 = [20 x i8] c"------------------\0A\00"
@.str.4 = [38 x i8] c"<TRAILING GARBAGE AFTER CERTIFICATE>\0A\00"
define i32 @ssl_print_certificate(i32* %0, i32 %1, i8** nocapture %2, i64* nocapture %3) {
%5 = alloca i8*
%6 = load i64, i64* %3
%7 = load i8*, i8** %2
%8 = bitcast i8** %5 to i8*
%9 = icmp ult i64 %6, 3
br i1 %9, label %52, label %10
10: ; preds = %4
%11 = load i8, i8* %7
%12 = zext i8 %11 to i32
%13 = shl nuw nsw i32 %12, 16
%14 = getelementptr inbounds i8, i8* %7, i64 1
%15 = load i8, i8* %14
%16 = zext i8 %15 to i32
%17 = shl nuw nsw i32 %16, 8
%18 = or i32 %17, %13
%19 = getelementptr inbounds i8, i8* %7, i64 2
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = or i32 %18, %21
%23 = zext i32 %22 to i64
%24 = add nuw nsw i64 %23, 3
%25 = icmp ult i64 %6, %24
br i1 %25, label %52, label %26
26: ; preds = %10
%27 = getelementptr inbounds i8, i8* %7, i64 3
store i8* %27, i8** %5
%28 = tail call i32 @BIO_indent(i32* %0, i32 %1, i32 80)
%29 = tail call i32 @BIO_printf(i32* %0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %22)
%30 = call i32* @d2i_X509(i32* null, i8** %5, i64 %23)
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %34
32: ; preds = %26
%33 = call i32 @BIO_puts(i32* %0, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %41
34: ; preds = %26
%35 = call i32 @BIO_puts(i32* %0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%36 = load i32, i32* @XN_FLAG_ONELINE
%37 = call i32 @X509_print_ex(i32* %0, i32* %30, i32 %36, i32 0)
%38 = call i32 @PEM_write_bio_X509(i32* %0, i32* %30)
%39 = call i32 @BIO_puts(i32* %0, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%40 = call i32 @X509_free(i32* %30)
br label %41
41: ; preds = %34, %32
%42 = load i8*, i8** %5
%43 = getelementptr inbounds i8, i8* %27, i64 %23
%44 = icmp eq i8* %42, %43
br i1 %44, label %47, label %45
45: ; preds = %41
%46 = call i32 @BIO_puts(i32* %0, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0))
br label %47
47: ; preds = %45, %41
%48 = load i8*, i8** %2
%49 = getelementptr inbounds i8, i8* %48, i64 %24
store i8* %49, i8** %2
%50 = load i64, i64* %3
%51 = sub i64 %50, %24
store i64 %51, i64* %3
br label %52
52: ; preds = %10, %4, %47
%53 = phi i32 [ 1, %47 ], [ 0, %4 ], [ 0, %10 ]
ret i32 %53
}