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

/* Variables and functions */
int O_EXCL;
int O_RDONLY;
int /*<<< orphan*/ SEEK_SET;
long atol(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int);
int /*<<< orphan*/ printf(char *);
int read(int, char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *strstr(char *, char *);
char *strtok_r(char *, char *, char **);
int tx_rx_stat_fd(char *eth_name, double *recv, double *send) {
  int nDevLen, fd, nBytes, i = 0;
  char *p, *p_dev, *ifconfig_value;
  long rx_tx[2];
  char buf[1024 * 12];
  char ath0[120];
  strcpy(ath0, eth_name);
  nDevLen = strlen(ath0);
  if (nDevLen < 1 || nDevLen > 120) {
    printf("dev length too long");
    return -1;
  }
  fd = open("/proc/net/dev", O_RDONLY | O_EXCL);
  if (-1 == fd) {
    printf("Failed to open /proc/net/dev");
    return -1;
  }
  memset(buf, 0, sizeof(buf));
  lseek(fd, 0, SEEK_SET);
  nBytes = read(fd, buf, sizeof(buf) - 1);
  if (-1 == nBytes) {
    printf("Failed to read /proc/net/dev");
    close(fd);
    return -1;
  }
  buf[nBytes] = '\0';
  p_dev = strstr(buf, ath0);
  if (NULL == p_dev) {
    printf("don't find dev");
    close(fd);
    return -1;
  }
  char *pointer;
  for (p = strtok_r(p_dev, " \t\r\n", &pointer); p;
       p = strtok_r(NULL, " \t\r\n", &pointer)) {
    i++;
    ifconfig_value = (char *)malloc(20);
    strcpy(ifconfig_value, p);
    if (i == 3) {
      rx_tx[0] = atol(ifconfig_value);
      *recv = (double)rx_tx[0];
    }
    if (i == 11) {
      rx_tx[1] = atol(ifconfig_value);
      *send = (double)rx_tx[1];
      free(ifconfig_value);
      break;
    }
    free(ifconfig_value);
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<tx_rx_stat_fd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30f0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x30(%rbp)
lea    -0x30e0(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
lea    -0x30e0(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x1,-0x24(%rbp)
jl     1221 <tx_rx_stat_fd+0x51>
cmpl   $0x78,-0x24(%rbp)
jle    1239 <tx_rx_stat_fd+0x69>
lea    0xdd8(%rip),%rdi
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1414 <tx_rx_stat_fd+0x244>
mov    0x2da8(%rip),%rax
mov    (%rax),%esi
mov    0x2d8f(%rip),%rax
or     (%rax),%esi
lea    0xdee(%rip),%rdi
call   10e0 <open@plt>
mov    %eax,-0x28(%rbp)
mov    $0xffffffff,%eax
cmp    -0x28(%rbp),%eax
jne    1280 <tx_rx_stat_fd+0xb0>
lea    0xda5(%rip),%rdi
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1414 <tx_rx_stat_fd+0x244>
lea    -0x3060(%rbp),%rdi
xor    %esi,%esi
mov    $0x3000,%edx
call   1080 <memset@plt>
mov    -0x28(%rbp),%edi
mov    0x2d33(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <lseek@plt>
mov    -0x28(%rbp),%edi
lea    -0x3060(%rbp),%rsi
mov    $0x2fff,%edx
call   10b0 <read@plt>
mov    %eax,-0x2c(%rbp)
mov    $0xffffffff,%eax
cmp    -0x2c(%rbp),%eax
jne    12eb <tx_rx_stat_fd+0x11b>
lea    0xd5f(%rip),%rdi
call   1060 <printf@plt>
mov    -0x28(%rbp),%edi
call   1090 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1414 <tx_rx_stat_fd+0x244>
movslq -0x2c(%rbp),%rax
movb   $0x0,-0x3060(%rbp,%rax,1)
lea    -0x3060(%rbp),%rdi
lea    -0x30e0(%rbp),%rsi
call   10f0 <strstr@plt>
mov    %rax,-0x40(%rbp)
xor    %eax,%eax
cmp    -0x40(%rbp),%rax
jne    133a <tx_rx_stat_fd+0x16a>
lea    0xd2d(%rip),%rdi
call   1060 <printf@plt>
mov    -0x28(%rbp),%edi
call   1090 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1414 <tx_rx_stat_fd+0x244>
mov    -0x40(%rbp),%rdi
lea    0xd18(%rip),%rsi
lea    -0x30e8(%rbp),%rdx
call   10a0 <strtok_r@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1405 <tx_rx_stat_fd+0x235>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    $0x14,%edi
call   10c0 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1040 <strcpy@plt>
cmpl   $0x3,-0x30(%rbp)
jne    13a9 <tx_rx_stat_fd+0x1d9>
mov    -0x48(%rbp),%rdi
call   10d0 <atol@plt>
mov    %rax,-0x60(%rbp)
cvtsi2sdq -0x60(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
cmpl   $0xb,-0x30(%rbp)
jne    13dc <tx_rx_stat_fd+0x20c>
mov    -0x48(%rbp),%rdi
call   10d0 <atol@plt>
mov    %rax,-0x58(%rbp)
cvtsi2sdq -0x58(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
jmp    1405 <tx_rx_stat_fd+0x235>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xc6d(%rip),%rsi
lea    -0x30e8(%rbp),%rdx
call   10a0 <strtok_r@plt>
mov    %rax,-0x38(%rbp)
jmp    1355 <tx_rx_stat_fd+0x185>
mov    -0x28(%rbp),%edi
call   1090 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30f0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tx_rx_stat_fd>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x30a8,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rsi
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
add    $0xffffff87,%eax
cmp    $0xffffff87,%eax
ja     1213 <tx_rx_stat_fd+0x43>
lea    0xdf2(%rip),%rdi
jmp    1371 <tx_rx_stat_fd+0x1a1>
mov    0x2dce(%rip),%rax
mov    0x2db7(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe14(%rip),%rdi
call   10e0 <open@plt>
cmp    $0xffffffff,%eax
je     136a <tx_rx_stat_fd+0x19a>
mov    %eax,%ebp
lea    0xa0(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x3000,%edx
call   1080 <memset@plt>
mov    0x2d76(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1070 <lseek@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x2fff,%edx
call   10b0 <read@plt>
cmp    $0xffffffff,%eax
je     1378 <tx_rx_stat_fd+0x1a8>
cltq
movb   $0x0,0xa0(%rsp,%rax,1)
lea    0xa0(%rsp),%rdi
lea    0x20(%rsp),%rsi
call   10f0 <strstr@plt>
test   %rax,%rax
je     1381 <tx_rx_stat_fd+0x1b1>
mov    %r15,0x10(%rsp)
mov    %r14,0x8(%rsp)
lea    0xdaa(%rip),%rsi
lea    0x18(%rsp),%rdx
mov    %rax,%rdi
call   10a0 <strtok_r@plt>
test   %rax,%rax
je     135f <tx_rx_stat_fd+0x18f>
mov    %rax,%r14
xor    %r15d,%r15d
lea    0xd87(%rip),%r12
lea    0x18(%rsp),%r13
jmp    131a <tx_rx_stat_fd+0x14a>
nopl   (%rax)
mov    %rbx,%rdi
call   10d0 <atol@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mov    0x10(%rsp),%rax
movsd  %xmm0,(%rax)
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %edi,%edi
mov    %r12,%rsi
mov    %r13,%rdx
call   10a0 <strtok_r@plt>
mov    %rax,%r14
add    $0x1,%r15d
test   %rax,%rax
je     135f <tx_rx_stat_fd+0x18f>
mov    $0x14,%edi
call   10c0 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
cmp    $0x2,%r15d
je     12e0 <tx_rx_stat_fd+0x110>
cmp    $0xa,%r15d
jne    12f9 <tx_rx_stat_fd+0x129>
mov    %rbx,%rdi
call   10d0 <atol@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mov    0x8(%rsp),%rax
movsd  %xmm0,(%rax)
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%edi
call   1090 <close@plt>
xor    %eax,%eax
jmp    1399 <tx_rx_stat_fd+0x1c9>
lea    0xca3(%rip),%rdi
call   1060 <printf@plt>
jmp    1394 <tx_rx_stat_fd+0x1c4>
lea    0xcb2(%rip),%rdi
jmp    1388 <tx_rx_stat_fd+0x1b8>
lea    0xcc6(%rip),%rdi
call   1060 <printf@plt>
mov    %ebp,%edi
call   1090 <close@plt>
mov    $0xffffffff,%eax
add    $0x30a8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"dev length too long\00"
@.str.1 = [14 x i8] c"/proc/net/dev\00"
@O_RDONLY = global i32 0
@O_EXCL = global i32 0
@.str.2 = [29 x i8] c"Failed to open /proc/net/dev\00"
@SEEK_SET = global i32 0
@.str.3 = [29 x i8] c"Failed to read /proc/net/dev\00"
@.str.4 = [15 x i8] c"don't find dev\00"
@.str.5 = [5 x i8] c" \09\0D\0A\00"
define i32 @tx_rx_stat_fd(i8* %0, double* %1, double* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca double*
%7 = alloca double*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca [2 x i64]
%16 = alloca [12288 x i8]
%17 = alloca [120 x i8]
%18 = alloca i8*
store i8* %0, i8** %5
store double* %1, double** %6
store double* %2, double** %7
store i32 0, i32* %11
%19 = getelementptr inbounds [120 x i8], [120 x i8]* %17, i64 0, i64 0
%20 = load i8*, i8** %5
%21 = call i32 @strcpy(i8* %19, i8* %20)
%22 = getelementptr inbounds [120 x i8], [120 x i8]* %17, i64 0, i64 0
%23 = call i32 @strlen(i8* %22)
store i32 %23, i32* %8
%24 = load i32, i32* %8
%25 = icmp slt i32 %24, 1
br i1 %25, label %29, label %26
26: ; preds = %3
%27 = load i32, i32* %8
%28 = icmp sgt i32 %27, 120
br i1 %28, label %29, label %31
29: ; preds = %26, %3
%30 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %113
31: ; preds = %26
%32 = load i32, i32* @O_RDONLY
%33 = load i32, i32* @O_EXCL
%34 = or i32 %32, %33
%35 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %34)
store i32 %35, i32* %9
%36 = load i32, i32* %9
%37 = icmp eq i32 -1, %36
br i1 %37, label %38, label %40
38: ; preds = %31
%39 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %4
br label %113
40: ; preds = %31
%41 = getelementptr inbounds [12288 x i8], [12288 x i8]* %16, i64 0, i64 0
%42 = call i32 @memset(i8* %41, i32 0, i32 12288)
%43 = load i32, i32* %9
%44 = load i32, i32* @SEEK_SET
%45 = call i32 @lseek(i32 %43, i32 0, i32 %44)
%46 = load i32, i32* %9
%47 = getelementptr inbounds [12288 x i8], [12288 x i8]* %16, i64 0, i64 0
%48 = call i32 @read(i32 %46, i8* %47, i32 12287)
store i32 %48, i32* %10
%49 = load i32, i32* %10
%50 = icmp eq i32 -1, %49
br i1 %50, label %51, label %55
51: ; preds = %40
%52 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%53 = load i32, i32* %9
%54 = call i32 @close(i32 %53)
store i32 -1, i32* %4
br label %113
55: ; preds = %40
%56 = load i32, i32* %10
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [12288 x i8], [12288 x i8]* %16, i64 0, i64 %57
store i8 0, i8* %58
%59 = getelementptr inbounds [12288 x i8], [12288 x i8]* %16, i64 0, i64 0
%60 = getelementptr inbounds [120 x i8], [120 x i8]* %17, i64 0, i64 0
%61 = call i8* @strstr(i8* %59, i8* %60)
store i8* %61, i8** %13
%62 = load i8*, i8** %13
%63 = icmp eq i8* null, %62
br i1 %63, label %64, label %68
64: ; preds = %55
%65 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%66 = load i32, i32* %9
%67 = call i32 @close(i32 %66)
store i32 -1, i32* %4
br label %113
68: ; preds = %55
%69 = load i8*, i8** %13
%70 = call i8* @strtok_r(i8* %69, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8** %18)
store i8* %70, i8** %12
br label %71
71: ; preds = %108, %68
%72 = load i8*, i8** %12
%73 = icmp ne i8* %72, null
br i1 %73, label %74, label %110
74: ; preds = %71
%75 = load i32, i32* %11
%76 = add nsw i32 %75, 1
store i32 %76, i32* %11
%77 = call i64 @malloc(i32 20)
%78 = inttoptr i64 %77 to i8*
store i8* %78, i8** %14
%79 = load i8*, i8** %14
%80 = load i8*, i8** %12
%81 = call i32 @strcpy(i8* %79, i8* %80)
%82 = load i32, i32* %11
%83 = icmp eq i32 %82, 3
br i1 %83, label %84, label %92
84: ; preds = %74
%85 = load i8*, i8** %14
%86 = call i64 @atol(i8* %85)
%87 = getelementptr inbounds [2 x i64], [2 x i64]* %15, i64 0, i64 0
store i64 %86, i64* %87
%88 = getelementptr inbounds [2 x i64], [2 x i64]* %15, i64 0, i64 0
%89 = load i64, i64* %88
%90 = sitofp i64 %89 to double
%91 = load double*, double** %6
store double %90, double* %91
br label %92
92: ; preds = %84, %74
%93 = load i32, i32* %11
%94 = icmp eq i32 %93, 11
br i1 %94, label %95, label %105
95: ; preds = %92
%96 = load i8*, i8** %14
%97 = call i64 @atol(i8* %96)
%98 = getelementptr inbounds [2 x i64], [2 x i64]* %15, i64 0, i64 1
store i64 %97, i64* %98
%99 = getelementptr inbounds [2 x i64], [2 x i64]* %15, i64 0, i64 1
%100 = load i64, i64* %99
%101 = sitofp i64 %100 to double
%102 = load double*, double** %7
store double %101, double* %102
%103 = load i8*, i8** %14
%104 = call i32 @free(i8* %103)
br label %110
105: ; preds = %92
%106 = load i8*, i8** %14
%107 = call i32 @free(i8* %106)
br label %108
108: ; preds = %105
%109 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8** %18)
store i8* %109, i8** %12
br label %71
110: ; preds = %95, %71
%111 = load i32, i32* %9
%112 = call i32 @close(i32 %111)
store i32 0, i32* %4
br label %113
113: ; preds = %110, %64, %51, %38, %29
%114 = load i32, i32* %4
ret i32 %114
}

LLVM IR (-O2):
@.str = [20 x i8] c"dev length too long\00"
@.str.1 = [14 x i8] c"/proc/net/dev\00"
@O_RDONLY = global i32 0
@O_EXCL = global i32 0
@.str.2 = [29 x i8] c"Failed to open /proc/net/dev\00"
@SEEK_SET = global i32 0
@.str.3 = [29 x i8] c"Failed to read /proc/net/dev\00"
@.str.4 = [15 x i8] c"don't find dev\00"
@.str.5 = [5 x i8] c" \09\0D\0A\00"
define i32 @tx_rx_stat_fd(i8* %0, double* nocapture writeonly %1, double* nocapture writeonly %2) {
%4 = alloca [12288 x i8]
%5 = alloca [120 x i8]
%6 = alloca i8*
%7 = getelementptr inbounds [12288 x i8], [12288 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [120 x i8], [120 x i8]* %5, i64 0, i64 0
%9 = call i32 @strcpy(i8* %8, i8* %0)
%10 = call i32 @strlen(i8* %8)
%11 = add i32 %10, -121
%12 = icmp ult i32 %11, -120
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %65
15: ; preds = %3
%16 = load i32, i32* @O_RDONLY
%17 = load i32, i32* @O_EXCL
%18 = or i32 %17, %16
%19 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %23
21: ; preds = %15
%22 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %65
23: ; preds = %15
%24 = call i32 @memset(i8* %7, i32 0, i32 12288)
%25 = load i32, i32* @SEEK_SET
%26 = call i32 @lseek(i32 %19, i32 0, i32 %25)
%27 = call i32 @read(i32 %19, i8* %7, i32 12287)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %32
29: ; preds = %23
%30 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%31 = call i32 @close(i32 %19)
br label %65
32: ; preds = %23
%33 = sext i32 %27 to i64
%34 = getelementptr inbounds [12288 x i8], [12288 x i8]* %4, i64 0, i64 %33
store i8 0, i8* %34
%35 = call i8* @strstr(i8* %7, i8* %8)
%36 = icmp eq i8* %35, null
br i1 %36, label %37, label %40
37: ; preds = %32
%38 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%39 = call i32 @close(i32 %19)
br label %65
40: ; preds = %32
%41 = bitcast i8** %6 to i8*
%42 = call i8* @strtok_r(i8* %35, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8** %6)
%43 = icmp eq i8* %42, null
br i1 %43, label %63, label %44
44: ; preds = %40, %59
%45 = phi i32 [ %47, %59 ], [ 0, %40 ]
%46 = phi i8* [ %61, %59 ], [ %42, %40 ]
%47 = add nuw nsw i32 %45, 1
%48 = call i64 @malloc(i32 20)
%49 = inttoptr i64 %48 to i8*
%50 = call i32 @strcpy(i8* %49, i8* %46)
switch i32 %45, label %59 [
i32 2, label %51
i32 10, label %54
]
51: ; preds = %44
%52 = call i64 @atol(i8* %49)
%53 = sitofp i64 %52 to double
store double %53, double* %1
br label %59
54: ; preds = %44
%55 = inttoptr i64 %48 to i8*
%56 = call i64 @atol(i8* %55)
%57 = sitofp i64 %56 to double
store double %57, double* %2
%58 = call i32 @free(i8* %55)
br label %63
59: ; preds = %51, %44
%60 = call i32 @free(i8* %49)
%61 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8** %6)
%62 = icmp eq i8* %61, null
br i1 %62, label %63, label %44
63: ; preds = %59, %40, %54
%64 = call i32 @close(i32 %19)
br label %65
65: ; preds = %63, %37, %29, %21, %13
%66 = phi i32 [ -1, %13 ], [ -1, %21 ], [ -1, %29 ], [ -1, %37 ], [ 0, %63 ]
ret i32 %66
}