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

/* Variables and functions */
long atol(char *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *strtok(char *, char *);
int tx_rx_stat(char *eth_name, double *recv, double *send) {
  int nDevLen, fd, nBytes, i = 0;
  char *p, *pDev, *ifconfig_value;
  long rx_tx[2];
  char buf[1024 * 1024];
  char ath0[120];
  char cmd[250];
  FILE *pipe;
  char *rets;
  int ret = 0;
  memset(ath0, 0, sizeof(ath0));
  sprintf(ath0, "%s:", eth_name);
  nDevLen = strlen(ath0);
  if (nDevLen < 1 || nDevLen > 120) {
    printf("dev length too long\n");
    return -1;
  }
  memset(buf, 0, sizeof(buf));
  sprintf(cmd, "cat /proc/net/dev | grep %s", ath0);
  pipe = popen(cmd, "r");
  if (!pipe) {
    printf("%s fail!\n", cmd);
    return -1;
  }
  rets = fgets(buf, sizeof(buf) - 1, pipe);
  if (rets != NULL) {
    printf("buf: \"%s\"", buf);
    for (p = strtok(buf, " \t\r\n"); p; p = strtok(NULL, " \t\r\n")) {
      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);
    }
  } else {
    pclose(pipe);
    printf("Link is down! %s not exist!\n", ath0);
    return -1;
  }
  pclose(pipe);
  return 0;
}


