#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, double);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ sscanf(char *, char *, double *);
int main(void) {
  while (1) {
    double received_bytes = 0.0;
    double transmitted_bytes = 0.0;
    double total_received_bytes = 0.0;
    double total_transmitted_bytes = 0.0;
    double network_activity[2];
    double bandwidth = 0.0;
    double proportional_bandwidth = 0.0;
    static double peak_bandwidth;
    int count = 1;
    FILE *fp;
    char line[256];
    while (count < 3) {
      fp = fopen("/proc/net/dev", "r");
      while (fgets(line, 256, fp)) {
        sscanf(line, "%*[ ]%*s%*[ ]%lf", &received_bytes);
        total_received_bytes = total_received_bytes + received_bytes;
        sscanf(line,
               "%*[ ]%*s%*[ ]%*lf%*[ ]%*lf%*[ ]%*lf%*[ ]%*lf%*[ ]%*lf%*[ "
               "]%*lf%*[ ]%*lf%*[ ]%*lf%*[ ]%lf",
               &transmitted_bytes);
        total_transmitted_bytes = total_transmitted_bytes + transmitted_bytes;
      }
      network_activity[count] = total_received_bytes + total_transmitted_bytes;
      count++;
      fclose(fp);
      if (count == 3) {
        break;
      }
      total_received_bytes = 0.0;
      total_transmitted_bytes = 0.0;
      sleep(1);
    }
    double relative_network_activity =
        network_activity[2] - network_activity[1];
    bandwidth = relative_network_activity * 8;
    if (bandwidth > peak_bandwidth) {
      peak_bandwidth = bandwidth;
    }
    if (peak_bandwidth > 0) {
      proportional_bandwidth = (bandwidth / peak_bandwidth) * 100;
    }
    printf("\n The total number of bytes received was: %lf",
           total_received_bytes);
    printf("\n The total number of bytes transmitted was: %lf",
           total_transmitted_bytes);
    printf("\n The relative network activity was: %lf Bytes",
           relative_network_activity);
    printf("\n The bandwidth was: %lf bits per second\n", bandwidth);
    printf("\n The PEAK bandwidth was: %lf ", peak_bandwidth);
    printf("\n The proprortional bandwidth of the peak is: %lf %%\n",
           proportional_bandwidth);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x170,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x50(%rbp)
movl   $0x1,-0x54(%rbp)
cmpl   $0x3,-0x54(%rbp)
jge    128e <main+0x12e>
lea    0xe56(%rip),%rdi
lea    0xe5d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x60(%rbp)
lea    -0x160(%rbp),%rdi
mov    -0x60(%rbp),%rdx
mov    $0x100,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     123a <main+0xda>
lea    -0x160(%rbp),%rdi
lea    0xe29(%rip),%rsi
lea    -0x10(%rbp),%rdx
call   1060 <sscanf@plt>
movsd  -0x20(%rbp),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
lea    -0x160(%rbp),%rdi
lea    0xe14(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1060 <sscanf@plt>
movsd  -0x28(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    11ca <main+0x6a>
movsd  -0x20(%rbp),%xmm0
addsd  -0x28(%rbp),%xmm0
movslq -0x54(%rbp),%rax
movsd  %xmm0,-0x40(%rbp,%rax,8)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
mov    -0x60(%rbp),%rdi
call   1030 <fclose@plt>
cmpl   $0x3,-0x54(%rbp)
jne    126f <main+0x10f>
jmp    128e <main+0x12e>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    $0x1,%edi
call   1080 <sleep@plt>
jmp    11a9 <main+0x49>
movsd  -0x30(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x168(%rbp)
ff
movsd  0xd58(%rip),%xmm0
mulsd  -0x168(%rbp),%xmm0
ff
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
ucomisd 0x2d96(%rip),%xmm0
jbe    12d5 <main+0x175>
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,0x2d83(%rip)
movsd  0x2d7b(%rip),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1308 <main+0x1a8>
movsd  -0x48(%rbp),%xmm0
divsd  0x2d61(%rip),%xmm0
movsd  0xd09(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x20(%rbp),%xmm0
lea    0xd76(%rip),%rdi
call   1040 <printf@plt>
movsd  -0x28(%rbp),%xmm0
lea    0xd93(%rip),%rdi
call   1040 <printf@plt>
movsd  -0x168(%rbp),%xmm0
ff
lea    0xdb0(%rip),%rdi
call   1040 <printf@plt>
movsd  -0x48(%rbp),%xmm0
lea    0xdce(%rip),%rdi
call   1040 <printf@plt>
movsd  0x2d01(%rip),%xmm0
lea    0xde4(%rip),%rdi
call   1040 <printf@plt>
movsd  -0x50(%rbp),%xmm0
lea    0xdf2(%rip),%rdi
call   1040 <printf@plt>
jmp    1172 <main+0x12>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
lea    0xe88(%rip),%rax
lea    0x20(%rsp),%rbx
lea    0x18(%rsp),%r13
lea    0xe98(%rip),%r12
lea    0x10(%rsp),%r14
jmp    1209 <main+0xa9>
movsd  %xmm0,0x8(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
mov    %r15,%rdi
call   1030 <fclose@plt>
lea    0xecc(%rip),%rdi
movsd  (%rsp),%xmm0
call   1040 <printf@plt>
lea    0xee9(%rip),%rdi
movsd  0x8(%rsp),%xmm0
call   1040 <printf@plt>
lea    0xf08(%rip),%rdi
call   1040 <printf@plt>
lea    0xf2b(%rip),%rdi
call   1040 <printf@plt>
xorpd  %xmm0,%xmm0
lea    0xf45(%rip),%rdi
call   1040 <printf@plt>
xorpd  %xmm0,%xmm0
lea    0xf54(%rip),%rdi
call   1040 <printf@plt>
lea    0xdf7(%rip),%rax
movq   $0x0,0x18(%rsp)
movq   $0x0,0x10(%rsp)
mov    %rax,%rdi
lea    0xde9(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
lea    0xdc9(%rip),%r15
je     1281 <main+0x121>
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
call   1060 <sscanf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   1060 <sscanf@plt>
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %rbp,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    1250 <main+0xf0>
mov    %rbp,%rdi
call   1030 <fclose@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
lea    0xd66(%rip),%rdi
lea    0xd6d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
xorpd  %xmm0,%xmm0
test   %rax,%rax
je     1190 <main+0x30>
movsd  %xmm0,(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
lea    0xd34(%rip),%rbp
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r13,%rdx
call   1060 <sscanf@plt>
movsd  (%rsp),%xmm0
addsd  0x18(%rsp),%xmm0
movsd  %xmm0,(%rsp)
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   1060 <sscanf@plt>
movsd  0x8(%rsp),%xmm0
addsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    12e0 <main+0x180>
jmp    119f <main+0x3f>

LLVM IR (-O0):
@main.peak_bandwidth = internal global double 0.000000e+00
@.str = [14 x i8] c"/proc/net/dev\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [17 x i8] c"%*[ ]%*s%*[ ]%lf\00"
@.str.3 = [89 x i8] c"%*[ ]%*s%*[ ]%*lf%*[ ]%*lf%*[ ]%*lf%*[ ]%*lf%*[ ]%*lf%*[ ]%*lf%*[ ]%*lf%*[ ]%*lf%*[ ]%lf\00"
@.str.4 = [46 x i8] c"\0A The total number of bytes received was: %lf\00"
@.str.5 = [49 x i8] c"\0A The total number of bytes transmitted was: %lf\00"
@.str.6 = [47 x i8] c"\0A The relative network activity was: %lf Bytes\00"
@.str.7 = [42 x i8] c"\0A The bandwidth was: %lf bits per second\0A\00"
@.str.8 = [31 x i8] c"\0A The PEAK bandwidth was: %lf \00"
@.str.9 = [54 x i8] c"\0A The proprortional bandwidth of the peak is: %lf %%\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca [2 x double]
%7 = alloca double
%8 = alloca double
%9 = alloca i32
%10 = alloca i32*
%11 = alloca [256 x i8]
%12 = alloca double
store i32 0, i32* %1
br label %13
13: ; preds = %0, %72
store double 0.000000e+00, double* %2
store double 0.000000e+00, double* %3
store double 0.000000e+00, double* %4
store double 0.000000e+00, double* %5
store double 0.000000e+00, double* %7
store double 0.000000e+00, double* %8
store i32 1, i32* %9
br label %14
14: ; preds = %49, %13
%15 = load i32, i32* %9
%16 = icmp slt i32 %15, 3
br i1 %16, label %17, label %51
17: ; preds = %14
%18 = 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* %18, i32** %10
br label %19
19: ; preds = %24, %17
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%21 = load i32*, i32** %10
%22 = call i64 @fgets(i8* %20, i32 256, i32* %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %35
24: ; preds = %19
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%26 = call i32 @sscanf(i8* %25, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), double* %2)
%27 = load double, double* %4
%28 = load double, double* %2
%29 = fadd double %27, %28
store double %29, double* %4
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%31 = call i32 @sscanf(i8* %30, i8* getelementptr inbounds ([89 x i8], [89 x i8]* @.str.3, i64 0, i64 0), double* %3)
%32 = load double, double* %5
%33 = load double, double* %3
%34 = fadd double %32, %33
store double %34, double* %5
br label %19
35: ; preds = %19
%36 = load double, double* %4
%37 = load double, double* %5
%38 = fadd double %36, %37
%39 = load i32, i32* %9
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [2 x double], [2 x double]* %6, i64 0, i64 %40
store double %38, double* %41
%42 = load i32, i32* %9
%43 = add nsw i32 %42, 1
store i32 %43, i32* %9
%44 = load i32*, i32** %10
%45 = call i32 @fclose(i32* %44)
%46 = load i32, i32* %9
%47 = icmp eq i32 %46, 3
br i1 %47, label %48, label %49
48: ; preds = %35
br label %51
49: ; preds = %35
store double 0.000000e+00, double* %4
store double 0.000000e+00, double* %5
%50 = call i32 @sleep(i32 1)
br label %14
51: ; preds = %48, %14
%52 = getelementptr inbounds [2 x double], [2 x double]* %6, i64 0, i64 2
%53 = load double, double* %52
%54 = getelementptr inbounds [2 x double], [2 x double]* %6, i64 0, i64 1
%55 = load double, double* %54
%56 = fsub double %53, %55
store double %56, double* %12
%57 = load double, double* %12
%58 = fmul double %57, 8.000000e+00
store double %58, double* %7
%59 = load double, double* %7
%60 = load double, double* @main.peak_bandwidth
%61 = fcmp ogt double %59, %60
br i1 %61, label %62, label %64
62: ; preds = %51
%63 = load double, double* %7
store double %63, double* @main.peak_bandwidth
br label %64
64: ; preds = %62, %51
%65 = load double, double* @main.peak_bandwidth
%66 = fcmp ogt double %65, 0.000000e+00
br i1 %66, label %67, label %72
67: ; preds = %64
%68 = load double, double* %7
%69 = load double, double* @main.peak_bandwidth
%70 = fdiv double %68, %69
%71 = fmul double %70, 1.000000e+02
store double %71, double* %8
br label %72
72: ; preds = %67, %64
%73 = load double, double* %4
%74 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), double %73)
%75 = load double, double* %5
%76 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.5, i64 0, i64 0), double %75)
%77 = load double, double* %12
%78 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.6, i64 0, i64 0), double %77)
%79 = load double, double* %7
%80 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0), double %79)
%81 = load double, double* @main.peak_bandwidth
%82 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0), double %81)
%83 = load double, double* %8
%84 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.9, i64 0, i64 0), double %83)
br label %13
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/net/dev\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [17 x i8] c"%*[ ]%*s%*[ ]%lf\00"
@.str.3 = [89 x i8] c"%*[ ]%*s%*[ ]%*lf%*[ ]%*lf%*[ ]%*lf%*[ ]%*lf%*[ ]%*lf%*[ ]%*lf%*[ ]%*lf%*[ ]%*lf%*[ ]%lf\00"
@.str.4 = [46 x i8] c"\0A The total number of bytes received was: %lf\00"
@.str.5 = [49 x i8] c"\0A The total number of bytes transmitted was: %lf\00"
@.str.6 = [47 x i8] c"\0A The relative network activity was: %lf Bytes\00"
@.str.7 = [42 x i8] c"\0A The bandwidth was: %lf bits per second\0A\00"
@.str.8 = [31 x i8] c"\0A The PEAK bandwidth was: %lf \00"
@.str.9 = [54 x i8] c"\0A The proprortional bandwidth of the peak is: %lf %%\0A\00"
define i32 @main() {
%1 = alloca double
%2 = alloca double
%3 = alloca [256 x i8]
%4 = bitcast double* %1 to i8*
%5 = bitcast double* %2 to i8*
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
br label %7
7: ; preds = %0, %33
store double 0.000000e+00, double* %1
store double 0.000000e+00, double* %2
%8 = 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))
%9 = call i64 @fgets(i8* %6, i32 256, i32* %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %16, label %11
11: ; preds = %7, %11
%12 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), double* %1)
%13 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([89 x i8], [89 x i8]* @.str.3, i64 0, i64 0), double* %2)
%14 = call i64 @fgets(i8* %6, i32 256, i32* %8)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %11
16: ; preds = %11, %7
%17 = call i32 @fclose(i32* %8)
%18 = call i32 @sleep(i32 1)
%19 = 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))
%20 = call i64 @fgets(i8* %6, i32 256, i32* %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %33, label %22
22: ; preds = %16, %22
%23 = phi double [ %27, %22 ], [ 0.000000e+00, %16 ]
%24 = phi double [ %30, %22 ], [ 0.000000e+00, %16 ]
%25 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), double* %1)
%26 = load double, double* %1
%27 = fadd double %23, %26
%28 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([89 x i8], [89 x i8]* @.str.3, i64 0, i64 0), double* %2)
%29 = load double, double* %2
%30 = fadd double %24, %29
%31 = call i64 @fgets(i8* %6, i32 256, i32* %19)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %22
33: ; preds = %22, %16
%34 = phi double [ 0.000000e+00, %16 ], [ %30, %22 ]
%35 = phi double [ 0.000000e+00, %16 ], [ %27, %22 ]
%36 = call i32 @fclose(i32* %19)
%37 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), double %35)
%38 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.5, i64 0, i64 0), double %34)
%39 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.6, i64 0, i64 0), double poison)
%40 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0), double poison)
%41 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0), double 0.000000e+00)
%42 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.9, i64 0, i64 0), double 0.000000e+00)
br label %7
}