#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 *, ...);
int parse_trap(unsigned char *, unsigned char **, int);
scalar_t__ parse_varbinds(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ stderr;
scalar_t__ unpack_tagcls(unsigned char **, unsigned char **, int);
int parse_varbind_list(unsigned char *p, unsigned char *e, int version,
                       int trap) {
  unsigned char *m = e;
  if (unpack_tagcls(&p, &m, (0x20 | 0x10))) {
    fprintf(stderr, "E: poorly formatted varbind list\n");
    goto error;
  }
  if (m < e) {
    fprintf(stderr, "W: %d bytes follow varbind list\n", (int)(e - m));
    e = m;
  }
  if (version != 0 && trap == -1) {
    if ((trap = parse_trap(p, &m, version)) == -1) {
      fprintf(stderr, "E: bad trap varbind in message\n");
      goto error;
    }
  }
  p = m;
  m = e;
  if (parse_varbinds(p, m, trap)) {
    fprintf(stderr, "E: bad varbinds in message\n");
    goto error;
  }
  return (0);
error:
  return (-1);
}


x86 assembly (clang, -O0):
<parse_varbind_list>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0x30,%edx
call   1030 <unpack_tagcls@plt>
cmp    $0x0,%rax
je     1196 <parse_varbind_list+0x56>
mov    0x2e5f(%rip),%rax
mov    (%rax),%edi
lea    0xe76(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1273 <parse_varbind_list+0x133>
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11d0 <parse_varbind_list+0x90>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
lea    0xe61(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1221 <parse_varbind_list+0xe1>
cmpl   $0xffffffff,-0x20(%rbp)
jne    1221 <parse_varbind_list+0xe1>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    -0x28(%rbp),%rsi
call   1050 <parse_trap@plt>
mov    %eax,-0x20(%rbp)
cmp    $0xffffffff,%eax
jne    121c <parse_varbind_list+0xdc>
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
lea    0xe33(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1273 <parse_varbind_list+0x133>
jmp    1221 <parse_varbind_list+0xe1>
mov    -0x28(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1040 <parse_varbinds@plt>
cmp    $0x0,%rax
je     1267 <parse_varbind_list+0x127>
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
lea    0xe08(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1273 <parse_varbind_list+0x133>
movl   $0x0,-0x4(%rbp)
jmp    127a <parse_varbind_list+0x13a>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_varbind_list>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %ecx,%ebp
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,0x8(%rsp)
mov    %rsi,(%rsp)
lea    0x8(%rsp),%rdi
mov    %rsp,%rsi
mov    $0x30,%edx
call   1030 <unpack_tagcls@plt>
test   %rax,%rax
je     1179 <parse_varbind_list+0x39>
lea    0xe89(%rip),%rsi
jmp    11f7 <parse_varbind_list+0xb7>
mov    (%rsp),%rdi
cmp    %rbx,%rdi
jae    11a6 <parse_varbind_list+0x66>
mov    0x2e57(%rip),%rax
mov    (%rax),%eax
sub    %edi,%ebx
lea    0xe8e(%rip),%rsi
mov    %eax,%edi
mov    %ebx,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%rsp),%rdi
mov    %rdi,%rbx
test   %r14d,%r14d
je     11cb <parse_varbind_list+0x8b>
cmp    $0xffffffff,%ebp
jne    11cb <parse_varbind_list+0x8b>
mov    0x8(%rsp),%rdi
mov    %rsp,%rsi
mov    %r14d,%edx
call   1050 <parse_trap@plt>
cmp    $0xffffffff,%eax
je     11f0 <parse_varbind_list+0xb0>
mov    %eax,%ebp
mov    (%rsp),%rdi
mov    %rdi,0x8(%rsp)
mov    %rbx,(%rsp)
mov    %rbx,%rsi
mov    %ebp,%edx
call   1040 <parse_varbinds@plt>
test   %rax,%rax
je     11ec <parse_varbind_list+0xac>
lea    0xe79(%rip),%rsi
jmp    11f7 <parse_varbind_list+0xb7>
xor    %eax,%eax
jmp    120c <parse_varbind_list+0xcc>
lea    0xe4c(%rip),%rsi
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [34 x i8] c"E: poorly formatted varbind list\0A\00"
@.str.1 = [33 x i8] c"W: %d bytes follow varbind list\0A\00"
@.str.2 = [32 x i8] c"E: bad trap varbind in message\0A\00"
@.str.3 = [28 x i8] c"E: bad varbinds in message\0A\00"
define i32 @parse_varbind_list(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%11 = load i8*, i8** %7
store i8* %11, i8** %10
%12 = call i64 @unpack_tagcls(i8** %6, i8** %10, i32 48)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %4
%15 = load i32, i32* @stderr
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %58
17: ; preds = %4
%18 = load i8*, i8** %10
%19 = load i8*, i8** %7
%20 = icmp ult i8* %18, %19
br i1 %20, label %21, label %31
21: ; preds = %17
%22 = load i32, i32* @stderr
%23 = load i8*, i8** %7
%24 = load i8*, i8** %10
%25 = ptrtoint i8* %23 to i64
%26 = ptrtoint i8* %24 to i64
%27 = sub i64 %25, %26
%28 = trunc i64 %27 to i32
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %28)
%30 = load i8*, i8** %10
store i8* %30, i8** %7
br label %31
31: ; preds = %21, %17
%32 = load i32, i32* %8
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %46
34: ; preds = %31
%35 = load i32, i32* %9
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %46
37: ; preds = %34
%38 = load i8*, i8** %6
%39 = load i32, i32* %8
%40 = call i32 @parse_trap(i8* %38, i8** %10, i32 %39)
store i32 %40, i32* %9
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %45
42: ; preds = %37
%43 = load i32, i32* @stderr
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %58
45: ; preds = %37
br label %46
46: ; preds = %45, %34, %31
%47 = load i8*, i8** %10
store i8* %47, i8** %6
%48 = load i8*, i8** %7
store i8* %48, i8** %10
%49 = load i8*, i8** %6
%50 = load i8*, i8** %10
%51 = load i32, i32* %9
%52 = call i64 @parse_varbinds(i8* %49, i8* %50, i32 %51)
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %46
%55 = load i32, i32* @stderr
%56 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
br label %58
57: ; preds = %46
store i32 0, i32* %5
br label %59
58: ; preds = %54, %42, %14
store i32 -1, i32* %5
br label %59
59: ; preds = %58, %57
%60 = load i32, i32* %5
ret i32 %60
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [34 x i8] c"E: poorly formatted varbind list\0A\00"
@.str.1 = [33 x i8] c"W: %d bytes follow varbind list\0A\00"
@.str.2 = [32 x i8] c"E: bad trap varbind in message\0A\00"
@.str.3 = [28 x i8] c"E: bad varbinds in message\0A\00"
define i32 @parse_varbind_list(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %5
%7 = bitcast i8** %6 to i8*
store i8* %1, i8** %6
%8 = call i64 @unpack_tagcls(i8** %5, i8** %6, i32 48)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %38
10: ; preds = %4
%11 = load i8*, i8** %6
%12 = icmp ult i8* %11, %1
br i1 %12, label %13, label %21
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = ptrtoint i8* %1 to i64
%16 = ptrtoint i8* %11 to i64
%17 = sub i64 %15, %16
%18 = trunc i64 %17 to i32
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = load i8*, i8** %6
br label %21
21: ; preds = %13, %10
%22 = phi i8* [ %20, %13 ], [ %11, %10 ]
%23 = phi i8* [ %20, %13 ], [ %1, %10 ]
%24 = icmp ne i32 %2, 0
%25 = icmp eq i32 %3, -1
%26 = and i1 %24, %25
br i1 %26, label %27, label %33
27: ; preds = %21
%28 = load i8*, i8** %5
%29 = call i32 @parse_trap(i8* %28, i8** %6, i32 %2)
%30 = icmp eq i32 %29, -1
br i1 %30, label %38, label %31
31: ; preds = %27
%32 = load i8*, i8** %6
br label %33
33: ; preds = %31, %21
%34 = phi i8* [ %32, %31 ], [ %22, %21 ]
%35 = phi i32 [ %29, %31 ], [ %3, %21 ]
store i8* %34, i8** %5
store i8* %23, i8** %6
%36 = call i64 @parse_varbinds(i8* %34, i8* %23, i32 %35)
%37 = icmp eq i64 %36, 0
br i1 %37, label %42, label %38
38: ; preds = %33, %27, %4
%39 = phi i8* [ getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), %4 ], [ getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), %27 ], [ getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), %33 ]
%40 = load i32, i32* @stderr
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* %39)
br label %42
42: ; preds = %38, %33
%43 = phi i32 [ 0, %33 ], [ -1, %38 ]
ret i32 %43
}