#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*/ calculate_speed(char *, unsigned long long,
                                   unsigned long long);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int parse_netdev(unsigned long long *, unsigned long long *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int /*<<< orphan*/ stdout;
char *get_netusage(unsigned long long int *rec, unsigned long long int *sent) {
  unsigned long long int newrec, newsent;
  newrec = newsent = 0;
  char downspeedstr[15], upspeedstr[15];
  static char retstr[42];
  int retval;
  retval = parse_netdev(&newrec, &newsent);
  if (retval) {
    fprintf(stdout, "Error when parsing /proc/net/dev file.\n");
    exit(1);
  }
  calculate_speed(downspeedstr, newrec, *rec);
  calculate_speed(upspeedstr, newsent, *sent);
  sprintf(retstr, "down: %s up: %s", downspeedstr, upspeedstr);
  *rec = newrec;
  *sent = newsent;
  return retstr;
}


x86 assembly (clang, -O0):
<get_netusage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <parse_netdev@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
je     11a9 <get_netusage+0x59>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
lea    0xe66(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    -0x2f(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%rax
mov    (%rax),%rdx
call   1030 <calculate_speed@plt>
lea    -0x3e(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
call   1030 <calculate_speed@plt>
lea    -0x2f(%rbp),%rdx
lea    -0x3e(%rbp),%rcx
lea    0x2e80(%rip),%rdi
lea    0xe41(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
lea    0x2e57(%rip),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_netusage>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
movq   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rdi
mov    %rsp,%rsi
call   1050 <parse_netdev@plt>
test   %eax,%eax
jne    11ea <get_netusage+0x9a>
mov    0x8(%rsp),%rsi
mov    (%rbx),%rdx
lea    0x21(%rsp),%r15
mov    %r15,%rdi
call   1030 <calculate_speed@plt>
mov    (%rsp),%rsi
mov    (%r14),%rdx
lea    0x12(%rsp),%r12
mov    %r12,%rdi
call   1030 <calculate_speed@plt>
lea    0x2eab(%rip),%r13
lea    0xe6c(%rip),%rsi
mov    %r13,%rdi
mov    %r15,%rdx
mov    %r12,%rcx
call   1060 <sprintf@plt>
mov    0x8(%rsp),%rax
mov    %rax,(%rbx)
mov    (%rsp),%rax
mov    %rax,(%r14)
mov    %r13,%rax
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    0x2def(%rip),%rax
mov    (%rax),%edi
lea    0xe06(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@get_netusage.retstr = internal global [42 x i8] zeroinitializer
@stdout = global i32 0
@.str = [40 x i8] c"Error when parsing /proc/net/dev file.\0A\00"
@.str.1 = [16 x i8] c"down: %s up: %s\00"
define i8* @get_netusage(i64* %0, i64* %1) {
%3 = alloca i64*
%4 = alloca i64*
%5 = alloca i64
%6 = alloca i64
%7 = alloca [15 x i8]
%8 = alloca [15 x i8]
%9 = alloca i32
store i64* %0, i64** %3
store i64* %1, i64** %4
store i64 0, i64* %6
store i64 0, i64* %5
%10 = call i32 @parse_netdev(i64* %5, i64* %6)
store i32 %10, i32* %9
%11 = load i32, i32* %9
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i32, i32* @stdout
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = getelementptr inbounds [15 x i8], [15 x i8]* %7, i64 0, i64 0
%19 = load i64, i64* %5
%20 = load i64*, i64** %3
%21 = load i64, i64* %20
%22 = call i32 @calculate_speed(i8* %18, i64 %19, i64 %21)
%23 = getelementptr inbounds [15 x i8], [15 x i8]* %8, i64 0, i64 0
%24 = load i64, i64* %6
%25 = load i64*, i64** %4
%26 = load i64, i64* %25
%27 = call i32 @calculate_speed(i8* %23, i64 %24, i64 %26)
%28 = getelementptr inbounds [15 x i8], [15 x i8]* %7, i64 0, i64 0
%29 = getelementptr inbounds [15 x i8], [15 x i8]* %8, i64 0, i64 0
%30 = call i32 @sprintf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @get_netusage.retstr, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %28, i8* %29)
%31 = load i64, i64* %5
%32 = load i64*, i64** %3
store i64 %31, i64* %32
%33 = load i64, i64* %6
%34 = load i64*, i64** %4
store i64 %33, i64* %34
ret i8* getelementptr inbounds ([42 x i8], [42 x i8]* @get_netusage.retstr, i64 0, i64 0)
}

LLVM IR (-O2):
@get_netusage.retstr = internal global [42 x i8] zeroinitializer
@stdout = global i32 0
@.str = [40 x i8] c"Error when parsing /proc/net/dev file.\0A\00"
@.str.1 = [16 x i8] c"down: %s up: %s\00"
define i8* @get_netusage(i64* nocapture %0, i64* nocapture %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca [15 x i8]
%6 = alloca [15 x i8]
%7 = bitcast i64* %3 to i8*
%8 = bitcast i64* %4 to i8*
store i64 0, i64* %4
store i64 0, i64* %3
%9 = getelementptr inbounds [15 x i8], [15 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds [15 x i8], [15 x i8]* %6, i64 0, i64 0
%11 = call i32 @parse_netdev(i64* %3, i64* %4)
%12 = icmp eq i32 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %2
%14 = load i32, i32* @stdout
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = load i64, i64* %3
%19 = load i64, i64* %0
%20 = call i32 @calculate_speed(i8* %9, i64 %18, i64 %19)
%21 = load i64, i64* %4
%22 = load i64, i64* %1
%23 = call i32 @calculate_speed(i8* %10, i64 %21, i64 %22)
%24 = call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @get_netusage.retstr, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %9, i8* %10)
%25 = load i64, i64* %3
store i64 %25, i64* %0
%26 = load i64, i64* %4
store i64 %26, i64* %1
ret i8* getelementptr inbounds ([42 x i8], [42 x i8]* @get_netusage.retstr, i64 0, i64 0)
}