#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_pptp(struct Seaper *, struct NetFrame *,
                                unsigned char const *, unsigned int);
void process_gre_pptp(struct Seaper *seap, struct NetFrame *frame,
                      const unsigned char *px, unsigned length) {
  unsigned flags;
  unsigned offset;
  unsigned payload_length;
  unsigned call_id;
  unsigned sequence_number;
  unsigned acknowledgement_number;
  flags =
      (*((unsigned char *)(px) + 0) << 8 | *((unsigned char *)(px) + 1) << 0);
  payload_length = (*((unsigned char *)(px + 4) + 0) << 8 |
                    *((unsigned char *)(px + 4) + 1) << 0);
  call_id = (*((unsigned char *)(px + 6) + 0) << 8 |
             *((unsigned char *)(px + 6) + 1) << 0);
  if ((flags & 0xE80F) != 0x2001) {
    FRAMERR(frame, "%s: unknown value: 0x%x (%d)\n", "gre", flags, flags);
    ;
    return;
  }
  offset = 8;
  if (flags & 0x1000) {
    sequence_number = (*((unsigned char *)(px + offset) + 0) << 24 |
                       *((unsigned char *)(px + offset) + 1) << 16 |
                       *((unsigned char *)(px + offset) + 2) << 8 |
                       *((unsigned char *)(px + offset) + 3) << 0);
    offset += 4;
  }
  if (flags & 0x0080) {
    acknowledgement_number = (*((unsigned char *)(px + offset) + 0) << 24 |
                              *((unsigned char *)(px + offset) + 1) << 16 |
                              *((unsigned char *)(px + offset) + 2) << 8 |
                              *((unsigned char *)(px + offset) + 3) << 0);
    offset += 4;
  }
  if (offset >= length) {
    FRAMERR(frame, "%s: truncated\n", "gre");
    ;
    return;
  }
  process_pptp(seap, frame, px + offset, length - offset);
}


