#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 */

/* Variables and functions */
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_WRONLY;
int /*<<< orphan*/ S_IRWXU;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int open(char *, int, ...);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int write(int, char **, int);
int main() {
  int fd, fd1, efd1, r1;
  char leidofd[512];
  fd = open("entrada.txt", O_RDONLY);
  if (fd < 0) {
    perror("Error en el open");
    exit(1);
  }
  fd1 = open("salida.txt", O_CREAT | O_WRONLY, S_IRWXU);
  if (fd1 < 0) {
    perror("Error en el open");
    exit(1);
  }
  while ((r1 = read(fd, leidofd, 512)) > 0) {
    efd1 = write(fd1, &leidofd, r1);
    if (efd1 < 0) {
      perror("Error en el write");
      exit(1);
    }
  }
  close(fd);
  close(fd1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11ac <main+0x4c>
lea    0xe6f(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2e45(%rip),%rax
mov    (%rax),%esi
mov    0x2e04(%rip),%rax
or     (%rax),%esi
mov    0x2e1b(%rip),%rax
mov    (%rax),%edx
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1060 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11f8 <main+0x98>
lea    0xe23(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    11fd <main+0x9d>
mov    -0x8(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    $0x200,%edx
call   1050 <read@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jle    1257 <main+0xf7>
mov    -0xc(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1252 <main+0xf2>
lea    0xde5(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    11fd <main+0x9d>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x200,%rsp
mov    0x2e66(%rip),%rax
mov    (%rax),%esi
lea    0xe85(%rip),%rdi
xor    %eax,%eax
call   1060 <open@plt>
test   %eax,%eax
js     1217 <main+0xb7>
mov    %eax,%r14d
mov    0x2e64(%rip),%rax
mov    0x2e25(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e3a(%rip),%rax
mov    (%rax),%edx
lea    0xe6e(%rip),%rdi
xor    %eax,%eax
call   1060 <open@plt>
test   %eax,%eax
js     1217 <main+0xb7>
mov    %eax,%ebp
mov    %rsp,%rbx
nop
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x200,%edx
call   1050 <read@plt>
test   %eax,%eax
jle    11fa <main+0x9a>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
test   %eax,%eax
jns    11c0 <main+0x60>
lea    0xe3d(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    %r14d,%edi
call   1040 <close@plt>
mov    %ebp,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xdee(%rip),%rdi
jmp    11eb <main+0x8b>

LLVM IR (-O0):
@.str = [12 x i8] c"entrada.txt\00"
@O_RDONLY = global i32 0
@.str.1 = [17 x i8] c"Error en el open\00"
@.str.2 = [11 x i8] c"salida.txt\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@S_IRWXU = global i32 0
@.str.3 = [18 x i8] c"Error en el write\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [512 x i8]
store i32 0, i32* %1
%7 = load i32, i32* @O_RDONLY
%8 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %7)
store i32 %8, i32* %2
%9 = load i32, i32* %2
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %0
%12 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %0
%15 = load i32, i32* @O_CREAT
%16 = load i32, i32* @O_WRONLY
%17 = or i32 %15, %16
%18 = load i32, i32* @S_IRWXU
%19 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %17, i32 %18)
store i32 %19, i32* %3
%20 = load i32, i32* %3
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %14
%23 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %14
br label %26
26: ; preds = %41, %25
%27 = load i32, i32* %2
%28 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%29 = call i32 @read(i32 %27, i8* %28, i32 512)
store i32 %29, i32* %5
%30 = icmp sgt i32 %29, 0
br i1 %30, label %31, label %42
31: ; preds = %26
%32 = load i32, i32* %3
%33 = bitcast [512 x i8]* %6 to i8**
%34 = load i32, i32* %5
%35 = call i32 @write(i32 %32, i8** %33, i32 %34)
store i32 %35, i32* %4
%36 = load i32, i32* %4
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %31
%39 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %31
br label %26
42: ; preds = %26
%43 = load i32, i32* %2
%44 = call i32 @close(i32 %43)
%45 = load i32, i32* %3
%46 = call i32 @close(i32 %45)
%47 = load i32, i32* %1
ret i32 %47
}

LLVM IR (-O2):
@.str = [12 x i8] c"entrada.txt\00"
@O_RDONLY = global i32 0
@.str.1 = [17 x i8] c"Error en el open\00"
@.str.2 = [11 x i8] c"salida.txt\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@S_IRWXU = global i32 0
@.str.3 = [18 x i8] c"Error en el write\00"
define i32 @main() {
%1 = alloca [512 x i8]
%2 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %0
%10 = load i32, i32* @O_CREAT
%11 = load i32, i32* @O_WRONLY
%12 = or i32 %11, %10
%13 = load i32, i32* @S_IRWXU
%14 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %12, i32 %13)
%15 = icmp slt i32 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %9
%17 = bitcast [512 x i8]* %1 to i8**
br label %21
18: ; preds = %9
%19 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %16, %24
%22 = call i32 @read(i32 %4, i8* %2, i32 512)
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %30
24: ; preds = %21
%25 = call i32 @write(i32 %14, i8** %17, i32 %22)
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %21
27: ; preds = %24
%28 = tail call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%29 = tail call i32 @exit(i32 1)
unreachable
30: ; preds = %21
%31 = tail call i32 @close(i32 %4)
%32 = tail call i32 @close(i32 %14)
ret i32 0
}