x86 assembly (clang, -O0):
<tx_rx_stat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100200,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x1001f4(%rbp)
lea    -0x1000e0(%rbp),%rdi
xor    %esi,%esi
mov    $0x78,%edx
call   1080 <memset@plt>
lea    -0x1000e0(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xdf3(%rip),%rsi
call   10e0 <sprintf@plt>
lea    -0x1000e0(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x1,-0x24(%rbp)
jl     1235 <tx_rx_stat+0x75>
cmpl   $0x78,-0x24(%rbp)
jle    124f <tx_rx_stat+0x8f>
lea    0xdc8(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    140c <tx_rx_stat+0x24c>
lea    -0x100060(%rbp),%rdi
xor    %esi,%esi
mov    $0x100000,%edx
call   1080 <memset@plt>
lea    -0x1001e0(%rbp),%rdi
lea    -0x1000e0(%rbp),%rdx
lea    0xda2(%rip),%rsi
call   10e0 <sprintf@plt>
lea    -0x1001e0(%rbp),%rdi
lea    0xdab(%rip),%rsi
call   10c0 <popen@plt>
mov    %rax,-0x1001e8(%rbp)
cmpq   $0x0,-0x1001e8(%rbp)
jne    12c5 <tx_rx_stat+0x105>
lea    -0x1001e0(%rbp),%rsi
lea    0xd85(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    140c <tx_rx_stat+0x24c>
lea    -0x100060(%rbp),%rdi
mov    -0x1001e8(%rbp),%rdx
mov    $0xfffff,%esi
call   1090 <fgets@plt>
mov    %rax,-0x1001f0(%rbp)
cmpq   $0x0,-0x1001f0(%rbp)
je     13cc <tx_rx_stat+0x20c>
lea    -0x100060(%rbp),%rsi
lea    0xd41(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x100060(%rbp),%rdi
lea    0xd36(%rip),%rsi
call   10d0 <strtok@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     13c7 <tx_rx_stat+0x207>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    $0x14,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1040 <strcpy@plt>
cmpl   $0x3,-0x30(%rbp)
jne    1372 <tx_rx_stat+0x1b2>
mov    -0x48(%rbp),%rdi
call   10b0 <atol@plt>
mov    %rax,-0x60(%rbp)
cvtsi2sdq -0x60(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
cmpl   $0xb,-0x30(%rbp)
jne    13a5 <tx_rx_stat+0x1e5>
mov    -0x48(%rbp),%rdi
call   10b0 <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    13c7 <tx_rx_stat+0x207>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xc92(%rip),%rsi
call   10d0 <strtok@plt>
mov    %rax,-0x38(%rbp)
jmp    131e <tx_rx_stat+0x15e>
jmp    13f9 <tx_rx_stat+0x239>
mov    -0x1001e8(%rbp),%rdi
call   1070 <pclose@plt>
lea    -0x1000e0(%rbp),%rsi
lea    0xc6a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    140c <tx_rx_stat+0x24c>
mov    -0x1001e8(%rbp),%rdi
call   1070 <pclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x100200,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tx_rx_stat>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x100198,%rsp
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%rbx
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x78,%edx
call   1090 <memset@plt>
lea    0xdfb(%rip),%rsi
mov    %rbp,%rdi
mov    %rbx,%rdx
call   10f0 <sprintf@plt>
mov    %rbp,%rdi
call   1060 <strlen@plt>
add    $0xffffff87,%eax
cmp    $0xffffff87,%eax
ja     1231 <tx_rx_stat+0x61>
lea    0xe31(%rip),%rdi
call   1050 <puts@plt>
jmp    1391 <tx_rx_stat+0x1c1>
lea    0x190(%rsp),%rdi
xor    %esi,%esi
mov    $0x100000,%edx
call   1090 <memset@plt>
lea    0xdb8(%rip),%rsi
lea    0x90(%rsp),%rbx
lea    0x10(%rsp),%rdx
mov    %rbx,%rdi
call   10f0 <sprintf@plt>
lea    0xdb8(%rip),%rsi
mov    %rbx,%rdi
call   10d0 <popen@plt>
test   %rax,%rax
je     1365 <tx_rx_stat+0x195>
mov    %rax,%r15
lea    0x190(%rsp),%rdi
mov    $0xfffff,%esi
mov    %rax,%rdx
call   10a0 <fgets@plt>
test   %rax,%rax
je     1376 <tx_rx_stat+0x1a6>
mov    %r14,0x8(%rsp)
lea    0xd86(%rip),%rdi
xor    %r14d,%r14d
lea    0x190(%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xd74(%rip),%rsi
mov    %rbx,%rdi
call   10e0 <strtok@plt>
test   %rax,%rax
je     1359 <tx_rx_stat+0x189>
mov    %rax,%rbp
lea    0xd59(%rip),%r13
jmp    1314 <tx_rx_stat+0x144>
nop
mov    %rbx,%rdi
call   10c0 <atol@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  %xmm0,(%r12)
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %edi,%edi
mov    %r13,%rsi
call   10e0 <strtok@plt>
mov    %rax,%rbp
add    $0x1,%r14d
test   %rax,%rax
je     1359 <tx_rx_stat+0x189>
mov    $0x14,%edi
call   10b0 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %rbp,%rsi
call   1040 <strcpy@plt>
cmp    $0x2,%r14d
je     12e0 <tx_rx_stat+0x110>
cmp    $0xa,%r14d
jne    12f6 <tx_rx_stat+0x126>
mov    %rbx,%rdi
call   10c0 <atol@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mov    0x8(%rsp),%rax
movsd  %xmm0,(%rax)
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1080 <pclose@plt>
xor    %eax,%eax
jmp    1396 <tx_rx_stat+0x1c6>
lea    0xcb6(%rip),%rdi
lea    0x90(%rsp),%rsi
jmp    138a <tx_rx_stat+0x1ba>
mov    %r15,%rdi
call   1080 <pclose@plt>
lea    0xcb6(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xffffffff,%eax
add    $0x100198,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s:\00"
@.str.1 = [21 x i8] c"dev length too long\0A\00"
@.str.2 = [28 x i8] c"cat /proc/net/dev | grep %s\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [10 x i8] c"%s fail!\0A\00"
@.str.5 = [10 x i8] c"buf: \22%s\22\00"
@.str.6 = [5 x i8] c" \09\0D\0A\00"
@.str.7 = [29 x i8] c"Link is down! %s not exist!\0A\00"
define i32 @tx_rx_stat(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 [1048576 x i8]
%17 = alloca [120 x i8]
%18 = alloca [250 x i8]
%19 = alloca i32*
%20 = alloca i8*
%21 = alloca i32
store i8* %0, i8** %5
store double* %1, double** %6
store double* %2, double** %7
store i32 0, i32* %11
store i32 0, i32* %21
%22 = getelementptr inbounds [120 x i8], [120 x i8]* %17, i64 0, i64 0
%23 = call i32 @memset(i8* %22, i32 0, i32 120)
%24 = getelementptr inbounds [120 x i8], [120 x i8]* %17, i64 0, i64 0
%25 = load i8*, i8** %5
%26 = call i32 @sprintf(i8* %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %25)
%27 = getelementptr inbounds [120 x i8], [120 x i8]* %17, i64 0, i64 0
%28 = call i32 @strlen(i8* %27)
store i32 %28, i32* %8
%29 = load i32, i32* %8
%30 = icmp slt i32 %29, 1
br i1 %30, label %34, label %31
31: ; preds = %3
%32 = load i32, i32* %8
%33 = icmp sgt i32 %32, 120
br i1 %33, label %34, label %36
34: ; preds = %31, %3
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %4
br label %108
36: ; preds = %31
%37 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %16, i64 0, i64 0
%38 = call i32 @memset(i8* %37, i32 0, i32 1048576)
%39 = getelementptr inbounds [250 x i8], [250 x i8]* %18, i64 0, i64 0
%40 = getelementptr inbounds [120 x i8], [120 x i8]* %17, i64 0, i64 0
%41 = call i32 @sprintf(i8* %39, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %40)
%42 = getelementptr inbounds [250 x i8], [250 x i8]* %18, i64 0, i64 0
%43 = call i32* @popen(i8* %42, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %43, i32** %19
%44 = load i32*, i32** %19
%45 = icmp ne i32* %44, null
br i1 %45, label %49, label %46
46: ; preds = %36
%47 = getelementptr inbounds [250 x i8], [250 x i8]* %18, i64 0, i64 0
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %47)
store i32 -1, i32* %4
br label %108
49: ; preds = %36
%50 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %16, i64 0, i64 0
%51 = load i32*, i32** %19
%52 = call i8* @fgets(i8* %50, i32 1048575, i32* %51)
store i8* %52, i8** %20
%53 = load i8*, i8** %20
%54 = icmp ne i8* %53, null
br i1 %54, label %55, label %100
55: ; preds = %49
%56 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %16, i64 0, i64 0
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i8* %56)
%58 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %16, i64 0, i64 0
%59 = call i8* @strtok(i8* %58, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
store i8* %59, i8** %12
br label %60
60: ; preds = %97, %55
%61 = load i8*, i8** %12
%62 = icmp ne i8* %61, null
br i1 %62, label %63, label %99
63: ; preds = %60
%64 = load i32, i32* %11
%65 = add nsw i32 %64, 1
store i32 %65, i32* %11
%66 = call i64 @malloc(i32 20)
%67 = inttoptr i64 %66 to i8*
store i8* %67, i8** %14
%68 = load i8*, i8** %14
%69 = load i8*, i8** %12
%70 = call i32 @strcpy(i8* %68, i8* %69)
%71 = load i32, i32* %11
%72 = icmp eq i32 %71, 3
br i1 %72, label %73, label %81
73: ; preds = %63
%74 = load i8*, i8** %14
%75 = call i64 @atol(i8* %74)
%76 = getelementptr inbounds [2 x i64], [2 x i64]* %15, i64 0, i64 0
store i64 %75, i64* %76
%77 = getelementptr inbounds [2 x i64], [2 x i64]* %15, i64 0, i64 0
%78 = load i64, i64* %77
%79 = sitofp i64 %78 to double
%80 = load double*, double** %6
store double %79, double* %80
br label %81
81: ; preds = %73, %63
%82 = load i32, i32* %11
%83 = icmp eq i32 %82, 11
br i1 %83, label %84, label %94
84: ; preds = %81
%85 = load i8*, i8** %14
%86 = call i64 @atol(i8* %85)
%87 = getelementptr inbounds [2 x i64], [2 x i64]* %15, i64 0, i64 1
store i64 %86, i64* %87
%88 = getelementptr inbounds [2 x i64], [2 x i64]* %15, i64 0, i64 1
%89 = load i64, i64* %88
%90 = sitofp i64 %89 to double
%91 = load double*, double** %7
store double %90, double* %91
%92 = load i8*, i8** %14
%93 = call i32 @free(i8* %92)
br label %99
94: ; preds = %81
%95 = load i8*, i8** %14
%96 = call i32 @free(i8* %95)
br label %97
97: ; preds = %94
%98 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
store i8* %98, i8** %12
br label %60
99: ; preds = %84, %60
br label %105
100: ; preds = %49
%101 = load i32*, i32** %19
%102 = call i32 @pclose(i32* %101)
%103 = getelementptr inbounds [120 x i8], [120 x i8]* %17, i64 0, i64 0
%104 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0), i8* %103)
store i32 -1, i32* %4
br label %108
105: ; preds = %99
%106 = load i32*, i32** %19
%107 = call i32 @pclose(i32* %106)
store i32 0, i32* %4
br label %108
108: ; preds = %105, %100, %46, %34
%109 = load i32, i32* %4
ret i32 %109
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s:\00"
@.str.2 = [28 x i8] c"cat /proc/net/dev | grep %s\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [10 x i8] c"%s fail!\0A\00"
@.str.5 = [10 x i8] c"buf: \22%s\22\00"
@.str.6 = [5 x i8] c" \09\0D\0A\00"
@.str.7 = [29 x i8] c"Link is down! %s not exist!\0A\00"
@str = [20 x i8] c"dev length too long\00"
define i32 @tx_rx_stat(i8* %0, double* nocapture writeonly %1, double* nocapture writeonly %2) {
%4 = alloca [1048576 x i8]
%5 = alloca [120 x i8]
%6 = alloca [250 x i8]
%7 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [120 x i8], [120 x i8]* %5, i64 0, i64 0
%9 = getelementptr inbounds [250 x i8], [250 x i8]* %6, i64 0, i64 0
%10 = call i32 @memset(i8* %8, i32 0, i32 120)
%11 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %0)
%12 = call i32 @strlen(i8* %8)
%13 = add i32 %12, -121
%14 = icmp ult i32 %13, -120
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %55
17: ; preds = %3
%18 = call i32 @memset(i8* %7, i32 0, i32 1048576)
%19 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%20 = call i32* @popen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %9)
br label %55
24: ; preds = %17
%25 = call i8* @fgets(i8* %7, i32 1048575, i32* %20)
%26 = icmp eq i8* %25, null
br i1 %26, label %50, label %27
27: ; preds = %24
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i8* %7)
%29 = call i8* @strtok(i8* %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%30 = icmp eq i8* %29, null
br i1 %30, label %53, label %31
31: ; preds = %27, %46
%32 = phi i32 [ %34, %46 ], [ 0, %27 ]
%33 = phi i8* [ %48, %46 ], [ %29, %27 ]
%34 = add nuw nsw i32 %32, 1
%35 = call i64 @malloc(i32 20)
%36 = inttoptr i64 %35 to i8*
%37 = call i32 @strcpy(i8* %36, i8* %33)
switch i32 %32, label %46 [
i32 2, label %38
i32 10, label %41
]
38: ; preds = %31
%39 = call i64 @atol(i8* %36)
%40 = sitofp i64 %39 to double
store double %40, double* %1
br label %46
41: ; preds = %31
%42 = inttoptr i64 %35 to i8*
%43 = call i64 @atol(i8* %42)
%44 = sitofp i64 %43 to double
store double %44, double* %2
%45 = call i32 @free(i8* %42)
br label %53
46: ; preds = %38, %31
%47 = call i32 @free(i8* %36)
%48 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%49 = icmp eq i8* %48, null
br i1 %49, label %53, label %31
50: ; preds = %24
%51 = call i32 @pclose(i32* %20)
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0), i8* %8)
br label %55
53: ; preds = %46, %27, %41
%54 = call i32 @pclose(i32* %20)
br label %55
55: ; preds = %53, %50, %22, %15
%56 = phi i32 [ -1, %15 ], [ 0, %53 ], [ -1, %50 ], [ -1, %22 ]
ret i32 %56
}