#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*/ scanf(char *, char *);
int main(int argc, char *argv[]) {
  char nome1, nome2;
  printf("Digite o nome do arquivo a ser copiado: ");
  scanf("%c", &nome1);
  printf("Digite o nome do arquivo novo: ");
  scanf("%c", &nome2);
  FILE *arquivo1 = fopen(nome1, "r"), *arquivo2 = fopen(nome2, "w+");
  int caractere;
  if (arquivo1 != NULL) {
    while ((caractere = fgetc(arquivo1)) != EOF) {
      printf("%c", caractere);
      putc(caractere, arquivo2);
    }
    fclose(arquivo1);
    fclose(arquivo2);
  } else
    printf("Nao foi possivel abrir o arquivo.");
  printf("\n\n");
  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
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe9e(%rip),%rdi
lea    -0x11(%rbp),%rsi
call   1070 <scanf@plt>
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe80(%rip),%rdi
lea    -0x12(%rbp),%rsi
call   1070 <scanf@plt>
lea    0xe93(%rip),%rsi
movsbl -0x11(%rbp),%edi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
lea    0xe81(%rip),%rsi
movsbl -0x12(%rbp),%edi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     123e <main+0xde>
jmp    11ea <main+0x8a>
mov    -0x20(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2deb(%rip),%rcx
cmp    (%rcx),%eax
je     1227 <main+0xc7>
mov    -0x2c(%rbp),%esi
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   1060 <putc@plt>
jmp    11ea <main+0x8a>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
jmp    124c <main+0xec>
lea    0xe0c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe20(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@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
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe8d(%rip),%rbx
lea    0x7(%rsp),%rsi
mov    %rbx,%rdi
call   1090 <scanf@plt>
lea    0xe7c(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x6(%rsp),%rsi
mov    %rbx,%rdi
call   1090 <scanf@plt>
movsbl 0x7(%rsp),%edi
lea    0xe7c(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbx
movsbl 0x6(%rsp),%edi
lea    0xe6a(%rip),%rsi
call   10a0 <fopen@plt>
test   %rbx,%rbx
je     1242 <main+0xc2>
mov    %rax,%r14
mov    %rbx,%rdi
call   1070 <fgetc@plt>
mov    0x2de8(%rip),%r15
cmp    (%r15),%eax
je     1230 <main+0xb0>
mov    %eax,%ebp
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1030 <putchar@plt>
mov    %ebp,%edi
mov    %r14,%rsi
call   1080 <putc@plt>
mov    %rbx,%rdi
call   1070 <fgetc@plt>
mov    %eax,%ebp
cmp    (%r15),%eax
jne    1210 <main+0x90>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
jmp    1250 <main+0xd0>
lea    0xe08(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe1c(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [41 x i8] c"Digite o nome do arquivo a ser copiado: \00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [32 x i8] c"Digite o nome do arquivo novo: \00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [3 x i8] c"w+\00"
@EOF = global i32 0
@.str.5 = [34 x i8] c"Nao foi possivel abrir o arquivo.\00"
@str = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i8
%4 = alloca i8
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%9 = load i8, i8* %3
%10 = call i32* @fopen(i8 signext %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%11 = load i8, i8* %4
%12 = call i32* @fopen(i8 signext %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%13 = icmp eq i32* %10, null
br i1 %13, label %28, label %14
14: ; preds = %2
%15 = call i32 @fgetc(i32* %10)
%16 = load i32, i32* @EOF
%17 = icmp eq i32 %15, %16
br i1 %17, label %25, label %18
18: ; preds = %14, %18
%19 = phi i32 [ %22, %18 ], [ %15, %14 ]
%20 = call i32 @putchar(i32 %19)
%21 = call i32 @putc(i32 %19, i32* %12)
%22 = call i32 @fgetc(i32* %10)
%23 = load i32, i32* @EOF
%24 = icmp eq i32 %22, %23
br i1 %24, label %25, label %18
25: ; preds = %18, %14
%26 = call i32 @fclose(i32* %10)
%27 = call i32 @fclose(i32* %12)
br label %30
28: ; preds = %2
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0))
br label %30
30: ; preds = %28, %25
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
ret i32 0
}