#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 */
typedef int /*<<< orphan*/ wol;
struct ifreq {
  int ifr_flags;
  scalar_t__ wolopts;
  int /*<<< orphan*/ cmd;
  scalar_t__ ifr_data;
  int /*<<< orphan*/ ifr_name;
};
struct ethtool_wolinfo {
  int ifr_flags;
  scalar_t__ wolopts;
  int /*<<< orphan*/ cmd;
  scalar_t__ ifr_data;
  int /*<<< orphan*/ ifr_name;
};
typedef scalar_t__ caddr_t;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ ETHTOOL_GWOL;
int /*<<< orphan*/ ETHTOOL_SWOL;
int IFF_RUNNING;
int IFF_UP;
int /*<<< orphan*/ SIOCETHTOOL;
int /*<<< orphan*/ SIOCGIFFLAGS;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int ioctl(int, int /*<<< orphan*/, struct ifreq *);
int /*<<< orphan*/ memset(struct ifreq *, int /*<<< orphan*/, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
void activate_WOL_suggestion(void) {
  int sock;
  struct ifreq ifr;
  struct ethtool_wolinfo wol;
  int ret;
  memset(&ifr, 0, sizeof(struct ifreq));
  sock = socket(AF_INET, SOCK_DGRAM, 0);
  if (sock < 0)
    return;
  strcpy(ifr.ifr_name, "eth0");
  ret = ioctl(sock, SIOCGIFFLAGS, &ifr);
  if (ret < 0) {
    close(sock);
    return;
  }
  if (ifr.ifr_flags & (IFF_UP | IFF_RUNNING)) {
    close(sock);
    return;
  }
  memset(&wol, 0, sizeof(wol));
  wol.cmd = ETHTOOL_GWOL;
  ifr.ifr_data = (caddr_t)&wol;
  ioctl(sock, SIOCETHTOOL, &ifr);
  wol.cmd = ETHTOOL_SWOL;
  wol.wolopts = 0;
  ioctl(sock, SIOCETHTOOL, &ifr);
  close(sock);
}


x86 assembly (clang, -O0):
<activate_WOL_suggestion>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    1193 <activate_WOL_suggestion+0x43>
jmp    1268 <activate_WOL_suggestion+0x118>
mov    -0x10(%rbp),%edi
lea    0xe63(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x4(%rbp),%edi
mov    0x2e14(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1050 <ioctl@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
jge    11d1 <activate_WOL_suggestion+0x81>
mov    -0x4(%rbp),%edi
call   1060 <close@plt>
jmp    1268 <activate_WOL_suggestion+0x118>
mov    -0x30(%rbp),%eax
mov    0x2dfd(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2dfc(%rip),%rdx
or     (%rdx),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     11fe <activate_WOL_suggestion+0xae>
mov    -0x4(%rbp),%edi
call   1060 <close@plt>
jmp    1268 <activate_WOL_suggestion+0x118>
lea    -0x58(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
mov    0x2dbb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
lea    -0x58(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2d74(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1050 <ioctl@plt>
mov    0x2d72(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2d4b(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1050 <ioctl@plt>
mov    -0x4(%rbp),%edi
call   1060 <close@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<activate_WOL_suggestion>:
push   %r15
push   %r14
push   %rbx
sub    $0x50,%rsp
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
test   %eax,%eax
js     1230 <activate_WOL_suggestion+0xe0>
mov    %eax,%ebx
mov    0x20(%rsp),%edi
lea    0xe6a(%rip),%rsi
call   1030 <strcpy@plt>
mov    0x2e1e(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %ebx,%edi
call   1050 <ioctl@plt>
test   %eax,%eax
js     1229 <activate_WOL_suggestion+0xd9>
mov    0x2e1f(%rip),%rax
mov    0x2e20(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
test   %ecx,(%rsp)
jne    1229 <activate_WOL_suggestion+0xd9>
lea    0x28(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
mov    0x2dec(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x38(%rsp)
mov    %r14,0x18(%rsp)
mov    0x2daa(%rip),%r15
mov    (%r15),%esi
mov    %rsp,%r14
mov    %ebx,%edi
mov    %r14,%rdx
call   1050 <ioctl@plt>
mov    0x2da3(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x38(%rsp)
movq   $0x0,0x30(%rsp)
mov    (%r15),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1050 <ioctl@plt>
mov    %ebx,%edi
call   1060 <close@plt>
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.ifreq = type { i32, i64, i32, i64, i32 }
%struct.ethtool_wolinfo = type { i32, i64, i32, i64, i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [5 x i8] c"eth0\00"
@SIOCGIFFLAGS = global i32 0
@IFF_UP = global i32 0
@IFF_RUNNING = global i32 0
@ETHTOOL_GWOL = global i32 0
@SIOCETHTOOL = global i32 0
@ETHTOOL_SWOL = global i32 0
define void @activate_WOL_suggestion() {
%1 = alloca i32
%2 = alloca %struct.ifreq
%3 = alloca %struct.ethtool_wolinfo
%4 = alloca i32
%5 = call i32 @memset(%struct.ifreq* %2, i32 0, i32 40)
%6 = load i32, i32* @AF_INET
%7 = load i32, i32* @SOCK_DGRAM
%8 = call i32 @socket(i32 %6, i32 %7, i32 0)
store i32 %8, i32* %1
%9 = load i32, i32* %1
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %0
br label %53
12: ; preds = %0
%13 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %2, i32 0, i32 4
%14 = load i32, i32* %13
%15 = call i32 @strcpy(i32 %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* %1
%17 = load i32, i32* @SIOCGIFFLAGS
%18 = call i32 @ioctl(i32 %16, i32 %17, %struct.ifreq* %2)
store i32 %18, i32* %4
%19 = load i32, i32* %4
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %12
%22 = load i32, i32* %1
%23 = call i32 @close(i32 %22)
br label %53
24: ; preds = %12
%25 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %2, i32 0, i32 0
%26 = load i32, i32* %25
%27 = load i32, i32* @IFF_UP
%28 = load i32, i32* @IFF_RUNNING
%29 = or i32 %27, %28
%30 = and i32 %26, %29
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %24
%33 = load i32, i32* %1
%34 = call i32 @close(i32 %33)
br label %53
35: ; preds = %24
%36 = bitcast %struct.ethtool_wolinfo* %3 to %struct.ifreq*
%37 = call i32 @memset(%struct.ifreq* %36, i32 0, i32 40)
%38 = load i32, i32* @ETHTOOL_GWOL
%39 = getelementptr inbounds %struct.ethtool_wolinfo, %struct.ethtool_wolinfo* %3, i32 0, i32 2
store i32 %38, i32* %39
%40 = ptrtoint %struct.ethtool_wolinfo* %3 to i64
%41 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %2, i32 0, i32 3
store i64 %40, i64* %41
%42 = load i32, i32* %1
%43 = load i32, i32* @SIOCETHTOOL
%44 = call i32 @ioctl(i32 %42, i32 %43, %struct.ifreq* %2)
%45 = load i32, i32* @ETHTOOL_SWOL
%46 = getelementptr inbounds %struct.ethtool_wolinfo, %struct.ethtool_wolinfo* %3, i32 0, i32 2
store i32 %45, i32* %46
%47 = getelementptr inbounds %struct.ethtool_wolinfo, %struct.ethtool_wolinfo* %3, i32 0, i32 1
store i64 0, i64* %47
%48 = load i32, i32* %1
%49 = load i32, i32* @SIOCETHTOOL
%50 = call i32 @ioctl(i32 %48, i32 %49, %struct.ifreq* %2)
%51 = load i32, i32* %1
%52 = call i32 @close(i32 %51)
br label %53
53: ; preds = %35, %32, %21, %11
ret void
}

LLVM IR (-O2):
%struct.ifreq = type { i32, i64, i32, i64, i32 }
%struct.ethtool_wolinfo = type { i32, i64, i32, i64, i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [5 x i8] c"eth0\00"
@SIOCGIFFLAGS = global i32 0
@IFF_UP = global i32 0
@IFF_RUNNING = global i32 0
@ETHTOOL_GWOL = global i32 0
@SIOCETHTOOL = global i32 0
@ETHTOOL_SWOL = global i32 0
define void @activate_WOL_suggestion() {
%1 = alloca %struct.ifreq
%2 = alloca %struct.ethtool_wolinfo
%3 = bitcast %struct.ifreq* %1 to i8*
%4 = bitcast %struct.ethtool_wolinfo* %2 to i8*
%5 = call i32 @memset(%struct.ifreq* %1, i32 0, i32 40)
%6 = load i32, i32* @AF_INET
%7 = load i32, i32* @SOCK_DGRAM
%8 = call i32 @socket(i32 %6, i32 %7, i32 0)
%9 = icmp slt i32 %8, 0
br i1 %9, label %40, label %10
10: ; preds = %0
%11 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %1, i64 0, i32 4
%12 = load i32, i32* %11
%13 = call i32 @strcpy(i32 %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @SIOCGIFFLAGS
%15 = call i32 @ioctl(i32 %8, i32 %14, %struct.ifreq* %1)
%16 = icmp slt i32 %15, 0
br i1 %16, label %38, label %17
17: ; preds = %10
%18 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %1, i64 0, i32 0
%19 = load i32, i32* %18
%20 = load i32, i32* @IFF_UP
%21 = load i32, i32* @IFF_RUNNING
%22 = or i32 %21, %20
%23 = and i32 %22, %19
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %38
25: ; preds = %17
%26 = bitcast %struct.ethtool_wolinfo* %2 to %struct.ifreq*
%27 = call i32 @memset(%struct.ifreq* %26, i32 0, i32 40)
%28 = load i32, i32* @ETHTOOL_GWOL
%29 = getelementptr inbounds %struct.ethtool_wolinfo, %struct.ethtool_wolinfo* %2, i64 0, i32 2
store i32 %28, i32* %29
%30 = ptrtoint %struct.ethtool_wolinfo* %2 to i64
%31 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %1, i64 0, i32 3
store i64 %30, i64* %31
%32 = load i32, i32* @SIOCETHTOOL
%33 = call i32 @ioctl(i32 %8, i32 %32, %struct.ifreq* %1)
%34 = load i32, i32* @ETHTOOL_SWOL
store i32 %34, i32* %29
%35 = getelementptr inbounds %struct.ethtool_wolinfo, %struct.ethtool_wolinfo* %2, i64 0, i32 1
store i64 0, i64* %35
%36 = load i32, i32* @SIOCETHTOOL
%37 = call i32 @ioctl(i32 %8, i32 %36, %struct.ifreq* %1)
br label %38
38: ; preds = %17, %10, %25
%39 = call i32 @close(i32 %8)
br label %40
40: ; preds = %38, %0
ret void
}