x86 assembly (clang, -O0):
<process_gre_pptp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%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    -0x18(%rbp),%rax
movzbl 0x4(%rax),%eax
shl    $0x8,%eax
mov    -0x18(%rbp),%rcx
movzbl 0x5(%rcx),%ecx
shl    $0x0,%ecx
or     %ecx,%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movzbl 0x6(%rax),%eax
shl    $0x8,%eax
mov    -0x18(%rbp),%rcx
movzbl 0x7(%rcx),%ecx
shl    $0x0,%ecx
or     %ecx,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%eax
and    $0xe80f,%eax
cmp    $0x2001,%eax
je     11bf <process_gre_pptp+0x9f>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%ecx
mov    -0x20(%rbp),%r8d
lea    0xe54(%rip),%rsi
lea    0xe6b(%rip),%rdx
mov    $0x0,%al
call   1030 <FRAMERR@plt>
jmp    12c9 <process_gre_pptp+0x1a9>
movl   $0x8,-0x24(%rbp)
mov    -0x20(%rbp),%eax
and    $0x1000,%eax
cmp    $0x0,%eax
je     1224 <process_gre_pptp+0x104>
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
movzbl (%rax,%rcx,1),%eax
shl    $0x18,%eax
mov    -0x18(%rbp),%rcx
mov    -0x24(%rbp),%edx
movzbl 0x1(%rcx,%rdx,1),%ecx
shl    $0x10,%ecx
or     %ecx,%eax
mov    -0x18(%rbp),%rcx
mov    -0x24(%rbp),%edx
movzbl 0x2(%rcx,%rdx,1),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    -0x18(%rbp),%rcx
mov    -0x24(%rbp),%edx
movzbl 0x3(%rcx,%rdx,1),%ecx
shl    $0x0,%ecx
or     %ecx,%eax
mov    %eax,-0x30(%rbp)
mov    -0x24(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
je     1282 <process_gre_pptp+0x162>
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
movzbl (%rax,%rcx,1),%eax
shl    $0x18,%eax
mov    -0x18(%rbp),%rcx
mov    -0x24(%rbp),%edx
movzbl 0x1(%rcx,%rdx,1),%ecx
shl    $0x10,%ecx
or     %ecx,%eax
mov    -0x18(%rbp),%rcx
mov    -0x24(%rbp),%edx
movzbl 0x2(%rcx,%rdx,1),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    -0x18(%rbp),%rcx
mov    -0x24(%rbp),%edx
movzbl 0x3(%rcx,%rdx,1),%ecx
shl    $0x0,%ecx
or     %ecx,%eax
mov    %eax,-0x34(%rbp)
mov    -0x24(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jb     12ac <process_gre_pptp+0x18c>
mov    -0x10(%rbp),%rdi
lea    0xd89(%rip),%rsi
lea    0xd7e(%rip),%rdx
mov    $0x0,%al
call   1030 <FRAMERR@plt>
jmp    12c9 <process_gre_pptp+0x1a9>
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    $0x40,%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    1187 <process_gre_pptp+0x67>
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
xor    %eax,%eax
jmp    1030 <FRAMERR@plt>
lea    0xe94(%rip),%rax
lea    0xe89(%rip),%rdx
mov    %rsi,%rdi
mov    %rax,%rsi
xor    %eax,%eax
jmp    1030 <FRAMERR@plt>

LLVM IR (-O0):
%struct.Seaper = 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"
@.str.2 = [15 x i8] c"%s: truncated\0A\00"
define void @process_gre_pptp(%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
%13 = alloca i32
%14 = 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
%15 = load i8*, i8** %7
%16 = getelementptr inbounds i8, i8* %15, i64 0
%17 = load i8, i8* %16
%18 = zext i8 %17 to i32
%19 = shl i32 %18, 8
%20 = load i8*, i8** %7
%21 = getelementptr inbounds i8, i8* %20, i64 1
%22 = load i8, i8* %21
%23 = zext i8 %22 to i32
%24 = shl i32 %23, 0
%25 = or i32 %19, %24
store i32 %25, i32* %9
%26 = load i8*, i8** %7
%27 = getelementptr inbounds i8, i8* %26, i64 4
%28 = getelementptr inbounds i8, i8* %27, i64 0
%29 = load i8, i8* %28
%30 = zext i8 %29 to i32
%31 = shl i32 %30, 8
%32 = load i8*, i8** %7
%33 = getelementptr inbounds i8, i8* %32, i64 4
%34 = getelementptr inbounds i8, i8* %33, i64 1
%35 = load i8, i8* %34
%36 = zext i8 %35 to i32
%37 = shl i32 %36, 0
%38 = or i32 %31, %37
store i32 %38, i32* %11
%39 = load i8*, i8** %7
%40 = getelementptr inbounds i8, i8* %39, i64 6
%41 = getelementptr inbounds i8, i8* %40, i64 0
%42 = load i8, i8* %41
%43 = zext i8 %42 to i32
%44 = shl i32 %43, 8
%45 = load i8*, i8** %7
%46 = getelementptr inbounds i8, i8* %45, i64 6
%47 = getelementptr inbounds i8, i8* %46, i64 1
%48 = load i8, i8* %47
%49 = zext i8 %48 to i32
%50 = shl i32 %49, 0
%51 = or i32 %44, %50
store i32 %51, i32* %12
%52 = load i32, i32* %9
%53 = and i32 %52, 59407
%54 = icmp ne i32 %53, 8193
br i1 %54, label %55, label %60
55: ; preds = %4
%56 = load %struct.NetFrame*, %struct.NetFrame** %6
%57 = load i32, i32* %9
%58 = load i32, i32* %9
%59 = call i32 (%struct.NetFrame*, i8*, i8*, ...) @FRAMERR(%struct.NetFrame* %56, 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 %57, i32 %58)
br label %162
60: ; preds = %4
store i32 8, i32* %10
%61 = load i32, i32* %9
%62 = and i32 %61, 4096
%63 = icmp ne i32 %62, 0
br i1 %63, label %64, label %102
64: ; preds = %60
%65 = load i8*, i8** %7
%66 = load i32, i32* %10
%67 = zext i32 %66 to i64
%68 = getelementptr inbounds i8, i8* %65, i64 %67
%69 = getelementptr inbounds i8, i8* %68, i64 0
%70 = load i8, i8* %69
%71 = zext i8 %70 to i32
%72 = shl i32 %71, 24
%73 = load i8*, i8** %7
%74 = load i32, i32* %10
%75 = zext i32 %74 to i64
%76 = getelementptr inbounds i8, i8* %73, i64 %75
%77 = getelementptr inbounds i8, i8* %76, i64 1
%78 = load i8, i8* %77
%79 = zext i8 %78 to i32
%80 = shl i32 %79, 16
%81 = or i32 %72, %80
%82 = load i8*, i8** %7
%83 = load i32, i32* %10
%84 = zext i32 %83 to i64
%85 = getelementptr inbounds i8, i8* %82, i64 %84
%86 = getelementptr inbounds i8, i8* %85, i64 2
%87 = load i8, i8* %86
%88 = zext i8 %87 to i32
%89 = shl i32 %88, 8
%90 = or i32 %81, %89
%91 = load i8*, i8** %7
%92 = load i32, i32* %10
%93 = zext i32 %92 to i64
%94 = getelementptr inbounds i8, i8* %91, i64 %93
%95 = getelementptr inbounds i8, i8* %94, i64 3
%96 = load i8, i8* %95
%97 = zext i8 %96 to i32
%98 = shl i32 %97, 0
%99 = or i32 %90, %98
store i32 %99, i32* %13
%100 = load i32, i32* %10
%101 = add i32 %100, 4
store i32 %101, i32* %10
br label %102
102: ; preds = %64, %60
%103 = load i32, i32* %9
%104 = and i32 %103, 128
%105 = icmp ne i32 %104, 0
br i1 %105, label %106, label %144
106: ; preds = %102
%107 = load i8*, i8** %7
%108 = load i32, i32* %10
%109 = zext i32 %108 to i64
%110 = getelementptr inbounds i8, i8* %107, i64 %109
%111 = getelementptr inbounds i8, i8* %110, i64 0
%112 = load i8, i8* %111
%113 = zext i8 %112 to i32
%114 = shl i32 %113, 24
%115 = load i8*, i8** %7
%116 = load i32, i32* %10
%117 = zext i32 %116 to i64
%118 = getelementptr inbounds i8, i8* %115, i64 %117
%119 = getelementptr inbounds i8, i8* %118, i64 1
%120 = load i8, i8* %119
%121 = zext i8 %120 to i32
%122 = shl i32 %121, 16
%123 = or i32 %114, %122
%124 = load i8*, i8** %7
%125 = load i32, i32* %10
%126 = zext i32 %125 to i64
%127 = getelementptr inbounds i8, i8* %124, i64 %126
%128 = getelementptr inbounds i8, i8* %127, i64 2
%129 = load i8, i8* %128
%130 = zext i8 %129 to i32
%131 = shl i32 %130, 8
%132 = or i32 %123, %131
%133 = load i8*, i8** %7
%134 = load i32, i32* %10
%135 = zext i32 %134 to i64
%136 = getelementptr inbounds i8, i8* %133, i64 %135
%137 = getelementptr inbounds i8, i8* %136, i64 3
%138 = load i8, i8* %137
%139 = zext i8 %138 to i32
%140 = shl i32 %139, 0
%141 = or i32 %132, %140
store i32 %141, i32* %14
%142 = load i32, i32* %10
%143 = add i32 %142, 4
store i32 %143, i32* %10
br label %144
144: ; preds = %106, %102
%145 = load i32, i32* %10
%146 = load i32, i32* %8
%147 = icmp uge i32 %145, %146
br i1 %147, label %148, label %151
148: ; preds = %144
%149 = load %struct.NetFrame*, %struct.NetFrame** %6
%150 = call i32 (%struct.NetFrame*, i8*, i8*, ...) @FRAMERR(%struct.NetFrame* %149, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %162
151: ; preds = %144
%152 = load %struct.Seaper*, %struct.Seaper** %5
%153 = load %struct.NetFrame*, %struct.NetFrame** %6
%154 = load i8*, i8** %7
%155 = load i32, i32* %10
%156 = zext i32 %155 to i64
%157 = getelementptr inbounds i8, i8* %154, i64 %156
%158 = load i32, i32* %8
%159 = load i32, i32* %10
%160 = sub i32 %158, %159
%161 = call i32 @process_pptp(%struct.Seaper* %152, %struct.NetFrame* %153, i8* %157, i32 %160)
br label %162
162: ; preds = %151, %148, %55
ret void
}

LLVM IR (-O2):
%struct.Seaper = 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"
@.str.2 = [15 x i8] c"%s: truncated\0A\00"
define void @process_gre_pptp(%struct.Seaper* %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 (%struct.NetFrame*, i8*, i8*, ...) @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 %32
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 %27, label %25
25: ; preds = %16
%26 = tail call i32 (%struct.NetFrame*, i8*, i8*, ...) @FRAMERR(%struct.NetFrame* %1, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %32
27: ; preds = %16
%28 = zext i32 %23 to i64
%29 = getelementptr inbounds i8, i8* %2, i64 %28
%30 = sub i32 %3, %23
%31 = tail call i32 @process_pptp(%struct.Seaper* %0, %struct.NetFrame* %1, i8* %29, i32 %30)
br label %32
32: ; preds = %27, %25, %14
ret void
}