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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ parse_varbind(unsigned char *, unsigned char *, int);
scalar_t__ process_record(int);
int /*<<< orphan*/ stderr;
scalar_t__ unpack_tagcls(unsigned char **, unsigned char **, int);
int parse_varbinds(unsigned char *p, unsigned char *e, int trap) {
  unsigned char *m = p;
  bool corrupt = false;
  for (p = m, m = e; p < e; p = m, m = e) {
    if (unpack_tagcls(&p, &m, (0x20 | 0x10))) {
      fprintf(stderr, "E: poortly formated varbind sequence\n");
      goto error;
    }
    if (parse_varbind(p, m, trap)) {
      corrupt = true;
      continue;
    }
  }
  if (trap == 4)
    if (process_record(corrupt))
      goto error;
  return (0);
error:
  return (-1);
}


x86 assembly (clang, -O0):
<parse_varbinds>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11f6 <parse_varbinds+0xb6>
lea    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0x30,%edx
call   1030 <unpack_tagcls@plt>
cmp    $0x0,%rax
je     11b6 <parse_varbinds+0x76>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
lea    0xe54(%rip),%rsi
call   1060 <fprintf@plt>
jmp    1228 <parse_varbinds+0xe8>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <parse_varbind@plt>
cmp    $0x0,%rax
je     11dc <parse_varbinds+0x9c>
movl   $0x1,-0x2c(%rbp)
jmp    11e1 <parse_varbinds+0xa1>
jmp    11e1 <parse_varbinds+0xa1>
mov    -0x28(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    1172 <parse_varbinds+0x32>
cmpl   $0x4,-0x1c(%rbp)
jne    121c <parse_varbinds+0xdc>
mov    -0x2c(%rbp),%edi
call   1040 <process_record@plt>
cmp    $0x0,%rax
je     1217 <parse_varbinds+0xd7>
jmp    1228 <parse_varbinds+0xe8>
jmp    121c <parse_varbinds+0xdc>
movl   $0x0,-0x4(%rbp)
jmp    122f <parse_varbinds+0xef>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_varbinds>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r15d
mov    %rdi,0x10(%rsp)
mov    %rsi,0x8(%rsp)
mov    $0x0,%ebp
cmp    %rsi,%rdi
jae    11c2 <parse_varbinds+0x82>
mov    %rsi,%rbx
xor    %ebp,%ebp
lea    0x10(%rsp),%r12
lea    0x8(%rsp),%r13
mov    $0x1,%r14d
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r13,%rsi
mov    $0x30,%edx
call   1030 <unpack_tagcls@plt>
test   %rax,%rax
jne    11df <parse_varbinds+0x9f>
mov    0x10(%rsp),%rdi
mov    0x8(%rsp),%rsi
mov    %r15d,%edx
call   1050 <parse_varbind@plt>
test   %rax,%rax
cmovne %r14d,%ebp
mov    0x8(%rsp),%rax
mov    %rax,0x10(%rsp)
mov    %rbx,0x8(%rsp)
cmp    %rbx,%rax
jb     1180 <parse_varbinds+0x40>
cmp    $0x4,%r15d
jne    11db <parse_varbinds+0x9b>
mov    %ebp,%edi
call   1040 <process_record@plt>
test   %rax,%rax
mov    $0x0,%eax
jne    11f4 <parse_varbinds+0xb4>
jmp    11f9 <parse_varbinds+0xb9>
xor    %eax,%eax
jmp    11f9 <parse_varbinds+0xb9>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
lea    0xe11(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [38 x i8] c"E: poortly formated varbind sequence\0A\00"
define i32 @parse_varbinds(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%10 = load i8*, i8** %5
store i8* %10, i8** %8
store i32 0, i32* %9
%11 = load i8*, i8** %8
store i8* %11, i8** %5
%12 = load i8*, i8** %6
store i8* %12, i8** %8
br label %13
13: ; preds = %31, %3
%14 = load i8*, i8** %5
%15 = load i8*, i8** %6
%16 = icmp ult i8* %14, %15
br i1 %16, label %17, label %34
17: ; preds = %13
%18 = call i64 @unpack_tagcls(i8** %5, i8** %8, i32 48)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
br label %44
23: ; preds = %17
%24 = load i8*, i8** %5
%25 = load i8*, i8** %8
%26 = load i32, i32* %7
%27 = call i64 @parse_varbind(i8* %24, i8* %25, i32 %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %23
store i32 1, i32* %9
br label %31
30: ; preds = %23
br label %31
31: ; preds = %30, %29
%32 = load i8*, i8** %8
store i8* %32, i8** %5
%33 = load i8*, i8** %6
store i8* %33, i8** %8
br label %13
34: ; preds = %13
%35 = load i32, i32* %7
%36 = icmp eq i32 %35, 4
br i1 %36, label %37, label %43
37: ; preds = %34
%38 = load i32, i32* %9
%39 = call i64 @process_record(i32 %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %37
br label %44
42: ; preds = %37
br label %43
43: ; preds = %42, %34
store i32 0, i32* %4
br label %45
44: ; preds = %41, %20
store i32 -1, i32* %4
br label %45
45: ; preds = %44, %43
%46 = load i32, i32* %4
ret i32 %46
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [38 x i8] c"E: poortly formated varbind sequence\0A\00"
define i32 @parse_varbinds(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = bitcast i8** %5 to i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = icmp ult i8* %0, %1
br i1 %7, label %8, label %23
8: ; preds = %3, %15
%9 = phi i32 [ %20, %15 ], [ 0, %3 ]
%10 = call i64 @unpack_tagcls(i8** %4, i8** %5, i32 48)
%11 = icmp eq i64 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %8
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
br label %29
15: ; preds = %8
%16 = load i8*, i8** %4
%17 = load i8*, i8** %5
%18 = call i64 @parse_varbind(i8* %16, i8* %17, i32 %2)
%19 = icmp eq i64 %18, 0
%20 = select i1 %19, i32 %9, i32 1
%21 = load i8*, i8** %5
store i8* %21, i8** %4
store i8* %1, i8** %5
%22 = icmp ult i8* %21, %1
br i1 %22, label %8, label %23
23: ; preds = %15, %3
%24 = phi i32 [ 0, %3 ], [ %20, %15 ]
%25 = icmp eq i32 %2, 4
br i1 %25, label %26, label %30
26: ; preds = %23
%27 = call i64 @process_record(i32 %24)
%28 = icmp eq i64 %27, 0
br i1 %28, label %30, label %29
29: ; preds = %26, %12
br label %30
30: ; preds = %23, %26, %29
%31 = phi i32 [ -1, %29 ], [ 0, %26 ], [ 0, %23 ]
ret i32 %31
}