#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_UNEXPECTED_EOC;
int /*<<< orphan*/ ASN1err(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ ERR_R_NESTED_ASN1_ERROR;
scalar_t__ asn1_check_eoc(unsigned char **, long);
int /*<<< orphan*/ asn1_check_tlen(long *, int /*<<< orphan*/ *,
                                   int /*<<< orphan*/ *, char *, char *,
                                   unsigned char **, long, int, int,
                                   int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ collect_data(int /*<<< orphan*/ *, unsigned char **, long);
int asn1_collect(BUF_MEM *buf, unsigned char **in, long len, char inf, int tag,
                 int aclass) {
  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 (!asn1_collect(buf, &p, plen, ininf, tag, aclass))
        return 0;
    } else {
      if (!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    %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    11b8 <asn1_collect+0x68>
cmpb   $0x0,-0x21(%rbp)
jne    11b8 <asn1_collect+0x68>
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
add    (%rax),%rcx
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    1358 <asn1_collect+0x208>
jmp    11bd <asn1_collect+0x6d>
cmpq   $0x0,-0x20(%rbp)
jle    1319 <asn1_collect+0x1c9>
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     121d <asn1_collect+0xcd>
cmpb   $0x0,-0x21(%rbp)
jne    1214 <asn1_collect+0xc4>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
mov    0x2dc7(%rip),%rax
mov    (%rax),%esi
call   1040 <ASN1err@plt>
movl   $0x0,-0x4(%rbp)
jmp    1358 <asn1_collect+0x208>
movb   $0x0,-0x21(%rbp)
jmp    1319 <asn1_collect+0x1c9>
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    1290 <asn1_collect+0x140>
mov    0x2d7c(%rip),%rax
mov    (%rax),%edi
mov    0x2d5b(%rip),%rax
mov    (%rax),%esi
call   1040 <ASN1err@plt>
movl   $0x0,-0x4(%rbp)
jmp    1358 <asn1_collect+0x208>
cmpb   $0x0,-0x49(%rbp)
je     12d3 <asn1_collect+0x183>
mov    -0x10(%rbp),%rdi
mov    -0x48(%rbp),%rdx
mov    -0x4a(%rbp),%al
mov    -0x28(%rbp),%r8d
mov    -0x2c(%rbp),%r9d
lea    -0x38(%rbp),%rsi
movsbl %al,%ecx
call   1050 <asn1_collect@plt>
cmp    $0x0,%eax
jne    12ce <asn1_collect+0x17e>
movl   $0x0,-0x4(%rbp)
jmp    1358 <asn1_collect+0x208>
jmp    12fe <asn1_collect+0x1ae>
mov    -0x10(%rbp),%rdi
mov    -0x48(%rbp),%rdx
lea    -0x38(%rbp),%rsi
call   1070 <collect_data@plt>
cmp    $0x0,%eax
jne    12f9 <asn1_collect+0x1a9>
movl   $0x0,-0x4(%rbp)
jmp    1358 <asn1_collect+0x208>
jmp    12fe <asn1_collect+0x1ae>
mov    -0x38(%rbp),%rcx
mov    -0x40(%rbp),%rax
sub    %rax,%rcx
mov    -0x20(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x20(%rbp)
jmp    11bd <asn1_collect+0x6d>
cmpb   $0x0,-0x21(%rbp)
je     1346 <asn1_collect+0x1f6>
mov    0x2cc6(%rip),%rax
mov    (%rax),%edi
mov    0x2cad(%rip),%rax
mov    (%rax),%esi
call   1040 <ASN1err@plt>
movl   $0x0,-0x4(%rbp)
jmp    1358 <asn1_collect+0x208>
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,0x10(%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    12c5 <asn1_collect+0x175>
mov    %ecx,0xc(%rsp)
mov    %rsi,0x18(%rsp)
test   %rbx,%rbx
jle    1263 <asn1_collect+0x113>
lea    0x10(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <asn1_check_eoc@plt>
test   %rax,%rax
jne    127f <asn1_collect+0x12f>
sub    $0x8,%rsp
lea    0x28(%rsp),%rdi
xor    %esi,%esi
xor    %edx,%edx
lea    0x12(%rsp),%rcx
lea    0x13(%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     129a <asn1_collect+0x14a>
cmpb   $0x0,0xb(%rsp)
mov    0x20(%rsp),%rdx
je     1230 <asn1_collect+0xe0>
movsbl 0xa(%rsp),%ecx
mov    %r13,%rdi
mov    %r14,%rsi
mov    %ebp,%r8d
mov    %r12d,%r9d
call   1050 <asn1_collect@plt>
test   %eax,%eax
jne    1243 <asn1_collect+0xf3>
jmp    12c3 <asn1_collect+0x173>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r13,%rdi
mov    %r14,%rsi
call   1070 <collect_data@plt>
test   %eax,%eax
je     12c3 <asn1_collect+0x173>
mov    0x10(%rsp),%rax
add    %r15,%rbx
sub    %rax,%rbx
mov    %rax,%r15
test   %rbx,%rbx
jg     11b0 <asn1_collect+0x60>
testb  $0x1,0xc(%rsp)
jne    126d <asn1_collect+0x11d>
jmp    128b <asn1_collect+0x13b>
mov    %r15,%rax
testb  $0x1,0xc(%rsp)
je     128b <asn1_collect+0x13b>
mov    0x2d7c(%rip),%rax
mov    (%rax),%edi
mov    0x2d63(%rip),%rax
jmp    12bc <asn1_collect+0x16c>
testb  $0x1,0xc(%rsp)
je     12ac <asn1_collect+0x15c>
mov    0x10(%rsp),%rax
mov    0x18(%rsp),%rcx
mov    %rax,(%rcx)
mov    $0x1,%eax
jmp    12c5 <asn1_collect+0x175>
mov    0x2d4f(%rip),%rax
mov    (%rax),%edi
mov    0x2d2e(%rip),%rax
jmp    12bc <asn1_collect+0x16c>
mov    0x2d3d(%rip),%rax
mov    (%rax),%edi
mov    0x2d0c(%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_MISSING_EOC = global i32 0
define i32 @asn1_collect(i32* %0, i8** %1, i64 %2, i8 signext %3, i32 %4, i32 %5) {
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i8**
%10 = alloca i64
%11 = alloca i8
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i64
%17 = alloca i8
%18 = alloca i8
store i32* %0, i32** %8
store i8** %1, i8*** %9
store i64 %2, i64* %10
store i8 %3, i8* %11
store i32 %4, i32* %12
store i32 %5, i32* %13
%19 = load i8**, i8*** %9
%20 = load i8*, i8** %19
store i8* %20, i8** %14
%21 = load i8, i8* %11
%22 = sext i8 %21 to i32
%23 = and i32 %22, 1
%24 = trunc i32 %23 to i8
store i8 %24, i8* %11
%25 = load i32*, i32** %8
%26 = icmp ne i32* %25, null
br i1 %26, label %35, label %27
27: ; preds = %6
%28 = load i8, i8* %11
%29 = icmp ne i8 %28, 0
br i1 %29, label %35, label %30
30: ; preds = %27
%31 = load i64, i64* %10
%32 = load i8**, i8*** %9
%33 = load i8*, i8** %32
%34 = getelementptr inbounds i8, i8* %33, i64 %31
store i8* %34, i8** %32
store i32 1, i32* %7
br label %100
35: ; preds = %27, %6
br label %36
36: ; preds = %82, %35
%37 = load i64, i64* %10
%38 = icmp sgt i64 %37, 0
br i1 %38, label %39, label %90
39: ; preds = %36
%40 = load i8*, i8** %14
store i8* %40, i8** %15
%41 = load i64, i64* %10
%42 = call i64 @asn1_check_eoc(i8** %14, i64 %41)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %52
44: ; preds = %39
%45 = load i8, i8* %11
%46 = icmp ne i8 %45, 0
br i1 %46, label %51, label %47
47: ; preds = %44
%48 = load i32, i32* @ASN1_F_ASN1_COLLECT
%49 = load i32, i32* @ASN1_R_UNEXPECTED_EOC
%50 = call i32 @ASN1err(i32 %48, i32 %49)
store i32 0, i32* %7
br label %100
51: ; preds = %44
store i8 0, i8* %11
br label %90
52: ; preds = %39
%53 = load i64, i64* %10
%54 = load i32, i32* %12
%55 = load i32, i32* %13
%56 = call i32 @asn1_check_tlen(i64* %16, i32* null, i32* null, i8* %18, i8* %17, i8** %14, i64 %53, i32 %54, i32 %55, i32 0, i32* null)
%57 = icmp ne i32 %56, 0
br i1 %57, label %62, label %58
58: ; preds = %52
%59 = load i32, i32* @ASN1_F_ASN1_COLLECT
%60 = load i32, i32* @ERR_R_NESTED_ASN1_ERROR
%61 = call i32 @ASN1err(i32 %59, i32 %60)
store i32 0, i32* %7
br label %100
62: ; preds = %52
%63 = load i8, i8* %17
%64 = icmp ne i8 %63, 0
br i1 %64, label %65, label %75
65: ; preds = %62
%66 = load i32*, i32** %8
%67 = load i64, i64* %16
%68 = load i8, i8* %18
%69 = load i32, i32* %12
%70 = load i32, i32* %13
%71 = call i32 @asn1_collect(i32* %66, i8** %14, i64 %67, i8 signext %68, i32 %69, i32 %70)
%72 = icmp ne i32 %71, 0
br i1 %72, label %74, label %73
73: ; preds = %65
store i32 0, i32* %7
br label %100
74: ; preds = %65
br label %82
75: ; preds = %62
%76 = load i32*, i32** %8
%77 = load i64, i64* %16
%78 = call i32 @collect_data(i32* %76, i8** %14, i64 %77)
%79 = icmp ne i32 %78, 0
br i1 %79, label %81, label %80
80: ; preds = %75
store i32 0, i32* %7
br label %100
81: ; preds = %75
br label %82
82: ; preds = %81, %74
%83 = load i8*, i8** %14
%84 = load i8*, i8** %15
%85 = ptrtoint i8* %83 to i64
%86 = ptrtoint i8* %84 to i64
%87 = sub i64 %85, %86
%88 = load i64, i64* %10
%89 = sub nsw i64 %88, %87
store i64 %89, i64* %10
br label %36
90: ; preds = %51, %36
%91 = load i8, i8* %11
%92 = icmp ne i8 %91, 0
br i1 %92, label %93, label %97
93: ; preds = %90
%94 = load i32, i32* @ASN1_F_ASN1_COLLECT
%95 = load i32, i32* @ASN1_R_MISSING_EOC
%96 = call i32 @ASN1err(i32 %94, i32 %95)
store i32 0, i32* %7
br label %100
97: ; preds = %90
%98 = load i8*, i8** %14
%99 = load i8**, i8*** %9
store i8* %98, i8** %99
store i32 1, i32* %7
br label %100
100: ; preds = %97, %93, %80, %73, %58, %47, %30
%101 = load i32, i32* %7
ret i32 %101
}

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