#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 {
  unsigned int *sll_addr;
  int /*<<< orphan*/ sll_protocol;
  int /*<<< orphan*/ sll_halen;
  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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_PACKET;
int /*<<< orphan*/ ETHER_ADDR_LEN;
int IFNAMSIZ;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ SIOCGIFHWADDR;
int /*<<< orphan*/ SIOCGIFINDEX;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(void *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
scalar_t__ ioctl(int, int /*<<< orphan*/, struct ifreq *);
int /*<<< orphan*/ memset(struct ifreq *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sscanf(char *, char *, unsigned int *, unsigned int *,
                          unsigned int *, unsigned int *, unsigned int *,
                          unsigned int *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ usleep(int);
int main(int argc, char *argv[]) {
  FILE *fp;
  unsigned int cnt = 0;
  unsigned int i, j = 0;
  int sockfd;
  struct ifreq if_idx;
  struct ifreq if_mac;
  char sendbuf[64];
  struct sockaddr_ll socket_address;
  char ifName[IFNAMSIZ];
  unsigned int mac[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
  if (argc > 1) {
    strcpy(ifName, argv[1]);
    if (argc > 2) {
      sscanf(argv[2], "%02x:%02x:%02x:%02x:%02x:%02x", &mac[0], &mac[1],
             &mac[2], &mac[3], &mac[4], &mac[5]);
    }
  } else {
    strcpy(ifName, "eth0");
  }
  printf("Broadcasting from FILE to MAC address ");
  printf("%2x:%2x:%2x:%2x:%2x:%2x\n", mac[0], mac[1], mac[2], mac[3], mac[4],
         mac[5]);
  if ((sockfd = socket(AF_PACKET, SOCK_DGRAM, htons(0x88b5))) == -1) {
    perror("Error opening socket");
    return -1;
  }
  memset(&if_idx, 0, sizeof(struct ifreq));
  strncpy(if_idx.ifr_name, ifName, IFNAMSIZ - 1);
  if (ioctl(sockfd, SIOCGIFINDEX, &if_idx) < 0) {
    perror("Error getting interface index");
    return -1;
  }
  memset(&if_mac, 0, sizeof(struct ifreq));
  strncpy(if_mac.ifr_name, ifName, IFNAMSIZ - 1);
  if (ioctl(sockfd, SIOCGIFHWADDR, &if_mac) < 0) {
    perror("Error getting interface MAC address");
    return -1;
  }
  socket_address.sll_family = AF_PACKET;
  socket_address.sll_ifindex = if_idx.ifr_ifindex;
  socket_address.sll_halen = ETHER_ADDR_LEN;
  socket_address.sll_protocol = htons(0x88b5);
  socket_address.sll_addr[0] = mac[0];
  socket_address.sll_addr[1] = mac[1];
  socket_address.sll_addr[2] = mac[2];
  socket_address.sll_addr[3] = mac[3];
  socket_address.sll_addr[4] = mac[4];
  socket_address.sll_addr[5] = mac[5];
  fp = fopen("sound.wav", "r");
  if (!fp) {
    perror("Could not open audio file!");
  }
  fseek(fp, 44, SEEK_SET);
  cnt = 0;
  while (1) {
    if (fread((void *)&sendbuf, 1, 64 - 16, fp) != 64 - 16) {
      if (feof(fp)) {
        printf("End of input reached! Sent %d packets!\n", cnt);
        break;
      } else {
        perror("Error reading from file");
        return -1;
      }
    }
    if (sendto(sockfd, sendbuf, 64 - 16, 0, (struct sockaddr *)&socket_address,
               sizeof(struct sockaddr_ll)) < 0) {
      perror("Error sending packet");
      return -1;
    } else {
      cnt++;
      printf("Sent %d packets!\r", cnt);
      if (cnt == 2) {
      }
      usleep(1000);
    }
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x24(%rbp)
mov    0x2d92(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0xa0(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0xd0(%rbp)
mov    %rcx,%rsp
mov    %rax,-0xa8(%rbp)
mov    0xd9d(%rip),%rax
mov    %rax,-0xc0(%rbp)
mov    0xd97(%rip),%rax
mov    %rax,-0xb8(%rbp)
mov    0xd91(%rip),%rax
mov    %rax,-0xb0(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1316 <main+0x116>
mov    -0xd0(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1040 <strcpy@plt>
cmpl   $0x2,-0x8(%rbp)
jle    1311 <main+0x111>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0xc0(%rbp),%rdx
lea    -0xc0(%rbp),%rcx
add    $0x4,%rcx
lea    -0xc0(%rbp),%r8
add    $0x8,%r8
lea    -0xc0(%rbp),%r9
add    $0xc,%r9
lea    -0xc0(%rbp),%r10
add    $0x10,%r10
lea    -0xc0(%rbp),%rax
add    $0x14,%rax
lea    0xd1d(%rip),%rsi
sub    $0x10,%rsp
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   10d0 <sscanf@plt>
add    $0x10,%rsp
jmp    1329 <main+0x129>
mov    -0xd0(%rbp),%rdi
lea    0xd12(%rip),%rsi
call   1040 <strcpy@plt>
lea    0xd0b(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0xc0(%rbp),%esi
mov    -0xbc(%rbp),%edx
mov    -0xb8(%rbp),%ecx
mov    -0xb4(%rbp),%r8d
mov    -0xb0(%rbp),%r9d
mov    -0xac(%rbp),%eax
lea    0xcfe(%rip),%rdi
sub    $0x10,%rsp
mov    %eax,(%rsp)
mov    $0x0,%al
call   1080 <printf@plt>
add    $0x10,%rsp
mov    0x2c53(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xd8(%rbp)
mov    0x2c54(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xd4(%rbp)
mov    $0x88b5,%edi
call   1070 <htons@plt>
mov    -0xd8(%rbp),%edi
mov    -0xd4(%rbp),%esi
mov    %eax,%edx
call   1120 <socket@plt>
mov    %eax,-0x28(%rbp)
cmp    $0xffffffff,%eax
jne    13df <main+0x1df>
lea    0xcb7(%rip),%rdi
call   1100 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0xc4(%rbp)
jmp    16a7 <main+0x4a7>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1090 <memset@plt>
mov    -0xd0(%rbp),%rsi
mov    -0x2c(%rbp),%edi
mov    0x2bc0(%rip),%rax
mov    (%rax),%edx
sub    $0x1,%edx
call   1030 <strncpy@plt>
mov    -0x28(%rbp),%edi
mov    0x2b94(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   10a0 <ioctl@plt>
cmp    $0x0,%rax
jge    144b <main+0x24b>
lea    0xc60(%rip),%rdi
call   1100 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0xc4(%rbp)
jmp    16a7 <main+0x4a7>
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1090 <memset@plt>
mov    -0xd0(%rbp),%rsi
mov    -0x34(%rbp),%edi
mov    0x2b54(%rip),%rax
mov    (%rax),%edx
sub    $0x1,%edx
call   1030 <strncpy@plt>
mov    -0x28(%rbp),%edi
mov    0x2b48(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdx
call   10a0 <ioctl@plt>
cmp    $0x0,%rax
jge    14b7 <main+0x2b7>
lea    0xc12(%rip),%rdi
call   1100 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0xc4(%rbp)
jmp    16a7 <main+0x4a7>
mov    0x2b12(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x84(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x88(%rbp)
mov    0x2b1a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8c(%rbp)
mov    $0x88b5,%edi
call   1070 <htons@plt>
mov    %eax,-0x90(%rbp)
mov    -0xc0(%rbp),%ecx
mov    -0x98(%rbp),%rax
mov    %ecx,(%rax)
mov    -0xbc(%rbp),%ecx
mov    -0x98(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0xb8(%rbp),%ecx
mov    -0x98(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0xb4(%rbp),%ecx
mov    -0x98(%rbp),%rax
mov    %ecx,0xc(%rax)
mov    -0xb0(%rbp),%ecx
mov    -0x98(%rbp),%rax
mov    %ecx,0x10(%rax)
mov    -0xac(%rbp),%ecx
mov    -0x98(%rbp),%rax
mov    %ecx,0x14(%rax)
lea    0xb7e(%rip),%rdi
lea    0xb81(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    157b <main+0x37b>
lea    0xb68(%rip),%rdi
call   1100 <perror@plt>
mov    -0x18(%rbp),%rdi
mov    0x2a32(%rip),%rax
mov    (%rax),%edx
mov    $0x2c,%esi
call   10e0 <fseek@plt>
movl   $0x0,-0x1c(%rbp)
jmp    159e <main+0x39e>
lea    -0x80(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x30,%edx
call   1050 <fread@plt>
cmp    $0x30,%eax
je     1609 <main+0x409>
mov    -0x18(%rbp),%rdi
call   10c0 <feof@plt>
cmp    $0x0,%rax
je     15e7 <main+0x3e7>
mov    -0x1c(%rbp),%esi
lea    0xb1e(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    168d <main+0x48d>
lea    0xb33(%rip),%rdi
call   1100 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0xc4(%rbp)
jmp    16a7 <main+0x4a7>
mov    -0x28(%rbp),%edi
lea    -0x80(%rbp),%rsi
lea    -0x98(%rbp),%r8
mov    $0x30,%edx
xor    %ecx,%ecx
mov    $0x18,%r9d
call   10b0 <sendto@plt>
cmp    $0x0,%rax
jge    1655 <main+0x455>
lea    0xaff(%rip),%rdi
call   1100 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0xc4(%rbp)
jmp    16a7 <main+0x4a7>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xae6(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
cmpl   $0x2,-0x1c(%rbp)
jne    167e <main+0x47e>
jmp    167e <main+0x47e>
mov    $0x3e8,%edi
call   1110 <usleep@plt>
jmp    1599 <main+0x399>
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0xc4(%rbp)
mov    -0xa0(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsp,%r12
mov    0x2e1d(%rip),%r13
mov    0x0(%r13),%eax
mov    %rsp,%r15
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    0xe49(%rip),%rax
mov    %rax,-0x30(%rbp)
movaps 0xe2e(%rip),%xmm0
movaps %xmm0,-0x40(%rbp)
cmp    $0x2,%edi
jl     1221 <main+0x91>
mov    %rsi,%r14
mov    %edi,%ebx
mov    0x8(%rsi),%rsi
mov    %r15,%rdi
call   1040 <strcpy@plt>
cmp    $0x2,%ebx
je     1230 <main+0xa0>
mov    0x10(%r14),%rdi
lea    -0x3c(%rbp),%rcx
lea    -0x38(%rbp),%r8
lea    -0x34(%rbp),%r9
lea    -0x30(%rbp),%rax
lea    -0x2c(%rbp),%rbx
lea    0xe08(%rip),%rsi
lea    -0x40(%rbp),%rdx
push   %rbx
push   %rax
call   1090 <sscanf@plt>
add    $0x10,%rsp
jmp    1230 <main+0xa0>
lea    0xe0e(%rip),%rsi
mov    %r15,%rdi
call   1040 <strcpy@plt>
lea    0xe04(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    -0x40(%rbp),%esi
mov    -0x3c(%rbp),%edx
mov    -0x38(%rbp),%ecx
mov    -0x34(%rbp),%r8d
mov    -0x30(%rbp),%r9d
mov    -0x2c(%rbp),%ebx
sub    $0x8,%rsp
lea    0xe05(%rip),%rdi
xor    %eax,%eax
push   %rbx
call   1060 <printf@plt>
add    $0x10,%rsp
mov    0x2d68(%rip),%rax
mov    (%rax),%r14d
mov    0x2d6e(%rip),%rax
mov    (%rax),%ebx
mov    $0x88b5,%edi
call   1050 <htons@plt>
mov    %r14d,%edi
mov    %ebx,%esi
mov    %eax,%edx
call   10b0 <socket@plt>
cmp    $0xffffffff,%eax
jne    12a3 <main+0x113>
lea    0xddd(%rip),%rdi
jmp    1332 <main+0x1a2>
mov    %eax,%r14d
lea    -0x50(%rbp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1070 <memset@plt>
mov    -0x4c(%rbp),%edi
mov    0x0(%r13),%edx
add    $0xffffffff,%edx
mov    %r15,%rsi
call   1030 <strncpy@plt>
mov    0x2ce6(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
mov    %rbx,%rdx
call   1080 <ioctl@plt>
test   %rax,%rax
jns    12ed <main+0x15d>
lea    0xda5(%rip),%rdi
jmp    1332 <main+0x1a2>
lea    -0x48(%rbp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1070 <memset@plt>
mov    -0x44(%rbp),%edi
mov    0x0(%r13),%edx
add    $0xffffffff,%edx
mov    %r15,%rsi
call   1030 <strncpy@plt>
mov    0x2cb7(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
mov    %rbx,%rdx
call   1080 <ioctl@plt>
test   %rax,%rax
jns    134e <main+0x1be>
lea    0xd7c(%rip),%rdi
call   10a0 <perror@plt>
mov    %r12,%rsp
mov    $0xffffffff,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x88b5,%edi
call   1050 <htons@plt>

LLVM IR (-O0):
%struct.ifreq = type { i32, i32 }
%struct.sockaddr_ll = type { i32*, i32, i32, i32, i32 }
%struct.sockaddr = type { i32 }
@IFNAMSIZ = global i32 0
@__const.main.mac = [6 x i32] [i32 255, i32 255, i32 255, i32 255, i32 255, i32 255]
@.str = [30 x i8] c"%02x:%02x:%02x:%02x:%02x:%02x\00"
@.str.1 = [5 x i8] c"eth0\00"
@.str.2 = [39 x i8] c"Broadcasting from FILE to MAC address \00"
@.str.3 = [25 x i8] c"%2x:%2x:%2x:%2x:%2x:%2x\0A\00"
@AF_PACKET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.4 = [21 x i8] c"Error opening socket\00"
@SIOCGIFINDEX = global i32 0
@.str.5 = [30 x i8] c"Error getting interface index\00"
@SIOCGIFHWADDR = global i32 0
@.str.6 = [36 x i8] c"Error getting interface MAC address\00"
@ETHER_ADDR_LEN = global i32 0
@.str.7 = [10 x i8] c"sound.wav\00"
@.str.8 = [2 x i8] c"r\00"
@.str.9 = [27 x i8] c"Could not open audio file!\00"
@SEEK_SET = global i32 0
@.str.10 = [40 x i8] c"End of input reached! Sent %d packets!\0A\00"
@.str.11 = [24 x i8] c"Error reading from file\00"
@.str.12 = [21 x i8] c"Error sending packet\00"
@.str.13 = [18 x i8] c"Sent %d packets!\0D\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 i32
%10 = alloca i32
%11 = alloca %struct.ifreq
%12 = alloca %struct.ifreq
%13 = alloca [64 x i8]
%14 = alloca %struct.sockaddr_ll
%15 = alloca i8*
%16 = alloca i64
%17 = alloca [6 x i32]
%18 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i32 0, i32* %9
%19 = load i32, i32* @IFNAMSIZ
%20 = zext i32 %19 to i64
%21 = call i8* @llvm.stacksave()
store i8* %21, i8** %15
%22 = alloca i8, i64 %20
store i64 %20, i64* %16
%23 = bitcast [6 x i32]* %17 to i8*
%24 = load i32, i32* %4
%25 = icmp sgt i32 %24, 1
br i1 %25, label %26, label %45
26: ; preds = %2
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 @strcpy(i8* %22, i8* %29)
%31 = load i32, i32* %4
%32 = icmp sgt i32 %31, 2
br i1 %32, label %33, label %44
33: ; preds = %26
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 2
%36 = load i8*, i8** %35
%37 = getelementptr inbounds [6 x i32], [6 x i32]* %17, i64 0, i64 0
%38 = getelementptr inbounds [6 x i32], [6 x i32]* %17, i64 0, i64 1
%39 = getelementptr inbounds [6 x i32], [6 x i32]* %17, i64 0, i64 2
%40 = getelementptr inbounds [6 x i32], [6 x i32]* %17, i64 0, i64 3
%41 = getelementptr inbounds [6 x i32], [6 x i32]* %17, i64 0, i64 4
%42 = getelementptr inbounds [6 x i32], [6 x i32]* %17, i64 0, i64 5
%43 = call i32 @sscanf(i8* %36, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32* %37, i32* %38, i32* %39, i32* %40, i32* %41, i32* %42)
br label %44
44: ; preds = %33, %26
br label %47
45: ; preds = %2
%46 = call i32 @strcpy(i8* %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %47
47: ; preds = %45, %44
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
%49 = getelementptr inbounds [6 x i32], [6 x i32]* %17, i64 0, i64 0
%50 = load i32, i32* %49
%51 = getelementptr inbounds [6 x i32], [6 x i32]* %17, i64 0, i64 1
%52 = load i32, i32* %51
%53 = getelementptr inbounds [6 x i32], [6 x i32]* %17, i64 0, i64 2
%54 = load i32, i32* %53
%55 = getelementptr inbounds [6 x i32], [6 x i32]* %17, i64 0, i64 3
%56 = load i32, i32* %55
%57 = getelementptr inbounds [6 x i32], [6 x i32]* %17, i64 0, i64 4
%58 = load i32, i32* %57
%59 = getelementptr inbounds [6 x i32], [6 x i32]* %17, i64 0, i64 5
%60 = load i32, i32* %59
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %50, i32 %52, i32 %54, i32 %56, i32 %58, i32 %60)
%62 = load i32, i32* @AF_PACKET
%63 = load i32, i32* @SOCK_DGRAM
%64 = call i32 @htons(i32 34997)
%65 = call i32 @socket(i32 %62, i32 %63, i32 %64)
store i32 %65, i32* %10
%66 = icmp eq i32 %65, -1
br i1 %66, label %67, label %69
67: ; preds = %47
%68 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %3
store i32 1, i32* %18
br label %181
69: ; preds = %47
%70 = call i32 @memset(%struct.ifreq* %11, i32 0, i32 8)
%71 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %11, i32 0, i32 1
%72 = load i32, i32* %71
%73 = load i32, i32* @IFNAMSIZ
%74 = sub nsw i32 %73, 1
%75 = call i32 @strncpy(i32 %72, i8* %22, i32 %74)
%76 = load i32, i32* %10
%77 = load i32, i32* @SIOCGIFINDEX
%78 = call i64 @ioctl(i32 %76, i32 %77, %struct.ifreq* %11)
%79 = icmp slt i64 %78, 0
br i1 %79, label %80, label %82
80: ; preds = %69
%81 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %3
store i32 1, i32* %18
br label %181
82: ; preds = %69
%83 = call i32 @memset(%struct.ifreq* %12, i32 0, i32 8)
%84 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %12, i32 0, i32 1
%85 = load i32, i32* %84
%86 = load i32, i32* @IFNAMSIZ
%87 = sub nsw i32 %86, 1
%88 = call i32 @strncpy(i32 %85, i8* %22, i32 %87)
%89 = load i32, i32* %10
%90 = load i32, i32* @SIOCGIFHWADDR
%91 = call i64 @ioctl(i32 %89, i32 %90, %struct.ifreq* %12)
%92 = icmp slt i64 %91, 0
br i1 %92, label %93, label %95
93: ; preds = %82
%94 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %3
store i32 1, i32* %18
br label %181
95: ; preds = %82
%96 = load i32, i32* @AF_PACKET
%97 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %14, i32 0, i32 4
store i32 %96, i32* %97
%98 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %11, i32 0, i32 0
%99 = load i32, i32* %98
%100 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %14, i32 0, i32 3
store i32 %99, i32* %100
%101 = load i32, i32* @ETHER_ADDR_LEN
%102 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %14, i32 0, i32 2
store i32 %101, i32* %102
%103 = call i32 @htons(i32 34997)
%104 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %14, i32 0, i32 1
store i32 %103, i32* %104
%105 = getelementptr inbounds [6 x i32], [6 x i32]* %17, i64 0, i64 0
%106 = load i32, i32* %105
%107 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %14, i32 0, i32 0
%108 = load i32*, i32** %107
%109 = getelementptr inbounds i32, i32* %108, i64 0
store i32 %106, i32* %109
%110 = getelementptr inbounds [6 x i32], [6 x i32]* %17, i64 0, i64 1
%111 = load i32, i32* %110
%112 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %14, i32 0, i32 0
%113 = load i32*, i32** %112
%114 = getelementptr inbounds i32, i32* %113, i64 1
store i32 %111, i32* %114
%115 = getelementptr inbounds [6 x i32], [6 x i32]* %17, i64 0, i64 2
%116 = load i32, i32* %115
%117 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %14, i32 0, i32 0
%118 = load i32*, i32** %117
%119 = getelementptr inbounds i32, i32* %118, i64 2
store i32 %116, i32* %119
%120 = getelementptr inbounds [6 x i32], [6 x i32]* %17, i64 0, i64 3
%121 = load i32, i32* %120
%122 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %14, i32 0, i32 0
%123 = load i32*, i32** %122
%124 = getelementptr inbounds i32, i32* %123, i64 3
store i32 %121, i32* %124
%125 = getelementptr inbounds [6 x i32], [6 x i32]* %17, i64 0, i64 4
%126 = load i32, i32* %125
%127 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %14, i32 0, i32 0
%128 = load i32*, i32** %127
%129 = getelementptr inbounds i32, i32* %128, i64 4
store i32 %126, i32* %129
%130 = getelementptr inbounds [6 x i32], [6 x i32]* %17, i64 0, i64 5
%131 = load i32, i32* %130
%132 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %14, i32 0, i32 0
%133 = load i32*, i32** %132
%134 = getelementptr inbounds i32, i32* %133, i64 5
store i32 %131, i32* %134
%135 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
store i32* %135, i32** %6
%136 = load i32*, i32** %6
%137 = icmp ne i32* %136, null
br i1 %137, label %140, label %138
138: ; preds = %95
%139 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0))
br label %140
140: ; preds = %138, %95
%141 = load i32*, i32** %6
%142 = load i32, i32* @SEEK_SET
%143 = call i32 @fseek(i32* %141, i32 44, i32 %142)
store i32 0, i32* %7
br label %144
144: ; preds = %177, %140
br label %145
145: ; preds = %144
%146 = bitcast [64 x i8]* %13 to i8*
%147 = load i32*, i32** %6
%148 = call i32 @fread(i8* %146, i32 1, i32 48, i32* %147)
%149 = icmp ne i32 %148, 48
br i1 %149, label %150, label %159
150: ; preds = %145
%151 = load i32*, i32** %6
%152 = call i64 @feof(i32* %151)
%153 = icmp ne i64 %152, 0
br i1 %153, label %154, label %157
154: ; preds = %150
%155 = load i32, i32* %7
%156 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.10, i64 0, i64 0), i32 %155)
br label %178
157: ; preds = %150
%158 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.11, i64 0, i64 0))
store i32 -1, i32* %3
store i32 1, i32* %18
br label %181
159: ; preds = %145
%160 = load i32, i32* %10
%161 = getelementptr inbounds [64 x i8], [64 x i8]* %13, i64 0, i64 0
%162 = bitcast %struct.sockaddr_ll* %14 to %struct.sockaddr*
%163 = call i64 @sendto(i32 %160, i8* %161, i32 48, i32 0, %struct.sockaddr* %162, i32 24)
%164 = icmp slt i64 %163, 0
br i1 %164, label %165, label %167
165: ; preds = %159
%166 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.12, i64 0, i64 0))
store i32 -1, i32* %3
store i32 1, i32* %18
br label %181
167: ; preds = %159
%168 = load i32, i32* %7
%169 = add i32 %168, 1
store i32 %169, i32* %7
%170 = load i32, i32* %7
%171 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.13, i64 0, i64 0), i32 %170)
%172 = load i32, i32* %7
%173 = icmp eq i32 %172, 2
br i1 %173, label %174, label %175
174: ; preds = %167
br label %175
175: ; preds = %174, %167
%176 = call i32 @usleep(i32 1000)
br label %177
177: ; preds = %175
br label %144
178: ; preds = %154
%179 = load i32*, i32** %6
%180 = call i32 @fclose(i32* %179)
store i32 0, i32* %3
store i32 1, i32* %18
br label %181
181: ; preds = %178, %165, %157, %93, %80, %67
%182 = load i8*, i8** %15
%183 = load i32, i32* %3
ret i32 %183
}

LLVM IR (-O2):
%struct.ifreq = type { i32, i32 }
@IFNAMSIZ = global i32 0
@__const.main.mac = [6 x i32] [i32 255, i32 255, i32 255, i32 255, i32 255, i32 255]
@.str = [30 x i8] c"%02x:%02x:%02x:%02x:%02x:%02x\00"
@.str.1 = [5 x i8] c"eth0\00"
@.str.2 = [39 x i8] c"Broadcasting from FILE to MAC address \00"
@.str.3 = [25 x i8] c"%2x:%2x:%2x:%2x:%2x:%2x\0A\00"
@AF_PACKET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.4 = [21 x i8] c"Error opening socket\00"
@SIOCGIFINDEX = global i32 0
@.str.5 = [30 x i8] c"Error getting interface index\00"
@SIOCGIFHWADDR = global i32 0
@.str.6 = [36 x i8] c"Error getting interface MAC address\00"
@ETHER_ADDR_LEN = global i32 0
@SEEK_SET = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.ifreq
%4 = alloca %struct.ifreq
%5 = alloca [6 x i32]
%6 = bitcast %struct.ifreq* %3 to i8*
%7 = bitcast %struct.ifreq* %4 to i8*
%8 = load i32, i32* @IFNAMSIZ
%9 = zext i32 %8 to i64
%10 = tail call i8* @llvm.stacksave()
%11 = alloca i8, i64 %9
%12 = bitcast [6 x i32]* %5 to i8*
%13 = icmp sgt i32 %0, 1
br i1 %13, label %14, label %29
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @strcpy(i8* %11, i8* %16)
%18 = icmp eq i32 %0, 2
br i1 %18, label %31, label %19
19: ; preds = %14
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = getelementptr inbounds [6 x i32], [6 x i32]* %5, i64 0, i64 0
%23 = getelementptr inbounds [6 x i32], [6 x i32]* %5, i64 0, i64 1
%24 = getelementptr inbounds [6 x i32], [6 x i32]* %5, i64 0, i64 2
%25 = getelementptr inbounds [6 x i32], [6 x i32]* %5, i64 0, i64 3
%26 = getelementptr inbounds [6 x i32], [6 x i32]* %5, i64 0, i64 4
%27 = getelementptr inbounds [6 x i32], [6 x i32]* %5, i64 0, i64 5
%28 = call i32 @sscanf(i8* %21, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32* %22, i32* %23, i32* %24, i32* %25, i32* %26, i32* %27)
br label %31
29: ; preds = %2
%30 = call i32 @strcpy(i8* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %31
31: ; preds = %14, %19, %29
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
%33 = getelementptr inbounds [6 x i32], [6 x i32]* %5, i64 0, i64 0
%34 = load i32, i32* %33
%35 = getelementptr inbounds [6 x i32], [6 x i32]* %5, i64 0, i64 1
%36 = load i32, i32* %35
%37 = getelementptr inbounds [6 x i32], [6 x i32]* %5, i64 0, i64 2
%38 = load i32, i32* %37
%39 = getelementptr inbounds [6 x i32], [6 x i32]* %5, i64 0, i64 3
%40 = load i32, i32* %39
%41 = getelementptr inbounds [6 x i32], [6 x i32]* %5, i64 0, i64 4
%42 = load i32, i32* %41
%43 = getelementptr inbounds [6 x i32], [6 x i32]* %5, i64 0, i64 5
%44 = load i32, i32* %43
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %34, i32 %36, i32 %38, i32 %40, i32 %42, i32 %44)
%46 = load i32, i32* @AF_PACKET
%47 = load i32, i32* @SOCK_DGRAM
%48 = call i32 @htons(i32 34997)
%49 = call i32 @socket(i32 %46, i32 %47, i32 %48)
%50 = icmp eq i32 %49, -1
br i1 %50, label %73, label %51
51: ; preds = %31
%52 = call i32 @memset(%struct.ifreq* %3, i32 0, i32 8)
%53 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 1
%54 = load i32, i32* %53
%55 = load i32, i32* @IFNAMSIZ
%56 = add nsw i32 %55, -1
%57 = call i32 @strncpy(i32 %54, i8* %11, i32 %56)
%58 = load i32, i32* @SIOCGIFINDEX
%59 = call i64 @ioctl(i32 %49, i32 %58, %struct.ifreq* %3)
%60 = icmp slt i64 %59, 0
br i1 %60, label %73, label %61
61: ; preds = %51
%62 = call i32 @memset(%struct.ifreq* %4, i32 0, i32 8)
%63 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %4, i64 0, i32 1
%64 = load i32, i32* %63
%65 = load i32, i32* @IFNAMSIZ
%66 = add nsw i32 %65, -1
%67 = call i32 @strncpy(i32 %64, i8* %11, i32 %66)
%68 = load i32, i32* @SIOCGIFHWADDR
%69 = call i64 @ioctl(i32 %49, i32 %68, %struct.ifreq* %4)
%70 = icmp slt i64 %69, 0
br i1 %70, label %73, label %71
71: ; preds = %61
%72 = call i32 @htons(i32 34997)
unreachable
73: ; preds = %61, %51, %31
%74 = phi i8* [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), %31 ], [ getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), %51 ], [ getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0), %61 ]
%75 = call i32 @perror(i8* %74)
ret i32 -1
}