#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_RDWR;
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open(char *, int, ...);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
char *strerror(int);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  int fd_in, fd_out, rd_len, wr_len;
  char buffer[4096];
  if (argc < 3) {
    fprintf(stderr, "Uso: %s <from filename> <to filename>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  if ((fd_in = open(argv[1], O_RDONLY)) < 0) {
    fprintf(stderr, "Err: (%d) - %s\n", errno, strerror(errno));
    exit(errno);
  }
  if ((fd_out = open(argv[2], O_RDWR | O_CREAT, 0755)) < 0) {
    fprintf(stderr, "Err: (%d) - %s\n", errno, strerror(errno));
    exit(errno);
  }
  while ((rd_len = read(fd_in, buffer, 4096)) > 0) {
    if ((wr_len = write(fd_out, buffer, rd_len)) < 0) {
      fprintf(stderr, "Err: (%d) - %s\n", errno, strerror(errno));
      exit(EXIT_FAILURE);
    }
  }
  close(fd_in);
  close(fd_out);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11bf <main+0x4f>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe56(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e0a(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    123a <main+0xca>
mov    0x2dde(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1028(%rbp)
mov    0x2dc7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1024(%rbp)
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x1028(%rbp),%edi
mov    -0x1024(%rbp),%edx
mov    %rax,%rcx
lea    0xe02(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d8d(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2d97(%rip),%rax
mov    (%rax),%esi
mov    0x2da6(%rip),%rax
or     (%rax),%esi
mov    $0x1ed,%edx
mov    $0x0,%al
call   1070 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    12c3 <main+0x153>
mov    0x2d55(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1030(%rbp)
mov    0x2d3e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x102c(%rbp)
mov    0x2d2f(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x1030(%rbp),%edi
mov    -0x102c(%rbp),%edx
mov    %rax,%rcx
lea    0xd79(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d04(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    12c8 <main+0x158>
mov    -0x14(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    $0x1000,%edx
call   1050 <read@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jle    1362 <main+0x1f2>
mov    -0x18(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jge    135d <main+0x1ed>
mov    0x2cbb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1038(%rbp)
mov    0x2ca4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1034(%rbp)
mov    0x2c95(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x1038(%rbp),%edi
mov    -0x1034(%rbp),%edx
mov    %rax,%rcx
lea    0xcdf(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2c62(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    12c8 <main+0x158>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
mov    0x2c37(%rip),%rax
mov    (%rax),%eax
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x1000,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jle    129b <main+0x12b>
mov    0x8(%rbx),%rdi
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1070 <open@plt>
test   %eax,%eax
js     1264 <main+0xf4>
mov    %eax,%r14d
mov    0x10(%rbx),%rdi
mov    0x2e2f(%rip),%rax
mov    0x2e40(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    $0x1ed,%edx
xor    %eax,%eax
call   1070 <open@plt>
test   %eax,%eax
js     1264 <main+0xf4>
mov    %eax,%ebp
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x1000,%edx
call   1050 <read@plt>
test   %eax,%eax
jle    1240 <main+0xd0>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
test   %eax,%eax
jns    11e0 <main+0x70>
mov    0x2dbd(%rip),%rax
mov    (%rax),%ebx
mov    0x2dac(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1090 <strerror@plt>
lea    0xe03(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2d7f(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    %r14d,%edi
call   1040 <close@plt>
mov    %ebp,%edi
call   1040 <close@plt>
mov    0x2d5a(%rip),%rax
mov    (%rax),%eax
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2d5d(%rip),%rax
mov    (%rax),%ebx
mov    0x2d4c(%rip),%r14
mov    (%r14),%ebp
mov    %ebp,%edi
call   1090 <strerror@plt>
lea    0xda2(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%r14),%edi
call   1080 <exit@plt>
mov    0x2d26(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xd52(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1232 <main+0xc2>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [39 x i8] c"Uso: %s <from filename> <to filename>\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [16 x i8] c"Err: (%d) - %s\0A\00"
@errno = global i32 0
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@EXIT_SUCCESS = global i32 0
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
%9 = alloca i32
%10 = alloca [4096 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 3
br i1 %12, label %13, label %21
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = load i32, i32* @O_RDONLY
%26 = call i32 (i8*, i32, ...) @open(i8* %24, i32 %25)
store i32 %26, i32* %6
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %36
28: ; preds = %21
%29 = load i32, i32* @stderr
%30 = load i32, i32* @errno
%31 = load i32, i32* @errno
%32 = call i8* @strerror(i32 %31)
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %30, i8* %32)
%34 = load i32, i32* @errno
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %21
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 2
%39 = load i8*, i8** %38
%40 = load i32, i32* @O_RDWR
%41 = load i32, i32* @O_CREAT
%42 = or i32 %40, %41
%43 = call i32 (i8*, i32, ...) @open(i8* %39, i32 %42, i32 493)
store i32 %43, i32* %7
%44 = icmp slt i32 %43, 0
br i1 %44, label %45, label %53
45: ; preds = %36
%46 = load i32, i32* @stderr
%47 = load i32, i32* @errno
%48 = load i32, i32* @errno
%49 = call i8* @strerror(i32 %48)
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %47, i8* %49)
%51 = load i32, i32* @errno
%52 = call i32 @exit(i32 %51)
unreachable
53: ; preds = %36
br label %54
54: ; preds = %73, %53
%55 = load i32, i32* %6
%56 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%57 = call i32 @read(i32 %55, i8* %56, i32 4096)
store i32 %57, i32* %8
%58 = icmp sgt i32 %57, 0
br i1 %58, label %59, label %74
59: ; preds = %54
%60 = load i32, i32* %7
%61 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%62 = load i32, i32* %8
%63 = call i32 @write(i32 %60, i8* %61, i32 %62)
store i32 %63, i32* %9
%64 = icmp slt i32 %63, 0
br i1 %64, label %65, label %73
65: ; preds = %59
%66 = load i32, i32* @stderr
%67 = load i32, i32* @errno
%68 = load i32, i32* @errno
%69 = call i8* @strerror(i32 %68)
%70 = call i32 (i32, i8*, ...) @fprintf(i32 %66, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %67, i8* %69)
%71 = load i32, i32* @EXIT_FAILURE
%72 = call i32 @exit(i32 %71)
unreachable
73: ; preds = %59
br label %54
74: ; preds = %54
%75 = load i32, i32* %6
%76 = call i32 @close(i32 %75)
%77 = load i32, i32* %7
%78 = call i32 @close(i32 %77)
%79 = load i32, i32* @EXIT_SUCCESS
ret i32 %79
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [39 x i8] c"Uso: %s <from filename> <to filename>\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [16 x i8] c"Err: (%d) - %s\0A\00"
@errno = global i32 0
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %12
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = load i32, i32* @O_RDONLY
%16 = tail call i32 (i8*, i32, ...) @open(i8* %14, i32 %15)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %25
18: ; preds = %12
%19 = load i32, i32* @stderr
%20 = load i32, i32* @errno
%21 = tail call i8* @strerror(i32 %20)
%22 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %20, i8* %21)
%23 = load i32, i32* @errno
%24 = tail call i32 @exit(i32 %23)
unreachable
25: ; preds = %12
%26 = getelementptr inbounds i8*, i8** %1, i64 2
%27 = load i8*, i8** %26
%28 = load i32, i32* @O_RDWR
%29 = load i32, i32* @O_CREAT
%30 = or i32 %29, %28
%31 = tail call i32 (i8*, i32, ...) @open(i8* %27, i32 %30, i32 493)
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %40
33: ; preds = %25
%34 = load i32, i32* @stderr
%35 = load i32, i32* @errno
%36 = tail call i8* @strerror(i32 %35)
%37 = tail call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %35, i8* %36)
%38 = load i32, i32* @errno
%39 = tail call i32 @exit(i32 %38)
unreachable
40: ; preds = %25, %43
%41 = call i32 @read(i32 %16, i8* %4, i32 4096)
%42 = icmp sgt i32 %41, 0
br i1 %42, label %43, label %53
43: ; preds = %40
%44 = call i32 @write(i32 %31, i8* %4, i32 %41)
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %40
46: ; preds = %43
%47 = load i32, i32* @stderr
%48 = load i32, i32* @errno
%49 = tail call i8* @strerror(i32 %48)
%50 = tail call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %48, i8* %49)
%51 = load i32, i32* @EXIT_FAILURE
%52 = tail call i32 @exit(i32 %51)
unreachable
53: ; preds = %40
%54 = tail call i32 @close(i32 %16)
%55 = tail call i32 @close(i32 %31)
%56 = load i32, i32* @EXIT_SUCCESS
ret i32 %56
}