#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*/ asprintf(char **, char const *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, long long *);
unsigned long long getRxBytesForInterface(char *interface) {
  const char *rx_str_fmt = "/sys/class/net/%s/statistics/rx_bytes";
  char *rx_str = NULL;
  FILE *file;
  long long rxValue = -1;
  if (interface) {
    asprintf(&rx_str, rx_str_fmt, interface);
    if (rx_str) {
      file = fopen(rx_str, "r");
      if (file) {
        fscanf(file, "%lld", &rxValue);
        fclose(file);
      }
      free(rx_str);
    }
  }
  return rxValue;
}


x86 assembly (clang, -O0):
<getRxBytesForInterface>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe9d(%rip),%rax
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0xffffffffffffffff,-0x28(%rbp)
ff
cmpq   $0x0,-0x8(%rbp)
je     11e8 <getRxBytesForInterface+0x98>
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%rdx
lea    -0x18(%rbp),%rdi
call   1060 <asprintf@plt>
cmpq   $0x0,-0x18(%rbp)
je     11e3 <getRxBytesForInterface+0x93>
mov    -0x18(%rbp),%rdi
lea    0xe7d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11da <getRxBytesForInterface+0x8a>
mov    -0x20(%rbp),%rdi
lea    0xe60(%rip),%rsi
lea    -0x28(%rbp),%rdx
call   1050 <fscanf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
jmp    11e8 <getRxBytesForInterface+0x98>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getRxBytesForInterface>:
push   %rbx
sub    $0x10,%rsp
movq   $0x0,(%rsp)
movq   $0xffffffffffffffff,0x8(%rsp)
ff ff
mov    $0xffffffffffffffff,%rbx
test   %rdi,%rdi
je     11cb <getRxBytesForInterface+0x7b>
mov    %rdi,%rdx
lea    0xe84(%rip),%rsi
mov    %rsp,%rdi
call   1060 <asprintf@plt>
mov    (%rsp),%rdi
test   %rdi,%rdi
je     11cb <getRxBytesForInterface+0x7b>
lea    0xe92(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11bd <getRxBytesForInterface+0x6d>
mov    %rax,%rbx
lea    0xe80(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %rax,%rdi
call   1050 <fscanf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rbx
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [38 x i8] c"/sys/class/net/%s/statistics/rx_bytes\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [5 x i8] c"%lld\00"
define i64 @getRxBytesForInterface(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i64
store i8* %0, i8** %2
store i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8** %3
store i8* null, i8** %4
store i64 -1, i64* %6
%7 = load i8*, i8** %2
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %29
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = load i8*, i8** %2
%12 = call i32 @asprintf(i8** %4, i8* %10, i8* %11)
%13 = load i8*, i8** %4
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %28
15: ; preds = %9
%16 = load i8*, i8** %4
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %17, i32** %5
%18 = load i32*, i32** %5
%19 = icmp ne i32* %18, null
br i1 %19, label %20, label %25
20: ; preds = %15
%21 = load i32*, i32** %5
%22 = call i32 @fscanf(i32* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64* %6)
%23 = load i32*, i32** %5
%24 = call i32 @fclose(i32* %23)
br label %25
25: ; preds = %20, %15
%26 = load i8*, i8** %4
%27 = call i32 @free(i8* %26)
br label %28
28: ; preds = %25, %9
br label %29
29: ; preds = %28, %1
%30 = load i64, i64* %6
ret i64 %30
}

LLVM IR (-O2):
@.str = [38 x i8] c"/sys/class/net/%s/statistics/rx_bytes\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [5 x i8] c"%lld\00"
define i64 @getRxBytesForInterface(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%5 = bitcast i64* %3 to i8*
store i64 -1, i64* %3
%6 = icmp eq i8* %0, null
br i1 %6, label %21, label %7
7: ; preds = %1
%8 = call i32 @asprintf(i8** %2, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %0)
%9 = load i8*, i8** %2
%10 = icmp eq i8* %9, null
br i1 %10, label %21, label %11
11: ; preds = %7
%12 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = call i32 @fscanf(i32* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64* %3)
%16 = call i32 @fclose(i32* %12)
br label %17
17: ; preds = %14, %11
%18 = load i8*, i8** %2
%19 = call i32 @free(i8* %18)
%20 = load i64, i64* %3
br label %21
21: ; preds = %7, %17, %1
%22 = phi i64 [ -1, %7 ], [ %20, %17 ], [ -1, %1 ]
ret i64 %22
}