#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*/ *);
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ printf(char *);
int strlen(char *);
int /*<<< orphan*/ system(char *);
int main() {
  FILE *tx;
  char string[101];
  int i;
  tx = fopen("texto.txt", "w");
  if (!tx) {
    printf("\nErro na abertura do arquivo!!!\n\n");
    system("pause");
    return (0);
  }
  printf("\tDigite o texto com até 100 caracteres:\n\n");
  gets(string);
  for (i = 0; i < strlen(string); i++) {
    fputc(string[i], tx);
  }
  fclose(tx);
  system("pause");
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe77(%rip),%rdi
lea    0xe7a(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11c8 <main+0x58>
lea    0xe61(%rip),%rdi
call   1060 <printf@plt>
lea    0xe77(%rip),%rdi
call   1050 <system@plt>
movl   $0x0,-0x4(%rbp)
jmp    1253 <main+0xe3>
lea    0xe65(%rip),%rdi
call   1060 <printf@plt>
lea    -0x80(%rbp),%rdi
call   1080 <gets@plt>
movl   $0x0,-0x84(%rbp)
mov    -0x84(%rbp),%eax
mov    %eax,-0x88(%rbp)
lea    -0x80(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x88(%rbp),%eax
cmp    %ecx,%eax
jge    1237 <main+0xc7>
movslq -0x84(%rbp),%rax
mov    -0x80(%rbp,%rax,1),%al
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1070 <fputc@plt>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    11e7 <main+0x77>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xde7(%rip),%rdi
call   1050 <system@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x70,%rsp
lea    0xe80(%rip),%rdi
lea    0xe83(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     11e9 <main+0x79>
mov    %rax,%r15
lea    0xe98(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%r14
mov    %r14,%rdi
call   1080 <gets@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    11df <main+0x6f>
xor    %ebx,%ebx
mov    %rsp,%r14
nopl   0x0(%rax)
movsbl (%rsp,%rbx,1),%edi
mov    %r15,%rsi
call   1070 <fputc@plt>
add    $0x1,%rbx
mov    %r14,%rdi
call   1050 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     11c0 <main+0x50>
mov    %r15,%rdi
call   1040 <fclose@plt>
jmp    11f5 <main+0x85>
lea    0xe22(%rip),%rdi
call   1030 <puts@plt>
lea    0xe10(%rip),%rdi
call   1060 <system@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c"texto.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [34 x i8] c"\0AErro na abertura do arquivo!!!\0A\0A\00"
@.str.3 = [6 x i8] c"pause\00"
@.str.4 = [43 x i8] c"\09Digite o texto com at\C3\A9 100 caracteres:\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [101 x i8]
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 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 = load i32*, i32** %2
%7 = icmp ne i32* %6, null
br i1 %7, label %11, label %8
8: ; preds = %0
%9 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %1
br label %34
11: ; preds = %0
%12 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0))
%13 = getelementptr inbounds [101 x i8], [101 x i8]* %3, i64 0, i64 0
%14 = call i32 @gets(i8* %13)
store i32 0, i32* %4
br label %15
15: ; preds = %27, %11
%16 = load i32, i32* %4
%17 = getelementptr inbounds [101 x i8], [101 x i8]* %3, i64 0, i64 0
%18 = call i32 @strlen(i8* %17)
%19 = icmp slt i32 %16, %18
br i1 %19, label %20, label %30
20: ; preds = %15
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [101 x i8], [101 x i8]* %3, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = load i32*, i32** %2
%26 = call i32 @fputc(i8 signext %24, i32* %25)
br label %27
27: ; preds = %20
%28 = load i32, i32* %4
%29 = add nsw i32 %28, 1
store i32 %29, i32* %4
br label %15
30: ; preds = %15
%31 = load i32*, i32** %2
%32 = call i32 @fclose(i32* %31)
%33 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %1
br label %34
34: ; preds = %30, %8
%35 = load i32, i32* %1
ret i32 %35
}

LLVM IR (-O2):
@.str = [10 x i8] c"texto.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.3 = [6 x i8] c"pause\00"
@str = [33 x i8] c"\0AErro na abertura do arquivo!!!\0A\00"
@str.5 = [42 x i8] c"\09Digite o texto com at\C3\A9 100 caracteres:\0A\00"
define i32 @main() {
%1 = alloca [101 x i8]
%2 = getelementptr inbounds [101 x i8], [101 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 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 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
%7 = tail call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %25
8: ; preds = %0
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.5, i64 0, i64 0))
%10 = call i32 @gets(i8* %2)
%11 = call i32 @strlen(i8* %2)
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %22
13: ; preds = %8, %13
%14 = phi i64 [ %18, %13 ], [ 0, %8 ]
%15 = getelementptr inbounds [101 x i8], [101 x i8]* %1, i64 0, i64 %14
%16 = load i8, i8* %15
%17 = call i32 @fputc(i8 signext %16, i32* %3)
%18 = add nuw nsw i64 %14, 1
%19 = call i32 @strlen(i8* %2)
%20 = sext i32 %19 to i64
%21 = icmp slt i64 %18, %20
br i1 %21, label %13, label %22
22: ; preds = %13, %8
%23 = call i32 @fclose(i32* %3)
%24 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %25
25: ; preds = %22, %5
ret i32 0
}