#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 */
typedef struct TYPE_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
typedef int uint8_t;
typedef int /*<<< orphan*/ uint32_t;
struct udphdr {
  int uh_sport;
  int uh_dport;
};
struct tcphdr {
  int th_sport;
  int th_dport;
};
struct TYPE_4__ {
  int /*<<< orphan*/ s_addr;
};
struct TYPE_3__ {
  int /*<<< orphan*/ s_addr;
};
struct ip {
  int ip_p;
  int ip_hl;
  TYPE_2__ ip_dst;
  TYPE_1__ ip_src;
};

/* Variables and functions */
#define IPPROTO_IPIP 130
#define IPPROTO_TCP 129
#define IPPROTO_UDP 128
int /*<<< orphan*/ ntohl(int /*<<< orphan*/);
int ntohs(int);
int /*<<< orphan*/ sym_hash_fn(int /*<<< orphan*/, int /*<<< orphan*/, int,
                               int);
uint32_t decode_ip_n_hash(struct ip *iph, uint8_t hash_split, uint8_t seed) {
  uint32_t rc = 0;
  if (hash_split == 2) {
    rc = sym_hash_fn(ntohl(iph->ip_src.s_addr), ntohl(iph->ip_dst.s_addr),
                     ntohs(0xFFFD) + seed, ntohs(0xFFFE) + seed);
  } else {
    struct tcphdr *tcph = NULL;
    struct udphdr *udph = NULL;
    switch (iph->ip_p) {
    case IPPROTO_TCP:
      tcph = (struct tcphdr *)((uint8_t *)iph + (iph->ip_hl << 2));
      rc = sym_hash_fn(ntohl(iph->ip_src.s_addr), ntohl(iph->ip_dst.s_addr),
                       ntohs(tcph->th_sport) + seed,
                       ntohs(tcph->th_dport) + seed);
      break;
    case IPPROTO_UDP:
      udph = (struct udphdr *)((uint8_t *)iph + (iph->ip_hl << 2));
      rc = sym_hash_fn(ntohl(iph->ip_src.s_addr), ntohl(iph->ip_dst.s_addr),
                       ntohs(udph->uh_sport) + seed,
                       ntohs(udph->uh_dport) + seed);
      break;
    case IPPROTO_IPIP:
      rc = decode_ip_n_hash((struct ip *)((uint8_t *)iph + (iph->ip_hl << 2)),
                            hash_split, seed);
      break;
    default:
      return 0;
      break;
    }
  }
  return rc;
}


