#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 time_t;

/* Variables and functions */
int /*<<< orphan*/ cache_netdev(unsigned long long *, unsigned long long *,
                                unsigned long long *, unsigned long long *,
                                int *);
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*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ stdout;
int time(int /*<<< orphan*/ *);
char *get_netusage(char *face) {
  unsigned long long int oldrec, oldsent, newrec, newsent;
  double downspeed, upspeed;
  char *downspeedstr, *upspeedstr;
  char *retstr;
  int retval;
  time_t mtime;
  int interval;
  downspeedstr = (char *)malloc(15);
  upspeedstr = (char *)malloc(15);
  retstr = (char *)malloc(42);
  retval = parse_netdev(&newrec, &newsent, face);
  if (retval) {
    fprintf(stdout, "Error when parsing /proc/net/dev file.\n");
    exit(1);
  }
  cache_netdev(&newrec, &newsent, &oldrec, &oldsent, &mtime);
  if ((interval = (time(NULL) - mtime)) == 0)
    interval = 1;
  downspeed = (newrec - oldrec) / 1024.0 / interval;
  if (downspeed > 1024.0) {
    downspeed /= 1024.0;
    sprintf(downspeedstr, "%.2fMB/s", downspeed);
  } else {
    sprintf(downspeedstr, "%.0fkB/s", downspeed);
  }
  upspeed = (newsent - oldsent) / 1024.0 / interval;
  if (upspeed > 1024.0) {
    upspeed /= 1024.0;
    sprintf(upspeedstr, "%.2fMB/s", upspeed);
  } else {
    sprintf(upspeedstr, "%.0fkB/s", upspeed);
  }
  sprintf(retstr, "↓%s ↑%s", 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)
mov    $0xf,%edi
call   1070 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    $0xf,%edi
call   1070 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    $0x2a,%edi
call   1070 <malloc@plt>
mov    %rax,-0x50(%rbp)
mov    -0x8(%rbp),%rdx
lea    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1080 <parse_netdev@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
je     11f3 <get_netusage+0x73>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
lea    0xe4c(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
lea    -0x10(%rbp),%rdx
lea    -0x18(%rbp),%rcx
lea    -0x58(%rbp),%r8
call   1040 <cache_netdev@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
sub    -0x58(%rbp),%eax
mov    %eax,-0x5c(%rbp)
cmp    $0x0,%eax
jne    122b <get_netusage+0xab>
movl   $0x1,-0x5c(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
movq   %rax,%xmm0
movaps 0xdce(%rip),%xmm1
punpckldq %xmm1,%xmm0
movapd 0xdd2(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xd9b(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsi2sdl -0x5c(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xd7c(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    12c0 <get_netusage+0x140>
movsd  -0x30(%rbp),%xmm0
movsd  0xd65(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x40(%rbp),%rdi
movsd  -0x30(%rbp),%xmm0
lea    0xda4(%rip),%rsi
mov    $0x1,%al
call   1090 <sprintf@plt>
jmp    12d7 <get_netusage+0x157>
mov    -0x40(%rbp),%rdi
movsd  -0x30(%rbp),%xmm0
lea    0xd91(%rip),%rsi
mov    $0x1,%al
call   1090 <sprintf@plt>
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
movq   %rax,%xmm0
movaps 0xd22(%rip),%xmm1
punpckldq %xmm1,%xmm0
movapd 0xd26(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xcef(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsi2sdl -0x5c(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  0xcd0(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    136c <get_netusage+0x1ec>
movsd  -0x38(%rbp),%xmm0
movsd  0xcb9(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x48(%rbp),%rdi
movsd  -0x38(%rbp),%xmm0
lea    0xcf8(%rip),%rsi
mov    $0x1,%al
call   1090 <sprintf@plt>
jmp    1383 <get_netusage+0x203>
mov    -0x48(%rbp),%rdi
movsd  -0x38(%rbp),%xmm0
lea    0xce5(%rip),%rsi
mov    $0x1,%al
call   1090 <sprintf@plt>
mov    -0x50(%rbp),%rdi
mov    -0x40(%rbp),%rdx
mov    -0x48(%rbp),%rcx
lea    0xcd4(%rip),%rsi
mov    $0x0,%al
call   1090 <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    $0x38,%rsp
mov    %rdi,%rbx
mov    $0xf,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    $0xf,%edi
call   1070 <malloc@plt>
mov    %rax,%r12
mov    $0x2a,%edi
call   1070 <malloc@plt>
mov    %rax,%r15
lea    0x18(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %rbx,%rdx
call   1080 <parse_netdev@plt>
test   %eax,%eax
jne    130b <get_netusage+0x18b>
lea    0x18(%rsp),%rdi
lea    0x10(%rsp),%rsi
lea    0x30(%rsp),%rdx
lea    0x28(%rsp),%rcx
lea    0xc(%rsp),%r8
call   1040 <cache_netdev@plt>
xor    %edi,%edi
call   1060 <time@plt>
sub    0xc(%rsp),%eax
mov    $0x1,%ecx
cmovne %eax,%ecx
mov    0x18(%rsp),%rax
sub    0x30(%rsp),%rax
movq   %rax,%xmm1
punpckldq 0xde9(%rip),%xmm1
subpd  0xdf1(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
mulsd  0xded(%rip),%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %ecx,%xmm1
movsd  %xmm1,0x20(%rsp)
divsd  %xmm1,%xmm0
ucomisd 0xddc(%rip),%xmm0
jbe    125f <get_netusage+0xdf>
mulsd  0xdca(%rip),%xmm0
lea    0xdfb(%rip),%rsi
jmp    1266 <get_netusage+0xe6>
lea    0xdfb(%rip),%rsi
mov    %r14,%rdi
mov    $0x1,%al
call   1090 <sprintf@plt>
mov    0x10(%rsp),%rax
sub    0x28(%rsp),%rax
movq   %rax,%xmm1
punpckldq 0xd79(%rip),%xmm1
subpd  0xd81(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
mulsd  0xd7d(%rip),%xmm0
divsd  0x20(%rsp),%xmm0
ucomisd 0xd77(%rip),%xmm0
jbe    12c4 <get_netusage+0x144>
mulsd  0xd65(%rip),%xmm0
lea    0xd96(%rip),%rsi
jmp    12cb <get_netusage+0x14b>
lea    0xd96(%rip),%rsi
mov    %r12,%rdi
mov    $0x1,%al
call   1090 <sprintf@plt>
lea    0xd8e(%rip),%rsi
mov    %r15,%rdi
mov    %r14,%rdx
mov    %r12,%rcx
xor    %eax,%eax
call   1090 <sprintf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r15,%rax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2cce(%rip),%rax
mov    (%rax),%edi
lea    0xd15(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <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"%.2fMB/s\00"
@.str.2 = [9 x i8] c"%.0fkB/s\00"
@.str.3 = [12 x i8] c"\E2\86\93%s \E2\86\91%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
%13 = alloca i32
%14 = alloca i32
store i8* %0, i8** %2
%15 = call i64 @malloc(i32 15)
%16 = inttoptr i64 %15 to i8*
store i8* %16, i8** %9
%17 = call i64 @malloc(i32 15)
%18 = inttoptr i64 %17 to i8*
store i8* %18, i8** %10
%19 = call i64 @malloc(i32 42)
%20 = inttoptr i64 %19 to i8*
store i8* %20, i8** %11
%21 = load i8*, i8** %2
%22 = call i32 @parse_netdev(i64* %5, i64* %6, i8* %21)
store i32 %22, i32* %12
%23 = load i32, i32* %12
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %1
%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 = %1
%30 = call i32 @cache_netdev(i64* %5, i64* %6, i64* %3, i64* %4, i32* %13)
%31 = call i32 @time(i32* null)
%32 = load i32, i32* %13
%33 = sub nsw i32 %31, %32
store i32 %33, i32* %14
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %29
store i32 1, i32* %14
br label %36
36: ; preds = %35, %29
%37 = load i64, i64* %5
%38 = load i64, i64* %3
%39 = sub i64 %37, %38
%40 = uitofp i64 %39 to double
%41 = fdiv double %40, 1.024000e+03
%42 = load i32, i32* %14
%43 = sitofp i32 %42 to double
%44 = fdiv double %41, %43
store double %44, double* %7
%45 = load double, double* %7
%46 = fcmp ogt double %45, 1.024000e+03
br i1 %46, label %47, label %53
47: ; preds = %36
%48 = load double, double* %7
%49 = fdiv double %48, 1.024000e+03
store double %49, double* %7
%50 = load i8*, i8** %9
%51 = load double, double* %7
%52 = call i32 (i8*, i8*, ...) @sprintf(i8* %50, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), double %51)
br label %57
53: ; preds = %36
%54 = load i8*, i8** %9
%55 = load double, double* %7
%56 = call i32 (i8*, i8*, ...) @sprintf(i8* %54, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), double %55)
br label %57
57: ; preds = %53, %47
%58 = load i64, i64* %6
%59 = load i64, i64* %4
%60 = sub i64 %58, %59
%61 = uitofp i64 %60 to double
%62 = fdiv double %61, 1.024000e+03
%63 = load i32, i32* %14
%64 = sitofp i32 %63 to double
%65 = fdiv double %62, %64
store double %65, double* %8
%66 = load double, double* %8
%67 = fcmp ogt double %66, 1.024000e+03
br i1 %67, label %68, label %74
68: ; preds = %57
%69 = load double, double* %8
%70 = fdiv double %69, 1.024000e+03
store double %70, double* %8
%71 = load i8*, i8** %10
%72 = load double, double* %8
%73 = call i32 (i8*, i8*, ...) @sprintf(i8* %71, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), double %72)
br label %78
74: ; preds = %57
%75 = load i8*, i8** %10
%76 = load double, double* %8
%77 = call i32 (i8*, i8*, ...) @sprintf(i8* %75, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), double %76)
br label %78
78: ; preds = %74, %68
%79 = load i8*, i8** %11
%80 = load i8*, i8** %9
%81 = load i8*, i8** %10
%82 = call i32 (i8*, i8*, ...) @sprintf(i8* %79, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %80, i8* %81)
%83 = load i8*, i8** %9
%84 = call i32 @free(i8* %83)
%85 = load i8*, i8** %10
%86 = call i32 @free(i8* %85)
%87 = load i8*, i8** %11
ret i8* %87
}

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"%.2fMB/s\00"
@.str.2 = [9 x i8] c"%.0fkB/s\00"
@.str.3 = [12 x i8] c"\E2\86\93%s \E2\86\91%s\00"
define i8* @get_netusage(i8* %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32
%7 = bitcast i64* %2 to i8*
%8 = bitcast i64* %3 to i8*
%9 = bitcast i64* %4 to i8*
%10 = bitcast i64* %5 to i8*
%11 = bitcast i32* %6 to i8*
%12 = tail call i64 @malloc(i32 15)
%13 = inttoptr i64 %12 to i8*
%14 = tail call i64 @malloc(i32 15)
%15 = inttoptr i64 %14 to i8*
%16 = tail call i64 @malloc(i32 42)
%17 = inttoptr i64 %16 to i8*
%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 = %1
%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 = %1
%25 = call i32 @cache_netdev(i64* %4, i64* %5, i64* %2, i64* %3, i32* %6)
%26 = call i32 @time(i32* null)
%27 = load i32, i32* %6
%28 = sub nsw i32 %26, %27
%29 = icmp eq i32 %28, 0
%30 = select i1 %29, i32 1, i32 %28
%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 = sitofp i32 %30 to double
%37 = fdiv double %35, %36
%38 = fcmp ogt double %37, 1.024000e+03
br i1 %38, label %39, label %42
39: ; preds = %24
%40 = fmul double %37, 0x3F50000000000000
%41 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %13, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), double %40)
br label %44
42: ; preds = %24
%43 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %13, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), double %37)
br label %44
44: ; preds = %42, %39
%45 = load i64, i64* %5
%46 = load i64, i64* %3
%47 = sub i64 %45, %46
%48 = uitofp i64 %47 to double
%49 = fmul double %48, 0x3F50000000000000
%50 = fdiv double %49, %36
%51 = fcmp ogt double %50, 1.024000e+03
br i1 %51, label %52, label %55
52: ; preds = %44
%53 = fmul double %50, 0x3F50000000000000
%54 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %15, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), double %53)
br label %57
55: ; preds = %44
%56 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %15, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), double %50)
br label %57
57: ; preds = %55, %52
%58 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %17, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %13, i8* %15)
%59 = call i32 @free(i8* %13)
%60 = call i32 @free(i8* %15)
ret i8* %17
}