#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 sock_fprog {
  int len;
  struct sock_filter *filter;
};
struct sock_filter {
  int member_0;
  int member_3;
  int /*<<< orphan*/ member_2;
  int /*<<< orphan*/ member_1;
};
typedef int /*<<< orphan*/ bpf_code;
typedef int /*<<< orphan*/ bpf;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_ATTACH_FILTER;
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ exit(int);
unsigned short ntohs(short);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int recvfrom(int, char *, int, int /*<<< orphan*/, int /*<<< orphan*/ *,
             int /*<<< orphan*/ *);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                      struct sock_fprog *, int);
scalar_t__ socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int sock, n;
  char buffer[2048];
  unsigned char *iphead, *ethhead;
  unsigned short proto;
  struct sock_filter bpf_code[] = {
      {0x6, 0, 0, 0x0000ffff},
  };
  struct sock_fprog bpf = {
      .len = (sizeof(bpf_code) / sizeof(*(bpf_code))),
      .filter = bpf_code,
  };
  if ((sock = socket(AF_INET, SOCK_DGRAM, 0) < 0)) {
    perror("socket");
    exit(1);
  }
  if (setsockopt(sock, SOL_SOCKET, SO_ATTACH_FILTER, &bpf, sizeof(bpf)) < 0) {
    perror("setsockopt");
    close(sock);
    exit(1);
  }
  while (1) {
    printf("----------\n");
    n = recvfrom(sock, buffer, 2048, 0, NULL, NULL);
    if (n < 42) {
      perror("recvfrom():");
      printf("Incomplete packet (errno is %d)\n", errno);
      close(sock);
      exit(0);
    }
    ethhead = buffer;
    printf("Source MAC address: "
           "%02x:%02x:%02x:%02x:%02x:%02x\n",
           ethhead[0], ethhead[1], ethhead[2], ethhead[3], ethhead[4],
           ethhead[5]);
    printf("Destination MAC address: "
           "%02x:%02x:%02x:%02x:%02x:%02x\n",
           ethhead[6], ethhead[7], ethhead[8], ethhead[9], ethhead[10],
           ethhead[11]);
    iphead = buffer + 14;
    if (*iphead == 0x45) {
      printf("Source host %d.%d.%d.%d\n", iphead[12], iphead[13], iphead[14],
             iphead[15]);
      printf("Dest host %d.%d.%d.%d\n", iphead[16], iphead[17], iphead[18],
             iphead[19]);
      printf("Source,Dest ports %d,%d\n", (iphead[20] << 8) + iphead[21],
             (iphead[22] << 8) + iphead[23]);
      printf("Layer-4 protocol %d\n", iphead[9]);
    } else {
      proto = ntohs(*(short *)(buffer + 12));
      switch (proto) {
      case 0x0806:
        printf("arp\n");
        break;
      case 0x86dd:
        printf("ipv6\n");
        break;
      default:
        printf("unknown protocal:0x%04x\n", proto);
        break;
      }
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x870,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe60(%rip),%rax
mov    %rax,-0x850(%rbp)
mov    0xe5a(%rip),%rax
mov    %rax,-0x848(%rbp)
movl   $0x1,-0x860(%rbp)
lea    -0x850(%rbp),%rax
mov    %rax,-0x858(%rbp)
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
mov    0x2df3(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
cmp    $0x0,%rax
setl   %al
mov    %al,%cl
and    $0x1,%cl
movzbl %cl,%ecx
mov    %ecx,-0x14(%rbp)
test   $0x1,%al
jne    1205 <main+0x85>
jmp    121b <main+0x9b>
lea    0xe04(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x14(%rbp),%edi
mov    0x2dc3(%rip),%rax
mov    (%rax),%esi
mov    0x2db2(%rip),%rax
mov    (%rax),%edx
lea    -0x860(%rbp),%rcx
mov    $0x10,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
jge    126a <main+0xea>
lea    0xdc4(%rip),%rdi
call   1080 <perror@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    126f <main+0xef>
lea    0xdac(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x820(%rbp),%rsi
mov    $0x800,%edx
xor    %ecx,%ecx
xor    %eax,%eax
mov    %eax,%r9d
mov    %r9,%r8
call   1060 <recvfrom@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x2a,-0x18(%rbp)
jge    12da <main+0x15a>
lea    0xd7f(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d05(%rip),%rax
mov    (%rax),%esi
lea    0xd76(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
xor    %edi,%edi
call   1090 <exit@plt>
lea    -0x820(%rbp),%rax
mov    %rax,-0x830(%rbp)
mov    -0x830(%rbp),%rax
movzbl (%rax),%esi
mov    -0x830(%rbp),%rax
movzbl 0x1(%rax),%edx
mov    -0x830(%rbp),%rax
movzbl 0x2(%rax),%ecx
mov    -0x830(%rbp),%rax
movzbl 0x3(%rax),%r8d
mov    -0x830(%rbp),%rax
movzbl 0x4(%rax),%r9d
mov    -0x830(%rbp),%rax
movzbl 0x5(%rax),%eax
lea    0xd29(%rip),%rdi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x830(%rbp),%rax
movzbl 0x6(%rax),%esi
mov    -0x830(%rbp),%rax
movzbl 0x7(%rax),%edx
mov    -0x830(%rbp),%rax
movzbl 0x8(%rax),%ecx
mov    -0x830(%rbp),%rax
movzbl 0x9(%rax),%r8d
mov    -0x830(%rbp),%rax
movzbl 0xa(%rax),%r9d
mov    -0x830(%rbp),%rax
movzbl 0xb(%rax),%eax
lea    0xd07(%rip),%rdi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x820(%rbp),%rax
add    $0xe,%rax
mov    %rax,-0x828(%rbp)
mov    -0x828(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x45,%eax
jne    148e <main+0x30e>
mov    -0x828(%rbp),%rax
movzbl 0xc(%rax),%esi
mov    -0x828(%rbp),%rax
movzbl 0xd(%rax),%edx
mov    -0x828(%rbp),%rax
movzbl 0xe(%rax),%ecx
mov    -0x828(%rbp),%rax
movzbl 0xf(%rax),%r8d
lea    0xcdc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x828(%rbp),%rax
movzbl 0x10(%rax),%esi
mov    -0x828(%rbp),%rax
movzbl 0x11(%rax),%edx
mov    -0x828(%rbp),%rax
movzbl 0x12(%rax),%ecx
mov    -0x828(%rbp),%rax
movzbl 0x13(%rax),%r8d
lea    0xcba(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x828(%rbp),%rax
movzbl 0x14(%rax),%esi
shl    $0x8,%esi
mov    -0x828(%rbp),%rax
movzbl 0x15(%rax),%eax
add    %eax,%esi
mov    -0x828(%rbp),%rax
movzbl 0x16(%rax),%edx
shl    $0x8,%edx
mov    -0x828(%rbp),%rax
movzbl 0x17(%rax),%eax
add    %eax,%edx
lea    0xc8d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x828(%rbp),%rax
movzbl 0x9(%rax),%esi
lea    0xc8d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1514 <main+0x394>
movswl -0x814(%rbp),%edi
call   1070 <ntohs@plt>
mov    %ax,-0x832(%rbp)
movzwl -0x832(%rbp),%eax
mov    %eax,-0x864(%rbp)
sub    $0x806,%eax
je     14d4 <main+0x354>
jmp    14be <main+0x33e>
mov    -0x864(%rbp),%eax
sub    $0x86dd,%eax
je     14e7 <main+0x367>
jmp    14fa <main+0x37a>
lea    0xc49(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    150f <main+0x38f>
lea    0xc3b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    150f <main+0x38f>
movzwl -0x832(%rbp),%esi
lea    0xc27(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1514 <main+0x394>
jmp    126f <main+0xef>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x838,%rsp
movaps 0xe58(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movl   $0x1,0x10(%rsp)
lea    0x20(%rsp),%rax
mov    %rax,0x18(%rsp)
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
mov    0x2e01(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
test   %rax,%rax
jns    11f3 <main+0x63>
lea    0xe2c(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    %rax,%rbx
shr    $0x3f,%rbx
mov    0x2de7(%rip),%rax
mov    (%rax),%esi
mov    0x2dd6(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%rcx
mov    %ebx,%edi
mov    $0x10,%r8d
call   1040 <setsockopt@plt>
test   %rax,%rax
jns    1240 <main+0xb0>
lea    0xded(%rip),%rdi
call   1090 <perror@plt>
mov    %ebx,%edi
call   1060 <close@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xeea(%rip),%rdi
call   1030 <puts@plt>
lea    0x30(%rsp),%rsi
mov    %ebx,%edi
mov    $0x800,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1070 <recvfrom@plt>
cmp    $0x2a,%eax
jge    129b <main+0x10b>
lea    0xdb1(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d43(%rip),%rax
mov    (%rax),%esi
lea    0xda8(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
lea    0xdad(%rip),%r14
lea    0xdd9(%rip),%r15
lea    0xe53(%rip),%r12
lea    0xe7a(%rip),%r13
lea    0x30(%rsp),%rbp
jmp    136f <main+0x1df>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl 0x4a(%rsp),%esi
movzbl 0x4b(%rsp),%edx
movzbl 0x4c(%rsp),%ecx
movzbl 0x4d(%rsp),%r8d
lea    0xdce(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x4e(%rsp),%esi
movzbl 0x4f(%rsp),%edx
movzbl 0x50(%rsp),%ecx
movzbl 0x51(%rsp),%r8d
lea    0xdc4(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzwl 0x52(%rsp),%esi
shl    $0x10,%esi
bswap  %esi
movzwl 0x54(%rsp),%edx
shl    $0x10,%edx
bswap  %edx
lea    0xdb9(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x47(%rsp),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r13,%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x800,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1070 <recvfrom@plt>
cmp    $0x2a,%eax
jl     126a <main+0xda>
movzbl 0x30(%rsp),%esi
movzbl 0x31(%rsp),%edx
movzbl 0x32(%rsp),%ecx
movzbl 0x33(%rsp),%r8d
movzbl 0x34(%rsp),%r9d
movzbl 0x35(%rsp),%eax
mov    %eax,(%rsp)
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x36(%rsp),%esi
movzbl 0x37(%rsp),%edx
movzbl 0x38(%rsp),%ecx
movzbl 0x39(%rsp),%r8d
movzbl 0x3a(%rsp),%r9d
movzbl 0x3b(%rsp),%eax
mov    %eax,(%rsp)
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmpb   $0x45,0x3e(%rsp)
je     12d0 <main+0x140>
movswl 0x3c(%rsp),%edi
call   1080 <ntohs@plt>
movzwl %ax,%esi
cmp    $0x86dd,%esi
je     1402 <main+0x272>
cmp    $0x806,%esi
jne    1413 <main+0x283>
lea    0xd49(%rip),%rdi
call   1030 <puts@plt>
jmp    1347 <main+0x1b7>
lea    0xd33(%rip),%rdi
call   1030 <puts@plt>
jmp    1347 <main+0x1b7>
lea    0xcfe(%rip),%rdi
jmp    1340 <main+0x1b0>

LLVM IR (-O0):
%struct.sock_filter = type { i32, i32, i32, i32 }
%struct.sock_fprog = type { i32, %struct.sock_filter* }
@__const.main.bpf_code = [1 x %struct.sock_filter] [%struct.sock_filter { i32 6, i32 0, i32 0, i32 65535 }]
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [7 x i8] c"socket\00"
@SOL_SOCKET = global i32 0
@SO_ATTACH_FILTER = global i32 0
@.str.1 = [11 x i8] c"setsockopt\00"
@.str.2 = [12 x i8] c"----------\0A\00"
@.str.3 = [12 x i8] c"recvfrom():\00"
@.str.4 = [33 x i8] c"Incomplete packet (errno is %d)\0A\00"
@errno = global i32 0
@.str.5 = [51 x i8] c"Source MAC address: %02x:%02x:%02x:%02x:%02x:%02x\0A\00"
@.str.6 = [56 x i8] c"Destination MAC address: %02x:%02x:%02x:%02x:%02x:%02x\0A\00"
@.str.7 = [25 x i8] c"Source host %d.%d.%d.%d\0A\00"
@.str.8 = [23 x i8] c"Dest host %d.%d.%d.%d\0A\00"
@.str.9 = [25 x i8] c"Source,Dest ports %d,%d\0A\00"
@.str.10 = [21 x i8] c"Layer-4 protocol %d\0A\00"
@.str.11 = [5 x i8] c"arp\0A\00"
@.str.12 = [6 x i8] c"ipv6\0A\00"
@.str.13 = [25 x i8] c"unknown protocal:0x%04x\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [2048 x i8]
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i16
%12 = alloca [1 x %struct.sock_filter]
%13 = alloca %struct.sock_fprog
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = bitcast [1 x %struct.sock_filter]* %12 to i8*
%15 = getelementptr inbounds %struct.sock_fprog, %struct.sock_fprog* %13, i32 0, i32 0
store i32 1, i32* %15
%16 = getelementptr inbounds %struct.sock_fprog, %struct.sock_fprog* %13, i32 0, i32 1
%17 = getelementptr inbounds [1 x %struct.sock_filter], [1 x %struct.sock_filter]* %12, i64 0, i64 0
store %struct.sock_filter* %17, %struct.sock_filter** %16
%18 = load i32, i32* @AF_INET
%19 = load i32, i32* @SOCK_DGRAM
%20 = call i64 @socket(i32 %18, i32 %19, i32 0)
%21 = icmp slt i64 %20, 0
%22 = zext i1 %21 to i32
store i32 %22, i32* %6
br i1 %21, label %23, label %26
23: ; preds = %2
%24 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %2
%27 = load i32, i32* %6
%28 = load i32, i32* @SOL_SOCKET
%29 = load i32, i32* @SO_ATTACH_FILTER
%30 = call i64 @setsockopt(i32 %27, i32 %28, i32 %29, %struct.sock_fprog* %13, i32 16)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %26
%33 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%34 = load i32, i32* %6
%35 = call i32 @close(i32 %34)
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %26
br label %38
38: ; preds = %37, %188
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%40 = load i32, i32* %6
%41 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%42 = call i32 @recvfrom(i32 %40, i8* %41, i32 2048, i32 0, i32* null, i32* null)
store i32 %42, i32* %7
%43 = load i32, i32* %7
%44 = icmp slt i32 %43, 42
br i1 %44, label %45, label %52
45: ; preds = %38
%46 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%47 = load i32, i32* @errno
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i32 %47)
%49 = load i32, i32* %6
%50 = call i32 @close(i32 %49)
%51 = call i32 @exit(i32 0)
unreachable
52: ; preds = %38
%53 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
store i8* %53, i8** %10
%54 = load i8*, i8** %10
%55 = getelementptr inbounds i8, i8* %54, i64 0
%56 = load i8, i8* %55
%57 = zext i8 %56 to i32
%58 = load i8*, i8** %10
%59 = getelementptr inbounds i8, i8* %58, i64 1
%60 = load i8, i8* %59
%61 = zext i8 %60 to i32
%62 = load i8*, i8** %10
%63 = getelementptr inbounds i8, i8* %62, i64 2
%64 = load i8, i8* %63
%65 = zext i8 %64 to i32
%66 = load i8*, i8** %10
%67 = getelementptr inbounds i8, i8* %66, i64 3
%68 = load i8, i8* %67
%69 = zext i8 %68 to i32
%70 = load i8*, i8** %10
%71 = getelementptr inbounds i8, i8* %70, i64 4
%72 = load i8, i8* %71
%73 = zext i8 %72 to i32
%74 = load i8*, i8** %10
%75 = getelementptr inbounds i8, i8* %74, i64 5
%76 = load i8, i8* %75
%77 = zext i8 %76 to i32
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.5, i64 0, i64 0), i32 %57, i32 %61, i32 %65, i32 %69, i32 %73, i32 %77)
%79 = load i8*, i8** %10
%80 = getelementptr inbounds i8, i8* %79, i64 6
%81 = load i8, i8* %80
%82 = zext i8 %81 to i32
%83 = load i8*, i8** %10
%84 = getelementptr inbounds i8, i8* %83, i64 7
%85 = load i8, i8* %84
%86 = zext i8 %85 to i32
%87 = load i8*, i8** %10
%88 = getelementptr inbounds i8, i8* %87, i64 8
%89 = load i8, i8* %88
%90 = zext i8 %89 to i32
%91 = load i8*, i8** %10
%92 = getelementptr inbounds i8, i8* %91, i64 9
%93 = load i8, i8* %92
%94 = zext i8 %93 to i32
%95 = load i8*, i8** %10
%96 = getelementptr inbounds i8, i8* %95, i64 10
%97 = load i8, i8* %96
%98 = zext i8 %97 to i32
%99 = load i8*, i8** %10
%100 = getelementptr inbounds i8, i8* %99, i64 11
%101 = load i8, i8* %100
%102 = zext i8 %101 to i32
%103 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.6, i64 0, i64 0), i32 %82, i32 %86, i32 %90, i32 %94, i32 %98, i32 %102)
%104 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%105 = getelementptr inbounds i8, i8* %104, i64 14
store i8* %105, i8** %9
%106 = load i8*, i8** %9
%107 = load i8, i8* %106
%108 = zext i8 %107 to i32
%109 = icmp eq i32 %108, 69
br i1 %109, label %110, label %171
110: ; preds = %52
%111 = load i8*, i8** %9
%112 = getelementptr inbounds i8, i8* %111, i64 12
%113 = load i8, i8* %112
%114 = zext i8 %113 to i32
%115 = load i8*, i8** %9
%116 = getelementptr inbounds i8, i8* %115, i64 13
%117 = load i8, i8* %116
%118 = zext i8 %117 to i32
%119 = load i8*, i8** %9
%120 = getelementptr inbounds i8, i8* %119, i64 14
%121 = load i8, i8* %120
%122 = zext i8 %121 to i32
%123 = load i8*, i8** %9
%124 = getelementptr inbounds i8, i8* %123, i64 15
%125 = load i8, i8* %124
%126 = zext i8 %125 to i32
%127 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i32 %114, i32 %118, i32 %122, i32 %126)
%128 = load i8*, i8** %9
%129 = getelementptr inbounds i8, i8* %128, i64 16
%130 = load i8, i8* %129
%131 = zext i8 %130 to i32
%132 = load i8*, i8** %9
%133 = getelementptr inbounds i8, i8* %132, i64 17
%134 = load i8, i8* %133
%135 = zext i8 %134 to i32
%136 = load i8*, i8** %9
%137 = getelementptr inbounds i8, i8* %136, i64 18
%138 = load i8, i8* %137
%139 = zext i8 %138 to i32
%140 = load i8*, i8** %9
%141 = getelementptr inbounds i8, i8* %140, i64 19
%142 = load i8, i8* %141
%143 = zext i8 %142 to i32
%144 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i32 %131, i32 %135, i32 %139, i32 %143)
%145 = load i8*, i8** %9
%146 = getelementptr inbounds i8, i8* %145, i64 20
%147 = load i8, i8* %146
%148 = zext i8 %147 to i32
%149 = shl i32 %148, 8
%150 = load i8*, i8** %9
%151 = getelementptr inbounds i8, i8* %150, i64 21
%152 = load i8, i8* %151
%153 = zext i8 %152 to i32
%154 = add nsw i32 %149, %153
%155 = load i8*, i8** %9
%156 = getelementptr inbounds i8, i8* %155, i64 22
%157 = load i8, i8* %156
%158 = zext i8 %157 to i32
%159 = shl i32 %158, 8
%160 = load i8*, i8** %9
%161 = getelementptr inbounds i8, i8* %160, i64 23
%162 = load i8, i8* %161
%163 = zext i8 %162 to i32
%164 = add nsw i32 %159, %163
%165 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0), i32 %154, i32 %164)
%166 = load i8*, i8** %9
%167 = getelementptr inbounds i8, i8* %166, i64 9
%168 = load i8, i8* %167
%169 = zext i8 %168 to i32
%170 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.10, i64 0, i64 0), i32 %169)
br label %188
171: ; preds = %52
%172 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%173 = getelementptr inbounds i8, i8* %172, i64 12
%174 = bitcast i8* %173 to i16*
%175 = load i16, i16* %174
%176 = call zeroext i16 @ntohs(i16 signext %175)
store i16 %176, i16* %11
%177 = load i16, i16* %11
%178 = zext i16 %177 to i32
switch i32 %178, label %183 [
i32 2054, label %179
i32 34525, label %181
]
179: ; preds = %171
%180 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0))
br label %187
181: ; preds = %171
%182 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.12, i64 0, i64 0))
br label %187
183: ; preds = %171
%184 = load i16, i16* %11
%185 = zext i16 %184 to i32
%186 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.13, i64 0, i64 0), i32 %185)
br label %187
187: ; preds = %183, %181, %179
br label %188
188: ; preds = %187, %110
br label %38
}

LLVM IR (-O2):
%struct.sock_filter = type { i32, i32, i32, i32 }
%struct.sock_fprog = type { i32, %struct.sock_filter* }
@__const.main.bpf_code = [1 x %struct.sock_filter] [%struct.sock_filter { i32 6, i32 0, i32 0, i32 65535 }]
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [7 x i8] c"socket\00"
@SOL_SOCKET = global i32 0
@SO_ATTACH_FILTER = global i32 0
@.str.1 = [11 x i8] c"setsockopt\00"
@.str.3 = [12 x i8] c"recvfrom():\00"
@.str.4 = [33 x i8] c"Incomplete packet (errno is %d)\0A\00"
@errno = global i32 0
@.str.5 = [51 x i8] c"Source MAC address: %02x:%02x:%02x:%02x:%02x:%02x\0A\00"
@.str.6 = [56 x i8] c"Destination MAC address: %02x:%02x:%02x:%02x:%02x:%02x\0A\00"
@.str.7 = [25 x i8] c"Source host %d.%d.%d.%d\0A\00"
@.str.8 = [23 x i8] c"Dest host %d.%d.%d.%d\0A\00"
@.str.9 = [25 x i8] c"Source,Dest ports %d,%d\0A\00"
@.str.10 = [21 x i8] c"Layer-4 protocol %d\0A\00"
@.str.13 = [25 x i8] c"unknown protocal:0x%04x\0A\00"
@str = [11 x i8] c"----------\00"
@str.14 = [5 x i8] c"ipv6\00"
@str.15 = [4 x i8] c"arp\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [2048 x i8]
%4 = alloca [1 x %struct.sock_filter]
%5 = alloca %struct.sock_fprog
%6 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%7 = bitcast [1 x %struct.sock_filter]* %4 to i8*
%8 = bitcast %struct.sock_fprog* %5 to i8*
%9 = getelementptr inbounds %struct.sock_fprog, %struct.sock_fprog* %5, i64 0, i32 0
store i32 1, i32* %9
%10 = getelementptr inbounds %struct.sock_fprog, %struct.sock_fprog* %5, i64 0, i32 1
%11 = getelementptr inbounds [1 x %struct.sock_filter], [1 x %struct.sock_filter]* %4, i64 0, i64 0
store %struct.sock_filter* %11, %struct.sock_filter** %10
%12 = load i32, i32* @AF_INET
%13 = load i32, i32* @SOCK_DGRAM
%14 = call i64 @socket(i32 %12, i32 %13, i32 0)
%15 = icmp slt i64 %14, 0
%16 = lshr i64 %14, 63
%17 = trunc i64 %16 to i32
br i1 %15, label %18, label %21
18: ; preds = %2
%19 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = load i32, i32* @SOL_SOCKET
%23 = load i32, i32* @SO_ATTACH_FILTER
%24 = call i64 @setsockopt(i32 %17, i32 %22, i32 %23, %struct.sock_fprog* %5, i32 16)
%25 = icmp slt i64 %24, 0
br i1 %25, label %58, label %26
26: ; preds = %21
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
%28 = call i32 @recvfrom(i32 %17, i8* %6, i32 2048, i32 0, i32* null, i32* null)
%29 = icmp slt i32 %28, 42
br i1 %29, label %62, label %30
30: ; preds = %26
%31 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 1
%32 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 2
%33 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 3
%34 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 4
%35 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 5
%36 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 6
%37 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 7
%38 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 8
%39 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 9
%40 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 10
%41 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 11
%42 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 14
%43 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 12
%44 = bitcast i8* %43 to i16*
%45 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 26
%46 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 27
%47 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 28
%48 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 29
%49 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 30
%50 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 31
%51 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 32
%52 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 33
%53 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 34
%54 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 35
%55 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 36
%56 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 37
%57 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 23
br label %68
58: ; preds = %21
%59 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%60 = call i32 @close(i32 %17)
%61 = call i32 @exit(i32 1)
unreachable
62: ; preds = %142, %26
%63 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%64 = load i32, i32* @errno
%65 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i32 %64)
%66 = call i32 @close(i32 %17)
%67 = call i32 @exit(i32 0)
unreachable
68: ; preds = %30, %142
%69 = load i8, i8* %6
%70 = zext i8 %69 to i32
%71 = load i8, i8* %31
%72 = zext i8 %71 to i32
%73 = load i8, i8* %32
%74 = zext i8 %73 to i32
%75 = load i8, i8* %33
%76 = zext i8 %75 to i32
%77 = load i8, i8* %34
%78 = zext i8 %77 to i32
%79 = load i8, i8* %35
%80 = zext i8 %79 to i32
%81 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.5, i64 0, i64 0), i32 %70, i32 %72, i32 %74, i32 %76, i32 %78, i32 %80)
%82 = load i8, i8* %36
%83 = zext i8 %82 to i32
%84 = load i8, i8* %37
%85 = zext i8 %84 to i32
%86 = load i8, i8* %38
%87 = zext i8 %86 to i32
%88 = load i8, i8* %39
%89 = zext i8 %88 to i32
%90 = load i8, i8* %40
%91 = zext i8 %90 to i32
%92 = load i8, i8* %41
%93 = zext i8 %92 to i32
%94 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str.6, i64 0, i64 0), i32 %83, i32 %85, i32 %87, i32 %89, i32 %91, i32 %93)
%95 = load i8, i8* %42
%96 = icmp eq i8 %95, 69
br i1 %96, label %97, label %132
97: ; preds = %68
%98 = load i8, i8* %45
%99 = zext i8 %98 to i32
%100 = load i8, i8* %46
%101 = zext i8 %100 to i32
%102 = load i8, i8* %47
%103 = zext i8 %102 to i32
%104 = load i8, i8* %48
%105 = zext i8 %104 to i32
%106 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i32 %99, i32 %101, i32 %103, i32 %105)
%107 = load i8, i8* %49
%108 = zext i8 %107 to i32
%109 = load i8, i8* %50
%110 = zext i8 %109 to i32
%111 = load i8, i8* %51
%112 = zext i8 %111 to i32
%113 = load i8, i8* %52
%114 = zext i8 %113 to i32
%115 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i32 %108, i32 %110, i32 %112, i32 %114)
%116 = load i8, i8* %53
%117 = zext i8 %116 to i32
%118 = shl nuw nsw i32 %117, 8
%119 = load i8, i8* %54
%120 = zext i8 %119 to i32
%121 = or i32 %118, %120
%122 = load i8, i8* %55
%123 = zext i8 %122 to i32
%124 = shl nuw nsw i32 %123, 8
%125 = load i8, i8* %56
%126 = zext i8 %125 to i32
%127 = or i32 %124, %126
%128 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0), i32 %121, i32 %127)
%129 = load i8, i8* %57
%130 = zext i8 %129 to i32
%131 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.10, i64 0, i64 0), i32 %130)
br label %142
132: ; preds = %68
%133 = load i16, i16* %44
%134 = call zeroext i16 @ntohs(i16 signext %133)
switch i16 %134, label %139 [
i16 2054, label %135
i16 -31011, label %137
]
135: ; preds = %132
%136 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.15, i64 0, i64 0))
br label %142
137: ; preds = %132
%138 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.14, i64 0, i64 0))
br label %142
139: ; preds = %132
%140 = zext i16 %134 to i32
%141 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.13, i64 0, i64 0), i32 %140)
br label %142
142: ; preds = %135, %137, %139, %97
%143 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
%144 = call i32 @recvfrom(i32 %17, i8* %6, i32 2048, i32 0, i32* null, i32* null)
%145 = icmp slt i32 %144, 42
br i1 %145, label %62, label %68
}