#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*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, char, int);
void copia(char dest[], char origem[]) {
  FILE *arqEntrada, *arqSaida;
  int i;
  char textoArquivo[1000];
  if (((arqEntrada = fopen(origem, "r")) != 0) ||
      ((arqSaida = fopen(dest, "r")) != 0)) {
    arqSaida = fopen(dest, "w");
    for (i = 0; !feof(arqEntrada); i++) {
      memset(textoArquivo, '\0', 1000);
      fgets(textoArquivo, 1000 + 1, arqEntrada);
      fputs(textoArquivo, arqSaida);
    }
    fclose(arqEntrada);
    fclose(arqSaida);
  }
}


x86 assembly (clang, -O0):
<copia>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe82(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11af <copia+0x4f>
mov    -0x8(%rbp),%rdi
lea    0xe64(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1240 <copia+0xe0>
mov    -0x8(%rbp),%rdi
lea    0xe48(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11e8 <copia+0x88>
jmp    122e <copia+0xce>
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x3e8,%edx
call   1050 <memset@plt>
lea    -0x410(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x3e9,%esi
call   1060 <fgets@plt>
lea    -0x410(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <fputs@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11ca <copia+0x6a>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copia>:
push   %r15
push   %r14
push   %rbx
sub    $0x3f0,%rsp
mov    %rsi,%rax
mov    %rdi,%rbx
lea    0xe87(%rip),%rsi
mov    %rax,%rdi
call   1080 <fopen@plt>
mov    %rax,%r15
test   %rax,%rax
jne    119d <copia+0x3d>
lea    0xe70(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1206 <copia+0xa6>
lea    0xe5e(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
mov    %rax,%r14
mov    %r15,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    11f6 <copia+0x96>
mov    %rsp,%rbx
xchg   %ax,%ax
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x3e8,%edx
call   1050 <memset@plt>
mov    %rbx,%rdi
mov    $0x3e9,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <fputs@plt>
mov    %r15,%rdi
call   1070 <feof@plt>
test   %eax,%eax
je     11c0 <copia+0x60>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
add    $0x3f0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
define void @copia(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca [1000 x i8]
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i8*, i8** %4
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %5
%11 = icmp ne i32* %10, null
br i1 %11, label %16, label %12
12: ; preds = %2
%13 = load i8*, i8** %3
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %6
%15 = icmp ne i32* %14, null
br i1 %15, label %16, label %41
16: ; preds = %12, %2
%17 = load i8*, i8** %3
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %6
store i32 0, i32* %7
br label %19
19: ; preds = %33, %16
%20 = load i32*, i32** %5
%21 = call i32 @feof(i32* %20)
%22 = icmp ne i32 %21, 0
%23 = xor i1 %22, true
br i1 %23, label %24, label %36
24: ; preds = %19
%25 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%26 = call i32 @memset(i8* %25, i8 signext 0, i32 1000)
%27 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%28 = load i32*, i32** %5
%29 = call i32 @fgets(i8* %27, i32 1001, i32* %28)
%30 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%31 = load i32*, i32** %6
%32 = call i32 @fputs(i8* %30, i32* %31)
br label %33
33: ; preds = %24
%34 = load i32, i32* %7
%35 = add nsw i32 %34, 1
store i32 %35, i32* %7
br label %19
36: ; preds = %19
%37 = load i32*, i32** %5
%38 = call i32 @fclose(i32* %37)
%39 = load i32*, i32** %6
%40 = call i32 @fclose(i32* %39)
br label %41
41: ; preds = %36, %12
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
define void @copia(i8* nocapture %0, i8* nocapture %1) {
%3 = alloca [1000 x i8]
%4 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %23, label %10
10: ; preds = %7, %2
%11 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @feof(i32* %5)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %10, %14
%15 = call i32 @memset(i8* %4, i8 signext 0, i32 1000)
%16 = call i32 @fgets(i8* %4, i32 1001, i32* %5)
%17 = call i32 @fputs(i8* %4, i32* %11)
%18 = call i32 @feof(i32* %5)
%19 = icmp eq i32 %18, 0
br i1 %19, label %14, label %20
20: ; preds = %14, %10
%21 = call i32 @fclose(i32* %5)
%22 = call i32 @fclose(i32* %11)
br label %23
23: ; preds = %20, %7
ret void
}