#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 *, char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ stdout;
char *get_netusage(char *netdevice) {
  unsigned long long int oldrec, oldsent, newrec, newsent;
  double downspeed, upspeed;
  char *downspeedstr = NULL;
  char *upspeedstr = NULL;
  char *retstr;
  int retval;
  retval = parse_netdev(&oldrec, &oldsent, netdevice);
  if (retval) {
    fprintf(stdout, "Error when parsing /proc/net/dev file.\n");
    exit(1);
  }
  sleep(1);
  retval = parse_netdev(&newrec, &newsent, netdevice);
  if (retval) {
    fprintf(stdout, "Error when parsing /proc/net/dev file.\n");
    exit(1);
  }
  downspeedstr = (char *)malloc(15);
  upspeedstr = (char *)malloc(15);
  retstr = (char *)malloc(42);
  downspeed = (newrec - oldrec) / 1024.0;
  if (downspeed > 1024.0) {
    downspeed /= 1024.0;
    sprintf(downspeedstr, "%.3fMB/s", downspeed);
  } else {
    sprintf(downspeedstr, "%.2fKB/s", downspeed);
  }
  upspeed = (newsent - oldsent) / 1024.0;
  if (upspeed > 1024.0) {
    upspeed /= 1024.0;
    sprintf(upspeedstr, "%.3fMB/s", upspeed);
  } else {
    sprintf(upspeedstr, "%.2fKB/s", upspeed);
  }
  sprintf(retstr, "%s: d %s u %s", netdevice, downspeedstr, upspeedstr);
  free(downspeedstr);
  free(upspeedstr);
  return retstr;
}


