#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 */
typedef int /*<<< orphan*/ whereto;
typedef int /*<<< orphan*/ u_char;
struct sockaddr {
  int /*<<< orphan*/ sa_data;
  scalar_t__ sa_family;
};
struct TYPE_2__ {
  int /*<<< orphan*/ sa_data;
};
struct ifreq {
  TYPE_1__ ifr_hwaddr;
  int /*<<< orphan*/ ifr_name;
};
struct cfgData {
  int dummy;
};
typedef int /*<<< orphan*/ one;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
scalar_t__ EPERM;
int /*<<< orphan*/ SIOCGIFHWADDR;
int /*<<< orphan*/ SOCK_PACKET;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_BROADCAST;
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int get_fill(int /*<<< orphan*/ *, struct cfgData const *);
int /*<<< orphan*/ getuid();
scalar_t__ ioctl(int, int /*<<< orphan*/, struct ifreq *);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/, int);
int send_arping(struct cfgData const *, char *);
int sendto(int, int /*<<< orphan*/ *, int, int /*<<< orphan*/,
           struct sockaddr *, int);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, char *, int);
scalar_t__ setuid(int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
int send_wol(const struct cfgData *data, char *ifname) {
  u_char outpack[1000];
  struct sockaddr whereto;
  int one = 1;
  int s;
  int i, pktsize;
  struct ifreq if_hwaddr;
  if ((s = socket(AF_INET, SOCK_PACKET, SOCK_PACKET)) < 0) {
    if (errno == EPERM)
      return 14;
    else
      return 10;
  }
  if (setuid(getuid()) != 0) {
    return 15;
  }
  pktsize = get_fill(outpack, data);
  strcpy(if_hwaddr.ifr_name, ifname);
  if (ioctl(s, SIOCGIFHWADDR, &if_hwaddr) < 0) {
    return 16;
  }
  memcpy(outpack + 6, if_hwaddr.ifr_hwaddr.sa_data, 6);
  if (setsockopt(s, SOL_SOCKET, SO_BROADCAST, (char *)&one, sizeof(one)) < 0)
    return 17;
  whereto.sa_family = 0;
  strcpy(whereto.sa_data, ifname);
  if ((i = sendto(s, outpack, pktsize, 0, &whereto, sizeof(whereto))) < 0)
    return 18;
  else
    ;
  close(s);
  sleep(3);
  return (send_arping(data, ifname));
}


x86 assembly (clang, -O0):
<send_wol>:
push   %rbp
mov    %rsp,%rbp
sub    $0xff0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x1,-0xfd4(%rbp)
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
mov    0x2df3(%rip),%rax
mov    (%rax),%esi
mov    0x2dea(%rip),%rax
mov    (%rax),%edx
call   10e0 <socket@plt>
mov    %eax,-0xfd8(%rbp)
cmp    $0x0,%eax
jge    123e <send_wol+0x7e>
mov    0x2da5(%rip),%rax
mov    (%rax),%rax
mov    0x2d8b(%rip),%rcx
cmp    (%rcx),%rax
jne    1232 <send_wol+0x72>
movl   $0xe,-0x4(%rbp)
jmp    1399 <send_wol+0x1d9>
movl   $0xa,-0x4(%rbp)
jmp    1399 <send_wol+0x1d9>
mov    $0x0,%al
call   1050 <getuid@plt>
mov    %eax,%edi
call   10c0 <setuid@plt>
cmp    $0x0,%rax
je     1262 <send_wol+0xa2>
movl   $0xf,-0x4(%rbp)
jmp    1399 <send_wol+0x1d9>
lea    -0xfc0(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10a0 <get_fill@plt>
mov    %eax,-0xfe0(%rbp)
mov    -0xfe4(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0xfd8(%rbp),%edi
mov    0x2d2c(%rip),%rax
mov    (%rax),%esi
lea    -0xfe8(%rbp),%rdx
call   1060 <ioctl@plt>
cmp    $0x0,%rax
jge    12b8 <send_wol+0xf8>
movl   $0x10,-0x4(%rbp)
jmp    1399 <send_wol+0x1d9>
lea    -0xfc0(%rbp),%rdi
add    $0x18,%rdi
mov    -0xfe8(%rbp),%esi
mov    $0x6,%edx
call   1090 <memcpy@plt>
mov    -0xfd8(%rbp),%edi
mov    0x2d08(%rip),%rax
mov    (%rax),%esi
mov    0x2ce7(%rip),%rax
mov    (%rax),%edx
lea    -0xfd4(%rbp),%rcx
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
cmp    $0x0,%rax
jge    1313 <send_wol+0x153>
movl   $0x11,-0x4(%rbp)
jmp    1399 <send_wol+0x1d9>
movq   $0x0,-0xfc8(%rbp)
mov    -0xfd0(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0xfd8(%rbp),%edi
lea    -0xfc0(%rbp),%rsi
mov    -0xfe0(%rbp),%edx
xor    %ecx,%ecx
lea    -0xfd0(%rbp),%r8
mov    $0x10,%r9d
call   1070 <sendto@plt>
mov    %eax,-0xfdc(%rbp)
cmp    $0x0,%eax
jge    136f <send_wol+0x1af>
movl   $0x12,-0x4(%rbp)
jmp    1399 <send_wol+0x1d9>
jmp    1374 <send_wol+0x1b4>
mov    -0xfd8(%rbp),%edi
call   1080 <close@plt>
mov    $0x3,%edi
call   10d0 <sleep@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10b0 <send_arping@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xff0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_wol>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0xfc8,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
movl   $0x1,0x4(%rsp)
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
mov    0x2df5(%rip),%rax
mov    (%rax),%edx
mov    %edx,%esi
call   10e0 <socket@plt>
test   %eax,%eax
js     12e2 <send_wol+0x122>
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <getuid@plt>
mov    %eax,%edi
call   10c0 <setuid@plt>
mov    %rax,%rcx
mov    $0xf,%eax
test   %rcx,%rcx
jne    1302 <send_wol+0x142>
lea    0x20(%rsp),%rdi
mov    %r14,%rsi
call   10a0 <get_fill@plt>
mov    %eax,%r15d
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    0x2d84(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebp,%edi
call   1060 <ioctl@plt>
test   %rax,%rax
js     1310 <send_wol+0x150>
lea    0x38(%rsp),%rdi
mov    0x8(%rsp),%esi
mov    $0x6,%edx
call   1090 <memcpy@plt>
mov    0x2d7b(%rip),%rax
mov    (%rax),%esi
mov    0x2d5a(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %ebp,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
test   %rax,%rax
js     1317 <send_wol+0x157>
movq   $0x0,0x18(%rsp)
mov    %rbx,%rsi
call   1030 <strcpy@plt>
lea    0x20(%rsp),%rsi
lea    0x10(%rsp),%r8
mov    %ebp,%edi
mov    %r15d,%edx
xor    %ecx,%ecx
mov    $0x10,%r9d
call   1070 <sendto@plt>
test   %eax,%eax
js     131e <send_wol+0x15e>
mov    %ebp,%edi
call   1080 <close@plt>
mov    $0x3,%edi
call   10d0 <sleep@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   10b0 <send_arping@plt>
jmp    1302 <send_wol+0x142>
mov    0x2ccf(%rip),%rax
mov    (%rax),%rax
mov    0x2cb5(%rip),%rcx
xor    %edx,%edx
cmp    (%rcx),%rax
sete   %dl
lea    0xa(,%rdx,4),%eax
add    $0xfc8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x10,%eax
jmp    1302 <send_wol+0x142>
mov    $0x11,%eax
jmp    1302 <send_wol+0x142>
mov    $0x12,%eax
jmp    1302 <send_wol+0x142>

LLVM IR (-O0):
%struct.cfgData = type { i32 }
%struct.sockaddr = type { i32, i64 }
%struct.ifreq = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
@AF_INET = global i32 0
@SOCK_PACKET = global i32 0
@errno = global i64 0
@EPERM = global i64 0
@SIOCGIFHWADDR = global i32 0
@SOL_SOCKET = global i32 0
@SO_BROADCAST = global i32 0
define i32 @send_wol(%struct.cfgData* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.cfgData*
%5 = alloca i8*
%6 = alloca [1000 x i32]
%7 = alloca %struct.sockaddr
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca %struct.ifreq
store %struct.cfgData* %0, %struct.cfgData** %4
store i8* %1, i8** %5
store i32 1, i32* %8
%13 = load i32, i32* @AF_INET
%14 = load i32, i32* @SOCK_PACKET
%15 = load i32, i32* @SOCK_PACKET
%16 = call i32 @socket(i32 %13, i32 %14, i32 %15)
store i32 %16, i32* %9
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %2
%19 = load i64, i64* @errno
%20 = load i64, i64* @EPERM
%21 = icmp eq i64 %19, %20
br i1 %21, label %22, label %23
22: ; preds = %18
store i32 14, i32* %3
br label %76
23: ; preds = %18
store i32 10, i32* %3
br label %76
24: ; preds = %2
%25 = call i32 (...) @getuid()
%26 = call i64 @setuid(i32 %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %24
store i32 15, i32* %3
br label %76
29: ; preds = %24
%30 = getelementptr inbounds [1000 x i32], [1000 x i32]* %6, i64 0, i64 0
%31 = load %struct.cfgData*, %struct.cfgData** %4
%32 = call i32 @get_fill(i32* %30, %struct.cfgData* %31)
store i32 %32, i32* %11
%33 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %12, i32 0, i32 1
%34 = load i32, i32* %33
%35 = load i8*, i8** %5
%36 = call i32 @strcpy(i32 %34, i8* %35)
%37 = load i32, i32* %9
%38 = load i32, i32* @SIOCGIFHWADDR
%39 = call i64 @ioctl(i32 %37, i32 %38, %struct.ifreq* %12)
%40 = icmp slt i64 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %29
store i32 16, i32* %3
br label %76
42: ; preds = %29
%43 = getelementptr inbounds [1000 x i32], [1000 x i32]* %6, i64 0, i64 0
%44 = getelementptr inbounds i32, i32* %43, i64 6
%45 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %12, i32 0, i32 0
%46 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %45, i32 0, i32 0
%47 = load i32, i32* %46
%48 = call i32 @memcpy(i32* %44, i32 %47, i32 6)
%49 = load i32, i32* %9
%50 = load i32, i32* @SOL_SOCKET
%51 = load i32, i32* @SO_BROADCAST
%52 = bitcast i32* %8 to i8*
%53 = call i64 @setsockopt(i32 %49, i32 %50, i32 %51, i8* %52, i32 4)
%54 = icmp slt i64 %53, 0
br i1 %54, label %55, label %56
55: ; preds = %42
store i32 17, i32* %3
br label %76
56: ; preds = %42
%57 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %7, i32 0, i32 1
store i64 0, i64* %57
%58 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %7, i32 0, i32 0
%59 = load i32, i32* %58
%60 = load i8*, i8** %5
%61 = call i32 @strcpy(i32 %59, i8* %60)
%62 = load i32, i32* %9
%63 = getelementptr inbounds [1000 x i32], [1000 x i32]* %6, i64 0, i64 0
%64 = load i32, i32* %11
%65 = call i32 @sendto(i32 %62, i32* %63, i32 %64, i32 0, %struct.sockaddr* %7, i32 16)
store i32 %65, i32* %10
%66 = icmp slt i32 %65, 0
br i1 %66, label %67, label %68
67: ; preds = %56
store i32 18, i32* %3
br label %76
68: ; preds = %56
br label %69
69: ; preds = %68
%70 = load i32, i32* %9
%71 = call i32 @close(i32 %70)
%72 = call i32 @sleep(i32 3)
%73 = load %struct.cfgData*, %struct.cfgData** %4
%74 = load i8*, i8** %5
%75 = call i32 @send_arping(%struct.cfgData* %73, i8* %74)
store i32 %75, i32* %3
br label %76
76: ; preds = %69, %67, %55, %41, %28, %23, %22
%77 = load i32, i32* %3
ret i32 %77
}

LLVM IR (-O2):
%struct.cfgData = type { i32 }
%struct.sockaddr = type { i32, i64 }
%struct.ifreq = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
@AF_INET = global i32 0
@SOCK_PACKET = global i32 0
@errno = global i64 0
@EPERM = global i64 0
@SIOCGIFHWADDR = global i32 0
@SOL_SOCKET = global i32 0
@SO_BROADCAST = global i32 0
define i32 @send_wol(%struct.cfgData* %0, i8* %1) {
%3 = alloca [1000 x i32]
%4 = alloca %struct.sockaddr
%5 = alloca i32
%6 = alloca %struct.ifreq
%7 = bitcast [1000 x i32]* %3 to i8*
%8 = bitcast %struct.sockaddr* %4 to i8*
%9 = bitcast i32* %5 to i8*
store i32 1, i32* %5
%10 = bitcast %struct.ifreq* %6 to i8*
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_PACKET
%13 = tail call i32 @socket(i32 %11, i32 %12, i32 %12)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %2
%16 = load i64, i64* @errno
%17 = load i64, i64* @EPERM
%18 = icmp eq i64 %16, %17
%19 = select i1 %18, i32 14, i32 10
br label %49
20: ; preds = %2
%21 = tail call i32 (...) @getuid()
%22 = tail call i64 @setuid(i32 %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %49
24: ; preds = %20
%25 = getelementptr inbounds [1000 x i32], [1000 x i32]* %3, i64 0, i64 0
%26 = call i32 @get_fill(i32* %25, %struct.cfgData* %0)
%27 = call i32 @strcpy(i32 undef, i8* %1)
%28 = load i32, i32* @SIOCGIFHWADDR
%29 = call i64 @ioctl(i32 %13, i32 %28, %struct.ifreq* %6)
%30 = icmp slt i64 %29, 0
br i1 %30, label %49, label %31
31: ; preds = %24
%32 = getelementptr inbounds [1000 x i32], [1000 x i32]* %3, i64 0, i64 6
%33 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %6, i64 0, i32 0, i32 0
%34 = load i32, i32* %33
%35 = call i32 @memcpy(i32* %32, i32 %34, i32 6)
%36 = load i32, i32* @SOL_SOCKET
%37 = load i32, i32* @SO_BROADCAST
%38 = call i64 @setsockopt(i32 %13, i32 %36, i32 %37, i8* %9, i32 4)
%39 = icmp slt i64 %38, 0
br i1 %39, label %49, label %40
40: ; preds = %31
%41 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %4, i64 0, i32 1
store i64 0, i64* %41
%42 = call i32 @strcpy(i32 undef, i8* %1)
%43 = call i32 @sendto(i32 %13, i32* %25, i32 %26, i32 0, %struct.sockaddr* %4, i32 16)
%44 = icmp slt i32 %43, 0
br i1 %44, label %49, label %45
45: ; preds = %40
%46 = call i32 @close(i32 %13)
%47 = call i32 @sleep(i32 3)
%48 = call i32 @send_arping(%struct.cfgData* %0, i8* %1)
br label %49
49: ; preds = %40, %31, %24, %20, %15, %45
%50 = phi i32 [ %48, %45 ], [ %19, %15 ], [ 15, %20 ], [ 16, %24 ], [ 17, %31 ], [ 18, %40 ]
ret i32 %50
}