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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7a(%rip),%rdi
lea    0xe79(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    0xe6b(%rip),%rdi
lea    0xe6a(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11de <main+0x6e>
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe67(%rip),%rdi
call   1040 <system@plt>
movl   $0x0,-0x4(%rbp)
jmp    12ed <main+0x17d>
cmpq   $0x0,-0x18(%rbp)
jne    120f <main+0x9f>
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe36(%rip),%rdi
call   1040 <system@plt>
movl   $0x0,-0x4(%rbp)
jmp    12ed <main+0x17d>
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    123b <main+0xcb>
jmp    125e <main+0xee>
mov    -0x10(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%esi
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    121d <main+0xad>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <copiar@plt>
lea    0xe13(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1297 <main+0x127>
jmp    12ba <main+0x14a>
mov    -0x18(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%esi
lea    0xdd4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1279 <main+0x109>
lea    0xd70(%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    0xd53(%rip),%rdi
call   1040 <system@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xe75(%rip),%rdi
lea    0xe74(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%r14
lea    0xe67(%rip),%rdi
lea    0xe66(%rip),%rsi
call   10a0 <fopen@plt>
test   %r14,%r14
je     124c <main+0xcc>
mov    %rax,%rbx
test   %rax,%rax
je     1255 <main+0xd5>
lea    0xe93(%rip),%rdi
call   1040 <puts@plt>
xchg   %ax,%ax
mov    %r14,%rdi
call   1080 <feof@plt>
mov    %r14,%rdi
test   %eax,%eax
jne    11ee <main+0x6e>
call   1070 <fgetc@plt>
movsbl %al,%edi
call   1030 <putchar@plt>
jmp    11d0 <main+0x50>
mov    %rbx,%rsi
call   1090 <copiar@plt>
lea    0xe82(%rip),%rdi
call   1040 <puts@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1080 <feof@plt>
test   %eax,%eax
jne    122e <main+0xae>
mov    %rbx,%rdi
call   1070 <fgetc@plt>
movsbl %al,%edi
call   1030 <putchar@plt>
jmp    1210 <main+0x90>
lea    0xe02(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
jmp    1261 <main+0xe1>
lea    0xdc3(%rip),%rdi
jmp    125c <main+0xdc>
lea    0xddd(%rip),%rdi
call   1040 <puts@plt>
lea    0xda8(%rip),%rdi
call   1060 <system@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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