x86 assembly (clang, -O0):
<get_netusage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
mov    -0x8(%rbp),%rdx
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <parse_netdev@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
je     11c9 <get_netusage+0x59>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
lea    0xe76(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
mov    -0x8(%rbp),%rdx
lea    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1060 <parse_netdev@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
je     1210 <get_netusage+0xa0>
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
lea    0xe2f(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    $0xf,%edi
mov    %edi,-0x58(%rbp)
call   1050 <malloc@plt>
mov    -0x58(%rbp),%edi
mov    %rax,-0x40(%rbp)
call   1050 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    $0x2a,%edi
call   1050 <malloc@plt>
mov    %rax,-0x50(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
movq   %rax,%xmm0
movaps 0xdbe(%rip),%xmm1
punpckldq %xmm1,%xmm0
movapd 0xdc2(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xd8b(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xd75(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    12c7 <get_netusage+0x157>
movsd  -0x30(%rbp),%xmm0
movsd  0xd5e(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x40(%rbp),%rdi
movsd  -0x30(%rbp),%xmm0
lea    0xd9d(%rip),%rsi
mov    $0x1,%al
call   1070 <sprintf@plt>
jmp    12de <get_netusage+0x16e>
mov    -0x40(%rbp),%rdi
movsd  -0x30(%rbp),%xmm0
lea    0xd8a(%rip),%rsi
mov    $0x1,%al
call   1070 <sprintf@plt>
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
movq   %rax,%xmm0
movaps 0xd1b(%rip),%xmm1
punpckldq %xmm1,%xmm0
movapd 0xd1f(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xce8(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  0xcd2(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    136a <get_netusage+0x1fa>
movsd  -0x38(%rbp),%xmm0
movsd  0xcbb(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x48(%rbp),%rdi
movsd  -0x38(%rbp),%xmm0
lea    0xcfa(%rip),%rsi
mov    $0x1,%al
call   1070 <sprintf@plt>
jmp    1381 <get_netusage+0x211>
mov    -0x48(%rbp),%rdi
movsd  -0x38(%rbp),%xmm0
lea    0xce7(%rip),%rsi
mov    $0x1,%al
call   1070 <sprintf@plt>
mov    -0x50(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x40(%rbp),%rcx
mov    -0x48(%rbp),%r8
lea    0xcd2(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x50(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_netusage>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%r14
lea    0x20(%rsp),%rdi
lea    0x18(%rsp),%rsi
mov    %r14,%rdx
call   1060 <parse_netdev@plt>
test   %eax,%eax
jne    12da <get_netusage+0x16a>
mov    $0x1,%edi
call   1090 <sleep@plt>
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
mov    %r14,%rdx
call   1060 <parse_netdev@plt>
test   %eax,%eax
jne    12da <get_netusage+0x16a>
mov    $0xf,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    $0xf,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    $0x2a,%edi
call   1050 <malloc@plt>
mov    0x10(%rsp),%rcx
sub    0x20(%rsp),%rcx
movq   %rcx,%xmm1
punpckldq 0xe09(%rip),%xmm1
subpd  0xe11(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
mulsd  0xe0d(%rip),%xmm0
mov    %rax,%r12
ucomisd 0xe0a(%rip),%xmm0
jbe    1231 <get_netusage+0xc1>
mulsd  0xdf8(%rip),%xmm0
lea    0xe29(%rip),%rsi
jmp    1238 <get_netusage+0xc8>
lea    0xe29(%rip),%rsi
mov    %r15,%rdi
mov    $0x1,%al
call   1070 <sprintf@plt>
mov    0x8(%rsp),%rax
sub    0x18(%rsp),%rax
movq   %rax,%xmm1
punpckldq 0xda7(%rip),%xmm1
subpd  0xdaf(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
mulsd  0xdab(%rip),%xmm0
ucomisd 0xdab(%rip),%xmm0
jbe    1290 <get_netusage+0x120>
mulsd  0xd99(%rip),%xmm0
lea    0xdca(%rip),%rsi
jmp    1297 <get_netusage+0x127>
lea    0xdca(%rip),%rsi
mov    %rbx,%rdi
mov    $0x1,%al
call   1070 <sprintf@plt>
lea    0xdc2(%rip),%rsi
mov    %r12,%rdi
mov    %r14,%rdx
mov    %r15,%rcx
mov    %rbx,%r8
xor    %eax,%eax
call   1070 <sprintf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r12,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2cff(%rip),%rax
mov    (%rax),%edi
lea    0xd46(%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 = [9 x i8] c"%.3fMB/s\00"
@.str.2 = [9 x i8] c"%.2fKB/s\00"
@.str.3 = [14 x i8] c"%s: d %s u %s\00"
define i8* @get_netusage(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca double
%8 = alloca double
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
store i8* %0, i8** %2
store i8* null, i8** %9
store i8* null, i8** %10
%13 = load i8*, i8** %2
%14 = call i32 @parse_netdev(i64* %3, i64* %4, i8* %13)
store i32 %14, i32* %12
%15 = load i32, i32* %12
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %1
%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 = %1
%22 = call i32 @sleep(i32 1)
%23 = load i8*, i8** %2
%24 = call i32 @parse_netdev(i64* %5, i64* %6, i8* %23)
store i32 %24, i32* %12
%25 = load i32, i32* %12
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %21
%28 = load i32, i32* @stdout
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %21
%32 = call i64 @malloc(i32 15)
%33 = inttoptr i64 %32 to i8*
store i8* %33, i8** %9
%34 = call i64 @malloc(i32 15)
%35 = inttoptr i64 %34 to i8*
store i8* %35, i8** %10
%36 = call i64 @malloc(i32 42)
%37 = inttoptr i64 %36 to i8*
store i8* %37, i8** %11
%38 = load i64, i64* %5
%39 = load i64, i64* %3
%40 = sub i64 %38, %39
%41 = uitofp i64 %40 to double
%42 = fdiv double %41, 1.024000e+03
store double %42, double* %7
%43 = load double, double* %7
%44 = fcmp ogt double %43, 1.024000e+03
br i1 %44, label %45, label %51
45: ; preds = %31
%46 = load double, double* %7
%47 = fdiv double %46, 1.024000e+03
store double %47, double* %7
%48 = load i8*, i8** %9
%49 = load double, double* %7
%50 = call i32 (i8*, i8*, ...) @sprintf(i8* %48, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), double %49)
br label %55
51: ; preds = %31
%52 = load i8*, i8** %9
%53 = load double, double* %7
%54 = call i32 (i8*, i8*, ...) @sprintf(i8* %52, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), double %53)
br label %55
55: ; preds = %51, %45
%56 = load i64, i64* %6
%57 = load i64, i64* %4
%58 = sub i64 %56, %57
%59 = uitofp i64 %58 to double
%60 = fdiv double %59, 1.024000e+03
store double %60, double* %8
%61 = load double, double* %8
%62 = fcmp ogt double %61, 1.024000e+03
br i1 %62, label %63, label %69
63: ; preds = %55
%64 = load double, double* %8
%65 = fdiv double %64, 1.024000e+03
store double %65, double* %8
%66 = load i8*, i8** %10
%67 = load double, double* %8
%68 = call i32 (i8*, i8*, ...) @sprintf(i8* %66, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), double %67)
br label %73
69: ; preds = %55
%70 = load i8*, i8** %10
%71 = load double, double* %8
%72 = call i32 (i8*, i8*, ...) @sprintf(i8* %70, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), double %71)
br label %73
73: ; preds = %69, %63
%74 = load i8*, i8** %11
%75 = load i8*, i8** %2
%76 = load i8*, i8** %9
%77 = load i8*, i8** %10
%78 = call i32 (i8*, i8*, ...) @sprintf(i8* %74, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %75, i8* %76, i8* %77)
%79 = load i8*, i8** %9
%80 = call i32 @free(i8* %79)
%81 = load i8*, i8** %10
%82 = call i32 @free(i8* %81)
%83 = load i8*, i8** %11
ret i8* %83
}

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