#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 timespec {
  int tv_sec;
  int tv_nsec;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC_RAW;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int fscanf(int /*<<< orphan*/ *, char *, ...);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
scalar_t__ strcmp(char *, char *);
long long getnetbytessec() {
  long long bytessend, bytesrecv, bytessec;
  static long long oldbytes = 0;
  static long long oldtimestamp = 0;
  int connected = 0;
  FILE *fp;
  char *dump = NULL;
  size_t len = 0;
  char ifacename[50];
  int ret;
  fp = fopen("/sys/class/net/enp1s0/carrier", "r");
  ret = fscanf(fp, "%d", &connected);
  fclose(fp);
  if (connected == 0) {
    return -1;
  }
  fp = fopen("/proc/net/dev", "r");
  ret = getline(&dump, &len, fp);
  ifacename[0] = '\0';
  while ((!feof(fp)) && (strcmp(ifacename, "enp1s0:") != 0)) {
    ret = getline(&dump, &len, fp);
    ret = fscanf(fp, "%s %lld %*d %*d %*d %*d %*d %*d %*d %lld", ifacename,
                 &bytesrecv, &bytessend);
  }
  fclose(fp);
  free(dump);
  if (ret) {
    struct timespec tp;
    clock_gettime(CLOCK_MONOTONIC_RAW, &tp);
    long timestamp = (1000 * tp.tv_sec) + (tp.tv_nsec / 1000000);
    bytessec = ((bytesrecv + bytessend - oldbytes) * 1000) /
               ((timestamp - oldtimestamp));
    oldbytes = bytesrecv + bytessend;
    oldtimestamp = timestamp;
    if (strcmp(ifacename, "lo") == 0)
      return -1;
    return (bytessec);
  } else {
    printf("Error while reading bytes of network interface\n");
    return 0;
  }
}


