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

/* Variables and functions */
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int formatMAC(char *, char *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
char *strtok(char *, char *);
int macForIP(char *ipAddr, char *macAddr) {
  FILE *in;
  extern FILE *popen();
  char buff[512];
  char command[1024] = "arp ";
  int returnValue = 0;
  strcat(command, ipAddr);
  if (!(in = popen(command, "r"))) {
    returnValue = 1;
  } else {
    while (fgets(buff, sizeof(buff), in) != NULL) {
      char *pch;
      pch = strtok(buff, " ");
      char macAddrTemp[32] = "";
      int found = 0;
      while (pch != NULL) {
        if (strchr(pch, ':') != 0) {
          strcpy(macAddrTemp, pch);
          found = 1;
          break;
        }
        pch = strtok(NULL, " ");
      }
      if (!found) {
        strcpy(macAddr, "no MAC found");
      } else {
        returnValue = formatMAC(macAddrTemp, macAddr);
        break;
      }
    }
  }
  pclose(in);
  return returnValue;
}


x86 assembly (clang, -O0):
<macForIP>:
push   %rbp
mov    %rsp,%rbp
sub    $0x660,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x620(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
movb   $0x61,-0x620(%rbp)
movb   $0x72,-0x61f(%rbp)
movb   $0x70,-0x61e(%rbp)
movb   $0x20,-0x61d(%rbp)
movl   $0x0,-0x624(%rbp)
lea    -0x620(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   10a0 <strcat@plt>
lea    -0x620(%rbp),%rdi
lea    0xe06(%rip),%rsi
mov    $0x0,%al
call   1080 <popen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    121e <macForIP+0x8e>
movl   $0x1,-0x624(%rbp)
jmp    1327 <macForIP+0x197>
jmp    1223 <macForIP+0x93>
lea    -0x220(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x200,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     1322 <macForIP+0x192>
lea    -0x220(%rbp),%rdi
lea    0xdb2(%rip),%rsi
call   1090 <strtok@plt>
mov    %rax,-0x630(%rbp)
lea    -0x650(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
movl   $0x0,-0x654(%rbp)
cmpq   $0x0,-0x630(%rbp)
je     12e0 <macForIP+0x150>
mov    -0x630(%rbp),%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     12c4 <macForIP+0x134>
lea    -0x650(%rbp),%rdi
mov    -0x630(%rbp),%rsi
call   1030 <strcpy@plt>
movl   $0x1,-0x654(%rbp)
jmp    12e0 <macForIP+0x150>
xor    %eax,%eax
mov    %eax,%edi
lea    0xd33(%rip),%rsi
call   1090 <strtok@plt>
mov    %rax,-0x630(%rbp)
jmp    1279 <macForIP+0xe9>
cmpl   $0x0,-0x654(%rbp)
jne    1302 <macForIP+0x172>
mov    -0x10(%rbp),%rdi
lea    0xd0c(%rip),%rsi
call   1030 <strcpy@plt>
jmp    131d <macForIP+0x18d>
lea    -0x650(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10b0 <formatMAC@plt>
mov    %eax,-0x624(%rbp)
jmp    1322 <macForIP+0x192>
jmp    1223 <macForIP+0x93>
jmp    1327 <macForIP+0x197>
mov    -0x18(%rbp),%rdi
call   1050 <pclose@plt>
mov    -0x624(%rbp),%eax
add    $0x660,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<macForIP>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x628,%rsp
mov    %rsi,%r14
mov    %rdi,%rbp
lea    0x220(%rsp),%rbx
xor    %r12d,%r12d
mov    $0x400,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
movl   $0x20707261,0x220(%rsp)
61 72 70 20
mov    %rbx,%rdi
mov    %rbp,%rsi
call   10a0 <strcat@plt>
lea    0xe22(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1080 <popen@plt>
mov    %rax,%r15
test   %rax,%rax
je     12a6 <macForIP+0x116>
lea    0x20(%rsp),%rdi
mov    $0x200,%esi
mov    %r15,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     12ca <macForIP+0x13a>
lea    0xdec(%rip),%rbx
lea    0x20(%rsp),%r12
lea    0xde2(%rip),%r13
jmp    1254 <macForIP+0xc4>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
mov    %r13,%rsi
call   1030 <strcpy@plt>
mov    %r12,%rdi
mov    $0x200,%esi
mov    %r15,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     12e7 <macForIP+0x157>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1090 <strtok@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
test   %rax,%rax
je     1230 <macForIP+0xa0>
mov    %rax,%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbp,%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
test   %rax,%rax
jne    12ae <macForIP+0x11e>
xor    %edi,%edi
mov    %rbx,%rsi
call   1090 <strtok@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1280 <macForIP+0xf0>
jmp    1230 <macForIP+0xa0>
mov    $0x1,%r12d
jmp    12ca <macForIP+0x13a>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   10b0 <formatMAC@plt>
mov    %eax,%r12d
mov    %r15,%rdi
call   1050 <pclose@plt>
mov    %r12d,%eax
add    $0x628,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %r12d,%r12d
jmp    12ca <macForIP+0x13a>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [13 x i8] c"no MAC found\00"
define i32 @macForIP(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca [512 x i8]
%7 = alloca [1024 x i8]
%8 = alloca i32
%9 = alloca i8*
%10 = alloca [32 x i8]
%11 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%12 = bitcast [1024 x i8]* %7 to i8*
%13 = bitcast i8* %12 to [1024 x i8]*
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i32 0, i32 0
store i8 97, i8* %14
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i32 0, i32 1
store i8 114, i8* %15
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i32 0, i32 2
store i8 112, i8* %16
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i32 0, i32 3
store i8 32, i8* %17
store i32 0, i32* %8
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%19 = load i8*, i8** %3
%20 = call i32 @strcat(i8* %18, i8* %19)
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%22 = call i32* (i8*, i8*, ...) bitcast (i32* (...)* @popen to i32* (i8*, i8*, ...)*)(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %22, i32** %5
%23 = icmp ne i32* %22, null
br i1 %23, label %25, label %24
24: ; preds = %2
store i32 1, i32* %8
br label %60
25: ; preds = %2
br label %26
26: ; preds = %58, %25
%27 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%28 = load i32*, i32** %5
%29 = call i32* @fgets(i8* %27, i32 512, i32* %28)
%30 = icmp ne i32* %29, null
br i1 %30, label %31, label %59
31: ; preds = %26
%32 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%33 = call i8* @strtok(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %33, i8** %9
%34 = bitcast [32 x i8]* %10 to i8*
store i32 0, i32* %11
br label %35
35: ; preds = %46, %31
%36 = load i8*, i8** %9
%37 = icmp ne i8* %36, null
br i1 %37, label %38, label %48
38: ; preds = %35
%39 = load i8*, i8** %9
%40 = call i64 @strchr(i8* %39, i8 signext 58)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %46
42: ; preds = %38
%43 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%44 = load i8*, i8** %9
%45 = call i32 @strcpy(i8* %43, i8* %44)
store i32 1, i32* %11
br label %48
46: ; preds = %38
%47 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %47, i8** %9
br label %35
48: ; preds = %42, %35
%49 = load i32, i32* %11
%50 = icmp ne i32 %49, 0
br i1 %50, label %54, label %51
51: ; preds = %48
%52 = load i8*, i8** %4
%53 = call i32 @strcpy(i8* %52, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %58
54: ; preds = %48
%55 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%56 = load i8*, i8** %4
%57 = call i32 @formatMAC(i8* %55, i8* %56)
store i32 %57, i32* %8
br label %59
58: ; preds = %51
br label %26
59: ; preds = %54, %26
br label %60
60: ; preds = %59, %24
%61 = load i32*, i32** %5
%62 = call i32 @pclose(i32* %61)
%63 = load i32, i32* %8
ret i32 %63
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [13 x i8] c"no MAC found\00"
define i32 @macForIP(i8* %0, i8* %1) {
%3 = alloca [512 x i8]
%4 = alloca [1024 x i8]
%5 = alloca [32 x i8]
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
store i8 97, i8* %7
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 1
store i8 114, i8* %8
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 2
store i8 112, i8* %9
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 3
store i8 32, i8* %10
%11 = call i32 @strcat(i8* %7, i8* %0)
%12 = call i32* (i8*, i8*, ...) bitcast (i32* (...)* @popen to i32* (i8*, i8*, ...)*)(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %36, label %14
14: ; preds = %2
%15 = call i32* @fgets(i8* %6, i32 512, i32* %12)
%16 = icmp eq i32* %15, null
br i1 %16, label %36, label %17
17: ; preds = %14
%18 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
br label %19
19: ; preds = %17, %32
%20 = call i8* @strtok(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp eq i8* %20, null
br i1 %21, label %32, label %22
22: ; preds = %19, %26
%23 = phi i8* [ %27, %26 ], [ %20, %19 ]
%24 = call i64 @strchr(i8* %23, i8 signext 58)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp eq i8* %27, null
br i1 %28, label %32, label %22
29: ; preds = %22
%30 = call i32 @strcpy(i8* %18, i8* %23)
%31 = call i32 @formatMAC(i8* %18, i8* %1)
br label %36
32: ; preds = %26, %19
%33 = call i32 @strcpy(i8* %1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%34 = call i32* @fgets(i8* %6, i32 512, i32* %12)
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %19
36: ; preds = %32, %14, %29, %2
%37 = phi i32 [ 1, %2 ], [ %31, %29 ], [ 0, %14 ], [ 0, %32 ]
%38 = call i32 @pclose(i32* %12)
ret i32 %37
}