#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*/ fputc(char, int /*<<< orphan*/ *);
char getchar();
int /*<<< orphan*/ printf(char *);
int main() {
  FILE *archivo;
  char caracter;
  archivo = fopen("prueba.txt", "a");
  printf("\nIntroduce un texto: \n");
  while ((caracter = getchar()) != '\n') {
    fputc(caracter, archivo);
  }
  fclose(archivo);
  printf("\nRevisa el archivo prueba.txt\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
lea    0xe9e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    0xe90(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%eax
cmp    $0xa,%eax
je     11ac <main+0x5c>
mov    -0x11(%rbp),%al
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1050 <fputc@plt>
jmp    1182 <main+0x32>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe68(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xed3(%rip),%rdi
lea    0xea1(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
lea    0xe94(%rip),%rdi
call   1030 <puts@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    $0xa,%al
je     1198 <main+0x48>
movsbl %al,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
jmp    1180 <main+0x30>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xe71(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [11 x i8] c"prueba.txt\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [23 x i8] c"\0AIntroduce un texto: \0A\00"
@.str.3 = [31 x i8] c"\0ARevisa el archivo prueba.txt\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8
store i32 0, i32* %1
%4 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %2
%5 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %6
6: ; preds = %10, %0
%7 = call signext i8 (...) @getchar()
store i8 %7, i8* %3
%8 = sext i8 %7 to i32
%9 = icmp ne i32 %8, 10
br i1 %9, label %10, label %14
10: ; preds = %6
%11 = load i8, i8* %3
%12 = load i32*, i32** %2
%13 = call i32 @fputc(i8 signext %11, i32* %12)
br label %6
14: ; preds = %6
%15 = load i32*, i32** %2
%16 = call i32 @fclose(i32* %15)
%17 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"prueba.txt\00"
@.str.1 = [2 x i8] c"a\00"
@str = [22 x i8] c"\0AIntroduce un texto: \00"
@str.4 = [30 x i8] c"\0ARevisa el archivo prueba.txt\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%3 = tail call signext i8 (...) @getchar()
%4 = icmp eq i8 %3, 10
br i1 %4, label %10, label %5
5: ; preds = %0, %5
%6 = phi i8 [ %8, %5 ], [ %3, %0 ]
%7 = tail call i32 @fputc(i8 signext %6, i32* %1)
%8 = tail call signext i8 (...) @getchar()
%9 = icmp eq i8 %8, 10
br i1 %9, label %10, label %5
10: ; preds = %5, %0
%11 = tail call i32 @fclose(i32* %1)
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.4, i64 0, i64 0))
ret i32 0
}