#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 int /*<<< orphan*/ uint8_t;
typedef int uint32_t;
struct ip6_hdr {
  int dummy;
};
struct ip {
  int dummy;
};
struct ether_header {
  int /*<<< orphan*/ ether_type;
};

/* Variables and functions */
#define ETHERTYPE_IP 130
#define ETHERTYPE_IPV6 129
#define ETHERTYPE_VLAN 128
int decode_ip_n_hash(struct ip *, int /*<<< orphan*/, int /*<<< orphan*/);
int decode_ipv6_n_hash(struct ip6_hdr *, int /*<<< orphan*/,
                       int /*<<< orphan*/);
int decode_others_n_hash(struct ether_header *, int /*<<< orphan*/);
int decode_vlan_n_hash(struct ether_header *, int /*<<< orphan*/,
                       int /*<<< orphan*/);
int ntohs(int /*<<< orphan*/);
uint32_t pkt_hdr_hash(const unsigned char *buffer, uint8_t hash_split,
                      uint8_t seed) {
  (void)0;
  int rc = 0;
  struct ether_header *ethh = (struct ether_header *)buffer;
  switch (ntohs(ethh->ether_type)) {
  case ETHERTYPE_IP:
    rc = decode_ip_n_hash((struct ip *)(ethh + 1), hash_split, seed);
    break;
  case ETHERTYPE_IPV6:
    rc = decode_ipv6_n_hash((struct ip6_hdr *)(ethh + 1), hash_split, seed);
    break;
  case ETHERTYPE_VLAN:
    rc = decode_vlan_n_hash(ethh, hash_split, seed);
    break;
  default:
    rc = decode_others_n_hash(ethh, seed);
    break;
  }
  (void)0;
  return rc;
}


x86 assembly (clang, -O0):
<pkt_hdr_hash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
call   1040 <ntohs@plt>
mov    %eax,%ecx
mov    %ecx,-0x24(%rbp)
sub    $0x80,%eax
je     11ed <pkt_hdr_hash+0x9d>
jmp    1191 <pkt_hdr_hash+0x41>
mov    -0x24(%rbp),%eax
sub    $0x81,%eax
je     11d2 <pkt_hdr_hash+0x82>
jmp    11a4 <pkt_hdr_hash+0x54>
mov    -0x24(%rbp),%eax
sub    $0x82,%eax
jne    1204 <pkt_hdr_hash+0xb4>
jmp    11b7 <pkt_hdr_hash+0x67>
mov    -0x20(%rbp),%rdi
add    $0x4,%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1070 <decode_ip_n_hash@plt>
mov    %eax,-0x14(%rbp)
jmp    1213 <pkt_hdr_hash+0xc3>
mov    -0x20(%rbp),%rdi
add    $0x4,%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <decode_ipv6_n_hash@plt>
mov    %eax,-0x14(%rbp)
jmp    1213 <pkt_hdr_hash+0xc3>
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1060 <decode_vlan_n_hash@plt>
mov    %eax,-0x14(%rbp)
jmp    1213 <pkt_hdr_hash+0xc3>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1050 <decode_others_n_hash@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pkt_hdr_hash>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebx
mov    %esi,%r14d
mov    %rdi,%rbp
mov    (%rdi),%edi
call   1040 <ntohs@plt>
cmp    $0x80,%eax
je     118d <pkt_hdr_hash+0x3d>
cmp    $0x81,%eax
je     119e <pkt_hdr_hash+0x4e>
cmp    $0x82,%eax
jne    11b3 <pkt_hdr_hash+0x63>
add    $0x4,%rbp
mov    %rbp,%rdi
mov    %r14d,%esi
mov    %ebx,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1070 <decode_ip_n_hash@plt>
mov    %rbp,%rdi
mov    %r14d,%esi
mov    %ebx,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <decode_vlan_n_hash@plt>
add    $0x4,%rbp
mov    %rbp,%rdi
mov    %r14d,%esi
mov    %ebx,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <decode_ipv6_n_hash@plt>
mov    %rbp,%rdi
mov    %ebx,%esi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <decode_others_n_hash@plt>

