#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*/ copiar(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ system(char *);
int main() {
  FILE *tx, *tx2;
  char c, texto[1001];
  tx = fopen("input.txt", "r");
  tx2 = fopen("output.txt", "w");
  if (!tx) {
    printf("\nErro na abertura do arquivo input!!!\n\n");
    system("pause");
    return (0);
  }
  if (!tx2) {
    printf("\nErro na abertura do arquivo output!!!\n\n");
    system("pause");
    return (0);
  }
  printf("\tTexto presente no arquivo input.txt:\n\n");
  while (!feof(tx)) {
    c = fgetc(tx);
    printf("%c", c);
  }
  copiar(tx, tx2);
  fclose(tx);
  tx = fopen("input.txt", "r");
  printf("\n\n\tTexto copiado para o arquivo output.txt:\n\n");
  while (fgets(texto, 1001, tx) != NULL)
    printf("%s", texto);
  printf("\n\n");
  fclose(tx);
  fclose(tx2);
  system("pause");
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe67(%rip),%rdi
lea    0xe6a(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    0xe5c(%rip),%rdi
lea    0xe60(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11f1 <main+0x71>
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe61(%rip),%rdi
call   1040 <system@plt>
movl   $0x0,-0x4(%rbp)
jmp    1318 <main+0x198>
cmpq   $0x0,-0x18(%rbp)
jne    1222 <main+0xa2>
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe30(%rip),%rdi
call   1040 <system@plt>
movl   $0x0,-0x4(%rbp)
jmp    1318 <main+0x198>
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    124e <main+0xce>
jmp    1271 <main+0xf1>
mov    -0x10(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%esi
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1230 <main+0xb0>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1090 <copiar@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xd72(%rip),%rdi
lea    0xd75(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    0xdf6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x3e9,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     12e5 <main+0x165>
lea    -0x410(%rbp),%rsi
lea    0xdf0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12ac <main+0x12c>
lea    0xd52(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xd35(%rip),%rdi
call   1040 <system@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x3f8,%rsp
lea    0xe4b(%rip),%rdi
lea    0xe4e(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%rbx
lea    0xe41(%rip),%rdi
lea    0xe45(%rip),%rsi
call   10c0 <fopen@plt>
test   %rbx,%rbx
je     12b0 <main+0x110>
mov    %rax,%r14
test   %rax,%rax
je     12b9 <main+0x119>
lea    0xe7e(%rip),%rdi
call   1040 <puts@plt>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   10a0 <feof@plt>
mov    %rbx,%rdi
test   %eax,%eax
jne    121e <main+0x7e>
call   1080 <fgetc@plt>
movsbl %al,%edi
call   1030 <putchar@plt>
jmp    1200 <main+0x60>
mov    %r14,%rsi
call   10b0 <copiar@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
lea    0xdcb(%rip),%rdi
lea    0xdce(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%r12
lea    0xe4d(%rip),%rdi
call   1040 <puts@plt>
mov    %rsp,%rdi
mov    $0x3e9,%esi
mov    %r12,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
je     1292 <main+0xf2>
lea    0xdb3(%rip),%r15
mov    %rsp,%rbx
nop
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
mov    $0x3e9,%esi
mov    %r12,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
jne    1270 <main+0xd0>
lea    0xdae(%rip),%rdi
call   1040 <puts@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
jmp    12c5 <main+0x125>
lea    0xd6b(%rip),%rdi
jmp    12c0 <main+0x120>
lea    0xd89(%rip),%rdi
call   1040 <puts@plt>
lea    0xd4d(%rip),%rdi
call   1060 <system@plt>
xor    %eax,%eax
add    $0x3f8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c"input.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [11 x i8] c"output.txt\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [40 x i8] c"\0AErro na abertura do arquivo input!!!\0A\0A\00"
@.str.5 = [6 x i8] c"pause\00"
@.str.6 = [41 x i8] c"\0AErro na abertura do arquivo output!!!\0A\0A\00"
@.str.7 = [40 x i8] c"\09Texto presente no arquivo input.txt:\0A\0A\00"
@.str.8 = [3 x i8] c"%c\00"
@.str.9 = [46 x i8] c"\0A\0A\09Texto copiado para o arquivo output.txt:\0A\0A\00"
@.str.10 = [3 x i8] c"%s\00"
@.str.11 = [3 x i8] c"\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i8
%5 = alloca [1001 x i8]
store i32 0, i32* %1
%6 = 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* %6, i32** %2
%7 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %7, i32** %3
%8 = load i32*, i32** %2
%9 = icmp ne i32* %8, null
br i1 %9, label %13, label %10
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0))
%12 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %1
br label %55
13: ; preds = %0
%14 = load i32*, i32** %3
%15 = icmp ne i32* %14, null
br i1 %15, label %19, label %16
16: ; preds = %13
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0))
%18 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %1
br label %55
19: ; preds = %13
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.7, i64 0, i64 0))
br label %21
21: ; preds = %26, %19
%22 = load i32*, i32** %2
%23 = call i32 @feof(i32* %22)
%24 = icmp ne i32 %23, 0
%25 = xor i1 %24, true
br i1 %25, label %26, label %32
26: ; preds = %21
%27 = load i32*, i32** %2
%28 = call signext i8 @fgetc(i32* %27)
store i8 %28, i8* %4
%29 = load i8, i8* %4
%30 = sext i8 %29 to i32
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32 %30)
br label %21
32: ; preds = %21
%33 = load i32*, i32** %2
%34 = load i32*, i32** %3
%35 = call i32 @copiar(i32* %33, i32* %34)
%36 = load i32*, i32** %2
%37 = call i32 @fclose(i32* %36)
%38 = 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* %38, i32** %2
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.9, i64 0, i64 0))
br label %40
40: ; preds = %45, %32
%41 = getelementptr inbounds [1001 x i8], [1001 x i8]* %5, i64 0, i64 0
%42 = load i32*, i32** %2
%43 = call i32* @fgets(i8* %41, i32 1001, i32* %42)
%44 = icmp ne i32* %43, null
br i1 %44, label %45, label %48
45: ; preds = %40
%46 = getelementptr inbounds [1001 x i8], [1001 x i8]* %5, i64 0, i64 0
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i8* %46)
br label %40
48: ; preds = %40
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0))
%50 = load i32*, i32** %2
%51 = call i32 @fclose(i32* %50)
%52 = load i32*, i32** %3
%53 = call i32 @fclose(i32* %52)
%54 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %1
br label %55
55: ; preds = %48, %16, %10
%56 = load i32, i32* %1
ret i32 %56
}

