#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 */

/* Variables and functions */
int /*<<< orphan*/ ETH_P_IP;
#define IPPROTO_ICMP 133
#define IPPROTO_IGMP 132
#define IPPROTO_IPIP 131
#define IPPROTO_RAW 130
#define IPPROTO_TCP 129
#define IPPROTO_UDP 128
int /*<<< orphan*/ PF_PACKET;
int /*<<< orphan*/ SOCK_RAW;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int recvfrom(int, char *, int, int /*<<< orphan*/, int /*<<< orphan*/ *,
             int /*<<< orphan*/ *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  int sockfd, read_len, proto;
  char buffer[2048];
  char *ethhead, *iphead, *tcphead, *udphead, *icmphead, *p;
  if ((sockfd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_IP))) < 0) {
    fprintf(stdout, "create socket error/n");
    exit(0);
  }
  while (1) {
    printf("\n\n");
    read_len = recvfrom(sockfd, buffer, 2048, 0, NULL, NULL);
    if (read_len < 42) {
      fprintf(stdout, "Incomplete header, packet corrupt.\n");
      continue;
    }
    ethhead = buffer;
    p = ethhead;
    printf("MAC: %.2X:%02X:%02X:%02X:%02X:%02X==>"
           "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X\n",
           p[6] & (0xFF), p[7] & (0xFF), p[8] & (0xFF), p[9] & (0xFF),
           p[10] & (0xFF), p[11] & (0xFF), p[0] & (0xFF), p[1] & (0xFF),
           p[2] & (0xFF), p[3] & (0xFF), p[4] & (0xFF), p[5] & (0xFF));
    iphead = ethhead + 14;
    p = iphead + 12;
    printf("IP: %d.%d.%d.%d => %d.%d.%d.%d\n", p[0] & (0xFF), p[1] & (0xFF),
           p[2] & (0xFF), p[3] & (0xFF), p[4] & (0xFF), p[5] & (0xFF),
           p[6] & (0xFF), p[7] & (0xFF));
    proto = (iphead + 9)[0];
    p = iphead + 20;
    printf("Protocol: ");
    switch (proto) {
    case IPPROTO_ICMP:
      printf("ICMP\n");
      break;
    case IPPROTO_IGMP:
      printf("IGMP\n");
      break;
    case IPPROTO_IPIP:
      printf("IPIP\n");
      break;
    case IPPROTO_TCP:
    case IPPROTO_UDP:
      printf("%s,", proto == IPPROTO_TCP ? "TCP" : "UDP");
      printf("source port: %u,",
             (((int)(p[0]) << 8) & 0XFF00) | (p[1] & (0xFF)));
      printf("dest port: %u\n",
             (((int)(p[2]) << 8) & 0XFF00) | (p[3] & (0xFF)));
      break;
    case IPPROTO_RAW:
      printf("RAW\n");
      break;
    default:
      printf("Unkown, please query in include/linux/in.h\n");
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x8b0,%rsp
movl   $0x0,-0x24(%rbp)
mov    %edi,-0x28(%rbp)
mov    %rsi,-0x30(%rbp)
mov    0x2e69(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x878(%rbp)
mov    0x2e4a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x874(%rbp)
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
call   1030 <htons@plt>
mov    -0x878(%rbp),%edi
mov    -0x874(%rbp),%esi
mov    %eax,%edx
call   1080 <socket@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jge    11e7 <main+0x87>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
lea    0xe3d(%rip),%rsi
call   1050 <fprintf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
jmp    11ec <main+0x8c>
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x34(%rbp),%edi
lea    -0x840(%rbp),%rsi
mov    $0x800,%edx
xor    %ecx,%ecx
xor    %eax,%eax
mov    %eax,%r9d
mov    %r9,%r8
call   1060 <recvfrom@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x2a,-0x38(%rbp)
jge    123f <main+0xdf>
mov    0x2da4(%rip),%rax
mov    (%rax),%edi
lea    0xdfc(%rip),%rsi
call   1050 <fprintf@plt>
jmp    11ec <main+0x8c>
lea    -0x840(%rbp),%rax
mov    %rax,-0x848(%rbp)
mov    -0x848(%rbp),%rax
mov    %rax,-0x870(%rbp)
mov    -0x870(%rbp),%rax
mov    %rax,-0x898(%rbp)
movzbl 0x6(%rax),%esi
movzbl 0x7(%rax),%edx
movzbl 0x8(%rax),%ecx
movzbl 0x9(%rax),%r8d
movzbl 0xa(%rax),%r9d
movzbl 0xb(%rax),%edi
movzbl (%rax),%r10d
movzbl 0x1(%rax),%r11d
movzbl 0x2(%rax),%ebx
movzbl 0x3(%rax),%r14d
movzbl 0x4(%rax),%r15d
movzbl 0x5(%rax),%r12d
mov    %rsp,%rax
mov    %r12d,0x30(%rax)
mov    %r15d,0x28(%rax)
mov    %r14d,0x20(%rax)
mov    %ebx,0x18(%rax)
mov    %r11d,0x10(%rax)
mov    %r10d,0x8(%rax)
mov    %edi,(%rax)
lea    0xd93(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x881(%rbp)
call   1040 <printf@plt>
mov    -0x881(%rbp),%al
mov    -0x848(%rbp),%rcx
add    $0xe,%rcx
mov    %rcx,-0x850(%rbp)
mov    -0x850(%rbp),%rcx
add    $0xc,%rcx
mov    %rcx,-0x870(%rbp)
mov    -0x870(%rbp),%rdi
mov    %rdi,-0x890(%rbp)
movzbl (%rdi),%esi
movzbl 0x1(%rdi),%edx
movzbl 0x2(%rdi),%ecx
movzbl 0x3(%rdi),%r8d
movzbl 0x4(%rdi),%r9d
movzbl 0x5(%rdi),%r10d
movzbl 0x6(%rdi),%r11d
movzbl 0x7(%rdi),%ebx
mov    %rsp,%rdi
mov    %ebx,0x10(%rdi)
mov    %r11d,0x8(%rdi)
mov    %r10d,(%rdi)
lea    0xd5b(%rip),%rdi
call   1040 <printf@plt>
mov    -0x881(%rbp),%al
mov    -0x850(%rbp),%rcx
movsbl 0x9(%rcx),%ecx
mov    %ecx,-0x3c(%rbp)
mov    -0x850(%rbp),%rcx
add    $0x14,%rcx
mov    %rcx,-0x870(%rbp)
lea    0xd49(%rip),%rdi
call   1040 <printf@plt>
mov    -0x3c(%rbp),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x880(%rbp)
sub    $0x5,%eax
ja     1485 <main+0x325>
mov    -0x880(%rbp),%rax
lea    0xc65(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xd19(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1493 <main+0x333>
lea    0xd0c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1493 <main+0x333>
lea    0xcff(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1493 <main+0x333>
mov    -0x3c(%rbp),%ecx
lea    0xcf7(%rip),%rsi
lea    0xcec(%rip),%rax
cmp    $0x81,%ecx
cmove  %rax,%rsi
lea    0xcd7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x870(%rbp),%rax
movsbl (%rax),%esi
shl    $0x8,%esi
and    $0xff00,%esi
mov    -0x870(%rbp),%rax
movsbl 0x1(%rax),%eax
and    $0xff,%eax
or     %eax,%esi
lea    0xcb0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x870(%rbp),%rax
movsbl 0x2(%rax),%esi
shl    $0x8,%esi
and    $0xff00,%esi
mov    -0x870(%rbp),%rax
movsbl 0x3(%rax),%eax
and    $0xff,%eax
or     %eax,%esi
lea    0xc8d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1493 <main+0x333>
lea    0xc89(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1493 <main+0x333>
lea    0xc7b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11ec <main+0x8c>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x818,%rsp
mov    0x2e68(%rip),%rax
mov    (%rax),%ebx
mov    0x2e4f(%rip),%rax
mov    (%rax),%ebp
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
call   1040 <htons@plt>
mov    %ebx,%edi
mov    %ebp,%esi
mov    %eax,%edx
call   1090 <socket@plt>
test   %eax,%eax
js     12de <main+0x16e>
mov    %eax,%ebp
lea    0xe7b(%rip),%rbx
lea    0x10(%rsp),%r12
mov    %eax,0xc(%rsp)
jmp    129f <main+0x12f>
nopl   0x0(%rax,%rax,1)
movzbl 0x16(%rsp),%esi
movzbl 0x17(%rsp),%edx
movzbl 0x18(%rsp),%ecx
movzbl 0x19(%rsp),%r8d
movzbl 0x1a(%rsp),%r9d
movzbl 0x1b(%rsp),%r10d
movzbl 0x10(%rsp),%r11d
movzbl 0x11(%rsp),%ebp
movzbl 0x12(%rsp),%ebx
movzbl 0x13(%rsp),%r13d
movzbl 0x14(%rsp),%r14d
movzbl 0x15(%rsp),%r15d
sub    $0x8,%rsp
lea    0xe1c(%rip),%rdi
xor    %eax,%eax
push   %r15
push   %r14
push   %r13
push   %rbx
push   %rbp
push   %r11
push   %r10
call   1050 <printf@plt>
add    $0x40,%rsp
movzbl 0x2a(%rsp),%esi
movzbl 0x2b(%rsp),%edx
movzbl 0x2c(%rsp),%ecx
movzbl 0x2d(%rsp),%r8d
movzbl 0x2e(%rsp),%r9d
movzbl 0x2f(%rsp),%r10d
movzbl 0x30(%rsp),%ebx
movzbl 0x31(%rsp),%ebp
sub    $0x8,%rsp
lea    0xe13(%rip),%rdi
xor    %eax,%eax
push   %rbp
mov    0x1c(%rsp),%ebp
push   %rbx
lea    0xdbe(%rip),%rbx
push   %r10
call   1050 <printf@plt>
add    $0x20,%rsp
lea    0xe12(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe0f(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
mov    %r12,%rsi
mov    $0x800,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1070 <recvfrom@plt>
cmp    $0x29,%eax
jg     11d0 <main+0x60>
mov    0x2d02(%rip),%rax
mov    (%rax),%edi
lea    0xd3f(%rip),%rsi
call   1060 <fprintf@plt>
jmp    129f <main+0x12f>
mov    0x2ceb(%rip),%rax
mov    (%rax),%edi
lea    0xd12(%rip),%rsi
call   1060 <fprintf@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@PF_PACKET = global i32 0
@SOCK_RAW = global i32 0
@ETH_P_IP = global i32 0
@stdout = global i32 0
@.str = [22 x i8] c"create socket error/n\00"
@.str.1 = [3 x i8] c"\0A\0A\00"
@.str.2 = [36 x i8] c"Incomplete header, packet corrupt.\0A\00"
@.str.3 = [68 x i8] c"MAC: %.2X:%02X:%02X:%02X:%02X:%02X==>%.2X:%.2X:%.2X:%.2X:%.2X:%.2X\0A\00"
@.str.4 = [32 x i8] c"IP: %d.%d.%d.%d => %d.%d.%d.%d\0A\00"
@.str.5 = [11 x i8] c"Protocol: \00"
@.str.6 = [6 x i8] c"ICMP\0A\00"
@.str.7 = [6 x i8] c"IGMP\0A\00"
@.str.8 = [6 x i8] c"IPIP\0A\00"
@.str.9 = [4 x i8] c"%s,\00"
@.str.10 = [4 x i8] c"TCP\00"
@.str.11 = [4 x i8] c"UDP\00"
@.str.12 = [17 x i8] c"source port: %u,\00"
@.str.13 = [15 x i8] c"dest port: %u\0A\00"
@.str.14 = [5 x i8] c"RAW\0A\00"
@.str.15 = [44 x i8] c"Unkown, please query in include/linux/in.h\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 i32
%9 = alloca [2048 x i8]
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = load i32, i32* @PF_PACKET
%17 = load i32, i32* @SOCK_RAW
%18 = load i32, i32* @ETH_P_IP
%19 = call i32 @htons(i32 %18)
%20 = call i32 @socket(i32 %16, i32 %17, i32 %19)
store i32 %20, i32* %6
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %2
%23 = load i32, i32* @stdout
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%25 = call i32 @exit(i32 0)
unreachable
26: ; preds = %2
br label %27
27: ; preds = %26, %34, %197
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%29 = load i32, i32* %6
%30 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 0
%31 = call i32 @recvfrom(i32 %29, i8* %30, i32 2048, i32 0, i32* null, i32* null)
store i32 %31, i32* %7
%32 = load i32, i32* %7
%33 = icmp slt i32 %32, 42
br i1 %33, label %34, label %37
34: ; preds = %27
%35 = load i32, i32* @stdout
%36 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
br label %27
37: ; preds = %27
%38 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 0
store i8* %38, i8** %10
%39 = load i8*, i8** %10
store i8* %39, i8** %15
%40 = load i8*, i8** %15
%41 = getelementptr inbounds i8, i8* %40, i64 6
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = and i32 %43, 255
%45 = load i8*, i8** %15
%46 = getelementptr inbounds i8, i8* %45, i64 7
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = and i32 %48, 255
%50 = load i8*, i8** %15
%51 = getelementptr inbounds i8, i8* %50, i64 8
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = and i32 %53, 255
%55 = load i8*, i8** %15
%56 = getelementptr inbounds i8, i8* %55, i64 9
%57 = load i8, i8* %56
%58 = sext i8 %57 to i32
%59 = and i32 %58, 255
%60 = load i8*, i8** %15
%61 = getelementptr inbounds i8, i8* %60, i64 10
%62 = load i8, i8* %61
%63 = sext i8 %62 to i32
%64 = and i32 %63, 255
%65 = load i8*, i8** %15
%66 = getelementptr inbounds i8, i8* %65, i64 11
%67 = load i8, i8* %66
%68 = sext i8 %67 to i32
%69 = and i32 %68, 255
%70 = load i8*, i8** %15
%71 = getelementptr inbounds i8, i8* %70, i64 0
%72 = load i8, i8* %71
%73 = sext i8 %72 to i32
%74 = and i32 %73, 255
%75 = load i8*, i8** %15
%76 = getelementptr inbounds i8, i8* %75, i64 1
%77 = load i8, i8* %76
%78 = sext i8 %77 to i32
%79 = and i32 %78, 255
%80 = load i8*, i8** %15
%81 = getelementptr inbounds i8, i8* %80, i64 2
%82 = load i8, i8* %81
%83 = sext i8 %82 to i32
%84 = and i32 %83, 255
%85 = load i8*, i8** %15
%86 = getelementptr inbounds i8, i8* %85, i64 3
%87 = load i8, i8* %86
%88 = sext i8 %87 to i32
%89 = and i32 %88, 255
%90 = load i8*, i8** %15
%91 = getelementptr inbounds i8, i8* %90, i64 4
%92 = load i8, i8* %91
%93 = sext i8 %92 to i32
%94 = and i32 %93, 255
%95 = load i8*, i8** %15
%96 = getelementptr inbounds i8, i8* %95, i64 5
%97 = load i8, i8* %96
%98 = sext i8 %97 to i32
%99 = and i32 %98, 255
%100 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.3, i64 0, i64 0), i32 %44, i32 %49, i32 %54, i32 %59, i32 %64, i32 %69, i32 %74, i32 %79, i32 %84, i32 %89, i32 %94, i32 %99)
%101 = load i8*, i8** %10
%102 = getelementptr inbounds i8, i8* %101, i64 14
store i8* %102, i8** %11
%103 = load i8*, i8** %11
%104 = getelementptr inbounds i8, i8* %103, i64 12
store i8* %104, i8** %15
%105 = load i8*, i8** %15
%106 = getelementptr inbounds i8, i8* %105, i64 0
%107 = load i8, i8* %106
%108 = sext i8 %107 to i32
%109 = and i32 %108, 255
%110 = load i8*, i8** %15
%111 = getelementptr inbounds i8, i8* %110, i64 1
%112 = load i8, i8* %111
%113 = sext i8 %112 to i32
%114 = and i32 %113, 255
%115 = load i8*, i8** %15
%116 = getelementptr inbounds i8, i8* %115, i64 2
%117 = load i8, i8* %116
%118 = sext i8 %117 to i32
%119 = and i32 %118, 255
%120 = load i8*, i8** %15
%121 = getelementptr inbounds i8, i8* %120, i64 3
%122 = load i8, i8* %121
%123 = sext i8 %122 to i32
%124 = and i32 %123, 255
%125 = load i8*, i8** %15
%126 = getelementptr inbounds i8, i8* %125, i64 4
%127 = load i8, i8* %126
%128 = sext i8 %127 to i32
%129 = and i32 %128, 255
%130 = load i8*, i8** %15
%131 = getelementptr inbounds i8, i8* %130, i64 5
%132 = load i8, i8* %131
%133 = sext i8 %132 to i32
%134 = and i32 %133, 255
%135 = load i8*, i8** %15
%136 = getelementptr inbounds i8, i8* %135, i64 6
%137 = load i8, i8* %136
%138 = sext i8 %137 to i32
%139 = and i32 %138, 255
%140 = load i8*, i8** %15
%141 = getelementptr inbounds i8, i8* %140, i64 7
%142 = load i8, i8* %141
%143 = sext i8 %142 to i32
%144 = and i32 %143, 255
%145 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i32 %109, i32 %114, i32 %119, i32 %124, i32 %129, i32 %134, i32 %139, i32 %144)
%146 = load i8*, i8** %11
%147 = getelementptr inbounds i8, i8* %146, i64 9
%148 = getelementptr inbounds i8, i8* %147, i64 0
%149 = load i8, i8* %148
%150 = sext i8 %149 to i32
store i32 %150, i32* %8
%151 = load i8*, i8** %11
%152 = getelementptr inbounds i8, i8* %151, i64 20
store i8* %152, i8** %15
%153 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%154 = load i32, i32* %8
switch i32 %154, label %195 [
i32 133, label %155
i32 132, label %157
i32 131, label %159
i32 129, label %161
i32 128, label %161
i32 130, label %193
]
155: ; preds = %37
%156 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
br label %197
157: ; preds = %37
%158 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
br label %197
159: ; preds = %37
%160 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
br label %197
161: ; preds = %37, %37
%162 = load i32, i32* %8
%163 = icmp eq i32 %162, 129
%164 = zext i1 %163 to i64
%165 = select i1 %163, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0)
%166 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i8* %165)
%167 = load i8*, i8** %15
%168 = getelementptr inbounds i8, i8* %167, i64 0
%169 = load i8, i8* %168
%170 = sext i8 %169 to i32
%171 = shl i32 %170, 8
%172 = and i32 %171, 65280
%173 = load i8*, i8** %15
%174 = getelementptr inbounds i8, i8* %173, i64 1
%175 = load i8, i8* %174
%176 = sext i8 %175 to i32
%177 = and i32 %176, 255
%178 = or i32 %172, %177
%179 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.12, i64 0, i64 0), i32 %178)
%180 = load i8*, i8** %15
%181 = getelementptr inbounds i8, i8* %180, i64 2
%182 = load i8, i8* %181
%183 = sext i8 %182 to i32
%184 = shl i32 %183, 8
%185 = and i32 %184, 65280
%186 = load i8*, i8** %15
%187 = getelementptr inbounds i8, i8* %186, i64 3
%188 = load i8, i8* %187
%189 = sext i8 %188 to i32
%190 = and i32 %189, 255
%191 = or i32 %185, %190
%192 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.13, i64 0, i64 0), i32 %191)
br label %197
193: ; preds = %37
%194 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.14, i64 0, i64 0))
br label %197
195: ; preds = %37
%196 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.15, i64 0, i64 0))
br label %197
197: ; preds = %195, %193, %161, %159, %157, %155
br label %27
}

