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

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ sa_data;
};
struct sockaddr_ll {
  int ifr_ifindex;
  int sll_ifindex;
  int /*<<< orphan*/ sll_protocol;
  int /*<<< orphan*/ sll_family;
  TYPE_1__ ifr_hwaddr;
  int /*<<< orphan*/ ifr_name;
};
struct sockaddr {
  int dummy;
};
struct ifreq {
  int ifr_ifindex;
  int sll_ifindex;
  int /*<<< orphan*/ sll_protocol;
  int /*<<< orphan*/ sll_family;
  TYPE_1__ ifr_hwaddr;
  int /*<<< orphan*/ ifr_name;
};
typedef int /*<<< orphan*/ ifr;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_PACKET;
int ETH_ALEN;
int /*<<< orphan*/ ETH_P_ALL;
int /*<<< orphan*/ SIOCGIFHWADDR;
int /*<<< orphan*/ SIOCGIFINDEX;
int /*<<< orphan*/ SOCK_RAW;
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *, ...);
int /*<<< orphan*/ htons(int);
scalar_t__ ioctl(int, int /*<<< orphan*/, struct sockaddr_ll *);
int /*<<< orphan*/ memcpy(unsigned char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ memset(struct sockaddr_ll *, int /*<<< orphan*/, int);
int run_active_host(int, char **, int, struct sockaddr_ll *, unsigned char *);
int /*<<< orphan*/ run_passive_host(int, char **, int, unsigned char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
char *strerror(int /*<<< orphan*/);
int main(int argc, char **argv) {
  int sock, iindex, mtp_listen = 0;
  struct sockaddr_ll addr;
  struct ifreq ifr;
  unsigned char ourmac[ETH_ALEN];
  if (argc != 3) {
    fprintf(stderr,
            "%s: Use: \"%s <eth> -l\" or "
            "\"%s <eth> <macaddress>\"\n",
            argv[0], argv[0], argv[0]);
    exit(1);
  }
  if (!strcmp(argv[2], "-l")) {
    mtp_listen = 1;
  }
  sock = socket(AF_PACKET, SOCK_RAW, ETH_P_ALL);
  if (sock < 0) {
    fprintf(stderr, "%s: socket(): %s\n", argv[0], strerror(errno));
    exit(1);
  }
  memset(&ifr, 0, sizeof(ifr));
  strcpy(ifr.ifr_name, argv[1]);
  if (ioctl(sock, SIOCGIFINDEX, &ifr) < 0) {
    fprintf(stderr, "%s: SIOCGIFINDEX(%s): %s\n", argv[0], argv[1],
            strerror(errno));
    exit(1);
  }
  iindex = ifr.ifr_ifindex;
  if (ioctl(sock, SIOCGIFHWADDR, &ifr) < 0) {
    fprintf(stderr, "%s: SIOCGIFHWADDR(%s): %s\n", argv[0], argv[1],
            strerror(errno));
    exit(1);
  }
  memcpy(ourmac, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
  memset(&addr, 0, sizeof(addr));
  addr.sll_family = AF_PACKET;
  addr.sll_protocol = htons(0x6d74);
  addr.sll_ifindex = iindex;
  if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
    fprintf(stderr, "%s: bind(%s): %s\n", argv[0], argv[1], strerror(errno));
    exit(1);
  }
  if (!mtp_listen)
    return run_active_host(argc, argv, sock, &addr, ourmac);
  while (1)
    run_passive_host(argc, argv, sock, ourmac);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    0x2de9(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x68(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x60(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     125c <main+0x8c>
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
mov    -0x10(%rbp),%rax
mov    (%rax),%r8
lea    0xdb5(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdc8(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    1280 <main+0xb0>
movl   $0x1,-0x1c(%rbp)
mov    0x2d41(%rip),%rax
mov    (%rax),%edi
mov    0x2d58(%rip),%rax
mov    (%rax),%esi
mov    0x2d37(%rip),%rax
mov    (%rax),%edx
call   10f0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    12f4 <main+0x124>
mov    0x2d04(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x74(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x70(%rbp)
mov    0x2ce5(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x74(%rbp),%edi
mov    -0x70(%rbp),%rdx
mov    %rax,%rcx
lea    0xd53(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1050 <memset@plt>
mov    -0x3c(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
mov    -0x14(%rbp),%edi
mov    0x2c82(%rip),%rax
mov    (%rax),%esi
lea    -0x50(%rbp),%rdx
call   1060 <ioctl@plt>
cmp    $0x0,%rax
jge    1396 <main+0x1c6>
mov    0x2c7e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x88(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x80(%rbp)
mov    0x2c4d(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x8c(%rbp),%edi
mov    -0x88(%rbp),%rdx
mov    -0x80(%rbp),%rcx
mov    %rax,%r8
lea    0xcc3(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x50(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2c1a(%rip),%rax
mov    (%rax),%esi
lea    -0x50(%rbp),%rdx
call   1060 <ioctl@plt>
cmp    $0x0,%rax
jge    1424 <main+0x254>
mov    0x2bf6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xa4(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0xa0(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x98(%rbp)
mov    0x2bc2(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0xa4(%rbp),%edi
mov    -0xa0(%rbp),%rdx
mov    -0x98(%rbp),%rcx
mov    %rax,%r8
lea    0xc4f(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x68(%rbp),%rdi
mov    -0x40(%rbp),%esi
mov    0x2bae(%rip),%rax
mov    (%rax),%edx
call   1090 <memcpy@plt>
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1050 <memset@plt>
mov    0x2b78(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    $0x6d74,%edi
call   1040 <htons@plt>
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    $0x18,%edx
call   10b0 <bind@plt>
cmp    $0x0,%rax
jge    14ec <main+0x31c>
mov    0x2b2e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xbc(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0xb8(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0xb0(%rbp)
mov    0x2afa(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0xbc(%rbp),%edi
mov    -0xb8(%rbp),%rdx
mov    -0xb0(%rbp),%rcx
mov    %rax,%r8
lea    0xba2(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    151f <main+0x34f>
mov    -0x68(%rbp),%r8
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    -0x38(%rbp),%rcx
call   10a0 <run_active_host@plt>
mov    %eax,-0x4(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret
jmp    1524 <main+0x354>
jmp    1529 <main+0x359>
mov    -0x68(%rbp),%rcx
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   10e0 <run_passive_host@plt>
jmp    1524 <main+0x354>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%r14
mov    %rsp,-0x38(%rbp)
mov    0x2df1(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r15
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
cmp    $0x3,%edi
jne    1354 <main+0x184>
mov    0x10(%r14),%rdi
lea    0xe1d(%rip),%rsi
call   1070 <strcmp@plt>
mov    %eax,%r12d
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
mov    0x2dba(%rip),%rax
mov    (%rax),%esi
mov    0x2d99(%rip),%rax
mov    (%rax),%edx
call   10f0 <socket@plt>
test   %eax,%eax
js     1372 <main+0x1a2>
mov    %eax,%ebx
mov    %r12d,-0x2c(%rbp)
lea    -0x50(%rbp),%r13
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1050 <memset@plt>
mov    -0x3c(%rbp),%edi
mov    0x8(%r14),%rsi
call   1030 <strcpy@plt>
mov    0x2d2e(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r13,%rdx
call   1060 <ioctl@plt>
test   %rax,%rax
js     13ac <main+0x1dc>
mov    -0x50(%rbp),%r12d
mov    0x2d2e(%rip),%rax
mov    (%rax),%esi
lea    -0x50(%rbp),%rdx
mov    %ebx,%edi
call   1060 <ioctl@plt>
test   %rax,%rax
js     13d3 <main+0x203>
mov    -0x40(%rbp),%esi
mov    0x2d2e(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
call   1090 <memcpy@plt>
lea    -0x68(%rbp),%r13
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1050 <memset@plt>
mov    0x2cf2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    $0x6d74,%edi
call   1040 <htons@plt>
mov    %eax,-0x60(%rbp)
mov    %r12d,-0x64(%rbp)
mov    %ebx,%edi
mov    %r13,%rsi
mov    $0x18,%edx
call   10b0 <bind@plt>
test   %rax,%rax
js     13fa <main+0x22a>
cmpl   $0x0,-0x2c(%rbp)
je     1340 <main+0x170>
lea    -0x68(%rbp),%rcx
mov    $0x3,%edi
mov    %r14,%rsi
mov    %ebx,%edx
mov    %r15,%r8
call   10a0 <run_active_host@plt>
mov    -0x38(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x3,%edi
mov    %r14,%rsi
mov    %ebx,%edx
mov    %r15,%rcx
call   10e0 <run_passive_host@plt>
jmp    1340 <main+0x170>
mov    0x2c5d(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rcx
lea    0xc99(%rip),%rsi
mov    %rcx,%rdx
mov    %rcx,%r8
jmp    142a <main+0x25a>
mov    0x2c3f(%rip),%rax
mov    (%rax),%ebx
mov    (%r14),%r14
mov    0x2c2b(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xca3(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x2c05(%rip),%rax
mov    (%rax),%ebx
mov    (%r14),%r15
mov    0x8(%r14),%r14
mov    0x2bed(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xc77(%rip),%rsi
jmp    141f <main+0x24f>
mov    0x2bde(%rip),%rax
mov    (%rax),%ebx
mov    (%r14),%r15
mov    0x8(%r14),%r14
mov    0x2bc6(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xc6a(%rip),%rsi
jmp    141f <main+0x24f>
mov    0x2bb7(%rip),%rax
mov    (%rax),%ebx
mov    (%r14),%r15
mov    0x8(%r14),%r14
mov    0x2b9f(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xc5e(%rip),%rsi
mov    %ebx,%edi
mov    %r15,%rdx
mov    %r14,%rcx
mov    %rax,%r8
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_ll = type { i32, i32, i32, i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.ifreq = type { i32, i32, i32, i32, %struct.TYPE_2__, i32 }
%struct.sockaddr = type { i32 }
@ETH_ALEN = global i32 0
@stderr = global i32 0
@.str = [51 x i8] c"%s: Use: \22%s <eth> -l\22 or \22%s <eth> <macaddress>\22\0A\00"
@.str.1 = [3 x i8] c"-l\00"
@AF_PACKET = global i32 0
@SOCK_RAW = global i32 0
@ETH_P_ALL = global i32 0
@.str.2 = [18 x i8] c"%s: socket(): %s\0A\00"
@errno = global i32 0
@SIOCGIFINDEX = global i32 0
@.str.3 = [26 x i8] c"%s: SIOCGIFINDEX(%s): %s\0A\00"
@SIOCGIFHWADDR = global i32 0
@.str.4 = [27 x i8] c"%s: SIOCGIFHWADDR(%s): %s\0A\00"
@.str.5 = [18 x i8] c"%s: bind(%s): %s\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 %struct.sockaddr_ll
%10 = alloca %struct.ifreq
%11 = alloca i8*
%12 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
%13 = load i32, i32* @ETH_ALEN
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %11
%16 = alloca i8, i64 %14
store i64 %14, i64* %12
%17 = load i32, i32* %4
%18 = icmp ne i32 %17, 3
br i1 %18, label %19, label %32
19: ; preds = %2
%20 = load i32, i32* @stderr
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 0
%23 = load i8*, i8** %22
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 0
%26 = load i8*, i8** %25
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 0
%29 = load i8*, i8** %28
%30 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i8* %23, i8* %26, i8* %29)
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %2
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = load i8*, i8** %34
%36 = call i32 @strcmp(i8* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%37 = icmp ne i32 %36, 0
br i1 %37, label %39, label %38
38: ; preds = %32
store i32 1, i32* %8
br label %39
39: ; preds = %38, %32
%40 = load i32, i32* @AF_PACKET
%41 = load i32, i32* @SOCK_RAW
%42 = load i32, i32* @ETH_P_ALL
%43 = call i32 @socket(i32 %40, i32 %41, i32 %42)
store i32 %43, i32* %6
%44 = load i32, i32* %6
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %55
46: ; preds = %39
%47 = load i32, i32* @stderr
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 0
%50 = load i8*, i8** %49
%51 = load i32, i32* @errno
%52 = call i8* @strerror(i32 %51)
%53 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %50, i8* %52)
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %39
%56 = bitcast %struct.ifreq* %10 to %struct.sockaddr_ll*
%57 = call i32 @memset(%struct.sockaddr_ll* %56, i32 0, i32 24)
%58 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %10, i32 0, i32 5
%59 = load i32, i32* %58
%60 = load i8**, i8*** %5
%61 = getelementptr inbounds i8*, i8** %60, i64 1
%62 = load i8*, i8** %61
%63 = call i32 @strcpy(i32 %59, i8* %62)
%64 = load i32, i32* %6
%65 = load i32, i32* @SIOCGIFINDEX
%66 = bitcast %struct.ifreq* %10 to %struct.sockaddr_ll*
%67 = call i64 @ioctl(i32 %64, i32 %65, %struct.sockaddr_ll* %66)
%68 = icmp slt i64 %67, 0
br i1 %68, label %69, label %81
69: ; preds = %55
%70 = load i32, i32* @stderr
%71 = load i8**, i8*** %5
%72 = getelementptr inbounds i8*, i8** %71, i64 0
%73 = load i8*, i8** %72
%74 = load i8**, i8*** %5
%75 = getelementptr inbounds i8*, i8** %74, i64 1
%76 = load i8*, i8** %75
%77 = load i32, i32* @errno
%78 = call i8* @strerror(i32 %77)
%79 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %70, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %73, i8* %76, i8* %78)
%80 = call i32 @exit(i32 1)
unreachable
81: ; preds = %55
%82 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %10, i32 0, i32 0
%83 = load i32, i32* %82
store i32 %83, i32* %7
%84 = load i32, i32* %6
%85 = load i32, i32* @SIOCGIFHWADDR
%86 = bitcast %struct.ifreq* %10 to %struct.sockaddr_ll*
%87 = call i64 @ioctl(i32 %84, i32 %85, %struct.sockaddr_ll* %86)
%88 = icmp slt i64 %87, 0
br i1 %88, label %89, label %101
89: ; preds = %81
%90 = load i32, i32* @stderr
%91 = load i8**, i8*** %5
%92 = getelementptr inbounds i8*, i8** %91, i64 0
%93 = load i8*, i8** %92
%94 = load i8**, i8*** %5
%95 = getelementptr inbounds i8*, i8** %94, i64 1
%96 = load i8*, i8** %95
%97 = load i32, i32* @errno
%98 = call i8* @strerror(i32 %97)
%99 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %90, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %93, i8* %96, i8* %98)
%100 = call i32 @exit(i32 1)
unreachable
101: ; preds = %81
%102 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %10, i32 0, i32 4
%103 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %102, i32 0, i32 0
%104 = load i32, i32* %103
%105 = load i32, i32* @ETH_ALEN
%106 = call i32 @memcpy(i8* %16, i32 %104, i32 %105)
%107 = call i32 @memset(%struct.sockaddr_ll* %9, i32 0, i32 24)
%108 = load i32, i32* @AF_PACKET
%109 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %9, i32 0, i32 3
store i32 %108, i32* %109
%110 = call i32 @htons(i32 28020)
%111 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %9, i32 0, i32 2
store i32 %110, i32* %111
%112 = load i32, i32* %7
%113 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %9, i32 0, i32 1
store i32 %112, i32* %113
%114 = load i32, i32* %6
%115 = bitcast %struct.sockaddr_ll* %9 to %struct.sockaddr*
%116 = call i64 @bind(i32 %114, %struct.sockaddr* %115, i32 24)
%117 = icmp slt i64 %116, 0
br i1 %117, label %118, label %130
118: ; preds = %101
%119 = load i32, i32* @stderr
%120 = load i8**, i8*** %5
%121 = getelementptr inbounds i8*, i8** %120, i64 0
%122 = load i8*, i8** %121
%123 = load i8**, i8*** %5
%124 = getelementptr inbounds i8*, i8** %123, i64 1
%125 = load i8*, i8** %124
%126 = load i32, i32* @errno
%127 = call i8* @strerror(i32 %126)
%128 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %119, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %122, i8* %125, i8* %127)
%129 = call i32 @exit(i32 1)
unreachable
130: ; preds = %101
%131 = load i32, i32* %8
%132 = icmp ne i32 %131, 0
br i1 %132, label %140, label %133
133: ; preds = %130
%134 = load i32, i32* %4
%135 = load i8**, i8*** %5
%136 = load i32, i32* %6
%137 = call i32 @run_active_host(i32 %134, i8** %135, i32 %136, %struct.sockaddr_ll* %9, i8* %16)
store i32 %137, i32* %3
%138 = load i8*, i8** %11
%139 = load i32, i32* %3
ret i32 %139
140: ; preds = %130
br label %141
141: ; preds = %142, %140
br label %142
142: ; preds = %141
%143 = load i32, i32* %4
%144 = load i8**, i8*** %5
%145 = load i32, i32* %6
%146 = call i32 @run_passive_host(i32 %143, i8** %144, i32 %145, i8* %16)
br label %141
}

LLVM IR (-O2):
%struct.sockaddr_ll = type { i32, i32, i32, i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.ifreq = type { i32, i32, i32, i32, %struct.TYPE_2__, i32 }
%struct.sockaddr = type { i32 }
@ETH_ALEN = global i32 0
@stderr = global i32 0
@.str = [51 x i8] c"%s: Use: \22%s <eth> -l\22 or \22%s <eth> <macaddress>\22\0A\00"
@.str.1 = [3 x i8] c"-l\00"
@AF_PACKET = global i32 0
@SOCK_RAW = global i32 0
@ETH_P_ALL = global i32 0
@.str.2 = [18 x i8] c"%s: socket(): %s\0A\00"
@errno = global i32 0
@SIOCGIFINDEX = global i32 0
@.str.3 = [26 x i8] c"%s: SIOCGIFINDEX(%s): %s\0A\00"
@SIOCGIFHWADDR = global i32 0
@.str.4 = [27 x i8] c"%s: SIOCGIFHWADDR(%s): %s\0A\00"
@.str.5 = [18 x i8] c"%s: bind(%s): %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.sockaddr_ll
%4 = alloca %struct.ifreq
%5 = bitcast %struct.sockaddr_ll* %3 to i8*
%6 = bitcast %struct.ifreq* %4 to i8*
%7 = load i32, i32* @ETH_ALEN
%8 = zext i32 %7 to i64
%9 = tail call i8* @llvm.stacksave()
%10 = alloca i8, i64 %8
%11 = icmp eq i32 %0, 3
br i1 %11, label %17, label %12
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %1
%15 = tail call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i8* %14, i8* %14, i8* %14)
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = getelementptr inbounds i8*, i8** %1, i64 2
%19 = load i8*, i8** %18
%20 = tail call i32 @strcmp(i8* dereferenceable(1) %19, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp eq i32 %20, 0
%22 = load i32, i32* @AF_PACKET
%23 = load i32, i32* @SOCK_RAW
%24 = load i32, i32* @ETH_P_ALL
%25 = tail call i32 @socket(i32 %22, i32 %23, i32 %24)
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %34
27: ; preds = %17
%28 = load i32, i32* @stderr
%29 = load i8*, i8** %1
%30 = load i32, i32* @errno
%31 = tail call i8* @strerror(i32 %30)
%32 = tail call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %29, i8* %31)
%33 = tail call i32 @exit(i32 1)
unreachable
34: ; preds = %17
%35 = bitcast %struct.ifreq* %4 to %struct.sockaddr_ll*
%36 = call i32 @memset(%struct.sockaddr_ll* %35, i32 0, i32 24)
%37 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %4, i64 0, i32 5
%38 = load i32, i32* %37
%39 = getelementptr inbounds i8*, i8** %1, i64 1
%40 = load i8*, i8** %39
%41 = call i32 @strcpy(i32 %38, i8* %40)
%42 = load i32, i32* @SIOCGIFINDEX
%43 = call i64 @ioctl(i32 %25, i32 %42, %struct.sockaddr_ll* %35)
%44 = icmp slt i64 %43, 0
br i1 %44, label %45, label %53
45: ; preds = %34
%46 = load i32, i32* @stderr
%47 = load i8*, i8** %1
%48 = load i8*, i8** %39
%49 = load i32, i32* @errno
%50 = call i8* @strerror(i32 %49)
%51 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %47, i8* %48, i8* %50)
%52 = call i32 @exit(i32 1)
unreachable
53: ; preds = %34
%54 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %4, i64 0, i32 0
%55 = load i32, i32* %54
%56 = load i32, i32* @SIOCGIFHWADDR
%57 = call i64 @ioctl(i32 %25, i32 %56, %struct.sockaddr_ll* %35)
%58 = icmp slt i64 %57, 0
br i1 %58, label %59, label %67
59: ; preds = %53
%60 = load i32, i32* @stderr
%61 = load i8*, i8** %1
%62 = load i8*, i8** %39
%63 = load i32, i32* @errno
%64 = call i8* @strerror(i32 %63)
%65 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %61, i8* %62, i8* %64)
%66 = call i32 @exit(i32 1)
unreachable
67: ; preds = %53
%68 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %4, i64 0, i32 4, i32 0
%69 = load i32, i32* %68
%70 = load i32, i32* @ETH_ALEN
%71 = call i32 @memcpy(i8* %10, i32 %69, i32 %70)
%72 = call i32 @memset(%struct.sockaddr_ll* %3, i32 0, i32 24)
%73 = load i32, i32* @AF_PACKET
%74 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %3, i64 0, i32 3
store i32 %73, i32* %74
%75 = call i32 @htons(i32 28020)
%76 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %3, i64 0, i32 2
store i32 %75, i32* %76
%77 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %3, i64 0, i32 1
store i32 %55, i32* %77
%78 = bitcast %struct.sockaddr_ll* %3 to %struct.sockaddr*
%79 = call i64 @bind(i32 %25, %struct.sockaddr* %78, i32 24)
%80 = icmp slt i64 %79, 0
br i1 %80, label %81, label %89
81: ; preds = %67
%82 = load i32, i32* @stderr
%83 = load i8*, i8** %1
%84 = load i8*, i8** %39
%85 = load i32, i32* @errno
%86 = call i8* @strerror(i32 %85)
%87 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %82, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %83, i8* %84, i8* %86)
%88 = call i32 @exit(i32 1)
unreachable
89: ; preds = %67
br i1 %21, label %92, label %90
90: ; preds = %89
%91 = call i32 @run_active_host(i32 3, i8** %1, i32 %25, %struct.sockaddr_ll* %3, i8* %10)
ret i32 %91
92: ; preds = %89, %92
%93 = call i32 @run_passive_host(i32 3, i8** %1, i32 %25, i8* %10)
br label %92
}