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

/* Variables and functions */
unsigned int atoi(char *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *);
scalar_t__ stat(char *, struct stat *);
char *strchr(char *, char);
int strlen(char *);
int /*<<< orphan*/ *strstr(char *, char *);
int tokenize(char *, char **, char *, char *, char *);
void get_tx_rx_data(char *if_name, unsigned int *tx_data,
                    unsigned int *rx_data) {
  char net_dev[] = "/proc/net/dev";
  struct stat file_stat;
  int toknum;
  char *token[32];
  FILE *pipe_fd;
  char line[500];
  int i, len, found = 0;
  char *ptr;
  *tx_data = *rx_data = 0;
  if (stat(net_dev, &file_stat) < 0)
    return;
  pipe_fd = popen("cat /proc/net/dev", "r");
  if (pipe_fd == NULL) {
    printf("Failed to open /proc/net/dev\n");
    return;
  }
  i = 0;
  while (fgets(line, sizeof(line) - 1, pipe_fd)) {
    if (++i < 2)
      continue;
    if (strstr(line, if_name) != NULL) {
      found = 1;
      break;
    }
  }
  pclose(pipe_fd);
  if (!found) {
    return;
  }
  if ((ptr = strchr(line, ':')) != NULL) {
    *ptr = ' ';
  }
  len = strlen(line) + 1;
  toknum = tokenize(line, token, " ", " \t\n", " ");
  if (toknum < 13)
    return;
  *rx_data = atoi(token[2]);
  *tx_data = atoi(token[10]);
  return;
}


