#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*/ line;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ get_bcast_addr(char *, char *);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ send_wol(char *, char *);
int sscanf(char *, char *, char *, int *, int *, char *, char *, char *);
int /*<<< orphan*/ strcmp(char *, char *);
int main() {
  char ip[100];
  char hwa[100];
  char mask[100];
  char line[200];
  char dev[100];
  int type, flags;
  FILE *fp;
  int num;
  char mac[16];
  char bcast_addr[16];
  int hwa_idx;
  int mac_idx;
  fp = fopen("/proc/net/arp", "r");
  if (fp == NULL) {
    printf("Unable to open the file\n");
    return 0;
  }
  get_bcast_addr("eth1", (char *)bcast_addr);
  if (fgets(line, sizeof(line), fp) != (char *)NULL) {
    mask[0] = '-';
    mask[1] = '\0';
    dev[0] = '-';
    dev[1] = '\0';
    for (; fgets(line, sizeof(line), fp);) {
      num = sscanf(line, "%s 0x%x 0x%x %100s %100s %100s\n", ip, &type, &flags,
                   hwa, mask, dev);
      if (num < 4)
        break;
      if (!strcmp(dev, "eth1")) {
        memset(mac, 0, 16);
        mac_idx = 0;
        for (hwa_idx = 0; hwa_idx <= 17; hwa_idx += 3, mac_idx += 2) {
          memcpy(mac + mac_idx, hwa + hwa_idx, 2);
        }
        send_wol(bcast_addr, mac);
      }
    }
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2f0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe47(%rip),%rdi
lea    0xe4e(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x2a0(%rbp)
cmpq   $0x0,-0x2a0(%rbp)
jne    11f2 <main+0x52>
lea    0xe2f(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    138f <main+0x1ef>
lea    -0x2d0(%rbp),%rsi
lea    0xe29(%rip),%rdi
call   1060 <get_bcast_addr@plt>
lea    -0x220(%rbp),%rdi
mov    -0x2a0(%rbp),%rdx
mov    $0xc8,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     137c <main+0x1dc>
movb   $0x2d,-0x150(%rbp)
movb   $0x0,-0x14f(%rbp)
movb   $0x2d,-0x290(%rbp)
movb   $0x0,-0x28f(%rbp)
lea    -0x220(%rbp),%rdi
mov    -0x2a0(%rbp),%rdx
mov    $0xc8,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     1377 <main+0x1d7>
lea    -0x220(%rbp),%rdi
lea    -0x70(%rbp),%rdx
lea    -0xe0(%rbp),%r9
lea    -0x150(%rbp),%r10
lea    -0x290(%rbp),%rax
lea    0xda2(%rip),%rsi
lea    -0x294(%rbp),%rcx
lea    -0x298(%rbp),%r8
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   10a0 <sscanf@plt>
mov    %eax,-0x2a4(%rbp)
cmpl   $0x4,-0x2a4(%rbp)
jge    12c0 <main+0x120>
jmp    1377 <main+0x1d7>
lea    -0x290(%rbp),%rdi
lea    0xd5b(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    1372 <main+0x1d2>
lea    -0x2c0(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
movl   $0x0,-0x2d8(%rbp)
movl   $0x0,-0x2d4(%rbp)
cmpl   $0x11,-0x2d4(%rbp)
jg     135f <main+0x1bf>
lea    -0x2c0(%rbp),%rdi
movslq -0x2d8(%rbp),%rax
add    %rax,%rdi
lea    -0xe0(%rbp),%rsi
movslq -0x2d4(%rbp),%rax
add    %rax,%rsi
mov    $0x2,%edx
call   1090 <memcpy@plt>
mov    -0x2d4(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x2d4(%rbp)
mov    -0x2d8(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x2d8(%rbp)
jmp    1303 <main+0x163>
lea    -0x2d0(%rbp),%rdi
lea    -0x2c0(%rbp),%rsi
call   10b0 <send_wol@plt>
jmp    1243 <main+0xa3>
jmp    137c <main+0x1dc>
mov    -0x2a0(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2f0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2b8,%rsp
lea    0xe58(%rip),%rdi
lea    0xe5f(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1351 <main+0x1c1>
mov    %rax,%rbx
lea    0xe49(%rip),%rdi
lea    0x20(%rsp),%rsi
call   1060 <get_bcast_addr@plt>
lea    0x180(%rsp),%rdi
mov    $0xc8,%esi
mov    %rbx,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1347 <main+0x1b7>
movw   $0x2d,0x110(%rsp)
movw   $0x2d,0xa0(%rsp)
lea    0x180(%rsp),%rdi
mov    $0xc8,%esi
mov    %rbx,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1347 <main+0x1b7>
lea    0x180(%rsp),%r15
lea    0x1c(%rsp),%r13
lea    0x18(%rsp),%rbp
lea    0x30(%rsp),%r14
mov    %rsp,%r12
jmp    1259 <main+0xc9>
nopl   (%rax)
mov    %r15,%rdi
mov    $0xc8,%esi
mov    %rbx,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1347 <main+0x1b7>
mov    %r15,%rdi
lea    0xdb2(%rip),%rsi
lea    0x250(%rsp),%rdx
mov    %r13,%rcx
mov    %rbp,%r8
mov    %r14,%r9
lea    0xa0(%rsp),%rax
push   %rax
lea    0x118(%rsp),%rax
push   %rax
call   1090 <sscanf@plt>
add    $0x10,%rsp
cmp    $0x4,%eax
jl     1347 <main+0x1b7>
mov    0xa0(%rsp),%eax
mov    $0x31687465,%ecx
xor    %ecx,%eax
movzbl 0xa4(%rsp),%ecx
or     %eax,%ecx
jne    1240 <main+0xb0>
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
mov    %r12,%rdi
mov    %r14,%rsi
mov    $0x2,%edx
call   1080 <memcpy@plt>
lea    0x2(%rsp),%rdi
lea    0x33(%rsp),%rsi
mov    $0x2,%edx
call   1080 <memcpy@plt>
lea    0x4(%rsp),%rdi
lea    0x36(%rsp),%rsi
mov    $0x2,%edx
call   1080 <memcpy@plt>
lea    0x6(%rsp),%rdi
lea    0x39(%rsp),%rsi
mov    $0x2,%edx
call   1080 <memcpy@plt>
lea    0x8(%rsp),%rdi
lea    0x3c(%rsp),%rsi
mov    $0x2,%edx
call   1080 <memcpy@plt>
lea    0xa(%rsp),%rdi
lea    0x3f(%rsp),%rsi
mov    $0x2,%edx
call   1080 <memcpy@plt>
lea    0x20(%rsp),%rdi
mov    %r12,%rsi
call   10a0 <send_wol@plt>
jmp    1240 <main+0xb0>
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    135d <main+0x1cd>
lea    0xcdd(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x2b8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/net/arp\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [25 x i8] c"Unable to open the file\0A\00"
@.str.3 = [5 x i8] c"eth1\00"
@.str.4 = [32 x i8] c"%s 0x%x 0x%x %100s %100s %100s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = alloca [100 x i8]
%4 = alloca [100 x i8]
%5 = alloca [200 x i8]
%6 = alloca [100 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
%11 = alloca [16 x i8]
%12 = alloca [16 x i8]
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %1
%15 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %15, i32** %9
%16 = load i32*, i32** %9
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %20
18: ; preds = %0
%19 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %81
20: ; preds = %0
%21 = getelementptr inbounds [16 x i8], [16 x i8]* %12, i64 0, i64 0
%22 = call i32 @get_bcast_addr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %21)
%23 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 0
%24 = load i32*, i32** %9
%25 = call i8* @fgets(i8* %23, i32 200, i32* %24)
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %78
27: ; preds = %20
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
store i8 45, i8* %28
%29 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 1
store i8 0, i8* %29
%30 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
store i8 45, i8* %30
%31 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 1
store i8 0, i8* %31
br label %32
32: ; preds = %76, %27
%33 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 0
%34 = load i32*, i32** %9
%35 = call i8* @fgets(i8* %33, i32 200, i32* %34)
%36 = icmp ne i8* %35, null
br i1 %36, label %37, label %77
37: ; preds = %32
%38 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 0
%39 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%40 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%41 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%42 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%43 = call i32 @sscanf(i8* %38, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %39, i32* %7, i32* %8, i8* %40, i8* %41, i8* %42)
store i32 %43, i32* %10
%44 = load i32, i32* %10
%45 = icmp slt i32 %44, 4
br i1 %45, label %46, label %47
46: ; preds = %37
br label %77
47: ; preds = %37
%48 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%49 = call i32 @strcmp(i8* %48, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%50 = icmp ne i32 %49, 0
br i1 %50, label %76, label %51
51: ; preds = %47
%52 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 0
%53 = call i32 @memset(i8* %52, i32 0, i32 16)
store i32 0, i32* %14
store i32 0, i32* %13
br label %54
54: ; preds = %67, %51
%55 = load i32, i32* %13
%56 = icmp sle i32 %55, 17
br i1 %56, label %57, label %72
57: ; preds = %54
%58 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 0
%59 = load i32, i32* %14
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %58, i64 %60
%62 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%63 = load i32, i32* %13
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i8, i8* %62, i64 %64
%66 = call i32 @memcpy(i8* %61, i8* %65, i32 2)
br label %67
67: ; preds = %57
%68 = load i32, i32* %13
%69 = add nsw i32 %68, 3
store i32 %69, i32* %13
%70 = load i32, i32* %14
%71 = add nsw i32 %70, 2
store i32 %71, i32* %14
br label %54
72: ; preds = %54
%73 = getelementptr inbounds [16 x i8], [16 x i8]* %12, i64 0, i64 0
%74 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 0
%75 = call i32 @send_wol(i8* %73, i8* %74)
br label %76
76: ; preds = %72, %47
br label %32
77: ; preds = %46, %32
br label %78
78: ; preds = %77, %20
%79 = load i32*, i32** %9
%80 = call i32 @fclose(i32* %79)
store i32 0, i32* %1
br label %81
81: ; preds = %78, %18
%82 = load i32, i32* %1
ret i32 %82
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/net/arp\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [5 x i8] c"eth1\00"
@.str.4 = [32 x i8] c"%s 0x%x 0x%x %100s %100s %100s\0A\00"
@str = [24 x i8] c"Unable to open the file\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = alloca [100 x i8]
%3 = alloca [100 x i8]
%4 = alloca [200 x i8]
%5 = alloca [100 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca [16 x i8]
%9 = alloca [16 x i8]
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%13 = getelementptr inbounds [200 x i8], [200 x i8]* %4, i64 0, i64 0
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%15 = bitcast i32* %6 to i8*
%16 = bitcast i32* %7 to i8*
%17 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%18 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%19 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %23
21: ; preds = %0
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
br label %63
23: ; preds = %0
%24 = call i32 @get_bcast_addr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %18)
%25 = call i8* @fgets(i8* %13, i32 200, i32* %19)
%26 = icmp eq i8* %25, null
br i1 %26, label %61, label %27
27: ; preds = %23
store i8 45, i8* %12
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 1
store i8 0, i8* %28
store i8 45, i8* %14
%29 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 1
store i8 0, i8* %29
%30 = call i8* @fgets(i8* %13, i32 200, i32* %19)
%31 = icmp eq i8* %30, null
br i1 %31, label %61, label %32
32: ; preds = %27
%33 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 2
%34 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 3
%35 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 4
%36 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 6
%37 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 6
%38 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 9
%39 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 8
%40 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 12
%41 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 10
%42 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 15
br label %43
43: ; preds = %32, %58
%44 = call i32 @sscanf(i8* %13, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %10, i32* %6, i32* %7, i8* %11, i8* %12, i8* %14)
%45 = icmp slt i32 %44, 4
br i1 %45, label %61, label %46
46: ; preds = %43
%47 = call i32 @bcmp(i8* dereferenceable(5) %14, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i64 5)
%48 = icmp eq i32 %47, 0
br i1 %48, label %49, label %58
49: ; preds = %46
%50 = call i32 @memset(i8* %17, i32 0, i32 16)
%51 = call i32 @memcpy(i8* %17, i8* %11, i32 2)
%52 = call i32 @memcpy(i8* %33, i8* %34, i32 2)
%53 = call i32 @memcpy(i8* %35, i8* %36, i32 2)
%54 = call i32 @memcpy(i8* %37, i8* %38, i32 2)
%55 = call i32 @memcpy(i8* %39, i8* %40, i32 2)
%56 = call i32 @memcpy(i8* %41, i8* %42, i32 2)
%57 = call i32 @send_wol(i8* %18, i8* %17)
br label %58
58: ; preds = %49, %46
%59 = call i8* @fgets(i8* %13, i32 200, i32* %19)
%60 = icmp eq i8* %59, null
br i1 %60, label %61, label %43
61: ; preds = %43, %58, %27, %23
%62 = call i32 @fclose(i32* %19)
br label %63
63: ; preds = %61, %21
ret i32 0
}