#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) {
  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) {
      ASN1err(ASN1_F_ASN1_COLLECT, ASN1_R_NESTED_ASN1_STRING);
      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    11a8 <asn1_collect+0x68>
cmpb   $0x0,-0x21(%rbp)
jne    11a8 <asn1_collect+0x68>
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
add    (%rax),%rcx
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    1332 <asn1_collect+0x1f2>
jmp    11ad <asn1_collect+0x6d>
cmpq   $0x0,-0x20(%rbp)
jle    12f3 <asn1_collect+0x1b3>
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rsi
lea    -0x38(%rbp),%rdi
call   1050 <asn1_check_eoc@plt>
cmp    $0x0,%rax
je     120d <asn1_collect+0xcd>
cmpb   $0x0,-0x21(%rbp)
jne    1204 <asn1_collect+0xc4>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
mov    0x2dcf(%rip),%rax
mov    (%rax),%esi
call   1040 <ASN1err@plt>
movl   $0x0,-0x4(%rbp)
jmp    1332 <asn1_collect+0x1f2>
movb   $0x0,-0x21(%rbp)
jmp    12f3 <asn1_collect+0x1b3>
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    1280 <asn1_collect+0x140>
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
mov    0x2d63(%rip),%rax
mov    (%rax),%esi
call   1040 <ASN1err@plt>
movl   $0x0,-0x4(%rbp)
jmp    1332 <asn1_collect+0x1f2>
cmpb   $0x0,-0x49(%rbp)
je     12ad <asn1_collect+0x16d>
mov    0x2d5f(%rip),%rax
mov    (%rax),%edi
mov    0x2d46(%rip),%rax
mov    (%rax),%esi
call   1040 <ASN1err@plt>
movl   $0x0,-0x4(%rbp)
jmp    1332 <asn1_collect+0x1f2>
mov    -0x10(%rbp),%rdi
mov    -0x48(%rbp),%rdx
lea    -0x38(%rbp),%rsi
call   1060 <collect_data@plt>
cmp    $0x0,%eax
jne    12d3 <asn1_collect+0x193>
movl   $0x0,-0x4(%rbp)
jmp    1332 <asn1_collect+0x1f2>
jmp    12d8 <asn1_collect+0x198>
mov    -0x38(%rbp),%rcx
mov    -0x40(%rbp),%rax
sub    %rax,%rcx
mov    -0x20(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x20(%rbp)
jmp    11ad <asn1_collect+0x6d>
cmpb   $0x0,-0x21(%rbp)
je     1320 <asn1_collect+0x1e0>
mov    0x2cec(%rip),%rax
mov    (%rax),%edi
mov    0x2ccb(%rip),%rax
mov    (%rax),%esi
call   1040 <ASN1err@plt>
movl   $0x0,-0x4(%rbp)
jmp    1332 <asn1_collect+0x1f2>
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,%r13d
mov    %rdx,%rbx
mov    %rdi,%rbp
mov    (%rsi),%r15
mov    %r15,0x10(%rsp)
test   %rdi,%rdi
jne    117d <asn1_collect+0x3d>
mov    %ecx,%eax
and    $0x1,%al
jne    117d <asn1_collect+0x3d>
add    %rbx,%r15
mov    %r15,(%rsi)
mov    $0x1,%eax
jmp    1293 <asn1_collect+0x153>
mov    %ecx,0xc(%rsp)
mov    %rsi,0x18(%rsp)
test   %rbx,%rbx
jle    121f <asn1_collect+0xdf>
lea    0x10(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <asn1_check_eoc@plt>
test   %rax,%rax
jne    123b <asn1_collect+0xfb>
sub    $0x8,%rsp
lea    0x28(%rsp),%rdi
xor    %esi,%esi
xor    %edx,%edx
lea    0x13(%rsp),%rcx
lea    0x12(%rsp),%r8
mov    %r14,%r9
push   $0x0
push   $0x0
push   %r12
push   %r13
push   %rbx
call   1030 <asn1_check_tlen@plt>
add    $0x30,%rsp
test   %eax,%eax
je     1256 <asn1_collect+0x116>
cmpb   $0x0,0xa(%rsp)
jne    1268 <asn1_collect+0x128>
mov    0x20(%rsp),%rdx
mov    %rbp,%rdi
mov    %r14,%rsi
call   1060 <collect_data@plt>
test   %eax,%eax
je     1291 <asn1_collect+0x151>
mov    0x10(%rsp),%rax
add    %r15,%rbx
sub    %rax,%rbx
mov    %rax,%r15
test   %rbx,%rbx
jg     11a0 <asn1_collect+0x60>
testb  $0x1,0xc(%rsp)
jne    1229 <asn1_collect+0xe9>
jmp    1247 <asn1_collect+0x107>
mov    %r15,%rax
testb  $0x1,0xc(%rsp)
je     1247 <asn1_collect+0x107>
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
mov    0x2d9f(%rip),%rax
jmp    128a <asn1_collect+0x14a>
testb  $0x1,0xc(%rsp)
je     127a <asn1_collect+0x13a>
mov    0x10(%rsp),%rax
mov    0x18(%rsp),%rcx
mov    %rax,(%rcx)
mov    $0x1,%eax
jmp    1293 <asn1_collect+0x153>
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
mov    0x2d6a(%rip),%rax
jmp    128a <asn1_collect+0x14a>
mov    0x2d81(%rip),%rax
mov    (%rax),%edi
mov    0x2d68(%rip),%rax
jmp    128a <asn1_collect+0x14a>
mov    0x2d6f(%rip),%rax
mov    (%rax),%edi
mov    0x2d36(%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) {
%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 %94
35: ; preds = %27, %6
br label %36
36: ; preds = %76, %35
%37 = load i64, i64* %10
%38 = icmp sgt i64 %37, 0
br i1 %38, label %39, label %84
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 %94
51: ; preds = %44
store i8 0, i8* %11
br label %84
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 %94
62: ; preds = %52
%63 = load i8, i8* %17
%64 = icmp ne i8 %63, 0
br i1 %64, label %65, label %69
65: ; preds = %62
%66 = load i32, i32* @ASN1_F_ASN1_COLLECT
%67 = load i32, i32* @ASN1_R_NESTED_ASN1_STRING
%68 = call i32 @ASN1err(i32 %66, i32 %67)
store i32 0, i32* %7
br label %94
69: ; preds = %62
%70 = load i32*, i32** %8
%71 = load i64, i64* %16
%72 = call i32 @collect_data(i32* %70, i8** %14, i64 %71)
%73 = icmp ne i32 %72, 0
br i1 %73, label %75, label %74
74: ; preds = %69
store i32 0, i32* %7
br label %94
75: ; preds = %69
br label %76
76: ; preds = %75
%77 = load i8*, i8** %14
%78 = load i8*, i8** %15
%79 = ptrtoint i8* %77 to i64
%80 = ptrtoint i8* %78 to i64
%81 = sub i64 %79, %80
%82 = load i64, i64* %10
%83 = sub nsw i64 %82, %81
store i64 %83, i64* %10
br label %36
84: ; preds = %51, %36
%85 = load i8, i8* %11
%86 = icmp ne i8 %85, 0
br i1 %86, label %87, label %91
87: ; preds = %84
%88 = load i32, i32* @ASN1_F_ASN1_COLLECT
%89 = load i32, i32* @ASN1_R_MISSING_EOC
%90 = call i32 @ASN1err(i32 %88, i32 %89)
store i32 0, i32* %7
br label %94
91: ; preds = %84
%92 = load i8*, i8** %14
%93 = load i8**, i8*** %9
store i8* %92, i8** %93
store i32 1, i32* %7
br label %94
94: ; preds = %91, %87, %74, %65, %58, %47, %30
%95 = load i32, i32* %7
ret i32 %95
}

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) {
%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
br i1 %43, label %48, label %44
44: ; preds = %41
%45 = load i32, i32* @ASN1_F_ASN1_COLLECT
%46 = load i32, i32* @ASN1_R_NESTED_ASN1_STRING
%47 = call i32 @ASN1err(i32 %45, i32 %46)
br label %68
48: ; preds = %41
%49 = load i64, i64* %8
%50 = call i32 @collect_data(i32* %0, i8** %7, i64 %49)
%51 = icmp eq i32 %50, 0
br i1 %51, label %68, label %52
52: ; preds = %48
%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 = %48, %66, %62, %44, %37, %30, %20
%69 = phi i32 [ 0, %62 ], [ 1, %66 ], [ 0, %30 ], [ 0, %44 ], [ 0, %37 ], [ 1, %20 ], [ 0, %48 ]
ret i32 %69
}