#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 */
struct Seaper {
  int dummy;
};
struct NetFrame {
  int dummy;
};
typedef scalar_t__ px;

/* Variables and functions */
int /*<<< orphan*/ FRAMERR(struct NetFrame *, char *, char *, ...);
int /*<<< orphan*/ process_gre_pptp(struct Seaper *, struct NetFrame *,
                                    unsigned char const *, unsigned int);
void process_gre(struct Seaper *seap, struct NetFrame *frame,
                 const unsigned char *px, unsigned length) {
  unsigned flags;
  unsigned version;
  unsigned protocol;
  unsigned offset;
  if (length < 8) {
    FRAMERR(frame, "%s: truncated\n", "gre");
    ;
    return;
  }
  flags =
      (*((unsigned char *)(px) + 0) << 8 | *((unsigned char *)(px) + 1) << 0);
  version = px[1] & 0x7;
  protocol = (*((unsigned char *)(px + 2) + 0) << 8 |
              *((unsigned char *)(px + 2) + 1) << 0);
  offset = 4;
  if (version == 1 && protocol == 0x880b)
    process_gre_pptp(seap, frame, px, length);
  else {
    FRAMERR(frame, "%s: unknown value: 0x%x (%d)\n", "gre", version, version);
    ;
  }
}


x86 assembly (clang, -O0):
<process_gre>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
cmpl   $0x8,-0x1c(%rbp)
jae    115f <process_gre+0x3f>
mov    -0x10(%rbp),%rdi
lea    0xeb4(%rip),%rsi
lea    0xebc(%rip),%rdx
mov    $0x0,%al
call   1030 <FRAMERR@plt>
jmp    11f9 <process_gre+0xd9>
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
shl    $0x8,%eax
mov    -0x18(%rbp),%rcx
movzbl 0x1(%rcx),%ecx
shl    $0x0,%ecx
or     %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movzbl 0x1(%rax),%eax
and    $0x7,%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
movzbl 0x2(%rax),%eax
shl    $0x8,%eax
mov    -0x18(%rbp),%rcx
movzbl 0x3(%rcx),%ecx
shl    $0x0,%ecx
or     %ecx,%eax
mov    %eax,-0x28(%rbp)
movl   $0x4,-0x2c(%rbp)
cmpl   $0x1,-0x24(%rbp)
jne    11d9 <process_gre+0xb9>
cmpl   $0x880b,-0x28(%rbp)
jne    11d9 <process_gre+0xb9>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1040 <process_gre_pptp@plt>
jmp    11f9 <process_gre+0xd9>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%ecx
mov    -0x24(%rbp),%r8d
lea    0xe28(%rip),%rsi
lea    0xe1d(%rip),%rdx
mov    $0x0,%al
call   1030 <FRAMERR@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_gre>:
cmp    $0x7,%ecx
ja     1140 <process_gre+0x20>
lea    0xed4(%rip),%rax
lea    0xedc(%rip),%rdx
mov    %rsi,%rdi
mov    %rax,%rsi
xor    %eax,%eax
jmp    1030 <FRAMERR@plt>
movzbl 0x1(%rdx),%r8d
and    $0x7,%r8d
cmp    $0x1,%r8b
jne    1164 <process_gre+0x44>
movzwl 0x2(%rdx),%eax
shl    $0x10,%eax
bswap  %eax
cmp    $0x880b,%eax
jne    1164 <process_gre+0x44>
jmp    1040 <process_gre_pptp@plt>
lea    0xea8(%rip),%rax
lea    0xe9d(%rip),%rdx
mov    %rsi,%rdi
mov    %rax,%rsi
mov    %r8d,%ecx
xor    %eax,%eax
jmp    1030 <FRAMERR@plt>

