#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
main() {
  FILE *pf = NULL;
  char buffer[81];
  int i = 0;
  if ((pf = fopen("texto", "r")) == NULL) {
    perror("El fichero no se puede abrir");
    exit(1);
  }
  while (!ferror(pf) && !feof(pf))
    buffer[i++] = fgetc(pf);
  buffer[--i] = '\0';
  if (ferror(pf))
    perror("Error durante la lectura");
  fclose(pf);
  printf("%s", buffer);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0x0,-0x74(%rbp)
lea    0xe58(%rip),%rdi
lea    0xe72(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11d8 <main+0x58>
lea    0xe3d(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    11dd <main+0x5d>
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x75(%rbp)
jne    120c <main+0x8c>
mov    -0x10(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x75(%rbp)
mov    -0x75(%rbp),%al
test   $0x1,%al
jne    121c <main+0x9c>
jmp    123d <main+0xbd>
mov    -0x10(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,%cl
mov    -0x74(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x74(%rbp)
cltq
mov    %cl,-0x70(%rbp,%rax,1)
jmp    11dd <main+0x5d>
mov    -0x74(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x74(%rbp)
cltq
movb   $0x0,-0x70(%rbp,%rax,1)
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     126c <main+0xec>
lea    0xdbc(%rip),%rdi
call   1090 <perror@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0x70(%rbp),%rsi
lea    0xdbc(%rip),%rdi
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x58,%rsp
lea    0xe72(%rip),%rdi
lea    0xe8c(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     122e <main+0xae>
mov    %rax,%r14
mov    %rax,%rdi
call   1030 <ferror@plt>
xor    %ebx,%ebx
test   %rax,%rax
jne    11e8 <main+0x68>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    11e8 <main+0x68>
mov    %r14,%rdi
call   1060 <fgetc@plt>
mov    %al,(%rsp,%rbx,1)
add    $0x1,%rbx
mov    %r14,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
je     11c0 <main+0x40>
add    $0xffffffff,%ebx
movslq %ebx,%rax
movb   $0x0,(%rsp,%rax,1)
mov    %r14,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
jne    1220 <main+0xa0>
mov    %r14,%rdi
call   1040 <fclose@plt>
lea    0xe2e(%rip),%rdi
mov    %rsp,%rsi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r14
ret
lea    0xdfc(%rip),%rdi
call   1090 <perror@plt>
jmp    11ff <main+0x7f>
lea    0xdd1(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"texto\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [29 x i8] c"El fichero no se puede abrir\00"
@.str.3 = [25 x i8] c"Error durante la lectura\00"
@.str.4 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [81 x i8]
%4 = alloca i32
store i32 0, i32* %1
store i32* null, i32** %2
store i32 0, i32* %4
%5 = call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 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 %10
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 @exit(i32 1)
unreachable
10: ; preds = %0
br label %11
11: ; preds = %22, %10
%12 = load i32*, i32** %2
%13 = call i64 @ferror(i32* %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %20, label %15
15: ; preds = %11
%16 = load i32*, i32** %2
%17 = call i32 @feof(i32* %16)
%18 = icmp ne i32 %17, 0
%19 = xor i1 %18, true
br label %20
20: ; preds = %15, %11
%21 = phi i1 [ false, %11 ], [ %19, %15 ]
br i1 %21, label %22, label %29
22: ; preds = %20
%23 = load i32*, i32** %2
%24 = call signext i8 @fgetc(i32* %23)
%25 = load i32, i32* %4
%26 = add nsw i32 %25, 1
store i32 %26, i32* %4
%27 = sext i32 %25 to i64
%28 = getelementptr inbounds [81 x i8], [81 x i8]* %3, i64 0, i64 %27
store i8 %24, i8* %28
br label %11
29: ; preds = %20
%30 = load i32, i32* %4
%31 = add nsw i32 %30, -1
store i32 %31, i32* %4
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [81 x i8], [81 x i8]* %3, i64 0, i64 %32
store i8 0, i8* %33
%34 = load i32*, i32** %2
%35 = call i64 @ferror(i32* %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %29
%38 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
br label %39
39: ; preds = %37, %29
%40 = load i32*, i32** %2
%41 = call i32 @fclose(i32* %40)
%42 = getelementptr inbounds [81 x i8], [81 x i8]* %3, i64 0, i64 0
%43 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %42)
%44 = load i32, i32* %1
ret i32 %44
}

LLVM IR (-O2):
@.str = [6 x i8] c"texto\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [29 x i8] c"El fichero no se puede abrir\00"
@.str.3 = [25 x i8] c"Error durante la lectura\00"
@.str.4 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca [81 x i8]
%2 = getelementptr inbounds [81 x i8], [81 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 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 %8, label %5
5: ; preds = %0
%6 = tail call i64 @ferror(i32* %3)
%7 = icmp eq i64 %6, 0
br i1 %7, label %11, label %21
8: ; preds = %0
%9 = tail call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %5, %15
%12 = phi i64 [ %17, %15 ], [ 0, %5 ]
%13 = tail call i32 @feof(i32* %3)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %11
%16 = tail call signext i8 @fgetc(i32* %3)
%17 = add nuw i64 %12, 1
%18 = getelementptr inbounds [81 x i8], [81 x i8]* %1, i64 0, i64 %12
store i8 %16, i8* %18
%19 = tail call i64 @ferror(i32* %3)
%20 = icmp eq i64 %19, 0
br i1 %20, label %11, label %21
21: ; preds = %11, %15, %5
%22 = phi i64 [ 0, %5 ], [ %17, %15 ], [ %12, %11 ]
%23 = shl i64 %22, 32
%24 = add i64 %23, -4294967296
%25 = ashr exact i64 %24, 32
%26 = getelementptr inbounds [81 x i8], [81 x i8]* %1, i64 0, i64 %25
store i8 0, i8* %26
%27 = tail call i64 @ferror(i32* %3)
%28 = icmp eq i64 %27, 0
br i1 %28, label %31, label %29
29: ; preds = %21
%30 = tail call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
br label %31
31: ; preds = %29, %21
%32 = tail call i32 @fclose(i32* %3)
%33 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %2)
ret i32 0
}