#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 */
long atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *);
long int get_rate() {
  FILE *fo;
  long int valor;
  char cadena[12];
  if ((fo = fopen("/sys/class/net/enp10s0/statistics/rx_bytes", "r")) == NULL) {
    printf("Error, no se ha podido abrir fichero.\n");
    return -1;
  }
  fgets(cadena, 12, fo);
  fclose(fo);
  valor = atoi(cadena);
  return valor;
}


x86 assembly (clang, -O0):
<get_rate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xea1(%rip),%rdi
lea    0xec5(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1192 <get_rate+0x42>
lea    0xead(%rip),%rdi
call   1040 <printf@plt>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    11c2 <get_rate+0x72>
lea    -0x24(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0xc,%esi
call   1050 <fgets@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0x24(%rbp),%rdi
call   1070 <atoi@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_rate>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xea2(%rip),%rdi
lea    0xec6(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1199 <get_rate+0x49>
mov    %rax,%rbx
lea    0xc(%rsp),%r14
mov    %r14,%rdi
mov    $0xc,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1070 <atoi@plt>
jmp    11ac <get_rate+0x5c>
lea    0xe8d(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffffffffffff,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [43 x i8] c"/sys/class/net/enp10s0/statistics/rx_bytes\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [39 x i8] c"Error, no se ha podido abrir fichero.\0A\00"
define i64 @get_rate() {
%1 = alloca i64
%2 = alloca i32*
%3 = alloca i64
%4 = alloca [12 x i8]
%5 = call i32* @fopen(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %2
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
store i64 -1, i64* %1
br label %18
9: ; preds = %0
%10 = getelementptr inbounds [12 x i8], [12 x i8]* %4, i64 0, i64 0
%11 = load i32*, i32** %2
%12 = call i32 @fgets(i8* %10, i32 12, i32* %11)
%13 = load i32*, i32** %2
%14 = call i32 @fclose(i32* %13)
%15 = getelementptr inbounds [12 x i8], [12 x i8]* %4, i64 0, i64 0
%16 = call i64 @atoi(i8* %15)
store i64 %16, i64* %3
%17 = load i64, i64* %3
store i64 %17, i64* %1
br label %18
18: ; preds = %9, %7
%19 = load i64, i64* %1
ret i64 %19
}

LLVM IR (-O2):
@.str = [43 x i8] c"/sys/class/net/enp10s0/statistics/rx_bytes\00"
@.str.1 = [2 x i8] c"r\00"
@str = [38 x i8] c"Error, no se ha podido abrir fichero.\00"
define i64 @get_rate() {
%1 = alloca [12 x i8]
%2 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
br label %11
7: ; preds = %0
%8 = call i32 @fgets(i8* %2, i32 12, i32* %3)
%9 = call i32 @fclose(i32* %3)
%10 = call i64 @atoi(i8* %2)
br label %11
11: ; preds = %7, %5
%12 = phi i64 [ -1, %5 ], [ %10, %7 ]
ret i64 %12
}