#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  FILE *fichero;
  char nombre[10] = "datos.dat";
  fichero = fopen(nombre, "w");
  printf("Fichero: %s -> ", nombre);
  if (fichero) {
    printf("creado (ABIERTO)\n");
  } else {
    printf("Error (NO ABIERTO)\n");
    return -1;
  }
  if (!fclose(fichero)) {
    printf("Fichero cerrado\n");
  } else {
    printf("Error: fichero NO CERRADO\n");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeba(%rip),%rax
mov    %rax,-0x1a(%rbp)
mov    0xeb7(%rip),%ax
mov    %ax,-0x12(%rbp)
lea    -0x1a(%rbp),%rdi
lea    0xeaa(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    -0x1a(%rbp),%rsi
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
je     1199 <main+0x69>
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11b3 <main+0x83>
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f9 <main+0xc9>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
cmp    $0x0,%eax
jne    11d8 <main+0xa8>
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11f2 <main+0xc2>
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f9 <main+0xc9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movabs $0x61642e736f746164,%rax
2e 64 61
mov    %rax,0x8(%rsp)
movw   $0x74,0x10(%rsp)
lea    0xea6(%rip),%rsi
lea    0x8(%rsp),%r14
mov    %r14,%rdi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0xe91(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
test   %rbx,%rbx
je     11bb <main+0x7b>
lea    0xe9e(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %ebx,%ebx
test   %eax,%eax
setne  %bl
lea    0xe94(%rip),%rax
lea    0xe9d(%rip),%rdi
cmove  %rax,%rdi
neg    %ebx
jmp    11c7 <main+0x87>
mov    $0xffffffff,%ebx
lea    0xe55(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.nombre = [10 x i8] c"datos.dat\00"
@.str = [2 x i8] c"w\00"
@.str.1 = [16 x i8] c"Fichero: %s -> \00"
@.str.2 = [18 x i8] c"creado (ABIERTO)\0A\00"
@.str.3 = [20 x i8] c"Error (NO ABIERTO)\0A\00"
@.str.4 = [17 x i8] c"Fichero cerrado\0A\00"
@.str.5 = [27 x i8] c"Error: fichero NO CERRADO\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [10 x i8]
store i32 0, i32* %1
%4 = bitcast [10 x i8]* %3 to i8*
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%6 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %6, i32** %2
%7 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%9 = load i32*, i32** %2
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %15
13: ; preds = %0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %1
br label %24
15: ; preds = %11
%16 = load i32*, i32** %2
%17 = call i32 @fclose(i32* %16)
%18 = icmp ne i32 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %15
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %23
21: ; preds = %15
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %1
br label %24
23: ; preds = %19
store i32 0, i32* %1
br label %24
24: ; preds = %23, %21, %13
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
@__const.main.nombre = [10 x i8] c"datos.dat\00"
@.str = [2 x i8] c"w\00"
@.str.1 = [16 x i8] c"Fichero: %s -> \00"
@str = [19 x i8] c"Error (NO ABIERTO)\00"
@str.6 = [17 x i8] c"creado (ABIERTO)\00"
@str.7 = [16 x i8] c"Fichero cerrado\00"
@str.8 = [26 x i8] c"Error: fichero NO CERRADO\00"
define i32 @main() {
%1 = alloca [10 x i8]
%2 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%3 = call i32* @fopen(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%5 = icmp eq i32* %3, null
br i1 %5, label %13, label %6
6: ; preds = %0
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.6, i64 0, i64 0))
%8 = call i32 @fclose(i32* %3)
%9 = icmp eq i32 %8, 0
%10 = select i1 %9, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @str.7, i64 0, i64 0), i8* getelementptr inbounds ([26 x i8], [26 x i8]* @str.8, i64 0, i64 0)
%11 = xor i1 %9, true
%12 = sext i1 %11 to i32
br label %13
13: ; preds = %0, %6
%14 = phi i8* [ %10, %6 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0), %0 ]
%15 = phi i32 [ %12, %6 ], [ -1, %0 ]
%16 = call i32 @puts(i8* dereferenceable(1) %14)
ret i32 %15
}