#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 EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ system(char *);
int main(int argc, char *argv[]) {
  FILE *arquivo = fopen("teste_1.txt", "r"),
       *arquivo2 = fopen("teste_2.txt", "w+");
  int caractere;
  if (arquivo != NULL) {
    while ((caractere = fgetc(arquivo)) != EOF) {
      printf("%c", caractere);
      putc(caractere, arquivo2);
    }
    fclose(arquivo);
    fclose(arquivo2);
  } else
    printf("Nao foi possivel abrir o arquivo.");
  printf("\n\n");
  system("PAUSE");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe83(%rip),%rdi
lea    0xe88(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    0xe7a(%rip),%rdi
lea    0xe7f(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1208 <main+0xa8>
jmp    11b4 <main+0x54>
mov    -0x18(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    0x2e21(%rip),%rcx
cmp    (%rcx),%eax
je     11f1 <main+0x91>
mov    -0x24(%rbp),%esi
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1070 <putc@plt>
jmp    11b4 <main+0x54>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
jmp    1216 <main+0xb6>
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe1a(%rip),%rdi
call   1040 <system@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xe72(%rip),%rdi
lea    0xe77(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbx
lea    0xe6a(%rip),%rdi
lea    0xe6f(%rip),%rsi
call   10a0 <fopen@plt>
test   %rbx,%rbx
je     1202 <main+0x82>
mov    %rax,%r14
mov    %rbx,%rdi
call   1080 <fgetc@plt>
mov    0x2e21(%rip),%r15
cmp    (%r15),%eax
je     11f0 <main+0x70>
mov    %eax,%ebp
xchg   %ax,%ax
mov    %ebp,%edi
call   1030 <putchar@plt>
mov    %ebp,%edi
mov    %r14,%rsi
call   1090 <putc@plt>
mov    %rbx,%rdi
call   1080 <fgetc@plt>
mov    %eax,%ebp
cmp    (%r15),%eax
jne    11d0 <main+0x50>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
jmp    1210 <main+0x90>
lea    0xe14(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe2e(%rip),%rdi
call   1040 <puts@plt>
lea    0xe1c(%rip),%rdi
call   1060 <system@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"teste_1.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [12 x i8] c"teste_2.txt\00"
@.str.3 = [3 x i8] c"w+\00"
@EOF = global i32 0
@.str.4 = [3 x i8] c"%c\00"
@.str.5 = [34 x i8] c"Nao foi possivel abrir o arquivo.\00"
@.str.6 = [3 x i8] c"\0A\0A\00"
@.str.7 = [6 x i8] c"PAUSE\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %6
%10 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %10, i32** %7
%11 = load i32*, i32** %6
%12 = icmp ne i32* %11, null
br i1 %12, label %13, label %30
13: ; preds = %2
br label %14
14: ; preds = %19, %13
%15 = load i32*, i32** %6
%16 = call i32 @fgetc(i32* %15)
store i32 %16, i32* %8
%17 = load i32, i32* @EOF
%18 = icmp ne i32 %16, %17
br i1 %18, label %19, label %25
19: ; preds = %14
%20 = load i32, i32* %8
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %20)
%22 = load i32, i32* %8
%23 = load i32*, i32** %7
%24 = call i32 @putc(i32 %22, i32* %23)
br label %14
25: ; preds = %14
%26 = load i32*, i32** %6
%27 = call i32 @fclose(i32* %26)
%28 = load i32*, i32** %7
%29 = call i32 @fclose(i32* %28)
br label %32
30: ; preds = %2
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0))
br label %32
32: ; preds = %30, %25
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%34 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"teste_1.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [12 x i8] c"teste_2.txt\00"
@.str.3 = [3 x i8] c"w+\00"
@EOF = global i32 0
@.str.5 = [34 x i8] c"Nao foi possivel abrir o arquivo.\00"
@.str.7 = [6 x i8] c"PAUSE\00"
@str = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 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 ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%5 = icmp eq i32* %3, null
br i1 %5, label %20, label %6
6: ; preds = %2
%7 = tail call i32 @fgetc(i32* %3)
%8 = load i32, i32* @EOF
%9 = icmp eq i32 %7, %8
br i1 %9, label %17, label %10
10: ; preds = %6, %10
%11 = phi i32 [ %14, %10 ], [ %7, %6 ]
%12 = tail call i32 @putchar(i32 %11)
%13 = tail call i32 @putc(i32 %11, i32* %4)
%14 = tail call i32 @fgetc(i32* %3)
%15 = load i32, i32* @EOF
%16 = icmp eq i32 %14, %15
br i1 %16, label %17, label %10
17: ; preds = %10, %6
%18 = tail call i32 @fclose(i32* %3)
%19 = tail call i32 @fclose(i32* %4)
br label %22
20: ; preds = %2
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0))
br label %22
22: ; preds = %20, %17
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%24 = tail call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
ret i32 0
}