x86 assembly (clang, -O0):
<getnetbytessec>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x24(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
lea    0xe47(%rip),%rdi
lea    0xe5c(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xe4a(%rip),%rsi
lea    -0x24(%rbp),%rdx
mov    $0x0,%al
call   1070 <fscanf@plt>
mov    %eax,-0x84(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
cmpl   $0x0,-0x24(%rbp)
jne    1205 <getnetbytessec+0x75>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    13ba <getnetbytessec+0x22a>
lea    0xe15(%rip),%rdi
lea    0xe09(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdx
lea    -0x38(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   10b0 <getline@plt>
mov    %eax,-0x84(%rbp)
movb   $0x0,-0x80(%rbp)
mov    -0x30(%rbp),%rdi
call   1090 <feof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x99(%rbp)
jne    1270 <getnetbytessec+0xe0>
lea    -0x80(%rbp),%rdi
lea    0xdd1(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x99(%rbp)
mov    -0x99(%rbp),%al
test   $0x1,%al
jne    1283 <getnetbytessec+0xf3>
jmp    12c3 <getnetbytessec+0x133>
mov    -0x30(%rbp),%rdx
lea    -0x38(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   10b0 <getline@plt>
mov    %eax,-0x84(%rbp)
mov    -0x30(%rbp),%rdi
lea    -0x80(%rbp),%rdx
lea    0xd8e(%rip),%rsi
lea    -0x18(%rbp),%rcx
lea    -0x10(%rbp),%r8
mov    $0x0,%al
call   1070 <fscanf@plt>
mov    %eax,-0x84(%rbp)
jmp    1237 <getnetbytessec+0xa7>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x84(%rbp)
je     13a6 <getnetbytessec+0x216>
mov    0x2cff(%rip),%rax
mov    (%rax),%edi
lea    -0x90(%rbp),%rsi
call   1040 <clock_gettime@plt>
imul   $0x3e8,-0x90(%rbp),%eax
mov    %eax,-0xa0(%rbp)
mov    -0x8c(%rbp),%eax
mov    $0xf4240,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0xa0(%rbp),%eax
add    %ecx,%eax
cltq
mov    %rax,-0x98(%rbp)
mov    -0x18(%rbp),%rax
add    -0x10(%rbp),%rax
sub    0x2d39(%rip),%rax
imul   $0x3e8,%rax,%rax
mov    -0x98(%rbp),%rcx
sub    0x2d2c(%rip),%rcx
cqto
idiv   %rcx
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
add    -0x10(%rbp),%rax
mov    %rax,0x2d0c(%rip)
mov    -0x98(%rbp),%rax
mov    %rax,0x2d06(%rip)
lea    -0x80(%rbp),%rdi
lea    0xce3(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1399 <getnetbytessec+0x209>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    13ba <getnetbytessec+0x22a>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    13ba <getnetbytessec+0x22a>
lea    0xcb6(%rip),%rdi
call   1060 <printf@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getnetbytessec>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
movl   $0x0,0x4(%rsp)
movq   $0x0,0x8(%rsp)
movq   $0x0,0x18(%rsp)
lea    0xe41(%rip),%rdi
lea    0xe56(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbx
lea    0xe49(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
xor    %eax,%eax
call   1070 <fscanf@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
cmpl   $0x0,0x4(%rsp)
je     12f1 <getnetbytessec+0x161>
lea    0xe23(%rip),%rdi
lea    0xe17(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbx
lea    0x8(%rsp),%rdi
lea    0x18(%rsp),%rsi
mov    %rax,%rdx
call   10b0 <getline@plt>
mov    %eax,%ebp
movb   $0x0,0x30(%rsp)
mov    %rbx,%rdi
call   1090 <feof@plt>
test   %eax,%eax
je     12fd <getnetbytessec+0x16d>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
test   %ebp,%ebp
je     1383 <getnetbytessec+0x1f3>
mov    0x2d91(%rip),%rax
mov    (%rax),%edi
lea    0x10(%rsp),%rsi
call   1050 <clock_gettime@plt>
movslq 0x10(%rsp),%rax
imul   $0x3e8,%rax,%rax
movslq 0x14(%rsp),%rcx
imul   $0x431bde83,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x32,%rcx
add    %edx,%ecx
movslq %ecx,%rbx
add    %rax,%rbx
mov    0x28(%rsp),%rbp
add    0x20(%rsp),%rbp
mov    0x2dd1(%rip),%r15
mov    0x2dd2(%rip),%r14
mov    %rbp,0x2dc3(%rip)
mov    %rbx,0x2dc4(%rip)
lea    0xda5(%rip),%rsi
lea    0x30(%rsp),%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
je     12f1 <getnetbytessec+0x161>
sub    %r15,%rbp
imul   $0x3e8,%rbp,%rax
sub    %r14,%rbx
mov    %rax,%rcx
or     %rbx,%rcx
shr    $0x20,%rcx
je     1393 <getnetbytessec+0x203>
cqto
idiv   %rbx
jmp    1397 <getnetbytessec+0x207>
mov    $0xffffffffffffffff,%rax
jmp    1397 <getnetbytessec+0x207>
lea    0xd2b(%rip),%rsi
lea    0x30(%rsp),%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1236 <getnetbytessec+0xa6>
lea    0x30(%rsp),%r13
lea    0x20(%rsp),%r14
lea    0x28(%rsp),%r15
lea    0xd02(%rip),%r12
nopl   (%rax)
lea    0x8(%rsp),%rdi
lea    0x18(%rsp),%rsi
mov    %rbx,%rdx
call   10b0 <getline@plt>
mov    %rbx,%rdi
lea    0xceb(%rip),%rsi
mov    %r13,%rdx
mov    %r14,%rcx
mov    %r15,%r8
xor    %eax,%eax
call   1070 <fscanf@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1090 <feof@plt>
test   %eax,%eax
jne    1236 <getnetbytessec+0xa6>
mov    %r13,%rdi
mov    %r12,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    1330 <getnetbytessec+0x1a0>
jmp    1236 <getnetbytessec+0xa6>
lea    0xcd9(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
jmp    1397 <getnetbytessec+0x207>
xor    %edx,%edx
div    %ebx
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
@getnetbytessec.oldbytes = internal global i64 0
@getnetbytessec.oldtimestamp = internal global i64 0
@.str = [30 x i8] c"/sys/class/net/enp1s0/carrier\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [14 x i8] c"/proc/net/dev\00"
@.str.4 = [8 x i8] c"enp1s0:\00"
@.str.5 = [41 x i8] c"%s %lld %*d %*d %*d %*d %*d %*d %*d %lld\00"
@CLOCK_MONOTONIC_RAW = global i32 0
@.str.6 = [3 x i8] c"lo\00"
@.str.7 = [48 x i8] c"Error while reading bytes of network interface\0A\00"
define i64 @getnetbytessec() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca [50 x i8]
%10 = alloca i32
%11 = alloca %struct.timespec
%12 = alloca i64
store i32 0, i32* %5
store i8* null, i8** %7
store i64 0, i64* %8
%13 = call i32* @fopen(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %13, i32** %6
%14 = load i32*, i32** %6
%15 = call i32 (i32*, i8*, ...) @fscanf(i32* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %5)
store i32 %15, i32* %10
%16 = load i32*, i32** %6
%17 = call i32 @fclose(i32* %16)
%18 = load i32, i32* %5
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %0
store i64 -1, i64* %1
br label %82
21: ; preds = %0
%22 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %22, i32** %6
%23 = load i32*, i32** %6
%24 = call i32 @getline(i8** %7, i64* %8, i32* %23)
store i32 %24, i32* %10
%25 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
store i8 0, i8* %25
br label %26
26: ; preds = %36, %21
%27 = load i32*, i32** %6
%28 = call i32 @feof(i32* %27)
%29 = icmp ne i32 %28, 0
br i1 %29, label %34, label %30
30: ; preds = %26
%31 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%32 = call i64 @strcmp(i8* %31, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%33 = icmp ne i64 %32, 0
br label %34
34: ; preds = %30, %26
%35 = phi i1 [ false, %26 ], [ %33, %30 ]
br i1 %35, label %36, label %42
36: ; preds = %34
%37 = load i32*, i32** %6
%38 = call i32 @getline(i8** %7, i64* %8, i32* %37)
store i32 %38, i32* %10
%39 = load i32*, i32** %6
%40 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%41 = call i32 (i32*, i8*, ...) @fscanf(i32* %39, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i8* %40, i64* %3, i64* %2)
store i32 %41, i32* %10
br label %26
42: ; preds = %34
%43 = load i32*, i32** %6
%44 = call i32 @fclose(i32* %43)
%45 = load i8*, i8** %7
%46 = call i32 @free(i8* %45)
%47 = load i32, i32* %10
%48 = icmp ne i32 %47, 0
br i1 %48, label %49, label %80
49: ; preds = %42
%50 = load i32, i32* @CLOCK_MONOTONIC_RAW
%51 = call i32 @clock_gettime(i32 %50, %struct.timespec* %11)
%52 = getelementptr inbounds %struct.timespec, %struct.timespec* %11, i32 0, i32 0
%53 = load i32, i32* %52
%54 = mul nsw i32 1000, %53
%55 = getelementptr inbounds %struct.timespec, %struct.timespec* %11, i32 0, i32 1
%56 = load i32, i32* %55
%57 = sdiv i32 %56, 1000000
%58 = add nsw i32 %54, %57
%59 = sext i32 %58 to i64
store i64 %59, i64* %12
%60 = load i64, i64* %3
%61 = load i64, i64* %2
%62 = add nsw i64 %60, %61
%63 = load i64, i64* @getnetbytessec.oldbytes
%64 = sub nsw i64 %62, %63
%65 = mul nsw i64 %64, 1000
%66 = load i64, i64* %12
%67 = load i64, i64* @getnetbytessec.oldtimestamp
%68 = sub nsw i64 %66, %67
%69 = sdiv i64 %65, %68
store i64 %69, i64* %4
%70 = load i64, i64* %3
%71 = load i64, i64* %2
%72 = add nsw i64 %70, %71
store i64 %72, i64* @getnetbytessec.oldbytes
%73 = load i64, i64* %12
store i64 %73, i64* @getnetbytessec.oldtimestamp
%74 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%75 = call i64 @strcmp(i8* %74, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%76 = icmp eq i64 %75, 0
br i1 %76, label %77, label %78
77: ; preds = %49
store i64 -1, i64* %1
br label %82
78: ; preds = %49
%79 = load i64, i64* %4
store i64 %79, i64* %1
br label %82
80: ; preds = %42
%81 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.7, i64 0, i64 0))
store i64 0, i64* %1
br label %82
82: ; preds = %80, %78, %77, %20
%83 = load i64, i64* %1
ret i64 %83
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
@getnetbytessec.oldbytes = internal unnamed_addr global i64 0
@getnetbytessec.oldtimestamp = internal unnamed_addr global i64 0
@.str = [30 x i8] c"/sys/class/net/enp1s0/carrier\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [14 x i8] c"/proc/net/dev\00"
@.str.4 = [8 x i8] c"enp1s0:\00"
@.str.5 = [41 x i8] c"%s %lld %*d %*d %*d %*d %*d %*d %*d %lld\00"
@CLOCK_MONOTONIC_RAW = global i32 0
@.str.6 = [3 x i8] c"lo\00"
@str = [47 x i8] c"Error while reading bytes of network interface\00"
define i64 @getnetbytessec() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca [50 x i8]
%7 = alloca %struct.timespec
%8 = bitcast i64* %1 to i8*
%9 = bitcast i64* %2 to i8*
%10 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%11 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%12 = bitcast i64* %5 to i8*
store i64 0, i64* %5
%13 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%14 = tail call i32* @fopen(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 (i32*, i8*, ...) @fscanf(i32* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%16 = call i32 @fclose(i32* %14)
%17 = load i32, i32* %3
%18 = icmp eq i32 %17, 0
br i1 %18, label %69, label %19
19: ; preds = %0
%20 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @getline(i8** %4, i64* %5, i32* %20)
store i8 0, i8* %13
%22 = call i32 @feof(i32* %20)
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %35
24: ; preds = %19
%25 = call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %35, label %30
27: ; preds = %30
%28 = call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %35, label %30
30: ; preds = %24, %27
%31 = call i32 @getline(i8** %4, i64* %5, i32* %20)
%32 = call i32 (i32*, i8*, ...) @fscanf(i32* %20, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i8* %13, i64* %2, i64* %1)
%33 = call i32 @feof(i32* %20)
%34 = icmp eq i32 %33, 0
br i1 %34, label %27, label %35
35: ; preds = %30, %27, %24, %19
%36 = phi i32 [ %21, %19 ], [ %21, %24 ], [ %32, %27 ], [ %32, %30 ]
%37 = call i32 @fclose(i32* %20)
%38 = load i8*, i8** %4
%39 = call i32 @free(i8* %38)
%40 = icmp eq i32 %36, 0
br i1 %40, label %67, label %41
41: ; preds = %35
%42 = bitcast %struct.timespec* %7 to i8*
%43 = load i32, i32* @CLOCK_MONOTONIC_RAW
%44 = call i32 @clock_gettime(i32 %43, %struct.timespec* %7)
%45 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i64 0, i32 0
%46 = load i32, i32* %45
%47 = mul nsw i32 %46, 1000
%48 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i64 0, i32 1
%49 = load i32, i32* %48
%50 = sdiv i32 %49, 1000000
%51 = add nsw i32 %50, %47
%52 = sext i32 %51 to i64
%53 = load i64, i64* %2
%54 = load i64, i64* %1
%55 = add nsw i64 %54, %53
%56 = load i64, i64* @getnetbytessec.oldbytes
%57 = load i64, i64* @getnetbytessec.oldtimestamp
store i64 %55, i64* @getnetbytessec.oldbytes
store i64 %52, i64* @getnetbytessec.oldtimestamp
%58 = call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%59 = icmp eq i64 %58, 0
br i1 %59, label %65, label %60
60: ; preds = %41
%61 = sub nsw i64 %55, %56
%62 = mul nsw i64 %61, 1000
%63 = sub nsw i64 %52, %57
%64 = sdiv i64 %62, %63
br label %65
65: ; preds = %41, %60
%66 = phi i64 [ %64, %60 ], [ -1, %41 ]
br label %69
67: ; preds = %35
%68 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str, i64 0, i64 0))
br label %69
69: ; preds = %0, %67, %65
%70 = phi i64 [ %66, %65 ], [ 0, %67 ], [ -1, %0 ]
ret i64 %70
}