LLVM IR (-O0):
%struct.ether_header = type { i32 }
%struct.ip = type { i32 }
%struct.ip6_hdr = type { i32 }
define i32 @pkt_hdr_hash(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.ether_header*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %7
%9 = load i8*, i8** %4
%10 = bitcast i8* %9 to %struct.ether_header*
store %struct.ether_header* %10, %struct.ether_header** %8
%11 = load %struct.ether_header*, %struct.ether_header** %8
%12 = getelementptr inbounds %struct.ether_header, %struct.ether_header* %11, i32 0, i32 0
%13 = load i32, i32* %12
%14 = call i32 @ntohs(i32 %13)
switch i32 %14, label %34 [
i32 130, label %15
i32 129, label %22
i32 128, label %29
]
15: ; preds = %3
%16 = load %struct.ether_header*, %struct.ether_header** %8
%17 = getelementptr inbounds %struct.ether_header, %struct.ether_header* %16, i64 1
%18 = bitcast %struct.ether_header* %17 to %struct.ip*
%19 = load i32, i32* %5
%20 = load i32, i32* %6
%21 = call i32 @decode_ip_n_hash(%struct.ip* %18, i32 %19, i32 %20)
store i32 %21, i32* %7
br label %38
22: ; preds = %3
%23 = load %struct.ether_header*, %struct.ether_header** %8
%24 = getelementptr inbounds %struct.ether_header, %struct.ether_header* %23, i64 1
%25 = bitcast %struct.ether_header* %24 to %struct.ip6_hdr*
%26 = load i32, i32* %5
%27 = load i32, i32* %6
%28 = call i32 @decode_ipv6_n_hash(%struct.ip6_hdr* %25, i32 %26, i32 %27)
store i32 %28, i32* %7
br label %38
29: ; preds = %3
%30 = load %struct.ether_header*, %struct.ether_header** %8
%31 = load i32, i32* %5
%32 = load i32, i32* %6
%33 = call i32 @decode_vlan_n_hash(%struct.ether_header* %30, i32 %31, i32 %32)
store i32 %33, i32* %7
br label %38
34: ; preds = %3
%35 = load %struct.ether_header*, %struct.ether_header** %8
%36 = load i32, i32* %6
%37 = call i32 @decode_others_n_hash(%struct.ether_header* %35, i32 %36)
store i32 %37, i32* %7
br label %38
38: ; preds = %34, %29, %22, %15
%39 = load i32, i32* %7
ret i32 %39
}

LLVM IR (-O2):
%struct.ether_header = type { i32 }
%struct.ip = type { i32 }
%struct.ip6_hdr = type { i32 }
define i32 @pkt_hdr_hash(i8* %0, i32 %1, i32 %2) {
%4 = bitcast i8* %0 to %struct.ether_header*
%5 = bitcast i8* %0 to i32*
%6 = load i32, i32* %5
%7 = tail call i32 @ntohs(i32 %6)
switch i32 %7, label %18 [
i32 130, label %8
i32 129, label %12
i32 128, label %16
]
8: ; preds = %3
%9 = getelementptr inbounds i8, i8* %0, i64 4
%10 = bitcast i8* %9 to %struct.ip*
%11 = tail call i32 @decode_ip_n_hash(%struct.ip* %10, i32 %1, i32 %2)
br label %20
12: ; preds = %3
%13 = getelementptr inbounds i8, i8* %0, i64 4
%14 = bitcast i8* %13 to %struct.ip6_hdr*
%15 = tail call i32 @decode_ipv6_n_hash(%struct.ip6_hdr* %14, i32 %1, i32 %2)
br label %20
16: ; preds = %3
%17 = tail call i32 @decode_vlan_n_hash(%struct.ether_header* %4, i32 %1, i32 %2)
br label %20
18: ; preds = %3
%19 = tail call i32 @decode_others_n_hash(%struct.ether_header* %4, i32 %2)
br label %20
20: ; preds = %18, %16, %12, %8
%21 = phi i32 [ %19, %18 ], [ %17, %16 ], [ %15, %12 ], [ %11, %8 ]
ret i32 %21
}