#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 */
struct stat {
  int st_mode;
};

/* Variables and functions */
scalar_t__ ENOENT;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int /*<<< orphan*/ S_ISREG(int);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ lstat(char *, struct stat *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strstr(char *, char *);
char find_intf_information(char *filePath, char *net_intf) {
  if (strstr(net_intf, "upload")) {
    strcat(filePath, "/statistics/tx_bytes");
  } else if (strstr(net_intf, "download")) {
    strcat(filePath, "/statistics/rx_bytes");
  } else {
    printf("Error: please enter a valid input; upload or download?\n");
    return -1;
  }
  struct stat link_attributes;
  if ((lstat(filePath, &link_attributes)) != 0) {
    if (errno == ENOENT) {
      fprintf(stderr, "Error_lstat:No information about this interface.\n");
      return (-1);
    } else {
      perror("Error_lstat: ");
      return (-1);
    }
  }
  if (!S_ISREG(link_attributes.st_mode)) {
    fprintf(stderr, "Error_S_ISREG: Information could not be interpreted.\n");
    return (-1);
  }
  if (!((link_attributes.st_mode & S_IRUSR) &&
        (link_attributes.st_mode & S_IRGRP) &&
        (link_attributes.st_mode & S_IROTH))) {
    printf("Warning:You may not have the permission to access to this "
           "information.\n");
    return (-1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<find_intf_information>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe75(%rip),%rsi
call   1090 <strstr@plt>
cmp    $0x0,%rax
je     11af <find_intf_information+0x3f>
mov    -0x10(%rbp),%rdi
lea    0xe62(%rip),%rsi
call   1080 <strcat@plt>
jmp    11f8 <find_intf_information+0x88>
mov    -0x18(%rbp),%rdi
lea    0xe62(%rip),%rsi
call   1090 <strstr@plt>
cmp    $0x0,%rax
je     11de <find_intf_information+0x6e>
mov    -0x10(%rbp),%rdi
lea    0xe51(%rip),%rsi
call   1080 <strcat@plt>
jmp    11f3 <find_intf_information+0x83>
lea    0xe55(%rip),%rdi
call   1030 <printf@plt>
movb   $0xff,-0x1(%rbp)
jmp    12e3 <find_intf_information+0x173>
jmp    11f8 <find_intf_information+0x88>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <lstat@plt>
cmp    $0x0,%rax
je     125c <find_intf_information+0xec>
mov    0x2dc2(%rip),%rax
mov    (%rax),%rax
mov    0x2d90(%rip),%rcx
cmp    (%rcx),%rax
jne    1247 <find_intf_information+0xd7>
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
lea    0xe39(%rip),%rsi
call   1050 <fprintf@plt>
movb   $0xff,-0x1(%rbp)
jmp    12e3 <find_intf_information+0x173>
lea    0xe56(%rip),%rdi
call   1070 <perror@plt>
movb   $0xff,-0x1(%rbp)
jmp    12e3 <find_intf_information+0x173>
mov    -0x20(%rbp),%edi
call   1060 <S_ISREG@plt>
cmp    $0x0,%eax
jne    128b <find_intf_information+0x11b>
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
lea    0xe35(%rip),%rsi
call   1050 <fprintf@plt>
movb   $0xff,-0x1(%rbp)
jmp    12e3 <find_intf_information+0x173>
mov    -0x20(%rbp),%eax
mov    0x2d2b(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     12ca <find_intf_information+0x15a>
mov    -0x20(%rbp),%eax
mov    0x2d26(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     12ca <find_intf_information+0x15a>
mov    -0x20(%rbp),%eax
mov    0x2d09(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    12df <find_intf_information+0x16f>
lea    0xe17(%rip),%rdi
call   1030 <printf@plt>
movb   $0xff,-0x1(%rbp)
jmp    12e3 <find_intf_information+0x173>
movb   $0x0,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_intf_information>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xe7f(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strstr@plt>
test   %rax,%rax
je     1197 <find_intf_information+0x27>
lea    0xe72(%rip),%rsi
jmp    11b6 <find_intf_information+0x46>
lea    0xe7e(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strstr@plt>
test   %rax,%rax
je     1237 <find_intf_information+0xc7>
lea    0xe6f(%rip),%rsi
mov    %r14,%rdi
call   1080 <strcat@plt>
mov    %rsp,%rsi
mov    %r14,%rdi
call   1040 <lstat@plt>
test   %rax,%rax
je     11fb <find_intf_information+0x8b>
mov    0x2e03(%rip),%rax
mov    (%rax),%rax
mov    0x2dd1(%rip),%rcx
cmp    (%rcx),%rax
jne    125c <find_intf_information+0xec>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
lea    0xe46(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1268 <find_intf_information+0xf8>
mov    (%rsp),%ebx
mov    %ebx,%edi
call   1060 <S_ISREG@plt>
test   %eax,%eax
je     1245 <find_intf_information+0xd5>
mov    0x2db0(%rip),%rax
test   %ebx,(%rax)
je     122e <find_intf_information+0xbe>
mov    0x2db5(%rip),%rax
test   %ebx,(%rax)
je     122e <find_intf_information+0xbe>
mov    0x2da2(%rip),%rax
test   %ebx,(%rax)
je     122e <find_intf_information+0xbe>
xor    %eax,%eax
jmp    126a <find_intf_information+0xfa>
lea    0xeb2(%rip),%rdi
jmp    123e <find_intf_information+0xce>
lea    0xe72(%rip),%rdi
call   1030 <puts@plt>
jmp    1268 <find_intf_information+0xf8>
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
lea    0xe25(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1268 <find_intf_information+0xf8>
lea    0xe09(%rip),%rdi
call   1070 <perror@plt>
mov    $0xff,%al
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [7 x i8] c"upload\00"
@.str.1 = [21 x i8] c"/statistics/tx_bytes\00"
@.str.2 = [9 x i8] c"download\00"
@.str.3 = [21 x i8] c"/statistics/rx_bytes\00"
@.str.4 = [56 x i8] c"Error: please enter a valid input; upload or download?\0A\00"
@errno = global i64 0
@ENOENT = global i64 0
@stderr = global i32 0
@.str.5 = [50 x i8] c"Error_lstat:No information about this interface.\0A\00"
@.str.6 = [14 x i8] c"Error_lstat: \00"
@.str.7 = [54 x i8] c"Error_S_ISREG: Information could not be interpreted.\0A\00"
@S_IRUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str.8 = [72 x i8] c"Warning:You may not have the permission to access to this information.\0A\00"
define signext i8 @find_intf_information(i8* %0, i8* %1) {
%3 = alloca i8
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca %struct.stat
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
%8 = call i64 @strstr(i8* %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = call i32 @strcat(i8* %11, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %23
13: ; preds = %2
%14 = load i8*, i8** %5
%15 = call i64 @strstr(i8* %14, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = load i8*, i8** %4
%19 = call i32 @strcat(i8* %18, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
br label %22
20: ; preds = %13
%21 = call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.4, i64 0, i64 0))
store i8 -1, i8* %3
br label %65
22: ; preds = %17
br label %23
23: ; preds = %22, %10
%24 = load i8*, i8** %4
%25 = call i64 @lstat(i8* %24, %struct.stat* %6)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %36
27: ; preds = %23
%28 = load i64, i64* @errno
%29 = load i64, i64* @ENOENT
%30 = icmp eq i64 %28, %29
br i1 %30, label %31, label %34
31: ; preds = %27
%32 = load i32, i32* @stderr
%33 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.5, i64 0, i64 0))
store i8 -1, i8* %3
br label %65
34: ; preds = %27
%35 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
store i8 -1, i8* %3
br label %65
36: ; preds = %23
%37 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%38 = load i32, i32* %37
%39 = call i32 @S_ISREG(i32 %38)
%40 = icmp ne i32 %39, 0
br i1 %40, label %44, label %41
41: ; preds = %36
%42 = load i32, i32* @stderr
%43 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.7, i64 0, i64 0))
store i8 -1, i8* %3
br label %65
44: ; preds = %36
%45 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%46 = load i32, i32* %45
%47 = load i32, i32* @S_IRUSR
%48 = and i32 %46, %47
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %62
50: ; preds = %44
%51 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%52 = load i32, i32* %51
%53 = load i32, i32* @S_IRGRP
%54 = and i32 %52, %53
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %62
56: ; preds = %50
%57 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%58 = load i32, i32* %57
%59 = load i32, i32* @S_IROTH
%60 = and i32 %58, %59
%61 = icmp ne i32 %60, 0
br i1 %61, label %64, label %62
62: ; preds = %56, %50, %44
%63 = call i32 @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.8, i64 0, i64 0))
store i8 -1, i8* %3
br label %65
64: ; preds = %56
store i8 0, i8* %3
br label %65
65: ; preds = %64, %62, %41, %34, %31, %20
%66 = load i8, i8* %3
ret i8 %66
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [7 x i8] c"upload\00"
@.str.1 = [21 x i8] c"/statistics/tx_bytes\00"
@.str.2 = [9 x i8] c"download\00"
@.str.3 = [21 x i8] c"/statistics/rx_bytes\00"
@errno = global i64 0
@ENOENT = global i64 0
@stderr = global i32 0
@.str.5 = [50 x i8] c"Error_lstat:No information about this interface.\0A\00"
@.str.6 = [14 x i8] c"Error_lstat: \00"
@.str.7 = [54 x i8] c"Error_S_ISREG: Information could not be interpreted.\0A\00"
@S_IRUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@str = [55 x i8] c"Error: please enter a valid input; upload or download?\00"
@str.9 = [71 x i8] c"Warning:You may not have the permission to access to this information.\00"
define signext i8 @find_intf_information(i8* %0, i8* %1) {
%3 = alloca %struct.stat
%4 = tail call i64 @strstr(i8* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %11
6: ; preds = %2
%7 = tail call i64 @strstr(i8* %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @str, i64 0, i64 0))
br label %50
11: ; preds = %6, %2
%12 = phi i8* [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), %2 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), %6 ]
%13 = tail call i32 @strcat(i8* %0, i8* %12)
%14 = bitcast %struct.stat* %3 to i8*
%15 = call i64 @lstat(i8* %0, %struct.stat* %3)
%16 = icmp eq i64 %15, 0
br i1 %16, label %26, label %17
17: ; preds = %11
%18 = load i64, i64* @errno
%19 = load i64, i64* @ENOENT
%20 = icmp eq i64 %18, %19
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = load i32, i32* @stderr
%23 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.5, i64 0, i64 0))
br label %48
24: ; preds = %17
%25 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
br label %48
26: ; preds = %11
%27 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%28 = load i32, i32* %27
%29 = tail call i32 @S_ISREG(i32 %28)
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %26
%32 = load i32, i32* @stderr
%33 = tail call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.7, i64 0, i64 0))
br label %48
34: ; preds = %26
%35 = load i32, i32* @S_IRUSR
%36 = and i32 %35, %28
%37 = icmp eq i32 %36, 0
br i1 %37, label %46, label %38
38: ; preds = %34
%39 = load i32, i32* @S_IRGRP
%40 = and i32 %39, %28
%41 = icmp eq i32 %40, 0
br i1 %41, label %46, label %42
42: ; preds = %38
%43 = load i32, i32* @S_IROTH
%44 = and i32 %43, %28
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %42, %38, %34
%47 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([71 x i8], [71 x i8]* @str.9, i64 0, i64 0))
br label %48
48: ; preds = %42, %46, %31, %24, %21
%49 = phi i8 [ -1, %21 ], [ -1, %24 ], [ -1, %46 ], [ -1, %31 ], [ 0, %42 ]
br label %50
50: ; preds = %48, %9
%51 = phi i8 [ %49, %48 ], [ -1, %9 ]
ret i8 %51
}