#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, char *, char *);
char *safe_strdup(char *);
scalar_t__ strcmp(char *, char *);
char *arp_get(char *req_ip) {
  FILE *proc;
  char ip[16];
  char mac[18];
  char *reply = NULL;
  if (!(proc = fopen("/proc/net/arp", "r"))) {
    return NULL;
  }
  while (!feof(proc) && fgetc(proc) != '\n')
    ;
  reply = NULL;
  while (!feof(proc) &&
         (fscanf(proc, " %15[0-9.] %*s %*s %17[A-Fa-f0-9:] %*s %*s", ip, mac) ==
          2)) {
    if (strcmp(ip, req_ip) == 0) {
      reply = safe_strdup(mac);
      break;
    }
  }
  fclose(proc);
  return reply;
}


x86 assembly (clang, -O0):
<arp_get>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x58(%rbp)
lea    0xe75(%rip),%rdi
lea    0xe7c(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11b2 <arp_get+0x42>
movq   $0x0,-0x8(%rbp)
jmp    128b <arp_get+0x11b>
jmp    11b7 <arp_get+0x47>
mov    -0x18(%rbp),%rdi
call   1070 <feof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x59(%rbp)
jne    11e5 <arp_get+0x75>
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
movsbl %al,%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x59(%rbp)
mov    -0x59(%rbp),%al
test   $0x1,%al
jne    11f5 <arp_get+0x85>
jmp    11fa <arp_get+0x8a>
jmp    11b7 <arp_get+0x47>
movq   $0x0,-0x58(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <feof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x5a(%rbp)
jne    123c <arp_get+0xcc>
mov    -0x18(%rbp),%rdi
lea    -0x30(%rbp),%rdx
lea    -0x50(%rbp),%rcx
lea    0xde2(%rip),%rsi
call   1040 <fscanf@plt>
cmp    $0x2,%eax
sete   %al
mov    %al,-0x5a(%rbp)
mov    -0x5a(%rbp),%al
test   $0x1,%al
jne    124c <arp_get+0xdc>
jmp    127a <arp_get+0x10a>
lea    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1275 <arp_get+0x105>
lea    -0x50(%rbp),%rdi
call   1080 <safe_strdup@plt>
mov    %rax,-0x58(%rbp)
jmp    127a <arp_get+0x10a>
jmp    1202 <arp_get+0x92>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x58(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arp_get>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rdi,%r14
lea    0xe78(%rip),%rdi
lea    0xe7f(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1217 <arp_get+0xa7>
mov    %rax,%rbx
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    11b8 <arp_get+0x48>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
cmp    $0xa,%al
jne    11a0 <arp_get+0x30>
xor    %r15d,%r15d
lea    0xe4e(%rip),%r12
lea    0x20(%rsp),%r13
mov    %rsp,%rbp
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    120d <arp_get+0x9d>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
mov    %rbp,%rcx
call   1040 <fscanf@plt>
cmp    $0x2,%eax
jne    120d <arp_get+0x9d>
mov    %r13,%rdi
mov    %r14,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    11d0 <arp_get+0x60>
mov    %rsp,%rdi
call   1080 <safe_strdup@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    121a <arp_get+0xaa>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x38,%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 = [43 x i8] c" %15[0-9.] %*s %*s %17[A-Fa-f0-9:] %*s %*s\00"
define i8* @arp_get(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [16 x i8]
%6 = alloca [18 x i8]
%7 = alloca i8*
store i8* %0, i8** %3
store i8* null, i8** %7
%8 = 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* %8, i32** %4
%9 = icmp ne i32* %8, null
br i1 %9, label %11, label %10
10: ; preds = %1
store i8* null, i8** %2
br label %50
11: ; preds = %1
br label %12
12: ; preds = %23, %11
%13 = load i32*, i32** %4
%14 = call i32 @feof(i32* %13)
%15 = icmp ne i32 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %12
%17 = load i32*, i32** %4
%18 = call signext i8 @fgetc(i32* %17)
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 10
br label %21
21: ; preds = %16, %12
%22 = phi i1 [ false, %12 ], [ %20, %16 ]
br i1 %22, label %23, label %24
23: ; preds = %21
br label %12
24: ; preds = %21
store i8* null, i8** %7
br label %25
25: ; preds = %45, %24
%26 = load i32*, i32** %4
%27 = call i32 @feof(i32* %26)
%28 = icmp ne i32 %27, 0
br i1 %28, label %35, label %29
29: ; preds = %25
%30 = load i32*, i32** %4
%31 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%32 = getelementptr inbounds [18 x i8], [18 x i8]* %6, i64 0, i64 0
%33 = call i32 @fscanf(i32* %30, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i8* %31, i8* %32)
%34 = icmp eq i32 %33, 2
br label %35
35: ; preds = %29, %25
%36 = phi i1 [ false, %25 ], [ %34, %29 ]
br i1 %36, label %37, label %46
37: ; preds = %35
%38 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%39 = load i8*, i8** %3
%40 = call i64 @strcmp(i8* %38, i8* %39)
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %37
%43 = getelementptr inbounds [18 x i8], [18 x i8]* %6, i64 0, i64 0
%44 = call i8* @safe_strdup(i8* %43)
store i8* %44, i8** %7
br label %46
45: ; preds = %37
br label %25
46: ; preds = %42, %35
%47 = load i32*, i32** %4
%48 = call i32 @fclose(i32* %47)
%49 = load i8*, i8** %7
store i8* %49, i8** %2
br label %50
50: ; preds = %46, %10
%51 = load i8*, i8** %2
ret i8* %51
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/net/arp\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [43 x i8] c" %15[0-9.] %*s %*s %17[A-Fa-f0-9:] %*s %*s\00"
define i8* @arp_get(i8* %0) {
%2 = alloca [16 x i8]
%3 = alloca [18 x i8]
%4 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [18 x i8], [18 x i8]* %3, i64 0, i64 0
%6 = 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))
%7 = icmp eq i32* %6, null
br i1 %7, label %29, label %8
8: ; preds = %1, %11
%9 = tail call i32 @feof(i32* %6)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = tail call signext i8 @fgetc(i32* %6)
%13 = icmp eq i8 %12, 10
br i1 %13, label %14, label %8
14: ; preds = %8, %11
br label %15
15: ; preds = %14, %21
%16 = call i32 @feof(i32* %6)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %26
18: ; preds = %15
%19 = call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i8* %4, i8* %5)
%20 = icmp eq i32 %19, 2
br i1 %20, label %21, label %26
21: ; preds = %18
%22 = call i64 @strcmp(i8* %4, i8* %0)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %15
24: ; preds = %21
%25 = call i8* @safe_strdup(i8* %5)
br label %26
26: ; preds = %15, %18, %24
%27 = phi i8* [ %25, %24 ], [ null, %18 ], [ null, %15 ]
%28 = call i32 @fclose(i32* %6)
br label %29
29: ; preds = %1, %26
%30 = phi i8* [ %27, %26 ], [ null, %1 ]
ret i8* %30
}