#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_3__ TYPE_1__;

/* Type definitions */
typedef int uint8_t;
struct udphdr {
  int /*<<< orphan*/ len;
};
struct sockaddr_storage {
  int dummy;
};
struct TYPE_3__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
};
struct iphdr {
  int /*<<< orphan*/ saddr;
};
struct ifreq {
  int /*<<< orphan*/ ifr_addr;
  int /*<<< orphan*/ ifr_name;
  int /*<<< orphan*/ ifr_flags;
};
struct ether_header {
  int *ether_dhost;
};
typedef int ssize_t;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ IFF_PROMISC;
int IFNAMSIZ;
int INET6_ADDRSTRLEN;
int /*<<< orphan*/ PF_PACKET;
int /*<<< orphan*/ SIOCGIFADDR;
int /*<<< orphan*/ SIOCGIFFLAGS;
int /*<<< orphan*/ SIOCSIFFLAGS;
int /*<<< orphan*/ SOCK_RAW;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_BINDTODEVICE;
int /*<<< orphan*/ SO_REUSEADDR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
char *inet_ntoa(TYPE_1__);
int /*<<< orphan*/ inet_ntop(int /*<<< orphan*/, TYPE_1__ *, char *, int);
scalar_t__ ioctl(int, int /*<<< orphan*/, struct ifreq *);
int /*<<< orphan*/ memset(struct ifreq *, int /*<<< orphan*/, int);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int recvfrom(int, int *, int, int /*<<< orphan*/, int /*<<< orphan*/ *,
             int /*<<< orphan*/ *);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, ...);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char *, int);
int main(int argc, char *argv[]) {
  char sender[INET6_ADDRSTRLEN];
  int sockfd, ret, i;
  int sockopt;
  ssize_t numbytes;
  struct ifreq ifopts;
  struct ifreq if_ip;
  struct sockaddr_storage their_addr;
  uint8_t buf[1024];
  char ifName[IFNAMSIZ];
  if (argc > 1)
    strcpy(ifName, argv[1]);
  else
    strcpy(ifName, "eth0");
  struct ether_header *eh = (struct ether_header *)buf;
  struct iphdr *iph = (struct iphdr *)(buf + sizeof(struct ether_header));
  struct udphdr *udph = (struct udphdr *)(buf + sizeof(struct iphdr) +
                                          sizeof(struct ether_header));
  memset(&if_ip, 0, sizeof(struct ifreq));
  if ((sockfd = socket(PF_PACKET, SOCK_RAW, htons(0x0800))) == -1) {
    perror("listener: socket");
    return -1;
  }
  strncpy(ifopts.ifr_name, ifName, IFNAMSIZ - 1);
  ioctl(sockfd, SIOCGIFFLAGS, &ifopts);
  ifopts.ifr_flags |= IFF_PROMISC;
  ioctl(sockfd, SIOCSIFFLAGS, &ifopts);
  if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &sockopt, sizeof sockopt) ==
      -1) {
    perror("setsockopt");
    close(sockfd);
    exit(EXIT_FAILURE);
  }
  if (setsockopt(sockfd, SOL_SOCKET, SO_BINDTODEVICE, ifName, IFNAMSIZ - 1) ==
      -1) {
    perror("SO_BINDTODEVICE");
    close(sockfd);
    exit(EXIT_FAILURE);
  }
repeat:
  numbytes = recvfrom(sockfd, buf, 1024, 0, NULL, NULL);
  if (eh->ether_dhost[0] == 0x00 && eh->ether_dhost[1] == 0x00 &&
      eh->ether_dhost[2] == 0x00 && eh->ether_dhost[3] == 0x00 &&
      eh->ether_dhost[4] == 0x00 && eh->ether_dhost[5] == 0x00) {
    printf("Correct destination MAC address\n");
  } else {
    ret = -1;
    goto done;
  }
  ((struct sockaddr_in *)&their_addr)->sin_addr.s_addr = iph->saddr;
  inet_ntop(AF_INET, &((struct sockaddr_in *)&their_addr)->sin_addr, sender,
            sizeof sender);
  strncpy(if_ip.ifr_name, ifName, IFNAMSIZ - 1);
  if (ioctl(sockfd, SIOCGIFADDR, &if_ip) >= 0) {
    printf("Source IP: %s\n My IP: %s\n", sender,
           inet_ntoa(((struct sockaddr_in *)&if_ip.ifr_addr)->sin_addr));
  }
  ret = ntohs(udph->len) - sizeof(struct udphdr);
  printf("\tData:");
  if (numbytes < 20)
    for (i = 0; i < numbytes; i++)
      printf("%02x:", buf[i]);
  printf("\n");
