#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*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ strcpy(char *, char *);
main() {
  FILE *pf;
  char buffer[81];
  int i = 0;
  if ((pf = fopen("texto", "w")) == NULL) {
    perror("El fichero no se puede abrir");
    exit(1);
  }
  strcpy(buffer, "Este es un texto escrito por fputc!!\n");
  while (!ferror(pf) && buffer[i])
    fputc(buffer[i++], pf);
  if (ferror(pf))
    perror("Error durante la escritura");
  fclose(pf);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x74(%rbp)
lea    0xe70(%rip),%rdi
lea    0xe6f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11c0 <main+0x50>
lea    0xe57(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    -0x70(%rbp),%rdi
lea    0xe5a(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
call   1040 <ferror@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x75(%rbp)
jne    11fd <main+0x8d>
movslq -0x74(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x75(%rbp)
mov    -0x75(%rbp),%al
test   $0x1,%al
jne    120d <main+0x9d>
jmp    122f <main+0xbf>
mov    -0x74(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x74(%rbp)
cltq
mov    -0x70(%rbp,%rax,1),%al
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1060 <fputc@plt>
jmp    11d0 <main+0x60>
mov    -0x10(%rbp),%rdi
call   1040 <ferror@plt>
cmp    $0x0,%rax
je     124e <main+0xde>
lea    0xe02(%rip),%rdi
call   1080 <perror@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x58,%rsp
lea    0xe82(%rip),%rdi
lea    0xe81(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1201 <main+0x91>
mov    %rax,%r14
lea    0xe8c(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %r14,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
jne    11e3 <main+0x73>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%rbx),%eax
test   %al,%al
je     11ef <main+0x7f>
movsbl %al,%edi
mov    %r14,%rsi
call   1060 <fputc@plt>
mov    %r14,%rdi
call   1040 <ferror@plt>
add    $0x1,%rbx
test   %rax,%rax
je     11c0 <main+0x50>
lea    0xe61(%rip),%rdi
call   1080 <perror@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe00(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"texto\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [29 x i8] c"El fichero no se puede abrir\00"
@.str.3 = [38 x i8] c"Este es un texto escrito por fputc!!\0A\00"
@.str.4 = [27 x i8] c"Error durante la escritura\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 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
%11 = getelementptr inbounds [81 x i8], [81 x i8]* %3, i64 0, i64 0
%12 = call i32 @strcpy(i8* %11, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
br label %13
13: ; preds = %26, %10
%14 = load i32*, i32** %2
%15 = call i64 @ferror(i32* %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %24, label %17
17: ; preds = %13
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [81 x i8], [81 x i8]* %3, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 0
br label %24
24: ; preds = %17, %13
%25 = phi i1 [ false, %13 ], [ %23, %17 ]
br i1 %25, label %26, label %34
26: ; preds = %24
%27 = load i32, i32* %4
%28 = add nsw i32 %27, 1
store i32 %28, i32* %4
%29 = sext i32 %27 to i64
%30 = getelementptr inbounds [81 x i8], [81 x i8]* %3, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = load i32*, i32** %2
%33 = call i32 @fputc(i8 signext %31, i32* %32)
br label %13
34: ; preds = %24
%35 = load i32*, i32** %2
%36 = call i64 @ferror(i32* %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %34
%39 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
br label %40
40: ; preds = %38, %34
%41 = load i32*, i32** %2
%42 = call i32 @fclose(i32* %41)
%43 = load i32, i32* %1
ret i32 %43
}

LLVM IR (-O2):
@.str = [6 x i8] c"texto\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [29 x i8] c"El fichero no se puede abrir\00"
@.str.3 = [38 x i8] c"Este es un texto escrito por fputc!!\0A\00"
@.str.4 = [27 x i8] c"Error durante la escritura\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 %5, label %8
5: ; preds = %0
%6 = tail call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %0
%9 = call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
%10 = call i64 @ferror(i32* %3)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %22
12: ; preds = %8, %17
%13 = phi i64 [ %18, %17 ], [ 0, %8 ]
%14 = getelementptr inbounds [81 x i8], [81 x i8]* %1, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 0
br i1 %16, label %24, label %17
17: ; preds = %12
%18 = add nuw i64 %13, 1
%19 = call i32 @fputc(i8 signext %15, i32* %3)
%20 = call i64 @ferror(i32* %3)
%21 = icmp eq i64 %20, 0
br i1 %21, label %12, label %22
22: ; preds = %17, %8
%23 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
br label %24
24: ; preds = %12, %22
%25 = call i32 @fclose(i32* %3)
ret i32 0
}