#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*/ ifconfig_value;
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*/ 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[2];
  long rx_tx[2];
  char buf[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++;
      memset(ifconfig_value, 0, sizeof(ifconfig_value));
      strcpy(ifconfig_value, p);
      if (i == 3) {
        rx_tx[0] = atol("-1a");
        *recv = (double)rx_tx[0];
      }
      if (i == 11) {
        rx_tx[1] = atol(ifconfig_value);
        *send = (double)rx_tx[1];
        break;
      }
    }
  } 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    $0x600,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x5f4(%rbp)
lea    -0x4e0(%rbp),%rdi
xor    %esi,%esi
mov    $0x78,%edx
call   1070 <memset@plt>
lea    -0x4e0(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe13(%rip),%rsi
call   10c0 <sprintf@plt>
lea    -0x4e0(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x1,-0x24(%rbp)
jl     1215 <tx_rx_stat+0x75>
cmpl   $0x78,-0x24(%rbp)
jle    122f <tx_rx_stat+0x8f>
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13e4 <tx_rx_stat+0x244>
lea    -0x460(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
lea    -0x5e0(%rbp),%rdi
lea    -0x4e0(%rbp),%rdx
lea    0xdc2(%rip),%rsi
call   10c0 <sprintf@plt>
lea    -0x5e0(%rbp),%rdi
lea    0xdcb(%rip),%rsi
call   10a0 <popen@plt>
mov    %rax,-0x5e8(%rbp)
cmpq   $0x0,-0x5e8(%rbp)
jne    12a5 <tx_rx_stat+0x105>
lea    -0x5e0(%rbp),%rsi
lea    0xda5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13e4 <tx_rx_stat+0x244>
lea    -0x460(%rbp),%rdi
mov    -0x5e8(%rbp),%rdx
mov    $0x3ff,%esi
call   1080 <fgets@plt>
mov    %rax,-0x5f0(%rbp)
cmpq   $0x0,-0x5f0(%rbp)
je     13a4 <tx_rx_stat+0x204>
lea    -0x460(%rbp),%rsi
lea    0xd61(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x460(%rbp),%rdi
lea    0xd56(%rip),%rsi
call   10b0 <strtok@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     139f <tx_rx_stat+0x1ff>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
lea    -0x42(%rbp),%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1070 <memset@plt>
lea    -0x42(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1030 <strcpy@plt>
cmpl   $0x3,-0x30(%rbp)
jne    1357 <tx_rx_stat+0x1b7>
lea    0xd10(%rip),%rdi
call   1090 <atol@plt>
mov    %rax,-0x60(%rbp)
cvtsi2sdq -0x60(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
cmpl   $0xb,-0x30(%rbp)
jne    1381 <tx_rx_stat+0x1e1>
lea    -0x42(%rbp),%rdi
call   1090 <atol@plt>
mov    %rax,-0x58(%rbp)
cvtsi2sdq -0x58(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    139f <tx_rx_stat+0x1ff>
jmp    1386 <tx_rx_stat+0x1e6>
xor    %eax,%eax
mov    %eax,%edi
lea    0xcba(%rip),%rsi
call   10b0 <strtok@plt>
mov    %rax,-0x38(%rbp)
jmp    12fe <tx_rx_stat+0x15e>
jmp    13d1 <tx_rx_stat+0x231>
mov    -0x5e8(%rbp),%rdi
call   1060 <pclose@plt>
lea    -0x4e0(%rbp),%rsi
lea    0xc96(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13e4 <tx_rx_stat+0x244>
mov    -0x5e8(%rbp),%rdi
call   1060 <pclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x600,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tx_rx_stat>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x598,%rsp
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%rbx
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x78,%edx
call   1080 <memset@plt>
lea    0xe1b(%rip),%rsi
mov    %rbp,%rdi
mov    %rbx,%rdx
call   10d0 <sprintf@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
add    $0xffffff87,%eax
cmp    $0xffffff87,%eax
ja     1211 <tx_rx_stat+0x61>
lea    0xe55(%rip),%rdi
call   1040 <puts@plt>
jmp    1379 <tx_rx_stat+0x1c9>
lea    0x190(%rsp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1080 <memset@plt>
lea    0xdd8(%rip),%rsi
lea    0x90(%rsp),%rbx
lea    0x10(%rsp),%rdx
mov    %rbx,%rdi
call   10d0 <sprintf@plt>
lea    0xdd8(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <popen@plt>
test   %rax,%rax
je     134d <tx_rx_stat+0x19d>
mov    %rax,%r15
lea    0x190(%rsp),%rdi
mov    $0x3ff,%esi
mov    %rax,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
je     135e <tx_rx_stat+0x1ae>
mov    %r14,0x8(%rsp)
lea    0xda6(%rip),%rdi
xor    %r13d,%r13d
lea    0x190(%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xd94(%rip),%rsi
mov    %rbx,%rdi
call   10c0 <strtok@plt>
test   %rax,%rax
je     1341 <tx_rx_stat+0x191>
mov    %rax,%r14
lea    0x6(%rsp),%rbx
lea    0xd74(%rip),%rbp
jmp    1300 <tx_rx_stat+0x150>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0xd64(%rip),%rdi
call   10a0 <atol@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  %xmm0,(%r12)
xor    %edi,%edi
mov    %rbp,%rsi
call   10c0 <strtok@plt>
mov    %rax,%r14
add    $0x1,%r13d
test   %rax,%rax
je     1341 <tx_rx_stat+0x191>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1080 <memset@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
cmp    $0x2,%r13d
je     12d0 <tx_rx_stat+0x120>
cmp    $0xa,%r13d
jne    12ea <tx_rx_stat+0x13a>
lea    0x6(%rsp),%rdi
call   10a0 <atol@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mov    0x8(%rsp),%rax
movsd  %xmm0,(%rax)
mov    %r15,%rdi
call   1070 <pclose@plt>
xor    %eax,%eax
jmp    137e <tx_rx_stat+0x1ce>
lea    0xcce(%rip),%rdi
lea    0x90(%rsp),%rsi
jmp    1372 <tx_rx_stat+0x1c2>
mov    %r15,%rdi
call   1070 <pclose@plt>
lea    0xcd2(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xffffffff,%eax
add    $0x598,%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 = [4 x i8] c"-1a\00"
@.str.8 = [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 [2 x i8]
%15 = alloca [2 x i64]
%16 = alloca [1024 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 %103
36: ; preds = %31
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%38 = call i32 @memset(i8* %37, i32 0, i32 1024)
%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 %103
49: ; preds = %36
%50 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%51 = load i32*, i32** %19
%52 = call i8* @fgets(i8* %50, i32 1023, i32* %51)
store i8* %52, i8** %20
%53 = load i8*, i8** %20
%54 = icmp ne i8* %53, null
br i1 %54, label %55, label %95
55: ; preds = %49
%56 = getelementptr inbounds [1024 x i8], [1024 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 [1024 x i8], [1024 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 = %92, %55
%61 = load i8*, i8** %12
%62 = icmp ne i8* %61, null
br i1 %62, label %63, label %94
63: ; preds = %60
%64 = load i32, i32* %11
%65 = add nsw i32 %64, 1
store i32 %65, i32* %11
%66 = getelementptr inbounds [2 x i8], [2 x i8]* %14, i64 0, i64 0
%67 = call i32 @memset(i8* %66, i32 0, i32 2)
%68 = getelementptr inbounds [2 x i8], [2 x i8]* %14, i64 0, i64 0
%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 %80
73: ; preds = %63
%74 = call i64 @atol(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%75 = getelementptr inbounds [2 x i64], [2 x i64]* %15, i64 0, i64 0
store i64 %74, i64* %75
%76 = getelementptr inbounds [2 x i64], [2 x i64]* %15, i64 0, i64 0
%77 = load i64, i64* %76
%78 = sitofp i64 %77 to double
%79 = load double*, double** %6
store double %78, double* %79
br label %80
80: ; preds = %73, %63
%81 = load i32, i32* %11
%82 = icmp eq i32 %81, 11
br i1 %82, label %83, label %91
83: ; preds = %80
%84 = getelementptr inbounds [2 x i8], [2 x i8]* %14, i64 0, i64 0
%85 = call i64 @atol(i8* %84)
%86 = getelementptr inbounds [2 x i64], [2 x i64]* %15, i64 0, i64 1
store i64 %85, i64* %86
%87 = getelementptr inbounds [2 x i64], [2 x i64]* %15, i64 0, i64 1
%88 = load i64, i64* %87
%89 = sitofp i64 %88 to double
%90 = load double*, double** %7
store double %89, double* %90
br label %94
91: ; preds = %80
br label %92
92: ; preds = %91
%93 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
store i8* %93, i8** %12
br label %60
94: ; preds = %83, %60
br label %100
95: ; preds = %49
%96 = load i32*, i32** %19
%97 = call i32 @pclose(i32* %96)
%98 = getelementptr inbounds [120 x i8], [120 x i8]* %17, i64 0, i64 0
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.8, i64 0, i64 0), i8* %98)
store i32 -1, i32* %4
br label %103
100: ; preds = %94
%101 = load i32*, i32** %19
%102 = call i32 @pclose(i32* %101)
store i32 0, i32* %4
br label %103
103: ; preds = %100, %95, %46, %34
%104 = load i32, i32* %4
ret i32 %104
}

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 = [4 x i8] c"-1a\00"
@.str.8 = [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 [2 x i8]
%5 = alloca [1024 x i8]
%6 = alloca [120 x i8]
%7 = alloca [250 x i8]
%8 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds [120 x i8], [120 x i8]* %6, i64 0, i64 0
%11 = getelementptr inbounds [250 x i8], [250 x i8]* %7, i64 0, i64 0
%12 = call i32 @memset(i8* %10, i32 0, i32 120)
%13 = call i32 @sprintf(i8* %10, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %0)
%14 = call i32 @strlen(i8* %10)
%15 = add i32 %14, -121
%16 = icmp ult i32 %15, -120
br i1 %16, label %17, label %19
17: ; preds = %3
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %53
19: ; preds = %3
%20 = call i32 @memset(i8* %9, i32 0, i32 1024)
%21 = call i32 @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %10)
%22 = call i32* @popen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %11)
br label %53
26: ; preds = %19
%27 = call i8* @fgets(i8* %9, i32 1023, i32* %22)
%28 = icmp eq i8* %27, null
br i1 %28, label %48, label %29
29: ; preds = %26
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i8* %9)
%31 = call i8* @strtok(i8* %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%32 = icmp eq i8* %31, null
br i1 %32, label %51, label %33
33: ; preds = %29, %45
%34 = phi i32 [ %36, %45 ], [ 0, %29 ]
%35 = phi i8* [ %46, %45 ], [ %31, %29 ]
%36 = add nuw nsw i32 %34, 1
%37 = call i32 @memset(i8* %8, i32 0, i32 2)
%38 = call i32 @strcpy(i8* %8, i8* %35)
switch i32 %34, label %45 [
i32 2, label %39
i32 10, label %42
]
39: ; preds = %33
%40 = call i64 @atol(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%41 = sitofp i64 %40 to double
store double %41, double* %1
br label %45
42: ; preds = %33
%43 = call i64 @atol(i8* %8)
%44 = sitofp i64 %43 to double
store double %44, double* %2
br label %51
45: ; preds = %39, %33
%46 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%47 = icmp eq i8* %46, null
br i1 %47, label %51, label %33
48: ; preds = %26
%49 = call i32 @pclose(i32* %22)
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.8, i64 0, i64 0), i8* %10)
br label %53
51: ; preds = %45, %29, %42
%52 = call i32 @pclose(i32* %22)
br label %53
53: ; preds = %51, %48, %24, %17
%54 = phi i32 [ -1, %17 ], [ 0, %51 ], [ -1, %48 ], [ -1, %24 ]
ret i32 %54
}