#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*/ arp_display(char *, int, int, char *, char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ perror(char *);
int sscanf(char *, char *, char *, int *, int *, char *, char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int arp_show(char *name) {
  char ip[100];
  char hwa[100];
  char mask[100];
  char line[200];
  char dev[100];
  int type, flags;
  FILE *fp;
  if ((fp = fopen("/proc/net/arp", "r")) == NULL) {
    perror("/proc/net/arp");
    return (-1);
  }
  if (fgets(line, sizeof(line), fp) != (char *)NULL) {
    strcpy(mask, "-");
    strcpy(dev, "-");
    for (; fgets(line, sizeof(line), fp);) {
      int num = sscanf(line, "%s 0x%x 0x%x %100s %100s %100s\n", ip, &type,
                       &flags, hwa, mask, dev);
      if (num < 4)
        break;
      arp_display(ip, type, flags, hwa, mask, dev);
    }
  }
  (void)fclose(fp);
  return (0);
}


x86 assembly (clang, -O0):
<arp_show>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2d0,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe7a(%rip),%rdi
lea    0xe81(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x2b0(%rbp)
cmp    $0x0,%rax
jne    11bb <arp_show+0x4b>
lea    0xe56(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12c7 <arp_show+0x157>
lea    -0x230(%rbp),%rdi
mov    -0x2b0(%rbp),%rdx
mov    $0xc8,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     12b4 <arp_show+0x144>
lea    -0x160(%rbp),%rdi
lea    0xe25(%rip),%rsi
call   1040 <strcpy@plt>
lea    -0x2a0(%rbp),%rdi
lea    0xe12(%rip),%rsi
call   1040 <strcpy@plt>
lea    -0x230(%rbp),%rdi
mov    -0x2b0(%rbp),%rdx
mov    $0xc8,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     12af <arp_show+0x13f>
lea    -0x230(%rbp),%rdi
lea    -0x80(%rbp),%rdx
lea    -0xf0(%rbp),%r9
lea    -0x160(%rbp),%r10
lea    -0x2a0(%rbp),%rax
lea    0xdc6(%rip),%rsi
lea    -0x2a4(%rbp),%rcx
lea    -0x2a8(%rbp),%r8
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1070 <sscanf@plt>
mov    %eax,-0x2b4(%rbp)
cmpl   $0x4,-0x2b4(%rbp)
jge    1280 <arp_show+0x110>
jmp    12af <arp_show+0x13f>
lea    -0x80(%rbp),%rdi
mov    -0x2a4(%rbp),%esi
mov    -0x2a8(%rbp),%edx
lea    -0xf0(%rbp),%rcx
lea    -0x160(%rbp),%r8
lea    -0x2a0(%rbp),%r9
call   1030 <arp_display@plt>
jmp    1203 <arp_show+0x93>
jmp    12b4 <arp_show+0x144>
mov    -0x2b0(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2d0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arp_show>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x298,%rsp
lea    0xe78(%rip),%rdi
lea    0xe7f(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1296 <arp_show+0x126>
mov    %rax,%rbx
lea    0x10(%rsp),%rdi
mov    $0xc8,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     127a <arp_show+0x10a>
lea    0xe4e(%rip),%rbp
lea    0x150(%rsp),%r14
mov    %r14,%rdi
mov    %rbp,%rsi
call   1040 <strcpy@plt>
lea    0xe0(%rsp),%r15
mov    %r15,%rdi
mov    %rbp,%rsi
call   1040 <strcpy@plt>
lea    0x10(%rsp),%rdi
mov    $0xc8,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     127a <arp_show+0x10a>
lea    0x10(%rsp),%r13
lea    0x230(%rsp),%rbp
lea    0x1c0(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r13,%rdi
lea    0xde8(%rip),%rsi
mov    %rbp,%rdx
lea    0xc(%rsp),%rcx
lea    0x8(%rsp),%r8
mov    %r12,%r9
push   %r15
push   %r14
call   1070 <sscanf@plt>
add    $0x10,%rsp
cmp    $0x4,%eax
jl     127a <arp_show+0x10a>
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
mov    %rbp,%rdi
mov    %r12,%rcx
mov    %r14,%r8
mov    %r15,%r9
call   1030 <arp_display@plt>
mov    %r13,%rdi
mov    $0xc8,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
jne    1220 <arp_show+0xb0>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x298,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd63(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%eax
jmp    1284 <arp_show+0x114>

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/net/arp\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"-\00"
@.str.3 = [32 x i8] c"%s 0x%x 0x%x %100s %100s %100s\0A\00"
define i32 @arp_show(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [100 x i8]
%5 = alloca [100 x i8]
%6 = alloca [100 x i8]
%7 = alloca [200 x i8]
%8 = alloca [100 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32
store i8* %0, i8** %3
%13 = 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* %13, i32** %11
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %17
15: ; preds = %1
%16 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %54
17: ; preds = %1
%18 = getelementptr inbounds [200 x i8], [200 x i8]* %7, i64 0, i64 0
%19 = load i32*, i32** %11
%20 = call i8* @fgets(i8* %18, i32 200, i32* %19)
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %51
22: ; preds = %17
%23 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%24 = call i32 @strcpy(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%26 = call i32 @strcpy(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %27
27: ; preds = %42, %22
%28 = getelementptr inbounds [200 x i8], [200 x i8]* %7, i64 0, i64 0
%29 = load i32*, i32** %11
%30 = call i8* @fgets(i8* %28, i32 200, i32* %29)
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %50
32: ; preds = %27
%33 = getelementptr inbounds [200 x i8], [200 x i8]* %7, i64 0, i64 0
%34 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%35 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%36 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%37 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%38 = call i32 @sscanf(i8* %33, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %34, i32* %9, i32* %10, i8* %35, i8* %36, i8* %37)
store i32 %38, i32* %12
%39 = load i32, i32* %12
%40 = icmp slt i32 %39, 4
br i1 %40, label %41, label %42
41: ; preds = %32
br label %50
42: ; preds = %32
%43 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%44 = load i32, i32* %9
%45 = load i32, i32* %10
%46 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%47 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%48 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%49 = call i32 @arp_display(i8* %43, i32 %44, i32 %45, i8* %46, i8* %47, i8* %48)
br label %27
50: ; preds = %41, %27
br label %51
51: ; preds = %50, %17
%52 = load i32*, i32** %11
%53 = call i32 @fclose(i32* %52)
store i32 0, i32* %2
br label %54
54: ; preds = %51, %15
%55 = load i32, i32* %2
ret i32 %55
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/net/arp\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"-\00"
@.str.3 = [32 x i8] c"%s 0x%x 0x%x %100s %100s %100s\0A\00"
define i32 @arp_show(i8* nocapture readnone %0) {
%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 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%12 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 0
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%14 = bitcast i32* %7 to i8*
%15 = bitcast i32* %8 to i8*
%16 = 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))
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %20
18: ; preds = %1
%19 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %39
20: ; preds = %1
%21 = call i8* @fgets(i8* %12, i32 200, i32* %16)
%22 = icmp eq i8* %21, null
br i1 %22, label %37, label %23
23: ; preds = %20
%24 = call i32 @strcpy(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 @strcpy(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%26 = call i8* @fgets(i8* %12, i32 200, i32* %16)
%27 = icmp eq i8* %26, null
br i1 %27, label %37, label %28
28: ; preds = %23, %31
%29 = call i32 @sscanf(i8* %12, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %9, i32* %7, i32* %8, i8* %10, i8* %11, i8* %13)
%30 = icmp slt i32 %29, 4
br i1 %30, label %37, label %31
31: ; preds = %28
%32 = load i32, i32* %7
%33 = load i32, i32* %8
%34 = call i32 @arp_display(i8* %9, i32 %32, i32 %33, i8* %10, i8* %11, i8* %13)
%35 = call i8* @fgets(i8* %12, i32 200, i32* %16)
%36 = icmp eq i8* %35, null
br i1 %36, label %37, label %28
37: ; preds = %31, %28, %23, %20
%38 = call i32 @fclose(i32* %16)
br label %39
39: ; preds = %37, %18
%40 = phi i32 [ -1, %18 ], [ 0, %37 ]
ret i32 %40
}