#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 scalar_t__ uint;

/* Variables and functions */
int /*<<< orphan*/ dump_pdu(int /*<<< orphan*/, unsigned char *,
                            unsigned char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
scalar_t__ unpack_taglen(unsigned char **, unsigned char **, scalar_t__ *,
                         unsigned char *);
int unpack_long_tag_and_class(unsigned char **p, unsigned char **e, uint tag,
                              unsigned char cls) {
  unsigned char mycls;
  uint mytag;
  if (unpack_taglen(p, e, &mytag, &mycls)) {
    fprintf(stderr, "E: could not extract tag and class\n");
    return (-1);
  }
  if ((mycls & 0xe0) == cls && (mytag == tag))
    return (0);
  fprintf(stderr, "E: got tag %x, expected %x\n", (uint)mytag, (uint)tag);
  fprintf(stderr, "E: got cls %x, expected %x\n", (uint)mycls, (uint)cls);
  dump_pdu(stderr, *p, *e);
  return (1);
}


x86 assembly (clang, -O0):
<unpack_long_tag_and_class>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %cl,%al
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %al,-0x21(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x30(%rbp),%rdx
lea    -0x22(%rbp),%rcx
call   1030 <unpack_taglen@plt>
cmp    $0x0,%rax
je     118b <unpack_long_tag_and_class+0x5b>
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
lea    0xe88(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    121f <unpack_long_tag_and_class+0xef>
movzbl -0x22(%rbp),%eax
and    $0xe0,%eax
movzbl -0x21(%rbp),%ecx
cmp    %ecx,%eax
jne    11ba <unpack_long_tag_and_class+0x8a>
mov    -0x30(%rbp),%rax
cmp    -0x20(%rbp),%rax
jne    11ba <unpack_long_tag_and_class+0x8a>
movl   $0x0,-0x4(%rbp)
jmp    121f <unpack_long_tag_and_class+0xef>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xe52(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
movzbl -0x22(%rbp),%eax
mov    %eax,%edx
movzbl -0x21(%rbp),%eax
mov    %eax,%ecx
lea    0xe4b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x18(%rbp),%rax
mov    (%rax),%rdx
call   1050 <dump_pdu@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unpack_long_tag_and_class>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %ecx,%r15d
mov    %rdx,%rbp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x8(%rsp),%rdx
lea    0x7(%rsp),%rcx
call   1030 <unpack_taglen@plt>
test   %rax,%rax
je     117a <unpack_long_tag_and_class+0x4a>
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
lea    0xe94(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    11dc <unpack_long_tag_and_class+0xac>
mov    0x7(%rsp),%al
and    $0xe0,%al
mov    0x8(%rsp),%rdx
cmp    %r15b,%al
jne    1191 <unpack_long_tag_and_class+0x61>
xor    %eax,%eax
cmp    %rbp,%rdx
je     11dc <unpack_long_tag_and_class+0xac>
mov    0x2e48(%rip),%r12
mov    (%r12),%edi
lea    0xe81(%rip),%rsi
mov    %rbp,%rcx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r12),%edi
movzbl 0x7(%rsp),%edx
movzbl %r15b,%ecx
lea    0xe7f(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r12),%edi
mov    (%rbx),%rsi
mov    (%r14),%rdx
call   1050 <dump_pdu@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [36 x i8] c"E: could not extract tag and class\0A\00"
@.str.1 = [28 x i8] c"E: got tag %x, expected %x\0A\00"
@.str.2 = [28 x i8] c"E: got cls %x, expected %x\0A\00"
define i32 @unpack_long_tag_and_class(i8** %0, i8** %1, i64 %2, i8 zeroext %3) {
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i64
%9 = alloca i8
%10 = alloca i8
%11 = alloca i64
store i8** %0, i8*** %6
store i8** %1, i8*** %7
store i64 %2, i64* %8
store i8 %3, i8* %9
%12 = load i8**, i8*** %6
%13 = load i8**, i8*** %7
%14 = call i64 @unpack_taglen(i8** %12, i8** %13, i64* %11, i8* %10)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %4
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %5
br label %48
19: ; preds = %4
%20 = load i8, i8* %10
%21 = zext i8 %20 to i32
%22 = and i32 %21, 224
%23 = load i8, i8* %9
%24 = zext i8 %23 to i32
%25 = icmp eq i32 %22, %24
br i1 %25, label %26, label %31
26: ; preds = %19
%27 = load i64, i64* %11
%28 = load i64, i64* %8
%29 = icmp eq i64 %27, %28
br i1 %29, label %30, label %31
30: ; preds = %26
store i32 0, i32* %5
br label %48
31: ; preds = %26, %19
%32 = load i32, i32* @stderr
%33 = load i64, i64* %11
%34 = load i64, i64* %8
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i64 %33, i64 %34)
%36 = load i32, i32* @stderr
%37 = load i8, i8* %10
%38 = zext i8 %37 to i64
%39 = load i8, i8* %9
%40 = zext i8 %39 to i64
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i64 %38, i64 %40)
%42 = load i32, i32* @stderr
%43 = load i8**, i8*** %6
%44 = load i8*, i8** %43
%45 = load i8**, i8*** %7
%46 = load i8*, i8** %45
%47 = call i32 @dump_pdu(i32 %42, i8* %44, i8* %46)
store i32 1, i32* %5
br label %48
48: ; preds = %31, %30, %16
%49 = load i32, i32* %5
ret i32 %49
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [36 x i8] c"E: could not extract tag and class\0A\00"
@.str.1 = [28 x i8] c"E: got tag %x, expected %x\0A\00"
@.str.2 = [28 x i8] c"E: got cls %x, expected %x\0A\00"
define i32 @unpack_long_tag_and_class(i8** %0, i8** %1, i64 %2, i8 zeroext %3) {
%5 = alloca i8
%6 = alloca i64
%7 = bitcast i64* %6 to i8*
%8 = call i64 @unpack_taglen(i8** %0, i8** %1, i64* %6, i8* %5)
%9 = icmp eq i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %4
%11 = load i32, i32* @stderr
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %32
13: ; preds = %4
%14 = load i8, i8* %5
%15 = and i8 %14, -32
%16 = icmp eq i8 %15, %3
%17 = load i64, i64* %6
%18 = icmp eq i64 %17, %2
%19 = select i1 %16, i1 %18, i1 false
br i1 %19, label %32, label %20
20: ; preds = %13
%21 = load i32, i32* @stderr
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i64 %17, i64 %2)
%23 = load i32, i32* @stderr
%24 = load i8, i8* %5
%25 = zext i8 %24 to i64
%26 = zext i8 %3 to i64
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i64 %25, i64 %26)
%28 = load i32, i32* @stderr
%29 = load i8*, i8** %0
%30 = load i8*, i8** %1
%31 = call i32 @dump_pdu(i32 %28, i8* %29, i8* %30)
br label %32
32: ; preds = %13, %20, %10
%33 = phi i32 [ -1, %10 ], [ 1, %20 ], [ 0, %13 ]
ret i32 %33
}