done:
  goto repeat;
  close(sockfd);
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10a0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2db8(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x1098(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x1090(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    0x2d5a(%rip),%rax
mov    (%rax),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x1088(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x1068(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    128d <main+0x9d>
mov    -0x1088(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1050 <strcpy@plt>
jmp    12a0 <main+0xb0>
mov    -0x1088(%rbp),%rdi
lea    0xd65(%rip),%rsi
call   1050 <strcpy@plt>
lea    -0x1060(%rbp),%rax
mov    %rax,-0x1070(%rbp)
lea    -0x1060(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x1078(%rbp)
lea    -0x1060(%rbp),%rax
add    $0x10,%rax
add    $0x20,%rax
mov    %rax,-0x1080(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   10a0 <memset@plt>
mov    0x2cfb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10a0(%rbp)
mov    0x2cbc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x109c(%rbp)
mov    $0x800,%edi
call   1080 <htons@plt>
mov    -0x10a0(%rbp),%edi
mov    -0x109c(%rbp),%esi
mov    %eax,%edx
call   1110 <socket@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
jne    134f <main+0x15f>
lea    0xcd1(%rip),%rdi
call   10f0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret
mov    -0x1088(%rbp),%rsi
mov    -0x3c(%rbp),%edi
mov    0x2c40(%rip),%rax
mov    (%rax),%edx
sub    $0x1,%edx
call   1040 <strncpy@plt>
mov    -0x24(%rbp),%edi
mov    0x2c3c(%rip),%rax
mov    (%rax),%esi
lea    -0x40(%rbp),%rdx
call   10b0 <ioctl@plt>
mov    0x2c0a(%rip),%rax
mov    (%rax),%eax
or     -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x24(%rbp),%edi
mov    0x2c60(%rip),%rax
mov    (%rax),%esi
lea    -0x40(%rbp),%rdx
call   10b0 <ioctl@plt>
mov    -0x24(%rbp),%edi
mov    0x2c2b(%rip),%rax
mov    (%rax),%esi
mov    0x2bd2(%rip),%rax
mov    (%rax),%edx
lea    -0x30(%rbp),%rcx
mov    $0x4,%r8d
mov    $0x0,%al
call   1060 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    13f4 <main+0x204>
lea    0xc3d(%rip),%rdi
call   10f0 <perror@plt>
mov    -0x24(%rbp),%edi
call   10c0 <close@plt>
mov    0x2bab(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    -0x1088(%rbp),%rcx
mov    -0x24(%rbp),%edi
mov    0x2bd3(%rip),%rax
mov    (%rax),%esi
mov    0x2b72(%rip),%rax
mov    (%rax),%edx
mov    0x2b89(%rip),%rax
mov    (%rax),%r8d
sub    $0x1,%r8d
mov    $0x0,%al
call   1060 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    1450 <main+0x260>
lea    0xbec(%rip),%rdi
call   10f0 <perror@plt>
mov    -0x24(%rbp),%edi
call   10c0 <close@plt>
mov    0x2b4f(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
jmp    1455 <main+0x265>
mov    -0x24(%rbp),%edi
lea    -0x1060(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
xor    %eax,%eax
mov    %eax,%r9d
mov    %r9,%r8
call   10d0 <recvfrom@plt>
mov    %eax,-0x34(%rbp)
mov    -0x1070(%rbp),%rax
mov    (%rax),%rax
cmpl   $0x0,(%rax)
jne    1500 <main+0x310>
mov    -0x1070(%rbp),%rax
mov    (%rax),%rax
cmpl   $0x0,0x4(%rax)
jne    1500 <main+0x310>
mov    -0x1070(%rbp),%rax
mov    (%rax),%rax
cmpl   $0x0,0x8(%rax)
jne    1500 <main+0x310>
mov    -0x1070(%rbp),%rax
mov    (%rax),%rax
cmpl   $0x0,0xc(%rax)
jne    1500 <main+0x310>
mov    -0x1070(%rbp),%rax
mov    (%rax),%rax
cmpl   $0x0,0x10(%rax)
jne    1500 <main+0x310>
mov    -0x1070(%rbp),%rax
mov    (%rax),%rax
cmpl   $0x0,0x14(%rax)
jne    1500 <main+0x310>
lea    0xb3d(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
jmp    150c <main+0x31c>
movl   $0xffffffff,-0x28(%rbp)
jmp    1610 <main+0x420>
mov    -0x1090(%rbp),%rdx
mov    -0x1098(%rbp),%rax
mov    -0x1078(%rbp),%rcx
mov    (%rcx),%ecx
mov    %ecx,-0x58(%rbp)
mov    0x2a93(%rip),%rcx
mov    (%rcx),%edi
lea    -0x58(%rbp),%rsi
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
mov    -0x1088(%rbp),%rsi
mov    -0x4c(%rbp),%edi
mov    0x2a55(%rip),%rax
mov    (%rax),%edx
sub    $0x1,%edx
call   1040 <strncpy@plt>
mov    -0x24(%rbp),%edi
mov    0x2a71(%rip),%rax
mov    (%rax),%esi
lea    -0x50(%rbp),%rdx
call   10b0 <ioctl@plt>
cmp    $0x0,%rax
jl     1594 <main+0x3a4>
mov    -0x50(%rbp),%edi
call   1070 <inet_ntoa@plt>
mov    -0x1090(%rbp),%rsi
mov    %rax,%rdx
lea    0xac5(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x1080(%rbp),%rax
mov    (%rax),%edi
call   10e0 <ntohs@plt>
cltq
sub    $0x4,%rax
mov    %eax,-0x28(%rbp)
lea    0xaba(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
cmpl   $0x14,-0x34(%rbp)
jge    1602 <main+0x412>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    15fd <main+0x40d>
movslq -0x2c(%rbp),%rax
mov    -0x1060(%rbp,%rax,4),%esi
lea    0xa8b(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    15ca <main+0x3da>
jmp    1602 <main+0x412>
lea    0xa61(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
jmp    1455 <main+0x265>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1048,%rsp
mov    0x2d9d(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r12
mov    %rax,-0x58(%rbp)
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    0x2d57(%rip),%r15
mov    (%r15),%eax
mov    %rsp,%r13
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
cmp    $0x2,%edi
jl     1268 <main+0x58>
mov    0x8(%rsi),%rsi
jmp    126f <main+0x5f>
lea    0xd91(%rip),%rsi
mov    %r13,%rdi
call   1060 <strcpy@plt>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   10c0 <memset@plt>
mov    0x2d5a(%rip),%rax
mov    (%rax),%r14d
mov    0x2d20(%rip),%rax
mov    (%rax),%ebx
mov    $0x800,%edi
call   10a0 <htons@plt>
mov    %r14d,%edi
mov    %ebx,%esi
mov    %eax,%edx
call   1130 <socket@plt>
cmp    $0xffffffff,%eax
je     1490 <main+0x280>
mov    %eax,%ebx
mov    (%r15),%edx
add    $0xffffffff,%edx
mov    %r13,%rsi
call   1050 <strncpy@plt>
mov    0x2ce0(%rip),%rax
mov    (%rax),%esi
lea    -0x68(%rbp),%r14
mov    %ebx,%edi
mov    %r14,%rdx
call   10d0 <ioctl@plt>
mov    0x2ca9(%rip),%rax
mov    (%rax),%eax
or     %eax,-0x60(%rbp)
mov    0x2d05(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   10d0 <ioctl@plt>
mov    0x2cd2(%rip),%r14
mov    (%r14),%esi
mov    0x2c78(%rip),%rax
mov    (%rax),%edx
lea    -0x5c(%rbp),%rcx
mov    $0x4,%r8d
mov    %ebx,%edi
xor    %eax,%eax
call   1080 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     14b0 <main+0x2a0>
mov    (%r14),%esi
mov    0x2c48(%rip),%rax
mov    (%rax),%edx
mov    (%r15),%r8d
add    $0xffffffff,%r8d
mov    %ebx,%edi
mov    %r13,-0x50(%rbp)
mov    %r13,%rcx
xor    %eax,%eax
call   1080 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     14b9 <main+0x2a9>
lea    -0x1070(%rbp),%r13
lea    0xcea(%rip),%r14
mov    %r12,-0x48(%rbp)
jmp    1380 <main+0x170>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    -0x48(%rbp),%r12
nopl   0x0(%rax)
mov    %ebx,%edi
mov    %r13,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   10f0 <recvfrom@plt>
mov    %eax,%r15d
mov    -0x1070(%rbp),%rax
cmpl   $0x0,(%rax)
jne    1380 <main+0x170>
cmpl   $0x0,0x4(%rax)
jne    1380 <main+0x170>
cmpl   $0x0,0x8(%rax)
jne    1380 <main+0x170>
cmpl   $0x0,0xc(%rax)
jne    1380 <main+0x170>
cmpl   $0x0,0x10(%rax)
jne    1380 <main+0x170>
cmpl   $0x0,0x14(%rax)
jne    1380 <main+0x170>
lea    0xc8d(%rip),%rdi
call   1070 <puts@plt>
mov    -0x1050(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2be0(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
mov    %r12,%rdx
mov    -0x58(%rbp),%rcx
call   1030 <inet_ntop@plt>
mov    -0x3c(%rbp),%edi
mov    0x2ba4(%rip),%rax
mov    (%rax),%edx
add    $0xffffffff,%edx
mov    -0x50(%rbp),%rsi
call   1050 <strncpy@plt>
mov    0x2bbf(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
lea    -0x40(%rbp),%rdx
call   10d0 <ioctl@plt>
test   %rax,%rax
js     143f <main+0x22f>
mov    -0x40(%rbp),%edi
call   1090 <inet_ntoa@plt>
lea    0xbff(%rip),%rdi
mov    %r12,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   10b0 <printf@plt>
mov    -0x1040(%rbp),%edi
call   1100 <ntohs@plt>
lea    0xbfa(%rip),%rdi
xor    %eax,%eax
call   10b0 <printf@plt>
lea    -0x1(%r15),%eax
cmp    $0x12,%eax
ja     136e <main+0x15e>
mov    %r15d,%r15d
xor    %r12d,%r12d
nopl   0x0(%rax,%rax,1)
mov    -0x1070(%rbp,%r12,4),%esi
ff
mov    %r14,%rdi
xor    %eax,%eax
call   10b0 <printf@plt>
add    $0x1,%r12
cmp    %r12,%r15
jne    1470 <main+0x260>
jmp    136e <main+0x15e>
lea    0xb6e(%rip),%rdi
call   1110 <perror@plt>
mov    $0xffffffff,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xb5f(%rip),%rdi
jmp    14c0 <main+0x2b0>
lea    0xb61(%rip),%rdi
call   1110 <perror@plt>
mov    %ebx,%edi
call   10e0 <close@plt>
mov    0x2ac5(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>

LLVM IR (-O0):
%struct.ifreq = type { i32, i32, i32 }
%struct.sockaddr_storage = type { i32 }
%struct.ether_header = type { i32* }
%struct.iphdr = type { i32 }
%struct.udphdr = type { i32 }
%struct.sockaddr_in = type { %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i32 }
@INET6_ADDRSTRLEN = global i32 0
@IFNAMSIZ = global i32 0
@.str = [5 x i8] c"eth0\00"
@PF_PACKET = global i32 0
@SOCK_RAW = global i32 0
@.str.1 = [17 x i8] c"listener: socket\00"
@SIOCGIFFLAGS = global i32 0
@IFF_PROMISC = global i32 0
@SIOCSIFFLAGS = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.2 = [11 x i8] c"setsockopt\00"
@EXIT_FAILURE = global i32 0
@SO_BINDTODEVICE = global i32 0
@.str.3 = [16 x i8] c"SO_BINDTODEVICE\00"
@.str.4 = [33 x i8] c"Correct destination MAC address\0A\00"
@AF_INET = global i32 0
@SIOCGIFADDR = global i32 0
@.str.5 = [26 x i8] c"Source IP: %s\0A My IP: %s\0A\00"
@.str.6 = [7 x i8] c"\09Data:\00"
@.str.7 = [6 x i8] c"%02x:\00"
@.str.8 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca %struct.ifreq
%14 = alloca %struct.ifreq
%15 = alloca %struct.sockaddr_storage
%16 = alloca [1024 x i32]
%17 = alloca i64
%18 = alloca %struct.ether_header*
%19 = alloca %struct.iphdr*
%20 = alloca %struct.udphdr*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%21 = load i32, i32* @INET6_ADDRSTRLEN
%22 = zext i32 %21 to i64
%23 = call i8* @llvm.stacksave()
store i8* %23, i8** %6
%24 = alloca i8, i64 %22
store i64 %22, i64* %7
%25 = load i32, i32* @IFNAMSIZ
%26 = zext i32 %25 to i64
%27 = alloca i8, i64 %26
store i64 %26, i64* %17
%28 = load i32, i32* %4
%29 = icmp sgt i32 %28, 1
br i1 %29, label %30, label %35
30: ; preds = %2
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i32 @strcpy(i8* %27, i8* %33)
br label %37
35: ; preds = %2
%36 = call i32 @strcpy(i8* %27, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %37
37: ; preds = %35, %30
%38 = getelementptr inbounds [1024 x i32], [1024 x i32]* %16, i64 0, i64 0
%39 = bitcast i32* %38 to %struct.ether_header*
store %struct.ether_header* %39, %struct.ether_header** %18
%40 = getelementptr inbounds [1024 x i32], [1024 x i32]* %16, i64 0, i64 0
%41 = getelementptr inbounds i32, i32* %40, i64 8
%42 = bitcast i32* %41 to %struct.iphdr*
store %struct.iphdr* %42, %struct.iphdr** %19
%43 = getelementptr inbounds [1024 x i32], [1024 x i32]* %16, i64 0, i64 0
%44 = getelementptr inbounds i32, i32* %43, i64 4
%45 = getelementptr inbounds i32, i32* %44, i64 8
%46 = bitcast i32* %45 to %struct.udphdr*
store %struct.udphdr* %46, %struct.udphdr** %20
%47 = call i32 @memset(%struct.ifreq* %14, i32 0, i32 12)
%48 = load i32, i32* @PF_PACKET
%49 = load i32, i32* @SOCK_RAW
%50 = call i32 @htons(i32 2048)
%51 = call i32 @socket(i32 %48, i32 %49, i32 %50)
store i32 %51, i32* %8
%52 = icmp eq i32 %51, -1
br i1 %52, label %53, label %57
53: ; preds = %37
%54 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
%55 = load i8*, i8** %6
%56 = load i32, i32* %3
ret i32 %56
57: ; preds = %37
%58 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %13, i32 0, i32 1
%59 = load i32, i32* %58
%60 = load i32, i32* @IFNAMSIZ
%61 = sub nsw i32 %60, 1
%62 = call i32 @strncpy(i32 %59, i8* %27, i32 %61)
%63 = load i32, i32* %8
%64 = load i32, i32* @SIOCGIFFLAGS
%65 = call i64 @ioctl(i32 %63, i32 %64, %struct.ifreq* %13)
%66 = load i32, i32* @IFF_PROMISC
%67 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %13, i32 0, i32 2
%68 = load i32, i32* %67
%69 = or i32 %68, %66
store i32 %69, i32* %67
%70 = load i32, i32* %8
%71 = load i32, i32* @SIOCSIFFLAGS
%72 = call i64 @ioctl(i32 %70, i32 %71, %struct.ifreq* %13)
%73 = load i32, i32* %8
%74 = load i32, i32* @SOL_SOCKET
%75 = load i32, i32* @SO_REUSEADDR
%76 = call i32 (i32, i32, i32, ...) @setsockopt(i32 %73, i32 %74, i32 %75, i32* %11, i64 4)
%77 = icmp eq i32 %76, -1
br i1 %77, label %78, label %84
78: ; preds = %57
%79 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%80 = load i32, i32* %8
%81 = call i32 @close(i32 %80)
%82 = load i32, i32* @EXIT_FAILURE
%83 = call i32 @exit(i32 %82)
unreachable
84: ; preds = %57
%85 = load i32, i32* %8
%86 = load i32, i32* @SOL_SOCKET
%87 = load i32, i32* @SO_BINDTODEVICE
%88 = load i32, i32* @IFNAMSIZ
%89 = sub nsw i32 %88, 1
%90 = call i32 (i32, i32, i32, ...) @setsockopt(i32 %85, i32 %86, i32 %87, i8* %27, i32 %89)
%91 = icmp eq i32 %90, -1
br i1 %91, label %92, label %98
92: ; preds = %84
%93 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%94 = load i32, i32* %8
%95 = call i32 @close(i32 %94)
%96 = load i32, i32* @EXIT_FAILURE
%97 = call i32 @exit(i32 %96)
unreachable
98: ; preds = %84
br label %99
99: ; preds = %204, %98
%100 = load i32, i32* %8
%101 = getelementptr inbounds [1024 x i32], [1024 x i32]* %16, i64 0, i64 0
%102 = call i32 @recvfrom(i32 %100, i32* %101, i32 1024, i32 0, i32* null, i32* null)
store i32 %102, i32* %12
%103 = load %struct.ether_header*, %struct.ether_header** %18
%104 = getelementptr inbounds %struct.ether_header, %struct.ether_header* %103, i32 0, i32 0
%105 = load i32*, i32** %104
%106 = getelementptr inbounds i32, i32* %105, i64 0
%107 = load i32, i32* %106
%108 = icmp eq i32 %107, 0
br i1 %108, label %109, label %146
109: ; preds = %99
%110 = load %struct.ether_header*, %struct.ether_header** %18
%111 = getelementptr inbounds %struct.ether_header, %struct.ether_header* %110, i32 0, i32 0
%112 = load i32*, i32** %111
%113 = getelementptr inbounds i32, i32* %112, i64 1
%114 = load i32, i32* %113
%115 = icmp eq i32 %114, 0
br i1 %115, label %116, label %146
116: ; preds = %109
%117 = load %struct.ether_header*, %struct.ether_header** %18
%118 = getelementptr inbounds %struct.ether_header, %struct.ether_header* %117, i32 0, i32 0
%119 = load i32*, i32** %118
%120 = getelementptr inbounds i32, i32* %119, i64 2
%121 = load i32, i32* %120
%122 = icmp eq i32 %121, 0
br i1 %122, label %123, label %146
123: ; preds = %116
%124 = load %struct.ether_header*, %struct.ether_header** %18
%125 = getelementptr inbounds %struct.ether_header, %struct.ether_header* %124, i32 0, i32 0
%126 = load i32*, i32** %125
%127 = getelementptr inbounds i32, i32* %126, i64 3
%128 = load i32, i32* %127
%129 = icmp eq i32 %128, 0
br i1 %129, label %130, label %146
130: ; preds = %123
%131 = load %struct.ether_header*, %struct.ether_header** %18
%132 = getelementptr inbounds %struct.ether_header, %struct.ether_header* %131, i32 0, i32 0
%133 = load i32*, i32** %132
%134 = getelementptr inbounds i32, i32* %133, i64 4
%135 = load i32, i32* %134
%136 = icmp eq i32 %135, 0
br i1 %136, label %137, label %146
137: ; preds = %130
%138 = load %struct.ether_header*, %struct.ether_header** %18
%139 = getelementptr inbounds %struct.ether_header, %struct.ether_header* %138, i32 0, i32 0
%140 = load i32*, i32** %139
%141 = getelementptr inbounds i32, i32* %140, i64 5
%142 = load i32, i32* %141
%143 = icmp eq i32 %142, 0
br i1 %143, label %144, label %146
144: ; preds = %137
%145 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
br label %147
146: ; preds = %137, %130, %123, %116, %109, %99
store i32 -1, i32* %9
br label %204
147: ; preds = %144
%148 = load %struct.iphdr*, %struct.iphdr** %19
%149 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %148, i32 0, i32 0
%150 = load i32, i32* %149
%151 = bitcast %struct.sockaddr_storage* %15 to %struct.sockaddr_in*
%152 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %151, i32 0, i32 0
%153 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %152, i32 0, i32 0
store i32 %150, i32* %153
%154 = load i32, i32* @AF_INET
%155 = bitcast %struct.sockaddr_storage* %15 to %struct.sockaddr_in*
%156 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %155, i32 0, i32 0
%157 = trunc i64 %22 to i32
%158 = call i32 @inet_ntop(i32 %154, %struct.TYPE_3__* %156, i8* %24, i32 %157)
%159 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %14, i32 0, i32 1
%160 = load i32, i32* %159
%161 = load i32, i32* @IFNAMSIZ
%162 = sub nsw i32 %161, 1
%163 = call i32 @strncpy(i32 %160, i8* %27, i32 %162)
%164 = load i32, i32* %8
%165 = load i32, i32* @SIOCGIFADDR
%166 = call i64 @ioctl(i32 %164, i32 %165, %struct.ifreq* %14)
%167 = icmp sge i64 %166, 0
br i1 %167, label %168, label %176
168: ; preds = %147
%169 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %14, i32 0, i32 0
%170 = bitcast i32* %169 to %struct.sockaddr_in*
%171 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %170, i32 0, i32 0
%172 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %171, i32 0, i32 0
%173 = load i32, i32* %172
%174 = call i8* @inet_ntoa(i32 %173)
%175 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %24, i8* %174)
br label %176
176: ; preds = %168, %147
%177 = load %struct.udphdr*, %struct.udphdr** %20
%178 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %177, i32 0, i32 0
%179 = load i32, i32* %178
%180 = call i32 @ntohs(i32 %179)
%181 = sext i32 %180 to i64
%182 = sub i64 %181, 4
%183 = trunc i64 %182 to i32
store i32 %183, i32* %9
%184 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%185 = load i32, i32* %12
%186 = icmp slt i32 %185, 20
br i1 %186, label %187, label %202
187: ; preds = %176
store i32 0, i32* %10
br label %188
188: ; preds = %198, %187
%189 = load i32, i32* %10
%190 = load i32, i32* %12
%191 = icmp slt i32 %189, %190
br i1 %191, label %192, label %201
192: ; preds = %188
%193 = load i32, i32* %10
%194 = sext i32 %193 to i64
%195 = getelementptr inbounds [1024 x i32], [1024 x i32]* %16, i64 0, i64 %194
%196 = load i32, i32* %195
%197 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i32 %196)
br label %198
198: ; preds = %192
%199 = load i32, i32* %10
%200 = add nsw i32 %199, 1
store i32 %200, i32* %10
br label %188
201: ; preds = %188
br label %202
202: ; preds = %201, %176
%203 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
br label %204
204: ; preds = %202, %146
br label %99
}

LLVM IR (-O2):
%struct.ifreq = type { i32, i32, i32 }
%struct.sockaddr_storage = type { i32 }
%struct.TYPE_3__ = type { i32 }
@INET6_ADDRSTRLEN = global i32 0
@IFNAMSIZ = global i32 0
@.str = [5 x i8] c"eth0\00"
@PF_PACKET = global i32 0
@SOCK_RAW = global i32 0
@.str.1 = [17 x i8] c"listener: socket\00"
@SIOCGIFFLAGS = global i32 0
@IFF_PROMISC = global i32 0
@SIOCSIFFLAGS = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.2 = [11 x i8] c"setsockopt\00"
@EXIT_FAILURE = global i32 0
@SO_BINDTODEVICE = global i32 0
@.str.3 = [16 x i8] c"SO_BINDTODEVICE\00"
@AF_INET = global i32 0
@SIOCGIFADDR = global i32 0
@.str.5 = [26 x i8] c"Source IP: %s\0A My IP: %s\0A\00"
@.str.6 = [7 x i8] c"\09Data:\00"
@.str.7 = [6 x i8] c"%02x:\00"
@str = [32 x i8] c"Correct destination MAC address\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.ifreq
%5 = alloca %struct.ifreq
%6 = alloca %struct.sockaddr_storage
%7 = alloca [1024 x i32]
%8 = load i32, i32* @INET6_ADDRSTRLEN
%9 = zext i32 %8 to i64
%10 = alloca i8, i64 %9
%11 = bitcast i32* %3 to i8*
%12 = bitcast %struct.ifreq* %4 to i8*
%13 = bitcast %struct.ifreq* %5 to i8*
%14 = bitcast %struct.sockaddr_storage* %6 to i8*
%15 = bitcast [1024 x i32]* %7 to i8*
%16 = load i32, i32* @IFNAMSIZ
%17 = zext i32 %16 to i64
%18 = alloca i8, i64 %17
%19 = icmp sgt i32 %0, 1
br i1 %19, label %20, label %23
20: ; preds = %2
%21 = getelementptr inbounds i8*, i8** %1, i64 1
%22 = load i8*, i8** %21
br label %23
23: ; preds = %2, %20
%24 = phi i8* [ %22, %20 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %2 ]
%25 = call i32 @strcpy(i8* %18, i8* %24)
%26 = getelementptr inbounds [1024 x i32], [1024 x i32]* %7, i64 0, i64 0
%27 = getelementptr inbounds [1024 x i32], [1024 x i32]* %7, i64 0, i64 8
%28 = getelementptr inbounds [1024 x i32], [1024 x i32]* %7, i64 0, i64 12
%29 = call i32 @memset(%struct.ifreq* %5, i32 0, i32 12)
%30 = load i32, i32* @PF_PACKET
%31 = load i32, i32* @SOCK_RAW
%32 = call i32 @htons(i32 2048)
%33 = call i32 @socket(i32 %30, i32 %31, i32 %32)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %37
35: ; preds = %23
%36 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
ret i32 -1
37: ; preds = %23
%38 = load i32, i32* @IFNAMSIZ
%39 = add nsw i32 %38, -1
%40 = call i32 @strncpy(i32 undef, i8* %18, i32 %39)
%41 = load i32, i32* @SIOCGIFFLAGS
%42 = call i64 @ioctl(i32 %33, i32 %41, %struct.ifreq* %4)
%43 = load i32, i32* @IFF_PROMISC
%44 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %4, i64 0, i32 2
%45 = load i32, i32* %44
%46 = or i32 %45, %43
store i32 %46, i32* %44
%47 = load i32, i32* @SIOCSIFFLAGS
%48 = call i64 @ioctl(i32 %33, i32 %47, %struct.ifreq* %4)
%49 = load i32, i32* @SOL_SOCKET
%50 = load i32, i32* @SO_REUSEADDR
%51 = call i32 (i32, i32, i32, ...) @setsockopt(i32 %33, i32 %49, i32 %50, i32* %3, i64 4)
%52 = icmp eq i32 %51, -1
br i1 %52, label %53, label %58
53: ; preds = %37
%54 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%55 = call i32 @close(i32 %33)
%56 = load i32, i32* @EXIT_FAILURE
%57 = call i32 @exit(i32 %56)
unreachable
58: ; preds = %37
%59 = load i32, i32* @SOL_SOCKET
%60 = load i32, i32* @SO_BINDTODEVICE
%61 = load i32, i32* @IFNAMSIZ
%62 = add nsw i32 %61, -1
%63 = call i32 (i32, i32, i32, ...) @setsockopt(i32 %33, i32 %59, i32 %60, i8* %18, i32 %62)
%64 = icmp eq i32 %63, -1
br i1 %64, label %71, label %65
65: ; preds = %58
%66 = bitcast [1024 x i32]* %7 to i32**
%67 = bitcast %struct.sockaddr_storage* %6 to %struct.TYPE_3__*
%68 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %6, i64 0, i32 0
%69 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %5, i64 0, i32 1
%70 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %5, i64 0, i32 0
br label %76
71: ; preds = %58
%72 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%73 = call i32 @close(i32 %33)
%74 = load i32, i32* @EXIT_FAILURE
%75 = call i32 @exit(i32 %74)
unreachable
76: ; preds = %81, %65
%77 = call i32 @recvfrom(i32 %33, i32* %26, i32 1024, i32 0, i32* null, i32* null)
%78 = load i32*, i32** %66
%79 = load i32, i32* %78
%80 = icmp eq i32 %79, 0
br i1 %80, label %82, label %81
81: ; preds = %76, %82, %86, %90, %94, %98, %133
br label %76
82: ; preds = %76
%83 = getelementptr inbounds i32, i32* %78, i64 1
%84 = load i32, i32* %83
%85 = icmp eq i32 %84, 0
br i1 %85, label %86, label %81
86: ; preds = %82
%87 = getelementptr inbounds i32, i32* %78, i64 2
%88 = load i32, i32* %87
%89 = icmp eq i32 %88, 0
br i1 %89, label %90, label %81
90: ; preds = %86
%91 = getelementptr inbounds i32, i32* %78, i64 3
%92 = load i32, i32* %91
%93 = icmp eq i32 %92, 0
br i1 %93, label %94, label %81
94: ; preds = %90
%95 = getelementptr inbounds i32, i32* %78, i64 4
%96 = load i32, i32* %95
%97 = icmp eq i32 %96, 0
br i1 %97, label %98, label %81
98: ; preds = %94
%99 = getelementptr inbounds i32, i32* %78, i64 5
%100 = load i32, i32* %99
%101 = icmp eq i32 %100, 0
br i1 %101, label %102, label %81
102: ; preds = %98
%103 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
%104 = load i32, i32* %27
store i32 %104, i32* %68
%105 = load i32, i32* @AF_INET
%106 = call i32 @inet_ntop(i32 %105, %struct.TYPE_3__* %67, i8* %10, i32 %8)
%107 = load i32, i32* %69
%108 = load i32, i32* @IFNAMSIZ
%109 = add nsw i32 %108, -1
%110 = call i32 @strncpy(i32 %107, i8* %18, i32 %109)
%111 = load i32, i32* @SIOCGIFADDR
%112 = call i64 @ioctl(i32 %33, i32 %111, %struct.ifreq* %5)
%113 = icmp sgt i64 %112, -1
br i1 %113, label %114, label %118
114: ; preds = %102
%115 = load i32, i32* %70
%116 = call i8* @inet_ntoa(i32 %115)
%117 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %10, i8* %116)
br label %118
118: ; preds = %114, %102
%119 = load i32, i32* %28
%120 = call i32 @ntohs(i32 %119)
%121 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%122 = add i32 %77, -1
%123 = icmp ult i32 %122, 19
br i1 %123, label %124, label %133
124: ; preds = %118
%125 = zext i32 %77 to i64
br label %126
126: ; preds = %124, %126
%127 = phi i64 [ 0, %124 ], [ %131, %126 ]
%128 = getelementptr inbounds [1024 x i32], [1024 x i32]* %7, i64 0, i64 %127
%129 = load i32, i32* %128
%130 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i32 %129)
%131 = add nuw nsw i64 %127, 1
%132 = icmp eq i64 %131, %125
br i1 %132, label %133, label %126
133: ; preds = %126, %118
%134 = call i32 @putchar(i32 10)
br label %81
}