#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 sockaddr_ll {
  int /*<<< orphan*/ sll_ifindex;
  int /*<<< orphan*/ sll_family;
};
struct sockaddr {
  int dummy;
};
struct ifreq {
  int /*<<< orphan*/ ifr_ifindex;
  int /*<<< orphan*/ ifr_name;
};
typedef int /*<<< orphan*/ sa;
typedef int /*<<< orphan*/ pkt;

/* Variables and functions */
int /*<<< orphan*/ AF_PACKET;
int /*<<< orphan*/ ETH_P_ALL;
int /*<<< orphan*/ SIOCGIFINDEX;
int /*<<< orphan*/ SOCK_RAW;
int /*<<< orphan*/ bind(int, struct sockaddr const *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, struct ifreq *);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ send(int, char **, int, int);
int /*<<< orphan*/ sleep(int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ status(char *);
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  if (argc < 2) {
    printf("%s", "Specify a monitor mode interface as parameter #1\n");
    exit(1);
  }
  int sockfd = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
  status("create socket");
  struct ifreq ifr;
  memcpy(ifr.ifr_name, argv[1], 16);
  ioctl(sockfd, SIOCGIFINDEX, &ifr);
  status("get interface");
  struct sockaddr_ll sa;
  sa.sll_family = AF_PACKET;
  sa.sll_ifindex = ifr.ifr_ifindex;
  bind(sockfd, (const struct sockaddr *)&sa, sizeof(sa));
  status("bind socket");
  char pkt[] = {0,    0,    8,    0,    0,    0,    0,    0,
                0xb4, 0,    0xff, 0x7f, 0xFF, 0xFF, 0xFF, 0xFF,
                0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
  printf("%s", "starting operation...\n");
  fflush(stdout);
  while (1) {
    send(sockfd, &pkt, sizeof(pkt), 0x0);
    sleep(0);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11ed <main+0x3d>
lea    0xe29(%rip),%rdi
lea    0xe25(%rip),%rsi
call   1050 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2ddc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    0x2de8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
call   1030 <htons@plt>
mov    -0x48(%rbp),%edi
mov    -0x44(%rbp),%esi
mov    %eax,%edx
call   10d0 <socket@plt>
mov    %eax,-0x14(%rbp)
lea    0xe0b(%rip),%rdi
call   1080 <status@plt>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    $0x10,%edx
call   1070 <memcpy@plt>
mov    -0x14(%rbp),%edi
mov    0x2d6a(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1060 <ioctl@plt>
lea    0xde3(%rip),%rdi
call   1080 <status@plt>
mov    0x2d64(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x8,%edx
call   10a0 <bind@plt>
lea    0xdc2(%rip),%rdi
call   1080 <status@plt>
mov    0xde5(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xde2(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xddf(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xd44(%rip),%rdi
lea    0xd9a(%rip),%rsi
call   1050 <printf@plt>
mov    0x2cf9(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x18,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
xor    %edi,%edi
call   10c0 <sleep@plt>
jmp    12d6 <main+0x126>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
cmp    $0x1,%edi
jle    12ba <main+0x10a>
mov    %rsi,%r14
mov    0x2e03(%rip),%r15
mov    (%r15),%ebx
mov    0x2e11(%rip),%rax
mov    (%rax),%ebp
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
call   1030 <htons@plt>
mov    %ebx,%edi
mov    %ebp,%esi
mov    %eax,%edx
call   10d0 <socket@plt>
mov    %eax,%ebp
lea    0xe3a(%rip),%rdi
call   1080 <status@plt>
mov    0x8(%r14),%rsi
mov    $0x10,%edx
call   1070 <memcpy@plt>
mov    0x2da3(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebp,%edi
call   1060 <ioctl@plt>
lea    0xe19(%rip),%rdi
call   1080 <status@plt>
mov    (%r15),%eax
mov    %eax,0x4(%rsp)
mov    0x8(%rsp),%eax
mov    %eax,(%rsp)
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x8,%edx
call   10a0 <bind@plt>
lea    0xdfe(%rip),%rdi
call   1080 <status@plt>
movaps 0xe21(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movq   $0xffffffffffffffff,0x20(%rsp)
ff ff
lea    0xd8c(%rip),%rdi
lea    0xde2(%rip),%rsi
call   1050 <printf@plt>
mov    0x2d41(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
lea    0x10(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x18,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
xor    %edi,%edi
call   10c0 <sleep@plt>
jmp    12a0 <main+0xf0>
lea    0xd3f(%rip),%rdi
lea    0xd3b(%rip),%rsi
call   1050 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.ifreq = type { i32, i32 }
%struct.sockaddr_ll = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [3 x i8] c"%s\00"
@.str.1 = [50 x i8] c"Specify a monitor mode interface as parameter\0A\00"
@AF_PACKET = global i32 0
@SOCK_RAW = global i32 0
@ETH_P_ALL = global i32 0
@.str.2 = [14 x i8] c"create socket\00"
@SIOCGIFINDEX = global i32 0
@.str.3 = [14 x i8] c"get interface\00"
@.str.4 = [12 x i8] c"bind socket\00"
@__const.main.pkt = [24 x i8] c"\00\00\08\00\00\00\00\00\B4\00\FF\7F\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF"
@.str.5 = [23 x i8] c"starting operation...\0A\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.ifreq
%8 = alloca %struct.sockaddr_ll
%9 = alloca [24 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = load i32, i32* @AF_PACKET
%17 = load i32, i32* @SOCK_RAW
%18 = load i32, i32* @ETH_P_ALL
%19 = call i32 @htons(i32 %18)
%20 = call i32 @socket(i32 %16, i32 %17, i32 %19)
store i32 %20, i32* %6
%21 = call i32 @status(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%22 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %7, i32 0, i32 1
%23 = load i32, i32* %22
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 @memcpy(i32 %23, i8* %26, i32 16)
%28 = load i32, i32* %6
%29 = load i32, i32* @SIOCGIFINDEX
%30 = call i32 @ioctl(i32 %28, i32 %29, %struct.ifreq* %7)
%31 = call i32 @status(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%32 = load i32, i32* @AF_PACKET
%33 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %8, i32 0, i32 1
store i32 %32, i32* %33
%34 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %7, i32 0, i32 0
%35 = load i32, i32* %34
%36 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %8, i32 0, i32 0
store i32 %35, i32* %36
%37 = load i32, i32* %6
%38 = bitcast %struct.sockaddr_ll* %8 to %struct.sockaddr*
%39 = call i32 @bind(i32 %37, %struct.sockaddr* %38, i32 8)
%40 = call i32 @status(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%41 = bitcast [24 x i8]* %9 to i8*
%42 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
%43 = load i32, i32* @stdout
%44 = call i32 @fflush(i32 %43)
br label %45
45: ; preds = %15, %45
%46 = load i32, i32* %6
%47 = bitcast [24 x i8]* %9 to i8**
%48 = call i32 @send(i32 %46, i8** %47, i32 24, i32 0)
%49 = call i32 @sleep(i32 0)
br label %45
}

LLVM IR (-O2):
%struct.ifreq = type { i32, i32 }
%struct.sockaddr_ll = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [3 x i8] c"%s\00"
@.str.1 = [50 x i8] c"Specify a monitor mode interface as parameter\0A\00"
@AF_PACKET = global i32 0
@SOCK_RAW = global i32 0
@ETH_P_ALL = global i32 0
@.str.2 = [14 x i8] c"create socket\00"
@SIOCGIFINDEX = global i32 0
@.str.3 = [14 x i8] c"get interface\00"
@.str.4 = [12 x i8] c"bind socket\00"
@__const.main.pkt = [24 x i8] c"\00\00\08\00\00\00\00\00\B4\00\FF\7F\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF"
@.str.5 = [23 x i8] c"starting operation...\0A\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.ifreq
%4 = alloca %struct.sockaddr_ll
%5 = alloca [24 x i8]
%6 = icmp slt i32 %0, 2
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = load i32, i32* @AF_PACKET
%12 = load i32, i32* @SOCK_RAW
%13 = load i32, i32* @ETH_P_ALL
%14 = tail call i32 @htons(i32 %13)
%15 = tail call i32 @socket(i32 %11, i32 %12, i32 %14)
%16 = tail call i32 @status(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%17 = bitcast %struct.ifreq* %3 to i8*
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = tail call i32 @memcpy(i32 undef, i8* %19, i32 16)
%21 = load i32, i32* @SIOCGIFINDEX
%22 = call i32 @ioctl(i32 %15, i32 %21, %struct.ifreq* %3)
%23 = call i32 @status(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%24 = bitcast %struct.sockaddr_ll* %4 to i8*
%25 = load i32, i32* @AF_PACKET
%26 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %4, i64 0, i32 1
store i32 %25, i32* %26
%27 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 0
%28 = load i32, i32* %27
%29 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %4, i64 0, i32 0
store i32 %28, i32* %29
%30 = bitcast %struct.sockaddr_ll* %4 to %struct.sockaddr*
%31 = call i32 @bind(i32 %15, %struct.sockaddr* %30, i32 8)
%32 = call i32 @status(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%33 = getelementptr inbounds [24 x i8], [24 x i8]* %5, i64 0, i64 0
%34 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
%35 = load i32, i32* @stdout
%36 = call i32 @fflush(i32 %35)
%37 = bitcast [24 x i8]* %5 to i8**
br label %38
38: ; preds = %38, %10
%39 = call i32 @send(i32 %15, i8** %37, i32 24, i32 0)
%40 = call i32 @sleep(i32 0)
br label %38
}