#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 atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *);
int obtener_ratio(char *FICHERO) {
  int valor;
  char lectura[9];
  FILE *fp;
  if ((fp = fopen(FICHERO, "r")) == NULL) {
    printf("Error en la lectura.\n");
    return -1;
  } else {
    fgets(lectura, 8, fp);
    fclose(fp);
    valor = atoi(lectura);
  }
  return valor;
}


x86 assembly (clang, -O0):
<obtener_ratio>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe99(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1192 <obtener_ratio+0x42>
lea    0xe81(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bf <obtener_ratio+0x6f>
lea    -0x1d(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x8,%esi
call   1050 <fgets@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0x1d(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<obtener_ratio>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xea2(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1192 <obtener_ratio+0x42>
mov    %rax,%rbx
lea    0xf(%rsp),%r14
mov    %r14,%rdi
mov    $0x8,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1070 <atoi@plt>
jmp    11a3 <obtener_ratio+0x53>
lea    0xe69(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [22 x i8] c"Error en la lectura.\0A\00"
define i32 @obtener_ratio(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [9 x i8]
%6 = alloca i32*
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %6
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %22
12: ; preds = %1
%13 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 0
%14 = load i32*, i32** %6
%15 = call i32 @fgets(i8* %13, i32 8, i32* %14)
%16 = load i32*, i32** %6
%17 = call i32 @fclose(i32* %16)
%18 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 0
%19 = call i32 @atoi(i8* %18)
store i32 %19, i32* %4
br label %20
20: ; preds = %12
%21 = load i32, i32* %4
store i32 %21, i32* %2
br label %22
22: ; preds = %20, %10
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@str = [21 x i8] c"Error en la lectura.\00"
define i32 @obtener_ratio(i8* nocapture %0) {
%2 = alloca [9 x i8]
%3 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %12
8: ; preds = %1
%9 = call i32 @fgets(i8* %3, i32 8, i32* %4)
%10 = call i32 @fclose(i32* %4)
%11 = call i32 @atoi(i8* %3)
br label %12
12: ; preds = %8, %6
%13 = phi i32 [ -1, %6 ], [ %11, %8 ]
ret i32 %13
}