#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 uint64_t;
struct udphdr {
  scalar_t__ dest;
};
struct iphdr {
  int protocol;
  int frag_off;
  scalar_t__ daddr;
  int ihl;
};
struct ether_header {
  scalar_t__ ether_type;
};

/* Variables and functions */
scalar_t__ htonl(int);
scalar_t__ htons(int);
uint64_t entry(void *pkt) {
  struct ether_header *ether_header = (void *)pkt;
  if (ether_header->ether_type != htons(0x0800))
    return 0;
  struct iphdr *iphdr = (void *)(ether_header + 1);
  if (iphdr->protocol != 17 || (iphdr->frag_off & 0x1ffff) != 0 ||
      iphdr->daddr != htonl(0x1020304))
    return 0;
  int hlen = iphdr->ihl * 4;
  struct udphdr *udphdr = (void *)iphdr + hlen;
  if (udphdr->dest != htons(5000))
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<entry>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    $0x800,%edi
call   1030 <htons@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
cmp    %rcx,%rax
je     1165 <entry+0x45>
movl   $0x0,-0x4(%rbp)
jmp    1219 <entry+0xf9>
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpl   $0x11,(%rax)
jne    11b9 <entry+0x99>
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%eax
and    $0x1ffff,%eax
cmp    $0x0,%eax
jne    11b9 <entry+0x99>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x40(%rbp)
mov    $0x1020304,%edi
call   1040 <htonl@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
cmp    %rcx,%rax
je     11c5 <entry+0xa5>
movl   $0x0,-0x4(%rbp)
jmp    1219 <entry+0xf9>
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%eax
shl    $0x2,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x48(%rbp)
mov    $0x1388,%edi
call   1030 <htons@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
cmp    %rcx,%rax
je     1212 <entry+0xf2>
movl   $0x0,-0x4(%rbp)
jmp    1219 <entry+0xf9>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<entry>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    (%rdi),%rbp
mov    $0x800,%edi
call   1030 <htons@plt>
xor    %r14d,%r14d
cmp    %rax,%rbp
jne    117b <entry+0x5b>
cmpl   $0x11,0x8(%rbx)
jne    117b <entry+0x5b>
testl  $0x1ffff,0xc(%rbx)
jne    117b <entry+0x5b>
mov    0x10(%rbx),%rbp
mov    $0x1020304,%edi
call   1040 <htonl@plt>
cmp    %rax,%rbp
jne    117b <entry+0x5b>
movslq 0x18(%rbx),%rax
mov    0x8(%rbx,%rax,4),%rbx
mov    $0x1388,%edi
call   1030 <htons@plt>
xor    %r14d,%r14d
cmp    %rax,%rbx
sete   %r14b
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.ether_header = type { i64 }
%struct.iphdr = type { i32, i32, i64, i32 }
%struct.udphdr = type { i64 }
define i32 @entry(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.ether_header*
%5 = alloca %struct.iphdr*
%6 = alloca i32
%7 = alloca %struct.udphdr*
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = bitcast i8* %8 to %struct.ether_header*
store %struct.ether_header* %9, %struct.ether_header** %4
%10 = load %struct.ether_header*, %struct.ether_header** %4
%11 = getelementptr inbounds %struct.ether_header, %struct.ether_header* %10, i32 0, i32 0
%12 = load i64, i64* %11
%13 = call i64 @htons(i32 2048)
%14 = icmp ne i64 %12, %13
br i1 %14, label %15, label %16
15: ; preds = %1
store i32 0, i32* %2
br label %56
16: ; preds = %1
%17 = load %struct.ether_header*, %struct.ether_header** %4
%18 = getelementptr inbounds %struct.ether_header, %struct.ether_header* %17, i64 1
%19 = bitcast %struct.ether_header* %18 to i8*
%20 = bitcast i8* %19 to %struct.iphdr*
store %struct.iphdr* %20, %struct.iphdr** %5
%21 = load %struct.iphdr*, %struct.iphdr** %5
%22 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %21, i32 0, i32 0
%23 = load i32, i32* %22
%24 = icmp ne i32 %23, 17
br i1 %24, label %37, label %25
25: ; preds = %16
%26 = load %struct.iphdr*, %struct.iphdr** %5
%27 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %26, i32 0, i32 1
%28 = load i32, i32* %27
%29 = and i32 %28, 131071
%30 = icmp ne i32 %29, 0
br i1 %30, label %37, label %31
31: ; preds = %25
%32 = load %struct.iphdr*, %struct.iphdr** %5
%33 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %32, i32 0, i32 2
%34 = load i64, i64* %33
%35 = call i64 @htonl(i32 16909060)
%36 = icmp ne i64 %34, %35
br i1 %36, label %37, label %38
37: ; preds = %31, %25, %16
store i32 0, i32* %2
br label %56
38: ; preds = %31
%39 = load %struct.iphdr*, %struct.iphdr** %5
%40 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %39, i32 0, i32 3
%41 = load i32, i32* %40
%42 = mul nsw i32 %41, 4
store i32 %42, i32* %6
%43 = load %struct.iphdr*, %struct.iphdr** %5
%44 = bitcast %struct.iphdr* %43 to i8*
%45 = load i32, i32* %6
%46 = sext i32 %45 to i64
%47 = getelementptr i8, i8* %44, i64 %46
%48 = bitcast i8* %47 to %struct.udphdr*
store %struct.udphdr* %48, %struct.udphdr** %7
%49 = load %struct.udphdr*, %struct.udphdr** %7
%50 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %49, i32 0, i32 0
%51 = load i64, i64* %50
%52 = call i64 @htons(i32 5000)
%53 = icmp ne i64 %51, %52
br i1 %53, label %54, label %55
54: ; preds = %38
store i32 0, i32* %2
br label %56
55: ; preds = %38
store i32 1, i32* %2
br label %56
56: ; preds = %55, %54, %37, %15
%57 = load i32, i32* %2
ret i32 %57
}

LLVM IR (-O2):
define i32 @entry(i8* nocapture %0) {
%2 = bitcast i8* %0 to i64*
%3 = load i64, i64* %2
%4 = tail call i64 @htons(i32 2048)
%5 = icmp eq i64 %3, %4
br i1 %5, label %6, label %35
6: ; preds = %1
%7 = getelementptr inbounds i8, i8* %0, i64 8
%8 = bitcast i8* %7 to i32*
%9 = load i32, i32* %8
%10 = icmp eq i32 %9, 17
br i1 %10, label %11, label %35
11: ; preds = %6
%12 = getelementptr inbounds i8, i8* %0, i64 12
%13 = bitcast i8* %12 to i32*
%14 = load i32, i32* %13
%15 = and i32 %14, 131071
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %35
17: ; preds = %11
%18 = getelementptr inbounds i8, i8* %0, i64 16
%19 = bitcast i8* %18 to i64*
%20 = load i64, i64* %19
%21 = tail call i64 @htonl(i32 16909060)
%22 = icmp eq i64 %20, %21
br i1 %22, label %23, label %35
23: ; preds = %17
%24 = getelementptr inbounds i8, i8* %0, i64 24
%25 = bitcast i8* %24 to i32*
%26 = load i32, i32* %25
%27 = shl nsw i32 %26, 2
%28 = sext i32 %27 to i64
%29 = getelementptr i8, i8* %7, i64 %28
%30 = bitcast i8* %29 to i64*
%31 = load i64, i64* %30
%32 = tail call i64 @htons(i32 5000)
%33 = icmp eq i64 %31, %32
%34 = zext i1 %33 to i32
br label %35
35: ; preds = %23, %17, %11, %6, %1
%36 = phi i32 [ 0, %1 ], [ %34, %23 ], [ 0, %17 ], [ 0, %11 ], [ 0, %6 ]
ret i32 %36
}