x86 assembly (clang, -O0):
<get_tx_rx_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x360,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0xe46(%rip),%rax
mov    %rax,-0x26(%rbp)
mov    0xe44(%rip),%eax
mov    %eax,-0x1e(%rbp)
mov    0xe3e(%rip),%ax
mov    %ax,-0x1a(%rbp)
movl   $0x0,-0x34c(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
lea    -0x26(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1080 <stat@plt>
cmp    $0x0,%rax
jge    1210 <get_tx_rx_data+0x70>
jmp    137d <get_tx_rx_data+0x1dd>
lea    0xde9(%rip),%rdi
lea    0xdf4(%rip),%rsi
call   10a0 <popen@plt>
mov    %rax,-0x148(%rbp)
cmpq   $0x0,-0x148(%rbp)
jne    1249 <get_tx_rx_data+0xa9>
lea    0xdd5(%rip),%rdi
call   1050 <printf@plt>
jmp    137d <get_tx_rx_data+0x1dd>
movl   $0x0,-0x344(%rbp)
lea    -0x340(%rbp),%rdi
mov    -0x148(%rbp),%rdx
mov    $0x1f3,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     12c0 <get_tx_rx_data+0x120>
mov    -0x344(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x344(%rbp)
cmp    $0x2,%eax
jge    1292 <get_tx_rx_data+0xf2>
jmp    1253 <get_tx_rx_data+0xb3>
lea    -0x340(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   10c0 <strstr@plt>
cmp    $0x0,%rax
je     12bb <get_tx_rx_data+0x11b>
movl   $0x1,-0x34c(%rbp)
jmp    12c0 <get_tx_rx_data+0x120>
jmp    1253 <get_tx_rx_data+0xb3>
mov    -0x148(%rbp),%rdi
call   1060 <pclose@plt>
cmpl   $0x0,-0x34c(%rbp)
jne    12de <get_tx_rx_data+0x13e>
jmp    137d <get_tx_rx_data+0x1dd>
lea    -0x340(%rbp),%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
mov    %rax,-0x358(%rbp)
cmp    $0x0,%rax
je     130a <get_tx_rx_data+0x16a>
mov    -0x358(%rbp),%rax
movb   $0x20,(%rax)
lea    -0x340(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x348(%rbp)
lea    -0x340(%rbp),%rdi
lea    -0x140(%rbp),%rsi
lea    0xcfe(%rip),%r8
lea    0xcf9(%rip),%rcx
mov    %r8,%rdx
call   1090 <tokenize@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0xd,-0x34(%rbp)
jge    1355 <get_tx_rx_data+0x1b5>
jmp    137d <get_tx_rx_data+0x1dd>
mov    -0x130(%rbp),%rdi
call   10b0 <atoi@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0xf0(%rbp),%rdi
call   10b0 <atoi@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
add    $0x360,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_tx_rx_data>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x318,%rsp
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r12
movabs $0x7665642f74656e,%rax
mov    %rax,0x16(%rsp)
movabs $0x656e2f636f72702f,%rax
2f 6e 65
mov    %rax,0x10(%rsp)
movl   $0x0,(%rdx)
movl   $0x0,(%rsi)
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1080 <stat@plt>
test   %rax,%rax
js     1305 <get_tx_rx_data+0x165>
lea    0xdfd(%rip),%rdi
lea    0xe08(%rip),%rsi
call   10a0 <popen@plt>
test   %rax,%rax
je     12f9 <get_tx_rx_data+0x159>
mov    %rax,%rbx
lea    0x120(%rsp),%rdi
mov    $0x1f3,%esi
mov    %rax,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     12ef <get_tx_rx_data+0x14f>
xor    %ebp,%ebp
lea    0x120(%rsp),%r13
jmp    1269 <get_tx_rx_data+0xc9>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r13,%rdi
mov    $0x1f3,%esi
mov    %rbx,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     12ef <get_tx_rx_data+0x14f>
sub    $0x1,%ebp
jb     1250 <get_tx_rx_data+0xb0>
mov    %r13,%rdi
mov    %r12,%rsi
call   10c0 <strstr@plt>
test   %rax,%rax
je     1250 <get_tx_rx_data+0xb0>
mov    %rbx,%rdi
call   1060 <pclose@plt>
lea    0x120(%rsp),%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     12a0 <get_tx_rx_data+0x100>
movb   $0x20,(%rax)
lea    0x120(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0xd5f(%rip),%rcx
lea    0xd56(%rip),%rdx
lea    0x20(%rsp),%rsi
mov    %rbx,%rdi
mov    %rdx,%r8
call   1090 <tokenize@plt>
cmp    $0xd,%eax
jl     1305 <get_tx_rx_data+0x165>
mov    0x30(%rsp),%rdi
call   10b0 <atoi@plt>
mov    %eax,(%r15)
mov    0x70(%rsp),%rdi
call   10b0 <atoi@plt>
mov    %eax,(%r14)
jmp    1305 <get_tx_rx_data+0x165>
mov    %rbx,%rdi
call   1060 <pclose@plt>
jmp    1305 <get_tx_rx_data+0x165>
lea    0xd1a(%rip),%rdi
call   1030 <puts@plt>
add    $0x318,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@__const.get_tx_rx_data.net_dev = [14 x i8] c"/proc/net/dev\00"
@.str = [18 x i8] c"cat /proc/net/dev\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [30 x i8] c"Failed to open /proc/net/dev\0A\00"
@.str.3 = [2 x i8] c" \00"
@.str.4 = [4 x i8] c" \09\0A\00"
define void @get_tx_rx_data(i8* %0, i32* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca [14 x i8]
%8 = alloca %struct.stat
%9 = alloca i32
%10 = alloca [32 x i8*]
%11 = alloca i32*
%12 = alloca [500 x i8]
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i8*
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
%17 = bitcast [14 x i8]* %7 to i8*
store i32 0, i32* %15
%18 = load i32*, i32** %6
store i32 0, i32* %18
%19 = load i32*, i32** %5
store i32 0, i32* %19
%20 = getelementptr inbounds [14 x i8], [14 x i8]* %7, i64 0, i64 0
%21 = call i64 @stat(i8* %20, %struct.stat* %8)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %3
br label %79
24: ; preds = %3
%25 = call i32* @popen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %25, i32** %11
%26 = load i32*, i32** %11
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %79
30: ; preds = %24
store i32 0, i32* %13
br label %31
31: ; preds = %47, %40, %30
%32 = getelementptr inbounds [500 x i8], [500 x i8]* %12, i64 0, i64 0
%33 = load i32*, i32** %11
%34 = call i64 @fgets(i8* %32, i32 499, i32* %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %48
36: ; preds = %31
%37 = load i32, i32* %13
%38 = add nsw i32 %37, 1
store i32 %38, i32* %13
%39 = icmp slt i32 %38, 2
br i1 %39, label %40, label %41
40: ; preds = %36
br label %31
41: ; preds = %36
%42 = getelementptr inbounds [500 x i8], [500 x i8]* %12, i64 0, i64 0
%43 = load i8*, i8** %4
%44 = call i32* @strstr(i8* %42, i8* %43)
%45 = icmp ne i32* %44, null
br i1 %45, label %46, label %47
46: ; preds = %41
store i32 1, i32* %15
br label %48
47: ; preds = %41
br label %31
48: ; preds = %46, %31
%49 = load i32*, i32** %11
%50 = call i32 @pclose(i32* %49)
%51 = load i32, i32* %15
%52 = icmp ne i32 %51, 0
br i1 %52, label %54, label %53
53: ; preds = %48
br label %79
54: ; preds = %48
%55 = getelementptr inbounds [500 x i8], [500 x i8]* %12, i64 0, i64 0
%56 = call i8* @strchr(i8* %55, i8 signext 58)
store i8* %56, i8** %16
%57 = icmp ne i8* %56, null
br i1 %57, label %58, label %60
58: ; preds = %54
%59 = load i8*, i8** %16
store i8 32, i8* %59
br label %60
60: ; preds = %58, %54
%61 = getelementptr inbounds [500 x i8], [500 x i8]* %12, i64 0, i64 0
%62 = call i32 @strlen(i8* %61)
%63 = add nsw i32 %62, 1
store i32 %63, i32* %14
%64 = getelementptr inbounds [500 x i8], [500 x i8]* %12, i64 0, i64 0
%65 = getelementptr inbounds [32 x i8*], [32 x i8*]* %10, i64 0, i64 0
%66 = call i32 @tokenize(i8* %64, i8** %65, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32 %66, i32* %9
%67 = load i32, i32* %9
%68 = icmp slt i32 %67, 13
br i1 %68, label %69, label %70
69: ; preds = %60
br label %79
70: ; preds = %60
%71 = getelementptr inbounds [32 x i8*], [32 x i8*]* %10, i64 0, i64 2
%72 = load i8*, i8** %71
%73 = call i32 @atoi(i8* %72)
%74 = load i32*, i32** %6
store i32 %73, i32* %74
%75 = getelementptr inbounds [32 x i8*], [32 x i8*]* %10, i64 0, i64 10
%76 = load i8*, i8** %75
%77 = call i32 @atoi(i8* %76)
%78 = load i32*, i32** %5
store i32 %77, i32* %78
br label %79
79: ; preds = %70, %69, %53, %28, %23
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@__const.get_tx_rx_data.net_dev = [14 x i8] c"/proc/net/dev\00"
@.str = [18 x i8] c"cat /proc/net/dev\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [2 x i8] c" \00"
@.str.4 = [4 x i8] c" \09\0A\00"
@str = [29 x i8] c"Failed to open /proc/net/dev\00"
define void @get_tx_rx_data(i8* nocapture %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = alloca [14 x i8]
%5 = alloca %struct.stat
%6 = alloca [32 x i8*]
%7 = alloca [500 x i8]
%8 = getelementptr inbounds [14 x i8], [14 x i8]* %4, i64 0, i64 0
%9 = bitcast %struct.stat* %5 to i8*
%10 = bitcast [32 x i8*]* %6 to i8*
%11 = getelementptr inbounds [500 x i8], [500 x i8]* %7, i64 0, i64 0
store i32 0, i32* %2
store i32 0, i32* %1
%12 = call i64 @stat(i8* %8, %struct.stat* %5)
%13 = icmp slt i64 %12, 0
br i1 %13, label %51, label %14
14: ; preds = %3
%15 = call i32* @popen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %20, label %17
17: ; preds = %14
%18 = call i64 @fgets(i8* %11, i32 499, i32* %15)
%19 = icmp eq i64 %18, 0
br i1 %19, label %32, label %22
20: ; preds = %14
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
br label %51
22: ; preds = %17, %26
%23 = phi i32 [ %24, %26 ], [ 0, %17 ]
%24 = add nuw nsw i32 %23, 1
%25 = icmp eq i32 %23, 0
br i1 %25, label %26, label %29
26: ; preds = %22, %29
%27 = call i64 @fgets(i8* %11, i32 499, i32* %15)
%28 = icmp eq i64 %27, 0
br i1 %28, label %32, label %22
29: ; preds = %22
%30 = call i32* @strstr(i8* %11, i8* dereferenceable(1) %0)
%31 = icmp eq i32* %30, null
br i1 %31, label %26, label %34
32: ; preds = %26, %17
%33 = call i32 @pclose(i32* %15)
br label %51
34: ; preds = %29
%35 = call i32 @pclose(i32* %15)
%36 = call i8* @strchr(i8* %11, i8 signext 58)
%37 = icmp eq i8* %36, null
br i1 %37, label %39, label %38
38: ; preds = %34
store i8 32, i8* %36
br label %39
39: ; preds = %38, %34
%40 = call i32 @strlen(i8* %11)
%41 = getelementptr inbounds [32 x i8*], [32 x i8*]* %6, i64 0, i64 0
%42 = call i32 @tokenize(i8* %11, i8** %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%43 = icmp slt i32 %42, 13
br i1 %43, label %51, label %44
44: ; preds = %39
%45 = getelementptr inbounds [32 x i8*], [32 x i8*]* %6, i64 0, i64 2
%46 = load i8*, i8** %45
%47 = call i32 @atoi(i8* %46)
store i32 %47, i32* %2
%48 = getelementptr inbounds [32 x i8*], [32 x i8*]* %6, i64 0, i64 10
%49 = load i8*, i8** %48
%50 = call i32 @atoi(i8* %49)
store i32 %50, i32* %1
br label %51
51: ; preds = %39, %32, %3, %44, %20
ret void
}