#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 host[100];
  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;
  host[0] = '\0';
  fp = fopen("/proc/net/arp", "r");
  if (fp == NULL) {
    printf("Unable to open the file\n");
    return 0;
  }
  get_bcast_addr("br0", (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, "br0")) {
        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    $0x360,%rsp
movl   $0x0,-0x4(%rbp)
movb   $0x0,-0x70(%rbp)
lea    0xe43(%rip),%rdi
lea    0xe4a(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x310(%rbp)
cmpq   $0x0,-0x310(%rbp)
jne    11f6 <main+0x56>
lea    0xe2b(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1396 <main+0x1f6>
lea    -0x340(%rbp),%rsi
lea    0xe25(%rip),%rdi
call   1060 <get_bcast_addr@plt>
lea    -0x290(%rbp),%rdi
mov    -0x310(%rbp),%rdx
mov    $0xc8,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     1383 <main+0x1e3>
movb   $0x2d,-0x1c0(%rbp)
movb   $0x0,-0x1bf(%rbp)
movb   $0x2d,-0x300(%rbp)
movb   $0x0,-0x2ff(%rbp)
lea    -0x290(%rbp),%rdi
mov    -0x310(%rbp),%rdx
mov    $0xc8,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     137e <main+0x1de>
lea    -0x290(%rbp),%rdi
lea    -0xe0(%rbp),%rdx
lea    -0x150(%rbp),%r9
lea    -0x1c0(%rbp),%r10
lea    -0x300(%rbp),%rax
lea    0xd9a(%rip),%rsi
lea    -0x304(%rbp),%rcx
lea    -0x308(%rbp),%r8
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   10a0 <sscanf@plt>
mov    %eax,-0x314(%rbp)
cmpl   $0x4,-0x314(%rbp)
jge    12c7 <main+0x127>
jmp    137e <main+0x1de>
lea    -0x300(%rbp),%rdi
lea    0xd54(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    1379 <main+0x1d9>
lea    -0x330(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
movl   $0x0,-0x348(%rbp)
movl   $0x0,-0x344(%rbp)
cmpl   $0x11,-0x344(%rbp)
jg     1366 <main+0x1c6>
lea    -0x330(%rbp),%rdi
movslq -0x348(%rbp),%rax
add    %rax,%rdi
lea    -0x150(%rbp),%rsi
movslq -0x344(%rbp),%rax
add    %rax,%rsi
mov    $0x2,%edx
call   1090 <memcpy@plt>
mov    -0x344(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x344(%rbp)
mov    -0x348(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x348(%rbp)
jmp    130a <main+0x16a>
lea    -0x340(%rbp),%rdi
lea    -0x330(%rbp),%rsi
call   10b0 <send_wol@plt>
jmp    1247 <main+0xa7>
jmp    1383 <main+0x1e3>
mov    -0x310(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x360,%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     1344 <main+0x1b4>
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     133a <main+0x1aa>
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     133a <main+0x1aa>
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     133a <main+0x1aa>
mov    %r15,%rdi
lea    0xdb1(%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     133a <main+0x1aa>
cmpl   $0x307262,0xa0(%rsp)
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    1350 <main+0x1c0>
lea    0xce9(%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 = [4 x i8] c"br0\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 [100 x i8]
%6 = alloca [200 x i8]
%7 = alloca [100 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32
%12 = alloca [16 x i8]
%13 = alloca [16 x i8]
%14 = alloca i32
%15 = alloca i32
store i32 0, i32* %1
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
store i8 0, i8* %16
%17 = 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* %17, i32** %10
%18 = load i32*, i32** %10
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %22
20: ; preds = %0
%21 = 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 %83
22: ; preds = %0
%23 = getelementptr inbounds [16 x i8], [16 x i8]* %13, i64 0, i64 0
%24 = call i32 @get_bcast_addr(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %23)
%25 = getelementptr inbounds [200 x i8], [200 x i8]* %6, i64 0, i64 0
%26 = load i32*, i32** %10
%27 = call i8* @fgets(i8* %25, i32 200, i32* %26)
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %80
29: ; preds = %22
%30 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
store i8 45, i8* %30
%31 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 1
store i8 0, i8* %31
%32 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
store i8 45, i8* %32
%33 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 1
store i8 0, i8* %33
br label %34
34: ; preds = %78, %29
%35 = getelementptr inbounds [200 x i8], [200 x i8]* %6, i64 0, i64 0
%36 = load i32*, i32** %10
%37 = call i8* @fgets(i8* %35, i32 200, i32* %36)
%38 = icmp ne i8* %37, null
br i1 %38, label %39, label %79
39: ; preds = %34
%40 = getelementptr inbounds [200 x i8], [200 x i8]* %6, i64 0, i64 0
%41 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%42 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%43 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%44 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%45 = call i32 @sscanf(i8* %40, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %41, i32* %8, i32* %9, i8* %42, i8* %43, i8* %44)
store i32 %45, i32* %11
%46 = load i32, i32* %11
%47 = icmp slt i32 %46, 4
br i1 %47, label %48, label %49
48: ; preds = %39
br label %79
49: ; preds = %39
%50 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%51 = call i32 @strcmp(i8* %50, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%52 = icmp ne i32 %51, 0
br i1 %52, label %78, label %53
53: ; preds = %49
%54 = getelementptr inbounds [16 x i8], [16 x i8]* %12, i64 0, i64 0
%55 = call i32 @memset(i8* %54, i32 0, i32 16)
store i32 0, i32* %15
store i32 0, i32* %14
br label %56
56: ; preds = %69, %53
%57 = load i32, i32* %14
%58 = icmp sle i32 %57, 17
br i1 %58, label %59, label %74
59: ; preds = %56
%60 = getelementptr inbounds [16 x i8], [16 x i8]* %12, i64 0, i64 0
%61 = load i32, i32* %15
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %60, i64 %62
%64 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%65 = load i32, i32* %14
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8, i8* %64, i64 %66
%68 = call i32 @memcpy(i8* %63, i8* %67, i32 2)
br label %69
69: ; preds = %59
%70 = load i32, i32* %14
%71 = add nsw i32 %70, 3
store i32 %71, i32* %14
%72 = load i32, i32* %15
%73 = add nsw i32 %72, 2
store i32 %73, i32* %15
br label %56
74: ; preds = %56
%75 = getelementptr inbounds [16 x i8], [16 x i8]* %13, i64 0, i64 0
%76 = getelementptr inbounds [16 x i8], [16 x i8]* %12, i64 0, i64 0
%77 = call i32 @send_wol(i8* %75, i8* %76)
br label %78
78: ; preds = %74, %49
br label %34
79: ; preds = %48, %34
br label %80
80: ; preds = %79, %22
%81 = load i32*, i32** %10
%82 = call i32 @fclose(i32* %81)
store i32 0, i32* %1
br label %83
83: ; preds = %80, %20
%84 = load i32, i32* %1
ret i32 %84
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/net/arp\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [4 x i8] c"br0\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 %64
23: ; preds = %0
%24 = call i32 @get_bcast_addr(i8* getelementptr inbounds ([4 x i8], [4 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 %62, 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 %62, label %32
32: ; preds = %27
%33 = bitcast [100 x i8]* %5 to i32*
%34 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 2
%35 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 3
%36 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 4
%37 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 6
%38 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 6
%39 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 9
%40 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 8
%41 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 12
%42 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 10
%43 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 15
br label %44
44: ; preds = %32, %59
%45 = 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)
%46 = icmp slt i32 %45, 4
br i1 %46, label %62, label %47
47: ; preds = %44
%48 = load i32, i32* %33
%49 = icmp eq i32 %48, 3175010
br i1 %49, label %50, label %59
50: ; preds = %47
%51 = call i32 @memset(i8* %17, i32 0, i32 16)
%52 = call i32 @memcpy(i8* %17, i8* %11, i32 2)
%53 = call i32 @memcpy(i8* %34, i8* %35, i32 2)
%54 = call i32 @memcpy(i8* %36, i8* %37, i32 2)
%55 = call i32 @memcpy(i8* %38, i8* %39, i32 2)
%56 = call i32 @memcpy(i8* %40, i8* %41, i32 2)
%57 = call i32 @memcpy(i8* %42, i8* %43, i32 2)
%58 = call i32 @send_wol(i8* %18, i8* %17)
br label %59
59: ; preds = %50, %47
%60 = call i8* @fgets(i8* %13, i32 200, i32* %19)
%61 = icmp eq i8* %60, null
br i1 %61, label %62, label %44
62: ; preds = %44, %59, %27, %23
%63 = call i32 @fclose(i32* %19)
br label %64
64: ; preds = %62, %21
ret i32 0
}