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

/* Variables and functions */
int /*<<< orphan*/ FRAMERR(struct NetFrame *, char *, char *, unsigned int,
                           unsigned int);
int /*<<< orphan*/ process_pptp(struct Ferret *, struct NetFrame *,
                                unsigned char const *, unsigned int);
void process_gre_pptp(struct Ferret *ferret, struct NetFrame *frame,
                      const unsigned char *px, unsigned length) {
  unsigned flags;
  unsigned offset;
  flags =
      (*((unsigned char *)(px) + 0) << 8 | *((unsigned char *)(px) + 1) << 0);
  if ((flags & 0xE80F) != 0x2001) {
    FRAMERR(frame, "%s: unknown value: 0x%x (%d)\n", "gre", flags, flags);
    ;
    return;
  }
  offset = 8;
  if (flags & 0x1000) {
    offset += 4;
  }
  if (flags & 0x0080) {
    offset += 4;
  }
  if (offset >= length) {
    return;
  }
  process_pptp(ferret, frame, px + offset, length - offset);
}


x86 assembly (clang, -O0):
<process_gre_pptp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
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    -0x20(%rbp),%eax
and    $0xe80f,%eax
cmp    $0x2001,%eax
je     1187 <process_gre_pptp+0x67>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%ecx
mov    -0x20(%rbp),%r8d
lea    0xe8a(%rip),%rsi
lea    0xea1(%rip),%rdx
call   1030 <FRAMERR@plt>
jmp    11f0 <process_gre_pptp+0xd0>
movl   $0x8,-0x24(%rbp)
mov    -0x20(%rbp),%eax
and    $0x1000,%eax
cmp    $0x0,%eax
je     11a8 <process_gre_pptp+0x88>
mov    -0x24(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
je     11c2 <process_gre_pptp+0xa2>
mov    -0x24(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jb     11d3 <process_gre_pptp+0xb3>
jmp    11f0 <process_gre_pptp+0xd0>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x24(%rbp),%eax
add    %rax,%rdx
mov    -0x1c(%rbp),%ecx
sub    -0x24(%rbp),%ecx
call   1040 <process_pptp@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_gre_pptp>:
movzbl (%rdx),%r10d
mov    %r10d,%r8d
shl    $0x8,%r8d
movzbl 0x1(%rdx),%r9d
or     %r9d,%r8d
mov    %r8d,%eax
and    $0xe80f,%eax
cmp    $0x2001,%eax
jne    1169 <process_gre_pptp+0x49>
and    $0x10,%r10d
shr    $0x2,%r10d
shr    $0x7,%r9d
lea    (%r10,%r9,4),%r8d
add    $0x8,%r8d
cmp    %ecx,%r8d
jae    1185 <process_gre_pptp+0x65>
mov    %r8d,%eax
add    %rax,%rdx
sub    %r8d,%ecx
jmp    1040 <process_pptp@plt>
lea    0xe90(%rip),%rax
lea    0xea7(%rip),%rdx
mov    %rsi,%rdi
mov    %rax,%rsi
mov    %r8d,%ecx
jmp    1030 <FRAMERR@plt>
ret

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

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