#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 timeval {
  scalar_t__ tv_usec;
  scalar_t__ tv_sec;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, double, unsigned long long,
                          unsigned long long);
int /*<<< orphan*/ sscanf(char *, char *, unsigned long long *,
                          unsigned long long *, unsigned long long *,
                          unsigned long long *, unsigned long long *,
                          unsigned long long *, unsigned long long *,
                          unsigned long long *, unsigned long long *);
int /*<<< orphan*/ *strstr(char *, char *);
void get_stat_network() {
  FILE *f;
  char line[256];
  unsigned long long c1, c2, c3, c4, c5, c6, c7, c8, c9;
  unsigned long long tx, rx;
  struct timeval tv;
  double uusec;
  f = fopen("/proc/net/dev", "r");
  if (f) {
    do {
      fgets(line, 256, f);
    } while (strstr(line, "eth0") == NULL);
    fclose(f);
    if (strstr(line, "eth0: ")) {
      sscanf(line,
             "%*[ ]eth0:%*[ ]%llu%*[ ]%llu%*[ ]%llu%*[ ]%llu%*[ ]%llu%*[ "
             "]%llu%*[ ]%llu%*[ ]%llu%*[ ]%llu",
             &c1, &c2, &c3, &c4, &c5, &c6, &c7, &c8, &c9);
    } else if (strstr(line, "eth0:")) {
      sscanf(line,
             "%*[ ]eth0:%llu%*[ ]%llu%*[ ]%llu%*[ ]%llu%*[ ]%llu%*[ ]%llu%*[ "
             "]%llu%*[ ]%llu%*[ ]%llu",
             &c1, &c2, &c3, &c4, &c5, &c6, &c7, &c8, &c9);
    }
    rx = c1;
    tx = c9;
    gettimeofday(&tv, NULL);
    uusec = (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0;
    printf("%lf|%llu|%llu\n", uusec, rx * 8, tx * 8);
  }
}


x86 assembly (clang, -O0):
<get_stat_network>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0x1b0,%rsp
lea    0xe83(%rip),%rdi
lea    0xe8a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1378 <get_stat_network+0x208>
jmp    11a5 <get_stat_network+0x35>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x100,%esi
call   1060 <fgets@plt>
lea    -0x120(%rbp),%rdi
lea    0xe50(%rip),%rsi
call   1090 <strstr@plt>
cmp    $0x0,%rax
je     11a5 <get_stat_network+0x35>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0x120(%rbp),%rdi
lea    0xe2f(%rip),%rsi
call   1090 <strstr@plt>
cmp    $0x0,%rax
je     126c <get_stat_network+0xfc>
lea    -0x120(%rbp),%rdi
lea    0xe19(%rip),%rsi
lea    -0x128(%rbp),%rdx
lea    -0x130(%rbp),%rcx
lea    -0x138(%rbp),%r8
lea    -0x140(%rbp),%r9
lea    -0x148(%rbp),%r14
lea    -0x150(%rbp),%rbx
lea    -0x158(%rbp),%r11
lea    -0x160(%rbp),%r10
lea    -0x168(%rbp),%rax
mov    %r14,(%rsp)
mov    %rbx,0x8(%rsp)
mov    %r11,0x10(%rsp)
mov    %r10,0x18(%rsp)
mov    %rax,0x20(%rsp)
call   1070 <sscanf@plt>
jmp    12f8 <get_stat_network+0x188>
lea    -0x120(%rbp),%rdi
lea    0xe06(%rip),%rsi
call   1090 <strstr@plt>
cmp    $0x0,%rax
je     12f3 <get_stat_network+0x183>
lea    -0x120(%rbp),%rdi
lea    0xdef(%rip),%rsi
lea    -0x128(%rbp),%rdx
lea    -0x130(%rbp),%rcx
lea    -0x138(%rbp),%r8
lea    -0x140(%rbp),%r9
lea    -0x148(%rbp),%r14
lea    -0x150(%rbp),%rbx
lea    -0x158(%rbp),%r11
lea    -0x160(%rbp),%r10
lea    -0x168(%rbp),%rax
mov    %r14,(%rsp)
mov    %rbx,0x8(%rsp)
mov    %r11,0x10(%rsp)
mov    %r10,0x18(%rsp)
mov    %rax,0x20(%rsp)
call   1070 <sscanf@plt>
jmp    12f8 <get_stat_network+0x188>
mov    -0x128(%rbp),%rax
mov    %rax,-0x178(%rbp)
mov    -0x168(%rbp),%rax
mov    %rax,-0x170(%rbp)
lea    -0x188(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
cvtsi2sdq -0x180(%rbp),%xmm0
ff ff
cvtsi2sdq -0x188(%rbp),%xmm1
ff ff
movsd  0xcc2(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x190(%rbp)
ff
movsd  -0x190(%rbp),%xmm0
ff
mov    -0x178(%rbp),%rsi
shl    $0x3,%rsi
mov    -0x170(%rbp),%rdx
shl    $0x3,%rdx
lea    0xd6a(%rip),%rdi
call   1040 <printf@plt>
add    $0x1b0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_stat_network>:
push   %r15
push   %r14
push   %rbx
sub    $0x160,%rsp
lea    0xe85(%rip),%rdi
lea    0xe8c(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     12a5 <get_stat_network+0x135>
mov    %rax,%r14
lea    0x60(%rsp),%rbx
lea    0xe71(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1090 <strstr@plt>
test   %rax,%rax
je     11b0 <get_stat_network+0x40>
mov    %r14,%rdi
call   1030 <fclose@plt>
lea    0xe3e(%rip),%rsi
lea    0x60(%rsp),%rdi
call   1090 <strstr@plt>
test   %rax,%rax
je     11f7 <get_stat_network+0x87>
lea    0xe2f(%rip),%rsi
jmp    1214 <get_stat_network+0xa4>
lea    0xe82(%rip),%rsi
lea    0x60(%rsp),%rdi
call   1090 <strstr@plt>
test   %rax,%rax
je     125b <get_stat_network+0xeb>
lea    0xe72(%rip),%rsi
sub    $0x8,%rsp
lea    0x10(%rsp),%rax
lea    0x30(%rsp),%rbx
lea    0x38(%rsp),%r10
lea    0x40(%rsp),%r11
lea    0x48(%rsp),%r14
lea    0x68(%rsp),%rdi
lea    0x18(%rsp),%rdx
lea    0x60(%rsp),%rcx
lea    0x58(%rsp),%r8
lea    0x50(%rsp),%r9
push   %rax
push   %rbx
push   %r10
push   %r11
push   %r14
call   1070 <sscanf@plt>
add    $0x30,%rsp
mov    0x10(%rsp),%rbx
mov    0x8(%rsp),%r14
lea    0x18(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
cvtsi2sdq 0x20(%rsp),%xmm1
cvtsi2sdq 0x18(%rsp),%xmm0
divsd  0xd79(%rip),%xmm0
addsd  %xmm1,%xmm0
shl    $0x3,%rbx
shl    $0x3,%r14
lea    0xe43(%rip),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1040 <printf@plt>
add    $0x160,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
@.str = [14 x i8] c"/proc/net/dev\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [5 x i8] c"eth0\00"
@.str.3 = [7 x i8] c"eth0: \00"
@.str.4 = [92 x i8] c"%*[ ]eth0:%*[ ]%llu%*[ ]%llu%*[ ]%llu%*[ ]%llu%*[ ]%llu%*[ ]%llu%*[ ]%llu%*[ ]%llu%*[ ]%llu\00"
@.str.5 = [6 x i8] c"eth0:\00"
@.str.6 = [87 x i8] c"%*[ ]eth0:%llu%*[ ]%llu%*[ ]%llu%*[ ]%llu%*[ ]%llu%*[ ]%llu%*[ ]%llu%*[ ]%llu%*[ ]%llu\00"
@.str.7 = [15 x i8] c"%lf|%llu|%llu\0A\00"
define void @get_stat_network() {
%1 = alloca i32*
%2 = alloca [256 x i8]
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
%14 = alloca %struct.timeval
%15 = alloca double
%16 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %16, i32** %1
%17 = load i32*, i32** %1
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %63
19: ; preds = %0
br label %20
20: ; preds = %24, %19
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%22 = load i32*, i32** %1
%23 = call i32 @fgets(i8* %21, i32 256, i32* %22)
br label %24
24: ; preds = %20
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%26 = call i32* @strstr(i8* %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%27 = icmp eq i32* %26, null
br i1 %27, label %20, label %28
28: ; preds = %24
%29 = load i32*, i32** %1
%30 = call i32 @fclose(i32* %29)
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%32 = call i32* @strstr(i8* %31, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%33 = icmp ne i32* %32, null
br i1 %33, label %34, label %37
34: ; preds = %28
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%36 = call i32 @sscanf(i8* %35, i8* getelementptr inbounds ([92 x i8], [92 x i8]* @.str.4, i64 0, i64 0), i64* %3, i64* %4, i64* %5, i64* %6, i64* %7, i64* %8, i64* %9, i64* %10, i64* %11)
br label %45
37: ; preds = %28
%38 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%39 = call i32* @strstr(i8* %38, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%40 = icmp ne i32* %39, null
br i1 %40, label %41, label %44
41: ; preds = %37
%42 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%43 = call i32 @sscanf(i8* %42, i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str.6, i64 0, i64 0), i64* %3, i64* %4, i64* %5, i64* %6, i64* %7, i64* %8, i64* %9, i64* %10, i64* %11)
br label %44
44: ; preds = %41, %37
br label %45
45: ; preds = %44, %34
%46 = load i64, i64* %3
store i64 %46, i64* %13
%47 = load i64, i64* %11
store i64 %47, i64* %12
%48 = call i32 @gettimeofday(%struct.timeval* %14, i32* null)
%49 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 1
%50 = load i64, i64* %49
%51 = sitofp i64 %50 to double
%52 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 0
%53 = load i64, i64* %52
%54 = sitofp i64 %53 to double
%55 = fdiv double %54, 1.000000e+06
%56 = fadd double %51, %55
store double %56, double* %15
%57 = load double, double* %15
%58 = load i64, i64* %13
%59 = mul i64 %58, 8
%60 = load i64, i64* %12
%61 = mul i64 %60, 8
%62 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), double %57, i64 %59, i64 %61)
br label %63
63: ; preds = %45, %0
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
@.str = [14 x i8] c"/proc/net/dev\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [5 x i8] c"eth0\00"
@.str.3 = [7 x i8] c"eth0: \00"
@.str.4 = [92 x i8] c"%*[ ]eth0:%*[ ]%llu%*[ ]%llu%*[ ]%llu%*[ ]%llu%*[ ]%llu%*[ ]%llu%*[ ]%llu%*[ ]%llu%*[ ]%llu\00"
@.str.5 = [6 x i8] c"eth0:\00"
@.str.6 = [87 x i8] c"%*[ ]eth0:%llu%*[ ]%llu%*[ ]%llu%*[ ]%llu%*[ ]%llu%*[ ]%llu%*[ ]%llu%*[ ]%llu%*[ ]%llu\00"
@.str.7 = [15 x i8] c"%lf|%llu|%llu\0A\00"
define void @get_stat_network() {
%1 = alloca [256 x i8]
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca %struct.timeval
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%13 = bitcast i64* %2 to i8*
%14 = bitcast i64* %3 to i8*
%15 = bitcast i64* %4 to i8*
%16 = bitcast i64* %5 to i8*
%17 = bitcast i64* %6 to i8*
%18 = bitcast i64* %7 to i8*
%19 = bitcast i64* %8 to i8*
%20 = bitcast i64* %9 to i8*
%21 = bitcast i64* %10 to i8*
%22 = bitcast %struct.timeval* %11 to i8*
%23 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%24 = icmp eq i32* %23, null
br i1 %24, label %54, label %25
25: ; preds = %0, %25
%26 = call i32 @fgets(i8* %12, i32 256, i32* %23)
%27 = call i32* @strstr(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%28 = icmp eq i32* %27, null
br i1 %28, label %25, label %29
29: ; preds = %25
%30 = call i32 @fclose(i32* %23)
%31 = call i32* @strstr(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %36
33: ; preds = %29
%34 = call i32* @strstr(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%35 = icmp eq i32* %34, null
br i1 %35, label %39, label %36
36: ; preds = %33, %29
%37 = phi i8* [ getelementptr inbounds ([92 x i8], [92 x i8]* @.str.4, i64 0, i64 0), %29 ], [ getelementptr inbounds ([87 x i8], [87 x i8]* @.str.6, i64 0, i64 0), %33 ]
%38 = call i32 @sscanf(i8* %12, i8* %37, i64* %2, i64* %3, i64* %4, i64* %5, i64* %6, i64* %7, i64* %8, i64* %9, i64* %10)
br label %39
39: ; preds = %36, %33
%40 = load i64, i64* %2
%41 = load i64, i64* %10
%42 = call i32 @gettimeofday(%struct.timeval* %11, i32* null)
%43 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i64 0, i32 1
%44 = load i64, i64* %43
%45 = sitofp i64 %44 to double
%46 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i64 0, i32 0
%47 = load i64, i64* %46
%48 = sitofp i64 %47 to double
%49 = fdiv double %48, 1.000000e+06
%50 = fadd double %49, %45
%51 = shl i64 %40, 3
%52 = shl i64 %41, 3
%53 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), double %50, i64 %51, i64 %52)
br label %54
54: ; preds = %39, %0
ret void
}