LLVM IR (-O0):
%struct.Seaper = type { i32 }
%struct.NetFrame = type { i32 }
@.str = [15 x i8] c"%s: truncated\0A\00"
@.str.1 = [4 x i8] c"gre\00"
@.str.2 = [30 x i8] c"%s: unknown value: 0x%x (%d)\0A\00"
define void @process_gre(%struct.Seaper* %0, %struct.NetFrame* %1, i8* %2, i32 %3) {
%5 = alloca %struct.Seaper*
%6 = alloca %struct.NetFrame*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store %struct.Seaper* %0, %struct.Seaper** %5
store %struct.NetFrame* %1, %struct.NetFrame** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%13 = load i32, i32* %8
%14 = icmp ult i32 %13, 8
br i1 %14, label %15, label %18
15: ; preds = %4
%16 = load %struct.NetFrame*, %struct.NetFrame** %6
%17 = call i32 (%struct.NetFrame*, i8*, i8*, ...) @FRAMERR(%struct.NetFrame* %16, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %64
18: ; preds = %4
%19 = load i8*, i8** %7
%20 = getelementptr inbounds i8, i8* %19, i64 0
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = shl i32 %22, 8
%24 = load i8*, i8** %7
%25 = getelementptr inbounds i8, i8* %24, i64 1
%26 = load i8, i8* %25
%27 = zext i8 %26 to i32
%28 = shl i32 %27, 0
%29 = or i32 %23, %28
store i32 %29, i32* %9
%30 = load i8*, i8** %7
%31 = getelementptr inbounds i8, i8* %30, i64 1
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
%34 = and i32 %33, 7
store i32 %34, i32* %10
%35 = load i8*, i8** %7
%36 = getelementptr inbounds i8, i8* %35, i64 2
%37 = getelementptr inbounds i8, i8* %36, i64 0
%38 = load i8, i8* %37
%39 = zext i8 %38 to i32
%40 = shl i32 %39, 8
%41 = load i8*, i8** %7
%42 = getelementptr inbounds i8, i8* %41, i64 2
%43 = getelementptr inbounds i8, i8* %42, i64 1
%44 = load i8, i8* %43
%45 = zext i8 %44 to i32
%46 = shl i32 %45, 0
%47 = or i32 %40, %46
store i32 %47, i32* %11
store i32 4, i32* %12
%48 = load i32, i32* %10
%49 = icmp eq i32 %48, 1
br i1 %49, label %50, label %59
50: ; preds = %18
%51 = load i32, i32* %11
%52 = icmp eq i32 %51, 34827
br i1 %52, label %53, label %59
53: ; preds = %50
%54 = load %struct.Seaper*, %struct.Seaper** %5
%55 = load %struct.NetFrame*, %struct.NetFrame** %6
%56 = load i8*, i8** %7
%57 = load i32, i32* %8
%58 = call i32 @process_gre_pptp(%struct.Seaper* %54, %struct.NetFrame* %55, i8* %56, i32 %57)
br label %64
59: ; preds = %50, %18
%60 = load %struct.NetFrame*, %struct.NetFrame** %6
%61 = load i32, i32* %10
%62 = load i32, i32* %10
%63 = call i32 (%struct.NetFrame*, i8*, i8*, ...) @FRAMERR(%struct.NetFrame* %60, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %61, i32 %62)
br label %64
64: ; preds = %15, %59, %53
ret void
}

LLVM IR (-O2):
%struct.Seaper = type { i32 }
%struct.NetFrame = type { i32 }
@.str = [15 x i8] c"%s: truncated\0A\00"
@.str.1 = [4 x i8] c"gre\00"
@.str.2 = [30 x i8] c"%s: unknown value: 0x%x (%d)\0A\00"
define void @process_gre(%struct.Seaper* %0, %struct.NetFrame* %1, i8* %2, i32 %3) {
%5 = icmp ult i32 %3, 8
br i1 %5, label %6, label %8
6: ; preds = %4
%7 = tail call i32 (%struct.NetFrame*, i8*, i8*, ...) @FRAMERR(%struct.NetFrame* %1, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %28
8: ; preds = %4
%9 = getelementptr inbounds i8, i8* %2, i64 1
%10 = load i8, i8* %9
%11 = and i8 %10, 7
%12 = getelementptr inbounds i8, i8* %2, i64 2
%13 = load i8, i8* %12
%14 = zext i8 %13 to i32
%15 = shl nuw nsw i32 %14, 8
%16 = getelementptr inbounds i8, i8* %2, i64 3
%17 = load i8, i8* %16
%18 = zext i8 %17 to i32
%19 = or i32 %15, %18
%20 = icmp eq i8 %11, 1
%21 = icmp eq i32 %19, 34827
%22 = select i1 %20, i1 %21, i1 false
br i1 %22, label %23, label %25
23: ; preds = %8
%24 = tail call i32 @process_gre_pptp(%struct.Seaper* %0, %struct.NetFrame* %1, i8* %2, i32 %3)
br label %28
25: ; preds = %8
%26 = zext i8 %11 to i32
%27 = tail call i32 (%struct.NetFrame*, i8*, i8*, ...) @FRAMERR(%struct.NetFrame* %1, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %26, i32 %26)
br label %28
28: ; preds = %23, %25, %6
ret void
}