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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int parse_netdev(unsigned long long *, unsigned long long *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ stdout;
char *get_netusage() {
  unsigned long long int oldrec, oldsent, newrec, newsent;
  double downspeed, upspeed;
  char *downspeedstr, *upspeedstr;
  char *retstr;
  int retval;
  downspeedstr = (char *)malloc(15);
  upspeedstr = (char *)malloc(15);
  retstr = (char *)malloc(42);
  retval = parse_netdev(&oldrec, &oldsent);
  if (retval) {
    fprintf(stdout, "Error when parsing /proc/net/dev file.\n");
    exit(1);
  }
  sleep(1);
  retval = parse_netdev(&newrec, &newsent);
  if (retval) {
    fprintf(stdout, "Error when parsing /proc/net/dev file.\n");
    exit(1);
  }
  downspeed = (newrec - oldrec) / 1024.0;
  if (downspeed > 1024.0) {
    downspeed /= 1024.0;
    sprintf(downspeedstr, "%.3f MB/s", downspeed);
  } else {
    sprintf(downspeedstr, "%.2f KB/s", downspeed);
  }
  upspeed = (newsent - oldsent) / 1024.0;
  if (upspeed > 1024.0) {
    upspeed /= 1024.0;
    sprintf(upspeedstr, "%.3f MB/s", upspeed);
  } else {
    sprintf(upspeedstr, "%.2f KB/s", upspeed);
  }
  sprintf(retstr, "down: %s up: %s", downspeedstr, upspeedstr);
  free(downspeedstr);
  free(upspeedstr);
  return retstr;
}


x86 assembly (clang, -O0):
<get_netusage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    $0xf,%edi
call   1050 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    $0xf,%edi
call   1050 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    $0x2a,%edi
call   1050 <malloc@plt>
mov    %rax,-0x48(%rbp)
lea    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1060 <parse_netdev@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
je     11db <get_netusage+0x6b>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
lea    0xe64(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <parse_netdev@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
je     121e <get_netusage+0xae>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
lea    0xe21(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
movq   %rax,%xmm0
movaps 0xddb(%rip),%xmm1
punpckldq %xmm1,%xmm0
movapd 0xddf(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xda8(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  0xd92(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    12aa <get_netusage+0x13a>
movsd  -0x28(%rbp),%xmm0
movsd  0xd7b(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x38(%rbp),%rdi
movsd  -0x28(%rbp),%xmm0
lea    0xdba(%rip),%rsi
mov    $0x1,%al
call   1070 <sprintf@plt>
jmp    12c1 <get_netusage+0x151>
mov    -0x38(%rbp),%rdi
movsd  -0x28(%rbp),%xmm0
lea    0xda8(%rip),%rsi
mov    $0x1,%al
call   1070 <sprintf@plt>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
movq   %rax,%xmm0
movaps 0xd38(%rip),%xmm1
punpckldq %xmm1,%xmm0
movapd 0xd3c(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xd05(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xcef(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    134d <get_netusage+0x1dd>
movsd  -0x30(%rbp),%xmm0
movsd  0xcd8(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x40(%rbp),%rdi
movsd  -0x30(%rbp),%xmm0
lea    0xd17(%rip),%rsi
mov    $0x1,%al
call   1070 <sprintf@plt>
jmp    1364 <get_netusage+0x1f4>
mov    -0x40(%rbp),%rdi
movsd  -0x30(%rbp),%xmm0
lea    0xd05(%rip),%rsi
mov    $0x1,%al
call   1070 <sprintf@plt>
mov    -0x48(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    -0x40(%rbp),%rcx
lea    0xcf5(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_netusage>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    $0xf,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    $0xf,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    $0x2a,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
lea    0x18(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1060 <parse_netdev@plt>
test   %eax,%eax
jne    12c7 <get_netusage+0x157>
mov    $0x1,%edi
call   1090 <sleep@plt>
lea    0x8(%rsp),%rdi
mov    %rsp,%rsi
call   1060 <parse_netdev@plt>
test   %eax,%eax
jne    12c7 <get_netusage+0x157>
mov    0x8(%rsp),%rax
sub    0x18(%rsp),%rax
movq   %rax,%xmm1
punpckldq 0xe13(%rip),%xmm1
subpd  0xe1b(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
mulsd  0xe17(%rip),%xmm0
ucomisd 0xe17(%rip),%xmm0
jbe    1224 <get_netusage+0xb4>
mulsd  0xe05(%rip),%xmm0
lea    0xe36(%rip),%rsi
jmp    122b <get_netusage+0xbb>
lea    0xe37(%rip),%rsi
mov    %r14,%rdi
mov    $0x1,%al
call   1070 <sprintf@plt>
mov    (%rsp),%rax
sub    0x10(%rsp),%rax
movq   %rax,%xmm1
punpckldq 0xdb5(%rip),%xmm1
subpd  0xdbd(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
mulsd  0xdb9(%rip),%xmm0
ucomisd 0xdb9(%rip),%xmm0
jbe    1282 <get_netusage+0x112>
mulsd  0xda7(%rip),%xmm0
lea    0xdd8(%rip),%rsi
jmp    1289 <get_netusage+0x119>
lea    0xdd9(%rip),%rsi
mov    %rbx,%rdi
mov    $0x1,%al
call   1070 <sprintf@plt>
lea    0xdd2(%rip),%rsi
mov    %r15,%rdi
mov    %r14,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1070 <sprintf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2d12(%rip),%rax
mov    (%rax),%edi
lea    0xd59(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stdout = global i32 0
@.str = [40 x i8] c"Error when parsing /proc/net/dev file.\0A\00"
@.str.1 = [10 x i8] c"%.3f MB/s\00"
@.str.2 = [10 x i8] c"%.2f KB/s\00"
@.str.3 = [16 x i8] c"down: %s up: %s\00"
define i8* @get_netusage() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca double
%6 = alloca double
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = call i64 @malloc(i32 15)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %7
%13 = call i64 @malloc(i32 15)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %8
%15 = call i64 @malloc(i32 42)
%16 = inttoptr i64 %15 to i8*
store i8* %16, i8** %9
%17 = call i32 @parse_netdev(i64* %1, i64* %2)
store i32 %17, i32* %10
%18 = load i32, i32* %10
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %0
%21 = load i32, i32* @stdout
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %0
%25 = call i32 @sleep(i32 1)
%26 = call i32 @parse_netdev(i64* %3, i64* %4)
store i32 %26, i32* %10
%27 = load i32, i32* %10
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %24
%30 = load i32, i32* @stdout
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %24
%34 = load i64, i64* %3
%35 = load i64, i64* %1
%36 = sub i64 %34, %35
%37 = uitofp i64 %36 to double
%38 = fdiv double %37, 1.024000e+03
store double %38, double* %5
%39 = load double, double* %5
%40 = fcmp ogt double %39, 1.024000e+03
br i1 %40, label %41, label %47
41: ; preds = %33
%42 = load double, double* %5
%43 = fdiv double %42, 1.024000e+03
store double %43, double* %5
%44 = load i8*, i8** %7
%45 = load double, double* %5
%46 = call i32 (i8*, i8*, ...) @sprintf(i8* %44, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), double %45)
br label %51
47: ; preds = %33
%48 = load i8*, i8** %7
%49 = load double, double* %5
%50 = call i32 (i8*, i8*, ...) @sprintf(i8* %48, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), double %49)
br label %51
51: ; preds = %47, %41
%52 = load i64, i64* %4
%53 = load i64, i64* %2
%54 = sub i64 %52, %53
%55 = uitofp i64 %54 to double
%56 = fdiv double %55, 1.024000e+03
store double %56, double* %6
%57 = load double, double* %6
%58 = fcmp ogt double %57, 1.024000e+03
br i1 %58, label %59, label %65
59: ; preds = %51
%60 = load double, double* %6
%61 = fdiv double %60, 1.024000e+03
store double %61, double* %6
%62 = load i8*, i8** %8
%63 = load double, double* %6
%64 = call i32 (i8*, i8*, ...) @sprintf(i8* %62, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), double %63)
br label %69
65: ; preds = %51
%66 = load i8*, i8** %8
%67 = load double, double* %6
%68 = call i32 (i8*, i8*, ...) @sprintf(i8* %66, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), double %67)
br label %69
69: ; preds = %65, %59
%70 = load i8*, i8** %9
%71 = load i8*, i8** %7
%72 = load i8*, i8** %8
%73 = call i32 (i8*, i8*, ...) @sprintf(i8* %70, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %71, i8* %72)
%74 = load i8*, i8** %7
%75 = call i32 @free(i8* %74)
%76 = load i8*, i8** %8
%77 = call i32 @free(i8* %76)
%78 = load i8*, i8** %9
ret i8* %78
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [40 x i8] c"Error when parsing /proc/net/dev file.\0A\00"
@.str.1 = [10 x i8] c"%.3f MB/s\00"
@.str.2 = [10 x i8] c"%.2f KB/s\00"
@.str.3 = [16 x i8] c"down: %s up: %s\00"
define i8* @get_netusage() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = bitcast i64* %1 to i8*
%6 = bitcast i64* %2 to i8*
%7 = bitcast i64* %3 to i8*
%8 = bitcast i64* %4 to i8*
%9 = tail call i64 @malloc(i32 15)
%10 = inttoptr i64 %9 to i8*
%11 = tail call i64 @malloc(i32 15)
%12 = inttoptr i64 %11 to i8*
%13 = tail call i64 @malloc(i32 42)
%14 = inttoptr i64 %13 to i8*
%15 = call i32 @parse_netdev(i64* %1, i64* %2)
%16 = icmp eq i32 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %0
%18 = load i32, i32* @stdout
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %0
%22 = call i32 @sleep(i32 1)
%23 = call i32 @parse_netdev(i64* %3, i64* %4)
%24 = icmp eq i32 %23, 0
br i1 %24, label %29, label %25
25: ; preds = %21
%26 = load i32, i32* @stdout
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %21
%30 = load i64, i64* %3
%31 = load i64, i64* %1
%32 = sub i64 %30, %31
%33 = uitofp i64 %32 to double
%34 = fmul double %33, 0x3F50000000000000
%35 = fcmp ogt double %34, 1.024000e+03
br i1 %35, label %36, label %39
36: ; preds = %29
%37 = fmul double %34, 0x3F50000000000000
%38 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %10, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), double %37)
br label %41
39: ; preds = %29
%40 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %10, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), double %34)
br label %41
41: ; preds = %39, %36
%42 = load i64, i64* %4
%43 = load i64, i64* %2
%44 = sub i64 %42, %43
%45 = uitofp i64 %44 to double
%46 = fmul double %45, 0x3F50000000000000
%47 = fcmp ogt double %46, 1.024000e+03
br i1 %47, label %48, label %51
48: ; preds = %41
%49 = fmul double %46, 0x3F50000000000000
%50 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %12, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), double %49)
br label %53
51: ; preds = %41
%52 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %12, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), double %46)
br label %53
53: ; preds = %51, %48
%54 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %14, i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %10, i8* %12)
%55 = call i32 @free(i8* %10)
%56 = call i32 @free(i8* %12)
ret i8* %14
}