#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*/ clearerr(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ printf(char *);
main() {
  FILE *pf;
  char *cadena = "Esta cadena nunca será escrita";
  if ((pf = fopen("datos", "r")) == NULL) {
    printf("Error: no se puede abrir el fichero\n");
    exit(1);
  }
  fprintf(pf, "%s\n", cadena);
  if (ferror(pf)) {
    printf("Error al escribir en el fichero\n");
    clearerr(pf);
  }
  fclose(pf);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7a(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe8f(%rip),%rdi
lea    0xe8e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11c1 <main+0x51>
lea    0xe76(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe7d(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     11fd <main+0x8d>
lea    0xe62(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1070 <clearerr@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xea8(%rip),%rdi
lea    0xea7(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11cf <main+0x5f>
mov    %rax,%rbx
lea    0xe95(%rip),%rsi
lea    0xe66(%rip),%rdx
mov    %rax,%rdi
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
je     11c3 <main+0x53>
lea    0xe76(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1070 <clearerr@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe76(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [32 x i8] c"Esta cadena nunca ser\C3\A1 escrita\00"
@.str.1 = [6 x i8] c"datos\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [37 x i8] c"Error: no se puede abrir el fichero\0A\00"
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [33 x i8] c"Error al escribir en el fichero\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8*
store i32 0, i32* %1
store i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8** %3
%4 = call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %4, i32** %2
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
%8 = call i32 @exit(i32 1)
unreachable
9: ; preds = %0
%10 = load i32*, i32** %2
%11 = load i8*, i8** %3
%12 = call i32 @fprintf(i32* %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %11)
%13 = load i32*, i32** %2
%14 = call i64 @ferror(i32* %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %9
%17 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0))
%18 = load i32*, i32** %2
%19 = call i32 @clearerr(i32* %18)
br label %20
20: ; preds = %16, %9
%21 = load i32*, i32** %2
%22 = call i32 @fclose(i32* %21)
%23 = load i32, i32* %1
ret i32 %23
}

LLVM IR (-O2):
@.str = [32 x i8] c"Esta cadena nunca ser\C3\A1 escrita\00"
@.str.1 = [6 x i8] c"datos\00"
@.str.2 = [2 x i8] c"r\00"
@.str.4 = [4 x i8] c"%s\0A\00"
@str = [32 x i8] c"Error al escribir en el fichero\00"
@str.6 = [36 x i8] c"Error: no se puede abrir el fichero\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.6, i64 0, i64 0))
%5 = tail call i32 @exit(i32 1)
unreachable
6: ; preds = %0
%7 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%8 = tail call i64 @ferror(i32* %1)
%9 = icmp eq i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %6
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
%12 = tail call i32 @clearerr(i32* %1)
br label %13
13: ; preds = %10, %6
%14 = tail call i32 @fclose(i32* %1)
ret i32 0
}