#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
char *getMask(char *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int /*<<< orphan*/ *strstr(char *, char *);
int /*<<< orphan*/ system(char *);
int main(int argc, char **argv) {
  char devString[10];
  char comand[100];
  char line[20], pi[20];
  FILE *fd = NULL;
  int exist = 0;
  if (argc != 2) {
    printf("\nUsage: %s [iface]\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  if ((fd = popen("cat /proc/net/dev", "r")) == NULL) {
    printf("\nCan't open /proc/net/dev");
    exit(EXIT_FAILURE);
  }
  sprintf(devString, " %s:", argv[1]);
  while (fgets(line, sizeof(line), fd) != NULL) {
    if (strstr(line, devString) != NULL)
      exist = 1;
  }
  fclose(fd);
  if (!exist) {
    printf("No such device\n");
    exit(EXIT_FAILURE);
  }
  system("ip  neigh flush all");
  sprintf(comand, "fping -a -r1 -g %s  > /dev/null 2>&1", getMask(argv[1]));
  system(comand);
  exist = 0;
  fd = popen("arp -n | fgrep \" b8:27:eb\"", "r");
  while (fgets(line, 200, fd) != NULL) {
    exist = 1;
    strncpy(pi, line, sizeof(line));
    pi[sizeof(line)] = 0;
    printf("pi@%s\n", pi);
  }
  if (!exist)
    printf("Could'nt find PI in this network\n");
  fclose(fd);
  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)
movq   $0x0,-0xc8(%rbp)
movl   $0x0,-0xcc(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11fb <main+0x5b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
lea    0xe12(%rip),%rdi
lea    0xe1d(%rip),%rsi
call   1090 <popen@plt>
mov    %rax,-0xc8(%rbp)
cmp    $0x0,%rax
jne    123b <main+0x9b>
lea    0xe02(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
lea    -0x1a(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdf4(%rip),%rsi
call   10a0 <sprintf@plt>
lea    -0xa0(%rbp),%rdi
mov    -0xc8(%rbp),%rdx
mov    $0x14,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
je     129e <main+0xfe>
lea    -0xa0(%rbp),%rdi
lea    -0x1a(%rbp),%rsi
call   10c0 <strstr@plt>
cmp    $0x0,%rax
je     1299 <main+0xf9>
movl   $0x1,-0xcc(%rbp)
jmp    1253 <main+0xb3>
mov    -0xc8(%rbp),%rdi
call   1040 <fclose@plt>
cmpl   $0x0,-0xcc(%rbp)
jne    12d3 <main+0x133>
lea    0xd89(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2d14(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
lea    0xd7d(%rip),%rdi
call   1050 <system@plt>
lea    -0x80(%rbp),%rax
mov    %rax,-0xd8(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <getMask@plt>
mov    -0xd8(%rbp),%rdi
mov    %rax,%rdx
lea    0xd63(%rip),%rsi
call   10a0 <sprintf@plt>
lea    -0x80(%rbp),%rdi
call   1050 <system@plt>
movl   $0x0,-0xcc(%rbp)
lea    0xd69(%rip),%rdi
lea    0xcf8(%rip),%rsi
call   1090 <popen@plt>
mov    %rax,-0xc8(%rbp)
lea    -0xa0(%rbp),%rdi
mov    -0xc8(%rbp),%rdx
mov    $0xc8,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
je     139f <main+0x1ff>
movl   $0x1,-0xcc(%rbp)
lea    -0xc0(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
mov    $0x14,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0xac(%rbp)
lea    -0xc0(%rbp),%rsi
lea    0xd18(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    133a <main+0x19a>
cmpl   $0x0,-0xcc(%rbp)
jne    13ba <main+0x21a>
lea    0xcff(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0xc8(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
mov    %rsi,%r14
cmp    $0x2,%edi
jne    1341 <main+0x191>
lea    0xe40(%rip),%rdi
lea    0xe4b(%rip),%rsi
call   10a0 <popen@plt>
test   %rax,%rax
je     1354 <main+0x1a4>
mov    %rax,%r15
mov    0x8(%r14),%rdx
lea    0xe4b(%rip),%rsi
lea    0x16(%rsp),%rdi
call   10b0 <sprintf@plt>
mov    %rsp,%rdi
mov    $0x14,%esi
mov    %r15,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
je     1364 <main+0x1b4>
xor    %ebp,%ebp
mov    %rsp,%rbx
lea    0x16(%rsp),%r12
mov    $0x1,%r13d
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r12,%rsi
call   10d0 <strstr@plt>
test   %rax,%rax
cmovne %r13d,%ebp
mov    %rbx,%rdi
mov    $0x14,%esi
mov    %r15,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
jne    1230 <main+0x80>
mov    %r15,%rdi
call   1050 <fclose@plt>
test   %ebp,%ebp
je     136c <main+0x1bc>
lea    0xdd9(%rip),%rdi
call   1060 <system@plt>
mov    0x8(%r14),%rdi
call   1080 <getMask@plt>
lea    0xdd8(%rip),%rsi
lea    0x40(%rsp),%rbx
mov    %rbx,%rdi
mov    %rax,%rdx
call   10b0 <sprintf@plt>
mov    %rbx,%rdi
call   1060 <system@plt>
lea    0xdde(%rip),%rdi
lea    0xd7d(%rip),%rsi
call   10a0 <popen@plt>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0xc8,%esi
mov    %rax,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
je     1319 <main+0x169>
lea    0x20(%rsp),%r15
mov    %rsp,%rbx
lea    0xdc6(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x14,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x34(%rsp)
mov    %r12,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
mov    $0xc8,%esi
mov    %r14,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
jne    12e0 <main+0x130>
jmp    1325 <main+0x175>
lea    0xd91(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%r14),%rsi
lea    0xcb5(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1378 <main+0x1c8>
lea    0xccd(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1378 <main+0x1c8>
mov    %r15,%rdi
call   1050 <fclose@plt>
lea    0xd2f(%rip),%rdi
call   1040 <puts@plt>
mov    0x2c61(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"\0AUsage: %s [iface]\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [18 x i8] c"cat /proc/net/dev\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [26 x i8] c"\0ACan't open /proc/net/dev\00"
@.str.4 = [5 x i8] c" %s:\00"
@.str.5 = [16 x i8] c"No such device\0A\00"
@.str.6 = [20 x i8] c"ip neigh flush all\00"
@.str.7 = [37 x i8] c"fping -a -r1 -g %s > /dev/null 2>&1\00"
@.str.8 = [27 x i8] c"arp -n | fgrep \22 b8:27:eb\22\00"
@.str.9 = [7 x i8] c"pi@%s\0A\00"
@.str.10 = [34 x i8] c"Could'nt find PI in this network\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [10 x i8]
%7 = alloca [100 x i8]
%8 = alloca [20 x i8]
%9 = alloca [20 x i8]
%10 = alloca i32*
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %10
store i32 0, i32* %11
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %21
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %2
%22 = call i32* @popen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %22, i32** %10
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %28
24: ; preds = %21
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %21
%29 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32 @sprintf(i8* %29, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %32)
br label %34
34: ; preds = %45, %28
%35 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%36 = load i32*, i32** %10
%37 = call i32* @fgets(i8* %35, i32 20, i32* %36)
%38 = icmp ne i32* %37, null
br i1 %38, label %39, label %46
39: ; preds = %34
%40 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%41 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%42 = call i32* @strstr(i8* %40, i8* %41)
%43 = icmp ne i32* %42, null
br i1 %43, label %44, label %45
44: ; preds = %39
store i32 1, i32* %11
br label %45
45: ; preds = %44, %39
br label %34
46: ; preds = %34
%47 = load i32*, i32** %10
%48 = call i32 @fclose(i32* %47)
%49 = load i32, i32* %11
%50 = icmp ne i32 %49, 0
br i1 %50, label %55, label %51
51: ; preds = %46
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%53 = load i32, i32* @EXIT_FAILURE
%54 = call i32 @exit(i32 %53)
unreachable
55: ; preds = %46
%56 = call i32 @system(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
%57 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%58 = load i8**, i8*** %5
%59 = getelementptr inbounds i8*, i8** %58, i64 1
%60 = load i8*, i8** %59
%61 = call i8* @getMask(i8* %60)
%62 = call i32 @sprintf(i8* %57, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0), i8* %61)
%63 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%64 = call i32 @system(i8* %63)
store i32 0, i32* %11
%65 = call i32* @popen(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %65, i32** %10
br label %66
66: ; preds = %71, %55
%67 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%68 = load i32*, i32** %10
%69 = call i32* @fgets(i8* %67, i32 200, i32* %68)
%70 = icmp ne i32* %69, null
br i1 %70, label %71, label %78
71: ; preds = %66
store i32 1, i32* %11
%72 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%73 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%74 = call i32 @strncpy(i8* %72, i8* %73, i32 20)
%75 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 20
store i8 0, i8* %75
%76 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), i8* %76)
br label %66
78: ; preds = %66
%79 = load i32, i32* %11
%80 = icmp ne i32 %79, 0
br i1 %80, label %83, label %81
81: ; preds = %78
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.10, i64 0, i64 0))
br label %83
83: ; preds = %81, %78
%84 = load i32*, i32** %10
%85 = call i32 @fclose(i32* %84)
ret i32 0
}

LLVM IR (-O2):
@.str = [20 x i8] c"\0AUsage: %s [iface]\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [18 x i8] c"cat /proc/net/dev\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [26 x i8] c"\0ACan't open /proc/net/dev\00"
@.str.4 = [5 x i8] c" %s:\00"
@.str.6 = [20 x i8] c"ip neigh flush all\00"
@.str.7 = [37 x i8] c"fping -a -r1 -g %s > /dev/null 2>&1\00"
@.str.8 = [27 x i8] c"arp -n | fgrep \22 b8:27:eb\22\00"
@.str.9 = [7 x i8] c"pi@%s\0A\00"
@str = [15 x i8] c"No such device\00"
@str.11 = [33 x i8] c"Could'nt find PI in this network\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [10 x i8]
%4 = alloca [100 x i8]
%5 = alloca [20 x i8]
%6 = alloca [20 x i8]
%7 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%11 = icmp eq i32 %0, 2
br i1 %11, label %17, label %12
12: ; preds = %2
%13 = load i8*, i8** %1
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %2
%18 = tail call i32* @popen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%22 = load i32, i32* @EXIT_FAILURE
%23 = tail call i32 @exit(i32 %22)
unreachable
24: ; preds = %17
%25 = getelementptr inbounds i8*, i8** %1, i64 1
%26 = load i8*, i8** %25
%27 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %26)
%28 = call i32* @fgets(i8* %9, i32 20, i32* %18)
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %32
30: ; preds = %24
%31 = call i32 @fclose(i32* %18)
br label %42
32: ; preds = %24, %32
%33 = phi i32 [ %36, %32 ], [ 0, %24 ]
%34 = call i32* @strstr(i8* %9, i8* %7)
%35 = icmp eq i32* %34, null
%36 = select i1 %35, i32 %33, i32 1
%37 = call i32* @fgets(i8* %9, i32 20, i32* %18)
%38 = icmp eq i32* %37, null
br i1 %38, label %39, label %32
39: ; preds = %32
%40 = icmp eq i32 %36, 0
%41 = call i32 @fclose(i32* %18)
br i1 %40, label %42, label %46
42: ; preds = %30, %39
%43 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%44 = load i32, i32* @EXIT_FAILURE
%45 = call i32 @exit(i32 %44)
unreachable
46: ; preds = %39
%47 = call i32 @system(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
%48 = load i8*, i8** %25
%49 = call i8* @getMask(i8* %48)
%50 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0), i8* %49)
%51 = call i32 @system(i8* %8)
%52 = call i32* @popen(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%53 = call i32* @fgets(i8* %9, i32 200, i32* %52)
%54 = icmp eq i32* %53, null
br i1 %54, label %62, label %55
55: ; preds = %46
%56 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 20
br label %57
57: ; preds = %55, %57
%58 = call i32 @strncpy(i8* %10, i8* %9, i32 20)
store i8 0, i8* %56
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), i8* %10)
%60 = call i32* @fgets(i8* %9, i32 200, i32* %52)
%61 = icmp eq i32* %60, null
br i1 %61, label %64, label %57
62: ; preds = %46
%63 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.11, i64 0, i64 0))
br label %64
64: ; preds = %57, %62
%65 = call i32 @fclose(i32* %52)
ret i32 0
}