LLVM IR (-O2):
@PF_PACKET = global i32 0
@SOCK_RAW = global i32 0
@ETH_P_IP = global i32 0
@stdout = global i32 0
@.str = [22 x i8] c"create socket error/n\00"
@.str.2 = [36 x i8] c"Incomplete header, packet corrupt.\0A\00"
@.str.3 = [68 x i8] c"MAC: %.2X:%02X:%02X:%02X:%02X:%02X==>%.2X:%.2X:%.2X:%.2X:%.2X:%.2X\0A\00"
@.str.4 = [32 x i8] c"IP: %d.%d.%d.%d => %d.%d.%d.%d\0A\00"
@.str.5 = [11 x i8] c"Protocol: \00"
@str = [2 x i8] c"\0A\00"
@str.16 = [43 x i8] c"Unkown, please query in include/linux/in.h\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [2048 x i8]
%4 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @PF_PACKET
%6 = load i32, i32* @SOCK_RAW
%7 = load i32, i32* @ETH_P_IP
%8 = tail call i32 @htons(i32 %7)
%9 = tail call i32 @socket(i32 %5, i32 %6, i32 %8)
%10 = icmp slt i32 %9, 0
br i1 %10, label %31, label %11
11: ; preds = %2
%12 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 6
%13 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 7
%14 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 8
%15 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 9
%16 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 10
%17 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 11
%18 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 1
%19 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 2
%20 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 3
%21 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 4
%22 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 5
%23 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 26
%24 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 27
%25 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 28
%26 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 29
%27 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 30
%28 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 31
%29 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 32
%30 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 33
br label %35
31: ; preds = %2
%32 = load i32, i32* @stdout
%33 = tail call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%34 = tail call i32 @exit(i32 0)
unreachable
35: ; preds = %42, %11
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%37 = call i32 @recvfrom(i32 %9, i8* %4, i32 2048, i32 0, i32* null, i32* null)
%38 = icmp slt i32 %37, 42
br i1 %38, label %39, label %43
39: ; preds = %35
%40 = load i32, i32* @stdout
%41 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
br label %42
42: ; preds = %39, %43
br label %35
43: ; preds = %35
%44 = load i8, i8* %12
%45 = zext i8 %44 to i32
%46 = load i8, i8* %13
%47 = zext i8 %46 to i32
%48 = load i8, i8* %14
%49 = zext i8 %48 to i32
%50 = load i8, i8* %15
%51 = zext i8 %50 to i32
%52 = load i8, i8* %16
%53 = zext i8 %52 to i32
%54 = load i8, i8* %17
%55 = zext i8 %54 to i32
%56 = load i8, i8* %4
%57 = zext i8 %56 to i32
%58 = load i8, i8* %18
%59 = zext i8 %58 to i32
%60 = load i8, i8* %19
%61 = zext i8 %60 to i32
%62 = load i8, i8* %20
%63 = zext i8 %62 to i32
%64 = load i8, i8* %21
%65 = zext i8 %64 to i32
%66 = load i8, i8* %22
%67 = zext i8 %66 to i32
%68 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([68 x i8], [68 x i8]* @.str.3, i64 0, i64 0), i32 %45, i32 %47, i32 %49, i32 %51, i32 %53, i32 %55, i32 %57, i32 %59, i32 %61, i32 %63, i32 %65, i32 %67)
%69 = load i8, i8* %23
%70 = zext i8 %69 to i32
%71 = load i8, i8* %24
%72 = zext i8 %71 to i32
%73 = load i8, i8* %25
%74 = zext i8 %73 to i32
%75 = load i8, i8* %26
%76 = zext i8 %75 to i32
%77 = load i8, i8* %27
%78 = zext i8 %77 to i32
%79 = load i8, i8* %28
%80 = zext i8 %79 to i32
%81 = load i8, i8* %29
%82 = zext i8 %81 to i32
%83 = load i8, i8* %30
%84 = zext i8 %83 to i32
%85 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i32 %70, i32 %72, i32 %74, i32 %76, i32 %78, i32 %80, i32 %82, i32 %84)
%86 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%87 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str.16, i64 0, i64 0))
br label %42
}