#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 *, ...);
int /*<<< orphan*/ dispatch_ethertype(struct Ferret *, struct NetFrame *,
                                      unsigned char const *, unsigned int,
                                      unsigned int, unsigned int);
int /*<<< orphan*/ process_cisco00000c(struct Ferret *, struct NetFrame *,
                                       unsigned char const *, unsigned int);
void process_snap_frame(struct Ferret *ferret, struct NetFrame *frame,
                        const unsigned char *px, unsigned length) {
  unsigned offset = 0;
  unsigned oui;
  unsigned ethertype;
  if (length < 5) {
    FRAMERR(frame, "%s: truncated\n", "SNAP");
    ;
    return;
  }
  oui = (*((unsigned char *)(px) + 0) << 16 |
         *((unsigned char *)(px) + 1) << 8 | *((unsigned char *)(px) + 2) << 0);
  ethertype = (*((unsigned char *)(px + 3) + 0) << 8 |
               *((unsigned char *)(px + 3) + 1) << 0);
  switch (oui) {
  case 0x000000:
    break;
  case 0x004096:
    FRAMERR(frame, "Unknown SAP OUI: 0x%06x\n", oui);
    return;
    break;
  case 0x00000c:
    offset += 3;
    process_cisco00000c(ferret, frame, px + offset, length - offset);
    return;
  case 0x080007:
    break;
  default:
    FRAMERR(frame, "Unknown SAP OUI: 0x%06x\n", oui);
    return;
  }
  dispatch_ethertype(ferret, frame, px + offset, length - offset, oui,
                     ethertype);
}


