#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 */
void *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_RDWR;
int /*<<< orphan*/ PROT_READ;
int /*<<< orphan*/ PROT_WRITE;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
size_t lseek(int, size_t, int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(void *, void *, size_t);
void *mmap(int /*<<< orphan*/, size_t, int /*<<< orphan*/, int /*<<< orphan*/,
           int, int /*<<< orphan*/);
int /*<<< orphan*/ munmap(void *, size_t);
int open(char const *, int, ...);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char const *argv[]) {
  int in, out;
  if (argc != 3) {
    fprintf(
        stderr,
        "Per utilizzare il programma, digitare il nome dell'eseguibile seguito "
        "dal nome del file di input e quello del file di output.\n");
    exit(1);
  }
  in = open(argv[1], O_RDONLY);
  if (in == -1) {
    perror("APERTURA FILE INPUT FALLITA\n");
    exit(2);
  }
  out = open(argv[2], O_RDWR | O_CREAT, 0666);
  if (out == -1) {
    close(in);
    perror("APERTURA FILE OUTPUT FALLITA\n");
    exit(2);
  }
  size_t size = lseek(in, 0, SEEK_END);
  lseek(out, size + 1, SEEK_SET);
  char end = 'EOF';
  write(out, &end, 1);
  void *source, *target;
  source = mmap(0, size, PROT_READ, MAP_SHARED, in, 0);
  if (source == MAP_FAILED) {
    perror("ERRORE DURANTE IL MAPPING DEL FILE DI INPUT\n");
    exit(1);
  }
  target = mmap(0, size, PROT_WRITE, MAP_SHARED, out, 0);
  if (target == MAP_FAILED) {
    perror("ERRORE DURANTE IL MAPPING DEL FILE DI OUTPUT\n");
    exit(2);
  }
  memcpy(target, source, size);
  munmap(source, size);
  munmap(target, size);
  close(in);
  close(out);
  exit(0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11df <main+0x3f>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
lea    0xe30(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2dd2(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   10a0 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    121a <main+0x7a>
lea    0xe74(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x2,%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2da7(%rip),%rax
mov    (%rax),%esi
mov    0x2dc6(%rip),%rax
or     (%rax),%esi
mov    $0x1b6,%edx
mov    $0x0,%al
call   10a0 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    126b <main+0xcb>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
lea    0xe40(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x2,%edi
call   10c0 <exit@plt>
mov    -0x14(%rbp),%edi
mov    0x2d53(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1050 <lseek@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x20(%rbp),%rsi
add    $0x1,%rsi
mov    0x2d12(%rip),%rax
mov    (%rax),%edx
call   1050 <lseek@plt>
movb   $0x46,-0x21(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x21(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x20(%rbp),%rsi
mov    0x2d33(%rip),%rax
mov    (%rax),%edx
mov    0x2d1a(%rip),%rax
mov    (%rax),%ecx
mov    -0x14(%rbp),%r8d
xor    %r9d,%r9d
mov    %r9d,%edi
call   1040 <mmap@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    0x2cb2(%rip),%rcx
cmp    (%rcx),%rax
jne    1305 <main+0x165>
lea    0xdc4(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x20(%rbp),%rsi
mov    0x2c90(%rip),%rax
mov    (%rax),%edx
mov    0x2cc7(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%r8d
xor    %r9d,%r9d
mov    %r9d,%edi
call   1040 <mmap@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    0x2c5f(%rip),%rcx
cmp    (%rcx),%rax
jne    1358 <main+0x1b8>
lea    0xd9e(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x2,%edi
call   10c0 <exit@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1080 <memcpy@plt>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1090 <munmap@plt>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1090 <munmap@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x3,%edi
jne    11d8 <main+0x38>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
mov    0x2e02(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   10a0 <open@plt>
cmp    $0xffffffff,%eax
jne    11f7 <main+0x57>
lea    0xeac(%rip),%rdi
jmp    12e8 <main+0x148>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
lea    0xe18(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    %eax,%ebx
mov    0x10(%rbp),%rdi
mov    0x2dcc(%rip),%rax
mov    0x2ded(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    $0x1b6,%edx
xor    %eax,%eax
call   10a0 <open@plt>
cmp    $0xffffffff,%eax
jne    1233 <main+0x93>
mov    %ebx,%edi
call   1060 <close@plt>
lea    0xe6e(%rip),%rdi
jmp    12e8 <main+0x148>
mov    %eax,%ebp
mov    0x2d8c(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
xor    %esi,%esi
call   1050 <lseek@plt>
mov    %rax,%r14
lea    0x1(%rax),%rsi
mov    0x2d53(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
call   1050 <lseek@plt>
movb   $0x46,0x7(%rsp)
lea    0x7(%rsp),%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1030 <write@plt>
mov    0x2d75(%rip),%rax
mov    (%rax),%edx
mov    0x2d5c(%rip),%r12
mov    (%r12),%ecx
xor    %edi,%edi
mov    %r14,%rsi
mov    %ebx,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    0x2cf9(%rip),%r13
cmp    0x0(%r13),%rax
jne    12bb <main+0x11b>
lea    0xe0e(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    %rax,%r15
mov    0x2cdb(%rip),%rax
mov    (%rax),%edx
mov    (%r12),%ecx
xor    %edi,%edi
mov    %r14,%rsi
mov    %ebp,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
cmp    0x0(%r13),%rax
jne    12f7 <main+0x157>
lea    0xdff(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x2,%edi
call   10c0 <exit@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1080 <memcpy@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1090 <munmap@plt>
mov    %r12,%rdi
mov    %r14,%rsi
call   1090 <munmap@plt>
mov    %ebx,%edi
call   1060 <close@plt>
mov    %ebp,%edi
call   1060 <close@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [127 x i8] c"Per utilizzare il programma, digitare il nome dell'eseguibile seguito dal nome del file di input e quello del file di output.\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [29 x i8] c"APERTURA FILE INPUT FALLITA\0A\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str.2 = [30 x i8] c"APERTURA FILE OUTPUT FALLITA\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.3 = [45 x i8] c"ERRORE DURANTE IL MAPPING DEL FILE DI INPUT\0A\00"
@PROT_WRITE = global i32 0
@.str.4 = [46 x i8] c"ERRORE DURANTE IL MAPPING DEL FILE DI OUTPUT\0A\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 i64
%9 = alloca i8
%10 = alloca i8*
%11 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 3
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([127 x i8], [127 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = load i32, i32* @O_RDONLY
%23 = call i32 (i8*, i32, ...) @open(i8* %21, i32 %22)
store i32 %23, i32* %6
%24 = load i32, i32* %6
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %29
26: ; preds = %18
%27 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 @exit(i32 2)
unreachable
29: ; preds = %18
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 2
%32 = load i8*, i8** %31
%33 = load i32, i32* @O_RDWR
%34 = load i32, i32* @O_CREAT
%35 = or i32 %33, %34
%36 = call i32 (i8*, i32, ...) @open(i8* %32, i32 %35, i32 438)
store i32 %36, i32* %7
%37 = load i32, i32* %7
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %44
39: ; preds = %29
%40 = load i32, i32* %6
%41 = call i32 @close(i32 %40)
%42 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%43 = call i32 @exit(i32 2)
unreachable
44: ; preds = %29
%45 = load i32, i32* %6
%46 = load i32, i32* @SEEK_END
%47 = call i64 @lseek(i32 %45, i64 0, i32 %46)
store i64 %47, i64* %8
%48 = load i32, i32* %7
%49 = load i64, i64* %8
%50 = add i64 %49, 1
%51 = load i32, i32* @SEEK_SET
%52 = call i64 @lseek(i32 %48, i64 %50, i32 %51)
store i8 70, i8* %9
%53 = load i32, i32* %7
%54 = call i32 @write(i32 %53, i8* %9, i32 1)
%55 = load i64, i64* %8
%56 = load i32, i32* @PROT_READ
%57 = load i32, i32* @MAP_SHARED
%58 = load i32, i32* %6
%59 = call i8* @mmap(i32 0, i64 %55, i32 %56, i32 %57, i32 %58, i32 0)
store i8* %59, i8** %10
%60 = load i8*, i8** %10
%61 = load i8*, i8** @MAP_FAILED
%62 = icmp eq i8* %60, %61
br i1 %62, label %63, label %66
63: ; preds = %44
%64 = call i32 @perror(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0))
%65 = call i32 @exit(i32 1)
unreachable
66: ; preds = %44
%67 = load i64, i64* %8
%68 = load i32, i32* @PROT_WRITE
%69 = load i32, i32* @MAP_SHARED
%70 = load i32, i32* %7
%71 = call i8* @mmap(i32 0, i64 %67, i32 %68, i32 %69, i32 %70, i32 0)
store i8* %71, i8** %11
%72 = load i8*, i8** %11
%73 = load i8*, i8** @MAP_FAILED
%74 = icmp eq i8* %72, %73
br i1 %74, label %75, label %78
75: ; preds = %66
%76 = call i32 @perror(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0))
%77 = call i32 @exit(i32 2)
unreachable
78: ; preds = %66
%79 = load i8*, i8** %11
%80 = load i8*, i8** %10
%81 = load i64, i64* %8
%82 = call i32 @memcpy(i8* %79, i8* %80, i64 %81)
%83 = load i8*, i8** %10
%84 = load i64, i64* %8
%85 = call i32 @munmap(i8* %83, i64 %84)
%86 = load i8*, i8** %11
%87 = load i64, i64* %8
%88 = call i32 @munmap(i8* %86, i64 %87)
%89 = load i32, i32* %6
%90 = call i32 @close(i32 %89)
%91 = load i32, i32* %7
%92 = call i32 @close(i32 %91)
%93 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [127 x i8] c"Per utilizzare il programma, digitare il nome dell'eseguibile seguito dal nome del file di input e quello del file di output.\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [29 x i8] c"APERTURA FILE INPUT FALLITA\0A\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str.2 = [30 x i8] c"APERTURA FILE OUTPUT FALLITA\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.3 = [45 x i8] c"ERRORE DURANTE IL MAPPING DEL FILE DI INPUT\0A\00"
@PROT_WRITE = global i32 0
@.str.4 = [46 x i8] c"ERRORE DURANTE IL MAPPING DEL FILE DI OUTPUT\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8
%4 = icmp eq i32 %0, 3
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([127 x i8], [127 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = load i32, i32* @O_RDONLY
%13 = tail call i32 (i8*, i32, ...) @open(i8* %11, i32 %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %9
%16 = tail call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%17 = tail call i32 @exit(i32 2)
unreachable
18: ; preds = %9
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
%21 = load i32, i32* @O_RDWR
%22 = load i32, i32* @O_CREAT
%23 = or i32 %22, %21
%24 = tail call i32 (i8*, i32, ...) @open(i8* %20, i32 %23, i32 438)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %30
26: ; preds = %18
%27 = tail call i32 @close(i32 %13)
%28 = tail call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%29 = tail call i32 @exit(i32 2)
unreachable
30: ; preds = %18
%31 = load i32, i32* @SEEK_END
%32 = tail call i64 @lseek(i32 %13, i64 0, i32 %31)
%33 = add i64 %32, 1
%34 = load i32, i32* @SEEK_SET
%35 = tail call i64 @lseek(i32 %24, i64 %33, i32 %34)
store i8 70, i8* %3
%36 = call i32 @write(i32 %24, i8* %3, i32 1)
%37 = load i32, i32* @PROT_READ
%38 = load i32, i32* @MAP_SHARED
%39 = tail call i8* @mmap(i32 0, i64 %32, i32 %37, i32 %38, i32 %13, i32 0)
%40 = load i8*, i8** @MAP_FAILED
%41 = icmp eq i8* %39, %40
br i1 %41, label %42, label %45
42: ; preds = %30
%43 = tail call i32 @perror(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0))
%44 = tail call i32 @exit(i32 1)
unreachable
45: ; preds = %30
%46 = load i32, i32* @PROT_WRITE
%47 = load i32, i32* @MAP_SHARED
%48 = tail call i8* @mmap(i32 0, i64 %32, i32 %46, i32 %47, i32 %24, i32 0)
%49 = load i8*, i8** @MAP_FAILED
%50 = icmp eq i8* %48, %49
br i1 %50, label %51, label %54
51: ; preds = %45
%52 = tail call i32 @perror(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0))
%53 = tail call i32 @exit(i32 2)
unreachable
54: ; preds = %45
%55 = tail call i32 @memcpy(i8* %48, i8* %39, i64 %32)
%56 = tail call i32 @munmap(i8* %39, i64 %32)
%57 = tail call i32 @munmap(i8* %48, i64 %32)
%58 = tail call i32 @close(i32 %13)
%59 = tail call i32 @close(i32 %24)
%60 = tail call i32 @exit(i32 0)
unreachable
}