LLVM IR (-O2):
@.str = [10 x i8] c"input.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [11 x i8] c"output.txt\00"
@.str.3 = [2 x i8] c"w\00"
@.str.5 = [6 x i8] c"pause\00"
@.str.10 = [3 x i8] c"%s\00"
@str = [39 x i8] c"\0AErro na abertura do arquivo input!!!\0A\00"
@str.12 = [40 x i8] c"\0AErro na abertura do arquivo output!!!\0A\00"
@str.13 = [39 x i8] c"\09Texto presente no arquivo input.txt:\0A\00"
@str.14 = [45 x i8] c"\0A\0A\09Texto copiado para o arquivo output.txt:\0A\00"
@str.15 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca [1001 x i8]
%2 = getelementptr inbounds [1001 x i8], [1001 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 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%5 = icmp eq i32* %3, null
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %40
9: ; preds = %0
%10 = icmp eq i32* %4, null
br i1 %10, label %11, label %14
11: ; preds = %9
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.12, i64 0, i64 0))
%13 = tail call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %40
14: ; preds = %9
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.13, i64 0, i64 0))
%16 = tail call i32 @feof(i32* %3)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %14, %18
%19 = tail call signext i8 @fgetc(i32* %3)
%20 = sext i8 %19 to i32
%21 = tail call i32 @putchar(i32 %20)
%22 = tail call i32 @feof(i32* %3)
%23 = icmp eq i32 %22, 0
br i1 %23, label %18, label %24
24: ; preds = %18, %14
%25 = tail call i32 @copiar(i32* %3, i32* %4)
%26 = tail call i32 @fclose(i32* %3)
%27 = 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))
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.14, i64 0, i64 0))
%29 = call i32* @fgets(i8* %2, i32 1001, i32* %27)
%30 = icmp eq i32* %29, null
br i1 %30, label %35, label %31
31: ; preds = %24, %31
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i8* %2)
%33 = call i32* @fgets(i8* %2, i32 1001, i32* %27)
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %31
35: ; preds = %31, %24
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.15, i64 0, i64 0))
%37 = call i32 @fclose(i32* %27)
%38 = call i32 @fclose(i32* %4)
%39 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %40
40: ; preds = %35, %11, %6
ret i32 0
}