x86 assembly (clang, -O0):
<process_snap_frame>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x5,-0x1c(%rbp)
jae    1176 <process_snap_frame+0x46>
mov    -0x10(%rbp),%rdi
lea    0xe9d(%rip),%rsi
lea    0xea5(%rip),%rdx
mov    $0x0,%al
call   1040 <FRAMERR@plt>
jmp    127a <process_snap_frame+0x14a>
mov    -0x18(%rbp),%rcx
movzbl (%rcx),%eax
shl    $0x10,%eax
movzbl 0x1(%rcx),%edx
shl    $0x8,%edx
or     %edx,%eax
movzbl 0x2(%rcx),%ecx
or     %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
movzwl 0x3(%rax),%eax
shl    $0x10,%eax
bswap  %eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x2c(%rbp)
test   %eax,%eax
je     11ec <process_snap_frame+0xbc>
jmp    11b5 <process_snap_frame+0x85>
mov    -0x2c(%rbp),%eax
sub    $0xc,%eax
je     120b <process_snap_frame+0xdb>
jmp    11c6 <process_snap_frame+0x96>
mov    -0x2c(%rbp),%eax
sub    $0x4096,%eax
je     11f1 <process_snap_frame+0xc1>
jmp    11d9 <process_snap_frame+0xa9>
mov    -0x2c(%rbp),%eax
sub    $0x80007,%eax
je     1236 <process_snap_frame+0x106>
jmp    123b <process_snap_frame+0x10b>
jmp    1255 <process_snap_frame+0x125>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xe15(%rip),%rsi
mov    $0x0,%al
call   1040 <FRAMERR@plt>
jmp    127a <process_snap_frame+0x14a>
mov    -0x20(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%eax
add    %rax,%rdx
mov    -0x1c(%rbp),%ecx
sub    -0x20(%rbp),%ecx
call   1050 <process_cisco00000c@plt>
jmp    127a <process_snap_frame+0x14a>
jmp    1255 <process_snap_frame+0x125>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xdcb(%rip),%rsi
mov    $0x0,%al
call   1040 <FRAMERR@plt>
jmp    127a <process_snap_frame+0x14a>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%eax
add    %rax,%rdx
mov    -0x1c(%rbp),%ecx
sub    -0x20(%rbp),%ecx
mov    -0x24(%rbp),%r8d
mov    -0x28(%rbp),%r9d
call   1030 <dispatch_ethertype@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_snap_frame>:
cmp    $0x4,%ecx
ja     1150 <process_snap_frame+0x20>
lea    0xec4(%rip),%rax
lea    0xecc(%rip),%rdx
mov    %rsi,%rdi
mov    %rax,%rsi
xor    %eax,%eax
jmp    1040 <FRAMERR@plt>
movzbl (%rdx),%r8d
shl    $0x10,%r8d
movzbl 0x1(%rdx),%eax
shl    $0x8,%eax
or     %r8d,%eax
movzbl 0x2(%rdx),%r8d
or     %eax,%r8d
cmp    $0x4095,%r8d
jg     118a <process_snap_frame+0x5a>
test   %r8d,%r8d
je     11b5 <process_snap_frame+0x85>
cmp    $0xc,%r8d
jne    11c6 <process_snap_frame+0x96>
add    $0x3,%rdx
add    $0xfffffffd,%ecx
jmp    1050 <process_cisco00000c@plt>
cmp    $0x80007,%r8d
je     11b5 <process_snap_frame+0x85>
cmp    $0x4096,%r8d
jne    11c6 <process_snap_frame+0x96>
lea    0xe71(%rip),%rax
mov    %rsi,%rdi
mov    %rax,%rsi
mov    $0x4096,%edx
xor    %eax,%eax
jmp    1040 <FRAMERR@plt>
movzwl 0x3(%rdx),%r9d
shl    $0x10,%r9d
bswap  %r9d
jmp    1030 <dispatch_ethertype@plt>
lea    0xe47(%rip),%rax
mov    %rsi,%rdi
mov    %rax,%rsi
mov    %r8d,%edx
xor    %eax,%eax
jmp    1040 <FRAMERR@plt>

LLVM IR (-O0):
%struct.Ferret = type { i32 }
%struct.NetFrame = type { i32 }
@.str = [15 x i8] c"%s: truncated\0A\00"
@.str.1 = [5 x i8] c"SNAP\00"
@.str.2 = [25 x i8] c"Unknown SAP OUI: 0x%06x\0A\00"
define void @process_snap_frame(%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
%11 = 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
store i32 0, i32* %9
%12 = load i32, i32* %8
%13 = icmp ult i32 %12, 5
br i1 %13, label %14, label %17
14: ; preds = %4
%15 = load %struct.NetFrame*, %struct.NetFrame** %6
%16 = call i32 (%struct.NetFrame*, i8*, ...) @FRAMERR(%struct.NetFrame* %15, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %85
17: ; preds = %4
%18 = load i8*, i8** %7
%19 = getelementptr inbounds i8, i8* %18, i64 0
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = shl i32 %21, 16
%23 = load i8*, i8** %7
%24 = getelementptr inbounds i8, i8* %23, i64 1
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = shl i32 %26, 8
%28 = or i32 %22, %27
%29 = load i8*, i8** %7
%30 = getelementptr inbounds i8, i8* %29, i64 2
%31 = load i8, i8* %30
%32 = zext i8 %31 to i32
%33 = shl i32 %32, 0
%34 = or i32 %28, %33
store i32 %34, i32* %10
%35 = load i8*, i8** %7
%36 = getelementptr inbounds i8, i8* %35, i64 3
%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 3
%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
%48 = load i32, i32* %10
switch i32 %48, label %68 [
i32 0, label %49
i32 16534, label %50
i32 12, label %54
i32 524295, label %67
]
49: ; preds = %17
br label %72
50: ; preds = %17
%51 = load %struct.NetFrame*, %struct.NetFrame** %6
%52 = load i32, i32* %10
%53 = call i32 (%struct.NetFrame*, i8*, ...) @FRAMERR(%struct.NetFrame* %51, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %52)
br label %85
54: ; preds = %17
%55 = load i32, i32* %9
%56 = add i32 %55, 3
store i32 %56, i32* %9
%57 = load %struct.Ferret*, %struct.Ferret** %5
%58 = load %struct.NetFrame*, %struct.NetFrame** %6
%59 = load i8*, i8** %7
%60 = load i32, i32* %9
%61 = zext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %59, i64 %61
%63 = load i32, i32* %8
%64 = load i32, i32* %9
%65 = sub i32 %63, %64
%66 = call i32 @process_cisco00000c(%struct.Ferret* %57, %struct.NetFrame* %58, i8* %62, i32 %65)
br label %85
67: ; preds = %17
br label %72
68: ; preds = %17
%69 = load %struct.NetFrame*, %struct.NetFrame** %6
%70 = load i32, i32* %10
%71 = call i32 (%struct.NetFrame*, i8*, ...) @FRAMERR(%struct.NetFrame* %69, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %70)
br label %85
72: ; preds = %67, %49
%73 = load %struct.Ferret*, %struct.Ferret** %5
%74 = load %struct.NetFrame*, %struct.NetFrame** %6
%75 = load i8*, i8** %7
%76 = load i32, i32* %9
%77 = zext i32 %76 to i64
%78 = getelementptr inbounds i8, i8* %75, i64 %77
%79 = load i32, i32* %8
%80 = load i32, i32* %9
%81 = sub i32 %79, %80
%82 = load i32, i32* %10
%83 = load i32, i32* %11
%84 = call i32 @dispatch_ethertype(%struct.Ferret* %73, %struct.NetFrame* %74, i8* %78, i32 %81, i32 %82, i32 %83)
br label %85
85: ; preds = %72, %68, %54, %50, %14
ret void
}

LLVM IR (-O2):
%struct.Ferret = type { i32 }
%struct.NetFrame = type { i32 }
@.str = [15 x i8] c"%s: truncated\0A\00"
@.str.1 = [5 x i8] c"SNAP\00"
@.str.2 = [25 x i8] c"Unknown SAP OUI: 0x%06x\0A\00"
define void @process_snap_frame(%struct.Ferret* %0, %struct.NetFrame* %1, i8* %2, i32 %3) {
%5 = icmp ult i32 %3, 5
br i1 %5, label %6, label %8
6: ; preds = %4
%7 = tail call i32 (%struct.NetFrame*, i8*, ...) @FRAMERR(%struct.NetFrame* %1, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %38
8: ; preds = %4
%9 = load i8, i8* %2
%10 = zext i8 %9 to i32
%11 = shl nuw nsw i32 %10, 16
%12 = getelementptr inbounds i8, i8* %2, i64 1
%13 = load i8, i8* %12
%14 = zext i8 %13 to i32
%15 = shl nuw nsw i32 %14, 8
%16 = or i32 %15, %11
%17 = getelementptr inbounds i8, i8* %2, i64 2
%18 = load i8, i8* %17
%19 = zext i8 %18 to i32
%20 = or i32 %16, %19
%21 = getelementptr inbounds i8, i8* %2, i64 3
switch i32 %20, label %27 [
i32 0, label %29
i32 16534, label %22
i32 12, label %24
i32 524295, label %29
]
22: ; preds = %8
%23 = tail call i32 (%struct.NetFrame*, i8*, ...) @FRAMERR(%struct.NetFrame* %1, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 16534)
br label %38
24: ; preds = %8
%25 = add i32 %3, -3
%26 = tail call i32 @process_cisco00000c(%struct.Ferret* %0, %struct.NetFrame* %1, i8* %21, i32 %25)
br label %38
27: ; preds = %8
%28 = tail call i32 (%struct.NetFrame*, i8*, ...) @FRAMERR(%struct.NetFrame* %1, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %20)
br label %38
29: ; preds = %8, %8
%30 = load i8, i8* %21
%31 = zext i8 %30 to i32
%32 = shl nuw nsw i32 %31, 8
%33 = getelementptr inbounds i8, i8* %2, i64 4
%34 = load i8, i8* %33
%35 = zext i8 %34 to i32
%36 = or i32 %32, %35
%37 = tail call i32 @dispatch_ethertype(%struct.Ferret* %0, %struct.NetFrame* %1, i8* %2, i32 %3, i32 %20, i32 %36)
br label %38
38: ; preds = %29, %27, %24, %22, %6
ret void
}