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

/* Variables and functions */
int /*<<< orphan*/ ASN1_F_ASN1_COLLECT;
int /*<<< orphan*/ ASN1_R_MISSING_EOC;
int /*<<< orphan*/ ASN1_R_NESTED_ASN1_STRING;
int /*<<< orphan*/ ASN1_R_UNEXPECTED_EOC;
int /*<<< orphan*/ ASN1err(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ ERR_R_NESTED_ASN1_ERROR;
scalar_t__ asn1_check_eoc(unsigned char const **, long);
int /*<<< orphan*/ asn1_check_tlen(long *, int /*<<< orphan*/ *,
                                   int /*<<< orphan*/ *, char *, char *,
                                   unsigned char const **, long, int, int,
                                   int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ collect_data(int /*<<< orphan*/ *, unsigned char const **,
                                long);
int asn1_collect(BUF_MEM *buf, const unsigned char **in, long len, char inf,
                 int tag, int aclass, int depth) {
  const unsigned char *p, *q;
  long plen;
  char cst, ininf;
  p = *in;
  inf &= 1;
  if (!buf && !inf) {
    *in += len;
    return 1;
  }
  while (len > 0) {
    q = p;
    if (asn1_check_eoc(&p, len)) {
      if (!inf) {
        ASN1err(ASN1_F_ASN1_COLLECT, ASN1_R_UNEXPECTED_EOC);
        return 0;
      }
      inf = 0;
      break;
    }
    if (!asn1_check_tlen(&plen, NULL, NULL, &ininf, &cst, &p, len, tag, aclass,
                         0, NULL)) {
      ASN1err(ASN1_F_ASN1_COLLECT, ERR_R_NESTED_ASN1_ERROR);
      return 0;
    }
    if (cst) {
      if (depth >= 5) {
        ASN1err(ASN1_F_ASN1_COLLECT, ASN1_R_NESTED_ASN1_STRING);
        return 0;
      }
      if (!asn1_collect(buf, &p, plen, ininf, tag, aclass, depth + 1))
        return 0;
    } else if (plen && !collect_data(buf, &p, plen))
      return 0;
    len -= p - q;
  }
  if (inf) {
    ASN1err(ASN1_F_ASN1_COLLECT, ASN1_R_MISSING_EOC);
    return 0;
  }
  *in = p;
  return 1;
}


x86 assembly (clang, -O0):
<asn1_collect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %cl,%al
mov    0x10(%rbp),%ecx
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %al,-0x21(%rbp)
mov    %r8d,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
movsbl -0x21(%rbp),%eax
and    $0x1,%eax
mov    %al,-0x21(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11bb <asn1_collect+0x6b>
cmpb   $0x0,-0x21(%rbp)
jne    11bb <asn1_collect+0x6b>
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
add    (%rax),%rcx
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    139c <asn1_collect+0x24c>
jmp    11c0 <asn1_collect+0x70>
cmpq   $0x0,-0x20(%rbp)
jle    135d <asn1_collect+0x20d>
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rsi
lea    -0x38(%rbp),%rdi
call   1060 <asn1_check_eoc@plt>
cmp    $0x0,%rax
je     1220 <asn1_collect+0xd0>
cmpb   $0x0,-0x21(%rbp)
jne    1217 <asn1_collect+0xc7>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
mov    0x2dbc(%rip),%rax
mov    (%rax),%esi
call   1040 <ASN1err@plt>
movl   $0x0,-0x4(%rbp)
jmp    139c <asn1_collect+0x24c>
movb   $0x0,-0x21(%rbp)
jmp    135d <asn1_collect+0x20d>
mov    -0x20(%rbp),%r11
mov    -0x28(%rbp),%r10d
mov    -0x2c(%rbp),%eax
lea    -0x48(%rbp),%rdi
xor    %ecx,%ecx
mov    %ecx,%edx
lea    -0x4a(%rbp),%rcx
lea    -0x49(%rbp),%r8
lea    -0x38(%rbp),%r9
xor    %esi,%esi
mov    %rdx,%rsi
mov    %r11,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
movl   $0x0,0x18(%rsp)
movq   $0x0,0x20(%rsp)
call   1030 <asn1_check_tlen@plt>
cmp    $0x0,%eax
jne    1293 <asn1_collect+0x143>
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
mov    0x2d50(%rip),%rax
mov    (%rax),%esi
call   1040 <ASN1err@plt>
movl   $0x0,-0x4(%rbp)
jmp    139c <asn1_collect+0x24c>
cmpb   $0x0,-0x49(%rbp)
je     130c <asn1_collect+0x1bc>
cmpl   $0x5,0x10(%rbp)
jl     12ca <asn1_collect+0x17a>
mov    0x2d42(%rip),%rax
mov    (%rax),%edi
mov    0x2d29(%rip),%rax
mov    (%rax),%esi
call   1040 <ASN1err@plt>
movl   $0x0,-0x4(%rbp)
jmp    139c <asn1_collect+0x24c>
mov    -0x10(%rbp),%rdi
mov    -0x48(%rbp),%rdx
mov    -0x4a(%rbp),%cl
mov    -0x28(%rbp),%r8d
mov    -0x2c(%rbp),%r9d
mov    0x10(%rbp),%eax
add    $0x1,%eax
lea    -0x38(%rbp),%rsi
movsbl %cl,%ecx
mov    %eax,(%rsp)
call   1050 <asn1_collect@plt>
cmp    $0x0,%eax
jne    1307 <asn1_collect+0x1b7>
movl   $0x0,-0x4(%rbp)
jmp    139c <asn1_collect+0x24c>
jmp    1342 <asn1_collect+0x1f2>
cmpq   $0x0,-0x48(%rbp)
je     133d <asn1_collect+0x1ed>
mov    -0x10(%rbp),%rdi
mov    -0x48(%rbp),%rdx
lea    -0x38(%rbp),%rsi
call   1070 <collect_data@plt>
cmp    $0x0,%eax
jne    133d <asn1_collect+0x1ed>
movl   $0x0,-0x4(%rbp)
jmp    139c <asn1_collect+0x24c>
jmp    1342 <asn1_collect+0x1f2>
mov    -0x38(%rbp),%rcx
mov    -0x40(%rbp),%rax
sub    %rax,%rcx
mov    -0x20(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x20(%rbp)
jmp    11c0 <asn1_collect+0x70>
cmpb   $0x0,-0x21(%rbp)
je     138a <asn1_collect+0x23a>
mov    0x2c82(%rip),%rax
mov    (%rax),%edi
mov    0x2c61(%rip),%rax
mov    (%rax),%esi
call   1040 <ASN1err@plt>
movl   $0x0,-0x4(%rbp)
jmp    139c <asn1_collect+0x24c>
mov    -0x38(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<asn1_collect>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9d,%r12d
mov    %r8d,%ebp
mov    %rdx,%rbx
mov    %rdi,%r13
mov    (%rsi),%r15
mov    %r15,0x8(%rsp)
test   %rdi,%rdi
jne    118d <asn1_collect+0x3d>
mov    %ecx,%eax
and    $0x1,%al
jne    118d <asn1_collect+0x3d>
add    %rbx,%r15
mov    %r15,(%rsi)
mov    $0x1,%eax
jmp    12f1 <asn1_collect+0x1a1>
mov    %ecx,0x4(%rsp)
mov    %rsi,0x18(%rsp)
test   %rbx,%rbx
jle    127d <asn1_collect+0x12d>
mov    0x60(%rsp),%eax
add    $0x1,%eax
mov    %rax,0x20(%rsp)
lea    0x8(%rsp),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <asn1_check_eoc@plt>
test   %rax,%rax
jne    1299 <asn1_collect+0x149>
sub    $0x8,%rsp
lea    0x18(%rsp),%rdi
xor    %esi,%esi
xor    %edx,%edx
lea    0xa(%rsp),%rcx
lea    0xb(%rsp),%r8
mov    %r14,%r9
push   $0x0
push   $0x0
push   %r12
push   %rbp
push   %rbx
call   1030 <asn1_check_tlen@plt>
add    $0x30,%rsp
test   %eax,%eax
je     12b4 <asn1_collect+0x164>
cmpb   $0x0,0x3(%rsp)
je     1240 <asn1_collect+0xf0>
mov    0x60(%rsp),%eax
cmp    $0x5,%eax
jge    12c6 <asn1_collect+0x176>
mov    0x10(%rsp),%rdx
movsbl 0x2(%rsp),%ecx
sub    $0x8,%rsp
mov    %r13,%rdi
mov    %r14,%rsi
mov    %ebp,%r8d
mov    %r12d,%r9d
push   0x28(%rsp)
call   1050 <asn1_collect@plt>
add    $0x10,%rsp
test   %eax,%eax
jne    125d <asn1_collect+0x10d>
jmp    12ef <asn1_collect+0x19f>
nopl   0x0(%rax,%rax,1)
mov    0x10(%rsp),%rdx
test   %rdx,%rdx
je     125d <asn1_collect+0x10d>
mov    %r13,%rdi
mov    %r14,%rsi
call   1070 <collect_data@plt>
test   %eax,%eax
je     12ef <asn1_collect+0x19f>
mov    0x8(%rsp),%rax
add    %r15,%rbx
sub    %rax,%rbx
mov    %rax,%r15
test   %rbx,%rbx
jg     11b0 <asn1_collect+0x60>
testb  $0x1,0x4(%rsp)
jne    1287 <asn1_collect+0x137>
jmp    12a5 <asn1_collect+0x155>
mov    %r15,%rax
testb  $0x1,0x4(%rsp)
je     12a5 <asn1_collect+0x155>
mov    0x2d62(%rip),%rax
mov    (%rax),%edi
mov    0x2d41(%rip),%rax
jmp    12e8 <asn1_collect+0x198>
testb  $0x1,0x4(%rsp)
je     12d8 <asn1_collect+0x188>
mov    0x8(%rsp),%rax
mov    0x18(%rsp),%rcx
mov    %rax,(%rcx)
mov    $0x1,%eax
jmp    12f1 <asn1_collect+0x1a1>
mov    0x2d35(%rip),%rax
mov    (%rax),%edi
mov    0x2d0c(%rip),%rax
jmp    12e8 <asn1_collect+0x198>
mov    0x2d23(%rip),%rax
mov    (%rax),%edi
mov    0x2d0a(%rip),%rax
jmp    12e8 <asn1_collect+0x198>
mov    0x2d11(%rip),%rax
mov    (%rax),%edi
mov    0x2cd8(%rip),%rax
mov    (%rax),%esi
call   1040 <ASN1err@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@ASN1_F_ASN1_COLLECT = global i32 0
@ASN1_R_UNEXPECTED_EOC = global i32 0
@ERR_R_NESTED_ASN1_ERROR = global i32 0
@ASN1_R_NESTED_ASN1_STRING = global i32 0
@ASN1_R_MISSING_EOC = global i32 0
define i32 @asn1_collect(i32* %0, i8** %1, i64 %2, i8 signext %3, i32 %4, i32 %5, i32 %6) {
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i8**
%11 = alloca i64
%12 = alloca i8
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i8*
%17 = alloca i8*
%18 = alloca i64
%19 = alloca i8
%20 = alloca i8
store i32* %0, i32** %9
store i8** %1, i8*** %10
store i64 %2, i64* %11
store i8 %3, i8* %12
store i32 %4, i32* %13
store i32 %5, i32* %14
store i32 %6, i32* %15
%21 = load i8**, i8*** %10
%22 = load i8*, i8** %21
store i8* %22, i8** %16
%23 = load i8, i8* %12
%24 = sext i8 %23 to i32
%25 = and i32 %24, 1
%26 = trunc i32 %25 to i8
store i8 %26, i8* %12
%27 = load i32*, i32** %9
%28 = icmp ne i32* %27, null
br i1 %28, label %37, label %29
29: ; preds = %7
%30 = load i8, i8* %12
%31 = icmp ne i8 %30, 0
br i1 %31, label %37, label %32
32: ; preds = %29
%33 = load i64, i64* %11
%34 = load i8**, i8*** %10
%35 = load i8*, i8** %34
%36 = getelementptr inbounds i8, i8* %35, i64 %33
store i8* %36, i8** %34
store i32 1, i32* %8
br label %114
37: ; preds = %29, %7
br label %38
38: ; preds = %96, %37
%39 = load i64, i64* %11
%40 = icmp sgt i64 %39, 0
br i1 %40, label %41, label %104
41: ; preds = %38
%42 = load i8*, i8** %16
store i8* %42, i8** %17
%43 = load i64, i64* %11
%44 = call i64 @asn1_check_eoc(i8** %16, i64 %43)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %54
46: ; preds = %41
%47 = load i8, i8* %12
%48 = icmp ne i8 %47, 0
br i1 %48, label %53, label %49
49: ; preds = %46
%50 = load i32, i32* @ASN1_F_ASN1_COLLECT
%51 = load i32, i32* @ASN1_R_UNEXPECTED_EOC
%52 = call i32 @ASN1err(i32 %50, i32 %51)
store i32 0, i32* %8
br label %114
53: ; preds = %46
store i8 0, i8* %12
br label %104
54: ; preds = %41
%55 = load i64, i64* %11
%56 = load i32, i32* %13
%57 = load i32, i32* %14
%58 = call i32 @asn1_check_tlen(i64* %18, i32* null, i32* null, i8* %20, i8* %19, i8** %16, i64 %55, i32 %56, i32 %57, i32 0, i32* null)
%59 = icmp ne i32 %58, 0
br i1 %59, label %64, label %60
60: ; preds = %54
%61 = load i32, i32* @ASN1_F_ASN1_COLLECT
%62 = load i32, i32* @ERR_R_NESTED_ASN1_ERROR
%63 = call i32 @ASN1err(i32 %61, i32 %62)
store i32 0, i32* %8
br label %114
64: ; preds = %54
%65 = load i8, i8* %19
%66 = icmp ne i8 %65, 0
br i1 %66, label %67, label %86
67: ; preds = %64
%68 = load i32, i32* %15
%69 = icmp sge i32 %68, 5
br i1 %69, label %70, label %74
70: ; preds = %67
%71 = load i32, i32* @ASN1_F_ASN1_COLLECT
%72 = load i32, i32* @ASN1_R_NESTED_ASN1_STRING
%73 = call i32 @ASN1err(i32 %71, i32 %72)
store i32 0, i32* %8
br label %114
74: ; preds = %67
%75 = load i32*, i32** %9
%76 = load i64, i64* %18
%77 = load i8, i8* %20
%78 = load i32, i32* %13
%79 = load i32, i32* %14
%80 = load i32, i32* %15
%81 = add nsw i32 %80, 1
%82 = call i32 @asn1_collect(i32* %75, i8** %16, i64 %76, i8 signext %77, i32 %78, i32 %79, i32 %81)
%83 = icmp ne i32 %82, 0
br i1 %83, label %85, label %84
84: ; preds = %74
store i32 0, i32* %8
br label %114
85: ; preds = %74
br label %96
86: ; preds = %64
%87 = load i64, i64* %18
%88 = icmp ne i64 %87, 0
br i1 %88, label %89, label %95
89: ; preds = %86
%90 = load i32*, i32** %9
%91 = load i64, i64* %18
%92 = call i32 @collect_data(i32* %90, i8** %16, i64 %91)
%93 = icmp ne i32 %92, 0
br i1 %93, label %95, label %94
94: ; preds = %89
store i32 0, i32* %8
br label %114
95: ; preds = %89, %86
br label %96
96: ; preds = %95, %85
%97 = load i8*, i8** %16
%98 = load i8*, i8** %17
%99 = ptrtoint i8* %97 to i64
%100 = ptrtoint i8* %98 to i64
%101 = sub i64 %99, %100
%102 = load i64, i64* %11
%103 = sub nsw i64 %102, %101
store i64 %103, i64* %11
br label %38
104: ; preds = %53, %38
%105 = load i8, i8* %12
%106 = icmp ne i8 %105, 0
br i1 %106, label %107, label %111
107: ; preds = %104
%108 = load i32, i32* @ASN1_F_ASN1_COLLECT
%109 = load i32, i32* @ASN1_R_MISSING_EOC
%110 = call i32 @ASN1err(i32 %108, i32 %109)
store i32 0, i32* %8
br label %114
111: ; preds = %104
%112 = load i8*, i8** %16
%113 = load i8**, i8*** %10
store i8* %112, i8** %113
store i32 1, i32* %8
br label %114
114: ; preds = %111, %107, %94, %84, %70, %60, %49, %32
%115 = load i32, i32* %8
ret i32 %115
}

LLVM IR (-O2):
@ASN1_F_ASN1_COLLECT = global i32 0
@ASN1_R_UNEXPECTED_EOC = global i32 0
@ERR_R_NESTED_ASN1_ERROR = global i32 0
@ASN1_R_NESTED_ASN1_STRING = global i32 0
@ASN1_R_MISSING_EOC = global i32 0
define i32 @asn1_collect(i32* %0, i8** nocapture %1, i64 %2, i8 signext %3, i32 %4, i32 %5, i32 %6) {
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8
%11 = alloca i8
%12 = bitcast i8** %8 to i8*
%13 = bitcast i64* %9 to i8*
%14 = load i8*, i8** %1
store i8* %14, i8** %8
%15 = and i8 %3, 1
%16 = icmp ne i32* %0, null
%17 = icmp ne i8 %15, 0
%18 = or i1 %16, %17
br i1 %18, label %19, label %24
19: ; preds = %7
%20 = icmp sgt i64 %2, 0
br i1 %20, label %21, label %71
21: ; preds = %19
%22 = icmp sgt i32 %6, 4
%23 = add nsw i32 %6, 1
br label %26
24: ; preds = %7
%25 = getelementptr inbounds i8, i8* %14, i64 %2
store i8* %25, i8** %1
br label %80
26: ; preds = %21, %64
%27 = phi i8* [ %14, %21 ], [ %65, %64 ]
%28 = phi i64 [ %2, %21 ], [ %69, %64 ]
%29 = call i64 @asn1_check_eoc(i8** %8, i64 %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %38, label %31
31: ; preds = %26
br i1 %17, label %32, label %34
32: ; preds = %31
%33 = load i8*, i8** %8
br label %78
34: ; preds = %31
%35 = load i32, i32* @ASN1_F_ASN1_COLLECT
%36 = load i32, i32* @ASN1_R_UNEXPECTED_EOC
%37 = call i32 @ASN1err(i32 %35, i32 %36)
br label %80
38: ; preds = %26
%39 = call i32 @asn1_check_tlen(i64* %9, i32* null, i32* null, i8* %11, i8* %10, i8** %8, i64 %28, i32 %4, i32 %5, i32 0, i32* null)
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %45
41: ; preds = %38
%42 = load i32, i32* @ASN1_F_ASN1_COLLECT
%43 = load i32, i32* @ERR_R_NESTED_ASN1_ERROR
%44 = call i32 @ASN1err(i32 %42, i32 %43)
br label %80
45: ; preds = %38
%46 = load i8, i8* %10
%47 = icmp eq i8 %46, 0
br i1 %47, label %58, label %48
48: ; preds = %45
br i1 %22, label %49, label %53
49: ; preds = %48
%50 = load i32, i32* @ASN1_F_ASN1_COLLECT
%51 = load i32, i32* @ASN1_R_NESTED_ASN1_STRING
%52 = call i32 @ASN1err(i32 %50, i32 %51)
br label %80
53: ; preds = %48
%54 = load i64, i64* %9
%55 = load i8, i8* %11
%56 = call i32 @asn1_collect(i32* %0, i8** %8, i64 %54, i8 signext %55, i32 %4, i32 %5, i32 %23)
%57 = icmp eq i32 %56, 0
br i1 %57, label %80, label %64
58: ; preds = %45
%59 = load i64, i64* %9
%60 = icmp eq i64 %59, 0
br i1 %60, label %64, label %61
61: ; preds = %58
%62 = call i32 @collect_data(i32* %0, i8** %8, i64 %59)
%63 = icmp eq i32 %62, 0
br i1 %63, label %80, label %64
64: ; preds = %58, %61, %53
%65 = load i8*, i8** %8
%66 = ptrtoint i8* %65 to i64
%67 = ptrtoint i8* %27 to i64
%68 = add i64 %28, %67
%69 = sub i64 %68, %66
%70 = icmp sgt i64 %69, 0
br i1 %70, label %26, label %71
71: ; preds = %64, %19
%72 = phi i8* [ %14, %19 ], [ %65, %64 ]
%73 = icmp eq i8 %15, 0
br i1 %73, label %78, label %74
74: ; preds = %71
%75 = load i32, i32* @ASN1_F_ASN1_COLLECT
%76 = load i32, i32* @ASN1_R_MISSING_EOC
%77 = call i32 @ASN1err(i32 %75, i32 %76)
br label %80
78: ; preds = %32, %71
%79 = phi i8* [ %33, %32 ], [ %72, %71 ]
store i8* %79, i8** %1
br label %80
80: ; preds = %61, %53, %78, %74, %49, %41, %34, %24
%81 = phi i32 [ 0, %74 ], [ 1, %78 ], [ 0, %34 ], [ 0, %49 ], [ 0, %41 ], [ 1, %24 ], [ 0, %53 ], [ 0, %61 ]
ret i32 %81
}