x86 assembly (clang, -O0):
<decode_ip_n_hash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x2,-0x14(%rbp)
jne    11b6 <decode_ip_n_hash+0x76>
mov    -0x10(%rbp),%rax
mov    0xc(%rax),%edi
call   1050 <ntohl@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%edi
call   1050 <ntohl@plt>
mov    %eax,-0x38(%rbp)
mov    $0xfffd,%edi
call   1040 <ntohs@plt>
add    -0x18(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    $0xfffe,%edi
call   1040 <ntohs@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%esi
mov    -0x34(%rbp),%edx
mov    %eax,%ecx
add    -0x18(%rbp),%ecx
call   1030 <sym_hash_fn@plt>
mov    %eax,-0x1c(%rbp)
jmp    1324 <decode_ip_n_hash+0x1e4>
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
sub    $0x80,%eax
je     1277 <decode_ip_n_hash+0x137>
jmp    11df <decode_ip_n_hash+0x9f>
mov    -0x40(%rbp),%eax
sub    $0x81,%eax
je     1205 <decode_ip_n_hash+0xc5>
jmp    11f2 <decode_ip_n_hash+0xb2>
mov    -0x40(%rbp),%eax
sub    $0x82,%eax
je     12e9 <decode_ip_n_hash+0x1a9>
jmp    1313 <decode_ip_n_hash+0x1d3>
mov    -0x10(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    0x4(%rcx),%ecx
shl    $0x2,%ecx
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0xc(%rax),%edi
call   1050 <ntohl@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%edi
call   1050 <ntohl@plt>
mov    %eax,-0x48(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%edi
call   1040 <ntohs@plt>
add    -0x18(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x28(%rbp),%rax
mov    0x4(%rax),%edi
call   1040 <ntohs@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%esi
mov    -0x44(%rbp),%edx
mov    %eax,%ecx
add    -0x18(%rbp),%ecx
call   1030 <sym_hash_fn@plt>
mov    %eax,-0x1c(%rbp)
jmp    131f <decode_ip_n_hash+0x1df>
mov    -0x10(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    0x4(%rcx),%ecx
shl    $0x2,%ecx
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0xc(%rax),%edi
call   1050 <ntohl@plt>
mov    %eax,-0x58(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%edi
call   1050 <ntohl@plt>
mov    %eax,-0x54(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%edi
call   1040 <ntohs@plt>
add    -0x18(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    -0x30(%rbp),%rax
mov    0x4(%rax),%edi
call   1040 <ntohs@plt>
mov    -0x58(%rbp),%edi
mov    -0x54(%rbp),%esi
mov    -0x50(%rbp),%edx
mov    %eax,%ecx
add    -0x18(%rbp),%ecx
call   1030 <sym_hash_fn@plt>
mov    %eax,-0x1c(%rbp)
jmp    131f <decode_ip_n_hash+0x1df>
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
shl    $0x2,%eax
cltq
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1060 <decode_ip_n_hash@plt>
mov    %eax,-0x1c(%rbp)
jmp    131f <decode_ip_n_hash+0x1df>
movl   $0x0,-0x4(%rbp)
jmp    132a <decode_ip_n_hash+0x1ea>
jmp    1324 <decode_ip_n_hash+0x1e4>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decode_ip_n_hash>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rdi,%rbx
cmp    $0x2,%esi
jne    1180 <decode_ip_n_hash+0x50>
mov    0xc(%rbx),%edi
call   1050 <ntohl@plt>
mov    %eax,%r15d
mov    0x8(%rbx),%edi
call   1050 <ntohl@plt>
mov    %eax,%ebx
mov    $0xfffd,%edi
call   1040 <ntohs@plt>
lea    (%rax,%r14,1),%ebp
mov    $0xfffe,%edi
call   1040 <ntohs@plt>
add    %eax,%r14d
mov    %r15d,%edi
mov    %ebx,%esi
mov    %ebp,%edx
jmp    11e5 <decode_ip_n_hash+0xb5>
nop
mov    (%rbx),%eax
cmp    $0x82,%eax
jne    1197 <decode_ip_n_hash+0x67>
mov    0x4(%rbx),%eax
shl    $0x2,%eax
cltq
lea    (%rbx,%rax,4),%rbx
jmp    1180 <decode_ip_n_hash+0x50>
cmp    $0x80,%eax
je     11a5 <decode_ip_n_hash+0x75>
cmp    $0x81,%eax
jne    11fb <decode_ip_n_hash+0xcb>
mov    0x4(%rbx),%eax
mov    0xc(%rbx),%edi
shl    $0x2,%eax
movslq %eax,%rbp
call   1050 <ntohl@plt>
mov    %eax,%r15d
mov    0x8(%rbx),%edi
call   1050 <ntohl@plt>
mov    %eax,%r12d
mov    (%rbx,%rbp,4),%edi
call   1040 <ntohs@plt>
lea    (%rax,%r14,1),%r13d
mov    0x4(%rbx,%rbp,4),%edi
call   1040 <ntohs@plt>
add    %eax,%r14d
mov    %r15d,%edi
mov    %r12d,%esi
mov    %r13d,%edx
mov    %r14d,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <sym_hash_fn@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ip = type { i32, i32, %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i32 }
%struct.TYPE_3__ = type { i32 }
%struct.tcphdr = type { i32, i32 }
%struct.udphdr = type { i32, i32 }
define i32 @decode_ip_n_hash(%struct.ip* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.ip*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.tcphdr*
%10 = alloca %struct.udphdr*
store %struct.ip* %0, %struct.ip** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 0, i32* %8
%11 = load i32, i32* %6
%12 = icmp eq i32 %11, 2
br i1 %12, label %13, label %31
13: ; preds = %3
%14 = load %struct.ip*, %struct.ip** %5
%15 = getelementptr inbounds %struct.ip, %struct.ip* %14, i32 0, i32 3
%16 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %15, i32 0, i32 0
%17 = load i32, i32* %16
%18 = call i32 @ntohl(i32 %17)
%19 = load %struct.ip*, %struct.ip** %5
%20 = getelementptr inbounds %struct.ip, %struct.ip* %19, i32 0, i32 2
%21 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %20, i32 0, i32 0
%22 = load i32, i32* %21
%23 = call i32 @ntohl(i32 %22)
%24 = call i32 @ntohs(i32 65533)
%25 = load i32, i32* %7
%26 = add nsw i32 %24, %25
%27 = call i32 @ntohs(i32 65534)
%28 = load i32, i32* %7
%29 = add nsw i32 %27, %28
%30 = call i32 @sym_hash_fn(i32 %18, i32 %23, i32 %26, i32 %29)
store i32 %30, i32* %8
br label %116
31: ; preds = %3
store %struct.tcphdr* null, %struct.tcphdr** %9
store %struct.udphdr* null, %struct.udphdr** %10
%32 = load %struct.ip*, %struct.ip** %5
%33 = getelementptr inbounds %struct.ip, %struct.ip* %32, i32 0, i32 0
%34 = load i32, i32* %33
switch i32 %34, label %114 [
i32 129, label %35
i32 128, label %68
i32 130, label %101
]
35: ; preds = %31
%36 = load %struct.ip*, %struct.ip** %5
%37 = bitcast %struct.ip* %36 to i32*
%38 = load %struct.ip*, %struct.ip** %5
%39 = getelementptr inbounds %struct.ip, %struct.ip* %38, i32 0, i32 1
%40 = load i32, i32* %39
%41 = shl i32 %40, 2
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i32, i32* %37, i64 %42
%44 = bitcast i32* %43 to %struct.tcphdr*
store %struct.tcphdr* %44, %struct.tcphdr** %9
%45 = load %struct.ip*, %struct.ip** %5
%46 = getelementptr inbounds %struct.ip, %struct.ip* %45, i32 0, i32 3
%47 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %46, i32 0, i32 0
%48 = load i32, i32* %47
%49 = call i32 @ntohl(i32 %48)
%50 = load %struct.ip*, %struct.ip** %5
%51 = getelementptr inbounds %struct.ip, %struct.ip* %50, i32 0, i32 2
%52 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %51, i32 0, i32 0
%53 = load i32, i32* %52
%54 = call i32 @ntohl(i32 %53)
%55 = load %struct.tcphdr*, %struct.tcphdr** %9
%56 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %55, i32 0, i32 0
%57 = load i32, i32* %56
%58 = call i32 @ntohs(i32 %57)
%59 = load i32, i32* %7
%60 = add nsw i32 %58, %59
%61 = load %struct.tcphdr*, %struct.tcphdr** %9
%62 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %61, i32 0, i32 1
%63 = load i32, i32* %62
%64 = call i32 @ntohs(i32 %63)
%65 = load i32, i32* %7
%66 = add nsw i32 %64, %65
%67 = call i32 @sym_hash_fn(i32 %49, i32 %54, i32 %60, i32 %66)
store i32 %67, i32* %8
br label %115
68: ; preds = %31
%69 = load %struct.ip*, %struct.ip** %5
%70 = bitcast %struct.ip* %69 to i32*
%71 = load %struct.ip*, %struct.ip** %5
%72 = getelementptr inbounds %struct.ip, %struct.ip* %71, i32 0, i32 1
%73 = load i32, i32* %72
%74 = shl i32 %73, 2
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds i32, i32* %70, i64 %75
%77 = bitcast i32* %76 to %struct.udphdr*
store %struct.udphdr* %77, %struct.udphdr** %10
%78 = load %struct.ip*, %struct.ip** %5
%79 = getelementptr inbounds %struct.ip, %struct.ip* %78, i32 0, i32 3
%80 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %79, i32 0, i32 0
%81 = load i32, i32* %80
%82 = call i32 @ntohl(i32 %81)
%83 = load %struct.ip*, %struct.ip** %5
%84 = getelementptr inbounds %struct.ip, %struct.ip* %83, i32 0, i32 2
%85 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %84, i32 0, i32 0
%86 = load i32, i32* %85
%87 = call i32 @ntohl(i32 %86)
%88 = load %struct.udphdr*, %struct.udphdr** %10
%89 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %88, i32 0, i32 0
%90 = load i32, i32* %89
%91 = call i32 @ntohs(i32 %90)
%92 = load i32, i32* %7
%93 = add nsw i32 %91, %92
%94 = load %struct.udphdr*, %struct.udphdr** %10
%95 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %94, i32 0, i32 1
%96 = load i32, i32* %95
%97 = call i32 @ntohs(i32 %96)
%98 = load i32, i32* %7
%99 = add nsw i32 %97, %98
%100 = call i32 @sym_hash_fn(i32 %82, i32 %87, i32 %93, i32 %99)
store i32 %100, i32* %8
br label %115
101: ; preds = %31
%102 = load %struct.ip*, %struct.ip** %5
%103 = bitcast %struct.ip* %102 to i32*
%104 = load %struct.ip*, %struct.ip** %5
%105 = getelementptr inbounds %struct.ip, %struct.ip* %104, i32 0, i32 1
%106 = load i32, i32* %105
%107 = shl i32 %106, 2
%108 = sext i32 %107 to i64
%109 = getelementptr inbounds i32, i32* %103, i64 %108
%110 = bitcast i32* %109 to %struct.ip*
%111 = load i32, i32* %6
%112 = load i32, i32* %7
%113 = call i32 @decode_ip_n_hash(%struct.ip* %110, i32 %111, i32 %112)
store i32 %113, i32* %8
br label %115
114: ; preds = %31
store i32 0, i32* %4
br label %118
115: ; preds = %101, %68, %35
br label %116
116: ; preds = %115, %13
%117 = load i32, i32* %8
store i32 %117, i32* %4
br label %118
118: ; preds = %116, %114
%119 = load i32, i32* %4
ret i32 %119
}

LLVM IR (-O2):
%struct.ip = type { i32, i32, %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i32 }
%struct.TYPE_3__ = type { i32 }
%struct.tcphdr = type { i32, i32 }
%struct.udphdr = type { i32, i32 }
define i32 @decode_ip_n_hash(%struct.ip* nocapture %0, i32 %1, i32 %2) {
%4 = icmp eq i32 %1, 2
br i1 %4, label %5, label %17
5: ; preds = %3
%6 = getelementptr inbounds %struct.ip, %struct.ip* %0, i64 0, i32 3, i32 0
%7 = load i32, i32* %6
%8 = tail call i32 @ntohl(i32 %7)
%9 = getelementptr inbounds %struct.ip, %struct.ip* %0, i64 0, i32 2, i32 0
%10 = load i32, i32* %9
%11 = tail call i32 @ntohl(i32 %10)
%12 = tail call i32 @ntohs(i32 65533)
%13 = add nsw i32 %12, %2
%14 = tail call i32 @ntohs(i32 65534)
%15 = add nsw i32 %14, %2
%16 = tail call i32 @sym_hash_fn(i32 %8, i32 %11, i32 %13, i32 %15)
br label %68
17: ; preds = %3, %61
%18 = phi %struct.ip* [ %67, %61 ], [ %0, %3 ]
%19 = getelementptr inbounds %struct.ip, %struct.ip* %18, i64 0, i32 0
%20 = load i32, i32* %19
switch i32 %20, label %68 [
i32 129, label %21
i32 128, label %41
i32 130, label %61
]
21: ; preds = %17
%22 = getelementptr inbounds %struct.ip, %struct.ip* %18, i64 0, i32 1
%23 = load i32, i32* %22
%24 = shl i32 %23, 2
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %19, i64 %25
%27 = getelementptr inbounds %struct.ip, %struct.ip* %18, i64 0, i32 3, i32 0
%28 = load i32, i32* %27
%29 = tail call i32 @ntohl(i32 %28)
%30 = getelementptr inbounds %struct.ip, %struct.ip* %18, i64 0, i32 2, i32 0
%31 = load i32, i32* %30
%32 = tail call i32 @ntohl(i32 %31)
%33 = load i32, i32* %26
%34 = tail call i32 @ntohs(i32 %33)
%35 = add nsw i32 %34, %2
%36 = getelementptr inbounds i32, i32* %26, i64 1
%37 = load i32, i32* %36
%38 = tail call i32 @ntohs(i32 %37)
%39 = add nsw i32 %38, %2
%40 = tail call i32 @sym_hash_fn(i32 %29, i32 %32, i32 %35, i32 %39)
br label %68
41: ; preds = %17
%42 = getelementptr inbounds %struct.ip, %struct.ip* %18, i64 0, i32 1
%43 = load i32, i32* %42
%44 = shl i32 %43, 2
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i32, i32* %19, i64 %45
%47 = getelementptr inbounds %struct.ip, %struct.ip* %18, i64 0, i32 3, i32 0
%48 = load i32, i32* %47
%49 = tail call i32 @ntohl(i32 %48)
%50 = getelementptr inbounds %struct.ip, %struct.ip* %18, i64 0, i32 2, i32 0
%51 = load i32, i32* %50
%52 = tail call i32 @ntohl(i32 %51)
%53 = load i32, i32* %46
%54 = tail call i32 @ntohs(i32 %53)
%55 = add nsw i32 %54, %2
%56 = getelementptr inbounds i32, i32* %46, i64 1
%57 = load i32, i32* %56
%58 = tail call i32 @ntohs(i32 %57)
%59 = add nsw i32 %58, %2
%60 = tail call i32 @sym_hash_fn(i32 %49, i32 %52, i32 %55, i32 %59)
br label %68
61: ; preds = %17
%62 = getelementptr inbounds %struct.ip, %struct.ip* %18, i64 0, i32 1
%63 = load i32, i32* %62
%64 = shl i32 %63, 2
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i32, i32* %19, i64 %65
%67 = bitcast i32* %66 to %struct.ip*
br label %17
68: ; preds = %17, %21, %41, %5
%69 = phi i32 [ %16, %5 ], [ %40, %21 ], [ %60, %41 ], [ 0, %17 ]
ret i32 %69
}